1 # #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger, Accounting
9 # Copyright (c) 1998-2003
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
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.
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 #======================================================================
32 #======================================================================
40 require "bin/mozilla/io.pl";
41 require "bin/mozilla/arap.pl";
48 # $locale->text('Edit the purchase_order');
49 # $locale->text('Edit the sales_order');
50 # $locale->text('Edit the request_quotation');
51 # $locale->text('Edit the sales_quotation');
53 # $locale->text('Workflow purchase_order');
54 # $locale->text('Workflow sales_order');
55 # $locale->text('Workflow request_quotation');
56 # $locale->text('Workflow sales_quotation');
59 $lxdebug->enter_sub();
63 if ($form->{type} eq 'purchase_order') {
64 $form->{title} = $action eq "edit" ?
65 $locale->text('Edit Purchase Order') :
66 $locale->text('Add Purchase Order');
67 $form->{heading} = $locale->text('Purchase Order');
68 $form->{vc} = 'vendor';
70 if ($form->{type} eq 'sales_order') {
71 $form->{title} = $action eq "edit" ?
72 $locale->text('Edit Sales Order') :
73 $locale->text('Add Sales Order');
74 $form->{heading} = $locale->text('Sales Order');
75 $form->{vc} = 'customer';
77 if ($form->{type} eq 'request_quotation') {
78 $form->{title} = $action eq "edit" ?
79 $locale->text('Edit Request for Quotation') :
80 $locale->text('Add Request for Quotation');
81 $form->{heading} = $locale->text('Request for Quotation');
82 $form->{vc} = 'vendor';
84 if ($form->{type} eq 'sales_quotation') {
85 $form->{title} = $action eq "edit" ?
86 $locale->text('Edit Quotation') :
87 $locale->text('Add Quotation');
88 $form->{heading} = $locale->text('Quotation');
89 $form->{vc} = 'customer';
92 $lxdebug->leave_sub();
96 $lxdebug->enter_sub();
101 "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}"
102 unless $form->{callback};
108 $lxdebug->leave_sub();
112 $lxdebug->enter_sub();
113 # show history button
114 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
115 #/show hhistory button
117 $form->{simple_save} = 0;
119 set_headings("edit");
121 # editing without stuff to edit? try adding it first
122 if ($form->{rowcount}) {
123 map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount});
127 undef $form->{rowcount};
129 $lxdebug->leave_sub();
132 } elsif (!$form->{id}) {
134 $lxdebug->leave_sub();
138 if ($form->{print_and_save}) {
139 $form->{action} = "print";
140 $form->{resubmit} = 1;
141 $language_id = $form->{language_id};
142 $printer_id = $form->{printer_id};
145 set_headings("edit");
149 if ($form->{print_and_save}) {
150 $form->{language_id} = $language_id;
151 $form->{printer_id} = $printer_id;
155 $lxdebug->leave_sub();
159 $lxdebug->enter_sub();
160 # get customer/vendor
161 $form->all_vc(\%myconfig, $form->{vc},
162 ($form->{vc} eq 'customer') ? "AR" : "AP");
164 # retrieve order/quotation
165 $form->{webdav} = $webdav;
166 $form->{jsscript} = 1;
168 my $editing = $form->{id};
170 OE->retrieve(\%myconfig, \%$form);
172 if ($form->{payment_id}) {
173 $payment_id = $form->{payment_id};
175 if ($form->{language_id}) {
176 $language_id = $form->{language_id};
178 if ($form->{taxzone_id}) {
179 $taxzone_id = $form->{taxzone_id};
182 $salesman_id = $form->{salesman_id} if ($editing);
185 # if multiple rowcounts (== collective order) then check if the
186 # there were more than one customer (in that case OE::retrieve removes
187 # the content from the field)
188 if ( $form->{rowcount}
189 && $form->{type} eq 'sales_order'
190 && defined $form->{customer}
191 && $form->{customer} eq '') {
193 # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
196 'Collective Orders only work for orders from one customer!')
200 $taxincluded = $form->{taxincluded};
201 $form->{shipto} = 1 if $form->{id};
203 if ($form->{"all_$form->{vc}"}) {
204 unless ($form->{"$form->{vc}_id"}) {
205 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
209 $cp_id = $form->{cp_id};
210 $intnotes = $form->{intnotes};
212 # get customer / vendor
213 if ($form->{type} =~ /(purchase_order|request_quotation)/) {
214 IR->get_vendor(\%myconfig, \%$form);
216 #quote all_vendor Bug 133
217 foreach $ref (@{ $form->{all_vendor} }) {
218 $ref->{name} = $form->quote($ref->{name});
222 if ($form->{type} =~ /sales_(order|quotation)/) {
223 IS->get_customer(\%myconfig, \%$form);
225 #quote all_vendor Bug 133
226 foreach $ref (@{ $form->{all_customer} }) {
227 $ref->{name} = $form->quote($ref->{name});
231 $form->{cp_id} = $cp_id;
234 $form->{payment_id} = $payment_id;
237 $form->{language_id} = $language_id;
240 $form->{taxzone_id} = $taxzone_id;
242 $form->{intnotes} = $intnotes if $intnotes;
243 ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
244 $form->{"old$form->{vc}"} =
245 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
247 # build the popup menus
248 if (@{ $form->{"all_$form->{vc}"} }) {
249 $form->{ $form->{vc} } =
250 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
251 map { $form->{"select$form->{vc}"} .=
252 "<option>$_->{name}--$_->{id}</option>\n" }
253 (@{ $form->{"all_$form->{vc}"} });
256 $form->{taxincluded} = $taxincluded if ($form->{id});
259 if (@{ $form->{all_departments} }) {
260 $form->{selectdepartment} = "<option>\n";
261 $form->{department} = "$form->{department}--$form->{department_id}";
264 $form->{selectdepartment} .=
265 "<option>$_->{description}--$_->{id}</option>\n"
266 } (@{ $form->{all_departments} });
269 $form->{employee} = "$form->{employee}--$form->{employee_id}";
272 $form->{forex} = $form->{exchangerate};
274 $form->{salesman_id} = $salesman_id if ($editing);
276 $lxdebug->leave_sub();
280 $lxdebug->enter_sub();
281 $form->{formname} = $form->{type} unless $form->{formname};
284 foreach $ref (@{ $form->{form_details} }) {
285 $form->{rowcount} = ++$i;
287 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
289 for my $i (1 .. $form->{rowcount}) {
291 $form->{"discount_$i"} =
292 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
294 $form->{"discount_$i"} =
295 $form->format_amount(\%myconfig, $form->{"discount_$i"});
297 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
299 $decimalplaces = ($dec > 2) ? $dec : 2;
301 # copy reqdate from deliverydate for invoice -> order conversion
302 $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
303 unless $form->{"reqdate_$i"};
305 $form->{"sellprice_$i"} =
306 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
309 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
310 $dec_qty = length $dec_qty;
312 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
314 map { $form->{"${_}_$i"} =~ s/\"/"/g }
315 qw(partnumber description unit);
318 $lxdebug->leave_sub();
322 $lxdebug->enter_sub();
324 my $checkedclosed = $form->{"closed"} ? "checked" : "";
325 my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
327 if ($form->{old_employee_id}) {
328 $form->{employee_id} = $form->{old_employee_id};
330 if ($form->{old_salesman_id}) {
331 $form->{salesman_id} = $form->{old_salesman_id};
334 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
337 if ($form->{old_employee_id}) {
338 $form->{employee_id} = $form->{old_employee_id};
340 if ($form->{old_salesman_id}) {
341 $form->{salesman_id} = $form->{old_salesman_id};
344 map { $form->{$_} =~ s/\"/"/g }
345 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
346 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
347 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
349 # use JavaScript Calendar or not
350 $form->{jsscript} = 1;
354 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\">
355 <input type=button name=transdate id="trigger1" value=|
356 . $locale->text('button') . qq|></td>
359 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\">
360 <input type=button name=reqdate name=reqdate id="trigger2" value=|
361 . $locale->text('button') . qq|></td>
366 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
367 "reqdate", "BL", "trigger2");
371 if (($form->{"type"} eq "sales_order") ||
372 ($form->{"type"} eq "purchase_order")) {
374 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
375 <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
380 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
381 <label for="closed">| . $locale->text('Closed') . qq|</label>|);
387 <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
393 # set option selected
394 foreach $item ($form->{vc}, currency, department, ($form->{vc} eq "customer" ? customer : vendor)) {
395 $form->{"select$item"} =~ s/ selected//;
396 $form->{"select$item"} =~
397 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
400 #quote select[customer|vendor] Bug 133
401 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
403 #substitute \n and \r to \s (bug 543)
404 $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
406 my @old_project_ids = ($form->{"globalproject_id"});
407 map({ push(@old_project_ids, $form->{"project_id_$_"})
408 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
410 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
411 $form->get_lists("contacts" => "ALL_CONTACTS",
412 "shipto" => "ALL_SHIPTO",
413 "projects" => { "key" => "ALL_PROJECTS",
415 "old_id" => \@old_project_ids },
416 "employees" => "ALL_EMPLOYEES",
417 "salesmen" => "ALL_SALESMEN",
418 "taxzones" => "ALL_TAXZONES",
419 "payments" => "ALL_PAYMENTS",
420 "currencies" => "ALL_CURRENCIES",
421 $vc => "ALL_" . uc($vc));
424 my @values = (undef);
425 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
426 push(@values, $item->{"cp_id"});
427 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
428 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
432 if (scalar @values > 1) {
435 <th align="right">| . $locale->text('Contact Person') . qq|</th>
437 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
438 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
447 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
448 push(@values, $item->{"name"}.qq|--|.$item->{"id"});
449 $labels{$item->{"name"}.qq|--|.$item->{"id"}} = $item->{name};
453 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
454 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
455 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
457 (($myconfig{vclimit} <= scalar(@values))
458 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
459 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
460 '-onChange' => 'document.getElementById(\'update_button\').click();',
461 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
462 <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
463 </td><input type=hidden name="select$form->{vc}" value="| .
464 Q($form->{"select$form->{vc}"}) . qq|">|;
468 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
469 push(@values, $item->{"id"});
470 $labels{$item->{"id"}} = $item->{"description"};
474 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
476 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
477 '-labels' => \%labels, '-default' => $form->{payment_id}))
482 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
483 push(@values, $item->{"shipto_id"});
484 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
488 if (scalar @values > 1) {
491 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
493 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
494 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
500 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
501 push(@values, $item->{"id"});
502 $labels{$item->{"id"}} = $item->{"projectnumber"};
504 my $globalprojectnumber =
505 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
506 '-labels' => \%labels,
507 '-default' => $form->{"globalproject_id"}));
512 if ($form->{type} =~ /^sales_/) {
513 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
514 push(@values, $item->{"id"});
515 $labels{$item->{"id"}} = ($item->{"name"} ne "" ? $item->{"name"} : $item->{"login"});
519 <th align="right">| . $locale->text('Salesman') . qq|</th>
521 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
522 '-values' => \@values, '-labels' => \%labels))
529 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
530 push(@values, $item->{"id"});
531 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
536 <th align="right">| . $locale->text('Employee') . qq|</th>
538 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
539 '-values' => \@values, '-labels' => \%labels)) . qq|
545 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
546 push(@values, $item->{"id"});
547 $labels{$item->{"id"}} = $item->{"description"};
552 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
554 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
555 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
562 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
563 push(@values, $item);
564 $labels{$item} = $item;
567 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
569 if (scalar @values) {
572 <th align="right">| . $locale->text('Currency') . qq|</th>
574 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
575 '-values' => \@values, '-labels' => \%labels)) . qq|
580 $form->{exchangerate} =
581 $form->format_amount(\%myconfig, $form->{exchangerate});
583 if (!$form->{exchangerate}) {
584 $form->{exchangerate} = "";
587 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
593 $form->{creditlimit} =
594 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
595 $form->{creditremaining} =
596 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
599 <input type=hidden name=forex value=$form->{forex}>
602 if ($form->{currency} ne $form->{defaultcurrency}) {
603 if ($form->{forex}) {
606 . $locale->text('Exchangerate')
607 . qq|</th><td>$form->{exchangerate}</td>
608 <input type=hidden name=exchangerate value=$form->{exchangerate}>
613 . $locale->text('Exchangerate')
614 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
618 if ($form->{business}) {
621 <th align="right">| . ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type')) . qq|</th>
622 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
623 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
629 if ($form->{max_dunning_level}) {
632 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
634 <b>$form->{max_dunning_level}</b>;
635 | . $locale->text('Dunning Amount') . qq|: <b>|
636 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
643 if ($form->{type} !~ /_quotation$/) {
646 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
647 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
650 <th width=70% align=right nowrap>|
651 . $locale->text('Quotation Number') . qq|</th>
652 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
655 <th width=70% align=right nowrap>|
656 . $locale->text('Customer Order Number') . qq|</th>
657 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
660 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
665 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
670 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
672 $creditremaining = qq|
675 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
676 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
682 ($form->{type} eq 'sales_quotation')
683 ? $locale->text('Valid until')
684 : $locale->text('Required by');
685 if ($form->{type} eq 'sales_quotation') {
688 <th width=70% align=right nowrap>|
689 . $locale->text('Quotation Number') . qq|</th>
690 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
691 <input type=hidden name=ordnumber value="$form->{ordnumber}">
697 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
698 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
699 <input type=hidden name=ordnumber value="$form->{ordnumber}">
707 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
711 <th align=right nowrap=true>$reqlabel</th>
715 $creditremaining = qq| <tr>
723 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
724 <td colspan=3><select name=department style="width: 250px">$form->{selectdepartment}</select>
725 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
727 </tr> | if $form->{selectdepartment};
729 if ($form->{type} eq 'sales_order') {
730 if ($form->{selectemployee}) {
732 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
736 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
738 if ($form->{resubmit} && ($form->{format} eq "html")) {
740 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
741 } elsif ($form->{resubmit}) {
742 $onload = qq|document.oe.submit()|;
747 $credittext = $locale->text('Credit Limit exceeded!!!');
748 if ($creditwarning) {
749 $onload = qq|alert('$credittext')|;
752 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
753 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
755 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
756 # show history button js
757 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
758 #/show history button js
759 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
764 <body onLoad="$onload">
766 <form method=post name=oe action=$form->{script}>
768 <script type="text/javascript" src="js/common.js"></script>
769 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
770 <script type="text/javascript" src="js/vendor_selection.js"></script>
771 <script type="text/javascript" src="js/calculate_qty.js"></script>
774 $form->hide_form(qw(id action type vc formname media format proforma queued printed emailed
775 title discount creditlimit creditremaining tradediscount business
776 max_dunning_level dunning_amount));
782 <th class=listtop>$form->{title}</th>
804 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
805 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
808 <th align=right>| . $locale->text('Ship via') . qq|</th>
809 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
812 <th align="right">| . $locale->text('Transaction description') . qq|</th>
813 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
820 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
822 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
823 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
827 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
829 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
830 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
844 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
845 <td>$globalprojectnumber</td>
856 <!-- shipto are in hidden variables -->
858 <input type=hidden name=shiptoname value="$form->{shiptoname}">
859 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
860 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
861 <input type=hidden name=shiptocity value="$form->{shiptocity}">
862 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
863 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
864 <input type=hidden name=shiptophone value="$form->{shiptophone}">
865 <input type=hidden name=shiptofax value="$form->{shiptofax}">
866 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
867 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
868 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
870 <!-- email variables -->
871 <input type=hidden name=message value="$form->{message}">
872 <input type=hidden name=email value="$form->{email}">
873 <input type=hidden name=subject value="$form->{subject}">
874 <input type=hidden name=cc value="$form->{cc}">
875 <input type=hidden name=bcc value="$form->{bcc}">
877 <input type=hidden name=taxpart value="$form->{taxpart}">
878 <input type=hidden name=taxservice value="$form->{taxservice}">
880 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
883 foreach $item (split / /, $form->{taxaccounts}) {
885 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
886 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
889 $lxdebug->leave_sub();
893 $lxdebug->enter_sub();
895 $form->{invtotal} = $form->{invsubtotal};
897 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
900 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
903 $rows = ($rows > $introws) ? $rows : $introws;
905 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
907 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
909 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
912 if ($form->{taxaccounts}) {
914 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
915 . $locale->text('Tax Included') . qq|</b><br><br>
919 if (!$form->{taxincluded}) {
921 foreach $item (split / /, $form->{taxaccounts}) {
922 if ($form->{"${item}_base"}) {
923 $form->{invtotal} += $form->{"${item}_total"} =
925 $form->{"${item}_base"} * $form->{"${item}_rate"},
927 $form->{"${item}_total"} =
928 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
932 <th align=right>$form->{"${item}_description"} |
933 . $form->{"${item}_rate"} * 100 .qq|%</th>
934 <td align=right>$form->{"${item}_total"}</td>
940 $form->{invsubtotal} =
941 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
945 <th align=right>| . $locale->text('Subtotal') . qq|</th>
946 <td align=right>$form->{invsubtotal}</td>
952 if ($form->{taxincluded}) {
953 foreach $item (split / /, $form->{taxaccounts}) {
954 if ($form->{"${item}_base"}) {
955 $form->{"${item}_total"} =
957 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
958 (1 + $form->{"${item}_rate"})
961 $form->{"${item}_netto"} =
963 ($form->{"${item}_base"} - $form->{"${item}_total"}),
965 $form->{"${item}_total"} =
966 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
967 $form->{"${item}_netto"} =
968 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
972 <th align=right>Enthaltene $form->{"${item}_description"} |
973 . $form->{"${item}_rate"} * 100 .qq|%</th>
974 <td align=right>$form->{"${item}_total"}</td>
977 <th align=right>Nettobetrag</th>
978 <td align=right>$form->{"${item}_netto"}</td>
986 $form->{oldinvtotal} = $form->{invtotal};
988 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
998 <th align=left>| . $locale->text('Notes') . qq|</th>
999 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
1010 <td align=right width=100%>
1016 <th align=right>| . $locale->text('Total') . qq|</th>
1017 <td align=right>$form->{invtotal}</td>
1025 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1026 <input type=hidden name=oldtotalpaid value=$totalpaid>
1028 <td><hr size=3 noshade></td>
1036 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
1039 <td align=left width=30%><b>Dateiname</b></td>
1040 <td align=left width=70%><b>Webdavlink</b></td>
1042 foreach $file (keys %{ $form->{WEBDAV} }) {
1045 <td align=left>$file</td>
1046 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1054 <td><hr size=3 noshade></td>
1072 | . $locale->text("Edit the $form->{type}") . qq|<br>
1073 <input class=submit type=submit name=action id=update_button value="|
1074 . $locale->text('Update') . qq|">
1075 <input class=submit type=submit name=action value="|
1076 . $locale->text('Ship to') . qq|">
1077 <input class=submit type=submit name=action value="|
1078 . $locale->text('Print') . qq|">
1079 <input class=submit type=submit name=action value="|
1080 . $locale->text('E-mail') . qq|">
1081 <input class=submit type=submit name=action value="|
1082 . $locale->text('Save') . qq|">
1083 <input class=submit type=submit name=action value="|
1084 . $locale->text('Save and Close') . qq|">
1087 if (($form->{id})) {
1089 <input type="button" class="submit" onclick="set_history_window(|
1091 . qq|);" name="history" id="history" value="|
1092 . $locale->text('history')
1095 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1096 <input class=submit type=submit name=action value="|
1097 . $locale->text('Save as new') . qq|">
1098 <input class=submit type=submit name=action value="|
1099 . $locale->text('Delete') . qq|">|;
1100 if (($form->{type} =~ /sales_quotation$/)) {
1102 <input class=submit type=submit name=action value="|
1103 . $locale->text('Sales Order') . qq|">|;
1105 if ($form->{type} =~ /request_quotation$/) {
1107 <input class=submit type=submit name=action value="|
1108 . $locale->text('Purchase Order') . qq|">|;
1112 <input class=submit type=submit name=action value="|
1113 . $locale->text('Invoice') . qq|">
1117 if ($form->{type} =~ /sales_order$/) {
1119 <br>$form->{heading} als neue Vorlage verwenden für<br>
1120 <input class=submit type=submit name=action value="|
1121 . $locale->text('Purchase Order') . qq|">
1122 <input class=submit type=submit name=action value="|
1123 . $locale->text('Quotation') . qq|">
1126 } elsif ($form->{type} =~ /purchase_order$/) {
1128 <br>$form->{heading} als neue Vorlage verwenden für<br>
1129 <input class=submit type=submit name=action value="|
1130 . $locale->text('Sales Order') . qq|">
1131 <input class=submit type=submit name=action value="|
1132 . $locale->text('Request for Quotation') . qq|">
1137 <br>$form->{heading} als neue Vorlage verwenden für<br>
1138 <input class=submit type=submit name=action value="|
1139 . $locale->text('Order') . qq|">
1142 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1144 <br>Workflow $form->{heading}<br>
1145 <input class=submit type=submit name=action value="|
1146 . $locale->text('Save as new') . qq|">
1147 <input class=submit type=submit name=action value="|
1148 . $locale->text('Invoice') . qq|">
1152 $form->hide_form("saved_xyznumber");
1156 <input type=hidden name=rowcount value=$form->{rowcount}>
1158 <input name=callback type=hidden value="$form->{callback}">
1160 <input type=hidden name=login value=$form->{login}>
1161 <input type=hidden name=password value=$form->{password}>
1168 $lxdebug->leave_sub();
1172 $lxdebug->enter_sub();
1174 set_headings($form->{"id"} ? "edit" : "add");
1176 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1177 qw(exchangerate creditlimit creditremaining);
1178 $form->{update} = 1;
1180 if($form->{payment_id}) {
1181 $payment_id = $form->{payment_id};
1184 &check_name($form->{vc});
1186 if($form->{payment_id} eq "") {
1187 $form->{payment_id} = $payment_id;
1191 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1192 $form->{exchangerate} = $exchangerate
1196 $form->check_exchangerate(
1197 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1201 $i = $form->{rowcount};
1203 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1205 if ( ($form->{"partnumber_$i"} eq "")
1206 && ($form->{"description_$i"} eq "")
1207 && ($form->{"partsgroup_$i"} eq "")) {
1209 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1214 if ( $form->{type} eq 'purchase_order'
1215 || $form->{type} eq 'request_quotation') {
1216 IR->retrieve_item(\%myconfig, \%$form);
1218 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1219 IS->retrieve_item(\%myconfig, \%$form);
1222 my $rows = scalar @{ $form->{item_list} };
1224 $form->{"discount_$i"} =
1225 $form->format_amount(\%myconfig, $form->{discount} * 100);
1228 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1237 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1238 if ($form->{"not_discountable_$i"}) {
1239 $form->{"discount_$i"} = 0;
1241 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1242 qw(partnumber description unit);
1243 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1244 keys %{ $form->{item_list}[0] };
1245 if ($form->{"part_payment_id_$i"} ne "") {
1246 $form->{payment_id} = $form->{"part_payment_id_$i"};
1249 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1251 ($dec) = ($s =~ /\.(\d+)/);
1253 $decimalplaces = ($dec > 2) ? $dec : 2;
1256 $form->{"sellprice_$i"} = $sellprice;
1259 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1261 # if there is an exchange rate adjust sellprice
1262 $form->{"sellprice_$i"} /= $exchangerate;
1266 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1267 (1 - $form->{"discount_$i"} / 100);
1268 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1269 map { $form->{"${_}_base"} += $amount }
1270 (split / /, $form->{"taxaccounts_$i"});
1271 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1272 split / /, $form->{taxaccounts}
1273 if !$form->{taxincluded};
1275 $form->{creditremaining} -= $amount;
1277 $form->{"sellprice_$i"} =
1278 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1281 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1283 # get pricegroups for parts
1284 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1286 # build up html code for prices_$i
1287 &set_pricegroup($i);
1294 # ok, so this is a new part
1295 # ask if it is a part or service item
1297 if ( $form->{"partsgroup_$i"}
1298 && ($form->{"partsnumber_$i"} eq "")
1299 && ($form->{"description_$i"} eq "")) {
1300 $form->{rowcount}--;
1301 $form->{"discount_$i"} = "";
1305 $form->{"id_$i"} = 0;
1306 $form->{"unit_$i"} = $locale->text('ea');
1314 $lxdebug->leave_sub();
1318 $lxdebug->enter_sub();
1320 if ($form->{type} eq 'purchase_order') {
1321 $form->{title} = $locale->text('Purchase Orders');
1322 $form->{vc} = 'vendor';
1323 $ordlabel = $locale->text('Order Number');
1324 $ordnumber = 'ordnumber';
1325 $employee = $locale->text('Employee');
1328 if ($form->{type} eq 'request_quotation') {
1329 $form->{title} = $locale->text('Request for Quotations');
1330 $form->{vc} = 'vendor';
1331 $ordlabel = $locale->text('RFQ Number');
1332 $ordnumber = 'quonumber';
1333 $employee = $locale->text('Employee');
1336 if ($form->{type} eq 'sales_order') {
1337 $form->{title} = $locale->text('Sales Orders');
1338 $form->{vc} = 'customer';
1339 $ordlabel = $locale->text('Order Number');
1340 $ordnumber = 'ordnumber';
1341 $employee = $locale->text('Employee');
1344 if ($form->{type} eq 'sales_quotation') {
1345 $form->{title} = $locale->text('Quotations');
1346 $form->{vc} = 'customer';
1347 $ordlabel = $locale->text('Quotation Number');
1348 $ordnumber = 'quonumber';
1349 $employee = $locale->text('Employee');
1352 # setup vendor / customer selection
1353 $form->all_vc(\%myconfig, $form->{vc},
1354 ($form->{vc} eq 'customer') ? "AR" : "AP");
1357 if (@{ $form->{all_departments} }) {
1358 $form->{selectdepartment} = "<option>\n";
1361 $form->{selectdepartment} .=
1362 "<option>$_->{description}--$_->{id}</option>\n"
1363 } (@{ $form->{all_departments} });
1368 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1369 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1371 | if $form->{selectdepartment};
1374 if (($form->{"type"} eq "sales_order") ||
1375 ($form->{"type"} eq "purchase_order")) {
1378 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1379 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1380 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1381 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1386 # use JavaScript Calendar or not
1387 $form->{jsscript} = 1;
1391 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1392 <input type=button name=transdatefrom id="trigger3" value=|
1393 . $locale->text('button') . qq|></td>
1396 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1397 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1398 . $locale->text('button') . qq|></td>
1403 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1404 "transdateto", "BL", "trigger4");
1406 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1408 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1410 "employees" => "ALL_EMPLOYEES",
1411 $vc => "ALL_" . uc($vc));
1415 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1416 push(@values, $item->{"id"});
1417 $labels{$item->{"id"}} = $item->{"projectnumber"};
1420 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1421 '-labels' => \%labels));
1426 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
1427 push(@values, $item->{"id"});
1428 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
1431 my $employee_block = qq|
1433 <th align="right">| . $locale->text('Employee') . qq|</th>
1435 NTI($cgi->popup_menu('-name' => 'employee_id',
1436 '-values' => \@values,
1437 '-labels' => \%labels)) . qq|
1444 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1445 push(@values, $item->{name}.qq|--|.$item->{"id"});
1446 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
1449 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1451 $myconfig{vclimit} <= scalar(@values)
1452 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
1453 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1454 '-default' => $form->{"old$form->{vc}"},
1455 '-onChange' => 'document.getElementById(\'update_button\').click();',
1456 '-values' => \@values,
1457 '-labels' => \%labels));
1463 <form method=post action=$form->{script}>
1467 <th class=listtop>$form->{title}</th>
1469 <tr height="5"></tr>
1474 <th align=right>$vc_label</th>
1475 <td colspan=3>$vc</td>
1479 <th align=right>$ordlabel</th>
1480 <td colspan=3><input name="$ordnumber" size=20></td>
1484 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1485 <td colspan="3"><input name="transaction_description" size=20></td>
1488 <th align="right">| . $locale->text("Project Number") . qq|</th>
1489 <td colspan="3">$projectnumber</td>
1492 <th align=right>| . $locale->text('From') . qq|</th>
1494 <th align=right>| . $locale->text('Bis') . qq|</th>
1497 <input type=hidden name=sort value=transdate>
1499 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1503 <td><input type="checkbox" name="open" value="1" id="open" checked>
1504 <label for="open">| . $locale->text("Open") . qq|</td>
1505 <td><input type="checkbox" name="closed" value="1" id="closed">
1506 <label for="closed">| . $locale->text("Closed") . qq|</td>
1510 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1511 | . $locale->text('ID') . qq|</td>
1512 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1513 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1514 . $locale->text('Date') . qq|</td>
1515 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1516 . $locale->text('Required by') . qq|</td>
1519 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vc_label</td>
1520 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1521 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1522 . $locale->text('Ship via') . qq|</td>
1523 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1526 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1527 . $locale->text('Amount') . qq|</td>
1528 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1529 . $locale->text('Tax') . qq|</td>
1530 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1531 . $locale->text('Total') . qq|</td>
1534 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1535 . $locale->text('Project Number') . qq|</td>
1536 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1537 . $locale->text('Transaction description') . qq|</td>
1540 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1541 . $locale->text('Subtotal') . qq|</td>
1549 <tr><td colspan=4><hr size=3 noshade></td></tr>
1555 <input type=hidden name=nextsub value=orders>
1556 <input type=hidden name=login value=$form->{login}>
1557 <input type=hidden name=password value=$form->{password}>
1558 <input type=hidden name=vc value=$form->{vc}>
1559 <input type=hidden name=type value=$form->{type}>
1561 <input class=submit type=submit name=action value="|
1562 . $locale->text('Continue') . qq|">
1569 $lxdebug->leave_sub();
1573 $lxdebug->enter_sub();
1575 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1579 qw(type vc login password transdatefrom transdateto
1580 open closed notdelivered delivered department
1581 transaction_description);
1582 push @fields, $form->{vc};
1583 $href = "$form->{script}?action=orders&"
1584 . join("&", map { "${_}=" . E($form->{$_}) } @fields)
1585 . "&${ordnumber}=" . E($form->{$ordnumber});
1588 # split vendor / customer
1589 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1590 split(/--/, $form->{ $form->{vc} });
1592 OE->transactions(\%myconfig, \%$form);
1595 "transdate", "reqdate",
1597 "name", "netamount",
1600 "shipvia", "globalprojectnumber",
1601 "transaction_description", "open",
1602 "closed", "delivered"
1605 $form->{l_open} = $form->{l_closed} = "Y"
1606 if ($form->{open} && $form->{closed});
1608 $form->{"l_delivered"} = "Y"
1609 if ($form->{"delivered"} && $form->{"notdelivered"});
1611 foreach $item (@columns) {
1612 if ($form->{"l_$item"} eq "Y") {
1613 push @column_index, $item;
1615 # add column to href and callback
1616 $callback .= "&l_$item=Y";
1617 $href .= "&l_$item=Y";
1621 # only show checkboxes if gotten here via sales_order form.
1622 if ($form->{type} =~ /sales_order/) {
1623 unshift @column_index, "ids";
1626 if ($form->{l_subtotal} eq 'Y') {
1627 $callback .= "&l_subtotal=Y";
1628 $href .= "&l_subtotal=Y";
1631 if ($form->{vc} eq 'vendor') {
1632 if ($form->{type} eq 'purchase_order') {
1633 $form->{title} = $locale->text('Purchase Orders');
1635 $form->{title} = $locale->text('Request for Quotations');
1637 $name = $locale->text('Vendor');
1638 $employee = $locale->text('Employee');
1640 if ($form->{vc} eq 'customer') {
1641 if ($form->{type} eq 'sales_order') {
1642 $form->{title} = $locale->text('Sales Orders');
1644 $form->{title} = $locale->text('Quotations');
1646 $employee = $locale->text('Employee');
1647 $name = $locale->text('Customer');
1650 $column_header{id} =
1651 qq|<th><a class=listheading href=$href&sort=id>|
1652 . $locale->text('ID')
1654 $column_header{transdate} =
1655 qq|<th><a class=listheading href=$href&sort=transdate>|
1656 . $locale->text('Date')
1658 $column_header{reqdate} =
1659 qq|<th><a class=listheading href=$href&sort=reqdate>|
1660 . $locale->text('Required by')
1662 $column_header{ordnumber} =
1663 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1664 . $locale->text('Order')
1666 $column_header{quonumber} =
1667 qq|<th><a class=listheading href=$href&sort=quonumber>|
1668 . ($form->{"type"} eq "request_quotation" ?
1669 $locale->text('RFQ') :
1670 $locale->text('Quotation'))
1672 $column_header{name} =
1673 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1674 $column_header{netamount} =
1675 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1676 $column_header{tax} =
1677 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1678 $column_header{amount} =
1679 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1680 $column_header{curr} =
1681 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1682 $column_header{shipvia} =
1683 qq|<th><a class=listheading href=$href&sort=shipvia>|
1684 . $locale->text('Ship via')
1686 $column_header{globalprojectnumber} =
1687 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1688 $column_header{open} =
1689 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1690 $column_header{closed} =
1691 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1692 $column_header{"delivered"} =
1693 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1695 $column_header{employee} =
1696 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1697 $column_header{transaction_description} =
1698 qq|<th><a class=listheading href="$href&sort=transaction_description">|
1699 . $locale->text("Transaction description") . qq|</a></th>|;
1701 $column_header{ids} = qq|<th></th>|;
1703 if ($form->{ $form->{vc} }) {
1704 $option = $locale->text(ucfirst $form->{vc});
1705 $option .= " : $form->{$form->{vc}}";
1707 if ($form->{department}) {
1708 $option .= "\n<br>" if ($option);
1709 ($department) = split /--/, $form->{department};
1710 $option .= $locale->text('Department') . " : $department";
1712 if ($form->{transdatefrom}) {
1714 . $locale->text('From') . " "
1715 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1717 if ($form->{transdateto}) {
1719 . $locale->text('Bis') . " "
1720 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1722 if ($form->{open}) {
1723 $option .= "\n<br>" if ($option);
1724 $option .= $locale->text('Open');
1726 if ($form->{closed}) {
1727 $option .= "\n<br>" if ($option);
1728 $option .= $locale->text('Closed');
1736 <form method="post" action="oe.pl">
1739 <th class=listtop>$form->{title}</th>
1741 <tr height="5"></tr>
1748 <tr class=listheading>|;
1750 map { print "\n$column_header{$_}" } @column_index;
1756 # add sort and escape callback
1757 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1759 if (@{ $form->{OE} }) {
1760 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1765 foreach $oe (@{ $form->{OE} }) {
1766 $form->{rowcount} = ++$j;
1768 if ($form->{l_subtotal} eq 'Y') {
1769 if ($sameitem ne $oe->{ $form->{sort} }) {
1771 $sameitem = $oe->{ $form->{sort} };
1775 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1777 $column_data{netamount} =
1779 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1781 $column_data{tax} = "<td align=right>"
1782 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1785 $column_data{amount} =
1787 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1789 $totalnetamount += $oe->{netamount};
1790 $totalamount += $oe->{amount};
1792 $subtotalnetamount += $oe->{netamount};
1793 $subtotalamount += $oe->{amount};
1796 qq|<td><input name="multi_id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1797 $column_data{id} = "<td>$oe->{id}</td>";
1798 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1799 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1801 $column_data{$ordnumber} =
1802 "<td><a href=oe.pl?action=$action&type=$form->{type}&id=$oe->{id}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback_escaped>$oe->{$ordnumber}</a></td>";
1803 $column_data{name} = "<td>$oe->{name}</td>";
1805 $column_data{employee} = "<td>$oe->{employee} </td>";
1806 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1807 $column_data{globalprojectnumber} = "<td>" . H($oe->{globalprojectnumber}) . "</td>";
1809 if ($oe->{closed}) {
1810 $column_data{closed} = "<td align=center>X</td>";
1811 $column_data{open} = "<td> </td>";
1813 $column_data{closed} = "<td> </td>";
1814 $column_data{open} = "<td align=center>X</td>";
1816 $column_data{"delivered"} = "<td>" .
1817 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1819 $column_data{transaction_description} = "<td>" . H($oe->{transaction_description}) . "</td>";
1824 <tr class=listrow$i>";
1826 map { print "\n$column_data{$_}" } @column_index;
1834 if ($form->{l_subtotal} eq 'Y') {
1840 <tr class=listtotal>|;
1842 map { $column_data{$_} = "<td> </td>" } @column_index;
1844 $column_data{netamount} =
1845 "<th class=listtotal align=right>"
1846 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1847 $column_data{tax} = "<th class=listtotal align=right>"
1848 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1851 $column_data{amount} =
1852 "<th class=listtotal align=right>"
1853 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1855 map { print "\n$column_data{$_}" } @column_index;
1863 <td><hr size=3 noshade></td>
1867 # multiple invoice edit button only if gotten there via sales_order form.
1869 if ($form->{type} =~ /sales_order/) {
1871 <input class"submit" type="submit" name="action" value="|
1872 . $locale->text('Continue') . qq|">
1873 <input type="hidden" name="nextsub" value="edit">
1874 <input type="hidden" name="type" value="$form->{type}">
1875 <input type="hidden" name="vc" value="$form->{vc}">
1876 <input type="hidden" name="login" value="$form->{login}">
1877 <input type="hidden" name="password" value="$form->{password}">
1878 <input type="hidden" name="callback" value="$callback">
1879 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1886 <form method=post action=$form->{script}>
1888 <input name=callback type=hidden value="$form->{callback}">
1890 <input type=hidden name=type value=$form->{type}>
1891 <input type=hidden name=vc value=$form->{vc}>
1893 <input type=hidden name=login value=$form->{login}>
1894 <input type=hidden name=password value=$form->{password}>
1902 $lxdebug->leave_sub();
1906 $lxdebug->enter_sub();
1908 map { $column_data{$_} = "<td> </td>" } @column_index;
1910 $column_data{netamount} =
1911 "<th class=listsubtotal align=right>"
1912 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1914 $column_data{tax} = "<td class=listsubtotal align=right>"
1915 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1918 $column_data{amount} =
1919 "<th class=listsubtotal align=right>"
1920 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1922 $subtotalnetamount = 0;
1923 $subtotalamount = 0;
1926 <tr class=listsubtotal>
1929 map { print "\n$column_data{$_}" } @column_index;
1935 $lxdebug->leave_sub();
1938 sub save_and_close {
1939 $lxdebug->enter_sub();
1941 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1944 if ($form->{type} =~ /_order$/) {
1945 $form->isblank("transdate", $locale->text('Order Date missing!'));
1947 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1950 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1951 $form->{$idx} =~ s/^\s*//g;
1952 $form->{$idx} =~ s/\s*$//g;
1954 $msg = ucfirst $form->{vc};
1955 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1957 # $locale->text('Customer missing!');
1958 # $locale->text('Vendor missing!');
1960 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1961 if ($form->{currency} ne $form->{defaultcurrency});
1965 if($form->{payment_id}) {
1966 $payment_id = $form->{payment_id};
1969 # if the name changed get new values
1970 if (&check_name($form->{vc})) {
1971 if($form->{payment_id} eq "") {
1972 $form->{payment_id} = $payment_id;
1978 $form->{id} = 0 if $form->{saveasnew};
1980 # this is for the internal notes section for the [email] Subject
1981 if ($form->{type} =~ /_order$/) {
1982 if ($form->{type} eq 'sales_order') {
1983 $form->{label} = $locale->text('Sales Order');
1985 $numberfld = "sonumber";
1986 $ordnumber = "ordnumber";
1988 $form->{label} = $locale->text('Purchase Order');
1990 $numberfld = "ponumber";
1991 $ordnumber = "ordnumber";
1994 $err = $locale->text('Cannot save order!');
1997 if ($form->{type} eq 'sales_quotation') {
1998 $form->{label} = $locale->text('Quotation');
2000 $numberfld = "sqnumber";
2001 $ordnumber = "quonumber";
2003 $form->{label} = $locale->text('Request for Quotation');
2005 $numberfld = "rfqnumber";
2006 $ordnumber = "quonumber";
2009 $err = $locale->text('Cannot save quotation!');
2013 # get new number in sequence if no number is given or if saveasnew was requested
2014 if (!$form->{$ordnumber} || $form->{saveasnew}) {
2015 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
2020 $form->error($err) if (!OE->save(\%myconfig, \%$form));
2022 # saving the history
2023 if(!exists $form->{addition}) {
2024 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2025 $form->{addition} = "SAVED";
2026 $form->save_history($form->dbconnect(\%myconfig));
2028 # /saving the history
2030 $form->redirect($form->{label} . " $form->{$ordnumber} " .
2031 $locale->text('saved!'));
2033 $lxdebug->leave_sub();
2037 $lxdebug->enter_sub();
2039 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
2042 if ($form->{type} =~ /_order$/) {
2043 $form->isblank("transdate", $locale->text('Order Date missing!'));
2045 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2048 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2049 $form->{$idx} =~ s/^\s*//g;
2050 $form->{$idx} =~ s/\s*$//g;
2052 $msg = ucfirst $form->{vc};
2053 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
2055 # $locale->text('Customer missing!');
2056 # $locale->text('Vendor missing!');
2058 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
2059 if ($form->{currency} ne $form->{defaultcurrency});
2063 if($form->{payment_id}) {
2064 $payment_id = $form->{payment_id};
2067 # if the name changed get new values
2068 if (&check_name($form->{vc})) {
2069 if($form->{payment_id} eq "") {
2070 $form->{payment_id} = $payment_id;
2076 $form->{id} = 0 if $form->{saveasnew};
2078 # this is for the internal notes section for the [email] Subject
2079 if ($form->{type} =~ /_order$/) {
2080 if ($form->{type} eq 'sales_order') {
2081 $form->{label} = $locale->text('Sales Order');
2083 $numberfld = "sonumber";
2084 $ordnumber = "ordnumber";
2086 $form->{label} = $locale->text('Purchase Order');
2088 $numberfld = "ponumber";
2089 $ordnumber = "ordnumber";
2092 $err = $locale->text('Cannot save order!');
2095 if ($form->{type} eq 'sales_quotation') {
2096 $form->{label} = $locale->text('Quotation');
2098 $numberfld = "sqnumber";
2099 $ordnumber = "quonumber";
2101 $form->{label} = $locale->text('Request for Quotation');
2103 $numberfld = "rfqnumber";
2104 $ordnumber = "quonumber";
2107 $err = $locale->text('Cannot save quotation!');
2111 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
2112 unless $form->{$ordnumber};
2116 OE->save(\%myconfig, \%$form);
2118 # saving the history
2119 if(!exists $form->{addition}) {
2120 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2121 $form->{addition} = "SAVED";
2122 $form->save_history($form->dbconnect(\%myconfig));
2124 # /saving the history
2126 $form->{simple_save} = 1;
2127 if(!$form->{print_and_save}) {
2128 set_headings("edit");
2132 $lxdebug->leave_sub();
2136 $lxdebug->enter_sub();
2140 if ($form->{type} =~ /_order$/) {
2141 $msg = $locale->text('Are you sure you want to delete Order Number');
2142 $ordnumber = 'ordnumber';
2144 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2145 $ordnumber = 'quonumber';
2151 <form method=post action=$form->{script}>
2154 # delete action variable
2155 map { delete $form->{$_} } qw(action header);
2157 foreach $key (keys %$form) {
2158 $form->{$key} =~ s/\"/"/g;
2159 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2163 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2165 <h4>$msg $form->{$ordnumber}</h4>
2167 <input type="hidden" name="yes_nextsub" value="delete_order_quotation">
2168 <input name=action class=submit type=submit value="|
2169 . $locale->text('Yes') . qq|">
2170 <input name=action class=submit type=submit onclick="history.back()" value="|
2171 . $locale->text('No') . qq|">
2178 $lxdebug->leave_sub();
2181 sub delete_order_quotation {
2182 $lxdebug->enter_sub();
2184 if ($form->{type} =~ /_order$/) {
2185 $msg = $locale->text('Order deleted!');
2186 $err = $locale->text('Cannot delete order!');
2188 $msg = $locale->text('Quotation deleted!');
2189 $err = $locale->text('Cannot delete quotation!');
2191 if (OE->delete(\%myconfig, \%$form, $spool)){
2192 # saving the history
2193 if(!exists $form->{addition}) {
2194 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2195 $form->{addition} = "DELETED";
2196 $form->save_history($form->dbconnect(\%myconfig));
2198 # /saving the history
2204 $lxdebug->leave_sub();
2208 $lxdebug->enter_sub();
2210 $form->{old_employee_id} = $form->{employee_id};
2211 $form->{old_salesman_id} = $form->{salesman_id};
2213 if ($form->{type} =~ /_order$/) {
2215 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2216 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2217 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2218 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2219 $form->isblank("transdate", $locale->text('Order Date missing!'))
2220 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2222 # also copy deliverydate from the order
2223 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2224 $form->{orddate} = $form->{transdate};
2226 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2227 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2228 $form->{ordnumber} = "";
2229 $form->{quodate} = $form->{transdate};
2232 if($form->{payment_id}) {
2233 $payment_id = $form->{payment_id};
2236 # if the name changed get new values
2237 if (&check_name($form->{vc})) {
2238 if($form->{payment_id} eq "") {
2239 $form->{payment_id} = $payment_id;
2245 $form->{cp_id} *= 1;
2247 for $i (1 .. $form->{rowcount}) {
2248 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2249 $form->{"${_}_${i}"})
2250 if ($form->{"${_}_${i}"}) }
2251 qw(ship qty sellprice listprice basefactor));
2254 if ( $form->{type} =~ /_order/
2255 && $form->{currency} ne $form->{defaultcurrency}) {
2257 # check if we need a new exchangerate
2258 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2260 $orddate = $form->current_date(\%myconfig);
2262 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2264 print(STDERR "CURRENCY $form->{currency} DEFAULT: $form->{defaultcurrency} EXCHANGE $exchangerate\n");
2266 if (!$exchangerate) {
2267 &backorder_exchangerate($orddate, $buysell);
2272 # close orders/quotations
2273 $form->{closed} = 1;
2275 # save order if one ordnumber has been given
2276 # if not it's most likely a collective order, which can't be saved back
2277 # so they just have to be closed
2278 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2279 OE->close_order(\%myconfig, \%$form);
2281 OE->close_orders(\%myconfig, \%$form);
2284 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2286 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2289 $form->{closed} = 0;
2290 $form->{rowcount}--;
2291 $form->{shipto} = 1;
2293 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
2295 if ($form->{type} =~ /_order$/) {
2296 $form->{exchangerate} = $exchangerate;
2300 if ( $form->{type} eq 'purchase_order'
2301 || $form->{type} eq 'request_quotation') {
2302 $form->{title} = $locale->text('Add Vendor Invoice');
2303 $form->{script} = 'ir.pl';
2307 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2308 $form->{title} = $locale->text('Add Sales Invoice');
2309 $form->{script} = 'is.pl';
2314 # bo creates the id, reset it
2315 map { delete $form->{$_} }
2316 qw(id subject message cc bcc printed emailed queued);
2317 $form->{ $form->{vc} } =~ s/--.*//g;
2318 $form->{type} = "invoice";
2321 $locale = new Locale "$myconfig{countrycode}", "$script";
2323 require "bin/mozilla/$form->{script}";
2325 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2327 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2328 qw(creditlimit creditremaining);
2330 $currency = $form->{currency};
2333 $form->{currency} = $currency;
2334 $form->{exchangerate} = "";
2335 $form->{forex} = "";
2336 $form->{exchangerate} = $exchangerate
2340 $form->check_exchangerate(
2341 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2344 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2349 for $i (1 .. $form->{rowcount}) {
2350 $form->{"discount_$i"} =
2351 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2353 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2355 $decimalplaces = ($dec > 2) ? $dec : 2;
2357 # copy delivery date from reqdate for order -> invoice conversion
2358 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2359 unless $form->{"deliverydate_$i"};
2361 $form->{"sellprice_$i"} =
2362 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2365 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2366 $dec_qty = length $dec_qty;
2368 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2370 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2371 qw(partnumber description unit);
2377 $lxdebug->leave_sub();
2380 sub backorder_exchangerate {
2381 $lxdebug->enter_sub();
2382 my ($orddate, $buysell) = @_;
2389 <form method=post action=$form->{script}>
2392 # delete action variable
2393 map { delete $form->{$_} } qw(action header exchangerate);
2395 foreach $key (keys %$form) {
2396 $form->{$key} =~ s/\"/"/g;
2397 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2400 $form->{title} = $locale->text('Add Exchangerate');
2404 <input type=hidden name=login value=$form->{login}>
2405 <input type=hidden name=password value=$form->{password}>
2407 <input type=hidden name=exchangeratedate value=$orddate>
2408 <input type=hidden name=buysell value=$buysell>
2411 <tr><th class=listtop>$form->{title}</th></tr>
2412 <tr height="5"></tr>
2417 <th align=right>| . $locale->text('Currency') . qq|</th>
2418 <td>$form->{currency}</td>
2421 <th align=right>| . $locale->text('Date') . qq|</th>
2425 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2426 <td><input name=exchangerate size=11></td>
2436 <input type=hidden name=nextsub value=save_exchangerate>
2438 <input name=action class=submit type=submit value="|
2439 . $locale->text('Continue') . qq|">
2447 $lxdebug->leave_sub();
2450 sub save_exchangerate {
2451 $lxdebug->enter_sub();
2453 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2454 $form->{exchangerate} =
2455 $form->parse_amount(\%myconfig, $form->{exchangerate});
2456 $form->save_exchangerate(\%myconfig, $form->{currency},
2457 $form->{exchangeratedate},
2458 $form->{exchangerate}, $form->{buysell});
2462 $lxdebug->leave_sub();
2465 sub create_backorder {
2466 $lxdebug->enter_sub();
2468 $form->{shipped} = 1;
2470 # figure out if we need to create a backorder
2471 # items aren't saved if qty != 0
2473 for $i (1 .. $form->{rowcount}) {
2474 $totalqty += $qty = $form->{"qty_$i"};
2475 $totalship += $ship = $form->{"ship_$i"};
2477 $form->{"qty_$i"} = $qty - $ship;
2480 if ($totalship == 0) {
2481 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2482 $form->{ordtotal} = 0;
2483 $form->{shipped} = 0;
2487 if ($totalqty == $totalship) {
2488 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2489 $form->{ordtotal} = 0;
2494 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2497 for $i (1 .. $form->{rowcount}) {
2499 $form->{"${_}_$i"} =
2500 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2501 } qw(sellprice discount);
2506 OE->save(\%myconfig, \%$form);
2508 # rebuild rows for invoice
2512 for $i (1 .. $form->{rowcount}) {
2513 $form->{"qty_$i"} = $form->{"ship_$i"};
2515 if ($form->{"qty_$i"}) {
2518 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2523 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2524 $form->{rowcount} = $count;
2526 $lxdebug->leave_sub();
2530 $lxdebug->enter_sub();
2532 $form->{saveasnew} = 1;
2533 $form->{closed} = 0;
2534 map { delete $form->{$_} } qw(printed emailed queued);
2536 # Let Lx-Office assign a new order number if the user hasn't changed the
2537 # previous one. If it has been changed manually then use it as-is.
2538 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2539 $form->{$idx} =~ s/^\s*//g;
2540 $form->{$idx} =~ s/\s*$//g;
2541 if ($form->{saved_xyznumber} &&
2542 ($form->{saved_xyznumber} eq $form->{$idx})) {
2543 delete($form->{$idx});
2548 $lxdebug->leave_sub();
2551 sub check_for_direct_delivery_yes {
2552 $lxdebug->enter_sub();
2554 $form->{direct_delivery_checked} = 1;
2555 delete @{$form}{grep /^shipto/, keys %{ $form }};
2556 map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
2557 $form->{shipto} = 1;
2559 $lxdebug->leave_sub();
2562 sub check_for_direct_delivery_no {
2563 $lxdebug->enter_sub();
2565 $form->{direct_delivery_checked} = 1;
2566 delete @{$form}{grep /^shipto/, keys %{ $form }};
2569 $lxdebug->leave_sub();
2572 sub check_for_direct_delivery {
2573 $lxdebug->enter_sub();
2575 if ($form->{direct_delivery_checked}
2576 || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
2577 $lxdebug->leave_sub();
2581 if ($form->{shipto_id}) {
2582 Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_");
2585 map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form };
2588 delete $form->{action};
2589 $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ref $_ eq "" } keys %{ $form } ];
2592 print $form->parse_html_template("oe/check_for_direct_delivery");
2594 $lxdebug->leave_sub();
2599 sub purchase_order {
2600 $lxdebug->enter_sub();
2602 if ($form->{type} eq 'sales_order') {
2603 check_for_direct_delivery();
2606 if ( $form->{type} eq 'sales_quotation'
2607 || $form->{type} eq 'request_quotation') {
2608 OE->close_order(\%myconfig, \%$form);
2611 if ($form->{type} =~ /^sales_/) {
2612 delete($form->{ordnumber});
2615 $form->{cp_id} *= 1;
2617 $form->{title} = $locale->text('Add Purchase Order');
2618 $form->{vc} = "vendor";
2619 $form->{type} = "purchase_order";
2623 $lxdebug->leave_sub();
2627 $lxdebug->enter_sub();
2629 if ( $form->{type} eq 'sales_quotation'
2630 || $form->{type} eq 'request_quotation') {
2631 OE->close_order(\%myconfig, $form);
2634 if ($form->{type} eq "purchase_order") {
2635 delete($form->{ordnumber});
2638 $form->{cp_id} *= 1;
2640 $form->{title} = $locale->text('Add Sales Order');
2641 $form->{vc} = "customer";
2642 $form->{type} = "sales_order";
2646 $lxdebug->leave_sub();
2650 $lxdebug->enter_sub();
2652 $form->{transdate} = $form->current_date(\%myconfig);
2653 delete $form->{duedate};
2655 $form->{closed} = 0;
2657 $form->{old_employee_id} = $form->{employee_id};
2658 $form->{old_salesman_id} = $form->{salesman_id};
2661 map { delete $form->{$_} }
2662 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2664 for $i (1 .. $form->{rowcount}) {
2665 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2666 $form->{"${_}_${i}"})
2667 if ($form->{"${_}_${i}"}) }
2668 qw(ship qty sellprice listprice basefactor));
2676 for $i (1 .. $form->{rowcount} - 1) {
2677 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2678 qw(partnumber description unit);
2681 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2682 qw(creditlimit creditremaining);
2686 $lxdebug->leave_sub();
2690 $lxdebug->enter_sub();
2692 $form->{print_and_save} = 1;
2697 my $saved_form = save_form();
2702 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2703 restore_form($saved_form);
2704 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2709 $lxdebug->leave_sub();
2713 call_sub($form->{yes_nextsub});
2717 call_sub($form->{no_nextsub});