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