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