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