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();
113 # show history button
114 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
115 #/show hhistory button
117 $form->{simple_save} = 0;
119 set_headings("edit");
121 # editing without stuff to edit? try adding it first
122 if ($form->{rowcount}) {
123 map { $id++ if $form->{"id_$_"} } (1 .. $form->{rowcount});
127 undef $form->{rowcount};
138 if ($form->{print_and_save}) {
139 $form->{action} = "print";
140 $form->{resubmit} = 1;
141 $language_id = $form->{language_id};
142 $printer_id = $form->{printer_id};
145 set_headings("edit");
149 if ($form->{print_and_save}) {
150 $form->{language_id} = $language_id;
151 $form->{printer_id} = $printer_id;
155 $lxdebug->leave_sub();
159 $lxdebug->enter_sub();
161 # get customer/vendor
162 $form->all_vc(\%myconfig, $form->{vc},
163 ($form->{vc} eq 'customer') ? "AR" : "AP");
165 # retrieve order/quotation
166 $form->{webdav} = $webdav;
168 $form->{jscalendar} = $jscalendar;
170 OE->retrieve(\%myconfig, \%$form);
172 if ($form->{payment_id}) {
173 $payment_id = $form->{payment_id};
175 if ($form->{language_id}) {
176 $language_id = $form->{language_id};
178 if ($form->{taxzone_id}) {
179 $taxzone_id = $form->{taxzone_id};
183 # if multiple rowcounts (== collective order) then check if the
184 # there were more than one customer (in that case OE::retrieve removes
185 # the content from the field)
186 if ( $form->{rowcount}
187 && $form->{type} eq 'sales_order'
188 && defined $form->{customer}
189 && $form->{customer} eq '') {
191 # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
194 'Collective Orders only work for orders from one customer!')
198 $taxincluded = $form->{taxincluded};
199 $form->{shipto} = 1 if $form->{id};
201 if ($form->{"all_$form->{vc}"}) {
202 unless ($form->{"$form->{vc}_id"}) {
203 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
207 $cp_id = $form->{cp_id};
208 $intnotes = $form->{intnotes};
210 # get customer / vendor
211 if ($form->{type} =~ /(purchase_order|request_quotation)/) {
212 IR->get_vendor(\%myconfig, \%$form);
214 #quote all_vendor Bug 133
215 foreach $ref (@{ $form->{all_vendor} }) {
216 $ref->{name} = $form->quote($ref->{name});
220 if ($form->{type} =~ /sales_(order|quotation)/) {
221 IS->get_customer(\%myconfig, \%$form);
223 #quote all_vendor Bug 133
224 foreach $ref (@{ $form->{all_customer} }) {
225 $ref->{name} = $form->quote($ref->{name});
229 $form->{cp_id} = $cp_id;
231 $form->{payment_id} = $payment_id;
234 $form->{language_id} = $language_id;
237 $form->{taxzone_id} = $taxzone_id;
239 $form->{intnotes} = $intnotes;
240 ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
241 $form->{"old$form->{vc}"} =
242 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
244 # build the popup menus
245 if (@{ $form->{"all_$form->{vc}"} }) {
246 $form->{ $form->{vc} } =
247 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
248 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" }
249 (@{ $form->{"all_$form->{vc}"} });
253 @curr = split(/:/, $form->{currencies});
255 $form->{defaultcurrency} = $curr[0];
256 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
258 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
260 $form->{taxincluded} = $taxincluded if ($form->{id});
263 if (@{ $form->{all_departments} }) {
264 $form->{selectdepartment} = "<option>\n";
265 $form->{department} = "$form->{department}--$form->{department_id}";
268 $form->{selectdepartment} .=
269 "<option>$_->{description}--$_->{id}\n"
270 } (@{ $form->{all_departments} });
273 $form->{employee} = "$form->{employee}--$form->{employee_id}";
276 if (@{ $form->{all_employees} }) {
277 $form->{selectemployee} = "";
278 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
279 (@{ $form->{all_employees} });
283 $form->{forex} = $form->{exchangerate};
285 $lxdebug->leave_sub();
289 $lxdebug->enter_sub();
290 $form->{formname} = $form->{type} unless $form->{formname};
293 foreach $ref (@{ $form->{form_details} }) {
294 $form->{rowcount} = ++$i;
296 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
298 for my $i (1 .. $form->{rowcount}) {
300 $form->{"discount_$i"} =
301 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
303 $form->{"discount_$i"} =
304 $form->format_amount(\%myconfig, $form->{"discount_$i"});
306 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
308 $decimalplaces = ($dec > 2) ? $dec : 2;
310 # copy reqdate from deliverydate for invoice -> order conversion
311 $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
312 unless $form->{"reqdate_$i"};
314 $form->{"sellprice_$i"} =
315 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
318 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
319 $dec_qty = length $dec_qty;
321 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
323 map { $form->{"${_}_$i"} =~ s/\"/"/g }
324 qw(partnumber description unit);
327 $lxdebug->leave_sub();
331 $lxdebug->enter_sub();
333 my $checkedclosed = $form->{"closed"} ? "checked" : "";
334 my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
336 map { $form->{$_} =~ s/\"/"/g }
337 qw(ordnumber quonumber shippingpoint shipvia notes intnotes shiptoname
338 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
339 shiptophone shiptofax shiptodepartment_1 shiptodepartment_2);
341 # use JavaScript Calendar or not
342 $form->{jsscript} = $form->{jscalendar};
345 $payment = qq|<option value=""></option>|;
346 foreach $item (@{ $form->{payment_terms} }) {
347 if ($form->{payment_id} eq $item->{id}) {
348 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
350 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
353 if ($form->{jsscript}) {
355 # with JavaScript Calendar
357 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
358 <td><input type=button name=transdate id="trigger1" value=|
359 . $locale->text('button') . qq|></td>
362 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>
363 <td width="4"><input type=button name=reqdate name=reqdate id="trigger2" value=|
364 . $locale->text('button') . qq|></td>
369 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
370 "reqdate", "BL", "trigger2");
374 # without JavaScript Calendar
376 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>|;
378 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value=$form->{reqdate}></td>|;
384 <td colspan=2 align=center>
385 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
386 <label for="closed">| . $locale->text('Closed') . qq|</label>
389 if (($form->{"type"} eq "sales_order") ||
390 ($form->{"type"} eq "purchase_order")) {
392 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
393 <label for="delivered">| . $locale->text('Delivered') . qq|</label>
403 # set option selected
404 foreach $item ($form->{vc}, currency, department, employee) {
405 $form->{"select$item"} =~ s/ selected//;
406 $form->{"select$item"} =~
407 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
410 #quote select[customer|vendor] Bug 133
411 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
413 my @old_project_ids = ($form->{"globalproject_id"});
414 map({ push(@old_project_ids, $form->{"project_id_$_"})
415 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
417 $form->get_lists("contacts" => "ALL_CONTACTS",
418 "shipto" => "ALL_SHIPTO",
419 "projects" => { "key" => "ALL_PROJECTS",
421 "old_id" => \@old_project_ids });
423 my (%labels, @values);
424 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
425 push(@values, $item->{"cp_id"});
426 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
427 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
430 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
431 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
435 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
436 push(@values, $item->{"shipto_id"});
437 $labels{$item->{"shipto_id"}} =
438 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
442 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
444 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
445 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
450 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
451 push(@values, $item->{"id"});
452 $labels{$item->{"id"}} = $item->{"projectnumber"};
454 my $globalprojectnumber =
455 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
456 '-labels' => \%labels,
457 '-default' => $form->{"globalproject_id"}));
459 $form->{exchangerate} =
460 $form->format_amount(\%myconfig, $form->{exchangerate});
462 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
468 $form->{creditlimit} =
469 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
470 $form->{creditremaining} =
471 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
474 <input type=hidden name=forex value=$form->{forex}>
477 if ($form->{currency} ne $form->{defaultcurrency}) {
478 if ($form->{forex}) {
481 . $locale->text('Exchangerate')
482 . qq|</th><td>$form->{exchangerate}</td>
483 <input type=hidden name=exchangerate value=$form->{exchangerate}>
488 . $locale->text('Exchangerate')
489 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
493 $vclabel = ucfirst $form->{vc};
494 $vclabel = $locale->text($vclabel);
498 if ($form->{business}) {
501 <th align=right>| . $locale->text('Business') . qq|</th>
502 <td>$form->{business}</td>
503 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
505 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
511 if ($form->{max_dunning_level}) {
517 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
518 <td><b>$form->{max_dunning_level}</b></td>
519 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
521 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
530 if (@{ $form->{TAXZONE} }) {
531 $form->{selecttaxzone} = "";
532 foreach $item (@{ $form->{TAXZONE} }) {
533 if ($item->{id} == $form->{taxzone_id}) {
534 $form->{selecttaxzone} .=
535 "<option value=$item->{id} selected>" . H($item->{description}) .
538 $form->{selecttaxzone} .=
539 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
544 $form->{selecttaxzone} =~ s/ selected//g;
545 if ($form->{taxzone_id} ne "") {
546 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}>/value=$form->{taxzone_id} selected>/;
552 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
553 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
554 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
558 if ($form->{type} !~ /_quotation$/) {
561 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
562 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
565 <th width=70% align=right nowrap>|
566 . $locale->text('Quotation Number') . qq|</th>
567 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
570 <th width=70% align=right nowrap>|
571 . $locale->text('Customer Order Number') . qq|</th>
572 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
575 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
580 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
585 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
587 $creditremaining = qq|
593 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
594 <td>$form->{creditlimit}</td>
596 <th nowrap>| . $locale->text('Remaining') . qq|</th>
597 <td class="plus$n" nowrap>$form->{creditremaining}</td>
606 ($form->{type} eq 'sales_quotation')
607 ? $locale->text('Valid until')
608 : $locale->text('Required by');
609 if ($form->{type} eq 'sales_quotation') {
612 <th width=70% align=right nowrap>|
613 . $locale->text('Quotation Number') . qq|</th>
614 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
615 <input type=hidden name=ordnumber value="$form->{ordnumber}">
621 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
622 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
623 <input type=hidden name=ordnumber value="$form->{ordnumber}">
631 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
635 <th align=right nowrap=true>$reqlabel</th>
639 $creditremaining = qq| <tr>
646 ($form->{"select$form->{vc}"})
647 ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}</select>\n<input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">|
648 : qq|<input name=$form->{vc} value="$form->{$form->{vc}}" size=35>|;
652 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
653 <td colspan=3><select name=department>$form->{selectdepartment}</select>
654 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
657 | if $form->{selectdepartment};
660 <input type=hidden name=employee value="$form->{employee}">
663 if ($form->{type} eq 'sales_order') {
664 if ($form->{selectemployee}) {
666 <input type=hidden name=customer_klass value=$form->{customer_klass}>
668 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
669 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
670 <input type=hidden name=selectemployee value="$form->{selectemployee}">
677 <input type=hidden name=customer_klass value=$form->{customer_klass}>
679 <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
680 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
681 <input type=hidden name=selectemployee value="$form->{selectemployee}">
686 if ($form->{resubmit} && ($form->{format} eq "html")) {
688 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
689 } elsif ($form->{resubmit}) {
690 $onload = qq|document.oe.submit()|;
695 $credittext = $locale->text('Credit Limit exceeded!!!');
696 if ($creditwarning) {
697 $onload = qq|alert('$credittext')|;
700 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
705 <body onLoad="$onload">
707 <form method=post name=oe action=$form->{script}>
708 <script type="text/javascript" src="js/common.js"></script>
709 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
710 <script type="text/javascript" src="js/vendor_selection.js"></script>
711 <script type="text/javascript" src="js/calculate_qty.js"></script>
713 <input type=hidden name=id value=$form->{id}>
714 <input type=hidden name=action value=$form->{action}>
716 <input type=hidden name=type value=$form->{type}>
717 <input type=hidden name=formname value=$form->{formname}>
718 <input type=hidden name=media value=$form->{media}>
719 <input type=hidden name=format value=$form->{format}>
720 <input type=hidden name=proforma value=$form->{proforma}>
722 <input type=hidden name=queued value="$form->{queued}">
723 <input type=hidden name=printed value="$form->{printed}">
724 <input type=hidden name=emailed value="$form->{emailed}">
726 <input type=hidden name=vc value=$form->{vc}>
728 <input type=hidden name=title value="$form->{title}">
730 <input type=hidden name=discount value=$form->{discount}>
731 <input type=hidden name=creditlimit value=$form->{creditlimit}>
732 <input type=hidden name=creditremaining value=$form->{creditremaining}>
734 <input type=hidden name=tradediscount value=$form->{tradediscount}>
735 <input type=hidden name=business value=$form->{business}>
736 <input type=hidden name=webdav value=$webdav>
740 <th class=listtop>$form->{title}</th>
750 <th align=right>$vclabel</th>
751 <td colspan=3>$vc</td>
752 <input type=hidden name=$form->{vc}_id value=$form->{"$form->{vc}_id"}>
753 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
754 <th align=richt nowrap>|
755 . $locale->text('Contact Person') . qq|</th>
756 <td colspan=3>$contact</td>
764 <th align=right>| . $locale->text('Currency') . qq|</th>
765 <td><select name=currency>$form->{selectcurrency}</select></td>
766 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
767 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
771 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
772 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
775 <th align=right>| . $locale->text('Ship via') . qq|</th>
776 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
783 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
785 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
786 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
790 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
792 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
793 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
806 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
807 <td>$globalprojectnumber</td>
818 <!-- shipto are in hidden variables -->
820 <input type=hidden name=shiptoname value="$form->{shiptoname}">
821 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
822 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
823 <input type=hidden name=shiptocity value="$form->{shiptocity}">
824 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
825 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
826 <input type=hidden name=shiptophone value="$form->{shiptophone}">
827 <input type=hidden name=shiptofax value="$form->{shiptofax}">
828 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
829 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
830 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
832 <!-- email variables -->
833 <input type=hidden name=message value="$form->{message}">
834 <input type=hidden name=email value="$form->{email}">
835 <input type=hidden name=subject value="$form->{subject}">
836 <input type=hidden name=cc value="$form->{cc}">
837 <input type=hidden name=bcc value="$form->{bcc}">
839 <input type=hidden name=taxpart value="$form->{taxpart}">
840 <input type=hidden name=taxservice value="$form->{taxservice}">
842 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
845 foreach $item (split / /, $form->{taxaccounts}) {
847 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
848 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
851 $lxdebug->leave_sub();
855 $lxdebug->enter_sub();
857 $form->{invtotal} = $form->{invsubtotal};
859 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
862 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
865 $rows = ($rows > $introws) ? $rows : $introws;
867 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
869 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
871 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
874 if ($form->{taxaccounts}) {
876 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
877 . $locale->text('Tax Included') . qq|</b><br><br>
881 if (!$form->{taxincluded}) {
883 foreach $item (split / /, $form->{taxaccounts}) {
884 if ($form->{"${item}_base"}) {
885 $form->{invtotal} += $form->{"${item}_total"} =
887 $form->{"${item}_base"} * $form->{"${item}_rate"},
889 $form->{"${item}_total"} =
890 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
894 <th align=right>$form->{"${item}_description"} |
895 . $form->{"${item}_rate"} * 100 .qq|%</th>
896 <td align=right>$form->{"${item}_total"}</td>
902 $form->{invsubtotal} =
903 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
907 <th align=right>| . $locale->text('Subtotal') . qq|</th>
908 <td align=right>$form->{invsubtotal}</td>
914 if ($form->{taxincluded}) {
915 foreach $item (split / /, $form->{taxaccounts}) {
916 if ($form->{"${item}_base"}) {
917 $form->{"${item}_total"} =
919 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
920 (1 + $form->{"${item}_rate"})
923 $form->{"${item}_netto"} =
925 ($form->{"${item}_base"} - $form->{"${item}_total"}),
927 $form->{"${item}_total"} =
928 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
929 $form->{"${item}_netto"} =
930 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
934 <th align=right>Enthaltene $form->{"${item}_description"} |
935 . $form->{"${item}_rate"} * 100 .qq|%</th>
936 <td align=right>$form->{"${item}_total"}</td>
939 <th align=right>Nettobetrag</th>
940 <td align=right>$form->{"${item}_netto"}</td>
948 $form->{oldinvtotal} = $form->{invtotal};
950 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
960 <th align=left>| . $locale->text('Notes') . qq|</th>
961 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
967 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
968 <td><select name=payment_id tabindex=24>$payment
972 <td align=right width=100%>
978 <th align=right>| . $locale->text('Total') . qq|</th>
979 <td align=right>$form->{invtotal}</td>
987 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
988 <input type=hidden name=oldtotalpaid value=$totalpaid>
990 <td><hr size=3 noshade></td>
998 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
1001 <td align=left width=30%><b>Dateiname</b></td>
1002 <td align=left width=70%><b>Webdavlink</b></td>
1004 foreach $file (keys %{ $form->{WEBDAV} }) {
1007 <td align=left>$file</td>
1008 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1016 <td><hr size=3 noshade></td>
1023 <input type=hidden name=jscalendar value=$form->{jscalendar}>
1036 | . $locale->text("Edit the $form->{type}") . qq|<br>
1037 <input class=submit type=submit name=action id=update_button value="|
1038 . $locale->text('Update') . qq|">
1039 <input class=submit type=submit name=action value="|
1040 . $locale->text('Ship to') . qq|">
1041 <input class=submit type=submit name=action value="|
1042 . $locale->text('Print') . qq|">
1043 <input class=submit type=submit name=action value="|
1044 . $locale->text('E-mail') . qq|">
1045 <input class=submit type=submit name=action value="|
1046 . $locale->text('Save') . qq|">
1047 <input class=submit type=submit name=action value="|
1048 . $locale->text('Save and Close') . qq|">
1051 if (($form->{id})) {
1053 <input type="button" class="submit" onclick="set_history_window(|
1055 . qq|);" name="history" id="history" value="|
1056 . $locale->text('history')
1059 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1060 <input class=submit type=submit name=action value="|
1061 . $locale->text('Save as new') . qq|">
1062 <input class=submit type=submit name=action value="|
1063 . $locale->text('Delete') . qq|">|;
1064 if (($form->{type} =~ /sales_quotation$/)) {
1066 <input class=submit type=submit name=action value="|
1067 . $locale->text('Sales Order') . qq|">|;
1069 if ($form->{type} =~ /request_quotation$/) {
1071 <input class=submit type=submit name=action value="|
1072 . $locale->text('Purchase Order') . qq|">|;
1076 <input class=submit type=submit name=action value="|
1077 . $locale->text('Invoice') . qq|">
1081 if ($form->{type} =~ /sales_order$/) {
1083 <br>$form->{heading} als neue Vorlage verwenden für<br>
1084 <input class=submit type=submit name=action value="|
1085 . $locale->text('Purchase Order') . qq|">
1086 <input class=submit type=submit name=action value="|
1087 . $locale->text('Quotation') . qq|">
1090 } elsif ($form->{type} =~ /purchase_order$/) {
1092 <br>$form->{heading} als neue Vorlage verwenden für<br>
1093 <input class=submit type=submit name=action value="|
1094 . $locale->text('Sales Order') . qq|">
1095 <input class=submit type=submit name=action value="|
1096 . $locale->text('Request for Quotation') . qq|">
1101 <br>$form->{heading} als neue Vorlage verwenden für<br>
1102 <input class=submit type=submit name=action value="|
1103 . $locale->text('Order') . qq|">
1106 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1108 <br>Workflow $form->{heading}<br>
1109 <input class=submit type=submit name=action value="|
1110 . $locale->text('Save as new') . qq|">
1111 <input class=submit type=submit name=action value="|
1112 . $locale->text('Invoice') . qq|">
1118 <input type=hidden name=rowcount value=$form->{rowcount}>
1120 <input name=callback type=hidden value="$form->{callback}">
1122 <input type=hidden name=path value=$form->{path}>
1123 <input type=hidden name=login value=$form->{login}>
1124 <input type=hidden name=password value=$form->{password}>
1131 $lxdebug->leave_sub();
1135 $lxdebug->enter_sub();
1137 set_headings($form->{"id"} ? "edit" : "add");
1139 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1140 qw(exchangerate creditlimit creditremaining);
1141 $form->{update} = 1;
1143 &check_name($form->{vc});
1146 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1147 $form->{exchangerate} = $exchangerate
1151 $form->check_exchangerate(
1152 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1156 $i = $form->{rowcount};
1158 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1160 if ( ($form->{"partnumber_$i"} eq "")
1161 && ($form->{"description_$i"} eq "")
1162 && ($form->{"partsgroup_$i"} eq "")) {
1164 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1169 if ( $form->{type} eq 'purchase_order'
1170 || $form->{type} eq 'request_quotation') {
1171 IR->retrieve_item(\%myconfig, \%$form);
1173 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1174 IS->retrieve_item(\%myconfig, \%$form);
1177 my $rows = scalar @{ $form->{item_list} };
1179 $form->{"discount_$i"} =
1180 $form->format_amount(\%myconfig, $form->{discount} * 100);
1183 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1192 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1193 if ($form->{"not_discountable_$i"}) {
1194 $form->{"discount_$i"} = 0;
1196 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1197 qw(partnumber description unit);
1198 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1199 keys %{ $form->{item_list}[0] };
1200 if ($form->{"part_payment_id_$i"} ne "") {
1201 $form->{payment_id} = $form->{"part_payment_id_$i"};
1204 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1206 ($dec) = ($s =~ /\.(\d+)/);
1208 $decimalplaces = ($dec > 2) ? $dec : 2;
1211 $form->{"sellprice_$i"} = $sellprice;
1214 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1216 # if there is an exchange rate adjust sellprice
1217 $form->{"sellprice_$i"} /= $exchangerate;
1221 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1222 (1 - $form->{"discount_$i"} / 100);
1223 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1224 map { $form->{"${_}_base"} += $amount }
1225 (split / /, $form->{"taxaccounts_$i"});
1226 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1227 split / /, $form->{taxaccounts}
1228 if !$form->{taxincluded};
1230 $form->{creditremaining} -= $amount;
1232 $form->{"sellprice_$i"} =
1233 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1236 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1238 # get pricegroups for parts
1239 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1241 # build up html code for prices_$i
1242 &set_pricegroup($i);
1249 # ok, so this is a new part
1250 # ask if it is a part or service item
1252 if ( $form->{"partsgroup_$i"}
1253 && ($form->{"partsnumber_$i"} eq "")
1254 && ($form->{"description_$i"} eq "")) {
1255 $form->{rowcount}--;
1256 $form->{"discount_$i"} = "";
1260 $form->{"id_$i"} = 0;
1261 $form->{"unit_$i"} = $locale->text('ea');
1269 $lxdebug->leave_sub();
1273 $lxdebug->enter_sub();
1275 if ($form->{type} eq 'purchase_order') {
1276 $form->{title} = $locale->text('Purchase Orders');
1277 $form->{vc} = 'vendor';
1278 $ordlabel = $locale->text('Order Number');
1279 $ordnumber = 'ordnumber';
1280 $employee = $locale->text('Employee');
1283 if ($form->{type} eq 'request_quotation') {
1284 $form->{title} = $locale->text('Request for Quotations');
1285 $form->{vc} = 'vendor';
1286 $ordlabel = $locale->text('RFQ Number');
1287 $ordnumber = 'quonumber';
1288 $employee = $locale->text('Employee');
1291 if ($form->{type} eq 'sales_order') {
1292 $form->{title} = $locale->text('Sales Orders');
1293 $form->{vc} = 'customer';
1294 $ordlabel = $locale->text('Order Number');
1295 $ordnumber = 'ordnumber';
1296 $employee = $locale->text('Salesperson');
1299 if ($form->{type} eq 'sales_quotation') {
1300 $form->{title} = $locale->text('Quotations');
1301 $form->{vc} = 'customer';
1302 $ordlabel = $locale->text('Quotation Number');
1303 $ordnumber = 'quonumber';
1304 $employee = $locale->text('Employee');
1307 # setup vendor / customer selection
1308 $form->all_vc(\%myconfig, $form->{vc},
1309 ($form->{vc} eq 'customer') ? "AR" : "AP");
1311 map { $vc .= "<option>$_->{name}--$_->{id}\n" }
1312 @{ $form->{"all_$form->{vc}"} };
1314 $vclabel = ucfirst $form->{vc};
1315 $vclabel = $locale->text($vclabel);
1317 # $locale->text('Vendor')
1318 # $locale->text('Customer')
1322 ? qq|<select name=$form->{vc}><option>\n$vc</select>|
1323 : qq|<input name=$form->{vc} size=35>|;
1326 if (@{ $form->{all_departments} }) {
1327 $form->{selectdepartment} = "<option>\n";
1330 $form->{selectdepartment} .=
1331 "<option>$_->{description}--$_->{id}\n"
1332 } (@{ $form->{all_departments} });
1337 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1338 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1340 | if $form->{selectdepartment};
1343 if (($form->{"type"} eq "sales_order") ||
1344 ($form->{"type"} eq "purchase_order")) {
1347 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1348 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1349 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1350 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1355 # use JavaScript Calendar or not
1356 $form->{jsscript} = $jscalendar;
1358 if ($form->{jsscript}) {
1360 # with JavaScript Calendar
1362 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}">
1363 <input type=button name=transdatefrom id="trigger3" value=|
1364 . $locale->text('button') . qq|></td>
1367 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}">
1368 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1369 . $locale->text('button') . qq|></td>
1374 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1375 "transdateto", "BL", "trigger4");
1378 # without JavaScript Calendar
1380 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
1382 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}"></td>|;
1385 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1390 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1391 push(@values, $item->{"id"});
1392 $labels{$item->{"id"}} = $item->{"projectnumber"};
1395 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1396 '-labels' => \%labels));
1403 <form method=post action=$form->{script}>
1407 <th class=listtop>$form->{title}</th>
1409 <tr height="5"></tr>
1414 <th align=right>$vclabel</th>
1415 <td colspan=3>$vc</td>
1419 <th align=right>$ordlabel</th>
1420 <td colspan=3><input name="$ordnumber" size=20></td>
1423 <th align="right">| . $locale->text("Project Number") . qq|</th>
1424 <td colspan="3">$projectnumber</td>
1427 <th align=right>| . $locale->text('From') . qq|</th>
1429 <th align=right>| . $locale->text('Bis') . qq|</th>
1432 <input type=hidden name=sort value=transdate>
1434 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1438 <td><input type="checkbox" name="open" value="1" id="open" checked>
1439 <label for="open">| . $locale->text("Open") . qq|</td>
1440 <td><input type="checkbox" name="closed" value="1" id="closed">
1441 <label for="closed">| . $locale->text("Closed") . qq|</td>
1445 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1446 | . $locale->text('ID') . qq|</td>
1447 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1448 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1449 . $locale->text('Date') . qq|</td>
1450 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1451 . $locale->text('Required by') . qq|</td>
1454 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vclabel</td>
1455 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1456 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1457 . $locale->text('Ship via') . qq|</td>
1458 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1461 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1462 . $locale->text('Amount') . qq|</td>
1463 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1464 . $locale->text('Tax') . qq|</td>
1465 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1466 . $locale->text('Total') . qq|</td>
1467 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1468 . $locale->text('Project Number') . qq|</td>
1471 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1472 . $locale->text('Subtotal') . qq|</td>
1480 <tr><td colspan=4><hr size=3 noshade></td></tr>
1486 <input type=hidden name=nextsub value=orders>
1487 <input type=hidden name=path value=$form->{path}>
1488 <input type=hidden name=login value=$form->{login}>
1489 <input type=hidden name=password value=$form->{password}>
1490 <input type=hidden name=vc value=$form->{vc}>
1491 <input type=hidden name=type value=$form->{type}>
1493 <input class=submit type=submit name=action value="|
1494 . $locale->text('Continue') . qq|">
1501 $lxdebug->leave_sub();
1505 $lxdebug->enter_sub();
1507 # split vendor / customer
1508 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1509 split(/--/, $form->{ $form->{vc} });
1511 OE->transactions(\%myconfig, \%$form);
1513 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1515 $number = $form->escape($form->{$ordnumber});
1516 $name = $form->escape($form->{ $form->{vc} });
1517 $department = $form->escape($form->{department});
1521 "$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";
1523 # construct callback
1524 $number = $form->escape($form->{$ordnumber}, 1);
1525 $name = $form->escape($form->{ $form->{vc} }, 1);
1526 $department = $form->escape($form->{department}, 1);
1529 "$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";
1532 $form->sort_columns("transdate", "reqdate", "id", "$ordnumber",
1533 "name", "netamount", "tax", "amount",
1534 "curr", "employee", "shipvia", "globalprojectnumber",
1535 "open", "closed", "delivered");
1537 $form->{l_open} = $form->{l_closed} = "Y"
1538 if ($form->{open} && $form->{closed});
1540 $form->{"l_delivered"} = "Y"
1541 if ($form->{"delivered"} && $form->{"notdelivered"});
1543 foreach $item (@columns) {
1544 if ($form->{"l_$item"} eq "Y") {
1545 push @column_index, $item;
1547 # add column to href and callback
1548 $callback .= "&l_$item=Y";
1549 $href .= "&l_$item=Y";
1553 # only show checkboxes if gotten here via sales_order form.
1554 if ($form->{type} =~ /sales_order/) {
1555 unshift @column_index, "ids";
1558 if ($form->{l_subtotal} eq 'Y') {
1559 $callback .= "&l_subtotal=Y";
1560 $href .= "&l_subtotal=Y";
1563 if ($form->{vc} eq 'vendor') {
1564 if ($form->{type} eq 'purchase_order') {
1565 $form->{title} = $locale->text('Purchase Orders');
1567 $form->{title} = $locale->text('Request for Quotations');
1569 $name = $locale->text('Vendor');
1570 $employee = $locale->text('Employee');
1572 if ($form->{vc} eq 'customer') {
1573 if ($form->{type} eq 'sales_order') {
1574 $form->{title} = $locale->text('Sales Orders');
1575 $employee = $locale->text('Salesperson');
1577 $form->{title} = $locale->text('Quotations');
1578 $employee = $locale->text('Employee');
1580 $name = $locale->text('Customer');
1583 $column_header{id} =
1584 qq|<th><a class=listheading href=$href&sort=id>|
1585 . $locale->text('ID')
1587 $column_header{transdate} =
1588 qq|<th><a class=listheading href=$href&sort=transdate>|
1589 . $locale->text('Date')
1591 $column_header{reqdate} =
1592 qq|<th><a class=listheading href=$href&sort=reqdate>|
1593 . $locale->text('Required by')
1595 $column_header{ordnumber} =
1596 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1597 . $locale->text('Order')
1599 $column_header{quonumber} =
1600 qq|<th><a class=listheading href=$href&sort=quonumber>|
1601 . ($form->{"type"} eq "request_quotation" ?
1602 $locale->text('RFQ') :
1603 $locale->text('Quotation'))
1605 $column_header{name} =
1606 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1607 $column_header{netamount} =
1608 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1609 $column_header{tax} =
1610 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1611 $column_header{amount} =
1612 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1613 $column_header{curr} =
1614 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1615 $column_header{shipvia} =
1616 qq|<th><a class=listheading href=$href&sort=shipvia>|
1617 . $locale->text('Ship via')
1619 $column_header{globalprojectnumber} =
1620 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1621 $column_header{open} =
1622 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1623 $column_header{closed} =
1624 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1625 $column_header{"delivered"} =
1626 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1628 $column_header{employee} =
1629 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1631 $column_header{ids} = qq|<th></th>|;
1633 if ($form->{ $form->{vc} }) {
1634 $option = $locale->text(ucfirst $form->{vc});
1635 $option .= " : $form->{$form->{vc}}";
1637 if ($form->{department}) {
1638 $option .= "\n<br>" if ($option);
1639 ($department) = split /--/, $form->{department};
1640 $option .= $locale->text('Department') . " : $department";
1642 if ($form->{transdatefrom}) {
1644 . $locale->text('From') . " "
1645 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1647 if ($form->{transdateto}) {
1649 . $locale->text('Bis') . " "
1650 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1652 if ($form->{open}) {
1653 $option .= "\n<br>" if ($option);
1654 $option .= $locale->text('Open');
1656 if ($form->{closed}) {
1657 $option .= "\n<br>" if ($option);
1658 $option .= $locale->text('Closed');
1666 <form method="post" action="oe.pl">
1669 <th class=listtop>$form->{title}</th>
1671 <tr height="5"></tr>
1678 <tr class=listheading>|;
1680 map { print "\n$column_header{$_}" } @column_index;
1686 # add sort and escape callback
1687 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1689 if (@{ $form->{OE} }) {
1690 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1695 foreach $oe (@{ $form->{OE} }) {
1696 $form->{rowcount} = ++$j;
1698 if ($form->{l_subtotal} eq 'Y') {
1699 if ($sameitem ne $oe->{ $form->{sort} }) {
1701 $sameitem = $oe->{ $form->{sort} };
1705 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1707 $column_data{netamount} =
1709 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1711 $column_data{tax} = "<td align=right>"
1712 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1715 $column_data{amount} =
1717 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1719 $totalnetamount += $oe->{netamount};
1720 $totalamount += $oe->{amount};
1722 $subtotalnetamount += $oe->{netamount};
1723 $subtotalamount += $oe->{amount};
1726 qq|<td><input name="id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1727 $column_data{id} = "<td>$oe->{id}</td>";
1728 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1729 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1731 $column_data{$ordnumber} =
1732 "<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>";
1733 $column_data{name} = "<td>$oe->{name}</td>";
1735 $column_data{employee} = "<td>$oe->{employee} </td>";
1736 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1737 $column_data{globalprojectnumber} = "<td>" . H($oe->{globalprojectnumber}) . "</td>";
1739 if ($oe->{closed}) {
1740 $column_data{closed} = "<td align=center>X</td>";
1741 $column_data{open} = "<td> </td>";
1743 $column_data{closed} = "<td> </td>";
1744 $column_data{open} = "<td align=center>X</td>";
1746 $column_data{"delivered"} = "<td>" .
1747 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1753 <tr class=listrow$i>";
1755 map { print "\n$column_data{$_}" } @column_index;
1763 if ($form->{l_subtotal} eq 'Y') {
1769 <tr class=listtotal>|;
1771 map { $column_data{$_} = "<td> </td>" } @column_index;
1773 $column_data{netamount} =
1774 "<th class=listtotal align=right>"
1775 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1776 $column_data{tax} = "<th class=listtotal align=right>"
1777 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1780 $column_data{amount} =
1781 "<th class=listtotal align=right>"
1782 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1784 map { print "\n$column_data{$_}" } @column_index;
1792 <td><hr size=3 noshade></td>
1796 # multiple invoice edit button only if gotten there via sales_order form.
1798 if ($form->{type} =~ /sales_order/) {
1800 <input type="hidden" name="path" value="$form->{path}">
1801 <input class"submit" type="submit" name="action" value="|
1802 . $locale->text('Continue') . qq|">
1803 <input type="hidden" name="nextsub" value="edit">
1804 <input type="hidden" name="type" value="$form->{type}">
1805 <input type="hidden" name="vc" value="$form->{vc}">
1806 <input type="hidden" name="login" value="$form->{login}">
1807 <input type="hidden" name="password" value="$form->{password}">
1808 <input type="hidden" name="callback" value="$callback">
1809 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1816 <form method=post action=$form->{script}>
1818 <input name=callback type=hidden value="$form->{callback}">
1820 <input type=hidden name=type value=$form->{type}>
1821 <input type=hidden name=vc value=$form->{vc}>
1823 <input type=hidden name=path value=$form->{path}>
1824 <input type=hidden name=login value=$form->{login}>
1825 <input type=hidden name=password value=$form->{password}>
1833 $lxdebug->leave_sub();
1837 $lxdebug->enter_sub();
1839 map { $column_data{$_} = "<td> </td>" } @column_index;
1841 $column_data{netamount} =
1842 "<th class=listsubtotal align=right>"
1843 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1845 $column_data{tax} = "<td class=listsubtotal align=right>"
1846 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1849 $column_data{amount} =
1850 "<th class=listsubtotal align=right>"
1851 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1853 $subtotalnetamount = 0;
1854 $subtotalamount = 0;
1857 <tr class=listsubtotal>
1860 map { print "\n$column_data{$_}" } @column_index;
1866 $lxdebug->leave_sub();
1869 sub save_and_close {
1870 $lxdebug->enter_sub();
1872 if ($form->{type} =~ /_order$/) {
1873 $form->isblank("transdate", $locale->text('Order Date missing!'));
1875 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1878 $msg = ucfirst $form->{vc};
1879 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1881 # $locale->text('Customer missing!');
1882 # $locale->text('Vendor missing!');
1884 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1885 if ($form->{currency} ne $form->{defaultcurrency});
1889 # if the name changed get new values
1890 if (&check_name($form->{vc})) {
1895 $form->{id} = 0 if $form->{saveasnew};
1897 # this is for the internal notes section for the [email] Subject
1898 if ($form->{type} =~ /_order$/) {
1899 if ($form->{type} eq 'sales_order') {
1900 $form->{label} = $locale->text('Sales Order');
1902 $numberfld = "sonumber";
1903 $ordnumber = "ordnumber";
1905 $form->{label} = $locale->text('Purchase Order');
1907 $numberfld = "ponumber";
1908 $ordnumber = "ordnumber";
1911 $err = $locale->text('Cannot save order!');
1914 if ($form->{type} eq 'sales_quotation') {
1915 $form->{label} = $locale->text('Quotation');
1917 $numberfld = "sqnumber";
1918 $ordnumber = "quonumber";
1920 $form->{label} = $locale->text('Request for Quotation');
1922 $numberfld = "rfqnumber";
1923 $ordnumber = "quonumber";
1926 $err = $locale->text('Cannot save quotation!');
1930 # get new number in sequence if no number is given or if saveasnew was requested
1931 if (!$form->{$ordnumber} || $form->{saveasnew}) {
1932 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
1937 $form->error($err) if (!OE->save(\%myconfig, \%$form));
1939 # saving the history
1940 if(!exists $form->{addition}) {
1941 $form->{addition} = "SAVED";
1942 $form->save_history($form->dbconnect(\%myconfig));
1944 # /saving the history
1946 $form->redirect($form->{label} . " $form->{$ordnumber} " .
1947 $locale->text('saved!'));
1949 $lxdebug->leave_sub();
1953 $lxdebug->enter_sub();
1955 if ($form->{type} =~ /_order$/) {
1956 $form->isblank("transdate", $locale->text('Order Date missing!'));
1958 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1961 $msg = ucfirst $form->{vc};
1962 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1964 # $locale->text('Customer missing!');
1965 # $locale->text('Vendor missing!');
1967 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1968 if ($form->{currency} ne $form->{defaultcurrency});
1972 # if the name changed get new values
1973 if (&check_name($form->{vc})) {
1978 $form->{id} = 0 if $form->{saveasnew};
1980 # this is for the internal notes section for the [email] Subject
1981 if ($form->{type} =~ /_order$/) {
1982 if ($form->{type} eq 'sales_order') {
1983 $form->{label} = $locale->text('Sales Order');
1985 $numberfld = "sonumber";
1986 $ordnumber = "ordnumber";
1988 $form->{label} = $locale->text('Purchase Order');
1990 $numberfld = "ponumber";
1991 $ordnumber = "ordnumber";
1994 $err = $locale->text('Cannot save order!');
1997 if ($form->{type} eq 'sales_quotation') {
1998 $form->{label} = $locale->text('Quotation');
2000 $numberfld = "sqnumber";
2001 $ordnumber = "quonumber";
2003 $form->{label} = $locale->text('Request for Quotation');
2005 $numberfld = "rfqnumber";
2006 $ordnumber = "quonumber";
2009 $err = $locale->text('Cannot save quotation!');
2013 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
2014 unless $form->{$ordnumber};
2018 OE->save(\%myconfig, \%$form);
2020 # saving the history
2021 if(!exists $form->{addition}) {
2022 $form->{addition} = "SAVED";
2023 $form->save_history($form->dbconnect(\%myconfig));
2025 # /saving the history
2027 $form->{simple_save} = 1;
2028 if(!$form->{print_and_save}) {
2029 set_headings("edit");
2033 $lxdebug->leave_sub();
2037 $lxdebug->enter_sub();
2041 if ($form->{type} =~ /_order$/) {
2042 $msg = $locale->text('Are you sure you want to delete Order Number');
2043 $ordnumber = 'ordnumber';
2045 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2046 $ordnumber = 'quonumber';
2052 <form method=post action=$form->{script}>
2055 # delete action variable
2056 map { delete $form->{$_} } qw(action header);
2058 foreach $key (keys %$form) {
2059 $form->{$key} =~ s/\"/"/g;
2060 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2064 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2066 <h4>$msg $form->{$ordnumber}</h4>
2068 <input name=action class=submit type=submit value="|
2069 . $locale->text('Yes') . qq|">
2076 $lxdebug->leave_sub();
2080 $lxdebug->enter_sub();
2082 if ($form->{type} =~ /_order$/) {
2083 $msg = $locale->text('Order deleted!');
2084 $err = $locale->text('Cannot delete order!');
2086 $msg = $locale->text('Quotation deleted!');
2087 $err = $locale->text('Cannot delete quotation!');
2089 if (OE->delete(\%myconfig, \%$form, $spool)){
2090 $form->redirect($msg);
2091 # saving the history
2092 if(!exists $form->{addition}) {
2093 $form->{addition} = "DELETED";
2094 $form->save_history($form->dbconnect(\%myconfig));
2096 # /saving the history
2100 $lxdebug->leave_sub();
2104 $lxdebug->enter_sub();
2106 if ($form->{type} =~ /_order$/) {
2108 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2109 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2110 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2111 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2113 $form->isblank("transdate", $locale->text('Order Date missing!'))
2114 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }
2117 # also copy deliverydate from the order
2118 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2119 $form->{orddate} = $form->{transdate};
2121 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2122 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2123 $form->{ordnumber} = "";
2124 $form->{quodate} = $form->{transdate};
2127 # if the name changed get new values
2128 if (&check_name($form->{vc})) {
2133 $form->{cp_id} *= 1;
2135 for $i (1 .. $form->{rowcount}) {
2136 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2137 $form->{"${_}_${i}"})
2138 if ($form->{"${_}_${i}"}) }
2139 qw(ship qty sellprice listprice basefactor));
2142 if ( $form->{type} =~ /_order/
2143 && $form->{currency} ne $form->{defaultcurrency}) {
2145 # check if we need a new exchangerate
2146 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2148 $orddate = $form->current_date(\%myconfig);
2150 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2153 if (!$exchangerate) {
2154 &backorder_exchangerate($orddate, $buysell);
2159 # close orders/quotations
2160 $form->{closed} = 1;
2162 # save order if one ordnumber has been given
2163 # if not it's most likely a collective order, which can't be saved back
2164 # so they just have to be closed
2165 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2166 OE->close_order(\%myconfig, \%$form);
2168 OE->close_orders(\%myconfig, \%$form);
2171 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2173 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2176 $form->{closed} = 0;
2177 $form->{rowcount}--;
2178 $form->{shipto} = 1;
2180 if ($form->{type} =~ /_order$/) {
2181 $form->{exchangerate} = $exchangerate;
2185 if ( $form->{type} eq 'purchase_order'
2186 || $form->{type} eq 'request_quotation') {
2187 $form->{title} = $locale->text('Add Vendor Invoice');
2188 $form->{script} = 'ir.pl';
2192 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2193 $form->{title} = $locale->text('Add Sales Invoice');
2194 $form->{script} = 'is.pl';
2199 # bo creates the id, reset it
2200 map { delete $form->{$_} }
2201 qw(id subject message cc bcc printed emailed queued);
2202 $form->{ $form->{vc} } =~ s/--.*//g;
2203 $form->{type} = "invoice";
2206 $locale = new Locale "$myconfig{countrycode}", "$script";
2208 require "$form->{path}/$form->{script}";
2210 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2212 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2213 qw(creditlimit creditremaining);
2215 $currency = $form->{currency};
2218 $form->{currency} = $currency;
2219 $form->{exchangerate} = "";
2220 $form->{forex} = "";
2221 $form->{exchangerate} = $exchangerate
2225 $form->check_exchangerate(
2226 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2229 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2234 for $i (1 .. $form->{rowcount}) {
2235 $form->{"discount_$i"} =
2236 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2238 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2240 $decimalplaces = ($dec > 2) ? $dec : 2;
2242 # copy delivery date from reqdate for order -> invoice conversion
2243 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2244 unless $form->{"deliverydate_$i"};
2246 $form->{"sellprice_$i"} =
2247 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2250 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2251 $dec_qty = length $dec_qty;
2253 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2255 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2256 qw(partnumber description unit);
2262 $lxdebug->leave_sub();
2265 sub backorder_exchangerate {
2266 $lxdebug->enter_sub();
2267 my ($orddate, $buysell) = @_;
2274 <form method=post action=$form->{script}>
2277 # delete action variable
2278 map { delete $form->{$_} } qw(action header exchangerate);
2280 foreach $key (keys %$form) {
2281 $form->{$key} =~ s/\"/"/g;
2282 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2285 $form->{title} = $locale->text('Add Exchangerate');
2289 <input type=hidden name=path value=$form->{path}>
2290 <input type=hidden name=login value=$form->{login}>
2291 <input type=hidden name=password value=$form->{password}>
2293 <input type=hidden name=exchangeratedate value=$orddate>
2294 <input type=hidden name=buysell value=$buysell>
2297 <tr><th class=listtop>$form->{title}</th></tr>
2298 <tr height="5"></tr>
2303 <th align=right>| . $locale->text('Currency') . qq|</th>
2304 <td>$form->{currency}</td>
2307 <th align=right>| . $locale->text('Date') . qq|</th>
2311 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2312 <td><input name=exchangerate size=11></td>
2322 <input type=hidden name=nextsub value=save_exchangerate>
2324 <input name=action class=submit type=submit value="|
2325 . $locale->text('Continue') . qq|">
2333 $lxdebug->leave_sub();
2336 sub save_exchangerate {
2337 $lxdebug->enter_sub();
2339 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2340 $form->{exchangerate} =
2341 $form->parse_amount(\%myconfig, $form->{exchangerate});
2342 $form->save_exchangerate(\%myconfig, $form->{currency},
2343 $form->{exchangeratedate},
2344 $form->{exchangerate}, $form->{buysell});
2348 $lxdebug->leave_sub();
2351 sub create_backorder {
2352 $lxdebug->enter_sub();
2354 $form->{shipped} = 1;
2356 # figure out if we need to create a backorder
2357 # items aren't saved if qty != 0
2359 for $i (1 .. $form->{rowcount}) {
2360 $totalqty += $qty = $form->{"qty_$i"};
2361 $totalship += $ship = $form->{"ship_$i"};
2363 $form->{"qty_$i"} = $qty - $ship;
2366 if ($totalship == 0) {
2367 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2368 $form->{ordtotal} = 0;
2369 $form->{shipped} = 0;
2373 if ($totalqty == $totalship) {
2374 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2375 $form->{ordtotal} = 0;
2380 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2383 for $i (1 .. $form->{rowcount}) {
2385 $form->{"${_}_$i"} =
2386 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2387 } qw(sellprice discount);
2392 OE->save(\%myconfig, \%$form);
2394 # rebuild rows for invoice
2398 for $i (1 .. $form->{rowcount}) {
2399 $form->{"qty_$i"} = $form->{"ship_$i"};
2401 if ($form->{"qty_$i"}) {
2404 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2409 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2410 $form->{rowcount} = $count;
2412 $lxdebug->leave_sub();
2416 $lxdebug->enter_sub();
2418 $form->{saveasnew} = 1;
2419 $form->{closed} = 0;
2420 map { delete $form->{$_} } qw(printed emailed queued ordnumber quonumber);
2424 $lxdebug->leave_sub();
2427 sub purchase_order {
2428 $lxdebug->enter_sub();
2430 if ( $form->{type} eq 'sales_quotation'
2431 || $form->{type} eq 'request_quotation') {
2432 OE->close_order(\%myconfig, \%$form);
2435 $form->{cp_id} *= 1;
2437 $form->{title} = $locale->text('Add Purchase Order');
2438 $form->{vc} = "vendor";
2439 $form->{type} = "purchase_order";
2443 $lxdebug->leave_sub();
2447 $lxdebug->enter_sub();
2449 if ( $form->{type} eq 'sales_quotation'
2450 || $form->{type} eq 'request_quotation') {
2451 OE->close_order(\%myconfig, $form);
2454 $form->{cp_id} *= 1;
2456 $form->{title} = $locale->text('Add Sales Order');
2457 $form->{vc} = "customer";
2458 $form->{type} = "sales_order";
2462 $lxdebug->leave_sub();
2466 $lxdebug->enter_sub();
2468 $form->{transdate} = $form->current_date(\%myconfig);
2469 delete $form->{duedate};
2471 $form->{closed} = 0;
2474 map { delete $form->{$_} }
2475 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2477 for $i (1 .. $form->{rowcount}) {
2478 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2479 $form->{"${_}_${i}"})
2480 if ($form->{"${_}_${i}"}) }
2481 qw(ship qty sellprice listprice basefactor));
2489 for $i (1 .. $form->{rowcount} - 1) {
2490 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2491 qw(partnumber description unit);
2494 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2495 qw(creditlimit creditremaining);
2499 $lxdebug->leave_sub();