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";
247 $form->{media} = "screen";
249 $form->{type} = "invoice";
250 $form->{formname} = "invoice";
251 $form->{media} = "screen";
256 map { $form->{$_} =~ s/\"/"/g }
257 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
259 # # get pricegroups for parts
260 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
264 foreach $ref (@{ $form->{invoice_details} }) {
267 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
268 $form->{"discount_$i"} =
269 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
270 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
272 $decimalplaces = ($dec > 2) ? $dec : 2;
274 $form->{"sellprice_$i"} =
275 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
278 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
279 $dec_qty = length $dec_qty;
282 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
284 map { $form->{"${_}_$i"} =~ s/\"/"/g }
285 qw(partnumber description unit partnotes);
286 $form->{rowcount} = $i;
290 $lxdebug->leave_sub();
294 $lxdebug->enter_sub();
298 if ($form->{type} eq "credit_note") {
299 $form->{title} = $locale->text('Edit Credit Note');
301 if ($form->{storno}) {
302 $form->{title} = $locale->text('Edit Storno Credit Note');
305 $form->{title} = $locale->text('Edit Sales Invoice');
307 if ($form->{storno}) {
308 $form->{title} = $locale->text('Edit Storno Invoice');
314 ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
316 $payment = qq|<option value=""></option>|;
317 foreach $item (@{ $form->{payment_terms} }) {
318 if ($form->{payment_id} eq $item->{id}) {
319 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
321 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
325 my $set_duedate_url =
326 "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=set_duedate";
328 my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url );
329 push(@ { $form->{AJAX} }, $pjx);
331 if (@{ $form->{TAXZONE} }) {
332 $form->{selecttaxzone} = "";
333 foreach $item (@{ $form->{TAXZONE} }) {
334 if ($item->{id} == $form->{taxzone_id}) {
335 $form->{selecttaxzone} .=
336 "<option value=$item->{id} selected>" . H($item->{description}) .
339 $form->{selecttaxzone} .=
340 "<option value=$item->{id}>" . H($item->{description}) . "</option>";
345 $form->{selecttaxzone} =~ s/ selected//g;
346 if ($form->{taxzone_id} ne "") {
347 $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/;
353 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
354 <td><select name=taxzone_id>$form->{selecttaxzone}</select></td>
355 <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
359 if (@{ $form->{SHIPTO} }) {
360 $form->{selectshipto} = "<option value=0></option>";
361 foreach $item (@{ $form->{SHIPTO} }) {
362 if ($item->{shipto_id} == $form->{shipto_id}) {
363 $form->{selectshipto} .=
364 "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}</option>";
366 $form->{selectshipto} .=
367 "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment}</option>";
372 $form->{selectshipto} = $form->unquote($form->{selectshipto});
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 $form->{selectshipto} = $form->quote($form->{selectshipto});
383 $shipto .= qq| <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
387 # set option selected
388 foreach $item (qw(AR customer currency department employee)) {
389 $form->{"select$item"} =~ s/ selected//;
390 $form->{"select$item"} =~
391 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
394 #quote customer Bug 133
395 $form->{selectcustomer} = $form->quote($form->{selectcustomer});
398 if ($form->{all_contacts}) {
400 $form->{selectcontact} = "<option></option>";
401 foreach $item (@{ $form->{all_contacts} }) {
402 my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : "";
403 if ($form->{cp_id} == $item->{cp_id}) {
404 $form->{selectcontact} .=
405 "<option value=$item->{cp_id} selected>$item->{cp_name}$department</option>";
407 $form->{selectcontact} .= "<option value=$item->{cp_id}>$item->{cp_name}$department</option>";
411 $form->{selectcontact} =~ s/ selected//g;
412 if ($form->{cp_id} ne "") {
413 $form->{selectcontact} =~ s/value=$form->{cp_id}/value=$form->{cp_id} selected/;
418 if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
424 #else {$form->{all_contacts} = 0;}
426 $form->{exchangerate} =
427 $form->format_amount(\%myconfig, $form->{exchangerate});
429 $form->{creditlimit} =
430 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
431 $form->{creditremaining} =
432 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
435 if ($form->{currency} ne $form->{defaultcurrency}) {
436 if ($form->{forex}) {
439 . $locale->text('Exchangerate')
440 . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
444 . $locale->text('Exchangerate')
445 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
449 <input type=hidden name=forex value=$form->{forex}>
453 ($form->{selectcustomer})
454 ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
455 : qq|<input name=customer value="$form->{customer}" size=35>|;
459 ($form->{selectcontact})
460 ? qq|<select name=cp_id>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
461 : qq|<input name=contact value="$form->{contact}" size=35>|;
465 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
466 <td colspan=3><select name=department>$form->{selectdepartment}</select>
467 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
470 | if $form->{selectdepartment};
472 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
474 if ($form->{business}) {
477 <th align=right>| . $locale->text('Business') . qq|</th>
478 <td>$form->{business}</td>
479 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
481 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
487 if ($form->{max_dunning_level}) {
493 <th align=right>| . $locale->text('Max. Dunning Level') . qq|:</th>
494 <td><b>$form->{max_dunning_level}</b></td>
495 <th align=right>| . $locale->text('Dunning Amount') . qq|:</th>
497 . $form->format_amount(\%myconfig, $form->{dunning_amount},2)
506 $form->{fokus} = "invoice.customer";
508 # use JavaScript Calendar or not
509 $form->{jsscript} = $jscalendar;
511 if ($form->{type} eq "credit_note") {
512 if ($form->{jsscript}) {
514 # with JavaScript Calendar
516 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
517 <td><input type=button name=invdate id="trigger1" value=|
518 . $locale->text('button') . qq|></td>
523 Form->write_trigger(\%myconfig, "1",
528 # without JavaScript Calendar
530 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
532 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
535 if ($form->{jsscript}) {
537 # with JavaScript Calendar
539 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
540 <td><input type=button name=invdate id="trigger1" value=|
541 . $locale->text('button') . qq|></td>
544 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
545 <td width="4"><input type=button name=duedate id="trigger2" value=|
546 . $locale->text('button') . qq|></td></td>
549 <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
550 <td width="4"><input type=button name=deliverydate id="trigger3" value=|
551 . $locale->text('button') . qq|></td></td>
556 Form->write_trigger(\%myconfig, "3",
558 "trigger1", "duedate",
560 "deliverydate", "BL",
564 # without JavaScript Calendar
566 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
568 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
571 if ($form->{resubmit} && ($form->{format} eq "html")) {
573 qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
574 } elsif ($form->{resubmit}) {
575 $onload = qq|document.invoice.submit()|;
580 $credittext = $locale->text('Credit Limit exceeded!!!');
581 if ($creditwarning) {
582 $onload = qq|alert('$credittext')|;
588 <body onLoad="$onload">
589 <script type="text/javascript" src="js/common.js"></script>
590 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
591 <script type="text/javascript" src="js/vendor_selection.js"></script>
592 <script type="text/javascript" src="js/calculate_qty.js"></script>
594 <form method=post name="invoice" action=$form->{script}>
597 <input type=hidden name=id value=$form->{id}>
598 <input type=hidden name=action value=$form->{action}>
600 <input type=hidden name=type value=$form->{type}>
601 <input type=hidden name=media value=$form->{media}>
602 <input type=hidden name=format value=$form->{format}>
604 <input type=hidden name=queued value="$form->{queued}">
605 <input type=hidden name=printed value="$form->{printed}">
606 <input type=hidden name=emailed value="$form->{emailed}">
608 <input type=hidden name=title value="$form->{title}">
609 <input type=hidden name=vc value=$form->{vc}>
611 <input type=hidden name=discount value=$form->{discount}>
612 <input type=hidden name=creditlimit value=$form->{creditlimit}>
613 <input type=hidden name=creditremaining value=$form->{creditremaining}>
615 <input type=hidden name=tradediscount value=$form->{tradediscount}>
616 <input type=hidden name=business value=$form->{business}>
618 <input type=hidden name=closedto value=$form->{closedto}>
619 <input type=hidden name=locked value=$form->{locked}>
621 <input type=hidden name=shipped value=$form->{shipped}>
622 <input type=hidden name=lizenzen value=$lizenzen>
623 <input type=hidden name=storno value=$form->{storno}>
624 <input type=hidden name=storno_id value=$form->{storno_id}>
630 <th class=listtop>$form->{title}</th>
640 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
641 <td colspan=3>$customer</td>
642 <input type=hidden name=customer_klass value=$form->{customer_klass}>
643 <input type=hidden name=customer_id value=$form->{customer_id}>
644 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
645 <th align=richt nowrap>|
646 . $locale->text('Contact Person') . qq|</th>
647 <td colspan=3>$contact</td>
654 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
655 <td>$form->{creditlimit}</td>
657 <th nowrap>| . $locale->text('Remaining') . qq|</th>
658 <td class="plus$n">$form->{creditremaining}</td>
667 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
668 <td colspan=3><select name=AR style="width:280px;">$form->{selectAR}</select></td>
669 <input type=hidden name=selectAR value="$form->{selectAR}">
674 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
675 <td><select name=currency>$form->{selectcurrency}</select></td>
676 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
677 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
678 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
679 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
683 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
684 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
687 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
688 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
695 # <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
697 # <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
698 # <input size=45 id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
702 # <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
704 # <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
705 # <input size=45 id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
715 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
716 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
717 <input type=hidden name=selectemployee value="$form->{selectemployee}">
720 if ($form->{type} eq "credit_note") {
722 <th align=right nowrap>| . $locale->text('Credit Note Number') . qq|</th>
723 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
726 <th align=right>| . $locale->text('Credit Note Date') . qq|</th>
731 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
732 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
735 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
739 <th align=right>| . $locale->text('Due Date') . qq|</th>
743 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
748 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
749 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
752 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
753 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
756 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
757 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
772 <!-- shipto are in hidden variables -->
774 <input type=hidden name=shiptoname value="$form->{shiptoname}">
775 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
776 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
777 <input type=hidden name=shiptocity value="$form->{shiptocity}">
778 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
779 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
780 <input type=hidden name=shiptophone value="$form->{shiptophone}">
781 <input type=hidden name=shiptofax value="$form->{shiptofax}">
782 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
784 <!-- email variables -->
785 <input type=hidden name=message value="$form->{message}">
786 <input type=hidden name=email value="$form->{email}">
787 <input type=hidden name=subject value="$form->{subject}">
788 <input type=hidden name=cc value="$form->{cc}">
789 <input type=hidden name=bcc value="$form->{bcc}">
790 <input type=hidden name=webdav value=$webdav>
791 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
794 foreach $item (split / /, $form->{taxaccounts}) {
796 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
797 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
798 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
801 $lxdebug->leave_sub();
805 $lxdebug->enter_sub();
807 $form->{invtotal} = $form->{invsubtotal};
809 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
812 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
815 $rows = ($rows > $introws) ? $rows : $introws;
817 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
819 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
821 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
824 if ($form->{taxaccounts}) {
826 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
827 . $locale->text('Tax Included') . qq|</b><br><br>|;
830 if (!$form->{taxincluded}) {
832 foreach $item (split / /, $form->{taxaccounts}) {
833 if ($form->{"${item}_base"}) {
834 $form->{"${item}_total"} =
836 $form->{"${item}_base"} * $form->{"${item}_rate"},
838 $form->{invtotal} += $form->{"${item}_total"};
839 $form->{"${item}_total"} =
840 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
844 <th align=right>$form->{"${item}_description"}</th>
845 <td align=right>$form->{"${item}_total"}</td>
851 $form->{invsubtotal} =
852 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
856 <th align=right>| . $locale->text('Subtotal') . qq|</th>
857 <td align=right>$form->{invsubtotal}</td>
863 if ($form->{taxincluded}) {
864 foreach $item (split / /, $form->{taxaccounts}) {
865 if ($form->{"${item}_base"}) {
866 $form->{"${item}_total"} =
868 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
869 (1 + $form->{"${item}_rate"})
872 $form->{"${item}_netto"} =
874 ($form->{"${item}_base"} - $form->{"${item}_total"}),
876 $form->{"${item}_total"} =
877 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
878 $form->{"${item}_netto"} =
879 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
883 <th align=right>Enthaltene $form->{"${item}_description"}</th>
884 <td align=right>$form->{"${item}_total"}</td>
887 <th align=right>Nettobetrag</th>
888 <td align=right>$form->{"${item}_netto"}</td>
896 $form->{oldinvtotal} = $form->{invtotal};
898 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
908 <th align=left>| . $locale->text('Notes') . qq|</th>
909 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
910 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
915 <td><select name=payment_id onChange="set_duedate(['payment_id__' + this.value],['duedate'])">$payment
920 <td align=right width=100%>
926 <th align=right>| . $locale->text('Total') . qq|</th>
927 <td align=right>$form->{invtotal}</td>
939 <td><hr size=3 noshade></td>
942 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
945 <td align=left width=30%><b>Dateiname</b></td>
946 <td align=left width=70%><b>Webdavlink</b></td>
948 foreach $file (keys %{ $form->{WEBDAV} }) {
951 <td align=left>$file</td>
952 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
963 if ($form->{type} eq "credit_note") {
968 <tr class=listheading>
969 <th colspan=6 class=listheading>|
970 . $locale->text('Payments') . qq|</th>
978 <tr class=listheading>
979 <th colspan=6 class=listheading>|
980 . $locale->text('Incoming Payments') . qq|</th>
985 if ($form->{currency} eq $form->{defaultcurrency}) {
986 @column_index = qw(datepaid source memo paid AR_paid);
988 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
991 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
992 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
993 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
994 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
995 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
996 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
1001 map { print "$column_data{$_}\n" } @column_index;
1008 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
1009 for $i (1 .. $form->{paidaccounts}) {
1014 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
1015 $form->{"selectAR_paid_$i"} =~
1016 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
1019 $totalpaid += $form->{"paid_$i"};
1020 if ($form->{"paid_$i"}) {
1021 $form->{"paid_$i"} =
1022 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
1024 $form->{"exchangerate_$i"} =
1025 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
1027 $exchangerate = qq| |;
1028 if ($form->{currency} ne $form->{defaultcurrency}) {
1029 if ($form->{"forex_$i"}) {
1031 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
1034 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
1038 $exchangerate .= qq|
1039 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
1042 $column_data{"paid_$i"} =
1043 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
1044 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
1045 $column_data{"AR_paid_$i"} =
1046 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
1047 $column_data{"datepaid_$i"} =
1048 qq|<td align=center><input id="datepaid_$i" name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}>
1049 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
1050 $column_data{"source_$i"} =
1051 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
1052 $column_data{"memo_$i"} =
1053 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
1055 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
1058 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
1062 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
1063 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
1064 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
1065 <input type=hidden name=oldtotalpaid value=$totalpaid>
1070 <td><hr size=3 noshade></td>
1084 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1085 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1089 <input class=submit type=submit accesskey="u" name=action value="|
1090 . $locale->text('Update') . qq|">
1091 <input class=submit type=submit name=action value="|
1092 . $locale->text('Ship to') . qq|">
1093 <input class=submit type=submit name=action value="|
1094 . $locale->text('Print') . qq|">
1095 <input class=submit type=submit name=action value="|
1096 . $locale->text('E-mail') . qq|">|;
1097 print qq|<input class=submit type=submit name=action value="|
1098 . $locale->text('Storno') . qq|">| unless ($form->{storno});
1099 print qq|<input class=submit type=submit name=action value="|
1100 . $locale->text('Post Payment') . qq|">
1102 print qq|<input class=submit type=submit name=action value="|
1103 . $locale->text('Use As Template') . qq|">
1105 if ($form->{id} && !($form->{type} eq "credit_note")) {
1107 <input class=submit type=submit name=action value="|
1108 . $locale->text('Credit Note') . qq|">
1111 if ($form->{radier}) {
1113 <input class=submit type=submit name=action value="|
1114 . $locale->text('Delete') . qq|">
1119 if ($invdate > $closedto) {
1121 <input class=submit type=submit name=action value="|
1122 . $locale->text('Order') . qq|">
1127 if ($invdate > $closedto) {
1128 print qq|<input class=submit type=submit name=action value="|
1129 . $locale->text('Update') . qq|">
1130 <input class=submit type=submit name=action value="|
1131 . $locale->text('Ship to') . qq|">
1132 <input class=submit type=submit name=action value="|
1133 . $locale->text('Preview') . qq|">
1134 <input class=submit type=submit name=action value="|
1135 . $locale->text('E-mail') . qq|">
1136 <input class=submit type=submit name=action value="|
1137 . $locale->text('Print and Post') . qq|">
1138 <input class=submit type=submit name=action value="|
1139 . $locale->text('Post') . qq|">|;
1143 if ($form->{menubar}) {
1144 require "$form->{path}/menu.pl";
1148 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) .
1151 <input type=hidden name=rowcount value=$form->{rowcount}>
1153 <input name=callback type=hidden value="$form->{callback}">
1155 <input type=hidden name=path value=$form->{path}>
1156 <input type=hidden name=login value=$form->{login}>
1157 <input type=hidden name=password value=$form->{password}>
1166 $lxdebug->leave_sub();
1170 $lxdebug->enter_sub();
1172 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1173 qw(exchangerate creditlimit creditremaining);
1174 if ($form->{second_run}) {
1175 $form->{print_and_post} = 0;
1178 $form->{update} = 1;
1180 &check_name(customer);
1184 $form->{exchangerate} = $exchangerate
1188 $form->check_exchangerate(
1189 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
1192 for $i (1 .. $form->{paidaccounts}) {
1193 if ($form->{"paid_$i"}) {
1195 $form->{"${_}_$i"} =
1196 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
1197 } qw(paid exchangerate);
1199 $form->{"exchangerate_$i"} = $exchangerate
1201 $form->{"forex_$i"} = (
1203 $form->check_exchangerate(
1204 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
1209 $i = $form->{rowcount};
1210 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
1212 # if last row empty, check the form otherwise retrieve new item
1213 if ( ($form->{"partnumber_$i"} eq "")
1214 && ($form->{"description_$i"} eq "")
1215 && ($form->{"partsgroup_$i"} eq "")) {
1217 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
1222 IS->retrieve_item(\%myconfig, \%$form);
1224 $rows = scalar @{ $form->{item_list} };
1226 $form->{"discount_$i"} =
1227 $form->format_amount(\%myconfig, $form->{discount} * 100);
1230 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
1239 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
1241 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
1242 qw(partnumber description unit);
1243 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
1244 keys %{ $form->{item_list}[0] };
1245 if ($form->{"part_payment_id_$i"} ne "") {
1246 $form->{payment_id} = $form->{"part_payment_id_$i"};
1249 if ($form->{"not_discountable_$i"}) {
1250 $form->{"discount_$i"} = 0;
1253 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1254 ($dec) = ($s =~ /\.(\d+)/);
1256 $decimalplaces = ($dec > 2) ? $dec : 2;
1259 $form->{"sellprice_$i"} = $sellprice;
1262 # if there is an exchange rate adjust sellprice
1263 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1264 $form->{"sellprice_$i"} /= $exchangerate;
1267 $form->{"listprice_$i"} /= $exchangerate;
1270 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1271 (1 - $form->{"discount_$i"} / 100);
1272 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1273 map { $form->{"${_}_base"} += $amount }
1274 (split / /, $form->{"taxaccounts_$i"});
1275 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1276 split / /, $form->{"taxaccounts_$i"}
1277 if !$form->{taxincluded};
1279 $form->{creditremaining} -= $amount;
1282 $form->{"${_}_$i"} =
1283 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
1285 } qw(sellprice listprice);
1288 $form->format_amount(\%myconfig, $form->{"qty_$i"});
1291 if ($form->{"inventory_accno_$i"} ne "") {
1292 $form->{"lizenzen_$i"} = qq|<option></option>|;
1293 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1294 $form->{"lizenzen_$i"} .=
1295 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1297 $form->{"lizenzen_$i"} .=
1298 qq|<option value=-1>Neue Lizenz</option>|;
1302 # get pricegroups for parts
1303 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1305 # build up html code for prices_$i
1306 &set_pricegroup($i);
1313 # ok, so this is a new part
1314 # ask if it is a part or service item
1316 if ( $form->{"partsgroup_$i"}
1317 && ($form->{"partsnumber_$i"} eq "")
1318 && ($form->{"description_$i"} eq "")) {
1319 $form->{rowcount}--;
1320 $form->{"discount_$i"} = "";
1324 $form->{"id_$i"} = 0;
1325 $form->{"unit_$i"} = $locale->text('ea');
1332 $lxdebug->leave_sub();
1335 $lxdebug->enter_sub();
1336 for $i (1 .. $form->{paidaccounts}) {
1337 if ($form->{"paid_$i"}) {
1338 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1340 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1342 $form->error($locale->text('Cannot post payment for a closed period!'))
1343 if ($datepaid <= $closedto);
1345 if ($form->{currency} ne $form->{defaultcurrency}) {
1346 $form->{"exchangerate_$i"} = $form->{exchangerate}
1347 if ($invdate == $datepaid);
1348 $form->isblank("exchangerate_$i",
1349 $locale->text('Exchangerate for payment missing!'));
1354 ($form->{AR}) = split /--/, $form->{AR};
1355 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1357 $form->redirect($locale->text(' Payment posted!'))
1358 if (IS->post_payment(\%myconfig, \%$form));
1359 $form->error($locale->text('Cannot post payment!'));
1362 $lxdebug->leave_sub();
1366 $lxdebug->enter_sub();
1367 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1368 $form->isblank("customer", $locale->text('Customer missing!'));
1370 # if oldcustomer ne customer redo form
1371 if (&check_name(customer)) {
1375 if ($form->{second_run}) {
1376 $form->{print_and_post} = 0;
1381 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1382 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1384 $form->error($locale->text('Cannot post invoice for a closed period!'))
1385 if ($invdate <= $closedto);
1387 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1388 if ($form->{currency} ne $form->{defaultcurrency});
1390 for $i (1 .. $form->{paidaccounts}) {
1391 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1392 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1394 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1396 $form->error($locale->text('Cannot post payment for a closed period!'))
1397 if ($datepaid <= $closedto);
1399 if ($form->{currency} ne $form->{defaultcurrency}) {
1400 $form->{"exchangerate_$i"} = $form->{exchangerate}
1401 if ($invdate == $datepaid);
1402 $form->isblank("exchangerate_$i",
1403 $locale->text('Exchangerate for payment missing!'));
1408 ($form->{AR}) = split /--/, $form->{AR};
1409 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1411 $form->{label} = $locale->text('Invoice');
1413 $form->{id} = 0 if $form->{postasnew};
1415 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1416 if (!$form->{invnumber} || $form->{postasnew}) {
1417 if ($form->{type} eq "credit_note") {
1418 $form->{invnumber} = $form->update_defaults(\%myconfig, "cnnumber");
1420 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
1425 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1426 $form->error($locale->text('Cannot post invoice!'));
1430 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1431 if (IS->post_invoice(\%myconfig, \%$form));
1432 $form->error($locale->text('Cannot post invoice!'));
1435 $lxdebug->leave_sub();
1438 sub print_and_post {
1439 $lxdebug->enter_sub();
1441 $old_form = new Form;
1443 $form->{print_and_post} = 1;
1447 $lxdebug->leave_sub();
1451 sub use_as_template {
1452 $lxdebug->enter_sub();
1454 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);
1455 $form->{paidaccounts} = 1;
1456 $form->{rowcount}--;
1457 $form->{invdate} = $form->current_date(\%myconfig);
1460 $lxdebug->leave_sub();
1464 $lxdebug->enter_sub();
1466 if ($form->{storno}) {
1467 $form->error($locale->text('Cannot storno storno invoice!'));
1470 $form->{storno_id} = $form->{id};
1471 $form->{storno} = 1;
1473 $form->{invnumber} = "Storno zu " . $form->{invnumber};
1476 $lxdebug->leave_sub();
1481 $lxdebug->enter_sub();
1483 $form->{preview} = 1;
1484 $old_form = new Form;
1485 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1486 $old_form->{rowcount}++;
1488 &print_form($old_form);
1489 $lxdebug->leave_sub();
1494 $lxdebug->enter_sub();
1495 if ($form->{second_run}) {
1496 $form->{print_and_post} = 0;
1503 <form method=post action=$form->{script}>
1506 # delete action variable
1507 map { delete $form->{$_} } qw(action header);
1509 foreach $key (keys %$form) {
1510 $form->{$key} =~ s/\"/"/g;
1511 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1515 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1518 . $locale->text('Are you sure you want to delete Invoice Number')
1519 . qq| $form->{invnumber}
1523 <input name=action class=submit type=submit value="|
1524 . $locale->text('Yes') . qq|">
1528 $lxdebug->leave_sub();
1532 $lxdebug->enter_sub();
1534 $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
1536 $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
1539 $form->{rowcount}--;
1540 $form->{shipto} = 1;
1543 $form->{title} = $locale->text('Add Credit Note');
1544 $form->{script} = 'is.pl';
1549 # bo creates the id, reset it
1550 map { delete $form->{$_} }
1551 qw(id invnumber subject message cc bcc printed emailed queued);
1552 $form->{ $form->{vc} } =~ s/--.*//g;
1553 $form->{type} = "credit_note";
1556 map { $form->{"select$_"} = "" } ($form->{vc}, currency);
1558 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
1559 qw(creditlimit creditremaining);
1561 $currency = $form->{currency};
1564 $form->{currency} = $currency;
1565 $form->{exchangerate} = "";
1566 $form->{forex} = "";
1567 $form->{exchangerate} = $exchangerate
1571 $form->check_exchangerate(
1572 \%myconfig, $form->{currency}, $form->{invdate}, $buysell
1575 $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
1582 $lxdebug->leave_sub();
1586 $lxdebug->enter_sub();
1588 $form->redirect($locale->text('Invoice deleted!'))
1589 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1590 $form->error($locale->text('Cannot delete invoice!'));
1592 $lxdebug->leave_sub();