Einheiten sortierbar gemacht.
[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})
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})
1322       . "</td>";
1323     $column_data{sellprice} =
1324         "<td align=right>"
1325       . $form->format_amount(\%myconfig, $ref->{sellprice})
1326       . "</td>";
1327     $column_data{listprice} =
1328         "<td align=right>"
1329       . $form->format_amount(\%myconfig, $ref->{listprice})
1330       . "</td>";
1331     $column_data{lastcost} =
1332         "<td align=right>"
1333       . $form->format_amount(\%myconfig, $ref->{lastcost})
1334       . "</td>";
1335
1336     $column_data{linetotalsellprice} = "<td align=right>"
1337       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
1338       . "</td>";
1339     $column_data{linetotallastcost} = "<td align=right>"
1340       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
1341       . "</td>";
1342     $column_data{linetotallistprice} = "<td align=right>"
1343       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
1344       . "</td>";
1345
1346     if (!$ref->{assemblyitem}) {
1347       $totalsellprice += $onhand * $ref->{sellprice};
1348       $totallastcost  += $onhand * $ref->{lastcost};
1349       $totallistprice += $onhand * $ref->{listprice};
1350
1351       $subtotalonhand    += $onhand;
1352       $subtotalsellprice += $onhand * $ref->{sellprice};
1353       $subtotallastcost  += $onhand * $ref->{lastcost};
1354       $subtotallistprice += $onhand * $ref->{listprice};
1355     }
1356
1357     $column_data{rop} =
1358       "<td align=right>"
1359       . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
1360     $column_data{weight} =
1361         "<td align=right>"
1362       . $form->format_amount(\%myconfig, $ref->{weight})
1363       . "</td>";
1364     $column_data{unit}        = "<td>$ref->{unit}&nbsp;</td>";
1365     $column_data{bin}         = "<td>$ref->{bin}&nbsp;</td>";
1366     $column_data{priceupdate} = "<td>$ref->{priceupdate}&nbsp;</td>";
1367
1368     $column_data{invnumber} =
1369       ($ref->{module} ne 'oe')
1370       ? "<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>"
1371       : "<td>$ref->{invnumber}</td>";
1372     $column_data{ordnumber} =
1373       ($ref->{module} eq 'oe')
1374       ? "<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>"
1375       : "<td>$ref->{ordnumber}</td>";
1376     $column_data{quonumber} =
1377       ($ref->{module} eq 'oe' && !$ref->{ordnumber})
1378       ? "<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>"
1379       : "<td>$ref->{quonumber}</td>";
1380
1381     $column_data{name} = "<td>$ref->{name}</td>";
1382
1383     $column_data{image} =
1384       ($ref->{image})
1385       ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
1386       : "<td>&nbsp;</td>";
1387     $column_data{drawing} =
1388       ($ref->{drawing})
1389       ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
1390       : "<td>&nbsp;</td>";
1391     $column_data{microfiche} =
1392       ($ref->{microfiche})
1393       ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
1394       : "<td>&nbsp;</td>";
1395
1396     $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
1397
1398     $column_data{soldtotal} = "<td  align=right>$ref->{soldtotal}</td>";
1399
1400     $i++;
1401     $i %= 2;
1402     print "<tr class=listrow$i>";
1403
1404     map { print "\n$column_data{$_}" } @column_index;
1405
1406     print qq|
1407     </tr>
1408 |;
1409   }
1410
1411   if ($form->{l_subtotal} eq 'Y') {
1412     &parts_subtotal;
1413   }    #fi
1414
1415   if ($form->{"l_linetotal"}) {
1416     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
1417     $column_data{linetotalsellprice} =
1418         "<th class=listtotal align=right>"
1419       . $form->format_amount(\%myconfig, $totalsellprice, 2)
1420       . "</th>";
1421     $column_data{linetotallastcost} =
1422         "<th class=listtotal align=right>"
1423       . $form->format_amount(\%myconfig, $totallastcost, 2)
1424       . "</th>";
1425     $column_data{linetotallistprice} =
1426         "<th class=listtotal align=right>"
1427       . $form->format_amount(\%myconfig, $totallistprice, 2)
1428       . "</th>";
1429
1430     print "<tr class=listtotal>";
1431
1432     map { print "\n$column_data{$_}" } @column_index;
1433
1434     print qq|</tr>
1435     |;
1436   }
1437
1438   print qq|
1439   <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
1440 </table>
1441
1442 |;
1443
1444   print qq|
1445
1446 <br>
1447
1448 <form method=post action=$form->{script}>
1449
1450 <input type=hidden name=path value=$form->{path}>
1451 <input type=hidden name=login value=$form->{login}>
1452 <input type=hidden name=password value=$form->{password}>
1453
1454 <input type=hidden name=itemstatus value="$form->{itemstatus}">
1455 <input type=hidden name=l_linetotal value="$form->{l_linetotal}">
1456 <input type=hidden name=l_partnumber value="$form->{l_partnumber}">
1457 <input type=hidden name=l_description value="$form->{l_description}">
1458 <input type=hidden name=l_onhand value="$form->{l_onhand}">
1459 <input type=hidden name=l_unit value="$form->{l_unit}">
1460 <input type=hidden name=l_sellprice value="$form->{l_sellprice}">
1461 <input type=hidden name=l_linetotalsellprice value="$form->{l_linetotalsellprice}">
1462 <input type=hidden name=sort value="$form->{sort}">
1463 <input type=hidden name=revers value="$form->{revers}">
1464 <input type=hidden name=lastsort value="$form->{lastsort}">
1465 <input type=hidden name=parts value="$form->{parts}">
1466
1467 <input type=hidden name=bom value="$form->{bom}">
1468 <input type=hidden name=titel value="$form->{titel}">
1469 <input type=hidden name=searchitems value="$form->{searchitems}">|;
1470
1471   print $totop100;
1472
1473   print qq|
1474     <input type=hidden name=ndxs_counter value="$form->{ndxs_counter}">
1475
1476     <input class=submit type=submit name=action value="|
1477     . $locale->text('choice') . qq|">
1478
1479   </form>
1480
1481 </body>
1482 </html>
1483 |;
1484
1485   $lxdebug->leave_sub();
1486 }    # end addtop100
1487
1488 sub generate_report {
1489   $lxdebug->enter_sub();
1490
1491   $revers   = $form->{revers};
1492   $lastsort = $form->{lastsort};
1493
1494   if (($form->{lastsort} eq "") && ($form->{sort} eq undef)) {
1495     $form->{revers}   = 0;
1496     $form->{lastsort} = "partnumber";
1497     $form->{sort}     = "partnumber";
1498   } else {
1499
1500     # switch between backward sorting of tables
1501     if ($form->{lastsort} eq $form->{sort}) {
1502       if ($form->{revers} == 0) {
1503         $form->{revers} = 1;
1504       } else {
1505         $form->{revers} = 0;
1506       }    #fi
1507     } else {
1508       $form->{revers} == 0;
1509       $form->{lastsort} = $form->{sort};
1510     }    #fi
1511   }    #fi
1512
1513   $callback =
1514     "$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="
1515     . $form->escape($form->{title}, 1);
1516
1517   # if we have a serialnumber limit search
1518   if ($form->{serialnumber} || $form->{l_serialnumber}) {
1519     $form->{l_serialnumber} = "Y";
1520     unless (   $form->{bought}
1521             || $form->{sold}
1522             || $form->{rfq}
1523             || $form->{quoted}) {
1524       $form->{bought} = $form->{sold} = 1;
1525     }
1526   }
1527
1528   IC->all_parts(\%myconfig, \%$form);
1529
1530   if ($form->{itemstatus} eq 'active') {
1531     $option .= $locale->text('Active') . " : ";
1532   }
1533   if ($form->{itemstatus} eq 'obsolete') {
1534     $option .= $locale->text('Obsolete') . " : ";
1535   }
1536   if ($form->{itemstatus} eq 'orphaned') {
1537     $option .= $locale->text('Orphaned') . " : ";
1538   }
1539   if ($form->{itemstatus} eq 'onhand') {
1540     $option .= $locale->text('On Hand') . " : ";
1541     $form->{l_onhand} = "Y";
1542   }
1543   if ($form->{itemstatus} eq 'short') {
1544     $option .= $locale->text('Short') . " : ";
1545     $form->{l_onhand} = "Y";
1546   }
1547   if ($form->{onorder}) {
1548     $form->{l_ordnumber} = "Y";
1549     $callback .= "&onorder=$form->{onorder}";
1550     $option   .= $locale->text('On Order') . " : ";
1551   }
1552   if ($form->{ordered}) {
1553     $form->{l_ordnumber} = "Y";
1554     $callback .= "&ordered=$form->{ordered}";
1555     $option   .= $locale->text('Ordered') . " : ";
1556   }
1557   if ($form->{rfq}) {
1558     $form->{l_quonumber} = "Y";
1559     $callback .= "&rfq=$form->{rfq}";
1560     $option   .= $locale->text('RFQ') . " : ";
1561   }
1562   if ($form->{quoted}) {
1563     $form->{l_quonumber} = "Y";
1564     $callback .= "&quoted=$form->{quoted}";
1565     $option   .= $locale->text('Quoted') . " : ";
1566   }
1567   if ($form->{bought}) {
1568     $form->{l_invnumber} = "Y";
1569     $callback .= "&bought=$form->{bought}";
1570     $option   .= $locale->text('Bought') . " : ";
1571   }
1572   if ($form->{sold}) {
1573     $form->{l_invnumber} = "Y";
1574     $callback .= "&sold=$form->{sold}";
1575     $option   .= $locale->text('Sold') . " : ";
1576   }
1577   if (   $form->{bought}
1578       || $form->{sold}
1579       || $form->{onorder}
1580       || $form->{ordered}
1581       || $form->{rfq}
1582       || $form->{quoted}) {
1583
1584     $form->{l_lastcost} = "";
1585     $form->{l_name}     = "Y";
1586     if ($form->{transdatefrom}) {
1587       $callback .= "&transdatefrom=$form->{transdatefrom}";
1588       $option   .= "\n<br>"
1589         . $locale->text('From')
1590         . "&nbsp;"
1591         . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1592     }
1593     if ($form->{transdateto}) {
1594       $callback .= "&transdateto=$form->{transdateto}";
1595       $option   .= "\n<br>"
1596         . $locale->text('To (time)')
1597         . "&nbsp;"
1598         . $locale->date(\%myconfig, $form->{transdateto}, 1);
1599     }
1600   }
1601
1602   $option .= "<br>";
1603
1604   if ($form->{partnumber}) {
1605     $callback .= "&partnumber=$form->{partnumber}";
1606     $option   .= $locale->text('Part Number') . qq| : $form->{partnumber}<br>|;
1607   }
1608   if ($form->{partsgroup}) {
1609     $callback .= "&partsgroup=$form->{partsgroup}";
1610     $option   .= $locale->text('Group') . qq| : $form->{partsgroup}<br>|;
1611   }
1612   if ($form->{serialnumber}) {
1613     $callback .= "&serialnumber=$form->{serialnumber}";
1614     $option   .=
1615       $locale->text('Serial Number') . qq| : $form->{serialnumber}<br>|;
1616   }
1617   if ($form->{description}) {
1618     $callback .= "&description=$form->{description}";
1619     $description = $form->{description};
1620     $description =~ s/
1621 /<br>/g;
1622     $option .=
1623       $locale->text('Part Description') . qq| : $form->{description}<br>|;
1624   }
1625   if ($form->{make}) {
1626     $callback .= "&make=$form->{make}";
1627     $option   .= $locale->text('Make') . qq| : $form->{make}<br>|;
1628   }
1629   if ($form->{model}) {
1630     $callback .= "&model=$form->{model}";
1631     $option   .= $locale->text('Model') . qq| : $form->{model}<br>|;
1632   }
1633   if ($form->{drawing}) {
1634     $callback .= "&drawing=$form->{drawing}";
1635     $option   .= $locale->text('Drawing') . qq| : $form->{drawing}<br>|;
1636   }
1637   if ($form->{microfiche}) {
1638     $callback .= "&microfiche=$form->{microfiche}";
1639     $option   .= $locale->text('Microfiche') . qq| : $form->{microfiche}<br>|;
1640   }
1641
1642   # table soldtotal aktive
1643   if ($form->{l_soldtotal}) {
1644     $callback .= "&soldtotal=$form->{soldtotal}";
1645     $option   .= $locale->text('soldtotal') . qq| : $form->{soldtotal}<br>|;
1646   }
1647
1648   if ($form->{l_deliverydate}) {
1649     $callback .= "&deliverydate=$form->{deliverydate}";
1650   }
1651
1652   @columns = $form->sort_columns(
1653     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)
1654   );
1655
1656   if ($form->{l_linetotal}) {
1657     $form->{l_onhand} = "Y";
1658     $form->{l_linetotalsellprice} = "Y" if $form->{l_sellprice};
1659     if ($form->{l_lastcost}) {
1660       $form->{l_linetotallastcost} = "Y";
1661       if (($form->{searchitems} eq 'assembly') && !$form->{bom}) {
1662         $form->{l_linetotallastcost} = "";
1663       }
1664     }
1665     $form->{l_linetotallistprice} = "Y" if $form->{l_listprice};
1666   }
1667
1668   if ($form->{searchitems} eq 'service') {
1669
1670     # remove bin, weight and rop from list
1671     map { $form->{"l_$_"} = "" } qw(bin weight rop);
1672
1673     $form->{l_onhand} = "";
1674
1675     # qty is irrelevant unless bought or sold
1676     if (   $form->{bought}
1677         || $form->{sold}
1678         || $form->{onorder}
1679         || $form->{ordered}
1680         || $form->{rfq}
1681         || $form->{quoted}) {
1682       $form->{l_onhand} = "Y";
1683     } else {
1684       $form->{l_linetotalsellprice} = "";
1685       $form->{l_linetotallastcost}  = "";
1686     }
1687   }
1688
1689   $form->{l_lastcost} = ""
1690     if ($form->{searchitems} eq 'assembly' && !$form->{bom});
1691
1692   foreach $item (@columns) {
1693     if ($form->{"l_$item"} eq "Y") {
1694       push @column_index, $item;
1695
1696       # add column to callback
1697       $callback .= "&l_$item=Y";
1698     }
1699   }
1700
1701   if ($form->{l_subtotal} eq 'Y') {
1702     $callback .= "&l_subtotal=Y";
1703   }
1704   $column_header{partnumber} =
1705     qq|<th nowrap><a class=listheading href=$callback&sort=partnumber&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1706     . $locale->text('Part Number')
1707     . qq|</a></th>|;
1708   $column_header{description} =
1709     qq|<th nowrap><a class=listheading href=$callback&sort=description&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1710     . $locale->text('Part Description')
1711     . qq|</a></th>|;
1712   $column_header{partsgroup} =
1713       qq|<th nowrap><a class=listheading href=$callback&sort=partsgroup>|
1714     . $locale->text('Group')
1715     . qq|</a></th>|;
1716   $column_header{bin} =
1717       qq|<th><a class=listheading href=$callback&sort=bin>|
1718     . $locale->text('Bin')
1719     . qq|</a></th>|;
1720   $column_header{priceupdate} =
1721       qq|<th nowrap><a class=listheading href=$callback&sort=priceupdate>|
1722     . $locale->text('Updated')
1723     . qq|</a></th>|;
1724   $column_header{onhand} =
1725     qq|<th nowrap><a  class=listheading href=$callback&sort=onhand&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1726     . $locale->text('Qty')
1727     . qq|</th>|;
1728   $column_header{unit} =
1729     qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
1730   $column_header{listprice} =
1731       qq|<th class=listheading nowrap>|
1732     . $locale->text('List Price')
1733     . qq|</th>|;
1734   $column_header{lastcost} =
1735     qq|<th class=listheading nowrap>| . $locale->text('Last Cost') . qq|</th>|;
1736   $column_header{rop} =
1737     qq|<th class=listheading nowrap>| . $locale->text('ROP') . qq|</th>|;
1738   $column_header{weight} =
1739     qq|<th class=listheading nowrap>| . $locale->text('Weight') . qq|</th>|;
1740
1741   $column_header{invnumber} =
1742       qq|<th nowrap><a class=listheading href=$callback&sort=invnumber>|
1743     . $locale->text('Invoice Number')
1744     . qq|</a></th>|;
1745   $column_header{ordnumber} =
1746       qq|<th nowrap><a class=listheading href=$callback&sort=ordnumber>|
1747     . $locale->text('Order Number')
1748     . qq|</a></th>|;
1749   $column_header{quonumber} =
1750       qq|<th nowrap><a class=listheading href=$callback&sort=quonumber>|
1751     . $locale->text('Quotation')
1752     . qq|</a></th>|;
1753
1754   $column_header{name} =
1755       qq|<th nowrap><a class=listheading href=$callback&sort=name>|
1756     . $locale->text('Name')
1757     . qq|</a></th>|;
1758
1759   $column_header{sellprice} =
1760       qq|<th class=listheading nowrap>|
1761     . $locale->text('Sell Price')
1762     . qq|</th>|;
1763   $column_header{linetotalsellprice} =
1764     qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
1765   $column_header{linetotallastcost} =
1766     qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
1767   $column_header{linetotallistprice} =
1768     qq|<th class=listheading nowrap>| . $locale->text('Extended') . qq|</th>|;
1769
1770   $column_header{image} =
1771     qq|<th class=listheading nowrap>| . $locale->text('Image') . qq|</a></th>|;
1772   $column_header{drawing} =
1773       qq|<th nowrap><a class=listheading href=$callback&sort=drawing>|
1774     . $locale->text('Drawing')
1775     . qq|</a></th>|;
1776   $column_header{microfiche} =
1777       qq|<th nowrap><a class=listheading href=$callback&sort=microfiche>|
1778     . $locale->text('Microfiche')
1779     . qq|</a></th>|;
1780
1781   $column_header{serialnumber} =
1782       qq|<th nowrap><a class=listheading href=$callback&sort=serialnumber>|
1783     . $locale->text('Serial Number')
1784     . qq|</a></th>|;
1785   $column_header{soldtotal} =
1786     qq|<th nowrap><a class=listheading href=$callback&sort=soldtotal&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1787     . $locale->text('soldtotal')
1788     . qq|</a></th>|;
1789
1790   $column_header{deliverydate} =
1791     qq|<th nowrap><a class=listheading href=$callback&sort=deliverydate&revers=$form->{revers}&lastsort=$form->{lastsort}>|
1792     . $locale->text('deliverydate')
1793     . qq|</a></th>|;
1794
1795   $form->header;
1796   $colspan = $#column_index + 1;
1797
1798   print qq|
1799 <body>
1800
1801 <table width=100%>
1802   <tr>
1803     <th class=listtop colspan=$colspan>$form->{title}</th>
1804   </tr>
1805   <tr height="5"></tr>
1806
1807   <tr><td colspan=$colspan>$option</td></tr>
1808
1809   <tr class=listheading>
1810 |;
1811
1812   map { print "\n$column_header{$_}" } @column_index;
1813
1814   print qq|
1815   </tr>
1816   |;
1817
1818   # add order to callback
1819   $form->{callback} = $callback .= "&sort=$form->{sort}";
1820
1821   # escape callback for href
1822   $callback = $form->escape($callback);
1823
1824   if (@{ $form->{parts} }) {
1825     $sameitem = $form->{parts}->[0]->{ $form->{sort} };
1826   }
1827
1828   foreach $ref (@{ $form->{parts} }) {
1829
1830     if ($form->{l_subtotal} eq 'Y' && !$ref->{assemblyitem}) {
1831       if ($sameitem ne $ref->{ $form->{sort} }) {
1832         &parts_subtotal;
1833         $sameitem = $ref->{ $form->{sort} };
1834       }
1835     }
1836
1837     $ref->{exchangerate} = 1 unless $ref->{exchangerate};
1838     $ref->{sellprice} *= $ref->{exchangerate};
1839     $ref->{listprice} *= $ref->{exchangerate};
1840     $ref->{lastcost}  *= $ref->{exchangerate};
1841
1842     # use this for assemblies
1843     $onhand = $ref->{onhand};
1844
1845     $align = "left";
1846     if ($ref->{assemblyitem}) {
1847       $align = "right";
1848       $onhand = 0 if ($form->{sold});
1849     }
1850
1851     $ref->{description} =~ s/
1852 /<br>/g;
1853
1854     $column_data{partnumber} =
1855       "<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>";
1856     $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>";
1857     $column_data{partsgroup}  = "<td>$ref->{partsgroup}&nbsp;</td>";
1858
1859     $column_data{onhand} =
1860         "<td align=right>"
1861       . $form->format_amount(\%myconfig, $ref->{onhand})
1862       . "</td>";
1863     $column_data{sellprice} =
1864         "<td align=right>"
1865       . $form->format_amount(\%myconfig, $ref->{sellprice}, -2)
1866       . "</td>";
1867     $column_data{listprice} =
1868         "<td align=right>"
1869       . $form->format_amount(\%myconfig, $ref->{listprice}, -2)
1870       . "</td>";
1871     $column_data{lastcost} =
1872         "<td align=right>"
1873       . $form->format_amount(\%myconfig, $ref->{lastcost}, -2)
1874       . "</td>";
1875
1876     $column_data{linetotalsellprice} = "<td align=right>"
1877       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{sellprice}, 2)
1878       . "</td>";
1879     $column_data{linetotallastcost} = "<td align=right>"
1880       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{lastcost}, 2)
1881       . "</td>";
1882     $column_data{linetotallistprice} = "<td align=right>"
1883       . $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{listprice}, 2)
1884       . "</td>";
1885
1886     if (!$ref->{assemblyitem}) {
1887       $totalsellprice += $onhand * $ref->{sellprice};
1888       $totallastcost  += $onhand * $ref->{lastcost};
1889       $totallistprice += $onhand * $ref->{listprice};
1890
1891       $subtotalonhand    += $onhand;
1892       $subtotalsellprice += $onhand * $ref->{sellprice};
1893       $subtotallastcost  += $onhand * $ref->{lastcost};
1894       $subtotallistprice += $onhand * $ref->{listprice};
1895     }
1896
1897     $column_data{rop} =
1898       "<td align=right>"
1899       . $form->format_amount(\%myconfig, $ref->{rop}) . "</td>";
1900     $column_data{weight} =
1901         "<td align=right>"
1902       . $form->format_amount(\%myconfig, $ref->{weight})
1903       . "</td>";
1904     $column_data{unit}        = "<td>$ref->{unit}&nbsp;</td>";
1905     $column_data{bin}         = "<td>$ref->{bin}&nbsp;</td>";
1906     $column_data{priceupdate} = "<td>$ref->{priceupdate}&nbsp;</td>";
1907
1908     $column_data{invnumber} =
1909       ($ref->{module} ne 'oe')
1910       ? "<td><a href=$ref->{module}.pl?action=edit&type=invoice&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{invnumber}</a></td>"
1911       : "<td>$ref->{invnumber}</td>";
1912     $column_data{ordnumber} =
1913       ($ref->{module} eq 'oe')
1914       ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{ordnumber}</a></td>"
1915       : "<td>$ref->{ordnumber}</td>";
1916     $column_data{quonumber} =
1917       ($ref->{module} eq 'oe' && !$ref->{ordnumber})
1918       ? "<td><a href=$ref->{module}.pl?action=edit&type=$ref->{type}&id=$ref->{trans_id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{quonumber}</a></td>"
1919       : "<td>$ref->{quonumber}</td>";
1920
1921     $column_data{name} = "<td>$ref->{name}</td>";
1922
1923     $column_data{image} =
1924       ($ref->{image})
1925       ? "<td><a href=$ref->{image}><img src=$ref->{image} height=32 border=0></a></td>"
1926       : "<td>&nbsp;</td>";
1927     $column_data{drawing} =
1928       ($ref->{drawing})
1929       ? "<td><a href=$ref->{drawing}>$ref->{drawing}</a></td>"
1930       : "<td>&nbsp;</td>";
1931     $column_data{microfiche} =
1932       ($ref->{microfiche})
1933       ? "<td><a href=$ref->{microfiche}>$ref->{microfiche}</a></td>"
1934       : "<td>&nbsp;</td>";
1935
1936     $column_data{serialnumber} = "<td>$ref->{serialnumber}</td>";
1937
1938     $column_data{soldtotal} =
1939         "<td align=right>"
1940       . $form->format_amount(\%myconfig, $ref->{soldtotal})
1941       . "</td>";
1942
1943     $column_data{deliverydate} = "<td>$ref->{deliverydate}</td>";
1944
1945     $i++;
1946     $i %= 2;
1947     print "<tr class=listrow$i>";
1948
1949     map { print "\n$column_data{$_}" } @column_index;
1950
1951     print qq|
1952     </tr>
1953 |;
1954
1955   }
1956
1957   if ($form->{l_subtotal} eq 'Y') {
1958     &parts_subtotal;
1959   }
1960
1961   if ($form->{"l_linetotal"}) {
1962     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
1963     $column_data{linetotalsellprice} =
1964         "<th class=listtotal align=right>"
1965       . $form->format_amount(\%myconfig, $totalsellprice, 2)
1966       . "</th>";
1967     $column_data{linetotallastcost} =
1968         "<th class=listtotal align=right>"
1969       . $form->format_amount(\%myconfig, $totallastcost, 2)
1970       . "</th>";
1971     $column_data{linetotallistprice} =
1972         "<th class=listtotal align=right>"
1973       . $form->format_amount(\%myconfig, $totallistprice, 2)
1974       . "</th>";
1975
1976     print "<tr class=listtotal>";
1977
1978     map { print "\n$column_data{$_}" } @column_index;
1979
1980     print qq|</tr>
1981     |;
1982   }
1983
1984   print qq|
1985   <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
1986 </table>
1987
1988 |;
1989
1990   print qq|
1991
1992 <br>
1993
1994 <form method=post action=$form->{script}>
1995
1996 <input name=callback type=hidden value="$form->{callback}">
1997
1998 <input type=hidden name=item value=$form->{searchitems}>
1999
2000 <input type=hidden name=path value=$form->{path}>
2001 <input type=hidden name=login value=$form->{login}>
2002 <input type=hidden name=password value=$form->{password}>|;
2003
2004   print qq|
2005   <input class=submit type=submit name=action value="|
2006     . $locale->text('Add') . qq|">
2007
2008   </form>
2009
2010 </body>
2011 </html>
2012 |;
2013
2014   $lxdebug->leave_sub();
2015 }    #end generate_report
2016
2017 sub parts_subtotal {
2018   $lxdebug->enter_sub();
2019
2020   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
2021   $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
2022
2023   $column_data{onhand} =
2024       "<th class=listsubtotal align=right>"
2025     . $form->format_amount(\%myconfig, $subtotalonhand)
2026     . "</th>";
2027
2028   $column_data{linetotalsellprice} =
2029       "<th class=listsubtotal align=right>"
2030     . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
2031     . "</th>";
2032   $column_data{linetotallistprice} =
2033       "<th class=listsubtotal align=right>"
2034     . $form->format_amount(\%myconfig, $subtotallistprice, 2)
2035     . "</th>";
2036   $column_data{linetotallastcost} =
2037       "<th class=listsubtotal align=right>"
2038     . $form->format_amount(\%myconfig, $subtotallastcost, 2)
2039     . "</th>";
2040
2041   $subtotalonhand    = 0;
2042   $subtotalsellprice = 0;
2043   $subtotallistprice = 0;
2044   $subtotallastcost  = 0;
2045
2046   print "<tr class=listsubtotal>";
2047
2048   map { print "\n$column_data{$_}" } @column_index;
2049
2050   print qq|
2051   </tr>
2052 |;
2053
2054   $lxdebug->leave_sub();
2055 }
2056
2057 sub edit {
2058   $lxdebug->enter_sub();
2059
2060   IC->get_part(\%myconfig, \%$form);
2061
2062   $form->{"original_partnumber"} = $form->{"partnumber"};
2063
2064   $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
2065
2066   &link_part;
2067   &display_form;
2068
2069   $lxdebug->leave_sub();
2070 }
2071
2072 sub link_part {
2073   $lxdebug->enter_sub();
2074
2075   IC->create_links("IC", \%myconfig, \%$form);
2076
2077   # currencies
2078   map({ $form->{selectcurrency} .= "<option>$_\n" }
2079       split(/:/, $form->{currencies}));
2080
2081   # parts and assemblies have the same links
2082   $item = $form->{item};
2083   if ($form->{item} eq 'assembly') {
2084     $item = 'part';
2085   }
2086
2087   # build the popup menus
2088   $form->{taxaccounts} = "";
2089   foreach $key (keys %{ $form->{IC_links} }) {
2090     foreach $ref (@{ $form->{IC_links}{$key} }) {
2091
2092       # if this is a tax field
2093       if ($key =~ /IC_tax/) {
2094         if ($key =~ /$item/) {
2095           $form->{taxaccounts} .= "$ref->{accno} ";
2096           $form->{"IC_tax_$ref->{accno}_description"} =
2097             "$ref->{accno}--$ref->{description}";
2098
2099           if ($form->{id}) {
2100             if ($form->{amount}{ $ref->{accno} }) {
2101               $form->{"IC_tax_$ref->{accno}"} = "checked";
2102             }
2103           } else {
2104             $form->{"IC_tax_$ref->{accno}"} = "checked";
2105           }
2106         }
2107       } else {
2108
2109         $form->{"select$key"} .=
2110           "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
2111         if ($form->{amount}{$key} eq $ref->{accno}) {
2112           $form->{$key} = "$ref->{accno}--$ref->{description}";
2113         }
2114
2115       }
2116     }
2117   }
2118   chop $form->{taxaccounts};
2119
2120   if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
2121     $form->{selectIC_income}  = $form->{selectIC_sale};
2122     $form->{selectIC_expense} = $form->{selectIC_cogs};
2123     $form->{IC_income}        = $form->{IC_sale};
2124     $form->{IC_expense}       = $form->{IC_cogs};
2125   }
2126
2127   delete $form->{IC_links};
2128   delete $form->{amount};
2129
2130   $form->get_partsgroup(\%myconfig, { all => 1 });
2131
2132   $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
2133
2134   if (@{ $form->{all_partsgroup} }) {
2135     $form->{selectpartsgroup} = qq|<option>\n|;
2136     map {
2137       $form->{selectpartsgroup} .=
2138         qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
2139     } @{ $form->{all_partsgroup} };
2140   }
2141
2142   if ($form->{item} eq 'assembly') {
2143
2144     foreach $i (1 .. $form->{assembly_rows}) {
2145       if ($form->{"partsgroup_id_$i"}) {
2146         $form->{"partsgroup_$i"} =
2147           qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
2148       }
2149     }
2150     $form->get_partsgroup(\%myconfig);
2151
2152     if (@{ $form->{all_partsgroup} }) {
2153       $form->{selectassemblypartsgroup} = qq|<option>\n|;
2154
2155       map {
2156         $form->{selectassemblypartsgroup} .=
2157           qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
2158       } @{ $form->{all_partsgroup} };
2159     }
2160   }
2161   $lxdebug->leave_sub();
2162 }
2163
2164 sub form_header {
2165   $lxdebug->enter_sub();
2166
2167   map({ $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, -2) }
2168       qw(sellprice listprice lastcost gv));
2169
2170   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
2171     qw(weight rop stock);
2172
2173   foreach $item (qw(partnumber description unit notes)) {
2174     $form->{$item} =~ s/\"/&quot;/g;
2175   }
2176
2177   $payment = qq|<option value=""></option>|;
2178   foreach $item (@{ $form->{payment_terms} }) {
2179     if ($form->{payment_id} eq $item->{id}) {
2180       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
2181     } else {
2182       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
2183     }
2184   }
2185
2186
2187   if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
2188     $rows = 4;
2189   }
2190
2191   $notes =
2192     qq|<textarea name=notes rows=$rows cols=45 wrap=soft>$form->{notes}</textarea>|;
2193   if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
2194     $description =
2195       qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
2196   } else {
2197     $description =
2198       qq|<input name=description size=40 value="$form->{description}">|;
2199   }
2200
2201   $ean =  qq|<input name=ean size=40 value="$form->{ean}">|;
2202
2203   foreach $item (split / /, $form->{taxaccounts}) {
2204     $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : "";
2205   }
2206
2207   IC->retrieve_buchungsgruppen(\%myconfig, $form);
2208   if (@{ $form->{BUCHUNGSGRUPPEN} }) {
2209     foreach $item (@{ $form->{BUCHUNGSGRUPPEN} }) {
2210       if ($item->{id} == $form->{buchungsgruppen_id}) {
2211         $form->{selectbuchungsgruppe} .=
2212           "<option value=$item->{id} selected>$item->{description}\n";
2213       } elsif (($form->{id} && $form->{orphaned}) || (!$form->{id})) {
2214         $form->{selectbuchungsgruppe} .=
2215           "<option value=$item->{id}>$item->{description}\n";
2216       }
2217
2218     }
2219   }
2220
2221   $buchungsgruppe = qq|
2222               <tr>
2223                 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
2224                 <td><select name=buchungsgruppen_id>$form->{selectbuchungsgruppe}</select></td>
2225               </tr>|;
2226
2227
2228   # set option
2229   foreach $item (qw(IC IC_income IC_expense)) {
2230     if ($form->{$item}) {
2231       if ($form->{id} && $form->{orphaned}) {
2232         $form->{"select$item"} =~ s/ selected//;
2233         $form->{"select$item"} =~
2234           s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
2235       } else {
2236         $form->{"select$item"} = qq|<option selected>$form->{$item}|;
2237       }
2238     }
2239   }
2240
2241   if ($form->{selectpartsgroup}) {
2242     $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
2243     $partsgroup =
2244       qq|<input type=hidden name=selectpartsgroup value="|
2245       . $form->escape($form->{selectpartsgroup}, 1) . qq|">|;
2246     $form->{selectpartsgroup} =~
2247       s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
2248
2249     $partsgroup .=
2250       qq|<select name=partsgroup>$form->{selectpartsgroup}</select>|;
2251     $group = $locale->text('Group');
2252   }
2253
2254   # tax fields
2255   foreach $item (split / /, $form->{taxaccounts}) {
2256     $tax .= qq|
2257       <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}>&nbsp;<b>$form->{"IC_tax_${item}_description"}</b>
2258       <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
2259 |;
2260   }
2261
2262   $form->{obsolete} = "checked" if $form->{obsolete};
2263
2264   $lastcost = qq|
2265               <tr>
2266                 <th align="right" nowrap="true">|
2267     . $locale->text('Last Cost') . qq|</th>
2268                 <td><input name=lastcost size=11 value=$form->{lastcost}></td>
2269               </tr>
2270 |;
2271   if (!$eur) {
2272     $linkaccounts = qq|
2273                <tr>
2274                 <th align=right>| . $locale->text('Inventory') . qq|</th>
2275                 <td><select name=IC>$form->{selectIC}</select></td>
2276                 <input name=selectIC type=hidden value="$form->{selectIC}">
2277               </tr>|;
2278   }
2279
2280   if ($form->{item} eq "part") {
2281
2282     $linkaccounts .= qq|
2283               <tr>
2284                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2285                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2286                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2287               </tr>
2288               <tr>
2289                 <th align=right>| . $locale->text('Expense') . qq|</th>
2290                 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
2291                 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
2292               </tr>
2293 |;
2294
2295     $weight = qq|
2296               <tr>
2297                 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
2298                 <td>
2299                   <table>
2300                     <tr>
2301                       <td>
2302                         <input name=weight size=10 value=$form->{weight}>
2303                       </td>
2304                     </tr>
2305                   </table>
2306                 </td>
2307               </tr>
2308 |;
2309
2310   }
2311
2312   if ($form->{item} eq "assembly") {
2313
2314     $lastcost = "";
2315
2316     $linkaccounts = qq|
2317               <tr>
2318                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2319                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2320                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
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                         &nbsp;$form->{weight}
2332                         <input type=hidden name=weight value=$form->{weight}>
2333                       </td>
2334                     </tr>
2335                   </table>
2336                 </td>
2337               </tr>
2338 |;
2339
2340   }
2341
2342   if ($form->{item} eq "service") {
2343
2344     $linkaccounts = qq|
2345               <tr>
2346                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2347                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2348                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2349               </tr>
2350               <tr>
2351                 <th align=right>| . $locale->text('Expense') . qq|</th>
2352                 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
2353                 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
2354               </tr>
2355 |;
2356
2357   }
2358   $linkaccounts = qq|<input type=hidden name=IC_income value="$form->{IC_income_default}">|;
2359
2360   if ($form->{IC_cogs_default}) {
2361     $form->{IC_expense_default} = $form->{IC_cogs_default};
2362   }
2363
2364   if (($form->{item} eq "service") || ($form->{item} eq "part")) {
2365     $linkaccounts .= qq|<input type=hidden name=IC_expense value="$form->{IC_expense_default}">|;
2366   }
2367   if ($form->{item} eq "part") {
2368     $linkaccounts .= qq|<input type=hidden name=IC value="$form->{IC_default}">|;
2369   }
2370
2371   if ($form->{item} ne 'service') {
2372     $n   = ($form->{onhand} > 0) ? "1" : "0";
2373     $rop = qq|
2374               <tr>
2375                 <th align="right" nowrap>| . $locale->text('On Hand') . qq|</th>
2376                 <th align=left nowrap class="plus$n">&nbsp;|
2377       . $form->format_amount(\%myconfig, $form->{onhand}) . qq|</th>
2378               </tr>
2379 |;
2380
2381     if ($form->{item} eq 'assembly') {
2382       $rop .= qq|
2383               <tr>
2384                 <th align="right" nowrap>| . $locale->text('Stock') . qq|</th>
2385                 <td><input name=stock size=10 value=$form->{stock}></td>
2386               </tr>
2387 |;
2388     }
2389
2390     $rop .= qq|
2391               <tr>
2392                 <th align="right" nowrap="true">| . $locale->text('ROP') . qq|</th>
2393                 <td><input name=rop size=10 value=$form->{rop}></td>
2394               </tr>
2395 |;
2396
2397     $bin = qq|
2398               <tr>
2399                 <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th>
2400                 <td><input name=bin size=10 value=$form->{bin}></td>
2401               </tr>
2402 |;
2403     $vegv = qq|
2404               <tr>
2405                 <th align="right" nowrap="true">|
2406       . $locale->text('Verrechnungseinheit') . qq|</th>
2407                 <td><input name=ve size=10 value=$form->{ve}></td>
2408               </tr>
2409               <tr>
2410                 <th align="right" nowrap="true">|
2411       . $locale->text('Geschäftsvolumen') . qq|</th>
2412                 <td><input name=gv size=10 value=$form->{gv}></td>
2413               </tr>
2414 |;
2415     $notdiscountableok = ($form->{not_discountable}) == 1 ? "checked" : "";
2416     $notdiscountable .= qq|
2417               <tr>
2418                 <th align=right nowrap>|
2419     . $locale->text('Not Discountable') . qq|</th>
2420                 <td><input class=checkbox type=checkbox name=not_discountable value=1 $notdiscountableok></td>
2421              </tr>
2422 |;
2423
2424   $formel =
2425     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>|;
2426     $imagelinks = qq|
2427   <tr>
2428     <td>
2429       <table width=100%>
2430         <tr>
2431           <th align=right nowrap>| . $locale->text('Image') . qq|</th>
2432           <td><input name=image size=40 value="$form->{image}"></td>
2433           <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
2434           <td><input name=microfiche size=20 value="$form->{microfiche}"></td>
2435         </tr>
2436         <tr>
2437           <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
2438           <td><input name=drawing size=40 value="$form->{drawing}"></td>
2439         </tr>
2440       </table>
2441     </td>
2442   </tr>
2443 |;
2444
2445   }
2446
2447   if ($form->{id}) {
2448     $obsolete = qq|
2449               <tr>
2450                 <th align="right" nowrap="true">| . $locale->text('Obsolete') . qq|</th>
2451                 <td><input name=obsolete type=checkbox class=checkbox value=1 $form->{obsolete}></td>
2452               </tr>
2453 |;
2454   }
2455   $shopok = $form->{shop} == 1 ? "checked" : "";
2456   $shop .= qq|
2457               <tr>
2458                 <th align=right nowrap>|
2459     . $locale->text('Shopartikel') . qq|</th>
2460                 <td><input class=checkbox type=checkbox name=shop value=1 $shopok></td>
2461              </tr>
2462 |;
2463
2464
2465   # type=submit $locale->text('Add Part')
2466   # type=submit $locale->text('Add Service')
2467   # type=submit $locale->text('Add Assembly')
2468
2469   # type=submit $locale->text('Edit Part')
2470   # type=submit $locale->text('Edit Service')
2471   # type=submit $locale->text('Edit Assembly')
2472   # use JavaScript Calendar or not
2473   $form->{jsscript} = $jscalendar;
2474   $jsscript = "";
2475   if ($form->{jsscript}) {
2476
2477     # with JavaScript Calendar
2478     $button1 = qq|
2479        <td width="13"><input name=priceupdate id=priceupdate size=11  title="$myconfig{dateformat}" value="$form->{priceupdate}"></td>
2480        <td width="4" align="left"><input type=button name=priceupdate id="trigger1" value=|
2481       . $locale->text('button') . qq|></td>
2482       |;
2483
2484     #write Trigger
2485     $jsscript =
2486       Form->write_trigger(\%myconfig, "1", "priceupdate", "BL", "trigger1");
2487   } else {
2488
2489     # without JavaScript Calendar
2490     $button1 = qq|
2491                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
2492   }
2493
2494   my $unit_select = '<input type="hidden" name="unit_changeable" value="' . $form->{"unit_changeable"} . '">';
2495   if (!$form->{"unit_changeable"}) {
2496     $unit_select .= '<input type="hidden" name="unit" value="' . $form->{"unit"} . '">' . $form->{"unit"};
2497   } else {
2498     my $units = AM->retrieve_units(\%myconfig, $form, $form->{"item"} eq "service" ? "service" : "dimension");
2499     $unit_select .= AM->unit_select_html($units, "unit", $form->{"unit"});
2500   }
2501
2502   $form->{fokus} = "ic.partnumber";
2503   $form->header;
2504
2505   print qq|
2506   <body onLoad="fokus()">
2507  <script type="text/javascript" src="js/common.js"></script>
2508  <script type="text/javascript" src="js/parts_language_selection.js"></script>
2509
2510 <form method=post name="ic" action=$form->{script}>
2511
2512 <input name=id type=hidden value=$form->{id}>
2513 <input name=item type=hidden value=$form->{item}>
2514 <input name=title type=hidden value="$form->{title}">
2515 <input name=makemodel type=hidden value="$form->{makemodel}">
2516 <input name=alternate type=hidden value="$form->{alternate}">
2517 <input name=onhand type=hidden value=$form->{onhand}>
2518 <input name=orphaned type=hidden value=$form->{orphaned}>
2519 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
2520 <input name=rowcount type=hidden value=$form->{rowcount}>
2521 <input name=eur type=hidden value=$eur>
2522 <input name=language_values type=hidden value="$form->{language_values}">
2523 <input name="original_partnumber" type="hidden" value="| . $form->quote($form->{"original_partnumber"}) . qq|">
2524
2525 <table width="100%">
2526   <tr>
2527     <th class=listtop>$form->{title}</th>
2528   </tr>
2529   <tr height="5"></tr>
2530   <tr>
2531     <td>
2532       <table width="100%">
2533         <tr valign=top>
2534           <th align=left>| . $locale->text('Part Number') . qq|</th>
2535           <th align=left>| . $locale->text('Part Description') . qq|</th>
2536           <th align=left>$group</th>
2537         </tr>
2538         <tr valign=top>
2539           <td><input name=partnumber value="$form->{partnumber}" size=20></td>
2540           <td>$description</td>
2541           <td>$partsgroup</td>
2542           <input type=hidden name=oldpartsgroup value="$form->{oldpartsgroup}">
2543         </tr>
2544       </table>
2545     </td>
2546   </tr>
2547   <tr>
2548     <td>
2549       <table width="100%" height="100%">
2550         <tr valign=top>
2551           <td width=70%>
2552             <table width="100%" height="100%">
2553               <tr class="listheading">
2554                 <th class="listheading" align="center" colspan=2>|
2555     . $locale->text('') . qq|</th>
2556               </tr>
2557               <td colspan=2>
2558                 <table>
2559                   $buchungsgruppe
2560                   $linkaccounts
2561                 </table>
2562               </td>
2563               <tr>
2564                 <th align="left">| . $locale->text('Notes') . qq|</th>
2565                 <th align="left">| . $locale->text('Formula') . qq|</th>
2566               </tr>
2567               <tr>
2568                 <td>
2569                   $notes
2570                 </td>
2571                 <td>
2572                   $formel
2573                 </td>
2574               </tr>
2575               <tr>
2576                 <th align="left"></th>
2577                 <th align="left">| . $locale->text('EAN-Code') . qq|</th>
2578               </tr>
2579               <tr>
2580                 <td>
2581                   <button type="button" onclick="parts_language_selection_window('language_values')">| . $locale->text('Set Language Values') . qq|</button>
2582                 </td>
2583                 <td>
2584                   $ean  
2585                 </td>
2586               </tr>
2587               <tr>
2588               <td colspan=2>
2589                 <table>
2590                 <tr>
2591                <th align=right>| . $locale->text('Payment Terms') . qq|</th>
2592                  <td><select name=payment_id>$payment</select></td>
2593                 </tr>
2594                </table>
2595               </td>
2596               </tr>
2597             </table>
2598           </td>
2599           <td width="30%">
2600             <table width="100%">
2601               <tr>
2602                 <th align="right" nowrap="true">|
2603     . $locale->text('Updated') . qq|</th>
2604                 $button1
2605               </tr>
2606               <tr>
2607                 <th align="right" nowrap="true">| . $locale->text('List Price') . qq|</th>
2608                 <td><input name=listprice size=11 value=$form->{listprice}></td>
2609               </tr>
2610               <tr>
2611                 <th align="right" nowrap="true">| . $locale->text('Sell Price') . qq|</th>
2612                 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
2613               </tr>
2614               $lastcost
2615               <tr>
2616                 <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
2617                 <td>$unit_select</td>
2618               </tr>
2619               $weight
2620               $rop
2621               $bin
2622               $notdiscountable
2623               $vegv
2624               $shop
2625               $obsolete
2626             </table>
2627           </td>
2628         </tr>
2629       </table>
2630     </td>
2631   </tr>
2632   $imagelinks
2633
2634 $jsscript
2635 |;
2636   $lxdebug->leave_sub();
2637 }
2638
2639 sub form_footer {
2640   $lxdebug->enter_sub();
2641
2642   if ($form->{item} eq "assembly") {
2643
2644     print qq|
2645         <tr>
2646           <td>
2647             <table width="100%">
2648               <tr>
2649                 <th colspan=2 align=right>|
2650       . $locale->text('Total') . qq|&nbsp;</th>
2651                 <th align=right>|
2652       . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
2653               </tr>
2654             </table>
2655           </td>
2656         </tr>
2657         <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
2658 |;
2659   }
2660
2661   print qq|
2662       <input type=hidden name=path value=$form->{path}>
2663       <input type=hidden name=login value=$form->{login}>
2664       <input type=hidden name=password value=$form->{password}>
2665       <input type=hidden name=callback value="$form->{callback}">
2666       <input type=hidden name=previousform value="$form->{previousform}">
2667       <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
2668       <input type=hidden name=vc value=$form->{vc}>
2669   <tr>
2670     <td><hr size=3 noshade></td>
2671   </tr>
2672 </table>
2673
2674 <br>
2675 <input class=submit type=submit name=action value="|
2676     . $locale->text('Update') . qq|">
2677   |;
2678
2679   unless ($form->{item} eq "service") {
2680     print qq|
2681       <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
2682     |;
2683   }
2684
2685   print qq|
2686      <input type=hidden name=price_rows value=$form->{price_rows}>|;
2687
2688   print qq|
2689       <input class=submit type=submit name=action value="|
2690     . $locale->text('Save') . qq|">|;
2691
2692   if ($form->{id}) {
2693
2694     if (!$form->{previousform}) {
2695       print qq|
2696       <input class=submit type=submit name=action value="|
2697         . $locale->text('Save as new') . qq|">|;
2698     }
2699
2700     if ($form->{orphaned}) {
2701       if (!$form->{previousform}) {
2702         if ($form->{item} eq 'assembly') {
2703           if (!$form->{onhand}) {
2704             print qq|
2705       <input class=submit type=submit name=action value="|
2706               . $locale->text('Delete') . qq|">|;
2707           }
2708         } else {
2709           print qq|
2710       <input class=submit type=submit name=action value="|
2711             . $locale->text('Delete') . qq|">|;
2712         }
2713       }
2714     }
2715   }
2716
2717   print qq|
2718
2719 </form>
2720 <script type="text/javascript" src="js/wz_tooltip.js"></script>
2721
2722 </body>
2723 </html>
2724 |;
2725
2726   $lxdebug->leave_sub();
2727 }
2728
2729 sub makemodel_row {
2730   $lxdebug->enter_sub();
2731   my ($numrows) = @_;
2732
2733   $form->{"make_$i"}  =~ s/\"/&quot;/g;
2734   $form->{"model_$i"} =~ s/\"/&quot;/g;
2735
2736   print qq|
2737   <tr>
2738     <td>
2739       <table width=100%>
2740         <tr>
2741           <th class="listheading">| . $locale->text('Make') . qq|</th>
2742           <th class="listheading">| . $locale->text('Model') . qq|</th>
2743         </tr>
2744 |;
2745
2746   for $i (1 .. $numrows) {
2747     print qq|
2748         <tr>
2749           <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
2750           <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
2751         </tr>
2752 |;
2753   }
2754
2755   print qq|
2756       </table>
2757     </td>
2758   </tr>
2759 |;
2760
2761   $lxdebug->leave_sub();
2762 }
2763
2764 sub assembly_row {
2765   $lxdebug->enter_sub();
2766   my ($numrows) = @_;
2767
2768   @column_index =
2769     qw(runningnumber qty unit bom partnumber description partsgroup total);
2770
2771   if ($form->{previousform}) {
2772     $nochange     = 1;
2773     @column_index = qw(qty unit bom partnumber description partsgroup total);
2774   } else {
2775
2776     # change callback
2777     $form->{old_callback} = $form->{callback};
2778     $callback             = $form->{callback};
2779     $form->{callback}     = "$form->{script}?action=display_form";
2780
2781     # delete action
2782     map { delete $form->{$_} } qw(action header);
2783
2784     $previousform = "";
2785
2786     # save form variables in a previousform variable
2787     foreach $key (sort keys %$form) {
2788
2789       # escape ampersands
2790       $form->{$key} =~ s/&/%26/g;
2791       $previousform .= qq|$key=$form->{$key}&|;
2792     }
2793     chop $previousform;
2794     $previousform = $form->escape($form->escape($previousform, 1));
2795     $form->{callback} = $callback;
2796
2797     $form->{assemblytotal} = 0;
2798     $form->{weight}        = 0;
2799
2800   }
2801   $column_header{runningnumber} =
2802     qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
2803   $column_header{qty} =
2804     qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
2805   $column_header{unit} =
2806     qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
2807   $column_header{partnumber} =
2808       qq|<th align=left nowrap width=20%>|
2809     . $locale->text('Part Number')
2810     . qq|</th>|;
2811   $column_header{description} =
2812     qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
2813   $column_header{total} =
2814     qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
2815   $column_header{bom}        = qq|<th>| . $locale->text('BOM') . qq|</th>|;
2816   $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
2817
2818   print qq|
2819   <tr class=listheading>
2820     <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
2821   </tr>
2822   <tr>
2823     <td>
2824       <table width=100%>
2825         <tr>
2826 |;
2827
2828   map { print "\n$column_header{$_}" } @column_index;
2829
2830   print qq|
2831         </tr>
2832 |;
2833
2834   for $i (1 .. $numrows) {
2835     $form->{"partnumber_$i"} =~ s/\"/&quot;/g;
2836
2837     $linetotal =
2838       $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
2839     $form->{assemblytotal} += $linetotal;
2840
2841     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
2842
2843     $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
2844
2845     if (($i >= 1) && ($i == $numrows)) {
2846
2847       if ($nochange) {
2848         map { $column_data{$_} = qq|<td></td>| }
2849           qw(qty unit partnumber description bom partsgroup);
2850       } else {
2851
2852         map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
2853
2854         $column_data{qty} =
2855           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2856         $column_data{partnumber} =
2857           qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
2858         $column_data{description} =
2859           qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
2860         $column_data{partsgroup} =
2861           qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
2862
2863       }
2864
2865     } else {
2866
2867       if ($form->{previousform}) {
2868         $column_data{partnumber} =
2869           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
2870         $column_data{qty} =
2871           qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
2872
2873         $column_data{bom} =
2874           qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
2875         $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : "&nbsp;";
2876         $column_data{bom} .= qq|</td>|;
2877
2878         $column_data{partsgroup} =
2879           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2880
2881       } else {
2882         $href =
2883           qq|$form->{script}?action=edit&id=$form->{"id_$i"}&path=$form->{path}&login=$form->{login}&password=$form->{password}&rowcount=$i&previousform=$previousform|;
2884         $column_data{partnumber} =
2885           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
2886         $column_data{runningnumber} =
2887           qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
2888         $column_data{qty} =
2889           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2890
2891         $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
2892         $column_data{bom} =
2893           qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
2894
2895         $column_data{partsgroup} =
2896           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2897       }
2898
2899       $column_data{unit} =
2900         qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
2901       $column_data{description} =
2902         qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
2903     }
2904
2905     $column_data{total} = qq|<td align=right>$linetotal</td>|;
2906
2907     $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
2908
2909     print qq|
2910         <tr>|;
2911
2912     map { print "\n$column_data{$_}" } @column_index;
2913
2914     print qq|
2915         </tr>
2916   <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2917   <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
2918   <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
2919 |;
2920   }
2921
2922   print qq|
2923       </table>
2924     </td>
2925   </tr>
2926 |;
2927
2928   $lxdebug->leave_sub();
2929 }
2930
2931 sub update {
2932   $lxdebug->enter_sub();
2933
2934   if ($form->{item} eq "assembly") {
2935     $i = $form->{assembly_rows};
2936
2937     # if last row is empty check the form otherwise retrieve item
2938     if (   ($form->{"partnumber_$i"} eq "")
2939         && ($form->{"description_$i"} eq "")
2940         && ($form->{"partsgroup_$i"}  eq "")) {
2941
2942       &check_form;
2943
2944     } else {
2945
2946       IC->assembly_item(\%myconfig, \%$form);
2947
2948       $rows = scalar @{ $form->{item_list} };
2949
2950       if ($rows) {
2951         $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2952
2953         if ($rows > 1) {
2954           $form->{makemodel_rows}--;
2955           &select_item;
2956           exit;
2957         } else {
2958           map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g }
2959             qw(partnumber description unit partsgroup);
2960           map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
2961             keys %{ $form->{item_list}[0] };
2962           $form->{"runningnumber_$i"} = $form->{assembly_rows};
2963           $form->{assembly_rows}++;
2964
2965           &check_form;
2966
2967         }
2968
2969       } else {
2970
2971         $form->{rowcount} = $i;
2972         $form->{assembly_rows}++;
2973
2974         &new_item;
2975
2976       }
2977     }
2978   }
2979
2980   if ($form->{item} eq "part") {
2981     &check_form;
2982   }
2983
2984   if ($form->{item} eq 'service') {
2985     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2986       qw(sellprice listprice);
2987     &form_header;
2988     &price_row;
2989     &form_footer;
2990   }
2991
2992   $lxdebug->leave_sub();
2993 }
2994
2995 sub save {
2996   $lxdebug->enter_sub();
2997
2998   # check if there is a part number - commented out, cause there is an automatic allocation of numbers
2999   # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
3000
3001   # check if there is a description
3002   $form->isblank("description", $locale->text("Part Description missing!"));
3003
3004   if ($form->{obsolete}) {
3005     $form->error(
3006       $locale->text(
3007         "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
3008       ))
3009       if ($form->{onhand});
3010   }
3011
3012   if (!$form->{buchungsgruppen_id}) {
3013     $form->error($locale->text("Parts must have an entry type.") . " " . 
3014      $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.") 
3015     );
3016   }
3017
3018   $form->error($locale->text('Description must not be empty!')) unless $form->{description};
3019   $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
3020
3021   # expand dynamic strings
3022   # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
3023   # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
3024   # $locale->text('Part Number missing!')
3025   # $locale->text('Service Number missing!')
3026   # $locale->text('Assembly Number missing!')
3027
3028   # save part
3029   $lxdebug->message(LXDebug::DEBUG1,
3030                     "ic.pl: sellprice in save = $form->{sellprice}\n");
3031   $rc = IC->save(\%myconfig, \%$form);
3032   if ($rc == 3) {
3033     $form->error($locale->text('Partnumber not unique!'));
3034   }
3035   $parts_id = $form->{id};
3036
3037   # load previous variables
3038   if ($form->{previousform}) {
3039
3040     # save the new form variables before splitting previousform
3041     map { $newform{$_} = $form->{$_} } keys %$form;
3042
3043     $previousform = $form->unescape($form->{previousform});
3044
3045     # don't trample on previous variables
3046     map { delete $form->{$_} } keys %newform;
3047
3048     # now take it apart and restore original values
3049     foreach $item (split /&/, $previousform) {
3050       ($key, $value) = split /=/, $item, 2;
3051       $value =~ s/%26/&/g;
3052       $form->{$key} = $value;
3053     }
3054     $form->{taxaccounts} = $newform{taxaccount2};
3055
3056     if ($form->{item} eq 'assembly') {
3057
3058       # undo number formatting
3059       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
3060         qw(weight listprice sellprice rop);
3061
3062       $form->{assembly_rows}--;
3063       $i = $newform{rowcount};
3064       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
3065
3066       $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
3067       $form->{weight}    -= $form->{"weight_$i"} * $form->{"qty_$i"};
3068
3069       # change/add values for assembly item
3070       map { $form->{"${_}_$i"} = $newform{$_} }
3071         qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno);
3072
3073       $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
3074       $form->{weight}    += $form->{"weight_$i"} * $form->{"qty_$i"};
3075
3076     } else {
3077
3078       # set values for last invoice/order item
3079       $i = $form->{rowcount};
3080       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
3081
3082       map { $form->{"${_}_$i"} = $newform{$_} }
3083         qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice);
3084       $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
3085       if ($form->{exchangerate} != 0) {
3086         $form->{"sellprice_$i"} /= $form->{exchangerate};
3087       }
3088       $lxdebug->message(LXDebug::DEBUG1,
3089                         qq|sellprice_$i in previousform 2 = |
3090                           . $form->{"sellprice_$i"} . qq|\n|);
3091       map { $form->{"taxaccounts_$i"} .= "$_ " } split / /,
3092         $newform{taxaccount};
3093       chop $form->{"taxaccounts_$i"};
3094       foreach $item (qw(description rate taxnumber)) {
3095         $index = $form->{"taxaccounts_$i"} . "_$item";
3096         $form->{$index} = $newform{$index};
3097       }
3098
3099       # credit remaining calculation
3100       $amount =
3101         $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
3102         $form->{"qty_$i"};
3103       map { $form->{"${_}_base"} += $amount }
3104         (split / /, $form->{"taxaccounts_$i"});
3105       map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
3106         split / /, $form->{"taxaccounts_$i"}
3107         if !$form->{taxincluded};
3108
3109       $form->{creditremaining} -= $amount;
3110
3111       # redo number formatting, because invoice parse them!
3112       $i = $form->{rowcount};
3113       map {
3114         $form->{"${_}_$i"} =
3115           $form->format_amount(\%myconfig, $form->{"${_}_$i"})
3116       } qw(weight listprice sellprice rop);
3117     }
3118
3119     $form->{"id_$i"} = $parts_id;
3120     delete $form->{action};
3121
3122     # restore original callback
3123     $callback = $form->unescape($form->{callback});
3124     $form->{callback} = $form->unescape($form->{old_callback});
3125     delete $form->{old_callback};
3126
3127     $form->{makemodel_rows}--;
3128
3129     # put callback together
3130     foreach $key (keys %$form) {
3131
3132       # do single escape for Apache 2.0
3133       $value = $form->escape($form->{$key}, 1);
3134       $callback .= qq|&$key=$value|;
3135     }
3136     $form->{callback} = $callback;
3137   }
3138   $lxdebug->message(LXDebug::DEBUG1,
3139                     qq|ic.pl: sellprice_$i nach sub save = |
3140                       . $form->{"sellprice_$i"} . qq|\n|);
3141
3142   # redirect
3143   $form->redirect;
3144
3145   $lxdebug->leave_sub();
3146 }
3147
3148 sub save_as_new {
3149   $lxdebug->enter_sub();
3150
3151   $form->{id} = 0;
3152   if ($form->{"original_partnumber"} &&
3153       ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
3154     $form->{partnumber} = "";
3155   }
3156   &save;
3157
3158   $lxdebug->leave_sub();
3159 }
3160
3161 sub delete {
3162   $lxdebug->enter_sub();
3163
3164   $rc = IC->delete(\%myconfig, \%$form);
3165
3166   # redirect
3167   $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
3168   $form->error($locale->text('Cannot delete item!'));
3169
3170   $lxdebug->leave_sub();
3171 }
3172
3173 sub stock_assembly {
3174   $lxdebug->enter_sub();
3175
3176   $form->{title} = $locale->text('Stock Assembly');
3177
3178   $form->header;
3179
3180   print qq|
3181 <body>
3182
3183 <form method=post action=$form->{script}>
3184
3185 <table width="100%">
3186   <tr>
3187     <th class=listtop>$form->{title}</th>
3188   </tr>
3189   <tr height="5"></tr>
3190   <tr valign=top>
3191     <td>
3192       <table>
3193         <tr>
3194           <th align="right" nowrap="true">|
3195     . $locale->text('Part Number') . qq|</th>
3196           <td><input name=partnumber size=20></td>
3197           <td>&nbsp;</td>
3198         </tr>
3199         <tr>
3200           <th align="right" nowrap="true">|
3201     . $locale->text('Part Description') . qq|</th>
3202           <td><input name=description size=40></td>
3203         </tr>
3204       </table>
3205     </td>
3206   </tr>
3207   <tr><td><hr size=3 noshade></td></tr>
3208 </table>
3209
3210 <input type=hidden name=path value=$form->{path}>
3211 <input type=hidden name=login value=$form->{login}>
3212 <input type=hidden name=password value=$form->{password}>
3213
3214 <input type=hidden name=nextsub value=list_assemblies>
3215
3216 <br>
3217 <input class=submit type=submit name=action value="|
3218     . $locale->text('Continue') . qq|">
3219 </form>
3220
3221 </body>
3222 </html>
3223 |;
3224
3225   $lxdebug->leave_sub();
3226 }
3227
3228 sub list_assemblies {
3229   $lxdebug->enter_sub();
3230
3231   IC->retrieve_assemblies(\%myconfig, \%$form);
3232
3233   $column_header{partnumber} =
3234     qq|<th class=listheading>| . $locale->text('Part Number') . qq|</th>|;
3235   $column_header{description} =
3236     qq|<th class=listheading>| . $locale->text('Part Description') . qq|</th>|;
3237   $column_header{bin} =
3238     qq|<th class=listheading>| . $locale->text('Bin') . qq|</th>|;
3239   $column_header{onhand} =
3240     qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
3241   $column_header{rop} =
3242     qq|<th class=listheading>| . $locale->text('ROP') . qq|</th>|;
3243   $column_header{stock} =
3244     qq|<th class=listheading>| . $locale->text('Add') . qq|</th>|;
3245
3246   @column_index = (qw(partnumber description bin onhand rop stock));
3247
3248   $form->{title} = $locale->text('Stock Assembly');
3249
3250   $form->{callback} =
3251     "$form->{script}?action=stock_assembly&path=$form->{path}&login=$form->{login}&password=$form->{password}";
3252
3253   $form->header;
3254
3255   $colspan = $#column_index + 1;
3256
3257   print qq|
3258 <body>
3259
3260 <form method=post action=$form->{script}>
3261
3262 <table width=100%>
3263   <tr>
3264     <th class=listtop colspan=$colspan>$form->{title}</th>
3265   </tr>
3266   <tr size=5></tr>
3267   <tr class=listheading>|;
3268
3269   map { print "\n$column_header{$_}" } @column_index;
3270
3271   print qq|
3272   </tr>
3273 |;
3274
3275   $i = 1;
3276   foreach $ref (@{ $form->{assembly_items} }) {
3277
3278     map { $ref->{$_} =~ s/\"/&quot;/g } qw(partnumber description);
3279
3280     $column_data{partnumber}  = qq|<td width=20%>$ref->{partnumber}</td>|;
3281     $column_data{description} =
3282       qq|<td width=50%>$ref->{description}&nbsp;</td>|;
3283     $column_data{bin}    = qq|<td>$ref->{bin}&nbsp;</td>|;
3284     $column_data{onhand} =
3285         qq|<td align=right>|
3286       . $form->format_amount(\%myconfig, $ref->{onhand})
3287       . qq|</td>|;
3288     $column_data{rop} =
3289         qq|<td align=right>|
3290       . $form->format_amount(\%myconfig, $ref->{rop})
3291       . qq|</td>|;
3292     $column_data{stock} = qq|<td width=10%><input name="qty_$i" size=10></td>|;
3293
3294     $j++;
3295     $j %= 2;
3296     print
3297       qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
3298
3299     map { print "\n$column_data{$_}" } @column_index;
3300
3301     print qq|
3302     </tr>
3303 |;
3304
3305     $i++;
3306
3307   }
3308
3309   $i--;
3310   print qq|
3311   <tr>
3312     <td colspan=6><hr size=3 noshade>
3313   </tr>
3314 </table>
3315 <input name=rowcount type=hidden value="$i">
3316
3317 <input type=hidden name=path value=$form->{path}>
3318 <input type=hidden name=login value=$form->{login}>
3319 <input type=hidden name=password value=$form->{password}>
3320
3321 <input name=callback type=hidden value="$form->{callback}">
3322
3323 <input type=hidden name=nextsub value=restock_assemblies>
3324
3325 <br>
3326 <input class=submit type=submit name=action value="|
3327     . $locale->text('Continue') . qq|">
3328
3329 </form>
3330
3331 </body>
3332 </html>
3333 |;
3334
3335   $lxdebug->leave_sub();
3336 }
3337
3338 sub restock_assemblies {
3339   $lxdebug->enter_sub();
3340
3341   $form->redirect($locale->text('Assemblies restocked!'))
3342     if (IC->restock_assemblies(\%myconfig, \%$form));
3343   $form->error($locale->text('Cannot stock assemblies!'));
3344
3345   $lxdebug->leave_sub();
3346 }
3347
3348 sub price_row {
3349   $lxdebug->enter_sub();
3350
3351   my ($numrows) = @_;
3352
3353   print qq|
3354   <tr>
3355     <td>
3356       <table width=100%>
3357         <tr>
3358           <th class="listheading">| . $locale->text('Preisklasse') . qq|</th>
3359           <th class="listheading">| . $locale->text('Preis') . qq|</th>
3360         </tr>
3361 |;
3362   for $i (1 .. $numrows) {
3363     print qq|
3364         <tr>
3365           <td width=50%><input type=hidden name="pricegroup_$i" size=30  value="$form->{"pricegroup_$i"}">$form->{"pricegroup_$i"}</td>
3366           <td width=50%><input name="price_$i" size=11 value="$form->{"price_$i"}"></td>
3367           <input type=hidden name="pricegroup_id_$i" value="$form->{"pricegroup_id_$i"}">
3368         </tr>
3369 |;
3370   }
3371
3372   print qq|
3373       </table>
3374     </td>
3375   </tr>
3376 |;
3377
3378   $lxdebug->leave_sub();
3379 }
3380
3381
3382 sub parts_language_selection {
3383   $lxdebug->enter_sub();
3384
3385
3386   my $languages = IC->retrieve_languages(\%myconfig, $form);
3387
3388
3389   my $callback = "$form->{script}?action=parts_language_selection&";
3390   map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
3391       (qw(login path password name input_name), grep({ /^[fl]_/ } keys %$form)));
3392
3393   my @header_sort = qw(name longdescription);
3394   my %header_title = ( "name" => $locale->text("Name"),
3395                        "longdescription" => $locale->text("Long Description"),
3396                        );
3397
3398   my @header =
3399     map(+{ "column_title" => $header_title{$_},
3400            "column" => $_,
3401            "callback" => $callback,
3402          },
3403         @header_sort);
3404
3405   $form->{"title"} = $locale->text("Language Values");
3406   $form->header();
3407   print($form->parse_html_template("ic/parts_language_selection", { "HEADER" => \@header,
3408                                                                    "LANGUAGES" => $languages,
3409                                                                    "onload" => $onload }));
3410
3411   $lxdebug->leave_sub();
3412 }
3413
3414 sub continue { &{ $form->{nextsub} } }