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