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 #======================================================================
34 use POSIX qw(strftime);
40 use SL::ReportGenerator;
41 use List::Util qw(max);
43 require "bin/mozilla/io.pl";
44 require "bin/mozilla/arap.pl";
45 require "bin/mozilla/reportgenerator.pl";
52 # $locale->text('Edit the purchase_order');
53 # $locale->text('Edit the sales_order');
54 # $locale->text('Edit the request_quotation');
55 # $locale->text('Edit the sales_quotation');
57 # $locale->text('Workflow purchase_order');
58 # $locale->text('Workflow sales_order');
59 # $locale->text('Workflow request_quotation');
60 # $locale->text('Workflow sales_quotation');
63 $lxdebug->enter_sub();
67 if ($form->{type} eq 'purchase_order') {
68 $form->{title} = $action eq "edit" ?
69 $locale->text('Edit Purchase Order') :
70 $locale->text('Add Purchase Order');
71 $form->{heading} = $locale->text('Purchase Order');
72 $form->{vc} = 'vendor';
74 if ($form->{type} eq 'sales_order') {
75 $form->{title} = $action eq "edit" ?
76 $locale->text('Edit Sales Order') :
77 $locale->text('Add Sales Order');
78 $form->{heading} = $locale->text('Sales Order');
79 $form->{vc} = 'customer';
81 if ($form->{type} eq 'request_quotation') {
82 $form->{title} = $action eq "edit" ?
83 $locale->text('Edit Request for Quotation') :
84 $locale->text('Add Request for Quotation');
85 $form->{heading} = $locale->text('Request for Quotation');
86 $form->{vc} = 'vendor';
88 if ($form->{type} eq 'sales_quotation') {
89 $form->{title} = $action eq "edit" ?
90 $locale->text('Edit Quotation') :
91 $locale->text('Add Quotation');
92 $form->{heading} = $locale->text('Quotation');
93 $form->{vc} = 'customer';
96 $lxdebug->leave_sub();
100 $lxdebug->enter_sub();
105 "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}"
106 unless $form->{callback};
112 $lxdebug->leave_sub();
116 $lxdebug->enter_sub();
117 # show history button
118 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
119 #/show hhistory button
121 $form->{simple_save} = 0;
123 set_headings("edit");
125 # editing without stuff to edit? try adding it first
126 if ($form->{rowcount} && !$form->{print_and_save}) {
127 map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount});
131 undef $form->{rowcount};
133 $lxdebug->leave_sub();
136 } elsif (!$form->{id}) {
138 $lxdebug->leave_sub();
142 if ($form->{print_and_save}) {
143 $form->{action} = "print";
144 $form->{resubmit} = 1;
145 $language_id = $form->{language_id};
146 $printer_id = $form->{printer_id};
149 set_headings("edit");
153 if ($form->{print_and_save}) {
154 $form->{language_id} = $language_id;
155 $form->{printer_id} = $printer_id;
159 $lxdebug->leave_sub();
163 $lxdebug->enter_sub();
164 # get customer/vendor
165 $form->all_vc(\%myconfig, $form->{vc},
166 ($form->{vc} eq 'customer') ? "AR" : "AP");
168 # retrieve order/quotation
169 $form->{webdav} = $webdav;
170 $form->{jsscript} = 1;
172 my $editing = $form->{id};
174 OE->retrieve(\%myconfig, \%$form);
176 if ($form->{payment_id}) {
177 $payment_id = $form->{payment_id};
179 if ($form->{language_id}) {
180 $language_id = $form->{language_id};
182 if ($form->{taxzone_id}) {
183 $taxzone_id = $form->{taxzone_id};
186 $salesman_id = $form->{salesman_id} if ($editing);
189 # if multiple rowcounts (== collective order) then check if the
190 # there were more than one customer (in that case OE::retrieve removes
191 # the content from the field)
192 if ( $form->{rowcount}
193 && $form->{type} eq 'sales_order'
194 && defined $form->{customer}
195 && $form->{customer} eq '') {
197 # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
200 'Collective Orders only work for orders from one customer!')
204 $taxincluded = $form->{taxincluded};
205 $form->{shipto} = 1 if $form->{id};
207 if ($form->{"all_$form->{vc}"}) {
208 unless ($form->{"$form->{vc}_id"}) {
209 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
213 $cp_id = $form->{cp_id};
214 $intnotes = $form->{intnotes};
216 # get customer / vendor
217 if ($form->{type} =~ /(purchase_order|request_quotation)/) {
218 IR->get_vendor(\%myconfig, \%$form);
220 #quote all_vendor Bug 133
221 foreach $ref (@{ $form->{all_vendor} }) {
222 $ref->{name} = $form->quote($ref->{name});
226 if ($form->{type} =~ /sales_(order|quotation)/) {
227 IS->get_customer(\%myconfig, \%$form);
229 #quote all_vendor Bug 133
230 foreach $ref (@{ $form->{all_customer} }) {
231 $ref->{name} = $form->quote($ref->{name});
235 $form->{cp_id} = $cp_id;
238 $form->{payment_id} = $payment_id;
241 $form->{language_id} = $language_id;
244 $form->{taxzone_id} = $taxzone_id;
246 $form->{intnotes} = $intnotes if $intnotes;
247 ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
248 $form->{"old$form->{vc}"} =
249 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
251 # build the popup menus
252 if (@{ $form->{"all_$form->{vc}"} }) {
253 $form->{ $form->{vc} } =
254 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
255 map { $form->{"select$form->{vc}"} .=
256 "<option>$_->{name}--$_->{id}</option>\n" }
257 (@{ $form->{"all_$form->{vc}"} });
260 $form->{taxincluded} = $taxincluded if ($form->{id});
263 if (@{ $form->{all_departments} }) {
264 $form->{selectdepartment} = "<option>\n";
265 $form->{department} = "$form->{department}--$form->{department_id}";
268 $form->{selectdepartment} .=
269 "<option>$_->{description}--$_->{id}</option>\n"
270 } (@{ $form->{all_departments} });
273 $form->{employee} = "$form->{employee}--$form->{employee_id}";
276 $form->{forex} = $form->{exchangerate};
278 $form->{salesman_id} = $salesman_id if ($editing);
280 $lxdebug->leave_sub();
284 $lxdebug->enter_sub();
285 $form->{formname} = $form->{type} unless $form->{formname};
288 foreach $ref (@{ $form->{form_details} }) {
289 $form->{rowcount} = ++$i;
291 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
293 for my $i (1 .. $form->{rowcount}) {
295 $form->{"discount_$i"} =
296 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
298 $form->{"discount_$i"} =
299 $form->format_amount(\%myconfig, $form->{"discount_$i"});
301 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
303 $decimalplaces = ($dec > 2) ? $dec : 2;
305 # copy reqdate from deliverydate for invoice -> order conversion
306 $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
307 unless $form->{"reqdate_$i"};
309 $form->{"sellprice_$i"} =
310 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
313 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
314 $dec_qty = length $dec_qty;
316 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
318 map { $form->{"${_}_$i"} =~ s/\"/"/g }
319 qw(partnumber description unit);
322 $lxdebug->leave_sub();
326 $lxdebug->enter_sub();
328 my $checkedclosed = $form->{"closed"} ? "checked" : "";
329 my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
331 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
332 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
334 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
336 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
337 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
339 map { $form->{$_} =~ s/\"/"/g }
340 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
341 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
342 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
344 # use JavaScript Calendar or not
345 $form->{jsscript} = 1;
349 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\">
350 <input type=button name=transdate id="trigger1" value=|
351 . $locale->text('button') . qq|></td>
354 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\">
355 <input type=button name=reqdate name=reqdate id="trigger2" value=|
356 . $locale->text('button') . qq|></td>
360 $jsscript = Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1", "reqdate", "BL", "trigger2");
364 if (($form->{"type"} eq "sales_order") ||
365 ($form->{"type"} eq "purchase_order")) {
366 push(@tmp, qq|<input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
367 <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
371 push(@tmp, qq|<input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
372 <label for="closed">| . $locale->text('Closed') . qq|</label>|);
376 $openclosed .= qq|<tr>
377 <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
382 # set option selected
383 foreach $item ($form->{vc}, currency, department, ($form->{vc} eq "customer" ? customer : vendor)) {
384 $form->{"select$item"} =~ s/ selected//;
385 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
388 #quote select[customer|vendor] Bug 133
389 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
391 #substitute \n and \r to \s (bug 543)
392 $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
394 my @old_project_ids = ($form->{"globalproject_id"});
395 map({ push(@old_project_ids, $form->{"project_id_$_"})
396 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
398 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
399 $form->get_lists("contacts" => "ALL_CONTACTS",
400 "shipto" => "ALL_SHIPTO",
402 "key" => "ALL_PROJECTS",
404 "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"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
421 if (scalar @values > 1) {
424 <th align="right">| . $locale->text('Contact Person') . qq|</th>
426 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
427 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
436 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
437 push(@values, $item->{"name"}.qq|--|.$item->{"id"});
438 $labels{$item->{"name"}.qq|--|.$item->{"id"}} = $item->{name};
442 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
443 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
444 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
446 (($myconfig{vclimit} <= scalar(@values))
447 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
448 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
449 '-onChange' => 'document.getElementById(\'update_button\').click();',
450 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
451 <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
452 </td><input type=hidden name="select$form->{vc}" value="| .
453 Q($form->{"select$form->{vc}"}) . qq|">|;
457 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
458 push(@values, $item->{"id"});
459 $labels{$item->{"id"}} = $item->{"description"};
463 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
465 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
466 '-labels' => \%labels, '-default' => $form->{payment_id}))
471 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
472 push(@values, $item->{"shipto_id"});
473 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
477 if (scalar @values > 1) {
480 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
482 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
483 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
489 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
490 push(@values, $item->{"id"});
491 $labels{$item->{"id"}} = $item->{"projectnumber"};
493 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
494 '-labels' => \%labels,
495 '-default' => $form->{"globalproject_id"}));
500 if ($form->{type} =~ /^sales_/) {
501 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
502 push(@values, $item->{"id"});
503 $labels{$item->{"id"}} = ($item->{"name"} ne "" ? $item->{"name"} : $item->{"login"});
507 <th align="right">| . $locale->text('Salesman') . qq|</th>
509 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
510 '-values' => \@values, '-labels' => \%labels))
517 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
518 push(@values, $item->{"id"});
519 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
524 <th align="right">| . $locale->text('Employee') . qq|</th>
526 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
527 '-values' => \@values, '-labels' => \%labels)) . qq|
533 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
534 push(@values, $item->{"id"});
535 $labels{$item->{"id"}} = $item->{"description"};
540 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
542 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
543 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
550 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
551 push(@values, $item);
552 $labels{$item} = $item;
555 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
557 if (scalar @values) {
560 <th align="right">| . $locale->text('Currency') . qq|</th>
562 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
563 '-values' => \@values, '-labels' => \%labels)) . qq|
568 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
569 $form->{exchangerate} = "" unless $form->{exchangerate};
571 $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
573 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
574 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
576 $exchangerate = qq|\n<input type=hidden name=forex value=$form->{forex}>\n|;
578 if ($form->{currency} ne $form->{defaultcurrency}) {
579 if ($form->{forex}) {
581 qq|<th align=right>| . $locale->text('Exchangerate')
582 . qq|</th><td>$form->{exchangerate}</td>
583 <input type=hidden name=exchangerate value=$form->{exchangerate}>
587 qq|<th align=right>| . $locale->text('Exchangerate')
588 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
592 if ($form->{business}) {
595 <th align="right">| . ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type')) . qq|</th>
596 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
597 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
603 if ($form->{max_dunning_level}) {
606 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
608 <b>$form->{max_dunning_level}</b>;
609 | . $locale->text('Dunning Amount') . qq|: <b>|
610 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
617 if ($form->{type} !~ /_quotation$/) {
620 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
621 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
624 <th width=70% align=right nowrap>|
625 . $locale->text('Quotation Number') . qq|</th>
626 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
629 <th width=70% align=right nowrap>|
630 . $locale->text('Customer Order Number') . qq|</th>
631 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
634 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
639 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
644 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
646 $creditremaining = qq|
649 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
650 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
655 $reqlabel = ($form->{type} eq 'sales_quotation') ? $locale->text('Valid until') : $locale->text('Required by');
656 if ($form->{type} eq 'sales_quotation') {
659 <th width=70% align=right nowrap>|
660 . $locale->text('Quotation Number') . qq|</th>
661 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
662 <input type=hidden name=ordnumber value="$form->{ordnumber}">
668 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
669 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
670 <input type=hidden name=ordnumber value="$form->{ordnumber}">
676 $ordnumber .= qq| <tr> <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th> $button1 </tr>
677 <tr> <th align=right nowrap=true>$reqlabel</th> $button2 </tr>\n|;
678 $creditremaining = qq| <tr> <td colspan=4></td> $shipto </tr>|;
683 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
684 <td colspan=3><select name=department style="width: 250px">$form->{selectdepartment}</select>
685 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
687 </tr> | if $form->{selectdepartment};
689 if ($form->{type} eq 'sales_order') {
690 $employee .= qq|\n<input type="hidden" name="customer_klass" value="$form->{customer_klass}">| if $form->{selectemployee};
692 $employee .= qq|\n<input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
695 $credittext = $locale->text('Credit Limit exceeded!!!');
697 $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()"
698 : ($form->{resubmit}) ? "document.oe.submit()"
699 : ($creditwarning) ? "alert('$credittext')"
702 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
703 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
705 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
706 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
707 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
712 <body onLoad="$onload">
714 <form method=post name=oe action=$form->{script}>
716 <script type="text/javascript" src="js/common.js"></script>
717 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
718 <script type="text/javascript" src="js/vendor_selection.js"></script>
719 <script type="text/javascript" src="js/calculate_qty.js"></script>
722 $form->hide_form(qw(id action type vc formname media format proforma queued printed emailed
723 title discount creditlimit creditremaining tradediscount business
724 max_dunning_level dunning_amount shiptoname shiptostreet shiptozipcode
725 shiptocity shiptocountry shiptocontact shiptophone shiptofax
726 shiptodepartment_1 shiptodepartment_2 shiptoemail
727 message email subject cc bcc taxpart taxservice taxaccounts),
728 map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} );
733 <th class=listtop>$form->{title}</th>
755 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
756 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
759 <th align=right>| . $locale->text('Ship via') . qq|</th>
760 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
763 <th align="right">| . $locale->text('Transaction description') . qq|</th>
764 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
771 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
773 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
774 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
778 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
780 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
781 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
795 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
796 <td>$globalprojectnumber</td>
809 $lxdebug->leave_sub();
813 $lxdebug->enter_sub();
815 $form->{invtotal} = $form->{invsubtotal};
817 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
820 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
823 $rows = ($rows > $introws) ? $rows : $introws;
825 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
827 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
829 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
832 if ($form->{taxaccounts}) {
834 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
835 . $locale->text('Tax Included') . qq|</b><br><br>
839 if (!$form->{taxincluded}) {
841 foreach $item (split / /, $form->{taxaccounts}) {
842 if ($form->{"${item}_base"}) {
843 $form->{invtotal} += $form->{"${item}_total"} =
845 $form->{"${item}_base"} * $form->{"${item}_rate"},
847 $form->{"${item}_total"} =
848 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
852 <th align=right>$form->{"${item}_description"} |
853 . $form->{"${item}_rate"} * 100 .qq|%</th>
854 <td align=right>$form->{"${item}_total"}</td>
860 $form->{invsubtotal} =
861 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
865 <th align=right>| . $locale->text('Subtotal') . qq|</th>
866 <td align=right>$form->{invsubtotal}</td>
872 if ($form->{taxincluded}) {
873 foreach $item (split / /, $form->{taxaccounts}) {
874 if ($form->{"${item}_base"}) {
875 $form->{"${item}_total"} =
877 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
878 (1 + $form->{"${item}_rate"})
881 $form->{"${item}_netto"} =
883 ($form->{"${item}_base"} - $form->{"${item}_total"}),
885 $form->{"${item}_total"} =
886 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
887 $form->{"${item}_netto"} =
888 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
892 <th align=right>Enthaltene $form->{"${item}_description"} |
893 . $form->{"${item}_rate"} * 100 .qq|%</th>
894 <td align=right>$form->{"${item}_total"}</td>
897 <th align=right>Nettobetrag</th>
898 <td align=right>$form->{"${item}_netto"}</td>
906 $form->{oldinvtotal} = $form->{invtotal};
908 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
918 <th align=left>| . $locale->text('Notes') . qq|</th>
919 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
934 if ($form->{type} =~ /^sales_/) {
937 <th align=left>| . $locale->text('Ertrag') . qq|</th>
938 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
941 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
942 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
948 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
949 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
958 <th align=right>| . $locale->text('Total') . qq|</th>
959 <td align=right>$form->{invtotal}</td>
967 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
968 <input type=hidden name=oldtotalpaid value=$totalpaid>
970 <td><hr size=3 noshade></td>
978 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
981 <td align=left width=30%><b>Dateiname</b></td>
982 <td align=left width=70%><b>Webdavlink</b></td>
984 foreach $file (@{ $form->{WEBDAV} }) {
987 <td align="left">$file->{name}</td>
988 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
996 <td><hr size=3 noshade></td>
1014 | . $locale->text("Edit the $form->{type}") . qq|<br>
1015 <input class=submit type=submit name=action id=update_button value="|
1016 . $locale->text('Update') . qq|">
1017 <input class=submit type=submit name=action value="|
1018 . $locale->text('Ship to') . qq|">
1019 <input class=submit type=submit name=action value="|
1020 . $locale->text('Print') . qq|">
1021 <input class=submit type=submit name=action value="|
1022 . $locale->text('E-mail') . qq|">
1023 <input class=submit type=submit name=action value="|
1024 . $locale->text('Save') . qq|">
1025 <input class=submit type=submit name=action value="|
1026 . $locale->text('Save and Close') . qq|">
1029 if (($form->{id})) {
1031 <input type="button" class="submit" onclick="set_history_window(|
1033 . qq|);" name="history" id="history" value="|
1034 . $locale->text('history')
1037 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1038 <input class=submit type=submit name=action value="|
1039 . $locale->text('Save as new') . qq|">
1040 <input class=submit type=submit name=action value="|
1041 . $locale->text('Delete') . qq|">|;
1042 if (($form->{type} =~ /sales_quotation$/)) {
1044 <input class=submit type=submit name=action value="|
1045 . $locale->text('Sales Order') . qq|">|;
1047 if ($form->{type} =~ /request_quotation$/) {
1049 <input class=submit type=submit name=action value="|
1050 . $locale->text('Purchase Order') . qq|">|;
1053 <input class=submit type=submit name=action value="|
1054 . $locale->text('Invoice') . qq|">
1057 if ($form->{type} =~ /sales_order$/) {
1059 <br>$form->{heading} als neue Vorlage verwenden für<br>
1060 <input class=submit type=submit name=action value="|
1061 . $locale->text('Purchase Order') . qq|">
1062 <input class=submit type=submit name=action value="|
1063 . $locale->text('Quotation') . qq|">
1066 } elsif ($form->{type} =~ /purchase_order$/) {
1068 <br>$form->{heading} als neue Vorlage verwenden für<br>
1069 <input class=submit type=submit name=action value="|
1070 . $locale->text('Sales Order') . qq|">
1071 <input class=submit type=submit name=action value="|
1072 . $locale->text('Request for Quotation') . qq|">
1077 <br>$form->{heading} als neue Vorlage verwenden für<br>
1078 <input class=submit type=submit name=action value="|
1079 . $locale->text('Order') . qq|">
1084 $form->hide_form("saved_xyznumber");
1088 <input type=hidden name=rowcount value=$form->{rowcount}>
1090 <input name=callback type=hidden value="$form->{callback}">
1092 <input type=hidden name=login value=$form->{login}>
1093 <input type=hidden name=password value=$form->{password}>
1100 $lxdebug->leave_sub();
1104 $lxdebug->enter_sub();
1106 set_headings($form->{"id"} ? "edit" : "add");
1108 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1109 $form->{update} = 1;
1111 $payment_id = $form->{payment_id} if $form->{payment_id};
1113 &check_name($form->{vc});
1115 $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
1118 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1119 $form->{exchangerate} = $exchangerate if
1120 $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
1123 $i = $form->{rowcount};
1125 $exchangerate = $form->{exchangerate} || 1;
1127 if ( ($form->{"partnumber_$i"} eq "")
1128 && ($form->{"description_$i"} eq "")
1129 && ($form->{"partsgroup_$i"} eq "")) {
1131 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1136 if ( $form->{type} eq 'purchase_order'
1137 || $form->{type} eq 'request_quotation') {
1138 IR->retrieve_item(\%myconfig, \%$form);
1140 if ( $form->{type} eq 'sales_order'
1141 || $form->{type} eq 'sales_quotation') {
1142 IS->retrieve_item(\%myconfig, \%$form);
1145 my $rows = scalar @{ $form->{item_list} };
1147 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
1150 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1159 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1160 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1161 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1162 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1163 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1165 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1166 $decimalplaces = max 2, length $1;
1169 $form->{"sellprice_$i"} = $sellprice;
1171 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1172 $form->{"sellprice_$i"} /= $exchangerate; # if there is an exchange rate adjust sellprice
1175 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1176 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1177 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1178 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
1180 $form->{creditremaining} -= $amount;
1182 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
1183 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1185 # get pricegroups for parts
1186 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1188 # build up html code for prices_$i
1189 &set_pricegroup($i);
1196 # ok, so this is a new part
1197 # ask if it is a part or service item
1199 if ( $form->{"partsgroup_$i"}
1200 && ($form->{"partsnumber_$i"} eq "")
1201 && ($form->{"description_$i"} eq "")) {
1202 $form->{rowcount}--;
1203 $form->{"discount_$i"} = "";
1207 $form->{"id_$i"} = 0;
1213 $lxdebug->leave_sub();
1217 $lxdebug->enter_sub();
1219 if ($form->{type} eq 'purchase_order') {
1220 $form->{title} = $locale->text('Purchase Orders');
1221 $form->{vc} = 'vendor';
1222 $ordlabel = $locale->text('Order Number');
1223 $ordnumber = 'ordnumber';
1224 $employee = $locale->text('Employee');
1227 if ($form->{type} eq 'request_quotation') {
1228 $form->{title} = $locale->text('Request for Quotations');
1229 $form->{vc} = 'vendor';
1230 $ordlabel = $locale->text('RFQ Number');
1231 $ordnumber = 'quonumber';
1232 $employee = $locale->text('Employee');
1235 if ($form->{type} eq 'sales_order') {
1236 $form->{title} = $locale->text('Sales Orders');
1237 $form->{vc} = 'customer';
1238 $ordlabel = $locale->text('Order Number');
1239 $ordnumber = 'ordnumber';
1240 $employee = $locale->text('Employee');
1243 if ($form->{type} eq 'sales_quotation') {
1244 $form->{title} = $locale->text('Quotations');
1245 $form->{vc} = 'customer';
1246 $ordlabel = $locale->text('Quotation Number');
1247 $ordnumber = 'quonumber';
1248 $employee = $locale->text('Employee');
1251 # setup vendor / customer selection
1252 $form->all_vc(\%myconfig, $form->{vc},
1253 ($form->{vc} eq 'customer') ? "AR" : "AP");
1256 if (@{ $form->{all_departments} }) {
1257 $form->{selectdepartment} = "<option>\n";
1260 $form->{selectdepartment} .=
1261 "<option>$_->{description}--$_->{id}</option>\n"
1262 } (@{ $form->{all_departments} });
1267 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1268 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1270 | if $form->{selectdepartment};
1273 if (($form->{"type"} eq "sales_order") ||
1274 ($form->{"type"} eq "purchase_order")) {
1277 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1278 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1279 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1280 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1285 # use JavaScript Calendar or not
1286 $form->{jsscript} = 1;
1290 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1291 <input type=button name=transdatefrom id="trigger3" value=|
1292 . $locale->text('button') . qq|></td>
1295 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1296 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1297 . $locale->text('button') . qq|></td>
1302 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1303 "transdateto", "BL", "trigger4");
1305 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1307 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1309 "employees" => "ALL_EMPLOYEES",
1310 $vc => "ALL_" . uc($vc));
1314 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1315 push(@values, $item->{"id"});
1316 $labels{$item->{"id"}} = $item->{"projectnumber"};
1319 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1320 '-labels' => \%labels));
1325 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
1326 push(@values, $item->{"id"});
1327 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
1330 my $employee_block = qq|
1332 <th align="right">| . $locale->text('Employee') . qq|</th>
1334 NTI($cgi->popup_menu('-name' => 'employee_id',
1335 '-values' => \@values,
1336 '-labels' => \%labels)) . qq|
1343 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1344 push(@values, $item->{name}.qq|--|.$item->{"id"});
1345 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
1348 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1350 $myconfig{vclimit} <= scalar(@values)
1351 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
1352 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1353 '-default' => $form->{"old$form->{vc}"},
1354 '-onChange' => 'document.getElementById(\'update_button\').click();',
1355 '-values' => \@values,
1356 '-labels' => \%labels));
1362 <form method=post action=$form->{script}>
1366 <th class=listtop>$form->{title}</th>
1368 <tr height="5"></tr>
1373 <th align=right>$vc_label</th>
1374 <td colspan=3>$vc</td>
1378 <th align=right>$ordlabel</th>
1379 <td colspan=3><input name="$ordnumber" size=20></td>
1383 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1384 <td colspan="3"><input name="transaction_description" size=20></td>
1387 <th align="right">| . $locale->text("Project Number") . qq|</th>
1388 <td colspan="3">$projectnumber</td>
1391 <th align=right>| . $locale->text('From') . qq|</th>
1393 <th align=right>| . $locale->text('Bis') . qq|</th>
1396 <input type=hidden name=sort value=transdate>
1398 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1402 <td><input type="checkbox" name="open" value="1" id="open" checked>
1403 <label for="open">| . $locale->text("Open") . qq|</td>
1404 <td><input type="checkbox" name="closed" value="1" id="closed">
1405 <label for="closed">| . $locale->text("Closed") . qq|</td>
1409 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1410 | . $locale->text('ID') . qq|</td>
1411 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1412 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1413 . $locale->text('Date') . qq|</td>
1414 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1415 . $locale->text('Required by') . qq|</td>
1418 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vc_label</td>
1419 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1420 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1421 . $locale->text('Ship via') . qq|</td>
1424 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1425 . $locale->text('Amount') . qq|</td>
1426 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1427 . $locale->text('Tax') . qq|</td>
1428 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1429 . $locale->text('Total') . qq|</td>
1432 <td><input name="l_marge_total" class=checkbox type=checkbox value=Y> |
1433 . $locale->text('Ertrag') . qq|</td>
1434 <td><input name="l_marge_percent" class=checkbox type=checkbox value=Y> |
1435 . $locale->text('Ertrag prozentual') . qq|</td>
1438 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1439 . $locale->text('Project Number') . qq|</td>
1440 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1441 . $locale->text('Transaction description') . qq|</td>
1444 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1445 . $locale->text('Subtotal') . qq|</td>
1453 <tr><td colspan=4><hr size=3 noshade></td></tr>
1459 <input type=hidden name=nextsub value=orders>
1460 <input type=hidden name=login value=$form->{login}>
1461 <input type=hidden name=password value=$form->{password}>
1462 <input type=hidden name=vc value=$form->{vc}>
1463 <input type=hidden name=type value=$form->{type}>
1465 <input class=submit type=submit name=action value="|
1466 . $locale->text('Continue') . qq|">
1473 $lxdebug->leave_sub();
1476 sub create_subtotal_row {
1477 $lxdebug->enter_sub();
1479 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1481 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1483 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1485 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1487 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1489 $lxdebug->leave_sub();
1495 $lxdebug->enter_sub();
1497 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1499 ($form->{ $form->{vc} }, $form->{"${form->{vc}}_id"}) = split(/--/, $form->{ $form->{vc} });
1501 $form->{sort} ||= 'transdate';
1503 OE->transactions(\%myconfig, \%$form);
1505 $form->{rowcount} = scalar @{ $form->{OE} };
1508 "transdate", "reqdate",
1510 "name", "netamount",
1513 "shipvia", "globalprojectnumber",
1514 "transaction_description", "open",
1515 "delivered", "marge_total", "marge_percent"
1518 # only show checkboxes if gotten here via sales_order form.
1519 my $allow_multiple_orders = $form->{type} eq 'sales_order';
1520 if ($allow_multiple_orders) {
1521 unshift @columns, "ids";
1524 $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed});
1525 $form->{l_delivered} = "Y" if ($form->{delivered} && $form->{notdelivered});
1527 my $attachment_basename;
1528 if ($form->{vc} eq 'vendor') {
1529 if ($form->{type} eq 'purchase_order') {
1530 $form->{title} = $locale->text('Purchase Orders');
1531 $attachment_basename = $locale->text('purchase_order_list');
1533 $form->{title} = $locale->text('Request for Quotations');
1534 $attachment_basename = $locale->text('rfq_list');
1538 if ($form->{type} eq 'sales_order') {
1539 $form->{title} = $locale->text('Sales Orders');
1540 $attachment_basename = $locale->text('sales_order_list');
1542 $form->{title} = $locale->text('Quotations');
1543 $attachment_basename = $locale->text('quotation_list');
1547 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1549 my @hidden_variables = map { "l_${_}" } @columns;
1550 push @hidden_variables, "l_subtotal", $form->{vc}, qw(l_closed l_notdelivered open closed delivered notdelivered ordnumber quonumber
1551 transaction_description transdatefrom transdateto type vc employee_id);
1553 my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
1556 'ids' => { 'text' => '', },
1557 'transdate' => { 'text' => $locale->text('Date'), },
1558 'reqdate' => { 'text' => $locale->text('Required by'), },
1559 'id' => { 'text' => $locale->text('ID'), },
1560 'ordnumber' => { 'text' => $locale->text('Order'), },
1561 'quonumber' => { 'text' => $form->{type} eq "request_quotation" ? $locale->text('RFQ') : $locale->text('Quotation'), },
1562 'name' => { 'text' => $form->{vc} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1563 'netamount' => { 'text' => $locale->text('Amount'), },
1564 'tax' => { 'text' => $locale->text('Tax'), },
1565 'amount' => { 'text' => $locale->text('Total'), },
1566 'curr' => { 'text' => $locale->text('Curr'), },
1567 'employee' => { 'text' => $locale->text('Salesperson'), },
1568 'shipvia' => { 'text' => $locale->text('Ship via'), },
1569 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1570 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1571 'open' => { 'text' => $locale->text('Open'), },
1572 'delivered' => { 'text' => $locale->text('Delivered'), },
1573 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1574 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), }
1577 foreach my $name (qw(id transdate reqdate quonumber ordnumber name employee shipvia)) {
1578 $column_defs{$name}->{link} = $href . "&sort=$name";
1581 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount curr);
1583 $form->{"l_type"} = "Y";
1584 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1585 $column_defs{ids}->{visible} = $allow_multiple_orders ? 'HTML' : 0;
1587 $report->set_columns(%column_defs);
1588 $report->set_column_order(@columns);
1590 $report->set_export_options('orders', @hidden_variables);
1592 $report->set_sort_indicator($form->{sort}, 1);
1595 if ($form->{customer}) {
1596 push @options, $locale->text('Customer') . " : $form->{customer}";
1598 if ($form->{vendor}) {
1599 push @options, $locale->text('Vendor') . " : $form->{vendor}";
1601 if ($form->{department}) {
1602 ($department) = split /--/, $form->{department};
1603 push @options, $locale->text('Department') . " : $department";
1605 if ($form->{ordnumber}) {
1606 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1608 if ($form->{notes}) {
1609 push @options, $locale->text('Notes') . " : $form->{notes}";
1611 if ($form->{transaction_description}) {
1612 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1614 if ($form->{transdatefrom}) {
1615 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1617 if ($form->{transdateto}) {
1618 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1620 if ($form->{open}) {
1621 push @options, $locale->text('Open');
1623 if ($form->{closed}) {
1624 push @options, $locale->text('Closed');
1626 if ($form->{delivered}) {
1627 push @options, $locale->text('Delivered');
1629 if ($form->{notdelivered}) {
1630 push @options, $locale->text('Not delivered');
1633 $report->set_options('top_info_text' => join("\n", @options),
1634 'raw_top_info_text' => $form->parse_html_template('oe/orders_top'),
1635 'raw_bottom_info_text' => $form->parse_html_template('oe/orders_bottom', { 'SHOW_CONTINUE_BUTTON' => $allow_multiple_orders }),
1636 'output_format' => 'HTML',
1637 'title' => $form->{title},
1638 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1640 $report->set_options_from_form();
1642 # add sort and escape callback, this one we use for the add sub
1643 $form->{callback} = $href .= "&sort=$form->{sort}";
1645 # escape callback for href
1646 $callback = $form->escape($href);
1648 my @subtotal_columns = qw(netamount amount marge_total marge_percent);
1650 my %totals = map { $_ => 0 } @subtotal_columns;
1651 my %subtotals = map { $_ => 0 } @subtotal_columns;
1655 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1657 foreach $oe (@{ $form->{OE} }) {
1658 map { $oe->{$_} *= $oe->{exchangerate} } @subtotal_columns;
1660 $oe->{tax} = $oe->{amount} - $oe->{netamount};
1661 $oe->{open} = $oe->{closed} ? $locale->text('No') : $locale->text('Yes');
1662 $oe->{delivered} = $oe->{delivered} ? $locale->text('Yes') : $locale->text('No');
1664 map { $subtotals{$_} += $oe->{$_};
1665 $totals{$_} += $oe->{$_} } @subtotal_columns;
1667 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1668 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1670 map { $oe->{$_} = $form->format_amount(\%myconfig, $oe->{$_}, 2) } qw(netamount tax amount marge_total marge_percent);
1674 foreach my $column (@columns) {
1675 next if ($column eq 'ids');
1677 'data' => $oe->{$column},
1678 'align' => $column_alignment{$column},
1683 'raw_data' => $cgi->hidden('-name' => "trans_id_${idx}", '-value' => $oe->{id})
1684 . $cgi->checkbox('-name' => "multi_id_${idx}", '-value' => 1, '-label' => ''),
1685 'valign' => 'center',
1686 'align' => 'center',
1689 $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1691 my $row_set = [ $row ];
1693 if (($form->{l_subtotal} eq 'Y')
1694 && (($idx == (scalar @{ $form->{OE} } - 1))
1695 || ($oe->{ $form->{sort} } ne $form->{OE}->[$idx + 1]->{ $form->{sort} }))) {
1696 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1699 $report->add_data($row_set);
1704 $report->add_separator();
1705 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1707 $report->generate_with_headers();
1709 $lxdebug->leave_sub();
1712 sub check_delivered_flag {
1713 $lxdebug->enter_sub();
1715 if (($form->{type} ne 'sales_order') && ($form->{type} ne 'purchase_order')) {
1716 return $lxdebug->leave_sub();
1719 my $all_delivered = 0;
1721 foreach my $i (1 .. $form->{rowcount}) {
1722 next if (!$form->{"id_$i"});
1724 if ($form->parse_amount(\%myconfig, $form->{"qty_$i"}) == $form->parse_amount(\%myconfig, $form->{"ship_$i"})) {
1733 $form->{delivered} = 1 if $all_delivered;
1735 $lxdebug->leave_sub();
1738 sub save_and_close {
1739 $lxdebug->enter_sub();
1741 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1743 if ($form->{type} =~ /_order$/) {
1744 $form->isblank("transdate", $locale->text('Order Date missing!'));
1746 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1749 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1750 $form->{$idx} =~ s/^\s*//g;
1751 $form->{$idx} =~ s/\s*$//g;
1753 $msg = ucfirst $form->{vc};
1754 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1756 # $locale->text('Customer missing!');
1757 # $locale->text('Vendor missing!');
1759 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1760 if ($form->{currency} ne $form->{defaultcurrency});
1764 if($form->{payment_id}) {
1765 $payment_id = $form->{payment_id};
1768 # if the name changed get new values
1769 if (&check_name($form->{vc})) {
1770 if($form->{payment_id} eq "") {
1771 $form->{payment_id} = $payment_id;
1777 $form->{id} = 0 if $form->{saveasnew};
1779 # this is for the internal notes section for the [email] Subject
1780 if ($form->{type} =~ /_order$/) {
1781 if ($form->{type} eq 'sales_order') {
1782 $form->{label} = $locale->text('Sales Order');
1784 $numberfld = "sonumber";
1785 $ordnumber = "ordnumber";
1787 $form->{label} = $locale->text('Purchase Order');
1789 $numberfld = "ponumber";
1790 $ordnumber = "ordnumber";
1793 $err = $locale->text('Cannot save order!');
1795 check_delivered_flag();
1798 if ($form->{type} eq 'sales_quotation') {
1799 $form->{label} = $locale->text('Quotation');
1801 $numberfld = "sqnumber";
1802 $ordnumber = "quonumber";
1804 $form->{label} = $locale->text('Request for Quotation');
1806 $numberfld = "rfqnumber";
1807 $ordnumber = "quonumber";
1810 $err = $locale->text('Cannot save quotation!');
1814 # get new number in sequence if no number is given or if saveasnew was requested
1815 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1816 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1821 $form->error($err) if (!OE->save(\%myconfig, \%$form));
1823 # saving the history
1824 if(!exists $form->{addition}) {
1825 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1826 $form->{addition} = "SAVED";
1827 $form->save_history($form->dbconnect(\%myconfig));
1829 # /saving the history
1831 $form->redirect($form->{label} . " $form->{$ordnumber} " .
1832 $locale->text('saved!'));
1834 $lxdebug->leave_sub();
1838 $lxdebug->enter_sub();
1840 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1843 if ($form->{type} =~ /_order$/) {
1844 $form->isblank("transdate", $locale->text('Order Date missing!'));
1846 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1849 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1850 $form->{$idx} =~ s/^\s*//g;
1851 $form->{$idx} =~ s/\s*$//g;
1853 $msg = ucfirst $form->{vc};
1854 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1856 # $locale->text('Customer missing!');
1857 # $locale->text('Vendor missing!');
1859 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1860 if ($form->{currency} ne $form->{defaultcurrency});
1864 if($form->{payment_id}) {
1865 $payment_id = $form->{payment_id};
1868 # if the name changed get new values
1869 if (&check_name($form->{vc})) {
1870 if($form->{payment_id} eq "") {
1871 $form->{payment_id} = $payment_id;
1877 $form->{id} = 0 if $form->{saveasnew};
1879 # this is for the internal notes section for the [email] Subject
1880 if ($form->{type} =~ /_order$/) {
1881 if ($form->{type} eq 'sales_order') {
1882 $form->{label} = $locale->text('Sales Order');
1884 $numberfld = "sonumber";
1885 $ordnumber = "ordnumber";
1887 $form->{label} = $locale->text('Purchase Order');
1889 $numberfld = "ponumber";
1890 $ordnumber = "ordnumber";
1893 $err = $locale->text('Cannot save order!');
1895 check_delivered_flag();
1898 if ($form->{type} eq 'sales_quotation') {
1899 $form->{label} = $locale->text('Quotation');
1901 $numberfld = "sqnumber";
1902 $ordnumber = "quonumber";
1904 $form->{label} = $locale->text('Request for Quotation');
1906 $numberfld = "rfqnumber";
1907 $ordnumber = "quonumber";
1910 $err = $locale->text('Cannot save quotation!');
1914 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
1915 unless $form->{$ordnumber};
1919 OE->save(\%myconfig, \%$form);
1921 # saving the history
1922 if(!exists $form->{addition}) {
1923 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1924 $form->{addition} = "SAVED";
1925 $form->save_history($form->dbconnect(\%myconfig));
1927 # /saving the history
1929 $form->{simple_save} = 1;
1930 if(!$form->{print_and_save}) {
1931 set_headings("edit");
1935 $lxdebug->leave_sub();
1939 $lxdebug->enter_sub();
1943 if ($form->{type} =~ /_order$/) {
1944 $msg = $locale->text('Are you sure you want to delete Order Number');
1945 $ordnumber = 'ordnumber';
1947 $msg = $locale->text('Are you sure you want to delete Quotation Number');
1948 $ordnumber = 'quonumber';
1954 <form method=post action=$form->{script}>
1957 # delete action variable
1958 map { delete $form->{$_} } qw(action header);
1960 foreach $key (keys %$form) {
1961 $form->{$key} =~ s/\"/"/g;
1962 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1966 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1968 <h4>$msg $form->{$ordnumber}</h4>
1970 <input type="hidden" name="yes_nextsub" value="delete_order_quotation">
1971 <input name=action class=submit type=submit value="|
1972 . $locale->text('Yes') . qq|">
1973 <button class=submit type=button onclick="history.back()">|
1974 . $locale->text('No') . qq|</button>
1981 $lxdebug->leave_sub();
1984 sub delete_order_quotation {
1985 $lxdebug->enter_sub();
1987 if ($form->{type} =~ /_order$/) {
1988 $msg = $locale->text('Order deleted!');
1989 $err = $locale->text('Cannot delete order!');
1991 $msg = $locale->text('Quotation deleted!');
1992 $err = $locale->text('Cannot delete quotation!');
1994 if (OE->delete(\%myconfig, \%$form, $spool)){
1995 # saving the history
1996 if(!exists $form->{addition}) {
1997 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1998 $form->{addition} = "DELETED";
1999 $form->save_history($form->dbconnect(\%myconfig));
2001 # /saving the history
2007 $lxdebug->leave_sub();
2011 $lxdebug->enter_sub();
2013 $form->{old_employee_id} = $form->{employee_id};
2014 $form->{old_salesman_id} = $form->{salesman_id};
2016 if ($form->{type} =~ /_order$/) {
2018 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2019 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2020 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2021 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2022 $form->isblank("transdate", $locale->text('Order Date missing!'))
2023 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2025 # also copy deliverydate from the order
2026 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2027 $form->{orddate} = $form->{transdate};
2029 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2030 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2031 $form->{ordnumber} = "";
2032 $form->{quodate} = $form->{transdate};
2035 $payment_id = $form->{payment_id} if $form->{payment_id};
2037 # if the name changed get new values
2038 if (&check_name($form->{vc})) {
2039 $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
2044 $form->{cp_id} *= 1;
2046 for $i (1 .. $form->{rowcount}) {
2047 for (qw(ship qty sellprice listprice basefactor)) {
2048 $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"};
2052 if ( $form->{type} =~ /_order/
2053 && $form->{currency} ne $form->{defaultcurrency}) {
2055 # check if we need a new exchangerate
2056 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2058 $orddate = $form->current_date(\%myconfig);
2059 $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate, $buysell);
2061 if (!$exchangerate) {
2062 &backorder_exchangerate($orddate, $buysell);
2067 # close orders/quotations
2068 $form->{closed} = 1;
2070 # save order if one ordnumber has been given
2071 # if not it's most likely a collective order, which can't be saved back
2072 # so they just have to be closed
2073 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2074 OE->close_order(\%myconfig, \%$form) if ($form->{id});
2076 OE->close_orders(\%myconfig, \%$form);
2079 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2080 $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2083 $form->{closed} = 0;
2084 $form->{rowcount}--;
2085 $form->{shipto} = 1;
2087 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
2089 if ($form->{type} =~ /_order$/) {
2090 $form->{exchangerate} = $exchangerate;
2094 if ( $form->{type} eq 'purchase_order'
2095 || $form->{type} eq 'request_quotation') {
2096 $form->{title} = $locale->text('Add Vendor Invoice');
2097 $form->{script} = 'ir.pl';
2102 if ( $form->{type} eq 'sales_order'
2103 || $form->{type} eq 'sales_quotation') {
2104 $form->{title} = $locale->text('Add Sales Invoice');
2105 $form->{script} = 'is.pl';
2110 # bo creates the id, reset it
2111 map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued);
2112 $form->{ $form->{vc} } =~ s/--.*//g;
2113 $form->{type} = "invoice";
2116 $locale = new Locale "$myconfig{countrycode}", "$script";
2118 require "bin/mozilla/$form->{script}";
2120 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2122 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2123 qw(creditlimit creditremaining);
2125 $currency = $form->{currency};
2128 $form->{currency} = $currency;
2129 $form->{exchangerate} = "";
2130 $form->{forex} = "";
2131 $form->{exchangerate} = $exchangerate
2135 $form->check_exchangerate(
2136 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2139 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2144 for $i (1 .. $form->{rowcount}) {
2145 $form->{"discount_$i"} =
2146 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2148 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2150 $decimalplaces = ($dec > 2) ? $dec : 2;
2152 # copy delivery date from reqdate for order -> invoice conversion
2153 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2154 unless $form->{"deliverydate_$i"};
2156 $form->{"sellprice_$i"} =
2157 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2160 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2161 $dec_qty = length $dec_qty;
2163 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2165 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2166 qw(partnumber description unit);
2172 $lxdebug->leave_sub();
2175 sub backorder_exchangerate {
2176 $lxdebug->enter_sub();
2177 my ($orddate, $buysell) = @_;
2184 <form method=post action=$form->{script}>
2187 # delete action variable
2188 map { delete $form->{$_} } qw(action header exchangerate);
2190 foreach $key (keys %$form) {
2191 $form->{$key} =~ s/\"/"/g;
2192 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2195 $form->{title} = $locale->text('Add Exchangerate');
2199 <input type=hidden name=login value=$form->{login}>
2200 <input type=hidden name=password value=$form->{password}>
2202 <input type=hidden name=exchangeratedate value=$orddate>
2203 <input type=hidden name=buysell value=$buysell>
2206 <tr><th class=listtop>$form->{title}</th></tr>
2207 <tr height="5"></tr>
2212 <th align=right>| . $locale->text('Currency') . qq|</th>
2213 <td>$form->{currency}</td>
2216 <th align=right>| . $locale->text('Date') . qq|</th>
2220 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2221 <td><input name=exchangerate size=11></td>
2231 <input type=hidden name=nextsub value=save_exchangerate>
2233 <input name=action class=submit type=submit value="|
2234 . $locale->text('Continue') . qq|">
2242 $lxdebug->leave_sub();
2245 sub save_exchangerate {
2246 $lxdebug->enter_sub();
2248 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2249 $form->{exchangerate} =
2250 $form->parse_amount(\%myconfig, $form->{exchangerate});
2251 $form->save_exchangerate(\%myconfig, $form->{currency},
2252 $form->{exchangeratedate},
2253 $form->{exchangerate}, $form->{buysell});
2257 $lxdebug->leave_sub();
2260 sub create_backorder {
2261 $lxdebug->enter_sub();
2263 $form->{shipped} = 1;
2265 # figure out if we need to create a backorder
2266 # items aren't saved if qty != 0
2268 for $i (1 .. $form->{rowcount}) {
2269 $totalqty += $qty = $form->{"qty_$i"};
2270 $totalship += $ship = $form->{"ship_$i"};
2272 $form->{"qty_$i"} = $qty - $ship;
2275 if ($totalship == 0) {
2276 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2277 $form->{ordtotal} = 0;
2278 $form->{shipped} = 0;
2282 if ($totalqty == $totalship) {
2283 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2284 $form->{ordtotal} = 0;
2289 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2292 for $i (1 .. $form->{rowcount}) {
2294 $form->{"${_}_$i"} =
2295 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2296 } qw(sellprice discount);
2301 OE->save(\%myconfig, \%$form);
2303 # rebuild rows for invoice
2307 for $i (1 .. $form->{rowcount}) {
2308 $form->{"qty_$i"} = $form->{"ship_$i"};
2310 if ($form->{"qty_$i"}) {
2313 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2318 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2319 $form->{rowcount} = $count;
2321 $lxdebug->leave_sub();
2325 $lxdebug->enter_sub();
2327 $form->{saveasnew} = 1;
2328 $form->{closed} = 0;
2329 map { delete $form->{$_} } qw(printed emailed queued);
2331 # Let Lx-Office assign a new order number if the user hasn't changed the
2332 # previous one. If it has been changed manually then use it as-is.
2333 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2334 $form->{$idx} =~ s/^\s*//g;
2335 $form->{$idx} =~ s/\s*$//g;
2336 if ($form->{saved_xyznumber} &&
2337 ($form->{saved_xyznumber} eq $form->{$idx})) {
2338 delete($form->{$idx});
2343 $lxdebug->leave_sub();
2346 sub check_for_direct_delivery_yes {
2347 $lxdebug->enter_sub();
2349 $form->{direct_delivery_checked} = 1;
2350 delete @{$form}{grep /^shipto/, keys %{ $form }};
2351 map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
2352 $form->{shipto} = 1;
2354 $lxdebug->leave_sub();
2357 sub check_for_direct_delivery_no {
2358 $lxdebug->enter_sub();
2360 $form->{direct_delivery_checked} = 1;
2361 delete @{$form}{grep /^shipto/, keys %{ $form }};
2364 $lxdebug->leave_sub();
2367 sub check_for_direct_delivery {
2368 $lxdebug->enter_sub();
2370 if ($form->{direct_delivery_checked}
2371 || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
2372 $lxdebug->leave_sub();
2376 if ($form->{shipto_id}) {
2377 Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_");
2380 map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form };
2383 delete $form->{action};
2384 $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ref $_ eq "" } keys %{ $form } ];
2387 print $form->parse_html_template("oe/check_for_direct_delivery");
2389 $lxdebug->leave_sub();
2394 sub purchase_order {
2395 $lxdebug->enter_sub();
2397 if ($form->{type} eq 'sales_order') {
2398 check_for_direct_delivery();
2401 if ( $form->{type} eq 'sales_quotation'
2402 || $form->{type} eq 'request_quotation') {
2403 OE->close_order(\%myconfig, \%$form);
2406 if ($form->{type} =~ /^sales_/) {
2407 delete($form->{ordnumber});
2410 $form->{cp_id} *= 1;
2412 $form->{title} = $locale->text('Add Purchase Order');
2413 $form->{vc} = "vendor";
2414 $form->{type} = "purchase_order";
2418 $lxdebug->leave_sub();
2422 $lxdebug->enter_sub();
2424 if ( $form->{type} eq 'sales_quotation'
2425 || $form->{type} eq 'request_quotation') {
2426 OE->close_order(\%myconfig, $form);
2429 if ($form->{type} eq "purchase_order") {
2430 delete($form->{ordnumber});
2433 $form->{cp_id} *= 1;
2435 $form->{title} = $locale->text('Add Sales Order');
2436 $form->{vc} = "customer";
2437 $form->{type} = "sales_order";
2441 $lxdebug->leave_sub();
2445 $lxdebug->enter_sub();
2447 $form->{transdate} = $form->current_date(\%myconfig);
2448 delete $form->{duedate};
2450 $form->{closed} = 0;
2452 $form->{old_employee_id} = $form->{employee_id};
2453 $form->{old_salesman_id} = $form->{salesman_id};
2456 map { delete $form->{$_} }
2457 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2459 for $i (1 .. $form->{rowcount}) {
2460 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2461 $form->{"${_}_${i}"})
2462 if ($form->{"${_}_${i}"}) }
2463 qw(ship qty sellprice listprice basefactor));
2471 for $i (1 .. $form->{rowcount} - 1) {
2472 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2473 qw(partnumber description unit);
2476 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2477 qw(creditlimit creditremaining);
2481 $lxdebug->leave_sub();
2485 $lxdebug->enter_sub();
2487 $form->{print_and_save} = 1;
2491 my $saved_form = save_form();
2496 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2497 restore_form($saved_form);
2498 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2502 $lxdebug->leave_sub();
2506 call_sub($form->{yes_nextsub});
2510 call_sub($form->{no_nextsub});