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