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