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 "bin/mozilla/io.pl";
41 require "bin/mozilla/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}&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->{"multi_id_$_"} } (1 .. $form->{rowcount});
127 undef $form->{rowcount};
129 $lxdebug->leave_sub();
132 } elsif (!$form->{id}) {
134 $lxdebug->leave_sub();
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();
160 # get customer/vendor
161 $form->all_vc(\%myconfig, $form->{vc},
162 ($form->{vc} eq 'customer') ? "AR" : "AP");
164 # retrieve order/quotation
165 $form->{webdav} = $webdav;
166 $form->{jsscript} = 1;
168 my $editing = $form->{id};
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};
182 $salesman_id = $form->{salesman_id} if ($editing);
185 # if multiple rowcounts (== collective order) then check if the
186 # there were more than one customer (in that case OE::retrieve removes
187 # the content from the field)
188 if ( $form->{rowcount}
189 && $form->{type} eq 'sales_order'
190 && defined $form->{customer}
191 && $form->{customer} eq '') {
193 # $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
196 'Collective Orders only work for orders from one customer!')
200 $taxincluded = $form->{taxincluded};
201 $form->{shipto} = 1 if $form->{id};
203 if ($form->{"all_$form->{vc}"}) {
204 unless ($form->{"$form->{vc}_id"}) {
205 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
209 $cp_id = $form->{cp_id};
210 $intnotes = $form->{intnotes};
212 # get customer / vendor
213 if ($form->{type} =~ /(purchase_order|request_quotation)/) {
214 IR->get_vendor(\%myconfig, \%$form);
216 #quote all_vendor Bug 133
217 foreach $ref (@{ $form->{all_vendor} }) {
218 $ref->{name} = $form->quote($ref->{name});
222 if ($form->{type} =~ /sales_(order|quotation)/) {
223 IS->get_customer(\%myconfig, \%$form);
225 #quote all_vendor Bug 133
226 foreach $ref (@{ $form->{all_customer} }) {
227 $ref->{name} = $form->quote($ref->{name});
231 $form->{cp_id} = $cp_id;
234 $form->{payment_id} = $payment_id;
237 $form->{language_id} = $language_id;
240 $form->{taxzone_id} = $taxzone_id;
242 $form->{intnotes} = $intnotes if $intnotes;
243 ($form->{ $form->{vc} }) = split /--/, $form->{ $form->{vc} };
244 $form->{"old$form->{vc}"} =
245 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
247 # build the popup menus
248 if (@{ $form->{"all_$form->{vc}"} }) {
249 $form->{ $form->{vc} } =
250 qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
251 map { $form->{"select$form->{vc}"} .=
252 "<option>$_->{name}--$_->{id}</option>\n" }
253 (@{ $form->{"all_$form->{vc}"} });
256 $form->{taxincluded} = $taxincluded if ($form->{id});
259 if (@{ $form->{all_departments} }) {
260 $form->{selectdepartment} = "<option>\n";
261 $form->{department} = "$form->{department}--$form->{department_id}";
264 $form->{selectdepartment} .=
265 "<option>$_->{description}--$_->{id}</option>\n"
266 } (@{ $form->{all_departments} });
269 $form->{employee} = "$form->{employee}--$form->{employee_id}";
272 $form->{forex} = $form->{exchangerate};
274 $form->{salesman_id} = $salesman_id if ($editing);
276 $lxdebug->leave_sub();
280 $lxdebug->enter_sub();
281 $form->{formname} = $form->{type} unless $form->{formname};
284 foreach $ref (@{ $form->{form_details} }) {
285 $form->{rowcount} = ++$i;
287 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
289 for my $i (1 .. $form->{rowcount}) {
291 $form->{"discount_$i"} =
292 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
294 $form->{"discount_$i"} =
295 $form->format_amount(\%myconfig, $form->{"discount_$i"});
297 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
299 $decimalplaces = ($dec > 2) ? $dec : 2;
301 # copy reqdate from deliverydate for invoice -> order conversion
302 $form->{"reqdate_$i"} = $form->{"deliverydate_$i"}
303 unless $form->{"reqdate_$i"};
305 $form->{"sellprice_$i"} =
306 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
309 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
310 $dec_qty = length $dec_qty;
312 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
314 map { $form->{"${_}_$i"} =~ s/\"/"/g }
315 qw(partnumber description unit);
318 $lxdebug->leave_sub();
322 $lxdebug->enter_sub();
324 my $checkedclosed = $form->{"closed"} ? "checked" : "";
325 my $checkeddelivered = $form->{"delivered"} ? "checked" : "";
327 if ($form->{old_employee_id}) {
328 $form->{employee_id} = $form->{old_employee_id};
330 if ($form->{old_salesman_id}) {
331 $form->{salesman_id} = $form->{old_salesman_id};
334 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
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} = 1;
346 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" onBlur=\"check_right_date_format(this)\">
347 <input type=button name=transdate id="trigger1" value=|
348 . $locale->text('button') . qq|></td>
351 <td width="13"><input name=reqdate id=reqdate size=11 title="$myconfig{dateformat}" value="$form->{reqdate}" onBlur=\"check_right_date_format(this)\">
352 <input type=button name=reqdate name=reqdate id="trigger2" value=|
353 . $locale->text('button') . qq|></td>
358 Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1",
359 "reqdate", "BL", "trigger2");
363 if (($form->{"type"} eq "sales_order") ||
364 ($form->{"type"} eq "purchase_order")) {
366 <input name="delivered" id="delivered" type="checkbox" class="checkbox" value="1" $checkeddelivered>
367 <label for="delivered">| . $locale->text('Delivered') . qq|</label>|);
372 <input name="closed" id="closed" type="checkbox" class="checkbox" value="1" $checkedclosed>
373 <label for="closed">| . $locale->text('Closed') . qq|</label>|);
379 <td colspan=| . (2 * scalar(@tmp)) . qq| align=center>| . join("\n", @tmp) . qq|
385 # set option selected
386 foreach $item ($form->{vc}, currency, department, ($form->{vc} eq "customer" ? customer : vendor)) {
387 $form->{"select$item"} =~ s/ selected//;
388 $form->{"select$item"} =~
389 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
392 #quote select[customer|vendor] Bug 133
393 $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
395 #substitute \n and \r to \s (bug 543)
396 $form->{"select$form->{vc}"} =~ s/[\n\r]/ /g;
398 my @old_project_ids = ($form->{"globalproject_id"});
399 map({ push(@old_project_ids, $form->{"project_id_$_"})
400 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
402 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
403 $form->get_lists("contacts" => "ALL_CONTACTS",
404 "shipto" => "ALL_SHIPTO",
405 "projects" => { "key" => "ALL_PROJECTS",
407 "old_id" => \@old_project_ids },
408 "employees" => "ALL_EMPLOYEES",
409 "salesmen" => "ALL_SALESMEN",
410 "taxzones" => "ALL_TAXZONES",
411 "payments" => "ALL_PAYMENTS",
412 "currencies" => "ALL_CURRENCIES",
413 $vc => "ALL_" . uc($vc));
416 my @values = (undef);
417 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
418 push(@values, $item->{"cp_id"});
419 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
420 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
424 if (scalar @values > 1) {
427 <th align="right">| . $locale->text('Contact Person') . qq|</th>
429 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
430 '-labels' => \%labels, '-default' => $form->{"cp_id"}))
439 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
440 push(@values, $item->{"name"}.qq|--|.$item->{"id"});
441 $labels{$item->{"name"}.qq|--|.$item->{"id"}} = $item->{name};
445 <input type="hidden" name="$form->{vc}_id" value="| . H($form->{"$form->{vc}_id"}) . qq|">
446 <input type="hidden" name="old$form->{vc}" value="| . H($form->{"old$form->{vc}"}) . qq|">
447 <th align="right">| . $locale->text(ucfirst($form->{vc})) . qq|</th>
449 (($myconfig{vclimit} <= scalar(@values))
450 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
451 : (NTI($cgi->popup_menu('-name' => "$form->{vc}", '-default' => $form->{"old$form->{vc}"},
452 '-onChange' => 'document.getElementById(\'update_button\').click();',
453 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
454 <input type="button" value="?" onclick="show_vc_details('$form->{vc}')">
455 </td><input type=hidden name="select$form->{vc}" value="| .
456 Q($form->{"select$form->{vc}"}) . qq|">|;
460 foreach my $item (@{ $form->{"ALL_PAYMENTS"} }) {
461 push(@values, $item->{"id"});
462 $labels{$item->{"id"}} = $item->{"description"};
466 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
468 NTI($cgi->popup_menu('-name' => 'payment_id', '-values' => \@values, '-style' => 'width: 250px',
469 '-labels' => \%labels, '-default' => $form->{payment_id}))
474 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
475 push(@values, $item->{"shipto_id"});
476 $labels{$item->{"shipto_id"}} = join "; ", grep { $_ } map { $item->{"shipto${_}" } } qw(name department_1 street city);
480 if (scalar @values > 1) {
483 <th align="right">| . $locale->text('Shipping Address') . qq|</th>
485 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, '-style' => 'width: 250px',
486 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
492 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
493 push(@values, $item->{"id"});
494 $labels{$item->{"id"}} = $item->{"projectnumber"};
496 my $globalprojectnumber =
497 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
498 '-labels' => \%labels,
499 '-default' => $form->{"globalproject_id"}));
504 if ($form->{type} =~ /^sales_/) {
505 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
506 push(@values, $item->{"id"});
507 $labels{$item->{"id"}} = ($item->{"name"} ne "" ? $item->{"name"} : $item->{"login"});
511 <th align="right">| . $locale->text('Salesman') . qq|</th>
513 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{"salesman_id"} ? $form->{"salesman_id"} : $form->{"employee_id"},
514 '-values' => \@values, '-labels' => \%labels))
521 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
522 push(@values, $item->{"id"});
523 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
528 <th align="right">| . $locale->text('Employee') . qq|</th>
530 NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
531 '-values' => \@values, '-labels' => \%labels)) . qq|
537 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
538 push(@values, $item->{"id"});
539 $labels{$item->{"id"}} = $item->{"description"};
544 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
546 NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
547 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
554 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
555 push(@values, $item);
556 $labels{$item} = $item;
559 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
561 if (scalar @values) {
564 <th align="right">| . $locale->text('Currency') . qq|</th>
566 NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
567 '-values' => \@values, '-labels' => \%labels)) . qq|
572 $form->{exchangerate} =
573 $form->format_amount(\%myconfig, $form->{exchangerate});
575 if (!$form->{exchangerate}) {
576 $form->{exchangerate} = "";
579 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
585 $form->{creditlimit} =
586 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
587 $form->{creditremaining} =
588 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
591 <input type=hidden name=forex value=$form->{forex}>
594 if ($form->{currency} ne $form->{defaultcurrency}) {
595 if ($form->{forex}) {
598 . $locale->text('Exchangerate')
599 . qq|</th><td>$form->{exchangerate}</td>
600 <input type=hidden name=exchangerate value=$form->{exchangerate}>
605 . $locale->text('Exchangerate')
606 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
610 if ($form->{business}) {
613 <th align="right">| . ($form->{vc} eq "customer" ? $locale->text('Customer type') : $locale->text('Vendor type')) . qq|</th>
614 <td>$form->{business}; | . $locale->text('Trade Discount') . qq| |
615 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
621 if ($form->{max_dunning_level}) {
624 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
626 <b>$form->{max_dunning_level}</b>;
627 | . $locale->text('Dunning Amount') . qq|: <b>|
628 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
635 if ($form->{type} !~ /_quotation$/) {
638 <th width=70% align=right nowrap>| . $locale->text('Order Number') . qq|</th>
639 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
642 <th width=70% align=right nowrap>|
643 . $locale->text('Quotation Number') . qq|</th>
644 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
647 <th width=70% align=right nowrap>|
648 . $locale->text('Customer Order Number') . qq|</th>
649 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
652 <th align=right nowrap>| . $locale->text('Order Date') . qq|</th>
657 <th align=right nowrap=true>| . $locale->text('Required by') . qq|</th>
662 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
664 $creditremaining = qq|
667 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
668 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
674 ($form->{type} eq 'sales_quotation')
675 ? $locale->text('Valid until')
676 : $locale->text('Required by');
677 if ($form->{type} eq 'sales_quotation') {
680 <th width=70% align=right nowrap>|
681 . $locale->text('Quotation Number') . qq|</th>
682 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
683 <input type=hidden name=ordnumber value="$form->{ordnumber}">
689 <th width=70% align=right nowrap>| . $locale->text('RFQ Number') . qq|</th>
690 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
691 <input type=hidden name=ordnumber value="$form->{ordnumber}">
699 <th align=right nowrap>| . $locale->text('Quotation Date') . qq|</th>
703 <th align=right nowrap=true>$reqlabel</th>
707 $creditremaining = qq| <tr>
715 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
716 <td colspan=3><select name=department style="width: 250px">$form->{selectdepartment}</select>
717 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
719 </tr> | if $form->{selectdepartment};
721 if ($form->{type} eq 'sales_order') {
722 if ($form->{selectemployee}) {
724 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
728 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">|;
730 if ($form->{resubmit} && ($form->{format} eq "html")) {
732 qq|window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()|;
733 } elsif ($form->{resubmit}) {
734 $onload = qq|document.oe.submit()|;
739 $credittext = $locale->text('Credit Limit exceeded!!!');
740 if ($creditwarning) {
741 $onload = qq|alert('$credittext')|;
744 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
745 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
747 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
748 # show history button js
749 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
750 #/show history button js
751 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
756 <body onLoad="$onload">
758 <form method=post name=oe action=$form->{script}>
760 <script type="text/javascript" src="js/common.js"></script>
761 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
762 <script type="text/javascript" src="js/vendor_selection.js"></script>
763 <script type="text/javascript" src="js/calculate_qty.js"></script>
766 $form->hide_form(qw(id action type vc formname media format proforma queued printed emailed
767 title discount creditlimit creditremaining tradediscount business
768 max_dunning_level dunning_amount));
774 <th class=listtop>$form->{title}</th>
796 <th align=right>| . $locale->text('Shipping Point') . qq|</th>
797 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
800 <th align=right>| . $locale->text('Ship via') . qq|</th>
801 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
804 <th align="right">| . $locale->text('Transaction description') . qq|</th>
805 <td colspan="3"><input name="transaction_description" size="35" value="| . H($form->{transaction_description}) . qq|"></td>
812 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
814 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
815 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
819 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
821 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
822 # <input size=45 id=vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
836 <th width="70%" align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
837 <td>$globalprojectnumber</td>
848 <!-- shipto are in hidden variables -->
850 <input type=hidden name=shiptoname value="$form->{shiptoname}">
851 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
852 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
853 <input type=hidden name=shiptocity value="$form->{shiptocity}">
854 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
855 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
856 <input type=hidden name=shiptophone value="$form->{shiptophone}">
857 <input type=hidden name=shiptofax value="$form->{shiptofax}">
858 <input type=hidden name=shiptodepartment_1 value="$form->{shiptodepartment_1}">
859 <input type=hidden name=shiptodepartment_2 value="$form->{shiptodepartment_2}">
860 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
862 <!-- email variables -->
863 <input type=hidden name=message value="$form->{message}">
864 <input type=hidden name=email value="$form->{email}">
865 <input type=hidden name=subject value="$form->{subject}">
866 <input type=hidden name=cc value="$form->{cc}">
867 <input type=hidden name=bcc value="$form->{bcc}">
869 <input type=hidden name=taxpart value="$form->{taxpart}">
870 <input type=hidden name=taxservice value="$form->{taxservice}">
872 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
875 foreach $item (split / /, $form->{taxaccounts}) {
877 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
878 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
881 $lxdebug->leave_sub();
885 $lxdebug->enter_sub();
887 $form->{invtotal} = $form->{invsubtotal};
889 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
892 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
895 $rows = ($rows > $introws) ? $rows : $introws;
897 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
899 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
901 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
904 if ($form->{taxaccounts}) {
906 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
907 . $locale->text('Tax Included') . qq|</b><br><br>
911 if (!$form->{taxincluded}) {
913 foreach $item (split / /, $form->{taxaccounts}) {
914 if ($form->{"${item}_base"}) {
915 $form->{invtotal} += $form->{"${item}_total"} =
917 $form->{"${item}_base"} * $form->{"${item}_rate"},
919 $form->{"${item}_total"} =
920 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
924 <th align=right>$form->{"${item}_description"} |
925 . $form->{"${item}_rate"} * 100 .qq|%</th>
926 <td align=right>$form->{"${item}_total"}</td>
932 $form->{invsubtotal} =
933 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
937 <th align=right>| . $locale->text('Subtotal') . qq|</th>
938 <td align=right>$form->{invsubtotal}</td>
944 if ($form->{taxincluded}) {
945 foreach $item (split / /, $form->{taxaccounts}) {
946 if ($form->{"${item}_base"}) {
947 $form->{"${item}_total"} =
949 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
950 (1 + $form->{"${item}_rate"})
953 $form->{"${item}_netto"} =
955 ($form->{"${item}_base"} - $form->{"${item}_total"}),
957 $form->{"${item}_total"} =
958 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
959 $form->{"${item}_netto"} =
960 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
964 <th align=right>Enthaltene $form->{"${item}_description"} |
965 . $form->{"${item}_rate"} * 100 .qq|%</th>
966 <td align=right>$form->{"${item}_total"}</td>
969 <th align=right>Nettobetrag</th>
970 <td align=right>$form->{"${item}_netto"}</td>
978 $form->{oldinvtotal} = $form->{invtotal};
980 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
990 <th align=left>| . $locale->text('Notes') . qq|</th>
991 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
1002 <td align=right width=100%>
1008 <th align=right>| . $locale->text('Total') . qq|</th>
1009 <td align=right>$form->{invtotal}</td>
1017 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1018 <input type=hidden name=oldtotalpaid value=$totalpaid>
1020 <td><hr size=3 noshade></td>
1028 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
1031 <td align=left width=30%><b>Dateiname</b></td>
1032 <td align=left width=70%><b>Webdavlink</b></td>
1034 foreach $file (keys %{ $form->{WEBDAV} }) {
1037 <td align=left>$file</td>
1038 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
1046 <td><hr size=3 noshade></td>
1064 | . $locale->text("Edit the $form->{type}") . qq|<br>
1065 <input class=submit type=submit name=action id=update_button value="|
1066 . $locale->text('Update') . qq|">
1067 <input class=submit type=submit name=action value="|
1068 . $locale->text('Ship to') . qq|">
1069 <input class=submit type=submit name=action value="|
1070 . $locale->text('Print') . qq|">
1071 <input class=submit type=submit name=action value="|
1072 . $locale->text('E-mail') . qq|">
1073 <input class=submit type=submit name=action value="|
1074 . $locale->text('Save') . qq|">
1075 <input class=submit type=submit name=action value="|
1076 . $locale->text('Save and Close') . qq|">
1079 if (($form->{id})) {
1081 <input type="button" class="submit" onclick="set_history_window(|
1083 . qq|);" name="history" id="history" value="|
1084 . $locale->text('history')
1087 <br>| . $locale->text("Workflow $form->{type}") . qq|<br>
1088 <input class=submit type=submit name=action value="|
1089 . $locale->text('Save as new') . qq|">
1090 <input class=submit type=submit name=action value="|
1091 . $locale->text('Delete') . qq|">|;
1092 if (($form->{type} =~ /sales_quotation$/)) {
1094 <input class=submit type=submit name=action value="|
1095 . $locale->text('Sales Order') . qq|">|;
1097 if ($form->{type} =~ /request_quotation$/) {
1099 <input class=submit type=submit name=action value="|
1100 . $locale->text('Purchase Order') . qq|">|;
1104 <input class=submit type=submit name=action value="|
1105 . $locale->text('Invoice') . qq|">
1109 if ($form->{type} =~ /sales_order$/) {
1111 <br>$form->{heading} als neue Vorlage verwenden für<br>
1112 <input class=submit type=submit name=action value="|
1113 . $locale->text('Purchase Order') . qq|">
1114 <input class=submit type=submit name=action value="|
1115 . $locale->text('Quotation') . qq|">
1118 } elsif ($form->{type} =~ /purchase_order$/) {
1120 <br>$form->{heading} als neue Vorlage verwenden für<br>
1121 <input class=submit type=submit name=action value="|
1122 . $locale->text('Sales Order') . qq|">
1123 <input class=submit type=submit name=action value="|
1124 . $locale->text('Request for Quotation') . qq|">
1129 <br>$form->{heading} als neue Vorlage verwenden für<br>
1130 <input class=submit type=submit name=action value="|
1131 . $locale->text('Order') . qq|">
1134 } elsif ($form->{type} =~ /sales_order$/ && $form->{rowcount} && !$form->{proforma}) {
1136 <br>Workflow $form->{heading}<br>
1137 <input class=submit type=submit name=action value="|
1138 . $locale->text('Save as new') . qq|">
1139 <input class=submit type=submit name=action value="|
1140 . $locale->text('Invoice') . qq|">
1144 $form->hide_form("saved_xyznumber");
1148 <input type=hidden name=rowcount value=$form->{rowcount}>
1150 <input name=callback type=hidden value="$form->{callback}">
1152 <input type=hidden name=login value=$form->{login}>
1153 <input type=hidden name=password value=$form->{password}>
1160 $lxdebug->leave_sub();
1164 $lxdebug->enter_sub();
1166 set_headings($form->{"id"} ? "edit" : "add");
1168 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1169 qw(exchangerate creditlimit creditremaining);
1170 $form->{update} = 1;
1172 if($form->{payment_id}) {
1173 $payment_id = $form->{payment_id};
1176 &check_name($form->{vc});
1178 if($form->{payment_id} eq "") {
1179 $form->{payment_id} = $payment_id;
1183 $buysell = 'sell' if ($form->{vc} eq 'vendor');
1184 $form->{exchangerate} = $exchangerate
1188 $form->check_exchangerate(
1189 \%myconfig, $form->{currency}, $form->{transdate}, $buysell
1193 $i = $form->{rowcount};
1195 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1197 if ( ($form->{"partnumber_$i"} eq "")
1198 && ($form->{"description_$i"} eq "")
1199 && ($form->{"partsgroup_$i"} eq "")) {
1201 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1206 if ( $form->{type} eq 'purchase_order'
1207 || $form->{type} eq 'request_quotation') {
1208 IR->retrieve_item(\%myconfig, \%$form);
1210 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
1211 IS->retrieve_item(\%myconfig, \%$form);
1214 my $rows = scalar @{ $form->{item_list} };
1216 $form->{"discount_$i"} =
1217 $form->format_amount(\%myconfig, $form->{discount} * 100);
1220 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
1229 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1230 if ($form->{"not_discountable_$i"}) {
1231 $form->{"discount_$i"} = 0;
1233 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1234 qw(partnumber description unit);
1235 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1236 keys %{ $form->{item_list}[0] };
1237 if ($form->{"part_payment_id_$i"} ne "") {
1238 $form->{payment_id} = $form->{"part_payment_id_$i"};
1241 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1243 ($dec) = ($s =~ /\.(\d+)/);
1245 $decimalplaces = ($dec > 2) ? $dec : 2;
1248 $form->{"sellprice_$i"} = $sellprice;
1251 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1253 # if there is an exchange rate adjust sellprice
1254 $form->{"sellprice_$i"} /= $exchangerate;
1258 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1259 (1 - $form->{"discount_$i"} / 100);
1260 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1261 map { $form->{"${_}_base"} += $amount }
1262 (split / /, $form->{"taxaccounts_$i"});
1263 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1264 split / /, $form->{taxaccounts}
1265 if !$form->{taxincluded};
1267 $form->{creditremaining} -= $amount;
1269 $form->{"sellprice_$i"} =
1270 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
1273 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
1275 # get pricegroups for parts
1276 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1278 # build up html code for prices_$i
1279 &set_pricegroup($i);
1286 # ok, so this is a new part
1287 # ask if it is a part or service item
1289 if ( $form->{"partsgroup_$i"}
1290 && ($form->{"partsnumber_$i"} eq "")
1291 && ($form->{"description_$i"} eq "")) {
1292 $form->{rowcount}--;
1293 $form->{"discount_$i"} = "";
1297 $form->{"id_$i"} = 0;
1298 $form->{"unit_$i"} = $locale->text('ea');
1306 $lxdebug->leave_sub();
1310 $lxdebug->enter_sub();
1312 if ($form->{type} eq 'purchase_order') {
1313 $form->{title} = $locale->text('Purchase Orders');
1314 $form->{vc} = 'vendor';
1315 $ordlabel = $locale->text('Order Number');
1316 $ordnumber = 'ordnumber';
1317 $employee = $locale->text('Employee');
1320 if ($form->{type} eq 'request_quotation') {
1321 $form->{title} = $locale->text('Request for Quotations');
1322 $form->{vc} = 'vendor';
1323 $ordlabel = $locale->text('RFQ Number');
1324 $ordnumber = 'quonumber';
1325 $employee = $locale->text('Employee');
1328 if ($form->{type} eq 'sales_order') {
1329 $form->{title} = $locale->text('Sales Orders');
1330 $form->{vc} = 'customer';
1331 $ordlabel = $locale->text('Order Number');
1332 $ordnumber = 'ordnumber';
1333 $employee = $locale->text('Employee');
1336 if ($form->{type} eq 'sales_quotation') {
1337 $form->{title} = $locale->text('Quotations');
1338 $form->{vc} = 'customer';
1339 $ordlabel = $locale->text('Quotation Number');
1340 $ordnumber = 'quonumber';
1341 $employee = $locale->text('Employee');
1344 # setup vendor / customer selection
1345 $form->all_vc(\%myconfig, $form->{vc},
1346 ($form->{vc} eq 'customer') ? "AR" : "AP");
1349 if (@{ $form->{all_departments} }) {
1350 $form->{selectdepartment} = "<option>\n";
1353 $form->{selectdepartment} .=
1354 "<option>$_->{description}--$_->{id}</option>\n"
1355 } (@{ $form->{all_departments} });
1360 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1361 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1363 | if $form->{selectdepartment};
1366 if (($form->{"type"} eq "sales_order") ||
1367 ($form->{"type"} eq "purchase_order")) {
1370 <td><input name="notdelivered" id="notdelivered" class="checkbox" type="checkbox" value="1" checked>
1371 <label for="notdelivered">|. $locale->text('Not delivered') . qq|</label></td>
1372 <td><input name="delivered" id="delivered" class="checkbox" type="checkbox" value="1" checked>
1373 <label for="delivered">| . $locale->text('Delivered') . qq|</label></td>
1378 # use JavaScript Calendar or not
1379 $form->{jsscript} = 1;
1383 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1384 <input type=button name=transdatefrom id="trigger3" value=|
1385 . $locale->text('button') . qq|></td>
1388 <td><input name=transdateto id=transdateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
1389 <input type=button name=transdateto name=transdateto id="trigger4" value=|
1390 . $locale->text('button') . qq|></td>
1395 Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger3",
1396 "transdateto", "BL", "trigger4");
1398 my $vc = $form->{vc} eq "customer" ? "customers" : "vendors";
1400 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1402 "employees" => "ALL_EMPLOYEES",
1403 $vc => "ALL_" . uc($vc));
1407 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
1408 push(@values, $item->{"id"});
1409 $labels{$item->{"id"}} = $item->{"projectnumber"};
1412 NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values,
1413 '-labels' => \%labels));
1418 foreach my $item (@{ $form->{"ALL_EMPLOYEES"} }) {
1419 push(@values, $item->{"id"});
1420 $labels{$item->{"id"}} = $item->{"name"} ne "" ? $item->{"name"} : $item->{"login"};
1423 my $employee_block = qq|
1425 <th align="right">| . $locale->text('Employee') . qq|</th>
1427 NTI($cgi->popup_menu('-name' => 'employee_id',
1428 '-values' => \@values,
1429 '-labels' => \%labels)) . qq|
1436 foreach my $item (@{ $form->{($form->{vc} eq "customer" ? "ALL_CUSTOMERS" : "ALL_VENDORS")}}) {
1437 push(@values, $item->{name}.qq|--|.$item->{"id"});
1438 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
1441 my $vc_label = $form->{vc} eq "customer" ? $locale->text('Customer') : $locale->text('Vendor');
1443 $myconfig{vclimit} <= scalar(@values)
1444 ? qq|<input type="text" value="| . H(($form->{"old$form->{vc}"} =~ /^(.*)\-\-.*$/)) . qq|" name="$form->{vc}">|
1445 : NTI($cgi->popup_menu('-name' => "$form->{vc}",
1446 '-default' => $form->{"old$form->{vc}"},
1447 '-onChange' => 'document.getElementById(\'update_button\').click();',
1448 '-values' => \@values,
1449 '-labels' => \%labels));
1455 <form method=post action=$form->{script}>
1459 <th class=listtop>$form->{title}</th>
1461 <tr height="5"></tr>
1466 <th align=right>$vc_label</th>
1467 <td colspan=3>$vc</td>
1471 <th align=right>$ordlabel</th>
1472 <td colspan=3><input name="$ordnumber" size=20></td>
1476 <th align="right">| . $locale->text('Transaction description') . qq|</th>
1477 <td colspan="3"><input name="transaction_description" size=20></td>
1480 <th align="right">| . $locale->text("Project Number") . qq|</th>
1481 <td colspan="3">$projectnumber</td>
1484 <th align=right>| . $locale->text('From') . qq|</th>
1486 <th align=right>| . $locale->text('Bis') . qq|</th>
1489 <input type=hidden name=sort value=transdate>
1491 <th align=right>| . $locale->text('Include in Report') . qq|</th>
1495 <td><input type="checkbox" name="open" value="1" id="open" checked>
1496 <label for="open">| . $locale->text("Open") . qq|</td>
1497 <td><input type="checkbox" name="closed" value="1" id="closed">
1498 <label for="closed">| . $locale->text("Closed") . qq|</td>
1502 <td><input name="l_id" class=checkbox type=checkbox value=Y>
1503 | . $locale->text('ID') . qq|</td>
1504 <td><input name="l_$ordnumber" class=checkbox type=checkbox value=Y checked> $ordlabel</td>
1505 <td><input name="l_transdate" class=checkbox type=checkbox value=Y checked> |
1506 . $locale->text('Date') . qq|</td>
1507 <td><input name="l_reqdate" class=checkbox type=checkbox value=Y checked> |
1508 . $locale->text('Required by') . qq|</td>
1511 <td><input name="l_name" class=checkbox type=checkbox value=Y checked> $vc_label</td>
1512 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1513 <td><input name="l_shipvia" class=checkbox type=checkbox value=Y> |
1514 . $locale->text('Ship via') . qq|</td>
1515 <td><input name="l_employee" class=checkbox type=checkbox value=Y checked> $employee</td>
1518 <td><input name="l_netamount" class=checkbox type=checkbox value=Y> |
1519 . $locale->text('Amount') . qq|</td>
1520 <td><input name="l_tax" class=checkbox type=checkbox value=Y> |
1521 . $locale->text('Tax') . qq|</td>
1522 <td><input name="l_amount" class=checkbox type=checkbox value=Y checked> |
1523 . $locale->text('Total') . qq|</td>
1526 <td><input name="l_globalprojectnumber" class=checkbox type=checkbox value=Y> |
1527 . $locale->text('Project Number') . qq|</td>
1528 <td><input name="l_transaction_description" class=checkbox type=checkbox value=Y> |
1529 . $locale->text('Transaction description') . qq|</td>
1532 <td><input name="l_subtotal" class=checkbox type=checkbox value=Y> |
1533 . $locale->text('Subtotal') . qq|</td>
1541 <tr><td colspan=4><hr size=3 noshade></td></tr>
1547 <input type=hidden name=nextsub value=orders>
1548 <input type=hidden name=login value=$form->{login}>
1549 <input type=hidden name=password value=$form->{password}>
1550 <input type=hidden name=vc value=$form->{vc}>
1551 <input type=hidden name=type value=$form->{type}>
1553 <input class=submit type=submit name=action value="|
1554 . $locale->text('Continue') . qq|">
1561 $lxdebug->leave_sub();
1565 $lxdebug->enter_sub();
1567 $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
1571 qw(type vc login password transdatefrom transdateto
1572 open closed notdelivered delivered department
1573 transaction_description);
1574 push @fields, $form->{vc};
1575 $href = "$form->{script}?action=orders&"
1576 . join("&", map { "${_}=" . E($form->{$_}) } @fields)
1577 . "&${ordnumber}=" . E($form->{$ordnumber});
1580 # split vendor / customer
1581 ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) =
1582 split(/--/, $form->{ $form->{vc} });
1584 OE->transactions(\%myconfig, \%$form);
1587 "transdate", "reqdate",
1589 "name", "netamount",
1592 "shipvia", "globalprojectnumber",
1593 "transaction_description", "open",
1594 "closed", "delivered"
1597 $form->{l_open} = $form->{l_closed} = "Y"
1598 if ($form->{open} && $form->{closed});
1600 $form->{"l_delivered"} = "Y"
1601 if ($form->{"delivered"} && $form->{"notdelivered"});
1603 foreach $item (@columns) {
1604 if ($form->{"l_$item"} eq "Y") {
1605 push @column_index, $item;
1607 # add column to href and callback
1608 $callback .= "&l_$item=Y";
1609 $href .= "&l_$item=Y";
1613 # only show checkboxes if gotten here via sales_order form.
1614 if ($form->{type} =~ /sales_order/) {
1615 unshift @column_index, "ids";
1618 if ($form->{l_subtotal} eq 'Y') {
1619 $callback .= "&l_subtotal=Y";
1620 $href .= "&l_subtotal=Y";
1623 if ($form->{vc} eq 'vendor') {
1624 if ($form->{type} eq 'purchase_order') {
1625 $form->{title} = $locale->text('Purchase Orders');
1627 $form->{title} = $locale->text('Request for Quotations');
1629 $name = $locale->text('Vendor');
1630 $employee = $locale->text('Employee');
1632 if ($form->{vc} eq 'customer') {
1633 if ($form->{type} eq 'sales_order') {
1634 $form->{title} = $locale->text('Sales Orders');
1636 $form->{title} = $locale->text('Quotations');
1638 $employee = $locale->text('Employee');
1639 $name = $locale->text('Customer');
1642 $column_header{id} =
1643 qq|<th><a class=listheading href=$href&sort=id>|
1644 . $locale->text('ID')
1646 $column_header{transdate} =
1647 qq|<th><a class=listheading href=$href&sort=transdate>|
1648 . $locale->text('Date')
1650 $column_header{reqdate} =
1651 qq|<th><a class=listheading href=$href&sort=reqdate>|
1652 . $locale->text('Required by')
1654 $column_header{ordnumber} =
1655 qq|<th><a class=listheading href=$href&sort=ordnumber>|
1656 . $locale->text('Order')
1658 $column_header{quonumber} =
1659 qq|<th><a class=listheading href=$href&sort=quonumber>|
1660 . ($form->{"type"} eq "request_quotation" ?
1661 $locale->text('RFQ') :
1662 $locale->text('Quotation'))
1664 $column_header{name} =
1665 qq|<th><a class=listheading href=$href&sort=name>$name</a></th>|;
1666 $column_header{netamount} =
1667 qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
1668 $column_header{tax} =
1669 qq|<th class=listheading>| . $locale->text('Tax') . qq|</th>|;
1670 $column_header{amount} =
1671 qq|<th class=listheading>| . $locale->text('Total') . qq|</th>|;
1672 $column_header{curr} =
1673 qq|<th class=listheading>| . $locale->text('Curr') . qq|</th>|;
1674 $column_header{shipvia} =
1675 qq|<th><a class=listheading href=$href&sort=shipvia>|
1676 . $locale->text('Ship via')
1678 $column_header{globalprojectnumber} =
1679 qq|<th class="listheading">| . $locale->text('Project Number') . qq|</th>|;
1680 $column_header{open} =
1681 qq|<th class=listheading>| . $locale->text('O') . qq|</th>|;
1682 $column_header{closed} =
1683 qq|<th class=listheading>| . $locale->text('C') . qq|</th>|;
1684 $column_header{"delivered"} =
1685 qq|<th class="listheading">| . $locale->text("Delivered") . qq|</th>|;
1687 $column_header{employee} =
1688 qq|<th><a class=listheading href=$href&sort=employee>$employee</a></th>|;
1689 $column_header{transaction_description} =
1690 qq|<th><a class=listheading href="$href&sort=transaction_description">|
1691 . $locale->text("Transaction description") . qq|</a></th>|;
1693 $column_header{ids} = qq|<th></th>|;
1695 if ($form->{ $form->{vc} }) {
1696 $option = $locale->text(ucfirst $form->{vc});
1697 $option .= " : $form->{$form->{vc}}";
1699 if ($form->{department}) {
1700 $option .= "\n<br>" if ($option);
1701 ($department) = split /--/, $form->{department};
1702 $option .= $locale->text('Department') . " : $department";
1704 if ($form->{transdatefrom}) {
1706 . $locale->text('From') . " "
1707 . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
1709 if ($form->{transdateto}) {
1711 . $locale->text('Bis') . " "
1712 . $locale->date(\%myconfig, $form->{transdateto}, 1);
1714 if ($form->{open}) {
1715 $option .= "\n<br>" if ($option);
1716 $option .= $locale->text('Open');
1718 if ($form->{closed}) {
1719 $option .= "\n<br>" if ($option);
1720 $option .= $locale->text('Closed');
1728 <form method="post" action="oe.pl">
1731 <th class=listtop>$form->{title}</th>
1733 <tr height="5"></tr>
1740 <tr class=listheading>|;
1742 map { print "\n$column_header{$_}" } @column_index;
1748 # add sort and escape callback
1749 $callback_escaped = $form->escape($callback . "&sort=$form->{sort}");
1751 if (@{ $form->{OE} }) {
1752 $sameitem = $form->{OE}->[0]->{ $form->{sort} };
1757 foreach $oe (@{ $form->{OE} }) {
1758 $form->{rowcount} = ++$j;
1760 if ($form->{l_subtotal} eq 'Y') {
1761 if ($sameitem ne $oe->{ $form->{sort} }) {
1763 $sameitem = $oe->{ $form->{sort} };
1767 map { $oe->{$_} *= $oe->{exchangerate} } (qw(netamount amount));
1769 $column_data{netamount} =
1771 . $form->format_amount(\%myconfig, $oe->{netamount}, 2, " ")
1773 $column_data{tax} = "<td align=right>"
1774 . $form->format_amount(\%myconfig, $oe->{amount} - $oe->{netamount},
1777 $column_data{amount} =
1779 . $form->format_amount(\%myconfig, $oe->{amount}, 2, " ") . "</td>";
1781 $totalnetamount += $oe->{netamount};
1782 $totalamount += $oe->{amount};
1784 $subtotalnetamount += $oe->{netamount};
1785 $subtotalamount += $oe->{amount};
1788 qq|<td><input name="multi_id_$j" class=checkbox type=checkbox><input type="hidden" name="trans_id_$j" value="$oe->{id}"></td>|;
1789 $column_data{id} = "<td>$oe->{id}</td>";
1790 $column_data{transdate} = "<td>$oe->{transdate} </td>";
1791 $column_data{reqdate} = "<td>$oe->{reqdate} </td>";
1793 $column_data{$ordnumber} =
1794 "<td><a href=oe.pl?action=$action&type=$form->{type}&id=$oe->{id}&vc=$form->{vc}&login=$form->{login}&password=$form->{password}&callback=$callback_escaped>$oe->{$ordnumber}</a></td>";
1795 $column_data{name} = "<td>$oe->{name}</td>";
1797 $column_data{employee} = "<td>$oe->{employee} </td>";
1798 $column_data{shipvia} = "<td>$oe->{shipvia} </td>";
1799 $column_data{globalprojectnumber} = "<td>" . H($oe->{globalprojectnumber}) . "</td>";
1801 if ($oe->{closed}) {
1802 $column_data{closed} = "<td align=center>X</td>";
1803 $column_data{open} = "<td> </td>";
1805 $column_data{closed} = "<td> </td>";
1806 $column_data{open} = "<td align=center>X</td>";
1808 $column_data{"delivered"} = "<td>" .
1809 ($oe->{"delivered"} ? $locale->text("Yes") : $locale->text("No")) .
1811 $column_data{transaction_description} = "<td>" . H($oe->{transaction_description}) . "</td>";
1816 <tr class=listrow$i>";
1818 map { print "\n$column_data{$_}" } @column_index;
1826 if ($form->{l_subtotal} eq 'Y') {
1832 <tr class=listtotal>|;
1834 map { $column_data{$_} = "<td> </td>" } @column_index;
1836 $column_data{netamount} =
1837 "<th class=listtotal align=right>"
1838 . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . "</th>";
1839 $column_data{tax} = "<th class=listtotal align=right>"
1840 . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
1843 $column_data{amount} =
1844 "<th class=listtotal align=right>"
1845 . $form->format_amount(\%myconfig, $totalamount, 2, " ") . "</th>";
1847 map { print "\n$column_data{$_}" } @column_index;
1855 <td><hr size=3 noshade></td>
1859 # multiple invoice edit button only if gotten there via sales_order form.
1861 if ($form->{type} =~ /sales_order/) {
1863 <input class"submit" type="submit" name="action" value="|
1864 . $locale->text('Continue') . qq|">
1865 <input type="hidden" name="nextsub" value="edit">
1866 <input type="hidden" name="type" value="$form->{type}">
1867 <input type="hidden" name="vc" value="$form->{vc}">
1868 <input type="hidden" name="login" value="$form->{login}">
1869 <input type="hidden" name="password" value="$form->{password}">
1870 <input type="hidden" name="callback" value="$callback">
1871 <input type="hidden" name="rowcount" value="$form->{rowcount}">|;
1878 <form method=post action=$form->{script}>
1880 <input name=callback type=hidden value="$form->{callback}">
1882 <input type=hidden name=type value=$form->{type}>
1883 <input type=hidden name=vc value=$form->{vc}>
1885 <input type=hidden name=login value=$form->{login}>
1886 <input type=hidden name=password value=$form->{password}>
1894 $lxdebug->leave_sub();
1898 $lxdebug->enter_sub();
1900 map { $column_data{$_} = "<td> </td>" } @column_index;
1902 $column_data{netamount} =
1903 "<th class=listsubtotal align=right>"
1904 . $form->format_amount(\%myconfig, $subtotalnetamount, 2, " ")
1906 $column_data{tax} = "<td class=listsubtotal align=right>"
1907 . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount,
1910 $column_data{amount} =
1911 "<th class=listsubtotal align=right>"
1912 . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . "</th>";
1914 $subtotalnetamount = 0;
1915 $subtotalamount = 0;
1918 <tr class=listsubtotal>
1921 map { print "\n$column_data{$_}" } @column_index;
1927 $lxdebug->leave_sub();
1930 sub save_and_close {
1931 $lxdebug->enter_sub();
1933 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1936 if ($form->{type} =~ /_order$/) {
1937 $form->isblank("transdate", $locale->text('Order Date missing!'));
1939 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
1942 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
1943 $form->{$idx} =~ s/^\s*//g;
1944 $form->{$idx} =~ s/\s*$//g;
1946 $msg = ucfirst $form->{vc};
1947 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
1949 # $locale->text('Customer missing!');
1950 # $locale->text('Vendor missing!');
1952 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1953 if ($form->{currency} ne $form->{defaultcurrency});
1957 if($form->{payment_id}) {
1958 $payment_id = $form->{payment_id};
1961 # if the name changed get new values
1962 if (&check_name($form->{vc})) {
1963 if($form->{payment_id} eq "") {
1964 $form->{payment_id} = $payment_id;
1970 $form->{id} = 0 if $form->{saveasnew};
1972 # this is for the internal notes section for the [email] Subject
1973 if ($form->{type} =~ /_order$/) {
1974 if ($form->{type} eq 'sales_order') {
1975 $form->{label} = $locale->text('Sales Order');
1977 $numberfld = "sonumber";
1978 $ordnumber = "ordnumber";
1980 $form->{label} = $locale->text('Purchase Order');
1982 $numberfld = "ponumber";
1983 $ordnumber = "ordnumber";
1986 $err = $locale->text('Cannot save order!');
1989 if ($form->{type} eq 'sales_quotation') {
1990 $form->{label} = $locale->text('Quotation');
1992 $numberfld = "sqnumber";
1993 $ordnumber = "quonumber";
1995 $form->{label} = $locale->text('Request for Quotation');
1997 $numberfld = "rfqnumber";
1998 $ordnumber = "quonumber";
2001 $err = $locale->text('Cannot save quotation!');
2005 # get new number in sequence if no number is given or if saveasnew was requested
2006 if (!$form->{$ordnumber} || $form->{saveasnew}) {
2007 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld);
2012 $form->error($err) if (!OE->save(\%myconfig, \%$form));
2014 # saving the history
2015 if(!exists $form->{addition}) {
2016 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2017 $form->{addition} = "SAVED";
2018 $form->save_history($form->dbconnect(\%myconfig));
2020 # /saving the history
2022 $form->redirect($form->{label} . " $form->{$ordnumber} " .
2023 $locale->text('saved!'));
2025 $lxdebug->leave_sub();
2029 $lxdebug->enter_sub();
2031 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
2034 if ($form->{type} =~ /_order$/) {
2035 $form->isblank("transdate", $locale->text('Order Date missing!'));
2037 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2040 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2041 $form->{$idx} =~ s/^\s*//g;
2042 $form->{$idx} =~ s/\s*$//g;
2044 $msg = ucfirst $form->{vc};
2045 $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
2047 # $locale->text('Customer missing!');
2048 # $locale->text('Vendor missing!');
2050 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
2051 if ($form->{currency} ne $form->{defaultcurrency});
2055 if($form->{payment_id}) {
2056 $payment_id = $form->{payment_id};
2059 # if the name changed get new values
2060 if (&check_name($form->{vc})) {
2061 if($form->{payment_id} eq "") {
2062 $form->{payment_id} = $payment_id;
2068 $form->{id} = 0 if $form->{saveasnew};
2070 # this is for the internal notes section for the [email] Subject
2071 if ($form->{type} =~ /_order$/) {
2072 if ($form->{type} eq 'sales_order') {
2073 $form->{label} = $locale->text('Sales Order');
2075 $numberfld = "sonumber";
2076 $ordnumber = "ordnumber";
2078 $form->{label} = $locale->text('Purchase Order');
2080 $numberfld = "ponumber";
2081 $ordnumber = "ordnumber";
2084 $err = $locale->text('Cannot save order!');
2087 if ($form->{type} eq 'sales_quotation') {
2088 $form->{label} = $locale->text('Quotation');
2090 $numberfld = "sqnumber";
2091 $ordnumber = "quonumber";
2093 $form->{label} = $locale->text('Request for Quotation');
2095 $numberfld = "rfqnumber";
2096 $ordnumber = "quonumber";
2099 $err = $locale->text('Cannot save quotation!');
2103 $form->{$ordnumber} = $form->update_defaults(\%myconfig, $numberfld)
2104 unless $form->{$ordnumber};
2108 OE->save(\%myconfig, \%$form);
2110 # saving the history
2111 if(!exists $form->{addition}) {
2112 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2113 $form->{addition} = "SAVED";
2114 $form->save_history($form->dbconnect(\%myconfig));
2116 # /saving the history
2118 $form->{simple_save} = 1;
2119 if(!$form->{print_and_save}) {
2120 set_headings("edit");
2124 $lxdebug->leave_sub();
2128 $lxdebug->enter_sub();
2132 if ($form->{type} =~ /_order$/) {
2133 $msg = $locale->text('Are you sure you want to delete Order Number');
2134 $ordnumber = 'ordnumber';
2136 $msg = $locale->text('Are you sure you want to delete Quotation Number');
2137 $ordnumber = 'quonumber';
2143 <form method=post action=$form->{script}>
2146 # delete action variable
2147 map { delete $form->{$_} } qw(action header);
2149 foreach $key (keys %$form) {
2150 $form->{$key} =~ s/\"/"/g;
2151 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2155 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
2157 <h4>$msg $form->{$ordnumber}</h4>
2159 <input type="hidden" name="yes_nextsub" value="delete_order_quotation">
2160 <input name=action class=submit type=submit value="|
2161 . $locale->text('Yes') . qq|">
2162 <input name=action class=submit type=submit onclick="history.back()" value="|
2163 . $locale->text('No') . qq|">
2170 $lxdebug->leave_sub();
2173 sub delete_order_quotation {
2174 $lxdebug->enter_sub();
2176 if ($form->{type} =~ /_order$/) {
2177 $msg = $locale->text('Order deleted!');
2178 $err = $locale->text('Cannot delete order!');
2180 $msg = $locale->text('Quotation deleted!');
2181 $err = $locale->text('Cannot delete quotation!');
2183 if (OE->delete(\%myconfig, \%$form, $spool)){
2184 # saving the history
2185 if(!exists $form->{addition}) {
2186 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
2187 $form->{addition} = "DELETED";
2188 $form->save_history($form->dbconnect(\%myconfig));
2190 # /saving the history
2196 $lxdebug->leave_sub();
2200 $lxdebug->enter_sub();
2202 $form->{old_employee_id} = $form->{employee_id};
2203 $form->{old_salesman_id} = $form->{salesman_id};
2205 if ($form->{type} =~ /_order$/) {
2207 # these checks only apply if the items don't bring their own ordnumbers/transdates.
2208 # The if clause ensures that by searching for empty ordnumber_#/transdate_# fields.
2209 $form->isblank("ordnumber", $locale->text('Order Number missing!'))
2210 if (+{ map { $form->{"ordnumber_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2211 $form->isblank("transdate", $locale->text('Order Date missing!'))
2212 if (+{ map { $form->{"transdate_$_"}, 1 } (1 .. $form->{rowcount} - 1) }->{''});
2214 # also copy deliverydate from the order
2215 $form->{deliverydate} = $form->{reqdate} if $form->{reqdate};
2216 $form->{orddate} = $form->{transdate};
2218 $form->isblank("quonumber", $locale->text('Quotation Number missing!'));
2219 $form->isblank("transdate", $locale->text('Quotation Date missing!'));
2220 $form->{ordnumber} = "";
2221 $form->{quodate} = $form->{transdate};
2224 if($form->{payment_id}) {
2225 $payment_id = $form->{payment_id};
2228 # if the name changed get new values
2229 if (&check_name($form->{vc})) {
2230 if($form->{payment_id} eq "") {
2231 $form->{payment_id} = $payment_id;
2237 $form->{cp_id} *= 1;
2239 for $i (1 .. $form->{rowcount}) {
2240 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2241 $form->{"${_}_${i}"})
2242 if ($form->{"${_}_${i}"}) }
2243 qw(ship qty sellprice listprice basefactor));
2246 if ( $form->{type} =~ /_order/
2247 && $form->{currency} ne $form->{defaultcurrency}) {
2249 # check if we need a new exchangerate
2250 $buysell = ($form->{type} eq 'sales_order') ? "buy" : "sell";
2252 $orddate = $form->current_date(\%myconfig);
2254 $form->check_exchangerate(\%myconfig, $form->{currency}, $orddate,
2256 print(STDERR "CURRENCY $form->{currency} DEFAULT: $form->{defaultcurrency} EXCHANGE $exchangerate\n");
2258 if (!$exchangerate) {
2259 &backorder_exchangerate($orddate, $buysell);
2264 # close orders/quotations
2265 $form->{closed} = 1;
2267 # save order if one ordnumber has been given
2268 # if not it's most likely a collective order, which can't be saved back
2269 # so they just have to be closed
2270 if (($form->{ordnumber} ne '') || ($form->{quonumber} ne '')) {
2271 OE->close_order(\%myconfig, \%$form);
2273 OE->close_orders(\%myconfig, \%$form);
2276 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
2278 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
2281 $form->{closed} = 0;
2282 $form->{rowcount}--;
2283 $form->{shipto} = 1;
2285 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
2287 if ($form->{type} =~ /_order$/) {
2288 $form->{exchangerate} = $exchangerate;
2292 if ( $form->{type} eq 'purchase_order'
2293 || $form->{type} eq 'request_quotation') {
2294 $form->{title} = $locale->text('Add Vendor Invoice');
2295 $form->{script} = 'ir.pl';
2299 if ($form->{type} eq 'sales_order' || $form->{type} eq 'sales_quotation') {
2300 $form->{title} = $locale->text('Add Sales Invoice');
2301 $form->{script} = 'is.pl';
2306 # bo creates the id, reset it
2307 map { delete $form->{$_} }
2308 qw(id subject message cc bcc printed emailed queued);
2309 $form->{ $form->{vc} } =~ s/--.*//g;
2310 $form->{type} = "invoice";
2313 $locale = new Locale "$myconfig{countrycode}", "$script";
2315 require "bin/mozilla/$form->{script}";
2317 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
2319 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
2320 qw(creditlimit creditremaining);
2322 $currency = $form->{currency};
2325 $form->{currency} = $currency;
2326 $form->{exchangerate} = "";
2327 $form->{forex} = "";
2328 $form->{exchangerate} = $exchangerate
2332 $form->check_exchangerate(
2333 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
2336 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
2341 for $i (1 .. $form->{rowcount}) {
2342 $form->{"discount_$i"} =
2343 $form->format_amount(\%myconfig, $form->{"discount_$i"});
2345 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
2347 $decimalplaces = ($dec > 2) ? $dec : 2;
2349 # copy delivery date from reqdate for order -> invoice conversion
2350 $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
2351 unless $form->{"deliverydate_$i"};
2353 $form->{"sellprice_$i"} =
2354 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
2357 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
2358 $dec_qty = length $dec_qty;
2360 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
2362 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2363 qw(partnumber description unit);
2369 $lxdebug->leave_sub();
2372 sub backorder_exchangerate {
2373 $lxdebug->enter_sub();
2374 my ($orddate, $buysell) = @_;
2381 <form method=post action=$form->{script}>
2384 # delete action variable
2385 map { delete $form->{$_} } qw(action header exchangerate);
2387 foreach $key (keys %$form) {
2388 $form->{$key} =~ s/\"/"/g;
2389 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
2392 $form->{title} = $locale->text('Add Exchangerate');
2396 <input type=hidden name=login value=$form->{login}>
2397 <input type=hidden name=password value=$form->{password}>
2399 <input type=hidden name=exchangeratedate value=$orddate>
2400 <input type=hidden name=buysell value=$buysell>
2403 <tr><th class=listtop>$form->{title}</th></tr>
2404 <tr height="5"></tr>
2409 <th align=right>| . $locale->text('Currency') . qq|</th>
2410 <td>$form->{currency}</td>
2413 <th align=right>| . $locale->text('Date') . qq|</th>
2417 <th align=right>| . $locale->text('Exchangerate') . qq|</th>
2418 <td><input name=exchangerate size=11></td>
2428 <input type=hidden name=nextsub value=save_exchangerate>
2430 <input name=action class=submit type=submit value="|
2431 . $locale->text('Continue') . qq|">
2439 $lxdebug->leave_sub();
2442 sub save_exchangerate {
2443 $lxdebug->enter_sub();
2445 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
2446 $form->{exchangerate} =
2447 $form->parse_amount(\%myconfig, $form->{exchangerate});
2448 $form->save_exchangerate(\%myconfig, $form->{currency},
2449 $form->{exchangeratedate},
2450 $form->{exchangerate}, $form->{buysell});
2454 $lxdebug->leave_sub();
2457 sub create_backorder {
2458 $lxdebug->enter_sub();
2460 $form->{shipped} = 1;
2462 # figure out if we need to create a backorder
2463 # items aren't saved if qty != 0
2465 for $i (1 .. $form->{rowcount}) {
2466 $totalqty += $qty = $form->{"qty_$i"};
2467 $totalship += $ship = $form->{"ship_$i"};
2469 $form->{"qty_$i"} = $qty - $ship;
2472 if ($totalship == 0) {
2473 map { $form->{"ship_$_"} = $form->{"qty_$_"} } (1 .. $form->{rowcount});
2474 $form->{ordtotal} = 0;
2475 $form->{shipped} = 0;
2479 if ($totalqty == $totalship) {
2480 map { $form->{"qty_$_"} = $form->{"ship_$_"} } (1 .. $form->{rowcount});
2481 $form->{ordtotal} = 0;
2486 qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
2489 for $i (1 .. $form->{rowcount}) {
2491 $form->{"${_}_$i"} =
2492 $form->format_amount(\%myconfig, $form->{"${_}_$i"})
2493 } qw(sellprice discount);
2498 OE->save(\%myconfig, \%$form);
2500 # rebuild rows for invoice
2504 for $i (1 .. $form->{rowcount}) {
2505 $form->{"qty_$i"} = $form->{"ship_$i"};
2507 if ($form->{"qty_$i"}) {
2510 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
2515 $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
2516 $form->{rowcount} = $count;
2518 $lxdebug->leave_sub();
2522 $lxdebug->enter_sub();
2524 $form->{saveasnew} = 1;
2525 $form->{closed} = 0;
2526 map { delete $form->{$_} } qw(printed emailed queued);
2528 # Let Lx-Office assign a new order number if the user hasn't changed the
2529 # previous one. If it has been changed manually then use it as-is.
2530 my $idx = $form->{type} =~ /_quotation$/ ? "quonumber" : "ordnumber";
2531 $form->{$idx} =~ s/^\s*//g;
2532 $form->{$idx} =~ s/\s*$//g;
2533 if ($form->{saved_xyznumber} &&
2534 ($form->{saved_xyznumber} eq $form->{$idx})) {
2535 delete($form->{$idx});
2540 $lxdebug->leave_sub();
2543 sub check_for_direct_delivery_yes {
2544 $lxdebug->enter_sub();
2546 $form->{direct_delivery_checked} = 1;
2547 delete @{$form}{grep /^shipto/, keys %{ $form }};
2548 map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
2549 $form->{shipto} = 1;
2551 $lxdebug->leave_sub();
2554 sub check_for_direct_delivery_no {
2555 $lxdebug->enter_sub();
2557 $form->{direct_delivery_checked} = 1;
2558 delete @{$form}{grep /^shipto/, keys %{ $form }};
2561 $lxdebug->leave_sub();
2564 sub check_for_direct_delivery {
2565 $lxdebug->enter_sub();
2567 if ($form->{direct_delivery_checked}
2568 || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
2569 $lxdebug->leave_sub();
2573 if ($form->{shipto_id}) {
2574 Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_");
2577 map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form };
2580 delete $form->{action};
2581 $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ref $_ eq "" } keys %{ $form } ];
2584 print $form->parse_html_template("oe/check_for_direct_delivery");
2586 $lxdebug->leave_sub();
2591 sub purchase_order {
2592 $lxdebug->enter_sub();
2594 if ($form->{type} eq 'sales_order') {
2595 check_for_direct_delivery();
2598 if ( $form->{type} eq 'sales_quotation'
2599 || $form->{type} eq 'request_quotation') {
2600 OE->close_order(\%myconfig, \%$form);
2603 if ($form->{type} =~ /^sales_/) {
2604 delete($form->{ordnumber});
2607 $form->{cp_id} *= 1;
2609 $form->{title} = $locale->text('Add Purchase Order');
2610 $form->{vc} = "vendor";
2611 $form->{type} = "purchase_order";
2615 $lxdebug->leave_sub();
2619 $lxdebug->enter_sub();
2621 if ( $form->{type} eq 'sales_quotation'
2622 || $form->{type} eq 'request_quotation') {
2623 OE->close_order(\%myconfig, $form);
2626 if ($form->{type} eq "purchase_order") {
2627 delete($form->{ordnumber});
2630 $form->{cp_id} *= 1;
2632 $form->{title} = $locale->text('Add Sales Order');
2633 $form->{vc} = "customer";
2634 $form->{type} = "sales_order";
2638 $lxdebug->leave_sub();
2642 $lxdebug->enter_sub();
2644 $form->{transdate} = $form->current_date(\%myconfig);
2645 delete $form->{duedate};
2647 $form->{closed} = 0;
2649 $form->{old_employee_id} = $form->{employee_id};
2650 $form->{old_salesman_id} = $form->{salesman_id};
2653 map { delete $form->{$_} }
2654 qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
2656 for $i (1 .. $form->{rowcount}) {
2657 map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
2658 $form->{"${_}_${i}"})
2659 if ($form->{"${_}_${i}"}) }
2660 qw(ship qty sellprice listprice basefactor));
2668 for $i (1 .. $form->{rowcount} - 1) {
2669 map { $form->{"${_}_$i"} =~ s/\"/"/g }
2670 qw(partnumber description unit);
2673 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 0, "0") }
2674 qw(creditlimit creditremaining);
2678 $lxdebug->leave_sub();
2682 $lxdebug->enter_sub();
2684 $form->{print_and_save} = 1;
2689 my $saved_form = save_form();
2694 map({ $saved_vars{$_} = $form->{$_}; } qw(id ordnumber quonumber));
2695 restore_form($saved_form);
2696 map({ $form->{$_} = $saved_vars{$_}; } qw(id ordnumber quonumber));
2701 $lxdebug->leave_sub();
2705 call_sub($form->{yes_nextsub});
2709 call_sub($form->{no_nextsub});