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;
167 $form->{jscalendar} = $jscalendar;
169 my $editing = $form->{id};
171 OE->retrieve(\%myconfig, \%$form);
173 if ($form->{payment_id}) {
174 $payment_id = $form->{payment_id};
176 if ($form->{language_id}) {
177 $language_id = $form->{language_id};
179 if ($form->{taxzone_id}) {
180 $taxzone_id = $form->{taxzone_id};
183 $salesman_id = $form->{salesman_id} if ($editing);
186 # if multiple rowcounts (== collective order) then check if the
187 # there were more than one customer (in that case OE::retrieve removes
188 # the content from the field)
189 if ( $form->{rowcount}
190 && $form->{type} eq 'sales_order'
191 && defined $form->{customer}
192 && $form->{customer} eq '') {
194 # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
197 'Collective Orders only work for orders from one customer!')
201 $taxincluded = $form->{taxincluded};
202 $form->{shipto} = 1 if $form->{id};
204 if ($form->{"all_$form->{vc}"}) {
205 unless ($form->{"$form->{vc}_id"}) {
206 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
210 $cp_id = $form->{cp_id};
211 $intnotes = $form->{intnotes};
213 # get customer / vendor
214 if ($form->{type} =~ /(purchase_order|request_quotation)/) {
215 IR->get_vendor(\%myconfig, \%$form);
217 #quote all_vendor Bug 133
218 foreach $ref (@{ $form->{all_vendor} }) {
219 $ref->{name} = $form->quote($ref->{name});
223 if ($form->{type} =~ /sales_(order|quotation)/) {
224 IS->get_customer(\%myconfig, \%$form);
226 #quote all_vendor Bug 133
227 foreach $ref (@{ $form->{all_customer} }) {
228 $ref->{name} = $form->quote($ref->{name});
232 $form->{cp_id} = $cp_id;
235 $form->{payment_id} = $payment_id;
238 $form->{language_id} = $language_id;
241 $form->{taxzone_id} = $taxzone_id;
243 $form->{intnotes} = $intnotes if $intnotes;
244 ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
245 $form->{"old$form->{vc}"} =
246 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
248 # build the popup menus
249 if (@{ $form->{"all_$form->{vc}"} }) {
250 $form->{ $form->{vc} } =
251 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
252 map { $form->{"select$form->{vc}"} .=
253 "<option>$_->{name}--$_->{id}</option>\n" }
254 (@{ $form->{"all_$form->{vc}"} });
257 $form->{taxincluded} = $taxincluded if ($form->{id});
260 if (@{ $form->{all_departments} }) {
261 $form->{selectdepartment} = "<option>\n";
262 $form->{department} = "$form->{department}--$form->{department_id}";
265 $form->{selectdepartment} .=
266 "<option>$_->{description}--$_->{id}</option>\n"
267 } (@{ $form->{all_departments} });
270 $form->{employee} = "$form->{employee}--$form->{employee_id}";
273 $form->{forex} = $form->{exchangerate};
275 $form->{salesman_id} = $salesman_id if ($editing);
277 $lxdebug->leave_sub();
281 $lxdebug->enter_sub();
282 $form->{formname} = $form->{type} unless $form->{formname};
285 foreach $ref (@{ $form->{form_details} }) {
286 $form->{rowcount} = ++$i;
288 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
290 for my $i (1 .. $form->{rowcount}) {
292 $form->{"discount_$i"} =
293 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
295 $form->{"discount_$i"} =
296 $form->format_amount(\%myconfig, $form->{"discount_$i"});
298 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
300 $decimalplaces = ($dec > 2) ? $dec : 2;
302 # copy reqdate from deliverydate for invoice -> order conversion
303 $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
304 unless $form->{"reqdate_$i"};
306 $form->{"sellprice_$i"} =
307 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
310 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
311 $dec_qty = length $dec_qty;
313 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
315 map { $form->{"${_}_$i"} =~ s/\"/"/g }
316 qw(partnumber description unit);
319 $lxdebug->leave_sub();
323 $lxdebug->enter_sub();
325 my $checkedclosed = $form->{"closed"} ? "checked" : "";
326 my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
328 map { $form->{$_} =~ s/\"/"/g }
329 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
330 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
331 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
333 # use JavaScript Calendar or not
334 $form->{jsscript} = $form->{jscalendar};
337 if ($form->{jsscript}) {
339 # with JavaScript Calendar
341 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>
342 <td><input type=button name=transdate id="trigger1" value=|
343 . $locale->text('button') . qq|></td>
346 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\"></td>
347 <td width="4"><input type=button name=reqdate name=reqdate id="trigger2" value=|
348 . $locale->text('button') . qq|></td>
353 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
354 "reqdate", "BL", "trigger2");
358 # without JavaScript Calendar
360 <td><input name="transdate" id="transdate" size="11" title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\"></td>|;
362 <td width="13"><input name="reqdate" id="reqdate" size="11" title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\"></td>|;
367 if (($form->{"type"} eq "sales_order") ||
368 ($form->{"type"} eq "purchase_order")) {
370 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
371 <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
376 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
377 <label for="closed">| . $locale->text('Closed') . qq|</label>|);
383 <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
389 # set option selected
390 foreach $item ($form->{vc}, currency, department, employee, ($form->{vc} eq "customer" ? customer : vendor)) {
391 $form->{"select$item"} =~ s/ selected//;
392 $form->{"select$item"} =~
393 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
396 #quote select[customer|vendor] Bug 133
397 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
399 #substitute \n and \r to \s (bug 543)
400 $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
402 my @old_project_ids = ($form->{"globalproject_id"});
403 map({ push(@old_project_ids, $form->{"project_id_$_"})
404 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
406 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
407 $form->get_lists("contacts" => "ALL_CONTACTS",
408 "shipto" => "ALL_SHIPTO",
409 "projects" => { "key" => "ALL_PROJECTS",
411 "old_id" => \@old_project_ids },
412 "employees" => "ALL_SALESMEN",
413 "taxzones" => "ALL_TAXZONES",
414 "payments" => "ALL_PAYMENTS",
415 "currencies" => "ALL_CURRENCIES",
416 $vc => "ALL_" . uc($vc));
419 my @values = (undef);
420 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
421 push(@values, $item->{"cp_id"});
422 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
423 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
426 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
427 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
432 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
433 push(@values, $item->{name}.qq|--|.$item->{"id"});
434 $labels{$item->{"id"}} = $item->{name}.qq|--|.$item->{"id"};
438 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
439 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
440 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
442 (($myconfig{vclimit} <= scalar(@values))
443 ? qq|<input type="text" value="| . H($form->{"old$form->{vc}"}) . qq|" name="$form->{vc}">|
444 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
445 '-onChange' => 'document.getElementById(\'update_button\').click();',
446 '-values' => \@values, '-labels' => \%labels)))) . qq|
447 </td><input type=hidden name="select$form->{vc}" value="| .
448 Q($form->{"select$form->{vc}"}) . qq|">|;
452 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
453 push(@values, $item->{"id"});
454 $labels{$item->{"id"}} = $item->{"description"};
458 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
460 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values,
461 '-labels' => \%labels, '-default' => $form->{payment_id}))
466 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
467 push(@values, $item->{"shipto_id"});
468 $labels{$item->{"shipto_id"}} =
469 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
473 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
475 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
476 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
481 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
482 push(@values, $item->{"id"});
483 $labels{$item->{"id"}} = $item->{"projectnumber"};
485 my $globalprojectnumber =
486 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
487 '-labels' => \%labels,
488 '-default' => $form->{"globalproject_id"}));
491 if ($form->{type} =~ /^sales_/) {
494 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
495 push(@values, $item->{id});
496 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
501 <th align="right">| . $locale->text('Salesman') . qq|</th>
503 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{salesman_id},
504 '-values' => \@values, '-labels' => \%labels))
511 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
512 push(@values, $item->{"id"});
513 $labels{$item->{"id"}} = $item->{"name"};
518 <th align="right">| . $locale->text('Employee') . qq|</th>
520 NTI($cgi->popup_menu('-name' => 'employee', '-default' => $form->{"employee"},
521 '-values' => \@values, '-labels' => \%labels)) . qq|
527 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
528 push(@values, $item->{"id"});
529 $labels{$item->{"id"}} = $item->{"description"};
534 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
536 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
537 '-values' => \@values, '-labels' => \%labels)) . qq|
544 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
545 push(@values, $item);
546 $labels{$item} = $item;
549 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
552 <th align="right">| . $locale->text('Currency') . qq|</th>
554 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
555 '-values' => \@values, '-labels' => \%labels)) . qq|
560 $form->{exchangerate} =
561 $form->format_amount(\%myconfig, $form->{exchangerate});
563 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
569 $form->{creditlimit} =
570 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
571 $form->{creditremaining} =
572 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
575 <input type=hidden name=forex value=$form->{forex}>
578 if ($form->{currency} ne $form->{defaultcurrency}) {
579 if ($form->{forex}) {
582 . $locale->text('Exchangerate')
583 . qq|</th><td>$form->{exchangerate}</td>
584 <input type=hidden name=exchangerate value=$form->{exchangerate}>
589 . $locale->text('Exchangerate')
590 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
594 if ($form->{business}) {
597 <th align=right>| . $locale->text('Business') . qq|</th>
598 <td>$form->{business}</td>
599 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
601 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
607 if ($form->{max_dunning_level}) {
613 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
614 <td><b>$form->{max_dunning_level}</b></td>
615 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
617 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
626 if ($form->{type} !~ /_quotation$/) {
629 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
630 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
633 <th width=70% align=right nowrap>|
634 . $locale->text('Quotation Number') . qq|</th>
635 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
638 <th width=70% align=right nowrap>|
639 . $locale->text('Customer Order Number') . qq|</th>
640 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
643 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
648 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
653 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
655 $creditremaining = qq|
661 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
662 <td>$form->{creditlimit}</td>
664 <th nowrap>| . $locale->text('Remaining') . qq|</th>
665 <td class="plus$n" nowrap>$form->{creditremaining}</td>
674 ($form->{type} eq 'sales_quotation')
675 ? $locale->text('Valid until')
676 : $locale->text('Required by');
677 if ($form->{type} eq 'sales_quotation') {
680 <th width=70% align=right nowrap>|
681 . $locale->text('Quotation Number') . qq|</th>
682 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
683 <input type=hidden name=ordnumber value="$form->{ordnumber}">
689 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
690 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
691 <input type=hidden name=ordnumber value="$form->{ordnumber}">
699 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
703 <th align=right nowrap=true>$reqlabel</th>
707 $creditremaining = qq| <tr>
715 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
716 <td colspan=3><select name=department>$form->{selectdepartment}</select>
717 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
719 </tr> | if $form->{selectdepartment};
721 if ($form->{type} eq 'sales_order') {
722 if ($form->{selectemployee}) {
724 <input type=hidden name=customer_klass value=$form->{customer_klass}>
730 <input type=hidden name=customer_klass value=$form->{customer_klass}>
734 if ($form->{resubmit} && ($form->{format} eq "html")) {
736 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
737 } elsif ($form->{resubmit}) {
738 $onload = qq|document.oe.submit()|;
743 $credittext = $locale->text('Credit Limit exceeded!!!');
744 if ($creditwarning) {
745 $onload = qq|alert('$credittext')|;
748 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
749 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
751 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
752 # show history button js
753 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
754 #/show history button js
758 <body onLoad="$onload">
760 <form method=post name=oe action=$form->{script}>
761 <script type="text/javascript" src="js/common.js"></script>
762 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
763 <script type="text/javascript" src="js/vendor_selection.js"></script>
764 <script type="text/javascript" src="js/calculate_qty.js"></script>
766 <input type=hidden name=id value=$form->{id}>
767 <input type=hidden name=action value=$form->{action}>
769 <input type=hidden name=type value=$form->{type}>
770 <input type=hidden name=formname value=$form->{formname}>
771 <input type=hidden name=media value=$form->{media}>
772 <input type=hidden name=format value=$form->{format}>
773 <input type=hidden name=proforma value=$form->{proforma}>
775 <input type=hidden name=queued value="$form->{queued}">
776 <input type=hidden name=printed value="$form->{printed}">
777 <input type=hidden name=emailed value="$form->{emailed}">
779 <input type=hidden name=vc value=$form->{vc}>
781 <input type=hidden name=title value="$form->{title}">
783 <input type=hidden name=discount value=$form->{discount}>
784 <input type=hidden name=creditlimit value=$form->{creditlimit}>
785 <input type=hidden name=creditremaining value=$form->{creditremaining}>
787 <input type=hidden name=tradediscount value=$form->{tradediscount}>
788 <input type=hidden name=business value=$form->{business}>
789 <input type=hidden name=webdav value=$webdav>
793 <th class=listtop>$form->{title}</th>
804 <th align=richt nowrap>|
805 . $locale->text('Contact Person') . qq|</th>
806 <td colspan=3>$contact</td>
818 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
819 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
822 <th align=right>| . $locale->text('Ship via') . qq|</th>
823 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
826 <th align="right">| . $locale->text('Transaction description') . qq|</th>
827 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
834 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
836 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
837 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
841 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
843 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
844 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
858 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
859 <td>$globalprojectnumber</td>
870 <!-- shipto are in hidden variables -->
872 <input type=hidden name=shiptoname value="$form->{shiptoname}">
873 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
874 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
875 <input type=hidden name=shiptocity value="$form->{shiptocity}">
876 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
877 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
878 <input type=hidden name=shiptophone value="$form->{shiptophone}">
879 <input type=hidden name=shiptofax value="$form->{shiptofax}">
880 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
881 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
882 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
884 <!-- email variables -->
885 <input type=hidden name=message value="$form->{message}">
886 <input type=hidden name=email value="$form->{email}">
887 <input type=hidden name=subject value="$form->{subject}">
888 <input type=hidden name=cc value="$form->{cc}">
889 <input type=hidden name=bcc value="$form->{bcc}">
891 <input type=hidden name=taxpart value="$form->{taxpart}">
892 <input type=hidden name=taxservice value="$form->{taxservice}">
894 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
897 foreach $item (split / /, $form->{taxaccounts}) {
899 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
900 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
903 $lxdebug->leave_sub();
907 $lxdebug->enter_sub();
909 $form->{invtotal} = $form->{invsubtotal};
911 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
914 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
917 $rows = ($rows > $introws) ? $rows : $introws;
919 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
921 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
923 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
926 if ($form->{taxaccounts}) {
928 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
929 . $locale->text('Tax Included') . qq|</b><br><br>
933 if (!$form->{taxincluded}) {
935 foreach $item (split / /, $form->{taxaccounts}) {
936 if ($form->{"${item}_base"}) {
937 $form->{invtotal} += $form->{"${item}_total"} =
939 $form->{"${item}_base"} * $form->{"${item}_rate"},
941 $form->{"${item}_total"} =
942 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
946 <th align=right>$form->{"${item}_description"} |
947 . $form->{"${item}_rate"} * 100 .qq|%</th>
948 <td align=right>$form->{"${item}_total"}</td>
954 $form->{invsubtotal} =
955 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
959 <th align=right>| . $locale->text('Subtotal') . qq|</th>
960 <td align=right>$form->{invsubtotal}</td>
966 if ($form->{taxincluded}) {
967 foreach $item (split / /, $form->{taxaccounts}) {
968 if ($form->{"${item}_base"}) {
969 $form->{"${item}_total"} =
971 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
972 (1 + $form->{"${item}_rate"})
975 $form->{"${item}_netto"} =
977 ($form->{"${item}_base"} - $form->{"${item}_total"}),
979 $form->{"${item}_total"} =
980 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
981 $form->{"${item}_netto"} =
982 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
986 <th align=right>Enthaltene $form->{"${item}_description"} |
987 . $form->{"${item}_rate"} * 100 .qq|%</th>
988 <td align=right>$form->{"${item}_total"}</td>
991 <th align=right>Nettobetrag</th>
992 <td align=right>$form->{"${item}_netto"}</td>
1000 $form->{oldinvtotal} = $form->{invtotal};
1002 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
1012 <th align=left>| . $locale->text('Notes') . qq|</th>
1013 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
1024 <td align=right width=100%>
1030 <th align=right>| . $locale->text('Total') . qq|</th>
1031 <td align=right>$form->{invtotal}</td>
1039 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1040 <input type=hidden name=oldtotalpaid value=$totalpaid>
1042 <td><hr size=3 noshade></td>
1050 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
1053 <td align=left width=30%><b>Dateiname</b></td>
1054 <td align=left width=70%><b>Webdavlink</b></td>
1056 foreach $file (keys %{ $form->{WEBDAV} }) {
1059 <td align=left>$file</td>
1060 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1068 <td><hr size=3 noshade></td>
1075 <input type=hidden name=jscalendar value=$form->{jscalendar}>
1088 | . $locale->text("Edit the $form->{type}") . qq|<br>
1089 <input class=submit type=submit name=action id=update_button value="|
1090 . $locale->text('Update') . qq|">
1091 <input class=submit type=submit name=action value="|
1092 . $locale->text('Ship to') . qq|">
1093 <input class=submit type=submit name=action value="|
1094 . $locale->text('Print') . qq|">
1095 <input class=submit type=submit name=action value="|
1096 . $locale->text('E-mail') . qq|">
1097 <input class=submit type=submit name=action value="|
1098 . $locale->text('Save') . qq|">
1099 <input class=submit type=submit name=action value="|
1100 . $locale->text('Save and Close') . qq|">
1103 if (($form->{id})) {
1105 <input type="button" class="submit" onclick="set_history_window(|
1107 . qq|);" name="history" id="history" value="|
1108 . $locale->text('history')
1111 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1112 <input class=submit type=submit name=action value="|
1113 . $locale->text('Save as new') . qq|">
1114 <input class=submit type=submit name=action value="|
1115 . $locale->text('Delete') . qq|">|;
1116 if (($form->{type} =~ /sales_quotation$/)) {
1118 <input class=submit type=submit name=action value="|
1119 . $locale->text('Sales Order') . qq|">|;
1121 if ($form->{type} =~ /request_quotation$/) {
1123 <input class=submit type=submit name=action value="|
1124 . $locale->text('Purchase Order') . qq|">|;
1128 <input class=submit type=submit name=action value="|
1129 . $locale->text('Invoice') . qq|">
1133 if ($form->{type} =~ /sales_order$/) {
1135 <br>$form->{heading} als neue Vorlage verwenden für<br>
1136 <input class=submit type=submit name=action value="|
1137 . $locale->text('Purchase Order') . qq|">
1138 <input class=submit type=submit name=action value="|
1139 . $locale->text('Quotation') . qq|">
1142 } elsif ($form->{type} =~ /purchase_order$/) {
1144 <br>$form->{heading} als neue Vorlage verwenden für<br>
1145 <input class=submit type=submit name=action value="|
1146 . $locale->text('Sales Order') . qq|">
1147 <input class=submit type=submit name=action value="|
1148 . $locale->text('Request for Quotation') . qq|">
1153 <br>$form->{heading} als neue Vorlage verwenden für<br>
1154 <input class=submit type=submit name=action value="|
1155 . $locale->text('Order') . qq|">
1158 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1160 <br>Workflow $form->{heading}<br>
1161 <input class=submit type=submit name=action value="|
1162 . $locale->text('Save as new') . qq|">
1163 <input class=submit type=submit name=action value="|
1164 . $locale->text('Invoice') . qq|">
1168 $form->hide_form("saved_xyznumber");
1172 <input type=hidden name=rowcount value=$form->{rowcount}>
1174 <input name=callback type=hidden value="$form->{callback}">
1176 <input type=hidden name=login value=$form->{login}>
1177 <input type=hidden name=password value=$form->{password}>
1184 $lxdebug->leave_sub();
1188 $lxdebug->enter_sub();
1190 set_headings($form->{"id"} ? "edit" : "add");
1192 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1193 qw(exchangerate creditlimit creditremaining);
1194 $form->{update} = 1;
1196 if($form->{payment_id}) {
1197 $payment_id = $form->{payment_id};
1200 &check_name($form->{vc});
1202 if($form->{payment_id} eq "") {
1203 $form->{payment_id} = $payment_id;
1207 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1208 $form->{exchangerate} = $exchangerate
1212 $form->check_exchangerate(
1213 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1217 $i = $form->{rowcount};
1219 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1221 if ( ($form->{"partnumber_$i"} eq "")
1222 && ($form->{"description_$i"} eq "")
1223 && ($form->{"partsgroup_$i"} eq "")) {
1225 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1230 if ( $form->{type} eq 'purchase_order'
1231 || $form->{type} eq 'request_quotation') {
1232 IR->retrieve_item(\%myconfig, \%$form);
1234 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1235 IS->retrieve_item(\%myconfig, \%$form);
1238 my $rows = scalar @{ $form->{item_list} };
1240 $form->{"discount_$i"} =
1241 $form->format_amount(\%myconfig, $form->{discount} * 100);
1244 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1253 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1254 if ($form->{"not_discountable_$i"}) {
1255 $form->{"discount_$i"} = 0;
1257 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1258 qw(partnumber description unit);
1259 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1260 keys %{ $form->{item_list}[0] };
1261 if ($form->{"part_payment_id_$i"} ne "") {
1262 $form->{payment_id} = $form->{"part_payment_id_$i"};
1265 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1267 ($dec) = ($s =~ /\.(\d+)/);
1269 $decimalplaces = ($dec > 2) ? $dec : 2;
1272 $form->{"sellprice_$i"} = $sellprice;
1275 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1277 # if there is an exchange rate adjust sellprice
1278 $form->{"sellprice_$i"} /= $exchangerate;
1282 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1283 (1 - $form->{"discount_$i"} / 100);
1284 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1285 map { $form->{"${_}_base"} += $amount }
1286 (split / /, $form->{"taxaccounts_$i"});
1287 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1288 split / /, $form->{taxaccounts}
1289 if !$form->{taxincluded};
1291 $form->{creditremaining} -= $amount;
1293 $form->{"sellprice_$i"} =
1294 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1297 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1299 # get pricegroups for parts
1300 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1302 # build up html code for prices_$i
1303 &set_pricegroup($i);
1310 # ok, so this is a new part
1311 # ask if it is a part or service item
1313 if ( $form->{"partsgroup_$i"}
1314 && ($form->{"partsnumber_$i"} eq "")
1315 && ($form->{"description_$i"} eq "")) {
1316 $form->{rowcount}--;
1317 $form->{"discount_$i"} = "";
1321 $form->{"id_$i"} = 0;
1322 $form->{"unit_$i"} = $locale->text('ea');
1330 $lxdebug->leave_sub();
1334 $lxdebug->enter_sub();
1336 if ($form->{type} eq 'purchase_order') {
1337 $form->{title} = $locale->text('Purchase Orders');
1338 $form->{vc} = 'vendor';
1339 $ordlabel = $locale->text('Order Number');
1340 $ordnumber = 'ordnumber';
1341 $employee = $locale->text('Employee');
1344 if ($form->{type} eq 'request_quotation') {
1345 $form->{title} = $locale->text('Request for Quotations');
1346 $form->{vc} = 'vendor';
1347 $ordlabel = $locale->text('RFQ Number');
1348 $ordnumber = 'quonumber';
1349 $employee = $locale->text('Employee');
1352 if ($form->{type} eq 'sales_order') {
1353 $form->{title} = $locale->text('Sales Orders');
1354 $form->{vc} = 'customer';
1355 $ordlabel = $locale->text('Order Number');
1356 $ordnumber = 'ordnumber';
1357 $employee = $locale->text('Employee');
1360 if ($form->{type} eq 'sales_quotation') {
1361 $form->{title} = $locale->text('Quotations');
1362 $form->{vc} = 'customer';
1363 $ordlabel = $locale->text('Quotation Number');
1364 $ordnumber = 'quonumber';
1365 $employee = $locale->text('Employee');
1368 # setup vendor / customer selection
1369 $form->all_vc(\%myconfig, $form->{vc},
1370 ($form->{vc} eq 'customer') ? "AR" : "AP");
1373 if (@{ $form->{all_departments} }) {
1374 $form->{selectdepartment} = "<option>\n";
1377 $form->{selectdepartment} .=
1378 "<option>$_->{description}--$_->{id}</option>\n"
1379 } (@{ $form->{all_departments} });
1384 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1385 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1387 | if $form->{selectdepartment};
1390 if (($form->{"type"} eq "sales_order") ||
1391 ($form->{"type"} eq "purchase_order")) {
1394 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1395 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1396 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1397 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1402 # use JavaScript Calendar or not
1403 $form->{jsscript} = $jscalendar;
1405 if ($form->{jsscript}) {
1407 # with JavaScript Calendar
1409 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1410 <input type=button name=transdatefrom id="trigger3" value=|
1411 . $locale->text('button') . qq|></td>
1414 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1415 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1416 . $locale->text('button') . qq|></td>
1421 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1422 "transdateto", "BL", "trigger4");
1425 # without JavaScript Calendar
1427 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
1429 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\></td>|;
1432 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1434 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1436 $vc => "ALL_" . uc($vc));
1440 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1441 push(@values, $item->{"id"});
1442 $labels{$item->{"id"}} = $item->{"projectnumber"};
1445 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1446 '-labels' => \%labels));
1451 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1452 push(@values, $item->{name}.qq|--|.$item->{"id"});
1453 $labels{$item->{"id"}} = $item->{name}.qq|--|.$item->{"id"};
1456 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1458 $myconfig{vclimit} <= scalar(@values)
1459 ? qq|<input type="text" value="| . H($form->{"old$form->{vc}"}) . qq|" name="$form->{vc}">|
1460 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1461 '-default' => $form->{"old$form->{vc}"},
1462 '-onChange' => 'document.getElementById(\'update_button\').click();',
1463 '-values' => \@values,
1464 '-labels' => \%labels));
1471 <form method=post action=$form->{script}>
1475 <th class=listtop>$form->{title}</th>
1477 <tr height="5"></tr>
1482 <th align=right>$vc_label</th>
1483 <td colspan=3>$vc</td>
1487 <th align=right>$ordlabel</th>
1488 <td colspan=3><input name="$ordnumber" size=20></td>
1491 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1492 <td colspan="3"><input name="transaction_description" size=20></td>
1495 <th align="right">| . $locale->text("Project Number") . qq|</th>
1496 <td colspan="3">$projectnumber</td>
1499 <th align=right>| . $locale->text('From') . qq|</th>
1501 <th align=right>| . $locale->text('Bis') . qq|</th>
1504 <input type=hidden name=sort value=transdate>
1506 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1510 <td><input type="checkbox" name="open" value="1" id="open" checked>
1511 <label for="open">| . $locale->text("Open") . qq|</td>
1512 <td><input type="checkbox" name="closed" value="1" id="closed">
1513 <label for="closed">| . $locale->text("Closed") . qq|</td>
1517 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1518 | . $locale->text('ID') . qq|</td>
1519 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1520 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1521 . $locale->text('Date') . qq|</td>
1522 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1523 . $locale->text('Required by') . qq|</td>
1526 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> ucfirst($form->{vc})</td>
1527 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1528 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1529 . $locale->text('Ship via') . qq|</td>
1530 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1533 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1534 . $locale->text('Amount') . qq|</td>
1535 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1536 . $locale->text('Tax') . qq|</td>
1537 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1538 . $locale->text('Total') . qq|</td>
1541 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1542 . $locale->text('Project Number') . qq|</td>
1543 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1544 . $locale->text('Transaction description') . qq|</td>
1547 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1548 . $locale->text('Subtotal') . qq|</td>
1556 <tr><td colspan=4><hr size=3 noshade></td></tr>
1562 <input type=hidden name=nextsub value=orders>
1563 <input type=hidden name=login value=$form->{login}>
1564 <input type=hidden name=password value=$form->{password}>
1565 <input type=hidden name=vc value=$form->{vc}>
1566 <input type=hidden name=type value=$form->{type}>
1568 <input class=submit type=submit name=action value="|
1569 . $locale->text('Continue') . qq|">
1576 $lxdebug->leave_sub();
1580 $lxdebug->enter_sub();
1582 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1586 qw(type vc login password transdatefrom transdateto
1587 open closed notdelivered delivered department
1588 transaction_description);
1589 push @fields, $form->{vc};
1590 $href = "$form->{script}?action=orders&"
1591 . join("&", map { "${_}=" . E($form->{$_}) } @fields)
1592 . "&${ordnumber}=" . E($form->{$ordnumber});
1595 # split vendor / customer
1596 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1597 split(/--/, $form->{ $form->{vc} });
1599 OE->transactions(\%myconfig, \%$form);
1602 "transdate", "reqdate",
1604 "name", "netamount",
1607 "shipvia", "globalprojectnumber",
1608 "transaction_description", "open",
1609 "closed", "delivered"
1612 $form->{l_open} = $form->{l_closed} = "Y"
1613 if ($form->{open} && $form->{closed});
1615 $form->{"l_delivered"} = "Y"
1616 if ($form->{"delivered"} && $form->{"notdelivered"});
1618 foreach $item (@columns) {
1619 if ($form->{"l_$item"} eq "Y") {
1620 push @column_index, $item;
1622 # add column to href and callback
1623 $callback .= "&l_$item=Y";
1624 $href .= "&l_$item=Y";
1628 # only show checkboxes if gotten here via sales_order form.
1629 if ($form->{type} =~ /sales_order/) {
1630 unshift @column_index, "ids";
1633 if ($form->{l_subtotal} eq 'Y') {
1634 $callback .= "&l_subtotal=Y";
1635 $href .= "&l_subtotal=Y";
1638 if ($form->{vc} eq 'vendor') {
1639 if ($form->{type} eq 'purchase_order') {
1640 $form->{title} = $locale->text('Purchase Orders');
1642 $form->{title} = $locale->text('Request for Quotations');
1644 $name = $locale->text('Vendor');
1645 $employee = $locale->text('Employee');
1647 if ($form->{vc} eq 'customer') {
1648 if ($form->{type} eq 'sales_order') {
1649 $form->{title} = $locale->text('Sales Orders');
1651 $form->{title} = $locale->text('Quotations');
1653 $employee = $locale->text('Employee');
1654 $name = $locale->text('Customer');
1657 $column_header{id} =
1658 qq|<th><a class=listheading href=$href&sort=id>|
1659 . $locale->text('ID')
1661 $column_header{transdate} =
1662 qq|<th><a class=listheading href=$href&sort=transdate>|
1663 . $locale->text('Date')
1665 $column_header{reqdate} =
1666 qq|<th><a class=listheading href=$href&sort=reqdate>|
1667 . $locale->text('Required by')
1669 $column_header{ordnumber} =
1670 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1671 . $locale->text('Order')
1673 $column_header{quonumber} =
1674 qq|<th><a class=listheading href=$href&sort=quonumber>|
1675 . ($form->{"type"} eq "request_quotation" ?
1676 $locale->text('RFQ') :
1677 $locale->text('Quotation'))
1679 $column_header{name} =
1680 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1681 $column_header{netamount} =
1682 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1683 $column_header{tax} =
1684 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1685 $column_header{amount} =
1686 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1687 $column_header{curr} =
1688 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1689 $column_header{shipvia} =
1690 qq|<th><a class=listheading href=$href&sort=shipvia>|
1691 . $locale->text('Ship via')
1693 $column_header{globalprojectnumber} =
1694 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1695 $column_header{open} =
1696 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1697 $column_header{closed} =
1698 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1699 $column_header{"delivered"} =
1700 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1702 $column_header{employee} =
1703 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1704 $column_header{transaction_description} =
1705 qq|<th><a class=listheading href="$href&sort=transaction_description">|
1706 . $locale->text("Transaction description") . qq|</a></th>|;
1708 $column_header{ids} = qq|<th></th>|;
1710 if ($form->{ $form->{vc} }) {
1711 $option = $locale->text(ucfirst $form->{vc});
1712 $option .= " : $form->{$form->{vc}}";
1714 if ($form->{department}) {
1715 $option .= "\n<br>" if ($option);
1716 ($department) = split /--/, $form->{department};
1717 $option .= $locale->text('Department') . " : $department";
1719 if ($form->{transdatefrom}) {
1721 . $locale->text('From') . " "
1722 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1724 if ($form->{transdateto}) {
1726 . $locale->text('Bis') . " "
1727 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1729 if ($form->{open}) {
1730 $option .= "\n<br>" if ($option);
1731 $option .= $locale->text('Open');
1733 if ($form->{closed}) {
1734 $option .= "\n<br>" if ($option);
1735 $option .= $locale->text('Closed');
1743 <form method="post" action="oe.pl">
1746 <th class=listtop>$form->{title}</th>
1748 <tr height="5"></tr>
1755 <tr class=listheading>|;
1757 map { print "\n$column_header{$_}" } @column_index;
1763 # add sort and escape callback
1764 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1766 if (@{ $form->{OE} }) {
1767 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1772 foreach $oe (@{ $form->{OE} }) {
1773 $form->{rowcount} = ++$j;
1775 if ($form->{l_subtotal} eq 'Y') {
1776 if ($sameitem ne $oe->{ $form->{sort} }) {
1778 $sameitem = $oe->{ $form->{sort} };
1782 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1784 $column_data{netamount} =
1786 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1788 $column_data{tax} = "<td align=right>"
1789 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1792 $column_data{amount} =
1794 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1796 $totalnetamount += $oe->{netamount};
1797 $totalamount += $oe->{amount};
1799 $subtotalnetamount += $oe->{netamount};
1800 $subtotalamount += $oe->{amount};
1803 qq|<td><input name="multi_id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1804 $column_data{id} = "<td>$oe->{id}</td>";
1805 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1806 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1808 $column_data{$ordnumber} =
1809 "<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>";
1810 $column_data{name} = "<td>$oe->{name}</td>";
1812 $column_data{employee} = "<td>$oe->{employee} </td>";
1813 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1814 $column_data{globalprojectnumber} = "<td>" . H($oe->{globalprojectnumber}) . "</td>";
1816 if ($oe->{closed}) {
1817 $column_data{closed} = "<td align=center>X</td>";
1818 $column_data{open} = "<td> </td>";
1820 $column_data{closed} = "<td> </td>";
1821 $column_data{open} = "<td align=center>X</td>";
1823 $column_data{"delivered"} = "<td>" .
1824 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1826 $column_data{transaction_description} = "<td>" . H($oe->{transaction_description}) . "</td>";
1831 <tr class=listrow$i>";
1833 map { print "\n$column_data{$_}" } @column_index;
1841 if ($form->{l_subtotal} eq 'Y') {
1847 <tr class=listtotal>|;
1849 map { $column_data{$_} = "<td> </td>" } @column_index;
1851 $column_data{netamount} =
1852 "<th class=listtotal align=right>"
1853 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1854 $column_data{tax} = "<th class=listtotal align=right>"
1855 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1858 $column_data{amount} =
1859 "<th class=listtotal align=right>"
1860 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1862 map { print "\n$column_data{$_}" } @column_index;
1870 <td><hr size=3 noshade></td>
1874 # multiple invoice edit button only if gotten there via sales_order form.
1876 if ($form->{type} =~ /sales_order/) {
1878 <input class"submit" type="submit" name="action" value="|
1879 . $locale->text('Continue') . qq|">
1880 <input type="hidden" name="nextsub" value="edit">
1881 <input type="hidden" name="type" value="$form->{type}">
1882 <input type="hidden" name="vc" value="$form->{vc}">
1883 <input type="hidden" name="login" value="$form->{login}">
1884 <input type="hidden" name="password" value="$form->{password}">
1885 <input type="hidden" name="callback" value="$callback">
1886 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1893 <form method=post action=$form->{script}>
1895 <input name=callback type=hidden value="$form->{callback}">
1897 <input type=hidden name=type value=$form->{type}>
1898 <input type=hidden name=vc value=$form->{vc}>
1900 <input type=hidden name=login value=$form->{login}>
1901 <input type=hidden name=password value=$form->{password}>
1909 $lxdebug->leave_sub();
1913 $lxdebug->enter_sub();
1915 map { $column_data{$_} = "<td> </td>" } @column_index;
1917 $column_data{netamount} =
1918 "<th class=listsubtotal align=right>"
1919 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1921 $column_data{tax} = "<td class=listsubtotal align=right>"
1922 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1925 $column_data{amount} =
1926 "<th class=listsubtotal align=right>"
1927 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1929 $subtotalnetamount = 0;
1930 $subtotalamount = 0;
1933 <tr class=listsubtotal>
1936 map { print "\n$column_data{$_}" } @column_index;
1942 $lxdebug->leave_sub();
1945 sub save_and_close {
1946 $lxdebug->enter_sub();
1948 if ($form->{type} =~ /_order$/) {
1949 $form->isblank("transdate", $locale->text('Order Date missing!'));
1951 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1954 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1955 $form->{$idx} =~ s/^\s*//g;
1956 $form->{$idx} =~ s/\s*$//g;
1958 $msg = ucfirst $form->{vc};
1959 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1961 # $locale->text('Customer missing!');
1962 # $locale->text('Vendor missing!');
1964 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1965 if ($form->{currency} ne $form->{defaultcurrency});
1969 if($form->{payment_id}) {
1970 $payment_id = $form->{payment_id};
1973 # if the name changed get new values
1974 if (&check_name($form->{vc})) {
1975 if($form->{payment_id} eq "") {
1976 $form->{payment_id} = $payment_id;
1982 $form->{id} = 0 if $form->{saveasnew};
1984 # this is for the internal notes section for the [email] Subject
1985 if ($form->{type} =~ /_order$/) {
1986 if ($form->{type} eq 'sales_order') {
1987 $form->{label} = $locale->text('Sales Order');
1989 $numberfld = "sonumber";
1990 $ordnumber = "ordnumber";
1992 $form->{label} = $locale->text('Purchase Order');
1994 $numberfld = "ponumber";
1995 $ordnumber = "ordnumber";
1998 $err = $locale->text('Cannot save order!');
2001 if ($form->{type} eq 'sales_quotation') {
2002 $form->{label} = $locale->text('Quotation');
2004 $numberfld = "sqnumber";
2005 $ordnumber = "quonumber";
2007 $form->{label} = $locale->text('Request for Quotation');
2009 $numberfld = "rfqnumber";
2010 $ordnumber = "quonumber";
2013 $err = $locale->text('Cannot save quotation!');
2017 # get new number in sequence if no number is given or if saveasnew was requested
2018 if (!$form->{$ordnumber} || $form->{saveasnew}) {
2019 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
2024 $form->error($err) if (!OE->save(\%myconfig, \%$form));
2026 # saving the history
2027 if(!exists $form->{addition}) {
2028 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2029 $form->{addition} = "SAVED";
2030 $form->save_history($form->dbconnect(\%myconfig));
2032 # /saving the history
2034 $form->redirect($form->{label} . " $form->{$ordnumber} " .
2035 $locale->text('saved!'));
2037 $lxdebug->leave_sub();
2041 $lxdebug->enter_sub();
2043 if ($form->{type} =~ /_order$/) {
2044 $form->isblank("transdate", $locale->text('Order Date missing!'));
2046 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2049 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2050 $form->{$idx} =~ s/^\s*//g;
2051 $form->{$idx} =~ s/\s*$//g;
2053 $msg = ucfirst $form->{vc};
2054 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
2056 # $locale->text('Customer missing!');
2057 # $locale->text('Vendor missing!');
2059 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
2060 if ($form->{currency} ne $form->{defaultcurrency});
2064 if($form->{payment_id}) {
2065 $payment_id = $form->{payment_id};
2068 # if the name changed get new values
2069 if (&check_name($form->{vc})) {
2070 if($form->{payment_id} eq "") {
2071 $form->{payment_id} = $payment_id;
2077 $form->{id} = 0 if $form->{saveasnew};
2079 # this is for the internal notes section for the [email] Subject
2080 if ($form->{type} =~ /_order$/) {
2081 if ($form->{type} eq 'sales_order') {
2082 $form->{label} = $locale->text('Sales Order');
2084 $numberfld = "sonumber";
2085 $ordnumber = "ordnumber";
2087 $form->{label} = $locale->text('Purchase Order');
2089 $numberfld = "ponumber";
2090 $ordnumber = "ordnumber";
2093 $err = $locale->text('Cannot save order!');
2096 if ($form->{type} eq 'sales_quotation') {
2097 $form->{label} = $locale->text('Quotation');
2099 $numberfld = "sqnumber";
2100 $ordnumber = "quonumber";
2102 $form->{label} = $locale->text('Request for Quotation');
2104 $numberfld = "rfqnumber";
2105 $ordnumber = "quonumber";
2108 $err = $locale->text('Cannot save quotation!');
2112 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
2113 unless $form->{$ordnumber};
2117 OE->save(\%myconfig, \%$form);
2119 # saving the history
2120 if(!exists $form->{addition}) {
2121 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2122 $form->{addition} = "SAVED";
2123 $form->save_history($form->dbconnect(\%myconfig));
2125 # /saving the history
2127 $form->{simple_save} = 1;
2128 if(!$form->{print_and_save}) {
2129 set_headings("edit");
2133 $lxdebug->leave_sub();
2137 $lxdebug->enter_sub();
2141 if ($form->{type} =~ /_order$/) {
2142 $msg = $locale->text('Are you sure you want to delete Order Number');
2143 $ordnumber = 'ordnumber';
2145 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2146 $ordnumber = 'quonumber';
2152 <form method=post action=$form->{script}>
2155 # delete action variable
2156 map { delete $form->{$_} } qw(action header);
2158 foreach $key (keys %$form) {
2159 $form->{$key} =~ s/\"/"/g;
2160 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2164 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2166 <h4>$msg $form->{$ordnumber}</h4>
2168 <input name=action class=submit type=submit value="|
2169 . $locale->text('Yes') . qq|">
2176 $lxdebug->leave_sub();
2180 $lxdebug->enter_sub();
2182 if ($form->{type} =~ /_order$/) {
2183 $msg = $locale->text('Order deleted!');
2184 $err = $locale->text('Cannot delete order!');
2186 $msg = $locale->text('Quotation deleted!');
2187 $err = $locale->text('Cannot delete quotation!');
2189 if (OE->delete(\%myconfig, \%$form, $spool)){
2190 $form->redirect($msg);
2191 # saving the history
2192 if(!exists $form->{addition}) {
2193 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2194 $form->{addition} = "DELETED";
2195 $form->save_history($form->dbconnect(\%myconfig));
2197 # /saving the history
2201 $lxdebug->leave_sub();
2205 $lxdebug->enter_sub();
2207 if ($form->{type} =~ /_order$/) {
2209 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2210 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2211 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2212 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2213 $form->isblank("transdate", $locale->text('Order Date missing!'))
2214 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2216 # also copy deliverydate from the order
2217 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2218 $form->{orddate} = $form->{transdate};
2220 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2221 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2222 $form->{ordnumber} = "";
2223 $form->{quodate} = $form->{transdate};
2226 if($form->{payment_id}) {
2227 $payment_id = $form->{payment_id};
2230 # if the name changed get new values
2231 if (&check_name($form->{vc})) {
2232 if($form->{payment_id} eq "") {
2233 $form->{payment_id} = $payment_id;
2239 $form->{cp_id} *= 1;
2241 for $i (1 .. $form->{rowcount}) {
2242 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2243 $form->{"${_}_${i}"})
2244 if ($form->{"${_}_${i}"}) }
2245 qw(ship qty sellprice listprice basefactor));
2248 if ( $form->{type} =~ /_order/
2249 && $form->{currency} ne $form->{defaultcurrency}) {
2251 # check if we need a new exchangerate
2252 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2254 $orddate = $form->current_date(\%myconfig);
2256 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2259 if (!$exchangerate) {
2260 &backorder_exchangerate($orddate, $buysell);
2265 # close orders/quotations
2266 $form->{closed} = 1;
2268 # save order if one ordnumber has been given
2269 # if not it's most likely a collective order, which can't be saved back
2270 # so they just have to be closed
2271 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2272 OE->close_order(\%myconfig, \%$form);
2274 OE->close_orders(\%myconfig, \%$form);
2277 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2279 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2282 $form->{closed} = 0;
2283 $form->{rowcount}--;
2284 $form->{shipto} = 1;
2286 if ($form->{type} =~ /_order$/) {
2287 $form->{exchangerate} = $exchangerate;
2291 if ( $form->{type} eq 'purchase_order'
2292 || $form->{type} eq 'request_quotation') {
2293 $form->{title} = $locale->text('Add Vendor Invoice');
2294 $form->{script} = 'ir.pl';
2298 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2299 $form->{title} = $locale->text('Add Sales Invoice');
2300 $form->{script} = 'is.pl';
2305 # bo creates the id, reset it
2306 map { delete $form->{$_} }
2307 qw(id subject message cc bcc printed emailed queued);
2308 $form->{ $form->{vc} } =~ s/--.*//g;
2309 $form->{type} = "invoice";
2312 $locale = new Locale "$myconfig{countrycode}", "$script";
2314 require "bin/mozilla/$form->{script}";
2316 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2318 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2319 qw(creditlimit creditremaining);
2321 $currency = $form->{currency};
2324 $form->{currency} = $currency;
2325 $form->{exchangerate} = "";
2326 $form->{forex} = "";
2327 $form->{exchangerate} = $exchangerate
2331 $form->check_exchangerate(
2332 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2335 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2340 for $i (1 .. $form->{rowcount}) {
2341 $form->{"discount_$i"} =
2342 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2344 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2346 $decimalplaces = ($dec > 2) ? $dec : 2;
2348 # copy delivery date from reqdate for order -> invoice conversion
2349 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2350 unless $form->{"deliverydate_$i"};
2352 $form->{"sellprice_$i"} =
2353 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2356 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2357 $dec_qty = length $dec_qty;
2359 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2361 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2362 qw(partnumber description unit);
2368 $lxdebug->leave_sub();
2371 sub backorder_exchangerate {
2372 $lxdebug->enter_sub();
2373 my ($orddate, $buysell) = @_;
2380 <form method=post action=$form->{script}>
2383 # delete action variable
2384 map { delete $form->{$_} } qw(action header exchangerate);
2386 foreach $key (keys %$form) {
2387 $form->{$key} =~ s/\"/"/g;
2388 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2391 $form->{title} = $locale->text('Add Exchangerate');
2395 <input type=hidden name=login value=$form->{login}>
2396 <input type=hidden name=password value=$form->{password}>
2398 <input type=hidden name=exchangeratedate value=$orddate>
2399 <input type=hidden name=buysell value=$buysell>
2402 <tr><th class=listtop>$form->{title}</th></tr>
2403 <tr height="5"></tr>
2408 <th align=right>| . $locale->text('Currency') . qq|</th>
2409 <td>$form->{currency}</td>
2412 <th align=right>| . $locale->text('Date') . qq|</th>
2416 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2417 <td><input name=exchangerate size=11></td>
2427 <input type=hidden name=nextsub value=save_exchangerate>
2429 <input name=action class=submit type=submit value="|
2430 . $locale->text('Continue') . qq|">
2438 $lxdebug->leave_sub();
2441 sub save_exchangerate {
2442 $lxdebug->enter_sub();
2444 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2445 $form->{exchangerate} =
2446 $form->parse_amount(\%myconfig, $form->{exchangerate});
2447 $form->save_exchangerate(\%myconfig, $form->{currency},
2448 $form->{exchangeratedate},
2449 $form->{exchangerate}, $form->{buysell});
2453 $lxdebug->leave_sub();
2456 sub create_backorder {
2457 $lxdebug->enter_sub();
2459 $form->{shipped} = 1;
2461 # figure out if we need to create a backorder
2462 # items aren't saved if qty != 0
2464 for $i (1 .. $form->{rowcount}) {
2465 $totalqty += $qty = $form->{"qty_$i"};
2466 $totalship += $ship = $form->{"ship_$i"};
2468 $form->{"qty_$i"} = $qty - $ship;
2471 if ($totalship == 0) {
2472 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2473 $form->{ordtotal} = 0;
2474 $form->{shipped} = 0;
2478 if ($totalqty == $totalship) {
2479 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2480 $form->{ordtotal} = 0;
2485 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2488 for $i (1 .. $form->{rowcount}) {
2490 $form->{"${_}_$i"} =
2491 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2492 } qw(sellprice discount);
2497 OE->save(\%myconfig, \%$form);
2499 # rebuild rows for invoice
2503 for $i (1 .. $form->{rowcount}) {
2504 $form->{"qty_$i"} = $form->{"ship_$i"};
2506 if ($form->{"qty_$i"}) {
2509 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2514 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2515 $form->{rowcount} = $count;
2517 $lxdebug->leave_sub();
2521 $lxdebug->enter_sub();
2523 $form->{saveasnew} = 1;
2524 $form->{closed} = 0;
2525 map { delete $form->{$_} } qw(printed emailed queued);
2527 # Let Lx-Office assign a new order number if the user hasn't changed the
2528 # previous one. If it has been changed manually then use it as-is.
2529 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2530 $form->{$idx} =~ s/^\s*//g;
2531 $form->{$idx} =~ s/\s*$//g;
2532 if ($form->{saved_xyznumber} &&
2533 ($form->{saved_xyznumber} eq $form->{$idx})) {
2534 delete($form->{$idx});
2539 $lxdebug->leave_sub();
2542 sub purchase_order {
2543 $lxdebug->enter_sub();
2545 if ( $form->{type} eq 'sales_quotation'
2546 || $form->{type} eq 'request_quotation') {
2547 OE->close_order(\%myconfig, \%$form);
2550 if ($form->{type} =~ /^sales_/) {
2551 delete($form->{ordnumber});
2554 $form->{cp_id} *= 1;
2556 $form->{title} = $locale->text('Add Purchase Order');
2557 $form->{vc} = "vendor";
2558 $form->{type} = "purchase_order";
2562 $lxdebug->leave_sub();
2566 $lxdebug->enter_sub();
2568 if ( $form->{type} eq 'sales_quotation'
2569 || $form->{type} eq 'request_quotation') {
2570 OE->close_order(\%myconfig, $form);
2573 if ($form->{type} eq "purchase_order") {
2574 delete($form->{ordnumber});
2577 $form->{cp_id} *= 1;
2579 $form->{title} = $locale->text('Add Sales Order');
2580 $form->{vc} = "customer";
2581 $form->{type} = "sales_order";
2585 $lxdebug->leave_sub();
2589 $lxdebug->enter_sub();
2591 $form->{transdate} = $form->current_date(\%myconfig);
2592 delete $form->{duedate};
2594 $form->{closed} = 0;
2597 map { delete $form->{$_} }
2598 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2600 for $i (1 .. $form->{rowcount}) {
2601 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2602 $form->{"${_}_${i}"})
2603 if ($form->{"${_}_${i}"}) }
2604 qw(ship qty sellprice listprice basefactor));
2612 for $i (1 .. $form->{rowcount} - 1) {
2613 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2614 qw(partnumber description unit);
2617 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2618 qw(creditlimit creditremaining);
2622 $lxdebug->leave_sub();
2626 $lxdebug->enter_sub();
2628 $form->{print_and_save} = 1;
2633 my $saved_form = save_form();
2638 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2639 restore_form($saved_form);
2640 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2645 $lxdebug->leave_sub();