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