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-2002
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 #======================================================================
30 # Inventory invoicing module
32 #======================================================================
38 require "$form->{path}/io.pl";
39 require "$form->{path}/arap.pl";
40 require "bin/mozilla/drafts.pl";
47 $lxdebug->enter_sub();
49 return $lxdebug->leave_sub() if (load_draft_maybe());
51 if ($form->{type} eq "credit_note") {
52 $form->{title} = $locale->text('Add Credit Note');
54 if ($form->{storno}) {
55 $form->{title} = $locale->text('Add Storno Credit Note');
58 $form->{title} = $locale->text('Add Sales Invoice');
64 "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
65 unless $form->{callback};
67 $form{jsscript} = "date";
69 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
71 $form->error("Access Denied");
77 $lxdebug->leave_sub();
81 $lxdebug->enter_sub();
84 $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
85 #/show hhistory button
87 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
89 $form->error("Access Denied");
92 if ($form->{print_and_post}) {
93 $form->{action} = "print";
94 $form->{resubmit} = 1;
95 $language_id = $form->{language_id};
96 $printer_id = $form->{printer_id};
100 if ($form->{print_and_post}) {
101 $form->{language_id} = $language_id;
102 $form->{printer_id} = $printer_id;
107 $lxdebug->leave_sub();
111 $lxdebug->enter_sub();
113 $form->{vc} = 'customer';
116 $form->{webdav} = $webdav;
117 $form->{lizenzen} = $lizenzen;
119 $form->create_links("AR", \%myconfig, "customer");
121 if ($form->{all_customer}) {
122 unless ($form->{customer_id}) {
123 $form->{customer_id} = $form->{all_customer}->[0]->{id};
124 $form->{salesman_id} = $form->{all_customer}->[0]->{salesman_id};
128 if ($form->{payment_id}) {
129 $payment_id = $form->{payment_id};
131 if ($form->{language_id}) {
132 $language_id = $form->{language_id};
134 if ($form->{taxzone_id}) {
135 $taxzone_id = $form->{taxzone_id};
140 if ($form->{shipto_id}) {
141 $shipto_id = $form->{shipto_id};
144 $cp_id = $form->{cp_id};
145 IS->get_customer(\%myconfig, \%$form);
147 #quote all_customer Bug 133
148 foreach $ref (@{ $form->{all_customer} }) {
149 $ref->{name} = $form->quote($ref->{name});
154 IS->retrieve_invoice(\%myconfig, \%$form);
155 $form->{cp_id} = $cp_id;
158 $form->{payment_id} = $payment_id;
161 $form->{language_id} = $language_id;
164 $form->{taxzone_id} = $taxzone_id;
167 $form->{shipto_id} = $shipto_id;
171 @curr = split(/:/, $form->{currencies});
173 $form->{defaultcurrency} = $curr[0];
175 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
177 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
179 if (@{ $form->{all_customer} }) {
180 $form->{customer} = "$form->{customer}--$form->{customer_id}";
181 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
182 (@{ $form->{all_customer} });
186 if ($form->{all_departments}) {
187 $form->{selectdepartment} = "<option>\n";
188 $form->{department} = "$form->{department}--$form->{department_id}";
191 $form->{selectdepartment} .=
192 "<option>$_->{description}--$_->{id}\n"
193 } (@{ $form->{all_departments} });
196 $form->{employee} = "$form->{employee}--$form->{employee_id}";
199 if ($form->{all_employees}) {
200 $form->{selectemployee} = "";
201 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
202 (@{ $form->{all_employees} });
206 $form->{forex} = $form->{exchangerate};
207 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
209 foreach $key (keys %{ $form->{AR_links} }) {
210 foreach $ref (@{ $form->{AR_links}{$key} }) {
211 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
214 if ($key eq "AR_paid") {
215 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
216 $form->{"AR_paid_$i"} =
217 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
220 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
221 $form->{"datepaid_$i"} =
222 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
223 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
224 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
225 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
226 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
228 $form->{paidaccounts} = $i;
232 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
237 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
239 $form->{AR} = $form->{AR_1} unless $form->{id};
242 ($form->datetonum($form->{invdate}, \%myconfig) <=
243 $form->datetonum($form->{closedto}, \%myconfig));
245 $lxdebug->leave_sub();
248 sub prepare_invoice {
249 $lxdebug->enter_sub();
251 if ($form->{type} eq "credit_note") {
252 $form->{type} = "credit_note";
253 $form->{formname} = "credit_note";
255 $form->{type} = "invoice";
256 $form->{formname} = "invoice";
261 map { $form->{$_} =~ s/\"/"/g }
262 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
264 # # get pricegroups for parts
265 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
269 foreach $ref (@{ $form->{invoice_details} }) {
272 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
273 $form->{"discount_$i"} =
274 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
275 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
277 $decimalplaces = ($dec > 2) ? $dec : 2;
279 $form->{"sellprice_$i"} =
280 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
283 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
284 $dec_qty = length $dec_qty;
287 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
289 map { $form->{"${_}_$i"} =~ s/\"/"/g }
290 qw(partnumber description unit partnotes);
291 $form->{rowcount} = $i;
295 $lxdebug->leave_sub();
299 $lxdebug->enter_sub();
303 if ($form->{type} eq "credit_note") {
304 $form->{title} = $locale->text('Edit Credit Note');
306 if ($form->{storno}) {
307 $form->{title} = $locale->text('Edit Storno Credit Note');
310 $form->{title} = $locale->text('Edit Sales Invoice');
312 if ($form->{storno}) {
313 $form->{title} = $locale->text('Edit Storno Invoice');
319 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
321 $payment = qq|<option value=""></option>|;
322 foreach $item (@{ $form->{payment_terms} }) {
323 if ($form->{payment_id} eq $item->{id}) {
324 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
326 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
330 my $set_duedate_url =
331 "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=set_duedate";
333 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
334 push(@ { $form->{AJAX} }, $pjx);
336 if (@{ $form->{TAXZONE} }) {
337 $form->{selecttaxzone} = "";
338 foreach $item (@{ $form->{TAXZONE} }) {
339 if ($item->{id} == $form->{taxzone_id}) {
340 $form->{selecttaxzone} .=
341 "<option value=$item->{id} selected>" . H($item->{description}) .
344 $form->{selecttaxzone} .=
345 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
350 $form->{selecttaxzone} =~ s/ selected//g;
351 if ($form->{taxzone_id} ne "") {
352 $form->{selecttaxzone} =~ s/value=\"$form->{taxzone_id}\"/value=\"$form->{taxzone_id}\" selected/;
358 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
359 <td><select name="taxzone_id">$form->{selecttaxzone}</select></td>
360 <input type="hidden" name="selecttaxzone" value="$form->{selecttaxzone}">
363 my @old_project_ids = ($form->{"globalproject_id"});
364 map({ push(@old_project_ids, $form->{"project_id_$_"})
365 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
367 $form->get_lists("contacts" => "ALL_CONTACTS",
368 "shipto" => "ALL_SHIPTO",
369 "projects" => { "key" => "ALL_PROJECTS",
371 "old_id" => \@old_project_ids },
372 "employees" => "ALL_SALESMEN");
375 my @values = (undef);
376 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
377 push(@values, $item->{"cp_id"});
378 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
379 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
382 NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
383 '-labels' => \%labels, '-default' => $form->{"cp_id"}));
387 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
388 push(@values, $item->{"shipto_id"});
389 $labels{$item->{"shipto_id"}} =
390 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
394 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
396 NTI($cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
397 '-labels' => \%labels, '-default' => $form->{"shipto_id"}))
402 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
403 push(@values, $item->{"id"});
404 $labels{$item->{"id"}} = $item->{"projectnumber"};
406 my $globalprojectnumber =
407 NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values,
408 '-labels' => \%labels,
409 '-default' => $form->{"globalproject_id"}));
413 foreach my $item (@{ $form->{ALL_SALESMEN} }) {
414 push(@values, $item->{id});
415 $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
420 <th align="right">| . $locale->text('Salesman') . qq|</th>
422 NTI($cgi->popup_menu('-name' => 'salesman_id', '-default' => $form->{salesman_id},
423 '-values' => \@values, '-labels' => \%labels))
427 # set option selected
428 foreach $item (qw(AR customer currency department employee)) {
429 $form->{"select$item"} =~ s/ selected//;
430 $form->{"select$item"} =~
431 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
434 #quote customer Bug 133
435 $form->{selectcustomer} = $form->quote($form->{selectcustomer});
437 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
443 $form->{exchangerate} =
444 $form->format_amount(\%myconfig, $form->{exchangerate});
446 $form->{creditlimit} =
447 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
448 $form->{creditremaining} =
449 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
452 if ($form->{currency} ne $form->{defaultcurrency}) {
453 if ($form->{forex}) {
455 qq|<th align="right">|
456 . $locale->text('Exchangerate')
457 . qq|</th><td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
460 qq|<th align="right">|
461 . $locale->text('Exchangerate')
462 . qq|</th><td><input name="exchangerate" size="10" value="$form->{exchangerate}"></td>|;
466 <input type="hidden" name="forex" value="$form->{forex}">
470 ($form->{selectcustomer})
471 ? qq|<select name="customer">$form->{selectcustomer}</select>\n<input type="hidden" name="selectcustomer" value="$form->{selectcustomer}">|
472 : qq|<input name="customer" value="$form->{customer}" size="35">|;
476 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
477 <td colspan="3"><select name="department">$form->{selectdepartment}</select>
478 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
481 | if $form->{selectdepartment};
483 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
485 if ($form->{business}) {
488 <th align="right">| . $locale->text('Business') . qq|</th>
489 <td>$form->{business}</td>
490 <th align="right">| . $locale->text('Trade Discount') . qq|</th>
492 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
498 if ($form->{max_dunning_level}) {
504 <th align="right">| . $locale->text('Max. Dunning Level') . qq|:</th>
505 <td><b>$form->{max_dunning_level}</b></td>
506 <th align="right">| . $locale->text('Dunning Amount') . qq|:</th>
508 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
517 $form->{fokus} = "invoice.customer";
519 # use JavaScript Calendar or not
520 $form->{jsscript} = $jscalendar;
522 if ($form->{type} eq "credit_note") {
523 if ($form->{jsscript}) {
525 # with JavaScript Calendar
527 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}"></td>
528 <td><input type="button" name="invdate" id="trigger1" value="|
529 . $locale->text('button') . qq|"></td>|;
533 Form->write_trigger(\%myconfig, "1",
538 # without JavaScript Calendar
540 qq|<td><input name="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}"></td>|;
542 qq|<td width="13"><input name="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}"></td>|;
545 if ($form->{jsscript}) {
547 # with JavaScript Calendar
549 <td><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}"></td>
550 <td><input type="button" name="invdate" id="trigger1" value="|
551 . $locale->text('button') . qq|"></td>
554 <td width="13"><input name="duedate" id="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}"></td>
555 <td width="4"><input type="button" name="duedate" id="trigger2" value="|
556 . $locale->text('button') . qq|"></td></td>
559 <td width="13"><input name="deliverydate" id="deliverydate" size="11" title="$myconfig{dateformat}" value="$form->{deliverydate}"></td>
560 <td width="4"><input type="button" name="deliverydate" id="trigger3" value="|
561 . $locale->text('button') . qq|"></td></td>
566 Form->write_trigger(\%myconfig, "3",
568 "trigger1", "duedate",
570 "deliverydate", "BL",
574 # without JavaScript Calendar
576 qq|<td><input name="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}"></td>|;
578 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
581 if ($form->{resubmit} && ($form->{format} eq "html")) {
583 qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
584 } elsif ($form->{resubmit}) {
585 $onload = qq|document.invoice.submit()|;
590 $credittext = $locale->text('Credit Limit exceeded!!!');
591 if ($creditwarning) {
592 $onload = qq|alert('$credittext')|;
595 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
598 $form->write_trigger(\%myconfig, 2,
599 "orddate", "BL", "trigger_orddate",
600 "quodate", "BL", "trigger_quodate");
601 # show history button js
602 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
603 #/show history button js
607 <body onLoad="$onload">
608 <script type="text/javascript" src="js/common.js"></script>
609 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
610 <script type="text/javascript" src="js/vendor_selection.js"></script>
611 <script type="text/javascript" src="js/calculate_qty.js"></script>
613 <form method="post" name="invoice" action="$form->{script}">
615 map({print $cgi->hidden("-name" => $_ , "-value" => $form->{$_});}
616 qw(id action type media format queued printed emailed title vc discount
617 creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id)) ;
618 print ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") ;
621 <input type="hidden" name="lizenzen" value="$lizenzen">
625 <th class="listtop">$form->{title}</th>
635 <th align="right" nowrap>| . $locale->text('Customer') . qq|</th>
636 <td colspan="3">$customer</td>
637 <input type="hidden" name="customer_klass" value="$form->{customer_klass}">
638 <input type="hidden" name="customer_id" value="$form->{customer_id}">
639 <input type="hidden" name="oldcustomer" value="$form->{oldcustomer}">
640 <th align="right" nowrap>|
641 . $locale->text('Contact Person') . qq|</th>
642 <td colspan="3">$contact</td>
649 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
650 <td>$form->{creditlimit}</td>
651 <td width="20%"></td>
652 <th nowrap>| . $locale->text('Remaining') . qq|</th>
653 <td class="plus$n">$form->{creditremaining}</td>
662 <th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
663 <td colspan="3"><select name="AR" style="width:280px;">$form->{selectAR}</select></td>
664 <input type="hidden" name="selectAR" value="$form->{selectAR}">
669 <th align="right" nowrap>| . $locale->text('Currency') . qq|</th>
670 <td><select name="currency">$form->{selectcurrency}</select></td>
671 <input type="hidden" name="selectcurrency" value="$form->{selectcurrency}">
672 <input type="hidden" name="defaultcurrency" value="$form->{defaultcurrency}">
673 <input type="hidden" name="fxgain_accno" value="$form->{fxgain_accno}">
674 <input type="hidden" name="fxloss_accno" value="$form->{fxloss_accno}">
678 <th align="right" nowrap>| . $locale->text('Shipping Point') . qq|</th>
680 $cgi->textfield("-name" => "shippingpoint", "-size" => 35, "-value" => $form->{shippingpoint}) .
683 <th align="right" nowrap>| . $locale->text('Ship via') . qq|</th>
684 <td colspan="3"><input name="shipvia" size="35" value="$form->{shipvia}"></td>
691 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
693 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
694 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
698 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
700 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
701 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
711 <th align="right" nowrap>| . $locale->text('Employee') . qq|</th>
712 <td colspan="2"><select name="employee">$form->{selectemployee}</select></td>
713 <input type="hidden" name="selectemployee" value="$form->{selectemployee}">
718 if ($form->{type} eq "credit_note") {
720 <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
721 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
724 <th align="right">| . $locale->text('Credit Note Date') . qq|</th>
729 <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
730 <td><input name="invnumber" size="11" value="$form->{invnumber}"></td>
733 <th align="right">| . $locale->text('Invoice Date') . qq|</th>
737 <th align="right">| . $locale->text('Due Date') . qq|</th>
741 <th align="right">| . $locale->text('Delivery Date') . qq|</th>
746 <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
747 <td><input name="ordnumber" size="11" value="$form->{ordnumber}"></td>
750 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
751 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
752 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
755 <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
756 <td><input name="quonumber" size="11" value="$form->{quonumber}"></td>
759 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
760 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
761 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
764 <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
765 <td><input name="cusordnumber" size="11" value="$form->{cusordnumber}"></td>
768 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
769 <td>$globalprojectnumber</td>
784 <!-- shipto are in hidden variables -->
786 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
787 qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2));
788 print qq|<!-- email variables --> |;
789 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
790 qw(message email subject cc bcc taxaccounts));
791 print qq|<input type="hidden" name="webdav" value="| . $webdav . qq|">|;
793 foreach $item (split(/ /, $form->{taxaccounts})) {
794 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); }
795 ("${item}_rate", "${item}_description", "${item}_taxnumber"));
797 $lxdebug->leave_sub();
801 $lxdebug->enter_sub();
803 $form->{invtotal} = $form->{invsubtotal};
805 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
808 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
811 $rows = ($rows > $introws) ? $rows : $introws;
813 qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
815 qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
817 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
820 if ($form->{taxaccounts}) {
822 <input name="taxincluded" class="checkbox" type="checkbox" value=$form->{taxincluded}> <b>|
823 . $locale->text('Tax Included') . qq|</b><br><br>|;
826 if (!$form->{taxincluded}) {
828 foreach $item (split / /, $form->{taxaccounts}) {
829 if ($form->{"${item}_base"}) {
830 $form->{"${item}_total"} =
832 $form->{"${item}_base"} * $form->{"${item}_rate"},
834 $form->{invtotal} += $form->{"${item}_total"};
835 $form->{"${item}_total"} =
836 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
840 <th align="right">$form->{"${item}_description"} |
841 . $form->{"${item}_rate"} * 100 .qq|%</th>
842 <td align="right">$form->{"${item}_total"}</td>
848 $form->{invsubtotal} =
849 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
853 <th align="right">| . $locale->text('Subtotal') . qq|</th>
854 <td align="right">$form->{invsubtotal}</td>
860 if ($form->{taxincluded}) {
861 foreach $item (split / /, $form->{taxaccounts}) {
862 if ($form->{"${item}_base"}) {
863 $form->{"${item}_total"} =
865 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
866 (1 + $form->{"${item}_rate"})
869 $form->{"${item}_netto"} =
871 ($form->{"${item}_base"} - $form->{"${item}_total"}),
873 $form->{"${item}_total"} =
874 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
875 $form->{"${item}_netto"} =
876 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
880 <th align="right">Enthaltene $form->{"${item}_description"} |
881 . $form->{"${item}_rate"} * 100 .qq|%</th>
882 <td align="right">$form->{"${item}_total"}</td>
885 <th align="right">Nettobetrag</th>
886 <td align="right">$form->{"${item}_netto"}</td>
894 $form->{oldinvtotal} = $form->{invtotal};
896 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
906 <th align="left">| . $locale->text('Notes') . qq|</th>
907 <th align="left">| . $locale->text('Internal Notes') . qq|</th>
908 <th align="right">| . $locale->text('Payment Terms') . qq|</th>
913 <td><select name="payment_id" onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
918 <td align="right" width="100%">
924 <th align="right">| . $locale->text('Total') . qq|</th>
925 <td align="right">$form->{invtotal}</td>
937 <td><hr size="3" noshade></td>
940 <th class="listtop" align="left">Dokumente im Webdav-Repository</th>
943 <td align="left" width="30%"><b>Dateiname</b></td>
944 <td align="left" width="70%"><b>Webdavlink</b></td>
946 foreach $file (keys %{ $form->{WEBDAV} }) {
949 <td align="left">$file</td>
950 <td align="left"><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
961 if ($form->{type} eq "credit_note") {
966 <tr class="listheading">
967 <th colspan="6" class="listheading">|
968 . $locale->text('Payments') . qq|</th>
976 <tr class="listheading">
977 <th colspan="6" class="listheading">|
978 . $locale->text('Incoming Payments') . qq|</th>
983 if ($form->{currency} eq $form->{defaultcurrency}) {
984 @column_index = qw(datepaid source memo paid AR_paid);
986 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
989 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
990 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
991 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
992 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
993 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
994 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
999 map { print "$column_data{$_}\n" } @column_index;
1006 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1007 for $i (1 .. $form->{paidaccounts}) {
1012 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1013 $form->{"selectAR_paid_$i"} =~
1014 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1017 $totalpaid += $form->{"paid_$i"};
1018 if ($form->{"paid_$i"}) {
1019 $form->{"paid_$i"} =
1020 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1022 $form->{"exchangerate_$i"} =
1023 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1025 $exchangerate = qq| |;
1026 if ($form->{currency} ne $form->{defaultcurrency}) {
1027 if ($form->{"forex_$i"}) {
1028 $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
1030 $exchangerate = qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
1034 $exchangerate .= qq|<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">|;
1036 $column_data{"paid_$i"} =
1037 qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}"></td>|;
1038 $column_data{"exchangerate_$i"} = qq|<td align="center">$exchangerate</td>|;
1039 $column_data{"AR_paid_$i"} =
1040 qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1041 $column_data{"datepaid_$i"} =
1042 qq|<td align="center"><input id="datepaid_$i" name="datepaid_$i" size="11" title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
1043 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1044 $column_data{"source_$i"} =
1045 qq|<td align=center><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
1046 $column_data{"memo_$i"} =
1047 qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
1049 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1052 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1055 map({ print($cgi->hidden("-name" => $_, "-value" => $form->{$_})); } qw(paidaccounts selectAR_paid oldinvtotal));
1056 print qq|<input type="hidden" name="oldtotalpaid" value="$totalpaid">
1061 <td><hr size="3" noshade></td>
1075 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1076 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1079 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar");
1082 <input class="submit" type="submit" accesskey="u" name="action" id="update_button" value="|
1083 . $locale->text('Update') . qq|">
1084 <input class="submit" type="submit" name="action" value="|
1085 . $locale->text('Ship to') . qq|">
1086 <input class="submit" type="submit" name="action" value="|
1087 . $locale->text('Print') . qq|">
1088 <input class="submit" type="submit" name="action" value="|
1089 . $locale->text('E-mail') . qq|"> |;
1090 print qq|<input class="submit" type="submit" name="action" value="|
1091 . $locale->text('Storno') . qq|"> | if ($show_storno);
1092 print qq|<input class="submit" type="submit" name="action" value="|
1093 . $locale->text('Post Payment') . qq|">
1095 print qq|<input class="submit" type="submit" name="action" value="|
1096 . $locale->text('Use As Template') . qq|">
1098 if ($form->{id} && !($form->{type} eq "credit_note")) {
1100 <input class="submit" type="submit" name="action" value="|
1101 . $locale->text('Credit Note') . qq|">
1104 if ($form->{radier}) {
1106 <input class="submit" type="submit" name="action" value="|
1107 . $locale->text('Delete') . qq|">
1112 if ($invdate > $closedto) {
1114 <input class="submit" type="submit" name="action" value="|
1115 . $locale->text('Order') . qq|">
1120 if ($invdate > $closedto) {
1121 print qq|<input class="submit" type="submit" name="action" id="update_button" value="|
1122 . $locale->text('Update') . qq|">
1123 <input class="submit" type="submit" name="action" value="|
1124 . $locale->text('Ship to') . qq|">
1125 <input class="submit" type="submit" name="action" value="|
1126 . $locale->text('Preview') . qq|">
1127 <input class="submit" type="submit" name="action" value="|
1128 . $locale->text('E-mail') . qq|">
1129 <input class="submit" type="submit" name="action" value="|
1130 . $locale->text('Print and Post') . qq|">
1131 <input class="submit" type="submit" name="action" value="|
1132 . $locale->text('Post') . qq|"> | .
1133 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
1134 '-class' => 'submit'));
1138 # button for saving history
1139 if($form->{id} ne "") {
1141 <input type="button" class="submit" onclick="set_history_window(|
1143 . qq|);" name="history" id="history" value="|
1144 . $locale->text('history')
1147 # /button for saving history
1150 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1153 <input type="hidden" name="rowcount" value="$form->{rowcount}">
1155 $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
1156 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1157 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1158 map({ print $cgi->hidden("-name" => $_ , "-value" => $form->{$_});} qw(path login password));
1167 $lxdebug->leave_sub();
1171 $lxdebug->enter_sub();
1173 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1174 qw(exchangerate creditlimit creditremaining);
1175 if ($form->{second_run}) {
1176 $form->{print_and_post} = 0;
1179 $form->{update} = 1;
1181 &check_name(customer);
1183 $form->{exchangerate} = $exchangerate
1187 $form->check_exchangerate(
1188 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
1191 for $i (1 .. $form->{paidaccounts}) {
1192 if ($form->{"paid_$i"}) {
1194 $form->{"${_}_$i"} =
1195 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1196 } qw(paid exchangerate);
1198 $form->{"exchangerate_$i"} = $exchangerate
1200 $form->{"forex_$i"} = (
1202 $form->check_exchangerate(
1203 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
1208 $i = $form->{rowcount};
1209 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1211 # if last row empty, check the form otherwise retrieve new item
1212 if ( ($form->{"partnumber_$i"} eq "")
1213 && ($form->{"description_$i"} eq "")
1214 && ($form->{"partsgroup_$i"} eq "")) {
1216 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1221 IS->retrieve_item(\%myconfig, \%$form);
1223 $rows = scalar @{ $form->{item_list} };
1225 $form->{"discount_$i"} =
1226 $form->format_amount(\%myconfig, $form->{discount} * 100);
1229 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1238 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1240 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1241 qw(partnumber description unit);
1242 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1243 keys %{ $form->{item_list}[0] };
1244 if ($form->{"part_payment_id_$i"} ne "") {
1245 $form->{payment_id} = $form->{"part_payment_id_$i"};
1248 if ($form->{"not_discountable_$i"}) {
1249 $form->{"discount_$i"} = 0;
1252 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1253 ($dec) = ($s =~ /\.(\d+)/);
1255 $decimalplaces = ($dec > 2) ? $dec : 2;
1258 $form->{"sellprice_$i"} = $sellprice;
1261 # if there is an exchange rate adjust sellprice
1262 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1263 $form->{"sellprice_$i"} /= $exchangerate;
1266 $form->{"listprice_$i"} /= $exchangerate;
1269 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1270 (1 - $form->{"discount_$i"} / 100);
1271 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1272 map { $form->{"${_}_base"} += $amount }
1273 (split / /, $form->{"taxaccounts_$i"});
1274 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1275 split / /, $form->{"taxaccounts_$i"}
1276 if !$form->{taxincluded};
1278 $form->{creditremaining} -= $amount;
1281 $form->{"${_}_$i"} =
1282 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
1284 } qw(sellprice listprice);
1287 $form->format_amount(\%myconfig, $form->{"qty_$i"});
1290 if ($form->{"inventory_accno_$i"} ne "") {
1291 $form->{"lizenzen_$i"} = qq|<option></option>|;
1292 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1293 $form->{"lizenzen_$i"} .=
1294 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1296 $form->{"lizenzen_$i"} .=
1297 qq|<option value=-1>Neue Lizenz</option>|;
1301 # get pricegroups for parts
1302 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1304 # build up html code for prices_$i
1305 &set_pricegroup($i);
1312 # ok, so this is a new part
1313 # ask if it is a part or service item
1315 if ( $form->{"partsgroup_$i"}
1316 && ($form->{"partsnumber_$i"} eq "")
1317 && ($form->{"description_$i"} eq "")) {
1318 $form->{rowcount}--;
1319 $form->{"discount_$i"} = "";
1323 $form->{"id_$i"} = 0;
1324 $form->{"unit_$i"} = $locale->text('ea');
1331 $lxdebug->leave_sub();
1335 $lxdebug->enter_sub();
1336 for $i (1 .. $form->{paidaccounts}) {
1337 if ($form->{"paid_$i"}) {
1338 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1340 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1342 $form->error($locale->text('Cannot post payment for a closed period!'))
1343 if ($datepaid <= $closedto);
1345 if ($form->{currency} ne $form->{defaultcurrency}) {
1346 $form->{"exchangerate_$i"} = $form->{exchangerate}
1347 if ($invdate == $datepaid);
1348 $form->isblank("exchangerate_$i",
1349 $locale->text('Exchangerate for payment missing!'));
1354 ($form->{AR}) = split /--/, $form->{AR};
1355 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1357 $form->redirect($locale->text(' Payment posted!'))
1358 if (IS->post_payment(\%myconfig, \%$form));
1359 $form->error($locale->text('Cannot post payment!'));
1362 $lxdebug->leave_sub();
1366 $lxdebug->enter_sub();
1367 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1368 $form->isblank("customer", $locale->text('Customer missing!'));
1370 # if oldcustomer ne customer redo form
1371 if (&check_name(customer)) {
1375 if ($form->{second_run}) {
1376 $form->{print_and_post} = 0;
1381 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1382 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1384 $form->error($locale->text('Cannot post invoice for a closed period!'))
1385 if ($invdate <= $closedto);
1387 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1388 if ($form->{currency} ne $form->{defaultcurrency});
1390 for $i (1 .. $form->{paidaccounts}) {
1391 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1392 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1394 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1396 $form->error($locale->text('Cannot post payment for a closed period!'))
1397 if ($datepaid <= $closedto);
1399 if ($form->{currency} ne $form->{defaultcurrency}) {
1400 $form->{"exchangerate_$i"} = $form->{exchangerate}
1401 if ($invdate == $datepaid);
1402 $form->isblank("exchangerate_$i",
1403 $locale->text('Exchangerate for payment missing!'));
1408 ($form->{AR}) = split /--/, $form->{AR};
1409 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1411 $form->{label} = $locale->text('Invoice');
1413 $form->{id} = 0 if $form->{postasnew};
1415 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1416 if ($form->{postasnew}) {
1417 if ($form->{type} eq "credit_note") {
1418 undef($form->{cnnumber});
1420 undef($form->{invnumber});
1425 $form->error($locale->text('Cannot post invoice!'))
1426 unless IS->post_invoice(\%myconfig, \%$form);
1427 remove_draft() if $form->{remove_draft};
1429 if(!exists $form->{addition}) {
1430 $form->{addition} = $print_post ? "PRINTED AND POSTED" :
1431 $form->{storno} ? "STORNO" :
1433 $form->save_history($form->dbconnect(\%myconfig));
1436 $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1439 $lxdebug->leave_sub();
1442 sub print_and_post {
1443 $lxdebug->enter_sub();
1445 $old_form = new Form;
1447 $form->{print_and_post} = 1;
1451 $lxdebug->leave_sub();
1455 sub use_as_template {
1456 $lxdebug->enter_sub();
1458 map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
1459 $form->{paidaccounts} = 1;
1460 $form->{rowcount}--;
1461 $form->{invdate} = $form->current_date(\%myconfig);
1464 $lxdebug->leave_sub();
1468 $lxdebug->enter_sub();
1470 if ($form->{storno}) {
1471 $form->error($locale->text('Cannot storno storno invoice!'));
1474 if (IS->has_storno(\%myconfig, $form, "ar")) {
1475 $form->error($locale->text("Invoice has already been storno'd!"));
1478 map({ my $key = $_; delete($form->{$key})
1479 unless (grep({ $key eq $_ } qw(path login password id type))); }
1486 $form->{storno_id} = $form->{id};
1487 $form->{storno} = 1;
1489 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1492 $lxdebug->leave_sub();
1497 $lxdebug->enter_sub();
1499 $form->{preview} = 1;
1500 $old_form = new Form;
1501 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1502 $old_form->{rowcount}++;
1504 &print_form($old_form);
1505 $lxdebug->leave_sub();
1510 $lxdebug->enter_sub();
1511 if ($form->{second_run}) {
1512 $form->{print_and_post} = 0;
1519 <form method="post" action="$form->{script}">
1522 # delete action variable
1523 map { delete $form->{$_} } qw(action header);
1525 foreach $key (keys %$form) {
1526 $form->{$key} =~ s/\"/"/g;
1527 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1531 <h2 class="confirm">| . $locale->text('Confirm!') . qq|</h2>
1534 . $locale->text('Are you sure you want to delete Invoice Number')
1535 . qq| $form->{invnumber}
1539 <input name="action" class="submit" type="submit" value="|
1540 . $locale->text('Yes') . qq|">
1544 $lxdebug->leave_sub();
1548 $lxdebug->enter_sub();
1550 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1552 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1555 $form->{rowcount}--;
1556 $form->{shipto} = 1;
1559 $form->{title} = $locale->text('Add Credit Note');
1560 $form->{script} = 'is.pl';
1565 # bo creates the id, reset it
1566 map { delete $form->{$_} }
1567 qw(id invnumber subject message cc bcc printed emailed queued);
1568 $form->{ $form->{vc} } =~ s/--.*//g;
1569 $form->{type} = "credit_note";
1572 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1574 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1575 qw(creditlimit creditremaining);
1577 $currency = $form->{currency};
1580 $form->{currency} = $currency;
1581 $form->{exchangerate} = "";
1582 $form->{forex} = "";
1583 $form->{exchangerate} = $exchangerate
1587 $form->check_exchangerate(
1588 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1591 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1598 $lxdebug->leave_sub();
1602 $lxdebug->enter_sub();
1603 if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
1604 # saving the history
1605 if(!exists $form->{addition}) {
1606 $form->{addition} = "DELETED";
1607 $form->save_history($form->dbconnect(\%myconfig));
1609 # /saving the history
1610 $form->redirect($locale->text('Invoice deleted!'));
1612 $form->error($locale->text('Cannot delete invoice!'));
1614 $lxdebug->leave_sub();
1618 $lxdebug->enter_sub();
1626 $lxdebug->leave_sub();