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