#===================================================================== # SQL-Ledger, Accounting # Copyright (c) 2001 # # Author: Dieter Simader # Email: dsimader@sql-ledger.org # Web: http://www.sql-ledger.org # # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #====================================================================== # # Inventory Control module # #====================================================================== use SL::IC; require "$form->{path}/io.pl"; 1; # end of main sub add { $form->{title} = $locale->text('Add ' . ucfirst $form->{item}); $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; $form->{unit} = ($form->{item} eq 'service') ? $locale->text('hr') : $locale->text('ea'); &link_part; &display_form; } sub search { $form->{title} = (ucfirst $form->{searchitems})."s"; $form->{title} = $locale->text($form->{title}); # $locale->text('Parts') # $locale->text('Services') unless ($form->{searchitems} eq 'service') { $onhand = qq|  |.$locale->text('On Hand').qq|  |.$locale->text('Short').qq| |; $makemodel = qq| |.$locale->text('Make').qq| |.$locale->text('Model').qq| |; } if ($form->{searchitems} eq 'assembly') { $form->{title} = $locale->text('Assemblies'); $toplevel = qq|  |.$locale->text('Top Level').qq|  |.$locale->text('Individual Items').qq| |; $bought = qq|
|.$locale->text('Sold').qq|

|.$locale->text('Ordered').qq|
  |.$locale->text('From').qq| |.$locale->text('to').qq|  |.$locale->text('Closed').qq|
|; } else { $bought = qq|
|.$locale->text('Bought').qq| |.$locale->text('Sold').qq|

|.$locale->text('On Order').qq| |.$locale->text('Ordered').qq|
 
|.$locale->text('From').qq| |.$locale->text('to').qq|  |.$locale->text('Closed').qq|
|; } $form->header; print qq|
{script}> {searchitems}>
$form->{title}
$makemodel $toplevel $bought
|.$locale->text('Number').qq| |.$locale->text('Description').qq|
|.$locale->text('Group').qq|
|.$locale->text('Drawing').qq| |.$locale->text('Microfiche').qq|
 |.$locale->text('Active').qq| $onhand  |.$locale->text('Obsolete').qq|  |.$locale->text('Orphaned').qq|

|.$locale->text('Include in Report').qq|
 |.$locale->text('Number').qq|  |.$locale->text('Description').qq|  |.$locale->text('Unit of measure').qq|
 |.$locale->text('List Price').qq|  |.$locale->text('Sell Price').qq|  |.$locale->text('Last Cost').qq|  |.$locale->text('Line Total').qq|
 |.$locale->text('Updated').qq|  |.$locale->text('Bin').qq|  |.$locale->text('ROP').qq|  |.$locale->text('Weight').qq|
 |.$locale->text('Image').qq|  |.$locale->text('Drawing').qq|  |.$locale->text('Microfiche').qq|  |.$locale->text('Group').qq|
 |.$locale->text('Subtotal').qq|

