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