This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / sql-ledger / bin / mozilla / ic.pl
1 #=====================================================================
2 # SQL-Ledger, Accounting
3 # Copyright (c) 2001
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 # Contributors:
10 #
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.
15 #
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 #======================================================================
24 #
25 # Inventory Control module
26 #
27 #======================================================================
28
29
30 use SL::IC;
31
32 require "$form->{path}/io.pl";
33
34 1;
35 # end of main
36
37
38
39 sub add {
40
41   %label = ( part       => 'Part',
42              service    => 'Service',
43              assembly   => 'Assembly',
44              labor      => 'Labor/Overhead' );
45
46 # $locale->text('Add Part')
47 # $locale->text('Add Service')
48 # $locale->text('Add Assembly')
49 # $locale->text('Add Labor/Overhead')
50
51   $label = "Add $label{$form->{item}}";
52   $form->{title} = $locale->text($label);
53
54   $form->{callback} = "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
55
56   $form->{orphaned} = 1;
57
58   if ($form->{previousform}) {
59     $form->{callback} = "";
60   }
61
62   &link_part;
63   &display_form;
64   
65 }
66
67
68 sub search {
69
70   $form->get_partsgroup(\%myconfig, { all => 0, searchitems => $form->{searchitems}});
71
72   IC->get_warehouses(\%myconfig, \%$form) unless $form->{searchitems} =~ /(service|labor)/;
73
74   if (@{ $form->{all_partsgroup} }) {
75     $partsgroup = qq|<option>\n|;
76
77     map { $partsgroup .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} }; 
78
79     $partsgroup = qq| 
80         <th align=right nowrap>|.$locale->text('Group').qq|</th>
81         <td><select name=partsgroup>$partsgroup</select></td>
82 |;
83   }
84
85   $l_listprice = qq|
86                 <td><input name=l_listprice class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('List Price').qq|</td>
87 |;
88   $l_sellprice = qq|
89                 <td><input name=l_sellprice class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Sell Price').qq|</td>
90 |;
91   $l_lastcost = qq|
92                 <td><input name=l_lastcost class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Cost').qq|</td>
93 |;
94   $l_linetotal = qq|
95                 <td><input name=l_linetotal class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Line Total').qq|</td>
96 |;
97   $l_curr = qq|
98                 <td><input name=l_curr class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Currency').qq|</td>
99 |;
100
101   $accrual = qq|
102                     <tr>
103                       <td colspan=4><input name=method class=radio type=radio value=accrual checked>|.$locale->text('Accrual').qq|
104                       &nbsp;<input name=method class=radio type=radio value=cash>|.$locale->text('Cash').qq|</td>
105                     </tr>
106 |;
107
108   $serialnumber = qq|
109           <th align=right nowrap>|.$locale->text('Serial Number').qq|</th>
110           <td><input name=serialnumber size=20></td>
111 |;
112
113   $l_serialnumber = qq|
114         <td><input name=l_serialnumber class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Serial Number').qq|</td>
115 |;
116
117
118   if ($form->{searchitems} =~ /(part|assembly)/) {
119     
120     $onhand = qq|
121             <input name=itemstatus class=radio type=radio value=onhand>&nbsp;|.$locale->text('On Hand').qq|
122             <input name=itemstatus class=radio type=radio value=short>&nbsp;|.$locale->text('Short').qq|
123 |;
124
125     $makemodel = qq|
126         <tr>
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>
131         </tr>
132 |;
133
134     $l_makemodel = qq|
135         <td><input name=l_make class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Make').qq|</td>
136         <td><input name=l_model class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Model').qq|</td>
137 |;
138
139     $l_bin = qq|
140                 <td><input name=l_bin class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Bin').qq|</td>|;
141
142     $l_rop = qq|
143                 <td><input name=l_rop class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('ROP').qq|</td>|;
144
145
146     $l_weight = qq|
147                 <td><input name=l_weight class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Weight').qq|</td>|;
148
149
150     if (@{ $form->{all_warehouses} }) {
151       $selectwarehouse = "<option>\n";
152
153       map { $selectwarehouse .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_warehouses} });
154       
155       $warehouse = qq|
156           <th align=right nowrap>|.$locale->text('Warehouse').qq|</th>
157           <td><select name=warehouse>$selectwarehouse</select></td>
158 |;
159
160       $l_warehouse = qq|
161         <td><input name=l_warehouse class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Warehouse').qq|</td>
162 |;
163
164
165       $drawing = qq|
166         <tr>
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>
171         </tr>
172 |;
173
174       $l_drawing = qq|
175               <tr>
176                 <td><input name=l_image class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Image').qq|</td>
177                 <td><input name=l_drawing class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Drawing').qq|</td>
178                 <td><input name=l_microfiche class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Microfiche').qq|</td>
179               </tr>
180 |;
181
182     }
183   }
184
185   if ($form->{searchitems} eq 'assembly') {
186  
187     $toplevel = qq|
188         <tr>
189           <td></td>
190           <td colspan=3>
191           <input name=null class=radio type=radio value=1 checked>&nbsp;|.$locale->text('Top Level').qq|
192           <input name=bom class=checkbox type=checkbox value=1>&nbsp;|.$locale->text('Individual Items').qq|
193           </td>
194         </tr>
195 |;
196     
197     $bought = qq|
198         <tr>
199           <td></td>
200           <td colspan=3>
201             <table>
202               <tr>
203                 <td>
204                   <table>
205                     <tr>
206                       <td><input name=sold class=checkbox type=checkbox value=1></td>
207                       <td nowrap>|.$locale->text('Sales Invoices').qq|</td>
208                     </tr>
209                     <tr>
210                       <td colspan=2><hr size=1 noshade></td>
211                     </tr>
212                     <tr>
213                       <td><input name=ordered class=checkbox type=checkbox value=1></td>
214                       <td nowrap>|.$locale->text('Sales Orders').qq|</td>
215                     </tr>
216                     <tr>
217                       <td colspan=4><hr size=1 noshade></td>
218                     </tr>
219                     <tr>
220                       <td><input name=quoted class=checkbox type=checkbox value=1></td>
221                       <td nowrap>|.$locale->text('Quotations').qq|</td>
222                     </tr>
223                   </table>
224                 </td>
225                 <td width=5%>&nbsp;</td>
226                 <td>
227                   <table>
228                     $accrual
229                     <tr>
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>
234                     </tr>
235                     <tr>
236                       <td colspan=4><input name=open class=checkbox type=checkbox value=1 checked>&nbsp;|.$locale->text('Open').qq|
237                       <input name=closed class=checkbox type=checkbox>&nbsp;|.$locale->text('Closed').qq|</td>
238                     </tr>
239                   </table>
240                 </td>
241               </tr>
242             </table>
243           </td>
244         </tr>
245 |;
246
247   } elsif ($form->{searchitems} eq 'component') {
248
249     $warehouse = "";
250     $serialnumber = "";
251     $l_serialnumber = "";
252     $l_warehouse = "";
253   
254   } elsif ($form->{searchitems} eq 'labor') {
255
256     $warehouse = "";
257     $serialnumber = "";
258     $l_serialnumber = "";
259     $l_sellprice = qq|
260                 <td><input name=l_sellprice class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Amount').qq|</td>
261 |;
262     $l_listprice = "";
263     $l_lastcost = "";
264     
265   } else {
266        
267      $bought = qq|
268         <tr>
269           <td></td>
270           <td colspan=3>
271             <table>
272               <tr>
273                 <td>
274                   <table>
275                     <tr>
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>
280                     </tr>
281                     <tr>
282                       <td colspan=4><hr size=1 noshade></td>
283                     </tr>
284                     <tr>
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>
289                     </tr>
290                     <tr>
291                       <td colspan=4><hr size=1 noshade></td>
292                     </tr>
293                     <tr>
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>
298                     </tr>
299                   </table>
300                 </td>
301                 <td width=5%>&nbsp;</td>
302                 <td>
303                   <table>
304                     $accrual
305                     <tr>
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>
310                     </tr>
311                     <tr>
312                       <td colspan=4><input name=open class=checkbox type=checkbox value=1 checked>&nbsp;|.$locale->text('Open').qq|
313                       <input name=closed class=checkbox type=checkbox>&nbsp;|.$locale->text('Closed').qq|</td>
314                     </tr>
315                   </table>
316                 </td>
317               </tr>
318             </table>
319           </td>
320         </tr>
321 |;
322   }
323
324   %title = ( all        => 'Items',
325              part       => 'Parts',
326              labor      => 'Labor/Overhead',
327              service    => 'Services',
328              assembly   => 'Assemblies',
329              component  => 'Components'
330            );
331
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')
338   
339   $form->{title} = $locale->text($title{$form->{searchitems}});
340    
341   $form->header;
342   
343   print qq|
344 <body>
345
346 <form method=post action=$form->{script}>
347
348 <input type=hidden name=searchitems value=$form->{searchitems}>
349 <input type=hidden name=title value="$form->{title}">
350
351 <table width="100%">
352   <tr><th class=listtop>$form->{title}</th></tr>
353   <tr height="5"></tr>
354   <tr valign=top>
355     <td>
356       <table>
357         <tr>
358           <th align=right nowrap>|.$locale->text('Number').qq|</th>
359           <td><input name=partnumber size=20></td>
360         </tr>
361         <tr>
362           <th align=right nowrap>|.$locale->text('Description').qq|</th>
363           <td colspan=3><input name=description size=40></td>
364         </tr>
365         <tr>
366           $warehouse
367         </tr>
368         <tr>
369           $partsgroup
370           $serialnumber
371         </tr>
372         $makemodel
373         $drawing
374         $toplevel
375         <tr>
376           <td></td>
377           <td colspan=3>
378             <input name=itemstatus class=radio type=radio value=active checked>&nbsp;|.$locale->text('Active').qq|
379             $onhand
380             <input name=itemstatus class=radio type=radio value=obsolete>&nbsp;|.$locale->text('Obsolete').qq|
381             <input name=itemstatus class=radio type=radio value=orphaned>&nbsp;|.$locale->text('Orphaned').qq|
382           </td>
383         </tr>
384         $bought
385         <tr>
386           <td></td>
387           <td colspan=3>
388             <hr size=1 noshade>
389           </td>
390         </tr>
391         <tr>
392           <th align=right nowrap>|.$locale->text('Include in Report').qq|</th>
393           <td colspan=3>
394             <table>
395               <tr>
396                 <td><input name=l_partnumber class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Number').qq|</td>
397                 <td><input name=l_description class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Description').qq|</td>
398                 $l_serialnumber
399                 <td><input name=l_unit class=checkbox type=checkbox value=Y checked>&nbsp;|.$locale->text('Unit of measure').qq|</td>
400                 <td><input name=l_priceupdate class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Updated').qq|</td>
401                 <td><input name=l_partsgroup class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Group').qq|</td>
402               </tr>
403               <tr>
404                 $l_listprice
405                 $l_sellprice
406                 $l_lastcost
407                 $l_linetotal
408                 $l_curr
409               </tr>
410               <tr>
411                 $l_bin
412                 $l_rop
413                 $l_weight
414               </tr>
415                 $l_drawing
416               <tr>
417                 $l_makemodel
418                 $l_warehouse
419               </tr>
420               <tr>
421                 <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|.$locale->text('Subtotal').qq|</td>
422               </tr>
423             </table>
424           </td>
425         </tr>
426       </table>
427     </td>
428   </tr>
429   <tr><td colspan=4><hr size=3 noshade></td></tr>
430 </table>
431
432 <input type=hidden name=nextsub value=generate_report>
433
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}>
437
438 <br>
439 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
440 </form>
441
442 </body>
443 </html>
444 |;
445
446 }
447
448
449
450 sub generate_report {
451
452   # setup $form->{sort}
453   unless ($form->{sort}) {
454     if ($form->{description} && !($form->{partnumber})) {
455       $form->{sort} = "description";
456     } else {
457       $form->{sort} = "partnumber";
458     }
459   }
460
461   $warehouse = $form->escape($form->{warehouse},1);
462   $partsgroup = $form->escape($form->{partsgroup},1);
463   $title = $form->escape($form->{title},1);
464   
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}";
466
467
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;
474       } else {
475         $form->{bought} = $form->{sold} = $form->{onorder} = $form->{ordered} = 1;
476       }
477     }
478   }
479
480  
481   if ($form->{itemstatus} eq 'active') {
482     $option .= $locale->text('Active')." : ";
483   }
484   if ($form->{itemstatus} eq 'obsolete') {
485     $form->{onhand} = $form->{short} = 0;
486     $form->{warehouse} = "";
487     $form->{l_warehouse} = 0;
488
489     $option .= $locale->text('Obsolete')." : ";
490   }
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;
496
497     $form->{warehouse} = "";
498     $form->{l_warehouse} = 0;
499
500     $form->{transdatefrom} = $form->{transdateto} = "";
501     
502     $option .= $locale->text('Orphaned')." : ";
503   }
504   if ($form->{itemstatus} eq 'onhand') {
505     $option .= $locale->text('On Hand')." : ";
506     $form->{l_onhand} = "Y";
507   }
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';
512     
513     $form->{warehouse} = "";
514     $form->{l_warehouse} = 0;
515   }
516   if ($form->{onorder}) {
517     $form->{l_ordnumber} = "Y";
518     $callback .= "&onorder=$form->{onorder}";
519     $option .= $locale->text('Purchase Order')." : ";
520   }
521   if ($form->{ordered}) {
522     $form->{l_ordnumber} = "Y";
523     $callback .= "&ordered=$form->{ordered}";
524     $option .= $locale->text('Sales Order')." : ";
525   }
526   if ($form->{rfq}) {
527     $form->{l_quonumber} = "Y";
528     $callback .= "&rfq=$form->{rfq}";
529     $option .= $locale->text('RFQ')." : ";
530   }
531   if ($form->{quoted}) {
532     $form->{l_quonumber} = "Y";
533     $callback .= "&quoted=$form->{quoted}";
534     $option .= $locale->text('Quotation')." : ";
535   }
536   if ($form->{bought}) {
537     $form->{l_invnumber} = "Y";
538     $callback .= "&bought=$form->{bought}";
539     $option .= $locale->text('Vendor Invoice')." : ";
540   }
541   if ($form->{sold}) {
542     $form->{l_invnumber} = "Y";
543     $callback .= "&sold=$form->{sold}";
544     $option .= $locale->text('Sales Invoice')." : ";
545   }
546   if ($form->{sold} || $form->{bought}) {
547     $label = ucfirst $form->{method};
548     $option .= $locale->text($label) ." : ";
549   }
550
551   if ($form->{bought} || $form->{sold} || $form->{onorder} || $form->{ordered} || $form->{rfq} || $form->{quoted}) {
552     
553     # warehouse stuff is meaningless
554     $form->{warehouse} = "";
555     $form->{l_warehouse} = 0;
556     
557     $form->{l_lastcost} = "";
558     $form->{l_name} = "Y";
559     $form->{l_employee} = "Y";
560
561      
562     if ($form->{open}) {
563       $callback .= "&open=$form->{open}";
564       $option .= $locale->text('Open');
565     }
566     if ($form->{closed}) {
567       $callback .= "&closed=$form->{closed}";
568       if ($form->{open}) {
569         $option .= " : ".$locale->text('Closed');
570       } else {
571         $option .= $locale->text('Closed');
572       }
573     }
574
575     if ($form->{transdatefrom}) {
576       $callback .= "&transdatefrom=$form->{transdatefrom}";
577       $option .= "\n<br>".$locale->text('From')."&nbsp;".$locale->date(\%myconfig, $form->{transdatefrom}, 1);
578     }
579     if ($form->{transdateto}) {
580       $callback .= "&transdateto=$form->{transdateto}";
581       $option .= "\n<br>".$locale->text('To')."&nbsp;".$locale->date(\%myconfig, $form->{transdateto}, 1);
582     }
583   }
584   
585   if ($form->{warehouse}) {
586     ($warehouse) = split /--/, $form->{warehouse};
587     $option .= "<br>".$locale->text('Warehouse')." : $warehouse";
588     $form->{l_warehouse} = 0;
589   }
590  
591   $option .= "<br>";
592   
593   if ($form->{partnumber}) {
594     $callback .= "&partnumber=".$form->escape($form->{partnumber},1);
595     $option .= $locale->text('Number').qq| : $form->{partnumber}<br>|;
596   }
597   if ($form->{partsgroup}) {
598     ($partsgroup) = split /--/, $form->{partsgroup};
599     $option .= $locale->text('Group').qq| : $partsgroup<br>|;
600   }
601   if ($form->{serialnumber}) {
602     $callback .= "&serialnumber=".$form->escape($form->{serialnumber},1);
603     $option .= $locale->text('Serial Number').qq| : $form->{serialnumber}<br>|;
604   }
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>|;
610   }
611   if ($form->{make}) {
612     $callback .= "&make=".$form->escape($form->{make},1);
613     $option .= $locale->text('Make').qq| : $form->{make}<br>|;
614   }
615   if ($form->{model}) {
616     $callback .= "&model=".$form->escape($form->{model},1);
617     $option .= $locale->text('Model').qq| : $form->{model}<br>|;
618   }
619   if ($form->{drawing}) {
620     $callback .= "&drawing=".$form->escape($form->{drawing},1);
621     $option .= $locale->text('Drawing').qq| : $form->{drawing}<br>|;
622   }
623   if ($form->{microfiche}) {
624     $callback .= "&microfiche=".$form->escape($form->{microfiche},1);
625     $option .= $locale->text('Microfiche').qq| : $form->{microfiche}<br>|;
626   }
627
628   
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));
630
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};
636   }
637
638   if ($form->{searchitems} eq 'service') {
639     # remove bin, weight and rop from list
640     map { $form->{"l_$_"} = "" } qw(bin weight rop);
641
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";
647     } else {
648       $form->{l_linetotalsellprice} = "";
649       $form->{l_linetotallastcost} = "";
650     }
651   }
652
653   
654   foreach $item (@columns) {
655     if ($form->{"l_$item"} eq "Y") {
656       push @column_index, $item;
657
658       # add column to callback
659       $callback .= "&l_$item=Y";
660     }
661   }
662
663   if ($form->{l_subtotal} eq 'Y') {
664     $callback .= "&l_subtotal=Y";
665   }
666
667
668   IC->all_parts(\%myconfig, \%$form);
669
670   $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
671   
672   $href = $callback;
673   
674   $form->sort_order();
675   
676   $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/;
677
678
679   if ($form->{searchitems} eq 'assembly' && $form->{l_partnumber}) {
680     # replace partnumber with partnumber_
681     $ndx = 0;
682     foreach $item (@column_index) {
683       $ndx++;
684       last if $item eq 'partnumber';
685     }
686
687     splice @column_index, $ndx, 0, map { "partnumber_$_" } (1 .. $form->{pncol});
688     $colspan = $form->{pncol} + 1;
689   }
690
691   if ($form->{searchitems} eq 'component') {
692     if ($form->{l_partnumber}) {
693       # splice it in after the partnumber
694       $ndx = 0;
695       foreach $item (@column_index) {
696         $ndx++;
697         last if $item eq 'partnumber';
698       }
699       
700       @a = splice @column_index, 0, $ndx;
701       unshift @column_index, "assemblypartnumber";
702       unshift @column_index, @a;
703     }
704   }
705   
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>|;
717
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>|;
720   
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>|;
724   
725   $column_header{name} = qq|<th nowrap><a class=listheading href=$href&sort=name>|.$locale->text('Name').qq|</a></th>|;
726   
727   $column_header{employee} = qq|<th nowrap><a class=listheading href=$href&sort=employee>|.$locale->text('Employee').qq|</a></th>|;
728   
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>|;
732   
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>|;
736   
737   $column_header{curr} = qq|<th class=listheading nowrap>|.$locale->text('Curr').qq|</th>|;
738   
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>|;
742   
743   $column_header{serialnumber} = qq|<th nowrap><a class=listheading href=$href&sort=serialnumber>|.$locale->text('Serial Number').qq|</a></th>|;
744   
745   $column_header{assemblypartnumber} = qq|<th nowrap><a class=listheading href=$href&sort=assemblypartnumber>|.$locale->text('Assembly').qq|</a></th>|;
746   
747   $column_header{warehouse} = qq|<th nowrap class=listheading>|.$locale->text('Warehouse').qq|</th>|;
748
749   
750   $form->header;
751
752   $i = 1;
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++;
756   }
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++;
760   }
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++;
764   }
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++;
768   }
769
770   foreach $item (split /;/, $myconfig{acs}) {
771     delete $button{$item};
772   }
773
774   print qq|
775 <body>
776
777 <table width=100%>
778   <tr>
779     <th class=listtop>$form->{title}</th>
780   </tr>
781   <tr height="5"></tr>
782
783   <tr><td>$option</td></tr>
784
785   <tr>
786     <td>
787       <table width=100%>
788         <tr class=listheading>
789 |;
790
791   map { print "\n$column_header{$_}" } @column_index;
792   
793   print qq|
794         </tr>
795   |;
796
797
798   # add order to callback
799   $form->{callback} = $callback .= "&sort=$form->{sort}";
800
801   # escape callback for href
802   $callback = $form->escape($callback);
803
804   if (@{ $form->{parts} }) {
805     $sameitem = $form->{parts}->[0]->{$form->{sort}};
806   }
807
808
809   foreach $ref (@{ $form->{parts} }) {
810   
811     if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
812       if ($sameitem ne $ref->{$form->{sort}}) {
813         &parts_subtotal;
814         $sameitem = $ref->{$form->{sort}};
815       }
816     }
817
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);
824       }
825     } else {
826       if ($ref->{module} eq 'oe') {
827         map { $ref->{$_} = $form->round_amount($ref->{$_} * $ref->{exchangerate}, 2) } qw(sellprice listprice lastcost);
828       }
829     }
830     
831     # use this for assemblies
832     $onhand = $ref->{onhand};
833     
834     $ref->{description} =~ s/\r/<br>/g;
835     
836     map { $column_data{"partnumber_$_"} = "<td>&nbsp;</td>" } (1 .. $form->{pncol});
837
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}&nbsp;</a></td>";
839     
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}&nbsp;</a></td>";
841     
842     if ($ref->{assemblyitem}) {
843       $onhand = 0 if ($form->{sold});
844       
845       $column_data{partnumber} = "<td>&nbsp;</td>";
846       
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}&nbsp;</a></td>";
848
849     }
850     
851     map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } qw(description partsgroup employee curr);
852
853     $column_data{onhand} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")."</td>";
854
855     map { $column_data{$_} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{$_}, 2, "&nbsp;") . "</td>" } qw(sellprice listprice lastcost);
856     
857     $column_data{linetotalsellprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2, "&nbsp;")."</td>";
858     $column_data{linetotallastcost} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2, "&nbsp;")."</td>";
859     $column_data{linetotallistprice} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2, "&nbsp;")."</td>";
860
861     if ($ref->{assemblyitem} && $ref->{stagger} > 1) {
862       map { $column_data{$_} = "<td>&nbsp;</td>" } qw(linetotalsellprice linetotallastcost linetotallistprice);
863     }
864     
865     if (!$ref->{assemblyitem}) {
866       $totalsellprice += $onhand * $ref->{sellprice};
867       $totallastcost += $onhand * $ref->{lastcost};
868       $totallistprice += $onhand * $ref->{listprice};
869
870       $subtotalonhand += $onhand;
871       $subtotalsellprice += $onhand * $ref->{sellprice};
872       $subtotallastcost += $onhand * $ref->{lastcost};
873       $subtotallistprice += $onhand * $ref->{listprice};
874     }
875
876     $column_data{rop} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;")."</td>";
877     $column_data{weight} = "<td align=right>".$form->format_amount(\%myconfig, $ref->{weight}, '', "&nbsp;")."</td>";
878     $column_data{unit} = "<td>$ref->{unit}&nbsp;</td>";
879     $column_data{bin} = "<td>$ref->{bin}&nbsp;</td>";
880     $column_data{priceupdate} = "<td>$ref->{priceupdate}&nbsp;</td>";
881     
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}&nbsp;</a></td>" : "<td>$ref->{invnumber}&nbsp;</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}&nbsp;</a></td>" : "<td>$ref->{ordnumber}&nbsp;</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}&nbsp;</a></td>" : "<td>$ref->{quonumber}&nbsp;</td>";
886
887     $column_data{name} = "<td>$ref->{name}&nbsp;</td>";
888    
889     $column_data{image} = ($ref->{image}) ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>" : "<td>&nbsp;</td>";
890     $column_data{drawing} = ($ref->{drawing}) ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>" : "<td>&nbsp;</td>";
891     $column_data{microfiche} = ($ref->{microfiche}) ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>" : "<td>&nbsp;</td>";
892     
893     $column_data{make} = "<td>$ref->{make}&nbsp;</td>";
894     $column_data{model} = "<td>$ref->{model}&nbsp;</td>";
895     
896     $column_data{serialnumber} = "<td>$ref->{serialnumber}&nbsp;</td>";
897     $column_data{warehouse} = "<td>$ref->{warehouse}&nbsp;</td>";
898     
899     $i++; $i %= 2;
900     print "<tr class=listrow$i>";
901
902     map { print "\n$column_data{$_}" } @column_index;
903
904     print qq|
905     </tr>
906 |;
907
908   }
909   
910   
911   if ($form->{l_subtotal} eq 'Y') {
912     &parts_subtotal;
913   }
914
915   if ($form->{"l_linetotal"}) {
916     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
917     $column_data{linetotalsellprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totalsellprice, 2, "&nbsp;")."</th>";
918     $column_data{linetotallastcost} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallastcost, 2, "&nbsp;")."</th>";
919     $column_data{linetotallistprice} = "<th class=listtotal align=right>".$form->format_amount(\%myconfig, $totallistprice, 2, "&nbsp;")."</th>";
920
921     print "<tr class=listtotal>";
922
923     map { print "\n$column_data{$_}" } @column_index;
924
925     print qq|</tr>
926     |;
927   }
928
929   print qq|
930       </table>
931     </td>
932   </tr>
933   <tr><td><hr size=3 noshade></td></tr>
934 </table>
935
936 |;
937  
938   print qq|
939
940 <br>
941
942 <form method=post action=$form->{script}>
943
944 <input name=callback type=hidden value="$form->{callback}">
945
946 <input type=hidden name=item value=$form->{searchitems}>
947
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}>
951 |;
952
953   foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
954     print $item->{code};
955   }
956
957   if ($form->{menubar}) {
958     require "$form->{path}/menu.pl";
959     &menubar;
960   }
961
962   print qq|
963   </form>
964
965 </body>
966 </html>
967 |;
968
969 }
970
971
972
973 sub parts_subtotal {
974
975   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
976   $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
977
978   $column_data{onhand} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalonhand, '', "&nbsp;")."</th>";
979
980   $column_data{linetotalsellprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotalsellprice, 2, "&nbsp;")."</th>";
981   $column_data{linetotallistprice} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallistprice, 2, "&nbsp;")."</th>";
982   $column_data{linetotallastcost} = "<th class=listsubtotal align=right>".$form->format_amount(\%myconfig, $subtotallastcost, 2, "&nbsp;")."</th>";
983   
984   $subtotalonhand = 0;
985   $subtotalsellprice = 0;
986   $subtotallistprice = 0;
987   $subtotallastcost = 0;
988
989   print "<tr class=listsubtotal>";
990
991   map { print "\n$column_data{$_}" } @column_index;
992
993   print qq|
994   </tr>
995 |;
996
997 }
998
999
1000
1001 sub edit {
1002   
1003  %label = ( part        => 'Part',
1004             service     => 'Service',
1005             assembly    => 'Assembly',
1006             labor       => 'Labor/Overhead' );
1007
1008 # $locale->text('Edit Part')
1009 # $locale->text('Edit Service')
1010 # $locale->text('Edit Assembly')
1011 # $locale->text('Edit Labor/Overhead')
1012
1013   IC->get_part(\%myconfig, \%$form);
1014
1015   $label = "Edit $label{$form->{item}}";
1016   $form->{title} = $locale->text($label);
1017
1018   &link_part;
1019
1020   $form->{previousform} = $form->escape($form->{previousform}, 1) if $form->{previousform};
1021   
1022   &display_form;
1023
1024 }
1025
1026
1027
1028 sub link_part {
1029
1030   IC->create_links("IC", \%myconfig, \%$form);
1031   
1032   # currencies 
1033   map { $form->{selectcurrency} .= "<option>$_\n" } split /:/, $form->{currencies};
1034   
1035   # parts and assemblies have the same links
1036   $item = $form->{item};
1037   
1038   # readonly
1039   if ($form->{item} eq 'part') {
1040     $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Part/;
1041   }
1042   if ($form->{item} eq 'service') {
1043     $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Service/;
1044   }
1045   if ($form->{item} eq 'assembly') {
1046     $item = 'part';
1047     $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Assembly/;
1048   }
1049   if ($form->{item} eq 'labor') {
1050     $item = 'labor';
1051     $form->{readonly} = 1 if $myconfig{acs} =~ /Goods \& Services--Add Labor\/Overhead/;
1052   }
1053
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}";
1063           
1064           if ($form->{id}) {
1065             if ($form->{amount}{$ref->{accno}}) {
1066               $form->{"IC_tax_$ref->{accno}"} = "checked";
1067             }
1068           } else {
1069             $form->{"IC_tax_$ref->{accno}"} = "checked";
1070           }
1071         }
1072       } else {
1073
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}";
1077         }
1078         
1079       }
1080     }
1081   }
1082   chop $form->{taxaccounts};
1083
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};
1089   }
1090   
1091   delete $form->{IC_links};
1092   delete $form->{amount};
1093
1094   $form->get_partsgroup(\%myconfig, {all => 1});
1095   $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1096   
1097   if (@{ $form->{all_partsgroup} }) {
1098     $form->{selectpartsgroup} = qq|<option>\n|;
1099
1100     map { $form->{selectpartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
1101   }
1102
1103   if ($form->{item} eq 'assembly') {
1104
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"}|;
1108       }
1109     }
1110     
1111     $form->get_partsgroup(\%myconfig);
1112
1113     if (@{ $form->{all_partsgroup} }) {
1114       $form->{selectassemblypartsgroup} = qq|<option>\n|;
1115
1116       map { $form->{selectassemblypartsgroup} .= qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n| } @{ $form->{all_partsgroup} };
1117     }
1118   }
1119   
1120   # setup make and models
1121   $i = 1;
1122   foreach $ref (@{ $form->{makemodels} }) {
1123     map { $form->{"${_}_$i"} = $ref->{$_} } qw(make model);
1124     $i++;
1125   }
1126   $form->{makemodel_rows} = $i - 1;
1127
1128   
1129   # setup vendors
1130   if (@{ $form->{all_vendor} }) {
1131     $form->{selectvendor} = "<option>\n";
1132     map { $form->{selectvendor} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } @{ $form->{all_vendor} };
1133   }
1134
1135   # vendor matrix
1136   $i = 1;
1137   foreach $ref (@{ $form->{vendormatrix} }) {
1138     $form->{"vendor_$i"} = qq|$ref->{name}--$ref->{id}|;
1139
1140     map { $form->{"${_}_$i"} = $ref->{$_} } qw(partnumber lastcost leadtime vendorcurr);
1141     $i++;
1142   }
1143   $form->{vendor_rows} = $i - 1;
1144   
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} };
1149   }
1150
1151   if (@{ $form->{all_pricegroup} }) {
1152     $form->{selectpricegroup} = "<option>\n";
1153     map { $form->{selectpricegroup} .= qq|<option value="$_->{pricegroup}--$_->{id}">$_->{pricegroup}\n| } @{ $form->{all_pricegroup} };
1154   }
1155
1156   $i = 1;
1157   # customer matrix
1158   foreach $ref (@{ $form->{customermatrix} }) {
1159
1160     $form->{"customer_$i"} = "$ref->{name}--$ref->{cid}" if $ref->{cid};
1161     $form->{"pricegroup_$i"} = "$ref->{pricegroup}--$ref->{gid}" if $ref->{gid};
1162
1163     map { $form->{"${_}_$i"} = $ref->{$_} } qw(validfrom validto pricebreak customerprice customercurr);
1164
1165     $i++;
1166     
1167   }
1168   $form->{customer_rows} = $i - 1;
1169
1170 }
1171
1172
1173
1174 sub form_header {
1175
1176   ($dec) = ($form->{sellprice} =~ /\.(\d+)/);
1177   $dec = length $dec;
1178   my $decimalplaces = ($dec > 2) ? $dec : 2;
1179
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);
1183   }
1184   
1185   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces)} qw(listprice sellprice);
1186   
1187   ($dec) = ($form->{lastcost} =~ /\.(\d+)/);
1188   $dec = length $dec;
1189   my $decimalplaces = ($dec > 2) ? $dec : 2;
1190
1191   $form->{lastcost} = $form->format_amount(\%myconfig, $form->{lastcost}, $decimalplaces);
1192
1193   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) } qw(weight rop stock);
1194   
1195   map { $form->{$_} = $form->quote($form->{$_}) } qw(partnumber description unit notes);
1196
1197   if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
1198     $rows = 2;
1199   }
1200   
1201   $notes = qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
1202
1203   if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
1204     $description = qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
1205   } else {
1206     $description = qq|<input name=description size=40 value="$form->{description}">|;
1207   }
1208   
1209   foreach $item (split / /, $form->{taxaccounts}) {
1210     $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : "";
1211   }
1212
1213
1214   # set option
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}/;
1220       } else {
1221         $form->{"select$item"} = qq|<option selected>$form->{$item}|;
1222       }
1223     }
1224   }
1225
1226   if ($form->{selectpartsgroup}) {
1227     $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
1228
1229     $partsgroup = qq|<input type=hidden name=selectpartsgroup value="|.$form->escape($form->{selectpartsgroup},1).qq|">|;
1230     
1231     $form->{selectpartsgroup} =~ s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
1232
1233     $partsgroup .= qq|<select name=partsgroup>$form->{selectpartsgroup}</select>|;
1234     $group = $locale->text('Group');
1235   }
1236
1237   # tax fields
1238   foreach $item (split / /, $form->{taxaccounts}) {
1239     $tax .= qq|
1240       <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}>&nbsp;<b>$form->{"IC_tax_${item}_description"}</b>
1241       <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
1242 |;
1243   }
1244
1245   $form->{obsolete} = "checked" if $form->{obsolete};
1246   
1247   $sellprice = qq|
1248               <tr>
1249                 <th align="right" nowrap="true">|.$locale->text('List Price').qq|</th>
1250                 <td><input name=listprice size=11 value=$form->{listprice}></td>
1251               </tr>
1252               <tr>
1253                 <th align="right" nowrap="true">|.$locale->text('Sell Price').qq|</th>
1254                 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
1255               </tr>
1256 |;
1257
1258   $lastcost = qq|
1259               <tr>
1260                 <th align="right" nowrap="true">|.$locale->text('Cost').qq|</th>
1261                 <td><input name=lastcost size=11 value=$form->{lastcost}></td>
1262               </tr>
1263               <tr>
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>
1267               </tr>
1268 |;
1269  
1270   if ($form->{item} eq "part") {
1271
1272     $linkaccounts = qq|
1273               <tr>
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}">
1277               </tr>
1278               <tr>
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}">
1282               </tr>
1283               <tr>
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}">
1287               </tr>
1288 |;
1289   
1290     if ($tax) {
1291       $linkaccounts .= qq|
1292               <tr>
1293                 <th align=right>|.$locale->text('Tax').qq|</th>
1294                 <td>$tax</td>
1295               </tr>
1296 |;
1297     }
1298   
1299     $weight = qq|
1300               <tr>
1301                 <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
1302                 <td>
1303                   <table>
1304                     <tr>
1305                       <td>
1306                         <input name=weight size=10 value=$form->{weight}>
1307                       </td>
1308                       <th>
1309                         &nbsp;
1310                         $form->{weightunit}
1311                         <input type=hidden name=weightunit value=$form->{weightunit}>
1312                       </th>
1313                     </tr>
1314                   </table>
1315                 </td>
1316               </tr>
1317 |;
1318     
1319   }
1320
1321
1322   if ($form->{item} eq "assembly") {
1323     
1324     $lastcost = qq|
1325               <tr>
1326                 <th align="right" nowrap="true">|.$locale->text('Cost').qq|</th> 
1327                 <td><input type=hidden name=lastcost value=$form->{lastcost}>$form->{lastcost}</td>
1328               </tr>
1329               <tr>
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>
1333               </tr>
1334 |;
1335
1336     $linkaccounts = qq|
1337 <!--
1338               <tr>
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}">
1342               </tr>
1343 -->
1344               <tr>
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}">
1348               </tr>
1349 |;
1350   
1351     if ($tax) {
1352       $linkaccounts .= qq|
1353               <tr>
1354                 <th align=right>|.$locale->text('Tax').qq|</th>
1355                 <td>$tax</td>
1356               </tr>
1357 |;
1358     }
1359   
1360     $weight = qq|
1361               <tr>
1362                 <th align="right" nowrap="true">|.$locale->text('Weight').qq|</th>
1363                 <td>
1364                   <table>
1365                     <tr>
1366                       <td>
1367                         &nbsp;$form->{weight}
1368                         <input type=hidden name=weight value=$form->{weight}>
1369                       </td>
1370                       <th>
1371                         &nbsp;
1372                         $form->{weightunit}
1373                         <input type=hidden name=weightunit value=$form->{weightunit}>
1374                       </th>
1375                     </tr>
1376                   </table>
1377                 </td>
1378               </tr>
1379 |;
1380     
1381   }
1382
1383  
1384   if ($form->{item} eq "service") {
1385     
1386     $linkaccounts = qq|
1387               <tr>
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}">
1391               </tr>
1392               <tr>
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}">
1396               </tr>
1397 |;
1398   
1399     if ($tax) {
1400       $linkaccounts .= qq|
1401               <tr>
1402                 <th align=right>|.$locale->text('Tax').qq|</th>
1403                 <td>$tax</td>
1404               </tr>
1405 |;
1406     }
1407
1408   }
1409
1410   if ($form->{item} eq "labor") {
1411     $lastcost = "";
1412     $sellprice = qq|
1413               <tr>
1414                 <th align="right" nowrap="true">|.$locale->text('Amount').qq|</th>
1415                 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
1416               </tr>
1417 |;
1418
1419     $linkaccounts = qq|
1420               <tr>
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}">
1424               </tr>
1425               <tr>
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}">
1429               </tr>
1430 |;
1431   
1432   }
1433
1434
1435   if ($form->{item} =~ /(part|assembly)/) {
1436     $n = ($form->{onhand} > 0) ? "1" : "0";
1437     $rop = qq|
1438               <tr>
1439                 <th align="right" nowrap>|.$locale->text('On Hand').qq|</th>
1440                 <th align=left nowrap class="plus$n">&nbsp;|.$form->format_amount(\%myconfig, $form->{onhand}).qq|</th>
1441               </tr>
1442 |;
1443
1444     if ($form->{item} eq 'assembly') {
1445       $rop .= qq|
1446               <tr>
1447                 <th align="right" nowrap>|.$locale->text('Stock').qq|</th>
1448                 <td><input name=stock size=10 value=$form->{stock}></td>
1449               </tr>
1450 |;
1451     }
1452
1453     $rop .= qq|
1454               <tr>
1455                 <th align="right" nowrap="true">|.$locale->text('ROP').qq|</th>
1456                 <td><input name=rop size=10 value=$form->{rop}></td>
1457               </tr>
1458 |;
1459     
1460     $bin = qq|
1461               <tr>
1462                 <th align="right" nowrap="true">|.$locale->text('Bin').qq|</th>
1463                 <td><input name=bin size=10 value=$form->{bin}></td>
1464               </tr>
1465 |;
1466     
1467     $imagelinks = qq|
1468   <tr>
1469     <td>
1470       <table width=100%>
1471         <tr>
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>
1476         </tr>
1477         <tr>
1478           <th align=right nowrap>|.$locale->text('Drawing').qq|</th>
1479           <td><input name=drawing size=40 value="$form->{drawing}"></td>
1480         </tr>
1481       </table>
1482     </td>
1483   </tr>
1484 |;
1485
1486   }
1487
1488   if ($form->{id}) {
1489     $obsolete = qq|
1490               <tr>
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>
1493               </tr>
1494 |;
1495   }
1496
1497
1498 # type=submit $locale->text('Edit Part')
1499 # type=submit $locale->text('Edit Service')
1500 # type=submit $locale->text('Edit Assembly')
1501
1502
1503   $form->header;
1504
1505   print qq|
1506 <body>
1507
1508 <form method=post action="$form->{script}#end">
1509
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}>
1520
1521 <table width="100%">
1522   <tr>
1523     <th class=listtop>$form->{title}</th>
1524   </tr>
1525   <tr height="5"></tr>
1526   <tr>
1527     <td>
1528       <table width="100%">
1529         <tr valign=top>
1530           <th align=left>|.$locale->text('Number').qq|</th>
1531           <th align=left>|.$locale->text('Description').qq|</th>
1532           <th align=left>$group</th>
1533         </tr>
1534         <tr valign=top>
1535           <td><input name=partnumber value="$form->{partnumber}" size=20></td>
1536           <td>$description</td>
1537           <td>$partsgroup</td>
1538         </tr>
1539       </table>
1540     </td>
1541   </tr>
1542   <tr>
1543     <td>
1544       <table width="100%" height="100%">
1545         <tr valign=top>
1546           <td width=70%>
1547             <table width="100%" height="100%">
1548               <tr class="listheading">
1549                 <th class="listheading" align="center" colspan=2>|.$locale->text('Link Accounts').qq|</th>
1550               </tr>
1551               $linkaccounts
1552               <tr>
1553                 <th align="left">|.$locale->text('Notes').qq|</th>
1554               </tr>
1555               <tr>
1556                 <td colspan=2>
1557                   $notes
1558                 </td>
1559               </tr>
1560             </table>
1561           </td>
1562           <td width="30%">
1563             <table width="100%">
1564               <tr>
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>    
1567               </tr>
1568               $sellprice
1569               $lastcost
1570               <tr>
1571                 <th align="right" nowrap="true">|.$locale->text('Unit').qq|</th>
1572                 <td><input name=unit size=5 value="$form->{unit}"></td>
1573               </tr>
1574               $weight
1575               $rop
1576               $bin
1577               $obsolete
1578             </table>
1579           </td>
1580         </tr>
1581       </table>
1582     </td>
1583   </tr>
1584   $imagelinks
1585 |;
1586 }
1587
1588
1589 sub form_footer {
1590
1591   print qq|
1592   <tr>
1593     <td><hr size=3 noshade></td>
1594   </tr>
1595 </table>
1596
1597 <input type=hidden name=customer_rows value=$form->{customer_rows}>
1598 |;
1599
1600
1601   if ($form->{item} =~ /(part|assembly)/) {
1602     print qq|
1603       <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
1604 |;
1605   }
1606   
1607   if ($form->{item} =~ /(part|service)/) {
1608     print qq|
1609       <input type=hidden name=vendor_rows value=$form->{vendor_rows}>
1610 |;
1611   }
1612
1613
1614   if (! $form->{readonly}) {
1615     print qq|
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|">|;
1618
1619     if ($form->{id}) {
1620
1621       if (!$form->{isassemblyitem}) {
1622         print qq|
1623         <input class=submit type=submit name=action value="|.$locale->text('Save as new').qq|">|;
1624       }
1625
1626       if ($form->{orphaned}) {
1627         print qq|
1628         <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">|;
1629       }
1630     }
1631   }
1632
1633   if ($form->{menubar}) {
1634     require "$form->{path}/menu.pl";
1635     &menubar;
1636   }
1637
1638   &assembly_row(++$form->{assembly_rows}) if $form->{item} eq 'assembly';
1639
1640   print qq|
1641
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}>
1648
1649 </form>
1650
1651 <a name="end"></a>
1652
1653 </body>
1654 </html>
1655 |;
1656
1657 }
1658
1659
1660
1661 sub makemodel_row {
1662   my ($numrows) = @_;
1663
1664   map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(make model);
1665
1666   print qq|
1667   <tr>
1668     <td>
1669       <table width=100%>
1670         <tr>
1671           <th class="listheading">|.$locale->text('Make').qq|</th>
1672           <th class="listheading">|.$locale->text('Model').qq|</th>
1673         </tr>
1674 |;
1675
1676   for $i (1 .. $numrows) {
1677     print qq|
1678         <tr>
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>
1681         </tr>
1682 |;
1683   }
1684
1685   print qq|
1686       </table>
1687     </td>
1688   </tr>
1689 |;
1690
1691 }
1692
1693
1694 sub vendor_row {
1695   my ($numrows) = @_;
1696
1697   $form->{selectvendor} = $form->unescape($form->{selectvendor});
1698   print qq|
1699   <input type=hidden name=selectvendor value="|.$form->escape($form->{selectvendor},1).qq|">
1700   
1701   <tr>
1702     <td>
1703       <table width=100%>
1704         <tr>
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>
1710         </tr>
1711 |;
1712
1713   for $i (1 .. $numrows) {
1714     
1715     $form->{selectcurrency} =~ s/ selected//;
1716    
1717     if ($i == $numrows) {
1718      
1719       $vendor = qq|
1720           <td><input name="vendor_$i" size=35 value="$form->{"vendor_$i"}"></td>
1721 |;
1722  
1723       if ($form->{selectvendor}) {
1724         $vendor = qq|
1725           <td width=99%><select name="vendor_$i">$form->{selectvendor}</select></td>
1726 |;
1727       }
1728    
1729     } else {
1730       
1731       $form->{selectcurrency} =~ s/option>$form->{"vendorcurr_$i"}/option selected>$form->{"vendorcurr_$i"}/;
1732  
1733       ($vendor) = split /--/, $form->{"vendor_$i"};
1734       $vendor = qq|
1735           <td>$vendor
1736           <input type=hidden name="vendor_$i" value="$form->{"vendor_$i"}">
1737           </td>
1738 |;
1739
1740     }
1741    
1742     print qq|
1743         <tr>
1744           $vendor
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>
1749         </tr>
1750 |;
1751       
1752   }
1753
1754   print qq|
1755       </table>
1756     </td>
1757   </tr>
1758 |;
1759
1760 }
1761
1762
1763 sub customer_row {
1764   my ($numrows) = @_;
1765
1766   if ($form->{selectpricegroup}) {
1767     $pricegroup = qq|
1768           <th class="listheading">|.$locale->text('Pricegroup').qq|
1769           </th>
1770 |;
1771   }
1772
1773   $form->{selectcustomer} = $form->unescape($form->{selectcustomer});
1774   $form->{selectpricegroup} = $form->unescape($form->{selectpricegroup});
1775   
1776   print qq|
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|">
1780   
1781   <tr>
1782     <td>
1783       <table width=100%>
1784         <tr>
1785           <th class="listheading">|.$locale->text('Customer').qq|</th>
1786           $pricegroup
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>
1792         </tr>
1793 |;
1794
1795   for $i (1 .. $numrows) {
1796     
1797     $form->{selectcurrency} =~ s/ selected//;
1798     $form->{selectcurrency} =~ s/option>$form->{"customercurr_$i"}/option selected>$form->{"customercurr_$i"}/;
1799     
1800     if ($i == $numrows) {
1801       $customer = qq|
1802           <td><input name="customer_$i" size=35 value="$form->{"customer_$i"}"></td>
1803           |;
1804   
1805       if ($form->{selectcustomer}) {
1806         $customer = qq|
1807           <td><select name="customer_$i">$form->{selectcustomer}</select></td>
1808 |;
1809       }
1810
1811       if ($form->{selectpricegroup}) {
1812         $pricegroup = qq|
1813           <td><select name="pricegroup_$i">$form->{selectpricegroup}</select></td>
1814 |;
1815       }
1816
1817     } else {
1818       ($customer) = split /--/, $form->{"customer_$i"};
1819       $customer = qq|
1820           <td>$customer</td>
1821           <input type=hidden name="customer_$i" value="$form->{"customer_$i"}">
1822           |;
1823
1824       if ($form->{selectpricegroup}) {
1825         ($pricegroup) = split /--/, $form->{"pricegroup_$i"};
1826         $pricegroup = qq|
1827           <td>$pricegroup</td>
1828           <input type=hidden name="pricegroup_$i" value="$form->{"pricegroup_$i"}">
1829 |;
1830       }
1831     }
1832     
1833     
1834     print qq|
1835         <tr>
1836           $customer
1837           $pricegroup
1838
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>
1844         </tr>
1845 |;
1846   }
1847
1848   print qq|
1849       </table>
1850     </td>
1851   </tr>
1852 |;
1853
1854 }
1855
1856
1857
1858 sub assembly_row {
1859   my ($numrows) = @_;
1860
1861   @column_index = qw(runningnumber qty unit bom adj partnumber description listprice sellprice lastcost);
1862   
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);
1866   }
1867   
1868   delete $form->{previousform};
1869
1870   # change callback
1871   $form->{old_callback} = $form->{callback};
1872   $callback = $form->{callback};
1873   $form->{callback} = "$form->{script}?action=display_form";
1874
1875   # delete action
1876   map { delete $form->{$_} } qw(action header);
1877
1878   $form->{baseassembly} = 0;
1879   $previousform = "";
1880   # save form variables in a previousform variable
1881   foreach $key (sort keys %$form) {
1882     # escape ampersands
1883     $form->{$key} =~ s/&/%26/g;
1884     $previousform .= qq|$key=$form->{$key}&|;
1885   }
1886   chop $previousform;
1887   $form->{previousform} = $form->escape($previousform, 1);
1888
1889   $form->{sellprice} = 0;
1890   $form->{listprice} = 0;
1891   $form->{lastcost} = 0;
1892   $form->{weight} = 0;
1893
1894   $form->{callback} = $callback;
1895
1896
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>|;
1908   
1909   print qq|
1910   <p>
1911
1912   <table width=100%>
1913   <tr class=listheading>
1914     <th class=listheading>|.$locale->text('Individual Items').qq|</th>
1915   </tr>
1916   <tr>
1917     <td>
1918       <table width=100%>
1919         <tr>
1920 |;
1921
1922   map { print "\n$column_header{$_}" } @column_index;
1923   
1924   print qq|
1925         </tr>
1926 |;
1927
1928
1929   for $i (1 .. $numrows) {
1930     $form->{"partnumber_$i"} = $form->quote($form->{"partnumber_$i"});
1931
1932     $linetotalsellprice = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
1933     $form->{sellprice} += $linetotalsellprice;
1934     
1935     $linetotallistprice = $form->round_amount($form->{"listprice_$i"} * $form->{"qty_$i"}, 2);
1936     $form->{listprice} += $linetotallistprice;
1937
1938     $linetotallastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"}, 2);
1939     $form->{lastcost} += $linetotallastcost;
1940
1941
1942     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
1943
1944     $linetotalsellprice = $form->format_amount(\%myconfig, $linetotalsellprice, 2);
1945     $linetotallistprice = $form->format_amount(\%myconfig, $linetotallistprice, 2);
1946     $linetotallastcost = $form->format_amount(\%myconfig, $linetotallastcost, 2);
1947
1948     if ($i == $numrows) {
1949
1950       map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom adj);
1951
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>|;
1956
1957     } else {
1958       
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"}">|;
1961         
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>|;
1964
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>|;
1968
1969       ($partsgroup) = split /--/, $form->{"partsgroup_$i"};
1970       $column_data{partsgroup} = qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$partsgroup</td>|;
1971
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>|;
1974       
1975     }
1976     
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>|;
1980     
1981     print qq|
1982         <tr>|;
1983
1984     map { print "\n$column_data{$_}" } @column_index;
1985     
1986     print qq|
1987         </tr>
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"}>
1994 |;
1995   }
1996
1997   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
1998
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>";
2002   
2003   print qq|
2004         <tr>|;
2005
2006   map { print "\n$column_data{$_}" } @column_index;
2007     
2008   print qq|
2009         </tr>
2010       </table>
2011     </td>
2012   </tr>
2013   <tr>
2014     <td><hr size=3 noshade></td>
2015   </tr>
2016   </table>
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|">
2020 |;
2021  
2022 }
2023
2024
2025 sub edit_assemblyitem {
2026
2027   $pn = substr($form->{action}, 1);
2028
2029   for ($i = 1; $i < $form->{assembly_rows}; $i++) {
2030     last if $form->{"partnumber_$i"} eq $pn;
2031   }
2032
2033   $form->error($local->text('unexpected error!')) unless $i;
2034   
2035   $form->{baseassembly} = ($form->{baseassembly}) ? $form->{baseassembly} : $form->{"assembly_$i"};
2036
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}|;
2038
2039   $form->redirect;
2040   
2041 }
2042
2043
2044 sub update {
2045
2046   if ($form->{item} eq "assembly") {
2047
2048     $i = $form->{assembly_rows};
2049     
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 "")) {
2052       
2053       &check_form;
2054       
2055     } else {
2056
2057       IC->assembly_item(\%myconfig, \%$form);
2058
2059       $rows = scalar @{ $form->{item_list} };
2060       
2061       if ($rows) {
2062         $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2063         $form->{"adj_$i"} = 1;
2064         
2065         if ($rows > 1) {
2066           $form->{makemodel_rows}--;
2067           $form->{customer_rows}--;
2068           &select_item;
2069           exit;
2070         } else {
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] };
2073
2074           if ($form->{item_list}[0]{partsgroup_id}) {
2075             $form->{"partsgroup_$i"} = qq|$form->{item_list}[0]{partsgroup}--$form->{item_list}[0]{partsgroup_id}|;
2076           }
2077           
2078           $form->{"runningnumber_$i"} = $form->{assembly_rows};
2079           $form->{assembly_rows}++;
2080
2081           &check_form;
2082
2083         }
2084
2085       } else {
2086
2087         $form->{rowcount} = $i;
2088         $form->{assembly_rows}++;
2089         
2090         &new_item;
2091
2092       }
2093     }
2094
2095   } else {
2096   
2097     &check_form;
2098
2099   }
2100
2101 }
2102
2103
2104 sub check_vendor {
2105   
2106   @flds = qw(vendor partnumber lastcost leadtime);
2107   @a = (); 
2108   $count = 0; 
2109
2110   map { $form->{"${_}_$form->{vendor_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{vendor_rows}"}) } qw(lastcost leadtime);
2111   
2112   for $i (1 .. $form->{vendor_rows} - 1) {
2113     
2114     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(lastcost leadtime);
2115     
2116     if ($form->{"lastcost_$i"} || $form->{"partnumber_$i"}) {
2117
2118       push @a, {};
2119       $j = $#a; 
2120       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2121       $count++;
2122
2123     } 
2124   }
2125   
2126   $i = $form->{vendor_rows};
2127   
2128   if (!$form->{selectvendor}) {
2129
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);
2134         exit;
2135       }
2136
2137       if ($j == 1) {
2138         # we got one name
2139         $form->{"vendor_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
2140       } else {
2141         # name is not on file
2142         $form->error(qq|$form->{"vendor_$i"} : |.$locale->text('Vendor not on file!'));
2143       }
2144     }
2145   }
2146
2147   if ($form->{"vendor_$i"}) {
2148     push @a, {};
2149     $j = $#a; 
2150     map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2151     $count++;
2152   }
2153
2154   $form->redo_rows(\@flds, \@a, $count, $form->{vendor_rows});
2155   $form->{vendor_rows} = $count;
2156
2157 }
2158
2159
2160 sub check_customer {
2161   
2162   @flds = qw(customer validfrom validto pricebreak customerprice pricegroup);
2163   @a = (); 
2164   $count = 0;
2165
2166   map { $form->{"${_}_$form->{customer_rows}"} = $form->parse_amount(\%myconfig, $form->{"${_}_$form->{customer_rows}"}) } qw(customerprice pricebreak);
2167
2168   for $i (1 .. $form->{customer_rows} - 1) {
2169
2170     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(customerprice pricebreak);
2171     
2172     if ($form->{"customerprice_$i"}) {
2173       if ($form->{"pricebreak_$i"} || $form->{"customer_$i"} || $form->{"pricegroup_$i"}) {
2174         
2175         push @a, {};
2176         $j = $#a; 
2177         map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2178         $count++;
2179         
2180       }
2181     }
2182   }
2183
2184   $i = $form->{customer_rows};
2185
2186   if (!$form->{selectcustomer}) {
2187
2188     if ($form->{"customer_$i"}) {
2189       ($form->{customer}) = split /--/, $form->{"customer_$i"};
2190
2191       if (($j = $form->get_name(\%myconfig, customer)) > 1) {
2192         &select_name(customer, $i);
2193         exit;
2194       }
2195
2196       if ($j == 1) {
2197         # we got one name
2198         $form->{"customer_$i"} = qq|$form->{name_list}[0]->{name}--$form->{name_list}[0]->{id}|;
2199       } else {
2200         # name is not on file
2201         $form->error(qq|$form->{customer} : |.$locale->text('Customer not on file!'));
2202       }
2203     }
2204   }
2205
2206   if ($form->{"customer_$i"} || $form->{"pricegroup_$i"} || ($form->{"customerprice_$i"} || $form->{"pricebreak_$i"})) {
2207     push @a, {};
2208     $j = $#a; 
2209     map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2210     $count++;
2211   }
2212
2213   $form->redo_rows(\@flds, \@a, $count, $form->{customer_rows});
2214   $form->{customer_rows} = $count;
2215
2216 }
2217
2218
2219
2220 sub select_name {
2221   my ($table, $vr) = @_;
2222   
2223   @column_index = qw(ndx name address);
2224
2225   $label = ucfirst $table;
2226   $column_data{ndx} = qq|<th>&nbsp;</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>|;
2229   
2230   # list items with radio button on a form
2231   $form->header;
2232
2233   $title = $locale->text('Select from one of the names below');
2234
2235   print qq|
2236 <body>
2237
2238 <form method=post action="$form->{script}#end">
2239
2240 <input type=hidden name=vr value=$vr>
2241
2242 <table width=100%>
2243   <tr>
2244     <th class=listtop>$title</th>
2245   </tr>
2246   <tr space=5></tr>
2247   <tr>
2248     <td>
2249       <table width=100%>
2250         <tr class=listheading>|;
2251
2252   map { print "\n$column_data{$_}" } @column_index;
2253   
2254   print qq|
2255         </tr>
2256 |;
2257
2258   my $i = 0;
2259   foreach $ref (@{ $form->{name_list} }) {
2260     $checked = ($i++) ? "" : "checked";
2261
2262     $ref->{name} = $form->quote($ref->{name});
2263     
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>|;
2267     
2268     $j++; $j %= 2;
2269     print qq|
2270         <tr class=listrow$j>|;
2271
2272     map { print "\n$column_data{$_}" } @column_index;
2273
2274     print qq|
2275         </tr>
2276
2277 <input name="new_id_$i" type=hidden value=$ref->{id}>
2278
2279 |;
2280
2281   }
2282   
2283   print qq|
2284       </table>
2285     </td>
2286   </tr>
2287   <tr>
2288     <td><hr size=3 noshade></td>
2289   </tr>
2290 </table>
2291
2292 <input name=lastndx type=hidden value=$i>
2293
2294 |;
2295
2296   # delete variables
2297   map { delete $form->{$_} } qw(action name_list header);
2298
2299   $form->hide_form();
2300   
2301   print qq|
2302 <input type=hidden name=nextsub value=name_selected>
2303
2304 <input type=hidden name=vc value=$table>
2305 <br>
2306 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2307 </form>
2308
2309 </body>
2310 </html>
2311 |;
2312
2313 }
2314
2315
2316
2317 sub name_selected {
2318
2319   # replace the variable with the one checked
2320
2321   # index for new item
2322   $i = $form->{ndx};
2323   
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"};
2326
2327   # delete all the new_ variables
2328   for $i (1 .. $form->{lastndx}) {
2329     map { delete $form->{"new_${_}_$i"} } (id, name);
2330   }
2331   
2332   map { delete $form->{$_} } qw(ndx lastndx nextsub);
2333
2334   &update;
2335
2336 }
2337
2338
2339 sub save {
2340
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});
2343   }
2344
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!')
2348
2349   $olditem = $form->{id};
2350
2351   # save part
2352   $rc = IC->save(\%myconfig, \%$form);
2353
2354   $parts_id = $form->{id};
2355
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;
2360
2361     $previousform = $form->unescape($form->{previousform});
2362     $baseassembly = $form->{baseassembly};
2363
2364     # don't trample on previous variables
2365     map { delete $form->{$_} } keys %newform;
2366
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;
2372     }
2373
2374
2375     if ($form->{item} eq 'assembly') {
2376
2377       if ($baseassembly) {
2378         #redo the assembly
2379         $previousform =~ /\&id=(\d+)/;
2380         $form->{id} = $1;
2381         
2382         # restore original callback
2383         $form->{callback} = $form->unescape($form->{old_callback});
2384
2385         &edit;
2386         exit;
2387       }
2388         
2389       # undo number formatting
2390       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(weight listprice sellprice lastcost rop);
2391
2392       $form->{assembly_rows}-- if $olditem;
2393       $i = $newform{rowcount};
2394       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2395
2396       ($dec) = ($form->{listprice} =~ /\.(\d+)/);
2397       $dec = length $dec;
2398       $dec1 = ($dec > 2) ? $dec : 2;
2399  
2400       ($dec) = ($form->{sellprice} =~ /\.(\d+)/);
2401       $dec = length $dec;
2402       $dec2 = ($dec > 2) ? $dec : 2;
2403      
2404       ($dec) = ($form->{lastcost} =~ /\.(\d+)/);
2405       $dec = length $dec;
2406       $dec3 = ($dec > 2) ? $dec : 2;
2407
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"};
2412
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);
2415
2416       $form->{listprice} += $form->{"listprice_$i"} * $form->{"qty_$i"};
2417       $form->{listprice} = $form->round_amount($form->{listprice}, $dec1);
2418
2419       $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
2420       $form->{sellprice} = $form->round_amount($form->{sellprice}, $dec2);
2421       
2422       $form->{lastcost} += $form->{"lastcost_$i"} * $form->{"qty_$i"};
2423       $form->{lastcost} = $form->round_amount($form->{lastcost}, $dec3);
2424
2425       $form->{weight} += $form->{"weight_$i"} * $form->{"qty_$i"};
2426
2427       $form->{"adj_$i"} = 1 if !$olditem;
2428
2429       $form->{customer_rows}--;
2430       
2431     } else {
2432       # set values for last invoice/order item
2433       $i = $form->{rowcount};
2434       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2435
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});
2438
2439       if ($form->{exchangerate} != 0) {
2440         ($dec) = ($newform{sellprice} =~ /\.(\d+)/);
2441         $dec = length $dec;
2442         $decimalplaces = ($dec > 2) ? $dec : 2;
2443         
2444         $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} / $form->{exchangerate}, $decimalplaces);
2445       }
2446       
2447       map { $form->{"taxaccounts_$i"} .= "$_ " if ($newform{"IC_tax_$_"}) } split / /, $newform{taxaccounts};
2448       chop $form->{"taxaccounts_$i"};
2449
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};
2454
2455       $form->{creditremaining} -= $amount;
2456       
2457     }
2458     
2459     $form->{"id_$i"} = $parts_id;
2460     delete $form->{action};
2461
2462     # restore original callback
2463     $callback = $form->unescape($form->{callback});
2464     $form->{callback} = $form->unescape($form->{old_callback});
2465     delete $form->{old_callback};
2466
2467     $form->{makemodel_rows}--;
2468
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|;
2474     }
2475     $form->{callback} = $callback;
2476   }
2477
2478   # redirect
2479   $form->redirect;
2480
2481 }
2482
2483
2484 sub save_as_new {
2485
2486   $form->{id} = 0;
2487   &save;
2488
2489 }
2490
2491
2492 sub delete {
2493
2494   $rc = IC->delete(\%myconfig, \%$form);
2495   
2496   # redirect
2497   $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2498   $form->error($locale->text('Cannot delete item!'));
2499
2500 }
2501
2502
2503
2504 sub stock_assembly {
2505
2506   $form->{title} = $locale->text('Stock Assembly');
2507   
2508   $form->header;
2509   
2510   print qq|
2511 <body>
2512
2513 <form method=post action=$form->{script}>
2514
2515 <table width="100%">
2516   <tr>
2517     <th class=listtop>$form->{title}</th>
2518   </tr>
2519   <tr height="5"></tr>
2520   <tr valign=top>
2521     <td>
2522       <table>
2523         <tr>
2524           <th align="right" nowrap="true">|.$locale->text('Number').qq|</th>
2525           <td><input name=partnumber size=20></td>
2526           <td>&nbsp;</td>
2527         </tr>
2528         <tr>
2529           <th align="right" nowrap="true">|.$locale->text('Description').qq|</th>
2530           <td><input name=description size=40></td>
2531         </tr>
2532         <tr>
2533           <td></td>
2534           <td><input name=checkinventory class=checkbox type=checkbox value=1>&nbsp;|.$locale->text('Check Inventory').qq|</td>
2535         </tr>
2536       </table>
2537     </td>
2538   </tr>
2539   <tr><td><hr size=3 noshade></td></tr>
2540 </table>
2541
2542 <input type=hidden name=sort value=partnumber>
2543
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}>
2547
2548 <input type=hidden name=nextsub value=list_assemblies>
2549
2550 <br>
2551 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2552 </form>
2553
2554 </body>
2555 </html>
2556 |;
2557
2558 }
2559
2560
2561
2562
2563 sub list_assemblies {
2564
2565   IC->retrieve_assemblies(\%myconfig, \%$form);
2566
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}";
2568   
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}";
2571   
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};
2576   }
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};
2581   }
2582  
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>|;
2589
2590   @column_index = $form->sort_columns(qw(partnumber description bin onhand rop stock));
2591   
2592   $form->{title} = $locale->text('Stock Assembly');
2593
2594   
2595   $form->header;
2596   
2597
2598   print qq|
2599 <body>
2600
2601 <form method=post action=$form->{script}>
2602
2603 <table width=100%>
2604   <tr>
2605     <th class=listtop>$form->{title}</th>
2606   </tr>
2607   <tr size=5></tr>
2608   <tr>
2609     <td>
2610       <table width=100%>
2611         <tr class=listheading>
2612 |;
2613
2614   map { print "\n$column_header{$_}" } @column_index;
2615
2616   print qq|
2617         </tr>
2618 |;
2619
2620   # add sort and escape callback
2621   $form->{callback} = $callback .= "&sort=$form->{sort}";
2622
2623   # escape callback for href
2624   $callback = $form->escape($callback);
2625
2626
2627   $i = 1;
2628   foreach $ref (@{ $form->{assembly_items} }) {
2629
2630     map { $ref->{$_} = $form->quote($ref->{$_}) } qw(partnumber description);
2631    
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}&nbsp;</a></td>";
2633     
2634     $column_data{description} = qq|<td width=50%>$ref->{description}&nbsp;</td>|;
2635     $column_data{bin} = qq|<td>$ref->{bin}&nbsp;</td>|;
2636     $column_data{onhand} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{onhand}, "", "&nbsp;").qq|</td>|;
2637     $column_data{rop} = qq|<td align=right>|.$form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;").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}>|;
2640
2641     $j++; $j %= 2;
2642     print qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
2643     
2644     map { print "\n$column_data{$_}" } @column_index;
2645     
2646     print qq|
2647         </tr>
2648 |;
2649
2650     $i++;
2651
2652   }
2653   
2654   $i--;
2655   print qq|
2656       </td>
2657     </table>
2658   <tr>
2659     <td><hr size=3 noshade>
2660   </tr>
2661 </table>
2662
2663 <input name=rowcount type=hidden value="$i">
2664 <input type=hidden name=checkinventory value=$form->{checkinventory}>
2665
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}>
2669
2670 <input name=callback type=hidden value="$form->{callback}">
2671
2672 <input type=hidden name=nextsub value=restock_assemblies>
2673
2674 <br>
2675 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
2676
2677 </form>
2678
2679 </body>
2680 </html>
2681 |;
2682  
2683 }
2684
2685
2686 sub restock_assemblies {
2687
2688
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});
2691   }
2692
2693   $form->redirect($locale->text('Assemblies restocked!')) if (IC->restock_assemblies(\%myconfig, \%$form));
2694   $form->error($locale->text('Cannot stock assemblies!'));
2695   
2696 }
2697
2698
2699 sub continue { &{ $form->{nextsub} } };
2700
2701 sub add_part { &add };
2702 sub add_service { &add };
2703 sub add_assembly { &add };
2704 sub add_labor_overhead { &add };
2705
2706