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 map { $form->{$_} =~ s/\"/"/g }
335 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
336 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
337 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
339 # use JavaScript Calendar or not
340 $form->{jsscript} = 1;
344 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\">
345 <input type=button name=transdate id="trigger1" value=|
346 . $locale->text('button') . qq|></td>
349 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\">
350 <input type=button name=reqdate name=reqdate id="trigger2" value=|
351 . $locale->text('button') . qq|></td>
356 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
357 "reqdate", "BL", "trigger2");
361 if (($form->{"type"} eq "sales_order") ||
362 ($form->{"type"} eq "purchase_order")) {
364 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
365 <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
370 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
371 <label for="closed">| . $locale->text('Closed') . qq|</label>|);
377 <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
383 # set option selected
384 foreach $item ($form->{vc}, currency, department, ($form->{vc} eq "customer" ? customer : vendor)) {
385 $form->{"select$item"} =~ s/ selected//;
386 $form->{"select$item"} =~
387 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
390 #quote select[customer|vendor] Bug 133
391 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
393 #substitute \n and \r to \s (bug 543)
394 $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
396 my @old_project_ids = ($form->{"globalproject_id"});
397 map({ push(@old_project_ids, $form->{"project_id_$_"})
398 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
400 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
401 $form->get_lists("contacts" => "ALL_CONTACTS",
402 "shipto" => "ALL_SHIPTO",
403 "projects" => { "key" => "ALL_PROJECTS",
405 "old_id" => \@old_project_ids },
406 "employees" => "ALL_EMPLOYEES",
407 "salesmen" => "ALL_SALESMEN",
408 "taxzones" => "ALL_TAXZONES",
409 "payments" => "ALL_PAYMENTS",
410 "currencies" => "ALL_CURRENCIES",
411 $vc => "ALL_" . uc($vc));
414 my @values = (undef);
415 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
416 push(@values, $item->{"cp_id"});
417 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
418 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
422 if (scalar @values > 1) {
425 <th align="right">| . $locale->text('Contact Person') . qq|</th>
427 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
428 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
437 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
438 push(@values, $item->{"name"}.qq|--|.$item->{"id"});
439 $labels{$item->{"name"}.qq|--|.$item->{"id"}} = $item->{name};
443 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
444 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
445 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
447 (($myconfig{vclimit} <= scalar(@values))
448 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
449 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
450 '-onChange' => 'document.getElementById(\'update_button\').click();',
451 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
452 <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
453 </td><input type=hidden name="select$form->{vc}" value="| .
454 Q($form->{"select$form->{vc}"}) . qq|">|;
458 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
459 push(@values, $item->{"id"});
460 $labels{$item->{"id"}} = $item->{"description"};
464 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
466 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
467 '-labels' => \%labels, '-default' => $form->{payment_id}))
472 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
473 push(@values, $item->{"shipto_id"});
474 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
478 if (scalar @values > 1) {
481 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
483 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
484 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
490 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
491 push(@values, $item->{"id"});
492 $labels{$item->{"id"}} = $item->{"projectnumber"};
494 my $globalprojectnumber =
495 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
496 '-labels' => \%labels,
497 '-default' => $form->{"globalproject_id"}));
502 if ($form->{type} =~ /^sales_/) {
503 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
504 push(@values, $item->{"id"});
505 $labels{$item->{"id"}} = ($item->{"name"} ne "" ? $item->{"name"} : $item->{"login"});
509 <th align="right">| . $locale->text('Salesman') . qq|</th>
511 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
512 '-values' => \@values, '-labels' => \%labels))
519 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
520 push(@values, $item->{"id"});
521 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
526 <th align="right">| . $locale->text('Employee') . qq|</th>
528 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
529 '-values' => \@values, '-labels' => \%labels)) . qq|
535 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
536 push(@values, $item->{"id"});
537 $labels{$item->{"id"}} = $item->{"description"};
542 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
544 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
545 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
552 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
553 push(@values, $item);
554 $labels{$item} = $item;
557 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
559 if (scalar @values) {
562 <th align="right">| . $locale->text('Currency') . qq|</th>
564 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
565 '-values' => \@values, '-labels' => \%labels)) . qq|
570 $form->{exchangerate} =
571 $form->format_amount(\%myconfig, $form->{exchangerate});
573 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
579 $form->{creditlimit} =
580 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
581 $form->{creditremaining} =
582 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
585 <input type=hidden name=forex value=$form->{forex}>
588 if ($form->{currency} ne $form->{defaultcurrency}) {
589 if ($form->{forex}) {
592 . $locale->text('Exchangerate')
593 . qq|</th><td>$form->{exchangerate}</td>
594 <input type=hidden name=exchangerate value=$form->{exchangerate}>
599 . $locale->text('Exchangerate')
600 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
604 if ($form->{business}) {
607 <th align="right">| . ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type')) . qq|</th>
608 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
609 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
615 if ($form->{max_dunning_level}) {
618 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
620 <b>$form->{max_dunning_level}</b>;
621 | . $locale->text('Dunning Amount') . qq|: <b>|
622 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
629 if ($form->{type} !~ /_quotation$/) {
632 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
633 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
636 <th width=70% align=right nowrap>|
637 . $locale->text('Quotation Number') . qq|</th>
638 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
641 <th width=70% align=right nowrap>|
642 . $locale->text('Customer Order Number') . qq|</th>
643 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
646 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
651 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
656 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
658 $creditremaining = qq|
661 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
662 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
668 ($form->{type} eq 'sales_quotation')
669 ? $locale->text('Valid until')
670 : $locale->text('Required by');
671 if ($form->{type} eq 'sales_quotation') {
674 <th width=70% align=right nowrap>|
675 . $locale->text('Quotation Number') . qq|</th>
676 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
677 <input type=hidden name=ordnumber value="$form->{ordnumber}">
683 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
684 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
685 <input type=hidden name=ordnumber value="$form->{ordnumber}">
693 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
697 <th align=right nowrap=true>$reqlabel</th>
701 $creditremaining = qq| <tr>
709 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
710 <td colspan=3><select name=department style="width: 250px">$form->{selectdepartment}</select>
711 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
713 </tr> | if $form->{selectdepartment};
715 if ($form->{type} eq 'sales_order') {
716 if ($form->{selectemployee}) {
718 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
722 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
724 if ($form->{resubmit} && ($form->{format} eq "html")) {
726 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
727 } elsif ($form->{resubmit}) {
728 $onload = qq|document.oe.submit()|;
733 $credittext = $locale->text('Credit Limit exceeded!!!');
734 if ($creditwarning) {
735 $onload = qq|alert('$credittext')|;
738 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
739 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
741 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
742 # show history button js
743 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
744 #/show history button js
745 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
750 <body onLoad="$onload">
752 <form method=post name=oe action=$form->{script}>
754 <script type="text/javascript" src="js/common.js"></script>
755 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
756 <script type="text/javascript" src="js/vendor_selection.js"></script>
757 <script type="text/javascript" src="js/calculate_qty.js"></script>
760 $form->hide_form(qw(id action type vc formname media format proforma queued printed emailed
761 title discount creditlimit creditremaining tradediscount business
762 max_dunning_level dunning_amount));
768 <th class=listtop>$form->{title}</th>
790 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
791 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
794 <th align=right>| . $locale->text('Ship via') . qq|</th>
795 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
798 <th align="right">| . $locale->text('Transaction description') . qq|</th>
799 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
806 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
808 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
809 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
813 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
815 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
816 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
830 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
831 <td>$globalprojectnumber</td>
842 <!-- shipto are in hidden variables -->
844 <input type=hidden name=shiptoname value="$form->{shiptoname}">
845 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
846 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
847 <input type=hidden name=shiptocity value="$form->{shiptocity}">
848 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
849 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
850 <input type=hidden name=shiptophone value="$form->{shiptophone}">
851 <input type=hidden name=shiptofax value="$form->{shiptofax}">
852 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
853 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
854 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
856 <!-- email variables -->
857 <input type=hidden name=message value="$form->{message}">
858 <input type=hidden name=email value="$form->{email}">
859 <input type=hidden name=subject value="$form->{subject}">
860 <input type=hidden name=cc value="$form->{cc}">
861 <input type=hidden name=bcc value="$form->{bcc}">
863 <input type=hidden name=taxpart value="$form->{taxpart}">
864 <input type=hidden name=taxservice value="$form->{taxservice}">
866 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
869 foreach $item (split / /, $form->{taxaccounts}) {
871 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
872 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
875 $lxdebug->leave_sub();
879 $lxdebug->enter_sub();
881 $form->{invtotal} = $form->{invsubtotal};
883 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
886 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
889 $rows = ($rows > $introws) ? $rows : $introws;
891 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
893 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
895 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
898 if ($form->{taxaccounts}) {
900 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
901 . $locale->text('Tax Included') . qq|</b><br><br>
905 if (!$form->{taxincluded}) {
907 foreach $item (split / /, $form->{taxaccounts}) {
908 if ($form->{"${item}_base"}) {
909 $form->{invtotal} += $form->{"${item}_total"} =
911 $form->{"${item}_base"} * $form->{"${item}_rate"},
913 $form->{"${item}_total"} =
914 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
918 <th align=right>$form->{"${item}_description"} |
919 . $form->{"${item}_rate"} * 100 .qq|%</th>
920 <td align=right>$form->{"${item}_total"}</td>
926 $form->{invsubtotal} =
927 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
931 <th align=right>| . $locale->text('Subtotal') . qq|</th>
932 <td align=right>$form->{invsubtotal}</td>
938 if ($form->{taxincluded}) {
939 foreach $item (split / /, $form->{taxaccounts}) {
940 if ($form->{"${item}_base"}) {
941 $form->{"${item}_total"} =
943 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
944 (1 + $form->{"${item}_rate"})
947 $form->{"${item}_netto"} =
949 ($form->{"${item}_base"} - $form->{"${item}_total"}),
951 $form->{"${item}_total"} =
952 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
953 $form->{"${item}_netto"} =
954 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
958 <th align=right>Enthaltene $form->{"${item}_description"} |
959 . $form->{"${item}_rate"} * 100 .qq|%</th>
960 <td align=right>$form->{"${item}_total"}</td>
963 <th align=right>Nettobetrag</th>
964 <td align=right>$form->{"${item}_netto"}</td>
972 $form->{oldinvtotal} = $form->{invtotal};
974 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
984 <th align=left>| . $locale->text('Notes') . qq|</th>
985 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
996 <td align=right width=100%>
1002 <th align=right>| . $locale->text('Total') . qq|</th>
1003 <td align=right>$form->{invtotal}</td>
1011 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1012 <input type=hidden name=oldtotalpaid value=$totalpaid>
1014 <td><hr size=3 noshade></td>
1022 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
1025 <td align=left width=30%><b>Dateiname</b></td>
1026 <td align=left width=70%><b>Webdavlink</b></td>
1028 foreach $file (keys %{ $form->{WEBDAV} }) {
1031 <td align=left>$file</td>
1032 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1040 <td><hr size=3 noshade></td>
1058 | . $locale->text("Edit the $form->{type}") . qq|<br>
1059 <input class=submit type=submit name=action id=update_button value="|
1060 . $locale->text('Update') . qq|">
1061 <input class=submit type=submit name=action value="|
1062 . $locale->text('Ship to') . qq|">
1063 <input class=submit type=submit name=action value="|
1064 . $locale->text('Print') . qq|">
1065 <input class=submit type=submit name=action value="|
1066 . $locale->text('E-mail') . qq|">
1067 <input class=submit type=submit name=action value="|
1068 . $locale->text('Save') . qq|">
1069 <input class=submit type=submit name=action value="|
1070 . $locale->text('Save and Close') . qq|">
1073 if (($form->{id})) {
1075 <input type="button" class="submit" onclick="set_history_window(|
1077 . qq|);" name="history" id="history" value="|
1078 . $locale->text('history')
1081 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1082 <input class=submit type=submit name=action value="|
1083 . $locale->text('Save as new') . qq|">
1084 <input class=submit type=submit name=action value="|
1085 . $locale->text('Delete') . qq|">|;
1086 if (($form->{type} =~ /sales_quotation$/)) {
1088 <input class=submit type=submit name=action value="|
1089 . $locale->text('Sales Order') . qq|">|;
1091 if ($form->{type} =~ /request_quotation$/) {
1093 <input class=submit type=submit name=action value="|
1094 . $locale->text('Purchase Order') . qq|">|;
1098 <input class=submit type=submit name=action value="|
1099 . $locale->text('Invoice') . qq|">
1103 if ($form->{type} =~ /sales_order$/) {
1105 <br>$form->{heading} als neue Vorlage verwenden für<br>
1106 <input class=submit type=submit name=action value="|
1107 . $locale->text('Purchase Order') . qq|">
1108 <input class=submit type=submit name=action value="|
1109 . $locale->text('Quotation') . qq|">
1112 } elsif ($form->{type} =~ /purchase_order$/) {
1114 <br>$form->{heading} als neue Vorlage verwenden für<br>
1115 <input class=submit type=submit name=action value="|
1116 . $locale->text('Sales Order') . qq|">
1117 <input class=submit type=submit name=action value="|
1118 . $locale->text('Request for Quotation') . qq|">
1123 <br>$form->{heading} als neue Vorlage verwenden für<br>
1124 <input class=submit type=submit name=action value="|
1125 . $locale->text('Order') . qq|">
1128 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1130 <br>Workflow $form->{heading}<br>
1131 <input class=submit type=submit name=action value="|
1132 . $locale->text('Save as new') . qq|">
1133 <input class=submit type=submit name=action value="|
1134 . $locale->text('Invoice') . qq|">
1138 $form->hide_form("saved_xyznumber");
1142 <input type=hidden name=rowcount value=$form->{rowcount}>
1144 <input name=callback type=hidden value="$form->{callback}">
1146 <input type=hidden name=login value=$form->{login}>
1147 <input type=hidden name=password value=$form->{password}>
1154 $lxdebug->leave_sub();
1158 $lxdebug->enter_sub();
1160 set_headings($form->{"id"} ? "edit" : "add");
1162 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1163 qw(exchangerate creditlimit creditremaining);
1164 $form->{update} = 1;
1166 if($form->{payment_id}) {
1167 $payment_id = $form->{payment_id};
1170 &check_name($form->{vc});
1172 if($form->{payment_id} eq "") {
1173 $form->{payment_id} = $payment_id;
1177 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1178 $form->{exchangerate} = $exchangerate
1182 $form->check_exchangerate(
1183 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1187 $i = $form->{rowcount};
1189 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1191 if ( ($form->{"partnumber_$i"} eq "")
1192 && ($form->{"description_$i"} eq "")
1193 && ($form->{"partsgroup_$i"} eq "")) {
1195 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1200 if ( $form->{type} eq 'purchase_order'
1201 || $form->{type} eq 'request_quotation') {
1202 IR->retrieve_item(\%myconfig, \%$form);
1204 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1205 IS->retrieve_item(\%myconfig, \%$form);
1208 my $rows = scalar @{ $form->{item_list} };
1210 $form->{"discount_$i"} =
1211 $form->format_amount(\%myconfig, $form->{discount} * 100);
1214 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1223 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1224 if ($form->{"not_discountable_$i"}) {
1225 $form->{"discount_$i"} = 0;
1227 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1228 qw(partnumber description unit);
1229 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1230 keys %{ $form->{item_list}[0] };
1231 if ($form->{"part_payment_id_$i"} ne "") {
1232 $form->{payment_id} = $form->{"part_payment_id_$i"};
1235 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1237 ($dec) = ($s =~ /\.(\d+)/);
1239 $decimalplaces = ($dec > 2) ? $dec : 2;
1242 $form->{"sellprice_$i"} = $sellprice;
1245 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1247 # if there is an exchange rate adjust sellprice
1248 $form->{"sellprice_$i"} /= $exchangerate;
1252 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1253 (1 - $form->{"discount_$i"} / 100);
1254 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1255 map { $form->{"${_}_base"} += $amount }
1256 (split / /, $form->{"taxaccounts_$i"});
1257 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1258 split / /, $form->{taxaccounts}
1259 if !$form->{taxincluded};
1261 $form->{creditremaining} -= $amount;
1263 $form->{"sellprice_$i"} =
1264 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1267 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1269 # get pricegroups for parts
1270 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1272 # build up html code for prices_$i
1273 &set_pricegroup($i);
1280 # ok, so this is a new part
1281 # ask if it is a part or service item
1283 if ( $form->{"partsgroup_$i"}
1284 && ($form->{"partsnumber_$i"} eq "")
1285 && ($form->{"description_$i"} eq "")) {
1286 $form->{rowcount}--;
1287 $form->{"discount_$i"} = "";
1291 $form->{"id_$i"} = 0;
1292 $form->{"unit_$i"} = $locale->text('ea');
1300 $lxdebug->leave_sub();
1304 $lxdebug->enter_sub();
1306 if ($form->{type} eq 'purchase_order') {
1307 $form->{title} = $locale->text('Purchase Orders');
1308 $form->{vc} = 'vendor';
1309 $ordlabel = $locale->text('Order Number');
1310 $ordnumber = 'ordnumber';
1311 $employee = $locale->text('Employee');
1314 if ($form->{type} eq 'request_quotation') {
1315 $form->{title} = $locale->text('Request for Quotations');
1316 $form->{vc} = 'vendor';
1317 $ordlabel = $locale->text('RFQ Number');
1318 $ordnumber = 'quonumber';
1319 $employee = $locale->text('Employee');
1322 if ($form->{type} eq 'sales_order') {
1323 $form->{title} = $locale->text('Sales Orders');
1324 $form->{vc} = 'customer';
1325 $ordlabel = $locale->text('Order Number');
1326 $ordnumber = 'ordnumber';
1327 $employee = $locale->text('Employee');
1330 if ($form->{type} eq 'sales_quotation') {
1331 $form->{title} = $locale->text('Quotations');
1332 $form->{vc} = 'customer';
1333 $ordlabel = $locale->text('Quotation Number');
1334 $ordnumber = 'quonumber';
1335 $employee = $locale->text('Employee');
1338 # setup vendor / customer selection
1339 $form->all_vc(\%myconfig, $form->{vc},
1340 ($form->{vc} eq 'customer') ? "AR" : "AP");
1343 if (@{ $form->{all_departments} }) {
1344 $form->{selectdepartment} = "<option>\n";
1347 $form->{selectdepartment} .=
1348 "<option>$_->{description}--$_->{id}</option>\n"
1349 } (@{ $form->{all_departments} });
1354 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1355 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1357 | if $form->{selectdepartment};
1360 if (($form->{"type"} eq "sales_order") ||
1361 ($form->{"type"} eq "purchase_order")) {
1364 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1365 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1366 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1367 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1372 # use JavaScript Calendar or not
1373 $form->{jsscript} = 1;
1377 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1378 <input type=button name=transdatefrom id="trigger3" value=|
1379 . $locale->text('button') . qq|></td>
1382 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1383 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1384 . $locale->text('button') . qq|></td>
1389 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1390 "transdateto", "BL", "trigger4");
1392 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1394 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1396 "employees" => "ALL_EMPLOYEES",
1397 $vc => "ALL_" . uc($vc));
1401 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1402 push(@values, $item->{"id"});
1403 $labels{$item->{"id"}} = $item->{"projectnumber"};
1406 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1407 '-labels' => \%labels));
1412 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
1413 push(@values, $item->{"id"});
1414 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
1417 my $employee_block = qq|
1419 <th align="right">| . $locale->text('Employee') . qq|</th>
1421 NTI($cgi->popup_menu('-name' => 'employee_id',
1422 '-values' => \@values,
1423 '-labels' => \%labels)) . qq|
1430 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1431 push(@values, $item->{name}.qq|--|.$item->{"id"});
1432 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
1435 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1437 $myconfig{vclimit} <= scalar(@values)
1438 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
1439 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1440 '-default' => $form->{"old$form->{vc}"},
1441 '-onChange' => 'document.getElementById(\'update_button\').click();',
1442 '-values' => \@values,
1443 '-labels' => \%labels));
1449 <form method=post action=$form->{script}>
1453 <th class=listtop>$form->{title}</th>
1455 <tr height="5"></tr>
1460 <th align=right>$vc_label</th>
1461 <td colspan=3>$vc</td>
1465 <th align=right>$ordlabel</th>
1466 <td colspan=3><input name="$ordnumber" size=20></td>
1470 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1471 <td colspan="3"><input name="transaction_description" size=20></td>
1474 <th align="right">| . $locale->text("Project Number") . qq|</th>
1475 <td colspan="3">$projectnumber</td>
1478 <th align=right>| . $locale->text('From') . qq|</th>
1480 <th align=right>| . $locale->text('Bis') . qq|</th>
1483 <input type=hidden name=sort value=transdate>
1485 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1489 <td><input type="checkbox" name="open" value="1" id="open" checked>
1490 <label for="open">| . $locale->text("Open") . qq|</td>
1491 <td><input type="checkbox" name="closed" value="1" id="closed">
1492 <label for="closed">| . $locale->text("Closed") . qq|</td>
1496 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1497 | . $locale->text('ID') . qq|</td>
1498 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1499 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1500 . $locale->text('Date') . qq|</td>
1501 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1502 . $locale->text('Required by') . qq|</td>
1505 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vc_label</td>
1506 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1507 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1508 . $locale->text('Ship via') . qq|</td>
1509 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1512 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1513 . $locale->text('Amount') . qq|</td>
1514 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1515 . $locale->text('Tax') . qq|</td>
1516 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1517 . $locale->text('Total') . qq|</td>
1520 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1521 . $locale->text('Project Number') . qq|</td>
1522 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1523 . $locale->text('Transaction description') . qq|</td>
1526 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1527 . $locale->text('Subtotal') . qq|</td>
1535 <tr><td colspan=4><hr size=3 noshade></td></tr>
1541 <input type=hidden name=nextsub value=orders>
1542 <input type=hidden name=login value=$form->{login}>
1543 <input type=hidden name=password value=$form->{password}>
1544 <input type=hidden name=vc value=$form->{vc}>
1545 <input type=hidden name=type value=$form->{type}>
1547 <input class=submit type=submit name=action value="|
1548 . $locale->text('Continue') . qq|">
1555 $lxdebug->leave_sub();
1559 $lxdebug->enter_sub();
1561 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1565 qw(type vc login password transdatefrom transdateto
1566 open closed notdelivered delivered department
1567 transaction_description);
1568 push @fields, $form->{vc};
1569 $href = "$form->{script}?action=orders&"
1570 . join("&", map { "${_}=" . E($form->{$_}) } @fields)
1571 . "&${ordnumber}=" . E($form->{$ordnumber});
1574 # split vendor / customer
1575 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1576 split(/--/, $form->{ $form->{vc} });
1578 OE->transactions(\%myconfig, \%$form);
1581 "transdate", "reqdate",
1583 "name", "netamount",
1586 "shipvia", "globalprojectnumber",
1587 "transaction_description", "open",
1588 "closed", "delivered"
1591 $form->{l_open} = $form->{l_closed} = "Y"
1592 if ($form->{open} && $form->{closed});
1594 $form->{"l_delivered"} = "Y"
1595 if ($form->{"delivered"} && $form->{"notdelivered"});
1597 foreach $item (@columns) {
1598 if ($form->{"l_$item"} eq "Y") {
1599 push @column_index, $item;
1601 # add column to href and callback
1602 $callback .= "&l_$item=Y";
1603 $href .= "&l_$item=Y";
1607 # only show checkboxes if gotten here via sales_order form.
1608 if ($form->{type} =~ /sales_order/) {
1609 unshift @column_index, "ids";
1612 if ($form->{l_subtotal} eq 'Y') {
1613 $callback .= "&l_subtotal=Y";
1614 $href .= "&l_subtotal=Y";
1617 if ($form->{vc} eq 'vendor') {
1618 if ($form->{type} eq 'purchase_order') {
1619 $form->{title} = $locale->text('Purchase Orders');
1621 $form->{title} = $locale->text('Request for Quotations');
1623 $name = $locale->text('Vendor');
1624 $employee = $locale->text('Employee');
1626 if ($form->{vc} eq 'customer') {
1627 if ($form->{type} eq 'sales_order') {
1628 $form->{title} = $locale->text('Sales Orders');
1630 $form->{title} = $locale->text('Quotations');
1632 $employee = $locale->text('Employee');
1633 $name = $locale->text('Customer');
1636 $column_header{id} =
1637 qq|<th><a class=listheading href=$href&sort=id>|
1638 . $locale->text('ID')
1640 $column_header{transdate} =
1641 qq|<th><a class=listheading href=$href&sort=transdate>|
1642 . $locale->text('Date')
1644 $column_header{reqdate} =
1645 qq|<th><a class=listheading href=$href&sort=reqdate>|
1646 . $locale->text('Required by')
1648 $column_header{ordnumber} =
1649 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1650 . $locale->text('Order')
1652 $column_header{quonumber} =
1653 qq|<th><a class=listheading href=$href&sort=quonumber>|
1654 . ($form->{"type"} eq "request_quotation" ?
1655 $locale->text('RFQ') :
1656 $locale->text('Quotation'))
1658 $column_header{name} =
1659 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1660 $column_header{netamount} =
1661 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1662 $column_header{tax} =
1663 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1664 $column_header{amount} =
1665 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1666 $column_header{curr} =
1667 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1668 $column_header{shipvia} =
1669 qq|<th><a class=listheading href=$href&sort=shipvia>|
1670 . $locale->text('Ship via')
1672 $column_header{globalprojectnumber} =
1673 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1674 $column_header{open} =
1675 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1676 $column_header{closed} =
1677 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1678 $column_header{"delivered"} =
1679 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1681 $column_header{employee} =
1682 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1683 $column_header{transaction_description} =
1684 qq|<th><a class=listheading href="$href&sort=transaction_description">|
1685 . $locale->text("Transaction description") . qq|</a></th>|;
1687 $column_header{ids} = qq|<th></th>|;
1689 if ($form->{ $form->{vc} }) {
1690 $option = $locale->text(ucfirst $form->{vc});
1691 $option .= " : $form->{$form->{vc}}";
1693 if ($form->{department}) {
1694 $option .= "\n<br>" if ($option);
1695 ($department) = split /--/, $form->{department};
1696 $option .= $locale->text('Department') . " : $department";
1698 if ($form->{transdatefrom}) {
1700 . $locale->text('From') . " "
1701 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1703 if ($form->{transdateto}) {
1705 . $locale->text('Bis') . " "
1706 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1708 if ($form->{open}) {
1709 $option .= "\n<br>" if ($option);
1710 $option .= $locale->text('Open');
1712 if ($form->{closed}) {
1713 $option .= "\n<br>" if ($option);
1714 $option .= $locale->text('Closed');
1722 <form method="post" action="oe.pl">
1725 <th class=listtop>$form->{title}</th>
1727 <tr height="5"></tr>
1734 <tr class=listheading>|;
1736 map { print "\n$column_header{$_}" } @column_index;
1742 # add sort and escape callback
1743 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1745 if (@{ $form->{OE} }) {
1746 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1751 foreach $oe (@{ $form->{OE} }) {
1752 $form->{rowcount} = ++$j;
1754 if ($form->{l_subtotal} eq 'Y') {
1755 if ($sameitem ne $oe->{ $form->{sort} }) {
1757 $sameitem = $oe->{ $form->{sort} };
1761 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1763 $column_data{netamount} =
1765 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1767 $column_data{tax} = "<td align=right>"
1768 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1771 $column_data{amount} =
1773 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1775 $totalnetamount += $oe->{netamount};
1776 $totalamount += $oe->{amount};
1778 $subtotalnetamount += $oe->{netamount};
1779 $subtotalamount += $oe->{amount};
1782 qq|<td><input name="multi_id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1783 $column_data{id} = "<td>$oe->{id}</td>";
1784 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1785 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1787 $column_data{$ordnumber} =
1788 "<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>";
1789 $column_data{name} = "<td>$oe->{name}</td>";
1791 $column_data{employee} = "<td>$oe->{employee} </td>";
1792 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1793 $column_data{globalprojectnumber} = "<td>" . H($oe->{globalprojectnumber}) . "</td>";
1795 if ($oe->{closed}) {
1796 $column_data{closed} = "<td align=center>X</td>";
1797 $column_data{open} = "<td> </td>";
1799 $column_data{closed} = "<td> </td>";
1800 $column_data{open} = "<td align=center>X</td>";
1802 $column_data{"delivered"} = "<td>" .
1803 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1805 $column_data{transaction_description} = "<td>" . H($oe->{transaction_description}) . "</td>";
1810 <tr class=listrow$i>";
1812 map { print "\n$column_data{$_}" } @column_index;
1820 if ($form->{l_subtotal} eq 'Y') {
1826 <tr class=listtotal>|;
1828 map { $column_data{$_} = "<td> </td>" } @column_index;
1830 $column_data{netamount} =
1831 "<th class=listtotal align=right>"
1832 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1833 $column_data{tax} = "<th class=listtotal align=right>"
1834 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1837 $column_data{amount} =
1838 "<th class=listtotal align=right>"
1839 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1841 map { print "\n$column_data{$_}" } @column_index;
1849 <td><hr size=3 noshade></td>
1853 # multiple invoice edit button only if gotten there via sales_order form.
1855 if ($form->{type} =~ /sales_order/) {
1857 <input class"submit" type="submit" name="action" value="|
1858 . $locale->text('Continue') . qq|">
1859 <input type="hidden" name="nextsub" value="edit">
1860 <input type="hidden" name="type" value="$form->{type}">
1861 <input type="hidden" name="vc" value="$form->{vc}">
1862 <input type="hidden" name="login" value="$form->{login}">
1863 <input type="hidden" name="password" value="$form->{password}">
1864 <input type="hidden" name="callback" value="$callback">
1865 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1872 <form method=post action=$form->{script}>
1874 <input name=callback type=hidden value="$form->{callback}">
1876 <input type=hidden name=type value=$form->{type}>
1877 <input type=hidden name=vc value=$form->{vc}>
1879 <input type=hidden name=login value=$form->{login}>
1880 <input type=hidden name=password value=$form->{password}>
1888 $lxdebug->leave_sub();
1892 $lxdebug->enter_sub();
1894 map { $column_data{$_} = "<td> </td>" } @column_index;
1896 $column_data{netamount} =
1897 "<th class=listsubtotal align=right>"
1898 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1900 $column_data{tax} = "<td class=listsubtotal align=right>"
1901 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1904 $column_data{amount} =
1905 "<th class=listsubtotal align=right>"
1906 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1908 $subtotalnetamount = 0;
1909 $subtotalamount = 0;
1912 <tr class=listsubtotal>
1915 map { print "\n$column_data{$_}" } @column_index;
1921 $lxdebug->leave_sub();
1924 sub save_and_close {
1925 $lxdebug->enter_sub();
1927 if ($form->{type} =~ /_order$/) {
1928 $form->isblank("transdate", $locale->text('Order Date missing!'));
1930 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1933 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1934 $form->{$idx} =~ s/^\s*//g;
1935 $form->{$idx} =~ s/\s*$//g;
1937 $msg = ucfirst $form->{vc};
1938 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1940 # $locale->text('Customer missing!');
1941 # $locale->text('Vendor missing!');
1943 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1944 if ($form->{currency} ne $form->{defaultcurrency});
1948 if($form->{payment_id}) {
1949 $payment_id = $form->{payment_id};
1952 # if the name changed get new values
1953 if (&check_name($form->{vc})) {
1954 if($form->{payment_id} eq "") {
1955 $form->{payment_id} = $payment_id;
1961 $form->{id} = 0 if $form->{saveasnew};
1963 # this is for the internal notes section for the [email] Subject
1964 if ($form->{type} =~ /_order$/) {
1965 if ($form->{type} eq 'sales_order') {
1966 $form->{label} = $locale->text('Sales Order');
1968 $numberfld = "sonumber";
1969 $ordnumber = "ordnumber";
1971 $form->{label} = $locale->text('Purchase Order');
1973 $numberfld = "ponumber";
1974 $ordnumber = "ordnumber";
1977 $err = $locale->text('Cannot save order!');
1980 if ($form->{type} eq 'sales_quotation') {
1981 $form->{label} = $locale->text('Quotation');
1983 $numberfld = "sqnumber";
1984 $ordnumber = "quonumber";
1986 $form->{label} = $locale->text('Request for Quotation');
1988 $numberfld = "rfqnumber";
1989 $ordnumber = "quonumber";
1992 $err = $locale->text('Cannot save quotation!');
1996 # get new number in sequence if no number is given or if saveasnew was requested
1997 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1998 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
2003 $form->error($err) if (!OE->save(\%myconfig, \%$form));
2005 # saving the history
2006 if(!exists $form->{addition}) {
2007 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2008 $form->{addition} = "SAVED";
2009 $form->save_history($form->dbconnect(\%myconfig));
2011 # /saving the history
2013 $form->redirect($form->{label} . " $form->{$ordnumber} " .
2014 $locale->text('saved!'));
2016 $lxdebug->leave_sub();
2020 $lxdebug->enter_sub();
2022 if ($form->{type} =~ /_order$/) {
2023 $form->isblank("transdate", $locale->text('Order Date missing!'));
2025 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2028 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2029 $form->{$idx} =~ s/^\s*//g;
2030 $form->{$idx} =~ s/\s*$//g;
2032 $msg = ucfirst $form->{vc};
2033 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
2035 # $locale->text('Customer missing!');
2036 # $locale->text('Vendor missing!');
2038 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
2039 if ($form->{currency} ne $form->{defaultcurrency});
2043 if($form->{payment_id}) {
2044 $payment_id = $form->{payment_id};
2047 # if the name changed get new values
2048 if (&check_name($form->{vc})) {
2049 if($form->{payment_id} eq "") {
2050 $form->{payment_id} = $payment_id;
2056 $form->{id} = 0 if $form->{saveasnew};
2058 # this is for the internal notes section for the [email] Subject
2059 if ($form->{type} =~ /_order$/) {
2060 if ($form->{type} eq 'sales_order') {
2061 $form->{label} = $locale->text('Sales Order');
2063 $numberfld = "sonumber";
2064 $ordnumber = "ordnumber";
2066 $form->{label} = $locale->text('Purchase Order');
2068 $numberfld = "ponumber";
2069 $ordnumber = "ordnumber";
2072 $err = $locale->text('Cannot save order!');
2075 if ($form->{type} eq 'sales_quotation') {
2076 $form->{label} = $locale->text('Quotation');
2078 $numberfld = "sqnumber";
2079 $ordnumber = "quonumber";
2081 $form->{label} = $locale->text('Request for Quotation');
2083 $numberfld = "rfqnumber";
2084 $ordnumber = "quonumber";
2087 $err = $locale->text('Cannot save quotation!');
2091 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
2092 unless $form->{$ordnumber};
2096 OE->save(\%myconfig, \%$form);
2098 # saving the history
2099 if(!exists $form->{addition}) {
2100 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2101 $form->{addition} = "SAVED";
2102 $form->save_history($form->dbconnect(\%myconfig));
2104 # /saving the history
2106 $form->{simple_save} = 1;
2107 if(!$form->{print_and_save}) {
2108 set_headings("edit");
2112 $lxdebug->leave_sub();
2116 $lxdebug->enter_sub();
2120 if ($form->{type} =~ /_order$/) {
2121 $msg = $locale->text('Are you sure you want to delete Order Number');
2122 $ordnumber = 'ordnumber';
2124 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2125 $ordnumber = 'quonumber';
2131 <form method=post action=$form->{script}>
2134 # delete action variable
2135 map { delete $form->{$_} } qw(action header);
2137 foreach $key (keys %$form) {
2138 $form->{$key} =~ s/\"/"/g;
2139 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2143 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2145 <h4>$msg $form->{$ordnumber}</h4>
2147 <input type="hidden" name="yes_nextsub" value="delete_order_quotation">
2148 <input name=action class=submit type=submit value="|
2149 . $locale->text('Yes') . qq|">
2150 <input name=action class=submit type=submit onclick="history.back()" value="|
2151 . $locale->text('No') . qq|">
2158 $lxdebug->leave_sub();
2161 sub delete_order_quotation {
2162 $lxdebug->enter_sub();
2164 if ($form->{type} =~ /_order$/) {
2165 $msg = $locale->text('Order deleted!');
2166 $err = $locale->text('Cannot delete order!');
2168 $msg = $locale->text('Quotation deleted!');
2169 $err = $locale->text('Cannot delete quotation!');
2171 if (OE->delete(\%myconfig, \%$form, $spool)){
2172 # saving the history
2173 if(!exists $form->{addition}) {
2174 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2175 $form->{addition} = "DELETED";
2176 $form->save_history($form->dbconnect(\%myconfig));
2178 # /saving the history
2184 $lxdebug->leave_sub();
2188 $lxdebug->enter_sub();
2190 $form->{old_employee_id} = $form->{employee_id};
2191 $form->{old_salesman_id} = $form->{salesman_id};
2193 if ($form->{type} =~ /_order$/) {
2195 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2196 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2197 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2198 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2199 $form->isblank("transdate", $locale->text('Order Date missing!'))
2200 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2202 # also copy deliverydate from the order
2203 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2204 $form->{orddate} = $form->{transdate};
2206 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2207 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2208 $form->{ordnumber} = "";
2209 $form->{quodate} = $form->{transdate};
2212 if($form->{payment_id}) {
2213 $payment_id = $form->{payment_id};
2216 # if the name changed get new values
2217 if (&check_name($form->{vc})) {
2218 if($form->{payment_id} eq "") {
2219 $form->{payment_id} = $payment_id;
2225 $form->{cp_id} *= 1;
2227 for $i (1 .. $form->{rowcount}) {
2228 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2229 $form->{"${_}_${i}"})
2230 if ($form->{"${_}_${i}"}) }
2231 qw(ship qty sellprice listprice basefactor));
2234 if ( $form->{type} =~ /_order/
2235 && $form->{currency} ne $form->{defaultcurrency}) {
2237 # check if we need a new exchangerate
2238 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2240 $orddate = $form->current_date(\%myconfig);
2242 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2244 print(STDERR "CURRENCY $form->{currency} DEFAULT: $form->{defaultcurrency} EXCHANGE $exchangerate\n");
2246 if (!$exchangerate) {
2247 &backorder_exchangerate($orddate, $buysell);
2252 # close orders/quotations
2253 $form->{closed} = 1;
2255 # save order if one ordnumber has been given
2256 # if not it's most likely a collective order, which can't be saved back
2257 # so they just have to be closed
2258 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2259 OE->close_order(\%myconfig, \%$form);
2261 OE->close_orders(\%myconfig, \%$form);
2264 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2266 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2269 $form->{closed} = 0;
2270 $form->{rowcount}--;
2271 $form->{shipto} = 1;
2273 if ($form->{type} =~ /_order$/) {
2274 $form->{exchangerate} = $exchangerate;
2278 if ( $form->{type} eq 'purchase_order'
2279 || $form->{type} eq 'request_quotation') {
2280 $form->{title} = $locale->text('Add Vendor Invoice');
2281 $form->{script} = 'ir.pl';
2285 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2286 $form->{title} = $locale->text('Add Sales Invoice');
2287 $form->{script} = 'is.pl';
2292 # bo creates the id, reset it
2293 map { delete $form->{$_} }
2294 qw(id subject message cc bcc printed emailed queued);
2295 $form->{ $form->{vc} } =~ s/--.*//g;
2296 $form->{type} = "invoice";
2299 $locale = new Locale "$myconfig{countrycode}", "$script";
2301 require "bin/mozilla/$form->{script}";
2303 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2305 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2306 qw(creditlimit creditremaining);
2308 $currency = $form->{currency};
2311 $form->{currency} = $currency;
2312 $form->{exchangerate} = "";
2313 $form->{forex} = "";
2314 $form->{exchangerate} = $exchangerate
2318 $form->check_exchangerate(
2319 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2322 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2327 for $i (1 .. $form->{rowcount}) {
2328 $form->{"discount_$i"} =
2329 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2331 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2333 $decimalplaces = ($dec > 2) ? $dec : 2;
2335 # copy delivery date from reqdate for order -> invoice conversion
2336 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2337 unless $form->{"deliverydate_$i"};
2339 $form->{"sellprice_$i"} =
2340 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2343 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2344 $dec_qty = length $dec_qty;
2346 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2348 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2349 qw(partnumber description unit);
2355 $lxdebug->leave_sub();
2358 sub backorder_exchangerate {
2359 $lxdebug->enter_sub();
2360 my ($orddate, $buysell) = @_;
2367 <form method=post action=$form->{script}>
2370 # delete action variable
2371 map { delete $form->{$_} } qw(action header exchangerate);
2373 foreach $key (keys %$form) {
2374 $form->{$key} =~ s/\"/"/g;
2375 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2378 $form->{title} = $locale->text('Add Exchangerate');
2382 <input type=hidden name=login value=$form->{login}>
2383 <input type=hidden name=password value=$form->{password}>
2385 <input type=hidden name=exchangeratedate value=$orddate>
2386 <input type=hidden name=buysell value=$buysell>
2389 <tr><th class=listtop>$form->{title}</th></tr>
2390 <tr height="5"></tr>
2395 <th align=right>| . $locale->text('Currency') . qq|</th>
2396 <td>$form->{currency}</td>
2399 <th align=right>| . $locale->text('Date') . qq|</th>
2403 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2404 <td><input name=exchangerate size=11></td>
2414 <input type=hidden name=nextsub value=save_exchangerate>
2416 <input name=action class=submit type=submit value="|
2417 . $locale->text('Continue') . qq|">
2425 $lxdebug->leave_sub();
2428 sub save_exchangerate {
2429 $lxdebug->enter_sub();
2431 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2432 $form->{exchangerate} =
2433 $form->parse_amount(\%myconfig, $form->{exchangerate});
2434 $form->save_exchangerate(\%myconfig, $form->{currency},
2435 $form->{exchangeratedate},
2436 $form->{exchangerate}, $form->{buysell});
2440 $lxdebug->leave_sub();
2443 sub create_backorder {
2444 $lxdebug->enter_sub();
2446 $form->{shipped} = 1;
2448 # figure out if we need to create a backorder
2449 # items aren't saved if qty != 0
2451 for $i (1 .. $form->{rowcount}) {
2452 $totalqty += $qty = $form->{"qty_$i"};
2453 $totalship += $ship = $form->{"ship_$i"};
2455 $form->{"qty_$i"} = $qty - $ship;
2458 if ($totalship == 0) {
2459 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2460 $form->{ordtotal} = 0;
2461 $form->{shipped} = 0;
2465 if ($totalqty == $totalship) {
2466 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2467 $form->{ordtotal} = 0;
2472 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2475 for $i (1 .. $form->{rowcount}) {
2477 $form->{"${_}_$i"} =
2478 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2479 } qw(sellprice discount);
2484 OE->save(\%myconfig, \%$form);
2486 # rebuild rows for invoice
2490 for $i (1 .. $form->{rowcount}) {
2491 $form->{"qty_$i"} = $form->{"ship_$i"};
2493 if ($form->{"qty_$i"}) {
2496 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2501 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2502 $form->{rowcount} = $count;
2504 $lxdebug->leave_sub();
2508 $lxdebug->enter_sub();
2510 $form->{saveasnew} = 1;
2511 $form->{closed} = 0;
2512 map { delete $form->{$_} } qw(printed emailed queued);
2514 # Let Lx-Office assign a new order number if the user hasn't changed the
2515 # previous one. If it has been changed manually then use it as-is.
2516 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2517 $form->{$idx} =~ s/^\s*//g;
2518 $form->{$idx} =~ s/\s*$//g;
2519 if ($form->{saved_xyznumber} &&
2520 ($form->{saved_xyznumber} eq $form->{$idx})) {
2521 delete($form->{$idx});
2526 $lxdebug->leave_sub();
2529 sub check_for_direct_delivery_yes {
2530 $lxdebug->enter_sub();
2532 $form->{direct_delivery_checked} = 1;
2533 delete @{$form}{grep /^shipto/, keys %{ $form }};
2534 map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
2535 $form->{shipto} = 1;
2537 $lxdebug->leave_sub();
2540 sub check_for_direct_delivery_no {
2541 $lxdebug->enter_sub();
2543 $form->{direct_delivery_checked} = 1;
2544 delete @{$form}{grep /^shipto/, keys %{ $form }};
2547 $lxdebug->leave_sub();
2550 sub check_for_direct_delivery {
2551 $lxdebug->enter_sub();
2553 if ($form->{direct_delivery_checked}
2554 || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
2555 $lxdebug->leave_sub();
2559 if ($form->{shipto_id}) {
2560 Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_");
2563 map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form };
2566 delete $form->{action};
2567 $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ref $_ eq "" } keys %{ $form } ];
2570 print $form->parse_html_template("oe/check_for_direct_delivery");
2572 $lxdebug->leave_sub();
2577 sub purchase_order {
2578 $lxdebug->enter_sub();
2580 if ($form->{type} eq 'sales_order') {
2581 check_for_direct_delivery();
2584 if ( $form->{type} eq 'sales_quotation'
2585 || $form->{type} eq 'request_quotation') {
2586 OE->close_order(\%myconfig, \%$form);
2589 if ($form->{type} =~ /^sales_/) {
2590 delete($form->{ordnumber});
2593 $form->{cp_id} *= 1;
2595 $form->{title} = $locale->text('Add Purchase Order');
2596 $form->{vc} = "vendor";
2597 $form->{type} = "purchase_order";
2601 $lxdebug->leave_sub();
2605 $lxdebug->enter_sub();
2607 if ( $form->{type} eq 'sales_quotation'
2608 || $form->{type} eq 'request_quotation') {
2609 OE->close_order(\%myconfig, $form);
2612 if ($form->{type} eq "purchase_order") {
2613 delete($form->{ordnumber});
2616 $form->{cp_id} *= 1;
2618 $form->{title} = $locale->text('Add Sales Order');
2619 $form->{vc} = "customer";
2620 $form->{type} = "sales_order";
2624 $lxdebug->leave_sub();
2628 $lxdebug->enter_sub();
2630 $form->{transdate} = $form->current_date(\%myconfig);
2631 delete $form->{duedate};
2633 $form->{closed} = 0;
2635 $form->{old_employee_id} = $form->{employee_id};
2636 $form->{old_salesman_id} = $form->{salesman_id};
2639 map { delete $form->{$_} }
2640 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2642 for $i (1 .. $form->{rowcount}) {
2643 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2644 $form->{"${_}_${i}"})
2645 if ($form->{"${_}_${i}"}) }
2646 qw(ship qty sellprice listprice basefactor));
2654 for $i (1 .. $form->{rowcount} - 1) {
2655 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2656 qw(partnumber description unit);
2659 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2660 qw(creditlimit creditremaining);
2664 $lxdebug->leave_sub();
2668 $lxdebug->enter_sub();
2670 $form->{print_and_save} = 1;
2675 my $saved_form = save_form();
2680 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2681 restore_form($saved_form);
2682 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2687 $lxdebug->leave_sub();
2691 call_sub($form->{yes_nextsub});
2695 call_sub($form->{no_nextsub});