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