1 #=====================================================================
2 # SQL-Ledger, Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
25 # Inventory Control module
27 #======================================================================
32 require "$form->{path}/io.pl";
41 %label = ( part => 'Part',
43 assembly => 'Assembly',
44 labor => 'Labor/Overhead' );
46 # $locale->text('Add Part')
47 # $locale->text('Add Service')
48 # $locale->text('Add Assembly')
49 # $locale->text('Add Labor/Overhead')
51 $label = "Add $label{$form->{item}}";
52 $form->{title} = $locale->text($label);
54 $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
56 $form->{orphaned} = 1;
58 if ($form->{previousform}) {
59 $form->{callback} = "";
70 $form->get_partsgroup(\%myconfig, { all => 0, searchitems => $form->{searchitems}});
72 IC->get_warehouses(\%myconfig, \%$form) unless $form->{searchitems} =~ /(service|labor)/;
74 if (@{ $form->{all_partsgroup} }) {
75 $partsgroup = qq|<option>\n|;
77 map { $partsgroup .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
80 <th align=right nowrap>|.$locale->text('Group').qq|</th>
81 <td><select name=partsgroup>$partsgroup</select></td>
86 <td><input name=l_listprice class=checkbox type=checkbox value=Y> |.$locale->text('List Price').qq|</td>
89 <td><input name=l_sellprice class=checkbox type=checkbox value=Y checked> |.$locale->text('Sell Price').qq|</td>
92 <td><input name=l_lastcost class=checkbox type=checkbox value=Y> |.$locale->text('Cost').qq|</td>
95 <td><input name=l_linetotal class=checkbox type=checkbox value=Y checked> |.$locale->text('Line Total').qq|</td>
98 <td><input name=l_curr class=checkbox type=checkbox value=Y> |.$locale->text('Currency').qq|</td>
103 <td colspan=4><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
104 <input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
109 <th align=right nowrap>|.$locale->text('Serial Number').qq|</th>
110 <td><input name=serialnumber size=20></td>
113 $l_serialnumber = qq|
114 <td><input name=l_serialnumber class=checkbox type=checkbox value=Y> |.$locale->text('Serial Number').qq|</td>
118 if ($form->{searchitems} =~ /(part|assembly)/) {
121 <input name=itemstatus class=radio type=radio value=onhand> |.$locale->text('On Hand').qq|
122 <input name=itemstatus class=radio type=radio value=short> |.$locale->text('Short').qq|
127 <th align=right nowrap>|.$locale->text('Make').qq|</th>
128 <td><input name=make size=20></td>
129 <th align=right nowrap>|.$locale->text('Model').qq|</th>
130 <td><input name=model size=20></td>
135 <td><input name=l_make class=checkbox type=checkbox value=Y> |.$locale->text('Make').qq|</td>
136 <td><input name=l_model class=checkbox type=checkbox value=Y> |.$locale->text('Model').qq|</td>
140 <td><input name=l_bin class=checkbox type=checkbox value=Y> |.$locale->text('Bin').qq|</td>|;
143 <td><input name=l_rop class=checkbox type=checkbox value=Y> |.$locale->text('ROP').qq|</td>|;
147 <td><input name=l_weight class=checkbox type=checkbox value=Y> |.$locale->text('Weight').qq|</td>|;
150 if (@{ $form->{all_warehouses} }) {
151 $selectwarehouse = "<option>\n";
153 map { $selectwarehouse .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_warehouses} });
156 <th align=right nowrap>|.$locale->text('Warehouse').qq|</th>
157 <td><select name=warehouse>$selectwarehouse</select></td>
161 <td><input name=l_warehouse class=checkbox type=checkbox value=Y> |.$locale->text('Warehouse').qq|</td>
167 <th align=right nowrap>|.$locale->text('Drawing').qq|</th>
168 <td><input name=drawing size=20></td>
169 <th align=right nowrap>|.$locale->text('Microfiche').qq|</th>
170 <td><input name=microfiche size=20></td>
176 <td><input name=l_image class=checkbox type=checkbox value=Y> |.$locale->text('Image').qq|</td>
177 <td><input name=l_drawing class=checkbox type=checkbox value=Y> |.$locale->text('Drawing').qq|</td>
178 <td><input name=l_microfiche class=checkbox type=checkbox value=Y> |.$locale->text('Microfiche').qq|</td>
185 if ($form->{searchitems} eq 'assembly') {
191 <input name=null class=radio type=radio value=1 checked> |.$locale->text('Top Level').qq|
192 <input name=bom class=checkbox type=checkbox value=1> |.$locale->text('Individual Items').qq|
206 <td><input name=sold class=checkbox type=checkbox value=1></td>
207 <td nowrap>|.$locale->text('Sales Invoices').qq|</td>
210 <td colspan=2><hr size=1 noshade></td>
213 <td><input name=ordered class=checkbox type=checkbox value=1></td>
214 <td nowrap>|.$locale->text('Sales Orders').qq|</td>
217 <td colspan=4><hr size=1 noshade></td>
220 <td><input name=quoted class=checkbox type=checkbox value=1></td>
221 <td nowrap>|.$locale->text('Quotations').qq|</td>
225 <td width=5%> </td>
230 <th>|.$locale->text('From').qq|</th>
231 <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
232 <th>|.$locale->text('To').qq|</th>
233 <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
236 <td colspan=4><input name=open class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|
237 <input name=closed class=checkbox type=checkbox> |.$locale->text('Closed').qq|</td>
247 } elsif ($form->{searchitems} eq 'component') {
251 $l_serialnumber = "";
254 } elsif ($form->{searchitems} eq 'labor') {
258 $l_serialnumber = "";
260 <td><input name=l_sellprice class=checkbox type=checkbox value=Y checked> |.$locale->text('Amount').qq|</td>
276 <td><input name=bought class=checkbox type=checkbox value=1></td>
277 <td nowrap>|.$locale->text('Vendor Invoices').qq|</td>
278 <td><input name=sold class=checkbox type=checkbox value=1></td>
279 <td nowrap>|.$locale->text('Sales Invoices').qq|</td>
282 <td colspan=4><hr size=1 noshade></td>
285 <td><input name=onorder class=checkbox type=checkbox value=1></td>
286 <td nowrap>|.$locale->text('Purchase Orders').qq|</td>
287 <td><input name=ordered class=checkbox type=checkbox value=1></td>
288 <td nowrap>|.$locale->text('Sales Orders').qq|</td>
291 <td colspan=4><hr size=1 noshade></td>
294 <td><input name=rfq class=checkbox type=checkbox value=1></td>
295 <td nowrap>|.$locale->text('RFQ').qq|</td>
296 <td><input name=quoted class=checkbox type=checkbox value=1></td>
297 <td nowrap>|.$locale->text('Quotations').qq|</td>
301 <td width=5%> </td>
306 <th>|.$locale->text('From').qq|</th>
307 <td><input name=transdatefrom size=11 title="$myconfig{dateformat}"></td>
308 <th>|.$locale->text('To').qq|</th>
309 <td><input name=transdateto size=11 title="$myconfig{dateformat}"></td>
312 <td colspan=4><input name=open class=checkbox type=checkbox value=1 checked> |.$locale->text('Open').qq|
313 <input name=closed class=checkbox type=checkbox> |.$locale->text('Closed').qq|</td>
324 %title = ( all => 'Items',
326 labor => 'Labor/Overhead',
327 service => 'Services',
328 assembly => 'Assemblies',
329 component => 'Components'
332 # $locale->text('Items')
333 # $locale->text('Parts')
334 # $locale->text('Labor/Overhead')
335 # $locale->text('Services')
336 # $locale->text('Assemblies')
337 # $locale->text('Components')
339 $form->{title} = $locale->text($title{$form->{searchitems}});
346 <form method=post action=$form->{script}>
348 <input type=hidden name=searchitems value=$form->{searchitems}>
349 <input type=hidden name=title value="$form->{title}">
352 <tr><th class=listtop>$form->{title}</th></tr>
358 <th align=right nowrap>|.$locale->text('Number').qq|</th>
359 <td><input name=partnumber size=20></td>
362 <th align=right nowrap>|.$locale->text('Description').qq|</th>
363 <td colspan=3><input name=description size=40></td>
378 <input name=itemstatus class=radio type=radio value=active checked> |.$locale->text('Active').qq|
380 <input name=itemstatus class=radio type=radio value=obsolete> |.$locale->text('Obsolete').qq|
381 <input name=itemstatus class=radio type=radio value=orphaned> |.$locale->text('Orphaned').qq|
392 <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
396 <td><input name=l_partnumber class=checkbox type=checkbox value=Y checked> |.$locale->text('Number').qq|</td>
397 <td><input name=l_description class=checkbox type=checkbox value=Y checked> |.$locale->text('Description').qq|</td>
399 <td><input name=l_unit class=checkbox type=checkbox value=Y checked> |.$locale->text('Unit of measure').qq|</td>
400 <td><input name=l_priceupdate class=checkbox type=checkbox value=Y> |.$locale->text('Updated').qq|</td>
401 <td><input name=l_partsgroup class=checkbox type=checkbox value=Y> |.$locale->text('Group').qq|</td>
421 <td><input name=l_subtotal class=checkbox type=checkbox value=Y> |.$locale->text('Subtotal').qq|</td>
429 <tr><td colspan=4><hr size=3 noshade></td></tr>
432 <input type=hidden name=nextsub value=generate_report>
434 <input type=hidden name=path value=$form->{path}>
435 <input type=hidden name=login value=$form->{login}>
436 <input type=hidden name=sessionid value=$form->{sessionid}>
439 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
450 sub generate_report {
452 # setup $form->{sort}
453 unless ($form->{sort}) {
454 if ($form->{description} && !($form->{partnumber})) {
455 $form->{sort} = "description";
457 $form->{sort} = "partnumber";
461 $warehouse = $form->escape($form->{warehouse},1);
462 $partsgroup = $form->escape($form->{partsgroup},1);
463 $title = $form->escape($form->{title},1);
465 $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&warehouse=$warehouse&partsgroup=$partsgroup&title=$title&method=$form->{method}";
468 # if we have a serialnumber limit search
469 if ($form->{serialnumber} || $form->{l_serialnumber}) {
470 $form->{l_serialnumber} = "Y";
471 unless ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered}) {
472 if ($form->{searchitems} eq 'assembly') {
473 $form->{sold} = $form->{ordered} = 1;
475 $form->{bought} = $form->{sold} = $form->{onorder} = $form->{ordered} = 1;
481 if ($form->{itemstatus} eq 'active') {
482 $option .= $locale->text('Active')." : ";
484 if ($form->{itemstatus} eq 'obsolete') {
485 $form->{onhand} = $form->{short} = 0;
486 $form->{warehouse} = "";
487 $form->{l_warehouse} = 0;
489 $option .= $locale->text('Obsolete')." : ";
491 if ($form->{itemstatus} eq 'orphaned') {
492 $form->{onhand} = $form->{short} = 0;
493 $form->{bought} = $form->{sold} = 0;
494 $form->{onorder} = $form->{ordered} = 0;
495 $form->{rfq} = $form->{quoted} = 0;
497 $form->{warehouse} = "";
498 $form->{l_warehouse} = 0;
500 $form->{transdatefrom} = $form->{transdateto} = "";
502 $option .= $locale->text('Orphaned')." : ";
504 if ($form->{itemstatus} eq 'onhand') {
505 $option .= $locale->text('On Hand')." : ";
506 $form->{l_onhand} = "Y";
508 if ($form->{itemstatus} eq 'short') {
509 $option .= $locale->text('Short')." : ";
510 $form->{l_onhand} = "Y";
511 $form->{l_rop} = "Y" unless $form->{searchitems} eq 'labor';
513 $form->{warehouse} = "";
514 $form->{l_warehouse} = 0;
516 if ($form->{onorder}) {
517 $form->{l_ordnumber} = "Y";
518 $callback .= "&onorder=$form->{onorder}";
519 $option .= $locale->text('Purchase Order')." : ";
521 if ($form->{ordered}) {
522 $form->{l_ordnumber} = "Y";
523 $callback .= "&ordered=$form->{ordered}";
524 $option .= $locale->text('Sales Order')." : ";
527 $form->{l_quonumber} = "Y";
528 $callback .= "&rfq=$form->{rfq}";
529 $option .= $locale->text('RFQ')." : ";
531 if ($form->{quoted}) {
532 $form->{l_quonumber} = "Y";
533 $callback .= ""ed=$form->{quoted}";
534 $option .= $locale->text('Quotation')." : ";
536 if ($form->{bought}) {
537 $form->{l_invnumber} = "Y";
538 $callback .= "&bought=$form->{bought}";
539 $option .= $locale->text('Vendor Invoice')." : ";
542 $form->{l_invnumber} = "Y";
543 $callback .= "&sold=$form->{sold}";
544 $option .= $locale->text('Sales Invoice')." : ";
546 if ($form->{sold} || $form->{bought}) {
547 $label = ucfirst $form->{method};
548 $option .= $locale->text($label) ." : ";
551 if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered} || $form->{rfq} || $form->{quoted}) {
553 # warehouse stuff is meaningless
554 $form->{warehouse} = "";
555 $form->{l_warehouse} = 0;
557 $form->{l_lastcost} = "";
558 $form->{l_name} = "Y";
559 $form->{l_employee} = "Y";
563 $callback .= "&open=$form->{open}";
564 $option .= $locale->text('Open');
566 if ($form->{closed}) {
567 $callback .= "&closed=$form->{closed}";
569 $option .= " : ".$locale->text('Closed');
571 $option .= $locale->text('Closed');
575 if ($form->{transdatefrom}) {
576 $callback .= "&transdatefrom=$form->{transdatefrom}";
577 $option .= "\n<br>".$locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
579 if ($form->{transdateto}) {
580 $callback .= "&transdateto=$form->{transdateto}";
581 $option .= "\n<br>".$locale->text('To')." ".$locale->date(\%myconfig, $form->{transdateto}, 1);
585 if ($form->{warehouse}) {
586 ($warehouse) = split /--/, $form->{warehouse};
587 $option .= "<br>".$locale->text('Warehouse')." : $warehouse";
588 $form->{l_warehouse} = 0;
593 if ($form->{partnumber}) {
594 $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
595 $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|;
597 if ($form->{partsgroup}) {
598 ($partsgroup) = split /--/, $form->{partsgroup};
599 $option .= $locale->text('Group').qq| : $partsgroup<br>|;
601 if ($form->{serialnumber}) {
602 $callback .= "&serialnumber=".$form->escape($form->{serialnumber},1);
603 $option .= $locale->text('Serial Number').qq| : $form->{serialnumber}<br>|;
605 if ($form->{description}) {
606 $callback .= "&description=".$form->escape($form->{description},1);
607 $description = $form->{description};
608 $description =~ s/
\r/<br>/g;
609 $option .= $locale->text('Description').qq| : $form->{description}<br>|;
612 $callback .= "&make=".$form->escape($form->{make},1);
613 $option .= $locale->text('Make').qq| : $form->{make}<br>|;
615 if ($form->{model}) {
616 $callback .= "&model=".$form->escape($form->{model},1);
617 $option .= $locale->text('Model').qq| : $form->{model}<br>|;
619 if ($form->{drawing}) {
620 $callback .= "&drawing=".$form->escape($form->{drawing},1);
621 $option .= $locale->text('Drawing').qq| : $form->{drawing}<br>|;
623 if ($form->{microfiche}) {
624 $callback .= "µfiche=".$form->escape($form->{microfiche},1);
625 $option .= $locale->text('Microfiche').qq| : $form->{microfiche}<br>|;
629 @columns = $form->sort_columns(qw(partnumber description assemblypartnumber partsgroup make model bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost curr priceupdate weight image drawing microfiche invnumber ordnumber quonumber name employee serialnumber warehouse));
631 if ($form->{l_linetotal}) {
632 $form->{l_onhand} = "Y";
633 $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
634 $form->{l_linetotallastcost} = "Y" if $form->{l_lastcost};
635 $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
638 if ($form->{searchitems} eq 'service') {
639 # remove bin, weight and rop from list
640 map { $form->{"l_$_"} = "" } qw(bin weight rop);
642 $form->{l_onhand} = "";
643 # qty is irrelevant unless bought or sold
644 if ($form->{bought} || $form->{sold} || $form->{onorder} ||
645 $form->{ordered} || $form->{rfq} || $form->{quoted}) {
646 $form->{l_onhand} = "Y";
648 $form->{l_linetotalsellprice} = "";
649 $form->{l_linetotallastcost} = "";
654 foreach $item (@columns) {
655 if ($form->{"l_$item"} eq "Y") {
656 push @column_index, $item;
658 # add column to callback
659 $callback .= "&l_$item=Y";
663 if ($form->{l_subtotal} eq 'Y') {
664 $callback .= "&l_subtotal=Y";
668 IC->all_parts(\%myconfig, \%$form);
670 $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
676 $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/;
679 if ($form->{searchitems} eq 'assembly' && $form->{l_partnumber}) {
680 # replace partnumber with partnumber_
682 foreach $item (@column_index) {
684 last if $item eq 'partnumber';
687 splice @column_index, $ndx, 0, map { "partnumber_$_" } (1 .. $form->{pncol});
688 $colspan = $form->{pncol} + 1;
691 if ($form->{searchitems} eq 'component') {
692 if ($form->{l_partnumber}) {
693 # splice it in after the partnumber
695 foreach $item (@column_index) {
697 last if $item eq 'partnumber';
700 @a = splice @column_index, 0, $ndx;
701 unshift @column_index, "assemblypartnumber";
702 unshift @column_index, @a;
706 $column_header{partnumber} = qq|<th nowrap colspan=$colspan><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</a></th>|;
707 $column_header{description} = qq|<th nowrap><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</a></th>|;
708 $column_header{partsgroup} = qq|<th nowrap><a class=listheading href=$href&sort=partsgroup>|.$locale->text('Group').qq|</a></th>|;
709 $column_header{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</a></th>|;
710 $column_header{priceupdate} = qq|<th nowrap><a class=listheading href=$href&sort=priceupdate>|.$locale->text('Updated').qq|</a></th>|;
711 $column_header{onhand} = qq|<th class=listheading nowrap>|.$locale->text('Qty').qq|</th>|;
712 $column_header{unit} = qq|<th class=listheading nowrap>|.$locale->text('Unit').qq|</th>|;
713 $column_header{listprice} = qq|<th class=listheading nowrap>|.$locale->text('List Price').qq|</th>|;
714 $column_header{lastcost} = qq|<th class=listheading nowrap>|.$locale->text('Cost').qq|</th>|;
715 $column_header{rop} = qq|<th class=listheading nowrap>|.$locale->text('ROP').qq|</th>|;
716 $column_header{weight} = qq|<th class=listheading nowrap>|.$locale->text('Weight').qq|</th>|;
718 $column_header{make} = qq|<th nowrap><a class=listheading href=$href&sort=make>|.$locale->text('Make').qq|</a></th>|;
719 $column_header{model} = qq|<th nowrap><a class=listheading href=$href&sort=model>|.$locale->text('Model').qq|</a></th>|;
721 $column_header{invnumber} = qq|<th nowrap><a class=listheading href=$href&sort=invnumber>|.$locale->text('Invoice Number').qq|</a></th>|;
722 $column_header{ordnumber} = qq|<th nowrap><a class=listheading href=$href&sort=ordnumber>|.$locale->text('Order Number').qq|</a></th>|;
723 $column_header{quonumber} = qq|<th nowrap><a class=listheading href=$href&sort=quonumber>|.$locale->text('Quotation').qq|</a></th>|;
725 $column_header{name} = qq|<th nowrap><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
727 $column_header{employee} = qq|<th nowrap><a class=listheading href=$href&sort=employee>|.$locale->text('Employee').qq|</a></th>|;
729 $column_header{sellprice} = qq|<th class=listheading nowrap>|;
730 $column_header{sellprice} .= ($form->{searchitems} ne 'labor') ? $locale->text('Sell Price') : $locale->text('Amount');
731 $column_header{sellprice} .= qq|</th>|;
733 $column_header{linetotalsellprice} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
734 $column_header{linetotallastcost} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
735 $column_header{linetotallistprice} = qq|<th class=listheading nowrap>|.$locale->text('Extended').qq|</th>|;
737 $column_header{curr} = qq|<th class=listheading nowrap>|.$locale->text('Curr').qq|</th>|;
739 $column_header{image} = qq|<th class=listheading nowrap>|.$locale->text('Image').qq|</a></th>|;
740 $column_header{drawing} = qq|<th nowrap><a class=listheading href=$href&sort=drawing>|.$locale->text('Drawing').qq|</a></th>|;
741 $column_header{microfiche} = qq|<th nowrap><a class=listheading href=$href&sort=microfiche>|.$locale->text('Microfiche').qq|</a></th>|;
743 $column_header{serialnumber} = qq|<th nowrap><a class=listheading href=$href&sort=serialnumber>|.$locale->text('Serial Number').qq|</a></th>|;
745 $column_header{assemblypartnumber} = qq|<th nowrap><a class=listheading href=$href&sort=assemblypartnumber>|.$locale->text('Assembly').qq|</a></th>|;
747 $column_header{warehouse} = qq|<th nowrap class=listheading>|.$locale->text('Warehouse').qq|</th>|;
753 if ($form->{searchitems} eq 'part') {
754 $button{'Goods & Services--Add Part'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Part').qq|"> |;
755 $button{'Goods & Services--Add Part'}{order} = $i++;
757 if ($form->{searchitems} eq 'service') {
758 $button{'Goods & Services--Add Service'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Service').qq|"> |;
759 $button{'Goods & Services--Add Service'}{order} = $i++;
761 if ($form->{searchitems} eq 'assembly') {
762 $button{'Goods & Services--Add Assembly'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Assembly').qq|"> |;
763 $button{'Goods & Services--Add Assembly'}{order} = $i++;
765 if ($form->{searchitems} eq 'labor') {
766 $button{'Goods & Services--Add Labor/Overhead'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Add Labor/Overhead').qq|"> |;
767 $button{'Goods & Services--Add Labor/Overhead'}{order} = $i++;
770 foreach $item (split /;/, $myconfig{acs}) {
771 delete $button{$item};
779 <th class=listtop>$form->{title}</th>
783 <tr><td>$option</td></tr>
788 <tr class=listheading>
791 map { print "\n$column_header{$_}" } @column_index;
798 # add order to callback
799 $form->{callback} = $callback .= "&sort=$form->{sort}";
801 # escape callback for href
802 $callback = $form->escape($callback);
804 if (@{ $form->{parts} }) {
805 $sameitem = $form->{parts}->[0]->{$form->{sort}};
809 foreach $ref (@{ $form->{parts} }) {
811 if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
812 if ($sameitem ne $ref->{$form->{sort}}) {
814 $sameitem = $ref->{$form->{sort}};
818 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
819 $ref->{discount} *= 1;
820 $ref->{sellprice} = $ref->{sellprice} * (1 - $ref->{discount});
821 if ($form->{l_curr}) {
822 if ($ref->{module} ne 'oe') {
823 map { $ref->{$_} = $form->round_amount($ref->{$_} / $ref->{exchangerate}, 2) } qw(sellprice listprice lastcost);
826 if ($ref->{module} eq 'oe') {
827 map { $ref->{$_} = $form->round_amount($ref->{$_} * $ref->{exchangerate}, 2) } qw(sellprice listprice lastcost);
831 # use this for assemblies
832 $onhand = $ref->{onhand};
834 $ref->{description} =~ s/
\r/<br>/g;
836 map { $column_data{"partnumber_$_"} = "<td> </td>" } (1 .. $form->{pncol});
838 $column_data{partnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber} </a></td>";
840 $column_data{assemblypartnumber} = "<td><a href=$form->{script}?action=edit&id=$ref->{assembly_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{assemblypartnumber} </a></td>";
842 if ($ref->{assemblyitem}) {
843 $onhand = 0 if ($form->{sold});
845 $column_data{partnumber} = "<td> </td>";
847 $column_data{"partnumber_$ref->{stagger}"} = "<td><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber} </a></td>";
851 map { $column_data{$_} = "<td>$ref->{$_} </td>" } qw(description partsgroup employee curr);
853 $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, '', " ")."</td>";
855 map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, " ") . "</td>" } qw(sellprice listprice lastcost);
857 $column_data{linetotalsellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2, " ")."</td>";
858 $column_data{linetotallastcost} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2, " ")."</td>";
859 $column_data{linetotallistprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2, " ")."</td>";
861 if ($ref->{assemblyitem} && $ref->{stagger} > 1) {
862 map { $column_data{$_} = "<td> </td>" } qw(linetotalsellprice linetotallastcost linetotallistprice);
865 if (!$ref->{assemblyitem}) {
866 $totalsellprice += $onhand * $ref->{sellprice};
867 $totallastcost += $onhand * $ref->{lastcost};
868 $totallistprice += $onhand * $ref->{listprice};
870 $subtotalonhand += $onhand;
871 $subtotalsellprice += $onhand * $ref->{sellprice};
872 $subtotallastcost += $onhand * $ref->{lastcost};
873 $subtotallistprice += $onhand * $ref->{listprice};
876 $column_data{rop} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{rop}, '', " ")."</td>";
877 $column_data{weight} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{weight}, '', " ")."</td>";
878 $column_data{unit} = "<td>$ref->{unit} </td>";
879 $column_data{bin} = "<td>$ref->{bin} </td>";
880 $column_data{priceupdate} = "<td>$ref->{priceupdate} </td>";
882 $ref->{module} = 'ps' if $ref->{till};
883 $column_data{invnumber} = ($ref->{module} ne 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{invnumber} </a></td>" : "<td>$ref->{invnumber} </td>";
884 $column_data{ordnumber} = ($ref->{module} eq 'oe') ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{ordnumber} </a></td>" : "<td>$ref->{ordnumber} </td>";
885 $column_data{quonumber} = ($ref->{module} eq 'oe' && !$ref->{ordnumber}) ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{quonumber} </a></td>" : "<td>$ref->{quonumber} </td>";
887 $column_data{name} = "<td>$ref->{name} </td>";
889 $column_data{image} = ($ref->{image}) ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>" : "<td> </td>";
890 $column_data{drawing} = ($ref->{drawing}) ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>" : "<td> </td>";
891 $column_data{microfiche} = ($ref->{microfiche}) ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>" : "<td> </td>";
893 $column_data{make} = "<td>$ref->{make} </td>";
894 $column_data{model} = "<td>$ref->{model} </td>";
896 $column_data{serialnumber} = "<td>$ref->{serialnumber} </td>";
897 $column_data{warehouse} = "<td>$ref->{warehouse} </td>";
900 print "<tr class=listrow$i>";
902 map { print "\n$column_data{$_}" } @column_index;
911 if ($form->{l_subtotal} eq 'Y') {
915 if ($form->{"l_linetotal"}) {
916 map { $column_data{$_} = "<td> </td>" } @column_index;
917 $column_data{linetotalsellprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalsellprice, 2, " ")."</th>";
918 $column_data{linetotallastcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallastcost, 2, " ")."</th>";
919 $column_data{linetotallistprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallistprice, 2, " ")."</th>";
921 print "<tr class=listtotal>";
923 map { print "\n$column_data{$_}" } @column_index;
933 <tr><td><hr size=3 noshade></td></tr>
942 <form method=post action=$form->{script}>
944 <input name=callback type=hidden value="$form->{callback}">
946 <input type=hidden name=item value=$form->{searchitems}>
948 <input type=hidden name=path value=$form->{path}>
949 <input type=hidden name=login value=$form->{login}>
950 <input type=hidden name=sessionid value=$form->{sessionid}>
953 foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
957 if ($form->{menubar}) {
958 require "$form->{path}/menu.pl";
975 map { $column_data{$_} = "<td> </td>" } @column_index;
976 $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
978 $column_data{onhand} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalonhand, '', " ")."</th>";
980 $column_data{linetotalsellprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalsellprice, 2, " ")."</th>";
981 $column_data{linetotallistprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallistprice, 2, " ")."</th>";
982 $column_data{linetotallastcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallastcost, 2, " ")."</th>";
985 $subtotalsellprice = 0;
986 $subtotallistprice = 0;
987 $subtotallastcost = 0;
989 print "<tr class=listsubtotal>";
991 map { print "\n$column_data{$_}" } @column_index;
1003 %label = ( part => 'Part',
1004 service => 'Service',
1005 assembly => 'Assembly',
1006 labor => 'Labor/Overhead' );
1008 # $locale->text('Edit Part')
1009 # $locale->text('Edit Service')
1010 # $locale->text('Edit Assembly')
1011 # $locale->text('Edit Labor/Overhead')
1013 IC->get_part(\%myconfig, \%$form);
1015 $label = "Edit $label{$form->{item}}";
1016 $form->{title} = $locale->text($label);
1020 $form->{previousform} = $form->escape($form->{previousform}, 1) if $form->{previousform};
1030 IC->create_links("IC", \%myconfig, \%$form);
1033 map { $form->{selectcurrency} .= "<option>$_\n" } split /:/, $form->{currencies};
1035 # parts and assemblies have the same links
1036 $item = $form->{item};
1039 if ($form->{item} eq 'part') {
1040 $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Part/;
1042 if ($form->{item} eq 'service') {
1043 $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Service/;
1045 if ($form->{item} eq 'assembly') {
1047 $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Assembly/;
1049 if ($form->{item} eq 'labor') {
1051 $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Labor\/Overhead/;
1054 # build the popup menus
1055 $form->{taxaccounts} = "";
1056 foreach $key (keys %{ $form->{IC_links} }) {
1057 foreach $ref (@{ $form->{IC_links}{$key} }) {
1058 # if this is a tax field
1059 if ($key =~ /IC_tax/) {
1060 if ($key =~ /$item/) {
1061 $form->{taxaccounts} .= "$ref->{accno} ";
1062 $form->{"IC_tax_$ref->{accno}_description"} = "$ref->{accno}--$ref->{description}";
1065 if ($form->{amount}{$ref->{accno}}) {
1066 $form->{"IC_tax_$ref->{accno}"} = "checked";
1069 $form->{"IC_tax_$ref->{accno}"} = "checked";
1074 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
1075 if ($form->{amount}{$key} eq $ref->{accno}) {
1076 $form->{$key} = "$ref->{accno}--$ref->{description}";
1082 chop $form->{taxaccounts};
1084 if ($form->{item} !~ /service/) {
1085 $form->{selectIC_income} = $form->{selectIC_sale};
1086 $form->{selectIC_expense} = $form->{selectIC_cogs};
1087 $form->{IC_income} = $form->{IC_sale};
1088 $form->{IC_expense} = $form->{IC_cogs};
1091 delete $form->{IC_links};
1092 delete $form->{amount};
1094 $form->get_partsgroup(\%myconfig, {all => 1});
1095 $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1097 if (@{ $form->{all_partsgroup} }) {
1098 $form->{selectpartsgroup} = qq|<option>\n|;
1100 map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
1103 if ($form->{item} eq 'assembly') {
1105 foreach $i (1 .. $form->{assembly_rows}) {
1106 if ($form->{"partsgroup_id_$i"}) {
1107 $form->{"partsgroup_$i"} = qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1111 $form->get_partsgroup(\%myconfig);
1113 if (@{ $form->{all_partsgroup} }) {
1114 $form->{selectassemblypartsgroup} = qq|<option>\n|;
1116 map { $form->{selectassemblypartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
1120 # setup make and models
1122 foreach $ref (@{ $form->{makemodels} }) {
1123 map { $form->{"${_}_$i"} = $ref->{$_} } qw(make model);
1126 $form->{makemodel_rows} = $i - 1;
1130 if (@{ $form->{all_vendor} }) {
1131 $form->{selectvendor} = "<option>\n";
1132 map { $form->{selectvendor} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_vendor} };
1137 foreach $ref (@{ $form->{vendormatrix} }) {
1138 $form->{"vendor_$i"} = qq|$ref->{name}--$ref->{id}|;
1140 map { $form->{"${_}_$i"} = $ref->{$_} } qw(partnumber lastcost leadtime vendorcurr);
1143 $form->{vendor_rows} = $i - 1;
1145 # setup customers and groups
1146 if (@{ $form->{all_customer} }) {
1147 $form->{selectcustomer} = "<option>\n";
1148 map { $form->{selectcustomer} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_customer} };
1151 if (@{ $form->{all_pricegroup} }) {
1152 $form->{selectpricegroup} = "<option>\n";
1153 map { $form->{selectpricegroup} .= qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n| } @{ $form->{all_pricegroup} };
1158 foreach $ref (@{ $form->{customermatrix} }) {
1160 $form->{"customer_$i"} = "$ref->{name}--$ref->{cid}" if $ref->{cid};
1161 $form->{"pricegroup_$i"} = "$ref->{pricegroup}--$ref->{gid}" if $ref->{gid};
1163 map { $form->{"${_}_$i"} = $ref->{$_} } qw(validfrom validto pricebreak customerprice customercurr);
1168 $form->{customer_rows} = $i - 1;
1176 ($dec) = ($form->{sellprice} =~ /\.(\d+)/);
1178 my $decimalplaces = ($dec > 2) ? $dec : 2;
1180 if ($form->{lastcost} > 0) {
1181 $markup = $form->round_amount((($form->{sellprice}/$form->{lastcost} - 1) * 100), 1);
1182 $form->{markup} = $form->format_amount(\%myconfig, $markup, 1);
1185 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces)} qw(listprice sellprice);
1187 ($dec) = ($form->{lastcost} =~ /\.(\d+)/);
1189 my $decimalplaces = ($dec > 2) ? $dec : 2;
1191 $form->{lastcost} = $form->format_amount(\%myconfig, $form->{lastcost}, $decimalplaces);
1193 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) } qw(weight rop stock);
1195 map { $form->{$_} = $form->quote($form->{$_}) } qw(partnumber description unit notes);
1197 if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
1201 $notes = qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
1203 if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
1204 $description = qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
1206 $description = qq|<input name=description size=40 value="$form->{description}">|;
1209 foreach $item (split / /, $form->{taxaccounts}) {
1210 $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : "";
1215 foreach $item (qw(IC IC_income IC_expense)) {
1216 if ($form->{$item}) {
1217 if ($form->{orphaned}) {
1218 $form->{"select$item"} =~ s/ selected//;
1219 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
1221 $form->{"select$item"} = qq|<option selected>$form->{$item}|;
1226 if ($form->{selectpartsgroup}) {
1227 $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
1229 $partsgroup = qq|<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">|;
1231 $form->{selectpartsgroup} =~ s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
1233 $partsgroup .= qq|<select name=partsgroup>$form->{selectpartsgroup}</select>|;
1234 $group = $locale->text('Group');
1238 foreach $item (split / /, $form->{taxaccounts}) {
1240 <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}> <b>$form->{"IC_tax_${item}_description"}</b>
1241 <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
1245 $form->{obsolete} = "checked" if $form->{obsolete};
1249 <th align="right" nowrap="true">|.$locale->text('List Price').qq|</th>
1250 <td><input name=listprice size=11 value=$form->{listprice}></td>
1253 <th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th>
1254 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
1260 <th align="right" nowrap="true">|.$locale->text('Cost').qq|</th>
1261 <td><input name=lastcost size=11 value=$form->{lastcost}></td>
1264 <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th>
1265 <td><input name=markup size=5 value=$form->{markup}></td>
1266 <input type=hidden name=oldmarkup value=$markup>
1270 if ($form->{item} eq "part") {
1274 <th align=right>|.$locale->text('Inventory').qq|</th>
1275 <td><select name=IC>$form->{selectIC}</select></td>
1276 <input name=selectIC type=hidden value="$form->{selectIC}">
1279 <th align=right>|.$locale->text('Income').qq|</th>
1280 <td><select name=IC_income>$form->{selectIC_income}</select></td>
1281 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
1284 <th align=right>|.$locale->text('COGS').qq|</th>
1285 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
1286 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
1291 $linkaccounts .= qq|
1293 <th align=right>|.$locale->text('Tax').qq|</th>
1301 <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
1306 <input name=weight size=10 value=$form->{weight}>
1311 <input type=hidden name=weightunit value=$form->{weightunit}>
1322 if ($form->{item} eq "assembly") {
1326 <th align="right" nowrap="true">|.$locale->text('Cost').qq|</th>
1327 <td><input type=hidden name=lastcost value=$form->{lastcost}>$form->{lastcost}</td>
1330 <th align="right" nowrap="true">|.$locale->text('Markup').qq| %</th>
1331 <td><input name=markup size=5 value=$form->{markup}></td>
1332 <input type=hidden name=oldmarkup value=$markup>
1339 <th align=right>|.$locale->text('Inventory').qq|</th>
1340 <td><select name=IC>$form->{selectIC}</select></td>
1341 <input name=selectIC type=hidden value="$form->{selectIC}">
1345 <th align=right>|.$locale->text('Income').qq|</th>
1346 <td><select name=IC_income>$form->{selectIC_income}</select></td>
1347 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
1352 $linkaccounts .= qq|
1354 <th align=right>|.$locale->text('Tax').qq|</th>
1362 <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
1367 $form->{weight}
1368 <input type=hidden name=weight value=$form->{weight}>
1373 <input type=hidden name=weightunit value=$form->{weightunit}>
1384 if ($form->{item} eq "service") {
1388 <th align=right>|.$locale->text('Income').qq|</th>
1389 <td><select name=IC_income>$form->{selectIC_income}</select></td>
1390 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
1393 <th align=right>|.$locale->text('Expense').qq|</th>
1394 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
1395 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
1400 $linkaccounts .= qq|
1402 <th align=right>|.$locale->text('Tax').qq|</th>
1410 if ($form->{item} eq "labor") {
1414 <th align="right" nowrap="true">|.$locale->text('Amount').qq|</th>
1415 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
1421 <th align=right>|.$locale->text('Labor/Overhead').qq|</th>
1422 <td><select name=IC>$form->{selectIC}</select></td>
1423 <input name=selectIC type=hidden value="$form->{selectIC}">
1426 <th align=right>|.$locale->text('Expense').qq|</th>
1427 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
1428 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
1435 if ($form->{item} =~ /(part|assembly)/) {
1436 $n = ($form->{onhand} > 0) ? "1" : "0";
1439 <th align="right" nowrap>|.$locale->text('On Hand').qq|</th>
1440 <th align=left nowrap class="plus$n"> |.$form->format_amount(\%myconfig, $form->{onhand}).qq|</th>
1444 if ($form->{item} eq 'assembly') {
1447 <th align="right" nowrap>|.$locale->text('Stock').qq|</th>
1448 <td><input name=stock size=10 value=$form->{stock}></td>
1455 <th align="right" nowrap="true">|.$locale->text('ROP').qq|</th>
1456 <td><input name=rop size=10 value=$form->{rop}></td>
1462 <th align="right" nowrap="true">|.$locale->text('Bin').qq|</th>
1463 <td><input name=bin size=10 value=$form->{bin}></td>
1472 <th align=right nowrap>|.$locale->text('Image').qq|</th>
1473 <td><input name=image size=40 value="$form->{image}"></td>
1474 <th align=right nowrap>|.$locale->text('Microfiche').qq|</th>
1475 <td><input name=microfiche size=20 value="$form->{microfiche}"></td>
1478 <th align=right nowrap>|.$locale->text('Drawing').qq|</th>
1479 <td><input name=drawing size=40 value="$form->{drawing}"></td>
1491 <th align="right" nowrap="true">|.$locale->text('Obsolete').qq|</th>
1492 <td><input name=obsolete type=checkbox class=checkbox value=1 $form->{obsolete}></td>
1498 # type=submit $locale->text('Edit Part')
1499 # type=submit $locale->text('Edit Service')
1500 # type=submit $locale->text('Edit Assembly')
1508 <form method=post action="$form->{script}#end">
1510 <input type=hidden name=id value=$form->{id}>
1511 <input type=hidden name=item value=$form->{item}>
1512 <input type=hidden name=title value="$form->{title}">
1513 <input type=hidden name=makemodel value="$form->{makemodel}">
1514 <input type=hidden name=alternate value="$form->{alternate}">
1515 <input type=hidden name=onhand value=$form->{onhand}>
1516 <input type=hidden name=orphaned value=$form->{orphaned}>
1517 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
1518 <input type=hidden name=rowcount value=$form->{rowcount}>
1519 <input type=hidden name=baseassembly value=$form->{baseassembly}>
1521 <table width="100%">
1523 <th class=listtop>$form->{title}</th>
1525 <tr height="5"></tr>
1528 <table width="100%">
1530 <th align=left>|.$locale->text('Number').qq|</th>
1531 <th align=left>|.$locale->text('Description').qq|</th>
1532 <th align=left>$group</th>
1535 <td><input name=partnumber value="$form->{partnumber}" size=20></td>
1536 <td>$description</td>
1537 <td>$partsgroup</td>
1544 <table width="100%" height="100%">
1547 <table width="100%" height="100%">
1548 <tr class="listheading">
1549 <th class="listheading" align="center" colspan=2>|.$locale->text('Link Accounts').qq|</th>
1553 <th align="left">|.$locale->text('Notes').qq|</th>
1563 <table width="100%">
1565 <th align="right" nowrap="true">|.$locale->text('Updated').qq|</th>
1566 <td><input name=priceupdate size=11 title="$myconfig{dateformat}" value=$form->{priceupdate}></td>
1571 <th align="right" nowrap="true">|.$locale->text('Unit').qq|</th>
1572 <td><input name=unit size=5 value="$form->{unit}"></td>
1593 <td><hr size=3 noshade></td>
1597 <input type=hidden name=customer_rows value=$form->{customer_rows}>
1601 if ($form->{item} =~ /(part|assembly)/) {
1603 <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
1607 if ($form->{item} =~ /(part|service)/) {
1609 <input type=hidden name=vendor_rows value=$form->{vendor_rows}>
1614 if (! $form->{readonly}) {
1616 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
1617 <input class=submit type=submit name=action value="|.$locale->text('Save').qq|">|;
1621 if (!$form->{isassemblyitem}) {
1623 <input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">|;
1626 if ($form->{orphaned}) {
1628 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">|;
1633 if ($form->{menubar}) {
1634 require "$form->{path}/menu.pl";
1638 &assembly_row(++$form->{assembly_rows}) if $form->{item} eq 'assembly';
1642 <input type=hidden name=path value=$form->{path}>
1643 <input type=hidden name=login value=$form->{login}>
1644 <input type=hidden name=sessionid value=$form->{sessionid}>
1645 <input type=hidden name=callback value="$form->{callback}">
1646 <input type=hidden name=previousform value="$form->{previousform}">
1647 <input type=hidden name=isassemblyitem value=$form->{isassemblyitem}>
1664 map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(make model);
1671 <th class="listheading">|.$locale->text('Make').qq|</th>
1672 <th class="listheading">|.$locale->text('Model').qq|</th>
1676 for $i (1 .. $numrows) {
1679 <td><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
1680 <td><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
1697 $form->{selectvendor} = $form->unescape($form->{selectvendor});
1699 <input type=hidden name=selectvendor value="|.$form->escape($form->{selectvendor},1).qq|">
1705 <th class="listheading">|.$locale->text('Vendor').qq|</th>
1706 <th class="listheading">|.$locale->text('Number').qq|</th>
1707 <th class="listheading">|.$locale->text('Cost').qq|</th>
1708 <th class="listheading">|.$locale->text('Curr').qq|</th>
1709 <th class="listheading">|.$locale->text('Leadtime').qq|</th>
1713 for $i (1 .. $numrows) {
1715 $form->{selectcurrency} =~ s/ selected//;
1717 if ($i == $numrows) {
1720 <td><input name="vendor_$i" size=35 value="$form->{"vendor_$i"}"></td>
1723 if ($form->{selectvendor}) {
1725 <td width=99%><select name="vendor_$i">$form->{selectvendor}</select></td>
1731 $form->{selectcurrency} =~ s/option>$form->{"vendorcurr_$i"}/option selected>$form->{"vendorcurr_$i"}/;
1733 ($vendor) = split /--/, $form->{"vendor_$i"};
1736 <input type=hidden name="vendor_$i" value="$form->{"vendor_$i"}">
1745 <td><input name="partnumber_$i" size=20 value="$form->{"partnumber_$i"}"></td>
1746 <td><input name="lastcost_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2).qq|></td>
1747 <td><select name="vendorcurr_$i">$form->{selectcurrency}</select></td>
1748 <td nowrap><input name="leadtime_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"leadtime_$i"}).qq|> <b>|.$locale->text('days').qq|</b></td>
1766 if ($form->{selectpricegroup}) {
1768 <th class="listheading">|.$locale->text('Pricegroup').qq|
1773 $form->{selectcustomer} = $form->unescape($form->{selectcustomer});
1774 $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
1777 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
1778 <input type=hidden name=selectcustomer value="|.$form->escape($form->{selectcustomer},1).qq|">
1779 <input type=hidden name=selectpricegroup value="|.$form->escape($form->{selectpricegroup},1).qq|">
1785 <th class="listheading">|.$locale->text('Customer').qq|</th>
1787 <th class="listheading">|.$locale->text('Break').qq|</th>
1788 <th class="listheading">|.$locale->text('Sell Price').qq|</th>
1789 <th class="listheading">|.$locale->text('Curr').qq|</th>
1790 <th class="listheading">|.$locale->text('From').qq|</th>
1791 <th class="listheading">|.$locale->text('To').qq|</th>
1795 for $i (1 .. $numrows) {
1797 $form->{selectcurrency} =~ s/ selected//;
1798 $form->{selectcurrency} =~ s/option>$form->{"customercurr_$i"}/option selected>$form->{"customercurr_$i"}/;
1800 if ($i == $numrows) {
1802 <td><input name="customer_$i" size=35 value="$form->{"customer_$i"}"></td>
1805 if ($form->{selectcustomer}) {
1807 <td><select name="customer_$i">$form->{selectcustomer}</select></td>
1811 if ($form->{selectpricegroup}) {
1813 <td><select name="pricegroup_$i">$form->{selectpricegroup}</select></td>
1818 ($customer) = split /--/, $form->{"customer_$i"};
1821 <input type=hidden name="customer_$i" value="$form->{"customer_$i"}">
1824 if ($form->{selectpricegroup}) {
1825 ($pricegroup) = split /--/, $form->{"pricegroup_$i"};
1827 <td>$pricegroup</td>
1828 <input type=hidden name="pricegroup_$i" value="$form->{"pricegroup_$i"}">
1839 <td><input name="pricebreak_$i" size=5 value=|.$form->format_amount(\%myconfig, $form->{"pricebreak_$i"}).qq|></td>
1840 <td><input name="customerprice_$i" size=10 value=|.$form->format_amount(\%myconfig, $form->{"customerprice_$i"}, 2).qq|></td>
1841 <td><select name="customercurr_$i">$form->{selectcurrency}</select></td>
1842 <td><input name="validfrom_$i" size=11 title="$myconfig{dateformat}" value="$form->{"validfrom_$i"}"></td>
1843 <td><input name="validto_$i" size=11 title="$myconfig{dateformat}" value="$form->{"validto_$i"}"></td>
1861 @column_index = qw(runningnumber qty unit bom adj partnumber description listprice sellprice lastcost);
1863 if ($form->{selectassemblypartsgroup}) {
1864 $form->{selectassemblypartsgroup} = $form->unescape($form->{selectassemblypartsgroup});
1865 @column_index = qw(runningnumber qty unit bom adj partnumber description partsgroup listprice sellprice lastcost);
1868 delete $form->{previousform};
1871 $form->{old_callback} = $form->{callback};
1872 $callback = $form->{callback};
1873 $form->{callback} = "$form->{script}?action=display_form";
1876 map { delete $form->{$_} } qw(action header);
1878 $form->{baseassembly} = 0;
1880 # save form variables in a previousform variable
1881 foreach $key (sort keys %$form) {
1883 $form->{$key} =~ s/&/%26/g;
1884 $previousform .= qq|$key=$form->{$key}&|;
1887 $form->{previousform} = $form->escape($previousform, 1);
1889 $form->{sellprice} = 0;
1890 $form->{listprice} = 0;
1891 $form->{lastcost} = 0;
1892 $form->{weight} = 0;
1894 $form->{callback} = $callback;
1897 $column_header{runningnumber} = qq|<th nowrap width=5%>|.$locale->text('No.').qq|</th>|;
1898 $column_header{qty} = qq|<th align=left nowrap width=10%>|.$locale->text('Qty').qq|</th>|;
1899 $column_header{unit} = qq|<th align=left nowrap width=5%>|.$locale->text('Unit').qq|</th>|;
1900 $column_header{partnumber} = qq|<th align=left nowrap width=20%>|.$locale->text('Number').qq|</th>|;
1901 $column_header{description} = qq|<th nowrap width=50%>|.$locale->text('Description').qq|</th>|;
1902 $column_header{sellprice} = qq|<th align=right nowrap>|.$locale->text('Sell').qq|</th>|;
1903 $column_header{listprice} = qq|<th align=right nowrap>|.$locale->text('List').qq|</th>|;
1904 $column_header{lastcost} = qq|<th align=right nowrap>|.$locale->text('Cost').qq|</th>|;
1905 $column_header{bom} = qq|<th>|.$locale->text('BOM').qq|</th>|;
1906 $column_header{adj} = qq|<th>|.$locale->text('A').qq|</th>|;
1907 $column_header{partsgroup} = qq|<th>|.$locale->text('Group').qq|</th>|;
1913 <tr class=listheading>
1914 <th class=listheading>|.$locale->text('Individual Items').qq|</th>
1922 map { print "\n$column_header{$_}" } @column_index;
1929 for $i (1 .. $numrows) {
1930 $form->{"partnumber_$i"} = $form->quote($form->{"partnumber_$i"});
1932 $linetotalsellprice = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
1933 $form->{sellprice} += $linetotalsellprice;
1935 $linetotallistprice = $form->round_amount($form->{"listprice_$i"} * $form->{"qty_$i"}, 2);
1936 $form->{listprice} += $linetotallistprice;
1938 $linetotallastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"}, 2);
1939 $form->{lastcost} += $linetotallastcost;
1942 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1944 $linetotalsellprice = $form->format_amount(\%myconfig, $linetotalsellprice, 2);
1945 $linetotallistprice = $form->format_amount(\%myconfig, $linetotallistprice, 2);
1946 $linetotallastcost = $form->format_amount(\%myconfig, $linetotallastcost, 2);
1948 if ($i == $numrows) {
1950 map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom adj);
1952 $column_data{qty} = qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1953 $column_data{partnumber} = qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
1954 $column_data{description} = qq|<td><input name="description_$i" size=30 value="$form->{"description_$i"}"></td>|;
1955 $column_data{partsgroup} = qq|<td><select name="partsgroup_$i">$form->{selectassemblypartsgroup}</select></td>|;
1959 $column_data{partnumber} = qq|<td><input class=submit type=submit name=action value=" $form->{"partnumber_$i"}"></td>
1960 <input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">|;
1962 $column_data{runningnumber} = qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
1963 $column_data{qty} = qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
1965 map { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? "checked" : "" } qw(bom adj);
1966 $column_data{bom} = qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
1967 $column_data{adj} = qq|<td align=center><input name="adj_$i" type=checkbox class=checkbox value=1 $form->{"adj_$i"}></td>|;
1969 ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
1970 $column_data{partsgroup} = qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$partsgroup</td>|;
1972 $column_data{unit} = qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
1973 $column_data{description} = qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
1977 $column_data{sellprice} = qq|<td align=right>$linetotalsellprice</td>|;
1978 $column_data{listprice} = qq|<td align=right>$linetotallistprice</td>|;
1979 $column_data{lastcost} = qq|<td align=right>$linetotallastcost</td>|;
1984 map { print "\n$column_data{$_}" } @column_index;
1988 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
1989 <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
1990 <input type=hidden name="listprice_$i" value=$form->{"listprice_$i"}>
1991 <input type=hidden name="lastcost_$i" value=$form->{"lastcost_$i"}>
1992 <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
1993 <input type=hidden name="assembly_$i" value=$form->{"assembly_$i"}>
1997 map { $column_data{$_} = "<td> </td>" } @column_index;
1999 $column_data{sellprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{sellprice}, 2)."</th>";
2000 $column_data{listprice} = "<th align=right>".$form->format_amount(\%myconfig, $form->{listprice}, 2)."</th>";
2001 $column_data{lastcost} = "<th align=right>".$form->format_amount(\%myconfig, $form->{lastcost}, 2)."</th>";
2006 map { print "\n$column_data{$_}" } @column_index;
2014 <td><hr size=3 noshade></td>
2017 <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
2018 <input type=hidden name=nextsub value=edit_assemblyitem>
2019 <input type=hidden name=selectassemblypartsgroup value="|.$form->escape($form->{selectassemblypartsgroup},1).qq|">
2025 sub edit_assemblyitem {
2027 $pn = substr($form->{action}, 1);
2029 for ($i = 1; $i < $form->{assembly_rows}; $i++) {
2030 last if $form->{"partnumber_$i"} eq $pn;
2033 $form->error($local->text('unexpected error!')) unless $i;
2035 $form->{baseassembly} = ($form->{baseassembly}) ? $form->{baseassembly} : $form->{"assembly_$i"};
2037 $form->{callback} = qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&rowcount=$i&baseassembly=$form->{baseassembly}&isassemblyitem=1&previousform=$form->{previousform}|;
2046 if ($form->{item} eq "assembly") {
2048 $i = $form->{assembly_rows};
2050 # if last row is empty check the form otherwise retrieve item
2051 if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
2057 IC->assembly_item(\%myconfig, \%$form);
2059 $rows = scalar @{ $form->{item_list} };
2062 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2063 $form->{"adj_$i"} = 1;
2066 $form->{makemodel_rows}--;
2067 $form->{customer_rows}--;
2071 map { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) } qw(partnumber description unit);
2072 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
2074 if ($form->{item_list}[0]{partsgroup_id}) {
2075 $form->{"partsgroup_$i"} = qq|$form->{item_list}[0]{partsgroup}--$form->{item_list}[0]{partsgroup_id}|;
2078 $form->{"runningnumber_$i"} = $form->{assembly_rows};
2079 $form->{assembly_rows}++;
2087 $form->{rowcount} = $i;
2088 $form->{assembly_rows}++;
2106 @flds = qw(vendor partnumber lastcost leadtime);
2110 map { $form->{"${_}_$form->{vendor_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{vendor_rows}"}) } qw(lastcost leadtime);
2112 for $i (1 .. $form->{vendor_rows} - 1) {
2114 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(lastcost leadtime);
2116 if ($form->{"lastcost_$i"} || $form->{"partnumber_$i"}) {
2120 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2126 $i = $form->{vendor_rows};
2128 if (!$form->{selectvendor}) {
2130 if ($form->{"vendor_$i"}) {
2131 ($form->{vendor}) = split /--/, $form->{"vendor_$i"};
2132 if (($j = $form->get_name(\%myconfig, vendor)) > 1) {
2133 &select_name(vendor, $i);
2139 $form->{"vendor_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
2141 # name is not on file
2142 $form->error(qq|$form->{"vendor_$i"} : |.$locale->text('Vendor not on file!'));
2147 if ($form->{"vendor_$i"}) {
2150 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2154 $form->redo_rows(\@flds, \@a, $count, $form->{vendor_rows});
2155 $form->{vendor_rows} = $count;
2160 sub check_customer {
2162 @flds = qw(customer validfrom validto pricebreak customerprice pricegroup);
2166 map { $form->{"${_}_$form->{customer_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{customer_rows}"}) } qw(customerprice pricebreak);
2168 for $i (1 .. $form->{customer_rows} - 1) {
2170 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(customerprice pricebreak);
2172 if ($form->{"customerprice_$i"}) {
2173 if ($form->{"pricebreak_$i"} || $form->{"customer_$i"} || $form->{"pricegroup_$i"}) {
2177 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2184 $i = $form->{customer_rows};
2186 if (!$form->{selectcustomer}) {
2188 if ($form->{"customer_$i"}) {
2189 ($form->{customer}) = split /--/, $form->{"customer_$i"};
2191 if (($j = $form->get_name(\%myconfig, customer)) > 1) {
2192 &select_name(customer, $i);
2198 $form->{"customer_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
2200 # name is not on file
2201 $form->error(qq|$form->{customer} : |.$locale->text('Customer not on file!'));
2206 if ($form->{"customer_$i"} || $form->{"pricegroup_$i"} || ($form->{"customerprice_$i"} || $form->{"pricebreak_$i"})) {
2209 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2213 $form->redo_rows(\@flds, \@a, $count, $form->{customer_rows});
2214 $form->{customer_rows} = $count;
2221 my ($table, $vr) = @_;
2223 @column_index = qw(ndx name address);
2225 $label = ucfirst $table;
2226 $column_data{ndx} = qq|<th> </th>|;
2227 $column_data{name} = qq|<th class=listheading>|.$locale->text($label).qq|</th>|;
2228 $column_data{address} = qq|<th class=listheading>|.$locale->text('Address').qq|</th>|;
2230 # list items with radio button on a form
2233 $title = $locale->text('Select from one of the names below');
2238 <form method=post action="$form->{script}#end">
2240 <input type=hidden name=vr value=$vr>
2244 <th class=listtop>$title</th>
2250 <tr class=listheading>|;
2252 map { print "\n$column_data{$_}" } @column_index;
2259 foreach $ref (@{ $form->{name_list} }) {
2260 $checked = ($i++) ? "" : "checked";
2262 $ref->{name} = $form->quote($ref->{name});
2264 $column_data{ndx} = qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
2265 $column_data{name} = qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
2266 $column_data{address} = qq|<td>$ref->{address1} $ref->{address2} $ref->{city} $ref->{state} $ref->{zipcode} $ref->{country}</td>|;
2270 <tr class=listrow$j>|;
2272 map { print "\n$column_data{$_}" } @column_index;
2277 <input name="new_id_$i" type=hidden value=$ref->{id}>
2288 <td><hr size=3 noshade></td>
2292 <input name=lastndx type=hidden value=$i>
2297 map { delete $form->{$_} } qw(action name_list header);
2302 <input type=hidden name=nextsub value=name_selected>
2304 <input type=hidden name=vc value=$table>
2306 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2319 # replace the variable with the one checked
2321 # index for new item
2324 $form->{"$form->{vc}_$form->{vr}"} = qq|$form->{"new_name_$i"}--$form->{"new_id_$i"}|;
2325 $form->{"$form->{vc}_id_$form->{vr}"} = $form->{"new_id_$i"};
2327 # delete all the new_ variables
2328 for $i (1 .. $form->{lastndx}) {
2329 map { delete $form->{"new_${_}_$i"} } (id, name);
2332 map { delete $form->{$_} } qw(ndx lastndx nextsub);
2341 if ($form->{obsolete}) {
2342 $form->error($locale->text("Inventory quantity must be zero before you can set this $form->{item} obsolete!")) if ($form->{onhand});
2345 # expand dynamic strings
2346 # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
2347 # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
2349 $olditem = $form->{id};
2352 $rc = IC->save(\%myconfig, \%$form);
2354 $parts_id = $form->{id};
2356 # load previous variables
2357 if ($form->{previousform} && !$form->{callback}) {
2358 # save the new form variables before splitting previousform
2359 map { $newform{$_} = $form->{$_} } keys %$form;
2361 $previousform = $form->unescape($form->{previousform});
2362 $baseassembly = $form->{baseassembly};
2364 # don't trample on previous variables
2365 map { delete $form->{$_} } keys %newform;
2367 # now take it apart and restore original values
2368 foreach $item (split /&/, $previousform) {
2369 ($key, $value) = split /=/, $item, 2;
2370 $value =~ s/%26/&/g;
2371 $form->{$key} = $value;
2375 if ($form->{item} eq 'assembly') {
2377 if ($baseassembly) {
2379 $previousform =~ /\&id=(\d+)/;
2382 # restore original callback
2383 $form->{callback} = $form->unescape($form->{old_callback});
2389 # undo number formatting
2390 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(weight listprice sellprice lastcost rop);
2392 $form->{assembly_rows}-- if $olditem;
2393 $i = $newform{rowcount};
2394 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2396 ($dec) = ($form->{listprice} =~ /\.(\d+)/);
2398 $dec1 = ($dec > 2) ? $dec : 2;
2400 ($dec) = ($form->{sellprice} =~ /\.(\d+)/);
2402 $dec2 = ($dec > 2) ? $dec : 2;
2404 ($dec) = ($form->{lastcost} =~ /\.(\d+)/);
2406 $dec3 = ($dec > 2) ? $dec : 2;
2408 $form->{listprice} -= $form->{"listprice_$i"} * $form->{"qty_$i"};
2409 $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
2410 $form->{lastcost} -= $form->{"lastcost_$i"} * $form->{"qty_$i"};
2411 $form->{weight} -= $form->{"weight_$i"} * $form->{"qty_$i"};
2413 # change/add values for assembly item
2414 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit weight listprice sellprice lastcost inventory_accno income_accno expense_accno);
2416 $form->{listprice} += $form->{"listprice_$i"} * $form->{"qty_$i"};
2417 $form->{listprice} = $form->round_amount($form->{listprice}, $dec1);
2419 $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
2420 $form->{sellprice} = $form->round_amount($form->{sellprice}, $dec2);
2422 $form->{lastcost} += $form->{"lastcost_$i"} * $form->{"qty_$i"};
2423 $form->{lastcost} = $form->round_amount($form->{lastcost}, $dec3);
2425 $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
2427 $form->{"adj_$i"} = 1 if !$olditem;
2429 $form->{customer_rows}--;
2432 # set values for last invoice/order item
2433 $i = $form->{rowcount};
2434 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2436 map { $form->{"${_}_$i"} = $newform{$_} } qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice partsgroup);
2437 $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
2439 if ($form->{exchangerate} != 0) {
2440 ($dec) = ($newform{sellprice} =~ /\.(\d+)/);
2442 $decimalplaces = ($dec > 2) ? $dec : 2;
2444 $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} / $form->{exchangerate}, $decimalplaces);
2447 map { $form->{"taxaccounts_$i"} .= "$_ " if ($newform{"IC_tax_$_"}) } split / /, $newform{taxaccounts};
2448 chop $form->{"taxaccounts_$i"};
2450 # credit remaining calculation
2451 $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"};
2452 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
2453 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
2455 $form->{creditremaining} -= $amount;
2459 $form->{"id_$i"} = $parts_id;
2460 delete $form->{action};
2462 # restore original callback
2463 $callback = $form->unescape($form->{callback});
2464 $form->{callback} = $form->unescape($form->{old_callback});
2465 delete $form->{old_callback};
2467 $form->{makemodel_rows}--;
2469 # put callback together
2470 foreach $key (keys %$form) {
2471 # do single escape for Apache 2.0
2472 $value = $form->escape($form->{$key}, 1);
2473 $callback .= qq|&$key=$value|;
2475 $form->{callback} = $callback;
2494 $rc = IC->delete(\%myconfig, \%$form);
2497 $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2498 $form->error($locale->text('Cannot delete item!'));
2504 sub stock_assembly {
2506 $form->{title} = $locale->text('Stock Assembly');
2513 <form method=post action=$form->{script}>
2515 <table width="100%">
2517 <th class=listtop>$form->{title}</th>
2519 <tr height="5"></tr>
2524 <th align="right" nowrap="true">|.$locale->text('Number').qq|</th>
2525 <td><input name=partnumber size=20></td>
2529 <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
2530 <td><input name=description size=40></td>
2534 <td><input name=checkinventory class=checkbox type=checkbox value=1> |.$locale->text('Check Inventory').qq|</td>
2539 <tr><td><hr size=3 noshade></td></tr>
2542 <input type=hidden name=sort value=partnumber>
2544 <input type=hidden name=path value=$form->{path}>
2545 <input type=hidden name=login value=$form->{login}>
2546 <input type=hidden name=sessionid value=$form->{sessionid}>
2548 <input type=hidden name=nextsub value=list_assemblies>
2551 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2563 sub list_assemblies {
2565 IC->retrieve_assemblies(\%myconfig, \%$form);
2567 $callback = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}";
2569 $form->sort_order();
2570 $href = "$form->{script}?action=list_assemblies&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&checkinventory=$form->{checkinventory}";
2572 if ($form->{partnumber}) {
2573 $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
2574 $href .= "&partnumber=".$form->escape($form->{partnumber});
2575 $form->{sort} = "partnumber" unless $form->{sort};
2577 if ($form->{description}) {
2578 $callback .= "&description=".$form->escape($form->{description},1);
2579 $href .= "&description=".$form->escape($form->{description});
2580 $form->{sort} = "description" unless $form->{sort};
2583 $column_header{partnumber} = qq|<th><a class=listheading href=$href&sort=partnumber>|.$locale->text('Number').qq|</th>|;
2584 $column_header{description} = qq|<th><a class=listheading href=$href&sort=description>|.$locale->text('Description').qq|</th>|;
2585 $column_header{bin} = qq|<th><a class=listheading href=$href&sort=bin>|.$locale->text('Bin').qq|</th>|;
2586 $column_header{onhand} = qq|<th class=listheading>|.$locale->text('Qty').qq|</th>|;
2587 $column_header{rop} = qq|<th class=listheading>|.$locale->text('ROP').qq|</th>|;
2588 $column_header{stock} = qq|<th class=listheading>|.$locale->text('Add').qq|</th>|;
2590 @column_index = $form->sort_columns(qw(partnumber description bin onhand rop stock));
2592 $form->{title} = $locale->text('Stock Assembly');
2601 <form method=post action=$form->{script}>
2605 <th class=listtop>$form->{title}</th>
2611 <tr class=listheading>
2614 map { print "\n$column_header{$_}" } @column_index;
2620 # add sort and escape callback
2621 $form->{callback} = $callback .= "&sort=$form->{sort}";
2623 # escape callback for href
2624 $callback = $form->escape($callback);
2628 foreach $ref (@{ $form->{assembly_items} }) {
2630 map { $ref->{$_} = $form->quote($ref->{$_}) } qw(partnumber description);
2632 $column_data{partnumber} = "<td width=20%><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber} </a></td>";
2634 $column_data{description} = qq|<td width=50%>$ref->{description} </td>|;
2635 $column_data{bin} = qq|<td>$ref->{bin} </td>|;
2636 $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, "", " ").qq|</td>|;
2637 $column_data{rop} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{rop}, '', " ").qq|</td>|;
2638 $column_data{stock} = qq|<td width=10%><input name="qty_$i" size=10 value=|.$form->format_amount(\%myconfig, $ref->{stock}).qq|></td>
2639 <input type=hidden name="stock_$i" value=$ref->{stock}>|;
2642 print qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
2644 map { print "\n$column_data{$_}" } @column_index;
2659 <td><hr size=3 noshade>
2663 <input name=rowcount type=hidden value="$i">
2664 <input type=hidden name=checkinventory value=$form->{checkinventory}>
2666 <input type=hidden name=path value=$form->{path}>
2667 <input type=hidden name=login value=$form->{login}>
2668 <input type=hidden name=sessionid value=$form->{sessionid}>
2670 <input name=callback type=hidden value="$form->{callback}">
2672 <input type=hidden name=nextsub value=restock_assemblies>
2675 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2686 sub restock_assemblies {
2689 if ($form->{checkinventory}) {
2690 map { $form->error($locale->text('Quantity exceeds available units to stock!')) if $form->parse_amount($myconfig, $form->{"qty_$_"}) > $form->{"stock_$_"} }(1 .. $form->{rowcount});
2693 $form->redirect($locale->text('Assemblies restocked!')) if (IC->restock_assemblies(\%myconfig, \%$form));
2694 $form->error($locale->text('Cannot stock assemblies!'));
2699 sub continue { &{ $form->{nextsub} } };
2701 sub add_part { &add };
2702 sub add_service { &add };
2703 sub add_assembly { &add };
2704 sub add_labor_overhead { &add };