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