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;
42 require "bin/mozilla/io.pl";
43 require "bin/mozilla/arap.pl";
44 require "bin/mozilla/reportgenerator.pl";
51 # $locale->text('Edit the purchase_order');
52 # $locale->text('Edit the sales_order');
53 # $locale->text('Edit the request_quotation');
54 # $locale->text('Edit the sales_quotation');
56 # $locale->text('Workflow purchase_order');
57 # $locale->text('Workflow sales_order');
58 # $locale->text('Workflow request_quotation');
59 # $locale->text('Workflow sales_quotation');
62 $lxdebug->enter_sub();
66 if ($form->{type} eq 'purchase_order') {
67 $form->{title} = $action eq "edit" ?
68 $locale->text('Edit Purchase Order') :
69 $locale->text('Add Purchase Order');
70 $form->{heading} = $locale->text('Purchase Order');
71 $form->{vc} = 'vendor';
73 if ($form->{type} eq 'sales_order') {
74 $form->{title} = $action eq "edit" ?
75 $locale->text('Edit Sales Order') :
76 $locale->text('Add Sales Order');
77 $form->{heading} = $locale->text('Sales Order');
78 $form->{vc} = 'customer';
80 if ($form->{type} eq 'request_quotation') {
81 $form->{title} = $action eq "edit" ?
82 $locale->text('Edit Request for Quotation') :
83 $locale->text('Add Request for Quotation');
84 $form->{heading} = $locale->text('Request for Quotation');
85 $form->{vc} = 'vendor';
87 if ($form->{type} eq 'sales_quotation') {
88 $form->{title} = $action eq "edit" ?
89 $locale->text('Edit Quotation') :
90 $locale->text('Add Quotation');
91 $form->{heading} = $locale->text('Quotation');
92 $form->{vc} = 'customer';
95 $lxdebug->leave_sub();
99 $lxdebug->enter_sub();
104 "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}"
105 unless $form->{callback};
111 $lxdebug->leave_sub();
115 $lxdebug->enter_sub();
116 # show history button
117 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
118 #/show hhistory button
120 $form->{simple_save} = 0;
122 set_headings("edit");
124 # editing without stuff to edit? try adding it first
125 if ($form->{rowcount} && !$form->{print_and_save}) {
126 map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount});
130 undef $form->{rowcount};
132 $lxdebug->leave_sub();
135 } elsif (!$form->{id}) {
137 $lxdebug->leave_sub();
141 if ($form->{print_and_save}) {
142 $form->{action} = "print";
143 $form->{resubmit} = 1;
144 $language_id = $form->{language_id};
145 $printer_id = $form->{printer_id};
148 set_headings("edit");
152 if ($form->{print_and_save}) {
153 $form->{language_id} = $language_id;
154 $form->{printer_id} = $printer_id;
158 $lxdebug->leave_sub();
162 $lxdebug->enter_sub();
163 # get customer/vendor
164 $form->all_vc(\%myconfig, $form->{vc},
165 ($form->{vc} eq 'customer') ? "AR" : "AP");
167 # retrieve order/quotation
168 $form->{webdav} = $webdav;
169 $form->{jsscript} = 1;
171 my $editing = $form->{id};
173 OE->retrieve(\%myconfig, \%$form);
175 if ($form->{payment_id}) {
176 $payment_id = $form->{payment_id};
178 if ($form->{language_id}) {
179 $language_id = $form->{language_id};
181 if ($form->{taxzone_id}) {
182 $taxzone_id = $form->{taxzone_id};
185 $salesman_id = $form->{salesman_id} if ($editing);
188 # if multiple rowcounts (== collective order) then check if the
189 # there were more than one customer (in that case OE::retrieve removes
190 # the content from the field)
191 if ( $form->{rowcount}
192 && $form->{type} eq 'sales_order'
193 && defined $form->{customer}
194 && $form->{customer} eq '') {
196 # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
199 'Collective Orders only work for orders from one customer!')
203 $taxincluded = $form->{taxincluded};
204 $form->{shipto} = 1 if $form->{id};
206 if ($form->{"all_$form->{vc}"}) {
207 unless ($form->{"$form->{vc}_id"}) {
208 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
212 $cp_id = $form->{cp_id};
213 $intnotes = $form->{intnotes};
215 # get customer / vendor
216 if ($form->{type} =~ /(purchase_order|request_quotation)/) {
217 IR->get_vendor(\%myconfig, \%$form);
219 #quote all_vendor Bug 133
220 foreach $ref (@{ $form->{all_vendor} }) {
221 $ref->{name} = $form->quote($ref->{name});
225 if ($form->{type} =~ /sales_(order|quotation)/) {
226 IS->get_customer(\%myconfig, \%$form);
228 #quote all_vendor Bug 133
229 foreach $ref (@{ $form->{all_customer} }) {
230 $ref->{name} = $form->quote($ref->{name});
234 $form->{cp_id} = $cp_id;
237 $form->{payment_id} = $payment_id;
240 $form->{language_id} = $language_id;
243 $form->{taxzone_id} = $taxzone_id;
245 $form->{intnotes} = $intnotes if $intnotes;
246 ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
247 $form->{"old$form->{vc}"} =
248 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
250 # build the popup menus
251 if (@{ $form->{"all_$form->{vc}"} }) {
252 $form->{ $form->{vc} } =
253 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
254 map { $form->{"select$form->{vc}"} .=
255 "<option>$_->{name}--$_->{id}</option>\n" }
256 (@{ $form->{"all_$form->{vc}"} });
259 $form->{taxincluded} = $taxincluded if ($form->{id});
262 if (@{ $form->{all_departments} }) {
263 $form->{selectdepartment} = "<option>\n";
264 $form->{department} = "$form->{department}--$form->{department_id}";
267 $form->{selectdepartment} .=
268 "<option>$_->{description}--$_->{id}</option>\n"
269 } (@{ $form->{all_departments} });
272 $form->{employee} = "$form->{employee}--$form->{employee_id}";
275 $form->{forex} = $form->{exchangerate};
277 $form->{salesman_id} = $salesman_id if ($editing);
279 $lxdebug->leave_sub();
283 $lxdebug->enter_sub();
284 $form->{formname} = $form->{type} unless $form->{formname};
287 foreach $ref (@{ $form->{form_details} }) {
288 $form->{rowcount} = ++$i;
290 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
292 for my $i (1 .. $form->{rowcount}) {
294 $form->{"discount_$i"} =
295 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
297 $form->{"discount_$i"} =
298 $form->format_amount(\%myconfig, $form->{"discount_$i"});
300 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
302 $decimalplaces = ($dec > 2) ? $dec : 2;
304 # copy reqdate from deliverydate for invoice -> order conversion
305 $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
306 unless $form->{"reqdate_$i"};
308 $form->{"sellprice_$i"} =
309 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
312 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
313 $dec_qty = length $dec_qty;
315 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
317 map { $form->{"${_}_$i"} =~ s/\"/"/g }
318 qw(partnumber description unit);
321 $lxdebug->leave_sub();
325 $lxdebug->enter_sub();
327 my $checkedclosed = $form->{"closed"} ? "checked" : "";
328 my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
330 if ($form->{old_employee_id}) {
331 $form->{employee_id} = $form->{old_employee_id};
333 if ($form->{old_salesman_id}) {
334 $form->{salesman_id} = $form->{old_salesman_id};
337 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
340 if ($form->{old_employee_id}) {
341 $form->{employee_id} = $form->{old_employee_id};
343 if ($form->{old_salesman_id}) {
344 $form->{salesman_id} = $form->{old_salesman_id};
347 map { $form->{$_} =~ s/\"/"/g }
348 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
349 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
350 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
352 # use JavaScript Calendar or not
353 $form->{jsscript} = 1;
357 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\">
358 <input type=button name=transdate id="trigger1" value=|
359 . $locale->text('button') . qq|></td>
362 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\">
363 <input type=button name=reqdate name=reqdate id="trigger2" value=|
364 . $locale->text('button') . qq|></td>
369 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
370 "reqdate", "BL", "trigger2");
374 if (($form->{"type"} eq "sales_order") ||
375 ($form->{"type"} eq "purchase_order")) {
377 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
378 <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
383 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
384 <label for="closed">| . $locale->text('Closed') . qq|</label>|);
390 <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
396 # set option selected
397 foreach $item ($form->{vc}, currency, department, ($form->{vc} eq "customer" ? customer : vendor)) {
398 $form->{"select$item"} =~ s/ selected//;
399 $form->{"select$item"} =~
400 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
403 #quote select[customer|vendor] Bug 133
404 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
406 #substitute \n and \r to \s (bug 543)
407 $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
409 my @old_project_ids = ($form->{"globalproject_id"});
410 map({ push(@old_project_ids, $form->{"project_id_$_"})
411 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
413 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
414 $form->get_lists("contacts" => "ALL_CONTACTS",
415 "shipto" => "ALL_SHIPTO",
416 "projects" => { "key" => "ALL_PROJECTS",
418 "old_id" => \@old_project_ids },
419 "employees" => "ALL_EMPLOYEES",
420 "salesmen" => "ALL_SALESMEN",
421 "taxzones" => "ALL_TAXZONES",
422 "payments" => "ALL_PAYMENTS",
423 "currencies" => "ALL_CURRENCIES",
424 $vc => "ALL_" . uc($vc));
427 my @values = (undef);
428 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
429 push(@values, $item->{"cp_id"});
430 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
431 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
435 if (scalar @values > 1) {
438 <th align="right">| . $locale->text('Contact Person') . qq|</th>
440 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
441 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
450 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
451 push(@values, $item->{"name"}.qq|--|.$item->{"id"});
452 $labels{$item->{"name"}.qq|--|.$item->{"id"}} = $item->{name};
456 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
457 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
458 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
460 (($myconfig{vclimit} <= scalar(@values))
461 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
462 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
463 '-onChange' => 'document.getElementById(\'update_button\').click();',
464 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
465 <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
466 </td><input type=hidden name="select$form->{vc}" value="| .
467 Q($form->{"select$form->{vc}"}) . qq|">|;
471 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
472 push(@values, $item->{"id"});
473 $labels{$item->{"id"}} = $item->{"description"};
477 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
479 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
480 '-labels' => \%labels, '-default' => $form->{payment_id}))
485 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
486 push(@values, $item->{"shipto_id"});
487 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
491 if (scalar @values > 1) {
494 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
496 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
497 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
503 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
504 push(@values, $item->{"id"});
505 $labels{$item->{"id"}} = $item->{"projectnumber"};
507 my $globalprojectnumber =
508 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
509 '-labels' => \%labels,
510 '-default' => $form->{"globalproject_id"}));
515 if ($form->{type} =~ /^sales_/) {
516 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
517 push(@values, $item->{"id"});
518 $labels{$item->{"id"}} = ($item->{"name"} ne "" ? $item->{"name"} : $item->{"login"});
522 <th align="right">| . $locale->text('Salesman') . qq|</th>
524 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
525 '-values' => \@values, '-labels' => \%labels))
532 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
533 push(@values, $item->{"id"});
534 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
539 <th align="right">| . $locale->text('Employee') . qq|</th>
541 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
542 '-values' => \@values, '-labels' => \%labels)) . qq|
548 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
549 push(@values, $item->{"id"});
550 $labels{$item->{"id"}} = $item->{"description"};
555 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
557 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
558 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
565 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
566 push(@values, $item);
567 $labels{$item} = $item;
570 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
572 if (scalar @values) {
575 <th align="right">| . $locale->text('Currency') . qq|</th>
577 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
578 '-values' => \@values, '-labels' => \%labels)) . qq|
583 $form->{exchangerate} =
584 $form->format_amount(\%myconfig, $form->{exchangerate});
586 if (!$form->{exchangerate}) {
587 $form->{exchangerate} = "";
590 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
596 $form->{creditlimit} =
597 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
598 $form->{creditremaining} =
599 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
602 <input type=hidden name=forex value=$form->{forex}>
605 if ($form->{currency} ne $form->{defaultcurrency}) {
606 if ($form->{forex}) {
609 . $locale->text('Exchangerate')
610 . qq|</th><td>$form->{exchangerate}</td>
611 <input type=hidden name=exchangerate value=$form->{exchangerate}>
616 . $locale->text('Exchangerate')
617 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
621 if ($form->{business}) {
624 <th align="right">| . ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type')) . qq|</th>
625 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
626 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
632 if ($form->{max_dunning_level}) {
635 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
637 <b>$form->{max_dunning_level}</b>;
638 | . $locale->text('Dunning Amount') . qq|: <b>|
639 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
646 if ($form->{type} !~ /_quotation$/) {
649 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
650 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
653 <th width=70% align=right nowrap>|
654 . $locale->text('Quotation Number') . qq|</th>
655 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
658 <th width=70% align=right nowrap>|
659 . $locale->text('Customer Order Number') . qq|</th>
660 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
663 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
668 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
673 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
675 $creditremaining = qq|
678 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
679 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
685 ($form->{type} eq 'sales_quotation')
686 ? $locale->text('Valid until')
687 : $locale->text('Required by');
688 if ($form->{type} eq 'sales_quotation') {
691 <th width=70% align=right nowrap>|
692 . $locale->text('Quotation Number') . qq|</th>
693 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
694 <input type=hidden name=ordnumber value="$form->{ordnumber}">
700 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
701 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
702 <input type=hidden name=ordnumber value="$form->{ordnumber}">
710 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
714 <th align=right nowrap=true>$reqlabel</th>
718 $creditremaining = qq| <tr>
726 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
727 <td colspan=3><select name=department style="width: 250px">$form->{selectdepartment}</select>
728 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
730 </tr> | if $form->{selectdepartment};
732 if ($form->{type} eq 'sales_order') {
733 if ($form->{selectemployee}) {
735 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
739 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
741 if ($form->{resubmit} && ($form->{format} eq "html")) {
743 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
744 } elsif ($form->{resubmit}) {
745 $onload = qq|document.oe.submit()|;
750 $credittext = $locale->text('Credit Limit exceeded!!!');
751 if ($creditwarning) {
752 $onload = qq|alert('$credittext')|;
755 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
756 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
758 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
759 # show history button js
760 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
761 #/show history button js
762 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
767 <body onLoad="$onload">
769 <form method=post name=oe action=$form->{script}>
771 <script type="text/javascript" src="js/common.js"></script>
772 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
773 <script type="text/javascript" src="js/vendor_selection.js"></script>
774 <script type="text/javascript" src="js/calculate_qty.js"></script>
777 $form->hide_form(qw(id action type vc formname media format proforma queued printed emailed
778 title discount creditlimit creditremaining tradediscount business
779 max_dunning_level dunning_amount));
785 <th class=listtop>$form->{title}</th>
807 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
808 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
811 <th align=right>| . $locale->text('Ship via') . qq|</th>
812 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
815 <th align="right">| . $locale->text('Transaction description') . qq|</th>
816 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
823 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
825 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
826 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
830 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
832 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
833 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
847 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
848 <td>$globalprojectnumber</td>
859 <!-- shipto are in hidden variables -->
861 <input type=hidden name=shiptoname value="$form->{shiptoname}">
862 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
863 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
864 <input type=hidden name=shiptocity value="$form->{shiptocity}">
865 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
866 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
867 <input type=hidden name=shiptophone value="$form->{shiptophone}">
868 <input type=hidden name=shiptofax value="$form->{shiptofax}">
869 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
870 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
871 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
873 <!-- email variables -->
874 <input type=hidden name=message value="$form->{message}">
875 <input type=hidden name=email value="$form->{email}">
876 <input type=hidden name=subject value="$form->{subject}">
877 <input type=hidden name=cc value="$form->{cc}">
878 <input type=hidden name=bcc value="$form->{bcc}">
880 <input type=hidden name=taxpart value="$form->{taxpart}">
881 <input type=hidden name=taxservice value="$form->{taxservice}">
883 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
886 foreach $item (split / /, $form->{taxaccounts}) {
888 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
889 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
892 $lxdebug->leave_sub();
896 $lxdebug->enter_sub();
898 $form->{invtotal} = $form->{invsubtotal};
900 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
903 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
906 $rows = ($rows > $introws) ? $rows : $introws;
908 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
910 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
912 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
915 if ($form->{taxaccounts}) {
917 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
918 . $locale->text('Tax Included') . qq|</b><br><br>
922 if (!$form->{taxincluded}) {
924 foreach $item (split / /, $form->{taxaccounts}) {
925 if ($form->{"${item}_base"}) {
926 $form->{invtotal} += $form->{"${item}_total"} =
928 $form->{"${item}_base"} * $form->{"${item}_rate"},
930 $form->{"${item}_total"} =
931 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
935 <th align=right>$form->{"${item}_description"} |
936 . $form->{"${item}_rate"} * 100 .qq|%</th>
937 <td align=right>$form->{"${item}_total"}</td>
943 $form->{invsubtotal} =
944 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
948 <th align=right>| . $locale->text('Subtotal') . qq|</th>
949 <td align=right>$form->{invsubtotal}</td>
955 if ($form->{taxincluded}) {
956 foreach $item (split / /, $form->{taxaccounts}) {
957 if ($form->{"${item}_base"}) {
958 $form->{"${item}_total"} =
960 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
961 (1 + $form->{"${item}_rate"})
964 $form->{"${item}_netto"} =
966 ($form->{"${item}_base"} - $form->{"${item}_total"}),
968 $form->{"${item}_total"} =
969 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
970 $form->{"${item}_netto"} =
971 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
975 <th align=right>Enthaltene $form->{"${item}_description"} |
976 . $form->{"${item}_rate"} * 100 .qq|%</th>
977 <td align=right>$form->{"${item}_total"}</td>
980 <th align=right>Nettobetrag</th>
981 <td align=right>$form->{"${item}_netto"}</td>
989 $form->{oldinvtotal} = $form->{invtotal};
991 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
1001 <th align=left>| . $locale->text('Notes') . qq|</th>
1002 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
1017 if ($form->{type} =~ /^sales_/) {
1020 <th align=left>| . $locale->text('Ertrag') . qq|</th>
1021 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
1024 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
1025 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
1031 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
1032 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
1041 <th align=right>| . $locale->text('Total') . qq|</th>
1042 <td align=right>$form->{invtotal}</td>
1050 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1051 <input type=hidden name=oldtotalpaid value=$totalpaid>
1053 <td><hr size=3 noshade></td>
1061 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
1064 <td align=left width=30%><b>Dateiname</b></td>
1065 <td align=left width=70%><b>Webdavlink</b></td>
1067 foreach $file (keys %{ $form->{WEBDAV} }) {
1070 <td align=left>$file</td>
1071 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1079 <td><hr size=3 noshade></td>
1097 | . $locale->text("Edit the $form->{type}") . qq|<br>
1098 <input class=submit type=submit name=action id=update_button value="|
1099 . $locale->text('Update') . qq|">
1100 <input class=submit type=submit name=action value="|
1101 . $locale->text('Ship to') . qq|">
1102 <input class=submit type=submit name=action value="|
1103 . $locale->text('Print') . qq|">
1104 <input class=submit type=submit name=action value="|
1105 . $locale->text('E-mail') . qq|">
1106 <input class=submit type=submit name=action value="|
1107 . $locale->text('Save') . qq|">
1108 <input class=submit type=submit name=action value="|
1109 . $locale->text('Save and Close') . qq|">
1112 if (($form->{id})) {
1114 <input type="button" class="submit" onclick="set_history_window(|
1116 . qq|);" name="history" id="history" value="|
1117 . $locale->text('history')
1120 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1121 <input class=submit type=submit name=action value="|
1122 . $locale->text('Save as new') . qq|">
1123 <input class=submit type=submit name=action value="|
1124 . $locale->text('Delete') . qq|">|;
1125 if (($form->{type} =~ /sales_quotation$/)) {
1127 <input class=submit type=submit name=action value="|
1128 . $locale->text('Sales Order') . qq|">|;
1130 if ($form->{type} =~ /request_quotation$/) {
1132 <input class=submit type=submit name=action value="|
1133 . $locale->text('Purchase Order') . qq|">|;
1136 <input class=submit type=submit name=action value="|
1137 . $locale->text('Invoice') . qq|">
1140 if ($form->{type} =~ /sales_order$/) {
1142 <br>$form->{heading} als neue Vorlage verwenden für<br>
1143 <input class=submit type=submit name=action value="|
1144 . $locale->text('Purchase Order') . qq|">
1145 <input class=submit type=submit name=action value="|
1146 . $locale->text('Quotation') . qq|">
1149 } elsif ($form->{type} =~ /purchase_order$/) {
1151 <br>$form->{heading} als neue Vorlage verwenden für<br>
1152 <input class=submit type=submit name=action value="|
1153 . $locale->text('Sales Order') . qq|">
1154 <input class=submit type=submit name=action value="|
1155 . $locale->text('Request for Quotation') . qq|">
1160 <br>$form->{heading} als neue Vorlage verwenden für<br>
1161 <input class=submit type=submit name=action value="|
1162 . $locale->text('Order') . qq|">
1167 $form->hide_form("saved_xyznumber");
1171 <input type=hidden name=rowcount value=$form->{rowcount}>
1173 <input name=callback type=hidden value="$form->{callback}">
1175 <input type=hidden name=login value=$form->{login}>
1176 <input type=hidden name=password value=$form->{password}>
1183 $lxdebug->leave_sub();
1187 $lxdebug->enter_sub();
1189 set_headings($form->{"id"} ? "edit" : "add");
1191 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1192 qw(exchangerate creditlimit creditremaining);
1193 $form->{update} = 1;
1195 if($form->{payment_id}) {
1196 $payment_id = $form->{payment_id};
1199 &check_name($form->{vc});
1201 if($form->{payment_id} eq "") {
1202 $form->{payment_id} = $payment_id;
1206 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1207 $form->{exchangerate} = $exchangerate
1211 $form->check_exchangerate(
1212 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1216 $i = $form->{rowcount};
1218 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1220 if ( ($form->{"partnumber_$i"} eq "")
1221 && ($form->{"description_$i"} eq "")
1222 && ($form->{"partsgroup_$i"} eq "")) {
1224 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1229 if ( $form->{type} eq 'purchase_order'
1230 || $form->{type} eq 'request_quotation') {
1231 IR->retrieve_item(\%myconfig, \%$form);
1233 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1234 IS->retrieve_item(\%myconfig, \%$form);
1237 my $rows = scalar @{ $form->{item_list} };
1239 $form->{"discount_$i"} =
1240 $form->format_amount(\%myconfig, $form->{discount} * 100);
1243 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1252 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1253 if ($form->{"not_discountable_$i"}) {
1254 $form->{"discount_$i"} = 0;
1256 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1257 qw(partnumber description unit);
1258 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1259 keys %{ $form->{item_list}[0] };
1260 if ($form->{"part_payment_id_$i"} ne "") {
1261 $form->{payment_id} = $form->{"part_payment_id_$i"};
1264 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1266 ($dec) = ($s =~ /\.(\d+)/);
1268 $decimalplaces = ($dec > 2) ? $dec : 2;
1271 $form->{"sellprice_$i"} = $sellprice;
1274 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1276 # if there is an exchange rate adjust sellprice
1277 $form->{"sellprice_$i"} /= $exchangerate;
1281 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1282 (1 - $form->{"discount_$i"} / 100);
1283 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1284 map { $form->{"${_}_base"} += $amount }
1285 (split / /, $form->{"taxaccounts_$i"});
1286 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1287 split / /, $form->{taxaccounts}
1288 if !$form->{taxincluded};
1290 $form->{creditremaining} -= $amount;
1292 $form->{"sellprice_$i"} =
1293 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1296 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1298 # get pricegroups for parts
1299 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1301 # build up html code for prices_$i
1302 &set_pricegroup($i);
1309 # ok, so this is a new part
1310 # ask if it is a part or service item
1312 if ( $form->{"partsgroup_$i"}
1313 && ($form->{"partsnumber_$i"} eq "")
1314 && ($form->{"description_$i"} eq "")) {
1315 $form->{rowcount}--;
1316 $form->{"discount_$i"} = "";
1320 $form->{"id_$i"} = 0;
1321 $form->{"unit_$i"} = $locale->text('ea');
1329 $lxdebug->leave_sub();
1333 $lxdebug->enter_sub();
1335 if ($form->{type} eq 'purchase_order') {
1336 $form->{title} = $locale->text('Purchase Orders');
1337 $form->{vc} = 'vendor';
1338 $ordlabel = $locale->text('Order Number');
1339 $ordnumber = 'ordnumber';
1340 $employee = $locale->text('Employee');
1343 if ($form->{type} eq 'request_quotation') {
1344 $form->{title} = $locale->text('Request for Quotations');
1345 $form->{vc} = 'vendor';
1346 $ordlabel = $locale->text('RFQ Number');
1347 $ordnumber = 'quonumber';
1348 $employee = $locale->text('Employee');
1351 if ($form->{type} eq 'sales_order') {
1352 $form->{title} = $locale->text('Sales Orders');
1353 $form->{vc} = 'customer';
1354 $ordlabel = $locale->text('Order Number');
1355 $ordnumber = 'ordnumber';
1356 $employee = $locale->text('Employee');
1359 if ($form->{type} eq 'sales_quotation') {
1360 $form->{title} = $locale->text('Quotations');
1361 $form->{vc} = 'customer';
1362 $ordlabel = $locale->text('Quotation Number');
1363 $ordnumber = 'quonumber';
1364 $employee = $locale->text('Employee');
1367 # setup vendor / customer selection
1368 $form->all_vc(\%myconfig, $form->{vc},
1369 ($form->{vc} eq 'customer') ? "AR" : "AP");
1372 if (@{ $form->{all_departments} }) {
1373 $form->{selectdepartment} = "<option>\n";
1376 $form->{selectdepartment} .=
1377 "<option>$_->{description}--$_->{id}</option>\n"
1378 } (@{ $form->{all_departments} });
1383 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1384 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1386 | if $form->{selectdepartment};
1389 if (($form->{"type"} eq "sales_order") ||
1390 ($form->{"type"} eq "purchase_order")) {
1393 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1394 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1395 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1396 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1401 # use JavaScript Calendar or not
1402 $form->{jsscript} = 1;
1406 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1407 <input type=button name=transdatefrom id="trigger3" value=|
1408 . $locale->text('button') . qq|></td>
1411 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1412 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1413 . $locale->text('button') . qq|></td>
1418 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1419 "transdateto", "BL", "trigger4");
1421 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1423 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1425 "employees" => "ALL_EMPLOYEES",
1426 $vc => "ALL_" . uc($vc));
1430 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1431 push(@values, $item->{"id"});
1432 $labels{$item->{"id"}} = $item->{"projectnumber"};
1435 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1436 '-labels' => \%labels));
1441 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
1442 push(@values, $item->{"id"});
1443 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
1446 my $employee_block = qq|
1448 <th align="right">| . $locale->text('Employee') . qq|</th>
1450 NTI($cgi->popup_menu('-name' => 'employee_id',
1451 '-values' => \@values,
1452 '-labels' => \%labels)) . qq|
1459 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1460 push(@values, $item->{name}.qq|--|.$item->{"id"});
1461 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
1464 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1466 $myconfig{vclimit} <= scalar(@values)
1467 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
1468 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1469 '-default' => $form->{"old$form->{vc}"},
1470 '-onChange' => 'document.getElementById(\'update_button\').click();',
1471 '-values' => \@values,
1472 '-labels' => \%labels));
1478 <form method=post action=$form->{script}>
1482 <th class=listtop>$form->{title}</th>
1484 <tr height="5"></tr>
1489 <th align=right>$vc_label</th>
1490 <td colspan=3>$vc</td>
1494 <th align=right>$ordlabel</th>
1495 <td colspan=3><input name="$ordnumber" size=20></td>
1499 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1500 <td colspan="3"><input name="transaction_description" size=20></td>
1503 <th align="right">| . $locale->text("Project Number") . qq|</th>
1504 <td colspan="3">$projectnumber</td>
1507 <th align=right>| . $locale->text('From') . qq|</th>
1509 <th align=right>| . $locale->text('Bis') . qq|</th>
1512 <input type=hidden name=sort value=transdate>
1514 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1518 <td><input type="checkbox" name="open" value="1" id="open" checked>
1519 <label for="open">| . $locale->text("Open") . qq|</td>
1520 <td><input type="checkbox" name="closed" value="1" id="closed">
1521 <label for="closed">| . $locale->text("Closed") . qq|</td>
1525 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1526 | . $locale->text('ID') . qq|</td>
1527 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1528 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1529 . $locale->text('Date') . qq|</td>
1530 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1531 . $locale->text('Required by') . qq|</td>
1534 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vc_label</td>
1535 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1536 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1537 . $locale->text('Ship via') . qq|</td>
1538 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1541 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1542 . $locale->text('Amount') . qq|</td>
1543 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1544 . $locale->text('Tax') . qq|</td>
1545 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1546 . $locale->text('Total') . qq|</td>
1549 <td><input name="l_marge_total" class=checkbox type=checkbox value=Y> |
1550 . $locale->text('Ertrag') . qq|</td>
1551 <td><input name="l_marge_percent" class=checkbox type=checkbox value=Y> |
1552 . $locale->text('Ertrag prozentual') . qq|</td>
1555 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1556 . $locale->text('Project Number') . qq|</td>
1557 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1558 . $locale->text('Transaction description') . qq|</td>
1561 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1562 . $locale->text('Subtotal') . qq|</td>
1570 <tr><td colspan=4><hr size=3 noshade></td></tr>
1576 <input type=hidden name=nextsub value=orders>
1577 <input type=hidden name=login value=$form->{login}>
1578 <input type=hidden name=password value=$form->{password}>
1579 <input type=hidden name=vc value=$form->{vc}>
1580 <input type=hidden name=type value=$form->{type}>
1582 <input class=submit type=submit name=action value="|
1583 . $locale->text('Continue') . qq|">
1590 $lxdebug->leave_sub();
1593 sub create_subtotal_row {
1594 $lxdebug->enter_sub();
1596 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1598 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1600 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1602 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1604 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1606 $lxdebug->leave_sub();
1612 $lxdebug->enter_sub();
1614 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1616 ($form->{ $form->{vc} }, $form->{"${form->{vc}}_id"}) = split(/--/, $form->{ $form->{vc} });
1618 $form->{sort} ||= 'transdate';
1620 OE->transactions(\%myconfig, \%$form);
1622 $form->{rowcount} = scalar @{ $form->{OE} };
1625 "transdate", "reqdate",
1627 "name", "netamount",
1630 "shipvia", "globalprojectnumber",
1631 "transaction_description", "open",
1632 "delivered", "marge_total", "marge_percent"
1635 # only show checkboxes if gotten here via sales_order form.
1636 my $allow_multiple_orders = $form->{type} eq 'sales_order';
1637 if ($allow_multiple_orders) {
1638 unshift @columns, "ids";
1641 $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed});
1642 $form->{l_delivered} = "Y" if ($form->{delivered} && $form->{notdelivered});
1644 my $attachment_basename;
1645 if ($form->{vc} eq 'vendor') {
1646 if ($form->{type} eq 'purchase_order') {
1647 $form->{title} = $locale->text('Purchase Orders');
1648 $attachment_basename = $locale->text('purchase_order_list');
1650 $form->{title} = $locale->text('Request for Quotations');
1651 $attachment_basename = $locale->text('rfq_list');
1655 if ($form->{type} eq 'sales_order') {
1656 $form->{title} = $locale->text('Sales Orders');
1657 $attachment_basename = $locale->text('sales_order_list');
1659 $form->{title} = $locale->text('Quotations');
1660 $attachment_basename = $locale->text('quotation_list');
1664 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1666 my @hidden_variables = map { "l_${_}" } @columns;
1667 push @hidden_variables, "l_subtotal", $form->{vc}, qw(l_closed l_notdelivered open closed delivered notdelivered ordnumber quonumber
1668 transaction_description transdatefrom transdateto type vc employee_id);
1670 my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
1673 'ids' => { 'text' => '', },
1674 'transdate' => { 'text' => $locale->text('Date'), },
1675 'reqdate' => { 'text' => $locale->text('Required by'), },
1676 'id' => { 'text' => $locale->text('ID'), },
1677 'ordnumber' => { 'text' => $locale->text('Order'), },
1678 'quonumber' => { 'text' => $form->{type} eq "request_quotation" ? $locale->text('RFQ') : $locale->text('Quotation'), },
1679 'name' => { 'text' => $form->{vc} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1680 'netamount' => { 'text' => $locale->text('Amount'), },
1681 'tax' => { 'text' => $locale->text('Tax'), },
1682 'amount' => { 'text' => $locale->text('Total'), },
1683 'curr' => { 'text' => $locale->text('Curr'), },
1684 'employee' => { 'text' => $locale->text('Salesperson'), },
1685 'shipvia' => { 'text' => $locale->text('Ship via'), },
1686 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1687 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1688 'open' => { 'text' => $locale->text('Open'), },
1689 'delivered' => { 'text' => $locale->text('Delivered'), },
1690 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1691 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), }
1694 foreach my $name (qw(id transdate reqdate quonumber ordnumber name employee shipvia)) {
1695 $column_defs{$name}->{link} = $href . "&sort=$name";
1698 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount curr);
1700 $form->{"l_type"} = "Y";
1701 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1702 $column_defs{ids}->{visible} = $allow_multiple_orders ? 'HTML' : 0;
1704 $report->set_columns(%column_defs);
1705 $report->set_column_order(@columns);
1707 $report->set_export_options('orders', @hidden_variables);
1709 $report->set_sort_indicator($form->{sort}, 1);
1712 if ($form->{customer}) {
1713 push @options, $locale->text('Customer') . " : $form->{customer}";
1715 if ($form->{vendor}) {
1716 push @options, $locale->text('Vendor') . " : $form->{vendor}";
1718 if ($form->{department}) {
1719 ($department) = split /--/, $form->{department};
1720 push @options, $locale->text('Department') . " : $department";
1722 if ($form->{ordnumber}) {
1723 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1725 if ($form->{notes}) {
1726 push @options, $locale->text('Notes') . " : $form->{notes}";
1728 if ($form->{transaction_description}) {
1729 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1731 if ($form->{transdatefrom}) {
1732 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1734 if ($form->{transdateto}) {
1735 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1737 if ($form->{open}) {
1738 push @options, $locale->text('Open');
1740 if ($form->{closed}) {
1741 push @options, $locale->text('Closed');
1743 if ($form->{delivered}) {
1744 push @options, $locale->text('Delivered');
1746 if ($form->{notdelivered}) {
1747 push @options, $locale->text('Not delivered');
1750 $report->set_options('top_info_text' => join("\n", @options),
1751 'raw_top_info_text' => $form->parse_html_template('oe/orders_top'),
1752 'raw_bottom_info_text' => $form->parse_html_template('oe/orders_bottom', { 'SHOW_CONTINUE_BUTTON' => $allow_multiple_orders }),
1753 'output_format' => 'HTML',
1754 'title' => $form->{title},
1755 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1757 $report->set_options_from_form();
1759 # add sort and escape callback, this one we use for the add sub
1760 $form->{callback} = $href .= "&sort=$form->{sort}";
1762 # escape callback for href
1763 $callback = $form->escape($href);
1765 my @subtotal_columns = qw(netamount amount marge_total);
1767 my %totals = map { $_ => 0 } @subtotal_columns;
1768 my %subtotals = map { $_ => 0 } @subtotal_columns;
1772 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1774 foreach $oe (@{ $form->{OE} }) {
1775 map { $oe->{$_} *= $oe->{exchangerate} } @subtotal_columns;
1777 $oe->{tax} = $oe->{amount} - $oe->{netamount};
1778 $oe->{open} = $oe->{closed} ? $locale->text('No') : $locale->text('Yes');
1779 $oe->{delivered} = $oe->{delivered} ? $locale->text('Yes') : $locale->text('No');
1781 map { $subtotals{$_} += $oe->{$_};
1782 $totals{$_} += $oe->{$_} } @subtotal_columns;
1784 map { $oe->{$_} = $form->format_amount(\%myconfig, $oe->{$_}, 2) } qw(netamount tax amount marge_total marge_percent);
1788 foreach my $column (@columns) {
1789 next if ($column eq 'ids');
1791 'data' => $oe->{$column},
1792 'align' => $column_alignment{$column},
1797 'raw_data' => $cgi->hidden('-name' => "trans_id_${idx}", '-value' => $oe->{id})
1798 . $cgi->checkbox('-name' => "multi_id_${idx}", '-value' => 1, '-label' => ''),
1799 'valign' => 'center',
1800 'align' => 'center',
1803 $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1805 my $row_set = [ $row ];
1807 if (($form->{l_subtotal} eq 'Y')
1808 && (($idx == (scalar @{ $form->{OE} } - 1))
1809 || ($oe->{ $form->{sort} } ne $form->{OE}->[$idx + 1]->{ $form->{sort} }))) {
1810 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1813 $report->add_data($row_set);
1818 $report->add_separator();
1819 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1821 $report->generate_with_headers();
1823 $lxdebug->leave_sub();
1826 sub check_delivered_flag {
1827 $lxdebug->enter_sub();
1829 if (($form->{type} ne 'sales_order') && ($form->{type} ne 'purchase_order')) {
1830 return $lxdebug->leave_sub();
1833 my $all_delivered = 0;
1835 foreach my $i (1 .. $form->{rowcount}) {
1836 next if (!$form->{"id_$i"});
1838 if ($form->parse_amount(\%myconfig, $form->{"qty_$i"}) == $form->parse_amount(\%myconfig, $form->{"ship_$i"})) {
1847 $form->{delivered} = 1 if $all_delivered;
1849 $lxdebug->leave_sub();
1852 sub save_and_close {
1853 $lxdebug->enter_sub();
1855 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1857 if ($form->{type} =~ /_order$/) {
1858 $form->isblank("transdate", $locale->text('Order Date missing!'));
1860 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1863 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1864 $form->{$idx} =~ s/^\s*//g;
1865 $form->{$idx} =~ s/\s*$//g;
1867 $msg = ucfirst $form->{vc};
1868 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1870 # $locale->text('Customer missing!');
1871 # $locale->text('Vendor missing!');
1873 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1874 if ($form->{currency} ne $form->{defaultcurrency});
1878 if($form->{payment_id}) {
1879 $payment_id = $form->{payment_id};
1882 # if the name changed get new values
1883 if (&check_name($form->{vc})) {
1884 if($form->{payment_id} eq "") {
1885 $form->{payment_id} = $payment_id;
1891 $form->{id} = 0 if $form->{saveasnew};
1893 # this is for the internal notes section for the [email] Subject
1894 if ($form->{type} =~ /_order$/) {
1895 if ($form->{type} eq 'sales_order') {
1896 $form->{label} = $locale->text('Sales Order');
1898 $numberfld = "sonumber";
1899 $ordnumber = "ordnumber";
1901 $form->{label} = $locale->text('Purchase Order');
1903 $numberfld = "ponumber";
1904 $ordnumber = "ordnumber";
1907 $err = $locale->text('Cannot save order!');
1909 check_delivered_flag();
1912 if ($form->{type} eq 'sales_quotation') {
1913 $form->{label} = $locale->text('Quotation');
1915 $numberfld = "sqnumber";
1916 $ordnumber = "quonumber";
1918 $form->{label} = $locale->text('Request for Quotation');
1920 $numberfld = "rfqnumber";
1921 $ordnumber = "quonumber";
1924 $err = $locale->text('Cannot save quotation!');
1928 # get new number in sequence if no number is given or if saveasnew was requested
1929 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1930 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1935 $form->error($err) if (!OE->save(\%myconfig, \%$form));
1937 # saving the history
1938 if(!exists $form->{addition}) {
1939 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1940 $form->{addition} = "SAVED";
1941 $form->save_history($form->dbconnect(\%myconfig));
1943 # /saving the history
1945 $form->redirect($form->{label} . " $form->{$ordnumber} " .
1946 $locale->text('saved!'));
1948 $lxdebug->leave_sub();
1952 $lxdebug->enter_sub();
1954 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1957 if ($form->{type} =~ /_order$/) {
1958 $form->isblank("transdate", $locale->text('Order Date missing!'));
1960 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1963 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1964 $form->{$idx} =~ s/^\s*//g;
1965 $form->{$idx} =~ s/\s*$//g;
1967 $msg = ucfirst $form->{vc};
1968 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1970 # $locale->text('Customer missing!');
1971 # $locale->text('Vendor missing!');
1973 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1974 if ($form->{currency} ne $form->{defaultcurrency});
1978 if($form->{payment_id}) {
1979 $payment_id = $form->{payment_id};
1982 # if the name changed get new values
1983 if (&check_name($form->{vc})) {
1984 if($form->{payment_id} eq "") {
1985 $form->{payment_id} = $payment_id;
1991 $form->{id} = 0 if $form->{saveasnew};
1993 # this is for the internal notes section for the [email] Subject
1994 if ($form->{type} =~ /_order$/) {
1995 if ($form->{type} eq 'sales_order') {
1996 $form->{label} = $locale->text('Sales Order');
1998 $numberfld = "sonumber";
1999 $ordnumber = "ordnumber";
2001 $form->{label} = $locale->text('Purchase Order');
2003 $numberfld = "ponumber";
2004 $ordnumber = "ordnumber";
2007 $err = $locale->text('Cannot save order!');
2009 check_delivered_flag();
2012 if ($form->{type} eq 'sales_quotation') {
2013 $form->{label} = $locale->text('Quotation');
2015 $numberfld = "sqnumber";
2016 $ordnumber = "quonumber";
2018 $form->{label} = $locale->text('Request for Quotation');
2020 $numberfld = "rfqnumber";
2021 $ordnumber = "quonumber";
2024 $err = $locale->text('Cannot save quotation!');
2028 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
2029 unless $form->{$ordnumber};
2033 OE->save(\%myconfig, \%$form);
2035 # saving the history
2036 if(!exists $form->{addition}) {
2037 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2038 $form->{addition} = "SAVED";
2039 $form->save_history($form->dbconnect(\%myconfig));
2041 # /saving the history
2043 $form->{simple_save} = 1;
2044 if(!$form->{print_and_save}) {
2045 set_headings("edit");
2049 $lxdebug->leave_sub();
2053 $lxdebug->enter_sub();
2057 if ($form->{type} =~ /_order$/) {
2058 $msg = $locale->text('Are you sure you want to delete Order Number');
2059 $ordnumber = 'ordnumber';
2061 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2062 $ordnumber = 'quonumber';
2068 <form method=post action=$form->{script}>
2071 # delete action variable
2072 map { delete $form->{$_} } qw(action header);
2074 foreach $key (keys %$form) {
2075 $form->{$key} =~ s/\"/"/g;
2076 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2080 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2082 <h4>$msg $form->{$ordnumber}</h4>
2084 <input type="hidden" name="yes_nextsub" value="delete_order_quotation">
2085 <input name=action class=submit type=submit value="|
2086 . $locale->text('Yes') . qq|">
2087 <button class=submit type=button onclick="history.back()">|
2088 . $locale->text('No') . qq|</button>
2095 $lxdebug->leave_sub();
2098 sub delete_order_quotation {
2099 $lxdebug->enter_sub();
2101 if ($form->{type} =~ /_order$/) {
2102 $msg = $locale->text('Order deleted!');
2103 $err = $locale->text('Cannot delete order!');
2105 $msg = $locale->text('Quotation deleted!');
2106 $err = $locale->text('Cannot delete quotation!');
2108 if (OE->delete(\%myconfig, \%$form, $spool)){
2109 # saving the history
2110 if(!exists $form->{addition}) {
2111 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2112 $form->{addition} = "DELETED";
2113 $form->save_history($form->dbconnect(\%myconfig));
2115 # /saving the history
2121 $lxdebug->leave_sub();
2125 $lxdebug->enter_sub();
2127 $form->{old_employee_id} = $form->{employee_id};
2128 $form->{old_salesman_id} = $form->{salesman_id};
2130 if ($form->{type} =~ /_order$/) {
2132 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2133 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2134 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2135 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2136 $form->isblank("transdate", $locale->text('Order Date missing!'))
2137 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2139 # also copy deliverydate from the order
2140 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2141 $form->{orddate} = $form->{transdate};
2143 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2144 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2145 $form->{ordnumber} = "";
2146 $form->{quodate} = $form->{transdate};
2149 if($form->{payment_id}) {
2150 $payment_id = $form->{payment_id};
2153 # if the name changed get new values
2154 if (&check_name($form->{vc})) {
2155 if($form->{payment_id} eq "") {
2156 $form->{payment_id} = $payment_id;
2162 $form->{cp_id} *= 1;
2164 for $i (1 .. $form->{rowcount}) {
2165 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2166 $form->{"${_}_${i}"})
2167 if ($form->{"${_}_${i}"}) }
2168 qw(ship qty sellprice listprice basefactor));
2171 if ( $form->{type} =~ /_order/
2172 && $form->{currency} ne $form->{defaultcurrency}) {
2174 # check if we need a new exchangerate
2175 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2177 $orddate = $form->current_date(\%myconfig);
2179 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2182 if (!$exchangerate) {
2183 &backorder_exchangerate($orddate, $buysell);
2188 # close orders/quotations
2189 $form->{closed} = 1;
2191 # save order if one ordnumber has been given
2192 # if not it's most likely a collective order, which can't be saved back
2193 # so they just have to be closed
2194 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2195 OE->close_order(\%myconfig, \%$form) if ($form->{id});
2197 OE->close_orders(\%myconfig, \%$form);
2200 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2202 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2205 $form->{closed} = 0;
2206 $form->{rowcount}--;
2207 $form->{shipto} = 1;
2209 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
2211 if ($form->{type} =~ /_order$/) {
2212 $form->{exchangerate} = $exchangerate;
2216 if ( $form->{type} eq 'purchase_order'
2217 || $form->{type} eq 'request_quotation') {
2218 $form->{title} = $locale->text('Add Vendor Invoice');
2219 $form->{script} = 'ir.pl';
2223 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2224 $form->{title} = $locale->text('Add Sales Invoice');
2225 $form->{script} = 'is.pl';
2230 # bo creates the id, reset it
2231 map { delete $form->{$_} }
2232 qw(id subject message cc bcc printed emailed queued);
2233 $form->{ $form->{vc} } =~ s/--.*//g;
2234 $form->{type} = "invoice";
2237 $locale = new Locale "$myconfig{countrycode}", "$script";
2239 require "bin/mozilla/$form->{script}";
2241 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2243 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2244 qw(creditlimit creditremaining);
2246 $currency = $form->{currency};
2249 $form->{currency} = $currency;
2250 $form->{exchangerate} = "";
2251 $form->{forex} = "";
2252 $form->{exchangerate} = $exchangerate
2256 $form->check_exchangerate(
2257 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2260 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2265 for $i (1 .. $form->{rowcount}) {
2266 $form->{"discount_$i"} =
2267 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2269 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2271 $decimalplaces = ($dec > 2) ? $dec : 2;
2273 # copy delivery date from reqdate for order -> invoice conversion
2274 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2275 unless $form->{"deliverydate_$i"};
2277 $form->{"sellprice_$i"} =
2278 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2281 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2282 $dec_qty = length $dec_qty;
2284 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2286 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2287 qw(partnumber description unit);
2293 $lxdebug->leave_sub();
2296 sub backorder_exchangerate {
2297 $lxdebug->enter_sub();
2298 my ($orddate, $buysell) = @_;
2305 <form method=post action=$form->{script}>
2308 # delete action variable
2309 map { delete $form->{$_} } qw(action header exchangerate);
2311 foreach $key (keys %$form) {
2312 $form->{$key} =~ s/\"/"/g;
2313 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2316 $form->{title} = $locale->text('Add Exchangerate');
2320 <input type=hidden name=login value=$form->{login}>
2321 <input type=hidden name=password value=$form->{password}>
2323 <input type=hidden name=exchangeratedate value=$orddate>
2324 <input type=hidden name=buysell value=$buysell>
2327 <tr><th class=listtop>$form->{title}</th></tr>
2328 <tr height="5"></tr>
2333 <th align=right>| . $locale->text('Currency') . qq|</th>
2334 <td>$form->{currency}</td>
2337 <th align=right>| . $locale->text('Date') . qq|</th>
2341 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2342 <td><input name=exchangerate size=11></td>
2352 <input type=hidden name=nextsub value=save_exchangerate>
2354 <input name=action class=submit type=submit value="|
2355 . $locale->text('Continue') . qq|">
2363 $lxdebug->leave_sub();
2366 sub save_exchangerate {
2367 $lxdebug->enter_sub();
2369 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2370 $form->{exchangerate} =
2371 $form->parse_amount(\%myconfig, $form->{exchangerate});
2372 $form->save_exchangerate(\%myconfig, $form->{currency},
2373 $form->{exchangeratedate},
2374 $form->{exchangerate}, $form->{buysell});
2378 $lxdebug->leave_sub();
2381 sub create_backorder {
2382 $lxdebug->enter_sub();
2384 $form->{shipped} = 1;
2386 # figure out if we need to create a backorder
2387 # items aren't saved if qty != 0
2389 for $i (1 .. $form->{rowcount}) {
2390 $totalqty += $qty = $form->{"qty_$i"};
2391 $totalship += $ship = $form->{"ship_$i"};
2393 $form->{"qty_$i"} = $qty - $ship;
2396 if ($totalship == 0) {
2397 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2398 $form->{ordtotal} = 0;
2399 $form->{shipped} = 0;
2403 if ($totalqty == $totalship) {
2404 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2405 $form->{ordtotal} = 0;
2410 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2413 for $i (1 .. $form->{rowcount}) {
2415 $form->{"${_}_$i"} =
2416 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2417 } qw(sellprice discount);
2422 OE->save(\%myconfig, \%$form);
2424 # rebuild rows for invoice
2428 for $i (1 .. $form->{rowcount}) {
2429 $form->{"qty_$i"} = $form->{"ship_$i"};
2431 if ($form->{"qty_$i"}) {
2434 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2439 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2440 $form->{rowcount} = $count;
2442 $lxdebug->leave_sub();
2446 $lxdebug->enter_sub();
2448 $form->{saveasnew} = 1;
2449 $form->{closed} = 0;
2450 map { delete $form->{$_} } qw(printed emailed queued);
2452 # Let Lx-Office assign a new order number if the user hasn't changed the
2453 # previous one. If it has been changed manually then use it as-is.
2454 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2455 $form->{$idx} =~ s/^\s*//g;
2456 $form->{$idx} =~ s/\s*$//g;
2457 if ($form->{saved_xyznumber} &&
2458 ($form->{saved_xyznumber} eq $form->{$idx})) {
2459 delete($form->{$idx});
2464 $lxdebug->leave_sub();
2467 sub check_for_direct_delivery_yes {
2468 $lxdebug->enter_sub();
2470 $form->{direct_delivery_checked} = 1;
2471 delete @{$form}{grep /^shipto/, keys %{ $form }};
2472 map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
2473 $form->{shipto} = 1;
2475 $lxdebug->leave_sub();
2478 sub check_for_direct_delivery_no {
2479 $lxdebug->enter_sub();
2481 $form->{direct_delivery_checked} = 1;
2482 delete @{$form}{grep /^shipto/, keys %{ $form }};
2485 $lxdebug->leave_sub();
2488 sub check_for_direct_delivery {
2489 $lxdebug->enter_sub();
2491 if ($form->{direct_delivery_checked}
2492 || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
2493 $lxdebug->leave_sub();
2497 if ($form->{shipto_id}) {
2498 Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_");
2501 map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form };
2504 delete $form->{action};
2505 $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ref $_ eq "" } keys %{ $form } ];
2508 print $form->parse_html_template("oe/check_for_direct_delivery");
2510 $lxdebug->leave_sub();
2515 sub purchase_order {
2516 $lxdebug->enter_sub();
2518 if ($form->{type} eq 'sales_order') {
2519 check_for_direct_delivery();
2522 if ( $form->{type} eq 'sales_quotation'
2523 || $form->{type} eq 'request_quotation') {
2524 OE->close_order(\%myconfig, \%$form);
2527 if ($form->{type} =~ /^sales_/) {
2528 delete($form->{ordnumber});
2531 $form->{cp_id} *= 1;
2533 $form->{title} = $locale->text('Add Purchase Order');
2534 $form->{vc} = "vendor";
2535 $form->{type} = "purchase_order";
2539 $lxdebug->leave_sub();
2543 $lxdebug->enter_sub();
2545 if ( $form->{type} eq 'sales_quotation'
2546 || $form->{type} eq 'request_quotation') {
2547 OE->close_order(\%myconfig, $form);
2550 if ($form->{type} eq "purchase_order") {
2551 delete($form->{ordnumber});
2554 $form->{cp_id} *= 1;
2556 $form->{title} = $locale->text('Add Sales Order');
2557 $form->{vc} = "customer";
2558 $form->{type} = "sales_order";
2562 $lxdebug->leave_sub();
2566 $lxdebug->enter_sub();
2568 $form->{transdate} = $form->current_date(\%myconfig);
2569 delete $form->{duedate};
2571 $form->{closed} = 0;
2573 $form->{old_employee_id} = $form->{employee_id};
2574 $form->{old_salesman_id} = $form->{salesman_id};
2577 map { delete $form->{$_} }
2578 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2580 for $i (1 .. $form->{rowcount}) {
2581 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2582 $form->{"${_}_${i}"})
2583 if ($form->{"${_}_${i}"}) }
2584 qw(ship qty sellprice listprice basefactor));
2592 for $i (1 .. $form->{rowcount} - 1) {
2593 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2594 qw(partnumber description unit);
2597 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2598 qw(creditlimit creditremaining);
2602 $lxdebug->leave_sub();
2606 $lxdebug->enter_sub();
2608 $form->{print_and_save} = 1;
2613 my $saved_form = save_form();
2618 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2619 restore_form($saved_form);
2620 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2625 $lxdebug->leave_sub();
2629 call_sub($form->{yes_nextsub});
2633 call_sub($form->{no_nextsub});