1 # #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger, Accounting
9 # Copyright (c) 1998-2003
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
32 #======================================================================
40 require "bin/mozilla/io.pl";
41 require "bin/mozilla/arap.pl";
48 # $locale->text('Edit the purchase_order');
49 # $locale->text('Edit the sales_order');
50 # $locale->text('Edit the request_quotation');
51 # $locale->text('Edit the sales_quotation');
53 # $locale->text('Workflow purchase_order');
54 # $locale->text('Workflow sales_order');
55 # $locale->text('Workflow request_quotation');
56 # $locale->text('Workflow sales_quotation');
59 $lxdebug->enter_sub();
63 if ($form->{type} eq 'purchase_order') {
64 $form->{title} = $action eq "edit" ?
65 $locale->text('Edit Purchase Order') :
66 $locale->text('Add Purchase Order');
67 $form->{heading} = $locale->text('Purchase Order');
68 $form->{vc} = 'vendor';
70 if ($form->{type} eq 'sales_order') {
71 $form->{title} = $action eq "edit" ?
72 $locale->text('Edit Sales Order') :
73 $locale->text('Add Sales Order');
74 $form->{heading} = $locale->text('Sales Order');
75 $form->{vc} = 'customer';
77 if ($form->{type} eq 'request_quotation') {
78 $form->{title} = $action eq "edit" ?
79 $locale->text('Edit Request for Quotation') :
80 $locale->text('Add Request for Quotation');
81 $form->{heading} = $locale->text('Request for Quotation');
82 $form->{vc} = 'vendor';
84 if ($form->{type} eq 'sales_quotation') {
85 $form->{title} = $action eq "edit" ?
86 $locale->text('Edit Quotation') :
87 $locale->text('Add Quotation');
88 $form->{heading} = $locale->text('Quotation');
89 $form->{vc} = 'customer';
92 $lxdebug->leave_sub();
96 $lxdebug->enter_sub();
101 "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}"
102 unless $form->{callback};
108 $lxdebug->leave_sub();
112 $lxdebug->enter_sub();
113 # show history button
114 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
115 #/show hhistory button
117 $form->{simple_save} = 0;
119 set_headings("edit");
121 # editing without stuff to edit? try adding it first
122 if ($form->{rowcount}) {
123 map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount});
127 undef $form->{rowcount};
129 $lxdebug->leave_sub();
132 } elsif (!$form->{id}) {
134 $lxdebug->leave_sub();
138 if ($form->{print_and_save}) {
139 $form->{action} = "print";
140 $form->{resubmit} = 1;
141 $language_id = $form->{language_id};
142 $printer_id = $form->{printer_id};
145 set_headings("edit");
149 if ($form->{print_and_save}) {
150 $form->{language_id} = $language_id;
151 $form->{printer_id} = $printer_id;
155 $lxdebug->leave_sub();
159 $lxdebug->enter_sub();
160 # get customer/vendor
161 $form->all_vc(\%myconfig, $form->{vc},
162 ($form->{vc} eq 'customer') ? "AR" : "AP");
164 # retrieve order/quotation
165 $form->{webdav} = $webdav;
166 $form->{jsscript} = 1;
168 my $editing = $form->{id};
170 OE->retrieve(\%myconfig, \%$form);
172 if ($form->{payment_id}) {
173 $payment_id = $form->{payment_id};
175 if ($form->{language_id}) {
176 $language_id = $form->{language_id};
178 if ($form->{taxzone_id}) {
179 $taxzone_id = $form->{taxzone_id};
182 $salesman_id = $form->{salesman_id} if ($editing);
185 # if multiple rowcounts (== collective order) then check if the
186 # there were more than one customer (in that case OE::retrieve removes
187 # the content from the field)
188 if ( $form->{rowcount}
189 && $form->{type} eq 'sales_order'
190 && defined $form->{customer}
191 && $form->{customer} eq '') {
193 # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
196 'Collective Orders only work for orders from one customer!')
200 $taxincluded = $form->{taxincluded};
201 $form->{shipto} = 1 if $form->{id};
203 if ($form->{"all_$form->{vc}"}) {
204 unless ($form->{"$form->{vc}_id"}) {
205 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
209 $cp_id = $form->{cp_id};
210 $intnotes = $form->{intnotes};
212 # get customer / vendor
213 if ($form->{type} =~ /(purchase_order|request_quotation)/) {
214 IR->get_vendor(\%myconfig, \%$form);
216 #quote all_vendor Bug 133
217 foreach $ref (@{ $form->{all_vendor} }) {
218 $ref->{name} = $form->quote($ref->{name});
222 if ($form->{type} =~ /sales_(order|quotation)/) {
223 IS->get_customer(\%myconfig, \%$form);
225 #quote all_vendor Bug 133
226 foreach $ref (@{ $form->{all_customer} }) {
227 $ref->{name} = $form->quote($ref->{name});
231 $form->{cp_id} = $cp_id;
234 $form->{payment_id} = $payment_id;
237 $form->{language_id} = $language_id;
240 $form->{taxzone_id} = $taxzone_id;
242 $form->{intnotes} = $intnotes if $intnotes;
243 ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
244 $form->{"old$form->{vc}"} =
245 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
247 # build the popup menus
248 if (@{ $form->{"all_$form->{vc}"} }) {
249 $form->{ $form->{vc} } =
250 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
251 map { $form->{"select$form->{vc}"} .=
252 "<option>$_->{name}--$_->{id}</option>\n" }
253 (@{ $form->{"all_$form->{vc}"} });
256 $form->{taxincluded} = $taxincluded if ($form->{id});
259 if (@{ $form->{all_departments} }) {
260 $form->{selectdepartment} = "<option>\n";
261 $form->{department} = "$form->{department}--$form->{department_id}";
264 $form->{selectdepartment} .=
265 "<option>$_->{description}--$_->{id}</option>\n"
266 } (@{ $form->{all_departments} });
269 $form->{employee} = "$form->{employee}--$form->{employee_id}";
272 $form->{forex} = $form->{exchangerate};
274 $form->{salesman_id} = $salesman_id if ($editing);
276 $lxdebug->leave_sub();
280 $lxdebug->enter_sub();
281 $form->{formname} = $form->{type} unless $form->{formname};
284 foreach $ref (@{ $form->{form_details} }) {
285 $form->{rowcount} = ++$i;
287 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
289 for my $i (1 .. $form->{rowcount}) {
291 $form->{"discount_$i"} =
292 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
294 $form->{"discount_$i"} =
295 $form->format_amount(\%myconfig, $form->{"discount_$i"});
297 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
299 $decimalplaces = ($dec > 2) ? $dec : 2;
301 # copy reqdate from deliverydate for invoice -> order conversion
302 $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
303 unless $form->{"reqdate_$i"};
305 $form->{"sellprice_$i"} =
306 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
309 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
310 $dec_qty = length $dec_qty;
312 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
314 map { $form->{"${_}_$i"} =~ s/\"/"/g }
315 qw(partnumber description unit);
318 $lxdebug->leave_sub();
322 $lxdebug->enter_sub();
324 my $checkedclosed = $form->{"closed"} ? "checked" : "";
325 my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
327 map { $form->{$_} =~ s/\"/"/g }
328 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
329 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
330 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
332 # use JavaScript Calendar or not
333 $form->{jsscript} = 1;
337 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\">
338 <input type=button name=transdate id="trigger1" value=|
339 . $locale->text('button') . qq|></td>
342 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\">
343 <input type=button name=reqdate name=reqdate id="trigger2" value=|
344 . $locale->text('button') . qq|></td>
349 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
350 "reqdate", "BL", "trigger2");
354 if (($form->{"type"} eq "sales_order") ||
355 ($form->{"type"} eq "purchase_order")) {
357 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
358 <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
363 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
364 <label for="closed">| . $locale->text('Closed') . qq|</label>|);
370 <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
376 # set option selected
377 foreach $item ($form->{vc}, currency, department, employee, ($form->{vc} eq "customer" ? customer : vendor)) {
378 $form->{"select$item"} =~ s/ selected//;
379 $form->{"select$item"} =~
380 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
383 #quote select[customer|vendor] Bug 133
384 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
386 #substitute \n and \r to \s (bug 543)
387 $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
389 my @old_project_ids = ($form->{"globalproject_id"});
390 map({ push(@old_project_ids, $form->{"project_id_$_"})
391 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
393 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
394 $form->get_lists("contacts" => "ALL_CONTACTS",
395 "shipto" => "ALL_SHIPTO",
396 "projects" => { "key" => "ALL_PROJECTS",
398 "old_id" => \@old_project_ids },
399 "employees" => "ALL_SALESMEN",
400 "taxzones" => "ALL_TAXZONES",
401 "payments" => "ALL_PAYMENTS",
402 "currencies" => "ALL_CURRENCIES",
403 $vc => "ALL_" . uc($vc));
406 my @values = (undef);
407 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
408 push(@values, $item->{"cp_id"});
409 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
410 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
414 if (scalar @values > 1) {
417 <th align="right">| . $locale->text('Contact Person') . qq|</th>
419 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
420 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
429 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
430 push(@values, $item->{name}.qq|--|.$item->{"id"});
431 $labels{$item->{"id"}} = $item->{name}.qq|--|.$item->{"id"};
435 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
436 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
437 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
439 (($myconfig{vclimit} <= scalar(@values))
440 ? qq|<input type="text" value="| . H($form->{"old$form->{vc}"}) . qq|" name="$form->{vc}">|
441 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
442 '-onChange' => 'document.getElementById(\'update_button\').click();',
443 '-values' => \@values, '-labels' => \%labels)))) . qq|
444 <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
445 </td><input type=hidden name="select$form->{vc}" value="| .
446 Q($form->{"select$form->{vc}"}) . qq|">|;
450 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
451 push(@values, $item->{"id"});
452 $labels{$item->{"id"}} = $item->{"description"};
456 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
458 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values,
459 '-labels' => \%labels, '-default' => $form->{payment_id}))
464 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
465 push(@values, $item->{"shipto_id"});
466 $labels{$item->{"shipto_id"}} =
467 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
471 if (scalar @values > 1) {
474 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
476 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
477 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
483 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
484 push(@values, $item->{"id"});
485 $labels{$item->{"id"}} = $item->{"projectnumber"};
487 my $globalprojectnumber =
488 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
489 '-labels' => \%labels,
490 '-default' => $form->{"globalproject_id"}));
493 if ($form->{type} =~ /^sales_/) {
496 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
497 push(@values, $item->{id});
498 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
503 <th align="right">| . $locale->text('Salesman') . qq|</th>
505 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{salesman_id},
506 '-values' => \@values, '-labels' => \%labels))
513 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
514 push(@values, $item->{"id"});
515 $labels{$item->{"id"}} = $item->{"name"};
520 <th align="right">| . $locale->text('Employee') . qq|</th>
522 NTI($cgi->popup_menu('-name' => 'employee', '-default' => $form->{"employee"},
523 '-values' => \@values, '-labels' => \%labels)) . qq|
529 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
530 push(@values, $item->{"id"});
531 $labels{$item->{"id"}} = $item->{"description"};
536 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
538 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
539 '-values' => \@values, '-labels' => \%labels)) . qq|
546 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
547 push(@values, $item);
548 $labels{$item} = $item;
551 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
553 if (scalar @values) {
556 <th align="right">| . $locale->text('Currency') . qq|</th>
558 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
559 '-values' => \@values, '-labels' => \%labels)) . qq|
564 $form->{exchangerate} =
565 $form->format_amount(\%myconfig, $form->{exchangerate});
567 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
573 $form->{creditlimit} =
574 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
575 $form->{creditremaining} =
576 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
579 <input type=hidden name=forex value=$form->{forex}>
582 if ($form->{currency} ne $form->{defaultcurrency}) {
583 if ($form->{forex}) {
586 . $locale->text('Exchangerate')
587 . qq|</th><td>$form->{exchangerate}</td>
588 <input type=hidden name=exchangerate value=$form->{exchangerate}>
593 . $locale->text('Exchangerate')
594 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
598 if ($form->{business}) {
601 <th align=right>| . $locale->text('Business') . qq|</th>
602 <td>$form->{business}</td>
603 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
605 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
611 if ($form->{max_dunning_level}) {
617 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
618 <td><b>$form->{max_dunning_level}</b></td>
619 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
621 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
630 if ($form->{type} !~ /_quotation$/) {
633 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
634 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
637 <th width=70% align=right nowrap>|
638 . $locale->text('Quotation Number') . qq|</th>
639 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
642 <th width=70% align=right nowrap>|
643 . $locale->text('Customer Order Number') . qq|</th>
644 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
647 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
652 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
657 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
659 $creditremaining = qq|
665 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
666 <td>$form->{creditlimit}</td>
668 <th nowrap>| . $locale->text('Remaining') . qq|</th>
669 <td class="plus$n" nowrap>$form->{creditremaining}</td>
678 ($form->{type} eq 'sales_quotation')
679 ? $locale->text('Valid until')
680 : $locale->text('Required by');
681 if ($form->{type} eq 'sales_quotation') {
684 <th width=70% align=right nowrap>|
685 . $locale->text('Quotation Number') . qq|</th>
686 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
687 <input type=hidden name=ordnumber value="$form->{ordnumber}">
693 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
694 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
695 <input type=hidden name=ordnumber value="$form->{ordnumber}">
703 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
707 <th align=right nowrap=true>$reqlabel</th>
711 $creditremaining = qq| <tr>
719 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
720 <td colspan=3><select name=department>$form->{selectdepartment}</select>
721 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
723 </tr> | if $form->{selectdepartment};
725 if ($form->{type} eq 'sales_order') {
726 if ($form->{selectemployee}) {
728 <input type=hidden name=customer_klass value=$form->{customer_klass}>
734 <input type=hidden name=customer_klass value=$form->{customer_klass}>
738 if ($form->{resubmit} && ($form->{format} eq "html")) {
740 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
741 } elsif ($form->{resubmit}) {
742 $onload = qq|document.oe.submit()|;
747 $credittext = $locale->text('Credit Limit exceeded!!!');
748 if ($creditwarning) {
749 $onload = qq|alert('$credittext')|;
752 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
753 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
755 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
756 # show history button js
757 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
758 #/show history button js
759 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
764 <body onLoad="$onload">
766 <form method=post name=oe action=$form->{script}>
767 <script type="text/javascript" src="js/common.js"></script>
768 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
769 <script type="text/javascript" src="js/vendor_selection.js"></script>
770 <script type="text/javascript" src="js/calculate_qty.js"></script>
772 <input type=hidden name=id value=$form->{id}>
773 <input type=hidden name=action value=$form->{action}>
775 <input type=hidden name=type value=$form->{type}>
776 <input type=hidden name=formname value=$form->{formname}>
777 <input type=hidden name=media value=$form->{media}>
778 <input type=hidden name=format value=$form->{format}>
779 <input type=hidden name=proforma value=$form->{proforma}>
781 <input type=hidden name=queued value="$form->{queued}">
782 <input type=hidden name=printed value="$form->{printed}">
783 <input type=hidden name=emailed value="$form->{emailed}">
785 <input type=hidden name=vc value=$form->{vc}>
787 <input type=hidden name=title value="$form->{title}">
789 <input type=hidden name=discount value=$form->{discount}>
790 <input type=hidden name=creditlimit value=$form->{creditlimit}>
791 <input type=hidden name=creditremaining value=$form->{creditremaining}>
793 <input type=hidden name=tradediscount value=$form->{tradediscount}>
794 <input type=hidden name=business value=$form->{business}>
795 <input type=hidden name=webdav value=$webdav>
799 <th class=listtop>$form->{title}</th>
821 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
822 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
825 <th align=right>| . $locale->text('Ship via') . qq|</th>
826 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
829 <th align="right">| . $locale->text('Transaction description') . qq|</th>
830 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
837 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
839 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
840 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
844 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
846 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
847 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
861 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
862 <td>$globalprojectnumber</td>
873 <!-- shipto are in hidden variables -->
875 <input type=hidden name=shiptoname value="$form->{shiptoname}">
876 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
877 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
878 <input type=hidden name=shiptocity value="$form->{shiptocity}">
879 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
880 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
881 <input type=hidden name=shiptophone value="$form->{shiptophone}">
882 <input type=hidden name=shiptofax value="$form->{shiptofax}">
883 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
884 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
885 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
887 <!-- email variables -->
888 <input type=hidden name=message value="$form->{message}">
889 <input type=hidden name=email value="$form->{email}">
890 <input type=hidden name=subject value="$form->{subject}">
891 <input type=hidden name=cc value="$form->{cc}">
892 <input type=hidden name=bcc value="$form->{bcc}">
894 <input type=hidden name=taxpart value="$form->{taxpart}">
895 <input type=hidden name=taxservice value="$form->{taxservice}">
897 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
900 foreach $item (split / /, $form->{taxaccounts}) {
902 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
903 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
906 $lxdebug->leave_sub();
910 $lxdebug->enter_sub();
912 $form->{invtotal} = $form->{invsubtotal};
914 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
917 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
920 $rows = ($rows > $introws) ? $rows : $introws;
922 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
924 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
926 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
929 if ($form->{taxaccounts}) {
931 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
932 . $locale->text('Tax Included') . qq|</b><br><br>
936 if (!$form->{taxincluded}) {
938 foreach $item (split / /, $form->{taxaccounts}) {
939 if ($form->{"${item}_base"}) {
940 $form->{invtotal} += $form->{"${item}_total"} =
942 $form->{"${item}_base"} * $form->{"${item}_rate"},
944 $form->{"${item}_total"} =
945 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
949 <th align=right>$form->{"${item}_description"} |
950 . $form->{"${item}_rate"} * 100 .qq|%</th>
951 <td align=right>$form->{"${item}_total"}</td>
957 $form->{invsubtotal} =
958 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
962 <th align=right>| . $locale->text('Subtotal') . qq|</th>
963 <td align=right>$form->{invsubtotal}</td>
969 if ($form->{taxincluded}) {
970 foreach $item (split / /, $form->{taxaccounts}) {
971 if ($form->{"${item}_base"}) {
972 $form->{"${item}_total"} =
974 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
975 (1 + $form->{"${item}_rate"})
978 $form->{"${item}_netto"} =
980 ($form->{"${item}_base"} - $form->{"${item}_total"}),
982 $form->{"${item}_total"} =
983 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
984 $form->{"${item}_netto"} =
985 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
989 <th align=right>Enthaltene $form->{"${item}_description"} |
990 . $form->{"${item}_rate"} * 100 .qq|%</th>
991 <td align=right>$form->{"${item}_total"}</td>
994 <th align=right>Nettobetrag</th>
995 <td align=right>$form->{"${item}_netto"}</td>
1003 $form->{oldinvtotal} = $form->{invtotal};
1005 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
1015 <th align=left>| . $locale->text('Notes') . qq|</th>
1016 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
1027 <td align=right width=100%>
1033 <th align=right>| . $locale->text('Total') . qq|</th>
1034 <td align=right>$form->{invtotal}</td>
1042 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1043 <input type=hidden name=oldtotalpaid value=$totalpaid>
1045 <td><hr size=3 noshade></td>
1053 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
1056 <td align=left width=30%><b>Dateiname</b></td>
1057 <td align=left width=70%><b>Webdavlink</b></td>
1059 foreach $file (keys %{ $form->{WEBDAV} }) {
1062 <td align=left>$file</td>
1063 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1071 <td><hr size=3 noshade></td>
1089 | . $locale->text("Edit the $form->{type}") . qq|<br>
1090 <input class=submit type=submit name=action id=update_button value="|
1091 . $locale->text('Update') . qq|">
1092 <input class=submit type=submit name=action value="|
1093 . $locale->text('Ship to') . qq|">
1094 <input class=submit type=submit name=action value="|
1095 . $locale->text('Print') . qq|">
1096 <input class=submit type=submit name=action value="|
1097 . $locale->text('E-mail') . qq|">
1098 <input class=submit type=submit name=action value="|
1099 . $locale->text('Save') . qq|">
1100 <input class=submit type=submit name=action value="|
1101 . $locale->text('Save and Close') . qq|">
1104 if (($form->{id})) {
1106 <input type="button" class="submit" onclick="set_history_window(|
1108 . qq|);" name="history" id="history" value="|
1109 . $locale->text('history')
1112 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1113 <input class=submit type=submit name=action value="|
1114 . $locale->text('Save as new') . qq|">
1115 <input class=submit type=submit name=action value="|
1116 . $locale->text('Delete') . qq|">|;
1117 if (($form->{type} =~ /sales_quotation$/)) {
1119 <input class=submit type=submit name=action value="|
1120 . $locale->text('Sales Order') . qq|">|;
1122 if ($form->{type} =~ /request_quotation$/) {
1124 <input class=submit type=submit name=action value="|
1125 . $locale->text('Purchase Order') . qq|">|;
1129 <input class=submit type=submit name=action value="|
1130 . $locale->text('Invoice') . qq|">
1134 if ($form->{type} =~ /sales_order$/) {
1136 <br>$form->{heading} als neue Vorlage verwenden für<br>
1137 <input class=submit type=submit name=action value="|
1138 . $locale->text('Purchase Order') . qq|">
1139 <input class=submit type=submit name=action value="|
1140 . $locale->text('Quotation') . qq|">
1143 } elsif ($form->{type} =~ /purchase_order$/) {
1145 <br>$form->{heading} als neue Vorlage verwenden für<br>
1146 <input class=submit type=submit name=action value="|
1147 . $locale->text('Sales Order') . qq|">
1148 <input class=submit type=submit name=action value="|
1149 . $locale->text('Request for Quotation') . qq|">
1154 <br>$form->{heading} als neue Vorlage verwenden für<br>
1155 <input class=submit type=submit name=action value="|
1156 . $locale->text('Order') . qq|">
1159 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1161 <br>Workflow $form->{heading}<br>
1162 <input class=submit type=submit name=action value="|
1163 . $locale->text('Save as new') . qq|">
1164 <input class=submit type=submit name=action value="|
1165 . $locale->text('Invoice') . 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;
1323 $form->{"unit_$i"} = $locale->text('ea');
1331 $lxdebug->leave_sub();
1335 $lxdebug->enter_sub();
1337 if ($form->{type} eq 'purchase_order') {
1338 $form->{title} = $locale->text('Purchase Orders');
1339 $form->{vc} = 'vendor';
1340 $ordlabel = $locale->text('Order Number');
1341 $ordnumber = 'ordnumber';
1342 $employee = $locale->text('Employee');
1345 if ($form->{type} eq 'request_quotation') {
1346 $form->{title} = $locale->text('Request for Quotations');
1347 $form->{vc} = 'vendor';
1348 $ordlabel = $locale->text('RFQ Number');
1349 $ordnumber = 'quonumber';
1350 $employee = $locale->text('Employee');
1353 if ($form->{type} eq 'sales_order') {
1354 $form->{title} = $locale->text('Sales Orders');
1355 $form->{vc} = 'customer';
1356 $ordlabel = $locale->text('Order Number');
1357 $ordnumber = 'ordnumber';
1358 $employee = $locale->text('Employee');
1361 if ($form->{type} eq 'sales_quotation') {
1362 $form->{title} = $locale->text('Quotations');
1363 $form->{vc} = 'customer';
1364 $ordlabel = $locale->text('Quotation Number');
1365 $ordnumber = 'quonumber';
1366 $employee = $locale->text('Employee');
1369 # setup vendor / customer selection
1370 $form->all_vc(\%myconfig, $form->{vc},
1371 ($form->{vc} eq 'customer') ? "AR" : "AP");
1374 if (@{ $form->{all_departments} }) {
1375 $form->{selectdepartment} = "<option>\n";
1378 $form->{selectdepartment} .=
1379 "<option>$_->{description}--$_->{id}</option>\n"
1380 } (@{ $form->{all_departments} });
1385 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1386 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1388 | if $form->{selectdepartment};
1391 if (($form->{"type"} eq "sales_order") ||
1392 ($form->{"type"} eq "purchase_order")) {
1395 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1396 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1397 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1398 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1403 # use JavaScript Calendar or not
1404 $form->{jsscript} = 1;
1408 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1409 <input type=button name=transdatefrom id="trigger3" value=|
1410 . $locale->text('button') . qq|></td>
1413 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1414 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1415 . $locale->text('button') . qq|></td>
1420 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1421 "transdateto", "BL", "trigger4");
1423 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1425 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1427 $vc => "ALL_" . uc($vc));
1431 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1432 push(@values, $item->{"id"});
1433 $labels{$item->{"id"}} = $item->{"projectnumber"};
1436 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1437 '-labels' => \%labels));
1442 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1443 push(@values, $item->{name}.qq|--|.$item->{"id"});
1444 $labels{$item->{"id"}} = $item->{name}.qq|--|.$item->{"id"};
1447 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1449 $myconfig{vclimit} <= scalar(@values)
1450 ? qq|<input type="text" value="| . H($form->{"old$form->{vc}"}) . qq|" name="$form->{vc}">|
1451 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1452 '-default' => $form->{"old$form->{vc}"},
1453 '-onChange' => 'document.getElementById(\'update_button\').click();',
1454 '-values' => \@values,
1455 '-labels' => \%labels));
1462 <form method=post action=$form->{script}>
1466 <th class=listtop>$form->{title}</th>
1468 <tr height="5"></tr>
1473 <th align=right>$vc_label</th>
1474 <td colspan=3>$vc</td>
1478 <th align=right>$ordlabel</th>
1479 <td colspan=3><input name="$ordnumber" size=20></td>
1482 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1483 <td colspan="3"><input name="transaction_description" size=20></td>
1486 <th align="right">| . $locale->text("Project Number") . qq|</th>
1487 <td colspan="3">$projectnumber</td>
1490 <th align=right>| . $locale->text('From') . qq|</th>
1492 <th align=right>| . $locale->text('Bis') . qq|</th>
1495 <input type=hidden name=sort value=transdate>
1497 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1501 <td><input type="checkbox" name="open" value="1" id="open" checked>
1502 <label for="open">| . $locale->text("Open") . qq|</td>
1503 <td><input type="checkbox" name="closed" value="1" id="closed">
1504 <label for="closed">| . $locale->text("Closed") . qq|</td>
1508 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1509 | . $locale->text('ID') . qq|</td>
1510 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1511 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1512 . $locale->text('Date') . qq|</td>
1513 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1514 . $locale->text('Required by') . qq|</td>
1517 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> ucfirst($form->{vc})</td>
1518 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1519 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1520 . $locale->text('Ship via') . qq|</td>
1521 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1524 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1525 . $locale->text('Amount') . qq|</td>
1526 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1527 . $locale->text('Tax') . qq|</td>
1528 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1529 . $locale->text('Total') . qq|</td>
1532 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1533 . $locale->text('Project Number') . qq|</td>
1534 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1535 . $locale->text('Transaction description') . qq|</td>
1538 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1539 . $locale->text('Subtotal') . qq|</td>
1547 <tr><td colspan=4><hr size=3 noshade></td></tr>
1553 <input type=hidden name=nextsub value=orders>
1554 <input type=hidden name=login value=$form->{login}>
1555 <input type=hidden name=password value=$form->{password}>
1556 <input type=hidden name=vc value=$form->{vc}>
1557 <input type=hidden name=type value=$form->{type}>
1559 <input class=submit type=submit name=action value="|
1560 . $locale->text('Continue') . qq|">
1567 $lxdebug->leave_sub();
1571 $lxdebug->enter_sub();
1573 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1577 qw(type vc login password transdatefrom transdateto
1578 open closed notdelivered delivered department
1579 transaction_description);
1580 push @fields, $form->{vc};
1581 $href = "$form->{script}?action=orders&"
1582 . join("&", map { "${_}=" . E($form->{$_}) } @fields)
1583 . "&${ordnumber}=" . E($form->{$ordnumber});
1586 # split vendor / customer
1587 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1588 split(/--/, $form->{ $form->{vc} });
1590 OE->transactions(\%myconfig, \%$form);
1593 "transdate", "reqdate",
1595 "name", "netamount",
1598 "shipvia", "globalprojectnumber",
1599 "transaction_description", "open",
1600 "closed", "delivered"
1603 $form->{l_open} = $form->{l_closed} = "Y"
1604 if ($form->{open} && $form->{closed});
1606 $form->{"l_delivered"} = "Y"
1607 if ($form->{"delivered"} && $form->{"notdelivered"});
1609 foreach $item (@columns) {
1610 if ($form->{"l_$item"} eq "Y") {
1611 push @column_index, $item;
1613 # add column to href and callback
1614 $callback .= "&l_$item=Y";
1615 $href .= "&l_$item=Y";
1619 # only show checkboxes if gotten here via sales_order form.
1620 if ($form->{type} =~ /sales_order/) {
1621 unshift @column_index, "ids";
1624 if ($form->{l_subtotal} eq 'Y') {
1625 $callback .= "&l_subtotal=Y";
1626 $href .= "&l_subtotal=Y";
1629 if ($form->{vc} eq 'vendor') {
1630 if ($form->{type} eq 'purchase_order') {
1631 $form->{title} = $locale->text('Purchase Orders');
1633 $form->{title} = $locale->text('Request for Quotations');
1635 $name = $locale->text('Vendor');
1636 $employee = $locale->text('Employee');
1638 if ($form->{vc} eq 'customer') {
1639 if ($form->{type} eq 'sales_order') {
1640 $form->{title} = $locale->text('Sales Orders');
1642 $form->{title} = $locale->text('Quotations');
1644 $employee = $locale->text('Employee');
1645 $name = $locale->text('Customer');
1648 $column_header{id} =
1649 qq|<th><a class=listheading href=$href&sort=id>|
1650 . $locale->text('ID')
1652 $column_header{transdate} =
1653 qq|<th><a class=listheading href=$href&sort=transdate>|
1654 . $locale->text('Date')
1656 $column_header{reqdate} =
1657 qq|<th><a class=listheading href=$href&sort=reqdate>|
1658 . $locale->text('Required by')
1660 $column_header{ordnumber} =
1661 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1662 . $locale->text('Order')
1664 $column_header{quonumber} =
1665 qq|<th><a class=listheading href=$href&sort=quonumber>|
1666 . ($form->{"type"} eq "request_quotation" ?
1667 $locale->text('RFQ') :
1668 $locale->text('Quotation'))
1670 $column_header{name} =
1671 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1672 $column_header{netamount} =
1673 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1674 $column_header{tax} =
1675 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1676 $column_header{amount} =
1677 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1678 $column_header{curr} =
1679 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1680 $column_header{shipvia} =
1681 qq|<th><a class=listheading href=$href&sort=shipvia>|
1682 . $locale->text('Ship via')
1684 $column_header{globalprojectnumber} =
1685 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1686 $column_header{open} =
1687 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1688 $column_header{closed} =
1689 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1690 $column_header{"delivered"} =
1691 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1693 $column_header{employee} =
1694 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1695 $column_header{transaction_description} =
1696 qq|<th><a class=listheading href="$href&sort=transaction_description">|
1697 . $locale->text("Transaction description") . qq|</a></th>|;
1699 $column_header{ids} = qq|<th></th>|;
1701 if ($form->{ $form->{vc} }) {
1702 $option = $locale->text(ucfirst $form->{vc});
1703 $option .= " : $form->{$form->{vc}}";
1705 if ($form->{department}) {
1706 $option .= "\n<br>" if ($option);
1707 ($department) = split /--/, $form->{department};
1708 $option .= $locale->text('Department') . " : $department";
1710 if ($form->{transdatefrom}) {
1712 . $locale->text('From') . " "
1713 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1715 if ($form->{transdateto}) {
1717 . $locale->text('Bis') . " "
1718 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1720 if ($form->{open}) {
1721 $option .= "\n<br>" if ($option);
1722 $option .= $locale->text('Open');
1724 if ($form->{closed}) {
1725 $option .= "\n<br>" if ($option);
1726 $option .= $locale->text('Closed');
1734 <form method="post" action="oe.pl">
1737 <th class=listtop>$form->{title}</th>
1739 <tr height="5"></tr>
1746 <tr class=listheading>|;
1748 map { print "\n$column_header{$_}" } @column_index;
1754 # add sort and escape callback
1755 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1757 if (@{ $form->{OE} }) {
1758 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1763 foreach $oe (@{ $form->{OE} }) {
1764 $form->{rowcount} = ++$j;
1766 if ($form->{l_subtotal} eq 'Y') {
1767 if ($sameitem ne $oe->{ $form->{sort} }) {
1769 $sameitem = $oe->{ $form->{sort} };
1773 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1775 $column_data{netamount} =
1777 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1779 $column_data{tax} = "<td align=right>"
1780 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1783 $column_data{amount} =
1785 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1787 $totalnetamount += $oe->{netamount};
1788 $totalamount += $oe->{amount};
1790 $subtotalnetamount += $oe->{netamount};
1791 $subtotalamount += $oe->{amount};
1794 qq|<td><input name="multi_id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1795 $column_data{id} = "<td>$oe->{id}</td>";
1796 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1797 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1799 $column_data{$ordnumber} =
1800 "<td><a href=oe.pl?action=$action&type=$form->{type}&id=$oe->{id}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback_escaped>$oe->{$ordnumber}</a></td>";
1801 $column_data{name} = "<td>$oe->{name}</td>";
1803 $column_data{employee} = "<td>$oe->{employee} </td>";
1804 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1805 $column_data{globalprojectnumber} = "<td>" . H($oe->{globalprojectnumber}) . "</td>";
1807 if ($oe->{closed}) {
1808 $column_data{closed} = "<td align=center>X</td>";
1809 $column_data{open} = "<td> </td>";
1811 $column_data{closed} = "<td> </td>";
1812 $column_data{open} = "<td align=center>X</td>";
1814 $column_data{"delivered"} = "<td>" .
1815 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1817 $column_data{transaction_description} = "<td>" . H($oe->{transaction_description}) . "</td>";
1822 <tr class=listrow$i>";
1824 map { print "\n$column_data{$_}" } @column_index;
1832 if ($form->{l_subtotal} eq 'Y') {
1838 <tr class=listtotal>|;
1840 map { $column_data{$_} = "<td> </td>" } @column_index;
1842 $column_data{netamount} =
1843 "<th class=listtotal align=right>"
1844 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1845 $column_data{tax} = "<th class=listtotal align=right>"
1846 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1849 $column_data{amount} =
1850 "<th class=listtotal align=right>"
1851 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1853 map { print "\n$column_data{$_}" } @column_index;
1861 <td><hr size=3 noshade></td>
1865 # multiple invoice edit button only if gotten there via sales_order form.
1867 if ($form->{type} =~ /sales_order/) {
1869 <input class"submit" type="submit" name="action" value="|
1870 . $locale->text('Continue') . qq|">
1871 <input type="hidden" name="nextsub" value="edit">
1872 <input type="hidden" name="type" value="$form->{type}">
1873 <input type="hidden" name="vc" value="$form->{vc}">
1874 <input type="hidden" name="login" value="$form->{login}">
1875 <input type="hidden" name="password" value="$form->{password}">
1876 <input type="hidden" name="callback" value="$callback">
1877 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1884 <form method=post action=$form->{script}>
1886 <input name=callback type=hidden value="$form->{callback}">
1888 <input type=hidden name=type value=$form->{type}>
1889 <input type=hidden name=vc value=$form->{vc}>
1891 <input type=hidden name=login value=$form->{login}>
1892 <input type=hidden name=password value=$form->{password}>
1900 $lxdebug->leave_sub();
1904 $lxdebug->enter_sub();
1906 map { $column_data{$_} = "<td> </td>" } @column_index;
1908 $column_data{netamount} =
1909 "<th class=listsubtotal align=right>"
1910 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1912 $column_data{tax} = "<td class=listsubtotal align=right>"
1913 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1916 $column_data{amount} =
1917 "<th class=listsubtotal align=right>"
1918 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1920 $subtotalnetamount = 0;
1921 $subtotalamount = 0;
1924 <tr class=listsubtotal>
1927 map { print "\n$column_data{$_}" } @column_index;
1933 $lxdebug->leave_sub();
1936 sub save_and_close {
1937 $lxdebug->enter_sub();
1939 if ($form->{type} =~ /_order$/) {
1940 $form->isblank("transdate", $locale->text('Order Date missing!'));
1942 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1945 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1946 $form->{$idx} =~ s/^\s*//g;
1947 $form->{$idx} =~ s/\s*$//g;
1949 $msg = ucfirst $form->{vc};
1950 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1952 # $locale->text('Customer missing!');
1953 # $locale->text('Vendor missing!');
1955 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1956 if ($form->{currency} ne $form->{defaultcurrency});
1960 if($form->{payment_id}) {
1961 $payment_id = $form->{payment_id};
1964 # if the name changed get new values
1965 if (&check_name($form->{vc})) {
1966 if($form->{payment_id} eq "") {
1967 $form->{payment_id} = $payment_id;
1973 $form->{id} = 0 if $form->{saveasnew};
1975 # this is for the internal notes section for the [email] Subject
1976 if ($form->{type} =~ /_order$/) {
1977 if ($form->{type} eq 'sales_order') {
1978 $form->{label} = $locale->text('Sales Order');
1980 $numberfld = "sonumber";
1981 $ordnumber = "ordnumber";
1983 $form->{label} = $locale->text('Purchase Order');
1985 $numberfld = "ponumber";
1986 $ordnumber = "ordnumber";
1989 $err = $locale->text('Cannot save order!');
1992 if ($form->{type} eq 'sales_quotation') {
1993 $form->{label} = $locale->text('Quotation');
1995 $numberfld = "sqnumber";
1996 $ordnumber = "quonumber";
1998 $form->{label} = $locale->text('Request for Quotation');
2000 $numberfld = "rfqnumber";
2001 $ordnumber = "quonumber";
2004 $err = $locale->text('Cannot save quotation!');
2008 # get new number in sequence if no number is given or if saveasnew was requested
2009 if (!$form->{$ordnumber} || $form->{saveasnew}) {
2010 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
2015 $form->error($err) if (!OE->save(\%myconfig, \%$form));
2017 # saving the history
2018 if(!exists $form->{addition}) {
2019 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2020 $form->{addition} = "SAVED";
2021 $form->save_history($form->dbconnect(\%myconfig));
2023 # /saving the history
2025 $form->redirect($form->{label} . " $form->{$ordnumber} " .
2026 $locale->text('saved!'));
2028 $lxdebug->leave_sub();
2032 $lxdebug->enter_sub();
2034 if ($form->{type} =~ /_order$/) {
2035 $form->isblank("transdate", $locale->text('Order Date missing!'));
2037 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2040 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2041 $form->{$idx} =~ s/^\s*//g;
2042 $form->{$idx} =~ s/\s*$//g;
2044 $msg = ucfirst $form->{vc};
2045 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
2047 # $locale->text('Customer missing!');
2048 # $locale->text('Vendor missing!');
2050 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
2051 if ($form->{currency} ne $form->{defaultcurrency});
2055 if($form->{payment_id}) {
2056 $payment_id = $form->{payment_id};
2059 # if the name changed get new values
2060 if (&check_name($form->{vc})) {
2061 if($form->{payment_id} eq "") {
2062 $form->{payment_id} = $payment_id;
2068 $form->{id} = 0 if $form->{saveasnew};
2070 # this is for the internal notes section for the [email] Subject
2071 if ($form->{type} =~ /_order$/) {
2072 if ($form->{type} eq 'sales_order') {
2073 $form->{label} = $locale->text('Sales Order');
2075 $numberfld = "sonumber";
2076 $ordnumber = "ordnumber";
2078 $form->{label} = $locale->text('Purchase Order');
2080 $numberfld = "ponumber";
2081 $ordnumber = "ordnumber";
2084 $err = $locale->text('Cannot save order!');
2087 if ($form->{type} eq 'sales_quotation') {
2088 $form->{label} = $locale->text('Quotation');
2090 $numberfld = "sqnumber";
2091 $ordnumber = "quonumber";
2093 $form->{label} = $locale->text('Request for Quotation');
2095 $numberfld = "rfqnumber";
2096 $ordnumber = "quonumber";
2099 $err = $locale->text('Cannot save quotation!');
2103 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
2104 unless $form->{$ordnumber};
2108 OE->save(\%myconfig, \%$form);
2110 # saving the history
2111 if(!exists $form->{addition}) {
2112 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2113 $form->{addition} = "SAVED";
2114 $form->save_history($form->dbconnect(\%myconfig));
2116 # /saving the history
2118 $form->{simple_save} = 1;
2119 if(!$form->{print_and_save}) {
2120 set_headings("edit");
2124 $lxdebug->leave_sub();
2128 $lxdebug->enter_sub();
2132 if ($form->{type} =~ /_order$/) {
2133 $msg = $locale->text('Are you sure you want to delete Order Number');
2134 $ordnumber = 'ordnumber';
2136 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2137 $ordnumber = 'quonumber';
2143 <form method=post action=$form->{script}>
2146 # delete action variable
2147 map { delete $form->{$_} } qw(action header);
2149 foreach $key (keys %$form) {
2150 $form->{$key} =~ s/\"/"/g;
2151 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2155 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2157 <h4>$msg $form->{$ordnumber}</h4>
2159 <input name=action class=submit type=submit value="|
2160 . $locale->text('Yes') . qq|">
2167 $lxdebug->leave_sub();
2171 $lxdebug->enter_sub();
2173 if ($form->{type} =~ /_order$/) {
2174 $msg = $locale->text('Order deleted!');
2175 $err = $locale->text('Cannot delete order!');
2177 $msg = $locale->text('Quotation deleted!');
2178 $err = $locale->text('Cannot delete quotation!');
2180 if (OE->delete(\%myconfig, \%$form, $spool)){
2181 $form->redirect($msg);
2182 # saving the history
2183 if(!exists $form->{addition}) {
2184 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2185 $form->{addition} = "DELETED";
2186 $form->save_history($form->dbconnect(\%myconfig));
2188 # /saving the history
2192 $lxdebug->leave_sub();
2196 $lxdebug->enter_sub();
2198 if ($form->{type} =~ /_order$/) {
2200 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2201 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2202 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2203 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2204 $form->isblank("transdate", $locale->text('Order Date missing!'))
2205 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2207 # also copy deliverydate from the order
2208 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2209 $form->{orddate} = $form->{transdate};
2211 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2212 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2213 $form->{ordnumber} = "";
2214 $form->{quodate} = $form->{transdate};
2217 if($form->{payment_id}) {
2218 $payment_id = $form->{payment_id};
2221 # if the name changed get new values
2222 if (&check_name($form->{vc})) {
2223 if($form->{payment_id} eq "") {
2224 $form->{payment_id} = $payment_id;
2230 $form->{cp_id} *= 1;
2232 for $i (1 .. $form->{rowcount}) {
2233 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2234 $form->{"${_}_${i}"})
2235 if ($form->{"${_}_${i}"}) }
2236 qw(ship qty sellprice listprice basefactor));
2239 if ( $form->{type} =~ /_order/
2240 && $form->{currency} ne $form->{defaultcurrency}) {
2242 # check if we need a new exchangerate
2243 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2245 $orddate = $form->current_date(\%myconfig);
2247 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2250 if (!$exchangerate) {
2251 &backorder_exchangerate($orddate, $buysell);
2256 # close orders/quotations
2257 $form->{closed} = 1;
2259 # save order if one ordnumber has been given
2260 # if not it's most likely a collective order, which can't be saved back
2261 # so they just have to be closed
2262 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2263 OE->close_order(\%myconfig, \%$form);
2265 OE->close_orders(\%myconfig, \%$form);
2268 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2270 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2273 $form->{closed} = 0;
2274 $form->{rowcount}--;
2275 $form->{shipto} = 1;
2277 if ($form->{type} =~ /_order$/) {
2278 $form->{exchangerate} = $exchangerate;
2282 if ( $form->{type} eq 'purchase_order'
2283 || $form->{type} eq 'request_quotation') {
2284 $form->{title} = $locale->text('Add Vendor Invoice');
2285 $form->{script} = 'ir.pl';
2289 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2290 $form->{title} = $locale->text('Add Sales Invoice');
2291 $form->{script} = 'is.pl';
2296 # bo creates the id, reset it
2297 map { delete $form->{$_} }
2298 qw(id subject message cc bcc printed emailed queued);
2299 $form->{ $form->{vc} } =~ s/--.*//g;
2300 $form->{type} = "invoice";
2303 $locale = new Locale "$myconfig{countrycode}", "$script";
2305 require "bin/mozilla/$form->{script}";
2307 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2309 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2310 qw(creditlimit creditremaining);
2312 $currency = $form->{currency};
2315 $form->{currency} = $currency;
2316 $form->{exchangerate} = "";
2317 $form->{forex} = "";
2318 $form->{exchangerate} = $exchangerate
2322 $form->check_exchangerate(
2323 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2326 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2331 for $i (1 .. $form->{rowcount}) {
2332 $form->{"discount_$i"} =
2333 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2335 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2337 $decimalplaces = ($dec > 2) ? $dec : 2;
2339 # copy delivery date from reqdate for order -> invoice conversion
2340 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2341 unless $form->{"deliverydate_$i"};
2343 $form->{"sellprice_$i"} =
2344 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2347 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2348 $dec_qty = length $dec_qty;
2350 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2352 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2353 qw(partnumber description unit);
2359 $lxdebug->leave_sub();
2362 sub backorder_exchangerate {
2363 $lxdebug->enter_sub();
2364 my ($orddate, $buysell) = @_;
2371 <form method=post action=$form->{script}>
2374 # delete action variable
2375 map { delete $form->{$_} } qw(action header exchangerate);
2377 foreach $key (keys %$form) {
2378 $form->{$key} =~ s/\"/"/g;
2379 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2382 $form->{title} = $locale->text('Add Exchangerate');
2386 <input type=hidden name=login value=$form->{login}>
2387 <input type=hidden name=password value=$form->{password}>
2389 <input type=hidden name=exchangeratedate value=$orddate>
2390 <input type=hidden name=buysell value=$buysell>
2393 <tr><th class=listtop>$form->{title}</th></tr>
2394 <tr height="5"></tr>
2399 <th align=right>| . $locale->text('Currency') . qq|</th>
2400 <td>$form->{currency}</td>
2403 <th align=right>| . $locale->text('Date') . qq|</th>
2407 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2408 <td><input name=exchangerate size=11></td>
2418 <input type=hidden name=nextsub value=save_exchangerate>
2420 <input name=action class=submit type=submit value="|
2421 . $locale->text('Continue') . qq|">
2429 $lxdebug->leave_sub();
2432 sub save_exchangerate {
2433 $lxdebug->enter_sub();
2435 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2436 $form->{exchangerate} =
2437 $form->parse_amount(\%myconfig, $form->{exchangerate});
2438 $form->save_exchangerate(\%myconfig, $form->{currency},
2439 $form->{exchangeratedate},
2440 $form->{exchangerate}, $form->{buysell});
2444 $lxdebug->leave_sub();
2447 sub create_backorder {
2448 $lxdebug->enter_sub();
2450 $form->{shipped} = 1;
2452 # figure out if we need to create a backorder
2453 # items aren't saved if qty != 0
2455 for $i (1 .. $form->{rowcount}) {
2456 $totalqty += $qty = $form->{"qty_$i"};
2457 $totalship += $ship = $form->{"ship_$i"};
2459 $form->{"qty_$i"} = $qty - $ship;
2462 if ($totalship == 0) {
2463 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2464 $form->{ordtotal} = 0;
2465 $form->{shipped} = 0;
2469 if ($totalqty == $totalship) {
2470 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2471 $form->{ordtotal} = 0;
2476 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2479 for $i (1 .. $form->{rowcount}) {
2481 $form->{"${_}_$i"} =
2482 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2483 } qw(sellprice discount);
2488 OE->save(\%myconfig, \%$form);
2490 # rebuild rows for invoice
2494 for $i (1 .. $form->{rowcount}) {
2495 $form->{"qty_$i"} = $form->{"ship_$i"};
2497 if ($form->{"qty_$i"}) {
2500 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2505 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2506 $form->{rowcount} = $count;
2508 $lxdebug->leave_sub();
2512 $lxdebug->enter_sub();
2514 $form->{saveasnew} = 1;
2515 $form->{closed} = 0;
2516 map { delete $form->{$_} } qw(printed emailed queued);
2518 # Let Lx-Office assign a new order number if the user hasn't changed the
2519 # previous one. If it has been changed manually then use it as-is.
2520 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2521 $form->{$idx} =~ s/^\s*//g;
2522 $form->{$idx} =~ s/\s*$//g;
2523 if ($form->{saved_xyznumber} &&
2524 ($form->{saved_xyznumber} eq $form->{$idx})) {
2525 delete($form->{$idx});
2530 $lxdebug->leave_sub();
2533 sub purchase_order {
2534 $lxdebug->enter_sub();
2536 if ( $form->{type} eq 'sales_quotation'
2537 || $form->{type} eq 'request_quotation') {
2538 OE->close_order(\%myconfig, \%$form);
2541 if ($form->{type} =~ /^sales_/) {
2542 delete($form->{ordnumber});
2545 $form->{cp_id} *= 1;
2547 $form->{title} = $locale->text('Add Purchase Order');
2548 $form->{vc} = "vendor";
2549 $form->{type} = "purchase_order";
2553 $lxdebug->leave_sub();
2557 $lxdebug->enter_sub();
2559 if ( $form->{type} eq 'sales_quotation'
2560 || $form->{type} eq 'request_quotation') {
2561 OE->close_order(\%myconfig, $form);
2564 if ($form->{type} eq "purchase_order") {
2565 delete($form->{ordnumber});
2568 $form->{cp_id} *= 1;
2570 $form->{title} = $locale->text('Add Sales Order');
2571 $form->{vc} = "customer";
2572 $form->{type} = "sales_order";
2576 $lxdebug->leave_sub();
2580 $lxdebug->enter_sub();
2582 $form->{transdate} = $form->current_date(\%myconfig);
2583 delete $form->{duedate};
2585 $form->{closed} = 0;
2588 map { delete $form->{$_} }
2589 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2591 for $i (1 .. $form->{rowcount}) {
2592 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2593 $form->{"${_}_${i}"})
2594 if ($form->{"${_}_${i}"}) }
2595 qw(ship qty sellprice listprice basefactor));
2603 for $i (1 .. $form->{rowcount} - 1) {
2604 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2605 qw(partnumber description unit);
2608 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2609 qw(creditlimit creditremaining);
2613 $lxdebug->leave_sub();
2617 $lxdebug->enter_sub();
2619 $form->{print_and_save} = 1;
2624 my $saved_form = save_form();
2629 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2630 restore_form($saved_form);
2631 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2636 $lxdebug->leave_sub();