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