Merge von 833,836-838 aus unstable: Lieferdatum in Rechnungen
[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     # also copy deliverydate from the order
1813     $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
1814   } else {
1815     $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
1816     $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1817     $form->{ordnumber} = "";
1818   }
1819
1820   # if the name changed get new values
1821   if (&check_name($form->{vc})) {
1822     &update;
1823     exit;
1824   }
1825
1826   ($null, $form->{cp_id}) = split /--/, $form->{contact};
1827   $form->{cp_id} *= 1;
1828
1829   if (   $form->{type} =~ /_order/
1830       && $form->{currency} ne $form->{defaultcurrency}) {
1831
1832     # check if we need a new exchangerate
1833     $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
1834
1835     $orddate      = $form->current_date(\%myconfig);
1836     $exchangerate =
1837       $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
1838                                 $buysell);
1839
1840     if (!$exchangerate) {
1841       &backorder_exchangerate($orddate, $buysell);
1842       exit;
1843     }
1844   }
1845
1846   # close orders/quotations
1847   $form->{closed} = 1;
1848
1849   # save order if one ordnumber has been given 
1850   # if not it's most likely a collective order, which can't be saved back
1851   # so they just have to be closed
1852   if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
1853     OE->save(\%myconfig, \%$form);
1854   } else {
1855     OE->close_orders(\%myconfig, \%$form);
1856   }
1857
1858   $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1859   $form->{duedate} =
1860     $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1861
1862   $form->{id}     = '';
1863   $form->{closed} = 0;
1864   $form->{rowcount}--;
1865   $form->{shipto} = 1;
1866
1867   if ($form->{type} =~ /_order$/) {
1868     $form->{exchangerate} = $exchangerate;
1869     &create_backorder;
1870   }
1871
1872   if (   $form->{type} eq 'purchase_order'
1873       || $form->{type} eq 'request_quotation') {
1874     $form->{title}  = $locale->text('Add Vendor Invoice');
1875     $form->{script} = 'ir.pl';
1876     $script         = "ir";
1877     $buysell        = 'sell';
1878   }
1879   if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1880     $form->{title}  = $locale->text('Add Sales Invoice');
1881     $form->{script} = 'is.pl';
1882     $script         = "is";
1883     $buysell        = 'buy';
1884   }
1885
1886   # bo creates the id, reset it
1887   map { delete $form->{$_} }
1888     qw(id subject message cc bcc printed emailed queued);
1889   $form->{ $form->{vc} } =~ s/--.*//g;
1890   $form->{type} = "invoice";
1891
1892   # locale messages
1893   $locale = new Locale "$myconfig{countrycode}", "$script";
1894
1895   require "$form->{path}/$form->{script}";
1896
1897   map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1898
1899   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1900     qw(creditlimit creditremaining);
1901
1902   $currency = $form->{currency};
1903   &invoice_links;
1904
1905   $form->{currency}     = $currency;
1906   $form->{exchangerate} = "";
1907   $form->{forex}        = "";
1908   $form->{exchangerate} = $exchangerate
1909     if (
1910         $form->{forex} = (
1911                     $exchangerate =
1912                       $form->check_exchangerate(
1913                       \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1914                       )));
1915
1916   $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1917
1918   &prepare_invoice;
1919
1920   # format amounts
1921   for $i (1 .. $form->{rowcount}) {
1922     $form->{"discount_$i"} =
1923       $form->format_amount(\%myconfig, $form->{"discount_$i"});
1924
1925     ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
1926     $dec           = length $dec;
1927     $decimalplaces = ($dec > 2) ? $dec : 2;
1928
1929     # copy delivery date from reqdate for order -> invoice conversion
1930     $form->{"deliverydate_$i"} = $form->{"reqdate_$i"} unless $form->{"deliverydate_$i"};
1931
1932     $form->{"sellprice_$i"} =
1933       $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1934                            $decimalplaces);
1935     
1936     (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
1937       $dec_qty      = length $dec_qty;
1938     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1939
1940     map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
1941       qw(partnumber description unit);
1942
1943   }
1944
1945   &display_form;
1946
1947   $lxdebug->leave_sub();
1948 }
1949
1950 sub backorder_exchangerate {
1951   $lxdebug->enter_sub();
1952   my ($orddate, $buysell) = @_;
1953
1954   $form->header;
1955
1956   print qq|
1957 <body>
1958
1959 <form method=post action=$form->{script}>
1960 |;
1961
1962   # delete action variable
1963   map { delete $form->{$_} } qw(action header exchangerate);
1964
1965   foreach $key (keys %$form) {
1966     $form->{$key} =~ s/\"/&quot;/g;
1967     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1968   }
1969
1970   $form->{title} = $locale->text('Add Exchangerate');
1971
1972   print qq|
1973
1974 <input type=hidden name=path value=$form->{path}>
1975 <input type=hidden name=login value=$form->{login}>
1976 <input type=hidden name=password value=$form->{password}>
1977
1978 <input type=hidden name=exchangeratedate value=$orddate>
1979 <input type=hidden name=buysell value=$buysell>
1980
1981 <table width=100%>
1982   <tr><th class=listtop>$form->{title}</th></tr>
1983   <tr height="5"></tr>
1984   <tr>
1985     <td>
1986       <table>
1987         <tr>
1988           <th align=right>| . $locale->text('Currency') . qq|</th>
1989           <td>$form->{currency}</td>
1990         </tr>
1991         <tr>
1992           <th align=right>| . $locale->text('Date') . qq|</th>
1993           <td>$orddate</td>
1994         </tr>
1995         <tr>
1996           <th align=right>| . $locale->text('Exchangerate') . qq|</th>
1997           <td><input name=exchangerate size=11></td>
1998         </tr>
1999       </table>
2000     </td>
2001   </tr>
2002 </table>
2003
2004 <hr size=3 noshade>
2005
2006 <br>
2007 <input type=hidden name=nextsub value=save_exchangerate>
2008
2009 <input name=action class=submit type=submit value="|
2010     . $locale->text('Continue') . qq|">
2011
2012 </form>
2013
2014 </body>
2015 </html>
2016 |;
2017
2018   $lxdebug->leave_sub();
2019 }
2020
2021 sub save_exchangerate {
2022   $lxdebug->enter_sub();
2023
2024   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2025   $form->{exchangerate} =
2026     $form->parse_amount(\%myconfig, $form->{exchangerate});
2027   $form->save_exchangerate(\%myconfig, $form->{currency},
2028                            $form->{exchangeratedate},
2029                            $form->{exchangerate}, $form->{buysell});
2030
2031   &invoice;
2032
2033   $lxdebug->leave_sub();
2034 }
2035
2036 sub create_backorder {
2037   $lxdebug->enter_sub();
2038
2039   $form->{shipped} = 1;
2040
2041   # figure out if we need to create a backorder
2042   # items aren't saved if qty != 0
2043
2044   for $i (1 .. $form->{rowcount}) {
2045     $totalqty  += $qty  = $form->{"qty_$i"};
2046     $totalship += $ship = $form->{"ship_$i"};
2047
2048     $form->{"qty_$i"} = $qty - $ship;
2049   }
2050
2051   if ($totalship == 0) {
2052     map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2053     $form->{ordtotal} = 0;
2054     $form->{shipped}  = 0;
2055     return;
2056   }
2057
2058   if ($totalqty == $totalship) {
2059     map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2060     $form->{ordtotal} = 0;
2061     return;
2062   }
2063
2064   @flds = (
2065     qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2066   );
2067
2068   for $i (1 .. $form->{rowcount}) {
2069     map {
2070       $form->{"${_}_$i"} =
2071         $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2072     } qw(sellprice discount);
2073   }
2074
2075   OE->save(\%myconfig, \%$form);
2076
2077   # rebuild rows for invoice
2078   @a     = ();
2079   $count = 0;
2080
2081   for $i (1 .. $form->{rowcount}) {
2082     $form->{"qty_$i"} = $form->{"ship_$i"};
2083
2084     if ($form->{"qty_$i"}) {
2085       push @a, {};
2086       $j = $#a;
2087       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2088       $count++;
2089     }
2090   }
2091
2092   $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2093   $form->{rowcount} = $count;
2094
2095   $lxdebug->leave_sub();
2096 }
2097
2098 sub save_as_new {
2099   $lxdebug->enter_sub();
2100
2101   $form->{saveasnew} = 1;
2102   $form->{closed}    = 0;
2103   map { delete $form->{$_} } qw(printed emailed queued);
2104
2105   &save;
2106
2107   $lxdebug->leave_sub();
2108 }
2109
2110 sub purchase_order {
2111   $lxdebug->enter_sub();
2112
2113   if (   $form->{type} eq 'sales_quotation'
2114       || $form->{type} eq 'request_quotation') {
2115     $form->{closed} = 1;
2116     OE->save(\%myconfig, \%$form);
2117   }
2118
2119   ($null, $form->{cp_id}) = split /--/, $form->{contact};
2120   $form->{cp_id} *= 1;
2121
2122   $form->{title} = $locale->text('Add Purchase Order');
2123   $form->{vc}    = "vendor";
2124   $form->{type}  = "purchase_order";
2125
2126   &poso;
2127
2128   $lxdebug->leave_sub();
2129 }
2130
2131 sub sales_order {
2132   $lxdebug->enter_sub();
2133
2134   if (   $form->{type} eq 'sales_quotation'
2135       || $form->{type} eq 'request_quotation') {
2136     $form->{closed} = 1;
2137     OE->save(\%myconfig, \%$form);
2138   }
2139
2140   ($null, $form->{cp_id}) = split /--/, $form->{contact};
2141   $form->{cp_id} *= 1;
2142
2143   $form->{title} = $locale->text('Add Sales Order');
2144   $form->{vc}    = "customer";
2145   $form->{type}  = "sales_order";
2146
2147   &poso;
2148
2149   $lxdebug->leave_sub();
2150 }
2151
2152 sub poso {
2153   $lxdebug->enter_sub();
2154
2155   $form->{transdate} = $form->current_date(\%myconfig);
2156   delete $form->{duedate};
2157
2158   $form->{closed} = 0;
2159
2160   # reset
2161   map { delete $form->{$_} }
2162     qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2163
2164   &order_links;
2165
2166   &prepare_order;
2167
2168   # format amounts
2169   for $i (1 .. $form->{rowcount} - 1) {
2170     map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
2171       qw(partnumber description unit);
2172   }
2173
2174   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2175     qw(creditlimit creditremaining);
2176
2177   &update;
2178
2179   $lxdebug->leave_sub();
2180 }
2181
2182 sub ship_receive {
2183   $lxdebug->enter_sub();
2184
2185   &order_links;
2186
2187   &prepare_order;
2188
2189   OE->get_warehouses(\%myconfig, \%$form);
2190
2191   # warehouse
2192   if (@{ $form->{all_warehouses} }) {
2193     $form->{selectwarehouse} = "<option>\n";
2194
2195     map { $form->{selectwarehouse} .= "<option>$_->{description}--$_->{id}\n" }
2196       (@{ $form->{all_warehouses} });
2197
2198     if ($form->{warehouse}) {
2199       $form->{selectwarehouse} = "<option>$form->{warehouse}";
2200     }
2201   }
2202
2203   $form->{shippingdate} = $form->current_date(\%myconfig);
2204   $form->{"$form->{vc}"} =~ s/--.*//;
2205
2206   @flds  = ();
2207   @a     = ();
2208   $count = 0;
2209   foreach $key (keys %$form) {
2210     if ($key =~ /_1$/) {
2211       $key =~ s/_1//;
2212       push @flds, $key;
2213     }
2214   }
2215
2216   for $i (1 .. $form->{rowcount}) {
2217
2218     # undo formatting from prepare_order
2219     map {
2220       $form->{"${_}_$i"} =
2221         $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
2222     } qw(qty ship);
2223     $n = ($form->{"qty_$i"} -= $form->{"ship_$i"});
2224     if (abs($n) > 0
2225         && ($form->{"inventory_accno_$i"} || $form->{"assembly_$i"})) {
2226       $form->{"ship_$i"}         = "";
2227       $form->{"serialnumber_$i"} = "";
2228
2229       push @a, {};
2230       $j = $#a;
2231
2232       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2233       $count++;
2234     }
2235   }
2236
2237   $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2238   $form->{rowcount} = $count;
2239
2240   &display_ship_receive;
2241
2242   $lxdebug->leave_sub();
2243 }
2244
2245 sub display_ship_receive {
2246   $lxdebug->enter_sub();
2247
2248   $vclabel = ucfirst $form->{vc};
2249   $vclabel = $locale->text($vclabel);
2250
2251   $form->{rowcount}++;
2252
2253   if ($form->{vc} eq 'customer') {
2254     $form->{title} = $locale->text('Ship Merchandise');
2255     $shipped = $locale->text('Shipping Date');
2256   } else {
2257     $form->{title} = $locale->text('Receive Merchandise');
2258     $shipped = $locale->text('Date Received');
2259   }
2260
2261   # set option selected
2262   foreach $item (warehouse, employee) {
2263     $form->{"select$item"} =~ s/ selected//;
2264     $form->{"select$item"} =~
2265       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
2266   }
2267
2268   $warehouse = qq|
2269               <tr>
2270                 <th align=right>| . $locale->text('Warehouse') . qq|</th>
2271                 <td><select name=warehouse>$form->{selectwarehouse}</select></td>
2272                 <input type=hidden name=selectwarehouse value="$form->{selectwarehouse}">
2273               </tr>
2274 | if $form->{selectwarehouse};
2275
2276   $employee = qq|
2277               <tr>
2278                 <th align=right nowrap>| . $locale->text('Contact') . qq|</th>
2279                 <td><select name=employee>$form->{selectemployee}</select></td>
2280                 <input type=hidden name=selectemployee value="$form->{selectemployee}">
2281               </tr>
2282 |;
2283
2284   $form->header;
2285
2286   print qq|
2287 <body>
2288
2289 <form method=post action=$form->{script}>
2290
2291 <input type=hidden name=id value=$form->{id}>
2292
2293 <input type=hidden name=display_form value=display_ship_receive>
2294
2295 <input type=hidden name=type value=$form->{type}>
2296 <input type=hidden name=media value=$form->{media}>
2297 <input type=hidden name=format value=$form->{format}>
2298
2299 <input type=hidden name=queued value="$form->{queued}">
2300 <input type=hidden name=printed value="$form->{printed}">
2301 <input type=hidden name=emailed value="$form->{emailed}">
2302
2303 <input type=hidden name=vc value=$form->{vc}>
2304
2305 <table width=100%>
2306   <tr class=listtop>
2307     <th class=listtop>$form->{title}</th>
2308   </tr>
2309   <tr height="5"></tr>
2310   <tr>
2311     <td>
2312       <table width="100%">
2313         <tr valign=top>
2314           <td>
2315             <table width=100%>
2316               <tr>
2317                 <th align=right>$vclabel</th>
2318                 <td colspan=3>$form->{$form->{vc}}</td>
2319                 <input type=hidden name=$form->{vc} value="$form->{$form->{vc}}">
2320                 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
2321               </tr>
2322               $department
2323               <tr>
2324                 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
2325                 <td colspan=3>
2326                 <input name=shippingpoint size=35 value="$form->{shippingpoint}">
2327               </tr>
2328               <tr>
2329                 <th align=right>| . $locale->text('Ship via') . qq|</th>
2330                 <td colspan=3>
2331                 <input name=shipvia size=35 value="$form->{shipvia}">
2332               </tr>
2333               $warehouse
2334             </table>
2335           </td>
2336           <td align=right>
2337             <table>
2338               $employee
2339               <tr>
2340                 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
2341                 <td>$form->{ordnumber}</td>
2342                 <input type=hidden name=ordnumber value="$form->{ordnumber}">
2343               </tr>
2344               <tr>
2345                 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
2346                 <td>$form->{transdate}</td>
2347                 <input type=hidden name=transdate value=$form->{transdate}>
2348               </tr>
2349               <tr>
2350                 <th align=right nowrap>$shipped</th>
2351                 <td><input name=shippingdate size=11 value=$form->{shippingdate}></td>
2352               </tr>
2353             </table>
2354           </td>
2355         </tr>
2356       </table>
2357     </td>
2358   </tr>
2359
2360 <!-- shipto are in hidden variables -->
2361
2362 <input type=hidden name=shiptoname value="$form->{shiptoname}">
2363 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
2364 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
2365 <input type=hidden name=shiptocity value="$form->{shiptocity}">
2366 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
2367 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
2368 <input type=hidden name=shiptophone value="$form->{shiptophone}">
2369 <input type=hidden name=shiptofax value="$form->{shiptofax}">
2370 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
2371
2372 <!-- email variables -->
2373 <input type=hidden name=message value="$form->{message}">
2374 <input type=hidden name=email value="$form->{email}">
2375 <input type=hidden name=subject value="$form->{subject}">
2376 <input type=hidden name=cc value="$form->{cc}">
2377 <input type=hidden name=bcc value="$form->{bcc}">
2378
2379 |;
2380
2381   @column_index =
2382     (partnumber, description, qty, ship, unit, bin, serialnumber);
2383
2384   if ($form->{type} eq "ship_order") {
2385     $column_data{ship} =
2386         qq|<th class=listheading align=center width="auto">|
2387       . $locale->text('Ship')
2388       . qq|</th>|;
2389   }
2390   if ($form->{type} eq "receive_order") {
2391     $column_data{ship} =
2392         qq|<th class=listheading align=center width="auto">|
2393       . $locale->text('Recd')
2394       . qq|</th>|;
2395   }
2396
2397   my $colspan = $#column_index + 1;
2398
2399   $column_data{partnumber} =
2400     qq|<th class=listheading nowrap>| . $locale->text('Number') . qq|</th>|;
2401   $column_data{description} =
2402       qq|<th class=listheading nowrap>|
2403     . $locale->text('Description')
2404     . qq|</th>|;
2405   $column_data{qty} =
2406     qq|<th class=listheading nowrap>| . $locale->text('Qty') . qq|</th>|;
2407   $column_data{unit} =
2408     qq|<th class=listheading nowrap>| . $locale->text('Unit') . qq|</th>|;
2409   $column_data{bin} =
2410     qq|<th class=listheading nowrap>| . $locale->text('Bin') . qq|</th>|;
2411   $column_data{serialnumber} =
2412       qq|<th class=listheading nowrap>|
2413     . $locale->text('Serial No.')
2414     . qq|</th>|;
2415
2416   print qq|
2417   <tr>
2418     <td>
2419       <table width=100%>
2420         <tr class=listheading>|;
2421
2422   map { print "\n$column_data{$_}" } @column_index;
2423
2424   print qq|
2425         </tr>
2426 |;
2427
2428   for $i (1 .. $form->{rowcount} - 1) {
2429
2430     # undo formatting
2431     $form->{"ship_$i"} = $form->parse_amount(\%myconfig, $form->{"ship_$i"});
2432
2433     # convert " to &quot;
2434     map { $form->{"${_}_$i"} =~ s/\"/&quot;/g }
2435       qw(partnumber description unit bin serialnumber);
2436
2437     $description = $form->{"description_$i"};
2438     $description =~ s/\n/<br>/g;
2439
2440     $column_data{partnumber} =
2441       qq|<td>$form->{"partnumber_$i"}<input type=hidden name="partnumber_$i" value="$form->{"partnumber_$i"}"></td>|;
2442     $column_data{description} =
2443       qq|<td>$description<input type=hidden name="description_$i" value="$form->{"description_$i"}"></td>|;
2444     $column_data{qty} =
2445         qq|<td align=right>|
2446       . $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty)
2447       . qq|<input type=hidden name="qty_$i" value="$form->{"qty_$i"}"></td>|;
2448     $column_data{ship} =
2449         qq|<td align=right><input name="ship_$i" size=5 value=|
2450       . $form->format_amount(\%myconfig, $form->{"ship_$i"})
2451       . qq|></td>|;
2452     $column_data{unit} =
2453       qq|<td>$form->{"unit_$i"}<input type=hidden name="unit_$i" value="$form->{"unit_$i"}"></td>|;
2454     $column_data{bin} =
2455       qq|<td>$form->{"bin_$i"}<input type=hidden name="bin_$i" value="$form->{"bin_$i"}"></td>|;
2456
2457     $column_data{serialnumber} =
2458       qq|<td><input name="serialnumber_$i" size=15 value="$form->{"serialnumber_$i"}"></td>|;
2459
2460     print qq|
2461         <tr valign=top>|;
2462
2463     map { print "\n$column_data{$_}" } @column_index;
2464
2465     print qq|
2466         </tr>
2467
2468 <input type=hidden name="orderitems_id_$i" value=$form->{"orderitems_id_$i"}>
2469 <input type=hidden name="id_$i" value=$form->{"id_$i"}>
2470 <input type=hidden name="assembly_$i" value="$form->{"assembly_$i"}">
2471 <input type=hidden name="partsgroup_$i" value="$form->{"partsgroup_$i"}">
2472
2473 |;
2474
2475   }
2476
2477   print qq|
2478       </table>
2479     </td>
2480   </tr>
2481   <tr>
2482     <td><hr size=3 noshade></td>
2483   </tr>
2484   <tr>
2485     <td>
2486 |;
2487
2488   $form->{copies} = 1;
2489
2490   &print_options;
2491
2492   print qq|
2493     </td>
2494   </tr>
2495 </table>
2496 <br>
2497 <input class=submit type=submit name=action value="|
2498     . $locale->text('Update') . qq|">
2499 <input class=submit type=submit name=action value="|
2500     . $locale->text('Print') . qq|">
2501 |;
2502
2503   if ($form->{type} eq 'ship_order') {
2504     print qq|
2505 <input class=submit type=submit name=action value="|
2506       . $locale->text('Ship to') . qq|">
2507 <input class=submit type=submit name=action value="|
2508       . $locale->text('E-mail') . qq|">
2509 |;
2510   }
2511
2512   print qq|
2513
2514 <input class=submit type=submit name=action value="|
2515     . $locale->text('Done') . qq|">
2516 |;
2517
2518   if ($form->{menubar}) {
2519     require "$form->{path}/menu.pl";
2520     &menubar;
2521   }
2522
2523   print qq|
2524
2525 <input type=hidden name=rowcount value=$form->{rowcount}>
2526
2527 <input name=callback type=hidden value="$callback">
2528
2529 <input type=hidden name=path value=$form->{path}>
2530 <input type=hidden name=login value=$form->{login}>
2531 <input type=hidden name=password value=$form->{password}>
2532
2533 </form>
2534
2535 </body>
2536 </html>
2537 |;
2538
2539   $lxdebug->leave_sub();
2540 }
2541
2542 sub done {
2543   $lxdebug->enter_sub();
2544
2545   if ($form->{type} eq 'ship_order') {
2546     $form->isblank("shippingdate", $locale->text('Shipping Date missing!'));
2547   } else {
2548     $form->isblank("shippingdate", $locale->text('Date received missing!'));
2549   }
2550
2551   $total = 0;
2552   map {
2553     $total += $form->{"ship_$_"} =
2554       $form->parse_amount(\%myconfig, $form->{"ship_$_"})
2555   } (1 .. $form->{rowcount} - 1);
2556
2557   $form->error($locale->text('Nothing entered!')) unless $total;
2558
2559   $form->redirect($locale->text('Inventory saved!'))
2560     if OE->save_inventory(\%myconfig, \%$form);
2561   $form->error($locale->text('Could not save!'));
2562
2563   $lxdebug->leave_sub();
2564 }
2565
2566 sub search_transfer {
2567   $lxdebug->enter_sub();
2568
2569   OE->get_warehouses(\%myconfig, \%$form);
2570
2571   # warehouse
2572   if (@{ $form->{all_warehouses} }) {
2573     $form->{selectwarehouse} = "<option>\n";
2574     $form->{warehouse}       = qq|$form->{warehouse}--$form->{warehouse_id}|;
2575
2576     map { $form->{selectwarehouse} .= "<option>$_->{description}--$_->{id}\n" }
2577       (@{ $form->{all_warehouses} });
2578   } else {
2579     $form->error($locale->text('Nothing to transfer!'));
2580   }
2581
2582   $form->{title} = $locale->text('Transfer Inventory');
2583
2584   $form->header;
2585
2586   print qq|
2587 <body>
2588
2589 <form method=post action=$form->{script}>
2590
2591 <table width=100%>
2592   <tr>
2593     <th class=listtop>$form->{title}</th>
2594   </tr>
2595   <tr height="5"></tr>
2596   <tr>
2597     <td>
2598       <table>
2599         <tr>
2600           <th align=right nowrap>| . $locale->text('Transfer to') . qq|</th>
2601           <td><select name=warehouse>$form->{selectwarehouse}</select></td>
2602         </tr>
2603         <tr>
2604           <th align="right" nowrap="true">| . $locale->text('Part Number') . qq|</th>
2605           <td><input name=partnumber size=20></td>
2606         </tr>
2607         <tr>
2608           <th align="right" nowrap="true">| . $locale->text('Description') . qq|</th>
2609           <td><input name=description size=40></td>
2610         </tr>
2611         <tr>
2612           <th align=right nowrap>| . $locale->text('Group') . qq|</th>
2613           <td><input name=partsgroup size=20></td>
2614         </tr>
2615       </table>
2616     </td>
2617   </tr>
2618   <tr>
2619     <td><hr size=3 noshade></td>
2620   </tr>
2621 </table>
2622
2623 <br>
2624 <input type=hidden name=sort value=partnumber>
2625 <input type=hidden name=nextsub value=list_transfer>
2626
2627 <input type=hidden name=path value=$form->{path}>
2628 <input type=hidden name=login value=$form->{login}>
2629 <input type=hidden name=password value=$form->{password}>
2630
2631 <input class=submit type=submit name=action value="|
2632     . $locale->text('Continue') . qq|">
2633 </form>
2634
2635 </body>
2636 </html>
2637 |;
2638
2639   $lxdebug->leave_sub();
2640 }
2641
2642 sub list_transfer {
2643   $lxdebug->enter_sub();
2644
2645   OE->get_inventory(\%myconfig, \%$form);
2646
2647   $partnumber  = $form->escape($form->{partnumber});
2648   $warehouse   = $form->escape($form->{warehouse});
2649   $description = $form->escape($form->{description});
2650   $partsgroup  = $form->escape($form->{partsgroup});
2651
2652   # construct href
2653   $href =
2654     "$form->{script}?path=$form->{path}&action=list_transfer&partnumber=$partnumber&warehouse=$warehouse&description=$description&partsgroup=$partsgroup&login=$form->{login}&password=$form->{password}";
2655
2656   # construct callback
2657   $partnumber  = $form->escape($form->{partnumber},  1);
2658   $warehouse   = $form->escape($form->{warehouse},   1);
2659   $description = $form->escape($form->{description}, 1);
2660   $partsgroup  = $form->escape($form->{partsgroup},  1);
2661
2662   $callback =
2663     "$form->{script}?path=$form->{path}&action=list_transfer&partnumber=$partnumber&warehouse=$warehouse&description=$description&partsgroup=$partsgroup&login=$form->{login}&password=$form->{password}";
2664
2665   @column_index =
2666     $form->sort_columns(
2667       qw(partnumber description partsgroup make model warehouse qty transfer));
2668
2669   $column_header{partnumber} =
2670       qq|<th><a class=listheading href=$href&sort=partnumber>|
2671     . $locale->text('Part Number')
2672     . qq|</a></th>|;
2673   $column_header{description} =
2674       qq|<th><a class=listheading href=$href&sort=description>|
2675     . $locale->text('Description')
2676     . qq|</a></th>|;
2677   $column_header{partsgroup} =
2678       qq|<th><a class=listheading href=$href&sort=partsgroup>|
2679     . $locale->text('Group')
2680     . qq|</a></th>|;
2681   $column_header{warehouse} =
2682       qq|<th><a class=listheading href=$href&sort=warehouse>|
2683     . $locale->text('From')
2684     . qq|</a></th>|;
2685   $column_header{qty} =
2686     qq|<th><a class=listheading>| . $locale->text('Qty') . qq|</a></th>|;
2687   $column_header{transfer} =
2688     qq|<th><a class=listheading>| . $locale->text('Transfer') . qq|</a></th>|;
2689
2690   $option = $locale->text('Transfer to');
2691
2692   ($warehouse, $warehouse_id) = split /--/, $form->{warehouse};
2693
2694   if ($form->{warehouse}) {
2695     $option .= " : $warehouse";
2696   }
2697   if ($form->{partnumber}) {
2698     $option .= "\n<br>" if ($option);
2699     $option .= $locale->text('Part Number') . " : $form->{partnumber}";
2700   }
2701   if ($form->{description}) {
2702     $option .= "\n<br>" if ($option);
2703     $option .= $locale->text('Description') . " : $form->{description}";
2704   }
2705   if ($form->{partsgroup}) {
2706     $option .= "\n<br>" if ($option);
2707     $option .= $locale->text('Group') . " : $form->{partsgroup}";
2708   }
2709
2710   $form->{title} = $locale->text('Transfer Inventory');
2711
2712   $form->header;
2713
2714   print qq|
2715 <body>
2716
2717 <form method=post action=$form->{script}>
2718
2719 <input type=hidden name=warehouse_id value=$warehouse_id>
2720
2721 <table width=100%>
2722   <tr>
2723     <th class=listtop>$form->{title}</th>
2724   </tr>
2725   <tr height="5"></tr>
2726   <tr>
2727     <td>$option</td>
2728   </tr>
2729   <tr>
2730     <td>
2731       <table width=100%>
2732         <tr class=listheading>|;
2733
2734   map { print "\n$column_header{$_}" } @column_index;
2735
2736   print qq|
2737         </tr>
2738 |;
2739
2740   if (@{ $form->{all_inventory} }) {
2741     $sameitem = $form->{all_inventory}->[0]->{ $form->{sort} };
2742   }
2743
2744   $i = 0;
2745   foreach $ref (@{ $form->{all_inventory} }) {
2746
2747     $i++;
2748
2749     $column_data{partnumber} =
2750       qq|<td><input type=hidden name="id_$i" value=$ref->{id}>$ref->{partnumber}</td>|;
2751     $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
2752     $column_data{partsgroup}  = "<td>$ref->{partsgroup}&nbsp;</td>";
2753     $column_data{warehouse}   =
2754       qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}>$ref->{warehouse}&nbsp;</td>|;
2755     $column_data{qty} =
2756         qq|<td><input type=hidden name="qty_$i" value=$ref->{qty}>|
2757       . $form->format_amount(\%myconfig, $ref->{qty}, $dec_qty)
2758       . qq|</td>|;
2759     $column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|;
2760
2761     $j++;
2762     $j %= 2;
2763     print "
2764         <tr class=listrow$j>";
2765
2766     map { print "\n$column_data{$_}" } @column_index;
2767
2768     print qq|
2769         </tr>
2770 |;
2771
2772   }
2773
2774   print qq|
2775       </table>
2776     </td>
2777   </tr>
2778
2779   <tr>
2780     <td><hr size=3 noshade></td>
2781   </tr>
2782 </table>
2783
2784 <br>
2785
2786 <input name=callback type=hidden value="$callback">
2787
2788 <input type=hidden name=rowcount value=$i>
2789
2790 <input type=hidden name=path value=$form->{path}>
2791 <input type=hidden name=login value=$form->{login}>
2792 <input type=hidden name=password value=$form->{password}>
2793
2794 <input class=submit type=submit name=action value="|
2795     . $locale->text('Transfer') . qq|">|;
2796
2797   if ($form->{menubar}) {
2798     require "$form->{path}/menu.pl";
2799     &menubar;
2800   }
2801
2802   print qq|
2803 </form>
2804
2805 </body>
2806 </html>
2807 |;
2808
2809   $lxdebug->leave_sub();
2810 }
2811
2812 sub transfer {
2813   $lxdebug->enter_sub();
2814
2815   $form->redirect($locale->text('Inventory transferred!'))
2816     if OE->transfer(\%myconfig, \%$form);
2817   $form->error($locale->text('Could not transfer Inventory!'));
2818
2819   $lxdebug->leave_sub();
2820 }