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";
46 $lxdebug->enter_sub();
48 if ($form->{type} eq "credit_note") {
49 $form->{title} = $locale->text('Add Credit Note');
51 if ($form->{storno}) {
52 $form->{title} = $locale->text('Add Storno Credit Note');
55 $form->{title} = $locale->text('Add Sales Invoice');
61 "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
62 unless $form->{callback};
64 $form{jsscript} = "date";
66 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
68 $form->error("Access Denied");
74 $lxdebug->leave_sub();
78 $lxdebug->enter_sub();
81 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
83 $form->error("Access Denied");
86 if ($form->{print_and_post}) {
87 $form->{action} = "print";
88 $form->{resubmit} = 1;
89 $language_id = $form->{language_id};
90 $printer_id = $form->{printer_id};
94 if ($form->{print_and_post}) {
95 $form->{language_id} = $language_id;
96 $form->{printer_id} = $printer_id;
101 $lxdebug->leave_sub();
105 $lxdebug->enter_sub();
107 $form->{vc} = 'customer';
110 $form->{webdav} = $webdav;
111 $form->{lizenzen} = $lizenzen;
113 $form->create_links("AR", \%myconfig, "customer");
115 if ($form->{all_customer}) {
116 unless ($form->{customer_id}) {
117 $form->{customer_id} = $form->{all_customer}->[0]->{id};
121 if ($form->{payment_id}) {
122 $payment_id = $form->{payment_id};
124 if ($form->{language_id}) {
125 $language_id = $form->{language_id};
127 if ($form->{taxzone_id}) {
128 $taxzone_id = $form->{taxzone_id};
133 if ($form->{shipto_id}) {
134 $shipto_id = $form->{shipto_id};
137 $cp_id = $form->{cp_id};
138 IS->get_customer(\%myconfig, \%$form);
140 #quote all_customer Bug 133
141 foreach $ref (@{ $form->{all_customer} }) {
142 $ref->{name} = $form->quote($ref->{name});
147 IS->retrieve_invoice(\%myconfig, \%$form);
148 $form->{cp_id} = $cp_id;
151 $form->{payment_id} = $payment_id;
154 $form->{language_id} = $language_id;
157 $form->{taxzone_id} = $taxzone_id;
160 $form->{shipto_id} = $shipto_id;
164 @curr = split(/:/, $form->{currencies});
166 $form->{defaultcurrency} = $curr[0];
168 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
170 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
172 if (@{ $form->{all_customer} }) {
173 $form->{customer} = "$form->{customer}--$form->{customer_id}";
174 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
175 (@{ $form->{all_customer} });
179 if ($form->{all_departments}) {
180 $form->{selectdepartment} = "<option>\n";
181 $form->{department} = "$form->{department}--$form->{department_id}";
184 $form->{selectdepartment} .=
185 "<option>$_->{description}--$_->{id}\n"
186 } (@{ $form->{all_departments} });
189 $form->{employee} = "$form->{employee}--$form->{employee_id}";
192 if ($form->{all_employees}) {
193 $form->{selectemployee} = "";
194 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
195 (@{ $form->{all_employees} });
199 $form->{forex} = $form->{exchangerate};
200 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
202 foreach $key (keys %{ $form->{AR_links} }) {
203 foreach $ref (@{ $form->{AR_links}{$key} }) {
204 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
207 if ($key eq "AR_paid") {
208 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
209 $form->{"AR_paid_$i"} =
210 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
213 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
214 $form->{"datepaid_$i"} =
215 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
216 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
217 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
218 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
219 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
221 $form->{paidaccounts} = $i;
225 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
230 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
232 $form->{AR} = $form->{AR_1} unless $form->{id};
235 ($form->datetonum($form->{invdate}, \%myconfig) <=
236 $form->datetonum($form->{closedto}, \%myconfig));
238 $lxdebug->leave_sub();
241 sub prepare_invoice {
242 $lxdebug->enter_sub();
244 if ($form->{type} eq "credit_note") {
245 $form->{type} = "credit_note";
246 $form->{formname} = "credit_note";
248 $form->{type} = "invoice";
249 $form->{formname} = "invoice";
254 map { $form->{$_} =~ s/\"/"/g }
255 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
257 # # get pricegroups for parts
258 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
262 foreach $ref (@{ $form->{invoice_details} }) {
265 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
266 $form->{"discount_$i"} =
267 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
268 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
270 $decimalplaces = ($dec > 2) ? $dec : 2;
272 $form->{"sellprice_$i"} =
273 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
276 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
277 $dec_qty = length $dec_qty;
280 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
282 map { $form->{"${_}_$i"} =~ s/\"/"/g }
283 qw(partnumber description unit partnotes);
284 $form->{rowcount} = $i;
288 $lxdebug->leave_sub();
292 $lxdebug->enter_sub();
296 if ($form->{type} eq "credit_note") {
297 $form->{title} = $locale->text('Edit Credit Note');
299 if ($form->{storno}) {
300 $form->{title} = $locale->text('Edit Storno Credit Note');
303 $form->{title} = $locale->text('Edit Sales Invoice');
305 if ($form->{storno}) {
306 $form->{title} = $locale->text('Edit Storno Invoice');
312 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
314 $payment = qq|<option value=""></option>|;
315 foreach $item (@{ $form->{payment_terms} }) {
316 if ($form->{payment_id} eq $item->{id}) {
317 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
319 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
323 my $set_duedate_url =
324 "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=set_duedate";
326 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
327 push(@ { $form->{AJAX} }, $pjx);
329 if (@{ $form->{TAXZONE} }) {
330 $form->{selecttaxzone} = "";
331 foreach $item (@{ $form->{TAXZONE} }) {
332 if ($item->{id} == $form->{taxzone_id}) {
333 $form->{selecttaxzone} .=
334 "<option value=$item->{id} selected>" . H($item->{description}) .
337 $form->{selecttaxzone} .=
338 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
343 $form->{selecttaxzone} =~ s/ selected//g;
344 if ($form->{taxzone_id} ne "") {
345 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
351 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
352 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
353 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
356 $form->get_lists("contacts" => "ALL_CONTACTS",
357 "shipto" => "ALL_SHIPTO");
359 my (%labels, @values);
360 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
361 push(@values, $item->{"cp_id"});
362 $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
363 ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
366 $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
367 '-labels' => \%labels, '-default' => $form->{"cp_id"});
371 foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
372 push(@values, $item->{"shipto_id"});
373 $labels{$item->{"shipto_id"}} =
374 $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
378 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
380 $cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
381 '-labels' => \%labels, '-default' => $form->{"shipto_id"})
384 # set option selected
385 foreach $item (qw(AR customer currency department employee)) {
386 $form->{"select$item"} =~ s/ selected//;
387 $form->{"select$item"} =~
388 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
391 #quote customer Bug 133
392 $form->{selectcustomer} = $form->quote($form->{selectcustomer});
394 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
400 $form->{exchangerate} =
401 $form->format_amount(\%myconfig, $form->{exchangerate});
403 $form->{creditlimit} =
404 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
405 $form->{creditremaining} =
406 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
409 if ($form->{currency} ne $form->{defaultcurrency}) {
410 if ($form->{forex}) {
413 . $locale->text('Exchangerate')
414 . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
418 . $locale->text('Exchangerate')
419 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
423 <input type=hidden name=forex value=$form->{forex}>
427 ($form->{selectcustomer})
428 ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
429 : qq|<input name=customer value="$form->{customer}" size=35>|;
433 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
434 <td colspan=3><select name=department>$form->{selectdepartment}</select>
435 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
438 | if $form->{selectdepartment};
440 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
442 if ($form->{business}) {
445 <th align=right>| . $locale->text('Business') . qq|</th>
446 <td>$form->{business}</td>
447 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
449 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
455 if ($form->{max_dunning_level}) {
461 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
462 <td><b>$form->{max_dunning_level}</b></td>
463 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
465 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
474 $form->{fokus} = "invoice.customer";
476 # use JavaScript Calendar or not
477 $form->{jsscript} = $jscalendar;
479 if ($form->{type} eq "credit_note") {
480 if ($form->{jsscript}) {
482 # with JavaScript Calendar
484 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
485 <td><input type=button name=invdate id="trigger1" value=|
486 . $locale->text('button') . qq|></td>
491 Form->write_trigger(\%myconfig, "1",
496 # without JavaScript Calendar
498 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
500 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
503 if ($form->{jsscript}) {
505 # with JavaScript Calendar
507 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
508 <td><input type=button name=invdate id="trigger1" value=|
509 . $locale->text('button') . qq|></td>
512 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
513 <td width="4"><input type=button name=duedate id="trigger2" value=|
514 . $locale->text('button') . qq|></td></td>
517 <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
518 <td width="4"><input type=button name=deliverydate id="trigger3" value=|
519 . $locale->text('button') . qq|></td></td>
524 Form->write_trigger(\%myconfig, "3",
526 "trigger1", "duedate",
528 "deliverydate", "BL",
532 # without JavaScript Calendar
534 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
536 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
539 if ($form->{resubmit} && ($form->{format} eq "html")) {
541 qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
542 } elsif ($form->{resubmit}) {
543 $onload = qq|document.invoice.submit()|;
548 $credittext = $locale->text('Credit Limit exceeded!!!');
549 if ($creditwarning) {
550 $onload = qq|alert('$credittext')|;
553 $form->{"javascript"} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
556 $form->write_trigger(\%myconfig, 2,
557 "orddate", "BL", "trigger_orddate",
558 "quodate", "BL", "trigger_quodate");
563 <body onLoad="$onload">
564 <script type="text/javascript" src="js/common.js"></script>
565 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
566 <script type="text/javascript" src="js/vendor_selection.js"></script>
567 <script type="text/javascript" src="js/calculate_qty.js"></script>
569 <form method=post name="invoice" action=$form->{script}>
572 <input type=hidden name=id value=$form->{id}>
573 <input type=hidden name=action value=$form->{action}>
575 <input type=hidden name=type value=$form->{type}>
576 <input type=hidden name=media value=$form->{media}>
577 <input type=hidden name=format value=$form->{format}>
579 <input type=hidden name=queued value="$form->{queued}">
580 <input type=hidden name=printed value="$form->{printed}">
581 <input type=hidden name=emailed value="$form->{emailed}">
583 <input type=hidden name=title value="$form->{title}">
584 <input type=hidden name=vc value=$form->{vc}>
586 <input type=hidden name=discount value=$form->{discount}>
587 <input type=hidden name=creditlimit value=$form->{creditlimit}>
588 <input type=hidden name=creditremaining value=$form->{creditremaining}>
590 <input type=hidden name=tradediscount value=$form->{tradediscount}>
591 <input type=hidden name=business value=$form->{business}>
593 <input type=hidden name=closedto value=$form->{closedto}>
594 <input type=hidden name=locked value=$form->{locked}>
596 <input type=hidden name=shipped value=$form->{shipped}>
597 <input type=hidden name=lizenzen value=$lizenzen>
598 <input type=hidden name=storno value=$form->{storno}>
599 <input type=hidden name=storno_id value=$form->{storno_id}>
605 <th class=listtop>$form->{title}</th>
615 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
616 <td colspan=3>$customer</td>
617 <input type=hidden name=customer_klass value=$form->{customer_klass}>
618 <input type=hidden name=customer_id value=$form->{customer_id}>
619 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
620 <th align=richt nowrap>|
621 . $locale->text('Contact Person') . qq|</th>
622 <td colspan=3>$contact</td>
629 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
630 <td>$form->{creditlimit}</td>
632 <th nowrap>| . $locale->text('Remaining') . qq|</th>
633 <td class="plus$n">$form->{creditremaining}</td>
642 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
643 <td colspan=3><select name=AR style="width:280px;">$form->{selectAR}</select></td>
644 <input type=hidden name=selectAR value="$form->{selectAR}">
649 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
650 <td><select name=currency>$form->{selectcurrency}</select></td>
651 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
652 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
653 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
654 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
658 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
659 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
662 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
663 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
670 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
672 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
673 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
677 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
679 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
680 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
690 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
691 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
692 <input type=hidden name=selectemployee value="$form->{selectemployee}">
695 if ($form->{type} eq "credit_note") {
697 <th align=right nowrap>| . $locale->text('Credit Note Number') . qq|</th>
698 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
701 <th align=right>| . $locale->text('Credit Note Date') . qq|</th>
706 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
707 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
710 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
714 <th align=right>| . $locale->text('Due Date') . qq|</th>
718 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
723 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
724 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
727 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
728 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|"></td>
729 <td><input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
732 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
733 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
736 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
737 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|"></td>
738 <td><input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
741 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
742 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
757 <!-- shipto are in hidden variables -->
759 <input type=hidden name=shiptoname value="$form->{shiptoname}">
760 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
761 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
762 <input type=hidden name=shiptocity value="$form->{shiptocity}">
763 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
764 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
765 <input type=hidden name=shiptophone value="$form->{shiptophone}">
766 <input type=hidden name=shiptofax value="$form->{shiptofax}">
767 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
769 <!-- email variables -->
770 <input type=hidden name=message value="$form->{message}">
771 <input type=hidden name=email value="$form->{email}">
772 <input type=hidden name=subject value="$form->{subject}">
773 <input type=hidden name=cc value="$form->{cc}">
774 <input type=hidden name=bcc value="$form->{bcc}">
775 <input type=hidden name=webdav value=$webdav>
776 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
779 foreach $item (split / /, $form->{taxaccounts}) {
781 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
782 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
783 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
786 $lxdebug->leave_sub();
790 $lxdebug->enter_sub();
792 $form->{invtotal} = $form->{invsubtotal};
794 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
797 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
800 $rows = ($rows > $introws) ? $rows : $introws;
802 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
804 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
806 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
809 if ($form->{taxaccounts}) {
811 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
812 . $locale->text('Tax Included') . qq|</b><br><br>|;
815 if (!$form->{taxincluded}) {
817 foreach $item (split / /, $form->{taxaccounts}) {
818 if ($form->{"${item}_base"}) {
819 $form->{"${item}_total"} =
821 $form->{"${item}_base"} * $form->{"${item}_rate"},
823 $form->{invtotal} += $form->{"${item}_total"};
824 $form->{"${item}_total"} =
825 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
829 <th align=right>$form->{"${item}_description"}</th>
830 <td align=right>$form->{"${item}_total"}</td>
836 $form->{invsubtotal} =
837 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
841 <th align=right>| . $locale->text('Subtotal') . qq|</th>
842 <td align=right>$form->{invsubtotal}</td>
848 if ($form->{taxincluded}) {
849 foreach $item (split / /, $form->{taxaccounts}) {
850 if ($form->{"${item}_base"}) {
851 $form->{"${item}_total"} =
853 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
854 (1 + $form->{"${item}_rate"})
857 $form->{"${item}_netto"} =
859 ($form->{"${item}_base"} - $form->{"${item}_total"}),
861 $form->{"${item}_total"} =
862 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
863 $form->{"${item}_netto"} =
864 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
868 <th align=right>Enthaltene $form->{"${item}_description"}</th>
869 <td align=right>$form->{"${item}_total"}</td>
872 <th align=right>Nettobetrag</th>
873 <td align=right>$form->{"${item}_netto"}</td>
881 $form->{oldinvtotal} = $form->{invtotal};
883 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
893 <th align=left>| . $locale->text('Notes') . qq|</th>
894 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
895 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
900 <td><select name=payment_id onChange="if (this.value) set_duedate(['payment_id__' + this.value],['duedate'])">$payment
905 <td align=right width=100%>
911 <th align=right>| . $locale->text('Total') . qq|</th>
912 <td align=right>$form->{invtotal}</td>
924 <td><hr size=3 noshade></td>
927 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
930 <td align=left width=30%><b>Dateiname</b></td>
931 <td align=left width=70%><b>Webdavlink</b></td>
933 foreach $file (keys %{ $form->{WEBDAV} }) {
936 <td align=left>$file</td>
937 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
948 if ($form->{type} eq "credit_note") {
953 <tr class=listheading>
954 <th colspan=6 class=listheading>|
955 . $locale->text('Payments') . qq|</th>
963 <tr class=listheading>
964 <th colspan=6 class=listheading>|
965 . $locale->text('Incoming Payments') . qq|</th>
970 if ($form->{currency} eq $form->{defaultcurrency}) {
971 @column_index = qw(datepaid source memo paid AR_paid);
973 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
976 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
977 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
978 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
979 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
980 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
981 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
986 map { print "$column_data{$_}\n" } @column_index;
993 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
994 for $i (1 .. $form->{paidaccounts}) {
999 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1000 $form->{"selectAR_paid_$i"} =~
1001 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1004 $totalpaid += $form->{"paid_$i"};
1005 if ($form->{"paid_$i"}) {
1006 $form->{"paid_$i"} =
1007 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1009 $form->{"exchangerate_$i"} =
1010 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1012 $exchangerate = qq| |;
1013 if ($form->{currency} ne $form->{defaultcurrency}) {
1014 if ($form->{"forex_$i"}) {
1016 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
1019 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
1023 $exchangerate .= qq|
1024 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
1027 $column_data{"paid_$i"} =
1028 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
1029 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
1030 $column_data{"AR_paid_$i"} =
1031 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1032 $column_data{"datepaid_$i"} =
1033 qq|<td align=center><input id="datepaid_$i" name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
1034 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1035 $column_data{"source_$i"} =
1036 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
1037 $column_data{"memo_$i"} =
1038 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
1040 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1043 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1047 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
1048 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
1049 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1050 <input type=hidden name=oldtotalpaid value=$totalpaid>
1055 <td><hr size=3 noshade></td>
1069 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1070 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1074 <input class=submit type=submit accesskey="u" name=action id=update_button value="|
1075 . $locale->text('Update') . qq|">
1076 <input class=submit type=submit name=action value="|
1077 . $locale->text('Ship to') . qq|">
1078 <input class=submit type=submit name=action value="|
1079 . $locale->text('Print') . qq|">
1080 <input class=submit type=submit name=action value="|
1081 . $locale->text('E-mail') . qq|">|;
1082 print qq|<input class=submit type=submit name=action value="|
1083 . $locale->text('Storno') . qq|">| unless ($form->{storno});
1084 print qq|<input class=submit type=submit name=action value="|
1085 . $locale->text('Post Payment') . qq|">
1087 print qq|<input class=submit type=submit name=action value="|
1088 . $locale->text('Use As Template') . qq|">
1090 if ($form->{id} && !($form->{type} eq "credit_note")) {
1092 <input class=submit type=submit name=action value="|
1093 . $locale->text('Credit Note') . qq|">
1096 if ($form->{radier}) {
1098 <input class=submit type=submit name=action value="|
1099 . $locale->text('Delete') . qq|">
1104 if ($invdate > $closedto) {
1106 <input class=submit type=submit name=action value="|
1107 . $locale->text('Order') . qq|">
1112 if ($invdate > $closedto) {
1113 print qq|<input class=submit type=submit name=action id=update_button value="|
1114 . $locale->text('Update') . qq|">
1115 <input class=submit type=submit name=action value="|
1116 . $locale->text('Ship to') . qq|">
1117 <input class=submit type=submit name=action value="|
1118 . $locale->text('Preview') . qq|">
1119 <input class=submit type=submit name=action value="|
1120 . $locale->text('E-mail') . qq|">
1121 <input class=submit type=submit name=action value="|
1122 . $locale->text('Print and Post') . qq|">
1123 <input class=submit type=submit name=action value="|
1124 . $locale->text('Post') . qq|">|;
1128 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1131 <input type=hidden name=rowcount value=$form->{rowcount}>
1133 <input name=callback type=hidden value="$form->{callback}">
1135 <input type=hidden name=path value=$form->{path}>
1136 <input type=hidden name=login value=$form->{login}>
1137 <input type=hidden name=password value=$form->{password}>
1146 $lxdebug->leave_sub();
1150 $lxdebug->enter_sub();
1152 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1153 qw(exchangerate creditlimit creditremaining);
1154 if ($form->{second_run}) {
1155 $form->{print_and_post} = 0;
1158 $form->{update} = 1;
1160 &check_name(customer);
1164 $form->{exchangerate} = $exchangerate
1168 $form->check_exchangerate(
1169 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
1172 for $i (1 .. $form->{paidaccounts}) {
1173 if ($form->{"paid_$i"}) {
1175 $form->{"${_}_$i"} =
1176 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1177 } qw(paid exchangerate);
1179 $form->{"exchangerate_$i"} = $exchangerate
1181 $form->{"forex_$i"} = (
1183 $form->check_exchangerate(
1184 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
1189 $i = $form->{rowcount};
1190 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1192 # if last row empty, check the form otherwise retrieve new item
1193 if ( ($form->{"partnumber_$i"} eq "")
1194 && ($form->{"description_$i"} eq "")
1195 && ($form->{"partsgroup_$i"} eq "")) {
1197 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1202 IS->retrieve_item(\%myconfig, \%$form);
1204 $rows = scalar @{ $form->{item_list} };
1206 $form->{"discount_$i"} =
1207 $form->format_amount(\%myconfig, $form->{discount} * 100);
1210 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1219 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1221 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1222 qw(partnumber description unit);
1223 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1224 keys %{ $form->{item_list}[0] };
1225 if ($form->{"part_payment_id_$i"} ne "") {
1226 $form->{payment_id} = $form->{"part_payment_id_$i"};
1229 if ($form->{"not_discountable_$i"}) {
1230 $form->{"discount_$i"} = 0;
1233 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1234 ($dec) = ($s =~ /\.(\d+)/);
1236 $decimalplaces = ($dec > 2) ? $dec : 2;
1239 $form->{"sellprice_$i"} = $sellprice;
1242 # if there is an exchange rate adjust sellprice
1243 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1244 $form->{"sellprice_$i"} /= $exchangerate;
1247 $form->{"listprice_$i"} /= $exchangerate;
1250 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1251 (1 - $form->{"discount_$i"} / 100);
1252 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1253 map { $form->{"${_}_base"} += $amount }
1254 (split / /, $form->{"taxaccounts_$i"});
1255 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1256 split / /, $form->{"taxaccounts_$i"}
1257 if !$form->{taxincluded};
1259 $form->{creditremaining} -= $amount;
1262 $form->{"${_}_$i"} =
1263 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
1265 } qw(sellprice listprice);
1268 $form->format_amount(\%myconfig, $form->{"qty_$i"});
1271 if ($form->{"inventory_accno_$i"} ne "") {
1272 $form->{"lizenzen_$i"} = qq|<option></option>|;
1273 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1274 $form->{"lizenzen_$i"} .=
1275 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1277 $form->{"lizenzen_$i"} .=
1278 qq|<option value=-1>Neue Lizenz</option>|;
1282 # get pricegroups for parts
1283 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1285 # build up html code for prices_$i
1286 &set_pricegroup($i);
1293 # ok, so this is a new part
1294 # ask if it is a part or service item
1296 if ( $form->{"partsgroup_$i"}
1297 && ($form->{"partsnumber_$i"} eq "")
1298 && ($form->{"description_$i"} eq "")) {
1299 $form->{rowcount}--;
1300 $form->{"discount_$i"} = "";
1304 $form->{"id_$i"} = 0;
1305 $form->{"unit_$i"} = $locale->text('ea');
1312 $lxdebug->leave_sub();
1315 $lxdebug->enter_sub();
1316 for $i (1 .. $form->{paidaccounts}) {
1317 if ($form->{"paid_$i"}) {
1318 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1320 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1322 $form->error($locale->text('Cannot post payment for a closed period!'))
1323 if ($datepaid <= $closedto);
1325 if ($form->{currency} ne $form->{defaultcurrency}) {
1326 $form->{"exchangerate_$i"} = $form->{exchangerate}
1327 if ($invdate == $datepaid);
1328 $form->isblank("exchangerate_$i",
1329 $locale->text('Exchangerate for payment missing!'));
1334 ($form->{AR}) = split /--/, $form->{AR};
1335 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1337 $form->redirect($locale->text(' Payment posted!'))
1338 if (IS->post_payment(\%myconfig, \%$form));
1339 $form->error($locale->text('Cannot post payment!'));
1342 $lxdebug->leave_sub();
1346 $lxdebug->enter_sub();
1347 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1348 $form->isblank("customer", $locale->text('Customer missing!'));
1350 # if oldcustomer ne customer redo form
1351 if (&check_name(customer)) {
1355 if ($form->{second_run}) {
1356 $form->{print_and_post} = 0;
1361 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1362 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1364 $form->error($locale->text('Cannot post invoice for a closed period!'))
1365 if ($invdate <= $closedto);
1367 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1368 if ($form->{currency} ne $form->{defaultcurrency});
1370 for $i (1 .. $form->{paidaccounts}) {
1371 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1372 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1374 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1376 $form->error($locale->text('Cannot post payment for a closed period!'))
1377 if ($datepaid <= $closedto);
1379 if ($form->{currency} ne $form->{defaultcurrency}) {
1380 $form->{"exchangerate_$i"} = $form->{exchangerate}
1381 if ($invdate == $datepaid);
1382 $form->isblank("exchangerate_$i",
1383 $locale->text('Exchangerate for payment missing!'));
1388 ($form->{AR}) = split /--/, $form->{AR};
1389 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1391 $form->{label} = $locale->text('Invoice');
1393 $form->{id} = 0 if $form->{postasnew};
1395 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1396 if (!$form->{invnumber} || $form->{postasnew}) {
1397 if ($form->{type} eq "credit_note") {
1398 $form->{invnumber} = $form->update_defaults(\%myconfig, "cnnumber");
1400 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
1405 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1406 $form->error($locale->text('Cannot post invoice!'));
1410 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1411 if (IS->post_invoice(\%myconfig, \%$form));
1412 $form->error($locale->text('Cannot post invoice!'));
1415 $lxdebug->leave_sub();
1418 sub print_and_post {
1419 $lxdebug->enter_sub();
1421 $old_form = new Form;
1423 $form->{print_and_post} = 1;
1427 $lxdebug->leave_sub();
1431 sub use_as_template {
1432 $lxdebug->enter_sub();
1434 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);
1435 $form->{paidaccounts} = 1;
1436 $form->{rowcount}--;
1437 $form->{invdate} = $form->current_date(\%myconfig);
1440 $lxdebug->leave_sub();
1444 $lxdebug->enter_sub();
1446 if ($form->{storno}) {
1447 $form->error($locale->text('Cannot storno storno invoice!'));
1450 $form->{storno_id} = $form->{id};
1451 $form->{storno} = 1;
1453 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1456 $lxdebug->leave_sub();
1461 $lxdebug->enter_sub();
1463 $form->{preview} = 1;
1464 $old_form = new Form;
1465 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1466 $old_form->{rowcount}++;
1468 &print_form($old_form);
1469 $lxdebug->leave_sub();
1474 $lxdebug->enter_sub();
1475 if ($form->{second_run}) {
1476 $form->{print_and_post} = 0;
1483 <form method=post action=$form->{script}>
1486 # delete action variable
1487 map { delete $form->{$_} } qw(action header);
1489 foreach $key (keys %$form) {
1490 $form->{$key} =~ s/\"/"/g;
1491 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1495 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1498 . $locale->text('Are you sure you want to delete Invoice Number')
1499 . qq| $form->{invnumber}
1503 <input name=action class=submit type=submit value="|
1504 . $locale->text('Yes') . qq|">
1508 $lxdebug->leave_sub();
1512 $lxdebug->enter_sub();
1514 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1516 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1519 $form->{rowcount}--;
1520 $form->{shipto} = 1;
1523 $form->{title} = $locale->text('Add Credit Note');
1524 $form->{script} = 'is.pl';
1529 # bo creates the id, reset it
1530 map { delete $form->{$_} }
1531 qw(id invnumber subject message cc bcc printed emailed queued);
1532 $form->{ $form->{vc} } =~ s/--.*//g;
1533 $form->{type} = "credit_note";
1536 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1538 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1539 qw(creditlimit creditremaining);
1541 $currency = $form->{currency};
1544 $form->{currency} = $currency;
1545 $form->{exchangerate} = "";
1546 $form->{forex} = "";
1547 $form->{exchangerate} = $exchangerate
1551 $form->check_exchangerate(
1552 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1555 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1562 $lxdebug->leave_sub();
1566 $lxdebug->enter_sub();
1568 $form->redirect($locale->text('Invoice deleted!'))
1569 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1570 $form->error($locale->text('Cannot delete invoice!'));
1572 $lxdebug->leave_sub();