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