#===================================================================== # LedgerSMB # Small Medium Business Accounting software # # See COPYRIGHT file for copyright information #====================================================================== # # This file has NOT undergone whitespace cleanup. # #====================================================================== # # Inventory Control module # #====================================================================== use LedgerSMB::IC; require "$form->{path}/io.pl"; 1; # end of main sub add { %label = ( part => 'Part', service => 'Service', assembly => 'Assembly', labor => 'Labor/Overhead', ); # $locale->text('Add Part') # $locale->text('Add Service') # $locale->text('Add Assembly') # $locale->text('Add Labor/Overhead') $label = "Add $label{$form->{item}}"; $form->{title} = $locale->text($label); $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; $form->{orphaned} = 1; if ($form->{previousform}) { $form->{callback} = ""; } &link_part; &display_form; } sub edit { %label = ( part => 'Part', service => 'Service', assembly => 'Assembly', labor => 'Labor/Overhead', ); # $locale->text('Edit Part') # $locale->text('Edit Service') # $locale->text('Edit Assembly') # $locale->text('Edit Labor/Overhead') IC->get_part(\%myconfig, \%$form); $label = "Edit $label{$form->{item}}"; $form->{title} = $locale->text($label); $form->{previousform} = $form->escape($form->{previousform}, 1) if $form->{previousform}; &link_part; &display_form; } sub link_part { IC->create_links("IC", \%myconfig, \%$form); # currencies $form->{selectcurrency} = ""; for (split /:/, $form->{currencies}) { $form->{selectcurrency} .= "$_\n" } # readonly if ($form->{item} eq 'part') { $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Part/; $form->error($locale->text('Cannot create Part').";".$locale->text('Inventory account does not exist!')) if ! @{ $form->{IC_links}{IC} }; $form->error($locale->text('Cannot create Part').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_sale} }; $form->error($locale->text('Cannot create Part').";".$locale->text('COGS account does not exist!')) if ! @{ $form->{IC_links}{IC_cogs} }; } if ($form->{item} eq 'service') { $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Service/; $form->error($locale->text('Cannot create Service').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_income} }; $form->error($locale->text('Cannot create Service').";".$locale->text('Expense account does not exist!')) if ! @{ $form->{IC_links}{IC_expense} }; } if ($form->{item} eq 'assembly') { $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Assembly/; $form->error($locale->text('Cannot create Assembly').";".$locale->text('Income account does not exist!')) if ! @{ $form->{IC_links}{IC_income} }; } if ($form->{item} eq 'labor') { $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Labor\/Overhead/; $form->error($locale->text('Cannot create Labor').";".$locale->text('Inventory account does not exist!')) if ! @{ $form->{IC_links}{IC} }; $form->error($locale->text('Cannot create Labor').";".$locale->text('COGS account does not exist!')) if ! @{ $form->{IC_links}{IC_cogs} }; } # parts, assemblies , labor and overhead have the same links $taxpart = ($form->{item} eq 'service') ? "service" : "part"; # build the popup menus $form->{taxaccounts} = ""; foreach $key (keys %{ $form->{IC_links} }) { $form->{"select$key"} = ""; foreach $ref (@{ $form->{IC_links}{$key} }) { # if this is a tax field if ($key =~ /IC_tax/) { if ($key =~ /$taxpart/) { $form->{taxaccounts} .= "$ref->{accno} "; $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}"; if ($form->{id}) { if ($form->{amount}{$ref->{accno}}) { $form->{"IC_tax_$ref->{accno}"} = "checked"; } } else { $form->{"IC_tax_$ref->{accno}"} = "checked"; } } } else { $form->{"select$key"} .= "$ref->{accno}--$ref->{description}\n"; } } } chop $form->{taxaccounts}; if ($form->{item} !~ /service/) { $form->{selectIC_inventory} = $form->{selectIC}; $form->{selectIC_income} = $form->{selectIC_sale}; $form->{selectIC_expense} = $form->{selectIC_cogs}; $form->{IC_income} = $form->{IC_sale}; $form->{IC_expense} = $form->{IC_cogs}; } # set option for (qw(IC_inventory IC_income IC_expense)) { $form->{$_} = "$form->{amount}{$_}{accno}--$form->{amount}{$_}{description}" if $form->{amount}{$_}{accno} } delete $form->{IC_links}; delete $form->{amount}; $form->get_partsgroup(\%myconfig, {all => 1}); if ($form->{partsgroup}) { $form->{partsgroup} = $form->quote($form->{partsgroup})."--$form->{partsgroup_id}"; } if (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} = qq|\n|; for (@{ $form->{all_partsgroup} }) { $form->{selectpartsgroup} .= qq|$_->{partsgroup}\n| } delete $form->{all_partsgroup}; } if ($form->{item} eq 'assembly') { for (1 .. $form->{assembly_rows}) { if ($form->{"partsgroup_id_$_"}) { $form->{"partsgroup_$_"} = qq|$form->{"partsgroup_$_"}--$form->{"partsgroup_id_$_"}|; } } $form->get_partsgroup(\%myconfig); if (@{ $form->{all_partsgroup} }) { $form->{selectassemblypartsgroup} = qq|\n|; for (@{ $form->{all_partsgroup} }) { $form->{selectassemblypartsgroup} .= qq|$_->{partsgroup}\n| } delete $form->{all_partsgroup}; } } # setup make and models $i = 1; foreach $ref (@{ $form->{makemodels} }) { for (qw(make model)) { $form->{"${_}_$i"} = $ref->{$_} } $i++; } $form->{makemodel_rows} = $i - 1; delete $form->{makemodels}; # setup vendors if (@{ $form->{all_vendor} }) { $form->{selectvendor} = "\n"; for (@{ $form->{all_vendor} }) { $form->{selectvendor} .= qq|$_->{name}\n| } delete $form->{all_vendor}; } # vendor matrix $i = 1; foreach $ref (@{ $form->{vendormatrix} }) { $form->{"vendor_$i"} = qq|$ref->{name}--$ref->{id}|; for (qw(partnumber lastcost leadtime vendorcurr)) { $form->{"${_}_$i"} = $ref->{$_} } $i++; } $form->{vendor_rows} = $i - 1; delete $form->{vendormatrix}; # setup customers and groups if (@{ $form->{all_customer} }) { $form->{selectcustomer} = "\n"; for (@{ $form->{all_customer} }) { $form->{selectcustomer} .= qq|$_->{name}\n| } delete $form->{all_customer}; } if (@{ $form->{all_pricegroup} }) { $form->{selectpricegroup} = "\n"; for (@{ $form->{all_pricegroup} }) { $form->{selectpricegroup} .= qq|$_->{pricegroup}\n| } delete $form->{all_pricegroup}; } $i = 1; # customer matrix foreach $ref (@{ $form->{customermatrix} }) { $form->{"customer_$i"} = "$ref->{name}--$ref->{cid}" if $ref->{cid}; $form->{"pricegroup_$i"} = "$ref->{pricegroup}--$ref->{gid}" if $ref->{gid}; for (qw(validfrom validto pricebreak customerprice customercurr)) { $form->{"${_}_$i"} = $ref->{$_} } $i++; } $form->{customer_rows} = $i - 1; delete $form->{customermatrix}; } sub form_header { if ($form->{lastcost} > 0) { $markup = $form->round_amount((($form->{sellprice}/$form->{lastcost} - 1) * 100), 1); $form->{markup} = $form->format_amount(\%myconfig, $markup, 1); } ($dec) = ($form->{sellprice} =~ /\.(\d+)/); $dec = length $dec; $decimalplaces = ($dec > 2) ? $dec : 2; for (qw(listprice sellprice)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces) } ($dec) = ($form->{lastcost} =~ /\.(\d+)/); $dec = length $dec; $decimalplaces = ($dec > 2) ? $dec : 2; for (qw(lastcost avgcost)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces) } for (qw(weight rop stock)) { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) } for (qw(partnumber description unit notes)) { $form->{$_} = $form->quote($form->{$_}) } if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) { $rows = 2; } $notes = qq|$form->{notes}|; if (($rows = $form->numtextrows($form->{description}, 40)) > 1) { $description = qq|$form->{description}|; } else { $description = qq||; } for (split / /, $form->{taxaccounts}) { $form->{"IC_tax_$_"} = ($form->{"IC_tax_$_"}) ? "checked" : "" } $form->{selectIC_inventory} = $form->{selectIC}; # set option for (qw(IC_inventory IC_income IC_expense)) { if ($form->{$_}) { if ($form->{orphaned}) { $form->{"select$_"} =~ s/ selected//; $form->{"select$_"} =~ s/option>\Q$form->{$_}\E/option selected>$form->{$_}/; } else { $form->{"select$_"} = qq|$form->{$_}|; } } } if ($form->{selectpartsgroup}) { $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup}); $partsgroup = qq||; $form->{partsgroup} = $form->quote($form->{partsgroup}); $form->{selectpartsgroup} =~ s/($form->{selectpartsgroup}|; $group = $locale->text('Group'); } # tax fields foreach $item (split / /, $form->{taxaccounts}) { $tax .= qq| {"IC_tax_$item"}> $form->{"IC_tax_${item}_description"} |; } $sellprice = qq| |.$locale->text('Sell Price').qq| {sellprice}> |.$locale->text('List Price').qq| {listprice}> |; $avgcost = qq| |.$locale->text('Average Cost').qq| {avgcost}>$form->{avgcost} |; $lastcost = qq| |.$locale->text('Last Cost').qq| {lastcost}> |.$locale->text('Markup').qq| % {markup}> |; if ($form->{item} =~ /(part|assembly)/) { $n = ($form->{onhand} > 0) ? "1" : "0"; $onhand = qq| |.$locale->text('On Hand').qq| |.$form->format_amount(\%myconfig, $form->{onhand}).qq| |; $rop = qq| |.$locale->text('ROP').qq| {rop}> |; $bin = qq| |.$locale->text('Bin').qq| |; $imagelinks = qq| |.$locale->text('Image').qq| |.$locale->text('Microfiche').qq| |.$locale->text('Drawing').qq| |; } if ($form->{item} eq "part") { $linkaccounts = qq| |.$locale->text('Inventory').qq| $form->{selectIC_inventory} |.$locale->text('Income').qq| $form->{selectIC_income} |.$locale->text('COGS').qq| $form->{selectIC_expense} |; if ($tax) { $linkaccounts .= qq| |.$locale->text('Tax').qq| $tax |; } $weight = qq| |.$locale->text('Weight').qq| {weight}> $form->{weightunit} {weightunit}> |; } if ($form->{item} eq "assembly") { $avgcost = ""; if ($form->{project_id}) { $weight = qq| |.$locale->text('Weight').qq| {weight}> $form->{weightunit} {weightunit}> |; } else { $weight = qq| |.$locale->text('Weight').qq| $form->{weight} {weight}> $form->{weightunit} {weightunit}> |; } if ($form->{project_id}) { $lastcost = ""; $avgcost = ""; $onhand = ""; $rop = ""; $form->{isassemblyitem} = 1; } else { $stock = qq| |.$locale->text('Stock').qq| {stock}> |; $lastcost = qq| |.$locale->text('Last Cost').qq| {lastcost}>$form->{lastcost} |.$locale->text('Markup').qq| % {markup}> |; } $linkaccounts = qq| |.$locale->text('Income').qq| $form->{selectIC_income} |; if ($tax) { $linkaccounts .= qq| |.$locale->text('Tax').qq| $tax |; } } if ($form->{item} eq "service") { $avgcost = ""; $linkaccounts = qq| |.$locale->text('Income').qq| $form->{selectIC_income} |.$locale->text('Expense').qq| $form->{selectIC_expense} |; if ($tax) { $linkaccounts .= qq| |.$locale->text('Tax').qq| $tax |; } } if ($form->{item} eq 'labor') { $avgcost = ""; $n = ($form->{onhand} > 0) ? "1" : "0"; $onhand = qq| |.$locale->text('On Hand').qq| |.$form->format_amount(\%myconfig, $form->{onhand}).qq| |; $linkaccounts = qq| |.$locale->text('Labor/Overhead').qq| $form->{selectIC_inventory} |.$locale->text('COGS').qq| $form->{selectIC_expense} |; } if ($form->{id}) { $checked = ($form->{obsolete}) ? "checked" : ""; $obsolete = qq| |.$locale->text('Obsolete').qq| |; $obsolete = "{obsolete}>" if $form->{project_id}; } # type=submit $locale->text('Edit Part') # type=submit $locale->text('Edit Service') # type=submit $locale->text('Edit Assembly') $form->header; print qq| |; $form->hide_form(qw(id item title makemodel alternate onhand orphaned taxaccounts rowcount baseassembly project_id)); print qq| $form->{title} |.$locale->text('Number').qq| |.$locale->text('Description').qq| $group $description $partsgroup |.$locale->text('Link Accounts').qq| $linkaccounts |.$locale->text('Notes').qq| $notes |.$locale->text('Updated').qq| {priceupdate}> $sellprice $lastcost $avgcost |.$locale->text('Unit').qq| $weight $onhand $stock $rop $bin $obsolete $imagelinks |; } sub form_footer { print qq| |; $form->hide_form(qw(customer_rows)); if ($form->{item} =~ /(part|assembly)/) { $form->hide_form(qw(makemodel_rows)); } if ($form->{item} =~ /(part|service)/) { $form->hide_form(qw(vendor_rows)); } # type=submit $locale->text('Update') # type=submit $locale->text('Save') # type=submit $locale->text('Save as new') # type=submit $locale->text('Delete') if (! $form->{readonly}) { %button = ('Update' => { ndx => 1, key => 'U', value => $locale->text('Update') }, 'Save' => { ndx => 3, key => 'S', value => $locale->text('Save') }, ); if ($form->{id}) { if (!$form->{isassemblyitem}) { $button{'Save as new'} = { ndx => 7, key => 'N', value => $locale->text('Save as new') }; } if ($form->{orphaned}) { $button{'Delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') }; } } for (sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button) { $form->print_button(\%button, $_) } } if ($form->{menubar}) { require "$form->{path}/menu.pl"; &menubar; } &assembly_row(++$form->{assembly_rows}) if $form->{item} eq 'assembly'; $form->hide_form(qw(login path sessionid callback previousform isassemblyitem)); print qq|