1 # #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger, Accounting
9 # Copyright (c) 1998-2003
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
32 #======================================================================
40 require "$form->{path}/io.pl";
41 require "$form->{path}/arap.pl";
48 # $locale->text('Edit the purchase_order');
49 # $locale->text('Edit the sales_order');
50 # $locale->text('Edit the request_quotation');
51 # $locale->text('Edit the sales_quotation');
53 # $locale->text('Workflow purchase_order');
54 # $locale->text('Workflow sales_order');
55 # $locale->text('Workflow request_quotation');
56 # $locale->text('Workflow sales_quotation');
59 $lxdebug->enter_sub();
63 if ($form->{type} eq 'purchase_order') {
64 $form->{title} = $action eq "edit" ?
65 $locale->text('Edit Purchase Order') :
66 $locale->text('Add Purchase Order');
67 $form->{heading} = $locale->text('Purchase Order');
68 $form->{vc} = 'vendor';
70 if ($form->{type} eq 'sales_order') {
71 $form->{title} = $action eq "edit" ?
72 $locale->text('Edit Sales Order') :
73 $locale->text('Add Sales Order');
74 $form->{heading} = $locale->text('Sales Order');
75 $form->{vc} = 'customer';
77 if ($form->{type} eq 'request_quotation') {
78 $form->{title} = $action eq "edit" ?
79 $locale->text('Edit Request for Quotation') :
80 $locale->text('Add Request for Quotation');
81 $form->{heading} = $locale->text('Request for Quotation');
82 $form->{vc} = 'vendor';
84 if ($form->{type} eq 'sales_quotation') {
85 $form->{title} = $action eq "edit" ?
86 $locale->text('Edit Quotation') :
87 $locale->text('Add Quotation');
88 $form->{heading} = $locale->text('Quotation');
89 $form->{vc} = 'customer';
92 $lxdebug->leave_sub();
96 $lxdebug->enter_sub();
101 "$form->{script}?action=add&type=$form->{type}&vc=$form->{vc}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
102 unless $form->{callback};
108 $lxdebug->leave_sub();
112 $lxdebug->enter_sub();
114 $form->{simple_save} = 0;
116 set_headings("edit");
118 # editing without stuff to edit? try adding it first
119 if ($form->{rowcount}) {
120 map { $id++ if $form->{"id_$_"} } (1 .. $form->{rowcount});
124 undef $form->{rowcount};
135 if ($form->{print_and_save}) {
136 $form->{action} = "print";
137 $form->{resubmit} = 1;
138 $language_id = $form->{language_id};
139 $printer_id = $form->{printer_id};
142 set_headings("edit");
146 if ($form->{print_and_save}) {
147 $form->{language_id} = $language_id;
148 $form->{printer_id} = $printer_id;
152 $lxdebug->leave_sub();
156 $lxdebug->enter_sub();
158 # get customer/vendor
159 $form->all_vc(\%myconfig, $form->{vc},
160 ($form->{vc} eq 'customer') ? "AR" : "AP");
162 # retrieve order/quotation
163 $form->{webdav} = $webdav;
165 $form->{jscalendar} = $jscalendar;
167 OE->retrieve(\%myconfig, \%$form);
169 if ($form->{payment_id}) {
170 $payment_id = $form->{payment_id};
172 if ($form->{language_id}) {
173 $language_id = $form->{language_id};
175 if ($form->{taxzone_id}) {
176 $taxzone_id = $form->{taxzone_id};
180 # if multiple rowcounts (== collective order) then check if the
181 # there were more than one customer (in that case OE::retrieve removes
182 # the content from the field)
183 if ( $form->{rowcount}
184 && $form->{type} eq 'sales_order'
185 && defined $form->{customer}
186 && $form->{customer} eq '') {
188 # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
191 'Collective Orders only work for orders from one customer!')
195 $taxincluded = $form->{taxincluded};
196 $form->{shipto} = 1 if $form->{id};
198 if ($form->{"all_$form->{vc}"}) {
199 unless ($form->{"$form->{vc}_id"}) {
200 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
204 $cp_id = $form->{cp_id};
205 $intnotes = $form->{intnotes};
207 # get customer / vendor
208 if ($form->{type} =~ /(purchase_order|request_quotation)/) {
209 IR->get_vendor(\%myconfig, \%$form);
211 #quote all_vendor Bug 133
212 foreach $ref (@{ $form->{all_vendor} }) {
213 $ref->{name} = $form->quote($ref->{name});
217 if ($form->{type} =~ /sales_(order|quotation)/) {
218 IS->get_customer(\%myconfig, \%$form);
220 #quote all_vendor Bug 133
221 foreach $ref (@{ $form->{all_customer} }) {
222 $ref->{name} = $form->quote($ref->{name});
226 $form->{cp_id} = $cp_id;
228 $form->{payment_id} = $payment_id;
231 $form->{language_id} = $language_id;
234 $form->{taxzone_id} = $taxzone_id;
236 $form->{intnotes} = $intnotes;
237 ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
238 $form->{"old$form->{vc}"} =
239 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
241 # build the popup menus
242 if (@{ $form->{"all_$form->{vc}"} }) {
243 $form->{ $form->{vc} } =
244 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
245 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
246 (@{ $form->{"all_$form->{vc}"} });
250 @curr = split(/:/, $form->{currencies});
252 $form->{defaultcurrency} = $curr[0];
253 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
255 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
257 $form->{taxincluded} = $taxincluded if ($form->{id});
260 if (@{ $form->{all_departments} }) {
261 $form->{selectdepartment} = "<option>\n";
262 $form->{department} = "$form->{department}--$form->{department_id}";
265 $form->{selectdepartment} .=
266 "<option>$_->{description}--$_->{id}\n"
267 } (@{ $form->{all_departments} });
270 $form->{employee} = "$form->{employee}--$form->{employee_id}";
273 if (@{ $form->{all_employees} }) {
274 $form->{selectemployee} = "";
275 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
276 (@{ $form->{all_employees} });
280 $form->{forex} = $form->{exchangerate};
282 $lxdebug->leave_sub();
286 $lxdebug->enter_sub();
287 $form->{formname} = $form->{type} unless $form->{formname};
290 foreach $ref (@{ $form->{form_details} }) {
291 $form->{rowcount} = ++$i;
293 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
295 for my $i (1 .. $form->{rowcount}) {
297 $form->{"discount_$i"} =
298 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
300 $form->{"discount_$i"} =
301 $form->format_amount(\%myconfig, $form->{"discount_$i"});
303 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
305 $decimalplaces = ($dec > 2) ? $dec : 2;
307 # copy reqdate from deliverydate for invoice -> order conversion
308 $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
309 unless $form->{"reqdate_$i"};
311 $form->{"sellprice_$i"} =
312 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
315 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
316 $dec_qty = length $dec_qty;
318 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
320 map { $form->{"${_}_$i"} =~ s/\"/"/g }
321 qw(partnumber description unit);
324 $lxdebug->leave_sub();
328 $lxdebug->enter_sub();
330 my $checkedclosed = $form->{"closed"} ? "checked" : "";
331 my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
333 map { $form->{$_} =~ s/\"/"/g }
334 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
335 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
336 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
338 # use JavaScript Calendar or not
339 $form->{jsscript} = $form->{jscalendar};
342 $payment = qq|<option value=""></option>|;
343 foreach $item (@{ $form->{payment_terms} }) {
344 if ($form->{payment_id} eq $item->{id}) {
345 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
347 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
350 if ($form->{jsscript}) {
352 # with JavaScript Calendar
354 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
355 <td><input type=button name=transdate id="trigger1" value=|
356 . $locale->text('button') . qq|></td>
359 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>
360 <td width="4"><input type=button name=reqdate name=reqdate id="trigger2" value=|
361 . $locale->text('button') . qq|></td>
366 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
367 "reqdate", "BL", "trigger2");
371 # without JavaScript Calendar
373 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>|;
375 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>|;
381 <td colspan=2 align=center>
382 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
383 <label for="closed">| . $locale->text('Closed') . qq|</label>
386 if (($form->{"type"} eq "sales_order") ||
387 ($form->{"type"} eq "purchase_order")) {
389 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
390 <label for="delivered">| . $locale->text('Delivered') . qq|</label>
400 # set option selected
401 foreach $item ($form->{vc}, currency, department, employee) {
402 $form->{"select$item"} =~ s/ selected//;
403 $form->{"select$item"} =~
404 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
407 #quote select[customer|vendor] Bug 133
408 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
410 my @old_project_ids = ($form->{"globalproject_id"});
411 map({ push(@old_project_ids, $form->{"project_id_$_"})
412 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
414 $form->get_lists("contacts" => "ALL_CONTACTS",
415 "shipto" => "ALL_SHIPTO",
416 "projects" => { "key" => "ALL_PROJECTS",
418 "old_id" => \@old_project_ids });
420 my (%labels, @values);
421 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
422 push(@values, $item->{"cp_id"});
423 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
424 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
427 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
428 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
432 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
433 push(@values, $item->{"shipto_id"});
434 $labels{$item->{"shipto_id"}} =
435 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
439 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
441 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
442 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
447 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
448 push(@values, $item->{"id"});
449 $labels{$item->{"id"}} = $item->{"projectnumber"};
451 my $globalprojectnumber =
452 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
453 '-labels' => \%labels,
454 '-default' => $form->{"globalproject_id"}));
456 $form->{exchangerate} =
457 $form->format_amount(\%myconfig, $form->{exchangerate});
459 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
465 $form->{creditlimit} =
466 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
467 $form->{creditremaining} =
468 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
471 <input type=hidden name=forex value=$form->{forex}>
474 if ($form->{currency} ne $form->{defaultcurrency}) {
475 if ($form->{forex}) {
478 . $locale->text('Exchangerate')
479 . qq|</th><td>$form->{exchangerate}</td>
480 <input type=hidden name=exchangerate value=$form->{exchangerate}>
485 . $locale->text('Exchangerate')
486 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
490 $vclabel = ucfirst $form->{vc};
491 $vclabel = $locale->text($vclabel);
495 if ($form->{business}) {
498 <th align=right>| . $locale->text('Business') . qq|</th>
499 <td>$form->{business}</td>
500 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
502 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
508 if ($form->{max_dunning_level}) {
514 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
515 <td><b>$form->{max_dunning_level}</b></td>
516 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
518 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
527 if (@{ $form->{TAXZONE} }) {
528 $form->{selecttaxzone} = "";
529 foreach $item (@{ $form->{TAXZONE} }) {
530 if ($item->{id} == $form->{taxzone_id}) {
531 $form->{selecttaxzone} .=
532 "<option value=$item->{id} selected>" . H($item->{description}) .
535 $form->{selecttaxzone} .=
536 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
541 $form->{selecttaxzone} =~ s/ selected//g;
542 if ($form->{taxzone_id} ne "") {
543 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}>/value=$form->{taxzone_id} selected>/;
549 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
550 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
551 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
555 if ($form->{type} !~ /_quotation$/) {
558 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
559 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
562 <th width=70% align=right nowrap>|
563 . $locale->text('Quotation Number') . qq|</th>
564 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
567 <th width=70% align=right nowrap>|
568 . $locale->text('Customer Order Number') . qq|</th>
569 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
572 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
577 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
582 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
584 $creditremaining = qq|
590 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
591 <td>$form->{creditlimit}</td>
593 <th nowrap>| . $locale->text('Remaining') . qq|</th>
594 <td class="plus$n" nowrap>$form->{creditremaining}</td>
603 ($form->{type} eq 'sales_quotation')
604 ? $locale->text('Valid until')
605 : $locale->text('Required by');
606 if ($form->{type} eq 'sales_quotation') {
609 <th width=70% align=right nowrap>|
610 . $locale->text('Quotation Number') . qq|</th>
611 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
612 <input type=hidden name=ordnumber value="$form->{ordnumber}">
618 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
619 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
620 <input type=hidden name=ordnumber value="$form->{ordnumber}">
628 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
632 <th align=right nowrap=true>$reqlabel</th>
636 $creditremaining = qq| <tr>
643 ($form->{"select$form->{vc}"})
644 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">|
645 : qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
649 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
650 <td colspan=3><select name=department>$form->{selectdepartment}</select>
651 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
654 | if $form->{selectdepartment};
657 <input type=hidden name=employee value="$form->{employee}">
660 if ($form->{type} eq 'sales_order') {
661 if ($form->{selectemployee}) {
663 <input type=hidden name=customer_klass value=$form->{customer_klass}>
665 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
666 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
667 <input type=hidden name=selectemployee value="$form->{selectemployee}">
674 <input type=hidden name=customer_klass value=$form->{customer_klass}>
676 <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
677 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
678 <input type=hidden name=selectemployee value="$form->{selectemployee}">
683 if ($form->{resubmit} && ($form->{format} eq "html")) {
685 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
686 } elsif ($form->{resubmit}) {
687 $onload = qq|document.oe.submit()|;
692 $credittext = $locale->text('Credit Limit exceeded!!!');
693 if ($creditwarning) {
694 $onload = qq|alert('$credittext')|;
697 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
702 <body onLoad="$onload">
704 <form method=post name=oe action=$form->{script}>
705 <script type="text/javascript" src="js/common.js"></script>
706 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
707 <script type="text/javascript" src="js/vendor_selection.js"></script>
708 <script type="text/javascript" src="js/calculate_qty.js"></script>
710 <input type=hidden name=id value=$form->{id}>
711 <input type=hidden name=action value=$form->{action}>
713 <input type=hidden name=type value=$form->{type}>
714 <input type=hidden name=formname value=$form->{formname}>
715 <input type=hidden name=media value=$form->{media}>
716 <input type=hidden name=format value=$form->{format}>
717 <input type=hidden name=proforma value=$form->{proforma}>
719 <input type=hidden name=queued value="$form->{queued}">
720 <input type=hidden name=printed value="$form->{printed}">
721 <input type=hidden name=emailed value="$form->{emailed}">
723 <input type=hidden name=vc value=$form->{vc}>
725 <input type=hidden name=title value="$form->{title}">
727 <input type=hidden name=discount value=$form->{discount}>
728 <input type=hidden name=creditlimit value=$form->{creditlimit}>
729 <input type=hidden name=creditremaining value=$form->{creditremaining}>
731 <input type=hidden name=tradediscount value=$form->{tradediscount}>
732 <input type=hidden name=business value=$form->{business}>
733 <input type=hidden name=webdav value=$webdav>
737 <th class=listtop>$form->{title}</th>
747 <th align=right>$vclabel</th>
748 <td colspan=3>$vc</td>
749 <input type=hidden name=$form->{vc}_id value=$form->{"$form->{vc}_id"}>
750 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
751 <th align=richt nowrap>|
752 . $locale->text('Contact Person') . qq|</th>
753 <td colspan=3>$contact</td>
761 <th align=right>| . $locale->text('Currency') . qq|</th>
762 <td><select name=currency>$form->{selectcurrency}</select></td>
763 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
764 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
768 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
769 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
772 <th align=right>| . $locale->text('Ship via') . qq|</th>
773 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
780 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
782 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
783 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
787 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
789 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
790 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
803 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
804 <td>$globalprojectnumber</td>
815 <!-- shipto are in hidden variables -->
817 <input type=hidden name=shiptoname value="$form->{shiptoname}">
818 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
819 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
820 <input type=hidden name=shiptocity value="$form->{shiptocity}">
821 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
822 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
823 <input type=hidden name=shiptophone value="$form->{shiptophone}">
824 <input type=hidden name=shiptofax value="$form->{shiptofax}">
825 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
826 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
827 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
829 <!-- email variables -->
830 <input type=hidden name=message value="$form->{message}">
831 <input type=hidden name=email value="$form->{email}">
832 <input type=hidden name=subject value="$form->{subject}">
833 <input type=hidden name=cc value="$form->{cc}">
834 <input type=hidden name=bcc value="$form->{bcc}">
836 <input type=hidden name=taxpart value="$form->{taxpart}">
837 <input type=hidden name=taxservice value="$form->{taxservice}">
839 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
842 foreach $item (split / /, $form->{taxaccounts}) {
844 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
845 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
848 $lxdebug->leave_sub();
852 $lxdebug->enter_sub();
854 $form->{invtotal} = $form->{invsubtotal};
856 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
859 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
862 $rows = ($rows > $introws) ? $rows : $introws;
864 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
866 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
868 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
871 if ($form->{taxaccounts}) {
873 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
874 . $locale->text('Tax Included') . qq|</b><br><br>
878 if (!$form->{taxincluded}) {
880 foreach $item (split / /, $form->{taxaccounts}) {
881 if ($form->{"${item}_base"}) {
882 $form->{invtotal} += $form->{"${item}_total"} =
884 $form->{"${item}_base"} * $form->{"${item}_rate"},
886 $form->{"${item}_total"} =
887 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
891 <th align=right>$form->{"${item}_description"}</th>
892 <td align=right>$form->{"${item}_total"}</td>
898 $form->{invsubtotal} =
899 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
903 <th align=right>| . $locale->text('Subtotal') . qq|</th>
904 <td align=right>$form->{invsubtotal}</td>
910 if ($form->{taxincluded}) {
911 foreach $item (split / /, $form->{taxaccounts}) {
912 if ($form->{"${item}_base"}) {
913 $form->{"${item}_total"} =
915 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
916 (1 + $form->{"${item}_rate"})
919 $form->{"${item}_netto"} =
921 ($form->{"${item}_base"} - $form->{"${item}_total"}),
923 $form->{"${item}_total"} =
924 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
925 $form->{"${item}_netto"} =
926 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
930 <th align=right>Enthaltene $form->{"${item}_description"}</th>
931 <td align=right>$form->{"${item}_total"}</td>
934 <th align=right>Nettobetrag</th>
935 <td align=right>$form->{"${item}_netto"}</td>
943 $form->{oldinvtotal} = $form->{invtotal};
945 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
955 <th align=left>| . $locale->text('Notes') . qq|</th>
956 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
962 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
963 <td><select name=payment_id tabindex=24>$payment
967 <td align=right width=100%>
973 <th align=right>| . $locale->text('Total') . qq|</th>
974 <td align=right>$form->{invtotal}</td>
982 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
983 <input type=hidden name=oldtotalpaid value=$totalpaid>
985 <td><hr size=3 noshade></td>
993 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
996 <td align=left width=30%><b>Dateiname</b></td>
997 <td align=left width=70%><b>Webdavlink</b></td>
999 foreach $file (keys %{ $form->{WEBDAV} }) {
1002 <td align=left>$file</td>
1003 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1011 <td><hr size=3 noshade></td>
1018 <input type=hidden name=jscalendar value=$form->{jscalendar}>
1031 | . $locale->text("Edit the $form->{type}") . qq|<br>
1032 <input class=submit type=submit name=action id=update_button value="|
1033 . $locale->text('Update') . qq|">
1034 <input class=submit type=submit name=action value="|
1035 . $locale->text('Ship to') . qq|">
1036 <input class=submit type=submit name=action value="|
1037 . $locale->text('Print') . qq|">
1038 <input class=submit type=submit name=action value="|
1039 . $locale->text('E-mail') . qq|">
1040 <input class=submit type=submit name=action value="|
1041 . $locale->text('Save') . qq|">
1042 <input class=submit type=submit name=action value="|
1043 . $locale->text('Save and Close') . qq|">
1046 if (($form->{id})) {
1048 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1049 <input class=submit type=submit name=action value="|
1050 . $locale->text('Save as new') . qq|">
1051 <input class=submit type=submit name=action value="|
1052 . $locale->text('Delete') . qq|">|;
1053 if (($form->{type} =~ /sales_quotation$/)) {
1055 <input class=submit type=submit name=action value="|
1056 . $locale->text('Sales Order') . qq|">|;
1058 if ($form->{type} =~ /request_quotation$/) {
1060 <input class=submit type=submit name=action value="|
1061 . $locale->text('Purchase Order') . qq|">|;
1065 <input class=submit type=submit name=action value="|
1066 . $locale->text('Invoice') . qq|">
1070 if ($form->{type} =~ /sales_order$/) {
1072 <br>$form->{heading} als neue Vorlage verwenden für<br>
1073 <input class=submit type=submit name=action value="|
1074 . $locale->text('Purchase Order') . qq|">
1075 <input class=submit type=submit name=action value="|
1076 . $locale->text('Quotation') . qq|">
1079 } elsif ($form->{type} =~ /purchase_order$/) {
1081 <br>$form->{heading} als neue Vorlage verwenden für<br>
1082 <input class=submit type=submit name=action value="|
1083 . $locale->text('Sales Order') . qq|">
1084 <input class=submit type=submit name=action value="|
1085 . $locale->text('Request for Quotation') . qq|">
1090 <br>$form->{heading} als neue Vorlage verwenden für<br>
1091 <input class=submit type=submit name=action value="|
1092 . $locale->text('Order') . qq|">
1095 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1097 <br>Workflow $form->{heading}<br>
1098 <input class=submit type=submit name=action value="|
1099 . $locale->text('Save as new') . qq|">
1100 <input class=submit type=submit name=action value="|
1101 . $locale->text('Invoice') . qq|">
1107 <input type=hidden name=rowcount value=$form->{rowcount}>
1109 <input name=callback type=hidden value="$form->{callback}">
1111 <input type=hidden name=path value=$form->{path}>
1112 <input type=hidden name=login value=$form->{login}>
1113 <input type=hidden name=password value=$form->{password}>
1120 $lxdebug->leave_sub();
1124 $lxdebug->enter_sub();
1126 set_headings($form->{"id"} ? "edit" : "add");
1128 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1129 qw(exchangerate creditlimit creditremaining);
1130 $form->{update} = 1;
1132 &check_name($form->{vc});
1135 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1136 $form->{exchangerate} = $exchangerate
1140 $form->check_exchangerate(
1141 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1145 $i = $form->{rowcount};
1147 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1149 if ( ($form->{"partnumber_$i"} eq "")
1150 && ($form->{"description_$i"} eq "")
1151 && ($form->{"partsgroup_$i"} eq "")) {
1153 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1158 if ( $form->{type} eq 'purchase_order'
1159 || $form->{type} eq 'request_quotation') {
1160 IR->retrieve_item(\%myconfig, \%$form);
1162 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1163 IS->retrieve_item(\%myconfig, \%$form);
1166 my $rows = scalar @{ $form->{item_list} };
1168 $form->{"discount_$i"} =
1169 $form->format_amount(\%myconfig, $form->{discount} * 100);
1172 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1181 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1182 if ($form->{"not_discountable_$i"}) {
1183 $form->{"discount_$i"} = 0;
1185 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1186 qw(partnumber description unit);
1187 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1188 keys %{ $form->{item_list}[0] };
1189 if ($form->{"part_payment_id_$i"} ne "") {
1190 $form->{payment_id} = $form->{"part_payment_id_$i"};
1193 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1195 ($dec) = ($s =~ /\.(\d+)/);
1197 $decimalplaces = ($dec > 2) ? $dec : 2;
1200 $form->{"sellprice_$i"} = $sellprice;
1203 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1205 # if there is an exchange rate adjust sellprice
1206 $form->{"sellprice_$i"} /= $exchangerate;
1210 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1211 (1 - $form->{"discount_$i"} / 100);
1212 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1213 map { $form->{"${_}_base"} += $amount }
1214 (split / /, $form->{"taxaccounts_$i"});
1215 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1216 split / /, $form->{taxaccounts}
1217 if !$form->{taxincluded};
1219 $form->{creditremaining} -= $amount;
1221 $form->{"sellprice_$i"} =
1222 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1225 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1227 # get pricegroups for parts
1228 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1230 # build up html code for prices_$i
1231 &set_pricegroup($i);
1238 # ok, so this is a new part
1239 # ask if it is a part or service item
1241 if ( $form->{"partsgroup_$i"}
1242 && ($form->{"partsnumber_$i"} eq "")
1243 && ($form->{"description_$i"} eq "")) {
1244 $form->{rowcount}--;
1245 $form->{"discount_$i"} = "";
1249 $form->{"id_$i"} = 0;
1250 $form->{"unit_$i"} = $locale->text('ea');
1258 $lxdebug->leave_sub();
1262 $lxdebug->enter_sub();
1264 if ($form->{type} eq 'purchase_order') {
1265 $form->{title} = $locale->text('Purchase Orders');
1266 $form->{vc} = 'vendor';
1267 $ordlabel = $locale->text('Order Number');
1268 $ordnumber = 'ordnumber';
1269 $employee = $locale->text('Employee');
1272 if ($form->{type} eq 'request_quotation') {
1273 $form->{title} = $locale->text('Request for Quotations');
1274 $form->{vc} = 'vendor';
1275 $ordlabel = $locale->text('RFQ Number');
1276 $ordnumber = 'quonumber';
1277 $employee = $locale->text('Employee');
1280 if ($form->{type} eq 'sales_order') {
1281 $form->{title} = $locale->text('Sales Orders');
1282 $form->{vc} = 'customer';
1283 $ordlabel = $locale->text('Order Number');
1284 $ordnumber = 'ordnumber';
1285 $employee = $locale->text('Salesperson');
1288 if ($form->{type} eq 'sales_quotation') {
1289 $form->{title} = $locale->text('Quotations');
1290 $form->{vc} = 'customer';
1291 $ordlabel = $locale->text('Quotation Number');
1292 $ordnumber = 'quonumber';
1293 $employee = $locale->text('Employee');
1296 # setup vendor / customer selection
1297 $form->all_vc(\%myconfig, $form->{vc},
1298 ($form->{vc} eq 'customer') ? "AR" : "AP");
1300 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
1301 @{ $form->{"all_$form->{vc}"} };
1303 $vclabel = ucfirst $form->{vc};
1304 $vclabel = $locale->text($vclabel);
1306 # $locale->text('Vendor')
1307 # $locale->text('Customer')
1311 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
1312 : qq|<input name=$form->{vc} size=35>|;
1315 if (@{ $form->{all_departments} }) {
1316 $form->{selectdepartment} = "<option>\n";
1319 $form->{selectdepartment} .=
1320 "<option>$_->{description}--$_->{id}\n"
1321 } (@{ $form->{all_departments} });
1326 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1327 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1329 | if $form->{selectdepartment};
1332 <input type=hidden name="open" value=1>
1336 if (($form->{"type"} eq "sales_order") ||
1337 ($form->{"type"} eq "purchase_order")) {
1340 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1341 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1342 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1343 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1348 # use JavaScript Calendar or not
1349 $form->{jsscript} = $jscalendar;
1351 if ($form->{jsscript}) {
1353 # with JavaScript Calendar
1355 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1356 <input type=button name=transdatefrom id="trigger3" value=|
1357 . $locale->text('button') . qq|></td>
1360 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1361 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1362 . $locale->text('button') . qq|></td>
1367 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1368 "transdateto", "BL", "trigger4");
1371 # without JavaScript Calendar
1373 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1375 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1378 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1383 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1384 push(@values, $item->{"id"});
1385 $labels{$item->{"id"}} = $item->{"projectnumber"};
1388 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1389 '-labels' => \%labels));
1396 <form method=post action=$form->{script}>
1400 <th class=listtop>$form->{title}</th>
1402 <tr height="5"></tr>
1407 <th align=right>$vclabel</th>
1408 <td colspan=3>$vc</td>
1412 <th align=right>$ordlabel</th>
1413 <td colspan=3><input name="$ordnumber" size=20></td>
1416 <th align="right">| . $locale->text("Project Number") . qq|</th>
1417 <td colspan="3">$projectnumber</td>
1420 <th align=right>| . $locale->text('From') . qq|</th>
1422 <th align=right>| . $locale->text('Bis') . qq|</th>
1425 <input type=hidden name=sort value=transdate>
1427 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1433 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1434 | . $locale->text('ID') . qq|</td>
1435 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1436 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1437 . $locale->text('Date') . qq|</td>
1438 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1439 . $locale->text('Required by') . qq|</td>
1442 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
1443 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1444 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1445 . $locale->text('Ship via') . qq|</td>
1446 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1449 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1450 . $locale->text('Amount') . qq|</td>
1451 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1452 . $locale->text('Tax') . qq|</td>
1453 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1454 . $locale->text('Total') . qq|</td>
1455 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1456 . $locale->text('Project Number') . qq|</td>
1459 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1460 . $locale->text('Subtotal') . qq|</td>
1468 <tr><td colspan=4><hr size=3 noshade></td></tr>
1474 <input type=hidden name=nextsub value=orders>
1475 <input type=hidden name=path value=$form->{path}>
1476 <input type=hidden name=login value=$form->{login}>
1477 <input type=hidden name=password value=$form->{password}>
1478 <input type=hidden name=vc value=$form->{vc}>
1479 <input type=hidden name=type value=$form->{type}>
1481 <input class=submit type=submit name=action value="|
1482 . $locale->text('Continue') . qq|">
1489 $lxdebug->leave_sub();
1493 $lxdebug->enter_sub();
1495 # split vendor / customer
1496 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1497 split(/--/, $form->{ $form->{vc} });
1499 OE->transactions(\%myconfig, \%$form);
1501 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1503 $number = $form->escape($form->{$ordnumber});
1504 $name = $form->escape($form->{ $form->{vc} });
1505 $department = $form->escape($form->{department});
1509 "$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";
1511 # construct callback
1512 $number = $form->escape($form->{$ordnumber}, 1);
1513 $name = $form->escape($form->{ $form->{vc} }, 1);
1514 $department = $form->escape($form->{department}, 1);
1517 "$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";
1520 $form->sort_columns("transdate", "reqdate", "id", "$ordnumber",
1521 "name", "netamount", "tax", "amount",
1522 "curr", "employee", "shipvia", "globalprojectnumber",
1523 "open", "closed", "delivered");
1525 $form->{l_open} = $form->{l_closed} = "Y"
1526 if ($form->{open} && $form->{closed});
1528 $form->{"l_delivered"} = "Y"
1529 if ($form->{"delivered"} && $form->{"notdelivered"});
1531 foreach $item (@columns) {
1532 if ($form->{"l_$item"} eq "Y") {
1533 push @column_index, $item;
1535 # add column to href and callback
1536 $callback .= "&l_$item=Y";
1537 $href .= "&l_$item=Y";
1541 # only show checkboxes if gotten here via sales_order form.
1542 if ($form->{type} =~ /sales_order/) {
1543 unshift @column_index, "ids";
1546 if ($form->{l_subtotal} eq 'Y') {
1547 $callback .= "&l_subtotal=Y";
1548 $href .= "&l_subtotal=Y";
1551 if ($form->{vc} eq 'vendor') {
1552 if ($form->{type} eq 'purchase_order') {
1553 $form->{title} = $locale->text('Purchase Orders');
1555 $form->{title} = $locale->text('Request for Quotations');
1557 $name = $locale->text('Vendor');
1558 $employee = $locale->text('Employee');
1560 if ($form->{vc} eq 'customer') {
1561 if ($form->{type} eq 'sales_order') {
1562 $form->{title} = $locale->text('Sales Orders');
1563 $employee = $locale->text('Salesperson');
1565 $form->{title} = $locale->text('Quotations');
1566 $employee = $locale->text('Employee');
1568 $name = $locale->text('Customer');
1571 $column_header{id} =
1572 qq|<th><a class=listheading href=$href&sort=id>|
1573 . $locale->text('ID')
1575 $column_header{transdate} =
1576 qq|<th><a class=listheading href=$href&sort=transdate>|
1577 . $locale->text('Date')
1579 $column_header{reqdate} =
1580 qq|<th><a class=listheading href=$href&sort=reqdate>|
1581 . $locale->text('Required by')
1583 $column_header{ordnumber} =
1584 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1585 . $locale->text('Order')
1587 $column_header{quonumber} =
1588 qq|<th><a class=listheading href=$href&sort=quonumber>|
1589 . ($form->{"type"} eq "request_quotation" ?
1590 $locale->text('RFQ') :
1591 $locale->text('Quotation'))
1593 $column_header{name} =
1594 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1595 $column_header{netamount} =
1596 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1597 $column_header{tax} =
1598 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1599 $column_header{amount} =
1600 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1601 $column_header{curr} =
1602 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1603 $column_header{shipvia} =
1604 qq|<th><a class=listheading href=$href&sort=shipvia>|
1605 . $locale->text('Ship via')
1607 $column_header{globalprojectnumber} =
1608 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1609 $column_header{open} =
1610 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1611 $column_header{closed} =
1612 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1613 $column_header{"delivered"} =
1614 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1616 $column_header{employee} =
1617 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1619 $column_header{ids} = qq|<th></th>|;
1621 if ($form->{ $form->{vc} }) {
1622 $option = $locale->text(ucfirst $form->{vc});
1623 $option .= " : $form->{$form->{vc}}";
1625 if ($form->{department}) {
1626 $option .= "\n<br>" if ($option);
1627 ($department) = split /--/, $form->{department};
1628 $option .= $locale->text('Department') . " : $department";
1630 if ($form->{transdatefrom}) {
1632 . $locale->text('From') . " "
1633 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1635 if ($form->{transdateto}) {
1637 . $locale->text('Bis') . " "
1638 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1640 if ($form->{open}) {
1641 $option .= "\n<br>" if ($option);
1642 $option .= $locale->text('Open');
1644 if ($form->{closed}) {
1645 $option .= "\n<br>" if ($option);
1646 $option .= $locale->text('Closed');
1654 <form method="post" action="oe.pl">
1657 <th class=listtop>$form->{title}</th>
1659 <tr height="5"></tr>
1666 <tr class=listheading>|;
1668 map { print "\n$column_header{$_}" } @column_index;
1674 # add sort and escape callback
1675 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1677 if (@{ $form->{OE} }) {
1678 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1683 foreach $oe (@{ $form->{OE} }) {
1684 $form->{rowcount} = ++$j;
1686 if ($form->{l_subtotal} eq 'Y') {
1687 if ($sameitem ne $oe->{ $form->{sort} }) {
1689 $sameitem = $oe->{ $form->{sort} };
1693 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1695 $column_data{netamount} =
1697 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1699 $column_data{tax} = "<td align=right>"
1700 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1703 $column_data{amount} =
1705 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1707 $totalnetamount += $oe->{netamount};
1708 $totalamount += $oe->{amount};
1710 $subtotalnetamount += $oe->{netamount};
1711 $subtotalamount += $oe->{amount};
1714 qq|<td><input name="id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1715 $column_data{id} = "<td>$oe->{id}</td>";
1716 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1717 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1719 $column_data{$ordnumber} =
1720 "<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>";
1721 $column_data{name} = "<td>$oe->{name}</td>";
1723 $column_data{employee} = "<td>$oe->{employee} </td>";
1724 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1725 $column_data{globalprojectnumber} = "<td>" . H($oe->{globalprojectnumber}) . "</td>";
1727 if ($oe->{closed}) {
1728 $column_data{closed} = "<td align=center>X</td>";
1729 $column_data{open} = "<td> </td>";
1731 $column_data{closed} = "<td> </td>";
1732 $column_data{open} = "<td align=center>X</td>";
1734 $column_data{"delivered"} = "<td>" .
1735 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1741 <tr class=listrow$i>";
1743 map { print "\n$column_data{$_}" } @column_index;
1751 if ($form->{l_subtotal} eq 'Y') {
1757 <tr class=listtotal>|;
1759 map { $column_data{$_} = "<td> </td>" } @column_index;
1761 $column_data{netamount} =
1762 "<th class=listtotal align=right>"
1763 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1764 $column_data{tax} = "<th class=listtotal align=right>"
1765 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1768 $column_data{amount} =
1769 "<th class=listtotal align=right>"
1770 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1772 map { print "\n$column_data{$_}" } @column_index;
1780 <td><hr size=3 noshade></td>
1784 # multiple invoice edit button only if gotten there via sales_order form.
1786 if ($form->{type} =~ /sales_order/) {
1788 <input type="hidden" name="path" value="$form->{path}">
1789 <input class"submit" type="submit" name="action" value="|
1790 . $locale->text('Continue') . qq|">
1791 <input type="hidden" name="nextsub" value="edit">
1792 <input type="hidden" name="type" value="$form->{type}">
1793 <input type="hidden" name="vc" value="$form->{vc}">
1794 <input type="hidden" name="login" value="$form->{login}">
1795 <input type="hidden" name="password" value="$form->{password}">
1796 <input type="hidden" name="callback" value="$callback">
1797 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1804 <form method=post action=$form->{script}>
1806 <input name=callback type=hidden value="$form->{callback}">
1808 <input type=hidden name=type value=$form->{type}>
1809 <input type=hidden name=vc value=$form->{vc}>
1811 <input type=hidden name=path value=$form->{path}>
1812 <input type=hidden name=login value=$form->{login}>
1813 <input type=hidden name=password value=$form->{password}>
1821 $lxdebug->leave_sub();
1825 $lxdebug->enter_sub();
1827 map { $column_data{$_} = "<td> </td>" } @column_index;
1829 $column_data{netamount} =
1830 "<th class=listsubtotal align=right>"
1831 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1833 $column_data{tax} = "<td class=listsubtotal align=right>"
1834 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1837 $column_data{amount} =
1838 "<th class=listsubtotal align=right>"
1839 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1841 $subtotalnetamount = 0;
1842 $subtotalamount = 0;
1845 <tr class=listsubtotal>
1848 map { print "\n$column_data{$_}" } @column_index;
1854 $lxdebug->leave_sub();
1857 sub save_and_close {
1858 $lxdebug->enter_sub();
1860 if ($form->{type} =~ /_order$/) {
1861 $form->isblank("transdate", $locale->text('Order Date missing!'));
1863 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1866 $msg = ucfirst $form->{vc};
1867 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1869 # $locale->text('Customer missing!');
1870 # $locale->text('Vendor missing!');
1872 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1873 if ($form->{currency} ne $form->{defaultcurrency});
1877 # if the name changed get new values
1878 if (&check_name($form->{vc})) {
1883 $form->{id} = 0 if $form->{saveasnew};
1885 # this is for the internal notes section for the [email] Subject
1886 if ($form->{type} =~ /_order$/) {
1887 if ($form->{type} eq 'sales_order') {
1888 $form->{label} = $locale->text('Sales Order');
1890 $numberfld = "sonumber";
1891 $ordnumber = "ordnumber";
1893 $form->{label} = $locale->text('Purchase Order');
1895 $numberfld = "ponumber";
1896 $ordnumber = "ordnumber";
1899 $err = $locale->text('Cannot save order!');
1902 if ($form->{type} eq 'sales_quotation') {
1903 $form->{label} = $locale->text('Quotation');
1905 $numberfld = "sqnumber";
1906 $ordnumber = "quonumber";
1908 $form->{label} = $locale->text('Request for Quotation');
1910 $numberfld = "rfqnumber";
1911 $ordnumber = "quonumber";
1914 $err = $locale->text('Cannot save quotation!');
1918 # get new number in sequence if no number is given or if saveasnew was requested
1919 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1920 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1926 $form->{label} . " $form->{$ordnumber} " . $locale->text('saved!'))
1927 if (OE->save(\%myconfig, \%$form));
1930 $lxdebug->leave_sub();
1934 $lxdebug->enter_sub();
1936 if ($form->{type} =~ /_order$/) {
1937 $form->isblank("transdate", $locale->text('Order Date missing!'));
1939 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1942 $msg = ucfirst $form->{vc};
1943 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1945 # $locale->text('Customer missing!');
1946 # $locale->text('Vendor missing!');
1948 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1949 if ($form->{currency} ne $form->{defaultcurrency});
1953 # if the name changed get new values
1954 if (&check_name($form->{vc})) {
1959 $form->{id} = 0 if $form->{saveasnew};
1961 # this is for the internal notes section for the [email] Subject
1962 if ($form->{type} =~ /_order$/) {
1963 if ($form->{type} eq 'sales_order') {
1964 $form->{label} = $locale->text('Sales Order');
1966 $numberfld = "sonumber";
1967 $ordnumber = "ordnumber";
1969 $form->{label} = $locale->text('Purchase Order');
1971 $numberfld = "ponumber";
1972 $ordnumber = "ordnumber";
1975 $err = $locale->text('Cannot save order!');
1978 if ($form->{type} eq 'sales_quotation') {
1979 $form->{label} = $locale->text('Quotation');
1981 $numberfld = "sqnumber";
1982 $ordnumber = "quonumber";
1984 $form->{label} = $locale->text('Request for Quotation');
1986 $numberfld = "rfqnumber";
1987 $ordnumber = "quonumber";
1990 $err = $locale->text('Cannot save quotation!');
1994 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
1995 unless $form->{$ordnumber};
1999 OE->save(\%myconfig, \%$form);
2000 $form->{simple_save} = 1;
2001 if(!$form->{print_and_save}) {
2002 set_headings("edit");
2006 $lxdebug->leave_sub();
2010 $lxdebug->enter_sub();
2014 if ($form->{type} =~ /_order$/) {
2015 $msg = $locale->text('Are you sure you want to delete Order Number');
2016 $ordnumber = 'ordnumber';
2018 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2019 $ordnumber = 'quonumber';
2025 <form method=post action=$form->{script}>
2028 # delete action variable
2029 map { delete $form->{$_} } qw(action header);
2031 foreach $key (keys %$form) {
2032 $form->{$key} =~ s/\"/"/g;
2033 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2037 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2039 <h4>$msg $form->{$ordnumber}</h4>
2041 <input name=action class=submit type=submit value="|
2042 . $locale->text('Yes') . qq|">
2049 $lxdebug->leave_sub();
2053 $lxdebug->enter_sub();
2055 if ($form->{type} =~ /_order$/) {
2056 $msg = $locale->text('Order deleted!');
2057 $err = $locale->text('Cannot delete order!');
2059 $msg = $locale->text('Quotation deleted!');
2060 $err = $locale->text('Cannot delete quotation!');
2063 $form->redirect($msg) if (OE->delete(\%myconfig, \%$form, $spool));
2066 $lxdebug->leave_sub();
2070 $lxdebug->enter_sub();
2072 if ($form->{type} =~ /_order$/) {
2074 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2075 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2076 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2077 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2079 $form->isblank("transdate", $locale->text('Order Date missing!'))
2080 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2083 # also copy deliverydate from the order
2084 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2085 $form->{orddate} = $form->{transdate};
2087 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2088 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2089 $form->{ordnumber} = "";
2090 $form->{quodate} = $form->{transdate};
2093 # if the name changed get new values
2094 if (&check_name($form->{vc})) {
2099 $form->{cp_id} *= 1;
2101 for $i (1 .. $form->{rowcount}) {
2102 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2103 $form->{"${_}_${i}"})
2104 if ($form->{"${_}_${i}"}) }
2105 qw(ship qty sellprice listprice basefactor));
2108 if ( $form->{type} =~ /_order/
2109 && $form->{currency} ne $form->{defaultcurrency}) {
2111 # check if we need a new exchangerate
2112 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2114 $orddate = $form->current_date(\%myconfig);
2116 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2119 if (!$exchangerate) {
2120 &backorder_exchangerate($orddate, $buysell);
2125 # close orders/quotations
2126 $form->{closed} = 1;
2128 # save order if one ordnumber has been given
2129 # if not it's most likely a collective order, which can't be saved back
2130 # so they just have to be closed
2131 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2132 OE->close_order(\%myconfig, \%$form);
2134 OE->close_orders(\%myconfig, \%$form);
2137 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2139 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2142 $form->{closed} = 0;
2143 $form->{rowcount}--;
2144 $form->{shipto} = 1;
2146 if ($form->{type} =~ /_order$/) {
2147 $form->{exchangerate} = $exchangerate;
2151 if ( $form->{type} eq 'purchase_order'
2152 || $form->{type} eq 'request_quotation') {
2153 $form->{title} = $locale->text('Add Vendor Invoice');
2154 $form->{script} = 'ir.pl';
2158 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2159 $form->{title} = $locale->text('Add Sales Invoice');
2160 $form->{script} = 'is.pl';
2165 # bo creates the id, reset it
2166 map { delete $form->{$_} }
2167 qw(id subject message cc bcc printed emailed queued);
2168 $form->{ $form->{vc} } =~ s/--.*//g;
2169 $form->{type} = "invoice";
2172 $locale = new Locale "$myconfig{countrycode}", "$script";
2174 require "$form->{path}/$form->{script}";
2176 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2178 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2179 qw(creditlimit creditremaining);
2181 $currency = $form->{currency};
2184 $form->{currency} = $currency;
2185 $form->{exchangerate} = "";
2186 $form->{forex} = "";
2187 $form->{exchangerate} = $exchangerate
2191 $form->check_exchangerate(
2192 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2195 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2200 for $i (1 .. $form->{rowcount}) {
2201 $form->{"discount_$i"} =
2202 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2204 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2206 $decimalplaces = ($dec > 2) ? $dec : 2;
2208 # copy delivery date from reqdate for order -> invoice conversion
2209 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2210 unless $form->{"deliverydate_$i"};
2212 $form->{"sellprice_$i"} =
2213 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2216 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2217 $dec_qty = length $dec_qty;
2219 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2221 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2222 qw(partnumber description unit);
2228 $lxdebug->leave_sub();
2231 sub backorder_exchangerate {
2232 $lxdebug->enter_sub();
2233 my ($orddate, $buysell) = @_;
2240 <form method=post action=$form->{script}>
2243 # delete action variable
2244 map { delete $form->{$_} } qw(action header exchangerate);
2246 foreach $key (keys %$form) {
2247 $form->{$key} =~ s/\"/"/g;
2248 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2251 $form->{title} = $locale->text('Add Exchangerate');
2255 <input type=hidden name=path value=$form->{path}>
2256 <input type=hidden name=login value=$form->{login}>
2257 <input type=hidden name=password value=$form->{password}>
2259 <input type=hidden name=exchangeratedate value=$orddate>
2260 <input type=hidden name=buysell value=$buysell>
2263 <tr><th class=listtop>$form->{title}</th></tr>
2264 <tr height="5"></tr>
2269 <th align=right>| . $locale->text('Currency') . qq|</th>
2270 <td>$form->{currency}</td>
2273 <th align=right>| . $locale->text('Date') . qq|</th>
2277 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2278 <td><input name=exchangerate size=11></td>
2288 <input type=hidden name=nextsub value=save_exchangerate>
2290 <input name=action class=submit type=submit value="|
2291 . $locale->text('Continue') . qq|">
2299 $lxdebug->leave_sub();
2302 sub save_exchangerate {
2303 $lxdebug->enter_sub();
2305 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2306 $form->{exchangerate} =
2307 $form->parse_amount(\%myconfig, $form->{exchangerate});
2308 $form->save_exchangerate(\%myconfig, $form->{currency},
2309 $form->{exchangeratedate},
2310 $form->{exchangerate}, $form->{buysell});
2314 $lxdebug->leave_sub();
2317 sub create_backorder {
2318 $lxdebug->enter_sub();
2320 $form->{shipped} = 1;
2322 # figure out if we need to create a backorder
2323 # items aren't saved if qty != 0
2325 for $i (1 .. $form->{rowcount}) {
2326 $totalqty += $qty = $form->{"qty_$i"};
2327 $totalship += $ship = $form->{"ship_$i"};
2329 $form->{"qty_$i"} = $qty - $ship;
2332 if ($totalship == 0) {
2333 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2334 $form->{ordtotal} = 0;
2335 $form->{shipped} = 0;
2339 if ($totalqty == $totalship) {
2340 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2341 $form->{ordtotal} = 0;
2346 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2349 for $i (1 .. $form->{rowcount}) {
2351 $form->{"${_}_$i"} =
2352 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2353 } qw(sellprice discount);
2358 OE->save(\%myconfig, \%$form);
2360 # rebuild rows for invoice
2364 for $i (1 .. $form->{rowcount}) {
2365 $form->{"qty_$i"} = $form->{"ship_$i"};
2367 if ($form->{"qty_$i"}) {
2370 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2375 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2376 $form->{rowcount} = $count;
2378 $lxdebug->leave_sub();
2382 $lxdebug->enter_sub();
2384 $form->{saveasnew} = 1;
2385 $form->{closed} = 0;
2386 map { delete $form->{$_} } qw(printed emailed queued ordnumber quonumber);
2390 $lxdebug->leave_sub();
2393 sub purchase_order {
2394 $lxdebug->enter_sub();
2396 if ( $form->{type} eq 'sales_quotation'
2397 || $form->{type} eq 'request_quotation') {
2398 OE->close_order(\%myconfig, \%$form);
2401 $form->{cp_id} *= 1;
2403 $form->{title} = $locale->text('Add Purchase Order');
2404 $form->{vc} = "vendor";
2405 $form->{type} = "purchase_order";
2409 $lxdebug->leave_sub();
2413 $lxdebug->enter_sub();
2415 if ( $form->{type} eq 'sales_quotation'
2416 || $form->{type} eq 'request_quotation') {
2417 OE->close_order(\%myconfig, $form);
2420 $form->{cp_id} *= 1;
2422 $form->{title} = $locale->text('Add Sales Order');
2423 $form->{vc} = "customer";
2424 $form->{type} = "sales_order";
2428 $lxdebug->leave_sub();
2432 $lxdebug->enter_sub();
2434 $form->{transdate} = $form->current_date(\%myconfig);
2435 delete $form->{duedate};
2437 $form->{closed} = 0;
2440 map { delete $form->{$_} }
2441 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2443 for $i (1 .. $form->{rowcount}) {
2444 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2445 $form->{"${_}_${i}"})
2446 if ($form->{"${_}_${i}"}) }
2447 qw(ship qty sellprice listprice basefactor));
2455 for $i (1 .. $form->{rowcount} - 1) {
2456 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2457 qw(partnumber description unit);
2460 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2461 qw(creditlimit creditremaining);
2465 $lxdebug->leave_sub();