6d49eab28470e98fb81eb0a15f6a0610b2c1cdc6
[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   my $dec = '';
1959   
1960   #decimalplaces for listprice
1961   ($dec) = ($form->{listprice} =~ /\.(\d+)/);
1962   $dec = length $dec;
1963   my $decimalplaces = ($dec > 2) ? $dec : 2;
1964   $form->{listprice} =
1965     $form->format_amount(\%myconfig, $form->{listprice}, $decimalplaces);
1966
1967   #decimalplaces for sellprice and gv
1968   ($dec) = ($form->{sellprice} =~ /\.(\d+)/);
1969   $dec = length $dec;
1970   my $decimalplaces = ($dec > 2) ? $dec : 2;
1971
1972   map {
1973     $form->{$_} =
1974       $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces)
1975   } qw(sellprice gv);
1976
1977   ($dec) = ($form->{lastcost} =~ /\.(\d+)/);
1978   $dec = length $dec;
1979   my $decimalplaces = ($dec > 2) ? $dec : 2;
1980
1981   $form->{lastcost} =
1982     $form->format_amount(\%myconfig, $form->{lastcost}, $decimalplaces);
1983
1984   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
1985     qw(weight rop stock);
1986
1987   foreach $item (qw(partnumber description unit notes)) {
1988     $form->{$item} =~ s/\"/&quot;/g;
1989   }
1990
1991   if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
1992     $rows = 2;
1993   }
1994
1995   $notes =
1996     qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
1997   if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
1998     $description =
1999       qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
2000   } else {
2001     $description =
2002       qq|<input name=description size=40 value="$form->{description}">|;
2003   }
2004
2005   foreach $item (split / /, $form->{taxaccounts}) {
2006     $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : "";
2007   }
2008
2009   # set option
2010   foreach $item (qw(IC IC_income IC_expense)) {
2011     if ($form->{$item}) {
2012       if ($form->{id} && $form->{orphaned}) {
2013         $form->{"select$item"} =~ s/ selected//;
2014         $form->{"select$item"} =~
2015           s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
2016       } else {
2017         $form->{"select$item"} = qq|<option selected>$form->{$item}|;
2018       }
2019     }
2020   }
2021   if ($form->{selectpartsgroup}) {
2022     $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
2023     $partsgroup =
2024       qq|<input type=hidden name=selectpartsgroup value="|
2025       . $form->escape($form->{selectpartsgroup}, 1) . qq|">|;
2026     $form->{selectpartsgroup} =~
2027       s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
2028
2029     $partsgroup .=
2030       qq|<select name=partsgroup>$form->{selectpartsgroup}</select>|;
2031     $group = $locale->text('Group');
2032   }
2033
2034   # tax fields
2035   foreach $item (split / /, $form->{taxaccounts}) {
2036     $tax .= qq|
2037       <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}>&nbsp;<b>$form->{"IC_tax_${item}_description"}</b>
2038       <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
2039 |;
2040   }
2041
2042   $form->{obsolete} = "checked" if $form->{obsolete};
2043
2044   $lastcost = qq|
2045               <tr>
2046                 <th align="right" nowrap="true">|
2047     . $locale->text('Last Cost')
2048     . qq|</th>
2049                 <td><input name=lastcost size=11 value=$form->{lastcost}></td>
2050               </tr>
2051 |;
2052   if (!$eur) {
2053     $linkaccounts = qq|
2054                <tr>
2055                 <th align=right>| . $locale->text('Inventory') . qq|</th>
2056                 <td><select name=IC>$form->{selectIC}</select></td>
2057                 <input name=selectIC type=hidden value="$form->{selectIC}">
2058               </tr>|;
2059   }
2060
2061   if ($form->{item} eq "part") {
2062
2063     $linkaccounts .= qq|
2064               <tr>
2065                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2066                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2067                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2068               </tr>
2069               <tr>
2070                 <th align=right>| . $locale->text('COGS') . qq|</th>
2071                 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
2072                 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
2073               </tr>
2074 |;
2075
2076     $weight = qq|
2077               <tr>
2078                 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
2079                 <td>
2080                   <table>
2081                     <tr>
2082                       <td>
2083                         <input name=weight size=10 value=$form->{weight}>
2084                       </td>
2085                       <th>
2086                         &nbsp;
2087                         $form->{weightunit}
2088                         <input type=hidden name=weightunit value=$form->{weightunit}>
2089                       </th>
2090                     </tr>
2091                   </table>
2092                 </td>
2093               </tr>
2094 |;
2095
2096   }
2097
2098   if ($form->{item} eq "assembly") {
2099
2100     $lastcost = "";
2101
2102     $linkaccounts = qq|
2103               <tr>
2104                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2105                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2106                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2107               </tr>
2108 |;
2109
2110     $weight = qq|
2111               <tr>
2112                 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
2113                 <td>
2114                   <table>
2115                     <tr>
2116                       <td>
2117                         &nbsp;$form->{weight}
2118                         <input type=hidden name=weight value=$form->{weight}>
2119                       </td>
2120                       <th>
2121                         &nbsp;
2122                         $form->{weightunit}
2123                         <input type=hidden name=weightunit value=$form->{weightunit}>
2124                       </th>
2125                     </tr>
2126                   </table>
2127                 </td>
2128               </tr>
2129 |;
2130
2131   }
2132
2133   if ($form->{item} eq "service") {
2134
2135     $linkaccounts = qq|
2136               <tr>
2137                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2138                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2139                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2140               </tr>
2141               <tr>
2142                 <th align=right>| . $locale->text('Expense') . qq|</th>
2143                 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
2144                 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
2145               </tr>
2146 |;
2147
2148   }
2149
2150   if ($form->{item} ne 'service') {
2151     $n   = ($form->{onhand} > 0) ? "1" : "0";
2152     $rop = qq|
2153               <tr>
2154                 <th align="right" nowrap>| . $locale->text('On Hand') . qq|</th>
2155                 <th align=left nowrap class="plus$n">&nbsp;|
2156       . $form->format_amount(\%myconfig, $form->{onhand})
2157       . qq|</th>
2158               </tr>
2159 |;
2160
2161     if ($form->{item} eq 'assembly') {
2162       $rop .= qq|
2163               <tr>
2164                 <th align="right" nowrap>| . $locale->text('Stock') . qq|</th>
2165                 <td><input name=stock size=10 value=$form->{stock}></td>
2166               </tr>
2167 |;
2168     }
2169
2170     $rop .= qq|
2171               <tr>
2172                 <th align="right" nowrap="true">| . $locale->text('ROP') . qq|</th>
2173                 <td><input name=rop size=10 value=$form->{rop}></td>
2174               </tr>
2175 |;
2176
2177     $bin = qq|
2178               <tr>
2179                 <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th>
2180                 <td><input name=bin size=10 value=$form->{bin}></td>
2181               </tr>
2182 |;
2183     $vegv = qq|
2184               <tr>
2185                 <th align="right" nowrap="true">|
2186       . $locale->text('Verrechnungseinheit')
2187       . qq|</th>
2188                 <td><input name=ve size=10 value=$form->{ve}></td>
2189               </tr>
2190               <tr>
2191                 <th align="right" nowrap="true">|
2192       . $locale->text('Geschäftsvolumen')
2193       . qq|</th>
2194                 <td><input name=gv size=10 value=$form->{gv}></td>
2195               </tr>
2196 |;
2197     $imagelinks = qq|
2198   <tr>
2199     <td>
2200       <table width=100%>
2201         <tr>
2202           <th align=right nowrap>| . $locale->text('Image') . qq|</th>
2203           <td><input name=image size=40 value="$form->{image}"></td>
2204           <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
2205           <td><input name=microfiche size=20 value="$form->{microfiche}"></td>
2206         </tr>
2207         <tr>
2208           <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
2209           <td><input name=drawing size=40 value="$form->{drawing}"></td>
2210         </tr>
2211       </table>
2212     </td>
2213   </tr>
2214 |;
2215
2216   }
2217
2218   if ($form->{id}) {
2219     $obsolete = qq|
2220               <tr>
2221                 <th align="right" nowrap="true">| . $locale->text('Obsolete') . qq|</th>
2222                 <td><input name=obsolete type=checkbox class=checkbox value=1 $form->{obsolete}></td>
2223               </tr>
2224 |;
2225   }
2226   $shopok = $form->{shop} == 1 ? "checked" : "";
2227   $obsolete .= qq|
2228               <tr>
2229                 <th align=right nowrap>|
2230     . $locale->text('Shopartikel')
2231     . qq|</th>
2232                 <td><input class=checkbox type=checkbox name=shop value=1 $shopok></td>
2233              </tr>
2234 |;
2235
2236   # type=submit $locale->text('Add Part')
2237   # type=submit $locale->text('Add Service')
2238   # type=submit $locale->text('Add Assembly')
2239
2240   # type=submit $locale->text('Edit Part')
2241   # type=submit $locale->text('Edit Service')
2242   # type=submit $locale->text('Edit Assembly')
2243   # use JavaScript Calendar or not
2244   $form->{jsscript} = $jscalendar;
2245   $jsscript = "";
2246   if ($form->{jsscript}) {
2247
2248     # with JavaScript Calendar
2249     $button1 = qq|
2250        <td width="13"><input name=priceupdate id=priceupdate size=11  title="$myconfig{dateformat}" value="$form->{priceupdate}"></td>
2251        <td width="4" align="left"><input type=button name=priceupdate id="trigger1" value=|
2252       . $locale->text('button')
2253       . qq|></td>
2254       |;
2255
2256     #write Trigger
2257     $jsscript =
2258       Form->write_trigger(\%myconfig, "1", "priceupdate", "BL", "trigger1", "",
2259                           "", "");
2260   } else {
2261
2262     # without JavaScript Calendar
2263     $button1 = qq|
2264                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
2265   }
2266
2267   $form->{fokus} = "ic.partnumber";
2268   $form->header;
2269
2270   print qq|
2271   <body onLoad="fokus()">
2272
2273
2274 <form method=post name="ic" action=$form->{script}>
2275
2276 <input name=id type=hidden value=$form->{id}>
2277 <input name=item type=hidden value=$form->{item}>
2278 <input name=title type=hidden value="$form->{title}">
2279 <input name=makemodel type=hidden value="$form->{makemodel}">
2280 <input name=alternate type=hidden value="$form->{alternate}">
2281 <input name=onhand type=hidden value=$form->{onhand}>
2282 <input name=orphaned type=hidden value=$form->{orphaned}>
2283 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
2284 <input name=rowcount type=hidden value=$form->{rowcount}>
2285 <input name=eur type=hidden value=$eur>
2286
2287 <table width="100%">
2288   <tr>
2289     <th class=listtop>$form->{title}</th>
2290   </tr>
2291   <tr height="5"></tr>
2292   <tr>
2293     <td>
2294       <table width="100%">
2295         <tr valign=top>
2296           <th align=left>| . $locale->text('Part Number') . qq|</th>
2297           <th align=left>| . $locale->text('Part Description') . qq|</th>
2298           <th align=left>$group</th>
2299         </tr>
2300         <tr valign=top>
2301           <td><input name=partnumber value="$form->{partnumber}" size=20></td>
2302           <td>$description</td>
2303           <td>$partsgroup</td>
2304           <input type=hidden name=oldpartsgroup value="$form->{oldpartsgroup}">
2305         </tr>
2306       </table>
2307     </td>
2308   </tr>
2309   <tr>
2310     <td>
2311       <table width="100%" height="100%">
2312         <tr valign=top>
2313           <td width=70%>
2314             <table width="100%" height="100%">
2315               <tr class="listheading">
2316                 <th class="listheading" align="center" colspan=2>|
2317     . $locale->text('Link Accounts')
2318     . qq|</th>
2319               </tr>
2320               $linkaccounts
2321               <tr>
2322                 <th align="left">| . $locale->text('Notes') . qq|</th>
2323               </tr>
2324               <tr>
2325                 <td colspan=2>
2326                   $notes
2327                 </td>
2328               </tr>
2329             </table>
2330           </td>
2331           <td width="30%">
2332             <table width="100%">
2333               <tr>
2334                 <th align="right" nowrap="true">|
2335     . $locale->text('Updated')
2336     . qq|</th>
2337                 $button1
2338               </tr>
2339               <tr>
2340                 <th align="right" nowrap="true">| . $locale->text('List Price') . qq|</th>
2341                 <td><input name=listprice size=11 value=$form->{listprice}></td>
2342               </tr>
2343               <tr>
2344                 <th align="right" nowrap="true">| . $locale->text('Sell Price') . qq|</th>
2345                 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
2346               </tr>
2347               $lastcost
2348               <tr>
2349                 <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
2350                 <td><input name=unit size=5 maxlength="10" value="$form->{unit}"></td>
2351               </tr>
2352               $weight
2353               $rop
2354               $bin
2355               $vegv
2356               $obsolete
2357             </table>
2358           </td>
2359         </tr>
2360       </table>
2361     </td>
2362   </tr>
2363   $imagelinks
2364
2365 $jsscript
2366 |;
2367   $lxdebug->leave_sub();
2368 }
2369
2370 sub form_footer {
2371   $lxdebug->enter_sub();
2372
2373   if ($form->{item} eq "assembly") {
2374
2375     print qq|
2376         <tr>
2377           <td>
2378             <table width="100%">
2379               <tr>
2380                 <th colspan=2 align=right>|
2381       . $locale->text('Total')
2382       . qq|&nbsp;</th>
2383                 <th align=right>|
2384       . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2)
2385       . qq|</th>
2386               </tr>
2387             </table>
2388           </td>
2389         </tr>
2390         <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
2391 |;
2392   }
2393
2394   print qq|
2395       <input type=hidden name=path value=$form->{path}>
2396       <input type=hidden name=login value=$form->{login}>
2397       <input type=hidden name=password value=$form->{password}>
2398       <input type=hidden name=callback value="$form->{callback}">
2399       <input type=hidden name=previousform value="$form->{previousform}">
2400       <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
2401       <input type=hidden name=vc value=$form->{vc}>
2402   <tr>
2403     <td><hr size=3 noshade></td>
2404   </tr>
2405 </table>
2406
2407 <br>
2408 <input class=submit type=submit name=action value="|
2409     . $locale->text('Update') . qq|">
2410   |;
2411
2412   unless ($form->{item} eq "service") {
2413     print qq|
2414       <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
2415     |;
2416   }
2417
2418   print qq|
2419       <input class=submit type=submit name=action value="|
2420     . $locale->text('Save') . qq|">|;
2421
2422   if ($form->{id}) {
2423
2424     if (!$form->{previousform}) {
2425       print qq|
2426       <input class=submit type=submit name=action value="|
2427         . $locale->text('Save as new') . qq|">|;
2428     }
2429
2430     if ($form->{orphaned}) {
2431       if (!$form->{previousform}) {
2432         if ($form->{item} eq 'assembly') {
2433           if (!$form->{onhand}) {
2434             print qq|
2435       <input class=submit type=submit name=action value="|
2436               . $locale->text('Delete') . qq|">|;
2437           }
2438         } else {
2439           print qq|
2440       <input class=submit type=submit name=action value="|
2441             . $locale->text('Delete') . qq|">|;
2442         }
2443       }
2444     }
2445   }
2446
2447   if (!$form->{previousform}) {
2448     if ($form->{menubar}) {
2449       require "$form->{path}/menu.pl";
2450       &menubar;
2451     }
2452   }
2453
2454   print qq|
2455
2456 </form>
2457
2458 </body>
2459 </html>
2460 |;
2461
2462   $lxdebug->leave_sub();
2463 }
2464
2465 sub makemodel_row {
2466   $lxdebug->enter_sub();
2467   my ($numrows) = @_;
2468
2469   $form->{"make_$i"}  =~ s/\"/&quot;/g;
2470   $form->{"model_$i"} =~ s/\"/&quot;/g;
2471
2472   print qq|
2473   <tr>
2474     <td>
2475       <table width=100%>
2476         <tr>
2477           <th class="listheading">| . $locale->text('Make') . qq|</th>
2478           <th class="listheading">| . $locale->text('Model') . qq|</th>
2479         </tr>
2480 |;
2481
2482   for $i (1 .. $numrows) {
2483     print qq|
2484         <tr>
2485           <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
2486           <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
2487         </tr>
2488 |;
2489   }
2490
2491   print qq|
2492       </table>
2493     </td>
2494   </tr>
2495 |;
2496
2497   $lxdebug->leave_sub();
2498 }
2499
2500 sub assembly_row {
2501   $lxdebug->enter_sub();
2502   my ($numrows) = @_;
2503
2504   @column_index =
2505     qw(runningnumber qty unit bom partnumber description partsgroup total);
2506
2507   if ($form->{previousform}) {
2508     $nochange     = 1;
2509     @column_index = qw(qty unit bom partnumber description partsgroup total);
2510   } else {
2511
2512     # change callback
2513     $form->{old_callback} = $form->{callback};
2514     $callback             = $form->{callback};
2515     $form->{callback}     = "$form->{script}?action=display_form";
2516
2517     # delete action
2518     map { delete $form->{$_} } qw(action header);
2519
2520     $previousform = "";
2521
2522     # save form variables in a previousform variable
2523     foreach $key (sort keys %$form) {
2524
2525       # escape ampersands
2526       $form->{$key} =~ s/&/%26/g;
2527       $previousform .= qq|$key=$form->{$key}&|;
2528     }
2529     chop $previousform;
2530     $previousform = $form->escape($form->escape($previousform, 1));
2531     $form->{callback} = $callback;
2532
2533     $form->{assemblytotal} = 0;
2534     $form->{weight}        = 0;
2535
2536   }
2537   $column_header{runningnumber} =
2538     qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
2539   $column_header{qty} =
2540     qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
2541   $column_header{unit} =
2542     qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
2543   $column_header{partnumber} =
2544       qq|<th align=left nowrap width=20%>|
2545     . $locale->text('Part Number')
2546     . qq|</th>|;
2547   $column_header{description} =
2548     qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
2549   $column_header{total} =
2550     qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
2551   $column_header{bom}        = qq|<th>| . $locale->text('BOM') . qq|</th>|;
2552   $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
2553
2554   print qq|
2555   <tr class=listheading>
2556     <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
2557   </tr>
2558   <tr>
2559     <td>
2560       <table width=100%>
2561         <tr>
2562 |;
2563
2564   map { print "\n$column_header{$_}" } @column_index;
2565
2566   print qq|
2567         </tr>
2568 |;
2569
2570   for $i (1 .. $numrows) {
2571     $form->{"partnumber_$i"} =~ s/\"/&quot;/g;
2572
2573     $linetotal =
2574       $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
2575     $form->{assemblytotal} += $linetotal;
2576
2577     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
2578
2579     $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
2580
2581     if (($i >= 1) && ($i == $numrows)) {
2582
2583       if ($nochange) {
2584         map { $column_data{$_} = qq|<td></td>| }
2585           qw(qty unit partnumber description bom partsgroup);
2586       } else {
2587
2588         map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
2589
2590         $column_data{qty} =
2591           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2592         $column_data{partnumber} =
2593           qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
2594         $column_data{description} =
2595           qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
2596         $column_data{partsgroup} =
2597           qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
2598
2599       }
2600
2601     } else {
2602
2603       if ($form->{previousform}) {
2604         $column_data{partnumber} =
2605           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
2606         $column_data{qty} =
2607           qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
2608
2609         $column_data{bom} =
2610           qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
2611         $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : "&nbsp;";
2612         $column_data{bom} .= qq|</td>|;
2613
2614         $column_data{partsgroup} =
2615           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2616
2617       } else {
2618         $href =
2619           qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&password=$form->{password}&rowcount=$i&previousform=$previousform|;
2620         $column_data{partnumber} =
2621           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
2622         $column_data{runningnumber} =
2623           qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
2624         $column_data{qty} =
2625           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2626
2627         $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
2628         $column_data{bom} =
2629           qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
2630
2631         $column_data{partsgroup} =
2632           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2633       }
2634
2635       $column_data{unit} =
2636         qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
2637       $column_data{description} =
2638         qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
2639     }
2640
2641     $column_data{total} = qq|<td align=right>$linetotal</td>|;
2642
2643     print qq|
2644         <tr>|;
2645
2646     map { print "\n$column_data{$_}" } @column_index;
2647
2648     print qq|
2649         </tr>
2650   <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2651   <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
2652   <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
2653 |;
2654   }
2655
2656   print qq|
2657       </table>
2658     </td>
2659   </tr>
2660 |;
2661
2662   $lxdebug->leave_sub();
2663 }
2664
2665 sub update {
2666   $lxdebug->enter_sub();
2667
2668   if ($form->{item} eq "assembly") {
2669     $i = $form->{assembly_rows};
2670
2671     # if last row is empty check the form otherwise retrieve item
2672     if (   ($form->{"partnumber_$i"} eq "")
2673         && ($form->{"description_$i"} eq "")
2674         && ($form->{"partsgroup_$i"}  eq "")) {
2675
2676       &check_form;
2677
2678         } else {
2679
2680       IC->assembly_item(\%myconfig, \%$form);
2681
2682       $rows = scalar @{ $form->{item_list} };
2683
2684       if ($rows) {
2685         $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2686
2687         if ($rows > 1) {
2688           $form->{makemodel_rows}--;
2689           &select_item;
2690           exit;
2691         } else {
2692           map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g }
2693             qw(partnumber description unit partsgroup);
2694           map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
2695             keys %{ $form->{item_list}[0] };
2696           $form->{"runningnumber_$i"} = $form->{assembly_rows};
2697           $form->{assembly_rows}++;
2698
2699           &check_form;
2700
2701         }
2702
2703       } else {
2704
2705         $form->{rowcount} = $i;
2706         $form->{assembly_rows}++;
2707
2708         &new_item;
2709
2710       }
2711     }
2712   }
2713
2714   if ($form->{item} eq "part") {
2715     &check_form;
2716   }
2717
2718   if ($form->{item} eq 'service') {
2719     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2720       qw(sellprice listprice);
2721
2722     &form_header;
2723     &form_footer;
2724   }
2725
2726   $lxdebug->leave_sub();
2727 }
2728
2729 sub save {
2730   $lxdebug->enter_sub();
2731
2732   # check if there is a part number
2733   # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
2734
2735   if ($form->{obsolete}) {
2736     $form->error(
2737       $locale->text(
2738         "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
2739       ))
2740       if ($form->{onhand});
2741   }
2742
2743   # expand dynamic strings
2744   # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
2745   # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
2746   # $locale->text('Part Number missing!')
2747   # $locale->text('Service Number missing!')
2748   # $locale->text('Assembly Number missing!')
2749
2750   # save part
2751   $rc = IC->save(\%myconfig, \%$form);
2752   if ($rc == 3) {
2753     $form->error($locale->text('Partnumber not unique!'));
2754   }
2755   $parts_id = $form->{id};
2756
2757   # load previous variables
2758   if ($form->{previousform}) {
2759
2760     # save the new form variables before splitting previousform
2761     map { $newform{$_} = $form->{$_} } keys %$form;
2762
2763     $previousform = $form->unescape($form->{previousform});
2764
2765     # don't trample on previous variables
2766     map { delete $form->{$_} } keys %newform;
2767
2768     # now take it apart and restore original values
2769     foreach $item (split /&/, $previousform) {
2770       ($key, $value) = split /=/, $item, 2;
2771       $value =~ s/%26/&/g;
2772       $form->{$key} = $value;
2773     }
2774     $form->{taxaccounts} = $newform{taxaccount2};
2775
2776     if ($form->{item} eq 'assembly') {
2777
2778       # undo number formatting
2779       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2780         qw(weight listprice sellprice rop);
2781
2782       $form->{assembly_rows}--;
2783       $i = $newform{rowcount};
2784       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2785
2786       $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
2787       $form->{weight}    -= $form->{"weight_$i"} * $form->{"qty_$i"};
2788
2789       # change/add values for assembly item
2790       map { $form->{"${_}_$i"} = $newform{$_} }
2791         qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno);
2792
2793       $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
2794       $form->{weight}    += $form->{"weight_$i"} * $form->{"qty_$i"};
2795
2796     } else {
2797
2798       # set values for last invoice/order item
2799       $i = $form->{rowcount};
2800       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2801
2802       map { $form->{"${_}_$i"} = $newform{$_} }
2803         qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice);
2804       $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
2805
2806       if ($form->{exchangerate} != 0) {
2807         $form->{"sellprice_$i"} /= $form->{exchangerate};
2808       }
2809
2810       map { $form->{"taxaccounts_$i"} .= "$_ " } split / /,
2811         $newform{taxaccount};
2812       chop $form->{"taxaccounts_$i"};
2813       foreach $item (qw(description rate taxnumber)) {
2814         $index = $form->{"taxaccounts_$i"} . "_$item";
2815         $form->{$index} = $newform{$index};
2816       }
2817
2818       # credit remaining calculation
2819       $amount =
2820         $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
2821         $form->{"qty_$i"};
2822       map { $form->{"${_}_base"} += $amount }
2823         (split / /, $form->{"taxaccounts_$i"});
2824       map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
2825         split / /, $form->{"taxaccounts_$i"}
2826         if !$form->{taxincluded};
2827
2828       $form->{creditremaining} -= $amount;
2829
2830     }
2831
2832     $form->{"id_$i"} = $parts_id;
2833     delete $form->{action};
2834
2835     # restore original callback
2836     $callback = $form->unescape($form->{callback});
2837     $form->{callback} = $form->unescape($form->{old_callback});
2838     delete $form->{old_callback};
2839
2840     $form->{makemodel_rows}--;
2841
2842     # put callback together
2843     foreach $key (keys %$form) {
2844
2845       # do single escape for Apache 2.0
2846       $value = $form->escape($form->{$key}, 1);
2847       $callback .= qq|&$key=$value|;
2848     }
2849     $form->{callback} = $callback;
2850   }
2851
2852   # redirect
2853   $form->redirect;
2854
2855   $lxdebug->leave_sub();
2856 }
2857
2858 sub save_as_new {
2859   $lxdebug->enter_sub();
2860
2861   $form->{id} = 0;
2862   &save;
2863
2864   $lxdebug->leave_sub();
2865 }
2866
2867 sub delete {
2868   $lxdebug->enter_sub();
2869
2870   $rc = IC->delete(\%myconfig, \%$form);
2871
2872   # redirect
2873   $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
2874   $form->error($locale->text('Cannot delete item!'));
2875
2876   $lxdebug->leave_sub();
2877 }
2878
2879 sub stock_assembly {
2880   $lxdebug->enter_sub();
2881
2882   $form->{title} = $locale->text('Stock Assembly');
2883
2884   $form->header;
2885
2886   print qq|
2887 <body>
2888
2889 <form method=post action=$form->{script}>
2890
2891 <table width="100%">
2892   <tr>
2893     <th class=listtop>$form->{title}</th>
2894   </tr>
2895   <tr height="5"></tr>
2896   <tr valign=top>
2897     <td>
2898       <table>
2899         <tr>
2900           <th align="right" nowrap="true">|
2901     . $locale->text('Part Number')
2902     . qq|</th>
2903           <td><input name=partnumber size=20></td>
2904           <td>&nbsp;</td>
2905         </tr>
2906         <tr>
2907           <th align="right" nowrap="true">|
2908     . $locale->text('Part Description')
2909     . qq|</th>
2910           <td><input name=description size=40></td>
2911         </tr>
2912       </table>
2913     </td>
2914   </tr>
2915   <tr><td><hr size=3 noshade></td></tr>
2916 </table>
2917
2918 <input type=hidden name=path value=$form->{path}>
2919 <input type=hidden name=login value=$form->{login}>
2920 <input type=hidden name=password value=$form->{password}>
2921
2922 <input type=hidden name=nextsub value=list_assemblies>
2923
2924 <br>
2925 <input class=submit type=submit name=action value="|
2926     . $locale->text('Continue') . qq|">
2927 </form>
2928
2929 </body>
2930 </html>
2931 |;
2932
2933   $lxdebug->leave_sub();
2934 }
2935
2936 sub list_assemblies {
2937   $lxdebug->enter_sub();
2938
2939   IC->retrieve_assemblies(\%myconfig, \%$form);
2940
2941   $column_header{partnumber} =
2942     qq|<th class=listheading>| . $locale->text('Part Number') . qq|</th>|;
2943   $column_header{description} =
2944     qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
2945   $column_header{bin} =
2946     qq|<th class=listheading>| . $locale->text('Bin') . qq|</th>|;
2947   $column_header{onhand} =
2948     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
2949   $column_header{rop} =
2950     qq|<th class=listheading>| . $locale->text('ROP') . qq|</th>|;
2951   $column_header{stock} =
2952     qq|<th class=listheading>| . $locale->text('Add') . qq|</th>|;
2953
2954   @column_index = (qw(partnumber description bin onhand rop stock));
2955
2956   $form->{title} = $locale->text('Stock Assembly');
2957
2958   $form->{callback} =
2959     "$form->{script}?action=stock_assembly&path=$form->{path}&login=$form->{login}&password=$form->{password}";
2960
2961   $form->header;
2962
2963   $colspan = $#column_index + 1;
2964
2965   print qq|
2966 <body>
2967
2968 <form method=post action=$form->{script}>
2969
2970 <table width=100%>
2971   <tr>
2972     <th class=listtop colspan=$colspan>$form->{title}</th>
2973   </tr>
2974   <tr size=5></tr>
2975   <tr class=listheading>|;
2976
2977   map { print "\n$column_header{$_}" } @column_index;
2978
2979   print qq|
2980   </tr>
2981 |;
2982
2983   $i = 1;
2984   foreach $ref (@{ $form->{assembly_items} }) {
2985
2986     map { $ref->{$_} =~ s/\"/&quot;/g } qw(partnumber description);
2987
2988     $column_data{partnumber}  = qq|<td width=20%>$ref->{partnumber}</td>|;
2989     $column_data{description} =
2990       qq|<td width=50%>$ref->{description}&nbsp;</td>|;
2991     $column_data{bin}    = qq|<td>$ref->{bin}&nbsp;</td>|;
2992     $column_data{onhand} =
2993         qq|<td align=right>|
2994       . $form->format_amount(\%myconfig, $ref->{onhand}, '', "&nbsp;")
2995       . qq|</td>|;
2996     $column_data{rop} =
2997         qq|<td align=right>|
2998       . $form->format_amount(\%myconfig, $ref->{rop}, '', "&nbsp;")
2999       . qq|</td>|;
3000     $column_data{stock} = qq|<td width=10%><input name="qty_$i" size=10></td>|;
3001
3002     $j++;
3003     $j %= 2;
3004     print
3005       qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
3006
3007     map { print "\n$column_data{$_}" } @column_index;
3008
3009     print qq|
3010     </tr>
3011 |;
3012
3013     $i++;
3014
3015   }
3016
3017   $i--;
3018   print qq|
3019   <tr>
3020     <td colspan=6><hr size=3 noshade>
3021   </tr>
3022 </table>
3023 <input name=rowcount type=hidden value="$i">
3024
3025 <input type=hidden name=path value=$form->{path}>
3026 <input type=hidden name=login value=$form->{login}>
3027 <input type=hidden name=password value=$form->{password}>
3028
3029 <input name=callback type=hidden value="$form->{callback}">
3030
3031 <input type=hidden name=nextsub value=restock_assemblies>
3032
3033 <br>
3034 <input class=submit type=submit name=action value="|
3035     . $locale->text('Continue') . qq|">
3036
3037 </form>
3038
3039 </body>
3040 </html>
3041 |;
3042
3043   $lxdebug->leave_sub();
3044 }
3045
3046 sub restock_assemblies {
3047   $lxdebug->enter_sub();
3048
3049   $form->redirect($locale->text('Assemblies restocked!'))
3050     if (IC->restock_assemblies(\%myconfig, \%$form));
3051   $form->error($locale->text('Cannot stock assemblies!'));
3052
3053   $lxdebug->leave_sub();
3054 }
3055
3056 sub continue { &{ $form->{nextsub} } }