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),
412 "price_factors" => "ALL_PRICE_FACTORS");
415 my @values = (undef);
416 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
417 push(@values, $item->{"cp_id"});
418 $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
422 if (scalar @values > 1) {
425 <th align="right">| . $locale->text('Contact Person') . qq|</th>
427 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
428 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
437 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
438 push(@values, $item->{"name"}.qq|--|.$item->{"id"});
439 $labels{$item->{"name"}.qq|--|.$item->{"id"}} = $item->{name};
443 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
444 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
445 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
447 (($myconfig{vclimit} <= scalar(@values))
448 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
449 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
450 '-onChange' => 'document.getElementById(\'update_button\').click();',
451 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
452 <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
453 </td><input type=hidden name="select$form->{vc}" value="| .
454 Q($form->{"select$form->{vc}"}) . qq|">|;
458 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
459 push(@values, $item->{"id"});
460 $labels{$item->{"id"}} = $item->{"description"};
464 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
466 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
467 '-labels' => \%labels, '-default' => $form->{payment_id}))
472 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
473 push(@values, $item->{"shipto_id"});
474 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
478 if (scalar @values > 1) {
481 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
483 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
484 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
490 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
491 push(@values, $item->{"id"});
492 $labels{$item->{"id"}} = $item->{"projectnumber"};
494 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
495 '-labels' => \%labels,
496 '-default' => $form->{"globalproject_id"}));
501 if ($form->{type} =~ /^sales_/) {
502 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
503 push(@values, $item->{"id"});
504 $labels{$item->{"id"}} = ($item->{"name"} ne "" ? $item->{"name"} : $item->{"login"});
508 <th align="right">| . $locale->text('Salesman') . qq|</th>
510 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
511 '-values' => \@values, '-labels' => \%labels))
518 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
519 push(@values, $item->{"id"});
520 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
525 <th align="right">| . $locale->text('Employee') . qq|</th>
527 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
528 '-values' => \@values, '-labels' => \%labels)) . qq|
534 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
535 push(@values, $item->{"id"});
536 $labels{$item->{"id"}} = $item->{"description"};
541 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
543 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
544 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
551 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
552 push(@values, $item);
553 $labels{$item} = $item;
556 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
558 if (scalar @values) {
561 <th align="right">| . $locale->text('Currency') . qq|</th>
563 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
564 '-values' => \@values, '-labels' => \%labels)) . qq|
569 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
570 $form->{exchangerate} = "" unless $form->{exchangerate};
572 $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
574 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
575 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
577 $exchangerate = qq|\n<input type=hidden name=forex value=$form->{forex}>\n|;
579 if ($form->{currency} ne $form->{defaultcurrency}) {
580 if ($form->{forex}) {
582 qq|<th align=right>| . $locale->text('Exchangerate')
583 . qq|</th><td>$form->{exchangerate}</td>
584 <input type=hidden name=exchangerate value=$form->{exchangerate}>
588 qq|<th align=right>| . $locale->text('Exchangerate')
589 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
593 if ($form->{business}) {
596 <th align="right">| . ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type')) . qq|</th>
597 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
598 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
604 if ($form->{max_dunning_level}) {
607 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
609 <b>$form->{max_dunning_level}</b>;
610 | . $locale->text('Dunning Amount') . qq|: <b>|
611 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
618 if ($form->{type} !~ /_quotation$/) {
621 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
622 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
625 <th width=70% align=right nowrap>|
626 . $locale->text('Quotation Number') . qq|</th>
627 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
630 <th width=70% align=right nowrap>|
631 . $locale->text('Customer Order Number') . qq|</th>
632 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
635 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
640 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
645 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
647 $creditremaining = qq|
650 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
651 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
656 $reqlabel = ($form->{type} eq 'sales_quotation') ? $locale->text('Valid until') : $locale->text('Required by');
657 if ($form->{type} eq 'sales_quotation') {
660 <th width=70% align=right nowrap>|
661 . $locale->text('Quotation Number') . qq|</th>
662 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
663 <input type=hidden name=ordnumber value="$form->{ordnumber}">
669 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
670 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
671 <input type=hidden name=ordnumber value="$form->{ordnumber}">
677 $ordnumber .= qq| <tr> <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th> $button1 </tr>
678 <tr> <th align=right nowrap=true>$reqlabel</th> $button2 </tr>\n|;
679 $creditremaining = qq| <tr> <td colspan=4></td> $shipto </tr>|;
684 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
685 <td colspan=3><select name=department style="width: 250px">$form->{selectdepartment}</select>
686 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
688 </tr> | if $form->{selectdepartment};
690 if ($form->{type} eq 'sales_order') {
691 $employee .= qq|\n<input type="hidden" name="customer_klass" value="$form->{customer_klass}">| if $form->{selectemployee};
693 $employee .= qq|\n<input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
696 $credittext = $locale->text('Credit Limit exceeded!!!');
698 $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()"
699 : ($form->{resubmit}) ? "document.oe.submit()"
700 : ($creditwarning) ? "alert('$credittext')"
703 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
704 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
706 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
707 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
708 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
713 <body onLoad="$onload">
715 <form method=post name=oe action=$form->{script}>
717 <script type="text/javascript" src="js/common.js"></script>
718 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
719 <script type="text/javascript" src="js/vendor_selection.js"></script>
720 <script type="text/javascript" src="js/calculate_qty.js"></script>
723 $form->hide_form(qw(id action type vc formname media format proforma queued printed emailed
724 title discount creditlimit creditremaining tradediscount business
725 max_dunning_level dunning_amount shiptoname shiptostreet shiptozipcode
726 shiptocity shiptocountry shiptocontact shiptophone shiptofax
727 shiptodepartment_1 shiptodepartment_2 shiptoemail
728 message email subject cc bcc taxpart taxservice taxaccounts),
729 map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} );
734 <th class=listtop>$form->{title}</th>
756 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
757 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
760 <th align=right>| . $locale->text('Ship via') . qq|</th>
761 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
764 <th align="right">| . $locale->text('Transaction description') . qq|</th>
765 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
772 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
774 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
775 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
779 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
781 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
782 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
796 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
797 <td>$globalprojectnumber</td>
810 $lxdebug->leave_sub();
814 $lxdebug->enter_sub();
816 $form->{invtotal} = $form->{invsubtotal};
818 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
821 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
824 $rows = ($rows > $introws) ? $rows : $introws;
826 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
828 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
830 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
833 if ($form->{taxaccounts}) {
835 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
836 . $locale->text('Tax Included') . qq|</b><br><br>
840 if (!$form->{taxincluded}) {
842 foreach $item (split / /, $form->{taxaccounts}) {
843 if ($form->{"${item}_base"}) {
844 $form->{invtotal} += $form->{"${item}_total"} =
846 $form->{"${item}_base"} * $form->{"${item}_rate"},
848 $form->{"${item}_total"} =
849 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
853 <th align=right>$form->{"${item}_description"} |
854 . $form->{"${item}_rate"} * 100 .qq|%</th>
855 <td align=right>$form->{"${item}_total"}</td>
861 $form->{invsubtotal} =
862 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
866 <th align=right>| . $locale->text('Subtotal') . qq|</th>
867 <td align=right>$form->{invsubtotal}</td>
873 if ($form->{taxincluded}) {
874 foreach $item (split / /, $form->{taxaccounts}) {
875 if ($form->{"${item}_base"}) {
876 $form->{"${item}_total"} =
878 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
879 (1 + $form->{"${item}_rate"})
882 $form->{"${item}_netto"} =
884 ($form->{"${item}_base"} - $form->{"${item}_total"}),
886 $form->{"${item}_total"} =
887 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
888 $form->{"${item}_netto"} =
889 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
893 <th align=right>Enthaltene $form->{"${item}_description"} |
894 . $form->{"${item}_rate"} * 100 .qq|%</th>
895 <td align=right>$form->{"${item}_total"}</td>
898 <th align=right>Nettobetrag</th>
899 <td align=right>$form->{"${item}_netto"}</td>
907 $form->{oldinvtotal} = $form->{invtotal};
909 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
919 <th align=left>| . $locale->text('Notes') . qq|</th>
920 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
935 if ($form->{type} =~ /^sales_/) {
938 <th align=left>| . $locale->text('Ertrag') . qq|</th>
939 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
942 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
943 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
949 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
950 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
959 <th align=right>| . $locale->text('Total') . qq|</th>
960 <td align=right>$form->{invtotal}</td>
968 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
969 <input type=hidden name=oldtotalpaid value=$totalpaid>
971 <td><hr size=3 noshade></td>
979 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
982 <td align=left width=30%><b>Dateiname</b></td>
983 <td align=left width=70%><b>Webdavlink</b></td>
985 foreach $file (@{ $form->{WEBDAV} }) {
988 <td align="left">$file->{name}</td>
989 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
997 <td><hr size=3 noshade></td>
1015 | . $locale->text("Edit the $form->{type}") . qq|<br>
1016 <input class=submit type=submit name=action id=update_button value="|
1017 . $locale->text('Update') . qq|">
1018 <input class=submit type=submit name=action value="|
1019 . $locale->text('Ship to') . qq|">
1020 <input class=submit type=submit name=action value="|
1021 . $locale->text('Print') . qq|">
1022 <input class=submit type=submit name=action value="|
1023 . $locale->text('E-mail') . qq|">
1024 <input class=submit type=submit name=action value="|
1025 . $locale->text('Save') . qq|">
1026 <input class=submit type=submit name=action value="|
1027 . $locale->text('Save and Close') . qq|">
1030 if (($form->{id})) {
1032 <input type="button" class="submit" onclick="set_history_window(|
1034 . qq|);" name="history" id="history" value="|
1035 . $locale->text('history')
1038 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1039 <input class=submit type=submit name=action value="|
1040 . $locale->text('Save as new') . qq|">
1041 <input class=submit type=submit name=action value="|
1042 . $locale->text('Delete') . qq|">|;
1043 if (($form->{type} =~ /sales_quotation$/)) {
1045 <input class=submit type=submit name=action value="|
1046 . $locale->text('Sales Order') . qq|">|;
1048 if ($form->{type} =~ /request_quotation$/) {
1050 <input class=submit type=submit name=action value="|
1051 . $locale->text('Purchase Order') . qq|">|;
1054 <input class=submit type=submit name=action value="|
1055 . $locale->text('Invoice') . qq|">
1058 if ($form->{type} =~ /sales_order$/) {
1060 <br>$form->{heading} als neue Vorlage verwenden für<br>
1061 <input class=submit type=submit name=action value="|
1062 . $locale->text('Purchase Order') . qq|">
1063 <input class=submit type=submit name=action value="|
1064 . $locale->text('Quotation') . qq|">
1067 } elsif ($form->{type} =~ /purchase_order$/) {
1069 <br>$form->{heading} als neue Vorlage verwenden für<br>
1070 <input class=submit type=submit name=action value="|
1071 . $locale->text('Sales Order') . qq|">
1072 <input class=submit type=submit name=action value="|
1073 . $locale->text('Request for Quotation') . qq|">
1078 <br>$form->{heading} als neue Vorlage verwenden für<br>
1079 <input class=submit type=submit name=action value="|
1080 . $locale->text('Order') . qq|">
1085 $form->hide_form("saved_xyznumber");
1089 <input type=hidden name=rowcount value=$form->{rowcount}>
1091 <input name=callback type=hidden value="$form->{callback}">
1093 <input type=hidden name=login value=$form->{login}>
1094 <input type=hidden name=password value=$form->{password}>
1101 $lxdebug->leave_sub();
1105 $lxdebug->enter_sub();
1107 set_headings($form->{"id"} ? "edit" : "add");
1109 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
1110 $form->{update} = 1;
1112 $payment_id = $form->{payment_id} if $form->{payment_id};
1114 &check_name($form->{vc});
1116 $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
1119 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1120 $form->{exchangerate} = $exchangerate if
1121 $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
1124 $i = $form->{rowcount};
1126 $exchangerate = $form->{exchangerate} || 1;
1128 if ( ($form->{"partnumber_$i"} eq "")
1129 && ($form->{"description_$i"} eq "")
1130 && ($form->{"partsgroup_$i"} eq "")) {
1132 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1137 if ( $form->{type} eq 'purchase_order'
1138 || $form->{type} eq 'request_quotation') {
1139 IR->retrieve_item(\%myconfig, \%$form);
1141 if ( $form->{type} eq 'sales_order'
1142 || $form->{type} eq 'sales_quotation') {
1143 IS->retrieve_item(\%myconfig, \%$form);
1146 my $rows = scalar @{ $form->{item_list} };
1148 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
1151 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1160 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1161 $form->{"discount_$i"} = 0 if $form->{"not_discountable_$i"};
1162 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
1163 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
1164 $form->{payment_id} = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
1166 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
1168 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
1169 $decimalplaces = max 2, length $1;
1172 $form->{"sellprice_$i"} = $sellprice;
1174 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1175 $form->{"sellprice_$i"} /= $exchangerate; # if there is an exchange rate adjust sellprice
1178 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
1179 map { $form->{"${_}_base"} = 0 } split / /, $form->{taxaccounts};
1180 map { $form->{"${_}_base"} += $amount } split / /, $form->{"taxaccounts_$i"};
1181 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
1183 $form->{creditremaining} -= $amount;
1185 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
1186 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1188 # get pricegroups for parts
1189 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1191 # build up html code for prices_$i
1192 &set_pricegroup($i);
1199 # ok, so this is a new part
1200 # ask if it is a part or service item
1202 if ( $form->{"partsgroup_$i"}
1203 && ($form->{"partsnumber_$i"} eq "")
1204 && ($form->{"description_$i"} eq "")) {
1205 $form->{rowcount}--;
1206 $form->{"discount_$i"} = "";
1210 $form->{"id_$i"} = 0;
1216 $lxdebug->leave_sub();
1220 $lxdebug->enter_sub();
1222 if ($form->{type} eq 'purchase_order') {
1223 $form->{title} = $locale->text('Purchase Orders');
1224 $form->{vc} = 'vendor';
1225 $ordlabel = $locale->text('Order Number');
1226 $ordnumber = 'ordnumber';
1227 $employee = $locale->text('Employee');
1230 if ($form->{type} eq 'request_quotation') {
1231 $form->{title} = $locale->text('Request for Quotations');
1232 $form->{vc} = 'vendor';
1233 $ordlabel = $locale->text('RFQ Number');
1234 $ordnumber = 'quonumber';
1235 $employee = $locale->text('Employee');
1238 if ($form->{type} eq 'sales_order') {
1239 $form->{title} = $locale->text('Sales Orders');
1240 $form->{vc} = 'customer';
1241 $ordlabel = $locale->text('Order Number');
1242 $ordnumber = 'ordnumber';
1243 $employee = $locale->text('Employee');
1246 if ($form->{type} eq 'sales_quotation') {
1247 $form->{title} = $locale->text('Quotations');
1248 $form->{vc} = 'customer';
1249 $ordlabel = $locale->text('Quotation Number');
1250 $ordnumber = 'quonumber';
1251 $employee = $locale->text('Employee');
1254 # setup vendor / customer selection
1255 $form->all_vc(\%myconfig, $form->{vc},
1256 ($form->{vc} eq 'customer') ? "AR" : "AP");
1259 if (@{ $form->{all_departments} }) {
1260 $form->{selectdepartment} = "<option>\n";
1263 $form->{selectdepartment} .=
1264 "<option>$_->{description}--$_->{id}</option>\n"
1265 } (@{ $form->{all_departments} });
1270 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1271 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1273 | if $form->{selectdepartment};
1276 if (($form->{"type"} eq "sales_order") ||
1277 ($form->{"type"} eq "purchase_order")) {
1280 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1281 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1282 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1283 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1288 # use JavaScript Calendar or not
1289 $form->{jsscript} = 1;
1293 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1294 <input type=button name=transdatefrom id="trigger3" value=|
1295 . $locale->text('button') . qq|></td>
1298 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1299 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1300 . $locale->text('button') . qq|></td>
1305 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1306 "transdateto", "BL", "trigger4");
1308 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1310 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1312 "employees" => "ALL_EMPLOYEES",
1313 $vc => "ALL_" . uc($vc));
1317 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1318 push(@values, $item->{"id"});
1319 $labels{$item->{"id"}} = $item->{"projectnumber"};
1322 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1323 '-labels' => \%labels));
1328 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
1329 push(@values, $item->{"id"});
1330 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
1333 my $employee_block = qq|
1335 <th align="right">| . $locale->text('Employee') . qq|</th>
1337 NTI($cgi->popup_menu('-name' => 'employee_id',
1338 '-values' => \@values,
1339 '-labels' => \%labels)) . qq|
1346 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1347 push(@values, $item->{name}.qq|--|.$item->{"id"});
1348 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
1351 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1353 $myconfig{vclimit} <= scalar(@values)
1354 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
1355 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1356 '-default' => $form->{"old$form->{vc}"},
1357 '-onChange' => 'document.getElementById(\'update_button\').click();',
1358 '-values' => \@values,
1359 '-labels' => \%labels));
1365 <form method=post action=$form->{script}>
1369 <th class=listtop>$form->{title}</th>
1371 <tr height="5"></tr>
1376 <th align=right>$vc_label</th>
1377 <td colspan=3>$vc</td>
1381 <th align=right>$ordlabel</th>
1382 <td colspan=3><input name="$ordnumber" size=20></td>
1386 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1387 <td colspan="3"><input name="transaction_description" size=20></td>
1390 <th align="right">| . $locale->text("Project Number") . qq|</th>
1391 <td colspan="3">$projectnumber</td>
1394 <th align=right>| . $locale->text('From') . qq|</th>
1396 <th align=right>| . $locale->text('Bis') . qq|</th>
1399 <input type=hidden name=sort value=transdate>
1401 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1405 <td><input type="checkbox" name="open" value="1" id="open" checked>
1406 <label for="open">| . $locale->text("Open") . qq|</td>
1407 <td><input type="checkbox" name="closed" value="1" id="closed">
1408 <label for="closed">| . $locale->text("Closed") . qq|</td>
1412 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1413 | . $locale->text('ID') . qq|</td>
1414 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1415 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1416 . $locale->text('Date') . qq|</td>
1417 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1418 . $locale->text('Required by') . qq|</td>
1421 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vc_label</td>
1422 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1423 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1424 . $locale->text('Ship via') . qq|</td>
1427 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1428 . $locale->text('Amount') . qq|</td>
1429 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1430 . $locale->text('Tax') . qq|</td>
1431 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1432 . $locale->text('Total') . qq|</td>
1435 <td><input name="l_marge_total" class=checkbox type=checkbox value=Y> |
1436 . $locale->text('Ertrag') . qq|</td>
1437 <td><input name="l_marge_percent" class=checkbox type=checkbox value=Y> |
1438 . $locale->text('Ertrag prozentual') . qq|</td>
1441 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1442 . $locale->text('Project Number') . qq|</td>
1443 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1444 . $locale->text('Transaction description') . qq|</td>
1447 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1448 . $locale->text('Subtotal') . qq|</td>
1456 <tr><td colspan=4><hr size=3 noshade></td></tr>
1462 <input type=hidden name=nextsub value=orders>
1463 <input type=hidden name=login value=$form->{login}>
1464 <input type=hidden name=password value=$form->{password}>
1465 <input type=hidden name=vc value=$form->{vc}>
1466 <input type=hidden name=type value=$form->{type}>
1468 <input class=submit type=submit name=action value="|
1469 . $locale->text('Continue') . qq|">
1476 $lxdebug->leave_sub();
1479 sub create_subtotal_row {
1480 $lxdebug->enter_sub();
1482 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1484 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1486 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1488 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1490 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1492 $lxdebug->leave_sub();
1498 $lxdebug->enter_sub();
1500 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1502 ($form->{ $form->{vc} }, $form->{"${form->{vc}}_id"}) = split(/--/, $form->{ $form->{vc} });
1504 $form->{sort} ||= 'transdate';
1506 OE->transactions(\%myconfig, \%$form);
1508 $form->{rowcount} = scalar @{ $form->{OE} };
1511 "transdate", "reqdate",
1513 "name", "netamount",
1516 "shipvia", "globalprojectnumber",
1517 "transaction_description", "open",
1518 "delivered", "marge_total", "marge_percent"
1521 # only show checkboxes if gotten here via sales_order form.
1522 my $allow_multiple_orders = $form->{type} eq 'sales_order';
1523 if ($allow_multiple_orders) {
1524 unshift @columns, "ids";
1527 $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed});
1528 $form->{l_delivered} = "Y" if ($form->{delivered} && $form->{notdelivered});
1530 my $attachment_basename;
1531 if ($form->{vc} eq 'vendor') {
1532 if ($form->{type} eq 'purchase_order') {
1533 $form->{title} = $locale->text('Purchase Orders');
1534 $attachment_basename = $locale->text('purchase_order_list');
1536 $form->{title} = $locale->text('Request for Quotations');
1537 $attachment_basename = $locale->text('rfq_list');
1541 if ($form->{type} eq 'sales_order') {
1542 $form->{title} = $locale->text('Sales Orders');
1543 $attachment_basename = $locale->text('sales_order_list');
1545 $form->{title} = $locale->text('Quotations');
1546 $attachment_basename = $locale->text('quotation_list');
1550 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1552 my @hidden_variables = map { "l_${_}" } @columns;
1553 push @hidden_variables, "l_subtotal", $form->{vc}, qw(l_closed l_notdelivered open closed delivered notdelivered ordnumber quonumber
1554 transaction_description transdatefrom transdateto type vc employee_id);
1556 my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
1559 'ids' => { 'text' => '', },
1560 'transdate' => { 'text' => $locale->text('Date'), },
1561 'reqdate' => { 'text' => $locale->text('Required by'), },
1562 'id' => { 'text' => $locale->text('ID'), },
1563 'ordnumber' => { 'text' => $locale->text('Order'), },
1564 'quonumber' => { 'text' => $form->{type} eq "request_quotation" ? $locale->text('RFQ') : $locale->text('Quotation'), },
1565 'name' => { 'text' => $form->{vc} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1566 'netamount' => { 'text' => $locale->text('Amount'), },
1567 'tax' => { 'text' => $locale->text('Tax'), },
1568 'amount' => { 'text' => $locale->text('Total'), },
1569 'curr' => { 'text' => $locale->text('Curr'), },
1570 'employee' => { 'text' => $locale->text('Salesperson'), },
1571 'shipvia' => { 'text' => $locale->text('Ship via'), },
1572 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1573 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1574 'open' => { 'text' => $locale->text('Open'), },
1575 'delivered' => { 'text' => $locale->text('Delivered'), },
1576 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1577 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), }
1580 foreach my $name (qw(id transdate reqdate quonumber ordnumber name employee shipvia)) {
1581 $column_defs{$name}->{link} = $href . "&sort=$name";
1584 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount curr);
1586 $form->{"l_type"} = "Y";
1587 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1588 $column_defs{ids}->{visible} = $allow_multiple_orders ? 'HTML' : 0;
1590 $report->set_columns(%column_defs);
1591 $report->set_column_order(@columns);
1593 $report->set_export_options('orders', @hidden_variables);
1595 $report->set_sort_indicator($form->{sort}, 1);
1598 if ($form->{customer}) {
1599 push @options, $locale->text('Customer') . " : $form->{customer}";
1601 if ($form->{vendor}) {
1602 push @options, $locale->text('Vendor') . " : $form->{vendor}";
1604 if ($form->{department}) {
1605 ($department) = split /--/, $form->{department};
1606 push @options, $locale->text('Department') . " : $department";
1608 if ($form->{ordnumber}) {
1609 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1611 if ($form->{notes}) {
1612 push @options, $locale->text('Notes') . " : $form->{notes}";
1614 if ($form->{transaction_description}) {
1615 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1617 if ($form->{transdatefrom}) {
1618 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1620 if ($form->{transdateto}) {
1621 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1623 if ($form->{open}) {
1624 push @options, $locale->text('Open');
1626 if ($form->{closed}) {
1627 push @options, $locale->text('Closed');
1629 if ($form->{delivered}) {
1630 push @options, $locale->text('Delivered');
1632 if ($form->{notdelivered}) {
1633 push @options, $locale->text('Not delivered');
1636 $report->set_options('top_info_text' => join("\n", @options),
1637 'raw_top_info_text' => $form->parse_html_template('oe/orders_top'),
1638 'raw_bottom_info_text' => $form->parse_html_template('oe/orders_bottom', { 'SHOW_CONTINUE_BUTTON' => $allow_multiple_orders }),
1639 'output_format' => 'HTML',
1640 'title' => $form->{title},
1641 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1643 $report->set_options_from_form();
1645 # add sort and escape callback, this one we use for the add sub
1646 $form->{callback} = $href .= "&sort=$form->{sort}";
1648 # escape callback for href
1649 $callback = $form->escape($href);
1651 my @subtotal_columns = qw(netamount amount marge_total marge_percent);
1653 my %totals = map { $_ => 0 } @subtotal_columns;
1654 my %subtotals = map { $_ => 0 } @subtotal_columns;
1658 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1660 foreach $oe (@{ $form->{OE} }) {
1661 map { $oe->{$_} *= $oe->{exchangerate} } @subtotal_columns;
1663 $oe->{tax} = $oe->{amount} - $oe->{netamount};
1664 $oe->{open} = $oe->{closed} ? $locale->text('No') : $locale->text('Yes');
1665 $oe->{delivered} = $oe->{delivered} ? $locale->text('Yes') : $locale->text('No');
1667 map { $subtotals{$_} += $oe->{$_};
1668 $totals{$_} += $oe->{$_} } @subtotal_columns;
1670 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1671 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1673 map { $oe->{$_} = $form->format_amount(\%myconfig, $oe->{$_}, 2) } qw(netamount tax amount marge_total marge_percent);
1677 foreach my $column (@columns) {
1678 next if ($column eq 'ids');
1680 'data' => $oe->{$column},
1681 'align' => $column_alignment{$column},
1686 'raw_data' => $cgi->hidden('-name' => "trans_id_${idx}", '-value' => $oe->{id})
1687 . $cgi->checkbox('-name' => "multi_id_${idx}", '-value' => 1, '-label' => ''),
1688 'valign' => 'center',
1689 'align' => 'center',
1692 $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1694 my $row_set = [ $row ];
1696 if (($form->{l_subtotal} eq 'Y')
1697 && (($idx == (scalar @{ $form->{OE} } - 1))
1698 || ($oe->{ $form->{sort} } ne $form->{OE}->[$idx + 1]->{ $form->{sort} }))) {
1699 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1702 $report->add_data($row_set);
1707 $report->add_separator();
1708 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1710 $report->generate_with_headers();
1712 $lxdebug->leave_sub();
1715 sub check_delivered_flag {
1716 $lxdebug->enter_sub();
1718 if (($form->{type} ne 'sales_order') && ($form->{type} ne 'purchase_order')) {
1719 return $lxdebug->leave_sub();
1722 my $all_delivered = 0;
1724 foreach my $i (1 .. $form->{rowcount}) {
1725 next if (!$form->{"id_$i"});
1727 if ($form->parse_amount(\%myconfig, $form->{"qty_$i"}) == $form->parse_amount(\%myconfig, $form->{"ship_$i"})) {
1736 $form->{delivered} = 1 if $all_delivered;
1738 $lxdebug->leave_sub();
1741 sub save_and_close {
1742 $lxdebug->enter_sub();
1744 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1746 if ($form->{type} =~ /_order$/) {
1747 $form->isblank("transdate", $locale->text('Order Date missing!'));
1749 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1752 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1753 $form->{$idx} =~ s/^\s*//g;
1754 $form->{$idx} =~ s/\s*$//g;
1756 $msg = ucfirst $form->{vc};
1757 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1759 # $locale->text('Customer missing!');
1760 # $locale->text('Vendor missing!');
1762 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1763 if ($form->{currency} ne $form->{defaultcurrency});
1767 if($form->{payment_id}) {
1768 $payment_id = $form->{payment_id};
1771 # if the name changed get new values
1772 if (&check_name($form->{vc})) {
1773 if($form->{payment_id} eq "") {
1774 $form->{payment_id} = $payment_id;
1780 $form->{id} = 0 if $form->{saveasnew};
1782 # this is for the internal notes section for the [email] Subject
1783 if ($form->{type} =~ /_order$/) {
1784 if ($form->{type} eq 'sales_order') {
1785 $form->{label} = $locale->text('Sales Order');
1787 $numberfld = "sonumber";
1788 $ordnumber = "ordnumber";
1790 $form->{label} = $locale->text('Purchase Order');
1792 $numberfld = "ponumber";
1793 $ordnumber = "ordnumber";
1796 $err = $locale->text('Cannot save order!');
1798 check_delivered_flag();
1801 if ($form->{type} eq 'sales_quotation') {
1802 $form->{label} = $locale->text('Quotation');
1804 $numberfld = "sqnumber";
1805 $ordnumber = "quonumber";
1807 $form->{label} = $locale->text('Request for Quotation');
1809 $numberfld = "rfqnumber";
1810 $ordnumber = "quonumber";
1813 $err = $locale->text('Cannot save quotation!');
1817 # get new number in sequence if no number is given or if saveasnew was requested
1818 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1819 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1824 $form->error($err) if (!OE->save(\%myconfig, \%$form));
1826 # saving the history
1827 if(!exists $form->{addition}) {
1828 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1829 $form->{addition} = "SAVED";
1830 $form->save_history($form->dbconnect(\%myconfig));
1832 # /saving the history
1834 $form->redirect($form->{label} . " $form->{$ordnumber} " .
1835 $locale->text('saved!'));
1837 $lxdebug->leave_sub();
1841 $lxdebug->enter_sub();
1843 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1846 if ($form->{type} =~ /_order$/) {
1847 $form->isblank("transdate", $locale->text('Order Date missing!'));
1849 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1852 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1853 $form->{$idx} =~ s/^\s*//g;
1854 $form->{$idx} =~ s/\s*$//g;
1856 $msg = ucfirst $form->{vc};
1857 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1859 # $locale->text('Customer missing!');
1860 # $locale->text('Vendor missing!');
1862 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1863 if ($form->{currency} ne $form->{defaultcurrency});
1867 if($form->{payment_id}) {
1868 $payment_id = $form->{payment_id};
1871 # if the name changed get new values
1872 if (&check_name($form->{vc})) {
1873 if($form->{payment_id} eq "") {
1874 $form->{payment_id} = $payment_id;
1880 $form->{id} = 0 if $form->{saveasnew};
1882 # this is for the internal notes section for the [email] Subject
1883 if ($form->{type} =~ /_order$/) {
1884 if ($form->{type} eq 'sales_order') {
1885 $form->{label} = $locale->text('Sales Order');
1887 $numberfld = "sonumber";
1888 $ordnumber = "ordnumber";
1890 $form->{label} = $locale->text('Purchase Order');
1892 $numberfld = "ponumber";
1893 $ordnumber = "ordnumber";
1896 $err = $locale->text('Cannot save order!');
1898 check_delivered_flag();
1901 if ($form->{type} eq 'sales_quotation') {
1902 $form->{label} = $locale->text('Quotation');
1904 $numberfld = "sqnumber";
1905 $ordnumber = "quonumber";
1907 $form->{label} = $locale->text('Request for Quotation');
1909 $numberfld = "rfqnumber";
1910 $ordnumber = "quonumber";
1913 $err = $locale->text('Cannot save quotation!');
1917 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
1918 unless $form->{$ordnumber};
1922 OE->save(\%myconfig, \%$form);
1924 # saving the history
1925 if(!exists $form->{addition}) {
1926 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1927 $form->{addition} = "SAVED";
1928 $form->save_history($form->dbconnect(\%myconfig));
1930 # /saving the history
1932 $form->{simple_save} = 1;
1933 if(!$form->{print_and_save}) {
1934 set_headings("edit");
1938 $lxdebug->leave_sub();
1942 $lxdebug->enter_sub();
1946 if ($form->{type} =~ /_order$/) {
1947 $msg = $locale->text('Are you sure you want to delete Order Number');
1948 $ordnumber = 'ordnumber';
1950 $msg = $locale->text('Are you sure you want to delete Quotation Number');
1951 $ordnumber = 'quonumber';
1957 <form method=post action=$form->{script}>
1960 # delete action variable
1961 map { delete $form->{$_} } qw(action header);
1963 foreach $key (keys %$form) {
1964 $form->{$key} =~ s/\"/"/g;
1965 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1969 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1971 <h4>$msg $form->{$ordnumber}</h4>
1973 <input type="hidden" name="yes_nextsub" value="delete_order_quotation">
1974 <input name=action class=submit type=submit value="|
1975 . $locale->text('Yes') . qq|">
1976 <button class=submit type=button onclick="history.back()">|
1977 . $locale->text('No') . qq|</button>
1984 $lxdebug->leave_sub();
1987 sub delete_order_quotation {
1988 $lxdebug->enter_sub();
1990 if ($form->{type} =~ /_order$/) {
1991 $msg = $locale->text('Order deleted!');
1992 $err = $locale->text('Cannot delete order!');
1994 $msg = $locale->text('Quotation deleted!');
1995 $err = $locale->text('Cannot delete quotation!');
1997 if (OE->delete(\%myconfig, \%$form, $spool)){
1998 # saving the history
1999 if(!exists $form->{addition}) {
2000 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2001 $form->{addition} = "DELETED";
2002 $form->save_history($form->dbconnect(\%myconfig));
2004 # /saving the history
2010 $lxdebug->leave_sub();
2014 $lxdebug->enter_sub();
2016 $form->{old_employee_id} = $form->{employee_id};
2017 $form->{old_salesman_id} = $form->{salesman_id};
2019 if ($form->{type} =~ /_order$/) {
2021 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2022 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2023 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2024 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2025 $form->isblank("transdate", $locale->text('Order Date missing!'))
2026 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2028 # also copy deliverydate from the order
2029 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2030 $form->{orddate} = $form->{transdate};
2032 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2033 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2034 $form->{ordnumber} = "";
2035 $form->{quodate} = $form->{transdate};
2038 $payment_id = $form->{payment_id} if $form->{payment_id};
2040 # if the name changed get new values
2041 if (&check_name($form->{vc})) {
2042 $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
2047 $form->{cp_id} *= 1;
2049 for $i (1 .. $form->{rowcount}) {
2050 for (qw(ship qty sellprice listprice basefactor)) {
2051 $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"};
2055 if ( $form->{type} =~ /_order/
2056 && $form->{currency} ne $form->{defaultcurrency}) {
2058 # check if we need a new exchangerate
2059 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2061 $orddate = $form->current_date(\%myconfig);
2062 $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate, $buysell);
2064 if (!$exchangerate) {
2065 &backorder_exchangerate($orddate, $buysell);
2070 # close orders/quotations
2071 $form->{closed} = 1;
2073 # save order if one ordnumber has been given
2074 # if not it's most likely a collective order, which can't be saved back
2075 # so they just have to be closed
2076 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2077 OE->close_order(\%myconfig, \%$form) if ($form->{id});
2079 OE->close_orders(\%myconfig, \%$form);
2082 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2083 $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2086 $form->{closed} = 0;
2087 $form->{rowcount}--;
2088 $form->{shipto} = 1;
2090 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
2092 if ($form->{type} =~ /_order$/) {
2093 $form->{exchangerate} = $exchangerate;
2097 if ( $form->{type} eq 'purchase_order'
2098 || $form->{type} eq 'request_quotation') {
2099 $form->{title} = $locale->text('Add Vendor Invoice');
2100 $form->{script} = 'ir.pl';
2105 if ( $form->{type} eq 'sales_order'
2106 || $form->{type} eq 'sales_quotation') {
2107 $form->{title} = $locale->text('Add Sales Invoice');
2108 $form->{script} = 'is.pl';
2113 # bo creates the id, reset it
2114 map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued);
2115 $form->{ $form->{vc} } =~ s/--.*//g;
2116 $form->{type} = "invoice";
2119 $locale = new Locale "$myconfig{countrycode}", "$script";
2121 require "bin/mozilla/$form->{script}";
2123 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2125 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2126 qw(creditlimit creditremaining);
2128 $currency = $form->{currency};
2131 $form->{currency} = $currency;
2132 $form->{exchangerate} = "";
2133 $form->{forex} = "";
2134 $form->{exchangerate} = $exchangerate
2138 $form->check_exchangerate(
2139 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2142 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2147 for $i (1 .. $form->{rowcount}) {
2148 $form->{"discount_$i"} =
2149 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2151 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2153 $decimalplaces = ($dec > 2) ? $dec : 2;
2155 # copy delivery date from reqdate for order -> invoice conversion
2156 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2157 unless $form->{"deliverydate_$i"};
2159 $form->{"sellprice_$i"} =
2160 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2163 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2164 $dec_qty = length $dec_qty;
2166 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2168 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2169 qw(partnumber description unit);
2175 $lxdebug->leave_sub();
2178 sub backorder_exchangerate {
2179 $lxdebug->enter_sub();
2180 my ($orddate, $buysell) = @_;
2187 <form method=post action=$form->{script}>
2190 # delete action variable
2191 map { delete $form->{$_} } qw(action header exchangerate);
2193 foreach $key (keys %$form) {
2194 $form->{$key} =~ s/\"/"/g;
2195 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2198 $form->{title} = $locale->text('Add Exchangerate');
2202 <input type=hidden name=login value=$form->{login}>
2203 <input type=hidden name=password value=$form->{password}>
2205 <input type=hidden name=exchangeratedate value=$orddate>
2206 <input type=hidden name=buysell value=$buysell>
2209 <tr><th class=listtop>$form->{title}</th></tr>
2210 <tr height="5"></tr>
2215 <th align=right>| . $locale->text('Currency') . qq|</th>
2216 <td>$form->{currency}</td>
2219 <th align=right>| . $locale->text('Date') . qq|</th>
2223 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2224 <td><input name=exchangerate size=11></td>
2234 <input type=hidden name=nextsub value=save_exchangerate>
2236 <input name=action class=submit type=submit value="|
2237 . $locale->text('Continue') . qq|">
2245 $lxdebug->leave_sub();
2248 sub save_exchangerate {
2249 $lxdebug->enter_sub();
2251 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2252 $form->{exchangerate} =
2253 $form->parse_amount(\%myconfig, $form->{exchangerate});
2254 $form->save_exchangerate(\%myconfig, $form->{currency},
2255 $form->{exchangeratedate},
2256 $form->{exchangerate}, $form->{buysell});
2260 $lxdebug->leave_sub();
2263 sub create_backorder {
2264 $lxdebug->enter_sub();
2266 $form->{shipped} = 1;
2268 # figure out if we need to create a backorder
2269 # items aren't saved if qty != 0
2271 for $i (1 .. $form->{rowcount}) {
2272 $totalqty += $qty = $form->{"qty_$i"};
2273 $totalship += $ship = $form->{"ship_$i"};
2275 $form->{"qty_$i"} = $qty - $ship;
2278 if ($totalship == 0) {
2279 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2280 $form->{ordtotal} = 0;
2281 $form->{shipped} = 0;
2285 if ($totalqty == $totalship) {
2286 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2287 $form->{ordtotal} = 0;
2292 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2295 for $i (1 .. $form->{rowcount}) {
2297 $form->{"${_}_$i"} =
2298 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2299 } qw(sellprice discount);
2304 OE->save(\%myconfig, \%$form);
2306 # rebuild rows for invoice
2310 for $i (1 .. $form->{rowcount}) {
2311 $form->{"qty_$i"} = $form->{"ship_$i"};
2313 if ($form->{"qty_$i"}) {
2316 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2321 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2322 $form->{rowcount} = $count;
2324 $lxdebug->leave_sub();
2328 $lxdebug->enter_sub();
2330 $form->{saveasnew} = 1;
2331 $form->{closed} = 0;
2332 map { delete $form->{$_} } qw(printed emailed queued);
2334 # Let Lx-Office assign a new order number if the user hasn't changed the
2335 # previous one. If it has been changed manually then use it as-is.
2336 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2337 $form->{$idx} =~ s/^\s*//g;
2338 $form->{$idx} =~ s/\s*$//g;
2339 if ($form->{saved_xyznumber} &&
2340 ($form->{saved_xyznumber} eq $form->{$idx})) {
2341 delete($form->{$idx});
2346 $lxdebug->leave_sub();
2349 sub check_for_direct_delivery_yes {
2350 $lxdebug->enter_sub();
2352 $form->{direct_delivery_checked} = 1;
2353 delete @{$form}{grep /^shipto/, keys %{ $form }};
2354 map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
2355 $form->{shipto} = 1;
2357 $lxdebug->leave_sub();
2360 sub check_for_direct_delivery_no {
2361 $lxdebug->enter_sub();
2363 $form->{direct_delivery_checked} = 1;
2364 delete @{$form}{grep /^shipto/, keys %{ $form }};
2367 $lxdebug->leave_sub();
2370 sub check_for_direct_delivery {
2371 $lxdebug->enter_sub();
2373 if ($form->{direct_delivery_checked}
2374 || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
2375 $lxdebug->leave_sub();
2379 if ($form->{shipto_id}) {
2380 Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_");
2383 map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form };
2386 delete $form->{action};
2387 $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ref $_ eq "" } keys %{ $form } ];
2390 print $form->parse_html_template("oe/check_for_direct_delivery");
2392 $lxdebug->leave_sub();
2397 sub purchase_order {
2398 $lxdebug->enter_sub();
2400 if ($form->{type} eq 'sales_order') {
2401 check_for_direct_delivery();
2404 if ( $form->{type} eq 'sales_quotation'
2405 || $form->{type} eq 'request_quotation') {
2406 OE->close_order(\%myconfig, \%$form);
2409 if ($form->{type} =~ /^sales_/) {
2410 delete($form->{ordnumber});
2413 $form->{cp_id} *= 1;
2415 $form->{title} = $locale->text('Add Purchase Order');
2416 $form->{vc} = "vendor";
2417 $form->{type} = "purchase_order";
2421 $lxdebug->leave_sub();
2425 $lxdebug->enter_sub();
2427 if ( $form->{type} eq 'sales_quotation'
2428 || $form->{type} eq 'request_quotation') {
2429 OE->close_order(\%myconfig, $form);
2432 if ($form->{type} eq "purchase_order") {
2433 delete($form->{ordnumber});
2436 $form->{cp_id} *= 1;
2438 $form->{title} = $locale->text('Add Sales Order');
2439 $form->{vc} = "customer";
2440 $form->{type} = "sales_order";
2444 $lxdebug->leave_sub();
2448 $lxdebug->enter_sub();
2450 $form->{transdate} = $form->current_date(\%myconfig);
2451 delete $form->{duedate};
2453 $form->{closed} = 0;
2455 $form->{old_employee_id} = $form->{employee_id};
2456 $form->{old_salesman_id} = $form->{salesman_id};
2459 map { delete $form->{$_} }
2460 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2462 for $i (1 .. $form->{rowcount}) {
2463 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2464 $form->{"${_}_${i}"})
2465 if ($form->{"${_}_${i}"}) }
2466 qw(ship qty sellprice listprice basefactor));
2474 for $i (1 .. $form->{rowcount} - 1) {
2475 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2476 qw(partnumber description unit);
2479 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2480 qw(creditlimit creditremaining);
2484 $lxdebug->leave_sub();
2488 $lxdebug->enter_sub();
2490 $form->{print_and_save} = 1;
2494 my $saved_form = save_form();
2499 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2500 restore_form($saved_form);
2501 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2505 $lxdebug->leave_sub();
2509 call_sub($form->{yes_nextsub});
2513 call_sub($form->{no_nextsub});