{path}> {login}> {password}>
|; } sub generate_report { # setup $form->{sort} unless ($form->{sort}) { if ($form->{description} && !($form->{partnumber})) { $form->{sort} = "description"; } else { $form->{sort} = "partnumber"; } } $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title=".$form->escape($form->{title},1); IC->all_parts(\%myconfig, \%$form); if ($form->{itemstatus} eq 'active') { $option .= $locale->text('Active')." : "; } if ($form->{itemstatus} eq 'obsolete') { $option .= $locale->text('Obsolete')." : "; } if ($form->{itemstatus} eq 'orphaned') { $option .= $locale->text('Orphaned')." : "; } if ($form->{itemstatus} eq 'onhand') { $option .= $locale->text('On Hand')." : "; $form->{l_onhand} = "Y"; } if ($form->{itemstatus} eq 'short') { $option .= $locale->text('Short')." : "; $form->{l_onhand} = "Y"; } if ($form->{onorder}) { $form->{l_ordnumber} = "Y"; $callback .= "&onorder=$form->{onorder}"; $option .= $locale->text('On Order')." : "; } if ($form->{ordered}) { $form->{l_ordnumber} = "Y"; $callback .= "&ordered=$form->{ordered}"; $option .= $locale->text('Ordered')." : "; } if ($form->{closed}) { $callback .= "&closed=$form->{closed}"; $option .= $locale->text('Closed')." : "; } if ($form->{bought}) { $form->{l_invnumber} = "Y"; $callback .= "&bought=$form->{bought}"; $option .= $locale->text('Bought')." : "; } if ($form->{sold}) { $form->{l_invnumber} = "Y"; $callback .= "&sold=$form->{sold}"; $option .= $locale->text('Sold')." : "; } if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) { $form->{l_lastcost} = ""; if ($form->{transdatefrom}) { $callback .= "&transdatefrom=$form->{transdatefrom}"; $option .= "\n
".$locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1); } if ($form->{transdateto}) { $callback .= "&transdateto=$form->{transdateto}"; $option .= "\n
".$locale->text('to')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); } } $option .= "
"; if ($form->{partnumber}) { $callback .= "&partnumber=$form->{partnumber}"; $option .= $locale->text('Number').qq| : $form->{partnumber}
|; } if ($form->{description}) { $callback .= "&description=$form->{description}"; $option .= $locale->text('Description').qq| : $form->{description}
|; } if ($form->{make}) { $callback .= "&make=$form->{make}"; $option .= $locale->text('Make').qq| : $form->{make}
|; } if ($form->{model}) { $callback .= "&model=$form->{model}"; $option .= $locale->text('Model').qq| : $form->{model}
|; } if ($form->{drawing}) { $callback .= "&drawing=$form->{drawing}"; $option .= $locale->text('Drawing').qq| : $form->{drawing}
|; } if ($form->{microfiche}) { $callback .= "µfiche=$form->{microfiche}"; $option .= $locale->text('Microfiche').qq| : $form->{microfiche}
|; } if ($form->{partsgroup}) { $callback .= "&partsgroup=$form->{partsgroup}"; $option .= $locale->text('Group').qq| : $form->{partsgroup}
|; } @columns = $form->sort_columns(qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost priceupdate weight image drawing microfiche invnumber ordnumber)); if ($form->{l_linetotal}) { $form->{l_onhand} = "Y"; $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice}; if ($form->{l_lastcost}) { $form->{l_linetotallastcost} = "Y"; if (($form->{searchitems} eq 'assembly') && !$form->{bom}) { $form->{l_linetotallastcost} = ""; } } $form->{l_linetotallistprice} = "Y" if $form->{l_listprice}; } if ($form->{searchitems} eq 'service') { # remove bin, weight and rop from list map { $form->{"l_$_"} = "" } qw(bin weight rop); $form->{l_onhand} = ""; # qty is irrelevant unless bought or sold if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) { $form->{l_onhand} = "Y"; } else { $form->{l_linetotalsellprice} = ""; $form->{l_linetotallastcost} = ""; } } $form->{l_lastcost} = "" if ($form->{searchitems} eq 'assembly' && !$form->{bom}); foreach $item (@columns) { if ($form->{"l_$item"} eq "Y") { push @column_index, $item; # add column to callback $callback .= "&l_$item=Y"; } } if ($form->{l_subtotal} eq 'Y') { $callback .= "&l_subtotal=Y"; } $column_header{partnumber} = qq||.$locale->text('Number').qq||; $column_header{description} = qq||.$locale->text('Description').qq||; $column_header{partsgroup} = qq||.$locale->text('Group').qq||; $column_header{bin} = qq||.$locale->text('Bin').qq||; $column_header{priceupdate} = qq||.$locale->text('Updated').qq||; $column_header{onhand} = qq||.$locale->text('Qty').qq||; $column_header{unit} = qq||.$locale->text('Unit').qq||; $column_header{listprice} = qq||.$locale->text('List Price').qq||; $column_header{lastcost} = qq||.$locale->text('Last Cost').qq||; $column_header{rop} = qq||.$locale->text('ROP').qq||; $column_header{weight} = qq||.$locale->text('Weight').qq||; $column_header{invnumber} = qq||.$locale->text('Invoice Number').qq||; $column_header{ordnumber} = qq||.$locale->text('Order Number').qq||; $column_header{sellprice} = qq||.$locale->text('Sell Price').qq||; $column_header{linetotalsellprice} = qq||.$locale->text('Extended').qq||; $column_header{linetotallastcost} = qq||.$locale->text('Extended').qq||; $column_header{linetotallistprice} = qq||.$locale->text('Extended').qq||; $column_header{image} = qq||.$locale->text('Image').qq||; $column_header{drawing} = qq||.$locale->text('Drawing').qq||; $column_header{microfiche} = qq||.$locale->text('Microfiche').qq||; $form->header; $colspan = $#column_index + 1; print qq| |; map { print "\n$column_header{$_}" } @column_index; print qq| |; # add order to callback $form->{callback} = $callback .= "&sort=$form->{sort}"; # escape callback for href $callback = $form->escape($callback); if (@{ $form->{parts} }) { $sameitem = $form->{parts}->[0]->{$form->{sort}}; } foreach $ref (@{ $form->{parts} }) { if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) { if ($sameitem ne $ref->{$form->{sort}}) { &parts_subtotal; $sameitem = $ref->{$form->{sort}}; } } $ref->{exchangerate} = 1 unless $ref->{exchangerate}; $ref->{sellprice} *= $ref->{exchangerate}; $ref->{listprice} *= $ref->{exchangerate}; $ref->{lastcost} *= $ref->{exchangerate}; $align = "left"; $onhand = $ref->{onhand}; if ($ref->{assemblyitem}) { $align = "right"; $onhand = 0 if ($form->{sold}); } $column_data{partnumber} = ""; $column_data{description} = ""; $column_data{partsgroup} = ""; $column_data{onhand} = ""; $column_data{sellprice} = ""; $column_data{listprice} = ""; $column_data{lastcost} = ""; $column_data{linetotalsellprice} = ""; $column_data{linetotallastcost} = ""; $column_data{linetotallistprice} = ""; if (!$ref->{assemblyitem}) { $totalsellprice += $onhand * $ref->{sellprice}; $totallastcost += $onhand * $ref->{lastcost}; $totallistprice += $onhand * $ref->{listprice}; $subtotalonhand += $onhand; $subtotalsellprice += $onhand * $ref->{sellprice}; $subtotallastcost += $onhand * $ref->{lastcost}; $subtotallistprice += $onhand * $ref->{listprice}; } $column_data{rop} = ""; $column_data{weight} = ""; $column_data{unit} = ""; $column_data{bin} = ""; $column_data{priceupdate} = ""; $column_data{invnumber} = ($ref->{module} ne 'oe') ? "" : ""; $column_data{ordnumber} = ($ref->{module} eq 'oe') ? "" : ""; $column_data{image} = ($ref->{image}) ? "" : ""; $column_data{drawing} = ($ref->{drawing}) ? "" : ""; $column_data{microfiche} = ($ref->{microfiche}) ? "" : ""; $i++; $i %= 2; print ""; map { print "\n$column_data{$_}" } @column_index; print qq| |; } if ($form->{l_subtotal} eq 'Y') { &parts_subtotal; } if ($form->{"l_linetotal"}) { map { $column_data{$_} = "" } @column_index; $column_data{linetotalsellprice} = ""; $column_data{linetotallastcost} = ""; $column_data{linetotallistprice} = ""; print ""; map { print "\n$column_data{$_}" } @column_index; print qq| |; } print qq|
$form->{title}
$option
{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{partnumber} $ref->{description} $ref->{partsgroup} ".$form->format_amount(\%myconfig, $onhand, '', " ")."".$form->format_amount(\%myconfig, $ref->{sellprice}, 2, " ") . "".$form->format_amount(\%myconfig, $ref->{listprice}, 2, " ") . "".$form->format_amount(\%myconfig, $ref->{lastcost}, 2, " ") . "".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2, " ")."".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2, " ")."".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2, " ")."".$form->format_amount(\%myconfig, $ref->{rop}, '', " ")."".$form->format_amount(\%myconfig, $ref->{weight}, '', " ")."$ref->{unit} $ref->{bin} $ref->{priceupdate} {module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber} $ref->{invnumber} {module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber} $ref->{ordnumber} {image}>{image} height=32 border=0> {drawing}>$ref->{drawing} {microfiche}>$ref->{microfiche} 
 ".$form->format_amount(\%myconfig, $totalsellprice, 2, " ")."".$form->format_amount(\%myconfig, $totallastcost, 2, " ")."".$form->format_amount(\%myconfig, $totallistprice, 2, " ")."

|; print qq|
{script}> {searchitems}> {path}> {login}> {password}>
|; } sub parts_subtotal { map { $column_data{$_} = " " } @column_index; $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom}); $column_data{onhand} = "".$form->format_amount(\%myconfig, $subtotalonhand, '', " ").""; $column_data{sellprice} = "".$form->format_amount(\%myconfig, $subtotalsellprice, 2, " ").""; $column_data{listprice} = "".$form->format_amount(\%myconfig, $subtotallistprice, 2, " ").""; $column_data{lastcost} = "".$form->format_amount(\%myconfig, $subtotallastcost, 2, " ").""; $subtotalonhand = 0; $subtotalsellprice = 0; $subtotallistprice = 0; $subtotallastcost = 0; print ""; map { print "\n$column_data{$_}" } @column_index; print qq| |; } sub edit { IC->get_part(\%myconfig, \%$form); $form->{title} = $locale->text('Edit '.ucfirst $form->{item}); &link_part; &display_form; } sub link_part { IC->create_links("IC", \%myconfig, \%$form); # parts and assemblies have the same links $item = $form->{item}; if ($form->{item} eq 'assembly') { $item = 'part'; } # build the popup menus $form->{taxaccounts} = ""; foreach $key (keys %{ $form->{IC_links} }) { foreach $ref (@{ $form->{IC_links}{$key} }) { # if this is a tax field if ($key =~ /IC_tax/) { if ($key =~ /$item/) { $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"} .= "