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 map { $form->{$_} =~ s/\"/"/g }
328 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
329 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
330 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
332 # use JavaScript Calendar or not
333 $form->{jsscript} = 1;
337 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\">
338 <input type=button name=transdate id="trigger1" value=|
339 . $locale->text('button') . qq|></td>
342 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\">
343 <input type=button name=reqdate name=reqdate id="trigger2" value=|
344 . $locale->text('button') . qq|></td>
349 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
350 "reqdate", "BL", "trigger2");
354 if (($form->{"type"} eq "sales_order") ||
355 ($form->{"type"} eq "purchase_order")) {
357 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
358 <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
363 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
364 <label for="closed">| . $locale->text('Closed') . qq|</label>|);
370 <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
376 # set option selected
377 foreach $item ($form->{vc}, currency, department, ($form->{vc} eq "customer" ? customer : vendor)) {
378 $form->{"select$item"} =~ s/ selected//;
379 $form->{"select$item"} =~
380 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
383 #quote select[customer|vendor] Bug 133
384 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
386 #substitute \n and \r to \s (bug 543)
387 $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
389 my @old_project_ids = ($form->{"globalproject_id"});
390 map({ push(@old_project_ids, $form->{"project_id_$_"})
391 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
393 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
394 $form->get_lists("contacts" => "ALL_CONTACTS",
395 "shipto" => "ALL_SHIPTO",
396 "projects" => { "key" => "ALL_PROJECTS",
398 "old_id" => \@old_project_ids },
399 "employees" => "ALL_EMPLOYEES",
400 "salesmen" => "ALL_SALESMEN",
401 "taxzones" => "ALL_TAXZONES",
402 "payments" => "ALL_PAYMENTS",
403 "currencies" => "ALL_CURRENCIES",
404 $vc => "ALL_" . uc($vc));
407 my @values = (undef);
408 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
409 push(@values, $item->{"cp_id"});
410 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
411 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
415 if (scalar @values > 1) {
418 <th align="right">| . $locale->text('Contact Person') . qq|</th>
420 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
421 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
430 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
431 push(@values, $item->{"name"}.qq|--|.$item->{"id"});
432 $labels{$item->{"name"}.qq|--|.$item->{"id"}} = $item->{name};
436 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
437 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
438 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
440 (($myconfig{vclimit} <= scalar(@values))
441 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
442 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
443 '-onChange' => 'document.getElementById(\'update_button\').click();',
444 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
445 <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
446 </td><input type=hidden name="select$form->{vc}" value="| .
447 Q($form->{"select$form->{vc}"}) . qq|">|;
451 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
452 push(@values, $item->{"id"});
453 $labels{$item->{"id"}} = $item->{"description"};
457 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
459 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
460 '-labels' => \%labels, '-default' => $form->{payment_id}))
465 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
466 push(@values, $item->{"shipto_id"});
467 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
471 if (scalar @values > 1) {
474 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
476 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
477 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
483 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
484 push(@values, $item->{"id"});
485 $labels{$item->{"id"}} = $item->{"projectnumber"};
487 my $globalprojectnumber =
488 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
489 '-labels' => \%labels,
490 '-default' => $form->{"globalproject_id"}));
495 if ($form->{type} =~ /^sales_/) {
496 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
497 push(@values, $item->{"id"});
498 $labels{$item->{"id"}} = ($item->{"name"} ne "" ? $item->{"name"} : $item->{"login"});
502 <th align="right">| . $locale->text('Salesman') . qq|</th>
504 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
505 '-values' => \@values, '-labels' => \%labels))
512 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
513 push(@values, $item->{"id"});
514 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
519 <th align="right">| . $locale->text('Employee') . qq|</th>
521 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
522 '-values' => \@values, '-labels' => \%labels)) . qq|
528 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
529 push(@values, $item->{"id"});
530 $labels{$item->{"id"}} = $item->{"description"};
535 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
537 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
538 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
545 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
546 push(@values, $item);
547 $labels{$item} = $item;
550 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
552 if (scalar @values) {
555 <th align="right">| . $locale->text('Currency') . qq|</th>
557 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
558 '-values' => \@values, '-labels' => \%labels)) . qq|
563 $form->{exchangerate} =
564 $form->format_amount(\%myconfig, $form->{exchangerate});
566 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
572 $form->{creditlimit} =
573 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
574 $form->{creditremaining} =
575 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
578 <input type=hidden name=forex value=$form->{forex}>
581 if ($form->{currency} ne $form->{defaultcurrency}) {
582 if ($form->{forex}) {
585 . $locale->text('Exchangerate')
586 . qq|</th><td>$form->{exchangerate}</td>
587 <input type=hidden name=exchangerate value=$form->{exchangerate}>
592 . $locale->text('Exchangerate')
593 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
597 if ($form->{business}) {
600 <th align="right">| . ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type')) . qq|</th>
601 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
602 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
608 if ($form->{max_dunning_level}) {
611 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
613 <b>$form->{max_dunning_level}</b>;
614 | . $locale->text('Dunning Amount') . qq|: <b>|
615 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
622 if ($form->{type} !~ /_quotation$/) {
625 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
626 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
629 <th width=70% align=right nowrap>|
630 . $locale->text('Quotation Number') . qq|</th>
631 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
634 <th width=70% align=right nowrap>|
635 . $locale->text('Customer Order Number') . qq|</th>
636 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
639 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
644 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
649 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
651 $creditremaining = qq|
654 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
655 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
661 ($form->{type} eq 'sales_quotation')
662 ? $locale->text('Valid until')
663 : $locale->text('Required by');
664 if ($form->{type} eq 'sales_quotation') {
667 <th width=70% align=right nowrap>|
668 . $locale->text('Quotation Number') . qq|</th>
669 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
670 <input type=hidden name=ordnumber value="$form->{ordnumber}">
676 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
677 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
678 <input type=hidden name=ordnumber value="$form->{ordnumber}">
686 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
690 <th align=right nowrap=true>$reqlabel</th>
694 $creditremaining = qq| <tr>
702 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
703 <td colspan=3><select name=department style="width: 250px">$form->{selectdepartment}</select>
704 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
706 </tr> | if $form->{selectdepartment};
708 if ($form->{type} eq 'sales_order') {
709 if ($form->{selectemployee}) {
711 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
715 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
717 if ($form->{resubmit} && ($form->{format} eq "html")) {
719 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
720 } elsif ($form->{resubmit}) {
721 $onload = qq|document.oe.submit()|;
726 $credittext = $locale->text('Credit Limit exceeded!!!');
727 if ($creditwarning) {
728 $onload = qq|alert('$credittext')|;
731 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
732 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
734 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
735 # show history button js
736 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
737 #/show history button js
738 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
743 <body onLoad="$onload">
745 <form method=post name=oe action=$form->{script}>
747 <script type="text/javascript" src="js/common.js"></script>
748 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
749 <script type="text/javascript" src="js/vendor_selection.js"></script>
750 <script type="text/javascript" src="js/calculate_qty.js"></script>
753 $form->hide_form(qw(id action type vc formname media format proforma queued printed emailed
754 title discount creditlimit creditremaining tradediscount business
755 max_dunning_level dunning_amount));
761 <th class=listtop>$form->{title}</th>
783 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
784 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
787 <th align=right>| . $locale->text('Ship via') . qq|</th>
788 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
791 <th align="right">| . $locale->text('Transaction description') . qq|</th>
792 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
799 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
801 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
802 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
806 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
808 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
809 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
823 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
824 <td>$globalprojectnumber</td>
835 <!-- shipto are in hidden variables -->
837 <input type=hidden name=shiptoname value="$form->{shiptoname}">
838 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
839 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
840 <input type=hidden name=shiptocity value="$form->{shiptocity}">
841 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
842 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
843 <input type=hidden name=shiptophone value="$form->{shiptophone}">
844 <input type=hidden name=shiptofax value="$form->{shiptofax}">
845 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
846 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
847 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
849 <!-- email variables -->
850 <input type=hidden name=message value="$form->{message}">
851 <input type=hidden name=email value="$form->{email}">
852 <input type=hidden name=subject value="$form->{subject}">
853 <input type=hidden name=cc value="$form->{cc}">
854 <input type=hidden name=bcc value="$form->{bcc}">
856 <input type=hidden name=taxpart value="$form->{taxpart}">
857 <input type=hidden name=taxservice value="$form->{taxservice}">
859 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
862 foreach $item (split / /, $form->{taxaccounts}) {
864 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
865 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
868 $lxdebug->leave_sub();
872 $lxdebug->enter_sub();
874 $form->{invtotal} = $form->{invsubtotal};
876 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
879 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
882 $rows = ($rows > $introws) ? $rows : $introws;
884 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
886 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
888 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
891 if ($form->{taxaccounts}) {
893 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
894 . $locale->text('Tax Included') . qq|</b><br><br>
898 if (!$form->{taxincluded}) {
900 foreach $item (split / /, $form->{taxaccounts}) {
901 if ($form->{"${item}_base"}) {
902 $form->{invtotal} += $form->{"${item}_total"} =
904 $form->{"${item}_base"} * $form->{"${item}_rate"},
906 $form->{"${item}_total"} =
907 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
911 <th align=right>$form->{"${item}_description"} |
912 . $form->{"${item}_rate"} * 100 .qq|%</th>
913 <td align=right>$form->{"${item}_total"}</td>
919 $form->{invsubtotal} =
920 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
924 <th align=right>| . $locale->text('Subtotal') . qq|</th>
925 <td align=right>$form->{invsubtotal}</td>
931 if ($form->{taxincluded}) {
932 foreach $item (split / /, $form->{taxaccounts}) {
933 if ($form->{"${item}_base"}) {
934 $form->{"${item}_total"} =
936 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
937 (1 + $form->{"${item}_rate"})
940 $form->{"${item}_netto"} =
942 ($form->{"${item}_base"} - $form->{"${item}_total"}),
944 $form->{"${item}_total"} =
945 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
946 $form->{"${item}_netto"} =
947 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
951 <th align=right>Enthaltene $form->{"${item}_description"} |
952 . $form->{"${item}_rate"} * 100 .qq|%</th>
953 <td align=right>$form->{"${item}_total"}</td>
956 <th align=right>Nettobetrag</th>
957 <td align=right>$form->{"${item}_netto"}</td>
965 $form->{oldinvtotal} = $form->{invtotal};
967 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
977 <th align=left>| . $locale->text('Notes') . qq|</th>
978 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
989 <td align=right width=100%>
995 <th align=right>| . $locale->text('Total') . qq|</th>
996 <td align=right>$form->{invtotal}</td>
1004 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1005 <input type=hidden name=oldtotalpaid value=$totalpaid>
1007 <td><hr size=3 noshade></td>
1015 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
1018 <td align=left width=30%><b>Dateiname</b></td>
1019 <td align=left width=70%><b>Webdavlink</b></td>
1021 foreach $file (keys %{ $form->{WEBDAV} }) {
1024 <td align=left>$file</td>
1025 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1033 <td><hr size=3 noshade></td>
1051 | . $locale->text("Edit the $form->{type}") . qq|<br>
1052 <input class=submit type=submit name=action id=update_button value="|
1053 . $locale->text('Update') . qq|">
1054 <input class=submit type=submit name=action value="|
1055 . $locale->text('Ship to') . qq|">
1056 <input class=submit type=submit name=action value="|
1057 . $locale->text('Print') . qq|">
1058 <input class=submit type=submit name=action value="|
1059 . $locale->text('E-mail') . qq|">
1060 <input class=submit type=submit name=action value="|
1061 . $locale->text('Save') . qq|">
1062 <input class=submit type=submit name=action value="|
1063 . $locale->text('Save and Close') . qq|">
1066 if (($form->{id})) {
1068 <input type="button" class="submit" onclick="set_history_window(|
1070 . qq|);" name="history" id="history" value="|
1071 . $locale->text('history')
1074 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1075 <input class=submit type=submit name=action value="|
1076 . $locale->text('Save as new') . qq|">
1077 <input class=submit type=submit name=action value="|
1078 . $locale->text('Delete') . qq|">|;
1079 if (($form->{type} =~ /sales_quotation$/)) {
1081 <input class=submit type=submit name=action value="|
1082 . $locale->text('Sales Order') . qq|">|;
1084 if ($form->{type} =~ /request_quotation$/) {
1086 <input class=submit type=submit name=action value="|
1087 . $locale->text('Purchase Order') . qq|">|;
1091 <input class=submit type=submit name=action value="|
1092 . $locale->text('Invoice') . qq|">
1096 if ($form->{type} =~ /sales_order$/) {
1098 <br>$form->{heading} als neue Vorlage verwenden für<br>
1099 <input class=submit type=submit name=action value="|
1100 . $locale->text('Purchase Order') . qq|">
1101 <input class=submit type=submit name=action value="|
1102 . $locale->text('Quotation') . qq|">
1105 } elsif ($form->{type} =~ /purchase_order$/) {
1107 <br>$form->{heading} als neue Vorlage verwenden für<br>
1108 <input class=submit type=submit name=action value="|
1109 . $locale->text('Sales Order') . qq|">
1110 <input class=submit type=submit name=action value="|
1111 . $locale->text('Request for Quotation') . qq|">
1116 <br>$form->{heading} als neue Vorlage verwenden für<br>
1117 <input class=submit type=submit name=action value="|
1118 . $locale->text('Order') . qq|">
1121 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1123 <br>Workflow $form->{heading}<br>
1124 <input class=submit type=submit name=action value="|
1125 . $locale->text('Save as new') . qq|">
1126 <input class=submit type=submit name=action value="|
1127 . $locale->text('Invoice') . qq|">
1131 $form->hide_form("saved_xyznumber");
1135 <input type=hidden name=rowcount value=$form->{rowcount}>
1137 <input name=callback type=hidden value="$form->{callback}">
1139 <input type=hidden name=login value=$form->{login}>
1140 <input type=hidden name=password value=$form->{password}>
1147 $lxdebug->leave_sub();
1151 $lxdebug->enter_sub();
1153 set_headings($form->{"id"} ? "edit" : "add");
1155 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1156 qw(exchangerate creditlimit creditremaining);
1157 $form->{update} = 1;
1159 if($form->{payment_id}) {
1160 $payment_id = $form->{payment_id};
1163 &check_name($form->{vc});
1165 if($form->{payment_id} eq "") {
1166 $form->{payment_id} = $payment_id;
1170 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1171 $form->{exchangerate} = $exchangerate
1175 $form->check_exchangerate(
1176 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1180 $i = $form->{rowcount};
1182 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1184 if ( ($form->{"partnumber_$i"} eq "")
1185 && ($form->{"description_$i"} eq "")
1186 && ($form->{"partsgroup_$i"} eq "")) {
1188 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1193 if ( $form->{type} eq 'purchase_order'
1194 || $form->{type} eq 'request_quotation') {
1195 IR->retrieve_item(\%myconfig, \%$form);
1197 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1198 IS->retrieve_item(\%myconfig, \%$form);
1201 my $rows = scalar @{ $form->{item_list} };
1203 $form->{"discount_$i"} =
1204 $form->format_amount(\%myconfig, $form->{discount} * 100);
1207 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1216 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1217 if ($form->{"not_discountable_$i"}) {
1218 $form->{"discount_$i"} = 0;
1220 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1221 qw(partnumber description unit);
1222 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1223 keys %{ $form->{item_list}[0] };
1224 if ($form->{"part_payment_id_$i"} ne "") {
1225 $form->{payment_id} = $form->{"part_payment_id_$i"};
1228 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1230 ($dec) = ($s =~ /\.(\d+)/);
1232 $decimalplaces = ($dec > 2) ? $dec : 2;
1235 $form->{"sellprice_$i"} = $sellprice;
1238 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1240 # if there is an exchange rate adjust sellprice
1241 $form->{"sellprice_$i"} /= $exchangerate;
1245 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1246 (1 - $form->{"discount_$i"} / 100);
1247 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1248 map { $form->{"${_}_base"} += $amount }
1249 (split / /, $form->{"taxaccounts_$i"});
1250 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1251 split / /, $form->{taxaccounts}
1252 if !$form->{taxincluded};
1254 $form->{creditremaining} -= $amount;
1256 $form->{"sellprice_$i"} =
1257 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1260 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1262 # get pricegroups for parts
1263 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1265 # build up html code for prices_$i
1266 &set_pricegroup($i);
1273 # ok, so this is a new part
1274 # ask if it is a part or service item
1276 if ( $form->{"partsgroup_$i"}
1277 && ($form->{"partsnumber_$i"} eq "")
1278 && ($form->{"description_$i"} eq "")) {
1279 $form->{rowcount}--;
1280 $form->{"discount_$i"} = "";
1284 $form->{"id_$i"} = 0;
1285 $form->{"unit_$i"} = $locale->text('ea');
1293 $lxdebug->leave_sub();
1297 $lxdebug->enter_sub();
1299 if ($form->{type} eq 'purchase_order') {
1300 $form->{title} = $locale->text('Purchase Orders');
1301 $form->{vc} = 'vendor';
1302 $ordlabel = $locale->text('Order Number');
1303 $ordnumber = 'ordnumber';
1304 $employee = $locale->text('Employee');
1307 if ($form->{type} eq 'request_quotation') {
1308 $form->{title} = $locale->text('Request for Quotations');
1309 $form->{vc} = 'vendor';
1310 $ordlabel = $locale->text('RFQ Number');
1311 $ordnumber = 'quonumber';
1312 $employee = $locale->text('Employee');
1315 if ($form->{type} eq 'sales_order') {
1316 $form->{title} = $locale->text('Sales Orders');
1317 $form->{vc} = 'customer';
1318 $ordlabel = $locale->text('Order Number');
1319 $ordnumber = 'ordnumber';
1320 $employee = $locale->text('Employee');
1323 if ($form->{type} eq 'sales_quotation') {
1324 $form->{title} = $locale->text('Quotations');
1325 $form->{vc} = 'customer';
1326 $ordlabel = $locale->text('Quotation Number');
1327 $ordnumber = 'quonumber';
1328 $employee = $locale->text('Employee');
1331 # setup vendor / customer selection
1332 $form->all_vc(\%myconfig, $form->{vc},
1333 ($form->{vc} eq 'customer') ? "AR" : "AP");
1336 if (@{ $form->{all_departments} }) {
1337 $form->{selectdepartment} = "<option>\n";
1340 $form->{selectdepartment} .=
1341 "<option>$_->{description}--$_->{id}</option>\n"
1342 } (@{ $form->{all_departments} });
1347 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1348 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1350 | if $form->{selectdepartment};
1353 if (($form->{"type"} eq "sales_order") ||
1354 ($form->{"type"} eq "purchase_order")) {
1357 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1358 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1359 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1360 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1365 # use JavaScript Calendar or not
1366 $form->{jsscript} = 1;
1370 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1371 <input type=button name=transdatefrom id="trigger3" value=|
1372 . $locale->text('button') . qq|></td>
1375 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1376 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1377 . $locale->text('button') . qq|></td>
1382 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1383 "transdateto", "BL", "trigger4");
1385 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1387 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1389 "employees" => "ALL_EMPLOYEES",
1390 $vc => "ALL_" . uc($vc));
1394 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1395 push(@values, $item->{"id"});
1396 $labels{$item->{"id"}} = $item->{"projectnumber"};
1399 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1400 '-labels' => \%labels));
1405 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
1406 push(@values, $item->{"id"});
1407 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
1410 my $employee_block = qq|
1412 <th align="right">| . $locale->text('Employee') . qq|</th>
1414 NTI($cgi->popup_menu('-name' => 'employee_id',
1415 '-values' => \@values,
1416 '-labels' => \%labels)) . qq|
1423 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1424 push(@values, $item->{name}.qq|--|.$item->{"id"});
1425 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
1428 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1430 $myconfig{vclimit} <= scalar(@values)
1431 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
1432 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1433 '-default' => $form->{"old$form->{vc}"},
1434 '-onChange' => 'document.getElementById(\'update_button\').click();',
1435 '-values' => \@values,
1436 '-labels' => \%labels));
1442 <form method=post action=$form->{script}>
1446 <th class=listtop>$form->{title}</th>
1448 <tr height="5"></tr>
1453 <th align=right>$vc_label</th>
1454 <td colspan=3>$vc</td>
1458 <th align=right>$ordlabel</th>
1459 <td colspan=3><input name="$ordnumber" size=20></td>
1463 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1464 <td colspan="3"><input name="transaction_description" size=20></td>
1467 <th align="right">| . $locale->text("Project Number") . qq|</th>
1468 <td colspan="3">$projectnumber</td>
1471 <th align=right>| . $locale->text('From') . qq|</th>
1473 <th align=right>| . $locale->text('Bis') . qq|</th>
1476 <input type=hidden name=sort value=transdate>
1478 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1482 <td><input type="checkbox" name="open" value="1" id="open" checked>
1483 <label for="open">| . $locale->text("Open") . qq|</td>
1484 <td><input type="checkbox" name="closed" value="1" id="closed">
1485 <label for="closed">| . $locale->text("Closed") . qq|</td>
1489 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1490 | . $locale->text('ID') . qq|</td>
1491 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1492 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1493 . $locale->text('Date') . qq|</td>
1494 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1495 . $locale->text('Required by') . qq|</td>
1498 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vc_label</td>
1499 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1500 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1501 . $locale->text('Ship via') . qq|</td>
1502 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1505 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1506 . $locale->text('Amount') . qq|</td>
1507 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1508 . $locale->text('Tax') . qq|</td>
1509 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1510 . $locale->text('Total') . qq|</td>
1513 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1514 . $locale->text('Project Number') . qq|</td>
1515 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1516 . $locale->text('Transaction description') . qq|</td>
1519 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1520 . $locale->text('Subtotal') . qq|</td>
1528 <tr><td colspan=4><hr size=3 noshade></td></tr>
1534 <input type=hidden name=nextsub value=orders>
1535 <input type=hidden name=login value=$form->{login}>
1536 <input type=hidden name=password value=$form->{password}>
1537 <input type=hidden name=vc value=$form->{vc}>
1538 <input type=hidden name=type value=$form->{type}>
1540 <input class=submit type=submit name=action value="|
1541 . $locale->text('Continue') . qq|">
1548 $lxdebug->leave_sub();
1552 $lxdebug->enter_sub();
1554 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1558 qw(type vc login password transdatefrom transdateto
1559 open closed notdelivered delivered department
1560 transaction_description);
1561 push @fields, $form->{vc};
1562 $href = "$form->{script}?action=orders&"
1563 . join("&", map { "${_}=" . E($form->{$_}) } @fields)
1564 . "&${ordnumber}=" . E($form->{$ordnumber});
1567 # split vendor / customer
1568 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1569 split(/--/, $form->{ $form->{vc} });
1571 OE->transactions(\%myconfig, \%$form);
1574 "transdate", "reqdate",
1576 "name", "netamount",
1579 "shipvia", "globalprojectnumber",
1580 "transaction_description", "open",
1581 "closed", "delivered"
1584 $form->{l_open} = $form->{l_closed} = "Y"
1585 if ($form->{open} && $form->{closed});
1587 $form->{"l_delivered"} = "Y"
1588 if ($form->{"delivered"} && $form->{"notdelivered"});
1590 foreach $item (@columns) {
1591 if ($form->{"l_$item"} eq "Y") {
1592 push @column_index, $item;
1594 # add column to href and callback
1595 $callback .= "&l_$item=Y";
1596 $href .= "&l_$item=Y";
1600 # only show checkboxes if gotten here via sales_order form.
1601 if ($form->{type} =~ /sales_order/) {
1602 unshift @column_index, "ids";
1605 if ($form->{l_subtotal} eq 'Y') {
1606 $callback .= "&l_subtotal=Y";
1607 $href .= "&l_subtotal=Y";
1610 if ($form->{vc} eq 'vendor') {
1611 if ($form->{type} eq 'purchase_order') {
1612 $form->{title} = $locale->text('Purchase Orders');
1614 $form->{title} = $locale->text('Request for Quotations');
1616 $name = $locale->text('Vendor');
1617 $employee = $locale->text('Employee');
1619 if ($form->{vc} eq 'customer') {
1620 if ($form->{type} eq 'sales_order') {
1621 $form->{title} = $locale->text('Sales Orders');
1623 $form->{title} = $locale->text('Quotations');
1625 $employee = $locale->text('Employee');
1626 $name = $locale->text('Customer');
1629 $column_header{id} =
1630 qq|<th><a class=listheading href=$href&sort=id>|
1631 . $locale->text('ID')
1633 $column_header{transdate} =
1634 qq|<th><a class=listheading href=$href&sort=transdate>|
1635 . $locale->text('Date')
1637 $column_header{reqdate} =
1638 qq|<th><a class=listheading href=$href&sort=reqdate>|
1639 . $locale->text('Required by')
1641 $column_header{ordnumber} =
1642 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1643 . $locale->text('Order')
1645 $column_header{quonumber} =
1646 qq|<th><a class=listheading href=$href&sort=quonumber>|
1647 . ($form->{"type"} eq "request_quotation" ?
1648 $locale->text('RFQ') :
1649 $locale->text('Quotation'))
1651 $column_header{name} =
1652 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1653 $column_header{netamount} =
1654 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1655 $column_header{tax} =
1656 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1657 $column_header{amount} =
1658 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1659 $column_header{curr} =
1660 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1661 $column_header{shipvia} =
1662 qq|<th><a class=listheading href=$href&sort=shipvia>|
1663 . $locale->text('Ship via')
1665 $column_header{globalprojectnumber} =
1666 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1667 $column_header{open} =
1668 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1669 $column_header{closed} =
1670 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1671 $column_header{"delivered"} =
1672 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1674 $column_header{employee} =
1675 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1676 $column_header{transaction_description} =
1677 qq|<th><a class=listheading href="$href&sort=transaction_description">|
1678 . $locale->text("Transaction description") . qq|</a></th>|;
1680 $column_header{ids} = qq|<th></th>|;
1682 if ($form->{ $form->{vc} }) {
1683 $option = $locale->text(ucfirst $form->{vc});
1684 $option .= " : $form->{$form->{vc}}";
1686 if ($form->{department}) {
1687 $option .= "\n<br>" if ($option);
1688 ($department) = split /--/, $form->{department};
1689 $option .= $locale->text('Department') . " : $department";
1691 if ($form->{transdatefrom}) {
1693 . $locale->text('From') . " "
1694 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1696 if ($form->{transdateto}) {
1698 . $locale->text('Bis') . " "
1699 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1701 if ($form->{open}) {
1702 $option .= "\n<br>" if ($option);
1703 $option .= $locale->text('Open');
1705 if ($form->{closed}) {
1706 $option .= "\n<br>" if ($option);
1707 $option .= $locale->text('Closed');
1715 <form method="post" action="oe.pl">
1718 <th class=listtop>$form->{title}</th>
1720 <tr height="5"></tr>
1727 <tr class=listheading>|;
1729 map { print "\n$column_header{$_}" } @column_index;
1735 # add sort and escape callback
1736 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1738 if (@{ $form->{OE} }) {
1739 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1744 foreach $oe (@{ $form->{OE} }) {
1745 $form->{rowcount} = ++$j;
1747 if ($form->{l_subtotal} eq 'Y') {
1748 if ($sameitem ne $oe->{ $form->{sort} }) {
1750 $sameitem = $oe->{ $form->{sort} };
1754 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1756 $column_data{netamount} =
1758 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1760 $column_data{tax} = "<td align=right>"
1761 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1764 $column_data{amount} =
1766 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1768 $totalnetamount += $oe->{netamount};
1769 $totalamount += $oe->{amount};
1771 $subtotalnetamount += $oe->{netamount};
1772 $subtotalamount += $oe->{amount};
1775 qq|<td><input name="multi_id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1776 $column_data{id} = "<td>$oe->{id}</td>";
1777 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1778 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1780 $column_data{$ordnumber} =
1781 "<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>";
1782 $column_data{name} = "<td>$oe->{name}</td>";
1784 $column_data{employee} = "<td>$oe->{employee} </td>";
1785 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1786 $column_data{globalprojectnumber} = "<td>" . H($oe->{globalprojectnumber}) . "</td>";
1788 if ($oe->{closed}) {
1789 $column_data{closed} = "<td align=center>X</td>";
1790 $column_data{open} = "<td> </td>";
1792 $column_data{closed} = "<td> </td>";
1793 $column_data{open} = "<td align=center>X</td>";
1795 $column_data{"delivered"} = "<td>" .
1796 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1798 $column_data{transaction_description} = "<td>" . H($oe->{transaction_description}) . "</td>";
1803 <tr class=listrow$i>";
1805 map { print "\n$column_data{$_}" } @column_index;
1813 if ($form->{l_subtotal} eq 'Y') {
1819 <tr class=listtotal>|;
1821 map { $column_data{$_} = "<td> </td>" } @column_index;
1823 $column_data{netamount} =
1824 "<th class=listtotal align=right>"
1825 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1826 $column_data{tax} = "<th class=listtotal align=right>"
1827 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1830 $column_data{amount} =
1831 "<th class=listtotal align=right>"
1832 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1834 map { print "\n$column_data{$_}" } @column_index;
1842 <td><hr size=3 noshade></td>
1846 # multiple invoice edit button only if gotten there via sales_order form.
1848 if ($form->{type} =~ /sales_order/) {
1850 <input class"submit" type="submit" name="action" value="|
1851 . $locale->text('Continue') . qq|">
1852 <input type="hidden" name="nextsub" value="edit">
1853 <input type="hidden" name="type" value="$form->{type}">
1854 <input type="hidden" name="vc" value="$form->{vc}">
1855 <input type="hidden" name="login" value="$form->{login}">
1856 <input type="hidden" name="password" value="$form->{password}">
1857 <input type="hidden" name="callback" value="$callback">
1858 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1865 <form method=post action=$form->{script}>
1867 <input name=callback type=hidden value="$form->{callback}">
1869 <input type=hidden name=type value=$form->{type}>
1870 <input type=hidden name=vc value=$form->{vc}>
1872 <input type=hidden name=login value=$form->{login}>
1873 <input type=hidden name=password value=$form->{password}>
1881 $lxdebug->leave_sub();
1885 $lxdebug->enter_sub();
1887 map { $column_data{$_} = "<td> </td>" } @column_index;
1889 $column_data{netamount} =
1890 "<th class=listsubtotal align=right>"
1891 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1893 $column_data{tax} = "<td class=listsubtotal align=right>"
1894 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1897 $column_data{amount} =
1898 "<th class=listsubtotal align=right>"
1899 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1901 $subtotalnetamount = 0;
1902 $subtotalamount = 0;
1905 <tr class=listsubtotal>
1908 map { print "\n$column_data{$_}" } @column_index;
1914 $lxdebug->leave_sub();
1917 sub save_and_close {
1918 $lxdebug->enter_sub();
1920 if ($form->{type} =~ /_order$/) {
1921 $form->isblank("transdate", $locale->text('Order Date missing!'));
1923 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1926 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1927 $form->{$idx} =~ s/^\s*//g;
1928 $form->{$idx} =~ s/\s*$//g;
1930 $msg = ucfirst $form->{vc};
1931 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1933 # $locale->text('Customer missing!');
1934 # $locale->text('Vendor missing!');
1936 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1937 if ($form->{currency} ne $form->{defaultcurrency});
1941 if($form->{payment_id}) {
1942 $payment_id = $form->{payment_id};
1945 # if the name changed get new values
1946 if (&check_name($form->{vc})) {
1947 if($form->{payment_id} eq "") {
1948 $form->{payment_id} = $payment_id;
1954 $form->{id} = 0 if $form->{saveasnew};
1956 # this is for the internal notes section for the [email] Subject
1957 if ($form->{type} =~ /_order$/) {
1958 if ($form->{type} eq 'sales_order') {
1959 $form->{label} = $locale->text('Sales Order');
1961 $numberfld = "sonumber";
1962 $ordnumber = "ordnumber";
1964 $form->{label} = $locale->text('Purchase Order');
1966 $numberfld = "ponumber";
1967 $ordnumber = "ordnumber";
1970 $err = $locale->text('Cannot save order!');
1973 if ($form->{type} eq 'sales_quotation') {
1974 $form->{label} = $locale->text('Quotation');
1976 $numberfld = "sqnumber";
1977 $ordnumber = "quonumber";
1979 $form->{label} = $locale->text('Request for Quotation');
1981 $numberfld = "rfqnumber";
1982 $ordnumber = "quonumber";
1985 $err = $locale->text('Cannot save quotation!');
1989 # get new number in sequence if no number is given or if saveasnew was requested
1990 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1991 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1996 $form->error($err) if (!OE->save(\%myconfig, \%$form));
1998 # saving the history
1999 if(!exists $form->{addition}) {
2000 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2001 $form->{addition} = "SAVED";
2002 $form->save_history($form->dbconnect(\%myconfig));
2004 # /saving the history
2006 $form->redirect($form->{label} . " $form->{$ordnumber} " .
2007 $locale->text('saved!'));
2009 $lxdebug->leave_sub();
2013 $lxdebug->enter_sub();
2015 if ($form->{type} =~ /_order$/) {
2016 $form->isblank("transdate", $locale->text('Order Date missing!'));
2018 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2021 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2022 $form->{$idx} =~ s/^\s*//g;
2023 $form->{$idx} =~ s/\s*$//g;
2025 $msg = ucfirst $form->{vc};
2026 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
2028 # $locale->text('Customer missing!');
2029 # $locale->text('Vendor missing!');
2031 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
2032 if ($form->{currency} ne $form->{defaultcurrency});
2036 if($form->{payment_id}) {
2037 $payment_id = $form->{payment_id};
2040 # if the name changed get new values
2041 if (&check_name($form->{vc})) {
2042 if($form->{payment_id} eq "") {
2043 $form->{payment_id} = $payment_id;
2049 $form->{id} = 0 if $form->{saveasnew};
2051 # this is for the internal notes section for the [email] Subject
2052 if ($form->{type} =~ /_order$/) {
2053 if ($form->{type} eq 'sales_order') {
2054 $form->{label} = $locale->text('Sales Order');
2056 $numberfld = "sonumber";
2057 $ordnumber = "ordnumber";
2059 $form->{label} = $locale->text('Purchase Order');
2061 $numberfld = "ponumber";
2062 $ordnumber = "ordnumber";
2065 $err = $locale->text('Cannot save order!');
2068 if ($form->{type} eq 'sales_quotation') {
2069 $form->{label} = $locale->text('Quotation');
2071 $numberfld = "sqnumber";
2072 $ordnumber = "quonumber";
2074 $form->{label} = $locale->text('Request for Quotation');
2076 $numberfld = "rfqnumber";
2077 $ordnumber = "quonumber";
2080 $err = $locale->text('Cannot save quotation!');
2084 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
2085 unless $form->{$ordnumber};
2089 OE->save(\%myconfig, \%$form);
2091 # saving the history
2092 if(!exists $form->{addition}) {
2093 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2094 $form->{addition} = "SAVED";
2095 $form->save_history($form->dbconnect(\%myconfig));
2097 # /saving the history
2099 $form->{simple_save} = 1;
2100 if(!$form->{print_and_save}) {
2101 set_headings("edit");
2105 $lxdebug->leave_sub();
2109 $lxdebug->enter_sub();
2113 if ($form->{type} =~ /_order$/) {
2114 $msg = $locale->text('Are you sure you want to delete Order Number');
2115 $ordnumber = 'ordnumber';
2117 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2118 $ordnumber = 'quonumber';
2124 <form method=post action=$form->{script}>
2127 # delete action variable
2128 map { delete $form->{$_} } qw(action header);
2130 foreach $key (keys %$form) {
2131 $form->{$key} =~ s/\"/"/g;
2132 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2136 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2138 <h4>$msg $form->{$ordnumber}</h4>
2140 <input type="hidden" name="yes_nextsub" value="delete_order_quotation">
2141 <input name=action class=submit type=submit value="|
2142 . $locale->text('Yes') . qq|">
2143 <input name=action class=submit type=submit onclick="history.back()" value="|
2144 . $locale->text('No') . qq|">
2151 $lxdebug->leave_sub();
2154 sub delete_order_quotation {
2155 $lxdebug->enter_sub();
2157 if ($form->{type} =~ /_order$/) {
2158 $msg = $locale->text('Order deleted!');
2159 $err = $locale->text('Cannot delete order!');
2161 $msg = $locale->text('Quotation deleted!');
2162 $err = $locale->text('Cannot delete quotation!');
2164 if (OE->delete(\%myconfig, \%$form, $spool)){
2165 # saving the history
2166 if(!exists $form->{addition}) {
2167 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2168 $form->{addition} = "DELETED";
2169 $form->save_history($form->dbconnect(\%myconfig));
2171 # /saving the history
2177 $lxdebug->leave_sub();
2181 $lxdebug->enter_sub();
2183 if ($form->{type} =~ /_order$/) {
2185 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2186 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2187 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2188 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2189 $form->isblank("transdate", $locale->text('Order Date missing!'))
2190 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2192 # also copy deliverydate from the order
2193 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2194 $form->{orddate} = $form->{transdate};
2196 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2197 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2198 $form->{ordnumber} = "";
2199 $form->{quodate} = $form->{transdate};
2202 if($form->{payment_id}) {
2203 $payment_id = $form->{payment_id};
2206 # if the name changed get new values
2207 if (&check_name($form->{vc})) {
2208 if($form->{payment_id} eq "") {
2209 $form->{payment_id} = $payment_id;
2215 $form->{cp_id} *= 1;
2217 for $i (1 .. $form->{rowcount}) {
2218 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2219 $form->{"${_}_${i}"})
2220 if ($form->{"${_}_${i}"}) }
2221 qw(ship qty sellprice listprice basefactor));
2224 if ( $form->{type} =~ /_order/
2225 && $form->{currency} ne $form->{defaultcurrency}) {
2227 # check if we need a new exchangerate
2228 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2230 $orddate = $form->current_date(\%myconfig);
2232 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2235 if (!$exchangerate) {
2236 &backorder_exchangerate($orddate, $buysell);
2241 # close orders/quotations
2242 $form->{closed} = 1;
2244 # save order if one ordnumber has been given
2245 # if not it's most likely a collective order, which can't be saved back
2246 # so they just have to be closed
2247 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2248 OE->close_order(\%myconfig, \%$form);
2250 OE->close_orders(\%myconfig, \%$form);
2253 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2255 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2258 $form->{closed} = 0;
2259 $form->{rowcount}--;
2260 $form->{shipto} = 1;
2262 if ($form->{type} =~ /_order$/) {
2263 $form->{exchangerate} = $exchangerate;
2267 if ( $form->{type} eq 'purchase_order'
2268 || $form->{type} eq 'request_quotation') {
2269 $form->{title} = $locale->text('Add Vendor Invoice');
2270 $form->{script} = 'ir.pl';
2274 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2275 $form->{title} = $locale->text('Add Sales Invoice');
2276 $form->{script} = 'is.pl';
2281 # bo creates the id, reset it
2282 map { delete $form->{$_} }
2283 qw(id subject message cc bcc printed emailed queued);
2284 $form->{ $form->{vc} } =~ s/--.*//g;
2285 $form->{type} = "invoice";
2288 $locale = new Locale "$myconfig{countrycode}", "$script";
2290 require "bin/mozilla/$form->{script}";
2292 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2294 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2295 qw(creditlimit creditremaining);
2297 $currency = $form->{currency};
2300 $form->{currency} = $currency;
2301 $form->{exchangerate} = "";
2302 $form->{forex} = "";
2303 $form->{exchangerate} = $exchangerate
2307 $form->check_exchangerate(
2308 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2311 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2316 for $i (1 .. $form->{rowcount}) {
2317 $form->{"discount_$i"} =
2318 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2320 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2322 $decimalplaces = ($dec > 2) ? $dec : 2;
2324 # copy delivery date from reqdate for order -> invoice conversion
2325 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2326 unless $form->{"deliverydate_$i"};
2328 $form->{"sellprice_$i"} =
2329 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2332 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2333 $dec_qty = length $dec_qty;
2335 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2337 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2338 qw(partnumber description unit);
2344 $lxdebug->leave_sub();
2347 sub backorder_exchangerate {
2348 $lxdebug->enter_sub();
2349 my ($orddate, $buysell) = @_;
2356 <form method=post action=$form->{script}>
2359 # delete action variable
2360 map { delete $form->{$_} } qw(action header exchangerate);
2362 foreach $key (keys %$form) {
2363 $form->{$key} =~ s/\"/"/g;
2364 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2367 $form->{title} = $locale->text('Add Exchangerate');
2371 <input type=hidden name=login value=$form->{login}>
2372 <input type=hidden name=password value=$form->{password}>
2374 <input type=hidden name=exchangeratedate value=$orddate>
2375 <input type=hidden name=buysell value=$buysell>
2378 <tr><th class=listtop>$form->{title}</th></tr>
2379 <tr height="5"></tr>
2384 <th align=right>| . $locale->text('Currency') . qq|</th>
2385 <td>$form->{currency}</td>
2388 <th align=right>| . $locale->text('Date') . qq|</th>
2392 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2393 <td><input name=exchangerate size=11></td>
2403 <input type=hidden name=nextsub value=save_exchangerate>
2405 <input name=action class=submit type=submit value="|
2406 . $locale->text('Continue') . qq|">
2414 $lxdebug->leave_sub();
2417 sub save_exchangerate {
2418 $lxdebug->enter_sub();
2420 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2421 $form->{exchangerate} =
2422 $form->parse_amount(\%myconfig, $form->{exchangerate});
2423 $form->save_exchangerate(\%myconfig, $form->{currency},
2424 $form->{exchangeratedate},
2425 $form->{exchangerate}, $form->{buysell});
2429 $lxdebug->leave_sub();
2432 sub create_backorder {
2433 $lxdebug->enter_sub();
2435 $form->{shipped} = 1;
2437 # figure out if we need to create a backorder
2438 # items aren't saved if qty != 0
2440 for $i (1 .. $form->{rowcount}) {
2441 $totalqty += $qty = $form->{"qty_$i"};
2442 $totalship += $ship = $form->{"ship_$i"};
2444 $form->{"qty_$i"} = $qty - $ship;
2447 if ($totalship == 0) {
2448 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2449 $form->{ordtotal} = 0;
2450 $form->{shipped} = 0;
2454 if ($totalqty == $totalship) {
2455 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2456 $form->{ordtotal} = 0;
2461 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2464 for $i (1 .. $form->{rowcount}) {
2466 $form->{"${_}_$i"} =
2467 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2468 } qw(sellprice discount);
2473 OE->save(\%myconfig, \%$form);
2475 # rebuild rows for invoice
2479 for $i (1 .. $form->{rowcount}) {
2480 $form->{"qty_$i"} = $form->{"ship_$i"};
2482 if ($form->{"qty_$i"}) {
2485 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2490 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2491 $form->{rowcount} = $count;
2493 $lxdebug->leave_sub();
2497 $lxdebug->enter_sub();
2499 $form->{saveasnew} = 1;
2500 $form->{closed} = 0;
2501 map { delete $form->{$_} } qw(printed emailed queued);
2503 # Let Lx-Office assign a new order number if the user hasn't changed the
2504 # previous one. If it has been changed manually then use it as-is.
2505 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2506 $form->{$idx} =~ s/^\s*//g;
2507 $form->{$idx} =~ s/\s*$//g;
2508 if ($form->{saved_xyznumber} &&
2509 ($form->{saved_xyznumber} eq $form->{$idx})) {
2510 delete($form->{$idx});
2515 $lxdebug->leave_sub();
2518 sub check_for_direct_delivery_yes {
2519 $lxdebug->enter_sub();
2521 $form->{direct_delivery_checked} = 1;
2522 delete @{$form}{grep /^shipto/, keys %{ $form }};
2523 map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
2524 $form->{shipto} = 1;
2526 $lxdebug->leave_sub();
2529 sub check_for_direct_delivery_no {
2530 $lxdebug->enter_sub();
2532 $form->{direct_delivery_checked} = 1;
2533 delete @{$form}{grep /^shipto/, keys %{ $form }};
2536 $lxdebug->leave_sub();
2539 sub check_for_direct_delivery {
2540 $lxdebug->enter_sub();
2542 if ($form->{direct_delivery_checked}
2543 || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
2544 $lxdebug->leave_sub();
2548 if ($form->{shipto_id}) {
2549 Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_");
2552 map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form };
2555 delete $form->{action};
2556 $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ref $_ eq "" } keys %{ $form } ];
2559 print $form->parse_html_template("oe/check_for_direct_delivery");
2561 $lxdebug->leave_sub();
2566 sub purchase_order {
2567 $lxdebug->enter_sub();
2569 if ($form->{type} eq 'sales_order') {
2570 check_for_direct_delivery();
2573 if ( $form->{type} eq 'sales_quotation'
2574 || $form->{type} eq 'request_quotation') {
2575 OE->close_order(\%myconfig, \%$form);
2578 if ($form->{type} =~ /^sales_/) {
2579 delete($form->{ordnumber});
2582 $form->{cp_id} *= 1;
2584 $form->{title} = $locale->text('Add Purchase Order');
2585 $form->{vc} = "vendor";
2586 $form->{type} = "purchase_order";
2590 $lxdebug->leave_sub();
2594 $lxdebug->enter_sub();
2596 if ( $form->{type} eq 'sales_quotation'
2597 || $form->{type} eq 'request_quotation') {
2598 OE->close_order(\%myconfig, $form);
2601 if ($form->{type} eq "purchase_order") {
2602 delete($form->{ordnumber});
2605 $form->{cp_id} *= 1;
2607 $form->{title} = $locale->text('Add Sales Order');
2608 $form->{vc} = "customer";
2609 $form->{type} = "sales_order";
2613 $lxdebug->leave_sub();
2617 $lxdebug->enter_sub();
2619 $form->{transdate} = $form->current_date(\%myconfig);
2620 delete $form->{duedate};
2622 $form->{closed} = 0;
2625 map { delete $form->{$_} }
2626 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2628 for $i (1 .. $form->{rowcount}) {
2629 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2630 $form->{"${_}_${i}"})
2631 if ($form->{"${_}_${i}"}) }
2632 qw(ship qty sellprice listprice basefactor));
2640 for $i (1 .. $form->{rowcount} - 1) {
2641 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2642 qw(partnumber description unit);
2645 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2646 qw(creditlimit creditremaining);
2650 $lxdebug->leave_sub();
2654 $lxdebug->enter_sub();
2656 $form->{print_and_save} = 1;
2661 my $saved_form = save_form();
2666 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2667 restore_form($saved_form);
2668 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2673 $lxdebug->leave_sub();
2677 call_sub($form->{yes_nextsub});
2681 call_sub($form->{no_nextsub});