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