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