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);
144 IS->retrieve_invoice(\%myconfig, \%$form);
145 $form->{cp_id} = $cp_id;
148 $form->{payment_id} = $payment_id;
151 $form->{language_id} = $language_id;
154 $form->{taxzone_id} = $taxzone_id;
157 $form->{shipto_id} = $shipto_id;
161 @curr = split /:/, $form->{currencies};
163 $form->{defaultcurrency} = $curr[0];
165 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
167 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
169 if ($form->{all_customer}) {
170 $form->{customer} = "$form->{customer}--$form->{customer_id}";
171 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
172 (@{ $form->{all_customer} });
176 if ($form->{all_departments}) {
177 $form->{selectdepartment} = "<option>\n";
178 $form->{department} = "$form->{department}--$form->{department_id}";
181 $form->{selectdepartment} .=
182 "<option>$_->{description}--$_->{id}\n"
183 } (@{ $form->{all_departments} });
186 $form->{employee} = "$form->{employee}--$form->{employee_id}";
189 if ($form->{all_employees}) {
190 $form->{selectemployee} = "";
191 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
192 (@{ $form->{all_employees} });
196 $form->{forex} = $form->{exchangerate};
197 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
199 foreach $key (keys %{ $form->{AR_links} }) {
200 foreach $ref (@{ $form->{AR_links}{$key} }) {
201 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
204 if ($key eq "AR_paid") {
205 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
206 $form->{"AR_paid_$i"} =
207 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
210 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
211 $form->{"datepaid_$i"} =
212 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
213 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
214 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
215 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
216 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
218 $form->{paidaccounts} = $i;
222 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
227 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
229 $form->{AR} = $form->{AR_1} unless $form->{id};
232 ($form->datetonum($form->{invdate}, \%myconfig) <=
233 $form->datetonum($form->{closedto}, \%myconfig));
235 $lxdebug->leave_sub();
238 sub prepare_invoice {
239 $lxdebug->enter_sub();
241 if ($form->{type} eq "credit_note") {
242 $form->{type} = "credit_note";
243 $form->{formname} = "credit_note";
244 $form->{media} = "screen";
246 $form->{type} = "invoice";
247 $form->{formname} = "invoice";
248 $form->{media} = "screen";
253 map { $form->{$_} =~ s/\"/"/g }
254 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
256 # # get pricegroups for parts
257 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
259 foreach $ref (@{ $form->{invoice_details} }) {
263 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
264 $form->{"discount_$i"} =
265 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
266 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
268 $decimalplaces = ($dec > 2) ? $dec : 2;
270 $form->{"sellprice_$i"} =
271 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
274 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
275 $dec_qty = length $dec_qty;
278 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
280 map { $form->{"${_}_$i"} =~ s/\"/"/g }
281 qw(partnumber description unit partnotes);
282 $form->{rowcount} = $i;
286 $lxdebug->leave_sub();
290 $lxdebug->enter_sub();
294 if ($form->{type} eq "credit_note") {
295 $form->{title} = $locale->text('Edit Credit Note');
297 if ($form->{storno}) {
298 $form->{title} = $locale->text('Edit Storno Credit Note');
301 $form->{title} = $locale->text('Edit Sales Invoice');
303 if ($form->{storno}) {
304 $form->{title} = $locale->text('Edit Storno Invoice');
309 $payment = qq|<option value=""></option>|;
310 foreach $item (@{ $form->{payment_terms} }) {
311 if ($form->{payment_id} eq $item->{id}) {
312 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
314 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
319 if (@{ $form->{TAXZONE} }) {
320 $form->{selecttaxzone} = "";
321 foreach $item (@{ $form->{TAXZONE} }) {
322 if ($item->{id} == $form->{taxzone_id}) {
323 $form->{selecttaxzone} .=
324 "<option value=$item->{id} selected>$item->{description}</option>";
326 $form->{selecttaxzone} .=
327 "<option value=$item->{id}>$item->{description}</option>";
332 $form->{selecttaxzone} =~ s/ selected//g;
333 if ($form->{taxzone_id} ne "") {
334 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
337 if ($form->{rowcount} >0) {
338 $form->{selecttaxzone} =~ /<option value=\d+ selected>.*?<\/option>/;
339 $form->{selecttaxzone} = $&;
345 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
346 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
347 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
351 if (@{ $form->{SHIPTO} }) {
352 $form->{selectshipto} = "<option value=0></option>";
353 foreach $item (@{ $form->{SHIPTO} }) {
354 if ($item->{id} == $form->{shipto_id}) {
355 $form->{selectshipto} .=
356 "<option value=$item->{id} selected>$item->{shiptoname}</option>";
358 $form->{selectshipto} .=
359 "<option value=$item->{id}>$item->{shiptoname}</option>";
364 $form->{selectshipto} =~ s/ selected//g;
365 if ($form->{shipto_id} ne "") {
366 $form->{selectshipto} =~ s/value=$form->{shipto_id}/value=$form->{shipto_id} selected/;
371 <th align=right>| . $locale->text('Shipping Address') . qq|</th>
372 <td><select name=shipto_id>$form->{selectshipto}</select></td>
373 <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
377 # set option selected
378 foreach $item (qw(AR customer currency department employee)) {
379 $form->{"select$item"} =~ s/ selected//;
380 $form->{"select$item"} =~
381 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
385 if ($form->{all_contacts}) {
387 $form->{selectcontact} = "<option></option>";
388 foreach $item (@{ $form->{all_contacts} }) {
389 my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : "";
390 if ($form->{cp_id} == $item->{cp_id}) {
391 $form->{selectcontact} .=
392 "<option value=$item->{cp_id} selected>$item->{cp_name}$department</option>";
394 $form->{selectcontact} .= "<option value=$item->{cp_id}>$item->{cp_name}$department</option>";
398 $form->{selectcontact} =~ s/ selected//g;
399 if ($form->{cp_id} ne "") {
400 $form->{selectcontact} =~ s/value=$form->{cp_id}/value=$form->{cp_id} selected/;
405 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
411 #else {$form->{all_contacts} = 0;}
413 $form->{exchangerate} =
414 $form->format_amount(\%myconfig, $form->{exchangerate});
416 $form->{creditlimit} =
417 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
418 $form->{creditremaining} =
419 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
422 if ($form->{currency} ne $form->{defaultcurrency}) {
423 if ($form->{forex}) {
426 . $locale->text('Exchangerate')
427 . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
431 . $locale->text('Exchangerate')
432 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
436 <input type=hidden name=forex value=$form->{forex}>
440 ($form->{selectcustomer})
441 ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
442 : qq|<input name=customer value="$form->{customer}" size=35>|;
446 ($form->{selectcontact})
447 ? qq|<select name=cp_id>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
448 : qq|<input name=contact value="$form->{contact}" size=35>|;
452 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
453 <td colspan=3><select name=department>$form->{selectdepartment}</select>
454 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
457 | if $form->{selectdepartment};
459 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
461 if ($form->{business}) {
464 <th align=right>| . $locale->text('Business') . qq|</th>
465 <td>$form->{business}</td>
466 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
468 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
474 if ($form->{max_dunning_level}) {
480 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
481 <td><b>$form->{max_dunning_level}</b></td>
482 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
484 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
493 $form->{fokus} = "invoice.customer";
495 # use JavaScript Calendar or not
496 $form->{jsscript} = $jscalendar;
498 if ($form->{type} eq "credit_note") {
499 if ($form->{jsscript}) {
501 # with JavaScript Calendar
503 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
504 <td><input type=button name=invdate id="trigger1" value=|
505 . $locale->text('button') . qq|></td>
510 Form->write_trigger(\%myconfig, "1",
515 # without JavaScript Calendar
517 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
519 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
522 if ($form->{jsscript}) {
524 # with JavaScript Calendar
526 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
527 <td><input type=button name=invdate id="trigger1" value=|
528 . $locale->text('button') . qq|></td>
531 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
532 <td width="4"><input type=button name=duedate id="trigger2" value=|
533 . $locale->text('button') . qq|></td></td>
536 <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
537 <td width="4"><input type=button name=deliverydate id="trigger3" value=|
538 . $locale->text('button') . qq|></td></td>
543 Form->write_trigger(\%myconfig, "3",
545 "trigger1", "duedate",
547 "deliverydate", "BL",
551 # without JavaScript Calendar
553 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
555 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
558 if ($form->{resubmit} && ($form->{format} eq "html")) {
560 qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
561 } elsif ($form->{resubmit}) {
562 $onload = qq|document.invoice.submit()|;
567 $credittext = $locale->text('Credit Limit exceeded!!!');
568 if ($creditwarning) {
569 $onload = qq|alert('$credittext')|;
575 <body onLoad="$onload">
576 <script type="text/javascript" src="js/common.js"></script>
577 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
578 <script type="text/javascript" src="js/vendor_selection.js"></script>
579 <script type="text/javascript" src="js/calculate_qty.js"></script>
581 <form method=post name="invoice" action=$form->{script}>
584 <input type=hidden name=id value=$form->{id}>
585 <input type=hidden name=action value=$form->{action}>
587 <input type=hidden name=type value=$form->{type}>
588 <input type=hidden name=media value=$form->{media}>
589 <input type=hidden name=format value=$form->{format}>
591 <input type=hidden name=queued value="$form->{queued}">
592 <input type=hidden name=printed value="$form->{printed}">
593 <input type=hidden name=emailed value="$form->{emailed}">
595 <input type=hidden name=title value="$form->{title}">
596 <input type=hidden name=vc value=$form->{vc}>
598 <input type=hidden name=discount value=$form->{discount}>
599 <input type=hidden name=creditlimit value=$form->{creditlimit}>
600 <input type=hidden name=creditremaining value=$form->{creditremaining}>
602 <input type=hidden name=tradediscount value=$form->{tradediscount}>
603 <input type=hidden name=business value=$form->{business}>
605 <input type=hidden name=closedto value=$form->{closedto}>
606 <input type=hidden name=locked value=$form->{locked}>
608 <input type=hidden name=shipped value=$form->{shipped}>
609 <input type=hidden name=lizenzen value=$lizenzen>
610 <input type=hidden name=storno value=$form->{storno}>
611 <input type=hidden name=storno_id value=$form->{storno_id}>
617 <th class=listtop>$form->{title}</th>
627 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
628 <td colspan=3>$customer</td>
629 <input type=hidden name=customer_klass value=$form->{customer_klass}>
630 <input type=hidden name=customer_id value=$form->{customer_id}>
631 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
632 <th align=richt nowrap>|
633 . $locale->text('Contact Person') . qq|</th>
634 <td colspan=3>$contact</td>
641 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
642 <td>$form->{creditlimit}</td>
644 <th nowrap>| . $locale->text('Remaining') . qq|</th>
645 <td class="plus$n">$form->{creditremaining}</td>
654 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
655 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
656 <input type=hidden name=selectAR value="$form->{selectAR}">
661 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
662 <td><select name=currency>$form->{selectcurrency}</select></td>
663 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
664 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
665 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
666 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
670 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
671 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
674 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
675 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
682 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
684 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
685 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
689 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
691 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
692 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
702 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
703 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
704 <input type=hidden name=selectemployee value="$form->{selectemployee}">
707 if ($form->{type} eq "credit_note") {
709 <th align=right nowrap>| . $locale->text('Credit Note Number') . qq|</th>
710 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
713 <th align=right>| . $locale->text('Credit Note Date') . qq|</th>
718 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
719 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
722 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
726 <th align=right>| . $locale->text('Due Date') . qq|</th>
730 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
735 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
736 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
739 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
740 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
743 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
744 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
759 <!-- shipto are in hidden variables -->
761 <input type=hidden name=shiptoname value="$form->{shiptoname}">
762 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
763 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
764 <input type=hidden name=shiptocity value="$form->{shiptocity}">
765 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
766 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
767 <input type=hidden name=shiptophone value="$form->{shiptophone}">
768 <input type=hidden name=shiptofax value="$form->{shiptofax}">
769 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
771 <!-- email variables -->
772 <input type=hidden name=message value="$form->{message}">
773 <input type=hidden name=email value="$form->{email}">
774 <input type=hidden name=subject value="$form->{subject}">
775 <input type=hidden name=cc value="$form->{cc}">
776 <input type=hidden name=bcc value="$form->{bcc}">
777 <input type=hidden name=webdav value=$webdav>
778 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
781 foreach $item (split / /, $form->{taxaccounts}) {
783 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
784 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
785 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
788 $lxdebug->leave_sub();
792 $lxdebug->enter_sub();
794 $form->{invtotal} = $form->{invsubtotal};
796 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
799 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
802 $rows = ($rows > $introws) ? $rows : $introws;
804 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
806 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
808 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
811 if ($form->{taxaccounts}) {
813 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
814 . $locale->text('Tax Included') . qq|</b><br><br>|;
817 if (!$form->{taxincluded}) {
819 foreach $item (split / /, $form->{taxaccounts}) {
820 if ($form->{"${item}_base"}) {
821 $form->{"${item}_total"} =
823 $form->{"${item}_base"} * $form->{"${item}_rate"},
825 $form->{invtotal} += $form->{"${item}_total"};
826 $form->{"${item}_total"} =
827 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
831 <th align=right>$form->{"${item}_description"}</th>
832 <td align=right>$form->{"${item}_total"}</td>
838 $form->{invsubtotal} =
839 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
843 <th align=right>| . $locale->text('Subtotal') . qq|</th>
844 <td align=right>$form->{invsubtotal}</td>
850 if ($form->{taxincluded}) {
851 foreach $item (split / /, $form->{taxaccounts}) {
852 if ($form->{"${item}_base"}) {
853 $form->{"${item}_total"} =
855 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
856 (1 + $form->{"${item}_rate"})
859 $form->{"${item}_netto"} =
861 ($form->{"${item}_base"} - $form->{"${item}_total"}),
863 $form->{"${item}_total"} =
864 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
865 $form->{"${item}_netto"} =
866 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
870 <th align=right>Enthaltene $form->{"${item}_description"}</th>
871 <td align=right>$form->{"${item}_total"}</td>
874 <th align=right>Nettobetrag</th>
875 <td align=right>$form->{"${item}_netto"}</td>
883 $form->{oldinvtotal} = $form->{invtotal};
885 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
895 <th align=left>| . $locale->text('Notes') . qq|</th>
896 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
897 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
902 <td><select name=payment_id tabindex=24>$payment
907 <td align=right width=100%>
913 <th align=right>| . $locale->text('Total') . qq|</th>
914 <td align=right>$form->{invtotal}</td>
926 <td><hr size=3 noshade></td>
929 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
932 <td align=left width=30%><b>Dateiname</b></td>
933 <td align=left width=70%><b>Webdavlink</b></td>
935 foreach $file (keys %{ $form->{WEBDAV} }) {
938 <td align=left>$file</td>
939 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
950 if ($form->{type} eq "credit_note") {
955 <tr class=listheading>
956 <th colspan=6 class=listheading>|
957 . $locale->text('Payments') . qq|</th>
965 <tr class=listheading>
966 <th colspan=6 class=listheading>|
967 . $locale->text('Incoming Payments') . qq|</th>
972 if ($form->{currency} eq $form->{defaultcurrency}) {
973 @column_index = qw(datepaid source memo paid AR_paid);
975 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
978 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
979 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
980 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
981 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
982 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
983 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
988 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 $form->{"paid_$i"} =
1006 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1007 $form->{"exchangerate_$i"} =
1008 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1010 $exchangerate = qq| |;
1011 if ($form->{currency} ne $form->{defaultcurrency}) {
1012 if ($form->{"forex_$i"}) {
1014 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
1017 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
1021 $exchangerate .= qq|
1022 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
1025 $column_data{"paid_$i"} =
1026 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
1027 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
1028 $column_data{"AR_paid_$i"} =
1029 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1030 $column_data{"datepaid_$i"} =
1031 qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
1032 $column_data{"source_$i"} =
1033 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
1034 $column_data{"memo_$i"} =
1035 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
1037 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1043 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
1044 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
1045 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1046 <input type=hidden name=oldtotalpaid value=$totalpaid>
1051 <td><hr size=3 noshade></td>
1065 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1066 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1070 <input class=submit type=submit name=action value="|
1071 . $locale->text('Update') . qq|">
1072 <input class=submit type=submit name=action value="|
1073 . $locale->text('Ship to') . qq|">
1074 <input class=submit type=submit name=action value="|
1075 . $locale->text('Print') . qq|">
1076 <input class=submit type=submit name=action value="|
1077 . $locale->text('E-mail') . qq|">|;
1078 print qq|<input class=submit type=submit name=action value="|
1079 . $locale->text('Storno') . qq|">| unless ($form->{storno});
1080 print qq|<input class=submit type=submit name=action value="|
1081 . $locale->text('Post Payment') . qq|">
1083 if ($form->{id} && !($form->{type} eq "credit_note")) {
1085 <input class=submit type=submit name=action value="|
1086 . $locale->text('Credit Note') . qq|">
1091 if ($invdate > $closedto) {
1093 <input class=submit type=submit name=action value="|
1094 . $locale->text('Order') . qq|">
1099 if ($invdate > $closedto) {
1100 print qq|<input class=submit type=submit name=action value="|
1101 . $locale->text('Update') . qq|">
1102 <input class=submit type=submit name=action value="|
1103 . $locale->text('Ship to') . qq|">
1104 <input class=submit type=submit name=action value="|
1105 . $locale->text('Preview') . qq|">
1106 <input class=submit type=submit name=action value="|
1107 . $locale->text('E-mail') . qq|">
1108 <input class=submit type=submit name=action value="|
1109 . $locale->text('Print and Post') . qq|">
1110 <input class=submit type=submit name=action value="|
1111 . $locale->text('Post') . qq|">|;
1115 if ($form->{menubar}) {
1116 require "$form->{path}/menu.pl";
1122 <input type=hidden name=rowcount value=$form->{rowcount}>
1124 <input name=callback type=hidden value="$form->{callback}">
1126 <input type=hidden name=path value=$form->{path}>
1127 <input type=hidden name=login value=$form->{login}>
1128 <input type=hidden name=password value=$form->{password}>
1137 $lxdebug->leave_sub();
1141 $lxdebug->enter_sub();
1143 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1144 qw(exchangerate creditlimit creditremaining);
1145 if ($form->{second_run}) {
1146 $form->{print_and_post} = 0;
1149 $form->{update} = 1;
1151 &check_name(customer);
1155 $form->{exchangerate} = $exchangerate
1159 $form->check_exchangerate(
1160 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
1163 for $i (1 .. $form->{paidaccounts}) {
1164 if ($form->{"paid_$i"}) {
1166 $form->{"${_}_$i"} =
1167 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1168 } qw(paid exchangerate);
1170 $form->{"exchangerate_$i"} = $exchangerate
1172 $form->{"forex_$i"} = (
1174 $form->check_exchangerate(
1175 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
1180 $i = $form->{rowcount};
1181 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1183 # if last row empty, check the form otherwise retrieve new item
1184 if ( ($form->{"partnumber_$i"} eq "")
1185 && ($form->{"description_$i"} eq "")
1186 && ($form->{"partsgroup_$i"} eq "")) {
1188 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1193 $form->{"selected_unit_$i"} = $form->{"unit_$i"};
1195 IS->retrieve_item(\%myconfig, \%$form);
1197 $rows = scalar @{ $form->{item_list} };
1199 $form->{"discount_$i"} =
1200 $form->format_amount(\%myconfig, $form->{discount} * 100);
1203 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1212 $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
1214 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1215 qw(partnumber description unit);
1216 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1217 keys %{ $form->{item_list}[0] };
1218 if ($form->{"part_payment_id_$i"} ne "") {
1219 $form->{payment_id} = $form->{"part_payment_id_$i"};
1222 if ($form->{"not_discountable_$i"}) {
1223 $form->{"discount_$i"} = 0;
1226 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1227 ($dec) = ($s =~ /\.(\d+)/);
1229 $decimalplaces = ($dec > 2) ? $dec : 2;
1232 $form->{"sellprice_$i"} = $sellprice;
1235 # if there is an exchange rate adjust sellprice
1236 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1237 $form->{"sellprice_$i"} /= $exchangerate;
1240 $form->{"listprice_$i"} /= $exchangerate;
1243 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1244 (1 - $form->{"discount_$i"} / 100);
1245 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1246 map { $form->{"${_}_base"} += $amount }
1247 (split / /, $form->{"taxaccounts_$i"});
1248 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1249 split / /, $form->{"taxaccounts_$i"}
1250 if !$form->{taxincluded};
1252 $form->{creditremaining} -= $amount;
1255 $form->{"${_}_$i"} =
1256 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
1258 } qw(sellprice listprice);
1261 $form->format_amount(\%myconfig, $form->{"qty_$i"});
1264 if ($form->{"inventory_accno_$i"} ne "") {
1265 $form->{"lizenzen_$i"} = qq|<option></option>|;
1266 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1267 $form->{"lizenzen_$i"} .=
1268 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1270 $form->{"lizenzen_$i"} .=
1271 qq|<option value=-1>Neue Lizenz</option>|;
1275 # get pricegroups for parts
1276 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1278 # build up html code for prices_$i
1279 &set_pricegroup($i);
1286 # ok, so this is a new part
1287 # ask if it is a part or service item
1289 if ( $form->{"partsgroup_$i"}
1290 && ($form->{"partsnumber_$i"} eq "")
1291 && ($form->{"description_$i"} eq "")) {
1292 $form->{rowcount}--;
1293 $form->{"discount_$i"} = "";
1297 $form->{"id_$i"} = 0;
1298 $form->{"unit_$i"} = $locale->text('ea');
1305 $lxdebug->leave_sub();
1308 $lxdebug->enter_sub();
1309 for $i (1 .. $form->{paidaccounts}) {
1310 if ($form->{"paid_$i"}) {
1311 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1313 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1315 $form->error($locale->text('Cannot post payment for a closed period!'))
1316 if ($datepaid <= $closedto);
1318 if ($form->{currency} ne $form->{defaultcurrency}) {
1319 $form->{"exchangerate_$i"} = $form->{exchangerate}
1320 if ($invdate == $datepaid);
1321 $form->isblank("exchangerate_$i",
1322 $locale->text('Exchangerate for payment missing!'));
1327 ($form->{AR}) = split /--/, $form->{AR};
1328 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1329 $form->redirect($locale->text(' Payment posted!'))
1330 if (IS->post_payment(\%myconfig, \%$form));
1331 $form->error($locale->text('Cannot post payment!'));
1334 $lxdebug->leave_sub();
1338 $lxdebug->enter_sub();
1339 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1340 $form->isblank("customer", $locale->text('Customer missing!'));
1342 # if oldcustomer ne customer redo form
1343 if (&check_name(customer)) {
1347 if ($form->{second_run}) {
1348 $form->{print_and_post} = 0;
1353 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1354 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1356 $form->error($locale->text('Cannot post invoice for a closed period!'))
1357 if ($invdate <= $closedto);
1359 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1360 if ($form->{currency} ne $form->{defaultcurrency});
1362 for $i (1 .. $form->{paidaccounts}) {
1363 if ($form->{"paid_$i"}) {
1364 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1366 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1368 $form->error($locale->text('Cannot post payment for a closed period!'))
1369 if ($datepaid <= $closedto);
1371 if ($form->{currency} ne $form->{defaultcurrency}) {
1372 $form->{"exchangerate_$i"} = $form->{exchangerate}
1373 if ($invdate == $datepaid);
1374 $form->isblank("exchangerate_$i",
1375 $locale->text('Exchangerate for payment missing!'));
1380 ($form->{AR}) = split /--/, $form->{AR};
1381 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1383 $form->{label} = $locale->text('Invoice');
1385 $form->{id} = 0 if $form->{postasnew};
1387 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1388 if (!$form->{invnumber} || $form->{postasnew}) {
1389 if ($form->{type} eq "credit_note") {
1390 $form->{invnumber} = $form->update_defaults(\%myconfig, "cnnumber");
1392 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
1396 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1397 $form->error($locale->text('Cannot post invoice!'));
1401 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1402 if (IS->post_invoice(\%myconfig, \%$form));
1403 $form->error($locale->text('Cannot post invoice!'));
1406 $lxdebug->leave_sub();
1409 sub print_and_post {
1410 $lxdebug->enter_sub();
1412 $old_form = new Form;
1414 $form->{print_and_post} = 1;
1418 $lxdebug->leave_sub();
1423 $lxdebug->enter_sub();
1425 if ($form->{storno}) {
1426 $form->error($locale->text('Cannot storno storno invoice!'));
1429 $form->{storno_id} = $form->{id};
1430 $form->{storno} = 1;
1432 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1433 $form->{rowcount}--;
1436 $lxdebug->leave_sub();
1441 $lxdebug->enter_sub();
1443 $form->{preview} = 1;
1444 $old_form = new Form;
1445 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1446 $old_form->{rowcount}++;
1448 &print_form($old_form);
1449 $lxdebug->leave_sub();
1454 $lxdebug->enter_sub();
1455 if ($form->{second_run}) {
1456 $form->{print_and_post} = 0;
1463 <form method=post action=$form->{script}>
1466 # delete action variable
1467 map { delete $form->{$_} } qw(action header);
1469 foreach $key (keys %$form) {
1470 $form->{$key} =~ s/\"/"/g;
1471 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1475 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1478 . $locale->text('Are you sure you want to delete Invoice Number')
1479 . qq| $form->{invnumber}
1483 <input name=action class=submit type=submit value="|
1484 . $locale->text('Yes') . qq|">
1488 $lxdebug->leave_sub();
1492 $lxdebug->enter_sub();
1494 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1496 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1499 $form->{rowcount}--;
1500 $form->{shipto} = 1;
1503 $form->{title} = $locale->text('Add Credit Note');
1504 $form->{script} = 'is.pl';
1509 # bo creates the id, reset it
1510 map { delete $form->{$_} }
1511 qw(id invnumber subject message cc bcc printed emailed queued);
1512 $form->{ $form->{vc} } =~ s/--.*//g;
1513 $form->{type} = "credit_note";
1516 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1518 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1519 qw(creditlimit creditremaining);
1521 $currency = $form->{currency};
1524 $form->{currency} = $currency;
1525 $form->{exchangerate} = "";
1526 $form->{forex} = "";
1527 $form->{exchangerate} = $exchangerate
1531 $form->check_exchangerate(
1532 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1535 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1542 $lxdebug->leave_sub();
1546 $lxdebug->enter_sub();
1548 $form->redirect($locale->text('Invoice deleted!'))
1549 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1550 $form->error($locale->text('Cannot delete invoice!'));
1552 $lxdebug->leave_sub();