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