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");
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>
785 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
787 <input name="globalprojectnumber" size="11" value="| . Q($form->{globalprojectnumber}) . qq|">
788 <input type="hidden" name="oldglobalprojectnumber" value="| . Q($form->{globalprojectnumber}) . qq|">
789 <input type="hidden" name="globalproject_id" value="| . Q($form->{globalproject_id}) . qq|">
801 <!-- shipto are in hidden variables -->
803 <input type=hidden name=shiptoname value="$form->{shiptoname}">
804 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
805 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
806 <input type=hidden name=shiptocity value="$form->{shiptocity}">
807 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
808 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
809 <input type=hidden name=shiptophone value="$form->{shiptophone}">
810 <input type=hidden name=shiptofax value="$form->{shiptofax}">
811 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
812 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
813 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
815 <!-- email variables -->
816 <input type=hidden name=message value="$form->{message}">
817 <input type=hidden name=email value="$form->{email}">
818 <input type=hidden name=subject value="$form->{subject}">
819 <input type=hidden name=cc value="$form->{cc}">
820 <input type=hidden name=bcc value="$form->{bcc}">
822 <input type=hidden name=taxpart value="$form->{taxpart}">
823 <input type=hidden name=taxservice value="$form->{taxservice}">
825 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
828 foreach $item (split / /, $form->{taxaccounts}) {
830 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
831 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
834 $lxdebug->leave_sub();
838 $lxdebug->enter_sub();
840 $form->{invtotal} = $form->{invsubtotal};
842 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
845 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
848 $rows = ($rows > $introws) ? $rows : $introws;
850 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
852 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
854 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
857 if ($form->{taxaccounts}) {
859 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
860 . $locale->text('Tax Included') . qq|</b><br><br>
864 if (!$form->{taxincluded}) {
866 foreach $item (split / /, $form->{taxaccounts}) {
867 if ($form->{"${item}_base"}) {
868 $form->{invtotal} += $form->{"${item}_total"} =
870 $form->{"${item}_base"} * $form->{"${item}_rate"},
872 $form->{"${item}_total"} =
873 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
877 <th align=right>$form->{"${item}_description"}</th>
878 <td align=right>$form->{"${item}_total"}</td>
884 $form->{invsubtotal} =
885 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
889 <th align=right>| . $locale->text('Subtotal') . qq|</th>
890 <td align=right>$form->{invsubtotal}</td>
896 if ($form->{taxincluded}) {
897 foreach $item (split / /, $form->{taxaccounts}) {
898 if ($form->{"${item}_base"}) {
899 $form->{"${item}_total"} =
901 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
902 (1 + $form->{"${item}_rate"})
905 $form->{"${item}_netto"} =
907 ($form->{"${item}_base"} - $form->{"${item}_total"}),
909 $form->{"${item}_total"} =
910 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
911 $form->{"${item}_netto"} =
912 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
916 <th align=right>Enthaltene $form->{"${item}_description"}</th>
917 <td align=right>$form->{"${item}_total"}</td>
920 <th align=right>Nettobetrag</th>
921 <td align=right>$form->{"${item}_netto"}</td>
929 $form->{oldinvtotal} = $form->{invtotal};
931 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
941 <th align=left>| . $locale->text('Notes') . qq|</th>
942 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
948 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
949 <td><select name=payment_id tabindex=24>$payment
953 <td align=right width=100%>
959 <th align=right>| . $locale->text('Total') . qq|</th>
960 <td align=right>$form->{invtotal}</td>
968 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
969 <input type=hidden name=oldtotalpaid value=$totalpaid>
971 <td><hr size=3 noshade></td>
979 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
982 <td align=left width=30%><b>Dateiname</b></td>
983 <td align=left width=70%><b>Webdavlink</b></td>
985 foreach $file (keys %{ $form->{WEBDAV} }) {
988 <td align=left>$file</td>
989 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
997 <td><hr size=3 noshade></td>
1004 <input type=hidden name=jscalendar value=$form->{jscalendar}>
1017 | . $locale->text("Edit the $form->{type}") . qq|<br>
1018 <input class=submit type=submit name=action id=update_button value="|
1019 . $locale->text('Update') . qq|">
1020 <input class=submit type=submit name=action value="|
1021 . $locale->text('Ship to') . qq|">
1022 <input class=submit type=submit name=action value="|
1023 . $locale->text('Print') . qq|">
1024 <input class=submit type=submit name=action value="|
1025 . $locale->text('E-mail') . qq|">
1026 <input class=submit type=submit name=action value="|
1027 . $locale->text('Save') . qq|">
1028 <input class=submit type=submit name=action value="|
1029 . $locale->text('Save and Close') . qq|">
1032 if (($form->{id})) {
1034 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1035 <input class=submit type=submit name=action value="|
1036 . $locale->text('Save as new') . qq|">
1037 <input class=submit type=submit name=action value="|
1038 . $locale->text('Delete') . qq|">|;
1039 if (($form->{type} =~ /sales_quotation$/)) {
1041 <input class=submit type=submit name=action value="|
1042 . $locale->text('Sales Order') . qq|">|;
1044 if ($form->{type} =~ /request_quotation$/) {
1046 <input class=submit type=submit name=action value="|
1047 . $locale->text('Purchase Order') . qq|">|;
1051 <input class=submit type=submit name=action value="|
1052 . $locale->text('Invoice') . qq|">
1056 if ($form->{type} =~ /sales_order$/) {
1058 <br>$form->{heading} als neue Vorlage verwenden für<br>
1059 <input class=submit type=submit name=action value="|
1060 . $locale->text('Purchase Order') . qq|">
1061 <input class=submit type=submit name=action value="|
1062 . $locale->text('Quotation') . qq|">
1065 } elsif ($form->{type} =~ /purchase_order$/) {
1067 <br>$form->{heading} als neue Vorlage verwenden für<br>
1068 <input class=submit type=submit name=action value="|
1069 . $locale->text('Sales Order') . qq|">
1070 <input class=submit type=submit name=action value="|
1071 . $locale->text('Request for Quotation') . qq|">
1076 <br>$form->{heading} als neue Vorlage verwenden für<br>
1077 <input class=submit type=submit name=action value="|
1078 . $locale->text('Order') . qq|">
1081 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1083 <br>Workflow $form->{heading}<br>
1084 <input class=submit type=submit name=action value="|
1085 . $locale->text('Save as new') . qq|">
1086 <input class=submit type=submit name=action value="|
1087 . $locale->text('Invoice') . qq|">
1093 <input type=hidden name=rowcount value=$form->{rowcount}>
1095 <input name=callback type=hidden value="$form->{callback}">
1097 <input type=hidden name=path value=$form->{path}>
1098 <input type=hidden name=login value=$form->{login}>
1099 <input type=hidden name=password value=$form->{password}>
1106 $lxdebug->leave_sub();
1110 $lxdebug->enter_sub();
1112 set_headings($form->{"id"} ? "edit" : "add");
1114 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1115 qw(exchangerate creditlimit creditremaining);
1116 $form->{update} = 1;
1118 &check_name($form->{vc});
1123 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1124 $form->{exchangerate} = $exchangerate
1128 $form->check_exchangerate(
1129 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1133 $i = $form->{rowcount};
1135 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1137 if ( ($form->{"partnumber_$i"} eq "")
1138 && ($form->{"description_$i"} eq "")
1139 && ($form->{"partsgroup_$i"} eq "")) {
1141 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1146 if ( $form->{type} eq 'purchase_order'
1147 || $form->{type} eq 'request_quotation') {
1148 IR->retrieve_item(\%myconfig, \%$form);
1150 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1151 IS->retrieve_item(\%myconfig, \%$form);
1154 my $rows = scalar @{ $form->{item_list} };
1156 $form->{"discount_$i"} =
1157 $form->format_amount(\%myconfig, $form->{discount} * 100);
1160 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1169 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1170 if ($form->{"not_discountable_$i"}) {
1171 $form->{"discount_$i"} = 0;
1173 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1174 qw(partnumber description unit);
1175 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1176 keys %{ $form->{item_list}[0] };
1177 if ($form->{"part_payment_id_$i"} ne "") {
1178 $form->{payment_id} = $form->{"part_payment_id_$i"};
1181 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1183 ($dec) = ($s =~ /\.(\d+)/);
1185 $decimalplaces = ($dec > 2) ? $dec : 2;
1188 $form->{"sellprice_$i"} = $sellprice;
1191 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1193 # if there is an exchange rate adjust sellprice
1194 $form->{"sellprice_$i"} /= $exchangerate;
1198 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1199 (1 - $form->{"discount_$i"} / 100);
1200 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1201 map { $form->{"${_}_base"} += $amount }
1202 (split / /, $form->{"taxaccounts_$i"});
1203 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1204 split / /, $form->{taxaccounts}
1205 if !$form->{taxincluded};
1207 $form->{creditremaining} -= $amount;
1209 $form->{"sellprice_$i"} =
1210 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1213 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1215 # get pricegroups for parts
1216 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1218 # build up html code for prices_$i
1219 &set_pricegroup($i);
1226 # ok, so this is a new part
1227 # ask if it is a part or service item
1229 if ( $form->{"partsgroup_$i"}
1230 && ($form->{"partsnumber_$i"} eq "")
1231 && ($form->{"description_$i"} eq "")) {
1232 $form->{rowcount}--;
1233 $form->{"discount_$i"} = "";
1237 $form->{"id_$i"} = 0;
1238 $form->{"unit_$i"} = $locale->text('ea');
1246 $lxdebug->leave_sub();
1250 $lxdebug->enter_sub();
1252 if ($form->{type} eq 'purchase_order') {
1253 $form->{title} = $locale->text('Purchase Orders');
1254 $form->{vc} = 'vendor';
1255 $ordlabel = $locale->text('Order Number');
1256 $ordnumber = 'ordnumber';
1257 $employee = $locale->text('Employee');
1260 if ($form->{type} eq 'request_quotation') {
1261 $form->{title} = $locale->text('Request for Quotations');
1262 $form->{vc} = 'vendor';
1263 $ordlabel = $locale->text('RFQ Number');
1264 $ordnumber = 'quonumber';
1265 $employee = $locale->text('Employee');
1268 if ($form->{type} eq 'sales_order') {
1269 $form->{title} = $locale->text('Sales Orders');
1270 $form->{vc} = 'customer';
1271 $ordlabel = $locale->text('Order Number');
1272 $ordnumber = 'ordnumber';
1273 $employee = $locale->text('Salesperson');
1276 if ($form->{type} eq 'sales_quotation') {
1277 $form->{title} = $locale->text('Quotations');
1278 $form->{vc} = 'customer';
1279 $ordlabel = $locale->text('Quotation Number');
1280 $ordnumber = 'quonumber';
1281 $employee = $locale->text('Employee');
1284 # setup vendor / customer selection
1285 $form->all_vc(\%myconfig, $form->{vc},
1286 ($form->{vc} eq 'customer') ? "AR" : "AP");
1288 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
1289 @{ $form->{"all_$form->{vc}"} };
1291 $vclabel = ucfirst $form->{vc};
1292 $vclabel = $locale->text($vclabel);
1294 # $locale->text('Vendor')
1295 # $locale->text('Customer')
1299 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
1300 : qq|<input name=$form->{vc} size=35>|;
1303 if (@{ $form->{all_departments} }) {
1304 $form->{selectdepartment} = "<option>\n";
1307 $form->{selectdepartment} .=
1308 "<option>$_->{description}--$_->{id}\n"
1309 } (@{ $form->{all_departments} });
1314 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1315 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1317 | if $form->{selectdepartment};
1320 <input type=hidden name="open" value=1>
1324 if (($form->{"type"} eq "sales_order") ||
1325 ($form->{"type"} eq "purchase_order")) {
1328 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1329 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1330 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1331 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1336 # use JavaScript Calendar or not
1337 $form->{jsscript} = $jscalendar;
1339 if ($form->{jsscript}) {
1341 # with JavaScript Calendar
1343 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1344 <input type=button name=transdatefrom id="trigger3" value=|
1345 . $locale->text('button') . qq|></td>
1348 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1349 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1350 . $locale->text('button') . qq|></td>
1355 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1356 "transdateto", "BL", "trigger4");
1359 # without JavaScript Calendar
1361 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1363 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1371 <form method=post action=$form->{script}>
1375 <th class=listtop>$form->{title}</th>
1377 <tr height="5"></tr>
1382 <th align=right>$vclabel</th>
1383 <td colspan=3>$vc</td>
1387 <th align=right>$ordlabel</th>
1388 <td colspan=3><input name="$ordnumber" size=20></td>
1391 <th align=right>| . $locale->text('From') . qq|</th>
1393 <th align=right>| . $locale->text('Bis') . qq|</th>
1396 <input type=hidden name=sort value=transdate>
1398 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1404 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1405 | . $locale->text('ID') . qq|</td>
1406 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1407 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1408 . $locale->text('Date') . qq|</td>
1409 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1410 . $locale->text('Required by') . qq|</td>
1413 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
1414 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1415 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1416 . $locale->text('Ship via') . qq|</td>
1419 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1420 . $locale->text('Amount') . qq|</td>
1421 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1422 . $locale->text('Tax') . qq|</td>
1423 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1424 . $locale->text('Total') . qq|</td>
1427 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1428 . $locale->text('Subtotal') . qq|</td>
1436 <tr><td colspan=4><hr size=3 noshade></td></tr>
1442 <input type=hidden name=nextsub value=orders>
1443 <input type=hidden name=path value=$form->{path}>
1444 <input type=hidden name=login value=$form->{login}>
1445 <input type=hidden name=password value=$form->{password}>
1446 <input type=hidden name=vc value=$form->{vc}>
1447 <input type=hidden name=type value=$form->{type}>
1449 <input class=submit type=submit name=action value="|
1450 . $locale->text('Continue') . qq|">
1457 $lxdebug->leave_sub();
1461 $lxdebug->enter_sub();
1463 # split vendor / customer
1464 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1465 split(/--/, $form->{ $form->{vc} });
1467 OE->transactions(\%myconfig, \%$form);
1469 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1471 $number = $form->escape($form->{$ordnumber});
1472 $name = $form->escape($form->{ $form->{vc} });
1473 $department = $form->escape($form->{department});
1477 "$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";
1479 # construct callback
1480 $number = $form->escape($form->{$ordnumber}, 1);
1481 $name = $form->escape($form->{ $form->{vc} }, 1);
1482 $department = $form->escape($form->{department}, 1);
1485 "$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";
1488 $form->sort_columns("transdate", "reqdate", "id", "$ordnumber",
1489 "name", "netamount", "tax", "amount",
1490 "curr", "employee", "shipvia", "open",
1491 "closed", "delivered");
1493 $form->{l_open} = $form->{l_closed} = "Y"
1494 if ($form->{open} && $form->{closed});
1496 $form->{"l_delivered"} = "Y"
1497 if ($form->{"delivered"} && $form->{"notdelivered"});
1499 foreach $item (@columns) {
1500 if ($form->{"l_$item"} eq "Y") {
1501 push @column_index, $item;
1503 # add column to href and callback
1504 $callback .= "&l_$item=Y";
1505 $href .= "&l_$item=Y";
1509 # only show checkboxes if gotten here via sales_order form.
1510 if ($form->{type} =~ /sales_order/) {
1511 unshift @column_index, "ids";
1514 if ($form->{l_subtotal} eq 'Y') {
1515 $callback .= "&l_subtotal=Y";
1516 $href .= "&l_subtotal=Y";
1519 if ($form->{vc} eq 'vendor') {
1520 if ($form->{type} eq 'purchase_order') {
1521 $form->{title} = $locale->text('Purchase Orders');
1523 $form->{title} = $locale->text('Request for Quotations');
1525 $name = $locale->text('Vendor');
1526 $employee = $locale->text('Employee');
1528 if ($form->{vc} eq 'customer') {
1529 if ($form->{type} eq 'sales_order') {
1530 $form->{title} = $locale->text('Sales Orders');
1531 $employee = $locale->text('Salesperson');
1533 $form->{title} = $locale->text('Quotations');
1534 $employee = $locale->text('Employee');
1536 $name = $locale->text('Customer');
1539 $column_header{id} =
1540 qq|<th><a class=listheading href=$href&sort=id>|
1541 . $locale->text('ID')
1543 $column_header{transdate} =
1544 qq|<th><a class=listheading href=$href&sort=transdate>|
1545 . $locale->text('Date')
1547 $column_header{reqdate} =
1548 qq|<th><a class=listheading href=$href&sort=reqdate>|
1549 . $locale->text('Required by')
1551 $column_header{ordnumber} =
1552 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1553 . $locale->text('Order')
1555 $column_header{quonumber} =
1556 qq|<th><a class=listheading href=$href&sort=quonumber>|
1557 . ($form->{"type"} eq "request_quotation" ?
1558 $locale->text('RFQ') :
1559 $locale->text('Quotation'))
1561 $column_header{name} =
1562 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1563 $column_header{netamount} =
1564 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1565 $column_header{tax} =
1566 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1567 $column_header{amount} =
1568 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1569 $column_header{curr} =
1570 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1571 $column_header{shipvia} =
1572 qq|<th><a class=listheading href=$href&sort=shipvia>|
1573 . $locale->text('Ship via')
1575 $column_header{open} =
1576 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1577 $column_header{closed} =
1578 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1579 $column_header{"delivered"} =
1580 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1582 $column_header{employee} =
1583 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1585 $column_header{ids} = qq|<th></th>|;
1587 if ($form->{ $form->{vc} }) {
1588 $option = $locale->text(ucfirst $form->{vc});
1589 $option .= " : $form->{$form->{vc}}";
1591 if ($form->{department}) {
1592 $option .= "\n<br>" if ($option);
1593 ($department) = split /--/, $form->{department};
1594 $option .= $locale->text('Department') . " : $department";
1596 if ($form->{transdatefrom}) {
1598 . $locale->text('From') . " "
1599 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1601 if ($form->{transdateto}) {
1603 . $locale->text('Bis') . " "
1604 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1606 if ($form->{open}) {
1607 $option .= "\n<br>" if ($option);
1608 $option .= $locale->text('Open');
1610 if ($form->{closed}) {
1611 $option .= "\n<br>" if ($option);
1612 $option .= $locale->text('Closed');
1620 <form method="post" action="oe.pl">
1623 <th class=listtop>$form->{title}</th>
1625 <tr height="5"></tr>
1632 <tr class=listheading>|;
1634 map { print "\n$column_header{$_}" } @column_index;
1640 # add sort and escape callback
1641 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1643 if (@{ $form->{OE} }) {
1644 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1649 foreach $oe (@{ $form->{OE} }) {
1650 $form->{rowcount} = ++$j;
1652 if ($form->{l_subtotal} eq 'Y') {
1653 if ($sameitem ne $oe->{ $form->{sort} }) {
1655 $sameitem = $oe->{ $form->{sort} };
1659 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1661 $column_data{netamount} =
1663 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1665 $column_data{tax} = "<td align=right>"
1666 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1669 $column_data{amount} =
1671 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1673 $totalnetamount += $oe->{netamount};
1674 $totalamount += $oe->{amount};
1676 $subtotalnetamount += $oe->{netamount};
1677 $subtotalamount += $oe->{amount};
1680 qq|<td><input name="id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1681 $column_data{id} = "<td>$oe->{id}</td>";
1682 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1683 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1685 $column_data{$ordnumber} =
1686 "<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>";
1687 $column_data{name} = "<td>$oe->{name}</td>";
1689 $column_data{employee} = "<td>$oe->{employee} </td>";
1690 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1692 if ($oe->{closed}) {
1693 $column_data{closed} = "<td align=center>X</td>";
1694 $column_data{open} = "<td> </td>";
1696 $column_data{closed} = "<td> </td>";
1697 $column_data{open} = "<td align=center>X</td>";
1699 $column_data{"delivered"} = "<td>" .
1700 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1706 <tr class=listrow$i>";
1708 map { print "\n$column_data{$_}" } @column_index;
1716 if ($form->{l_subtotal} eq 'Y') {
1722 <tr class=listtotal>|;
1724 map { $column_data{$_} = "<td> </td>" } @column_index;
1726 $column_data{netamount} =
1727 "<th class=listtotal align=right>"
1728 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1729 $column_data{tax} = "<th class=listtotal align=right>"
1730 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1733 $column_data{amount} =
1734 "<th class=listtotal align=right>"
1735 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1737 map { print "\n$column_data{$_}" } @column_index;
1745 <td><hr size=3 noshade></td>
1749 # multiple invoice edit button only if gotten there via sales_order form.
1751 if ($form->{type} =~ /sales_order/) {
1753 <input type="hidden" name="path" value="$form->{path}">
1754 <input class"submit" type="submit" name="action" value="|
1755 . $locale->text('Continue') . qq|">
1756 <input type="hidden" name="nextsub" value="edit">
1757 <input type="hidden" name="type" value="$form->{type}">
1758 <input type="hidden" name="vc" value="$form->{vc}">
1759 <input type="hidden" name="login" value="$form->{login}">
1760 <input type="hidden" name="password" value="$form->{password}">
1761 <input type="hidden" name="callback" value="$callback">
1762 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1769 <form method=post action=$form->{script}>
1771 <input name=callback type=hidden value="$form->{callback}">
1773 <input type=hidden name=type value=$form->{type}>
1774 <input type=hidden name=vc value=$form->{vc}>
1776 <input type=hidden name=path value=$form->{path}>
1777 <input type=hidden name=login value=$form->{login}>
1778 <input type=hidden name=password value=$form->{password}>
1786 $lxdebug->leave_sub();
1790 $lxdebug->enter_sub();
1792 map { $column_data{$_} = "<td> </td>" } @column_index;
1794 $column_data{netamount} =
1795 "<th class=listsubtotal align=right>"
1796 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1798 $column_data{tax} = "<td class=listsubtotal align=right>"
1799 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1802 $column_data{amount} =
1803 "<th class=listsubtotal align=right>"
1804 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1806 $subtotalnetamount = 0;
1807 $subtotalamount = 0;
1810 <tr class=listsubtotal>
1813 map { print "\n$column_data{$_}" } @column_index;
1819 $lxdebug->leave_sub();
1822 sub save_and_close {
1823 $lxdebug->enter_sub();
1825 if ($form->{type} =~ /_order$/) {
1826 $form->isblank("transdate", $locale->text('Order Date missing!'));
1828 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1831 $msg = ucfirst $form->{vc};
1832 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1834 # $locale->text('Customer missing!');
1835 # $locale->text('Vendor missing!');
1837 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1838 if ($form->{currency} ne $form->{defaultcurrency});
1842 # if the name changed get new values
1843 if (&check_name($form->{vc})) {
1848 $form->{id} = 0 if $form->{saveasnew};
1850 # this is for the internal notes section for the [email] Subject
1851 if ($form->{type} =~ /_order$/) {
1852 if ($form->{type} eq 'sales_order') {
1853 $form->{label} = $locale->text('Sales Order');
1855 $numberfld = "sonumber";
1856 $ordnumber = "ordnumber";
1858 $form->{label} = $locale->text('Purchase Order');
1860 $numberfld = "ponumber";
1861 $ordnumber = "ordnumber";
1864 $err = $locale->text('Cannot save order!');
1867 if ($form->{type} eq 'sales_quotation') {
1868 $form->{label} = $locale->text('Quotation');
1870 $numberfld = "sqnumber";
1871 $ordnumber = "quonumber";
1873 $form->{label} = $locale->text('Request for Quotation');
1875 $numberfld = "rfqnumber";
1876 $ordnumber = "quonumber";
1879 $err = $locale->text('Cannot save quotation!');
1883 # get new number in sequence if no number is given or if saveasnew was requested
1884 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1885 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1891 $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
1892 if (OE->save(\%myconfig, \%$form));
1895 $lxdebug->leave_sub();
1899 $lxdebug->enter_sub();
1901 if ($form->{type} =~ /_order$/) {
1902 $form->isblank("transdate", $locale->text('Order Date missing!'));
1904 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1907 $msg = ucfirst $form->{vc};
1908 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1910 # $locale->text('Customer missing!');
1911 # $locale->text('Vendor missing!');
1913 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1914 if ($form->{currency} ne $form->{defaultcurrency});
1918 # if the name changed get new values
1919 if (&check_name($form->{vc})) {
1924 $form->{id} = 0 if $form->{saveasnew};
1926 # this is for the internal notes section for the [email] Subject
1927 if ($form->{type} =~ /_order$/) {
1928 if ($form->{type} eq 'sales_order') {
1929 $form->{label} = $locale->text('Sales Order');
1931 $numberfld = "sonumber";
1932 $ordnumber = "ordnumber";
1934 $form->{label} = $locale->text('Purchase Order');
1936 $numberfld = "ponumber";
1937 $ordnumber = "ordnumber";
1940 $err = $locale->text('Cannot save order!');
1943 if ($form->{type} eq 'sales_quotation') {
1944 $form->{label} = $locale->text('Quotation');
1946 $numberfld = "sqnumber";
1947 $ordnumber = "quonumber";
1949 $form->{label} = $locale->text('Request for Quotation');
1951 $numberfld = "rfqnumber";
1952 $ordnumber = "quonumber";
1955 $err = $locale->text('Cannot save quotation!');
1959 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
1960 unless $form->{$ordnumber};
1964 OE->save(\%myconfig, \%$form);
1965 $form->{simple_save} = 1;
1966 if(!$form->{print_and_save}) {
1967 set_headings("edit");
1971 $lxdebug->leave_sub();
1975 $lxdebug->enter_sub();
1979 if ($form->{type} =~ /_order$/) {
1980 $msg = $locale->text('Are you sure you want to delete Order Number');
1981 $ordnumber = 'ordnumber';
1983 $msg = $locale->text('Are you sure you want to delete Quotation Number');
1984 $ordnumber = 'quonumber';
1990 <form method=post action=$form->{script}>
1993 # delete action variable
1994 map { delete $form->{$_} } qw(action header);
1996 foreach $key (keys %$form) {
1997 $form->{$key} =~ s/\"/"/g;
1998 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2002 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2004 <h4>$msg $form->{$ordnumber}</h4>
2006 <input name=action class=submit type=submit value="|
2007 . $locale->text('Yes') . qq|">
2014 $lxdebug->leave_sub();
2018 $lxdebug->enter_sub();
2020 if ($form->{type} =~ /_order$/) {
2021 $msg = $locale->text('Order deleted!');
2022 $err = $locale->text('Cannot delete order!');
2024 $msg = $locale->text('Quotation deleted!');
2025 $err = $locale->text('Cannot delete quotation!');
2028 $form->redirect($msg) if (OE->delete(\%myconfig, \%$form, $spool));
2031 $lxdebug->leave_sub();
2035 $lxdebug->enter_sub();
2037 if ($form->{type} =~ /_order$/) {
2039 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2040 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2041 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2042 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2044 $form->isblank("transdate", $locale->text('Order Date missing!'))
2045 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2048 # also copy deliverydate from the order
2049 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2050 $form->{orddate} = $form->{transdate};
2052 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2053 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2054 $form->{ordnumber} = "";
2055 $form->{quodate} = $form->{transdate};
2058 # if the name changed get new values
2059 if (&check_name($form->{vc})) {
2064 $form->{cp_id} *= 1;
2066 for $i (1 .. $form->{rowcount}) {
2067 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2068 $form->{"${_}_${i}"})
2069 if ($form->{"${_}_${i}"}) }
2070 qw(ship qty sellprice listprice basefactor));
2073 if ( $form->{type} =~ /_order/
2074 && $form->{currency} ne $form->{defaultcurrency}) {
2076 # check if we need a new exchangerate
2077 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2079 $orddate = $form->current_date(\%myconfig);
2081 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2084 if (!$exchangerate) {
2085 &backorder_exchangerate($orddate, $buysell);
2090 # close orders/quotations
2091 $form->{closed} = 1;
2093 # save order if one ordnumber has been given
2094 # if not it's most likely a collective order, which can't be saved back
2095 # so they just have to be closed
2096 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2097 OE->close_order(\%myconfig, \%$form);
2099 OE->close_orders(\%myconfig, \%$form);
2102 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2104 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2107 $form->{closed} = 0;
2108 $form->{rowcount}--;
2109 $form->{shipto} = 1;
2111 if ($form->{type} =~ /_order$/) {
2112 $form->{exchangerate} = $exchangerate;
2116 if ( $form->{type} eq 'purchase_order'
2117 || $form->{type} eq 'request_quotation') {
2118 $form->{title} = $locale->text('Add Vendor Invoice');
2119 $form->{script} = 'ir.pl';
2123 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2124 $form->{title} = $locale->text('Add Sales Invoice');
2125 $form->{script} = 'is.pl';
2130 # bo creates the id, reset it
2131 map { delete $form->{$_} }
2132 qw(id subject message cc bcc printed emailed queued);
2133 $form->{ $form->{vc} } =~ s/--.*//g;
2134 $form->{type} = "invoice";
2137 $locale = new Locale "$myconfig{countrycode}", "$script";
2139 require "$form->{path}/$form->{script}";
2141 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2143 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2144 qw(creditlimit creditremaining);
2146 $currency = $form->{currency};
2149 $form->{currency} = $currency;
2150 $form->{exchangerate} = "";
2151 $form->{forex} = "";
2152 $form->{exchangerate} = $exchangerate
2156 $form->check_exchangerate(
2157 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2160 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2165 for $i (1 .. $form->{rowcount}) {
2166 $form->{"discount_$i"} =
2167 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2169 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2171 $decimalplaces = ($dec > 2) ? $dec : 2;
2173 # copy delivery date from reqdate for order -> invoice conversion
2174 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2175 unless $form->{"deliverydate_$i"};
2177 $form->{"sellprice_$i"} =
2178 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2181 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2182 $dec_qty = length $dec_qty;
2184 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2186 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2187 qw(partnumber description unit);
2193 $lxdebug->leave_sub();
2196 sub backorder_exchangerate {
2197 $lxdebug->enter_sub();
2198 my ($orddate, $buysell) = @_;
2205 <form method=post action=$form->{script}>
2208 # delete action variable
2209 map { delete $form->{$_} } qw(action header exchangerate);
2211 foreach $key (keys %$form) {
2212 $form->{$key} =~ s/\"/"/g;
2213 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2216 $form->{title} = $locale->text('Add Exchangerate');
2220 <input type=hidden name=path value=$form->{path}>
2221 <input type=hidden name=login value=$form->{login}>
2222 <input type=hidden name=password value=$form->{password}>
2224 <input type=hidden name=exchangeratedate value=$orddate>
2225 <input type=hidden name=buysell value=$buysell>
2228 <tr><th class=listtop>$form->{title}</th></tr>
2229 <tr height="5"></tr>
2234 <th align=right>| . $locale->text('Currency') . qq|</th>
2235 <td>$form->{currency}</td>
2238 <th align=right>| . $locale->text('Date') . qq|</th>
2242 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2243 <td><input name=exchangerate size=11></td>
2253 <input type=hidden name=nextsub value=save_exchangerate>
2255 <input name=action class=submit type=submit value="|
2256 . $locale->text('Continue') . qq|">
2264 $lxdebug->leave_sub();
2267 sub save_exchangerate {
2268 $lxdebug->enter_sub();
2270 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2271 $form->{exchangerate} =
2272 $form->parse_amount(\%myconfig, $form->{exchangerate});
2273 $form->save_exchangerate(\%myconfig, $form->{currency},
2274 $form->{exchangeratedate},
2275 $form->{exchangerate}, $form->{buysell});
2279 $lxdebug->leave_sub();
2282 sub create_backorder {
2283 $lxdebug->enter_sub();
2285 $form->{shipped} = 1;
2287 # figure out if we need to create a backorder
2288 # items aren't saved if qty != 0
2290 for $i (1 .. $form->{rowcount}) {
2291 $totalqty += $qty = $form->{"qty_$i"};
2292 $totalship += $ship = $form->{"ship_$i"};
2294 $form->{"qty_$i"} = $qty - $ship;
2297 if ($totalship == 0) {
2298 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2299 $form->{ordtotal} = 0;
2300 $form->{shipped} = 0;
2304 if ($totalqty == $totalship) {
2305 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2306 $form->{ordtotal} = 0;
2311 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2314 for $i (1 .. $form->{rowcount}) {
2316 $form->{"${_}_$i"} =
2317 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2318 } qw(sellprice discount);
2323 OE->save(\%myconfig, \%$form);
2325 # rebuild rows for invoice
2329 for $i (1 .. $form->{rowcount}) {
2330 $form->{"qty_$i"} = $form->{"ship_$i"};
2332 if ($form->{"qty_$i"}) {
2335 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2340 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2341 $form->{rowcount} = $count;
2343 $lxdebug->leave_sub();
2347 $lxdebug->enter_sub();
2349 $form->{saveasnew} = 1;
2350 $form->{closed} = 0;
2351 map { delete $form->{$_} } qw(printed emailed queued ordnumber quonumber);
2355 $lxdebug->leave_sub();
2358 sub purchase_order {
2359 $lxdebug->enter_sub();
2361 if ( $form->{type} eq 'sales_quotation'
2362 || $form->{type} eq 'request_quotation') {
2363 OE->close_order(\%myconfig, \%$form);
2366 $form->{cp_id} *= 1;
2368 $form->{title} = $locale->text('Add Purchase Order');
2369 $form->{vc} = "vendor";
2370 $form->{type} = "purchase_order";
2374 $lxdebug->leave_sub();
2378 $lxdebug->enter_sub();
2380 if ( $form->{type} eq 'sales_quotation'
2381 || $form->{type} eq 'request_quotation') {
2382 OE->close_order(\%myconfig, $form);
2385 $form->{cp_id} *= 1;
2387 $form->{title} = $locale->text('Add Sales Order');
2388 $form->{vc} = "customer";
2389 $form->{type} = "sales_order";
2393 $lxdebug->leave_sub();
2397 $lxdebug->enter_sub();
2399 $form->{transdate} = $form->current_date(\%myconfig);
2400 delete $form->{duedate};
2402 $form->{closed} = 0;
2405 map { delete $form->{$_} }
2406 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2408 for $i (1 .. $form->{rowcount}) {
2409 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2410 $form->{"${_}_${i}"})
2411 if ($form->{"${_}_${i}"}) }
2412 qw(ship qty sellprice listprice basefactor));
2420 for $i (1 .. $form->{rowcount} - 1) {
2421 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2422 qw(partnumber description unit);
2425 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2426 qw(creditlimit creditremaining);
2430 $lxdebug->leave_sub();