f9907cbf2855d00e5eec31d3a090d045f69360c9
[kivitendo-erp.git] / bin / mozilla / oe.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) 1998-2003
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 # Order entry module
31 # Quotation module
32 #======================================================================
33
34 use SL::OE;
35 use SL::IR;
36 use SL::IS;
37 use SL::PE;
38
39 require "$form->{path}/io.pl";
40 require "$form->{path}/arap.pl";
41
42 1;
43
44 # end of main
45
46 sub add {
47   $lxdebug->enter_sub();
48
49   if ($form->{type} eq 'purchase_order') {
50     $form->{title} = $locale->text('Add Purchase Order');
51     $form->{vc}    = 'vendor';
52   }
53   if ($form->{type} eq 'sales_order') {
54     $form->{title} = $locale->text('Add Sales Order');
55     $form->{vc}    = 'customer';
56   }
57   if ($form->{type} eq 'request_quotation') {
58     $form->{title} = $locale->text('Add Request for Quotation');
59     $form->{vc}    = 'vendor';
60   }
61   if ($form->{type} eq 'sales_quotation') {
62     $form->{title} = $locale->text('Add Quotation');
63     $form->{vc}    = 'customer';
64   }
65
66   $form->{callback} =
67     "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
68     unless $form->{callback};
69
70   &order_links;
71   &prepare_order;
72   &display_form;
73
74   $lxdebug->leave_sub();
75 }
76
77 sub edit {
78   $lxdebug->enter_sub();
79
80   # editing without stuff to edit? try adding it first
81   if ($form->{rowcount}) {
82     map {$id++ if $form->{"id_$_"}} (1 .. $form->{rowcount});
83     if (!$id) {
84       # reset rowcount
85       undef $form->{rowcount};
86       &add;
87       return;
88     }
89   } else {
90     if (!$form->{id}) {
91       &add;
92       return;
93     }
94   }
95
96   if ($form->{type} eq 'purchase_order') {
97     $form->{title}   = $locale->text('Edit Purchase Order');
98     $form->{heading} = $locale->text('Purchase Order');
99     $form->{vc}      = 'vendor';
100   }
101   if ($form->{type} eq 'sales_order') {
102     $form->{title}   = $locale->text('Edit Sales Order');
103     $form->{heading} = $locale->text('Sales Order');
104     $form->{vc}      = 'customer';
105   }
106   if ($form->{type} eq 'request_quotation') {
107     $form->{title}   = $locale->text('Edit Request for Quotation');
108     $form->{heading} = $locale->text('Request for Quotation');
109     $form->{vc}      = 'vendor';
110   }
111   if ($form->{type} eq 'sales_quotation') {
112     $form->{title}   = $locale->text('Edit Quotation');
113     $form->{heading} = $locale->text('Quotation');
114     $form->{vc}      = 'customer';
115   }
116
117   &order_links;
118   &prepare_order;
119   &display_form;
120
121   $lxdebug->leave_sub();
122 }
123
124 sub order_links {
125   $lxdebug->enter_sub();
126
127   # get customer/vendor
128   $form->all_vc(\%myconfig, $form->{vc},
129                 ($form->{vc} eq 'customer') ? "AR" : "AP");
130
131   # retrieve order/quotation
132   $form->{webdav} = $webdav;
133
134
135   # set jscalendar
136   $form->{jscalendar} = $jscalendar;
137
138   OE->retrieve(\%myconfig, \%$form);
139
140   # if multiple rowcounts (== collective order) then check if the
141   # there were more than one customer (in that case OE::retrieve removes 
142   # the content from the field)
143   if ($form->{rowcount} && $form->{type} eq 'sales_order' && defined $form->{customer} && $form->{customer} eq '') {
144 #    $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
145     $form->error($locale->text('Collective Orders only work for orders from one customer!'));
146   }
147
148   $taxincluded = $form->{taxincluded};
149   $form->{shipto} = 1 if $form->{id};
150
151   if ($form->{"all_$form->{vc}"}) {
152     unless ($form->{"$form->{vc}_id"}) {
153       $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
154     }
155   }
156
157   $cp_id    = $form->{cp_id};
158   $intnotes = $form->{intnotes};
159
160   # get customer / vendor
161   if ($form->{type} =~ /(purchase_order|request_quotation|receive_order)/) {
162     IR->get_vendor(\%myconfig, \%$form);
163   }
164   if ($form->{type} =~ /(sales|ship)_(order|quotation)/) {
165     IS->get_customer(\%myconfig, \%$form);
166   }
167   $form->{cp_id} = $cp_id;
168
169   $form->{intnotes} = $intnotes;
170   ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
171   $form->{"old$form->{vc}"} =
172     qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
173
174   # build the popup menus
175   if (@{ $form->{"all_$form->{vc}"} }) {
176     $form->{ $form->{vc} } =
177       qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
178     map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
179       (@{ $form->{"all_$form->{vc}"} });
180   }
181
182   # currencies
183   @curr = split /:/, $form->{currencies};
184   chomp $curr[0];
185   $form->{defaultcurrency} = $curr[0];
186   $form->{currency}        = $form->{defaultcurrency} unless $form->{currency};
187
188   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
189
190   $form->{taxincluded} = $taxincluded if ($form->{id});
191
192   # departments
193   if (@{ $form->{all_departments} }) {
194     $form->{selectdepartment} = "<option>\n";
195     $form->{department}       = "$form->{department}--$form->{department_id}";
196
197     map {
198       $form->{selectdepartment} .=
199         "<option>$_->{description}--$_->{id}\n"
200     } (@{ $form->{all_departments} });
201   }
202
203   $form->{employee} = "$form->{employee}--$form->{employee_id}";
204
205   # sales staff
206   if (@{ $form->{all_employees} }) {
207     $form->{selectemployee} = "";
208     map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
209       (@{ $form->{all_employees} });
210   }
211
212   # forex
213   $form->{forex} = $form->{exchangerate};
214
215   $lxdebug->leave_sub();
216 }
217
218 sub prepare_order {
219   $lxdebug->enter_sub();
220   $form->{format}   = "pdf";
221   $form->{media}    = "screen";
222   $form->{formname} = $form->{type};
223
224     map { $form->{$_} =~ s/\"/&quot;/g }
225       qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact);
226
227     foreach $ref (@{ $form->{form_details} }) {
228       $form->{rowcount} = ++$i;
229
230       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
231     }
232     for my $i (1 .. $form->{rowcount}) {
233       if ($form->{id}) {
234         $form->{"discount_$i"} =
235           $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
236       } else {
237         $form->{"discount_$i"} =
238           $form->format_amount(\%myconfig, $form->{"discount_$i"});
239       }
240       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);    
241       $dec           = length $dec;
242       $decimalplaces = ($dec > 2) ? $dec : 2;
243
244       # copy reqdate from deliverydate for invoice -> order conversion
245       $form->{"reqdate_$i"} = $form->{"deliverydate_$i"} unless $form->{"reqdate_$i"};
246
247       $form->{"sellprice_$i"} =
248         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
249                             $decimalplaces);
250       
251       (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
252       $dec_qty      = length $dec_qty;
253       $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
254
255       map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
256         qw(partnumber description unit);
257     }
258
259   $lxdebug->leave_sub();
260 }
261
262 sub form_header {
263   $lxdebug->enter_sub();
264
265   $checkedopen   = ($form->{closed}) ? ""        : "checked";
266   $checkedclosed = ($form->{closed}) ? "checked" : "";
267
268   # use JavaScript Calendar or not
269   $form->{jsscript} = $form->{jscalendar};
270   $jsscript = "";
271
272   if ($form->{jsscript}) {
273
274     # with JavaScript Calendar
275     $button1 = qq|
276        <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
277        <td><input type=button name=transdate id="trigger1" value=|
278       . $locale->text('button') . qq|></td>
279       |;
280     $button2 = qq|
281        <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>
282        <td width="4"><input type=button name=reqdate name=reqdate id="trigger2" value=|
283       . $locale->text('button') . qq|></td>
284      |;
285
286     #write Trigger
287     $jsscript =
288       Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
289                           "reqdate", "BL", "trigger2");
290
291   } else {
292
293     # without JavaScript Calendar
294     $button1 = qq|
295                               <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>|;
296     $button2 = qq|
297                               <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>|;
298   }
299
300   if ($form->{id}) {
301     $openclosed = qq|
302       <tr>
303         <td colspan=2 align=center>
304           <table>
305             <tr>
306               <th nowrap><input name=closed type=radio class=radio value=0 $checkedopen> |
307       . $locale->text('Open') . qq|</th>
308               <th nowrap><input name=closed type=radio class=radio value=1 $checkedclosed> |
309       . $locale->text('Closed') . qq|</th>
310             </tr>
311           </table>
312         </td>
313       </tr>
314 |;
315   }
316
317   # set option selected
318   foreach $item ($form->{vc}, currency, department, employee, contact) {
319     $form->{"select$item"} =~ s/ selected//;
320     $form->{"select$item"} =~
321       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
322   }
323
324   #build contacts
325   if ($form->{all_contacts}) {
326
327     $form->{selectcontact} = "";
328     foreach $item (@{ $form->{all_contacts} }) {
329       if ($form->{cp_id} == $item->{cp_id}) {
330         $form->{selectcontact} .=
331           "<option selected>$item->{cp_name}--$item->{cp_id}";
332       } else {
333         $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
334       }
335     }
336   }
337
338   $form->{exchangerate} =
339     $form->format_amount(\%myconfig, $form->{exchangerate});
340
341   $form->{creditlimit} =
342     $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
343   $form->{creditremaining} =
344     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
345
346   $contact =
347     ($form->{selectcontact})
348     ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
349     : qq|<input name=contact value="$form->{contact}" size=35>|;
350
351   $exchangerate = qq|
352 <input type=hidden name=forex value=$form->{forex}>
353 |;
354
355   if ($form->{currency} ne $form->{defaultcurrency}) {
356     if ($form->{forex}) {
357       $exchangerate .=
358           qq|<th align=right>|
359         . $locale->text('Exchangerate')
360         . qq|</th><td>$form->{exchangerate}</td>
361       <input type=hidden name=exchangerate value=$form->{exchangerate}>
362 |;
363     } else {
364       $exchangerate .=
365           qq|<th align=right>|
366         . $locale->text('Exchangerate')
367         . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
368     }
369   }
370
371   $vclabel = ucfirst $form->{vc};
372   $vclabel = $locale->text($vclabel);
373
374   $terms = qq|
375                     <tr>
376                       <th align=right nowrap>| . $locale->text('Terms: Net') . qq|</th>
377                       <td nowrap><input name=terms size="3" maxlength="3" value=$form->{terms}> |
378     . $locale->text('days') . qq|</td>
379                     </tr>
380 |;
381
382   if ($form->{business}) {
383     $business = qq|
384               <tr>
385                 <th align=right>| . $locale->text('Business') . qq|</th>
386                 <td>$form->{business}</td>
387                 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
388                 <td>|
389       . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
390       . qq| %</td>
391               </tr>
392 |;
393   }
394
395   if ($form->{type} !~ /_quotation$/) {
396     $ordnumber = qq|
397               <tr>
398                 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
399                 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
400               </tr>
401               <tr>
402                 <th width=70% align=right nowrap>|
403       . $locale->text('Quotation Number') . qq|</th>
404                 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
405               </tr>
406               <tr>
407                 <th width=70% align=right nowrap>|
408       . $locale->text('Customer Order Number') . qq|</th>
409                 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
410               </tr>
411               <tr>
412                 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
413                 $button1
414
415               </tr>
416               <tr>
417                 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
418                 $button2
419               </tr>
420 |;
421
422     $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
423
424     $creditremaining = qq|
425               <tr>
426                 <td></td>
427                 <td colspan=3>
428                   <table>
429                     <tr>
430                       <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
431                       <td>$form->{creditlimit}</td>
432                       <td width=20%></td>
433                       <th nowrap>| . $locale->text('Remaining') . qq|</th>
434                       <td class="plus$n">$form->{creditremaining}</td>
435                     </tr>
436                   </table>
437                 </td>
438               </tr>
439 |;
440   } else {
441     $reqlabel =
442       ($form->{type} eq 'sales_quotation')
443       ? $locale->text('Valid until')
444       : $locale->text('Required by');
445     if ($form->{type} eq 'sales_quotation') {
446       $ordnumber = qq|
447               <tr>
448                 <th width=70% align=right nowrap>|
449         . $locale->text('Quotation Number') . qq|</th>
450                 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
451                 <input type=hidden name=ordnumber value="$form->{ordnumber}">
452               </tr>
453 |;
454     } else {
455       $ordnumber = qq|
456               <tr>
457                 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
458                 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
459                 <input type=hidden name=ordnumber value="$form->{ordnumber}">
460               </tr>
461 |;
462
463       $terms = "";
464     }
465
466     $ordnumber .= qq|
467               <tr>
468                 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
469                 $button1
470               </tr>
471               <tr>
472                 <th align=right nowrap=true>$reqlabel</th>
473                 $button2
474               </tr>
475 |;
476
477   }
478
479   $vc =
480     ($form->{"select$form->{vc}"})
481     ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">|
482     : qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
483
484   $department = qq|
485               <tr>
486                 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
487                 <td colspan=3><select name=department>$form->{selectdepartment}</select>
488                 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
489                 </td>
490               </tr>
491 | if $form->{selectdepartment};
492
493   $employee = qq|
494               <input type=hidden name=employee value="$form->{employee}">
495 |;
496
497   if ($form->{type} eq 'sales_order') {
498     if ($form->{selectemployee}) {
499       $employee = qq|
500     <input type=hidden name=customer_klass value=$form->{customer_klass}>
501               <tr>
502                 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
503                 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
504                 <input type=hidden name=selectemployee value="$form->{selectemployee}">
505                 <td></td>
506               </tr>
507 |;
508     }
509   } else {
510     $employee = qq|
511     <input type=hidden name=customer_klass value=$form->{customer_klass}>
512               <tr>
513                 <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
514                 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
515                 <input type=hidden name=selectemployee value="$form->{selectemployee}">
516                 <td></td>
517               </tr>
518 |;
519   }
520
521   $form->header;
522
523   print qq|
524 <body>
525
526 <form method=post action=$form->{script}>
527
528 <input type=hidden name=id value=$form->{id}>
529
530 <input type=hidden name=type value=$form->{type}>
531 <input type=hidden name=formname value=$form->{formname}>
532 <input type=hidden name=media value=$form->{media}>
533 <input type=hidden name=format value=$form->{format}>
534
535 <input type=hidden name=queued value="$form->{queued}">
536 <input type=hidden name=printed value="$form->{printed}">
537 <input type=hidden name=emailed value="$form->{emailed}">
538
539 <input type=hidden name=vc value=$form->{vc}>
540
541 <input type=hidden name=title value="$form->{title}">
542
543 <input type=hidden name=discount value=$form->{discount}>
544 <input type=hidden name=creditlimit value=$form->{creditlimit}>
545 <input type=hidden name=creditremaining value=$form->{creditremaining}>
546
547 <input type=hidden name=tradediscount value=$form->{tradediscount}>
548 <input type=hidden name=business value=$form->{business}>
549 <input type=hidden name=webdav value=$webdav>
550
551 <table width=100%>
552   <tr class=listtop>
553     <th class=listtop>$form->{title}</th>
554   </tr>
555   <tr height="5"></tr>
556   <tr>
557     <td>
558       <table width="100%">
559         <tr valign=top>
560           <td>
561             <table width=100%>
562               <tr>
563                 <th align=right>$vclabel</th>
564                 <td colspan=3>$vc</td>
565                 <input type=hidden name=$form->{vc}_id value=$form->{"$form->{vc}_id"}>
566                 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
567                 <th align=richt nowrap>|
568     . $locale->text('Contact Person') . qq|</th>
569                 <td colspan=3>$contact</td>
570               </tr>
571               $creditremaining
572               $business
573               $department
574               <tr>
575                 <th align=right>| . $locale->text('Currency') . qq|</th>
576                 <td><select name=currency>$form->{selectcurrency}</select></td>
577                 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
578                 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
579                 $exchangerate
580               </tr>
581               <tr>
582                 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
583                 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
584               </tr>
585               <tr>
586                 <th align=right>| . $locale->text('Ship via') . qq|</th>
587                 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
588               </tr>
589             </table>
590           </td>
591           <td align=right>
592             <table>
593               $openclosed
594               $employee
595               $ordnumber
596               $terms
597             </table>
598           </td>
599         </tr>
600       </table>
601     </td>
602   </tr>
603
604 $jsscript
605
606 <!-- shipto are in hidden variables -->
607
608 <input type=hidden name=shiptoname value="$form->{shiptoname}">
609 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
610 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
611 <input type=hidden name=shiptocity value="$form->{shiptocity}">
612 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
613 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
614 <input type=hidden name=shiptophone value="$form->{shiptophone}">
615 <input type=hidden name=shiptofax value="$form->{shiptofax}">
616 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
617
618 <!-- email variables -->
619 <input type=hidden name=message value="$form->{message}">
620 <input type=hidden name=email value="$form->{email}">
621 <input type=hidden name=subject value="$form->{subject}">
622 <input type=hidden name=cc value="$form->{cc}">
623 <input type=hidden name=bcc value="$form->{bcc}">
624
625 <input type=hidden name=taxpart value="$form->{taxpart}">
626 <input type=hidden name=taxservice value="$form->{taxservice}">
627
628 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
629 |;
630
631   foreach $item (split / /, $form->{taxaccounts}) {
632     print qq|
633 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
634 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
635 |;
636   }
637   $lxdebug->leave_sub();
638 }
639
640 sub form_footer {
641   $lxdebug->enter_sub();
642
643   $form->{invtotal} = $form->{invsubtotal};
644
645   if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
646     $rows = 2;
647   }
648   if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
649     $introws = 2;
650   }
651   $rows = ($rows > $introws) ? $rows : $introws;
652   $notes =
653     qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
654   $intnotes =
655     qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
656
657   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
658
659   $taxincluded = "";
660   if ($form->{taxaccounts}) {
661     $taxincluded = qq|
662               <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
663       . $locale->text('Tax Included') . qq|</b><br><br>
664 |;
665   }
666
667   if (!$form->{taxincluded}) {
668
669     foreach $item (split / /, $form->{taxaccounts}) {
670       if ($form->{"${item}_base"}) {
671         $form->{invtotal} += $form->{"${item}_total"} =
672           $form->round_amount(
673                              $form->{"${item}_base"} * $form->{"${item}_rate"},
674                              2);
675         $form->{"${item}_total"} =
676           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
677
678         $tax .= qq|
679               <tr>
680                 <th align=right>$form->{"${item}_description"}</th>
681                 <td align=right>$form->{"${item}_total"}</td>
682               </tr>
683 |;
684       }
685     }
686
687     $form->{invsubtotal} =
688       $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
689
690     $subtotal = qq|
691               <tr>
692                 <th align=right>| . $locale->text('Subtotal') . qq|</th>
693                 <td align=right>$form->{invsubtotal}</td>
694               </tr>
695 |;
696
697   }
698
699   if ($form->{taxincluded}) {
700     foreach $item (split / /, $form->{taxaccounts}) {
701       if ($form->{"${item}_base"}) {
702         $form->{"${item}_total"} =
703           $form->round_amount(
704                            ($form->{"${item}_base"} * $form->{"${item}_rate"} /
705                               (1 + $form->{"${item}_rate"})
706                            ),
707                            2);
708         $form->{"${item}_netto"} =
709           $form->round_amount(
710                           ($form->{"${item}_base"} - $form->{"${item}_total"}),
711                           2);
712         $form->{"${item}_total"} =
713           $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
714         $form->{"${item}_netto"} =
715           $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
716
717         $tax .= qq|
718               <tr>
719                 <th align=right>Enthaltene $form->{"${item}_description"}</th>
720                 <td align=right>$form->{"${item}_total"}</td>
721               </tr>
722               <tr>
723                 <th align=right>Nettobetrag</th>
724                 <td align=right>$form->{"${item}_netto"}</td>
725               </tr>
726 |;
727       }
728     }
729
730   }
731
732   $form->{oldinvtotal} = $form->{invtotal};
733   $form->{invtotal}    =
734     $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
735
736   print qq|
737   <tr>
738     <td>
739       <table width=100%>
740         <tr valign=bottom>
741           <td>
742             <table>
743               <tr>
744                 <th align=left>| . $locale->text('Notes') . qq|</th>
745                 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
746               </tr>
747               <tr valign=top>
748                 <td>$notes</td>
749                 <td>$intnotes</td>
750               </tr>
751             </table>
752           </td>
753           <td align=right width=100%>
754             $taxincluded
755             <table width=100%>
756               $subtotal
757               $tax
758               <tr>
759                 <th align=right>| . $locale->text('Total') . qq|</th>
760                 <td align=right>$form->{invtotal}</td>
761               </tr>
762             </table>
763           </td>
764         </tr>
765       </table>
766     </td>
767   </tr>
768 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
769 <input type=hidden name=oldtotalpaid value=$totalpaid>
770   <tr>
771     <td><hr size=3 noshade></td>
772   </tr>
773 |;
774
775   if ($webdav) {
776     $webdav_list = qq|
777
778   <tr>
779     <th class=listtop align=left>Dokumente im Webdav-Repository</th>
780   </tr>
781     <table width=100%>
782       <td align=left width=30%><b>Dateiname</b></td>
783       <td align=left width=70%><b>Webdavlink</b></td>
784 |;
785     foreach $file (keys %{ $form->{WEBDAV} }) {
786       $webdav_list .= qq|
787       <tr>
788         <td align=left>$file</td>
789         <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
790       </tr>
791 |;
792     }
793     $webdav_list .= qq|
794     </table>
795   </tr>
796   <tr>
797     <td><hr size=3 noshade></td>
798   </tr>
799 |;
800
801     print $webdav_list;
802   }
803   print qq|
804 <input type=hidden name=jscalendar value=$form->{jscalendar}>
805 |;
806   print qq|
807   <tr>
808     <td>
809 |;
810   &print_options;
811
812   print qq|
813     </td>
814   </tr>
815 </table>
816
817 Bearbeiten des $form->{heading}<br>
818 <input class=submit type=submit name=action value="|
819     . $locale->text('Update') . qq|">
820 <input class=submit type=submit name=action value="|
821     . $locale->text('Ship to') . qq|">
822 <input class=submit type=submit name=action value="|
823     . $locale->text('Print') . qq|">
824 <input class=submit type=submit name=action value="|
825     . $locale->text('E-mail') . qq|">
826 <input class=submit type=submit name=action value="|
827     . $locale->text('Save') . qq|">
828 |;
829
830   if ($form->{id}) {
831     print qq|
832 <br>Workflow  $form->{heading}<br>
833 <input class=submit type=submit name=action value="|
834       . $locale->text('Save as new') . qq|">
835 <input class=submit type=submit name=action value="|
836       . $locale->text('Delete') . qq|">|;
837     if ($form->{type} =~ /sales_quotation$/) {
838       print qq|
839 <input class=submit type=submit name=action value="|
840         . $locale->text('Sales Order') . qq|">|;
841     }
842     if ($form->{type} =~ /request_quotation$/) {
843       print qq|
844 <input class=submit type=submit name=action value="|
845         . $locale->text('Purchase Order') . qq|">|;
846     }
847     print qq|
848 <input class=submit type=submit name=action value="|
849       . $locale->text('Invoice') . qq|">
850 |;
851
852     if ($form->{type} =~ /sales_order$/) {
853       print qq|
854 <br>$form->{heading} als neue Vorlage verwenden f&uuml;r<br>
855 <input class=submit type=submit name=action value="|
856         . $locale->text('Purchase Order') . qq|">
857 <input class=submit type=submit name=action value="|
858         . $locale->text('Quotation') . qq|">
859 |;
860
861     } elsif ($form->{type} =~ /purchase_order$/) {
862       print qq|
863 <br>$form->{heading} als neue Vorlage verwenden f&uuml;r<br>
864 <input class=submit type=submit name=action value="|
865         . $locale->text('Sales Order') . qq|">
866 <input class=submit type=submit name=action value="|
867         . $locale->text('Quotation') . qq|">
868 |;
869
870     } else {
871       print qq|
872 <br>$form->{heading} als neue Vorlage verwenden f&uuml;r<br>
873 <input class=submit type=submit name=action value="|
874         . $locale->text('Order') . qq|">
875 |;
876     }
877   } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount}) {
878     print qq|
879 <br>Workflow  $form->{heading}<br>
880 <input class=submit type=submit name=action value="|
881       . $locale->text('Save as new') . qq|">
882 <input class=submit type=submit name=action value="|
883       . $locale->text('Invoice') . qq|">
884 |;
885   }
886   
887
888   if ($form->{menubar}) {
889     require "$form->{path}/menu.pl";
890     &menubar;
891   }
892
893   print qq|
894
895 <input type=hidden name=rowcount value=$form->{rowcount}>
896
897 <input name=callback type=hidden value="$form->{callback}">
898
899 <input type=hidden name=path value=$form->{path}>
900 <input type=hidden name=login value=$form->{login}>
901 <input type=hidden name=password value=$form->{password}>
902
903 </form>
904
905 </body>
906 </html>
907 |;
908   $lxdebug->leave_sub();
909 }
910
911 sub update {
912   $lxdebug->enter_sub();
913
914   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
915     qw(exchangerate creditlimit creditremaining);
916
917   &check_name($form->{vc});
918
919   &check_project;
920
921   $buysell              = 'buy';
922   $buysell              = 'sell' if ($form->{vc} eq 'vendor');
923   $form->{exchangerate} = $exchangerate
924     if (
925         $form->{forex} = (
926                   $exchangerate =
927                     $form->check_exchangerate(
928                     \%myconfig, $form->{currency}, $form->{transdate}, $buysell
929                     )));
930
931   # for pricegroups
932   $i = $form->{rowcount};
933
934   $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
935
936   if (   ($form->{"partnumber_$i"} eq "")
937       && ($form->{"description_$i"} eq "")
938       && ($form->{"partsgroup_$i"}  eq "")) {
939
940     $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
941     &check_form;
942
943       } else {
944
945     if (   $form->{type} eq 'purchase_order'
946         || $form->{type} eq 'request_quotation') {
947       IR->retrieve_item(\%myconfig, \%$form);
948     }
949     if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
950       IS->retrieve_item(\%myconfig, \%$form);
951     }
952
953     my $rows = scalar @{ $form->{item_list} };
954
955     $form->{"discount_$i"} =
956       $form->format_amount(\%myconfig, $form->{discount} * 100);
957
958     if ($rows) {
959       $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
960
961       if ($rows > 1) {
962
963         &select_item;
964         exit;
965
966       } else {
967
968         $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
969
970         map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g }
971           qw(partnumber description unit);
972         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
973           keys %{ $form->{item_list}[0] };
974
975         $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
976
977         ($dec) = ($s =~ /\.(\d+)/);
978         $dec           = length $dec;
979         $decimalplaces = ($dec > 2) ? $dec : 2;
980
981         if ($sellprice) {
982           $form->{"sellprice_$i"} = $sellprice;
983         } else {
984
985           $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
986           # if there is an exchange rate adjust sellprice
987           $form->{"sellprice_$i"} /= $exchangerate;
988         }
989
990         $amount =
991           $form->{"sellprice_$i"} * $form->{"qty_$i"} *
992           (1 - $form->{"discount_$i"} / 100);
993         map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
994         map { $form->{"${_}_base"} += $amount }
995           (split / /, $form->{"taxaccounts_$i"});
996         map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
997           split / /, $form->{taxaccounts}
998           if !$form->{taxincluded};
999
1000         $form->{creditremaining} -= $amount;
1001
1002         $form->{"sellprice_$i"} =
1003           $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1004                                $decimalplaces);
1005         $form->{"qty_$i"} =
1006           $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1007
1008         # get pricegroups for parts
1009         IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1010
1011         # build up html code for prices_$i
1012         &set_pricegroup($i);
1013       }
1014
1015       &display_form;
1016
1017     } else {
1018
1019       # ok, so this is a new part
1020       # ask if it is a part or service item
1021
1022       if (   $form->{"partsgroup_$i"}
1023           && ($form->{"partsnumber_$i"} eq "")
1024           && ($form->{"description_$i"} eq "")) {
1025         $form->{rowcount}--;
1026         $form->{"discount_$i"} = "";
1027         &display_form;
1028           } else {
1029
1030         $form->{"id_$i"}   = 0;
1031         $form->{"unit_$i"} = $locale->text('ea');
1032
1033         &new_item;
1034
1035       }
1036     }
1037   }
1038
1039
1040   $lxdebug->leave_sub();
1041 }
1042
1043 sub search {
1044   $lxdebug->enter_sub();
1045
1046   if ($form->{type} eq 'purchase_order') {
1047     $form->{title} = $locale->text('Purchase Orders');
1048     $form->{vc}    = 'vendor';
1049     $ordlabel      = $locale->text('Order Number');
1050     $ordnumber     = 'ordnumber';
1051     $employee      = $locale->text('Employee');
1052   }
1053   if ($form->{type} eq 'request_quotation') {
1054     $form->{title} = $locale->text('Request for Quotations');
1055     $form->{vc}    = 'vendor';
1056     $ordlabel      = $locale->text('RFQ Number');
1057     $ordnumber     = 'quonumber';
1058     $employee      = $locale->text('Employee');
1059   }
1060   if ($form->{type} eq 'receive_order') {
1061     $form->{title} = $locale->text('Receive Merchandise');
1062     $form->{vc}    = 'vendor';
1063     $ordlabel      = $locale->text('Order Number');
1064     $ordnumber     = 'ordnumber';
1065     $employee      = $locale->text('Employee');
1066   }
1067   if ($form->{type} eq 'sales_order') {
1068     $form->{title} = $locale->text('Sales Orders');
1069     $form->{vc}    = 'customer';
1070     $ordlabel      = $locale->text('Order Number');
1071     $ordnumber     = 'ordnumber';
1072     $employee      = $locale->text('Salesperson');
1073   }
1074   if ($form->{type} eq 'ship_order') {
1075     $form->{title} = $locale->text('Ship Merchandise');
1076     $form->{vc}    = 'customer';
1077     $ordlabel      = $locale->text('Order Number');
1078     $ordnumber     = 'ordnumber';
1079     $employee      = $locale->text('Salesperson');
1080
1081   }
1082
1083   if ($form->{type} eq 'sales_quotation') {
1084     $form->{title} = $locale->text('Quotations');
1085     $form->{vc}    = 'customer';
1086     $ordlabel      = $locale->text('Quotation Number');
1087     $ordnumber     = 'quonumber';
1088     $employee      = $locale->text('Employee');
1089   }
1090
1091   if ($form->{type} =~ /(ship|receive)_order/) {
1092     OE->get_warehouses(\%myconfig, \%$form);
1093
1094     # warehouse
1095     if (@{ $form->{all_warehouses} }) {
1096       $form->{selectwarehouse} = "<option>\n";
1097       $form->{warehouse}       = qq|$form->{warehouse}--$form->{warehouse_id}|;
1098
1099       map {
1100         $form->{selectwarehouse} .=
1101           "<option>$_->{description}--$_->{id}\n"
1102       } (@{ $form->{all_warehouses} });
1103
1104       $warehouse = qq|
1105               <tr>
1106                 <th align=right>| . $locale->text('Warehouse') . qq|</th>
1107                 <td colspan=3><select name=warehouse>$form->{selectwarehouse}</select></td>
1108                 <input type=hidden name=selectwarehouse value="$form->{selectwarehouse}">
1109               </tr>
1110 |;
1111
1112     }
1113   }
1114
1115   # setup vendor / customer selection
1116   $form->all_vc(\%myconfig, $form->{vc},
1117                 ($form->{vc} eq 'customer') ? "AR" : "AP");
1118
1119   map { $vc .= "<option>$_->{name}--$_->{id}\n" }
1120     @{ $form->{"all_$form->{vc}"} };
1121
1122   $vclabel = ucfirst $form->{vc};
1123   $vclabel = $locale->text($vclabel);
1124
1125   # $locale->text('Vendor')
1126   # $locale->text('Customer')
1127
1128   $vc =
1129     ($vc)
1130     ? qq|<select name=$form->{vc}><option>\n$vc</select>|
1131     : qq|<input name=$form->{vc} size=35>|;
1132
1133   # departments
1134   if (@{ $form->{all_departments} }) {
1135     $form->{selectdepartment} = "<option>\n";
1136
1137     map {
1138       $form->{selectdepartment} .=
1139         "<option>$_->{description}--$_->{id}\n"
1140     } (@{ $form->{all_departments} });
1141   }
1142
1143   $department = qq|
1144         <tr>
1145           <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1146           <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1147         </tr>
1148 | if $form->{selectdepartment};
1149
1150   if ($form->{type} !~ /(ship_order|receive_order)/) {
1151     $openclosed = qq|
1152               <tr>
1153                 <td><input name="open" class=checkbox type=checkbox value=1 checked> |
1154       . $locale->text('Open') . qq|</td>
1155                 <td><input name="closed" class=checkbox type=checkbox value=1 $form->{closed}> |
1156       . $locale->text('Closed') . qq|</td>
1157               </tr>
1158 |;
1159   } else {
1160
1161     $openclosed = qq|
1162                 <input type=hidden name="open" value=1>
1163 |;
1164   }
1165
1166   # use JavaScript Calendar or not
1167   $form->{jsscript} = $jscalendar;
1168   $jsscript = "";
1169   if ($form->{jsscript}) {
1170
1171     # with JavaScript Calendar
1172     $button1 = qq|
1173        <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1174        <input type=button name=transdatefrom id="trigger3" value=|
1175       . $locale->text('button') . qq|></td>
1176       |;
1177     $button2 = qq|
1178        <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1179        <input type=button name=transdateto name=transdateto id="trigger4" value=|
1180       . $locale->text('button') . qq|></td>
1181      |;
1182
1183     #write Trigger
1184     $jsscript =
1185       Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1186                           "transdateto", "BL", "trigger4");
1187   } else {
1188
1189     # without JavaScript Calendar
1190     $button1 = qq|
1191                               <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1192     $button2 = qq|
1193                               <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1194   }
1195
1196   $form->header;
1197
1198   print qq|
1199 <body>
1200
1201 <form method=post action=$form->{script}>
1202
1203 <table width=100%>
1204   <tr>
1205     <th class=listtop>$form->{title}</th>
1206   </tr>
1207   <tr height="5"></tr>
1208   <tr>
1209     <td>
1210       <table>
1211         <tr>
1212           <th align=right>$vclabel</th>
1213           <td colspan=3>$vc</td>
1214         </tr>
1215         $warehouse
1216         $department
1217         <tr>
1218           <th align=right>$ordlabel</th>
1219           <td colspan=3><input name="$ordnumber" size=20></td>
1220         </tr>
1221         <tr>
1222           <th align=right>| . $locale->text('From') . qq|</th>
1223           $button1
1224           <th align=right>| . $locale->text('Bis') . qq|</th>
1225           $button2
1226         </tr>
1227         <input type=hidden name=sort value=transdate>
1228         <tr>
1229           <th align=right>| . $locale->text('Include in Report') . qq|</th>
1230           <td colspan=5>
1231             <table>
1232               $openclosed
1233               <tr>
1234                 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1235                 | . $locale->text('ID') . qq|</td>
1236                 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1237                 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1238     . $locale->text('Date') . qq|</td>
1239                 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1240     . $locale->text('Required by') . qq|</td>
1241               </tr>
1242               <tr>
1243                 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
1244                 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1245                 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1246     . $locale->text('Ship via') . qq|</td>
1247               </tr>
1248               <tr>
1249                 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1250     . $locale->text('Amount') . qq|</td>
1251                 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1252     . $locale->text('Tax') . qq|</td>
1253                 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1254     . $locale->text('Total') . qq|</td>
1255               </tr>
1256               <tr>
1257                 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1258     . $locale->text('Subtotal') . qq|</td>
1259               </tr>
1260             </table>
1261           </td>
1262         </tr>
1263       </table>
1264     </td>
1265   </tr>
1266   <tr><td colspan=4><hr size=3 noshade></td></tr>
1267 </table>
1268
1269 $jsscript
1270
1271 <br>
1272 <input type=hidden name=nextsub value=orders>
1273 <input type=hidden name=path value=$form->{path}>
1274 <input type=hidden name=login value=$form->{login}>
1275 <input type=hidden name=password value=$form->{password}>
1276 <input type=hidden name=vc value=$form->{vc}>
1277 <input type=hidden name=type value=$form->{type}>
1278
1279 <input class=submit type=submit name=action value="|
1280     . $locale->text('Continue') . qq|">
1281 </form>
1282
1283 </body>
1284 </html>
1285 |;
1286
1287   $lxdebug->leave_sub();
1288 }
1289
1290 sub orders {
1291   $lxdebug->enter_sub();
1292
1293   # split vendor / customer
1294   ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1295     split(/--/, $form->{ $form->{vc} });
1296
1297   OE->transactions(\%myconfig, \%$form);
1298
1299   $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1300
1301   $number     = $form->escape($form->{$ordnumber});
1302   $name       = $form->escape($form->{ $form->{vc} });
1303   $department = $form->escape($form->{department});
1304   $warehouse  = $form->escape($form->{warehouse});
1305
1306   # construct href
1307   $href =
1308     "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&$ordnumber=$number&$form->{vc}=$name&department=$department&warehouse=$warehouse";
1309
1310   # construct callback
1311   $number     = $form->escape($form->{$ordnumber},    1);
1312   $name       = $form->escape($form->{ $form->{vc} }, 1);
1313   $department = $form->escape($form->{department},    1);
1314   $warehouse  = $form->escape($form->{warehouse},     1);
1315
1316   $callback =
1317     "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}&$ordnumber=$number&$form->{vc}=$name&department=$department&warehouse=$warehouse";
1318
1319   @columns =
1320     $form->sort_columns("transdate", "reqdate",   "id",      "$ordnumber",
1321                         "name",      "netamount", "tax",     "amount",
1322                         "curr",      "employee",  "shipvia", "open",
1323                         "closed");
1324
1325   $form->{l_open} = $form->{l_closed} = "Y"
1326     if ($form->{open} && $form->{closed});
1327
1328   foreach $item (@columns) {
1329     if ($form->{"l_$item"} eq "Y") {
1330       push @column_index, $item;
1331
1332       # add column to href and callback
1333       $callback .= "&l_$item=Y";
1334       $href     .= "&l_$item=Y";
1335     }
1336   }
1337
1338   # only show checkboxes if gotten here via sales_order form.
1339   if ($form->{type} =~ /sales_order/) {
1340     unshift @column_index, "ids";
1341   }
1342
1343   if ($form->{l_subtotal} eq 'Y') {
1344     $callback .= "&l_subtotal=Y";
1345     $href     .= "&l_subtotal=Y";
1346   }
1347
1348   if ($form->{vc} eq 'vendor') {
1349     if ($form->{type} eq 'receive_order') {
1350       $form->{title} = $locale->text('Receive Merchandise');
1351     } elsif ($form->{type} eq 'purchase_order') {
1352       $form->{title} = $locale->text('Purchase Orders');
1353     } else {
1354       $form->{title} = $locale->text('Request for Quotations');
1355     }
1356     $name     = $locale->text('Vendor');
1357     $employee = $locale->text('Employee');
1358   }
1359   if ($form->{vc} eq 'customer') {
1360     if ($form->{type} eq 'sales_order') {
1361       $form->{title} = $locale->text('Sales Orders');
1362       $employee = $locale->text('Salesperson');
1363     } elsif ($form->{type} eq 'ship_order') {
1364       $form->{title} = $locale->text('Ship Merchandise');
1365       $employee = $locale->text('Salesperson');
1366     } else {
1367       $form->{title} = $locale->text('Quotations');
1368       $employee = $locale->text('Employee');
1369     }
1370     $name = $locale->text('Customer');
1371   }
1372
1373   $column_header{id} =
1374       qq|<th><a class=listheading href=$href&sort=id>|
1375     . $locale->text('ID')
1376     . qq|</a></th>|;
1377   $column_header{transdate} =
1378       qq|<th><a class=listheading href=$href&sort=transdate>|
1379     . $locale->text('Date')
1380     . qq|</a></th>|;
1381   $column_header{reqdate} =
1382       qq|<th><a class=listheading href=$href&sort=reqdate>|
1383     . $locale->text('Required by')
1384     . qq|</a></th>|;
1385   $column_header{ordnumber} =
1386       qq|<th><a class=listheading href=$href&sort=ordnumber>|
1387     . $locale->text('Order')
1388     . qq|</a></th>|;
1389   $column_header{quonumber} =
1390       qq|<th><a class=listheading href=$href&sort=quonumber>|
1391     . $locale->text('Quotation')
1392     . qq|</a></th>|;
1393   $column_header{name} =
1394     qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1395   $column_header{netamount} =
1396     qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1397   $column_header{tax} =
1398     qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1399   $column_header{amount} =
1400     qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1401   $column_header{curr} =
1402     qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1403   $column_header{shipvia} =
1404       qq|<th><a class=listheading href=$href&sort=shipvia>|
1405     . $locale->text('Ship via')
1406     . qq|</a></th>|;
1407   $column_header{open} =
1408     qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1409   $column_header{closed} =
1410     qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1411
1412   $column_header{employee} =
1413     qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1414
1415   $column_header{ids} = qq|<th></th>|;
1416
1417   if ($form->{ $form->{vc} }) {
1418     $option = $locale->text(ucfirst $form->{vc});
1419     $option .= " : $form->{$form->{vc}}";
1420   }
1421   if ($form->{warehouse}) {
1422     ($warehouse) = split /--/, $form->{warehouse};
1423     $option .= "\n<br>" if ($option);
1424     $option .= $locale->text('Warehouse');
1425     $option .= " : $warehouse";
1426   }
1427   if ($form->{department}) {
1428     $option .= "\n<br>" if ($option);
1429     ($department) = split /--/, $form->{department};
1430     $option .= $locale->text('Department') . " : $department";
1431   }
1432   if ($form->{transdatefrom}) {
1433     $option .= "\n<br>"
1434       . $locale->text('From') . " "
1435       . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1436   }
1437   if ($form->{transdateto}) {
1438     $option .= "\n<br>"
1439       . $locale->text('Bis') . " "
1440       . $locale->date(\%myconfig, $form->{transdateto}, 1);
1441   }
1442   if ($form->{open}) {
1443     $option .= "\n<br>" if ($option);
1444     $option .= $locale->text('Open');
1445   }
1446   if ($form->{closed}) {
1447     $option .= "\n<br>" if ($option);
1448     $option .= $locale->text('Closed');
1449   }
1450
1451   $form->header;
1452
1453   print qq|
1454 <body>
1455
1456 <form method="post" action="oe.pl">
1457 <table width=100%>
1458   <tr>
1459     <th class=listtop>$form->{title}</th>
1460   </tr>
1461   <tr height="5"></tr>
1462   <tr>
1463     <td>$option</td>
1464   </tr>
1465   <tr>
1466     <td>
1467       <table width=100%>
1468         <tr class=listheading>|;
1469
1470   map { print "\n$column_header{$_}" } @column_index;
1471
1472   print qq|
1473         </tr>
1474 |;
1475
1476   # add sort and escape callback
1477   $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1478
1479   if (@{ $form->{OE} }) {
1480     $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1481   }
1482
1483   $action = "edit";
1484   $action = "ship_receive" if ($form->{type} =~ /(ship|receive)_order/);
1485
1486   $warehouse = $form->escape($form->{warehouse});
1487
1488   foreach $oe (@{ $form->{OE} }) {
1489     $form->{rowcount} = ++$j;
1490
1491     if ($form->{l_subtotal} eq 'Y') {
1492       if ($sameitem ne $oe->{ $form->{sort} }) {
1493         &subtotal;
1494         $sameitem = $oe->{ $form->{sort} };
1495       }
1496     }
1497
1498     map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1499
1500     $column_data{netamount} =
1501         "<td align=right>"
1502       . $form->format_amount(\%myconfig, $oe->{netamount}, 2, "&nbsp;")
1503       . "</td>";
1504     $column_data{tax} = "<td align=right>"
1505       . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1506                              2, "&nbsp;")
1507       . "</td>";
1508     $column_data{amount} =
1509       "<td align=right>"
1510       . $form->format_amount(\%myconfig, $oe->{amount}, 2, "&nbsp;") . "</td>";
1511
1512     $totalnetamount += $oe->{netamount};
1513     $totalamount    += $oe->{amount};
1514
1515     $subtotalnetamount += $oe->{netamount};
1516     $subtotalamount    += $oe->{amount};
1517
1518     $column_data{ids}    = qq|<td><input name="id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1519     $column_data{id}        = "<td>$oe->{id}</td>";
1520     $column_data{transdate} = "<td>$oe->{transdate}&nbsp;</td>";
1521     $column_data{reqdate}   = "<td>$oe->{reqdate}&nbsp;</td>";
1522
1523     $column_data{$ordnumber} =
1524       "<td><a href=oe.pl?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback_escaped>$oe->{$ordnumber}</a></td>";
1525     $column_data{name} = "<td>$oe->{name}</td>";
1526
1527     $column_data{employee} = "<td>$oe->{employee}&nbsp;</td>";
1528     $column_data{shipvia}  = "<td>$oe->{shipvia}&nbsp;</td>";
1529
1530     if ($oe->{closed}) {
1531       $column_data{closed} = "<td align=center>X</td>";
1532       $column_data{open}   = "<td>&nbsp;</td>";
1533     } else {
1534       $column_data{closed} = "<td>&nbsp;</td>";
1535       $column_data{open}   = "<td align=center>X</td>";
1536     }
1537
1538     $i++;
1539     $i %= 2;
1540     print "
1541         <tr class=listrow$i>";
1542
1543     map { print "\n$column_data{$_}" } @column_index;
1544
1545     print qq|
1546         </tr>
1547 |;
1548
1549   }
1550
1551   if ($form->{l_subtotal} eq 'Y') {
1552     &subtotal;
1553   }
1554
1555   # print totals
1556   print qq|
1557         <tr class=listtotal>|;
1558
1559   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
1560
1561   $column_data{netamount} =
1562     "<th class=listtotal align=right>"
1563     . $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;") . "</th>";
1564   $column_data{tax} = "<th class=listtotal align=right>"
1565     . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1566                            2, "&nbsp;")
1567     . "</th>";
1568   $column_data{amount} =
1569     "<th class=listtotal align=right>"
1570     . $form->format_amount(\%myconfig, $totalamount, 2, "&nbsp;") . "</th>";
1571
1572   map { print "\n$column_data{$_}" } @column_index;
1573
1574   print qq|
1575         </tr>
1576       </td>
1577     </table>
1578   </tr>
1579   <tr>
1580     <td><hr size=3 noshade></td>
1581   </tr>
1582 </table>|;
1583
1584 # multiple invoice edit button only if gotten there via sales_order form.
1585
1586 if ($form->{type} =~ /sales_order/) {
1587 print qq|
1588   <input type="hidden" name="path" value="$form->{path}">
1589   <input class"submit" type="submit" name="action" value="|
1590 . $locale->text('Continue') .qq|">
1591   <input type="hidden" name="nextsub" value="edit">
1592   <input type="hidden" name="type" value="$form->{type}">
1593   <input type="hidden" name="warehouse" value="$warehouse">
1594   <input type="hidden" name="vc" value="$form->{vc}">
1595   <input type="hidden" name="login" value="$form->{login}">
1596   <input type="hidden" name="password" value="$form->{password}">
1597   <input type="hidden" name="callback" value="$callback">
1598   <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1599 }
1600
1601 print qq|
1602 </form>
1603
1604 <br>
1605 <form method=post action=$form->{script}>
1606
1607 <input name=callback type=hidden value="$form->{callback}">
1608
1609 <input type=hidden name=type value=$form->{type}>
1610 <input type=hidden name=vc value=$form->{vc}>
1611
1612 <input type=hidden name=path value=$form->{path}>
1613 <input type=hidden name=login value=$form->{login}>
1614 <input type=hidden name=password value=$form->{password}>
1615 |;
1616
1617   if ($form->{type} !~ /(ship|receive)_order/) {
1618     print qq|
1619 <input class=submit type=submit name=action value="|
1620       . $locale->text('Add') . qq|">|;
1621   }
1622
1623   if ($form->{menubar}) {
1624     require "$form->{path}/menu.pl";
1625     &menubar;
1626   }
1627
1628   print qq|
1629 </form>
1630
1631 </body>
1632 </html>
1633 |;
1634
1635   $lxdebug->leave_sub();
1636 }
1637
1638 sub subtotal {
1639   $lxdebug->enter_sub();
1640
1641   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
1642
1643   $column_data{netamount} =
1644       "<th class=listsubtotal align=right>"
1645     . $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;")
1646     . "</th>";
1647   $column_data{tax} = "<td class=listsubtotal align=right>"
1648     . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1649                            2, "&nbsp;")
1650     . "</th>";
1651   $column_data{amount} =
1652     "<th class=listsubtotal align=right>"
1653     . $form->format_amount(\%myconfig, $subtotalamount, 2, "&nbsp;") . "</th>";
1654
1655   $subtotalnetamount = 0;
1656   $subtotalamount    = 0;
1657
1658   print "
1659         <tr class=listsubtotal>
1660 ";
1661
1662   map { print "\n$column_data{$_}" } @column_index;
1663
1664   print qq|
1665         </tr>
1666 |;
1667
1668   $lxdebug->leave_sub();
1669 }
1670
1671 sub save {
1672   $lxdebug->enter_sub();
1673
1674   if ($form->{type} =~ /_order$/) {
1675     $form->isblank("transdate", $locale->text('Order Date missing!'));
1676   } else {
1677     $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1678   }
1679
1680   $msg = ucfirst $form->{vc};
1681   $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1682
1683   # $locale->text('Customer missing!');
1684   # $locale->text('Vendor missing!');
1685
1686   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1687     if ($form->{currency} ne $form->{defaultcurrency});
1688
1689   &validate_items;
1690
1691   # if the name changed get new values
1692   if (&check_name($form->{vc})) {
1693     &update;
1694     exit;
1695   }
1696
1697   $form->{id} = 0 if $form->{saveasnew};
1698
1699   # this is for the internal notes section for the [email] Subject
1700   if ($form->{type} =~ /_order$/) {
1701     if ($form->{type} eq 'sales_order') {
1702       $form->{label} = $locale->text('Sales Order');
1703
1704       $numberfld = "sonumber";
1705       $ordnumber = "ordnumber";
1706     } else {
1707       $form->{label} = $locale->text('Purchase Order');
1708
1709       $numberfld = "ponumber";
1710       $ordnumber = "ordnumber";
1711     }
1712
1713     $err = $locale->text('Cannot save order!');
1714
1715   } else {
1716     if ($form->{type} eq 'sales_quotation') {
1717       $form->{label} = $locale->text('Quotation');
1718
1719       $numberfld = "sqnumber";
1720       $ordnumber = "quonumber";
1721     } else {
1722       $form->{label} = $locale->text('Request for Quotation');
1723
1724       $numberfld = "rfqnumber";
1725       $ordnumber = "quonumber";
1726     }
1727
1728     $err = $locale->text('Cannot save quotation!');
1729
1730   }
1731
1732   $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
1733     unless $form->{$ordnumber};
1734
1735   $form->redirect(
1736             $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
1737     if (OE->save(\%myconfig, \%$form));
1738   $form->error($err);
1739
1740   $lxdebug->leave_sub();
1741 }
1742
1743 sub delete {
1744   $lxdebug->enter_sub();
1745
1746   $form->header;
1747
1748   if ($form->{type} =~ /_order$/) {
1749     $msg       = $locale->text('Are you sure you want to delete Order Number');
1750     $ordnumber = 'ordnumber';
1751   } else {
1752     $msg = $locale->text('Are you sure you want to delete Quotation Number');
1753     $ordnumber = 'quonumber';
1754   }
1755
1756   print qq|
1757 <body>
1758
1759 <form method=post action=$form->{script}>
1760 |;
1761
1762   # delete action variable
1763   map { delete $form->{$_} } qw(action header);
1764
1765   foreach $key (keys %$form) {
1766     $form->{$key} =~ s/\"/&quot;/g;
1767     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1768   }
1769
1770   print qq|
1771 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1772
1773 <h4>$msg $form->{$ordnumber}</h4>
1774 <p>
1775 <input name=action class=submit type=submit value="|
1776     . $locale->text('Yes') . qq|">
1777 </form>
1778
1779 </body>
1780 </html>
1781 |;
1782
1783   $lxdebug->leave_sub();
1784 }
1785
1786 sub yes {
1787   $lxdebug->enter_sub();
1788
1789   if ($form->{type} =~ /_order$/) {
1790     $msg = $locale->text('Order deleted!');
1791     $err = $locale->text('Cannot delete order!');
1792   } else {
1793     $msg = $locale->text('Quotation deleted!');
1794     $err = $locale->text('Cannot delete quotation!');
1795   }
1796
1797   $form->redirect($msg) if (OE->delete(\%myconfig, \%$form, $spool));
1798   $form->error($err);
1799
1800   $lxdebug->leave_sub();
1801 }
1802
1803 sub invoice {
1804   $lxdebug->enter_sub();
1805
1806   if ($form->{type} =~ /_order$/) {
1807     # these checks only apply if the items don't bring their own ordnumbers/transdates.
1808     # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
1809     $form->isblank("ordnumber", $locale->text('Order Number missing!')) if ( +{ map { $form->{"ordnumber_$_"}, 1 } ( 1 .. $form->{rowcount}-1 ) }->{''} );
1810     $form->isblank("transdate", $locale->text('Order Date missing!'))   if ( +{ map { $form->{"transdate_$_"}, 1 } ( 1 .. $form->{rowcount}-1 ) }->{''} );
1811
1812   } else {
1813     $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
1814     $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1815     $form->{ordnumber} = "";
1816   }
1817
1818   # if the name changed get new values
1819   if (&check_name($form->{vc})) {
1820     &update;
1821     exit;
1822   }
1823
1824   ($null, $form->{cp_id}) = split /--/, $form->{contact};
1825   $form->{cp_id} *= 1;
1826
1827   if (   $form->{type} =~ /_order/
1828       && $form->{currency} ne $form->{defaultcurrency}) {
1829
1830     # check if we need a new exchangerate
1831     $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
1832
1833     $orddate      = $form->current_date(\%myconfig);
1834     $exchangerate =
1835       $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
1836                                 $buysell);
1837
1838     if (!$exchangerate) {
1839       &backorder_exchangerate($orddate, $buysell);
1840       exit;
1841     }
1842   }
1843
1844   # close orders/quotations
1845   $form->{closed} = 1;
1846
1847   # save order if one ordnumber has been given 
1848   # if not it's most likely a collective order, which can't be saved back
1849   # so they just have to be closed
1850   if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
1851     OE->save(\%myconfig, \%$form);
1852   } else {
1853     OE->close_orders(\%myconfig, \%$form);
1854   }
1855
1856   $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1857   $form->{duedate} =
1858     $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1859
1860   $form->{id}     = '';
1861   $form->{closed} = 0;
1862   $form->{rowcount}--;
1863   $form->{shipto} = 1;
1864
1865   if ($form->{type} =~ /_order$/) {
1866     $form->{exchangerate} = $exchangerate;
1867     &create_backorder;
1868   }
1869
1870   if (   $form->{type} eq 'purchase_order'
1871       || $form->{type} eq 'request_quotation') {
1872     $form->{title}  = $locale->text('Add Vendor Invoice');
1873     $form->{script} = 'ir.pl';
1874     $script         = "ir";
1875     $buysell        = 'sell';
1876   }
1877   if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1878     $form->{title}  = $locale->text('Add Sales Invoice');
1879     $form->{script} = 'is.pl';
1880     $script         = "is";
1881     $buysell        = 'buy';
1882   }
1883
1884   # bo creates the id, reset it
1885   map { delete $form->{$_} }
1886     qw(id subject message cc bcc printed emailed queued);
1887   $form->{ $form->{vc} } =~ s/--.*//g;
1888   $form->{type} = "invoice";
1889
1890   # locale messages
1891   $locale = new Locale "$myconfig{countrycode}", "$script";
1892
1893   require "$form->{path}/$form->{script}";
1894
1895   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1896
1897   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1898     qw(creditlimit creditremaining);
1899
1900   $currency = $form->{currency};
1901   &invoice_links;
1902
1903   $form->{currency}     = $currency;
1904   $form->{exchangerate} = "";
1905   $form->{forex}        = "";
1906   $form->{exchangerate} = $exchangerate
1907     if (
1908         $form->{forex} = (
1909                     $exchangerate =
1910                       $form->check_exchangerate(
1911                       \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1912                       )));
1913
1914   $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1915
1916   &prepare_invoice;
1917
1918   # format amounts
1919   for $i (1 .. $form->{rowcount}) {
1920     $form->{"discount_$i"} =
1921       $form->format_amount(\%myconfig, $form->{"discount_$i"});
1922
1923     ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
1924     $dec           = length $dec;
1925     $decimalplaces = ($dec > 2) ? $dec : 2;
1926
1927     # copy delivery date from reqdate for order -> invoice conversion
1928     $form->{"deliverydate_$i"} = $form->{"reqdate_$i"} unless $form->{"deliverydate_$i"};
1929
1930     $form->{"sellprice_$i"} =
1931       $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1932                            $decimalplaces);
1933     
1934     (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
1935       $dec_qty      = length $dec_qty;
1936     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1937
1938     map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
1939       qw(partnumber description unit);
1940
1941   }
1942
1943   &display_form;
1944
1945   $lxdebug->leave_sub();
1946 }
1947
1948 sub backorder_exchangerate {
1949   $lxdebug->enter_sub();
1950   my ($orddate, $buysell) = @_;
1951
1952   $form->header;
1953
1954   print qq|
1955 <body>
1956
1957 <form method=post action=$form->{script}>
1958 |;
1959
1960   # delete action variable
1961   map { delete $form->{$_} } qw(action header exchangerate);
1962
1963   foreach $key (keys %$form) {
1964     $form->{$key} =~ s/\"/&quot;/g;
1965     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1966   }
1967
1968   $form->{title} = $locale->text('Add Exchangerate');
1969
1970   print qq|
1971
1972 <input type=hidden name=path value=$form->{path}>
1973 <input type=hidden name=login value=$form->{login}>
1974 <input type=hidden name=password value=$form->{password}>
1975
1976 <input type=hidden name=exchangeratedate value=$orddate>
1977 <input type=hidden name=buysell value=$buysell>
1978
1979 <table width=100%>
1980   <tr><th class=listtop>$form->{title}</th></tr>
1981   <tr height="5"></tr>
1982   <tr>
1983     <td>
1984       <table>
1985         <tr>
1986           <th align=right>| . $locale->text('Currency') . qq|</th>
1987           <td>$form->{currency}</td>
1988         </tr>
1989         <tr>
1990           <th align=right>| . $locale->text('Date') . qq|</th>
1991           <td>$orddate</td>
1992         </tr>
1993         <tr>
1994           <th align=right>| . $locale->text('Exchangerate') . qq|</th>
1995           <td><input name=exchangerate size=11></td>
1996         </tr>
1997       </table>
1998     </td>
1999   </tr>
2000 </table>
2001
2002 <hr size=3 noshade>
2003
2004 <br>
2005 <input type=hidden name=nextsub value=save_exchangerate>
2006
2007 <input name=action class=submit type=submit value="|
2008     . $locale->text('Continue') . qq|">
2009
2010 </form>
2011
2012 </body>
2013 </html>
2014 |;
2015
2016   $lxdebug->leave_sub();
2017 }
2018
2019 sub save_exchangerate {
2020   $lxdebug->enter_sub();
2021
2022   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2023   $form->{exchangerate} =
2024     $form->parse_amount(\%myconfig, $form->{exchangerate});
2025   $form->save_exchangerate(\%myconfig, $form->{currency},
2026                            $form->{exchangeratedate},
2027                            $form->{exchangerate}, $form->{buysell});
2028
2029   &invoice;
2030
2031   $lxdebug->leave_sub();
2032 }
2033
2034 sub create_backorder {
2035   $lxdebug->enter_sub();
2036
2037   $form->{shipped} = 1;
2038
2039   # figure out if we need to create a backorder
2040   # items aren't saved if qty != 0
2041
2042   for $i (1 .. $form->{rowcount}) {
2043     $totalqty  += $qty  = $form->{"qty_$i"};
2044     $totalship += $ship = $form->{"ship_$i"};
2045
2046     $form->{"qty_$i"} = $qty - $ship;
2047   }
2048
2049   if ($totalship == 0) {
2050     map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2051     $form->{ordtotal} = 0;
2052     $form->{shipped}  = 0;
2053     return;
2054   }
2055
2056   if ($totalqty == $totalship) {
2057     map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2058     $form->{ordtotal} = 0;
2059     return;
2060   }
2061
2062   @flds = (
2063     qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2064   );
2065
2066   for $i (1 .. $form->{rowcount}) {
2067     map {
2068       $form->{"${_}_$i"} =
2069         $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2070     } qw(sellprice discount);
2071   }
2072
2073   OE->save(\%myconfig, \%$form);
2074
2075   # rebuild rows for invoice
2076   @a     = ();
2077   $count = 0;
2078
2079   for $i (1 .. $form->{rowcount}) {
2080     $form->{"qty_$i"} = $form->{"ship_$i"};
2081
2082     if ($form->{"qty_$i"}) {
2083       push @a, {};
2084       $j = $#a;
2085       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2086       $count++;
2087     }
2088   }
2089
2090   $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2091   $form->{rowcount} = $count;
2092
2093   $lxdebug->leave_sub();
2094 }
2095
2096 sub save_as_new {
2097   $lxdebug->enter_sub();
2098
2099   $form->{saveasnew} = 1;
2100   $form->{closed}    = 0;
2101   map { delete $form->{$_} } qw(printed emailed queued);
2102
2103   &save;
2104
2105   $lxdebug->leave_sub();
2106 }
2107
2108 sub purchase_order {
2109   $lxdebug->enter_sub();
2110
2111   if (   $form->{type} eq 'sales_quotation'
2112       || $form->{type} eq 'request_quotation') {
2113     $form->{closed} = 1;
2114     OE->save(\%myconfig, \%$form);
2115   }
2116
2117   ($null, $form->{cp_id}) = split /--/, $form->{contact};
2118   $form->{cp_id} *= 1;
2119
2120   $form->{title} = $locale->text('Add Purchase Order');
2121   $form->{vc}    = "vendor";
2122   $form->{type}  = "purchase_order";
2123
2124   &poso;
2125
2126   $lxdebug->leave_sub();
2127 }
2128
2129 sub sales_order {
2130   $lxdebug->enter_sub();
2131
2132   if (   $form->{type} eq 'sales_quotation'
2133       || $form->{type} eq 'request_quotation') {
2134     $form->{closed} = 1;
2135     OE->save(\%myconfig, \%$form);
2136   }
2137
2138   ($null, $form->{cp_id}) = split /--/, $form->{contact};
2139   $form->{cp_id} *= 1;
2140
2141   $form->{title} = $locale->text('Add Sales Order');
2142   $form->{vc}    = "customer";
2143   $form->{type}  = "sales_order";
2144
2145   &poso;
2146
2147   $lxdebug->leave_sub();
2148 }
2149
2150 sub poso {
2151   $lxdebug->enter_sub();
2152
2153   $form->{transdate} = $form->current_date(\%myconfig);
2154   delete $form->{duedate};
2155
2156   $form->{closed} = 0;
2157
2158   # reset
2159   map { delete $form->{$_} }
2160     qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2161
2162   &order_links;
2163
2164   &prepare_order;
2165
2166   # format amounts
2167   for $i (1 .. $form->{rowcount} - 1) {
2168     map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
2169       qw(partnumber description unit);
2170   }
2171
2172   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2173     qw(creditlimit creditremaining);
2174
2175   &update;
2176
2177   $lxdebug->leave_sub();
2178 }
2179
2180 sub ship_receive {
2181   $lxdebug->enter_sub();
2182
2183   &order_links;
2184
2185   &prepare_order;
2186
2187   OE->get_warehouses(\%myconfig, \%$form);
2188
2189   # warehouse
2190   if (@{ $form->{all_warehouses} }) {
2191     $form->{selectwarehouse} = "<option>\n";
2192
2193     map { $form->{selectwarehouse} .= "<option>$_->{description}--$_->{id}\n" }
2194       (@{ $form->{all_warehouses} });
2195
2196     if ($form->{warehouse}) {
2197       $form->{selectwarehouse} = "<option>$form->{warehouse}";
2198     }
2199   }
2200
2201   $form->{shippingdate} = $form->current_date(\%myconfig);
2202   $form->{"$form->{vc}"} =~ s/--.*//;
2203
2204   @flds  = ();
2205   @a     = ();
2206   $count = 0;
2207   foreach $key (keys %$form) {
2208     if ($key =~ /_1$/) {
2209       $key =~ s/_1//;
2210       push @flds, $key;
2211     }
2212   }
2213
2214   for $i (1 .. $form->{rowcount}) {
2215
2216     # undo formatting from prepare_order
2217     map {
2218       $form->{"${_}_$i"} =
2219         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
2220     } qw(qty ship);
2221     $n = ($form->{"qty_$i"} -= $form->{"ship_$i"});
2222     if (abs($n) > 0
2223         && ($form->{"inventory_accno_$i"} || $form->{"assembly_$i"})) {
2224       $form->{"ship_$i"}         = "";
2225       $form->{"serialnumber_$i"} = "";
2226
2227       push @a, {};
2228       $j = $#a;
2229
2230       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2231       $count++;
2232     }
2233   }
2234
2235   $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2236   $form->{rowcount} = $count;
2237
2238   &display_ship_receive;
2239
2240   $lxdebug->leave_sub();
2241 }
2242
2243 sub display_ship_receive {
2244   $lxdebug->enter_sub();
2245
2246   $vclabel = ucfirst $form->{vc};
2247   $vclabel = $locale->text($vclabel);
2248
2249   $form->{rowcount}++;
2250
2251   if ($form->{vc} eq 'customer') {
2252     $form->{title} = $locale->text('Ship Merchandise');
2253     $shipped = $locale->text('Shipping Date');
2254   } else {
2255     $form->{title} = $locale->text('Receive Merchandise');
2256     $shipped = $locale->text('Date Received');
2257   }
2258
2259   # set option selected
2260   foreach $item (warehouse, employee) {
2261     $form->{"select$item"} =~ s/ selected//;
2262     $form->{"select$item"} =~
2263       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
2264   }
2265
2266   $warehouse = qq|
2267               <tr>
2268                 <th align=right>| . $locale->text('Warehouse') . qq|</th>
2269                 <td><select name=warehouse>$form->{selectwarehouse}</select></td>
2270                 <input type=hidden name=selectwarehouse value="$form->{selectwarehouse}">
2271               </tr>
2272 | if $form->{selectwarehouse};
2273
2274   $employee = qq|
2275               <tr>
2276                 <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
2277                 <td><select name=employee>$form->{selectemployee}</select></td>
2278                 <input type=hidden name=selectemployee value="$form->{selectemployee}">
2279               </tr>
2280 |;
2281
2282   $form->header;
2283
2284   print qq|
2285 <body>
2286
2287 <form method=post action=$form->{script}>
2288
2289 <input type=hidden name=id value=$form->{id}>
2290
2291 <input type=hidden name=display_form value=display_ship_receive>
2292
2293 <input type=hidden name=type value=$form->{type}>
2294 <input type=hidden name=media value=$form->{media}>
2295 <input type=hidden name=format value=$form->{format}>
2296
2297 <input type=hidden name=queued value="$form->{queued}">
2298 <input type=hidden name=printed value="$form->{printed}">
2299 <input type=hidden name=emailed value="$form->{emailed}">
2300
2301 <input type=hidden name=vc value=$form->{vc}>
2302
2303 <table width=100%>
2304   <tr class=listtop>
2305     <th class=listtop>$form->{title}</th>
2306   </tr>
2307   <tr height="5"></tr>
2308   <tr>
2309     <td>
2310       <table width="100%">
2311         <tr valign=top>
2312           <td>
2313             <table width=100%>
2314               <tr>
2315                 <th align=right>$vclabel</th>
2316                 <td colspan=3>$form->{$form->{vc}}</td>
2317                 <input type=hidden name=$form->{vc} value="$form->{$form->{vc}}">
2318                 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
2319               </tr>
2320               $department
2321               <tr>
2322                 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
2323                 <td colspan=3>
2324                 <input name=shippingpoint size=35 value="$form->{shippingpoint}">
2325               </tr>
2326               <tr>
2327                 <th align=right>| . $locale->text('Ship via') . qq|</th>
2328                 <td colspan=3>
2329                 <input name=shipvia size=35 value="$form->{shipvia}">
2330               </tr>
2331               $warehouse
2332             </table>
2333           </td>
2334           <td align=right>
2335             <table>
2336               $employee
2337               <tr>
2338                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
2339                 <td>$form->{ordnumber}</td>
2340                 <input type=hidden name=ordnumber value="$form->{ordnumber}">
2341               </tr>
2342               <tr>
2343                 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
2344                 <td>$form->{transdate}</td>
2345                 <input type=hidden name=transdate value=$form->{transdate}>
2346               </tr>
2347               <tr>
2348                 <th align=right nowrap>$shipped</th>
2349                 <td><input name=shippingdate size=11 value=$form->{shippingdate}></td>
2350               </tr>
2351             </table>
2352           </td>
2353         </tr>
2354       </table>
2355     </td>
2356   </tr>
2357
2358 <!-- shipto are in hidden variables -->
2359
2360 <input type=hidden name=shiptoname value="$form->{shiptoname}">
2361 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
2362 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
2363 <input type=hidden name=shiptocity value="$form->{shiptocity}">
2364 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
2365 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
2366 <input type=hidden name=shiptophone value="$form->{shiptophone}">
2367 <input type=hidden name=shiptofax value="$form->{shiptofax}">
2368 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
2369
2370 <!-- email variables -->
2371 <input type=hidden name=message value="$form->{message}">
2372 <input type=hidden name=email value="$form->{email}">
2373 <input type=hidden name=subject value="$form->{subject}">
2374 <input type=hidden name=cc value="$form->{cc}">
2375 <input type=hidden name=bcc value="$form->{bcc}">
2376
2377 |;
2378
2379   @column_index =
2380     (partnumber, description, qty, ship, unit, bin, serialnumber);
2381
2382   if ($form->{type} eq "ship_order") {
2383     $column_data{ship} =
2384         qq|<th class=listheading align=center width="auto">|
2385       . $locale->text('Ship')
2386       . qq|</th>|;
2387   }
2388   if ($form->{type} eq "receive_order") {
2389     $column_data{ship} =
2390         qq|<th class=listheading align=center width="auto">|
2391       . $locale->text('Recd')
2392       . qq|</th>|;
2393   }
2394
2395   my $colspan = $#column_index + 1;
2396
2397   $column_data{partnumber} =
2398     qq|<th class=listheading nowrap>| . $locale->text('Number') . qq|</th>|;
2399   $column_data{description} =
2400       qq|<th class=listheading nowrap>|
2401     . $locale->text('Description')
2402     . qq|</th>|;
2403   $column_data{qty} =
2404     qq|<th class=listheading nowrap>| . $locale->text('Qty') . qq|</th>|;
2405   $column_data{unit} =
2406     qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
2407   $column_data{bin} =
2408     qq|<th class=listheading nowrap>| . $locale->text('Bin') . qq|</th>|;
2409   $column_data{serialnumber} =
2410       qq|<th class=listheading nowrap>|
2411     . $locale->text('Serial No.')
2412     . qq|</th>|;
2413
2414   print qq|
2415   <tr>
2416     <td>
2417       <table width=100%>
2418         <tr class=listheading>|;
2419
2420   map { print "\n$column_data{$_}" } @column_index;
2421
2422   print qq|
2423         </tr>
2424 |;
2425
2426   for $i (1 .. $form->{rowcount} - 1) {
2427
2428     # undo formatting
2429     $form->{"ship_$i"} = $form->parse_amount(\%myconfig, $form->{"ship_$i"});
2430
2431     # convert " to &quot;
2432     map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
2433       qw(partnumber description unit bin serialnumber);
2434
2435     $description = $form->{"description_$i"};
2436     $description =~ s/\n/<br>/g;
2437
2438     $column_data{partnumber} =
2439       qq|<td>$form->{"partnumber_$i"}<input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
2440     $column_data{description} =
2441       qq|<td>$description<input type=hidden name="description_$i" value="$form->{"description_$i"}"></td>|;
2442     $column_data{qty} =
2443         qq|<td align=right>|
2444       . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty)
2445       . qq|<input type=hidden name="qty_$i" value="$form->{"qty_$i"}"></td>|;
2446     $column_data{ship} =
2447         qq|<td align=right><input name="ship_$i" size=5 value=|
2448       . $form->format_amount(\%myconfig, $form->{"ship_$i"})
2449       . qq|></td>|;
2450     $column_data{unit} =
2451       qq|<td>$form->{"unit_$i"}<input type=hidden name="unit_$i" value="$form->{"unit_$i"}"></td>|;
2452     $column_data{bin} =
2453       qq|<td>$form->{"bin_$i"}<input type=hidden name="bin_$i" value="$form->{"bin_$i"}"></td>|;
2454
2455     $column_data{serialnumber} =
2456       qq|<td><input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}"></td>|;
2457
2458     print qq|
2459         <tr valign=top>|;
2460
2461     map { print "\n$column_data{$_}" } @column_index;
2462
2463     print qq|
2464         </tr>
2465
2466 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
2467 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2468 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
2469 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
2470
2471 |;
2472
2473   }
2474
2475   print qq|
2476       </table>
2477     </td>
2478   </tr>
2479   <tr>
2480     <td><hr size=3 noshade></td>
2481   </tr>
2482   <tr>
2483     <td>
2484 |;
2485
2486   $form->{copies} = 1;
2487
2488   &print_options;
2489
2490   print qq|
2491     </td>
2492   </tr>
2493 </table>
2494 <br>
2495 <input class=submit type=submit name=action value="|
2496     . $locale->text('Update') . qq|">
2497 <input class=submit type=submit name=action value="|
2498     . $locale->text('Print') . qq|">
2499 |;
2500
2501   if ($form->{type} eq 'ship_order') {
2502     print qq|
2503 <input class=submit type=submit name=action value="|
2504       . $locale->text('Ship to') . qq|">
2505 <input class=submit type=submit name=action value="|
2506       . $locale->text('E-mail') . qq|">
2507 |;
2508   }
2509
2510   print qq|
2511
2512 <input class=submit type=submit name=action value="|
2513     . $locale->text('Done') . qq|">
2514 |;
2515
2516   if ($form->{menubar}) {
2517     require "$form->{path}/menu.pl";
2518     &menubar;
2519   }
2520
2521   print qq|
2522
2523 <input type=hidden name=rowcount value=$form->{rowcount}>
2524
2525 <input name=callback type=hidden value="$callback">
2526
2527 <input type=hidden name=path value=$form->{path}>
2528 <input type=hidden name=login value=$form->{login}>
2529 <input type=hidden name=password value=$form->{password}>
2530
2531 </form>
2532
2533 </body>
2534 </html>
2535 |;
2536
2537   $lxdebug->leave_sub();
2538 }
2539
2540 sub done {
2541   $lxdebug->enter_sub();
2542
2543   if ($form->{type} eq 'ship_order') {
2544     $form->isblank("shippingdate", $locale->text('Shipping Date missing!'));
2545   } else {
2546     $form->isblank("shippingdate", $locale->text('Date received missing!'));
2547   }
2548
2549   $total = 0;
2550   map {
2551     $total += $form->{"ship_$_"} =
2552       $form->parse_amount(\%myconfig, $form->{"ship_$_"})
2553   } (1 .. $form->{rowcount} - 1);
2554
2555   $form->error($locale->text('Nothing entered!')) unless $total;
2556
2557   $form->redirect($locale->text('Inventory saved!'))
2558     if OE->save_inventory(\%myconfig, \%$form);
2559   $form->error($locale->text('Could not save!'));
2560
2561   $lxdebug->leave_sub();
2562 }
2563
2564 sub search_transfer {
2565   $lxdebug->enter_sub();
2566
2567   OE->get_warehouses(\%myconfig, \%$form);
2568
2569   # warehouse
2570   if (@{ $form->{all_warehouses} }) {
2571     $form->{selectwarehouse} = "<option>\n";
2572     $form->{warehouse}       = qq|$form->{warehouse}--$form->{warehouse_id}|;
2573
2574     map { $form->{selectwarehouse} .= "<option>$_->{description}--$_->{id}\n" }
2575       (@{ $form->{all_warehouses} });
2576   } else {
2577     $form->error($locale->text('Nothing to transfer!'));
2578   }
2579
2580   $form->{title} = $locale->text('Transfer Inventory');
2581
2582   $form->header;
2583
2584   print qq|
2585 <body>
2586
2587 <form method=post action=$form->{script}>
2588
2589 <table width=100%>
2590   <tr>
2591     <th class=listtop>$form->{title}</th>
2592   </tr>
2593   <tr height="5"></tr>
2594   <tr>
2595     <td>
2596       <table>
2597         <tr>
2598           <th align=right nowrap>| . $locale->text('Transfer to') . qq|</th>
2599           <td><select name=warehouse>$form->{selectwarehouse}</select></td>
2600         </tr>
2601         <tr>
2602           <th align="right" nowrap="true">| . $locale->text('Part Number') . qq|</th>
2603           <td><input name=partnumber size=20></td>
2604         </tr>
2605         <tr>
2606           <th align="right" nowrap="true">| . $locale->text('Description') . qq|</th>
2607           <td><input name=description size=40></td>
2608         </tr>
2609         <tr>
2610           <th align=right nowrap>| . $locale->text('Group') . qq|</th>
2611           <td><input name=partsgroup size=20></td>
2612         </tr>
2613       </table>
2614     </td>
2615   </tr>
2616   <tr>
2617     <td><hr size=3 noshade></td>
2618   </tr>
2619 </table>
2620
2621 <br>
2622 <input type=hidden name=sort value=partnumber>
2623 <input type=hidden name=nextsub value=list_transfer>
2624
2625 <input type=hidden name=path value=$form->{path}>
2626 <input type=hidden name=login value=$form->{login}>
2627 <input type=hidden name=password value=$form->{password}>
2628
2629 <input class=submit type=submit name=action value="|
2630     . $locale->text('Continue') . qq|">
2631 </form>
2632
2633 </body>
2634 </html>
2635 |;
2636
2637   $lxdebug->leave_sub();
2638 }
2639
2640 sub list_transfer {
2641   $lxdebug->enter_sub();
2642
2643   OE->get_inventory(\%myconfig, \%$form);
2644
2645   $partnumber  = $form->escape($form->{partnumber});
2646   $warehouse   = $form->escape($form->{warehouse});
2647   $description = $form->escape($form->{description});
2648   $partsgroup  = $form->escape($form->{partsgroup});
2649
2650   # construct href
2651   $href =
2652     "$form->{script}?path=$form->{path}&action=list_transfer&partnumber=$partnumber&warehouse=$warehouse&description=$description&partsgroup=$partsgroup&login=$form->{login}&password=$form->{password}";
2653
2654   # construct callback
2655   $partnumber  = $form->escape($form->{partnumber},  1);
2656   $warehouse   = $form->escape($form->{warehouse},   1);
2657   $description = $form->escape($form->{description}, 1);
2658   $partsgroup  = $form->escape($form->{partsgroup},  1);
2659
2660   $callback =
2661     "$form->{script}?path=$form->{path}&action=list_transfer&partnumber=$partnumber&warehouse=$warehouse&description=$description&partsgroup=$partsgroup&login=$form->{login}&password=$form->{password}";
2662
2663   @column_index =
2664     $form->sort_columns(
2665       qw(partnumber description partsgroup make model warehouse qty transfer));
2666
2667   $column_header{partnumber} =
2668       qq|<th><a class=listheading href=$href&sort=partnumber>|
2669     . $locale->text('Part Number')
2670     . qq|</a></th>|;
2671   $column_header{description} =
2672       qq|<th><a class=listheading href=$href&sort=description>|
2673     . $locale->text('Description')
2674     . qq|</a></th>|;
2675   $column_header{partsgroup} =
2676       qq|<th><a class=listheading href=$href&sort=partsgroup>|
2677     . $locale->text('Group')
2678     . qq|</a></th>|;
2679   $column_header{warehouse} =
2680       qq|<th><a class=listheading href=$href&sort=warehouse>|
2681     . $locale->text('From')
2682     . qq|</a></th>|;
2683   $column_header{qty} =
2684     qq|<th><a class=listheading>| . $locale->text('Qty') . qq|</a></th>|;
2685   $column_header{transfer} =
2686     qq|<th><a class=listheading>| . $locale->text('Transfer') . qq|</a></th>|;
2687
2688   $option = $locale->text('Transfer to');
2689
2690   ($warehouse, $warehouse_id) = split /--/, $form->{warehouse};
2691
2692   if ($form->{warehouse}) {
2693     $option .= " : $warehouse";
2694   }
2695   if ($form->{partnumber}) {
2696     $option .= "\n<br>" if ($option);
2697     $option .= $locale->text('Part Number') . " : $form->{partnumber}";
2698   }
2699   if ($form->{description}) {
2700     $option .= "\n<br>" if ($option);
2701     $option .= $locale->text('Description') . " : $form->{description}";
2702   }
2703   if ($form->{partsgroup}) {
2704     $option .= "\n<br>" if ($option);
2705     $option .= $locale->text('Group') . " : $form->{partsgroup}";
2706   }
2707
2708   $form->{title} = $locale->text('Transfer Inventory');
2709
2710   $form->header;
2711
2712   print qq|
2713 <body>
2714
2715 <form method=post action=$form->{script}>
2716
2717 <input type=hidden name=warehouse_id value=$warehouse_id>
2718
2719 <table width=100%>
2720   <tr>
2721     <th class=listtop>$form->{title}</th>
2722   </tr>
2723   <tr height="5"></tr>
2724   <tr>
2725     <td>$option</td>
2726   </tr>
2727   <tr>
2728     <td>
2729       <table width=100%>
2730         <tr class=listheading>|;
2731
2732   map { print "\n$column_header{$_}" } @column_index;
2733
2734   print qq|
2735         </tr>
2736 |;
2737
2738   if (@{ $form->{all_inventory} }) {
2739     $sameitem = $form->{all_inventory}->[0]->{ $form->{sort} };
2740   }
2741
2742   $i = 0;
2743   foreach $ref (@{ $form->{all_inventory} }) {
2744
2745     $i++;
2746
2747     $column_data{partnumber} =
2748       qq|<td><input type=hidden name="id_$i" value=$ref->{id}>$ref->{partnumber}</td>|;
2749     $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
2750     $column_data{partsgroup}  = "<td>$ref->{partsgroup}&nbsp;</td>";
2751     $column_data{warehouse}   =
2752       qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}>$ref->{warehouse}&nbsp;</td>|;
2753     $column_data{qty} =
2754         qq|<td><input type=hidden name="qty_$i" value=$ref->{qty}>|
2755       . $form->format_amount(\%myconfig, $ref->{qty}, $dec_qty)
2756       . qq|</td>|;
2757     $column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|;
2758
2759     $j++;
2760     $j %= 2;
2761     print "
2762         <tr class=listrow$j>";
2763
2764     map { print "\n$column_data{$_}" } @column_index;
2765
2766     print qq|
2767         </tr>
2768 |;
2769
2770   }
2771
2772   print qq|
2773       </table>
2774     </td>
2775   </tr>
2776
2777   <tr>
2778     <td><hr size=3 noshade></td>
2779   </tr>
2780 </table>
2781
2782 <br>
2783
2784 <input name=callback type=hidden value="$callback">
2785
2786 <input type=hidden name=rowcount value=$i>
2787
2788 <input type=hidden name=path value=$form->{path}>
2789 <input type=hidden name=login value=$form->{login}>
2790 <input type=hidden name=password value=$form->{password}>
2791
2792 <input class=submit type=submit name=action value="|
2793     . $locale->text('Transfer') . qq|">|;
2794
2795   if ($form->{menubar}) {
2796     require "$form->{path}/menu.pl";
2797     &menubar;
2798   }
2799
2800   print qq|
2801 </form>
2802
2803 </body>
2804 </html>
2805 |;
2806
2807   $lxdebug->leave_sub();
2808 }
2809
2810 sub transfer {
2811   $lxdebug->enter_sub();
2812
2813   $form->redirect($locale->text('Inventory transferred!'))
2814     if OE->transfer(\%myconfig, \%$form);
2815   $form->error($locale->text('Could not transfer Inventory!'));
2816
2817   $lxdebug->leave_sub();
2818 }