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 $form->get_lists("contacts" => "ALL_CONTACTS",
411 "shipto" => "ALL_SHIPTO",
412 "projects" => { "key" => "ALL_PROJECTS",
414 "old_id" => $form->{"globalproject_id"} });
416 my (%labels, @values);
417 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
418 push(@values, $item->{"cp_id"});
419 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
420 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
423 $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
424 '-labels' => \%labels, '-default' => $form->{"cp_id"});
428 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
429 push(@values, $item->{"shipto_id"});
430 $labels{$item->{"shipto_id"}} =
431 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
436 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
437 push(@values, $item->{"id"});
438 $labels{$item->{"id"}} = $item->{"projectnumber"};
440 my $globalprojectnumber =
441 $cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
442 '-labels' => \%labels,
443 '-default' => $form->{"globalproject_id"});
446 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
448 $cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
449 '-labels' => \%labels, '-default' => $form->{"shipto_id"})
452 $form->{exchangerate} =
453 $form->format_amount(\%myconfig, $form->{exchangerate});
455 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
461 $form->{creditlimit} =
462 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
463 $form->{creditremaining} =
464 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
467 <input type=hidden name=forex value=$form->{forex}>
470 if ($form->{currency} ne $form->{defaultcurrency}) {
471 if ($form->{forex}) {
474 . $locale->text('Exchangerate')
475 . qq|</th><td>$form->{exchangerate}</td>
476 <input type=hidden name=exchangerate value=$form->{exchangerate}>
481 . $locale->text('Exchangerate')
482 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
486 $vclabel = ucfirst $form->{vc};
487 $vclabel = $locale->text($vclabel);
491 if ($form->{business}) {
494 <th align=right>| . $locale->text('Business') . qq|</th>
495 <td>$form->{business}</td>
496 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
498 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
504 if ($form->{max_dunning_level}) {
510 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
511 <td><b>$form->{max_dunning_level}</b></td>
512 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
514 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
523 if (@{ $form->{TAXZONE} }) {
524 $form->{selecttaxzone} = "";
525 foreach $item (@{ $form->{TAXZONE} }) {
526 if ($item->{id} == $form->{taxzone_id}) {
527 $form->{selecttaxzone} .=
528 "<option value=$item->{id} selected>" . H($item->{description}) .
531 $form->{selecttaxzone} .=
532 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
537 $form->{selecttaxzone} =~ s/ selected//g;
538 if ($form->{taxzone_id} ne "") {
539 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}>/value=$form->{taxzone_id} selected>/;
545 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
546 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
547 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
551 if ($form->{type} !~ /_quotation$/) {
554 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
555 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
558 <th width=70% align=right nowrap>|
559 . $locale->text('Quotation Number') . qq|</th>
560 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
563 <th width=70% align=right nowrap>|
564 . $locale->text('Customer Order Number') . qq|</th>
565 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
568 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
573 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
578 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
580 $creditremaining = qq|
586 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
587 <td>$form->{creditlimit}</td>
589 <th nowrap>| . $locale->text('Remaining') . qq|</th>
590 <td class="plus$n" nowrap>$form->{creditremaining}</td>
599 ($form->{type} eq 'sales_quotation')
600 ? $locale->text('Valid until')
601 : $locale->text('Required by');
602 if ($form->{type} eq 'sales_quotation') {
605 <th width=70% align=right nowrap>|
606 . $locale->text('Quotation Number') . qq|</th>
607 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
608 <input type=hidden name=ordnumber value="$form->{ordnumber}">
614 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
615 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
616 <input type=hidden name=ordnumber value="$form->{ordnumber}">
624 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
628 <th align=right nowrap=true>$reqlabel</th>
632 $creditremaining = qq| <tr>
639 ($form->{"select$form->{vc}"})
640 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">|
641 : qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
645 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
646 <td colspan=3><select name=department>$form->{selectdepartment}</select>
647 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
650 | if $form->{selectdepartment};
653 <input type=hidden name=employee value="$form->{employee}">
656 if ($form->{type} eq 'sales_order') {
657 if ($form->{selectemployee}) {
659 <input type=hidden name=customer_klass value=$form->{customer_klass}>
661 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
662 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
663 <input type=hidden name=selectemployee value="$form->{selectemployee}">
670 <input type=hidden name=customer_klass value=$form->{customer_klass}>
672 <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
673 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
674 <input type=hidden name=selectemployee value="$form->{selectemployee}">
679 if ($form->{resubmit} && ($form->{format} eq "html")) {
681 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
682 } elsif ($form->{resubmit}) {
683 $onload = qq|document.oe.submit()|;
688 $credittext = $locale->text('Credit Limit exceeded!!!');
689 if ($creditwarning) {
690 $onload = qq|alert('$credittext')|;
693 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
698 <body onLoad="$onload">
700 <form method=post name=oe action=$form->{script}>
701 <script type="text/javascript" src="js/common.js"></script>
702 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
703 <script type="text/javascript" src="js/vendor_selection.js"></script>
704 <script type="text/javascript" src="js/calculate_qty.js"></script>
706 <input type=hidden name=id value=$form->{id}>
707 <input type=hidden name=action value=$form->{action}>
709 <input type=hidden name=type value=$form->{type}>
710 <input type=hidden name=formname value=$form->{formname}>
711 <input type=hidden name=media value=$form->{media}>
712 <input type=hidden name=format value=$form->{format}>
713 <input type=hidden name=proforma value=$form->{proforma}>
715 <input type=hidden name=queued value="$form->{queued}">
716 <input type=hidden name=printed value="$form->{printed}">
717 <input type=hidden name=emailed value="$form->{emailed}">
719 <input type=hidden name=vc value=$form->{vc}>
721 <input type=hidden name=title value="$form->{title}">
723 <input type=hidden name=discount value=$form->{discount}>
724 <input type=hidden name=creditlimit value=$form->{creditlimit}>
725 <input type=hidden name=creditremaining value=$form->{creditremaining}>
727 <input type=hidden name=tradediscount value=$form->{tradediscount}>
728 <input type=hidden name=business value=$form->{business}>
729 <input type=hidden name=webdav value=$webdav>
733 <th class=listtop>$form->{title}</th>
743 <th align=right>$vclabel</th>
744 <td colspan=3>$vc</td>
745 <input type=hidden name=$form->{vc}_id value=$form->{"$form->{vc}_id"}>
746 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
747 <th align=richt nowrap>|
748 . $locale->text('Contact Person') . qq|</th>
749 <td colspan=3>$contact</td>
757 <th align=right>| . $locale->text('Currency') . qq|</th>
758 <td><select name=currency>$form->{selectcurrency}</select></td>
759 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
760 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
764 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
765 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
768 <th align=right>| . $locale->text('Ship via') . qq|</th>
769 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
776 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
778 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
779 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
783 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
785 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
786 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
799 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
800 <td>$globalprojectnumber</td>
811 <!-- shipto are in hidden variables -->
813 <input type=hidden name=shiptoname value="$form->{shiptoname}">
814 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
815 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
816 <input type=hidden name=shiptocity value="$form->{shiptocity}">
817 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
818 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
819 <input type=hidden name=shiptophone value="$form->{shiptophone}">
820 <input type=hidden name=shiptofax value="$form->{shiptofax}">
821 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
822 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
823 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
825 <!-- email variables -->
826 <input type=hidden name=message value="$form->{message}">
827 <input type=hidden name=email value="$form->{email}">
828 <input type=hidden name=subject value="$form->{subject}">
829 <input type=hidden name=cc value="$form->{cc}">
830 <input type=hidden name=bcc value="$form->{bcc}">
832 <input type=hidden name=taxpart value="$form->{taxpart}">
833 <input type=hidden name=taxservice value="$form->{taxservice}">
835 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
838 foreach $item (split / /, $form->{taxaccounts}) {
840 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
841 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
844 $lxdebug->leave_sub();
848 $lxdebug->enter_sub();
850 $form->{invtotal} = $form->{invsubtotal};
852 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
855 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
858 $rows = ($rows > $introws) ? $rows : $introws;
860 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
862 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
864 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
867 if ($form->{taxaccounts}) {
869 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
870 . $locale->text('Tax Included') . qq|</b><br><br>
874 if (!$form->{taxincluded}) {
876 foreach $item (split / /, $form->{taxaccounts}) {
877 if ($form->{"${item}_base"}) {
878 $form->{invtotal} += $form->{"${item}_total"} =
880 $form->{"${item}_base"} * $form->{"${item}_rate"},
882 $form->{"${item}_total"} =
883 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
887 <th align=right>$form->{"${item}_description"}</th>
888 <td align=right>$form->{"${item}_total"}</td>
894 $form->{invsubtotal} =
895 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
899 <th align=right>| . $locale->text('Subtotal') . qq|</th>
900 <td align=right>$form->{invsubtotal}</td>
906 if ($form->{taxincluded}) {
907 foreach $item (split / /, $form->{taxaccounts}) {
908 if ($form->{"${item}_base"}) {
909 $form->{"${item}_total"} =
911 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
912 (1 + $form->{"${item}_rate"})
915 $form->{"${item}_netto"} =
917 ($form->{"${item}_base"} - $form->{"${item}_total"}),
919 $form->{"${item}_total"} =
920 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
921 $form->{"${item}_netto"} =
922 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
926 <th align=right>Enthaltene $form->{"${item}_description"}</th>
927 <td align=right>$form->{"${item}_total"}</td>
930 <th align=right>Nettobetrag</th>
931 <td align=right>$form->{"${item}_netto"}</td>
939 $form->{oldinvtotal} = $form->{invtotal};
941 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
951 <th align=left>| . $locale->text('Notes') . qq|</th>
952 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
958 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
959 <td><select name=payment_id tabindex=24>$payment
963 <td align=right width=100%>
969 <th align=right>| . $locale->text('Total') . qq|</th>
970 <td align=right>$form->{invtotal}</td>
978 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
979 <input type=hidden name=oldtotalpaid value=$totalpaid>
981 <td><hr size=3 noshade></td>
989 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
992 <td align=left width=30%><b>Dateiname</b></td>
993 <td align=left width=70%><b>Webdavlink</b></td>
995 foreach $file (keys %{ $form->{WEBDAV} }) {
998 <td align=left>$file</td>
999 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1007 <td><hr size=3 noshade></td>
1014 <input type=hidden name=jscalendar value=$form->{jscalendar}>
1027 | . $locale->text("Edit the $form->{type}") . qq|<br>
1028 <input class=submit type=submit name=action id=update_button value="|
1029 . $locale->text('Update') . qq|">
1030 <input class=submit type=submit name=action value="|
1031 . $locale->text('Ship to') . qq|">
1032 <input class=submit type=submit name=action value="|
1033 . $locale->text('Print') . qq|">
1034 <input class=submit type=submit name=action value="|
1035 . $locale->text('E-mail') . qq|">
1036 <input class=submit type=submit name=action value="|
1037 . $locale->text('Save') . qq|">
1038 <input class=submit type=submit name=action value="|
1039 . $locale->text('Save and Close') . qq|">
1042 if (($form->{id})) {
1044 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1045 <input class=submit type=submit name=action value="|
1046 . $locale->text('Save as new') . qq|">
1047 <input class=submit type=submit name=action value="|
1048 . $locale->text('Delete') . qq|">|;
1049 if (($form->{type} =~ /sales_quotation$/)) {
1051 <input class=submit type=submit name=action value="|
1052 . $locale->text('Sales Order') . qq|">|;
1054 if ($form->{type} =~ /request_quotation$/) {
1056 <input class=submit type=submit name=action value="|
1057 . $locale->text('Purchase Order') . qq|">|;
1061 <input class=submit type=submit name=action value="|
1062 . $locale->text('Invoice') . qq|">
1066 if ($form->{type} =~ /sales_order$/) {
1068 <br>$form->{heading} als neue Vorlage verwenden für<br>
1069 <input class=submit type=submit name=action value="|
1070 . $locale->text('Purchase Order') . qq|">
1071 <input class=submit type=submit name=action value="|
1072 . $locale->text('Quotation') . qq|">
1075 } elsif ($form->{type} =~ /purchase_order$/) {
1077 <br>$form->{heading} als neue Vorlage verwenden für<br>
1078 <input class=submit type=submit name=action value="|
1079 . $locale->text('Sales Order') . qq|">
1080 <input class=submit type=submit name=action value="|
1081 . $locale->text('Request for Quotation') . qq|">
1086 <br>$form->{heading} als neue Vorlage verwenden für<br>
1087 <input class=submit type=submit name=action value="|
1088 . $locale->text('Order') . qq|">
1091 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1093 <br>Workflow $form->{heading}<br>
1094 <input class=submit type=submit name=action value="|
1095 . $locale->text('Save as new') . qq|">
1096 <input class=submit type=submit name=action value="|
1097 . $locale->text('Invoice') . qq|">
1103 <input type=hidden name=rowcount value=$form->{rowcount}>
1105 <input name=callback type=hidden value="$form->{callback}">
1107 <input type=hidden name=path value=$form->{path}>
1108 <input type=hidden name=login value=$form->{login}>
1109 <input type=hidden name=password value=$form->{password}>
1116 $lxdebug->leave_sub();
1120 $lxdebug->enter_sub();
1122 set_headings($form->{"id"} ? "edit" : "add");
1124 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1125 qw(exchangerate creditlimit creditremaining);
1126 $form->{update} = 1;
1128 &check_name($form->{vc});
1133 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1134 $form->{exchangerate} = $exchangerate
1138 $form->check_exchangerate(
1139 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1143 $i = $form->{rowcount};
1145 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1147 if ( ($form->{"partnumber_$i"} eq "")
1148 && ($form->{"description_$i"} eq "")
1149 && ($form->{"partsgroup_$i"} eq "")) {
1151 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1156 if ( $form->{type} eq 'purchase_order'
1157 || $form->{type} eq 'request_quotation') {
1158 IR->retrieve_item(\%myconfig, \%$form);
1160 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1161 IS->retrieve_item(\%myconfig, \%$form);
1164 my $rows = scalar @{ $form->{item_list} };
1166 $form->{"discount_$i"} =
1167 $form->format_amount(\%myconfig, $form->{discount} * 100);
1170 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1179 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1180 if ($form->{"not_discountable_$i"}) {
1181 $form->{"discount_$i"} = 0;
1183 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1184 qw(partnumber description unit);
1185 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1186 keys %{ $form->{item_list}[0] };
1187 if ($form->{"part_payment_id_$i"} ne "") {
1188 $form->{payment_id} = $form->{"part_payment_id_$i"};
1191 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1193 ($dec) = ($s =~ /\.(\d+)/);
1195 $decimalplaces = ($dec > 2) ? $dec : 2;
1198 $form->{"sellprice_$i"} = $sellprice;
1201 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1203 # if there is an exchange rate adjust sellprice
1204 $form->{"sellprice_$i"} /= $exchangerate;
1208 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1209 (1 - $form->{"discount_$i"} / 100);
1210 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1211 map { $form->{"${_}_base"} += $amount }
1212 (split / /, $form->{"taxaccounts_$i"});
1213 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1214 split / /, $form->{taxaccounts}
1215 if !$form->{taxincluded};
1217 $form->{creditremaining} -= $amount;
1219 $form->{"sellprice_$i"} =
1220 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1223 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1225 # get pricegroups for parts
1226 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1228 # build up html code for prices_$i
1229 &set_pricegroup($i);
1236 # ok, so this is a new part
1237 # ask if it is a part or service item
1239 if ( $form->{"partsgroup_$i"}
1240 && ($form->{"partsnumber_$i"} eq "")
1241 && ($form->{"description_$i"} eq "")) {
1242 $form->{rowcount}--;
1243 $form->{"discount_$i"} = "";
1247 $form->{"id_$i"} = 0;
1248 $form->{"unit_$i"} = $locale->text('ea');
1256 $lxdebug->leave_sub();
1260 $lxdebug->enter_sub();
1262 if ($form->{type} eq 'purchase_order') {
1263 $form->{title} = $locale->text('Purchase Orders');
1264 $form->{vc} = 'vendor';
1265 $ordlabel = $locale->text('Order Number');
1266 $ordnumber = 'ordnumber';
1267 $employee = $locale->text('Employee');
1270 if ($form->{type} eq 'request_quotation') {
1271 $form->{title} = $locale->text('Request for Quotations');
1272 $form->{vc} = 'vendor';
1273 $ordlabel = $locale->text('RFQ Number');
1274 $ordnumber = 'quonumber';
1275 $employee = $locale->text('Employee');
1278 if ($form->{type} eq 'sales_order') {
1279 $form->{title} = $locale->text('Sales Orders');
1280 $form->{vc} = 'customer';
1281 $ordlabel = $locale->text('Order Number');
1282 $ordnumber = 'ordnumber';
1283 $employee = $locale->text('Salesperson');
1286 if ($form->{type} eq 'sales_quotation') {
1287 $form->{title} = $locale->text('Quotations');
1288 $form->{vc} = 'customer';
1289 $ordlabel = $locale->text('Quotation Number');
1290 $ordnumber = 'quonumber';
1291 $employee = $locale->text('Employee');
1294 # setup vendor / customer selection
1295 $form->all_vc(\%myconfig, $form->{vc},
1296 ($form->{vc} eq 'customer') ? "AR" : "AP");
1298 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
1299 @{ $form->{"all_$form->{vc}"} };
1301 $vclabel = ucfirst $form->{vc};
1302 $vclabel = $locale->text($vclabel);
1304 # $locale->text('Vendor')
1305 # $locale->text('Customer')
1309 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
1310 : qq|<input name=$form->{vc} size=35>|;
1313 if (@{ $form->{all_departments} }) {
1314 $form->{selectdepartment} = "<option>\n";
1317 $form->{selectdepartment} .=
1318 "<option>$_->{description}--$_->{id}\n"
1319 } (@{ $form->{all_departments} });
1324 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1325 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1327 | if $form->{selectdepartment};
1330 <input type=hidden name="open" value=1>
1334 if (($form->{"type"} eq "sales_order") ||
1335 ($form->{"type"} eq "purchase_order")) {
1338 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1339 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1340 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1341 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1346 # use JavaScript Calendar or not
1347 $form->{jsscript} = $jscalendar;
1349 if ($form->{jsscript}) {
1351 # with JavaScript Calendar
1353 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1354 <input type=button name=transdatefrom id="trigger3" value=|
1355 . $locale->text('button') . qq|></td>
1358 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1359 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1360 . $locale->text('button') . qq|></td>
1365 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1366 "transdateto", "BL", "trigger4");
1369 # without JavaScript Calendar
1371 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1373 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1381 <form method=post action=$form->{script}>
1385 <th class=listtop>$form->{title}</th>
1387 <tr height="5"></tr>
1392 <th align=right>$vclabel</th>
1393 <td colspan=3>$vc</td>
1397 <th align=right>$ordlabel</th>
1398 <td colspan=3><input name="$ordnumber" size=20></td>
1401 <th align=right>| . $locale->text('From') . qq|</th>
1403 <th align=right>| . $locale->text('Bis') . qq|</th>
1406 <input type=hidden name=sort value=transdate>
1408 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1414 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1415 | . $locale->text('ID') . qq|</td>
1416 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1417 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1418 . $locale->text('Date') . qq|</td>
1419 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1420 . $locale->text('Required by') . qq|</td>
1423 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
1424 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1425 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1426 . $locale->text('Ship via') . qq|</td>
1429 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1430 . $locale->text('Amount') . qq|</td>
1431 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1432 . $locale->text('Tax') . qq|</td>
1433 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1434 . $locale->text('Total') . qq|</td>
1437 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1438 . $locale->text('Subtotal') . qq|</td>
1446 <tr><td colspan=4><hr size=3 noshade></td></tr>
1452 <input type=hidden name=nextsub value=orders>
1453 <input type=hidden name=path value=$form->{path}>
1454 <input type=hidden name=login value=$form->{login}>
1455 <input type=hidden name=password value=$form->{password}>
1456 <input type=hidden name=vc value=$form->{vc}>
1457 <input type=hidden name=type value=$form->{type}>
1459 <input class=submit type=submit name=action value="|
1460 . $locale->text('Continue') . qq|">
1467 $lxdebug->leave_sub();
1471 $lxdebug->enter_sub();
1473 # split vendor / customer
1474 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1475 split(/--/, $form->{ $form->{vc} });
1477 OE->transactions(\%myconfig, \%$form);
1479 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1481 $number = $form->escape($form->{$ordnumber});
1482 $name = $form->escape($form->{ $form->{vc} });
1483 $department = $form->escape($form->{department});
1487 "$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";
1489 # construct callback
1490 $number = $form->escape($form->{$ordnumber}, 1);
1491 $name = $form->escape($form->{ $form->{vc} }, 1);
1492 $department = $form->escape($form->{department}, 1);
1495 "$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";
1498 $form->sort_columns("transdate", "reqdate", "id", "$ordnumber",
1499 "name", "netamount", "tax", "amount",
1500 "curr", "employee", "shipvia", "open",
1501 "closed", "delivered");
1503 $form->{l_open} = $form->{l_closed} = "Y"
1504 if ($form->{open} && $form->{closed});
1506 $form->{"l_delivered"} = "Y"
1507 if ($form->{"delivered"} && $form->{"notdelivered"});
1509 foreach $item (@columns) {
1510 if ($form->{"l_$item"} eq "Y") {
1511 push @column_index, $item;
1513 # add column to href and callback
1514 $callback .= "&l_$item=Y";
1515 $href .= "&l_$item=Y";
1519 # only show checkboxes if gotten here via sales_order form.
1520 if ($form->{type} =~ /sales_order/) {
1521 unshift @column_index, "ids";
1524 if ($form->{l_subtotal} eq 'Y') {
1525 $callback .= "&l_subtotal=Y";
1526 $href .= "&l_subtotal=Y";
1529 if ($form->{vc} eq 'vendor') {
1530 if ($form->{type} eq 'purchase_order') {
1531 $form->{title} = $locale->text('Purchase Orders');
1533 $form->{title} = $locale->text('Request for Quotations');
1535 $name = $locale->text('Vendor');
1536 $employee = $locale->text('Employee');
1538 if ($form->{vc} eq 'customer') {
1539 if ($form->{type} eq 'sales_order') {
1540 $form->{title} = $locale->text('Sales Orders');
1541 $employee = $locale->text('Salesperson');
1543 $form->{title} = $locale->text('Quotations');
1544 $employee = $locale->text('Employee');
1546 $name = $locale->text('Customer');
1549 $column_header{id} =
1550 qq|<th><a class=listheading href=$href&sort=id>|
1551 . $locale->text('ID')
1553 $column_header{transdate} =
1554 qq|<th><a class=listheading href=$href&sort=transdate>|
1555 . $locale->text('Date')
1557 $column_header{reqdate} =
1558 qq|<th><a class=listheading href=$href&sort=reqdate>|
1559 . $locale->text('Required by')
1561 $column_header{ordnumber} =
1562 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1563 . $locale->text('Order')
1565 $column_header{quonumber} =
1566 qq|<th><a class=listheading href=$href&sort=quonumber>|
1567 . ($form->{"type"} eq "request_quotation" ?
1568 $locale->text('RFQ') :
1569 $locale->text('Quotation'))
1571 $column_header{name} =
1572 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1573 $column_header{netamount} =
1574 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1575 $column_header{tax} =
1576 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1577 $column_header{amount} =
1578 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1579 $column_header{curr} =
1580 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1581 $column_header{shipvia} =
1582 qq|<th><a class=listheading href=$href&sort=shipvia>|
1583 . $locale->text('Ship via')
1585 $column_header{open} =
1586 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1587 $column_header{closed} =
1588 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1589 $column_header{"delivered"} =
1590 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1592 $column_header{employee} =
1593 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1595 $column_header{ids} = qq|<th></th>|;
1597 if ($form->{ $form->{vc} }) {
1598 $option = $locale->text(ucfirst $form->{vc});
1599 $option .= " : $form->{$form->{vc}}";
1601 if ($form->{department}) {
1602 $option .= "\n<br>" if ($option);
1603 ($department) = split /--/, $form->{department};
1604 $option .= $locale->text('Department') . " : $department";
1606 if ($form->{transdatefrom}) {
1608 . $locale->text('From') . " "
1609 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1611 if ($form->{transdateto}) {
1613 . $locale->text('Bis') . " "
1614 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1616 if ($form->{open}) {
1617 $option .= "\n<br>" if ($option);
1618 $option .= $locale->text('Open');
1620 if ($form->{closed}) {
1621 $option .= "\n<br>" if ($option);
1622 $option .= $locale->text('Closed');
1630 <form method="post" action="oe.pl">
1633 <th class=listtop>$form->{title}</th>
1635 <tr height="5"></tr>
1642 <tr class=listheading>|;
1644 map { print "\n$column_header{$_}" } @column_index;
1650 # add sort and escape callback
1651 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1653 if (@{ $form->{OE} }) {
1654 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1659 foreach $oe (@{ $form->{OE} }) {
1660 $form->{rowcount} = ++$j;
1662 if ($form->{l_subtotal} eq 'Y') {
1663 if ($sameitem ne $oe->{ $form->{sort} }) {
1665 $sameitem = $oe->{ $form->{sort} };
1669 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1671 $column_data{netamount} =
1673 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1675 $column_data{tax} = "<td align=right>"
1676 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1679 $column_data{amount} =
1681 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1683 $totalnetamount += $oe->{netamount};
1684 $totalamount += $oe->{amount};
1686 $subtotalnetamount += $oe->{netamount};
1687 $subtotalamount += $oe->{amount};
1690 qq|<td><input name="id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1691 $column_data{id} = "<td>$oe->{id}</td>";
1692 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1693 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1695 $column_data{$ordnumber} =
1696 "<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>";
1697 $column_data{name} = "<td>$oe->{name}</td>";
1699 $column_data{employee} = "<td>$oe->{employee} </td>";
1700 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1702 if ($oe->{closed}) {
1703 $column_data{closed} = "<td align=center>X</td>";
1704 $column_data{open} = "<td> </td>";
1706 $column_data{closed} = "<td> </td>";
1707 $column_data{open} = "<td align=center>X</td>";
1709 $column_data{"delivered"} = "<td>" .
1710 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1716 <tr class=listrow$i>";
1718 map { print "\n$column_data{$_}" } @column_index;
1726 if ($form->{l_subtotal} eq 'Y') {
1732 <tr class=listtotal>|;
1734 map { $column_data{$_} = "<td> </td>" } @column_index;
1736 $column_data{netamount} =
1737 "<th class=listtotal align=right>"
1738 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1739 $column_data{tax} = "<th class=listtotal align=right>"
1740 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1743 $column_data{amount} =
1744 "<th class=listtotal align=right>"
1745 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1747 map { print "\n$column_data{$_}" } @column_index;
1755 <td><hr size=3 noshade></td>
1759 # multiple invoice edit button only if gotten there via sales_order form.
1761 if ($form->{type} =~ /sales_order/) {
1763 <input type="hidden" name="path" value="$form->{path}">
1764 <input class"submit" type="submit" name="action" value="|
1765 . $locale->text('Continue') . qq|">
1766 <input type="hidden" name="nextsub" value="edit">
1767 <input type="hidden" name="type" value="$form->{type}">
1768 <input type="hidden" name="vc" value="$form->{vc}">
1769 <input type="hidden" name="login" value="$form->{login}">
1770 <input type="hidden" name="password" value="$form->{password}">
1771 <input type="hidden" name="callback" value="$callback">
1772 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1779 <form method=post action=$form->{script}>
1781 <input name=callback type=hidden value="$form->{callback}">
1783 <input type=hidden name=type value=$form->{type}>
1784 <input type=hidden name=vc value=$form->{vc}>
1786 <input type=hidden name=path value=$form->{path}>
1787 <input type=hidden name=login value=$form->{login}>
1788 <input type=hidden name=password value=$form->{password}>
1796 $lxdebug->leave_sub();
1800 $lxdebug->enter_sub();
1802 map { $column_data{$_} = "<td> </td>" } @column_index;
1804 $column_data{netamount} =
1805 "<th class=listsubtotal align=right>"
1806 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1808 $column_data{tax} = "<td class=listsubtotal align=right>"
1809 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1812 $column_data{amount} =
1813 "<th class=listsubtotal align=right>"
1814 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1816 $subtotalnetamount = 0;
1817 $subtotalamount = 0;
1820 <tr class=listsubtotal>
1823 map { print "\n$column_data{$_}" } @column_index;
1829 $lxdebug->leave_sub();
1832 sub save_and_close {
1833 $lxdebug->enter_sub();
1835 if ($form->{type} =~ /_order$/) {
1836 $form->isblank("transdate", $locale->text('Order Date missing!'));
1838 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1841 $msg = ucfirst $form->{vc};
1842 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1844 # $locale->text('Customer missing!');
1845 # $locale->text('Vendor missing!');
1847 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1848 if ($form->{currency} ne $form->{defaultcurrency});
1852 # if the name changed get new values
1853 if (&check_name($form->{vc})) {
1858 $form->{id} = 0 if $form->{saveasnew};
1860 # this is for the internal notes section for the [email] Subject
1861 if ($form->{type} =~ /_order$/) {
1862 if ($form->{type} eq 'sales_order') {
1863 $form->{label} = $locale->text('Sales Order');
1865 $numberfld = "sonumber";
1866 $ordnumber = "ordnumber";
1868 $form->{label} = $locale->text('Purchase Order');
1870 $numberfld = "ponumber";
1871 $ordnumber = "ordnumber";
1874 $err = $locale->text('Cannot save order!');
1877 if ($form->{type} eq 'sales_quotation') {
1878 $form->{label} = $locale->text('Quotation');
1880 $numberfld = "sqnumber";
1881 $ordnumber = "quonumber";
1883 $form->{label} = $locale->text('Request for Quotation');
1885 $numberfld = "rfqnumber";
1886 $ordnumber = "quonumber";
1889 $err = $locale->text('Cannot save quotation!');
1893 # get new number in sequence if no number is given or if saveasnew was requested
1894 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1895 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1901 $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
1902 if (OE->save(\%myconfig, \%$form));
1905 $lxdebug->leave_sub();
1909 $lxdebug->enter_sub();
1911 if ($form->{type} =~ /_order$/) {
1912 $form->isblank("transdate", $locale->text('Order Date missing!'));
1914 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1917 $msg = ucfirst $form->{vc};
1918 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1920 # $locale->text('Customer missing!');
1921 # $locale->text('Vendor missing!');
1923 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1924 if ($form->{currency} ne $form->{defaultcurrency});
1928 # if the name changed get new values
1929 if (&check_name($form->{vc})) {
1934 $form->{id} = 0 if $form->{saveasnew};
1936 # this is for the internal notes section for the [email] Subject
1937 if ($form->{type} =~ /_order$/) {
1938 if ($form->{type} eq 'sales_order') {
1939 $form->{label} = $locale->text('Sales Order');
1941 $numberfld = "sonumber";
1942 $ordnumber = "ordnumber";
1944 $form->{label} = $locale->text('Purchase Order');
1946 $numberfld = "ponumber";
1947 $ordnumber = "ordnumber";
1950 $err = $locale->text('Cannot save order!');
1953 if ($form->{type} eq 'sales_quotation') {
1954 $form->{label} = $locale->text('Quotation');
1956 $numberfld = "sqnumber";
1957 $ordnumber = "quonumber";
1959 $form->{label} = $locale->text('Request for Quotation');
1961 $numberfld = "rfqnumber";
1962 $ordnumber = "quonumber";
1965 $err = $locale->text('Cannot save quotation!');
1969 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
1970 unless $form->{$ordnumber};
1974 OE->save(\%myconfig, \%$form);
1975 $form->{simple_save} = 1;
1976 if(!$form->{print_and_save}) {
1977 set_headings("edit");
1981 $lxdebug->leave_sub();
1985 $lxdebug->enter_sub();
1989 if ($form->{type} =~ /_order$/) {
1990 $msg = $locale->text('Are you sure you want to delete Order Number');
1991 $ordnumber = 'ordnumber';
1993 $msg = $locale->text('Are you sure you want to delete Quotation Number');
1994 $ordnumber = 'quonumber';
2000 <form method=post action=$form->{script}>
2003 # delete action variable
2004 map { delete $form->{$_} } qw(action header);
2006 foreach $key (keys %$form) {
2007 $form->{$key} =~ s/\"/"/g;
2008 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2012 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2014 <h4>$msg $form->{$ordnumber}</h4>
2016 <input name=action class=submit type=submit value="|
2017 . $locale->text('Yes') . qq|">
2024 $lxdebug->leave_sub();
2028 $lxdebug->enter_sub();
2030 if ($form->{type} =~ /_order$/) {
2031 $msg = $locale->text('Order deleted!');
2032 $err = $locale->text('Cannot delete order!');
2034 $msg = $locale->text('Quotation deleted!');
2035 $err = $locale->text('Cannot delete quotation!');
2038 $form->redirect($msg) if (OE->delete(\%myconfig, \%$form, $spool));
2041 $lxdebug->leave_sub();
2045 $lxdebug->enter_sub();
2047 if ($form->{type} =~ /_order$/) {
2049 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2050 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2051 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2052 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2054 $form->isblank("transdate", $locale->text('Order Date missing!'))
2055 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2058 # also copy deliverydate from the order
2059 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2060 $form->{orddate} = $form->{transdate};
2062 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2063 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2064 $form->{ordnumber} = "";
2065 $form->{quodate} = $form->{transdate};
2068 # if the name changed get new values
2069 if (&check_name($form->{vc})) {
2074 $form->{cp_id} *= 1;
2076 for $i (1 .. $form->{rowcount}) {
2077 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2078 $form->{"${_}_${i}"})
2079 if ($form->{"${_}_${i}"}) }
2080 qw(ship qty sellprice listprice basefactor));
2083 if ( $form->{type} =~ /_order/
2084 && $form->{currency} ne $form->{defaultcurrency}) {
2086 # check if we need a new exchangerate
2087 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2089 $orddate = $form->current_date(\%myconfig);
2091 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2094 if (!$exchangerate) {
2095 &backorder_exchangerate($orddate, $buysell);
2100 # close orders/quotations
2101 $form->{closed} = 1;
2103 # save order if one ordnumber has been given
2104 # if not it's most likely a collective order, which can't be saved back
2105 # so they just have to be closed
2106 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2107 OE->close_order(\%myconfig, \%$form);
2109 OE->close_orders(\%myconfig, \%$form);
2112 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2114 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2117 $form->{closed} = 0;
2118 $form->{rowcount}--;
2119 $form->{shipto} = 1;
2121 if ($form->{type} =~ /_order$/) {
2122 $form->{exchangerate} = $exchangerate;
2126 if ( $form->{type} eq 'purchase_order'
2127 || $form->{type} eq 'request_quotation') {
2128 $form->{title} = $locale->text('Add Vendor Invoice');
2129 $form->{script} = 'ir.pl';
2133 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2134 $form->{title} = $locale->text('Add Sales Invoice');
2135 $form->{script} = 'is.pl';
2140 # bo creates the id, reset it
2141 map { delete $form->{$_} }
2142 qw(id subject message cc bcc printed emailed queued);
2143 $form->{ $form->{vc} } =~ s/--.*//g;
2144 $form->{type} = "invoice";
2147 $locale = new Locale "$myconfig{countrycode}", "$script";
2149 require "$form->{path}/$form->{script}";
2151 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2153 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2154 qw(creditlimit creditremaining);
2156 $currency = $form->{currency};
2159 $form->{currency} = $currency;
2160 $form->{exchangerate} = "";
2161 $form->{forex} = "";
2162 $form->{exchangerate} = $exchangerate
2166 $form->check_exchangerate(
2167 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2170 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2175 for $i (1 .. $form->{rowcount}) {
2176 $form->{"discount_$i"} =
2177 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2179 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2181 $decimalplaces = ($dec > 2) ? $dec : 2;
2183 # copy delivery date from reqdate for order -> invoice conversion
2184 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2185 unless $form->{"deliverydate_$i"};
2187 $form->{"sellprice_$i"} =
2188 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2191 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2192 $dec_qty = length $dec_qty;
2194 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2196 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2197 qw(partnumber description unit);
2203 $lxdebug->leave_sub();
2206 sub backorder_exchangerate {
2207 $lxdebug->enter_sub();
2208 my ($orddate, $buysell) = @_;
2215 <form method=post action=$form->{script}>
2218 # delete action variable
2219 map { delete $form->{$_} } qw(action header exchangerate);
2221 foreach $key (keys %$form) {
2222 $form->{$key} =~ s/\"/"/g;
2223 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2226 $form->{title} = $locale->text('Add Exchangerate');
2230 <input type=hidden name=path value=$form->{path}>
2231 <input type=hidden name=login value=$form->{login}>
2232 <input type=hidden name=password value=$form->{password}>
2234 <input type=hidden name=exchangeratedate value=$orddate>
2235 <input type=hidden name=buysell value=$buysell>
2238 <tr><th class=listtop>$form->{title}</th></tr>
2239 <tr height="5"></tr>
2244 <th align=right>| . $locale->text('Currency') . qq|</th>
2245 <td>$form->{currency}</td>
2248 <th align=right>| . $locale->text('Date') . qq|</th>
2252 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2253 <td><input name=exchangerate size=11></td>
2263 <input type=hidden name=nextsub value=save_exchangerate>
2265 <input name=action class=submit type=submit value="|
2266 . $locale->text('Continue') . qq|">
2274 $lxdebug->leave_sub();
2277 sub save_exchangerate {
2278 $lxdebug->enter_sub();
2280 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2281 $form->{exchangerate} =
2282 $form->parse_amount(\%myconfig, $form->{exchangerate});
2283 $form->save_exchangerate(\%myconfig, $form->{currency},
2284 $form->{exchangeratedate},
2285 $form->{exchangerate}, $form->{buysell});
2289 $lxdebug->leave_sub();
2292 sub create_backorder {
2293 $lxdebug->enter_sub();
2295 $form->{shipped} = 1;
2297 # figure out if we need to create a backorder
2298 # items aren't saved if qty != 0
2300 for $i (1 .. $form->{rowcount}) {
2301 $totalqty += $qty = $form->{"qty_$i"};
2302 $totalship += $ship = $form->{"ship_$i"};
2304 $form->{"qty_$i"} = $qty - $ship;
2307 if ($totalship == 0) {
2308 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2309 $form->{ordtotal} = 0;
2310 $form->{shipped} = 0;
2314 if ($totalqty == $totalship) {
2315 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2316 $form->{ordtotal} = 0;
2321 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2324 for $i (1 .. $form->{rowcount}) {
2326 $form->{"${_}_$i"} =
2327 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2328 } qw(sellprice discount);
2333 OE->save(\%myconfig, \%$form);
2335 # rebuild rows for invoice
2339 for $i (1 .. $form->{rowcount}) {
2340 $form->{"qty_$i"} = $form->{"ship_$i"};
2342 if ($form->{"qty_$i"}) {
2345 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2350 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2351 $form->{rowcount} = $count;
2353 $lxdebug->leave_sub();
2357 $lxdebug->enter_sub();
2359 $form->{saveasnew} = 1;
2360 $form->{closed} = 0;
2361 map { delete $form->{$_} } qw(printed emailed queued ordnumber quonumber);
2365 $lxdebug->leave_sub();
2368 sub purchase_order {
2369 $lxdebug->enter_sub();
2371 if ( $form->{type} eq 'sales_quotation'
2372 || $form->{type} eq 'request_quotation') {
2373 OE->close_order(\%myconfig, \%$form);
2376 $form->{cp_id} *= 1;
2378 $form->{title} = $locale->text('Add Purchase Order');
2379 $form->{vc} = "vendor";
2380 $form->{type} = "purchase_order";
2384 $lxdebug->leave_sub();
2388 $lxdebug->enter_sub();
2390 if ( $form->{type} eq 'sales_quotation'
2391 || $form->{type} eq 'request_quotation') {
2392 OE->close_order(\%myconfig, $form);
2395 $form->{cp_id} *= 1;
2397 $form->{title} = $locale->text('Add Sales Order');
2398 $form->{vc} = "customer";
2399 $form->{type} = "sales_order";
2403 $lxdebug->leave_sub();
2407 $lxdebug->enter_sub();
2409 $form->{transdate} = $form->current_date(\%myconfig);
2410 delete $form->{duedate};
2412 $form->{closed} = 0;
2415 map { delete $form->{$_} }
2416 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2418 for $i (1 .. $form->{rowcount}) {
2419 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2420 $form->{"${_}_${i}"})
2421 if ($form->{"${_}_${i}"}) }
2422 qw(ship qty sellprice listprice basefactor));
2430 for $i (1 .. $form->{rowcount} - 1) {
2431 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2432 qw(partnumber description unit);
2435 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2436 qw(creditlimit creditremaining);
2440 $lxdebug->leave_sub();