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",
417 "key" => "ALL_PROJECTS",
419 "old_id" => \@old_project_ids
421 "employees" => "ALL_EMPLOYEES",
422 "salesmen" => "ALL_SALESMEN",
423 "taxzones" => "ALL_TAXZONES",
424 "payments" => "ALL_PAYMENTS",
425 "currencies" => "ALL_CURRENCIES",
426 $vc => "ALL_" . uc($vc));
429 my @values = (undef);
430 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
431 push(@values, $item->{"cp_id"});
432 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
433 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
437 if (scalar @values > 1) {
440 <th align="right">| . $locale->text('Contact Person') . qq|</th>
442 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
443 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
452 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
453 push(@values, $item->{"name"}.qq|--|.$item->{"id"});
454 $labels{$item->{"name"}.qq|--|.$item->{"id"}} = $item->{name};
458 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
459 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
460 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
462 (($myconfig{vclimit} <= scalar(@values))
463 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
464 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
465 '-onChange' => 'document.getElementById(\'update_button\').click();',
466 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
467 <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
468 </td><input type=hidden name="select$form->{vc}" value="| .
469 Q($form->{"select$form->{vc}"}) . qq|">|;
473 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
474 push(@values, $item->{"id"});
475 $labels{$item->{"id"}} = $item->{"description"};
479 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
481 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
482 '-labels' => \%labels, '-default' => $form->{payment_id}))
487 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
488 push(@values, $item->{"shipto_id"});
489 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
493 if (scalar @values > 1) {
496 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
498 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
499 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
505 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
506 push(@values, $item->{"id"});
507 $labels{$item->{"id"}} = $item->{"projectnumber"};
509 my $globalprojectnumber =
510 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
511 '-labels' => \%labels,
512 '-default' => $form->{"globalproject_id"}));
517 if ($form->{type} =~ /^sales_/) {
518 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
519 push(@values, $item->{"id"});
520 $labels{$item->{"id"}} = ($item->{"name"} ne "" ? $item->{"name"} : $item->{"login"});
524 <th align="right">| . $locale->text('Salesman') . qq|</th>
526 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
527 '-values' => \@values, '-labels' => \%labels))
534 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
535 push(@values, $item->{"id"});
536 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
541 <th align="right">| . $locale->text('Employee') . qq|</th>
543 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
544 '-values' => \@values, '-labels' => \%labels)) . qq|
550 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
551 push(@values, $item->{"id"});
552 $labels{$item->{"id"}} = $item->{"description"};
557 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
559 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
560 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
567 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
568 push(@values, $item);
569 $labels{$item} = $item;
572 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
574 if (scalar @values) {
577 <th align="right">| . $locale->text('Currency') . qq|</th>
579 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
580 '-values' => \@values, '-labels' => \%labels)) . qq|
585 $form->{exchangerate} =
586 $form->format_amount(\%myconfig, $form->{exchangerate});
588 if (!$form->{exchangerate}) {
589 $form->{exchangerate} = "";
592 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
598 $form->{creditlimit} =
599 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
600 $form->{creditremaining} =
601 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
604 <input type=hidden name=forex value=$form->{forex}>
607 if ($form->{currency} ne $form->{defaultcurrency}) {
608 if ($form->{forex}) {
611 . $locale->text('Exchangerate')
612 . qq|</th><td>$form->{exchangerate}</td>
613 <input type=hidden name=exchangerate value=$form->{exchangerate}>
618 . $locale->text('Exchangerate')
619 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
623 if ($form->{business}) {
626 <th align="right">| . ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type')) . qq|</th>
627 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
628 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
634 if ($form->{max_dunning_level}) {
637 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
639 <b>$form->{max_dunning_level}</b>;
640 | . $locale->text('Dunning Amount') . qq|: <b>|
641 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
648 if ($form->{type} !~ /_quotation$/) {
651 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
652 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
655 <th width=70% align=right nowrap>|
656 . $locale->text('Quotation Number') . qq|</th>
657 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
660 <th width=70% align=right nowrap>|
661 . $locale->text('Customer Order Number') . qq|</th>
662 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
665 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
670 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
675 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
677 $creditremaining = qq|
680 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
681 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
687 ($form->{type} eq 'sales_quotation')
688 ? $locale->text('Valid until')
689 : $locale->text('Required by');
690 if ($form->{type} eq 'sales_quotation') {
693 <th width=70% align=right nowrap>|
694 . $locale->text('Quotation Number') . qq|</th>
695 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
696 <input type=hidden name=ordnumber value="$form->{ordnumber}">
702 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
703 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
704 <input type=hidden name=ordnumber value="$form->{ordnumber}">
712 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
716 <th align=right nowrap=true>$reqlabel</th>
720 $creditremaining = qq| <tr>
728 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
729 <td colspan=3><select name=department style="width: 250px">$form->{selectdepartment}</select>
730 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
732 </tr> | if $form->{selectdepartment};
734 if ($form->{type} eq 'sales_order') {
735 if ($form->{selectemployee}) {
737 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
741 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
743 if ($form->{resubmit} && ($form->{format} eq "html")) {
745 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
746 } elsif ($form->{resubmit}) {
747 $onload = qq|document.oe.submit()|;
752 $credittext = $locale->text('Credit Limit exceeded!!!');
753 if ($creditwarning) {
754 $onload = qq|alert('$credittext')|;
757 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
758 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
760 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
761 # show history button js
762 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
763 #/show history button js
764 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
769 <body onLoad="$onload">
771 <form method=post name=oe action=$form->{script}>
773 <script type="text/javascript" src="js/common.js"></script>
774 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
775 <script type="text/javascript" src="js/vendor_selection.js"></script>
776 <script type="text/javascript" src="js/calculate_qty.js"></script>
779 $form->hide_form(qw(id action type vc formname media format proforma queued printed emailed
780 title discount creditlimit creditremaining tradediscount business
781 max_dunning_level dunning_amount));
787 <th class=listtop>$form->{title}</th>
809 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
810 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
813 <th align=right>| . $locale->text('Ship via') . qq|</th>
814 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
817 <th align="right">| . $locale->text('Transaction description') . qq|</th>
818 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
825 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
827 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
828 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
832 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
834 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
835 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
849 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
850 <td>$globalprojectnumber</td>
861 <!-- shipto are in hidden variables -->
863 <input type=hidden name=shiptoname value="$form->{shiptoname}">
864 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
865 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
866 <input type=hidden name=shiptocity value="$form->{shiptocity}">
867 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
868 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
869 <input type=hidden name=shiptophone value="$form->{shiptophone}">
870 <input type=hidden name=shiptofax value="$form->{shiptofax}">
871 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
872 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
873 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
875 <!-- email variables -->
876 <input type=hidden name=message value="$form->{message}">
877 <input type=hidden name=email value="$form->{email}">
878 <input type=hidden name=subject value="$form->{subject}">
879 <input type=hidden name=cc value="$form->{cc}">
880 <input type=hidden name=bcc value="$form->{bcc}">
882 <input type=hidden name=taxpart value="$form->{taxpart}">
883 <input type=hidden name=taxservice value="$form->{taxservice}">
885 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
888 foreach $item (split / /, $form->{taxaccounts}) {
890 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
891 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
894 $lxdebug->leave_sub();
898 $lxdebug->enter_sub();
900 $form->{invtotal} = $form->{invsubtotal};
902 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
905 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
908 $rows = ($rows > $introws) ? $rows : $introws;
910 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
912 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
914 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
917 if ($form->{taxaccounts}) {
919 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
920 . $locale->text('Tax Included') . qq|</b><br><br>
924 if (!$form->{taxincluded}) {
926 foreach $item (split / /, $form->{taxaccounts}) {
927 if ($form->{"${item}_base"}) {
928 $form->{invtotal} += $form->{"${item}_total"} =
930 $form->{"${item}_base"} * $form->{"${item}_rate"},
932 $form->{"${item}_total"} =
933 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
937 <th align=right>$form->{"${item}_description"} |
938 . $form->{"${item}_rate"} * 100 .qq|%</th>
939 <td align=right>$form->{"${item}_total"}</td>
945 $form->{invsubtotal} =
946 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
950 <th align=right>| . $locale->text('Subtotal') . qq|</th>
951 <td align=right>$form->{invsubtotal}</td>
957 if ($form->{taxincluded}) {
958 foreach $item (split / /, $form->{taxaccounts}) {
959 if ($form->{"${item}_base"}) {
960 $form->{"${item}_total"} =
962 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
963 (1 + $form->{"${item}_rate"})
966 $form->{"${item}_netto"} =
968 ($form->{"${item}_base"} - $form->{"${item}_total"}),
970 $form->{"${item}_total"} =
971 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
972 $form->{"${item}_netto"} =
973 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
977 <th align=right>Enthaltene $form->{"${item}_description"} |
978 . $form->{"${item}_rate"} * 100 .qq|%</th>
979 <td align=right>$form->{"${item}_total"}</td>
982 <th align=right>Nettobetrag</th>
983 <td align=right>$form->{"${item}_netto"}</td>
991 $form->{oldinvtotal} = $form->{invtotal};
993 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
1003 <th align=left>| . $locale->text('Notes') . qq|</th>
1004 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
1019 if ($form->{type} =~ /^sales_/) {
1022 <th align=left>| . $locale->text('Ertrag') . qq|</th>
1023 <td>| . $form->format_amount(\%myconfig, $form->{marge_total}, 2, 0) . qq|</td>
1026 <th align=left>| . $locale->text('Ertrag prozentual') . qq|</th>
1027 <td>| . $form->format_amount(\%myconfig, $form->{marge_percent}, 2, 0) . qq| %</td>
1033 <input type=hidden name="marge_total" value="$form->{"marge_total"}">
1034 <input type=hidden name="marge_percent" value="$form->{"marge_percent"}">
1043 <th align=right>| . $locale->text('Total') . qq|</th>
1044 <td align=right>$form->{invtotal}</td>
1052 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1053 <input type=hidden name=oldtotalpaid value=$totalpaid>
1055 <td><hr size=3 noshade></td>
1063 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
1066 <td align=left width=30%><b>Dateiname</b></td>
1067 <td align=left width=70%><b>Webdavlink</b></td>
1069 foreach $file (@{ $form->{WEBDAV} }) {
1072 <td align="left">$file->{name}</td>
1073 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
1081 <td><hr size=3 noshade></td>
1099 | . $locale->text("Edit the $form->{type}") . qq|<br>
1100 <input class=submit type=submit name=action id=update_button value="|
1101 . $locale->text('Update') . qq|">
1102 <input class=submit type=submit name=action value="|
1103 . $locale->text('Ship to') . qq|">
1104 <input class=submit type=submit name=action value="|
1105 . $locale->text('Print') . qq|">
1106 <input class=submit type=submit name=action value="|
1107 . $locale->text('E-mail') . qq|">
1108 <input class=submit type=submit name=action value="|
1109 . $locale->text('Save') . qq|">
1110 <input class=submit type=submit name=action value="|
1111 . $locale->text('Save and Close') . qq|">
1114 if (($form->{id})) {
1116 <input type="button" class="submit" onclick="set_history_window(|
1118 . qq|);" name="history" id="history" value="|
1119 . $locale->text('history')
1122 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1123 <input class=submit type=submit name=action value="|
1124 . $locale->text('Save as new') . qq|">
1125 <input class=submit type=submit name=action value="|
1126 . $locale->text('Delete') . qq|">|;
1127 if (($form->{type} =~ /sales_quotation$/)) {
1129 <input class=submit type=submit name=action value="|
1130 . $locale->text('Sales Order') . qq|">|;
1132 if ($form->{type} =~ /request_quotation$/) {
1134 <input class=submit type=submit name=action value="|
1135 . $locale->text('Purchase Order') . qq|">|;
1138 <input class=submit type=submit name=action value="|
1139 . $locale->text('Invoice') . qq|">
1142 if ($form->{type} =~ /sales_order$/) {
1144 <br>$form->{heading} als neue Vorlage verwenden für<br>
1145 <input class=submit type=submit name=action value="|
1146 . $locale->text('Purchase Order') . qq|">
1147 <input class=submit type=submit name=action value="|
1148 . $locale->text('Quotation') . qq|">
1151 } elsif ($form->{type} =~ /purchase_order$/) {
1153 <br>$form->{heading} als neue Vorlage verwenden für<br>
1154 <input class=submit type=submit name=action value="|
1155 . $locale->text('Sales Order') . qq|">
1156 <input class=submit type=submit name=action value="|
1157 . $locale->text('Request for Quotation') . qq|">
1162 <br>$form->{heading} als neue Vorlage verwenden für<br>
1163 <input class=submit type=submit name=action value="|
1164 . $locale->text('Order') . qq|">
1169 $form->hide_form("saved_xyznumber");
1173 <input type=hidden name=rowcount value=$form->{rowcount}>
1175 <input name=callback type=hidden value="$form->{callback}">
1177 <input type=hidden name=login value=$form->{login}>
1178 <input type=hidden name=password value=$form->{password}>
1185 $lxdebug->leave_sub();
1189 $lxdebug->enter_sub();
1191 set_headings($form->{"id"} ? "edit" : "add");
1193 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1194 qw(exchangerate creditlimit creditremaining);
1195 $form->{update} = 1;
1197 if($form->{payment_id}) {
1198 $payment_id = $form->{payment_id};
1201 &check_name($form->{vc});
1203 if($form->{payment_id} eq "") {
1204 $form->{payment_id} = $payment_id;
1208 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1209 $form->{exchangerate} = $exchangerate
1213 $form->check_exchangerate(
1214 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1218 $i = $form->{rowcount};
1220 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1222 if ( ($form->{"partnumber_$i"} eq "")
1223 && ($form->{"description_$i"} eq "")
1224 && ($form->{"partsgroup_$i"} eq "")) {
1226 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1231 if ( $form->{type} eq 'purchase_order'
1232 || $form->{type} eq 'request_quotation') {
1233 IR->retrieve_item(\%myconfig, \%$form);
1235 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1236 IS->retrieve_item(\%myconfig, \%$form);
1239 my $rows = scalar @{ $form->{item_list} };
1241 $form->{"discount_$i"} =
1242 $form->format_amount(\%myconfig, $form->{discount} * 100);
1245 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1254 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1255 if ($form->{"not_discountable_$i"}) {
1256 $form->{"discount_$i"} = 0;
1258 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1259 qw(partnumber description unit);
1260 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1261 keys %{ $form->{item_list}[0] };
1262 if ($form->{"part_payment_id_$i"} ne "") {
1263 $form->{payment_id} = $form->{"part_payment_id_$i"};
1266 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1268 ($dec) = ($s =~ /\.(\d+)/);
1270 $decimalplaces = ($dec > 2) ? $dec : 2;
1273 $form->{"sellprice_$i"} = $sellprice;
1276 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1278 # if there is an exchange rate adjust sellprice
1279 $form->{"sellprice_$i"} /= $exchangerate;
1283 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1284 (1 - $form->{"discount_$i"} / 100);
1285 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1286 map { $form->{"${_}_base"} += $amount }
1287 (split / /, $form->{"taxaccounts_$i"});
1288 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1289 split / /, $form->{taxaccounts}
1290 if !$form->{taxincluded};
1292 $form->{creditremaining} -= $amount;
1294 $form->{"sellprice_$i"} =
1295 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1298 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1300 # get pricegroups for parts
1301 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1303 # build up html code for prices_$i
1304 &set_pricegroup($i);
1311 # ok, so this is a new part
1312 # ask if it is a part or service item
1314 if ( $form->{"partsgroup_$i"}
1315 && ($form->{"partsnumber_$i"} eq "")
1316 && ($form->{"description_$i"} eq "")) {
1317 $form->{rowcount}--;
1318 $form->{"discount_$i"} = "";
1322 $form->{"id_$i"} = 0;
1328 $lxdebug->leave_sub();
1332 $lxdebug->enter_sub();
1334 if ($form->{type} eq 'purchase_order') {
1335 $form->{title} = $locale->text('Purchase Orders');
1336 $form->{vc} = 'vendor';
1337 $ordlabel = $locale->text('Order Number');
1338 $ordnumber = 'ordnumber';
1339 $employee = $locale->text('Employee');
1342 if ($form->{type} eq 'request_quotation') {
1343 $form->{title} = $locale->text('Request for Quotations');
1344 $form->{vc} = 'vendor';
1345 $ordlabel = $locale->text('RFQ Number');
1346 $ordnumber = 'quonumber';
1347 $employee = $locale->text('Employee');
1350 if ($form->{type} eq 'sales_order') {
1351 $form->{title} = $locale->text('Sales Orders');
1352 $form->{vc} = 'customer';
1353 $ordlabel = $locale->text('Order Number');
1354 $ordnumber = 'ordnumber';
1355 $employee = $locale->text('Employee');
1358 if ($form->{type} eq 'sales_quotation') {
1359 $form->{title} = $locale->text('Quotations');
1360 $form->{vc} = 'customer';
1361 $ordlabel = $locale->text('Quotation Number');
1362 $ordnumber = 'quonumber';
1363 $employee = $locale->text('Employee');
1366 # setup vendor / customer selection
1367 $form->all_vc(\%myconfig, $form->{vc},
1368 ($form->{vc} eq 'customer') ? "AR" : "AP");
1371 if (@{ $form->{all_departments} }) {
1372 $form->{selectdepartment} = "<option>\n";
1375 $form->{selectdepartment} .=
1376 "<option>$_->{description}--$_->{id}</option>\n"
1377 } (@{ $form->{all_departments} });
1382 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1383 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1385 | if $form->{selectdepartment};
1388 if (($form->{"type"} eq "sales_order") ||
1389 ($form->{"type"} eq "purchase_order")) {
1392 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1393 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1394 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1395 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1400 # use JavaScript Calendar or not
1401 $form->{jsscript} = 1;
1405 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1406 <input type=button name=transdatefrom id="trigger3" value=|
1407 . $locale->text('button') . qq|></td>
1410 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1411 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1412 . $locale->text('button') . qq|></td>
1417 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1418 "transdateto", "BL", "trigger4");
1420 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1422 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1424 "employees" => "ALL_EMPLOYEES",
1425 $vc => "ALL_" . uc($vc));
1429 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1430 push(@values, $item->{"id"});
1431 $labels{$item->{"id"}} = $item->{"projectnumber"};
1434 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1435 '-labels' => \%labels));
1440 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
1441 push(@values, $item->{"id"});
1442 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
1445 my $employee_block = qq|
1447 <th align="right">| . $locale->text('Employee') . qq|</th>
1449 NTI($cgi->popup_menu('-name' => 'employee_id',
1450 '-values' => \@values,
1451 '-labels' => \%labels)) . qq|
1458 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1459 push(@values, $item->{name}.qq|--|.$item->{"id"});
1460 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
1463 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1465 $myconfig{vclimit} <= scalar(@values)
1466 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
1467 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1468 '-default' => $form->{"old$form->{vc}"},
1469 '-onChange' => 'document.getElementById(\'update_button\').click();',
1470 '-values' => \@values,
1471 '-labels' => \%labels));
1477 <form method=post action=$form->{script}>
1481 <th class=listtop>$form->{title}</th>
1483 <tr height="5"></tr>
1488 <th align=right>$vc_label</th>
1489 <td colspan=3>$vc</td>
1493 <th align=right>$ordlabel</th>
1494 <td colspan=3><input name="$ordnumber" size=20></td>
1498 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1499 <td colspan="3"><input name="transaction_description" size=20></td>
1502 <th align="right">| . $locale->text("Project Number") . qq|</th>
1503 <td colspan="3">$projectnumber</td>
1506 <th align=right>| . $locale->text('From') . qq|</th>
1508 <th align=right>| . $locale->text('Bis') . qq|</th>
1511 <input type=hidden name=sort value=transdate>
1513 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1517 <td><input type="checkbox" name="open" value="1" id="open" checked>
1518 <label for="open">| . $locale->text("Open") . qq|</td>
1519 <td><input type="checkbox" name="closed" value="1" id="closed">
1520 <label for="closed">| . $locale->text("Closed") . qq|</td>
1524 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1525 | . $locale->text('ID') . qq|</td>
1526 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1527 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1528 . $locale->text('Date') . qq|</td>
1529 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1530 . $locale->text('Required by') . qq|</td>
1533 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vc_label</td>
1534 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1535 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1536 . $locale->text('Ship via') . qq|</td>
1539 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1540 . $locale->text('Amount') . qq|</td>
1541 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1542 . $locale->text('Tax') . qq|</td>
1543 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1544 . $locale->text('Total') . qq|</td>
1547 <td><input name="l_marge_total" class=checkbox type=checkbox value=Y> |
1548 . $locale->text('Ertrag') . qq|</td>
1549 <td><input name="l_marge_percent" class=checkbox type=checkbox value=Y> |
1550 . $locale->text('Ertrag prozentual') . qq|</td>
1553 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1554 . $locale->text('Project Number') . qq|</td>
1555 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1556 . $locale->text('Transaction description') . qq|</td>
1559 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1560 . $locale->text('Subtotal') . qq|</td>
1568 <tr><td colspan=4><hr size=3 noshade></td></tr>
1574 <input type=hidden name=nextsub value=orders>
1575 <input type=hidden name=login value=$form->{login}>
1576 <input type=hidden name=password value=$form->{password}>
1577 <input type=hidden name=vc value=$form->{vc}>
1578 <input type=hidden name=type value=$form->{type}>
1580 <input class=submit type=submit name=action value="|
1581 . $locale->text('Continue') . qq|">
1588 $lxdebug->leave_sub();
1591 sub create_subtotal_row {
1592 $lxdebug->enter_sub();
1594 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
1596 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
1598 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
1600 $row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
1602 map { $totals->{$_} = 0 } @{ $subtotal_columns };
1604 $lxdebug->leave_sub();
1610 $lxdebug->enter_sub();
1612 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1614 ($form->{ $form->{vc} }, $form->{"${form->{vc}}_id"}) = split(/--/, $form->{ $form->{vc} });
1616 $form->{sort} ||= 'transdate';
1618 OE->transactions(\%myconfig, \%$form);
1620 $form->{rowcount} = scalar @{ $form->{OE} };
1623 "transdate", "reqdate",
1625 "name", "netamount",
1628 "shipvia", "globalprojectnumber",
1629 "transaction_description", "open",
1630 "delivered", "marge_total", "marge_percent"
1633 # only show checkboxes if gotten here via sales_order form.
1634 my $allow_multiple_orders = $form->{type} eq 'sales_order';
1635 if ($allow_multiple_orders) {
1636 unshift @columns, "ids";
1639 $form->{l_open} = $form->{l_closed} = "Y" if ($form->{open} && $form->{closed});
1640 $form->{l_delivered} = "Y" if ($form->{delivered} && $form->{notdelivered});
1642 my $attachment_basename;
1643 if ($form->{vc} eq 'vendor') {
1644 if ($form->{type} eq 'purchase_order') {
1645 $form->{title} = $locale->text('Purchase Orders');
1646 $attachment_basename = $locale->text('purchase_order_list');
1648 $form->{title} = $locale->text('Request for Quotations');
1649 $attachment_basename = $locale->text('rfq_list');
1653 if ($form->{type} eq 'sales_order') {
1654 $form->{title} = $locale->text('Sales Orders');
1655 $attachment_basename = $locale->text('sales_order_list');
1657 $form->{title} = $locale->text('Quotations');
1658 $attachment_basename = $locale->text('quotation_list');
1662 my $report = SL::ReportGenerator->new(\%myconfig, $form);
1664 my @hidden_variables = map { "l_${_}" } @columns;
1665 push @hidden_variables, "l_subtotal", $form->{vc}, qw(l_closed l_notdelivered open closed delivered notdelivered ordnumber quonumber
1666 transaction_description transdatefrom transdateto type vc employee_id);
1668 my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
1671 'ids' => { 'text' => '', },
1672 'transdate' => { 'text' => $locale->text('Date'), },
1673 'reqdate' => { 'text' => $locale->text('Required by'), },
1674 'id' => { 'text' => $locale->text('ID'), },
1675 'ordnumber' => { 'text' => $locale->text('Order'), },
1676 'quonumber' => { 'text' => $form->{type} eq "request_quotation" ? $locale->text('RFQ') : $locale->text('Quotation'), },
1677 'name' => { 'text' => $form->{vc} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
1678 'netamount' => { 'text' => $locale->text('Amount'), },
1679 'tax' => { 'text' => $locale->text('Tax'), },
1680 'amount' => { 'text' => $locale->text('Total'), },
1681 'curr' => { 'text' => $locale->text('Curr'), },
1682 'employee' => { 'text' => $locale->text('Salesperson'), },
1683 'shipvia' => { 'text' => $locale->text('Ship via'), },
1684 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
1685 'transaction_description' => { 'text' => $locale->text('Transaction description'), },
1686 'open' => { 'text' => $locale->text('Open'), },
1687 'delivered' => { 'text' => $locale->text('Delivered'), },
1688 'marge_total' => { 'text' => $locale->text('Ertrag'), },
1689 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), }
1692 foreach my $name (qw(id transdate reqdate quonumber ordnumber name employee shipvia)) {
1693 $column_defs{$name}->{link} = $href . "&sort=$name";
1696 my %column_alignment = map { $_ => 'right' } qw(netamount tax amount curr);
1698 $form->{"l_type"} = "Y";
1699 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
1700 $column_defs{ids}->{visible} = $allow_multiple_orders ? 'HTML' : 0;
1702 $report->set_columns(%column_defs);
1703 $report->set_column_order(@columns);
1705 $report->set_export_options('orders', @hidden_variables);
1707 $report->set_sort_indicator($form->{sort}, 1);
1710 if ($form->{customer}) {
1711 push @options, $locale->text('Customer') . " : $form->{customer}";
1713 if ($form->{vendor}) {
1714 push @options, $locale->text('Vendor') . " : $form->{vendor}";
1716 if ($form->{department}) {
1717 ($department) = split /--/, $form->{department};
1718 push @options, $locale->text('Department') . " : $department";
1720 if ($form->{ordnumber}) {
1721 push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
1723 if ($form->{notes}) {
1724 push @options, $locale->text('Notes') . " : $form->{notes}";
1726 if ($form->{transaction_description}) {
1727 push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
1729 if ($form->{transdatefrom}) {
1730 push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1732 if ($form->{transdateto}) {
1733 push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
1735 if ($form->{open}) {
1736 push @options, $locale->text('Open');
1738 if ($form->{closed}) {
1739 push @options, $locale->text('Closed');
1741 if ($form->{delivered}) {
1742 push @options, $locale->text('Delivered');
1744 if ($form->{notdelivered}) {
1745 push @options, $locale->text('Not delivered');
1748 $report->set_options('top_info_text' => join("\n", @options),
1749 'raw_top_info_text' => $form->parse_html_template('oe/orders_top'),
1750 'raw_bottom_info_text' => $form->parse_html_template('oe/orders_bottom', { 'SHOW_CONTINUE_BUTTON' => $allow_multiple_orders }),
1751 'output_format' => 'HTML',
1752 'title' => $form->{title},
1753 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
1755 $report->set_options_from_form();
1757 # add sort and escape callback, this one we use for the add sub
1758 $form->{callback} = $href .= "&sort=$form->{sort}";
1760 # escape callback for href
1761 $callback = $form->escape($href);
1763 my @subtotal_columns = qw(netamount amount marge_total marge_percent);
1765 my %totals = map { $_ => 0 } @subtotal_columns;
1766 my %subtotals = map { $_ => 0 } @subtotal_columns;
1770 my $edit_url = build_std_url('action=edit', 'type', 'vc');
1772 foreach $oe (@{ $form->{OE} }) {
1773 map { $oe->{$_} *= $oe->{exchangerate} } @subtotal_columns;
1775 $oe->{tax} = $oe->{amount} - $oe->{netamount};
1776 $oe->{open} = $oe->{closed} ? $locale->text('No') : $locale->text('Yes');
1777 $oe->{delivered} = $oe->{delivered} ? $locale->text('Yes') : $locale->text('No');
1779 map { $subtotals{$_} += $oe->{$_};
1780 $totals{$_} += $oe->{$_} } @subtotal_columns;
1782 $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
1783 $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
1785 map { $oe->{$_} = $form->format_amount(\%myconfig, $oe->{$_}, 2) } qw(netamount tax amount marge_total marge_percent);
1789 foreach my $column (@columns) {
1790 next if ($column eq 'ids');
1792 'data' => $oe->{$column},
1793 'align' => $column_alignment{$column},
1798 'raw_data' => $cgi->hidden('-name' => "trans_id_${idx}", '-value' => $oe->{id})
1799 . $cgi->checkbox('-name' => "multi_id_${idx}", '-value' => 1, '-label' => ''),
1800 'valign' => 'center',
1801 'align' => 'center',
1804 $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
1806 my $row_set = [ $row ];
1808 if (($form->{l_subtotal} eq 'Y')
1809 && (($idx == (scalar @{ $form->{OE} } - 1))
1810 || ($oe->{ $form->{sort} } ne $form->{OE}->[$idx + 1]->{ $form->{sort} }))) {
1811 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
1814 $report->add_data($row_set);
1819 $report->add_separator();
1820 $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
1822 $report->generate_with_headers();
1824 $lxdebug->leave_sub();
1827 sub check_delivered_flag {
1828 $lxdebug->enter_sub();
1830 if (($form->{type} ne 'sales_order') && ($form->{type} ne 'purchase_order')) {
1831 return $lxdebug->leave_sub();
1834 my $all_delivered = 0;
1836 foreach my $i (1 .. $form->{rowcount}) {
1837 next if (!$form->{"id_$i"});
1839 if ($form->parse_amount(\%myconfig, $form->{"qty_$i"}) == $form->parse_amount(\%myconfig, $form->{"ship_$i"})) {
1848 $form->{delivered} = 1 if $all_delivered;
1850 $lxdebug->leave_sub();
1853 sub save_and_close {
1854 $lxdebug->enter_sub();
1856 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1858 if ($form->{type} =~ /_order$/) {
1859 $form->isblank("transdate", $locale->text('Order Date missing!'));
1861 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1864 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1865 $form->{$idx} =~ s/^\s*//g;
1866 $form->{$idx} =~ s/\s*$//g;
1868 $msg = ucfirst $form->{vc};
1869 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1871 # $locale->text('Customer missing!');
1872 # $locale->text('Vendor missing!');
1874 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1875 if ($form->{currency} ne $form->{defaultcurrency});
1879 if($form->{payment_id}) {
1880 $payment_id = $form->{payment_id};
1883 # if the name changed get new values
1884 if (&check_name($form->{vc})) {
1885 if($form->{payment_id} eq "") {
1886 $form->{payment_id} = $payment_id;
1892 $form->{id} = 0 if $form->{saveasnew};
1894 # this is for the internal notes section for the [email] Subject
1895 if ($form->{type} =~ /_order$/) {
1896 if ($form->{type} eq 'sales_order') {
1897 $form->{label} = $locale->text('Sales Order');
1899 $numberfld = "sonumber";
1900 $ordnumber = "ordnumber";
1902 $form->{label} = $locale->text('Purchase Order');
1904 $numberfld = "ponumber";
1905 $ordnumber = "ordnumber";
1908 $err = $locale->text('Cannot save order!');
1910 check_delivered_flag();
1913 if ($form->{type} eq 'sales_quotation') {
1914 $form->{label} = $locale->text('Quotation');
1916 $numberfld = "sqnumber";
1917 $ordnumber = "quonumber";
1919 $form->{label} = $locale->text('Request for Quotation');
1921 $numberfld = "rfqnumber";
1922 $ordnumber = "quonumber";
1925 $err = $locale->text('Cannot save quotation!');
1929 # get new number in sequence if no number is given or if saveasnew was requested
1930 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1931 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1936 $form->error($err) if (!OE->save(\%myconfig, \%$form));
1938 # saving the history
1939 if(!exists $form->{addition}) {
1940 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1941 $form->{addition} = "SAVED";
1942 $form->save_history($form->dbconnect(\%myconfig));
1944 # /saving the history
1946 $form->redirect($form->{label} . " $form->{$ordnumber} " .
1947 $locale->text('saved!'));
1949 $lxdebug->leave_sub();
1953 $lxdebug->enter_sub();
1955 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1958 if ($form->{type} =~ /_order$/) {
1959 $form->isblank("transdate", $locale->text('Order Date missing!'));
1961 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1964 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1965 $form->{$idx} =~ s/^\s*//g;
1966 $form->{$idx} =~ s/\s*$//g;
1968 $msg = ucfirst $form->{vc};
1969 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1971 # $locale->text('Customer missing!');
1972 # $locale->text('Vendor missing!');
1974 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1975 if ($form->{currency} ne $form->{defaultcurrency});
1979 if($form->{payment_id}) {
1980 $payment_id = $form->{payment_id};
1983 # if the name changed get new values
1984 if (&check_name($form->{vc})) {
1985 if($form->{payment_id} eq "") {
1986 $form->{payment_id} = $payment_id;
1992 $form->{id} = 0 if $form->{saveasnew};
1994 # this is for the internal notes section for the [email] Subject
1995 if ($form->{type} =~ /_order$/) {
1996 if ($form->{type} eq 'sales_order') {
1997 $form->{label} = $locale->text('Sales Order');
1999 $numberfld = "sonumber";
2000 $ordnumber = "ordnumber";
2002 $form->{label} = $locale->text('Purchase Order');
2004 $numberfld = "ponumber";
2005 $ordnumber = "ordnumber";
2008 $err = $locale->text('Cannot save order!');
2010 check_delivered_flag();
2013 if ($form->{type} eq 'sales_quotation') {
2014 $form->{label} = $locale->text('Quotation');
2016 $numberfld = "sqnumber";
2017 $ordnumber = "quonumber";
2019 $form->{label} = $locale->text('Request for Quotation');
2021 $numberfld = "rfqnumber";
2022 $ordnumber = "quonumber";
2025 $err = $locale->text('Cannot save quotation!');
2029 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
2030 unless $form->{$ordnumber};
2034 OE->save(\%myconfig, \%$form);
2036 # saving the history
2037 if(!exists $form->{addition}) {
2038 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2039 $form->{addition} = "SAVED";
2040 $form->save_history($form->dbconnect(\%myconfig));
2042 # /saving the history
2044 $form->{simple_save} = 1;
2045 if(!$form->{print_and_save}) {
2046 set_headings("edit");
2050 $lxdebug->leave_sub();
2054 $lxdebug->enter_sub();
2058 if ($form->{type} =~ /_order$/) {
2059 $msg = $locale->text('Are you sure you want to delete Order Number');
2060 $ordnumber = 'ordnumber';
2062 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2063 $ordnumber = 'quonumber';
2069 <form method=post action=$form->{script}>
2072 # delete action variable
2073 map { delete $form->{$_} } qw(action header);
2075 foreach $key (keys %$form) {
2076 $form->{$key} =~ s/\"/"/g;
2077 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2081 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2083 <h4>$msg $form->{$ordnumber}</h4>
2085 <input type="hidden" name="yes_nextsub" value="delete_order_quotation">
2086 <input name=action class=submit type=submit value="|
2087 . $locale->text('Yes') . qq|">
2088 <button class=submit type=button onclick="history.back()">|
2089 . $locale->text('No') . qq|</button>
2096 $lxdebug->leave_sub();
2099 sub delete_order_quotation {
2100 $lxdebug->enter_sub();
2102 if ($form->{type} =~ /_order$/) {
2103 $msg = $locale->text('Order deleted!');
2104 $err = $locale->text('Cannot delete order!');
2106 $msg = $locale->text('Quotation deleted!');
2107 $err = $locale->text('Cannot delete quotation!');
2109 if (OE->delete(\%myconfig, \%$form, $spool)){
2110 # saving the history
2111 if(!exists $form->{addition}) {
2112 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2113 $form->{addition} = "DELETED";
2114 $form->save_history($form->dbconnect(\%myconfig));
2116 # /saving the history
2122 $lxdebug->leave_sub();
2126 $lxdebug->enter_sub();
2128 $form->{old_employee_id} = $form->{employee_id};
2129 $form->{old_salesman_id} = $form->{salesman_id};
2131 if ($form->{type} =~ /_order$/) {
2133 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2134 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2135 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2136 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2137 $form->isblank("transdate", $locale->text('Order Date missing!'))
2138 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2140 # also copy deliverydate from the order
2141 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2142 $form->{orddate} = $form->{transdate};
2144 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2145 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2146 $form->{ordnumber} = "";
2147 $form->{quodate} = $form->{transdate};
2150 $payment_id = $form->{payment_id} if $form->{payment_id};
2152 # if the name changed get new values
2153 if (&check_name($form->{vc})) {
2154 $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
2159 $form->{cp_id} *= 1;
2161 for $i (1 .. $form->{rowcount}) {
2162 for (qw(ship qty sellprice listprice basefactor)) {
2163 $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"};
2167 if ( $form->{type} =~ /_order/
2168 && $form->{currency} ne $form->{defaultcurrency}) {
2170 # check if we need a new exchangerate
2171 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2173 $orddate = $form->current_date(\%myconfig);
2174 $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate, $buysell);
2176 if (!$exchangerate) {
2177 &backorder_exchangerate($orddate, $buysell);
2182 # close orders/quotations
2183 $form->{closed} = 1;
2185 # save order if one ordnumber has been given
2186 # if not it's most likely a collective order, which can't be saved back
2187 # so they just have to be closed
2188 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2189 OE->close_order(\%myconfig, \%$form) if ($form->{id});
2191 OE->close_orders(\%myconfig, \%$form);
2194 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2195 $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2198 $form->{closed} = 0;
2199 $form->{rowcount}--;
2200 $form->{shipto} = 1;
2202 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
2204 if ($form->{type} =~ /_order$/) {
2205 $form->{exchangerate} = $exchangerate;
2209 if ( $form->{type} eq 'purchase_order'
2210 || $form->{type} eq 'request_quotation') {
2211 $form->{title} = $locale->text('Add Vendor Invoice');
2212 $form->{script} = 'ir.pl';
2217 if ( $form->{type} eq 'sales_order'
2218 || $form->{type} eq 'sales_quotation') {
2219 $form->{title} = $locale->text('Add Sales Invoice');
2220 $form->{script} = 'is.pl';
2225 # bo creates the id, reset it
2226 map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued);
2227 $form->{ $form->{vc} } =~ s/--.*//g;
2228 $form->{type} = "invoice";
2231 $locale = new Locale "$myconfig{countrycode}", "$script";
2233 require "bin/mozilla/$form->{script}";
2235 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2237 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2238 qw(creditlimit creditremaining);
2240 $currency = $form->{currency};
2243 $form->{currency} = $currency;
2244 $form->{exchangerate} = "";
2245 $form->{forex} = "";
2246 $form->{exchangerate} = $exchangerate
2250 $form->check_exchangerate(
2251 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2254 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2259 for $i (1 .. $form->{rowcount}) {
2260 $form->{"discount_$i"} =
2261 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2263 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2265 $decimalplaces = ($dec > 2) ? $dec : 2;
2267 # copy delivery date from reqdate for order -> invoice conversion
2268 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2269 unless $form->{"deliverydate_$i"};
2271 $form->{"sellprice_$i"} =
2272 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2275 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2276 $dec_qty = length $dec_qty;
2278 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2280 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2281 qw(partnumber description unit);
2287 $lxdebug->leave_sub();
2290 sub backorder_exchangerate {
2291 $lxdebug->enter_sub();
2292 my ($orddate, $buysell) = @_;
2299 <form method=post action=$form->{script}>
2302 # delete action variable
2303 map { delete $form->{$_} } qw(action header exchangerate);
2305 foreach $key (keys %$form) {
2306 $form->{$key} =~ s/\"/"/g;
2307 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2310 $form->{title} = $locale->text('Add Exchangerate');
2314 <input type=hidden name=login value=$form->{login}>
2315 <input type=hidden name=password value=$form->{password}>
2317 <input type=hidden name=exchangeratedate value=$orddate>
2318 <input type=hidden name=buysell value=$buysell>
2321 <tr><th class=listtop>$form->{title}</th></tr>
2322 <tr height="5"></tr>
2327 <th align=right>| . $locale->text('Currency') . qq|</th>
2328 <td>$form->{currency}</td>
2331 <th align=right>| . $locale->text('Date') . qq|</th>
2335 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2336 <td><input name=exchangerate size=11></td>
2346 <input type=hidden name=nextsub value=save_exchangerate>
2348 <input name=action class=submit type=submit value="|
2349 . $locale->text('Continue') . qq|">
2357 $lxdebug->leave_sub();
2360 sub save_exchangerate {
2361 $lxdebug->enter_sub();
2363 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2364 $form->{exchangerate} =
2365 $form->parse_amount(\%myconfig, $form->{exchangerate});
2366 $form->save_exchangerate(\%myconfig, $form->{currency},
2367 $form->{exchangeratedate},
2368 $form->{exchangerate}, $form->{buysell});
2372 $lxdebug->leave_sub();
2375 sub create_backorder {
2376 $lxdebug->enter_sub();
2378 $form->{shipped} = 1;
2380 # figure out if we need to create a backorder
2381 # items aren't saved if qty != 0
2383 for $i (1 .. $form->{rowcount}) {
2384 $totalqty += $qty = $form->{"qty_$i"};
2385 $totalship += $ship = $form->{"ship_$i"};
2387 $form->{"qty_$i"} = $qty - $ship;
2390 if ($totalship == 0) {
2391 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2392 $form->{ordtotal} = 0;
2393 $form->{shipped} = 0;
2397 if ($totalqty == $totalship) {
2398 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2399 $form->{ordtotal} = 0;
2404 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2407 for $i (1 .. $form->{rowcount}) {
2409 $form->{"${_}_$i"} =
2410 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2411 } qw(sellprice discount);
2416 OE->save(\%myconfig, \%$form);
2418 # rebuild rows for invoice
2422 for $i (1 .. $form->{rowcount}) {
2423 $form->{"qty_$i"} = $form->{"ship_$i"};
2425 if ($form->{"qty_$i"}) {
2428 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2433 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2434 $form->{rowcount} = $count;
2436 $lxdebug->leave_sub();
2440 $lxdebug->enter_sub();
2442 $form->{saveasnew} = 1;
2443 $form->{closed} = 0;
2444 map { delete $form->{$_} } qw(printed emailed queued);
2446 # Let Lx-Office assign a new order number if the user hasn't changed the
2447 # previous one. If it has been changed manually then use it as-is.
2448 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2449 $form->{$idx} =~ s/^\s*//g;
2450 $form->{$idx} =~ s/\s*$//g;
2451 if ($form->{saved_xyznumber} &&
2452 ($form->{saved_xyznumber} eq $form->{$idx})) {
2453 delete($form->{$idx});
2458 $lxdebug->leave_sub();
2461 sub check_for_direct_delivery_yes {
2462 $lxdebug->enter_sub();
2464 $form->{direct_delivery_checked} = 1;
2465 delete @{$form}{grep /^shipto/, keys %{ $form }};
2466 map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
2467 $form->{shipto} = 1;
2469 $lxdebug->leave_sub();
2472 sub check_for_direct_delivery_no {
2473 $lxdebug->enter_sub();
2475 $form->{direct_delivery_checked} = 1;
2476 delete @{$form}{grep /^shipto/, keys %{ $form }};
2479 $lxdebug->leave_sub();
2482 sub check_for_direct_delivery {
2483 $lxdebug->enter_sub();
2485 if ($form->{direct_delivery_checked}
2486 || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
2487 $lxdebug->leave_sub();
2491 if ($form->{shipto_id}) {
2492 Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_");
2495 map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form };
2498 delete $form->{action};
2499 $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ref $_ eq "" } keys %{ $form } ];
2502 print $form->parse_html_template("oe/check_for_direct_delivery");
2504 $lxdebug->leave_sub();
2509 sub purchase_order {
2510 $lxdebug->enter_sub();
2512 if ($form->{type} eq 'sales_order') {
2513 check_for_direct_delivery();
2516 if ( $form->{type} eq 'sales_quotation'
2517 || $form->{type} eq 'request_quotation') {
2518 OE->close_order(\%myconfig, \%$form);
2521 if ($form->{type} =~ /^sales_/) {
2522 delete($form->{ordnumber});
2525 $form->{cp_id} *= 1;
2527 $form->{title} = $locale->text('Add Purchase Order');
2528 $form->{vc} = "vendor";
2529 $form->{type} = "purchase_order";
2533 $lxdebug->leave_sub();
2537 $lxdebug->enter_sub();
2539 if ( $form->{type} eq 'sales_quotation'
2540 || $form->{type} eq 'request_quotation') {
2541 OE->close_order(\%myconfig, $form);
2544 if ($form->{type} eq "purchase_order") {
2545 delete($form->{ordnumber});
2548 $form->{cp_id} *= 1;
2550 $form->{title} = $locale->text('Add Sales Order');
2551 $form->{vc} = "customer";
2552 $form->{type} = "sales_order";
2556 $lxdebug->leave_sub();
2560 $lxdebug->enter_sub();
2562 $form->{transdate} = $form->current_date(\%myconfig);
2563 delete $form->{duedate};
2565 $form->{closed} = 0;
2567 $form->{old_employee_id} = $form->{employee_id};
2568 $form->{old_salesman_id} = $form->{salesman_id};
2571 map { delete $form->{$_} }
2572 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2574 for $i (1 .. $form->{rowcount}) {
2575 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2576 $form->{"${_}_${i}"})
2577 if ($form->{"${_}_${i}"}) }
2578 qw(ship qty sellprice listprice basefactor));
2586 for $i (1 .. $form->{rowcount} - 1) {
2587 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2588 qw(partnumber description unit);
2591 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2592 qw(creditlimit creditremaining);
2596 $lxdebug->leave_sub();
2600 $lxdebug->enter_sub();
2602 $form->{print_and_save} = 1;
2606 my $saved_form = save_form();
2611 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2612 restore_form($saved_form);
2613 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2617 $lxdebug->leave_sub();
2621 call_sub($form->{yes_nextsub});
2625 call_sub($form->{no_nextsub});