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|ship)_(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");
413 my (%labels, @values);
414 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
415 push(@values, $item->{"cp_id"});
416 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
417 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
420 $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
421 '-labels' => \%labels, '-default' => $form->{"cp_id"});
425 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
426 push(@values, $item->{"shipto_id"});
427 $labels{$item->{"shipto_id"}} =
428 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
432 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
434 $cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
435 '-labels' => \%labels, '-default' => $form->{"shipto_id"})
438 $form->{exchangerate} =
439 $form->format_amount(\%myconfig, $form->{exchangerate});
441 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
447 $form->{creditlimit} =
448 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
449 $form->{creditremaining} =
450 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
453 <input type=hidden name=forex value=$form->{forex}>
456 if ($form->{currency} ne $form->{defaultcurrency}) {
457 if ($form->{forex}) {
460 . $locale->text('Exchangerate')
461 . qq|</th><td>$form->{exchangerate}</td>
462 <input type=hidden name=exchangerate value=$form->{exchangerate}>
467 . $locale->text('Exchangerate')
468 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
472 $vclabel = ucfirst $form->{vc};
473 $vclabel = $locale->text($vclabel);
477 if ($form->{business}) {
480 <th align=right>| . $locale->text('Business') . qq|</th>
481 <td>$form->{business}</td>
482 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
484 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
490 if ($form->{max_dunning_level}) {
496 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
497 <td><b>$form->{max_dunning_level}</b></td>
498 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
500 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
509 if (@{ $form->{TAXZONE} }) {
510 $form->{selecttaxzone} = "";
511 foreach $item (@{ $form->{TAXZONE} }) {
512 if ($item->{id} == $form->{taxzone_id}) {
513 $form->{selecttaxzone} .=
514 "<option value=$item->{id} selected>" . H($item->{description}) .
517 $form->{selecttaxzone} .=
518 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
523 $form->{selecttaxzone} =~ s/ selected//g;
524 if ($form->{taxzone_id} ne "") {
525 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}>/value=$form->{taxzone_id} selected>/;
531 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
532 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
533 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
537 if ($form->{type} !~ /_quotation$/) {
540 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
541 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
544 <th width=70% align=right nowrap>|
545 . $locale->text('Quotation Number') . qq|</th>
546 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
549 <th width=70% align=right nowrap>|
550 . $locale->text('Customer Order Number') . qq|</th>
551 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
554 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
559 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
564 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
566 $creditremaining = qq|
572 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
573 <td>$form->{creditlimit}</td>
575 <th nowrap>| . $locale->text('Remaining') . qq|</th>
576 <td class="plus$n" nowrap>$form->{creditremaining}</td>
585 ($form->{type} eq 'sales_quotation')
586 ? $locale->text('Valid until')
587 : $locale->text('Required by');
588 if ($form->{type} eq 'sales_quotation') {
591 <th width=70% align=right nowrap>|
592 . $locale->text('Quotation Number') . qq|</th>
593 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
594 <input type=hidden name=ordnumber value="$form->{ordnumber}">
600 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
601 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
602 <input type=hidden name=ordnumber value="$form->{ordnumber}">
610 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
614 <th align=right nowrap=true>$reqlabel</th>
618 $creditremaining = qq| <tr>
625 ($form->{"select$form->{vc}"})
626 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">|
627 : qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
631 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
632 <td colspan=3><select name=department>$form->{selectdepartment}</select>
633 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
636 | if $form->{selectdepartment};
639 <input type=hidden name=employee value="$form->{employee}">
642 if ($form->{type} eq 'sales_order') {
643 if ($form->{selectemployee}) {
645 <input type=hidden name=customer_klass value=$form->{customer_klass}>
647 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
648 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
649 <input type=hidden name=selectemployee value="$form->{selectemployee}">
656 <input type=hidden name=customer_klass value=$form->{customer_klass}>
658 <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
659 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
660 <input type=hidden name=selectemployee value="$form->{selectemployee}">
665 if ($form->{resubmit} && ($form->{format} eq "html")) {
667 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
668 } elsif ($form->{resubmit}) {
669 $onload = qq|document.oe.submit()|;
674 $credittext = $locale->text('Credit Limit exceeded!!!');
675 if ($creditwarning) {
676 $onload = qq|alert('$credittext')|;
679 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
684 <body onLoad="$onload">
686 <form method=post name=oe action=$form->{script}>
687 <script type="text/javascript" src="js/common.js"></script>
688 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
689 <script type="text/javascript" src="js/vendor_selection.js"></script>
690 <script type="text/javascript" src="js/calculate_qty.js"></script>
692 <input type=hidden name=id value=$form->{id}>
693 <input type=hidden name=action value=$form->{action}>
695 <input type=hidden name=type value=$form->{type}>
696 <input type=hidden name=formname value=$form->{formname}>
697 <input type=hidden name=media value=$form->{media}>
698 <input type=hidden name=format value=$form->{format}>
699 <input type=hidden name=proforma value=$form->{proforma}>
701 <input type=hidden name=queued value="$form->{queued}">
702 <input type=hidden name=printed value="$form->{printed}">
703 <input type=hidden name=emailed value="$form->{emailed}">
705 <input type=hidden name=vc value=$form->{vc}>
707 <input type=hidden name=title value="$form->{title}">
709 <input type=hidden name=discount value=$form->{discount}>
710 <input type=hidden name=creditlimit value=$form->{creditlimit}>
711 <input type=hidden name=creditremaining value=$form->{creditremaining}>
713 <input type=hidden name=tradediscount value=$form->{tradediscount}>
714 <input type=hidden name=business value=$form->{business}>
715 <input type=hidden name=webdav value=$webdav>
719 <th class=listtop>$form->{title}</th>
729 <th align=right>$vclabel</th>
730 <td colspan=3>$vc</td>
731 <input type=hidden name=$form->{vc}_id value=$form->{"$form->{vc}_id"}>
732 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
733 <th align=richt nowrap>|
734 . $locale->text('Contact Person') . qq|</th>
735 <td colspan=3>$contact</td>
743 <th align=right>| . $locale->text('Currency') . qq|</th>
744 <td><select name=currency>$form->{selectcurrency}</select></td>
745 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
746 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
750 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
751 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
754 <th align=right>| . $locale->text('Ship via') . qq|</th>
755 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
762 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
764 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
765 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
769 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
771 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
772 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
793 <!-- shipto are in hidden variables -->
795 <input type=hidden name=shiptoname value="$form->{shiptoname}">
796 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
797 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
798 <input type=hidden name=shiptocity value="$form->{shiptocity}">
799 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
800 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
801 <input type=hidden name=shiptophone value="$form->{shiptophone}">
802 <input type=hidden name=shiptofax value="$form->{shiptofax}">
803 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
804 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
805 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
807 <!-- email variables -->
808 <input type=hidden name=message value="$form->{message}">
809 <input type=hidden name=email value="$form->{email}">
810 <input type=hidden name=subject value="$form->{subject}">
811 <input type=hidden name=cc value="$form->{cc}">
812 <input type=hidden name=bcc value="$form->{bcc}">
814 <input type=hidden name=taxpart value="$form->{taxpart}">
815 <input type=hidden name=taxservice value="$form->{taxservice}">
817 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
820 foreach $item (split / /, $form->{taxaccounts}) {
822 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
823 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
826 $lxdebug->leave_sub();
830 $lxdebug->enter_sub();
832 $form->{invtotal} = $form->{invsubtotal};
834 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
837 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
840 $rows = ($rows > $introws) ? $rows : $introws;
842 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
844 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
846 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
849 if ($form->{taxaccounts}) {
851 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
852 . $locale->text('Tax Included') . qq|</b><br><br>
856 if (!$form->{taxincluded}) {
858 foreach $item (split / /, $form->{taxaccounts}) {
859 if ($form->{"${item}_base"}) {
860 $form->{invtotal} += $form->{"${item}_total"} =
862 $form->{"${item}_base"} * $form->{"${item}_rate"},
864 $form->{"${item}_total"} =
865 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
869 <th align=right>$form->{"${item}_description"}</th>
870 <td align=right>$form->{"${item}_total"}</td>
876 $form->{invsubtotal} =
877 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
881 <th align=right>| . $locale->text('Subtotal') . qq|</th>
882 <td align=right>$form->{invsubtotal}</td>
888 if ($form->{taxincluded}) {
889 foreach $item (split / /, $form->{taxaccounts}) {
890 if ($form->{"${item}_base"}) {
891 $form->{"${item}_total"} =
893 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
894 (1 + $form->{"${item}_rate"})
897 $form->{"${item}_netto"} =
899 ($form->{"${item}_base"} - $form->{"${item}_total"}),
901 $form->{"${item}_total"} =
902 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
903 $form->{"${item}_netto"} =
904 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
908 <th align=right>Enthaltene $form->{"${item}_description"}</th>
909 <td align=right>$form->{"${item}_total"}</td>
912 <th align=right>Nettobetrag</th>
913 <td align=right>$form->{"${item}_netto"}</td>
921 $form->{oldinvtotal} = $form->{invtotal};
923 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
933 <th align=left>| . $locale->text('Notes') . qq|</th>
934 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
940 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
941 <td><select name=payment_id tabindex=24>$payment
945 <td align=right width=100%>
951 <th align=right>| . $locale->text('Total') . qq|</th>
952 <td align=right>$form->{invtotal}</td>
960 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
961 <input type=hidden name=oldtotalpaid value=$totalpaid>
963 <td><hr size=3 noshade></td>
971 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
974 <td align=left width=30%><b>Dateiname</b></td>
975 <td align=left width=70%><b>Webdavlink</b></td>
977 foreach $file (keys %{ $form->{WEBDAV} }) {
980 <td align=left>$file</td>
981 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
989 <td><hr size=3 noshade></td>
996 <input type=hidden name=jscalendar value=$form->{jscalendar}>
1009 | . $locale->text("Edit the $form->{type}") . qq|<br>
1010 <input class=submit type=submit name=action id=update_button value="|
1011 . $locale->text('Update') . qq|">
1012 <input class=submit type=submit name=action value="|
1013 . $locale->text('Ship to') . qq|">
1014 <input class=submit type=submit name=action value="|
1015 . $locale->text('Print') . qq|">
1016 <input class=submit type=submit name=action value="|
1017 . $locale->text('E-mail') . qq|">
1018 <input class=submit type=submit name=action value="|
1019 . $locale->text('Save') . qq|">
1020 <input class=submit type=submit name=action value="|
1021 . $locale->text('Save and Close') . qq|">
1024 if (($form->{id})) {
1026 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1027 <input class=submit type=submit name=action value="|
1028 . $locale->text('Save as new') . qq|">
1029 <input class=submit type=submit name=action value="|
1030 . $locale->text('Delete') . qq|">|;
1031 if (($form->{type} =~ /sales_quotation$/)) {
1033 <input class=submit type=submit name=action value="|
1034 . $locale->text('Sales Order') . qq|">|;
1036 if ($form->{type} =~ /request_quotation$/) {
1038 <input class=submit type=submit name=action value="|
1039 . $locale->text('Purchase Order') . qq|">|;
1043 <input class=submit type=submit name=action value="|
1044 . $locale->text('Invoice') . qq|">
1048 if ($form->{type} =~ /sales_order$/) {
1050 <br>$form->{heading} als neue Vorlage verwenden für<br>
1051 <input class=submit type=submit name=action value="|
1052 . $locale->text('Purchase Order') . qq|">
1053 <input class=submit type=submit name=action value="|
1054 . $locale->text('Quotation') . qq|">
1057 } elsif ($form->{type} =~ /purchase_order$/) {
1059 <br>$form->{heading} als neue Vorlage verwenden für<br>
1060 <input class=submit type=submit name=action value="|
1061 . $locale->text('Sales Order') . qq|">
1062 <input class=submit type=submit name=action value="|
1063 . $locale->text('Request for Quotation') . qq|">
1068 <br>$form->{heading} als neue Vorlage verwenden für<br>
1069 <input class=submit type=submit name=action value="|
1070 . $locale->text('Order') . qq|">
1073 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1075 <br>Workflow $form->{heading}<br>
1076 <input class=submit type=submit name=action value="|
1077 . $locale->text('Save as new') . qq|">
1078 <input class=submit type=submit name=action value="|
1079 . $locale->text('Invoice') . qq|">
1085 <input type=hidden name=rowcount value=$form->{rowcount}>
1087 <input name=callback type=hidden value="$form->{callback}">
1089 <input type=hidden name=path value=$form->{path}>
1090 <input type=hidden name=login value=$form->{login}>
1091 <input type=hidden name=password value=$form->{password}>
1098 $lxdebug->leave_sub();
1102 $lxdebug->enter_sub();
1104 set_headings($form->{"id"} ? "edit" : "add");
1106 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1107 qw(exchangerate creditlimit creditremaining);
1108 $form->{update} = 1;
1110 &check_name($form->{vc});
1115 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1116 $form->{exchangerate} = $exchangerate
1120 $form->check_exchangerate(
1121 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1125 $i = $form->{rowcount};
1127 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1129 if ( ($form->{"partnumber_$i"} eq "")
1130 && ($form->{"description_$i"} eq "")
1131 && ($form->{"partsgroup_$i"} eq "")) {
1133 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1138 if ( $form->{type} eq 'purchase_order'
1139 || $form->{type} eq 'request_quotation') {
1140 IR->retrieve_item(\%myconfig, \%$form);
1142 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1143 IS->retrieve_item(\%myconfig, \%$form);
1146 my $rows = scalar @{ $form->{item_list} };
1148 $form->{"discount_$i"} =
1149 $form->format_amount(\%myconfig, $form->{discount} * 100);
1152 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1161 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1162 if ($form->{"not_discountable_$i"}) {
1163 $form->{"discount_$i"} = 0;
1165 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1166 qw(partnumber description unit);
1167 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1168 keys %{ $form->{item_list}[0] };
1169 if ($form->{"part_payment_id_$i"} ne "") {
1170 $form->{payment_id} = $form->{"part_payment_id_$i"};
1173 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1175 ($dec) = ($s =~ /\.(\d+)/);
1177 $decimalplaces = ($dec > 2) ? $dec : 2;
1180 $form->{"sellprice_$i"} = $sellprice;
1183 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1185 # if there is an exchange rate adjust sellprice
1186 $form->{"sellprice_$i"} /= $exchangerate;
1190 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1191 (1 - $form->{"discount_$i"} / 100);
1192 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1193 map { $form->{"${_}_base"} += $amount }
1194 (split / /, $form->{"taxaccounts_$i"});
1195 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1196 split / /, $form->{taxaccounts}
1197 if !$form->{taxincluded};
1199 $form->{creditremaining} -= $amount;
1201 $form->{"sellprice_$i"} =
1202 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1205 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1207 # get pricegroups for parts
1208 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1210 # build up html code for prices_$i
1211 &set_pricegroup($i);
1218 # ok, so this is a new part
1219 # ask if it is a part or service item
1221 if ( $form->{"partsgroup_$i"}
1222 && ($form->{"partsnumber_$i"} eq "")
1223 && ($form->{"description_$i"} eq "")) {
1224 $form->{rowcount}--;
1225 $form->{"discount_$i"} = "";
1229 $form->{"id_$i"} = 0;
1230 $form->{"unit_$i"} = $locale->text('ea');
1238 $lxdebug->leave_sub();
1242 $lxdebug->enter_sub();
1244 if ($form->{type} eq 'purchase_order') {
1245 $form->{title} = $locale->text('Purchase Orders');
1246 $form->{vc} = 'vendor';
1247 $ordlabel = $locale->text('Order Number');
1248 $ordnumber = 'ordnumber';
1249 $employee = $locale->text('Employee');
1252 if ($form->{type} eq 'request_quotation') {
1253 $form->{title} = $locale->text('Request for Quotations');
1254 $form->{vc} = 'vendor';
1255 $ordlabel = $locale->text('RFQ Number');
1256 $ordnumber = 'quonumber';
1257 $employee = $locale->text('Employee');
1260 if ($form->{type} eq 'sales_order') {
1261 $form->{title} = $locale->text('Sales Orders');
1262 $form->{vc} = 'customer';
1263 $ordlabel = $locale->text('Order Number');
1264 $ordnumber = 'ordnumber';
1265 $employee = $locale->text('Salesperson');
1268 if ($form->{type} eq 'sales_quotation') {
1269 $form->{title} = $locale->text('Quotations');
1270 $form->{vc} = 'customer';
1271 $ordlabel = $locale->text('Quotation Number');
1272 $ordnumber = 'quonumber';
1273 $employee = $locale->text('Employee');
1276 # setup vendor / customer selection
1277 $form->all_vc(\%myconfig, $form->{vc},
1278 ($form->{vc} eq 'customer') ? "AR" : "AP");
1280 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
1281 @{ $form->{"all_$form->{vc}"} };
1283 $vclabel = ucfirst $form->{vc};
1284 $vclabel = $locale->text($vclabel);
1286 # $locale->text('Vendor')
1287 # $locale->text('Customer')
1291 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
1292 : qq|<input name=$form->{vc} size=35>|;
1295 if (@{ $form->{all_departments} }) {
1296 $form->{selectdepartment} = "<option>\n";
1299 $form->{selectdepartment} .=
1300 "<option>$_->{description}--$_->{id}\n"
1301 } (@{ $form->{all_departments} });
1306 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1307 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1309 | if $form->{selectdepartment};
1312 <input type=hidden name="open" value=1>
1316 if (($form->{"type"} eq "sales_order") ||
1317 ($form->{"type"} eq "purchase_order")) {
1320 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1321 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1322 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1323 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1328 # use JavaScript Calendar or not
1329 $form->{jsscript} = $jscalendar;
1331 if ($form->{jsscript}) {
1333 # with JavaScript Calendar
1335 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1336 <input type=button name=transdatefrom id="trigger3" value=|
1337 . $locale->text('button') . qq|></td>
1340 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1341 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1342 . $locale->text('button') . qq|></td>
1347 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1348 "transdateto", "BL", "trigger4");
1351 # without JavaScript Calendar
1353 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1355 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1363 <form method=post action=$form->{script}>
1367 <th class=listtop>$form->{title}</th>
1369 <tr height="5"></tr>
1374 <th align=right>$vclabel</th>
1375 <td colspan=3>$vc</td>
1380 <th align=right>$ordlabel</th>
1381 <td colspan=3><input name="$ordnumber" size=20></td>
1384 <th align=right>| . $locale->text('From') . qq|</th>
1386 <th align=right>| . $locale->text('Bis') . qq|</th>
1389 <input type=hidden name=sort value=transdate>
1391 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1397 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1398 | . $locale->text('ID') . qq|</td>
1399 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1400 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1401 . $locale->text('Date') . qq|</td>
1402 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1403 . $locale->text('Required by') . qq|</td>
1406 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
1407 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1408 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1409 . $locale->text('Ship via') . qq|</td>
1412 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1413 . $locale->text('Amount') . qq|</td>
1414 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1415 . $locale->text('Tax') . qq|</td>
1416 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1417 . $locale->text('Total') . qq|</td>
1420 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1421 . $locale->text('Subtotal') . qq|</td>
1429 <tr><td colspan=4><hr size=3 noshade></td></tr>
1435 <input type=hidden name=nextsub value=orders>
1436 <input type=hidden name=path value=$form->{path}>
1437 <input type=hidden name=login value=$form->{login}>
1438 <input type=hidden name=password value=$form->{password}>
1439 <input type=hidden name=vc value=$form->{vc}>
1440 <input type=hidden name=type value=$form->{type}>
1442 <input class=submit type=submit name=action value="|
1443 . $locale->text('Continue') . qq|">
1450 $lxdebug->leave_sub();
1454 $lxdebug->enter_sub();
1456 # split vendor / customer
1457 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1458 split(/--/, $form->{ $form->{vc} });
1460 OE->transactions(\%myconfig, \%$form);
1462 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1464 $number = $form->escape($form->{$ordnumber});
1465 $name = $form->escape($form->{ $form->{vc} });
1466 $department = $form->escape($form->{department});
1467 $warehouse = $form->escape($form->{warehouse});
1471 "$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&warehouse=$warehouse";
1473 # construct callback
1474 $number = $form->escape($form->{$ordnumber}, 1);
1475 $name = $form->escape($form->{ $form->{vc} }, 1);
1476 $department = $form->escape($form->{department}, 1);
1477 $warehouse = $form->escape($form->{warehouse}, 1);
1480 "$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&warehouse=$warehouse";
1483 $form->sort_columns("transdate", "reqdate", "id", "$ordnumber",
1484 "name", "netamount", "tax", "amount",
1485 "curr", "employee", "shipvia", "open",
1486 "closed", "delivered");
1488 $form->{l_open} = $form->{l_closed} = "Y"
1489 if ($form->{open} && $form->{closed});
1491 $form->{"l_delivered"} = "Y"
1492 if ($form->{"delivered"} && $form->{"notdelivered"});
1494 foreach $item (@columns) {
1495 if ($form->{"l_$item"} eq "Y") {
1496 push @column_index, $item;
1498 # add column to href and callback
1499 $callback .= "&l_$item=Y";
1500 $href .= "&l_$item=Y";
1504 # only show checkboxes if gotten here via sales_order form.
1505 if ($form->{type} =~ /sales_order/) {
1506 unshift @column_index, "ids";
1509 if ($form->{l_subtotal} eq 'Y') {
1510 $callback .= "&l_subtotal=Y";
1511 $href .= "&l_subtotal=Y";
1514 if ($form->{vc} eq 'vendor') {
1515 if ($form->{type} eq 'purchase_order') {
1516 $form->{title} = $locale->text('Purchase Orders');
1518 $form->{title} = $locale->text('Request for Quotations');
1520 $name = $locale->text('Vendor');
1521 $employee = $locale->text('Employee');
1523 if ($form->{vc} eq 'customer') {
1524 if ($form->{type} eq 'sales_order') {
1525 $form->{title} = $locale->text('Sales Orders');
1526 $employee = $locale->text('Salesperson');
1528 $form->{title} = $locale->text('Quotations');
1529 $employee = $locale->text('Employee');
1531 $name = $locale->text('Customer');
1534 $column_header{id} =
1535 qq|<th><a class=listheading href=$href&sort=id>|
1536 . $locale->text('ID')
1538 $column_header{transdate} =
1539 qq|<th><a class=listheading href=$href&sort=transdate>|
1540 . $locale->text('Date')
1542 $column_header{reqdate} =
1543 qq|<th><a class=listheading href=$href&sort=reqdate>|
1544 . $locale->text('Required by')
1546 $column_header{ordnumber} =
1547 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1548 . $locale->text('Order')
1550 $column_header{quonumber} =
1551 qq|<th><a class=listheading href=$href&sort=quonumber>|
1552 . ($form->{"type"} eq "request_quotation" ?
1553 $locale->text('RFQ') :
1554 $locale->text('Quotation'))
1556 $column_header{name} =
1557 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1558 $column_header{netamount} =
1559 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1560 $column_header{tax} =
1561 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1562 $column_header{amount} =
1563 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1564 $column_header{curr} =
1565 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1566 $column_header{shipvia} =
1567 qq|<th><a class=listheading href=$href&sort=shipvia>|
1568 . $locale->text('Ship via')
1570 $column_header{open} =
1571 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1572 $column_header{closed} =
1573 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1574 $column_header{"delivered"} =
1575 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1577 $column_header{employee} =
1578 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1580 $column_header{ids} = qq|<th></th>|;
1582 if ($form->{ $form->{vc} }) {
1583 $option = $locale->text(ucfirst $form->{vc});
1584 $option .= " : $form->{$form->{vc}}";
1586 if ($form->{warehouse}) {
1587 ($warehouse) = split /--/, $form->{warehouse};
1588 $option .= "\n<br>" if ($option);
1589 $option .= $locale->text('Warehouse');
1590 $option .= " : $warehouse";
1592 if ($form->{department}) {
1593 $option .= "\n<br>" if ($option);
1594 ($department) = split /--/, $form->{department};
1595 $option .= $locale->text('Department') . " : $department";
1597 if ($form->{transdatefrom}) {
1599 . $locale->text('From') . " "
1600 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1602 if ($form->{transdateto}) {
1604 . $locale->text('Bis') . " "
1605 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1607 if ($form->{open}) {
1608 $option .= "\n<br>" if ($option);
1609 $option .= $locale->text('Open');
1611 if ($form->{closed}) {
1612 $option .= "\n<br>" if ($option);
1613 $option .= $locale->text('Closed');
1621 <form method="post" action="oe.pl">
1624 <th class=listtop>$form->{title}</th>
1626 <tr height="5"></tr>
1633 <tr class=listheading>|;
1635 map { print "\n$column_header{$_}" } @column_index;
1641 # add sort and escape callback
1642 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1644 if (@{ $form->{OE} }) {
1645 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1649 $action = "ship_receive" if ($form->{type} =~ /(ship|receive)_order/);
1651 $warehouse = $form->escape($form->{warehouse});
1653 foreach $oe (@{ $form->{OE} }) {
1654 $form->{rowcount} = ++$j;
1656 if ($form->{l_subtotal} eq 'Y') {
1657 if ($sameitem ne $oe->{ $form->{sort} }) {
1659 $sameitem = $oe->{ $form->{sort} };
1663 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1665 $column_data{netamount} =
1667 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1669 $column_data{tax} = "<td align=right>"
1670 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1673 $column_data{amount} =
1675 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1677 $totalnetamount += $oe->{netamount};
1678 $totalamount += $oe->{amount};
1680 $subtotalnetamount += $oe->{netamount};
1681 $subtotalamount += $oe->{amount};
1684 qq|<td><input name="id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1685 $column_data{id} = "<td>$oe->{id}</td>";
1686 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1687 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1689 $column_data{$ordnumber} =
1690 "<td><a href=oe.pl?path=$form->{path}&action=$action&type=$form->{type}&id=$oe->{id}&warehouse=$warehouse&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback_escaped>$oe->{$ordnumber}</a></td>";
1691 $column_data{name} = "<td>$oe->{name}</td>";
1693 $column_data{employee} = "<td>$oe->{employee} </td>";
1694 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1696 if ($oe->{closed}) {
1697 $column_data{closed} = "<td align=center>X</td>";
1698 $column_data{open} = "<td> </td>";
1700 $column_data{closed} = "<td> </td>";
1701 $column_data{open} = "<td align=center>X</td>";
1703 $column_data{"delivered"} = "<td>" .
1704 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1710 <tr class=listrow$i>";
1712 map { print "\n$column_data{$_}" } @column_index;
1720 if ($form->{l_subtotal} eq 'Y') {
1726 <tr class=listtotal>|;
1728 map { $column_data{$_} = "<td> </td>" } @column_index;
1730 $column_data{netamount} =
1731 "<th class=listtotal align=right>"
1732 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1733 $column_data{tax} = "<th class=listtotal align=right>"
1734 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1737 $column_data{amount} =
1738 "<th class=listtotal align=right>"
1739 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1741 map { print "\n$column_data{$_}" } @column_index;
1749 <td><hr size=3 noshade></td>
1753 # multiple invoice edit button only if gotten there via sales_order form.
1755 if ($form->{type} =~ /sales_order/) {
1757 <input type="hidden" name="path" value="$form->{path}">
1758 <input class"submit" type="submit" name="action" value="|
1759 . $locale->text('Continue') . qq|">
1760 <input type="hidden" name="nextsub" value="edit">
1761 <input type="hidden" name="type" value="$form->{type}">
1762 <input type="hidden" name="warehouse" value="$warehouse">
1763 <input type="hidden" name="vc" value="$form->{vc}">
1764 <input type="hidden" name="login" value="$form->{login}">
1765 <input type="hidden" name="password" value="$form->{password}">
1766 <input type="hidden" name="callback" value="$callback">
1767 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1774 <form method=post action=$form->{script}>
1776 <input name=callback type=hidden value="$form->{callback}">
1778 <input type=hidden name=type value=$form->{type}>
1779 <input type=hidden name=vc value=$form->{vc}>
1781 <input type=hidden name=path value=$form->{path}>
1782 <input type=hidden name=login value=$form->{login}>
1783 <input type=hidden name=password value=$form->{password}>
1786 if ($form->{type} !~ /(ship|receive)_order/) {
1788 <input class=submit type=submit name=action value="|
1789 . $locale->text('Add') . qq|">|;
1799 $lxdebug->leave_sub();
1803 $lxdebug->enter_sub();
1805 map { $column_data{$_} = "<td> </td>" } @column_index;
1807 $column_data{netamount} =
1808 "<th class=listsubtotal align=right>"
1809 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1811 $column_data{tax} = "<td class=listsubtotal align=right>"
1812 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1815 $column_data{amount} =
1816 "<th class=listsubtotal align=right>"
1817 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1819 $subtotalnetamount = 0;
1820 $subtotalamount = 0;
1823 <tr class=listsubtotal>
1826 map { print "\n$column_data{$_}" } @column_index;
1832 $lxdebug->leave_sub();
1835 sub save_and_close {
1836 $lxdebug->enter_sub();
1838 if ($form->{type} =~ /_order$/) {
1839 $form->isblank("transdate", $locale->text('Order Date missing!'));
1841 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1844 $msg = ucfirst $form->{vc};
1845 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1847 # $locale->text('Customer missing!');
1848 # $locale->text('Vendor missing!');
1850 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1851 if ($form->{currency} ne $form->{defaultcurrency});
1855 # if the name changed get new values
1856 if (&check_name($form->{vc})) {
1861 $form->{id} = 0 if $form->{saveasnew};
1863 # this is for the internal notes section for the [email] Subject
1864 if ($form->{type} =~ /_order$/) {
1865 if ($form->{type} eq 'sales_order') {
1866 $form->{label} = $locale->text('Sales Order');
1868 $numberfld = "sonumber";
1869 $ordnumber = "ordnumber";
1871 $form->{label} = $locale->text('Purchase Order');
1873 $numberfld = "ponumber";
1874 $ordnumber = "ordnumber";
1877 $err = $locale->text('Cannot save order!');
1880 if ($form->{type} eq 'sales_quotation') {
1881 $form->{label} = $locale->text('Quotation');
1883 $numberfld = "sqnumber";
1884 $ordnumber = "quonumber";
1886 $form->{label} = $locale->text('Request for Quotation');
1888 $numberfld = "rfqnumber";
1889 $ordnumber = "quonumber";
1892 $err = $locale->text('Cannot save quotation!');
1896 # get new number in sequence if no number is given or if saveasnew was requested
1897 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1898 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1904 $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
1905 if (OE->save(\%myconfig, \%$form));
1908 $lxdebug->leave_sub();
1912 $lxdebug->enter_sub();
1914 if ($form->{type} =~ /_order$/) {
1915 $form->isblank("transdate", $locale->text('Order Date missing!'));
1917 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1920 $msg = ucfirst $form->{vc};
1921 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1923 # $locale->text('Customer missing!');
1924 # $locale->text('Vendor missing!');
1926 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1927 if ($form->{currency} ne $form->{defaultcurrency});
1931 # if the name changed get new values
1932 if (&check_name($form->{vc})) {
1937 $form->{id} = 0 if $form->{saveasnew};
1939 # this is for the internal notes section for the [email] Subject
1940 if ($form->{type} =~ /_order$/) {
1941 if ($form->{type} eq 'sales_order') {
1942 $form->{label} = $locale->text('Sales Order');
1944 $numberfld = "sonumber";
1945 $ordnumber = "ordnumber";
1947 $form->{label} = $locale->text('Purchase Order');
1949 $numberfld = "ponumber";
1950 $ordnumber = "ordnumber";
1953 $err = $locale->text('Cannot save order!');
1956 if ($form->{type} eq 'sales_quotation') {
1957 $form->{label} = $locale->text('Quotation');
1959 $numberfld = "sqnumber";
1960 $ordnumber = "quonumber";
1962 $form->{label} = $locale->text('Request for Quotation');
1964 $numberfld = "rfqnumber";
1965 $ordnumber = "quonumber";
1968 $err = $locale->text('Cannot save quotation!');
1972 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
1973 unless $form->{$ordnumber};
1977 OE->save(\%myconfig, \%$form);
1978 $form->{simple_save} = 1;
1979 if(!$form->{print_and_save}) {
1980 set_headings("edit");
1984 $lxdebug->leave_sub();
1988 $lxdebug->enter_sub();
1992 if ($form->{type} =~ /_order$/) {
1993 $msg = $locale->text('Are you sure you want to delete Order Number');
1994 $ordnumber = 'ordnumber';
1996 $msg = $locale->text('Are you sure you want to delete Quotation Number');
1997 $ordnumber = 'quonumber';
2003 <form method=post action=$form->{script}>
2006 # delete action variable
2007 map { delete $form->{$_} } qw(action header);
2009 foreach $key (keys %$form) {
2010 $form->{$key} =~ s/\"/"/g;
2011 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2015 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2017 <h4>$msg $form->{$ordnumber}</h4>
2019 <input name=action class=submit type=submit value="|
2020 . $locale->text('Yes') . qq|">
2027 $lxdebug->leave_sub();
2031 $lxdebug->enter_sub();
2033 if ($form->{type} =~ /_order$/) {
2034 $msg = $locale->text('Order deleted!');
2035 $err = $locale->text('Cannot delete order!');
2037 $msg = $locale->text('Quotation deleted!');
2038 $err = $locale->text('Cannot delete quotation!');
2041 $form->redirect($msg) if (OE->delete(\%myconfig, \%$form, $spool));
2044 $lxdebug->leave_sub();
2048 $lxdebug->enter_sub();
2050 if ($form->{type} =~ /_order$/) {
2052 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2053 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2054 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2055 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2057 $form->isblank("transdate", $locale->text('Order Date missing!'))
2058 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2061 # also copy deliverydate from the order
2062 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2063 $form->{orddate} = $form->{transdate};
2065 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2066 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2067 $form->{ordnumber} = "";
2068 $form->{quodate} = $form->{transdate};
2071 # if the name changed get new values
2072 if (&check_name($form->{vc})) {
2077 $form->{cp_id} *= 1;
2079 for $i (1 .. $form->{rowcount}) {
2080 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2081 $form->{"${_}_${i}"})
2082 if ($form->{"${_}_${i}"}) }
2083 qw(ship qty sellprice listprice basefactor));
2086 if ( $form->{type} =~ /_order/
2087 && $form->{currency} ne $form->{defaultcurrency}) {
2089 # check if we need a new exchangerate
2090 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2092 $orddate = $form->current_date(\%myconfig);
2094 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2097 if (!$exchangerate) {
2098 &backorder_exchangerate($orddate, $buysell);
2103 # close orders/quotations
2104 $form->{closed} = 1;
2106 # save order if one ordnumber has been given
2107 # if not it's most likely a collective order, which can't be saved back
2108 # so they just have to be closed
2109 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2110 OE->close_order(\%myconfig, \%$form);
2112 OE->close_orders(\%myconfig, \%$form);
2115 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2117 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2120 $form->{closed} = 0;
2121 $form->{rowcount}--;
2122 $form->{shipto} = 1;
2124 if ($form->{type} =~ /_order$/) {
2125 $form->{exchangerate} = $exchangerate;
2129 if ( $form->{type} eq 'purchase_order'
2130 || $form->{type} eq 'request_quotation') {
2131 $form->{title} = $locale->text('Add Vendor Invoice');
2132 $form->{script} = 'ir.pl';
2136 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2137 $form->{title} = $locale->text('Add Sales Invoice');
2138 $form->{script} = 'is.pl';
2143 # bo creates the id, reset it
2144 map { delete $form->{$_} }
2145 qw(id subject message cc bcc printed emailed queued);
2146 $form->{ $form->{vc} } =~ s/--.*//g;
2147 $form->{type} = "invoice";
2150 $locale = new Locale "$myconfig{countrycode}", "$script";
2152 require "$form->{path}/$form->{script}";
2154 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2156 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2157 qw(creditlimit creditremaining);
2159 $currency = $form->{currency};
2162 $form->{currency} = $currency;
2163 $form->{exchangerate} = "";
2164 $form->{forex} = "";
2165 $form->{exchangerate} = $exchangerate
2169 $form->check_exchangerate(
2170 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2173 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2178 for $i (1 .. $form->{rowcount}) {
2179 $form->{"discount_$i"} =
2180 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2182 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2184 $decimalplaces = ($dec > 2) ? $dec : 2;
2186 # copy delivery date from reqdate for order -> invoice conversion
2187 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2188 unless $form->{"deliverydate_$i"};
2190 $form->{"sellprice_$i"} =
2191 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2194 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2195 $dec_qty = length $dec_qty;
2197 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2199 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2200 qw(partnumber description unit);
2206 $lxdebug->leave_sub();
2209 sub backorder_exchangerate {
2210 $lxdebug->enter_sub();
2211 my ($orddate, $buysell) = @_;
2218 <form method=post action=$form->{script}>
2221 # delete action variable
2222 map { delete $form->{$_} } qw(action header exchangerate);
2224 foreach $key (keys %$form) {
2225 $form->{$key} =~ s/\"/"/g;
2226 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2229 $form->{title} = $locale->text('Add Exchangerate');
2233 <input type=hidden name=path value=$form->{path}>
2234 <input type=hidden name=login value=$form->{login}>
2235 <input type=hidden name=password value=$form->{password}>
2237 <input type=hidden name=exchangeratedate value=$orddate>
2238 <input type=hidden name=buysell value=$buysell>
2241 <tr><th class=listtop>$form->{title}</th></tr>
2242 <tr height="5"></tr>
2247 <th align=right>| . $locale->text('Currency') . qq|</th>
2248 <td>$form->{currency}</td>
2251 <th align=right>| . $locale->text('Date') . qq|</th>
2255 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2256 <td><input name=exchangerate size=11></td>
2266 <input type=hidden name=nextsub value=save_exchangerate>
2268 <input name=action class=submit type=submit value="|
2269 . $locale->text('Continue') . qq|">
2277 $lxdebug->leave_sub();
2280 sub save_exchangerate {
2281 $lxdebug->enter_sub();
2283 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2284 $form->{exchangerate} =
2285 $form->parse_amount(\%myconfig, $form->{exchangerate});
2286 $form->save_exchangerate(\%myconfig, $form->{currency},
2287 $form->{exchangeratedate},
2288 $form->{exchangerate}, $form->{buysell});
2292 $lxdebug->leave_sub();
2295 sub create_backorder {
2296 $lxdebug->enter_sub();
2298 $form->{shipped} = 1;
2300 # figure out if we need to create a backorder
2301 # items aren't saved if qty != 0
2303 for $i (1 .. $form->{rowcount}) {
2304 $totalqty += $qty = $form->{"qty_$i"};
2305 $totalship += $ship = $form->{"ship_$i"};
2307 $form->{"qty_$i"} = $qty - $ship;
2310 if ($totalship == 0) {
2311 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2312 $form->{ordtotal} = 0;
2313 $form->{shipped} = 0;
2317 if ($totalqty == $totalship) {
2318 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2319 $form->{ordtotal} = 0;
2324 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2327 for $i (1 .. $form->{rowcount}) {
2329 $form->{"${_}_$i"} =
2330 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2331 } qw(sellprice discount);
2336 OE->save(\%myconfig, \%$form);
2338 # rebuild rows for invoice
2342 for $i (1 .. $form->{rowcount}) {
2343 $form->{"qty_$i"} = $form->{"ship_$i"};
2345 if ($form->{"qty_$i"}) {
2348 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2353 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2354 $form->{rowcount} = $count;
2356 $lxdebug->leave_sub();
2360 $lxdebug->enter_sub();
2362 $form->{saveasnew} = 1;
2363 $form->{closed} = 0;
2364 map { delete $form->{$_} } qw(printed emailed queued ordnumber quonumber);
2368 $lxdebug->leave_sub();
2371 sub purchase_order {
2372 $lxdebug->enter_sub();
2374 if ( $form->{type} eq 'sales_quotation'
2375 || $form->{type} eq 'request_quotation') {
2376 OE->close_order(\%myconfig, \%$form);
2379 $form->{cp_id} *= 1;
2381 $form->{title} = $locale->text('Add Purchase Order');
2382 $form->{vc} = "vendor";
2383 $form->{type} = "purchase_order";
2387 $lxdebug->leave_sub();
2391 $lxdebug->enter_sub();
2393 if ( $form->{type} eq 'sales_quotation'
2394 || $form->{type} eq 'request_quotation') {
2395 OE->close_order(\%myconfig, $form);
2398 $form->{cp_id} *= 1;
2400 $form->{title} = $locale->text('Add Sales Order');
2401 $form->{vc} = "customer";
2402 $form->{type} = "sales_order";
2406 $lxdebug->leave_sub();
2410 $lxdebug->enter_sub();
2412 $form->{transdate} = $form->current_date(\%myconfig);
2413 delete $form->{duedate};
2415 $form->{closed} = 0;
2418 map { delete $form->{$_} }
2419 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2421 for $i (1 .. $form->{rowcount}) {
2422 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2423 $form->{"${_}_${i}"})
2424 if ($form->{"${_}_${i}"}) }
2425 qw(ship qty sellprice listprice basefactor));
2433 for $i (1 .. $form->{rowcount} - 1) {
2434 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2435 qw(partnumber description unit);
2438 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2439 qw(creditlimit creditremaining);
2443 $lxdebug->leave_sub();