solved Bug 248.
[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                           "", "");
2233   } else {
2234
2235     # without JavaScript Calendar
2236     $button1 = qq|
2237                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
2238   }
2239
2240   $form->{fokus} = "ic.partnumber";
2241   $form->header;
2242
2243   print qq|
2244   <body onLoad="fokus()">
2245
2246
2247 <form method=post name="ic" action=$form->{script}>
2248
2249 <input name=id type=hidden value=$form->{id}>
2250 <input name=item type=hidden value=$form->{item}>
2251 <input name=title type=hidden value="$form->{title}">
2252 <input name=makemodel type=hidden value="$form->{makemodel}">
2253 <input name=alternate type=hidden value="$form->{alternate}">
2254 <input name=onhand type=hidden value=$form->{onhand}>
2255 <input name=orphaned type=hidden value=$form->{orphaned}>
2256 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
2257 <input name=rowcount type=hidden value=$form->{rowcount}>
2258 <input name=eur type=hidden value=$eur>
2259
2260 <table width="100%">
2261   <tr>
2262     <th class=listtop>$form->{title}</th>
2263   </tr>
2264   <tr height="5"></tr>
2265   <tr>
2266     <td>
2267       <table width="100%">
2268         <tr valign=top>
2269           <th align=left>| . $locale->text('Part Number') . qq|</th>
2270           <th align=left>| . $locale->text('Part Description') . qq|</th>
2271           <th align=left>$group</th>
2272         </tr>
2273         <tr valign=top>
2274           <td><input name=partnumber value="$form->{partnumber}" size=20></td>
2275           <td>$description</td>
2276           <td>$partsgroup</td>
2277           <input type=hidden name=oldpartsgroup value="$form->{oldpartsgroup}">
2278         </tr>
2279       </table>
2280     </td>
2281   </tr>
2282   <tr>
2283     <td>
2284       <table width="100%" height="100%">
2285         <tr valign=top>
2286           <td width=70%>
2287             <table width="100%" height="100%">
2288               <tr class="listheading">
2289                 <th class="listheading" align="center" colspan=2>|
2290     . $locale->text('Link Accounts') . qq|</th>
2291               </tr>
2292               $linkaccounts
2293               <tr>
2294                 <th align="left">| . $locale->text('Notes') . qq|</th>
2295               </tr>
2296               <tr>
2297                 <td colspan=2>
2298                   $notes
2299                 </td>
2300               </tr>
2301             </table>
2302           </td>
2303           <td width="30%">
2304             <table width="100%">
2305               <tr>
2306                 <th align="right" nowrap="true">|
2307     . $locale->text('Updated') . qq|</th>
2308                 $button1
2309               </tr>
2310               <tr>
2311                 <th align="right" nowrap="true">| . $locale->text('List Price') . qq|</th>
2312                 <td><input name=listprice size=11 value=$form->{listprice}></td>
2313               </tr>
2314               <tr>
2315                 <th align="right" nowrap="true">| . $locale->text('Sell Price') . qq|</th>
2316                 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
2317               </tr>
2318               $lastcost
2319               <tr>
2320                 <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
2321                 <td><input name=unit size=5 maxlength="10" value="$form->{unit}"></td>
2322               </tr>
2323               $weight
2324               $rop
2325               $bin
2326               $vegv
2327               $obsolete
2328             </table>
2329           </td>
2330         </tr>
2331       </table>
2332     </td>
2333   </tr>
2334   $imagelinks
2335
2336 $jsscript
2337 |;
2338   $lxdebug->leave_sub();
2339 }
2340
2341 sub form_footer {
2342   $lxdebug->enter_sub();
2343
2344   if ($form->{item} eq "assembly") {
2345
2346     print qq|
2347         <tr>
2348           <td>
2349             <table width="100%">
2350               <tr>
2351                 <th colspan=2 align=right>|
2352       . $locale->text('Total') . qq|&nbsp;</th>
2353                 <th align=right>|
2354       . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
2355               </tr>
2356             </table>
2357           </td>
2358         </tr>
2359         <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
2360 |;
2361   }
2362
2363   print qq|
2364       <input type=hidden name=path value=$form->{path}>
2365       <input type=hidden name=login value=$form->{login}>
2366       <input type=hidden name=password value=$form->{password}>
2367       <input type=hidden name=callback value="$form->{callback}">
2368       <input type=hidden name=previousform value="$form->{previousform}">
2369       <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
2370       <input type=hidden name=vc value=$form->{vc}>
2371   <tr>
2372     <td><hr size=3 noshade></td>
2373   </tr>
2374 </table>
2375
2376 <br>
2377 <input class=submit type=submit name=action value="|
2378     . $locale->text('Update') . qq|">
2379   |;
2380
2381   unless ($form->{item} eq "service") {
2382     print qq|
2383       <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
2384     |;
2385   }
2386
2387   print qq|
2388      <input type=hidden name=price_rows value=$form->{price_rows}>|;
2389
2390   print qq|
2391       <input class=submit type=submit name=action value="|
2392     . $locale->text('Save') . qq|">|;
2393
2394   if ($form->{id}) {
2395
2396     if (!$form->{previousform}) {
2397       print qq|
2398       <input class=submit type=submit name=action value="|
2399         . $locale->text('Save as new') . qq|">|;
2400     }
2401
2402     if ($form->{orphaned}) {
2403       if (!$form->{previousform}) {
2404         if ($form->{item} eq 'assembly') {
2405           if (!$form->{onhand}) {
2406             print qq|
2407       <input class=submit type=submit name=action value="|
2408               . $locale->text('Delete') . qq|">|;
2409           }
2410         } else {
2411           print qq|
2412       <input class=submit type=submit name=action value="|
2413             . $locale->text('Delete') . qq|">|;
2414         }
2415       }
2416     }
2417   }
2418
2419   if (!$form->{previousform}) {
2420     if ($form->{menubar}) {
2421       require "$form->{path}/menu.pl";
2422       &menubar;
2423     }
2424   }
2425
2426   print qq|
2427
2428 </form>
2429
2430 </body>
2431 </html>
2432 |;
2433
2434   $lxdebug->leave_sub();
2435 }
2436
2437 sub makemodel_row {
2438   $lxdebug->enter_sub();
2439   my ($numrows) = @_;
2440
2441   $form->{"make_$i"}  =~ s/\"/&quot;/g;
2442   $form->{"model_$i"} =~ s/\"/&quot;/g;
2443
2444   print qq|
2445   <tr>
2446     <td>
2447       <table width=100%>
2448         <tr>
2449           <th class="listheading">| . $locale->text('Make') . qq|</th>
2450           <th class="listheading">| . $locale->text('Model') . qq|</th>
2451         </tr>
2452 |;
2453
2454   for $i (1 .. $numrows) {
2455     print qq|
2456         <tr>
2457           <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
2458           <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
2459         </tr>
2460 |;
2461   }
2462
2463   print qq|
2464       </table>
2465     </td>
2466   </tr>
2467 |;
2468
2469   $lxdebug->leave_sub();
2470 }
2471
2472 sub assembly_row {
2473   $lxdebug->enter_sub();
2474   my ($numrows) = @_;
2475
2476   @column_index =
2477     qw(runningnumber qty unit bom partnumber description partsgroup total);
2478
2479   if ($form->{previousform}) {
2480     $nochange     = 1;
2481     @column_index = qw(qty unit bom partnumber description partsgroup total);
2482   } else {
2483
2484     # change callback
2485     $form->{old_callback} = $form->{callback};
2486     $callback             = $form->{callback};
2487     $form->{callback}     = "$form->{script}?action=display_form";
2488
2489     # delete action
2490     map { delete $form->{$_} } qw(action header);
2491
2492     $previousform = "";
2493
2494     # save form variables in a previousform variable
2495     foreach $key (sort keys %$form) {
2496
2497       # escape ampersands
2498       $form->{$key} =~ s/&/%26/g;
2499       $previousform .= qq|$key=$form->{$key}&|;
2500     }
2501     chop $previousform;
2502     $previousform = $form->escape($form->escape($previousform, 1));
2503     $form->{callback} = $callback;
2504
2505     $form->{assemblytotal} = 0;
2506     $form->{weight}        = 0;
2507
2508   }
2509   $column_header{runningnumber} =
2510     qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
2511   $column_header{qty} =
2512     qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
2513   $column_header{unit} =
2514     qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
2515   $column_header{partnumber} =
2516       qq|<th align=left nowrap width=20%>|
2517     . $locale->text('Part Number')
2518     . qq|</th>|;
2519   $column_header{description} =
2520     qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
2521   $column_header{total} =
2522     qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
2523   $column_header{bom}        = qq|<th>| . $locale->text('BOM') . qq|</th>|;
2524   $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
2525
2526   print qq|
2527   <tr class=listheading>
2528     <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
2529   </tr>
2530   <tr>
2531     <td>
2532       <table width=100%>
2533         <tr>
2534 |;
2535
2536   map { print "\n$column_header{$_}" } @column_index;
2537
2538   print qq|
2539         </tr>
2540 |;
2541
2542   for $i (1 .. $numrows) {
2543     $form->{"partnumber_$i"} =~ s/\"/&quot;/g;
2544
2545     $linetotal =
2546       $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
2547     $form->{assemblytotal} += $linetotal;
2548
2549     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
2550
2551     $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
2552
2553     if (($i >= 1) && ($i == $numrows)) {
2554
2555       if ($nochange) {
2556         map { $column_data{$_} = qq|<td></td>| }
2557           qw(qty unit partnumber description bom partsgroup);
2558       } else {
2559
2560         map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
2561
2562         $column_data{qty} =
2563           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2564         $column_data{partnumber} =
2565           qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
2566         $column_data{description} =
2567           qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
2568         $column_data{partsgroup} =
2569           qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
2570
2571       }
2572
2573     } else {
2574
2575       if ($form->{previousform}) {
2576         $column_data{partnumber} =
2577           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
2578         $column_data{qty} =
2579           qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
2580
2581         $column_data{bom} =
2582           qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
2583         $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : "&nbsp;";
2584         $column_data{bom} .= qq|</td>|;
2585
2586         $column_data{partsgroup} =
2587           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2588
2589       } else {
2590         $href =
2591           qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&password=$form->{password}&rowcount=$i&previousform=$previousform|;
2592         $column_data{partnumber} =
2593           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
2594         $column_data{runningnumber} =
2595           qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
2596         $column_data{qty} =
2597           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2598
2599         $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
2600         $column_data{bom} =
2601           qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
2602
2603         $column_data{partsgroup} =
2604           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2605       }
2606
2607       $column_data{unit} =
2608         qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
2609       $column_data{description} =
2610         qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
2611     }
2612
2613     $column_data{total} = qq|<td align=right>$linetotal</td>|;
2614
2615     print qq|
2616         <tr>|;
2617
2618     map { print "\n$column_data{$_}" } @column_index;
2619
2620     print qq|
2621         </tr>
2622   <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2623   <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
2624   <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
2625 |;
2626   }
2627
2628   print qq|
2629       </table>
2630     </td>
2631   </tr>
2632 |;
2633
2634   $lxdebug->leave_sub();
2635 }
2636
2637 sub update {
2638   $lxdebug->enter_sub();
2639
2640   if ($form->{item} eq "assembly") {
2641     $i = $form->{assembly_rows};
2642
2643     # if last row is empty check the form otherwise retrieve item
2644     if (   ($form->{"partnumber_$i"} eq "")
2645         && ($form->{"description_$i"} eq "")
2646         && ($form->{"partsgroup_$i"}  eq "")) {
2647
2648       &check_form;
2649
2650         } else {
2651
2652       IC->assembly_item(\%myconfig, \%$form);
2653
2654       $rows = scalar @{ $form->{item_list} };
2655
2656       if ($rows) {
2657         $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2658
2659         if ($rows > 1) {
2660           $form->{makemodel_rows}--;
2661           &select_item;
2662           exit;
2663         } else {
2664           map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g }
2665             qw(partnumber description unit partsgroup);
2666           map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
2667             keys %{ $form->{item_list}[0] };
2668           $form->{"runningnumber_$i"} = $form->{assembly_rows};
2669           $form->{assembly_rows}++;
2670
2671           &check_form;
2672
2673         }
2674
2675       } else {
2676
2677         $form->{rowcount} = $i;
2678         $form->{assembly_rows}++;
2679
2680         &new_item;
2681
2682       }
2683     }
2684   }
2685
2686   if ($form->{item} eq "part") {
2687     &check_form;
2688   }
2689
2690   if ($form->{item} eq 'service') {
2691     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2692       qw(sellprice listprice);
2693     &form_header;
2694     &form_footer;
2695   }
2696
2697   $lxdebug->leave_sub();
2698 }
2699
2700 sub save {
2701   $lxdebug->enter_sub();
2702
2703   # check if there is a part number
2704   # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
2705
2706   if ($form->{obsolete}) {
2707     $form->error(
2708       $locale->text(
2709         "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
2710       ))
2711       if ($form->{onhand});
2712   }
2713
2714   # expand dynamic strings
2715   # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
2716   # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
2717   # $locale->text('Part Number missing!')
2718   # $locale->text('Service Number missing!')
2719   # $locale->text('Assembly Number missing!')
2720
2721   # save part
2722   $lxdebug->message(LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
2723   $rc = IC->save(\%myconfig, \%$form);
2724   if ($rc == 3) {
2725     $form->error($locale->text('Partnumber not unique!'));
2726   }
2727   $parts_id = $form->{id};
2728
2729   # load previous variables
2730   if ($form->{previousform}) {
2731
2732     # save the new form variables before splitting previousform
2733     map { $newform{$_} = $form->{$_} } keys %$form;
2734
2735     $previousform = $form->unescape($form->{previousform});
2736
2737     # don't trample on previous variables
2738     map { delete $form->{$_} } keys %newform;
2739
2740     # now take it apart and restore original values
2741     foreach $item (split /&/, $previousform) {
2742       ($key, $value) = split /=/, $item, 2;
2743       $value =~ s/%26/&/g;
2744       $form->{$key} = $value;
2745     }
2746     $form->{taxaccounts} = $newform{taxaccount2};
2747
2748     if ($form->{item} eq 'assembly') {
2749
2750       # undo number formatting
2751       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2752         qw(weight listprice sellprice rop);
2753
2754       $form->{assembly_rows}--;
2755       $i = $newform{rowcount};
2756       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2757
2758       $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
2759       $form->{weight}    -= $form->{"weight_$i"} * $form->{"qty_$i"};
2760
2761       # change/add values for assembly item
2762       map { $form->{"${_}_$i"} = $newform{$_} }
2763         qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno);
2764
2765       $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
2766       $form->{weight}    += $form->{"weight_$i"} * $form->{"qty_$i"};
2767
2768     } else {
2769
2770       # set values for last invoice/order item
2771       $i = $form->{rowcount};
2772       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2773
2774       map { $form->{"${_}_$i"} = $newform{$_} }
2775         qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice);
2776       $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
2777       if ($form->{exchangerate} != 0) {
2778         $form->{"sellprice_$i"} /= $form->{exchangerate};
2779       }
2780       $lxdebug->message(LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = |.$form->{"sellprice_$i"}.qq|\n|);
2781       map { $form->{"taxaccounts_$i"} .= "$_ " } split / /,
2782         $newform{taxaccount};
2783       chop $form->{"taxaccounts_$i"};
2784       foreach $item (qw(description rate taxnumber)) {
2785         $index = $form->{"taxaccounts_$i"} . "_$item";
2786         $form->{$index} = $newform{$index};
2787       }
2788
2789       # credit remaining calculation
2790       $amount =
2791         $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
2792         $form->{"qty_$i"};
2793       map { $form->{"${_}_base"} += $amount }
2794         (split / /, $form->{"taxaccounts_$i"});
2795       map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
2796         split / /, $form->{"taxaccounts_$i"}
2797         if !$form->{taxincluded};
2798
2799       $form->{creditremaining} -= $amount;
2800
2801     # redo number formatting, because invoice parse them!
2802     $i = $form->{rowcount};
2803     map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}) }
2804     qw(weight listprice sellprice rop);
2805     }
2806
2807     $form->{"id_$i"} = $parts_id;
2808     delete $form->{action};
2809
2810     # restore original callback
2811     $callback = $form->unescape($form->{callback});
2812     $form->{callback} = $form->unescape($form->{old_callback});
2813     delete $form->{old_callback};
2814
2815     $form->{makemodel_rows}--;
2816
2817     # put callback together
2818     foreach $key (keys %$form) {
2819
2820       # do single escape for Apache 2.0
2821       $value = $form->escape($form->{$key}, 1);
2822       $callback .= qq|&$key=$value|;
2823     }
2824     $form->{callback} = $callback;
2825   }
2826   $lxdebug->message(LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = |.$form->{"sellprice_$i"}.qq|\n|);
2827   # redirect
2828   $form->redirect;
2829
2830   $lxdebug->leave_sub();
2831 }
2832
2833 sub save_as_new {
2834   $lxdebug->enter_sub();
2835
2836   $form->{id} = 0;
2837   &save;
2838
2839   $lxdebug->leave_sub();
2840 }
2841
2842 sub delete {
2843   $lxdebug->enter_sub();
2844
2845   $rc = IC->delete(\%myconfig, \%$form);
2846
2847   # redirect
2848   $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2849   $form->error($locale->text('Cannot delete item!'));
2850
2851   $lxdebug->leave_sub();
2852 }
2853
2854 sub stock_assembly {
2855   $lxdebug->enter_sub();
2856
2857   $form->{title} = $locale->text('Stock Assembly');
2858
2859   $form->header;
2860
2861   print qq|
2862 <body>
2863
2864 <form method=post action=$form->{script}>
2865
2866 <table width="100%">
2867   <tr>
2868     <th class=listtop>$form->{title}</th>
2869   </tr>
2870   <tr height="5"></tr>
2871   <tr valign=top>
2872     <td>
2873       <table>
2874         <tr>
2875           <th align="right" nowrap="true">|
2876     . $locale->text('Part Number') . qq|</th>
2877           <td><input name=partnumber size=20></td>
2878           <td>&nbsp;</td>
2879         </tr>
2880         <tr>
2881           <th align="right" nowrap="true">|
2882     . $locale->text('Part Description') . qq|</th>
2883           <td><input name=description size=40></td>
2884         </tr>
2885       </table>
2886     </td>
2887   </tr>
2888   <tr><td><hr size=3 noshade></td></tr>
2889 </table>
2890
2891 <input type=hidden name=path value=$form->{path}>
2892 <input type=hidden name=login value=$form->{login}>
2893 <input type=hidden name=password value=$form->{password}>
2894
2895 <input type=hidden name=nextsub value=list_assemblies>
2896
2897 <br>
2898 <input class=submit type=submit name=action value="|
2899     . $locale->text('Continue') . qq|">
2900 </form>
2901
2902 </body>
2903 </html>
2904 |;
2905
2906   $lxdebug->leave_sub();
2907 }
2908
2909 sub list_assemblies {
2910   $lxdebug->enter_sub();
2911
2912   IC->retrieve_assemblies(\%myconfig, \%$form);
2913
2914   $column_header{partnumber} =
2915     qq|<th class=listheading>| . $locale->text('Part Number') . qq|</th>|;
2916   $column_header{description} =
2917     qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
2918   $column_header{bin} =
2919     qq|<th class=listheading>| . $locale->text('Bin') . qq|</th>|;
2920   $column_header{onhand} =
2921     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
2922   $column_header{rop} =
2923     qq|<th class=listheading>| . $locale->text('ROP') . qq|</th>|;
2924   $column_header{stock} =
2925     qq|<th class=listheading>| . $locale->text('Add') . qq|</th>|;
2926
2927   @column_index = (qw(partnumber description bin onhand rop stock));
2928
2929   $form->{title} = $locale->text('Stock Assembly');
2930
2931   $form->{callback} =
2932     "$form->{script}?action=stock_assembly&path=$form->{path}&login=$form->{login}&password=$form->{password}";
2933
2934   $form->header;
2935
2936   $colspan = $#column_index + 1;
2937
2938   print qq|
2939 <body>
2940
2941 <form method=post action=$form->{script}>
2942
2943 <table width=100%>
2944   <tr>
2945     <th class=listtop colspan=$colspan>$form->{title}</th>
2946   </tr>
2947   <tr size=5></tr>
2948   <tr class=listheading>|;
2949
2950   map { print "\n$column_header{$_}" } @column_index;
2951
2952   print qq|
2953   </tr>
2954 |;
2955
2956   $i = 1;
2957   foreach $ref (@{ $form->{assembly_items} }) {
2958
2959     map { $ref->{$_} =~ s/\"/&quot;/g } qw(partnumber description);
2960
2961     $column_data{partnumber}  = qq|<td width=20%>$ref->{partnumber}</td>|;
2962     $column_data{description} =
2963       qq|<td width=50%>$ref->{description}&nbsp;</td>|;
2964     $column_data{bin}    = qq|<td>$ref->{bin}&nbsp;</td>|;
2965     $column_data{onhand} =
2966         qq|<td align=right>|
2967       . $form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")
2968       . qq|</td>|;
2969     $column_data{rop} =
2970         qq|<td align=right>|
2971       . $form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;")
2972       . qq|</td>|;
2973     $column_data{stock} = qq|<td width=10%><input name="qty_$i" size=10></td>|;
2974
2975     $j++;
2976     $j %= 2;
2977     print
2978       qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
2979
2980     map { print "\n$column_data{$_}" } @column_index;
2981
2982     print qq|
2983     </tr>
2984 |;
2985
2986     $i++;
2987
2988   }
2989
2990   $i--;
2991   print qq|
2992   <tr>
2993     <td colspan=6><hr size=3 noshade>
2994   </tr>
2995 </table>
2996 <input name=rowcount type=hidden value="$i">
2997
2998 <input type=hidden name=path value=$form->{path}>
2999 <input type=hidden name=login value=$form->{login}>
3000 <input type=hidden name=password value=$form->{password}>
3001
3002 <input name=callback type=hidden value="$form->{callback}">
3003
3004 <input type=hidden name=nextsub value=restock_assemblies>
3005
3006 <br>
3007 <input class=submit type=submit name=action value="|
3008     . $locale->text('Continue') . qq|">
3009
3010 </form>
3011
3012 </body>
3013 </html>
3014 |;
3015
3016   $lxdebug->leave_sub();
3017 }
3018
3019 sub restock_assemblies {
3020   $lxdebug->enter_sub();
3021
3022   $form->redirect($locale->text('Assemblies restocked!'))
3023     if (IC->restock_assemblies(\%myconfig, \%$form));
3024   $form->error($locale->text('Cannot stock assemblies!'));
3025
3026   $lxdebug->leave_sub();
3027 }
3028
3029 sub price_row {
3030   $lxdebug->enter_sub();
3031
3032   my ($numrows) = @_;
3033
3034   print qq|
3035   <tr>
3036     <td>
3037       <table width=100%>
3038         <tr>
3039           <th class="listheading">| . $locale->text('Preisklasse') . qq|</th>
3040           <th class="listheading">| . $locale->text('Preis') . qq|</th>
3041         </tr>
3042 |;
3043   for $i (1 .. $numrows) {
3044     print qq|
3045         <tr>
3046           <td width=50%><input type=hidden name="pricegroup_$i" size=30  value="$form->{"pricegroup_$i"}">$form->{"pricegroup_$i"}</td>
3047           <td width=50%><input name="price_$i" size=11 value="$form->{"price_$i"}"></td>
3048           <input type=hidden name="pricegroup_id_$i" value="$form->{"pricegroup_id_$i"}">
3049         </tr>
3050 |;
3051   }
3052
3053   print qq|
3054       </table>
3055     </td>
3056   </tr>
3057 |;
3058
3059   $lxdebug->leave_sub();
3060 }
3061
3062 sub continue { &{ $form->{nextsub} } }