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