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