abd36a84d1f4f886c05afac37d9a605a14d77e5f
[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 unless $ref->{exchangerate};
1740     $ref->{sellprice}    *= $ref->{exchangerate};
1741     $ref->{listprice}    *= $ref->{exchangerate};
1742     $ref->{lastcost}     *= $ref->{exchangerate};
1743
1744     # use this for assemblies
1745     my $onhand = $ref->{onhand};
1746
1747     if ($ref->{assemblyitem}) {
1748       $row->{partnumber}{align}   = 'right';
1749       $row->{onhand}{data}        = 0;
1750       $onhand                     = 0 if ($form->{sold});
1751     }
1752
1753     my $edit_link               = build_std_url('action=edit', 'id=' . E($ref->{id}), 'callback');
1754     $row->{partnumber}->{link}  = $edit_link;
1755     $row->{description}->{link} = $edit_link;
1756
1757     foreach (qw(sellprice listprice lastcost)) {
1758       $row->{$_}{data}            = $form->format_amount(\%myconfig, $ref->{$_}, -2);
1759       $row->{"linetotal$_"}{data} = $form->format_amount(\%myconfig, $ref->{onhand} * $ref->{$_}, 2);
1760     }
1761
1762     map { $row->{$_}{data} = $form->format_amount(\%myconfig, $ref->{$_}); } qw(onhand rop weight soldtotal);
1763
1764     if (!$ref->{assemblyitem}) {
1765       foreach my $col (@subtotal_columns) {
1766         $totals{$col}    += $onhand * $ref->{$col};
1767         $subtotals{$col} += $onhand * $ref->{$col};
1768       }
1769
1770       $subtotals{onhand} += $onhand;
1771     }
1772
1773     # set module stuff
1774     if ($ref->{module} eq 'oe') {
1775       my $edit_oe_link = build_std_url("script=oe.pl", 'action=edit', 'type=' . E($ref->{type}), 'id=' . E($ref->{trans_id}), 'callback');
1776       $row->{ordnumber}{link} = $edit_oe_link;
1777       $row->{quonumber}{link} = $edit_oe_link if (!$ref->{ordnumber});
1778
1779     } else {
1780       $row->{invnumber}{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'type=invoice', 'id=' . E($ref->{trans_id}), 'callback');
1781     }
1782
1783     # set properties of images
1784     if ($ref->{image} && (lc $report->{options}->{output_format} eq 'html')) {
1785       $row->{image}{data}     = '';
1786       $row->{image}{raw_data} = '<a href="' . H($ref->{image}) . '"><img src="' . H($ref->{image}) . '" height="32" border="0"></a>';
1787     }
1788     map { $row->{$_}{link} = $ref->{$_} } qw(drawing microfiche);
1789
1790     $report->add_data($row);
1791
1792     my $next_ref = $form->{parts}[$idx + 1];
1793
1794     # insert subtotal rows
1795     if (($form->{l_subtotal} eq 'Y') &&
1796         (!$next_ref ||
1797          (!$next_ref->{assemblyitem} && ($same_item ne $next_ref->{ $form->{sort} })))) {
1798       my $row = { map { $_ => { 'class' => 'listsubtotal', } } @columns };
1799
1800       if (($form->{searchitems} ne 'assembly') || !$form->{bom}) {
1801         $row->{onhand}->{data} = $form->format_amount(\%myconfig, $subtotals{onhand});
1802       }
1803
1804       map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $subtotals{$_}, 2) } @subtotal_columns;
1805       map { $subtotals{$_} = 0 } ('onhand', @subtotal_columns);
1806
1807       $report->add_data($row);
1808
1809       $same_item = $next_ref->{ $form->{sort} };
1810     }
1811
1812     $idx++;
1813   }
1814
1815   if ($form->{"l_linetotal"}) {
1816     my $row = { map { $_ => { 'class' => 'listtotal', } } @columns };
1817
1818     map { $row->{"linetotal$_"}->{data} = $form->format_amount(\%myconfig, $totals{$_}, 2) } @subtotal_columns;
1819
1820     $report->add_separator();
1821     $report->add_data($row);
1822   }
1823
1824   $report->generate_with_headers();
1825
1826   $lxdebug->leave_sub();
1827 }    #end generate_report
1828
1829 sub parts_subtotal {
1830   $lxdebug->enter_sub();
1831   
1832   # imports
1833   our (%column_data, @column_index);
1834   our ($subtotalonhand, $totalsellprice, $totallastcost, $totallistprice, $subtotalsellprice, $subtotallastcost, $subtotallistprice);
1835
1836   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
1837   $subtotalonhand = 0 if ($form->{searchitems} eq 'assembly' && $form->{bom});
1838
1839   $column_data{onhand} =
1840       "<th class=listsubtotal align=right>"
1841     . $form->format_amount(\%myconfig, $subtotalonhand)
1842     . "</th>";
1843
1844   $column_data{linetotalsellprice} =
1845       "<th class=listsubtotal align=right>"
1846     . $form->format_amount(\%myconfig, $subtotalsellprice, 2)
1847     . "</th>";
1848   $column_data{linetotallistprice} =
1849       "<th class=listsubtotal align=right>"
1850     . $form->format_amount(\%myconfig, $subtotallistprice, 2)
1851     . "</th>";
1852   $column_data{linetotallastcost} =
1853       "<th class=listsubtotal align=right>"
1854     . $form->format_amount(\%myconfig, $subtotallastcost, 2)
1855     . "</th>";
1856
1857   $subtotalonhand    = 0;
1858   $subtotalsellprice = 0;
1859   $subtotallistprice = 0;
1860   $subtotallastcost  = 0;
1861
1862   print "<tr class=listsubtotal>";
1863
1864   map { print "\n$column_data{$_}" } @column_index;
1865
1866   print qq|
1867   </tr>
1868 |;
1869
1870   $lxdebug->leave_sub();
1871 }
1872
1873 sub edit {
1874   $lxdebug->enter_sub();
1875   # show history button
1876   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
1877   #/show hhistory button
1878   IC->get_part(\%myconfig, \%$form);
1879
1880   $form->{"original_partnumber"} = $form->{"partnumber"};
1881
1882   $form->{title} = $locale->text('Edit ' . ucfirst $form->{item});
1883
1884   &link_part;
1885   &display_form;
1886
1887   $lxdebug->leave_sub();
1888 }
1889
1890 sub link_part {
1891   $lxdebug->enter_sub();
1892
1893   IC->create_links("IC", \%myconfig, \%$form);
1894
1895   # currencies
1896   map({ $form->{selectcurrency} .= "<option>$_\n" }
1897       split(/:/, $form->{currencies}));
1898
1899   # parts and assemblies have the same links
1900   my $item = $form->{item};
1901   if ($form->{item} eq 'assembly') {
1902     $item = 'part';
1903   }
1904
1905   # build the popup menus
1906   $form->{taxaccounts} = "";
1907   foreach my $key (keys %{ $form->{IC_links} }) {
1908     foreach my $ref (@{ $form->{IC_links}{$key} }) {
1909
1910       # if this is a tax field
1911       if ($key =~ /IC_tax/) {
1912         if ($key =~ /$item/) {
1913           $form->{taxaccounts} .= "$ref->{accno} ";
1914           $form->{"IC_tax_$ref->{accno}_description"} =
1915             "$ref->{accno}--$ref->{description}";
1916
1917           if ($form->{id}) {
1918             if ($form->{amount}{ $ref->{accno} }) {
1919               $form->{"IC_tax_$ref->{accno}"} = "checked";
1920             }
1921           } else {
1922             $form->{"IC_tax_$ref->{accno}"} = "checked";
1923           }
1924         }
1925       } else {
1926
1927         $form->{"select$key"} .=
1928           "<option $ref->{selected}>$ref->{accno}--$ref->{description}\n";
1929         if ($form->{amount}{$key} eq $ref->{accno}) {
1930           $form->{$key} = "$ref->{accno}--$ref->{description}";
1931         }
1932
1933       }
1934     }
1935   }
1936   chop $form->{taxaccounts};
1937
1938   if (($form->{item} eq "part") || ($form->{item} eq "assembly")) {
1939     $form->{selectIC_income}  = $form->{selectIC_sale};
1940     $form->{selectIC_expense} = $form->{selectIC_cogs};
1941     $form->{IC_income}        = $form->{IC_sale};
1942     $form->{IC_expense}       = $form->{IC_cogs};
1943   }
1944
1945   delete $form->{IC_links};
1946   delete $form->{amount};
1947
1948   $form->get_partsgroup(\%myconfig, { all => 1 });
1949
1950   $form->{partsgroup} = "$form->{partsgroup}--$form->{partsgroup_id}";
1951
1952   if (@{ $form->{all_partsgroup} }) {
1953     $form->{selectpartsgroup} = qq|<option>\n|;
1954     map {
1955       $form->{selectpartsgroup} .=
1956         qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1957     } @{ $form->{all_partsgroup} };
1958   }
1959
1960   if ($form->{item} eq 'assembly') {
1961
1962     foreach my $i (1 .. $form->{assembly_rows}) {
1963       if ($form->{"partsgroup_id_$i"}) {
1964         $form->{"partsgroup_$i"} =
1965           qq|$form->{"partsgroup_$i"}--$form->{"partsgroup_id_$i"}|;
1966       }
1967     }
1968     $form->get_partsgroup(\%myconfig);
1969
1970     if (@{ $form->{all_partsgroup} }) {
1971       $form->{selectassemblypartsgroup} = qq|<option>\n|;
1972
1973       map {
1974         $form->{selectassemblypartsgroup} .=
1975           qq|<option value="$_->{partsgroup}--$_->{id}">$_->{partsgroup}\n|
1976       } @{ $form->{all_partsgroup} };
1977     }
1978   }
1979   $lxdebug->leave_sub();
1980 }
1981
1982 sub form_header {
1983   $lxdebug->enter_sub();
1984
1985   my ($payment, $rows, $notes, $description, $ean, $buchungsgruppe, $partsgroup, $group, $tax, $lastcost, $eur, $linkaccounts, $weight, $n, $rop, $bin, $vegv);
1986   my ($notdiscountableok, $notdiscountable);
1987   my ($formula, $formula_label, $imagelinks, $obsolete, $shopok, $shop);
1988
1989
1990   map({ $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, -2) }
1991       qw(sellprice listprice lastcost gv));
1992
1993   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}) }
1994     qw(weight rop stock);
1995
1996   foreach my $item (qw(partnumber description unit notes)) {
1997     $form->{$item} =~ s/\"/&quot;/g;
1998   }
1999
2000   $payment = qq|<option value=""></option>|;
2001   foreach my $item (@{ $form->{payment_terms} }) {
2002     if ($form->{payment_id} eq $item->{id}) {
2003       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
2004     } else {
2005       $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
2006     }
2007   }
2008
2009
2010   if (($rows = $form->numtextrows($form->{notes}, 40)) < 2) {
2011     $rows = 4;
2012   }
2013
2014   $notes =
2015     qq|<textarea name=notes rows=$rows cols=45 wrap=soft>$form->{notes}</textarea>|;
2016   if (($rows = $form->numtextrows($form->{description}, 40)) > 1) {
2017     $description =
2018       qq|<textarea name="description" rows=$rows cols=40 wrap=soft>$form->{description}</textarea>|;
2019   } else {
2020     $description =
2021       qq|<input name=description size=40 value="$form->{description}">|;
2022   }
2023
2024   $ean =  qq|<input name=ean size=40 value="$form->{ean}">|;
2025
2026   foreach my $item (split / /, $form->{taxaccounts}) {
2027     $form->{"IC_tax_$item"} = ($form->{"IC_tax_$item"}) ? "checked" : "";
2028   }
2029
2030   IC->retrieve_buchungsgruppen(\%myconfig, $form);
2031   if (@{ $form->{BUCHUNGSGRUPPEN} }) {
2032     foreach my $item (@{ $form->{BUCHUNGSGRUPPEN} }) {
2033       if ($item->{id} == $form->{buchungsgruppen_id}) {
2034         $form->{selectbuchungsgruppe} .=
2035           "<option value=$item->{id} selected>$item->{description}\n";
2036       } elsif (($form->{id} && $form->{orphaned}) || (!$form->{id})) {
2037         $form->{selectbuchungsgruppe} .=
2038           "<option value=$item->{id}>$item->{description}\n";
2039       }
2040
2041     }
2042   }
2043
2044   $buchungsgruppe = qq|
2045               <tr>
2046                 <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
2047                 <td><select name=buchungsgruppen_id>$form->{selectbuchungsgruppe}</select></td>
2048               </tr>|;
2049
2050
2051   # set option
2052   foreach my $item (qw(IC IC_income IC_expense)) {
2053     if ($form->{$item}) {
2054       if ($form->{id} && $form->{orphaned}) {
2055         $form->{"select$item"} =~ s/ selected//;
2056         $form->{"select$item"} =~
2057           s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
2058       } else {
2059         $form->{"select$item"} = qq|<option selected>$form->{$item}|;
2060       }
2061     }
2062   }
2063
2064   if ($form->{selectpartsgroup}) {
2065     $form->{selectpartsgroup} = $form->unescape($form->{selectpartsgroup});
2066     $partsgroup =
2067       qq|<input type=hidden name=selectpartsgroup value="|
2068       . $form->escape($form->{selectpartsgroup}, 1) . qq|">|;
2069     $form->{selectpartsgroup} =~
2070       s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
2071
2072     $partsgroup .=
2073       qq|<select name=partsgroup>$form->{selectpartsgroup}</select>|;
2074     $group = $locale->text('Group');
2075   }
2076
2077   # tax fields
2078   foreach my $item (split / /, $form->{taxaccounts}) {
2079     $tax .= qq|
2080       <input class=checkbox type=checkbox name="IC_tax_$item" value=1 $form->{"IC_tax_$item"}>&nbsp;<b>$form->{"IC_tax_${item}_description"}</b>
2081       <br><input type=hidden name=IC_tax_${item}_description value="$form->{"IC_tax_${item}_description"}">
2082 |;
2083   }
2084
2085   $form->{obsolete} = "checked" if $form->{obsolete};
2086
2087   $lastcost = qq|
2088               <tr>
2089                 <th align="right" nowrap="true">|
2090     . $locale->text('Last Cost') . qq|</th>
2091                 <td><input name=lastcost size=11 value=$form->{lastcost}></td>
2092               </tr>
2093 |;
2094   if (!$eur) {
2095     $linkaccounts = qq|
2096                <tr>
2097                 <th align=right>| . $locale->text('Inventory') . qq|</th>
2098                 <td><select name=IC>$form->{selectIC}</select></td>
2099                 <input name=selectIC type=hidden value="$form->{selectIC}">
2100               </tr>|;
2101   }
2102
2103   if ($form->{item} eq "part") {
2104
2105     $linkaccounts .= qq|
2106               <tr>
2107                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2108                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2109                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2110               </tr>
2111               <tr>
2112                 <th align=right>| . $locale->text('Expense') . qq|</th>
2113                 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
2114                 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
2115               </tr>
2116 |;
2117
2118     $weight = qq|
2119               <tr>
2120                 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
2121                 <td>
2122                   <table>
2123                     <tr>
2124                       <td>
2125                         <input name=weight size=10 value=$form->{weight}>
2126                       </td>
2127                     </tr>
2128                   </table>
2129                 </td>
2130               </tr>
2131 |;
2132
2133   }
2134
2135   if ($form->{item} eq "assembly") {
2136
2137     $lastcost = "";
2138
2139     $linkaccounts = qq|
2140               <tr>
2141                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2142                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2143                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2144               </tr>
2145 |;
2146
2147     $weight = qq|
2148               <tr>
2149                 <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
2150                 <td>
2151                   <table>
2152                     <tr>
2153                       <td>
2154                         &nbsp;$form->{weight}
2155                         <input type=hidden name=weight value=$form->{weight}>
2156                       </td>
2157                     </tr>
2158                   </table>
2159                 </td>
2160               </tr>
2161 |;
2162
2163   }
2164
2165   if ($form->{item} eq "service") {
2166
2167     $linkaccounts = qq|
2168               <tr>
2169                 <th align=right>| . $locale->text('Revenue') . qq|</th>
2170                 <td><select name=IC_income>$form->{selectIC_income}</select></td>
2171                 <input name=selectIC_income type=hidden value="$form->{selectIC_income}">
2172               </tr>
2173               <tr>
2174                 <th align=right>| . $locale->text('Expense') . qq|</th>
2175                 <td><select name=IC_expense>$form->{selectIC_expense}</select></td>
2176                 <input name=selectIC_expense type=hidden value="$form->{selectIC_expense}">
2177               </tr>
2178 |;
2179
2180   }
2181   $linkaccounts = qq|<input type=hidden name=IC_income value="$form->{IC_income_default}">|;
2182
2183   if ($form->{IC_cogs_default}) {
2184     $form->{IC_expense_default} = $form->{IC_cogs_default};
2185   }
2186
2187   if (($form->{item} eq "service") || ($form->{item} eq "part")) {
2188     $linkaccounts .= qq|<input type=hidden name=IC_expense value="$form->{IC_expense_default}">|;
2189   }
2190   if ($form->{item} eq "part") {
2191     $linkaccounts .= qq|<input type=hidden name=IC value="$form->{IC_default}">|;
2192   }
2193
2194   if ($form->{item} ne 'service') {
2195     $n   = ($form->{onhand} > 0) ? "1" : "0";
2196     $rop = qq|
2197               <tr>
2198                 <th align="right" nowrap>| . $locale->text('On Hand') . qq|</th>
2199                 <th align=left nowrap class="plus$n">&nbsp;|
2200       . $form->format_amount(\%myconfig, $form->{onhand}) . qq|</th>
2201               </tr>
2202 |;
2203
2204     if ($form->{item} eq 'assembly') {
2205       $rop .= qq|
2206               <tr>
2207                 <th align="right" nowrap>| . $locale->text('Stock') . qq|</th>
2208                 <td><input name=stock size=10 value=$form->{stock}></td>
2209               </tr>
2210 |;
2211     }
2212
2213     $rop .= qq|
2214               <tr>
2215                 <th align="right" nowrap="true">| . $locale->text('ROP') . qq|</th>
2216                 <td><input name=rop size=10 value=$form->{rop}></td>
2217               </tr>
2218 |;
2219
2220     $bin = qq|
2221               <tr>
2222                 <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th>
2223                 <td><input name=bin size=10 value=$form->{bin}></td>
2224               </tr>
2225 |;
2226     $vegv = qq|
2227               <tr>
2228                 <th align="right" nowrap="true">|
2229       . $locale->text('Verrechnungseinheit') . qq|</th>
2230                 <td><input name=ve size=10 value=$form->{ve}></td>
2231               </tr>
2232               <tr>
2233                 <th align="right" nowrap="true">|
2234       . $locale->text('Business Volume') . qq|</th>
2235                 <td><input name=gv size=10 value=$form->{gv}></td>
2236               </tr>
2237 |;
2238     $notdiscountableok = ($form->{not_discountable}) == 1 ? "checked" : "";
2239     $notdiscountable .= qq|
2240               <tr>
2241                 <th align=right nowrap>|
2242     . $locale->text('Not Discountable') . qq|</th>
2243                 <td><input class=checkbox type=checkbox name=not_discountable value=1 $notdiscountableok></td>
2244              </tr>
2245 |;
2246
2247     $formula =
2248       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>|;
2249
2250     $formula_label = $locale->text('Formula');
2251
2252     $imagelinks = qq|
2253   <tr>
2254     <td>
2255       <table width=100%>
2256         <tr>
2257           <th align=right nowrap>| . $locale->text('Image') . qq|</th>
2258           <td><input name=image size=40 value="$form->{image}"></td>
2259           <th align=right nowrap>| . $locale->text('Microfiche') . qq|</th>
2260           <td><input name=microfiche size=20 value="$form->{microfiche}"></td>
2261         </tr>
2262         <tr>
2263           <th align=right nowrap>| . $locale->text('Drawing') . qq|</th>
2264           <td><input name=drawing size=40 value="$form->{drawing}"></td>
2265         </tr>
2266       </table>
2267     </td>
2268   </tr>
2269 |;
2270
2271   }
2272
2273   if ($form->{id}) {
2274     $obsolete = qq|
2275               <tr>
2276                 <th align="right" nowrap="true">| . $locale->text('Obsolete') . qq|</th>
2277                 <td><input name=obsolete type=checkbox class=checkbox value=1 $form->{obsolete}></td>
2278               </tr>
2279 |;
2280   }
2281   $shopok = $form->{shop} == 1 ? "checked" : "";
2282   $shop .= qq|
2283               <tr>
2284                 <th align=right nowrap>|
2285     . $locale->text('Shopartikel') . qq|</th>
2286                 <td><input class=checkbox type=checkbox name=shop value=1 $shopok></td>
2287              </tr>
2288 |;
2289
2290
2291   # type=submit $locale->text('Add Part')
2292   # type=submit $locale->text('Add Service')
2293   # type=submit $locale->text('Add Assembly')
2294
2295   # type=submit $locale->text('Edit Part')
2296   # type=submit $locale->text('Edit Service')
2297   # type=submit $locale->text('Edit Assembly')
2298   # use JavaScript Calendar or not
2299   my ($jsscript, $button1);
2300   $form->{jsscript} = 1;
2301   $jsscript = "";
2302   if ($form->{jsscript}) {
2303
2304     # with JavaScript Calendar
2305     $button1 = qq|
2306        <td width="13"><input name=priceupdate id=priceupdate size=11  title="$myconfig{dateformat}" value="$form->{priceupdate}"></td>
2307        <td width="4" align="left"><input type=button name=priceupdate id="trigger1" value=|
2308       . $locale->text('button') . qq|></td>
2309       |;
2310
2311     #write Trigger
2312     $jsscript =
2313       Form->write_trigger(\%myconfig, "1", "priceupdate", "BL", "trigger1");
2314   } else {
2315
2316     # without JavaScript Calendar
2317     $button1 = qq|
2318                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
2319   }
2320
2321   my $unit_select = '<input type="hidden" name="unit_changeable" value="' . $form->{"unit_changeable"} . '">';
2322   if (!$form->{"unit_changeable"}) {
2323     $unit_select .= '<input type="hidden" name="unit" value="' . $form->{"unit"} . '">' . $form->{"unit"};
2324   } else {
2325     my $units = AM->retrieve_units(\%myconfig, $form, $form->{"item"} eq "service" ? "service" : "dimension");
2326     $unit_select .= AM->unit_select_html($units, "unit", $form->{"unit"});
2327   }
2328
2329   $form->{fokus} = "ic.partnumber";
2330   $form->header;
2331
2332   print qq|
2333   <body onLoad="fokus()">
2334  <script type="text/javascript" src="js/common.js"></script>
2335  <script type="text/javascript" src="js/parts_language_selection.js"></script>
2336
2337 <form method=post name="ic" action=$form->{script}>
2338
2339 <input name=id type=hidden value=$form->{id}>
2340 <input name=item type=hidden value=$form->{item}>
2341 <input name=title type=hidden value="$form->{title}">
2342 <input name=makemodel type=hidden value="$form->{makemodel}">
2343 <input name=alternate type=hidden value="$form->{alternate}">
2344 <input name=onhand type=hidden value=$form->{onhand}>
2345 <input name=orphaned type=hidden value=$form->{orphaned}>
2346 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
2347 <input name=rowcount type=hidden value=$form->{rowcount}>
2348 <input name=eur type=hidden value=$eur>
2349 <input name=language_values type=hidden value="$form->{language_values}">
2350 <input name="original_partnumber" type="hidden" value="| . $form->quote($form->{"original_partnumber"}) . qq|">
2351
2352 <table width="100%">
2353   <tr>
2354     <th class=listtop>$form->{title}</th>
2355   </tr>
2356   <tr height="5"></tr>
2357   <tr>
2358     <td>
2359       <table width="100%">
2360         <tr valign=top>
2361           <th align=left>| . $locale->text('Part Number') . qq|</th>
2362           <th align=left>| . $locale->text('Part Description') . qq|</th>
2363           <th align=left>$group</th>
2364         </tr>
2365         <tr valign=top>
2366           <td><input name=partnumber value="$form->{partnumber}" size=20></td>
2367           <td>$description</td>
2368           <td>$partsgroup</td>
2369           <input type=hidden name=oldpartsgroup value="$form->{oldpartsgroup}">
2370         </tr>
2371       </table>
2372     </td>
2373   </tr>
2374   <tr>
2375     <td>
2376       <table width="100%" height="100%">
2377         <tr valign=top>
2378           <td width=70%>
2379             <table width="100%" height="100%">
2380               <tr class="listheading">
2381                 <th class="listheading" align="center" colspan=2>|
2382     . $locale->text('') . qq|</th>
2383               </tr>
2384               <td colspan=2>
2385                 <table>
2386                   $buchungsgruppe
2387                   $linkaccounts
2388                 </table>
2389               </td>
2390               <tr>
2391                 <th align="left">| . $locale->text('Notes') . qq|</th>
2392                 <th align="left">$formula_label</th>
2393               </tr>
2394               <tr>
2395                 <td>
2396                   $notes
2397                 </td>
2398                 <td>
2399                   $formula
2400                 </td>
2401               </tr>
2402               <tr>
2403                 <th align="left"></th>
2404                 <th align="left">| . $locale->text('EAN-Code') . qq|</th>
2405               </tr>
2406               <tr>
2407                 <td>
2408                   <button type="button" onclick="parts_language_selection_window('language_values')">| . $locale->text('Set Language Values') . qq|</button>
2409                 </td>
2410                 <td>
2411                   $ean  
2412                 </td>
2413               </tr>
2414               <tr>
2415               <td colspan=2>
2416                 <table>
2417                 <tr>
2418                <th align=right>| . $locale->text('Payment Terms') . qq|</th>
2419                  <td><select name=payment_id>$payment</select></td>
2420                 </tr>
2421                </table>
2422               </td>
2423               </tr>
2424             </table>
2425           </td>
2426           <td width="30%">
2427             <table width="100%">
2428               <tr>
2429                 <th align="right" nowrap="true">|
2430     . $locale->text('Updated') . qq|</th>
2431                 $button1
2432               </tr>
2433               <tr>
2434                 <th align="right" nowrap="true">| . $locale->text('List Price') . qq|</th>
2435                 <td><input name=listprice size=11 value=$form->{listprice}></td>
2436               </tr>
2437               <tr>
2438                 <th align="right" nowrap="true">| . $locale->text('Sell Price') . qq|</th>
2439                 <td><input name=sellprice size=11 value=$form->{sellprice}></td>
2440               </tr>
2441               $lastcost
2442               <tr>
2443                 <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
2444                 <td>$unit_select</td>
2445               </tr>
2446               $weight
2447               $rop
2448               $bin
2449               $notdiscountable
2450               $vegv
2451               $shop
2452               $obsolete
2453             </table>
2454           </td>
2455         </tr>
2456       </table>
2457     </td>
2458   </tr>
2459   $imagelinks
2460
2461 $jsscript
2462 |;
2463   $lxdebug->leave_sub();
2464 }
2465
2466 sub form_footer {
2467   $lxdebug->enter_sub();
2468
2469   if ($form->{item} eq "assembly") {
2470
2471     print qq|
2472         <tr>
2473           <td>
2474             <table width="100%">
2475               <tr>
2476                 <th colspan=2 align=right>|
2477       . $locale->text('Total') . qq|&nbsp;</th>
2478                 <th align=right>|
2479       . $form->format_amount(\%myconfig, $form->{assemblytotal}, 2) . qq|</th>
2480               </tr>
2481             </table>
2482           </td>
2483         </tr>
2484         <input type=hidden name=assembly_rows value=$form->{assembly_rows}>
2485 |;
2486   }
2487
2488   print qq|
2489       <input type=hidden name=login value=$form->{login}>
2490       <input type=hidden name=password value=$form->{password}>
2491       <input type=hidden name=callback value="$form->{callback}">
2492       <input type=hidden name=previousform value="$form->{previousform}">
2493       <input type=hidden name=taxaccount2 value="$form->{taxaccount2}">
2494       <input type=hidden name=vc value=$form->{vc}>
2495   <tr>
2496     <td><hr size=3 noshade></td>
2497   </tr>
2498 </table>
2499
2500 <br>
2501 <input class=submit type=submit name=action value="|
2502     . $locale->text('Update') . qq|">
2503   |;
2504
2505   unless ($form->{item} eq "service") {
2506     print qq|
2507       <input type=hidden name=makemodel_rows value=$form->{makemodel_rows}>
2508     |;
2509   }
2510
2511   print qq|
2512      <input type=hidden name=price_rows value=$form->{price_rows}>|;
2513
2514   print qq|
2515       <input class=submit type=submit name=action value="|
2516     . $locale->text('Save') . qq|">|;
2517
2518   if ($form->{id}) {
2519
2520     if (!$form->{previousform}) {
2521       print qq|
2522       <input class=submit type=submit name=action value="|
2523         . $locale->text('Save as new') . qq|">|;
2524     }
2525
2526     if ($form->{orphaned}) {
2527       if (!$form->{previousform}) {
2528         if ($form->{item} eq 'assembly') {
2529           if (!$form->{onhand}) {
2530             print qq|
2531       <input class=submit type=submit name=action value="|
2532               . $locale->text('Delete') . qq|">|;
2533           }
2534         } else {
2535           print qq|
2536       <input class=submit type=submit name=action value="|
2537             . $locale->text('Delete') . qq|">|;
2538         }
2539       }
2540     }
2541   }
2542
2543   if (!$form->{previousform}) {
2544     if ($form->{menubar}) {
2545       require "bin/mozilla/menu.pl";
2546       &menubar;
2547     }
2548   }
2549 # button for saving history
2550   if($form->{id} ne "") {
2551         print qq|
2552                 <input type=button class=submit onclick=set_history_window(|
2553                 . $form->{id} 
2554                 . qq|); name=history id=history value=|
2555                 . $locale->text('history') 
2556                 . qq|>|;
2557   }
2558 # /button for saving history
2559   print qq|
2560
2561 </form>
2562
2563 <script type="text/javascript" src="js/wz_tooltip.js"></script>
2564
2565 </body>
2566 </html>
2567 |;
2568
2569   $lxdebug->leave_sub();
2570 }
2571
2572 sub makemodel_row {
2573   $lxdebug->enter_sub();
2574   my ($numrows) = @_;
2575   
2576   print qq|
2577   <tr>
2578     <td>
2579       <table width=100%>
2580         <tr>
2581           <th class="listheading">| . $locale->text('Make') . qq|</th>
2582           <th class="listheading">| . $locale->text('Model') . qq|</th>
2583         </tr>
2584 |;
2585
2586   for my $i (1 .. $numrows) {
2587     $form->{"make_$i"}  =~ s/\"/&quot;/g;
2588     $form->{"model_$i"} =~ s/\"/&quot;/g;
2589     print qq|
2590         <tr>
2591           <td width=50%><input name="make_$i" size=30 value="$form->{"make_$i"}"></td>
2592           <td width=50%><input name="model_$i" size=30 value="$form->{"model_$i"}"></td>
2593         </tr>
2594 |;
2595   }
2596
2597   print qq|
2598       </table>
2599     </td>
2600   </tr>
2601 |;
2602
2603   $lxdebug->leave_sub();
2604 }
2605
2606 sub assembly_row {
2607   $lxdebug->enter_sub();
2608   my ($numrows) = @_;
2609   my (@column_index, %column_data, %column_header);
2610   my ($nochange, $callback, $previousform, $linetotal, $href);
2611
2612   our ($deliverydate); # ToDO: cjeck if this indeed comes from global context
2613
2614   @column_index =
2615     qw(runningnumber qty unit bom partnumber description partsgroup total);
2616
2617   if ($form->{previousform}) {
2618     $nochange     = 1;
2619     @column_index = qw(qty unit bom partnumber description partsgroup total);
2620   } else {
2621
2622     # change callback
2623     $form->{old_callback} = $form->{callback};
2624     $callback             = $form->{callback};
2625     $form->{callback}     = "$form->{script}?action=display_form";
2626
2627     # delete action
2628     map { delete $form->{$_} } qw(action header);
2629
2630     $previousform = "";
2631
2632     # save form variables in a previousform variable
2633     foreach my $key (sort keys %$form) {
2634
2635       # escape ampersands
2636       $form->{$key} =~ s/&/%26/g;
2637       $previousform .= qq|$key=$form->{$key}&|;
2638     }
2639     chop $previousform;
2640     $previousform = $form->escape($form->escape($previousform, 1));
2641     $form->{callback} = $callback;
2642
2643     $form->{assemblytotal} = 0;
2644     $form->{weight}        = 0;
2645
2646   }
2647   $column_header{runningnumber} =
2648     qq|<th nowrap width=5%>| . $locale->text('No.') . qq|</th>|;
2649   $column_header{qty} =
2650     qq|<th align=left nowrap width=10%>| . $locale->text('Qty') . qq|</th>|;
2651   $column_header{unit} =
2652     qq|<th align=left nowrap width=5%>| . $locale->text('Unit') . qq|</th>|;
2653   $column_header{partnumber} =
2654       qq|<th align=left nowrap width=20%>|
2655     . $locale->text('Part Number')
2656     . qq|</th>|;
2657   $column_header{description} =
2658     qq|<th nowrap width=50%>| . $locale->text('Part Description') . qq|</th>|;
2659   $column_header{total} =
2660     qq|<th align=right nowrap>| . $locale->text('Extended') . qq|</th>|;
2661   $column_header{bom}        = qq|<th>| . $locale->text('BOM') . qq|</th>|;
2662   $column_header{partsgroup} = qq|<th>| . $locale->text('Group') . qq|</th>|;
2663
2664   print qq|
2665   <tr class=listheading>
2666     <th class=listheading>| . $locale->text('Individual Items') . qq|</th>
2667   </tr>
2668   <tr>
2669     <td>
2670       <table width=100%>
2671         <tr>
2672 |;
2673
2674   map { print "\n$column_header{$_}" } @column_index;
2675
2676   print qq|
2677         </tr>
2678 |;
2679
2680   for my $i (1 .. $numrows) {
2681     $form->{"partnumber_$i"} =~ s/\"/&quot;/g;
2682
2683     $linetotal =
2684       $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"}, 2);
2685     $form->{assemblytotal} += $linetotal;
2686
2687     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
2688
2689     $linetotal = $form->format_amount(\%myconfig, $linetotal, 2);
2690
2691     if (($i >= 1) && ($i == $numrows)) {
2692
2693       if ($nochange) {
2694         map { $column_data{$_} = qq|<td></td>| }
2695           qw(qty unit partnumber description bom partsgroup);
2696       } else {
2697
2698         map { $column_data{$_} = qq|<td></td>| } qw(runningnumber unit bom);
2699
2700         $column_data{qty} =
2701           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2702         $column_data{partnumber} =
2703           qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}"></td>|;
2704         $column_data{description} =
2705           qq|<td><input name="description_$i" size=40 value="$form->{"description_$i"}"></td>|;
2706         $column_data{partsgroup} =
2707           qq|<td><input name="partsgroup_$i" size=10 value="$form->{"partsgroup_$i"}"></td>|;
2708
2709       }
2710
2711     } else {
2712
2713       if ($form->{previousform}) {
2714         $column_data{partnumber} =
2715           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}">$form->{"partnumber_$i"}</td>|;
2716         $column_data{qty} =
2717           qq|<td align=right><input type=hidden name="qty_$i" value="$form->{"qty_$i"}">$form->{"qty_$i"}</td>|;
2718
2719         $column_data{bom} =
2720           qq|<td align=center><input type=hidden name="bom_$i" value=$form->{"bom_$i"}>|;
2721         $column_data{bom} .= ($form->{"bom_$i"}) ? "x" : "&nbsp;";
2722         $column_data{bom} .= qq|</td>|;
2723
2724         $column_data{partsgroup} =
2725           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2726
2727       } else {
2728         $href =
2729           qq|$form->{script}?action=edit&id=$form->{"id_$i"}&login=$form->{login}&password=$form->{password}&rowcount=$i&previousform=$previousform|;
2730         $column_data{partnumber} =
2731           qq|<td><input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"><a href=$href>$form->{"partnumber_$i"}</a></td>|;
2732         $column_data{runningnumber} =
2733           qq|<td><input name="runningnumber_$i" size=3 value="$i"></td>|;
2734         $column_data{qty} =
2735           qq|<td><input name="qty_$i" size=5 value="$form->{"qty_$i"}"></td>|;
2736
2737         $form->{"bom_$i"} = ($form->{"bom_$i"}) ? "checked" : "";
2738         $column_data{bom} =
2739           qq|<td align=center><input name="bom_$i" type=checkbox class=checkbox value=1 $form->{"bom_$i"}></td>|;
2740
2741         $column_data{partsgroup} =
2742           qq|<td><input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">$form->{"partsgroup_$i"}</td>|;
2743       }
2744
2745       $column_data{unit} =
2746         qq|<td><input type=hidden name="unit_$i" value="$form->{"unit_$i"}">$form->{"unit_$i"}</td>|;
2747       $column_data{description} =
2748         qq|<td><input type=hidden name="description_$i" value="$form->{"description_$i"}">$form->{"description_$i"}</td>|;
2749     }
2750
2751     $column_data{total} = qq|<td align=right>$linetotal</td>|;
2752
2753     $column_data{deliverydate} = qq|<td align=right>$deliverydate</td>|;
2754
2755     print qq|
2756         <tr>|;
2757
2758     map { print "\n$column_data{$_}" } @column_index;
2759
2760     print qq|
2761         </tr>
2762   <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2763   <input type=hidden name="sellprice_$i" value=$form->{"sellprice_$i"}>
2764   <input type=hidden name="weight_$i" value=$form->{"weight_$i"}>
2765 |;
2766   }
2767
2768   print qq|
2769       </table>
2770     </td>
2771   </tr>
2772 |;
2773
2774   $lxdebug->leave_sub();
2775 }
2776
2777 sub update {
2778   $lxdebug->enter_sub();
2779
2780   if ($form->{item} eq "assembly") {
2781     my $i = $form->{assembly_rows};
2782
2783     # if last row is empty check the form otherwise retrieve item
2784     if (   ($form->{"partnumber_$i"} eq "")
2785         && ($form->{"description_$i"} eq "")
2786         && ($form->{"partsgroup_$i"}  eq "")) {
2787
2788       &check_form;
2789
2790     } else {
2791
2792       IC->assembly_item(\%myconfig, \%$form);
2793
2794       my $rows = scalar @{ $form->{item_list} };
2795
2796       if ($rows) {
2797         $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2798
2799         if ($rows > 1) {
2800           $form->{makemodel_rows}--;
2801           &select_item;
2802           exit;
2803         } else {
2804           map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g }
2805             qw(partnumber description unit partsgroup);
2806           map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
2807             keys %{ $form->{item_list}[0] };
2808           $form->{"runningnumber_$i"} = $form->{assembly_rows};
2809           $form->{assembly_rows}++;
2810
2811           &check_form;
2812
2813         }
2814
2815       } else {
2816
2817         $form->{rowcount} = $i;
2818         $form->{assembly_rows}++;
2819
2820         &new_item;
2821
2822       }
2823     }
2824
2825   } elsif (($form->{item} eq 'part') || ($form->{item} eq 'service')) {
2826     &check_form;
2827   }
2828
2829   $lxdebug->leave_sub();
2830 }
2831
2832 sub save {
2833   $lxdebug->enter_sub();
2834
2835   my ($parts_id, %newform, $previousform, $amount, $callback);
2836
2837   # check if there is a part number - commented out, cause there is an automatic allocation of numbers
2838   # $form->isblank("partnumber", $locale->text(ucfirst $form->{item}." Part Number missing!"));
2839
2840   # check if there is a description
2841   $form->isblank("description", $locale->text("Part Description missing!"));
2842
2843   if ($form->{obsolete}) {
2844     $form->error(
2845       $locale->text(
2846         "Inventory quantity must be zero before you can set this $form->{item} obsolete!"
2847       ))
2848       if ($form->{onhand} * 1);
2849   }
2850
2851   if (!$form->{buchungsgruppen_id}) {
2852     $form->error($locale->text("Parts must have an entry type.") . " " . 
2853      $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.") 
2854     );
2855   }
2856
2857   $form->error($locale->text('Description must not be empty!')) unless $form->{description};
2858   $form->error($locale->text('Partnumber must not be set to empty!')) if $form->{id} && !$form->{partnumber};
2859
2860   # expand dynamic strings
2861   # $locale->text('Inventory quantity must be zero before you can set this part obsolete!')
2862   # $locale->text('Inventory quantity must be zero before you can set this assembly obsolete!')
2863   # $locale->text('Part Number missing!')
2864   # $locale->text('Service Number missing!')
2865   # $locale->text('Assembly Number missing!')
2866
2867   # save part
2868   $lxdebug->message($LXDebug::DEBUG1, "ic.pl: sellprice in save = $form->{sellprice}\n");
2869   if (IC->save(\%myconfig, \%$form) == 3) {
2870     $form->error($locale->text('Partnumber not unique!'));
2871   }
2872   # saving the history
2873   if(!exists $form->{addition}) {
2874     $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2875         $form->{addition} = "SAVED";
2876         $form->save_history($form->dbconnect(\%myconfig));
2877   }
2878   # /saving the history
2879   $parts_id = $form->{id};
2880
2881   my $i;
2882   # load previous variables
2883   if ($form->{previousform}) {
2884
2885     # save the new form variables before splitting previousform
2886     map { $newform{$_} = $form->{$_} } keys %$form;
2887
2888     $previousform = $form->unescape($form->{previousform});
2889
2890     # don't trample on previous variables
2891     map { delete $form->{$_} } keys %newform;
2892
2893     # now take it apart and restore original values
2894     foreach my $item (split /&/, $previousform) {
2895       my ($key, $value) = split /=/, $item, 2;
2896       $value =~ s/%26/&/g;
2897       $form->{$key} = $value;
2898     }
2899     $form->{taxaccounts} = $newform{taxaccount2};
2900
2901     if ($form->{item} eq 'assembly') {
2902
2903       # undo number formatting
2904       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2905         qw(weight listprice sellprice rop);
2906
2907       $form->{assembly_rows}--;
2908       $i = $newform{rowcount};
2909       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2910
2911       $form->{sellprice} -= $form->{"sellprice_$i"} * $form->{"qty_$i"};
2912       $form->{weight}    -= $form->{"weight_$i"} * $form->{"qty_$i"};
2913
2914       # change/add values for assembly item
2915       map { $form->{"${_}_$i"} = $newform{$_} }
2916         qw(partnumber description bin unit weight listprice sellprice inventory_accno income_accno expense_accno);
2917
2918       $form->{sellprice} += $form->{"sellprice_$i"} * $form->{"qty_$i"};
2919       $form->{weight}    += $form->{"weight_$i"} * $form->{"qty_$i"};
2920
2921     } else {
2922
2923       # set values for last invoice/order item
2924       $i = $form->{rowcount};
2925       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
2926
2927       map { $form->{"${_}_$i"} = $newform{$_} }
2928         qw(partnumber description bin unit listprice inventory_accno income_accno expense_accno sellprice);
2929       $form->{"sellprice_$i"} = $newform{lastcost} if ($form->{vendor_id});
2930       if ($form->{exchangerate} != 0) {
2931         $form->{"sellprice_$i"} /= $form->{exchangerate};
2932       }
2933       $lxdebug->message($LXDebug::DEBUG1, qq|sellprice_$i in previousform 2 = | . $form->{"sellprice_$i"} . qq|\n|);
2934       map { $form->{"taxaccounts_$i"} .= "$_ " } split / /,
2935         $newform{taxaccount};
2936       chop $form->{"taxaccounts_$i"};
2937       foreach my $item (qw(description rate taxnumber)) {
2938         my $index = $form->{"taxaccounts_$i"} . "_$item";
2939         $form->{$index} = $newform{$index};
2940       }
2941
2942       # credit remaining calculation
2943       $amount =
2944         $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
2945         $form->{"qty_$i"};
2946       map { $form->{"${_}_base"} += $amount }
2947         (split / /, $form->{"taxaccounts_$i"});
2948       map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
2949         split / /, $form->{"taxaccounts_$i"}
2950         if !$form->{taxincluded};
2951
2952       $form->{creditremaining} -= $amount;
2953
2954       # redo number formatting, because invoice parse them!
2955       $i = $form->{rowcount};
2956       map {
2957         $form->{"${_}_$i"} =
2958           $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2959       } qw(weight listprice sellprice rop);
2960     }
2961
2962     $form->{"id_$i"} = $parts_id;
2963     delete $form->{action};
2964
2965     # restore original callback
2966     $callback = $form->unescape($form->{callback});
2967     $form->{callback} = $form->unescape($form->{old_callback});
2968     delete $form->{old_callback};
2969
2970     $form->{makemodel_rows}--;
2971
2972     # put callback together
2973     foreach my $key (keys %$form) {
2974
2975       # do single escape for Apache 2.0
2976       my $value = $form->escape($form->{$key}, 1);
2977       $callback .= qq|&$key=$value|;
2978     }
2979     $form->{callback} = $callback;
2980   }
2981   $lxdebug->message($LXDebug::DEBUG1, qq|ic.pl: sellprice_$i nach sub save = | . $form->{"sellprice_$i"} . qq|\n|);
2982
2983   # redirect
2984   $form->redirect;
2985
2986   $lxdebug->leave_sub();
2987 }
2988
2989 sub save_as_new {
2990   $lxdebug->enter_sub();
2991
2992   # saving the history
2993   if(!exists $form->{addition}) {
2994     $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
2995         $form->{addition} = "SAVED AS NEW";
2996         $form->save_history($form->dbconnect(\%myconfig));
2997   }
2998   # /saving the history
2999   $form->{id} = 0;
3000   if ($form->{"original_partnumber"} &&
3001       ($form->{"partnumber"} eq $form->{"original_partnumber"})) {
3002     $form->{partnumber} = "";
3003   }
3004   &save;
3005   $lxdebug->leave_sub();
3006 }
3007
3008 sub delete {
3009   $lxdebug->enter_sub();
3010   # saving the history
3011   if(!exists $form->{addition}) {
3012     $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
3013         $form->{addition} = "DELETED";
3014         $form->save_history($form->dbconnect(\%myconfig));
3015   }
3016   # /saving the history
3017   my $rc = IC->delete(\%myconfig, \%$form);
3018
3019   # redirect
3020   $form->redirect($locale->text('Item deleted!')) if ($rc > 0);
3021   $form->error($locale->text('Cannot delete item!'));
3022
3023   $lxdebug->leave_sub();
3024 }
3025
3026 sub price_row {
3027   $lxdebug->enter_sub();
3028
3029   my ($numrows) = @_;
3030
3031   print qq|
3032   <tr>
3033     <td>
3034       <table width=100%>
3035         <tr>
3036           <th class="listheading">| . $locale->text('Preisklasse') . qq|</th>
3037           <th class="listheading">| . $locale->text('Preis') . qq|</th>
3038         </tr>
3039 |;
3040   for my $i (1 .. $numrows) {
3041     print qq|
3042         <tr>
3043           <td width=50%><input type=hidden name="pricegroup_$i" size=30  value="$form->{"pricegroup_$i"}">$form->{"pricegroup_$i"}</td>
3044           <td width=50%><input name="price_$i" size=11 value="$form->{"price_$i"}"></td>
3045           <input type=hidden name="pricegroup_id_$i" value="$form->{"pricegroup_id_$i"}">
3046         </tr>
3047 |;
3048   }
3049
3050   print qq|
3051       </table>
3052     </td>
3053   </tr>
3054 |;
3055
3056   $lxdebug->leave_sub();
3057 }
3058
3059 sub parts_language_selection {
3060   $lxdebug->enter_sub();
3061
3062   our ($onload);
3063
3064   my $languages = IC->retrieve_languages(\%myconfig, $form);
3065
3066
3067   my $callback = "$form->{script}?action=parts_language_selection&";
3068   map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
3069       (qw(login password name input_name), grep({ /^[fl]_/ } keys %$form)));
3070
3071   my @header_sort = qw(name longdescription);
3072   my %header_title = ( "name" => $locale->text("Name"),
3073                        "longdescription" => $locale->text("Long Description"),
3074                        );
3075
3076   my @header =
3077     map(+{ "column_title" => $header_title{$_},
3078            "column" => $_,
3079            "callback" => $callback,
3080          },
3081         @header_sort);
3082
3083   $form->{"title"} = $locale->text("Language Values");
3084   $form->header();
3085   print($form->parse_html_template("ic/parts_language_selection", { "HEADER" => \@header,
3086                                                                    "LANGUAGES" => $languages,
3087                                                                    "onload" => $onload }));
3088
3089   $lxdebug->leave_sub();
3090 }
3091
3092 sub continue { call_sub($form->{"nextsub"}); }