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