b2a4da64a9da486cb8a38a97677ea9be11798207
[kivitendo-erp.git] / bin / mozilla / ic.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #=====================================================================
8 # SQL-Ledger, Accounting
9 # Copyright (c) 2001
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
29 #
30 # Inventory Control module
31 #
32 #======================================================================
33 #$locale->text('ea');
34
35 use SL::IC;
36
37 #use SL::PE;
38
39 require "$form->{path}/io.pl";
40
41 1;
42
43 # end of main
44
45 sub add {
46   $lxdebug->enter_sub();
47
48   $form->{title} = $locale->text('Add ' . ucfirst $form->{item});
49
50   $form->{callback} =
51     "$form->{script}?action=add&item=$form->{item}&path=$form->{path}&login=$form->{login}&password=$form->{password}"
52     unless $form->{callback};
53
54   $form->{unit} =
55     ($form->{item} eq 'service') ? $locale->text('hr') : $locale->text('ea');
56   IC->get_pricegroups(\%myconfig, \%$form);
57   &link_part;
58   &display_form;
59
60   $lxdebug->leave_sub();
61 }
62
63 sub search {
64   $lxdebug->enter_sub();
65
66   $form->{title} = (ucfirst $form->{searchitems}) . "s";
67   $form->{title} = $locale->text($form->{title});
68
69   # switch for backward sorting
70   $form->{revers} = 0;
71
72   # memory for which table was sort at last time
73   $form->{lastsort} = "";
74
75   # counter for added entries to top100
76   $form->{ndxs_counter} = 0;
77
78   # $locale->text('Parts')
79   # $locale->text('Services')
80
81   # use JavaScript Calendar or not
82   $form->{jsscript} = $jscalendar;
83   $jsscript = "";
84   if ($form->{jsscript}) {
85
86     # with JavaScript Calendar
87     $button1 = qq|
88        <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>
89        <td><input type=button name=transdatefrom id="trigger1" value=|
90       . $locale->text('button') . qq|></td>
91       |;
92     $button2 = qq|
93        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>
94        <td><input type=button name=transdateto name=transdateto id="trigger2" value=|
95       . $locale->text('button') . qq|></td>
96      |;
97
98     #write Trigger
99     $jsscript =
100       Form->write_trigger(\%myconfig, "2", "transdatefrom", "BL", "trigger1",
101                           "transdateto", "BL", "trigger2");
102   } else {
103
104     # without JavaScript Calendar
105     $button1 = qq|
106                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
107     $button2 = qq|
108                               <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
109   }
110
111   unless ($form->{searchitems} eq 'service') {
112
113     $onhand = qq|
114             <input name=itemstatus class=radio type=radio value=onhand>&nbsp;|
115       . $locale->text('On Hand') . qq|
116             <input name=itemstatus class=radio type=radio value=short>&nbsp;|
117       . $locale->text('Short') . qq|
118 |;
119
120     $makemodel = qq|
121         <tr>
122           <th align=right nowrap>| . $locale->text('Make') . qq|</th>
123           <td><input name=make size=20></td>
124           <th align=right nowrap>| . $locale->text('Model') . qq|</th>
125           <td><input name=model size=20></td>
126         </tr>
127 |;
128
129     $serialnumber = qq|
130           <th align=right nowrap>| . $locale->text('Serial Number') . qq|</th>
131           <td><input name=serialnumber size=20></td>
132 |;
133
134     $l_serialnumber = qq|
135         <td><input name=l_serialnumber class=checkbox type=checkbox value=Y>&nbsp;|
136       . $locale->text('Serial Number') . qq|</td>
137 |;
138
139   }
140
141   if ($form->{searchitems} eq 'assembly') {
142
143     $form->{title} = $locale->text('Assemblies');
144
145     $toplevel = qq|
146         <tr>
147           <td></td>
148           <td colspan=3>
149           <input name=null class=radio type=radio value=1 checked>&nbsp;|
150       . $locale->text('Top Level') . qq|
151           <input name=bom class=checkbox type=checkbox value=1>&nbsp;|
152       . $locale->text('Individual Items') . qq|
153           </td>
154         </tr>
155 |;
156
157     $bought = qq|
158         <tr>
159           <td></td>
160           <td colspan=3>
161             <table>
162               <tr>
163                 <td>
164                   <table>
165                     <tr>
166                       <td><input name=sold class=checkbox type=checkbox value=1></td>
167                       <td nowrap>| . $locale->text('Sold') . qq|</td>
168                     </tr>
169                     <tr>
170                       <td colspan=2><hr size=1 noshade></td>
171                     </tr>
172                     <tr>
173                       <td><input name=ordered class=checkbox type=checkbox value=1></td>
174                       <td nowrap>| . $locale->text('Ordered') . qq|</td>
175                     </tr>
176                     <tr>
177                       <td colspan=4><hr size=1 noshade></td>
178                     </tr>
179                     <tr>
180                       <td><input name=quoted class=checkbox type=checkbox value=1></td>
181                       <td nowrap>| . $locale->text('Quoted') . qq|</td>
182                     </tr>
183                   </table>
184                 </td>
185                 <td width=5%>&nbsp;</td>
186                 <th>| . $locale->text('From') . qq|</th>
187                 $button1
188                 <th>| . $locale->text('To') . qq|</th>
189                 $button2
190               </tr>
191             </table>
192           </td>
193         </tr>
194 |;
195
196   } else {
197
198     $bought = qq|
199         <tr>
200           <td></td>
201           <td colspan=3>
202             <table>
203               <tr>
204                 <td>
205                   <table>
206                     <tr>
207                       <td><input name=bought class=checkbox type=checkbox value=1></td>
208                       <td nowrap>| . $locale->text('Bought') . qq|</td>
209                       <td><input name=sold class=checkbox type=checkbox value=1></td>
210                       <td nowrap>| . $locale->text('Sold') . qq|</td>
211                     </tr>
212                     <tr>
213                       <td colspan=4><hr size=1 noshade></td>
214                     </tr>
215                     <tr>
216                       <td><input name=onorder class=checkbox type=checkbox value=1></td>
217                       <td nowrap>| . $locale->text('On Order') . qq|</td>
218                       <td><input name=ordered class=checkbox type=checkbox value=1></td>
219                       <td nowrap>| . $locale->text('Ordered') . qq|</td>
220                     </tr>
221                     <tr>
222                       <td colspan=4><hr size=1 noshade></td>
223                     </tr>
224                     <tr>
225                       <td><input name=rfq class=checkbox type=checkbox value=1></td>
226                       <td nowrap>| . $locale->text('RFQ') . qq|</td>
227                       <td><input name=quoted class=checkbox type=checkbox value=1></td>
228                       <td nowrap>| . $locale->text('Quoted') . qq|</td>
229                     </tr>
230                   </table>
231                 </td>
232                 <td width=5%>&nbsp;</td>
233                 <td>
234                   <table>
235                     <tr>
236                       <th>| . $locale->text('From') . qq|</th>
237                       $button1
238                       <th>| . $locale->text('To') . qq|</th>
239                       $button2
240                     </tr>
241                   </table>
242                 </td>
243               </tr>
244             </table>
245           </td>
246         </tr>
247 |;
248   }
249
250   $form->header;
251
252   print qq|
253 <body>
254
255 <form method=post action=$form->{script}>
256
257 <input type=hidden name=searchitems value=$form->{searchitems}>
258 <input type=hidden name=title value="$form->{title}">
259
260 <input type=hidden name=revers value="$form->{revers}">
261 <input type=hidden name=lastsort value="$form->{lastsort}">
262
263 <table width="100%">
264   <tr><th class=listtop>$form->{title}</th></tr>
265   <tr height="5"></tr>
266   <tr valign=top>
267     <td>
268       <table>
269         <tr>
270           <th align=right nowrap>| . $locale->text('Part Number') . qq|</th>
271           <td><input name=partnumber size=20></td>
272         </tr>
273         <tr>
274           <th align=right nowrap>|
275     . $locale->text('Part Description') . qq|</th>
276           <td colspan=3><input name=description size=40></td>
277         </tr>
278         <tr>
279           <th align=right nowrap>| . $locale->text('Group') . qq|</th>
280           <td><input name=partsgroup size=20></td>
281           $serialnumber
282         </tr>
283         $makemodel
284         <tr>
285           <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
286           <td><input name=drawing size=20></td>
287           <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
288           <td><input name=microfiche size=20></td>
289         </tr>
290         $toplevel
291         <tr>
292           <td></td>
293           <td colspan=3>
294             <input name=itemstatus class=radio type=radio value=active checked>&nbsp;|
295     . $locale->text('Active') . qq|
296             $onhand
297             <input name=itemstatus class=radio type=radio value=obsolete>&nbsp;|
298     . $locale->text('Obsolete') . qq|
299             <input name=itemstatus class=radio type=radio value=orphaned>&nbsp;|
300     . $locale->text('Orphaned') . qq|
301           </td>
302         </tr>
303         $bought
304         <tr>
305           <td></td>
306           <td colspan=3>
307             <hr size=1 noshade>
308           </td>
309         </tr>
310         <tr>
311           <th align=right nowrap>|
312     . $locale->text('Include in Report') . qq|</th>
313           <td colspan=3>
314             <table>
315               <tr>
316                 <td><input name=l_partnumber class=checkbox type=checkbox value=Y checked>&nbsp;|
317     . $locale->text('Part Number') . qq|</td>
318                 <td><input name=l_description class=checkbox type=checkbox value=Y checked>&nbsp;|
319     . $locale->text('Part Description') . qq|</td>
320                 $l_serialnumber
321                 <td><input name=l_unit class=checkbox type=checkbox value=Y checked>&nbsp;|
322     . $locale->text('Unit of measure') . qq|</td>
323               </tr>
324               <tr>
325                 <td><input name=l_listprice class=checkbox type=checkbox value=Y>&nbsp;|
326     . $locale->text('List Price') . qq|</td>
327                 <td><input name=l_sellprice class=checkbox type=checkbox value=Y checked>&nbsp;|
328     . $locale->text('Sell Price') . qq|</td>
329                 <td><input name=l_lastcost class=checkbox type=checkbox value=Y>&nbsp;|
330     . $locale->text('Last Cost') . qq|</td>
331                 <td><input name=l_linetotal class=checkbox type=checkbox value=Y checked>&nbsp;|
332     . $locale->text('Line Total') . qq|</td>
333               </tr>
334               <tr>
335                 <td><input name=l_priceupdate class=checkbox type=checkbox value=Y>&nbsp;|
336     . $locale->text('Updated') . qq|</td>
337                 <td><input name=l_bin class=checkbox type=checkbox value=Y>&nbsp;|
338     . $locale->text('Bin') . qq|</td>
339                 <td><input name=l_rop class=checkbox type=checkbox value=Y>&nbsp;|
340     . $locale->text('ROP') . qq|</td>
341                 <td><input name=l_weight class=checkbox type=checkbox value=Y>&nbsp;|
342     . $locale->text('Weight') . qq|</td>
343               </tr>
344               <tr>
345                 <td><input name=l_image class=checkbox type=checkbox value=Y>&nbsp;|
346     . $locale->text('Image') . qq|</td>
347                 <td><input name=l_drawing class=checkbox type=checkbox value=Y>&nbsp;|
348     . $locale->text('Drawing') . qq|</td>
349                 <td><input name=l_microfiche class=checkbox type=checkbox value=Y>&nbsp;|
350     . $locale->text('Microfiche') . qq|</td>
351                 <td><input name=l_partsgroup class=checkbox type=checkbox value=Y>&nbsp;|
352     . $locale->text('Group') . qq|</td>
353               </tr>
354               <tr>
355                 <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
356     . $locale->text('Subtotal') . qq|</td>
357                 <td><input name=l_soldtotal class=checkbox type=checkbox value=Y>&nbsp;|
358     . $locale->text('soldtotal') . qq|</td>
359                 <td><input name=l_deliverydate class=checkbox type=checkbox value=Y>&nbsp;|
360     . $locale->text('deliverydate') . qq|</td>    
361               </tr>
362             </table>
363           </td>
364         </tr>
365       </table>
366     </td>
367   </tr>
368   <tr><td colspan=4><hr size=3 noshade></td></tr>
369 </table>
370
371 $jsscript
372
373 <input type=hidden name=nextsub value=generate_report>
374
375 <input type=hidden name=path value=$form->{path}>
376 <input type=hidden name=login value=$form->{login}>
377 <input type=hidden name=password value=$form->{password}>
378
379 <input type=hidden name=revers value="$form->{revers}">
380 <input type=hidden name=lastsort value="$form->{lastsort}">
381
382 <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">
383
384 <br>
385 <input class=submit type=submit name=action value="|
386     . $locale->text('Continue') . qq|">
387 <input class=submit type=submit name=action value="|
388     . $locale->text('TOP100') . qq|">
389 </form>
390
391 </body>
392 </html>
393 |;
394   $lxdebug->leave_sub();
395 }    #end search()
396
397 sub choice {
398   $lxdebug->enter_sub();
399
400   $form->{title} = $locale->text('Top 100 hinzufuegen');
401
402   $form->header;
403
404   print qq|
405   <body>
406
407   <form method=post action=$form->{script}>
408
409   <input type=hidden name=searchitems value=$form->{searchitems}>
410   <input type=hidden name=title value="$form->{title}">
411
412   <input type=hidden name=revers value="$form->{revers}">
413   <input type=hidden name=lastsort value="$form->{lastsort}">|;
414
415   print qq|
416       <table>
417         <tr class=listheading>
418          <th class=listheading nowrap>|
419     . $locale->text('Part Number') . qq|</th>
420          <th class=listheading nowrap>|
421     . $locale->text('Part Description') . qq|</th>
422         </tr>
423         <tr valign=top>
424          <td><input type=text name=partnumber size=20 value=></td>
425          <td><input type=text name=description size=30 value=></td>
426        </tr>
427       </table>
428      <br>|;
429
430   print qq|
431
432 <input type=hidden name=path value=$form->{path}>
433 <input type=hidden name=login value=$form->{login}>
434 <input type=hidden name=password value=$form->{password}>
435
436 <input type=hidden name=itemstatus value="$form->{itemstatus}">
437 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
438 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
439 <input type=hidden name=l_description value="$form->{l_description}">
440 <input type=hidden name=l_onhand value="$form->{l_onhand}">
441 <input type=hidden name=l_unit value="$form->{l_unit}">
442 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
443 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
444 <input type=hidden name=sort value="$form->{sort}">
445 <input type=hidden name=revers value="$form->{revers}">
446 <input type=hidden name=lastsort value="$form->{lastsort}">
447
448 <input type=hidden name=bom value="$form->{bom}">
449 <input type=hidden name=titel value="$form->{titel}">
450 <input type=hidden name=searchitems value="$form->{searchitems}">
451
452 <input type=hidden name=row value=$j>
453
454 <input type=hidden name=nextsub value=item_selected>
455
456 <input type=hidden name=test value=item_selected>
457
458 <input name=lastndx type=hidden value=$lastndx>
459
460 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>
461
462 <input name=extras type=hidden value=$form->{extras}>|;
463
464   # if choice set data
465   if ($form->{ndx}) {
466     for ($i = 0; $i < $form->{ndxs_counter}; $i++) {
467
468       # prepeare data
469       $partnumber  = $form->{"totop100_partnumber_$j"};
470       $description = $form->{"totop100_description_$j"};
471       $unit        = $form->{"totop100_unit_$j"};
472       $sellprice   = $form->{"totop100_sellprice_$j"};
473       $soldtotal   = $form->{"totop100_soldtotal_$j"};
474
475       # insert data into top100
476       push @{ $form->{parts} },
477         { number      => "",
478           partnumber  => "$partnumber",
479           description => "$description",
480           unit        => "$unit",
481           sellprice   => "$sellprice",
482           soldtotal   => "$soldtotal" };
483     }    #rof
484   }    #fi
485
486   $totop100 = "";
487
488   # set data for next page
489   if (($form->{ndxs_counter}) > 0) {
490     for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
491       $partnumber  = $form->{"totop100_partnumber_$i"};
492       $description = $form->{"totop100_description_$i"};
493       $unit        = $form->{"totop100_unit_$i"};
494       $sellprice   = $form->{"totop100_sellprice_$i"};
495       $soldtotal   = $form->{"totop100_soldtotal_$i"};
496
497       $totop100 .= qq|
498 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
499 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
500 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
501 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
502 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
503       |;
504     }    #rof
505   }    #fi
506
507   print $totop100;
508
509   print qq|
510      <input class=submit type=submit name=action value="|
511     . $locale->text('list') . qq|">
512     </form>
513
514    </body>
515   </html>|;
516   $lxdebug->leave_sub();
517 }    #end choice
518
519 sub list {
520   $lxdebug->enter_sub();
521
522   # get parts for
523   if (($form->{partnumber} eq "") and ($form->{description} eq "")) {
524     IC->get_parts(\%myconfig, \%$form, "");
525   } else {
526     if ((!($form->{partnumber} eq "")) and ($form->{description} eq "")) {
527       IC->get_parts(\%myconfig, \%$form, "partnumber");
528     } else {
529       if (($form->{partnumber} eq "") and (!($form->{description} eq ""))) {
530         IC->get_parts(\%myconfig, \%$form, "description");
531       } else {
532         IC->get_parts(\%myconfig, \%$form, "all");
533       }    #fi
534     }    #fi
535   }    #fi
536
537   $form->{title} = $locale->text('Top 100 hinzufuegen');
538
539   $form->header;
540
541   print qq|
542 <body>
543   <form method=post action=ic.pl>
544     <table width=100%>
545      <tr>
546       <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
547      </tr>
548         <tr height="5"></tr>
549         <tr class=listheading>
550           <th>&nbsp;</th>
551           <th class=listheading>| . $locale->text('Part Number') . qq|</th>
552           <th class=listheading>| . $locale->text('Part Description') . qq|</th>
553           <th class=listheading>| . $locale->text('Unit of measure') . qq|</th>
554           <th class=listheading>| . $locale->text('Sell Price') . qq|</th>
555           <th class=listheading>| . $locale->text('soldtotal') . qq|</th>
556         </tr>|;
557
558   my $j = 0;
559   my $i = $form->{rows};
560
561   for ($j = 1; $j <= $i; $j++) {
562
563     print qq|
564         <tr class=listrow1>|;
565     if ($j == 1) {
566       print qq|
567             <td><input name=ndx class=radio type=radio value=$j checked></td>|;
568     } else {
569       print qq|
570           <td><input name=ndx class=radio type=radio value=$j></td>|;
571     }
572     print qq|
573           <td><input name="new_partnumber_$j" type=hidden value="$form->{"partnumber_$j"}">$form->{"partnumber_$j"}</td>
574           <td><input name="new_description_$j" type=hidden value="$form->{"description_$j"}">$form->{"description_$j"}</td>
575           <td><input name="new_unit_$j" type=hidden value="$form->{"unit_$j"}">$form->{"unit_$j"}</td>
576           <td><input name="new_sellprice_$j" type=hidden value="$form->{"sellprice_$j"}">$form->{"sellprice_$j"}</td>
577           <td><input name="new_soldtotal_$j" type=hidden value="$form->{"soldtotal_$j"}">$form->{"soldtotal_$j"}</td>
578         </tr>
579
580         <input name="new_id_$j" type=hidden value="$form->{"id_$j"}">|;
581   }
582
583   print qq|
584
585 </table>
586
587 <br>
588
589
590 <input type=hidden name=path value=$form->{path}>
591 <input type=hidden name=login value=$form->{login}>
592 <input type=hidden name=password value=$form->{password}>
593
594 <input type=hidden name=itemstatus value="$form->{itemstatus}">
595 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
596 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
597 <input type=hidden name=l_description value="$form->{l_description}">
598 <input type=hidden name=l_onhand value="$form->{l_onhand}">
599 <input type=hidden name=l_unit value="$form->{l_unit}">
600 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
601 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
602 <input type=hidden name=sort value="$form->{sort}">
603 <input type=hidden name=revers value="$form->{revers}">
604 <input type=hidden name=lastsort value="$form->{lastsort}">
605
606 <input type=hidden name=bom value="$form->{bom}">
607 <input type=hidden name=titel value="$form->{titel}">
608 <input type=hidden name=searchitems value="$form->{searchitems}">
609
610 <input type=hidden name=row value=$j>
611
612 <input type=hidden name=nextsub value=item_selected>
613
614 <input name=lastndx type=hidden value=$lastndx>
615
616 <input name=ndxs_counter type=hidden value=$form->{ndxs_counter}>|;
617
618   $totop100 = "";
619
620   if (($form->{ndxs_counter}) > 0) {
621     for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
622       $j1 = $form->{"totop100_partnumber_$i"};
623       $j2 = $form->{"totop100_description_$i"};
624       $j3 = $form->{"totop100_unit_$i"};
625       $j4 = $form->{"totop100_sellprice_$i"};
626       $j5 = $form->{"totop100_soldtotal_$i"};
627
628       $partnumber  = $j1;
629       $description = $j2;
630       $unit        = $j3;
631       $sellprice   = $j4;
632       $soldtotal   = $j5;
633
634       $totop100 .= qq|
635 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
636 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
637 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
638 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
639 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
640       |;
641     }    #rof
642   }    #fi
643
644   print $totop100;
645
646   print qq|
647 <input class=submit type=submit name=action value="|
648     . $locale->text('TOP100') . qq|">
649
650 </form>
651 </body>
652 </html>
653 |;
654   $lxdebug->leave_sub();
655 }    #end list()
656
657 sub top100 {
658   $lxdebug->enter_sub();
659
660   if ($form->{ndx}) {
661     $form->{ndxs_counter}++;
662
663     if ($form->{ndxs_counter} > 0) {
664
665       $index = $form->{ndx};
666
667       $j1 = $form->{"new_partnumber_$index"};
668       $form->{"totop100_partnumber_$form->{ndxs_counter}"} = $j1;
669       $j2 = $form->{"new_description_$index"};
670       $form->{"totop100_description_$form->{ndxs_counter}"} = $j2;
671       $j3 = $form->{"new_unit_$index"};
672       $form->{"totop100_unit_$form->{ndxs_counter}"} = $j3;
673       $j4 = $form->{"new_sellprice_$index"};
674       $form->{"totop100_sellprice_$form->{ndxs_counter}"} = $j4;
675       $j5 = $form->{"new_soldtotal_$index"};
676       $form->{"totop100_soldtotal_$form->{ndxs_counter}"} = $j5;
677     }    #fi
678   }    #fi
679   &addtop100();
680   $lxdebug->leave_sub();
681 }    #end top100
682
683 sub addtop100 {
684   $lxdebug->enter_sub();
685
686   $form->{top100}      = "top100";
687   $form->{l_soldtotal} = "Y";
688   $form->{soldtotal}   = "soldtotal";
689   $form->{sort}        = "soldtotal";
690   $form->{l_qty}       = "N";
691   $callback .= "&form->{top100}=$form->{top100}";
692   $form->{l_linetotal} = "";
693   $form->{revers}      = 1;
694   $form->{number}      = "position";
695   $form->{l_number}    = "Y";
696
697   my $totop100 = "";
698
699   $form->{title} = $locale->text('Top 100');
700
701   $revers   = $form->{revers};
702   $lastsort = $form->{lastsort};
703
704   if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
705     $form->{revers}   = 0;
706     $form->{lastsort} = "partnumber";
707     $form->{sort}     = "partnumber";
708   }    #fi
709
710   $callback =
711     "$form->{script}?action=top100&path=$form->{path}&login=$form->{login}&password=$form->{password}&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title="
712     . $form->escape($form->{title}, 1);
713
714   # if we have a serialnumber limit search
715   if ($form->{serialnumber} || $form->{l_serialnumber}) {
716     $form->{l_serialnumber} = "Y";
717     unless (   $form->{bought}
718             || $form->{sold}
719             || $form->{rfq}
720             || $form->{quoted}) {
721       $form->{bought} = $form->{sold} = 1;
722     }
723   }
724   IC->all_parts(\%myconfig, \%$form);
725
726   if ($form->{itemstatus} eq 'active') {
727     $option .= $locale->text('Active') . " : ";
728   }
729   if ($form->{itemstatus} eq 'obsolete') {
730     $option .= $locale->text('Obsolete') . " : ";
731   }
732   if ($form->{itemstatus} eq 'orphaned') {
733     $option .= $locale->text('Orphaned') . " : ";
734   }
735   if ($form->{itemstatus} eq 'onhand') {
736     $option .= $locale->text('On Hand') . " : ";
737     $form->{l_onhand} = "Y";
738   }
739   if ($form->{itemstatus} eq 'short') {
740     $option .= $locale->text('Short') . " : ";
741     $form->{l_onhand} = "Y";
742   }
743   if ($form->{onorder}) {
744     $form->{l_ordnumber} = "Y";
745     $callback .= "&onorder=$form->{onorder}";
746     $option   .= $locale->text('On Order') . " : ";
747   }
748   if ($form->{ordered}) {
749     $form->{l_ordnumber} = "Y";
750     $callback .= "&ordered=$form->{ordered}";
751     $option   .= $locale->text('Ordered') . " : ";
752   }
753   if ($form->{rfq}) {
754     $form->{l_quonumber} = "Y";
755     $callback .= "&rfq=$form->{rfq}";
756     $option   .= $locale->text('RFQ') . " : ";
757   }
758   if ($form->{quoted}) {
759     $form->{l_quonumber} = "Y";
760     $callback .= "&quoted=$form->{quoted}";
761     $option   .= $locale->text('Quoted') . " : ";
762   }
763   if ($form->{bought}) {
764     $form->{l_invnumber} = "Y";
765     $callback .= "&bought=$form->{bought}";
766     $option   .= $locale->text('Bought') . " : ";
767   }
768   if ($form->{sold}) {
769     $form->{l_invnumber} = "Y";
770     $callback .= "&sold=$form->{sold}";
771     $option   .= $locale->text('Sold') . " : ";
772   }
773   if (   $form->{bought}
774       || $form->{sold}
775       || $form->{onorder}
776       || $form->{ordered}
777       || $form->{rfq}
778       || $form->{quoted}) {
779
780     $form->{l_lastcost} = "";
781     $form->{l_name}     = "Y";
782     if ($form->{transdatefrom}) {
783       $callback .= "&transdatefrom=$form->{transdatefrom}";
784       $option   .= "\n<br>"
785         . $locale->text('From')
786         . "&nbsp;"
787         . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
788     }
789     if ($form->{transdateto}) {
790       $callback .= "&transdateto=$form->{transdateto}";
791       $option   .= "\n<br>"
792         . $locale->text('To')
793         . "&nbsp;"
794         . $locale->date(\%myconfig, $form->{transdateto}, 1);
795     }
796   }
797
798   $option .= "<br>";
799
800   if ($form->{partnumber}) {
801     $callback .= "&partnumber=$form->{partnumber}";
802     $option   .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
803   }
804   if ($form->{partsgroup}) {
805     $callback .= "&partsgroup=$form->{partsgroup}";
806     $option   .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
807   }
808   if ($form->{serialnumber}) {
809     $callback .= "&serialnumber=$form->{serialnumber}";
810     $option   .=
811       $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
812   }
813   if ($form->{description}) {
814     $callback .= "&description=$form->{description}";
815     $description = $form->{description};
816     $description =~ s/
817 /<br>/g;
818     $option .=
819       $locale->text('Part Description') . qq| : $form->{description}<br>|;
820   }
821   if ($form->{make}) {
822     $callback .= "&make=$form->{make}";
823     $option   .= $locale->text('Make') . qq| : $form->{make}<br>|;
824   }
825   if ($form->{model}) {
826     $callback .= "&model=$form->{model}";
827     $option   .= $locale->text('Model') . qq| : $form->{model}<br>|;
828   }
829   if ($form->{drawing}) {
830     $callback .= "&drawing=$form->{drawing}";
831     $option   .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
832   }
833   if ($form->{microfiche}) {
834     $callback .= "&microfiche=$form->{microfiche}";
835     $option   .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
836   }
837   if ($form->{l_soldtotal}) {
838     $callback .= "&soldtotal=$form->{soldtotal}";
839     $option   .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
840   }
841
842   @columns = $form->sort_columns(
843     qw(number partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal)
844   );
845
846   if ($form->{l_linetotal}) {
847     $form->{l_onhand} = "Y";
848     $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
849     if ($form->{l_lastcost}) {
850       $form->{l_linetotallastcost} = "Y";
851       if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
852         $form->{l_linetotallastcost} = "";
853       }
854     }
855     $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
856   }
857
858   if ($form->{searchitems} eq 'service') {
859
860     # remove bin, weight and rop from list
861     map { $form->{"l_$_"} = "" } qw(bin weight rop);
862
863     $form->{l_onhand} = "";
864
865     # qty is irrelevant unless bought or sold
866     if (   $form->{bought}
867         || $form->{sold}
868         || $form->{onorder}
869         || $form->{ordered}
870         || $form->{rfq}
871         || $form->{quoted}) {
872       $form->{l_onhand} = "Y";
873         } else {
874       $form->{l_linetotalsellprice} = "";
875       $form->{l_linetotallastcost}  = "";
876     }
877   }
878
879   $form->{l_lastcost} = ""
880     if ($form->{searchitems} eq 'assembly' && !$form->{bom});
881
882   foreach $item (@columns) {
883     if ($form->{"l_$item"} eq "Y") {
884       push @column_index, $item;
885
886       # add column to callback
887       $callback .= "&l_$item=Y";
888     }
889   }
890
891   if ($form->{l_subtotal} eq 'Y') {
892     $callback .= "&l_subtotal=Y";
893   }
894
895   $column_header{number} =
896     qq|<th class=listheading nowrap>| . $locale->text('number') . qq|</th>|;
897   $column_header{partnumber} =
898     qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
899     . $locale->text('Part Number')
900     . qq|</a></th>|;
901   $column_header{description} =
902     qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
903     . $locale->text('Part Description')
904     . qq|</a></th>|;
905   $column_header{partsgroup} =
906       qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
907     . $locale->text('Group')
908     . qq|</a></th>|;
909   $column_header{bin} =
910       qq|<th><a class=listheading href=$callback&sort=bin>|
911     . $locale->text('Bin')
912     . qq|</a></th>|;
913   $column_header{priceupdate} =
914       qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
915     . $locale->text('Updated')
916     . qq|</a></th>|;
917   $column_header{onhand} =
918     qq|<th nowrap><a  class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
919     . $locale->text('Qty')
920     . qq|</th>|;
921   $column_header{unit} =
922     qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
923   $column_header{listprice} =
924       qq|<th class=listheading nowrap>|
925     . $locale->text('List Price')
926     . qq|</th>|;
927   $column_header{lastcost} =
928     qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
929   $column_header{rop} =
930     qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
931   $column_header{weight} =
932     qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
933
934   $column_header{invnumber} =
935       qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
936     . $locale->text('Invoice Number')
937     . qq|</a></th>|;
938   $column_header{ordnumber} =
939       qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
940     . $locale->text('Order Number')
941     . qq|</a></th>|;
942   $column_header{quonumber} =
943       qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
944     . $locale->text('Quotation')
945     . qq|</a></th>|;
946
947   $column_header{name} =
948       qq|<th nowrap><a class=listheading href=$callback&sort=name>|
949     . $locale->text('Name')
950     . qq|</a></th>|;
951
952   $column_header{sellprice} =
953       qq|<th class=listheading nowrap>|
954     . $locale->text('Sell Price')
955     . qq|</th>|;
956   $column_header{linetotalsellprice} =
957     qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
958   $column_header{linetotallastcost} =
959     qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
960   $column_header{linetotallistprice} =
961     qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
962
963   $column_header{image} =
964     qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
965   $column_header{drawing} =
966       qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
967     . $locale->text('Drawing')
968     . qq|</a></th>|;
969   $column_header{microfiche} =
970       qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
971     . $locale->text('Microfiche')
972     . qq|</a></th>|;
973
974   $column_header{serialnumber} =
975       qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
976     . $locale->text('Serial Number')
977     . qq|</a></th>|;
978   $column_header{soldtotal} =
979     qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
980     . $locale->text('soldtotal')
981     . qq|</a></th>|;
982
983   $form->header;
984   $colspan = $#column_index + 1;
985
986   print qq|
987 <body>
988
989 <table width=100%>
990   <tr>
991     <th class=listtop colspan=$colspan>$form->{title}</th>
992   </tr>
993   <tr height="5"></tr>
994
995   <tr><td colspan=$colspan>$option</td></tr>
996
997   <tr class=listheading>
998 |;
999
1000   map { print "\n$column_header{$_}" } @column_index;
1001
1002   print qq|
1003   </tr>
1004   |;
1005
1006   # add order to callback
1007   $form->{callback} = $callback .= "&sort=$form->{sort}";
1008
1009   # escape callback for href
1010   $callback = $form->escape($callback);
1011
1012   if (@{ $form->{parts} }) {
1013     $sameitem = $form->{parts}->[0]->{ $form->{sort} };
1014   }
1015
1016   # insert numbers for top100
1017   my $j = 0;
1018   foreach $ref (@{ $form->{parts} }) {
1019     $j++;
1020     $ref->{number} = $j;
1021   }
1022
1023   # if avaible -> insert choice here
1024   if (($form->{ndxs_counter}) > 0) {
1025     for ($i = 1; ($i < $form->{ndxs_counter} + 1); $i++) {
1026       $partnumber  = $form->{"totop100_partnumber_$i"};
1027       $description = $form->{"totop100_description_$i"};
1028       $unit        = $form->{"totop100_unit_$i"};
1029       $sellprice   = $form->{"totop100_sellprice_$i"};
1030       $soldtotal   = $form->{"totop100_soldtotal_$i"};
1031
1032       $totop100 .= qq|
1033 <input type=hidden name=totop100_partnumber_$i value=$form->{"totop100_partnumber_$i"}>
1034 <input type=hidden name=totop100_description_$i value=$form->{"totop100_description_$i"}>
1035 <input type=hidden name=totop100_unit_$i value=$form->{"totop100_unit_$i"}>
1036 <input type=hidden name=totop100_sellprice_$i value=$form->{"totop100_sellprice_$i"}>
1037 <input type=hidden name=totop100_soldtotal_$i value=$form->{"totop100_soldtotal_$i"}>
1038       |;
1039
1040       # insert into list
1041       push @{ $form->{parts} },
1042         { number      => "",
1043           partnumber  => "$partnumber",
1044           description => "$description",
1045           unit        => "$unit",
1046           sellprice   => "$sellprice",
1047           soldtotal   => "$soldtotal" };
1048     }    #rof
1049   }    #fi
1050        # build data for columns
1051   foreach $ref (@{ $form->{parts} }) {
1052
1053     if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
1054       if ($sameitem ne $ref->{ $form->{sort} }) {
1055         &parts_subtotal;
1056         $sameitem = $ref->{ $form->{sort} };
1057       }
1058     }
1059
1060     $ref->{exchangerate} = 1 unless $ref->{exchangerate};
1061     $ref->{sellprice} *= $ref->{exchangerate};
1062     $ref->{listprice} *= $ref->{exchangerate};
1063     $ref->{lastcost}  *= $ref->{exchangerate};
1064
1065     # use this for assemblies
1066     $onhand = $ref->{onhand};
1067
1068     $align = "left";
1069     if ($ref->{assemblyitem}) {
1070       $align = "right";
1071       $onhand = 0 if ($form->{sold});
1072     }
1073
1074     $ref->{description} =~ s/
1075 /<br>/g;
1076
1077     $column_data{number} =
1078         "<td align=right>"
1079       . $form->format_amount(\%myconfig, $ref->{number}, '', "&nbsp;")
1080       . "</td>";
1081     $column_data{partnumber} =
1082       "<td align=$align>$ref->{partnumber}&nbsp;</a></td>";
1083     $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
1084     $column_data{partsgroup}  = "<td>$ref->{partsgroup}&nbsp;</td>";
1085
1086     $column_data{onhand} =
1087         "<td align=right>"
1088       . $form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")
1089       . "</td>";
1090     $column_data{sellprice} =
1091         "<td align=right>"
1092       . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, "&nbsp;")
1093       . "</td>";
1094     $column_data{listprice} =
1095         "<td align=right>"
1096       . $form->format_amount(\%myconfig, $ref->{listprice}, 2, "&nbsp;")
1097       . "</td>";
1098     $column_data{lastcost} =
1099         "<td align=right>"
1100       . $form->format_amount(\%myconfig, $ref->{lastcost}, 2, "&nbsp;")
1101       . "</td>";
1102
1103     $column_data{linetotalsellprice} = "<td align=right>"
1104       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice},
1105                              2, "&nbsp;")
1106       . "</td>";
1107     $column_data{linetotallastcost} = "<td align=right>"
1108       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost},
1109                              2, "&nbsp;")
1110       . "</td>";
1111     $column_data{linetotallistprice} = "<td align=right>"
1112       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice},
1113                              2, "&nbsp;")
1114       . "</td>";
1115
1116     if (!$ref->{assemblyitem}) {
1117       $totalsellprice += $onhand * $ref->{sellprice};
1118       $totallastcost  += $onhand * $ref->{lastcost};
1119       $totallistprice += $onhand * $ref->{listprice};
1120
1121       $subtotalonhand    += $onhand;
1122       $subtotalsellprice += $onhand * $ref->{sellprice};
1123       $subtotallastcost  += $onhand * $ref->{lastcost};
1124       $subtotallistprice += $onhand * $ref->{listprice};
1125     }
1126
1127     $column_data{rop} =
1128       "<td align=right>"
1129       . $form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;") . "</td>";
1130     $column_data{weight} =
1131         "<td align=right>"
1132       . $form->format_amount(\%myconfig, $ref->{weight}, '', "&nbsp;")
1133       . "</td>";
1134     $column_data{unit}        = "<td>$ref->{unit}&nbsp;</td>";
1135     $column_data{bin}         = "<td>$ref->{bin}&nbsp;</td>";
1136     $column_data{priceupdate} = "<td>$ref->{priceupdate}&nbsp;</td>";
1137
1138     $column_data{invnumber} =
1139       ($ref->{module} ne 'oe')
1140       ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>"
1141       : "<td>$ref->{invnumber}</td>";
1142     $column_data{ordnumber} =
1143       ($ref->{module} eq 'oe')
1144       ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber}</a></td>"
1145       : "<td>$ref->{ordnumber}</td>";
1146     $column_data{quonumber} =
1147       ($ref->{module} eq 'oe' && !$ref->{ordnumber})
1148       ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{quonumber}</a></td>"
1149       : "<td>$ref->{quonumber}</td>";
1150
1151     $column_data{name} = "<td>$ref->{name}</td>";
1152
1153     $column_data{image} =
1154       ($ref->{image})
1155       ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
1156       : "<td>&nbsp;</td>";
1157     $column_data{drawing} =
1158       ($ref->{drawing})
1159       ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
1160       : "<td>&nbsp;</td>";
1161     $column_data{microfiche} =
1162       ($ref->{microfiche})
1163       ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
1164       : "<td>&nbsp;</td>";
1165
1166     $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
1167
1168     $column_data{soldtotal} = "<td  align=right>$ref->{soldtotal}</td>";
1169
1170     $i++;
1171     $i %= 2;
1172     print "<tr class=listrow$i>";
1173
1174     map { print "\n$column_data{$_}" } @column_index;
1175
1176     print qq|
1177     </tr>
1178 |;
1179   }
1180
1181   if ($form->{l_subtotal} eq 'Y') {
1182     &parts_subtotal;
1183   }    #fi
1184
1185   if ($form->{"l_linetotal"}) {
1186     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
1187     $column_data{linetotalsellprice} =
1188         "<th class=listtotal align=right>"
1189       . $form->format_amount(\%myconfig, $totalsellprice, 2, "&nbsp;")
1190       . "</th>";
1191     $column_data{linetotallastcost} =
1192         "<th class=listtotal align=right>"
1193       . $form->format_amount(\%myconfig, $totallastcost, 2, "&nbsp;")
1194       . "</th>";
1195     $column_data{linetotallistprice} =
1196         "<th class=listtotal align=right>"
1197       . $form->format_amount(\%myconfig, $totallistprice, 2, "&nbsp;")
1198       . "</th>";
1199
1200     print "<tr class=listtotal>";
1201
1202     map { print "\n$column_data{$_}" } @column_index;
1203
1204     print qq|</tr>
1205     |;
1206   }
1207
1208   print qq|
1209   <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
1210 </table>
1211
1212 |;
1213
1214   print qq|
1215
1216 <br>
1217
1218 <form method=post action=$form->{script}>
1219
1220 <input type=hidden name=path value=$form->{path}>
1221 <input type=hidden name=login value=$form->{login}>
1222 <input type=hidden name=password value=$form->{password}>
1223
1224 <input type=hidden name=itemstatus value="$form->{itemstatus}">
1225 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
1226 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
1227 <input type=hidden name=l_description value="$form->{l_description}">
1228 <input type=hidden name=l_onhand value="$form->{l_onhand}">
1229 <input type=hidden name=l_unit value="$form->{l_unit}">
1230 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
1231 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
1232 <input type=hidden name=sort value="$form->{sort}">
1233 <input type=hidden name=revers value="$form->{revers}">
1234 <input type=hidden name=lastsort value="$form->{lastsort}">
1235 <input type=hidden name=parts value="$form->{parts}">
1236
1237 <input type=hidden name=bom value="$form->{bom}">
1238 <input type=hidden name=titel value="$form->{titel}">
1239 <input type=hidden name=searchitems value="$form->{searchitems}">|;
1240
1241   print $totop100;
1242
1243   print qq|
1244     <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">
1245
1246     <input class=submit type=submit name=action value="|
1247     . $locale->text('choice') . qq|">|;
1248
1249   if ($form->{menubar}) {
1250     require "$form->{path}/menu.pl";
1251     &menubar;
1252   }
1253
1254   print qq|
1255   </form>
1256
1257 </body>
1258 </html>
1259 |;
1260
1261   $lxdebug->leave_sub();
1262 }    # end addtop100
1263
1264 sub generate_report {
1265   $lxdebug->enter_sub();
1266
1267   $revers   = $form->{revers};
1268   $lastsort = $form->{lastsort};
1269
1270   if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
1271     $form->{revers}   = 0;
1272     $form->{lastsort} = "partnumber";
1273     $form->{sort}     = "partnumber";
1274   } else {
1275
1276     # switch between backward sorting of tables
1277     if ($form->{lastsort} eq $form->{sort}) {
1278       if ($form->{revers} == 0) {
1279         $form->{revers} = 1;
1280       } else {
1281         $form->{revers} = 0;
1282       }    #fi
1283     } else {
1284       $form->{revers} == 0;
1285       $form->{lastsort} = $form->{sort};
1286     }    #fi
1287   }    #fi
1288
1289   $callback =
1290     "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}&searchitems=$form->{searchitems}&itemstatus=$form->{itemstatus}&bom=$form->{bom}&l_linetotal=$form->{l_linetotal}&title="
1291     . $form->escape($form->{title}, 1);
1292
1293   # if we have a serialnumber limit search
1294   if ($form->{serialnumber} || $form->{l_serialnumber}) {
1295     $form->{l_serialnumber} = "Y";
1296     unless (   $form->{bought}
1297             || $form->{sold}
1298             || $form->{rfq}
1299             || $form->{quoted}) {
1300       $form->{bought} = $form->{sold} = 1;
1301     }
1302   }
1303
1304   IC->all_parts(\%myconfig, \%$form);
1305
1306   if ($form->{itemstatus} eq 'active') {
1307     $option .= $locale->text('Active') . " : ";
1308   }
1309   if ($form->{itemstatus} eq 'obsolete') {
1310     $option .= $locale->text('Obsolete') . " : ";
1311   }
1312   if ($form->{itemstatus} eq 'orphaned') {
1313     $option .= $locale->text('Orphaned') . " : ";
1314   }
1315   if ($form->{itemstatus} eq 'onhand') {
1316     $option .= $locale->text('On Hand') . " : ";
1317     $form->{l_onhand} = "Y";
1318   }
1319   if ($form->{itemstatus} eq 'short') {
1320     $option .= $locale->text('Short') . " : ";
1321     $form->{l_onhand} = "Y";
1322   }
1323   if ($form->{onorder}) {
1324     $form->{l_ordnumber} = "Y";
1325     $callback .= "&onorder=$form->{onorder}";
1326     $option   .= $locale->text('On Order') . " : ";
1327   }
1328   if ($form->{ordered}) {
1329     $form->{l_ordnumber} = "Y";
1330     $callback .= "&ordered=$form->{ordered}";
1331     $option   .= $locale->text('Ordered') . " : ";
1332   }
1333   if ($form->{rfq}) {
1334     $form->{l_quonumber} = "Y";
1335     $callback .= "&rfq=$form->{rfq}";
1336     $option   .= $locale->text('RFQ') . " : ";
1337   }
1338   if ($form->{quoted}) {
1339     $form->{l_quonumber} = "Y";
1340     $callback .= "&quoted=$form->{quoted}";
1341     $option   .= $locale->text('Quoted') . " : ";
1342   }
1343   if ($form->{bought}) {
1344     $form->{l_invnumber} = "Y";
1345     $callback .= "&bought=$form->{bought}";
1346     $option   .= $locale->text('Bought') . " : ";
1347   }
1348   if ($form->{sold}) {
1349     $form->{l_invnumber} = "Y";
1350     $callback .= "&sold=$form->{sold}";
1351     $option   .= $locale->text('Sold') . " : ";
1352   }
1353   if (   $form->{bought}
1354       || $form->{sold}
1355       || $form->{onorder}
1356       || $form->{ordered}
1357       || $form->{rfq}
1358       || $form->{quoted}) {
1359
1360     $form->{l_lastcost} = "";
1361     $form->{l_name}     = "Y";
1362     if ($form->{transdatefrom}) {
1363       $callback .= "&transdatefrom=$form->{transdatefrom}";
1364       $option   .= "\n<br>"
1365         . $locale->text('From')
1366         . "&nbsp;"
1367         . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1368     }
1369     if ($form->{transdateto}) {
1370       $callback .= "&transdateto=$form->{transdateto}";
1371       $option   .= "\n<br>"
1372         . $locale->text('To')
1373         . "&nbsp;"
1374         . $locale->date(\%myconfig, $form->{transdateto}, 1);
1375     }
1376   }
1377
1378   $option .= "<br>";
1379
1380   if ($form->{partnumber}) {
1381     $callback .= "&partnumber=$form->{partnumber}";
1382     $option   .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
1383   }
1384   if ($form->{partsgroup}) {
1385     $callback .= "&partsgroup=$form->{partsgroup}";
1386     $option   .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
1387   }
1388   if ($form->{serialnumber}) {
1389     $callback .= "&serialnumber=$form->{serialnumber}";
1390     $option   .=
1391       $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
1392   }
1393   if ($form->{description}) {
1394     $callback .= "&description=$form->{description}";
1395     $description = $form->{description};
1396     $description =~ s/
1397 /<br>/g;
1398     $option .=
1399       $locale->text('Part Description') . qq| : $form->{description}<br>|;
1400   }
1401   if ($form->{make}) {
1402     $callback .= "&make=$form->{make}";
1403     $option   .= $locale->text('Make') . qq| : $form->{make}<br>|;
1404   }
1405   if ($form->{model}) {
1406     $callback .= "&model=$form->{model}";
1407     $option   .= $locale->text('Model') . qq| : $form->{model}<br>|;
1408   }
1409   if ($form->{drawing}) {
1410     $callback .= "&drawing=$form->{drawing}";
1411     $option   .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
1412   }
1413   if ($form->{microfiche}) {
1414     $callback .= "&microfiche=$form->{microfiche}";
1415     $option   .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
1416   }
1417
1418   # table soldtotal aktive
1419   if ($form->{l_soldtotal}) {
1420     $callback .= "&soldtotal=$form->{soldtotal}";
1421     $option   .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
1422   }
1423
1424   if ($form->{l_deliverydate}) {
1425     $callback .= "&deliverydate=$form->{deliverydate}";
1426   }
1427
1428   @columns = $form->sort_columns(
1429     qw(partnumber description partsgroup bin onhand rop unit listprice linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost priceupdate weight image drawing microfiche invnumber ordnumber quonumber name serialnumber soldtotal deliverydate)
1430   );
1431
1432   if ($form->{l_linetotal}) {
1433     $form->{l_onhand} = "Y";
1434     $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1435     if ($form->{l_lastcost}) {
1436       $form->{l_linetotallastcost} = "Y";
1437       if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1438         $form->{l_linetotallastcost} = "";
1439       }
1440     }
1441     $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1442   }
1443
1444   if ($form->{searchitems} eq 'service') {
1445
1446     # remove bin, weight and rop from list
1447     map { $form->{"l_$_"} = "" } qw(bin weight rop);
1448
1449     $form->{l_onhand} = "";
1450
1451     # qty is irrelevant unless bought or sold
1452     if (   $form->{bought}
1453         || $form->{sold}
1454         || $form->{onorder}
1455         || $form->{ordered}
1456         || $form->{rfq}
1457         || $form->{quoted}) {
1458       $form->{l_onhand} = "Y";
1459         } else {
1460       $form->{l_linetotalsellprice} = "";
1461       $form->{l_linetotallastcost}  = "";
1462     }
1463   }
1464
1465   $form->{l_lastcost} = ""
1466     if ($form->{searchitems} eq 'assembly' && !$form->{bom});
1467
1468   foreach $item (@columns) {
1469     if ($form->{"l_$item"} eq "Y") {
1470       push @column_index, $item;
1471
1472       # add column to callback
1473       $callback .= "&l_$item=Y";
1474     }
1475   }
1476
1477   if ($form->{l_subtotal} eq 'Y') {
1478     $callback .= "&l_subtotal=Y";
1479   }
1480   $column_header{partnumber} =
1481     qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1482     . $locale->text('Part Number')
1483     . qq|</a></th>|;
1484   $column_header{description} =
1485     qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1486     . $locale->text('Part Description')
1487     . qq|</a></th>|;
1488   $column_header{partsgroup} =
1489       qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
1490     . $locale->text('Group')
1491     . qq|</a></th>|;
1492   $column_header{bin} =
1493       qq|<th><a class=listheading href=$callback&sort=bin>|
1494     . $locale->text('Bin')
1495     . qq|</a></th>|;
1496   $column_header{priceupdate} =
1497       qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
1498     . $locale->text('Updated')
1499     . qq|</a></th>|;
1500   $column_header{onhand} =
1501     qq|<th nowrap><a  class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1502     . $locale->text('Qty')
1503     . qq|</th>|;
1504   $column_header{unit} =
1505     qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
1506   $column_header{listprice} =
1507       qq|<th class=listheading nowrap>|
1508     . $locale->text('List Price')
1509     . qq|</th>|;
1510   $column_header{lastcost} =
1511     qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
1512   $column_header{rop} =
1513     qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
1514   $column_header{weight} =
1515     qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
1516
1517   $column_header{invnumber} =
1518       qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
1519     . $locale->text('Invoice Number')
1520     . qq|</a></th>|;
1521   $column_header{ordnumber} =
1522       qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
1523     . $locale->text('Order Number')
1524     . qq|</a></th>|;
1525   $column_header{quonumber} =
1526       qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
1527     . $locale->text('Quotation')
1528     . qq|</a></th>|;
1529
1530   $column_header{name} =
1531       qq|<th nowrap><a class=listheading href=$callback&sort=name>|
1532     . $locale->text('Name')
1533     . qq|</a></th>|;
1534
1535   $column_header{sellprice} =
1536       qq|<th class=listheading nowrap>|
1537     . $locale->text('Sell Price')
1538     . qq|</th>|;
1539   $column_header{linetotalsellprice} =
1540     qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
1541   $column_header{linetotallastcost} =
1542     qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
1543   $column_header{linetotallistprice} =
1544     qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
1545
1546   $column_header{image} =
1547     qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
1548   $column_header{drawing} =
1549       qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
1550     . $locale->text('Drawing')
1551     . qq|</a></th>|;
1552   $column_header{microfiche} =
1553       qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
1554     . $locale->text('Microfiche')
1555     . qq|</a></th>|;
1556
1557   $column_header{serialnumber} =
1558       qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
1559     . $locale->text('Serial Number')
1560     . qq|</a></th>|;
1561   $column_header{soldtotal} =
1562     qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1563     . $locale->text('soldtotal')
1564     . qq|</a></th>|;
1565
1566   $column_header{deliverydate} =
1567     qq|<th nowrap><a class=listheading href=$callback&sort=deliverydate&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1568     . $locale->text('deliverydate')
1569     . qq|</a></th>|;
1570
1571   $form->header;
1572   $colspan = $#column_index + 1;
1573
1574   print qq|
1575 <body>
1576
1577 <table width=100%>
1578   <tr>
1579     <th class=listtop colspan=$colspan>$form->{title}</th>
1580   </tr>
1581   <tr height="5"></tr>
1582
1583   <tr><td colspan=$colspan>$option</td></tr>
1584
1585   <tr class=listheading>
1586 |;
1587
1588   map { print "\n$column_header{$_}" } @column_index;
1589
1590   print qq|
1591   </tr>
1592   |;
1593
1594   # add order to callback
1595   $form->{callback} = $callback .= "&sort=$form->{sort}";
1596
1597   # escape callback for href
1598   $callback = $form->escape($callback);
1599
1600   if (@{ $form->{parts} }) {
1601     $sameitem = $form->{parts}->[0]->{ $form->{sort} };
1602   }
1603
1604   foreach $ref (@{ $form->{parts} }) {
1605
1606     if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
1607       if ($sameitem ne $ref->{ $form->{sort} }) {
1608         &parts_subtotal;
1609         $sameitem = $ref->{ $form->{sort} };
1610       }
1611     }
1612
1613     $ref->{exchangerate} = 1 unless $ref->{exchangerate};
1614     $ref->{sellprice} *= $ref->{exchangerate};
1615     $ref->{listprice} *= $ref->{exchangerate};
1616     $ref->{lastcost}  *= $ref->{exchangerate};
1617
1618     # use this for assemblies
1619     $onhand = $ref->{onhand};
1620
1621     $align = "left";
1622     if ($ref->{assemblyitem}) {
1623       $align = "right";
1624       $onhand = 0 if ($form->{sold});
1625     }
1626
1627     $ref->{description} =~ s/
1628 /<br>/g;
1629
1630     $column_data{partnumber} =
1631       "<td align=$align><a href=$form->{script}?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{partnumber}&nbsp;</a></td>";
1632     $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
1633     $column_data{partsgroup}  = "<td>$ref->{partsgroup}&nbsp;</td>";
1634
1635     $column_data{onhand} =
1636         "<td align=right>"
1637       . $form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")
1638       . "</td>";
1639     $column_data{sellprice} =
1640         "<td align=right>"
1641       . $form->format_amount(\%myconfig, $ref->{sellprice}, 2, "&nbsp;")
1642       . "</td>";
1643     $column_data{listprice} =
1644         "<td align=right>"
1645       . $form->format_amount(\%myconfig, $ref->{listprice}, 2, "&nbsp;")
1646       . "</td>";
1647     $column_data{lastcost} =
1648         "<td align=right>"
1649       . $form->format_amount(\%myconfig, $ref->{lastcost}, 2, "&nbsp;")
1650       . "</td>";
1651
1652     $column_data{linetotalsellprice} = "<td align=right>"
1653       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice},
1654                              2, "&nbsp;")
1655       . "</td>";
1656     $column_data{linetotallastcost} = "<td align=right>"
1657       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost},
1658                              2, "&nbsp;")
1659       . "</td>";
1660     $column_data{linetotallistprice} = "<td align=right>"
1661       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice},
1662                              2, "&nbsp;")
1663       . "</td>";
1664
1665     if (!$ref->{assemblyitem}) {
1666       $totalsellprice += $onhand * $ref->{sellprice};
1667       $totallastcost  += $onhand * $ref->{lastcost};
1668       $totallistprice += $onhand * $ref->{listprice};
1669
1670       $subtotalonhand    += $onhand;
1671       $subtotalsellprice += $onhand * $ref->{sellprice};
1672       $subtotallastcost  += $onhand * $ref->{lastcost};
1673       $subtotallistprice += $onhand * $ref->{listprice};
1674     }
1675
1676     $column_data{rop} =
1677       "<td align=right>"
1678       . $form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;") . "</td>";
1679     $column_data{weight} =
1680         "<td align=right>"
1681       . $form->format_amount(\%myconfig, $ref->{weight}, '', "&nbsp;")
1682       . "</td>";
1683     $column_data{unit}        = "<td>$ref->{unit}&nbsp;</td>";
1684     $column_data{bin}         = "<td>$ref->{bin}&nbsp;</td>";
1685     $column_data{priceupdate} = "<td>$ref->{priceupdate}&nbsp;</td>";
1686
1687     $column_data{invnumber} =
1688       ($ref->{module} ne 'oe')
1689       ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>"
1690       : "<td>$ref->{invnumber}</td>";
1691     $column_data{ordnumber} =
1692       ($ref->{module} eq 'oe')
1693       ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber}</a></td>"
1694       : "<td>$ref->{ordnumber}</td>";
1695     $column_data{quonumber} =
1696       ($ref->{module} eq 'oe' && !$ref->{ordnumber})
1697       ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{quonumber}</a></td>"
1698       : "<td>$ref->{quonumber}</td>";
1699
1700     $column_data{name} = "<td>$ref->{name}</td>";
1701
1702     $column_data{image} =
1703       ($ref->{image})
1704       ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
1705       : "<td>&nbsp;</td>";
1706     $column_data{drawing} =
1707       ($ref->{drawing})
1708       ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
1709       : "<td>&nbsp;</td>";
1710     $column_data{microfiche} =
1711       ($ref->{microfiche})
1712       ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
1713       : "<td>&nbsp;</td>";
1714
1715     $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
1716
1717     $column_data{soldtotal} =
1718         "<td align=right>"
1719       . $form->format_amount(\%myconfig, $ref->{soldtotal}, '', "&nbsp;")
1720       . "</td>";
1721
1722     $column_data{deliverydate} = "<td>$ref->{deliverydate}</td>";
1723
1724     $i++;
1725     $i %= 2;
1726     print "<tr class=listrow$i>";
1727
1728     map { print "\n$column_data{$_}" } @column_index;
1729
1730     print qq|
1731     </tr>
1732 |;
1733
1734   }
1735
1736   if ($form->{l_subtotal} eq 'Y') {
1737     &parts_subtotal;
1738   }
1739
1740   if ($form->{"l_linetotal"}) {
1741     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
1742     $column_data{linetotalsellprice} =
1743         "<th class=listtotal align=right>"
1744       . $form->format_amount(\%myconfig, $totalsellprice, 2, "&nbsp;")
1745       . "</th>";
1746     $column_data{linetotallastcost} =
1747         "<th class=listtotal align=right>"
1748       . $form->format_amount(\%myconfig, $totallastcost, 2, "&nbsp;")
1749       . "</th>";
1750     $column_data{linetotallistprice} =
1751         "<th class=listtotal align=right>"
1752       . $form->format_amount(\%myconfig, $totallistprice, 2, "&nbsp;")
1753       . "</th>";
1754
1755     print "<tr class=listtotal>";
1756
1757     map { print "\n$column_data{$_}" } @column_index;
1758
1759     print qq|</tr>
1760     |;
1761   }
1762
1763   print qq|
1764   <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
1765 </table>
1766
1767 |;
1768
1769   print qq|
1770
1771 <br>
1772
1773 <form method=post action=$form->{script}>
1774
1775 <input name=callback type=hidden value="$form->{callback}">
1776
1777 <input type=hidden name=item value=$form->{searchitems}>
1778
1779 <input type=hidden name=path value=$form->{path}>
1780 <input type=hidden name=login value=$form->{login}>
1781 <input type=hidden name=password value=$form->{password}>|;
1782
1783   print qq|
1784   <input class=submit type=submit name=action value="|
1785     . $locale->text('Add') . qq|">|;
1786
1787   if ($form->{menubar}) {
1788     require "$form->{path}/menu.pl";
1789     &menubar;
1790   }
1791
1792   print qq|
1793   </form>
1794
1795 </body>
1796 </html>
1797 |;
1798
1799   $lxdebug->leave_sub();
1800 }    #end generate_report
1801
1802 sub parts_subtotal {
1803   $lxdebug->enter_sub();
1804
1805   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
1806   $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
1807
1808   $column_data{onhand} =
1809       "<th class=listsubtotal align=right>"
1810     . $form->format_amount(\%myconfig, $subtotalonhand, '', "&nbsp;")
1811     . "</th>";
1812
1813   $column_data{linetotalsellprice} =
1814       "<th class=listsubtotal align=right>"
1815     . $form->format_amount(\%myconfig, $subtotalsellprice, 2, "&nbsp;")
1816     . "</th>";
1817   $column_data{linetotallistprice} =
1818       "<th class=listsubtotal align=right>"
1819     . $form->format_amount(\%myconfig, $subtotallistprice, 2, "&nbsp;")
1820     . "</th>";
1821   $column_data{linetotallastcost} =
1822       "<th class=listsubtotal align=right>"
1823     . $form->format_amount(\%myconfig, $subtotallastcost, 2, "&nbsp;")
1824     . "</th>";
1825
1826   $subtotalonhand    = 0;
1827   $subtotalsellprice = 0;
1828   $subtotallistprice = 0;
1829   $subtotallastcost  = 0;
1830
1831   print "<tr class=listsubtotal>";
1832
1833   map { print "\n$column_data{$_}" } @column_index;
1834
1835   print qq|
1836   </tr>
1837 |;
1838
1839   $lxdebug->leave_sub();
1840 }
1841
1842 sub edit {
1843   $lxdebug->enter_sub();
1844
1845   IC->get_part(\%myconfig, \%$form);
1846
1847   $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
1848
1849   &link_part;
1850   &display_form;
1851
1852   $lxdebug->leave_sub();
1853 }
1854
1855 sub link_part {
1856   $lxdebug->enter_sub();
1857
1858   IC->create_links("IC", \%myconfig, \%$form);
1859
1860   # currencies
1861   map { $form->{selectcurrency} .= "<option>$_\n" } split /:/,
1862     $form->{currencies};
1863
1864   # parts and assemblies have the same links
1865   $item = $form->{item};
1866   if ($form->{item} eq 'assembly') {
1867     $item = 'part';
1868   }
1869
1870   # build the popup menus
1871   $form->{taxaccounts} = "";
1872   foreach $key (keys %{ $form->{IC_links} }) {
1873     foreach $ref (@{ $form->{IC_links}{$key} }) {
1874
1875       # if this is a tax field
1876       if ($key =~ /IC_tax/) {
1877         if ($key =~ /$item/) {
1878           $form->{taxaccounts} .= "$ref->{accno} ";
1879           $form->{"IC_tax_$ref->{accno}_description"} =
1880             "$ref->{accno}--$ref->{description}";
1881
1882           if ($form->{id}) {
1883             if ($form->{amount}{ $ref->{accno} }) {
1884               $form->{"IC_tax_$ref->{accno}"} = "checked";
1885             }
1886           } else {
1887             $form->{"IC_tax_$ref->{accno}"} = "checked";
1888           }
1889         }
1890       } else {
1891
1892         $form->{"select$key"} .=
1893           "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
1894         if ($form->{amount}{$key} eq $ref->{accno}) {
1895           $form->{$key} = "$ref->{accno}--$ref->{description}";
1896         }
1897
1898       }
1899     }
1900   }
1901   chop $form->{taxaccounts};
1902
1903   if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
1904     $form->{selectIC_income}  = $form->{selectIC_sale};
1905     $form->{selectIC_expense} = $form->{selectIC_cogs};
1906     $form->{IC_income}        = $form->{IC_sale};
1907     $form->{IC_expense}       = $form->{IC_cogs};
1908   }
1909
1910   delete $form->{IC_links};
1911   delete $form->{amount};
1912
1913   $form->get_partsgroup(\%myconfig, { all => 1 });
1914
1915   $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1916
1917   if (@{ $form->{all_partsgroup} }) {
1918     $form->{selectpartsgroup} = qq|<option>\n|;
1919     map {
1920       $form->{selectpartsgroup} .=
1921         qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1922     } @{ $form->{all_partsgroup} };
1923   }
1924
1925   if ($form->{item} eq 'assembly') {
1926
1927     foreach $i (1 .. $form->{assembly_rows}) {
1928       if ($form->{"partsgroup_id_$i"}) {
1929         $form->{"partsgroup_$i"} =
1930           qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1931       }
1932     }
1933     $form->get_partsgroup(\%myconfig);
1934
1935     if (@{ $form->{all_partsgroup} }) {
1936       $form->{selectassemblypartsgroup} = qq|<option>\n|;
1937
1938       map {
1939         $form->{selectassemblypartsgroup} .=
1940           qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1941       } @{ $form->{all_partsgroup} };
1942     }
1943   }
1944   $lxdebug->leave_sub();
1945 }
1946
1947 sub form_header {
1948   $lxdebug->enter_sub();
1949
1950   my $dec = '';
1951
1952   #decimalplaces for listprice
1953   ($dec) = ($form->{listprice} =~ /\.(\d+)/);
1954   $dec = length $dec;
1955   my $decimalplaces = ($dec > 2) ? $dec : 2;
1956   $form->{listprice} =
1957     $form->format_amount(\%myconfig, $form->{listprice}, $decimalplaces);
1958
1959   #decimalplaces for sellprice and gv
1960   ($dec) = ($form->{sellprice} =~ /\.(\d+)/);
1961   $dec = length $dec;
1962   my $decimalplaces = ($dec > 2) ? $dec : 2;
1963
1964   map {
1965     $form->{$_} =
1966       $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces)
1967   } qw(sellprice gv);
1968
1969   ($dec) = ($form->{lastcost} =~ /\.(\d+)/);
1970   $dec = length $dec;
1971   my $decimalplaces = ($dec > 2) ? $dec : 2;
1972
1973   $form->{lastcost} =
1974     $form->format_amount(\%myconfig, $form->{lastcost}, $decimalplaces);
1975
1976   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
1977     qw(weight rop stock);
1978
1979   foreach $item (qw(partnumber description unit notes)) {
1980     $form->{$item} =~ s/\"/&quot;/g;
1981   }
1982
1983   if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
1984     $rows = 2;
1985   }
1986
1987   $notes =
1988     qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
1989   if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
1990     $description =
1991       qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
1992   } else {
1993     $description =
1994       qq|<input name=description size=40 value="$form->{description}">|;
1995   }
1996
1997   foreach $item (split / /, $form->{taxaccounts}) {
1998     $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : "";
1999   }
2000
2001   # set option
2002   foreach $item (qw(IC IC_income IC_expense)) {
2003     if ($form->{$item}) {
2004       if ($form->{id} && $form->{orphaned}) {
2005         $form->{"select$item"} =~ s/ selected//;
2006         $form->{"select$item"} =~
2007           s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
2008       } else {
2009         $form->{"select$item"} = qq|<option selected>$form->{$item}|;
2010       }
2011     }
2012   }
2013
2014   if ($form->{selectpartsgroup}) {
2015     $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
2016     $partsgroup =
2017       qq|<input type=hidden name=selectpartsgroup value="|
2018       . $form->escape($form->{selectpartsgroup}, 1) . qq|">|;
2019     $form->{selectpartsgroup} =~
2020       s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
2021
2022     $partsgroup .=
2023       qq|<select name=partsgroup>$form->{selectpartsgroup}</select>|;
2024     $group = $locale->text('Group');
2025   }
2026
2027   # tax fields
2028   foreach $item (split / /, $form->{taxaccounts}) {
2029     $tax .= qq|
2030       <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}>&nbsp;<b>$form->{"IC_tax_${item}_description"}</b>
2031       <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
2032 |;
2033   }
2034
2035   $form->{obsolete} = "checked" if $form->{obsolete};
2036
2037   $lastcost = qq|
2038               <tr>
2039                 <th align="right" nowrap="true">|
2040     . $locale->text('Last Cost') . qq|</th>
2041                 <td><input name=lastcost size=11 value=$form->{lastcost}></td>
2042               </tr>
2043 |;
2044   if (!$eur) {
2045     $linkaccounts = qq|
2046                <tr>
2047                 <th align=right>| . $locale->text('Inventory') . qq|</th>
2048                 <td><select name=IC>$form->{selectIC}</select></td>
2049                 <input name=selectIC type=hidden value="$form->{selectIC}">
2050               </tr>|;
2051   }
2052
2053   if ($form->{item} eq "part") {
2054
2055     $linkaccounts .= qq|
2056               <tr>
2057                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2058                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2059                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2060               </tr>
2061               <tr>
2062                 <th align=right>| . $locale->text('Expense') . qq|</th>
2063                 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
2064                 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
2065               </tr>
2066 |;
2067
2068     $weight = qq|
2069               <tr>
2070                 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
2071                 <td>
2072                   <table>
2073                     <tr>
2074                       <td>
2075                         <input name=weight size=10 value=$form->{weight}>
2076                       </td>
2077                       <th>
2078                         &nbsp;
2079                         $form->{weightunit}
2080                         <input type=hidden name=weightunit value=$form->{weightunit}>
2081                       </th>
2082                     </tr>
2083                   </table>
2084                 </td>
2085               </tr>
2086 |;
2087
2088   }
2089
2090   if ($form->{item} eq "assembly") {
2091
2092     $lastcost = "";
2093
2094     $linkaccounts = qq|
2095               <tr>
2096                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2097                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2098                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2099               </tr>
2100 |;
2101
2102     $weight = qq|
2103               <tr>
2104                 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
2105                 <td>
2106                   <table>
2107                     <tr>
2108                       <td>
2109                         &nbsp;$form->{weight}
2110                         <input type=hidden name=weight value=$form->{weight}>
2111                       </td>
2112                       <th>
2113                         &nbsp;
2114                         $form->{weightunit}
2115                         <input type=hidden name=weightunit value=$form->{weightunit}>
2116                       </th>
2117                     </tr>
2118                   </table>
2119                 </td>
2120               </tr>
2121 |;
2122
2123   }
2124
2125   if ($form->{item} eq "service") {
2126
2127     $linkaccounts = qq|
2128               <tr>
2129                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2130                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2131                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2132               </tr>
2133               <tr>
2134                 <th align=right>| . $locale->text('Expense') . qq|</th>
2135                 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
2136                 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
2137               </tr>
2138 |;
2139
2140   }
2141
2142   if ($form->{item} ne 'service') {
2143     $n   = ($form->{onhand} > 0) ? "1" : "0";
2144     $rop = qq|
2145               <tr>
2146                 <th align="right" nowrap>| . $locale->text('On Hand') . qq|</th>
2147                 <th align=left nowrap class="plus$n">&nbsp;|
2148       . $form->format_amount(\%myconfig, $form->{onhand}) . qq|</th>
2149               </tr>
2150 |;
2151
2152     if ($form->{item} eq 'assembly') {
2153       $rop .= qq|
2154               <tr>
2155                 <th align="right" nowrap>| . $locale->text('Stock') . qq|</th>
2156                 <td><input name=stock size=10 value=$form->{stock}></td>
2157               </tr>
2158 |;
2159     }
2160
2161     $rop .= qq|
2162               <tr>
2163                 <th align="right" nowrap="true">| . $locale->text('ROP') . qq|</th>
2164                 <td><input name=rop size=10 value=$form->{rop}></td>
2165               </tr>
2166 |;
2167
2168     $bin = qq|
2169               <tr>
2170                 <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th>
2171                 <td><input name=bin size=10 value=$form->{bin}></td>
2172               </tr>
2173 |;
2174     $vegv = qq|
2175               <tr>
2176                 <th align="right" nowrap="true">|
2177       . $locale->text('Verrechnungseinheit') . qq|</th>
2178                 <td><input name=ve size=10 value=$form->{ve}></td>
2179               </tr>
2180               <tr>
2181                 <th align="right" nowrap="true">|
2182       . $locale->text('Geschäftsvolumen') . qq|</th>
2183                 <td><input name=gv size=10 value=$form->{gv}></td>
2184               </tr>
2185 |;
2186     $imagelinks = qq|
2187   <tr>
2188     <td>
2189       <table width=100%>
2190         <tr>
2191           <th align=right nowrap>| . $locale->text('Image') . qq|</th>
2192           <td><input name=image size=40 value="$form->{image}"></td>
2193           <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
2194           <td><input name=microfiche size=20 value="$form->{microfiche}"></td>
2195         </tr>
2196         <tr>
2197           <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
2198           <td><input name=drawing size=40 value="$form->{drawing}"></td>
2199         </tr>
2200       </table>
2201     </td>
2202   </tr>
2203 |;
2204
2205   }
2206
2207   if ($form->{id}) {
2208     $obsolete = qq|
2209               <tr>
2210                 <th align="right" nowrap="true">| . $locale->text('Obsolete') . qq|</th>
2211                 <td><input name=obsolete type=checkbox class=checkbox value=1 $form->{obsolete}></td>
2212               </tr>
2213 |;
2214   }
2215   $shopok = $form->{shop} == 1 ? "checked" : "";
2216   $obsolete .= qq|
2217               <tr>
2218                 <th align=right nowrap>|
2219     . $locale->text('Shopartikel') . qq|</th>
2220                 <td><input class=checkbox type=checkbox name=shop value=1 $shopok></td>
2221              </tr>
2222 |;
2223
2224   # type=submit $locale->text('Add Part')
2225   # type=submit $locale->text('Add Service')
2226   # type=submit $locale->text('Add Assembly')
2227
2228   # type=submit $locale->text('Edit Part')
2229   # type=submit $locale->text('Edit Service')
2230   # type=submit $locale->text('Edit Assembly')
2231   # use JavaScript Calendar or not
2232   $form->{jsscript} = $jscalendar;
2233   $jsscript = "";
2234   if ($form->{jsscript}) {
2235
2236     # with JavaScript Calendar
2237     $button1 = qq|
2238        <td width="13"><input name=priceupdate id=priceupdate size=11  title="$myconfig{dateformat}" value="$form->{priceupdate}"></td>
2239        <td width="4" align="left"><input type=button name=priceupdate id="trigger1" value=|
2240       . $locale->text('button') . qq|></td>
2241       |;
2242
2243     #write Trigger
2244     $jsscript =
2245       Form->write_trigger(\%myconfig, "1", "priceupdate", "BL", "trigger1");
2246   } else {
2247
2248     # without JavaScript Calendar
2249     $button1 = qq|
2250                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
2251   }
2252
2253   $form->{fokus} = "ic.partnumber";
2254   $form->header;
2255
2256   print qq|
2257   <body onLoad="fokus()">
2258
2259
2260 <form method=post name="ic" action=$form->{script}>
2261
2262 <input name=id type=hidden value=$form->{id}>
2263 <input name=item type=hidden value=$form->{item}>
2264 <input name=title type=hidden value="$form->{title}">
2265 <input name=makemodel type=hidden value="$form->{makemodel}">
2266 <input name=alternate type=hidden value="$form->{alternate}">
2267 <input name=onhand type=hidden value=$form->{onhand}>
2268 <input name=orphaned type=hidden value=$form->{orphaned}>
2269 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
2270 <input name=rowcount type=hidden value=$form->{rowcount}>
2271 <input name=eur type=hidden value=$eur>
2272
2273 <table width="100%">
2274   <tr>
2275     <th class=listtop>$form->{title}</th>
2276   </tr>
2277   <tr height="5"></tr>
2278   <tr>
2279     <td>
2280       <table width="100%">
2281         <tr valign=top>
2282           <th align=left>| . $locale->text('Part Number') . qq|</th>
2283           <th align=left>| . $locale->text('Part Description') . qq|</th>
2284           <th align=left>$group</th>
2285         </tr>
2286         <tr valign=top>
2287           <td><input name=partnumber value="$form->{partnumber}" size=20></td>
2288           <td>$description</td>
2289           <td>$partsgroup</td>
2290           <input type=hidden name=oldpartsgroup value="$form->{oldpartsgroup}">
2291         </tr>
2292       </table>
2293     </td>
2294   </tr>
2295   <tr>
2296     <td>
2297       <table width="100%" height="100%">
2298         <tr valign=top>
2299           <td width=70%>
2300             <table width="100%" height="100%">
2301               <tr class="listheading">
2302                 <th class="listheading" align="center" colspan=2>|
2303     . $locale->text('Link Accounts') . qq|</th>
2304               </tr>
2305               $linkaccounts
2306               <tr>
2307                 <th align="left">| . $locale->text('Notes') . qq|</th>
2308               </tr>
2309               <tr>
2310                 <td colspan=2>
2311                   $notes
2312                 </td>
2313               </tr>
2314             </table>
2315           </td>
2316           <td width="30%">
2317             <table width="100%">
2318               <tr>
2319                 <th align="right" nowrap="true">|
2320     . $locale->text('Updated') . qq|</th>
2321                 $button1
2322               </tr>
2323               <tr>
2324                 <th align="right" nowrap="true">| . $locale->text('List Price') . qq|</th>
2325                 <td><input name=listprice size=11 value=$form->{listprice}></td>
2326               </tr>
2327               <tr>
2328                 <th align="right" nowrap="true">| . $locale->text('Sell Price') . qq|</th>
2329                 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
2330               </tr>
2331               $lastcost
2332               <tr>
2333                 <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
2334                 <td><input name=unit size=5 maxlength="10" value="$form->{unit}"></td>
2335               </tr>
2336               $weight
2337               $rop
2338               $bin
2339               $vegv
2340               $obsolete
2341             </table>
2342           </td>
2343         </tr>
2344       </table>
2345     </td>
2346   </tr>
2347   $imagelinks
2348
2349 $jsscript
2350 |;
2351   $lxdebug->leave_sub();
2352 }
2353
2354 sub form_footer {
2355   $lxdebug->enter_sub();
2356
2357   if ($form->{item} eq "assembly") {
2358
2359     print qq|
2360         <tr>
2361           <td>
2362             <table width="100%">
2363               <tr>
2364                 <th colspan=2 align=right>|
2365       . $locale->text('Total') . qq|&nbsp;</th>
2366                 <th align=right>|
2367       . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
2368               </tr>
2369             </table>
2370           </td>
2371         </tr>
2372         <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
2373 |;
2374   }
2375
2376   print qq|
2377       <input type=hidden name=path value=$form->{path}>
2378       <input type=hidden name=login value=$form->{login}>
2379       <input type=hidden name=password value=$form->{password}>
2380       <input type=hidden name=callback value="$form->{callback}">
2381       <input type=hidden name=previousform value="$form->{previousform}">
2382       <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
2383       <input type=hidden name=vc value=$form->{vc}>
2384   <tr>
2385     <td><hr size=3 noshade></td>
2386   </tr>
2387 </table>
2388
2389 <br>
2390 <input class=submit type=submit name=action value="|
2391     . $locale->text('Update') . qq|">
2392   |;
2393
2394   unless ($form->{item} eq "service") {
2395     print qq|
2396       <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
2397     |;
2398   }
2399
2400   print qq|
2401      <input type=hidden name=price_rows value=$form->{price_rows}>|;
2402
2403   print qq|
2404       <input class=submit type=submit name=action value="|
2405     . $locale->text('Save') . qq|">|;
2406
2407   if ($form->{id}) {
2408
2409     if (!$form->{previousform}) {
2410       print qq|
2411       <input class=submit type=submit name=action value="|
2412         . $locale->text('Save as new') . qq|">|;
2413     }
2414
2415     if ($form->{orphaned}) {
2416       if (!$form->{previousform}) {
2417         if ($form->{item} eq 'assembly') {
2418           if (!$form->{onhand}) {
2419             print qq|
2420       <input class=submit type=submit name=action value="|
2421               . $locale->text('Delete') . qq|">|;
2422           }
2423         } else {
2424           print qq|
2425       <input class=submit type=submit name=action value="|
2426             . $locale->text('Delete') . qq|">|;
2427         }
2428       }
2429     }
2430   }
2431
2432   if (!$form->{previousform}) {
2433     if ($form->{menubar}) {
2434       require "$form->{path}/menu.pl";
2435       &menubar;
2436     }
2437   }
2438
2439   print qq|
2440
2441 </form>
2442
2443 </body>
2444 </html>
2445 |;
2446
2447   $lxdebug->leave_sub();
2448 }
2449
2450 sub makemodel_row {
2451   $lxdebug->enter_sub();
2452   my ($numrows) = @_;
2453
2454   $form->{"make_$i"}  =~ s/\"/&quot;/g;
2455   $form->{"model_$i"} =~ s/\"/&quot;/g;
2456
2457   print qq|
2458   <tr>
2459     <td>
2460       <table width=100%>
2461         <tr>
2462           <th class="listheading">| . $locale->text('Make') . qq|</th>
2463           <th class="listheading">| . $locale->text('Model') . qq|</th>
2464         </tr>
2465 |;
2466
2467   for $i (1 .. $numrows) {
2468     print qq|
2469         <tr>
2470           <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
2471           <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
2472         </tr>
2473 |;
2474   }
2475
2476   print qq|
2477       </table>
2478     </td>
2479   </tr>
2480 |;
2481
2482   $lxdebug->leave_sub();
2483 }
2484
2485 sub assembly_row {
2486   $lxdebug->enter_sub();
2487   my ($numrows) = @_;
2488
2489   @column_index =
2490     qw(runningnumber qty unit bom partnumber description partsgroup total);
2491
2492   if ($form->{previousform}) {
2493     $nochange     = 1;
2494     @column_index = qw(qty unit bom partnumber description partsgroup total);
2495   } else {
2496
2497     # change callback
2498     $form->{old_callback} = $form->{callback};
2499     $callback             = $form->{callback};
2500     $form->{callback}     = "$form->{script}?action=display_form";
2501
2502     # delete action
2503     map { delete $form->{$_} } qw(action header);
2504
2505     $previousform = "";
2506
2507     # save form variables in a previousform variable
2508     foreach $key (sort keys %$form) {
2509
2510       # escape ampersands
2511       $form->{$key} =~ s/&/%26/g;
2512       $previousform .= qq|$key=$form->{$key}&|;
2513     }
2514     chop $previousform;
2515     $previousform = $form->escape($form->escape($previousform, 1));
2516     $form->{callback} = $callback;
2517
2518     $form->{assemblytotal} = 0;
2519     $form->{weight}        = 0;
2520
2521   }
2522   $column_header{runningnumber} =
2523     qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
2524   $column_header{qty} =
2525     qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
2526   $column_header{unit} =
2527     qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
2528   $column_header{partnumber} =
2529       qq|<th align=left nowrap width=20%>|
2530     . $locale->text('Part Number')
2531     . qq|</th>|;
2532   $column_header{description} =
2533     qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
2534   $column_header{total} =
2535     qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
2536   $column_header{bom}        = qq|<th>| . $locale->text('BOM') . qq|</th>|;
2537   $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
2538
2539   print qq|
2540   <tr class=listheading>
2541     <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
2542   </tr>
2543   <tr>
2544     <td>
2545       <table width=100%>
2546         <tr>
2547 |;
2548
2549   map { print "\n$column_header{$_}" } @column_index;
2550
2551   print qq|
2552         </tr>
2553 |;
2554
2555   for $i (1 .. $numrows) {
2556     $form->{"partnumber_$i"} =~ s/\"/&quot;/g;
2557
2558     $linetotal =
2559       $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
2560     $form->{assemblytotal} += $linetotal;
2561
2562     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
2563
2564     $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
2565
2566     if (($i >= 1) && ($i == $numrows)) {
2567
2568       if ($nochange) {
2569         map { $column_data{$_} = qq|<td></td>| }
2570           qw(qty unit partnumber description bom partsgroup);
2571       } else {
2572
2573         map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
2574
2575         $column_data{qty} =
2576           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2577         $column_data{partnumber} =
2578           qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
2579         $column_data{description} =
2580           qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
2581         $column_data{partsgroup} =
2582           qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
2583
2584       }
2585
2586     } else {
2587
2588       if ($form->{previousform}) {
2589         $column_data{partnumber} =
2590           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
2591         $column_data{qty} =
2592           qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
2593
2594         $column_data{bom} =
2595           qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
2596         $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : "&nbsp;";
2597         $column_data{bom} .= qq|</td>|;
2598
2599         $column_data{partsgroup} =
2600           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2601
2602       } else {
2603         $href =
2604           qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&password=$form->{password}&rowcount=$i&previousform=$previousform|;
2605         $column_data{partnumber} =
2606           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
2607         $column_data{runningnumber} =
2608           qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
2609         $column_data{qty} =
2610           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2611
2612         $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
2613         $column_data{bom} =
2614           qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
2615
2616         $column_data{partsgroup} =
2617           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2618       }
2619
2620       $column_data{unit} =
2621         qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
2622       $column_data{description} =
2623         qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
2624     }
2625
2626     $column_data{total} = qq|<td align=right>$linetotal</td>|;
2627
2628     $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
2629
2630     print qq|
2631         <tr>|;
2632
2633     map { print "\n$column_data{$_}" } @column_index;
2634
2635     print qq|
2636         </tr>
2637   <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2638   <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
2639   <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
2640 |;
2641   }
2642
2643   print qq|
2644       </table>
2645     </td>
2646   </tr>
2647 |;
2648
2649   $lxdebug->leave_sub();
2650 }
2651
2652 sub update {
2653   $lxdebug->enter_sub();
2654
2655   if ($form->{item} eq "assembly") {
2656     $i = $form->{assembly_rows};
2657
2658     # if last row is empty check the form otherwise retrieve item
2659     if (   ($form->{"partnumber_$i"} eq "")
2660         && ($form->{"description_$i"} eq "")
2661         && ($form->{"partsgroup_$i"}  eq "")) {
2662
2663       &check_form;
2664
2665         } else {
2666
2667       IC->assembly_item(\%myconfig, \%$form);
2668
2669       $rows = scalar @{ $form->{item_list} };
2670
2671       if ($rows) {
2672         $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2673
2674         if ($rows > 1) {
2675           $form->{makemodel_rows}--;
2676           &select_item;
2677           exit;
2678         } else {
2679           map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g }
2680             qw(partnumber description unit partsgroup);
2681           map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
2682             keys %{ $form->{item_list}[0] };
2683           $form->{"runningnumber_$i"} = $form->{assembly_rows};
2684           $form->{assembly_rows}++;
2685
2686           &check_form;
2687
2688         }
2689
2690       } else {
2691
2692         $form->{rowcount} = $i;
2693         $form->{assembly_rows}++;
2694
2695         &new_item;
2696
2697       }
2698     }
2699   }
2700
2701   if ($form->{item} eq "part") {
2702     &check_form;
2703   }
2704
2705   if ($form->{item} eq 'service') {
2706     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2707       qw(sellprice listprice);
2708     &form_header;
2709     &form_footer;
2710   }
2711
2712   $lxdebug->leave_sub();
2713 }
2714
2715 sub save {
2716   $lxdebug->enter_sub();
2717
2718   # check if there is a part number - commented out, cause there is an automatic allocation of numbers
2719   # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
2720
2721   # check if there is a description
2722   $form->isblank("description", $locale->text("Part Description missing!"));
2723
2724   if ($form->{obsolete}) {
2725     $form->error(
2726       $locale->text(
2727         "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
2728       ))
2729       if ($form->{onhand});
2730   }
2731
2732   # expand dynamic strings
2733   # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
2734   # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
2735   # $locale->text('Part Number missing!')
2736   # $locale->text('Service Number missing!')
2737   # $locale->text('Assembly Number missing!')
2738
2739   # save part
2740   $lxdebug->message(LXDebug::DEBUG1,
2741                     "ic.pl: sellprice in save = $form->{sellprice}\n");
2742   $rc = IC->save(\%myconfig, \%$form);
2743   if ($rc == 3) {
2744     $form->error($locale->text('Partnumber not unique!'));
2745   }
2746   $parts_id = $form->{id};
2747
2748   # load previous variables
2749   if ($form->{previousform}) {
2750
2751     # save the new form variables before splitting previousform
2752     map { $newform{$_} = $form->{$_} } keys %$form;
2753
2754     $previousform = $form->unescape($form->{previousform});
2755
2756     # don't trample on previous variables
2757     map { delete $form->{$_} } keys %newform;
2758
2759     # now take it apart and restore original values
2760     foreach $item (split /&/, $previousform) {
2761       ($key, $value) = split /=/, $item, 2;
2762       $value =~ s/%26/&/g;
2763       $form->{$key} = $value;
2764     }
2765     $form->{taxaccounts} = $newform{taxaccount2};
2766
2767     if ($form->{item} eq 'assembly') {
2768
2769       # undo number formatting
2770       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2771         qw(weight listprice sellprice rop);
2772
2773       $form->{assembly_rows}--;
2774       $i = $newform{rowcount};
2775       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2776
2777       $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
2778       $form->{weight}    -= $form->{"weight_$i"} * $form->{"qty_$i"};
2779
2780       # change/add values for assembly item
2781       map { $form->{"${_}_$i"} = $newform{$_} }
2782         qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno);
2783
2784       $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
2785       $form->{weight}    += $form->{"weight_$i"} * $form->{"qty_$i"};
2786
2787     } else {
2788
2789       # set values for last invoice/order item
2790       $i = $form->{rowcount};
2791       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2792
2793       map { $form->{"${_}_$i"} = $newform{$_} }
2794         qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice);
2795       $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
2796       if ($form->{exchangerate} != 0) {
2797         $form->{"sellprice_$i"} /= $form->{exchangerate};
2798       }
2799       $lxdebug->message(LXDebug::DEBUG1,
2800                         qq|sellprice_$i in previousform 2 = |
2801                           . $form->{"sellprice_$i"} . qq|\n|);
2802       map { $form->{"taxaccounts_$i"} .= "$_ " } split / /,
2803         $newform{taxaccount};
2804       chop $form->{"taxaccounts_$i"};
2805       foreach $item (qw(description rate taxnumber)) {
2806         $index = $form->{"taxaccounts_$i"} . "_$item";
2807         $form->{$index} = $newform{$index};
2808       }
2809
2810       # credit remaining calculation
2811       $amount =
2812         $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
2813         $form->{"qty_$i"};
2814       map { $form->{"${_}_base"} += $amount }
2815         (split / /, $form->{"taxaccounts_$i"});
2816       map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
2817         split / /, $form->{"taxaccounts_$i"}
2818         if !$form->{taxincluded};
2819
2820       $form->{creditremaining} -= $amount;
2821
2822       # redo number formatting, because invoice parse them!
2823       $i = $form->{rowcount};
2824       map {
2825         $form->{"${_}_$i"} =
2826           $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2827       } qw(weight listprice sellprice rop);
2828     }
2829
2830     $form->{"id_$i"} = $parts_id;
2831     delete $form->{action};
2832
2833     # restore original callback
2834     $callback = $form->unescape($form->{callback});
2835     $form->{callback} = $form->unescape($form->{old_callback});
2836     delete $form->{old_callback};
2837
2838     $form->{makemodel_rows}--;
2839
2840     # put callback together
2841     foreach $key (keys %$form) {
2842
2843       # do single escape for Apache 2.0
2844       $value = $form->escape($form->{$key}, 1);
2845       $callback .= qq|&$key=$value|;
2846     }
2847     $form->{callback} = $callback;
2848   }
2849   $lxdebug->message(LXDebug::DEBUG1,
2850                     qq|ic.pl: sellprice_$i nach sub save = |
2851                       . $form->{"sellprice_$i"} . qq|\n|);
2852
2853   # redirect
2854   $form->redirect;
2855
2856   $lxdebug->leave_sub();
2857 }
2858
2859 sub save_as_new {
2860   $lxdebug->enter_sub();
2861
2862   $form->{id} = 0;
2863   &save;
2864
2865   $lxdebug->leave_sub();
2866 }
2867
2868 sub delete {
2869   $lxdebug->enter_sub();
2870
2871   $rc = IC->delete(\%myconfig, \%$form);
2872
2873   # redirect
2874   $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2875   $form->error($locale->text('Cannot delete item!'));
2876
2877   $lxdebug->leave_sub();
2878 }
2879
2880 sub stock_assembly {
2881   $lxdebug->enter_sub();
2882
2883   $form->{title} = $locale->text('Stock Assembly');
2884
2885   $form->header;
2886
2887   print qq|
2888 <body>
2889
2890 <form method=post action=$form->{script}>
2891
2892 <table width="100%">
2893   <tr>
2894     <th class=listtop>$form->{title}</th>
2895   </tr>
2896   <tr height="5"></tr>
2897   <tr valign=top>
2898     <td>
2899       <table>
2900         <tr>
2901           <th align="right" nowrap="true">|
2902     . $locale->text('Part Number') . qq|</th>
2903           <td><input name=partnumber size=20></td>
2904           <td>&nbsp;</td>
2905         </tr>
2906         <tr>
2907           <th align="right" nowrap="true">|
2908     . $locale->text('Part Description') . qq|</th>
2909           <td><input name=description size=40></td>
2910         </tr>
2911       </table>
2912     </td>
2913   </tr>
2914   <tr><td><hr size=3 noshade></td></tr>
2915 </table>
2916
2917 <input type=hidden name=path value=$form->{path}>
2918 <input type=hidden name=login value=$form->{login}>
2919 <input type=hidden name=password value=$form->{password}>
2920
2921 <input type=hidden name=nextsub value=list_assemblies>
2922
2923 <br>
2924 <input class=submit type=submit name=action value="|
2925     . $locale->text('Continue') . qq|">
2926 </form>
2927
2928 </body>
2929 </html>
2930 |;
2931
2932   $lxdebug->leave_sub();
2933 }
2934
2935 sub list_assemblies {
2936   $lxdebug->enter_sub();
2937
2938   IC->retrieve_assemblies(\%myconfig, \%$form);
2939
2940   $column_header{partnumber} =
2941     qq|<th class=listheading>| . $locale->text('Part Number') . qq|</th>|;
2942   $column_header{description} =
2943     qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
2944   $column_header{bin} =
2945     qq|<th class=listheading>| . $locale->text('Bin') . qq|</th>|;
2946   $column_header{onhand} =
2947     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
2948   $column_header{rop} =
2949     qq|<th class=listheading>| . $locale->text('ROP') . qq|</th>|;
2950   $column_header{stock} =
2951     qq|<th class=listheading>| . $locale->text('Add') . qq|</th>|;
2952
2953   @column_index = (qw(partnumber description bin onhand rop stock));
2954
2955   $form->{title} = $locale->text('Stock Assembly');
2956
2957   $form->{callback} =
2958     "$form->{script}?action=stock_assembly&path=$form->{path}&login=$form->{login}&password=$form->{password}";
2959
2960   $form->header;
2961
2962   $colspan = $#column_index + 1;
2963
2964   print qq|
2965 <body>
2966
2967 <form method=post action=$form->{script}>
2968
2969 <table width=100%>
2970   <tr>
2971     <th class=listtop colspan=$colspan>$form->{title}</th>
2972   </tr>
2973   <tr size=5></tr>
2974   <tr class=listheading>|;
2975
2976   map { print "\n$column_header{$_}" } @column_index;
2977
2978   print qq|
2979   </tr>
2980 |;
2981
2982   $i = 1;
2983   foreach $ref (@{ $form->{assembly_items} }) {
2984
2985     map { $ref->{$_} =~ s/\"/&quot;/g } qw(partnumber description);
2986
2987     $column_data{partnumber}  = qq|<td width=20%>$ref->{partnumber}</td>|;
2988     $column_data{description} =
2989       qq|<td width=50%>$ref->{description}&nbsp;</td>|;
2990     $column_data{bin}    = qq|<td>$ref->{bin}&nbsp;</td>|;
2991     $column_data{onhand} =
2992         qq|<td align=right>|
2993       . $form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")
2994       . qq|</td>|;
2995     $column_data{rop} =
2996         qq|<td align=right>|
2997       . $form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;")
2998       . qq|</td>|;
2999     $column_data{stock} = qq|<td width=10%><input name="qty_$i" size=10></td>|;
3000
3001     $j++;
3002     $j %= 2;
3003     print
3004       qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
3005
3006     map { print "\n$column_data{$_}" } @column_index;
3007
3008     print qq|
3009     </tr>
3010 |;
3011
3012     $i++;
3013
3014   }
3015
3016   $i--;
3017   print qq|
3018   <tr>
3019     <td colspan=6><hr size=3 noshade>
3020   </tr>
3021 </table>
3022 <input name=rowcount type=hidden value="$i">
3023
3024 <input type=hidden name=path value=$form->{path}>
3025 <input type=hidden name=login value=$form->{login}>
3026 <input type=hidden name=password value=$form->{password}>
3027
3028 <input name=callback type=hidden value="$form->{callback}">
3029
3030 <input type=hidden name=nextsub value=restock_assemblies>
3031
3032 <br>
3033 <input class=submit type=submit name=action value="|
3034     . $locale->text('Continue') . qq|">
3035
3036 </form>
3037
3038 </body>
3039 </html>
3040 |;
3041
3042   $lxdebug->leave_sub();
3043 }
3044
3045 sub restock_assemblies {
3046   $lxdebug->enter_sub();
3047
3048   $form->redirect($locale->text('Assemblies restocked!'))
3049     if (IC->restock_assemblies(\%myconfig, \%$form));
3050   $form->error($locale->text('Cannot stock assemblies!'));
3051
3052   $lxdebug->leave_sub();
3053 }
3054
3055 sub price_row {
3056   $lxdebug->enter_sub();
3057
3058   my ($numrows) = @_;
3059
3060   print qq|
3061   <tr>
3062     <td>
3063       <table width=100%>
3064         <tr>
3065           <th class="listheading">| . $locale->text('Preisklasse') . qq|</th>
3066           <th class="listheading">| . $locale->text('Preis') . qq|</th>
3067         </tr>
3068 |;
3069   for $i (1 .. $numrows) {
3070     print qq|
3071         <tr>
3072           <td width=50%><input type=hidden name="pricegroup_$i" size=30  value="$form->{"pricegroup_$i"}">$form->{"pricegroup_$i"}</td>
3073           <td width=50%><input name="price_$i" size=11 value="$form->{"price_$i"}"></td>
3074           <input type=hidden name="pricegroup_id_$i" value="$form->{"pricegroup_id_$i"}">
3075         </tr>
3076 |;
3077   }
3078
3079   print qq|
3080       </table>
3081     </td>
3082   </tr>
3083 |;
3084
3085   $lxdebug->leave_sub();
3086 }
3087
3088 sub continue { &{ $form->{nextsub} } }