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 "$form->{path}/io.pl";
41 require "$form->{path}/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}&path=$form->{path}&password=$form->{password}"
102 unless $form->{callback};
108 $lxdebug->leave_sub();
112 $lxdebug->enter_sub();
114 $form->{simple_save} = 0;
116 set_headings("edit");
118 # editing without stuff to edit? try adding it first
119 if ($form->{rowcount}) {
120 map { $id++ if $form->{"id_$_"} } (1 .. $form->{rowcount});
124 undef $form->{rowcount};
135 if ($form->{print_and_save}) {
136 $form->{action} = "print";
137 $form->{resubmit} = 1;
138 $language_id = $form->{language_id};
139 $printer_id = $form->{printer_id};
142 set_headings("edit");
146 if ($form->{print_and_save}) {
147 $form->{language_id} = $language_id;
148 $form->{printer_id} = $printer_id;
152 $lxdebug->leave_sub();
156 $lxdebug->enter_sub();
158 # get customer/vendor
159 $form->all_vc(\%myconfig, $form->{vc},
160 ($form->{vc} eq 'customer') ? "AR" : "AP");
162 # retrieve order/quotation
163 $form->{webdav} = $webdav;
165 $form->{jscalendar} = $jscalendar;
167 OE->retrieve(\%myconfig, \%$form);
169 if ($form->{payment_id}) {
170 $payment_id = $form->{payment_id};
172 if ($form->{language_id}) {
173 $language_id = $form->{language_id};
175 if ($form->{taxzone_id}) {
176 $taxzone_id = $form->{taxzone_id};
180 # if multiple rowcounts (== collective order) then check if the
181 # there were more than one customer (in that case OE::retrieve removes
182 # the content from the field)
183 if ( $form->{rowcount}
184 && $form->{type} eq 'sales_order'
185 && defined $form->{customer}
186 && $form->{customer} eq '') {
188 # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
191 'Collective Orders only work for orders from one customer!')
195 $taxincluded = $form->{taxincluded};
196 $form->{shipto} = 1 if $form->{id};
198 if ($form->{"all_$form->{vc}"}) {
199 unless ($form->{"$form->{vc}_id"}) {
200 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
204 $cp_id = $form->{cp_id};
205 $intnotes = $form->{intnotes};
207 # get customer / vendor
208 if ($form->{type} =~ /(purchase_order|request_quotation)/) {
209 IR->get_vendor(\%myconfig, \%$form);
211 #quote all_vendor Bug 133
212 foreach $ref (@{ $form->{all_vendor} }) {
213 $ref->{name} = $form->quote($ref->{name});
217 if ($form->{type} =~ /sales_(order|quotation)/) {
218 IS->get_customer(\%myconfig, \%$form);
220 #quote all_vendor Bug 133
221 foreach $ref (@{ $form->{all_customer} }) {
222 $ref->{name} = $form->quote($ref->{name});
226 $form->{cp_id} = $cp_id;
228 $form->{payment_id} = $payment_id;
231 $form->{language_id} = $language_id;
234 $form->{taxzone_id} = $taxzone_id;
236 $form->{intnotes} = $intnotes;
237 ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
238 $form->{"old$form->{vc}"} =
239 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
241 # build the popup menus
242 if (@{ $form->{"all_$form->{vc}"} }) {
243 $form->{ $form->{vc} } =
244 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
245 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
246 (@{ $form->{"all_$form->{vc}"} });
250 @curr = split(/:/, $form->{currencies});
252 $form->{defaultcurrency} = $curr[0];
253 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
255 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
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}\n"
267 } (@{ $form->{all_departments} });
270 $form->{employee} = "$form->{employee}--$form->{employee_id}";
273 if (@{ $form->{all_employees} }) {
274 $form->{selectemployee} = "";
275 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
276 (@{ $form->{all_employees} });
280 $form->{forex} = $form->{exchangerate};
282 $lxdebug->leave_sub();
286 $lxdebug->enter_sub();
287 $form->{formname} = $form->{type} unless $form->{formname};
290 foreach $ref (@{ $form->{form_details} }) {
291 $form->{rowcount} = ++$i;
293 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
295 for my $i (1 .. $form->{rowcount}) {
297 $form->{"discount_$i"} =
298 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
300 $form->{"discount_$i"} =
301 $form->format_amount(\%myconfig, $form->{"discount_$i"});
303 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
305 $decimalplaces = ($dec > 2) ? $dec : 2;
307 # copy reqdate from deliverydate for invoice -> order conversion
308 $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
309 unless $form->{"reqdate_$i"};
311 $form->{"sellprice_$i"} =
312 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
315 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
316 $dec_qty = length $dec_qty;
318 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
320 map { $form->{"${_}_$i"} =~ s/\"/"/g }
321 qw(partnumber description unit);
324 $lxdebug->leave_sub();
328 $lxdebug->enter_sub();
330 my $checkedclosed = $form->{"closed"} ? "checked" : "";
331 my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
333 map { $form->{$_} =~ s/\"/"/g }
334 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
335 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
336 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
338 # use JavaScript Calendar or not
339 $form->{jsscript} = $form->{jscalendar};
342 $payment = qq|<option value=""></option>|;
343 foreach $item (@{ $form->{payment_terms} }) {
344 if ($form->{payment_id} eq $item->{id}) {
345 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
347 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
350 if ($form->{jsscript}) {
352 # with JavaScript Calendar
354 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
355 <td><input type=button name=transdate id="trigger1" value=|
356 . $locale->text('button') . qq|></td>
359 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>
360 <td width="4"><input type=button name=reqdate name=reqdate id="trigger2" value=|
361 . $locale->text('button') . qq|></td>
366 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
367 "reqdate", "BL", "trigger2");
371 # without JavaScript Calendar
373 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>|;
375 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>|;
381 <td colspan=2 align=center>
382 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
383 <label for="closed">| . $locale->text('Closed') . qq|</label>
386 if (($form->{"type"} eq "sales_order") ||
387 ($form->{"type"} eq "purchase_order")) {
389 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
390 <label for="delivered">| . $locale->text('Delivered') . qq|</label>
400 # set option selected
401 foreach $item ($form->{vc}, currency, department, employee) {
402 $form->{"select$item"} =~ s/ selected//;
403 $form->{"select$item"} =~
404 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
407 #quote select[customer|vendor] Bug 133
408 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
410 my @old_project_ids = ($form->{"globalproject_id"});
411 map({ push(@old_project_ids, $form->{"project_id_$_"})
412 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
414 $form->get_lists("contacts" => "ALL_CONTACTS",
415 "shipto" => "ALL_SHIPTO",
416 "projects" => { "key" => "ALL_PROJECTS",
418 "old_id" => \@old_project_ids });
420 my (%labels, @values);
421 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
422 push(@values, $item->{"cp_id"});
423 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
424 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
427 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
428 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
432 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
433 push(@values, $item->{"shipto_id"});
434 $labels{$item->{"shipto_id"}} =
435 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
439 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
441 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
442 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
447 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
448 push(@values, $item->{"id"});
449 $labels{$item->{"id"}} = $item->{"projectnumber"};
451 my $globalprojectnumber =
452 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
453 '-labels' => \%labels,
454 '-default' => $form->{"globalproject_id"}));
456 $form->{exchangerate} =
457 $form->format_amount(\%myconfig, $form->{exchangerate});
459 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
465 $form->{creditlimit} =
466 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
467 $form->{creditremaining} =
468 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
471 <input type=hidden name=forex value=$form->{forex}>
474 if ($form->{currency} ne $form->{defaultcurrency}) {
475 if ($form->{forex}) {
478 . $locale->text('Exchangerate')
479 . qq|</th><td>$form->{exchangerate}</td>
480 <input type=hidden name=exchangerate value=$form->{exchangerate}>
485 . $locale->text('Exchangerate')
486 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
490 $vclabel = ucfirst $form->{vc};
491 $vclabel = $locale->text($vclabel);
495 if ($form->{business}) {
498 <th align=right>| . $locale->text('Business') . qq|</th>
499 <td>$form->{business}</td>
500 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
502 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
508 if ($form->{max_dunning_level}) {
514 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
515 <td><b>$form->{max_dunning_level}</b></td>
516 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
518 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
527 if (@{ $form->{TAXZONE} }) {
528 $form->{selecttaxzone} = "";
529 foreach $item (@{ $form->{TAXZONE} }) {
530 if ($item->{id} == $form->{taxzone_id}) {
531 $form->{selecttaxzone} .=
532 "<option value=$item->{id} selected>" . H($item->{description}) .
535 $form->{selecttaxzone} .=
536 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
541 $form->{selecttaxzone} =~ s/ selected//g;
542 if ($form->{taxzone_id} ne "") {
543 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}>/value=$form->{taxzone_id} selected>/;
549 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
550 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
551 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
555 if ($form->{type} !~ /_quotation$/) {
558 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
559 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
562 <th width=70% align=right nowrap>|
563 . $locale->text('Quotation Number') . qq|</th>
564 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
567 <th width=70% align=right nowrap>|
568 . $locale->text('Customer Order Number') . qq|</th>
569 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
572 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
577 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
582 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
584 $creditremaining = qq|
590 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
591 <td>$form->{creditlimit}</td>
593 <th nowrap>| . $locale->text('Remaining') . qq|</th>
594 <td class="plus$n" nowrap>$form->{creditremaining}</td>
603 ($form->{type} eq 'sales_quotation')
604 ? $locale->text('Valid until')
605 : $locale->text('Required by');
606 if ($form->{type} eq 'sales_quotation') {
609 <th width=70% align=right nowrap>|
610 . $locale->text('Quotation Number') . qq|</th>
611 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
612 <input type=hidden name=ordnumber value="$form->{ordnumber}">
618 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
619 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
620 <input type=hidden name=ordnumber value="$form->{ordnumber}">
628 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
632 <th align=right nowrap=true>$reqlabel</th>
636 $creditremaining = qq| <tr>
643 ($form->{"select$form->{vc}"})
644 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">|
645 : qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
649 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
650 <td colspan=3><select name=department>$form->{selectdepartment}</select>
651 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
654 | if $form->{selectdepartment};
657 <input type=hidden name=employee value="$form->{employee}">
660 if ($form->{type} eq 'sales_order') {
661 if ($form->{selectemployee}) {
663 <input type=hidden name=customer_klass value=$form->{customer_klass}>
665 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
666 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
667 <input type=hidden name=selectemployee value="$form->{selectemployee}">
674 <input type=hidden name=customer_klass value=$form->{customer_klass}>
676 <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
677 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
678 <input type=hidden name=selectemployee value="$form->{selectemployee}">
683 if ($form->{resubmit} && ($form->{format} eq "html")) {
685 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
686 } elsif ($form->{resubmit}) {
687 $onload = qq|document.oe.submit()|;
692 $credittext = $locale->text('Credit Limit exceeded!!!');
693 if ($creditwarning) {
694 $onload = qq|alert('$credittext')|;
697 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
702 <body onLoad="$onload">
704 <form method=post name=oe action=$form->{script}>
705 <script type="text/javascript" src="js/common.js"></script>
706 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
707 <script type="text/javascript" src="js/vendor_selection.js"></script>
708 <script type="text/javascript" src="js/calculate_qty.js"></script>
710 <input type=hidden name=id value=$form->{id}>
711 <input type=hidden name=action value=$form->{action}>
713 <input type=hidden name=type value=$form->{type}>
714 <input type=hidden name=formname value=$form->{formname}>
715 <input type=hidden name=media value=$form->{media}>
716 <input type=hidden name=format value=$form->{format}>
717 <input type=hidden name=proforma value=$form->{proforma}>
719 <input type=hidden name=queued value="$form->{queued}">
720 <input type=hidden name=printed value="$form->{printed}">
721 <input type=hidden name=emailed value="$form->{emailed}">
723 <input type=hidden name=vc value=$form->{vc}>
725 <input type=hidden name=title value="$form->{title}">
727 <input type=hidden name=discount value=$form->{discount}>
728 <input type=hidden name=creditlimit value=$form->{creditlimit}>
729 <input type=hidden name=creditremaining value=$form->{creditremaining}>
731 <input type=hidden name=tradediscount value=$form->{tradediscount}>
732 <input type=hidden name=business value=$form->{business}>
733 <input type=hidden name=webdav value=$webdav>
737 <th class=listtop>$form->{title}</th>
747 <th align=right>$vclabel</th>
748 <td colspan=3>$vc</td>
749 <input type=hidden name=$form->{vc}_id value=$form->{"$form->{vc}_id"}>
750 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
751 <th align=richt nowrap>|
752 . $locale->text('Contact Person') . qq|</th>
753 <td colspan=3>$contact</td>
761 <th align=right>| . $locale->text('Currency') . qq|</th>
762 <td><select name=currency>$form->{selectcurrency}</select></td>
763 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
764 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
768 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
769 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
772 <th align=right>| . $locale->text('Ship via') . qq|</th>
773 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
780 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
782 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
783 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
787 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
789 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
790 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
803 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
804 <td>$globalprojectnumber</td>
815 <!-- shipto are in hidden variables -->
817 <input type=hidden name=shiptoname value="$form->{shiptoname}">
818 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
819 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
820 <input type=hidden name=shiptocity value="$form->{shiptocity}">
821 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
822 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
823 <input type=hidden name=shiptophone value="$form->{shiptophone}">
824 <input type=hidden name=shiptofax value="$form->{shiptofax}">
825 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
826 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
827 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
829 <!-- email variables -->
830 <input type=hidden name=message value="$form->{message}">
831 <input type=hidden name=email value="$form->{email}">
832 <input type=hidden name=subject value="$form->{subject}">
833 <input type=hidden name=cc value="$form->{cc}">
834 <input type=hidden name=bcc value="$form->{bcc}">
836 <input type=hidden name=taxpart value="$form->{taxpart}">
837 <input type=hidden name=taxservice value="$form->{taxservice}">
839 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
842 foreach $item (split / /, $form->{taxaccounts}) {
844 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
845 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
848 $lxdebug->leave_sub();
852 $lxdebug->enter_sub();
854 $form->{invtotal} = $form->{invsubtotal};
856 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
859 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
862 $rows = ($rows > $introws) ? $rows : $introws;
864 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
866 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
868 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
871 if ($form->{taxaccounts}) {
873 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
874 . $locale->text('Tax Included') . qq|</b><br><br>
878 if (!$form->{taxincluded}) {
880 foreach $item (split / /, $form->{taxaccounts}) {
881 if ($form->{"${item}_base"}) {
882 $form->{invtotal} += $form->{"${item}_total"} =
884 $form->{"${item}_base"} * $form->{"${item}_rate"},
886 $form->{"${item}_total"} =
887 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
891 <th align=right>$form->{"${item}_description"}</th>
892 <td align=right>$form->{"${item}_total"}</td>
898 $form->{invsubtotal} =
899 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
903 <th align=right>| . $locale->text('Subtotal') . qq|</th>
904 <td align=right>$form->{invsubtotal}</td>
910 if ($form->{taxincluded}) {
911 foreach $item (split / /, $form->{taxaccounts}) {
912 if ($form->{"${item}_base"}) {
913 $form->{"${item}_total"} =
915 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
916 (1 + $form->{"${item}_rate"})
919 $form->{"${item}_netto"} =
921 ($form->{"${item}_base"} - $form->{"${item}_total"}),
923 $form->{"${item}_total"} =
924 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
925 $form->{"${item}_netto"} =
926 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
930 <th align=right>Enthaltene $form->{"${item}_description"}</th>
931 <td align=right>$form->{"${item}_total"}</td>
934 <th align=right>Nettobetrag</th>
935 <td align=right>$form->{"${item}_netto"}</td>
943 $form->{oldinvtotal} = $form->{invtotal};
945 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
955 <th align=left>| . $locale->text('Notes') . qq|</th>
956 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
962 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
963 <td><select name=payment_id tabindex=24>$payment
967 <td align=right width=100%>
973 <th align=right>| . $locale->text('Total') . qq|</th>
974 <td align=right>$form->{invtotal}</td>
982 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
983 <input type=hidden name=oldtotalpaid value=$totalpaid>
985 <td><hr size=3 noshade></td>
993 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
996 <td align=left width=30%><b>Dateiname</b></td>
997 <td align=left width=70%><b>Webdavlink</b></td>
999 foreach $file (keys %{ $form->{WEBDAV} }) {
1002 <td align=left>$file</td>
1003 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1011 <td><hr size=3 noshade></td>
1018 <input type=hidden name=jscalendar value=$form->{jscalendar}>
1031 | . $locale->text("Edit the $form->{type}") . qq|<br>
1032 <input class=submit type=submit name=action id=update_button value="|
1033 . $locale->text('Update') . qq|">
1034 <input class=submit type=submit name=action value="|
1035 . $locale->text('Ship to') . qq|">
1036 <input class=submit type=submit name=action value="|
1037 . $locale->text('Print') . qq|">
1038 <input class=submit type=submit name=action value="|
1039 . $locale->text('E-mail') . qq|">
1040 <input class=submit type=submit name=action value="|
1041 . $locale->text('Save') . qq|">
1042 <input class=submit type=submit name=action value="|
1043 . $locale->text('Save and Close') . qq|">
1046 if (($form->{id})) {
1048 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1049 <input class=submit type=submit name=action value="|
1050 . $locale->text('Save as new') . qq|">
1051 <input class=submit type=submit name=action value="|
1052 . $locale->text('Delete') . qq|">|;
1053 if (($form->{type} =~ /sales_quotation$/)) {
1055 <input class=submit type=submit name=action value="|
1056 . $locale->text('Sales Order') . qq|">|;
1058 if ($form->{type} =~ /request_quotation$/) {
1060 <input class=submit type=submit name=action value="|
1061 . $locale->text('Purchase Order') . qq|">|;
1065 <input class=submit type=submit name=action value="|
1066 . $locale->text('Invoice') . qq|">
1070 if ($form->{type} =~ /sales_order$/) {
1072 <br>$form->{heading} als neue Vorlage verwenden für<br>
1073 <input class=submit type=submit name=action value="|
1074 . $locale->text('Purchase Order') . qq|">
1075 <input class=submit type=submit name=action value="|
1076 . $locale->text('Quotation') . qq|">
1079 } elsif ($form->{type} =~ /purchase_order$/) {
1081 <br>$form->{heading} als neue Vorlage verwenden für<br>
1082 <input class=submit type=submit name=action value="|
1083 . $locale->text('Sales Order') . qq|">
1084 <input class=submit type=submit name=action value="|
1085 . $locale->text('Request for Quotation') . qq|">
1090 <br>$form->{heading} als neue Vorlage verwenden für<br>
1091 <input class=submit type=submit name=action value="|
1092 . $locale->text('Order') . qq|">
1095 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1097 <br>Workflow $form->{heading}<br>
1098 <input class=submit type=submit name=action value="|
1099 . $locale->text('Save as new') . qq|">
1100 <input class=submit type=submit name=action value="|
1101 . $locale->text('Invoice') . qq|">
1107 <input type=hidden name=rowcount value=$form->{rowcount}>
1109 <input name=callback type=hidden value="$form->{callback}">
1111 <input type=hidden name=path value=$form->{path}>
1112 <input type=hidden name=login value=$form->{login}>
1113 <input type=hidden name=password value=$form->{password}>
1120 $lxdebug->leave_sub();
1124 $lxdebug->enter_sub();
1126 set_headings($form->{"id"} ? "edit" : "add");
1128 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1129 qw(exchangerate creditlimit creditremaining);
1130 $form->{update} = 1;
1132 &check_name($form->{vc});
1135 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1136 $form->{exchangerate} = $exchangerate
1140 $form->check_exchangerate(
1141 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1145 $i = $form->{rowcount};
1147 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1149 if ( ($form->{"partnumber_$i"} eq "")
1150 && ($form->{"description_$i"} eq "")
1151 && ($form->{"partsgroup_$i"} eq "")) {
1153 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1158 if ( $form->{type} eq 'purchase_order'
1159 || $form->{type} eq 'request_quotation') {
1160 IR->retrieve_item(\%myconfig, \%$form);
1162 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1163 IS->retrieve_item(\%myconfig, \%$form);
1166 my $rows = scalar @{ $form->{item_list} };
1168 $form->{"discount_$i"} =
1169 $form->format_amount(\%myconfig, $form->{discount} * 100);
1172 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1181 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1182 if ($form->{"not_discountable_$i"}) {
1183 $form->{"discount_$i"} = 0;
1185 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1186 qw(partnumber description unit);
1187 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1188 keys %{ $form->{item_list}[0] };
1189 if ($form->{"part_payment_id_$i"} ne "") {
1190 $form->{payment_id} = $form->{"part_payment_id_$i"};
1193 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1195 ($dec) = ($s =~ /\.(\d+)/);
1197 $decimalplaces = ($dec > 2) ? $dec : 2;
1200 $form->{"sellprice_$i"} = $sellprice;
1203 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1205 # if there is an exchange rate adjust sellprice
1206 $form->{"sellprice_$i"} /= $exchangerate;
1210 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1211 (1 - $form->{"discount_$i"} / 100);
1212 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1213 map { $form->{"${_}_base"} += $amount }
1214 (split / /, $form->{"taxaccounts_$i"});
1215 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1216 split / /, $form->{taxaccounts}
1217 if !$form->{taxincluded};
1219 $form->{creditremaining} -= $amount;
1221 $form->{"sellprice_$i"} =
1222 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1225 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1227 # get pricegroups for parts
1228 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1230 # build up html code for prices_$i
1231 &set_pricegroup($i);
1238 # ok, so this is a new part
1239 # ask if it is a part or service item
1241 if ( $form->{"partsgroup_$i"}
1242 && ($form->{"partsnumber_$i"} eq "")
1243 && ($form->{"description_$i"} eq "")) {
1244 $form->{rowcount}--;
1245 $form->{"discount_$i"} = "";
1249 $form->{"id_$i"} = 0;
1250 $form->{"unit_$i"} = $locale->text('ea');
1258 $lxdebug->leave_sub();
1262 $lxdebug->enter_sub();
1264 if ($form->{type} eq 'purchase_order') {
1265 $form->{title} = $locale->text('Purchase Orders');
1266 $form->{vc} = 'vendor';
1267 $ordlabel = $locale->text('Order Number');
1268 $ordnumber = 'ordnumber';
1269 $employee = $locale->text('Employee');
1272 if ($form->{type} eq 'request_quotation') {
1273 $form->{title} = $locale->text('Request for Quotations');
1274 $form->{vc} = 'vendor';
1275 $ordlabel = $locale->text('RFQ Number');
1276 $ordnumber = 'quonumber';
1277 $employee = $locale->text('Employee');
1280 if ($form->{type} eq 'sales_order') {
1281 $form->{title} = $locale->text('Sales Orders');
1282 $form->{vc} = 'customer';
1283 $ordlabel = $locale->text('Order Number');
1284 $ordnumber = 'ordnumber';
1285 $employee = $locale->text('Salesperson');
1288 if ($form->{type} eq 'sales_quotation') {
1289 $form->{title} = $locale->text('Quotations');
1290 $form->{vc} = 'customer';
1291 $ordlabel = $locale->text('Quotation Number');
1292 $ordnumber = 'quonumber';
1293 $employee = $locale->text('Employee');
1296 # setup vendor / customer selection
1297 $form->all_vc(\%myconfig, $form->{vc},
1298 ($form->{vc} eq 'customer') ? "AR" : "AP");
1300 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
1301 @{ $form->{"all_$form->{vc}"} };
1303 $vclabel = ucfirst $form->{vc};
1304 $vclabel = $locale->text($vclabel);
1306 # $locale->text('Vendor')
1307 # $locale->text('Customer')
1311 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
1312 : qq|<input name=$form->{vc} size=35>|;
1315 if (@{ $form->{all_departments} }) {
1316 $form->{selectdepartment} = "<option>\n";
1319 $form->{selectdepartment} .=
1320 "<option>$_->{description}--$_->{id}\n"
1321 } (@{ $form->{all_departments} });
1326 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1327 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1329 | if $form->{selectdepartment};
1332 <input type=hidden name="open" value=1>
1336 if (($form->{"type"} eq "sales_order") ||
1337 ($form->{"type"} eq "purchase_order")) {
1340 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1341 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1342 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1343 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1348 # use JavaScript Calendar or not
1349 $form->{jsscript} = $jscalendar;
1351 if ($form->{jsscript}) {
1353 # with JavaScript Calendar
1355 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1356 <input type=button name=transdatefrom id="trigger3" value=|
1357 . $locale->text('button') . qq|></td>
1360 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1361 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1362 . $locale->text('button') . qq|></td>
1367 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1368 "transdateto", "BL", "trigger4");
1371 # without JavaScript Calendar
1373 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1375 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1383 <form method=post action=$form->{script}>
1387 <th class=listtop>$form->{title}</th>
1389 <tr height="5"></tr>
1394 <th align=right>$vclabel</th>
1395 <td colspan=3>$vc</td>
1399 <th align=right>$ordlabel</th>
1400 <td colspan=3><input name="$ordnumber" size=20></td>
1403 <th align=right>| . $locale->text('From') . qq|</th>
1405 <th align=right>| . $locale->text('Bis') . qq|</th>
1408 <input type=hidden name=sort value=transdate>
1410 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1416 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1417 | . $locale->text('ID') . qq|</td>
1418 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1419 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1420 . $locale->text('Date') . qq|</td>
1421 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1422 . $locale->text('Required by') . qq|</td>
1425 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
1426 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1427 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1428 . $locale->text('Ship via') . qq|</td>
1431 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1432 . $locale->text('Amount') . qq|</td>
1433 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1434 . $locale->text('Tax') . qq|</td>
1435 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1436 . $locale->text('Total') . qq|</td>
1439 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1440 . $locale->text('Subtotal') . qq|</td>
1448 <tr><td colspan=4><hr size=3 noshade></td></tr>
1454 <input type=hidden name=nextsub value=orders>
1455 <input type=hidden name=path value=$form->{path}>
1456 <input type=hidden name=login value=$form->{login}>
1457 <input type=hidden name=password value=$form->{password}>
1458 <input type=hidden name=vc value=$form->{vc}>
1459 <input type=hidden name=type value=$form->{type}>
1461 <input class=submit type=submit name=action value="|
1462 . $locale->text('Continue') . qq|">
1469 $lxdebug->leave_sub();
1473 $lxdebug->enter_sub();
1475 # split vendor / customer
1476 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1477 split(/--/, $form->{ $form->{vc} });
1479 OE->transactions(\%myconfig, \%$form);
1481 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1483 $number = $form->escape($form->{$ordnumber});
1484 $name = $form->escape($form->{ $form->{vc} });
1485 $department = $form->escape($form->{department});
1489 "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}¬delivered=$form->{notdelivered}&delivered=$form->{delivered}&$ordnumber=$number&$form->{vc}=$name&department=$department";
1491 # construct callback
1492 $number = $form->escape($form->{$ordnumber}, 1);
1493 $name = $form->escape($form->{ $form->{vc} }, 1);
1494 $department = $form->escape($form->{department}, 1);
1497 "$form->{script}?path=$form->{path}&action=orders&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&transdatefrom=$form->{transdatefrom}&transdateto=$form->{transdateto}&open=$form->{open}&closed=$form->{closed}¬delivered=$form->{notdelivered}&delivered=$form->{delivered}&$ordnumber=$number&$form->{vc}=$name&department=$department";
1500 $form->sort_columns("transdate", "reqdate", "id", "$ordnumber",
1501 "name", "netamount", "tax", "amount",
1502 "curr", "employee", "shipvia", "open",
1503 "closed", "delivered");
1505 $form->{l_open} = $form->{l_closed} = "Y"
1506 if ($form->{open} && $form->{closed});
1508 $form->{"l_delivered"} = "Y"
1509 if ($form->{"delivered"} && $form->{"notdelivered"});
1511 foreach $item (@columns) {
1512 if ($form->{"l_$item"} eq "Y") {
1513 push @column_index, $item;
1515 # add column to href and callback
1516 $callback .= "&l_$item=Y";
1517 $href .= "&l_$item=Y";
1521 # only show checkboxes if gotten here via sales_order form.
1522 if ($form->{type} =~ /sales_order/) {
1523 unshift @column_index, "ids";
1526 if ($form->{l_subtotal} eq 'Y') {
1527 $callback .= "&l_subtotal=Y";
1528 $href .= "&l_subtotal=Y";
1531 if ($form->{vc} eq 'vendor') {
1532 if ($form->{type} eq 'purchase_order') {
1533 $form->{title} = $locale->text('Purchase Orders');
1535 $form->{title} = $locale->text('Request for Quotations');
1537 $name = $locale->text('Vendor');
1538 $employee = $locale->text('Employee');
1540 if ($form->{vc} eq 'customer') {
1541 if ($form->{type} eq 'sales_order') {
1542 $form->{title} = $locale->text('Sales Orders');
1543 $employee = $locale->text('Salesperson');
1545 $form->{title} = $locale->text('Quotations');
1546 $employee = $locale->text('Employee');
1548 $name = $locale->text('Customer');
1551 $column_header{id} =
1552 qq|<th><a class=listheading href=$href&sort=id>|
1553 . $locale->text('ID')
1555 $column_header{transdate} =
1556 qq|<th><a class=listheading href=$href&sort=transdate>|
1557 . $locale->text('Date')
1559 $column_header{reqdate} =
1560 qq|<th><a class=listheading href=$href&sort=reqdate>|
1561 . $locale->text('Required by')
1563 $column_header{ordnumber} =
1564 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1565 . $locale->text('Order')
1567 $column_header{quonumber} =
1568 qq|<th><a class=listheading href=$href&sort=quonumber>|
1569 . ($form->{"type"} eq "request_quotation" ?
1570 $locale->text('RFQ') :
1571 $locale->text('Quotation'))
1573 $column_header{name} =
1574 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1575 $column_header{netamount} =
1576 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1577 $column_header{tax} =
1578 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1579 $column_header{amount} =
1580 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1581 $column_header{curr} =
1582 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1583 $column_header{shipvia} =
1584 qq|<th><a class=listheading href=$href&sort=shipvia>|
1585 . $locale->text('Ship via')
1587 $column_header{open} =
1588 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1589 $column_header{closed} =
1590 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1591 $column_header{"delivered"} =
1592 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1594 $column_header{employee} =
1595 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1597 $column_header{ids} = qq|<th></th>|;
1599 if ($form->{ $form->{vc} }) {
1600 $option = $locale->text(ucfirst $form->{vc});
1601 $option .= " : $form->{$form->{vc}}";
1603 if ($form->{department}) {
1604 $option .= "\n<br>" if ($option);
1605 ($department) = split /--/, $form->{department};
1606 $option .= $locale->text('Department') . " : $department";
1608 if ($form->{transdatefrom}) {
1610 . $locale->text('From') . " "
1611 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1613 if ($form->{transdateto}) {
1615 . $locale->text('Bis') . " "
1616 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1618 if ($form->{open}) {
1619 $option .= "\n<br>" if ($option);
1620 $option .= $locale->text('Open');
1622 if ($form->{closed}) {
1623 $option .= "\n<br>" if ($option);
1624 $option .= $locale->text('Closed');
1632 <form method="post" action="oe.pl">
1635 <th class=listtop>$form->{title}</th>
1637 <tr height="5"></tr>
1644 <tr class=listheading>|;
1646 map { print "\n$column_header{$_}" } @column_index;
1652 # add sort and escape callback
1653 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1655 if (@{ $form->{OE} }) {
1656 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1661 foreach $oe (@{ $form->{OE} }) {
1662 $form->{rowcount} = ++$j;
1664 if ($form->{l_subtotal} eq 'Y') {
1665 if ($sameitem ne $oe->{ $form->{sort} }) {
1667 $sameitem = $oe->{ $form->{sort} };
1671 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1673 $column_data{netamount} =
1675 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1677 $column_data{tax} = "<td align=right>"
1678 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1681 $column_data{amount} =
1683 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1685 $totalnetamount += $oe->{netamount};
1686 $totalamount += $oe->{amount};
1688 $subtotalnetamount += $oe->{netamount};
1689 $subtotalamount += $oe->{amount};
1692 qq|<td><input name="id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1693 $column_data{id} = "<td>$oe->{id}</td>";
1694 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1695 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1697 $column_data{$ordnumber} =
1698 "<td><a href=oe.pl?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback_escaped>$oe->{$ordnumber}</a></td>";
1699 $column_data{name} = "<td>$oe->{name}</td>";
1701 $column_data{employee} = "<td>$oe->{employee} </td>";
1702 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1704 if ($oe->{closed}) {
1705 $column_data{closed} = "<td align=center>X</td>";
1706 $column_data{open} = "<td> </td>";
1708 $column_data{closed} = "<td> </td>";
1709 $column_data{open} = "<td align=center>X</td>";
1711 $column_data{"delivered"} = "<td>" .
1712 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1718 <tr class=listrow$i>";
1720 map { print "\n$column_data{$_}" } @column_index;
1728 if ($form->{l_subtotal} eq 'Y') {
1734 <tr class=listtotal>|;
1736 map { $column_data{$_} = "<td> </td>" } @column_index;
1738 $column_data{netamount} =
1739 "<th class=listtotal align=right>"
1740 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1741 $column_data{tax} = "<th class=listtotal align=right>"
1742 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1745 $column_data{amount} =
1746 "<th class=listtotal align=right>"
1747 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1749 map { print "\n$column_data{$_}" } @column_index;
1757 <td><hr size=3 noshade></td>
1761 # multiple invoice edit button only if gotten there via sales_order form.
1763 if ($form->{type} =~ /sales_order/) {
1765 <input type="hidden" name="path" value="$form->{path}">
1766 <input class"submit" type="submit" name="action" value="|
1767 . $locale->text('Continue') . qq|">
1768 <input type="hidden" name="nextsub" value="edit">
1769 <input type="hidden" name="type" value="$form->{type}">
1770 <input type="hidden" name="vc" value="$form->{vc}">
1771 <input type="hidden" name="login" value="$form->{login}">
1772 <input type="hidden" name="password" value="$form->{password}">
1773 <input type="hidden" name="callback" value="$callback">
1774 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1781 <form method=post action=$form->{script}>
1783 <input name=callback type=hidden value="$form->{callback}">
1785 <input type=hidden name=type value=$form->{type}>
1786 <input type=hidden name=vc value=$form->{vc}>
1788 <input type=hidden name=path value=$form->{path}>
1789 <input type=hidden name=login value=$form->{login}>
1790 <input type=hidden name=password value=$form->{password}>
1798 $lxdebug->leave_sub();
1802 $lxdebug->enter_sub();
1804 map { $column_data{$_} = "<td> </td>" } @column_index;
1806 $column_data{netamount} =
1807 "<th class=listsubtotal align=right>"
1808 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1810 $column_data{tax} = "<td class=listsubtotal align=right>"
1811 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1814 $column_data{amount} =
1815 "<th class=listsubtotal align=right>"
1816 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1818 $subtotalnetamount = 0;
1819 $subtotalamount = 0;
1822 <tr class=listsubtotal>
1825 map { print "\n$column_data{$_}" } @column_index;
1831 $lxdebug->leave_sub();
1834 sub save_and_close {
1835 $lxdebug->enter_sub();
1837 if ($form->{type} =~ /_order$/) {
1838 $form->isblank("transdate", $locale->text('Order Date missing!'));
1840 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1843 $msg = ucfirst $form->{vc};
1844 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1846 # $locale->text('Customer missing!');
1847 # $locale->text('Vendor missing!');
1849 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1850 if ($form->{currency} ne $form->{defaultcurrency});
1854 # if the name changed get new values
1855 if (&check_name($form->{vc})) {
1860 $form->{id} = 0 if $form->{saveasnew};
1862 # this is for the internal notes section for the [email] Subject
1863 if ($form->{type} =~ /_order$/) {
1864 if ($form->{type} eq 'sales_order') {
1865 $form->{label} = $locale->text('Sales Order');
1867 $numberfld = "sonumber";
1868 $ordnumber = "ordnumber";
1870 $form->{label} = $locale->text('Purchase Order');
1872 $numberfld = "ponumber";
1873 $ordnumber = "ordnumber";
1876 $err = $locale->text('Cannot save order!');
1879 if ($form->{type} eq 'sales_quotation') {
1880 $form->{label} = $locale->text('Quotation');
1882 $numberfld = "sqnumber";
1883 $ordnumber = "quonumber";
1885 $form->{label} = $locale->text('Request for Quotation');
1887 $numberfld = "rfqnumber";
1888 $ordnumber = "quonumber";
1891 $err = $locale->text('Cannot save quotation!');
1895 # get new number in sequence if no number is given or if saveasnew was requested
1896 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1897 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1903 $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
1904 if (OE->save(\%myconfig, \%$form));
1907 $lxdebug->leave_sub();
1911 $lxdebug->enter_sub();
1913 if ($form->{type} =~ /_order$/) {
1914 $form->isblank("transdate", $locale->text('Order Date missing!'));
1916 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1919 $msg = ucfirst $form->{vc};
1920 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1922 # $locale->text('Customer missing!');
1923 # $locale->text('Vendor missing!');
1925 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1926 if ($form->{currency} ne $form->{defaultcurrency});
1930 # if the name changed get new values
1931 if (&check_name($form->{vc})) {
1936 $form->{id} = 0 if $form->{saveasnew};
1938 # this is for the internal notes section for the [email] Subject
1939 if ($form->{type} =~ /_order$/) {
1940 if ($form->{type} eq 'sales_order') {
1941 $form->{label} = $locale->text('Sales Order');
1943 $numberfld = "sonumber";
1944 $ordnumber = "ordnumber";
1946 $form->{label} = $locale->text('Purchase Order');
1948 $numberfld = "ponumber";
1949 $ordnumber = "ordnumber";
1952 $err = $locale->text('Cannot save order!');
1955 if ($form->{type} eq 'sales_quotation') {
1956 $form->{label} = $locale->text('Quotation');
1958 $numberfld = "sqnumber";
1959 $ordnumber = "quonumber";
1961 $form->{label} = $locale->text('Request for Quotation');
1963 $numberfld = "rfqnumber";
1964 $ordnumber = "quonumber";
1967 $err = $locale->text('Cannot save quotation!');
1971 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
1972 unless $form->{$ordnumber};
1976 OE->save(\%myconfig, \%$form);
1977 $form->{simple_save} = 1;
1978 if(!$form->{print_and_save}) {
1979 set_headings("edit");
1983 $lxdebug->leave_sub();
1987 $lxdebug->enter_sub();
1991 if ($form->{type} =~ /_order$/) {
1992 $msg = $locale->text('Are you sure you want to delete Order Number');
1993 $ordnumber = 'ordnumber';
1995 $msg = $locale->text('Are you sure you want to delete Quotation Number');
1996 $ordnumber = 'quonumber';
2002 <form method=post action=$form->{script}>
2005 # delete action variable
2006 map { delete $form->{$_} } qw(action header);
2008 foreach $key (keys %$form) {
2009 $form->{$key} =~ s/\"/"/g;
2010 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2014 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2016 <h4>$msg $form->{$ordnumber}</h4>
2018 <input name=action class=submit type=submit value="|
2019 . $locale->text('Yes') . qq|">
2026 $lxdebug->leave_sub();
2030 $lxdebug->enter_sub();
2032 if ($form->{type} =~ /_order$/) {
2033 $msg = $locale->text('Order deleted!');
2034 $err = $locale->text('Cannot delete order!');
2036 $msg = $locale->text('Quotation deleted!');
2037 $err = $locale->text('Cannot delete quotation!');
2040 $form->redirect($msg) if (OE->delete(\%myconfig, \%$form, $spool));
2043 $lxdebug->leave_sub();
2047 $lxdebug->enter_sub();
2049 if ($form->{type} =~ /_order$/) {
2051 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2052 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2053 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2054 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2056 $form->isblank("transdate", $locale->text('Order Date missing!'))
2057 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2060 # also copy deliverydate from the order
2061 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2062 $form->{orddate} = $form->{transdate};
2064 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2065 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2066 $form->{ordnumber} = "";
2067 $form->{quodate} = $form->{transdate};
2070 # if the name changed get new values
2071 if (&check_name($form->{vc})) {
2076 $form->{cp_id} *= 1;
2078 for $i (1 .. $form->{rowcount}) {
2079 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2080 $form->{"${_}_${i}"})
2081 if ($form->{"${_}_${i}"}) }
2082 qw(ship qty sellprice listprice basefactor));
2085 if ( $form->{type} =~ /_order/
2086 && $form->{currency} ne $form->{defaultcurrency}) {
2088 # check if we need a new exchangerate
2089 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2091 $orddate = $form->current_date(\%myconfig);
2093 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2096 if (!$exchangerate) {
2097 &backorder_exchangerate($orddate, $buysell);
2102 # close orders/quotations
2103 $form->{closed} = 1;
2105 # save order if one ordnumber has been given
2106 # if not it's most likely a collective order, which can't be saved back
2107 # so they just have to be closed
2108 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2109 OE->close_order(\%myconfig, \%$form);
2111 OE->close_orders(\%myconfig, \%$form);
2114 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2116 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2119 $form->{closed} = 0;
2120 $form->{rowcount}--;
2121 $form->{shipto} = 1;
2123 if ($form->{type} =~ /_order$/) {
2124 $form->{exchangerate} = $exchangerate;
2128 if ( $form->{type} eq 'purchase_order'
2129 || $form->{type} eq 'request_quotation') {
2130 $form->{title} = $locale->text('Add Vendor Invoice');
2131 $form->{script} = 'ir.pl';
2135 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2136 $form->{title} = $locale->text('Add Sales Invoice');
2137 $form->{script} = 'is.pl';
2142 # bo creates the id, reset it
2143 map { delete $form->{$_} }
2144 qw(id subject message cc bcc printed emailed queued);
2145 $form->{ $form->{vc} } =~ s/--.*//g;
2146 $form->{type} = "invoice";
2149 $locale = new Locale "$myconfig{countrycode}", "$script";
2151 require "$form->{path}/$form->{script}";
2153 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2155 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2156 qw(creditlimit creditremaining);
2158 $currency = $form->{currency};
2161 $form->{currency} = $currency;
2162 $form->{exchangerate} = "";
2163 $form->{forex} = "";
2164 $form->{exchangerate} = $exchangerate
2168 $form->check_exchangerate(
2169 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2172 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2177 for $i (1 .. $form->{rowcount}) {
2178 $form->{"discount_$i"} =
2179 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2181 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2183 $decimalplaces = ($dec > 2) ? $dec : 2;
2185 # copy delivery date from reqdate for order -> invoice conversion
2186 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2187 unless $form->{"deliverydate_$i"};
2189 $form->{"sellprice_$i"} =
2190 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2193 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2194 $dec_qty = length $dec_qty;
2196 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2198 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2199 qw(partnumber description unit);
2205 $lxdebug->leave_sub();
2208 sub backorder_exchangerate {
2209 $lxdebug->enter_sub();
2210 my ($orddate, $buysell) = @_;
2217 <form method=post action=$form->{script}>
2220 # delete action variable
2221 map { delete $form->{$_} } qw(action header exchangerate);
2223 foreach $key (keys %$form) {
2224 $form->{$key} =~ s/\"/"/g;
2225 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2228 $form->{title} = $locale->text('Add Exchangerate');
2232 <input type=hidden name=path value=$form->{path}>
2233 <input type=hidden name=login value=$form->{login}>
2234 <input type=hidden name=password value=$form->{password}>
2236 <input type=hidden name=exchangeratedate value=$orddate>
2237 <input type=hidden name=buysell value=$buysell>
2240 <tr><th class=listtop>$form->{title}</th></tr>
2241 <tr height="5"></tr>
2246 <th align=right>| . $locale->text('Currency') . qq|</th>
2247 <td>$form->{currency}</td>
2250 <th align=right>| . $locale->text('Date') . qq|</th>
2254 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2255 <td><input name=exchangerate size=11></td>
2265 <input type=hidden name=nextsub value=save_exchangerate>
2267 <input name=action class=submit type=submit value="|
2268 . $locale->text('Continue') . qq|">
2276 $lxdebug->leave_sub();
2279 sub save_exchangerate {
2280 $lxdebug->enter_sub();
2282 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2283 $form->{exchangerate} =
2284 $form->parse_amount(\%myconfig, $form->{exchangerate});
2285 $form->save_exchangerate(\%myconfig, $form->{currency},
2286 $form->{exchangeratedate},
2287 $form->{exchangerate}, $form->{buysell});
2291 $lxdebug->leave_sub();
2294 sub create_backorder {
2295 $lxdebug->enter_sub();
2297 $form->{shipped} = 1;
2299 # figure out if we need to create a backorder
2300 # items aren't saved if qty != 0
2302 for $i (1 .. $form->{rowcount}) {
2303 $totalqty += $qty = $form->{"qty_$i"};
2304 $totalship += $ship = $form->{"ship_$i"};
2306 $form->{"qty_$i"} = $qty - $ship;
2309 if ($totalship == 0) {
2310 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2311 $form->{ordtotal} = 0;
2312 $form->{shipped} = 0;
2316 if ($totalqty == $totalship) {
2317 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2318 $form->{ordtotal} = 0;
2323 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2326 for $i (1 .. $form->{rowcount}) {
2328 $form->{"${_}_$i"} =
2329 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2330 } qw(sellprice discount);
2335 OE->save(\%myconfig, \%$form);
2337 # rebuild rows for invoice
2341 for $i (1 .. $form->{rowcount}) {
2342 $form->{"qty_$i"} = $form->{"ship_$i"};
2344 if ($form->{"qty_$i"}) {
2347 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2352 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2353 $form->{rowcount} = $count;
2355 $lxdebug->leave_sub();
2359 $lxdebug->enter_sub();
2361 $form->{saveasnew} = 1;
2362 $form->{closed} = 0;
2363 map { delete $form->{$_} } qw(printed emailed queued ordnumber quonumber);
2367 $lxdebug->leave_sub();
2370 sub purchase_order {
2371 $lxdebug->enter_sub();
2373 if ( $form->{type} eq 'sales_quotation'
2374 || $form->{type} eq 'request_quotation') {
2375 OE->close_order(\%myconfig, \%$form);
2378 $form->{cp_id} *= 1;
2380 $form->{title} = $locale->text('Add Purchase Order');
2381 $form->{vc} = "vendor";
2382 $form->{type} = "purchase_order";
2386 $lxdebug->leave_sub();
2390 $lxdebug->enter_sub();
2392 if ( $form->{type} eq 'sales_quotation'
2393 || $form->{type} eq 'request_quotation') {
2394 OE->close_order(\%myconfig, $form);
2397 $form->{cp_id} *= 1;
2399 $form->{title} = $locale->text('Add Sales Order');
2400 $form->{vc} = "customer";
2401 $form->{type} = "sales_order";
2405 $lxdebug->leave_sub();
2409 $lxdebug->enter_sub();
2411 $form->{transdate} = $form->current_date(\%myconfig);
2412 delete $form->{duedate};
2414 $form->{closed} = 0;
2417 map { delete $form->{$_} }
2418 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2420 for $i (1 .. $form->{rowcount}) {
2421 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2422 $form->{"${_}_${i}"})
2423 if ($form->{"${_}_${i}"}) }
2424 qw(ship qty sellprice listprice basefactor));
2432 for $i (1 .. $form->{rowcount} - 1) {
2433 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2434 qw(partnumber description unit);
2437 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2438 qw(creditlimit creditremaining);
2442 $lxdebug->leave_sub();