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");
72 $form->{format} = "pdf";
76 $lxdebug->leave_sub();
80 $lxdebug->enter_sub();
83 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
85 $form->error("Access Denied");
88 if ($form->{print_and_post}) {
89 $form->{action} = "print";
90 $form->{resubmit} = 1;
91 $language_id = $form->{language_id};
92 $printer_id = $form->{printer_id};
96 if ($form->{print_and_post}) {
97 $form->{language_id} = $language_id;
98 $form->{printer_id} = $printer_id;
103 $lxdebug->leave_sub();
107 $lxdebug->enter_sub();
109 $form->{vc} = 'customer';
112 $form->{webdav} = $webdav;
113 $form->{lizenzen} = $lizenzen;
115 $form->create_links("AR", \%myconfig, "customer");
117 if ($form->{all_customer}) {
118 unless ($form->{customer_id}) {
119 $form->{customer_id} = $form->{all_customer}->[0]->{id};
123 if ($form->{payment_id}) {
124 $payment_id = $form->{payment_id};
126 if ($form->{language_id}) {
127 $language_id = $form->{language_id};
129 if ($form->{taxzone_id}) {
130 $taxzone_id = $form->{taxzone_id};
135 if ($form->{shipto_id}) {
136 $shipto_id = $form->{shipto_id};
139 $cp_id = $form->{cp_id};
140 IS->get_customer(\%myconfig, \%$form);
142 #quote all_customer Bug 133
143 foreach $ref (@{ $form->{all_customer} }) {
144 $ref->{name} = $form->quote($ref->{name});
149 IS->retrieve_invoice(\%myconfig, \%$form);
150 $form->{cp_id} = $cp_id;
153 $form->{payment_id} = $payment_id;
156 $form->{language_id} = $language_id;
159 $form->{taxzone_id} = $taxzone_id;
162 $form->{shipto_id} = $shipto_id;
166 @curr = split(/:/, $form->{currencies});
168 $form->{defaultcurrency} = $curr[0];
170 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
172 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
174 if (@{ $form->{all_customer} }) {
175 $form->{customer} = "$form->{customer}--$form->{customer_id}";
176 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
177 (@{ $form->{all_customer} });
181 if ($form->{all_departments}) {
182 $form->{selectdepartment} = "<option>\n";
183 $form->{department} = "$form->{department}--$form->{department_id}";
186 $form->{selectdepartment} .=
187 "<option>$_->{description}--$_->{id}\n"
188 } (@{ $form->{all_departments} });
191 $form->{employee} = "$form->{employee}--$form->{employee_id}";
194 if ($form->{all_employees}) {
195 $form->{selectemployee} = "";
196 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
197 (@{ $form->{all_employees} });
201 $form->{forex} = $form->{exchangerate};
202 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
204 foreach $key (keys %{ $form->{AR_links} }) {
205 foreach $ref (@{ $form->{AR_links}{$key} }) {
206 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
209 if ($key eq "AR_paid") {
210 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
211 $form->{"AR_paid_$i"} =
212 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
215 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
216 $form->{"datepaid_$i"} =
217 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
218 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
219 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
220 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
221 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
223 $form->{paidaccounts} = $i;
227 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
232 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
234 $form->{AR} = $form->{AR_1} unless $form->{id};
237 ($form->datetonum($form->{invdate}, \%myconfig) <=
238 $form->datetonum($form->{closedto}, \%myconfig));
240 $lxdebug->leave_sub();
243 sub prepare_invoice {
244 $lxdebug->enter_sub();
246 if ($form->{type} eq "credit_note") {
247 $form->{type} = "credit_note";
248 $form->{formname} = "credit_note";
249 $form->{media} = "screen";
251 $form->{type} = "invoice";
252 $form->{formname} = "invoice";
253 $form->{media} = "screen";
258 map { $form->{$_} =~ s/\"/"/g }
259 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
261 # # get pricegroups for parts
262 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
266 foreach $ref (@{ $form->{invoice_details} }) {
269 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
270 $form->{"discount_$i"} =
271 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
272 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
274 $decimalplaces = ($dec > 2) ? $dec : 2;
276 $form->{"sellprice_$i"} =
277 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
280 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
281 $dec_qty = length $dec_qty;
284 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
286 map { $form->{"${_}_$i"} =~ s/\"/"/g }
287 qw(partnumber description unit partnotes);
288 $form->{rowcount} = $i;
292 $lxdebug->leave_sub();
296 $lxdebug->enter_sub();
300 if ($form->{type} eq "credit_note") {
301 $form->{title} = $locale->text('Edit Credit Note');
303 if ($form->{storno}) {
304 $form->{title} = $locale->text('Edit Storno Credit Note');
307 $form->{title} = $locale->text('Edit Sales Invoice');
309 if ($form->{storno}) {
310 $form->{title} = $locale->text('Edit Storno Invoice');
316 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
318 $payment = qq|<option value=""></option>|;
319 foreach $item (@{ $form->{payment_terms} }) {
320 if ($form->{payment_id} eq $item->{id}) {
321 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
323 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
328 if (@{ $form->{TAXZONE} }) {
329 $form->{selecttaxzone} = "";
330 foreach $item (@{ $form->{TAXZONE} }) {
331 if ($item->{id} == $form->{taxzone_id}) {
332 $form->{selecttaxzone} .=
333 "<option value=$item->{id} selected>$item->{description}</option>";
335 $form->{selecttaxzone} .=
336 "<option value=$item->{id}>$item->{description}</option>";
341 $form->{selecttaxzone} =~ s/ selected//g;
342 if ($form->{taxzone_id} ne "") {
343 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
346 if ($form->{rowcount} >0) {
347 $form->{selecttaxzone} =~ /<option value=\d+ selected>.*?<\/option>/;
348 $form->{selecttaxzone} = $&;
354 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
355 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
356 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
360 if (@{ $form->{SHIPTO} }) {
361 $form->{selectshipto} = "<option value=0></option>";
362 foreach $item (@{ $form->{SHIPTO} }) {
363 if ($item->{shipto_id} == $form->{shipto_id}) {
364 $form->{selectshipto} .=
365 "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}</option>";
367 $form->{selectshipto} .=
368 "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment}</option>";
373 $form->{selectshipto} =~ s/ selected//g;
374 if ($form->{shipto_id} ne "") {
375 $form->{selectshipto} =~ s/value=$form->{shipto_id}/value=$form->{shipto_id} selected/;
380 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
381 <td><select name=shipto_id style="width:200px;">$form->{selectshipto}</select></td>
382 <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
386 # set option selected
387 foreach $item (qw(AR customer currency department employee)) {
388 $form->{"select$item"} =~ s/ selected//;
389 $form->{"select$item"} =~
390 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
393 #quote customer Bug 133
394 $form->{selectcustomer} = $form->quote($form->{selectcustomer});
397 if ($form->{all_contacts}) {
399 $form->{selectcontact} = "<option></option>";
400 foreach $item (@{ $form->{all_contacts} }) {
401 my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : "";
402 if ($form->{cp_id} == $item->{cp_id}) {
403 $form->{selectcontact} .=
404 "<option value=$item->{cp_id} selected>$item->{cp_name}$department</option>";
406 $form->{selectcontact} .= "<option value=$item->{cp_id}>$item->{cp_name}$department</option>";
410 $form->{selectcontact} =~ s/ selected//g;
411 if ($form->{cp_id} ne "") {
412 $form->{selectcontact} =~ s/value=$form->{cp_id}/value=$form->{cp_id} selected/;
417 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
423 #else {$form->{all_contacts} = 0;}
425 $form->{exchangerate} =
426 $form->format_amount(\%myconfig, $form->{exchangerate});
428 $form->{creditlimit} =
429 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
430 $form->{creditremaining} =
431 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
434 if ($form->{currency} ne $form->{defaultcurrency}) {
435 if ($form->{forex}) {
438 . $locale->text('Exchangerate')
439 . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
443 . $locale->text('Exchangerate')
444 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
448 <input type=hidden name=forex value=$form->{forex}>
452 ($form->{selectcustomer})
453 ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
454 : qq|<input name=customer value="$form->{customer}" size=35>|;
458 ($form->{selectcontact})
459 ? qq|<select name=cp_id>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
460 : qq|<input name=contact value="$form->{contact}" size=35>|;
464 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
465 <td colspan=3><select name=department>$form->{selectdepartment}</select>
466 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
469 | if $form->{selectdepartment};
471 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
473 if ($form->{business}) {
476 <th align=right>| . $locale->text('Business') . qq|</th>
477 <td>$form->{business}</td>
478 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
480 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
486 if ($form->{max_dunning_level}) {
492 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
493 <td><b>$form->{max_dunning_level}</b></td>
494 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
496 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
505 $form->{fokus} = "invoice.customer";
507 # use JavaScript Calendar or not
508 $form->{jsscript} = $jscalendar;
510 if ($form->{type} eq "credit_note") {
511 if ($form->{jsscript}) {
513 # with JavaScript Calendar
515 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
516 <td><input type=button name=invdate id="trigger1" value=|
517 . $locale->text('button') . qq|></td>
522 Form->write_trigger(\%myconfig, "1",
527 # without JavaScript Calendar
529 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
531 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
534 if ($form->{jsscript}) {
536 # with JavaScript Calendar
538 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
539 <td><input type=button name=invdate id="trigger1" value=|
540 . $locale->text('button') . qq|></td>
543 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
544 <td width="4"><input type=button name=duedate id="trigger2" value=|
545 . $locale->text('button') . qq|></td></td>
548 <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
549 <td width="4"><input type=button name=deliverydate id="trigger3" value=|
550 . $locale->text('button') . qq|></td></td>
555 Form->write_trigger(\%myconfig, "3",
557 "trigger1", "duedate",
559 "deliverydate", "BL",
563 # without JavaScript Calendar
565 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
567 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
570 if ($form->{resubmit} && ($form->{format} eq "html")) {
572 qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
573 } elsif ($form->{resubmit}) {
574 $onload = qq|document.invoice.submit()|;
579 $credittext = $locale->text('Credit Limit exceeded!!!');
580 if ($creditwarning) {
581 $onload = qq|alert('$credittext')|;
587 <body onLoad="$onload">
588 <script type="text/javascript" src="js/common.js"></script>
589 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
590 <script type="text/javascript" src="js/vendor_selection.js"></script>
591 <script type="text/javascript" src="js/calculate_qty.js"></script>
593 <form method=post name="invoice" action=$form->{script}>
596 <input type=hidden name=id value=$form->{id}>
597 <input type=hidden name=action value=$form->{action}>
599 <input type=hidden name=type value=$form->{type}>
600 <input type=hidden name=media value=$form->{media}>
601 <input type=hidden name=format value=$form->{format}>
603 <input type=hidden name=queued value="$form->{queued}">
604 <input type=hidden name=printed value="$form->{printed}">
605 <input type=hidden name=emailed value="$form->{emailed}">
607 <input type=hidden name=title value="$form->{title}">
608 <input type=hidden name=vc value=$form->{vc}>
610 <input type=hidden name=discount value=$form->{discount}>
611 <input type=hidden name=creditlimit value=$form->{creditlimit}>
612 <input type=hidden name=creditremaining value=$form->{creditremaining}>
614 <input type=hidden name=tradediscount value=$form->{tradediscount}>
615 <input type=hidden name=business value=$form->{business}>
617 <input type=hidden name=closedto value=$form->{closedto}>
618 <input type=hidden name=locked value=$form->{locked}>
620 <input type=hidden name=shipped value=$form->{shipped}>
621 <input type=hidden name=lizenzen value=$lizenzen>
622 <input type=hidden name=storno value=$form->{storno}>
623 <input type=hidden name=storno_id value=$form->{storno_id}>
629 <th class=listtop>$form->{title}</th>
639 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
640 <td colspan=3>$customer</td>
641 <input type=hidden name=customer_klass value=$form->{customer_klass}>
642 <input type=hidden name=customer_id value=$form->{customer_id}>
643 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
644 <th align=richt nowrap>|
645 . $locale->text('Contact Person') . qq|</th>
646 <td colspan=3>$contact</td>
653 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
654 <td>$form->{creditlimit}</td>
656 <th nowrap>| . $locale->text('Remaining') . qq|</th>
657 <td class="plus$n">$form->{creditremaining}</td>
666 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
667 <td colspan=3><select name=AR style="width:280px;">$form->{selectAR}</select></td>
668 <input type=hidden name=selectAR value="$form->{selectAR}">
673 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
674 <td><select name=currency>$form->{selectcurrency}</select></td>
675 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
676 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
677 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
678 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
682 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
683 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
686 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
687 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
694 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
696 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
697 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
701 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
703 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
704 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
714 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
715 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
716 <input type=hidden name=selectemployee value="$form->{selectemployee}">
719 if ($form->{type} eq "credit_note") {
721 <th align=right nowrap>| . $locale->text('Credit Note Number') . qq|</th>
722 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
725 <th align=right>| . $locale->text('Credit Note Date') . qq|</th>
730 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
731 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
734 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
738 <th align=right>| . $locale->text('Due Date') . qq|</th>
742 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
747 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
748 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
751 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
752 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
755 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
756 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
771 <!-- shipto are in hidden variables -->
773 <input type=hidden name=shiptoname value="$form->{shiptoname}">
774 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
775 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
776 <input type=hidden name=shiptocity value="$form->{shiptocity}">
777 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
778 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
779 <input type=hidden name=shiptophone value="$form->{shiptophone}">
780 <input type=hidden name=shiptofax value="$form->{shiptofax}">
781 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
783 <!-- email variables -->
784 <input type=hidden name=message value="$form->{message}">
785 <input type=hidden name=email value="$form->{email}">
786 <input type=hidden name=subject value="$form->{subject}">
787 <input type=hidden name=cc value="$form->{cc}">
788 <input type=hidden name=bcc value="$form->{bcc}">
789 <input type=hidden name=webdav value=$webdav>
790 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
793 foreach $item (split / /, $form->{taxaccounts}) {
795 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
796 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
797 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
800 $lxdebug->leave_sub();
804 $lxdebug->enter_sub();
806 $form->{invtotal} = $form->{invsubtotal};
808 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
811 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
814 $rows = ($rows > $introws) ? $rows : $introws;
816 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
818 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
820 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
823 if ($form->{taxaccounts}) {
825 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
826 . $locale->text('Tax Included') . qq|</b><br><br>|;
829 if (!$form->{taxincluded}) {
831 foreach $item (split / /, $form->{taxaccounts}) {
832 if ($form->{"${item}_base"}) {
833 $form->{"${item}_total"} =
835 $form->{"${item}_base"} * $form->{"${item}_rate"},
837 $form->{invtotal} += $form->{"${item}_total"};
838 $form->{"${item}_total"} =
839 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
843 <th align=right>$form->{"${item}_description"}</th>
844 <td align=right>$form->{"${item}_total"}</td>
850 $form->{invsubtotal} =
851 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
855 <th align=right>| . $locale->text('Subtotal') . qq|</th>
856 <td align=right>$form->{invsubtotal}</td>
862 if ($form->{taxincluded}) {
863 foreach $item (split / /, $form->{taxaccounts}) {
864 if ($form->{"${item}_base"}) {
865 $form->{"${item}_total"} =
867 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
868 (1 + $form->{"${item}_rate"})
871 $form->{"${item}_netto"} =
873 ($form->{"${item}_base"} - $form->{"${item}_total"}),
875 $form->{"${item}_total"} =
876 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
877 $form->{"${item}_netto"} =
878 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
882 <th align=right>Enthaltene $form->{"${item}_description"}</th>
883 <td align=right>$form->{"${item}_total"}</td>
886 <th align=right>Nettobetrag</th>
887 <td align=right>$form->{"${item}_netto"}</td>
895 $form->{oldinvtotal} = $form->{invtotal};
897 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
907 <th align=left>| . $locale->text('Notes') . qq|</th>
908 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
909 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
914 <td><select name=payment_id tabindex=24>$payment
919 <td align=right width=100%>
925 <th align=right>| . $locale->text('Total') . qq|</th>
926 <td align=right>$form->{invtotal}</td>
938 <td><hr size=3 noshade></td>
941 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
944 <td align=left width=30%><b>Dateiname</b></td>
945 <td align=left width=70%><b>Webdavlink</b></td>
947 foreach $file (keys %{ $form->{WEBDAV} }) {
950 <td align=left>$file</td>
951 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
962 if ($form->{type} eq "credit_note") {
967 <tr class=listheading>
968 <th colspan=6 class=listheading>|
969 . $locale->text('Payments') . qq|</th>
977 <tr class=listheading>
978 <th colspan=6 class=listheading>|
979 . $locale->text('Incoming Payments') . qq|</th>
984 if ($form->{currency} eq $form->{defaultcurrency}) {
985 @column_index = qw(datepaid source memo paid AR_paid);
987 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
990 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
991 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
992 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
993 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
994 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
995 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
1000 map { print "$column_data{$_}\n" } @column_index;
1005 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1006 for $i (1 .. $form->{paidaccounts}) {
1011 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1012 $form->{"selectAR_paid_$i"} =~
1013 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1016 $totalpaid += $form->{"paid_$i"};
1017 $form->{"paid_$i"} =
1018 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1019 $form->{"exchangerate_$i"} =
1020 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1022 $exchangerate = qq| |;
1023 if ($form->{currency} ne $form->{defaultcurrency}) {
1024 if ($form->{"forex_$i"}) {
1026 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
1029 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
1033 $exchangerate .= qq|
1034 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
1037 $column_data{"paid_$i"} =
1038 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
1039 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
1040 $column_data{"AR_paid_$i"} =
1041 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1042 $column_data{"datepaid_$i"} =
1043 qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></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;
1055 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
1056 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
1057 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1058 <input type=hidden name=oldtotalpaid value=$totalpaid>
1063 <td><hr size=3 noshade></td>
1077 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1078 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1082 <input class=submit type=submit name=action 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|">| unless ($form->{storno});
1092 print qq|<input class=submit type=submit name=action value="|
1093 . $locale->text('Post Payment') . qq|">
1095 if ($form->{id} && !($form->{type} eq "credit_note")) {
1097 <input class=submit type=submit name=action value="|
1098 . $locale->text('Credit Note') . qq|">
1101 if ($form->{radier}) {
1103 <input class=submit type=submit name=action value="|
1104 . $locale->text('Delete') . qq|">
1109 if ($invdate > $closedto) {
1111 <input class=submit type=submit name=action value="|
1112 . $locale->text('Order') . qq|">
1117 if ($invdate > $closedto) {
1118 print qq|<input class=submit type=submit name=action value="|
1119 . $locale->text('Update') . qq|">
1120 <input class=submit type=submit name=action value="|
1121 . $locale->text('Ship to') . qq|">
1122 <input class=submit type=submit name=action value="|
1123 . $locale->text('Preview') . qq|">
1124 <input class=submit type=submit name=action value="|
1125 . $locale->text('E-mail') . qq|">
1126 <input class=submit type=submit name=action value="|
1127 . $locale->text('Print and Post') . qq|">
1128 <input class=submit type=submit name=action value="|
1129 . $locale->text('Post') . qq|">|;
1133 if ($form->{menubar}) {
1134 require "$form->{path}/menu.pl";
1140 <input type=hidden name=rowcount value=$form->{rowcount}>
1142 <input name=callback type=hidden value="$form->{callback}">
1144 <input type=hidden name=path value=$form->{path}>
1145 <input type=hidden name=login value=$form->{login}>
1146 <input type=hidden name=password value=$form->{password}>
1155 $lxdebug->leave_sub();
1159 $lxdebug->enter_sub();
1161 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1162 qw(exchangerate creditlimit creditremaining);
1163 if ($form->{second_run}) {
1164 $form->{print_and_post} = 0;
1167 $form->{update} = 1;
1169 &check_name(customer);
1173 $form->{exchangerate} = $exchangerate
1177 $form->check_exchangerate(
1178 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
1181 for $i (1 .. $form->{paidaccounts}) {
1182 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1184 $form->{"${_}_$i"} =
1185 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1186 } qw(paid exchangerate);
1188 $form->{"exchangerate_$i"} = $exchangerate
1190 $form->{"forex_$i"} = (
1192 $form->check_exchangerate(
1193 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
1198 $i = $form->{rowcount};
1199 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1201 # if last row empty, check the form otherwise retrieve new item
1202 if ( ($form->{"partnumber_$i"} eq "")
1203 && ($form->{"description_$i"} eq "")
1204 && ($form->{"partsgroup_$i"} eq "")) {
1206 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1211 IS->retrieve_item(\%myconfig, \%$form);
1213 $rows = scalar @{ $form->{item_list} };
1215 $form->{"discount_$i"} =
1216 $form->format_amount(\%myconfig, $form->{discount} * 100);
1219 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1228 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1230 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1231 qw(partnumber description unit);
1232 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1233 keys %{ $form->{item_list}[0] };
1234 if ($form->{"part_payment_id_$i"} ne "") {
1235 $form->{payment_id} = $form->{"part_payment_id_$i"};
1238 if ($form->{"not_discountable_$i"}) {
1239 $form->{"discount_$i"} = 0;
1242 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1243 ($dec) = ($s =~ /\.(\d+)/);
1245 $decimalplaces = ($dec > 2) ? $dec : 2;
1248 $form->{"sellprice_$i"} = $sellprice;
1251 # if there is an exchange rate adjust sellprice
1252 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1253 $form->{"sellprice_$i"} /= $exchangerate;
1256 $form->{"listprice_$i"} /= $exchangerate;
1259 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1260 (1 - $form->{"discount_$i"} / 100);
1261 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1262 map { $form->{"${_}_base"} += $amount }
1263 (split / /, $form->{"taxaccounts_$i"});
1264 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1265 split / /, $form->{"taxaccounts_$i"}
1266 if !$form->{taxincluded};
1268 $form->{creditremaining} -= $amount;
1271 $form->{"${_}_$i"} =
1272 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
1274 } qw(sellprice listprice);
1277 $form->format_amount(\%myconfig, $form->{"qty_$i"});
1280 if ($form->{"inventory_accno_$i"} ne "") {
1281 $form->{"lizenzen_$i"} = qq|<option></option>|;
1282 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1283 $form->{"lizenzen_$i"} .=
1284 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1286 $form->{"lizenzen_$i"} .=
1287 qq|<option value=-1>Neue Lizenz</option>|;
1291 # get pricegroups for parts
1292 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1294 # build up html code for prices_$i
1295 &set_pricegroup($i);
1302 # ok, so this is a new part
1303 # ask if it is a part or service item
1305 if ( $form->{"partsgroup_$i"}
1306 && ($form->{"partsnumber_$i"} eq "")
1307 && ($form->{"description_$i"} eq "")) {
1308 $form->{rowcount}--;
1309 $form->{"discount_$i"} = "";
1313 $form->{"id_$i"} = 0;
1314 $form->{"unit_$i"} = $locale->text('ea');
1321 $lxdebug->leave_sub();
1324 $lxdebug->enter_sub();
1325 for $i (1 .. $form->{paidaccounts}) {
1326 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1327 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1329 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1331 $form->error($locale->text('Cannot post payment for a closed period!'))
1332 if ($datepaid <= $closedto);
1334 if ($form->{currency} ne $form->{defaultcurrency}) {
1335 $form->{"exchangerate_$i"} = $form->{exchangerate}
1336 if ($invdate == $datepaid);
1337 $form->isblank("exchangerate_$i",
1338 $locale->text('Exchangerate for payment missing!'));
1343 ($form->{AR}) = split /--/, $form->{AR};
1344 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1346 $form->redirect($locale->text(' Payment posted!'))
1347 if (IS->post_payment(\%myconfig, \%$form));
1348 $form->error($locale->text('Cannot post payment!'));
1351 $lxdebug->leave_sub();
1355 $lxdebug->enter_sub();
1356 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1357 $form->isblank("customer", $locale->text('Customer missing!'));
1359 # if oldcustomer ne customer redo form
1360 if (&check_name(customer)) {
1364 if ($form->{second_run}) {
1365 $form->{print_and_post} = 0;
1370 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1371 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1373 $form->error($locale->text('Cannot post invoice for a closed period!'))
1374 if ($invdate <= $closedto);
1376 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1377 if ($form->{currency} ne $form->{defaultcurrency});
1379 for $i (1 .. $form->{paidaccounts}) {
1380 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1381 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1383 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1385 $form->error($locale->text('Cannot post payment for a closed period!'))
1386 if ($datepaid <= $closedto);
1388 if ($form->{currency} ne $form->{defaultcurrency}) {
1389 $form->{"exchangerate_$i"} = $form->{exchangerate}
1390 if ($invdate == $datepaid);
1391 $form->isblank("exchangerate_$i",
1392 $locale->text('Exchangerate for payment missing!'));
1397 ($form->{AR}) = split /--/, $form->{AR};
1398 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1400 $form->{label} = $locale->text('Invoice');
1402 $form->{id} = 0 if $form->{postasnew};
1404 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1405 if (!$form->{invnumber} || $form->{postasnew}) {
1406 if ($form->{type} eq "credit_note") {
1407 $form->{invnumber} = $form->update_defaults(\%myconfig, "cnnumber");
1409 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
1414 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1415 $form->error($locale->text('Cannot post invoice!'));
1419 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1420 if (IS->post_invoice(\%myconfig, \%$form));
1421 $form->error($locale->text('Cannot post invoice!'));
1424 $lxdebug->leave_sub();
1427 sub print_and_post {
1428 $lxdebug->enter_sub();
1430 $old_form = new Form;
1432 $form->{print_and_post} = 1;
1436 $lxdebug->leave_sub();
1441 $lxdebug->enter_sub();
1443 if ($form->{storno}) {
1444 $form->error($locale->text('Cannot storno storno invoice!'));
1447 $form->{storno_id} = $form->{id};
1448 $form->{storno} = 1;
1450 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1451 $form->{rowcount}--;
1454 $lxdebug->leave_sub();
1459 $lxdebug->enter_sub();
1461 $form->{preview} = 1;
1462 $old_form = new Form;
1463 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1464 $old_form->{rowcount}++;
1466 &print_form($old_form);
1467 $lxdebug->leave_sub();
1472 $lxdebug->enter_sub();
1473 if ($form->{second_run}) {
1474 $form->{print_and_post} = 0;
1481 <form method=post action=$form->{script}>
1484 # delete action variable
1485 map { delete $form->{$_} } qw(action header);
1487 foreach $key (keys %$form) {
1488 $form->{$key} =~ s/\"/"/g;
1489 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1493 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1496 . $locale->text('Are you sure you want to delete Invoice Number')
1497 . qq| $form->{invnumber}
1501 <input name=action class=submit type=submit value="|
1502 . $locale->text('Yes') . qq|">
1506 $lxdebug->leave_sub();
1510 $lxdebug->enter_sub();
1512 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1514 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1517 $form->{rowcount}--;
1518 $form->{shipto} = 1;
1521 $form->{title} = $locale->text('Add Credit Note');
1522 $form->{script} = 'is.pl';
1527 # bo creates the id, reset it
1528 map { delete $form->{$_} }
1529 qw(id invnumber subject message cc bcc printed emailed queued);
1530 $form->{ $form->{vc} } =~ s/--.*//g;
1531 $form->{type} = "credit_note";
1534 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1536 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1537 qw(creditlimit creditremaining);
1539 $currency = $form->{currency};
1542 $form->{currency} = $currency;
1543 $form->{exchangerate} = "";
1544 $form->{forex} = "";
1545 $form->{exchangerate} = $exchangerate
1549 $form->check_exchangerate(
1550 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1553 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1560 $lxdebug->leave_sub();
1564 $lxdebug->enter_sub();
1566 $form->redirect($locale->text('Invoice deleted!'))
1567 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1568 $form->error($locale->text('Cannot delete invoice!'));
1570 $lxdebug->leave_sub();