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 $form->{title} = $locale->text('Add Credit Note');
51 "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
52 unless $form->{callback};
54 $form{jsscript} = "date";
59 $form->{format} = "pdf";
63 $lxdebug->leave_sub();
67 $lxdebug->enter_sub();
69 $form->{title} = $locale->text('Edit Credit Note');
72 if ($form->{print_and_post}) {
73 $form->{action} = "print";
74 $form->{resubmit} = 1;
80 $lxdebug->leave_sub();
83 sub credit_note_links {
84 $lxdebug->enter_sub();
86 $form->{vc} = 'customer';
89 $form->{webdav} = $webdav;
90 $form->{lizenzen} = $lizenzen;
92 $form->create_links("AR", \%myconfig, "customer");
94 if ($form->{all_customer}) {
95 unless ($form->{customer_id}) {
96 $form->{customer_id} = $form->{all_customer}->[0]->{id};
100 if ($form->{payment_id}) {
101 $payment_id = $form->{payment_id};
103 if ($form->{language_id}) {
104 $language_id = $form->{language_id};
107 $cp_id = $form->{cp_id};
108 IS->get_customer(\%myconfig, \%$form);
110 IS->retrieve_invoice(\%myconfig, \%$form);
111 $form->{cp_id} = $cp_id;
114 $form->{payment_id} = $payment_id;
117 $form->{language_id} = $language_id;
121 @curr = split /:/, $form->{currencies};
123 $form->{defaultcurrency} = $curr[0];
125 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
127 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
129 if ($form->{all_customer}) {
130 $form->{customer} = "$form->{customer}--$form->{customer_id}";
131 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
132 (@{ $form->{all_customer} });
136 if ($form->{all_departments}) {
137 $form->{selectdepartment} = "<option>\n";
138 $form->{department} = "$form->{department}--$form->{department_id}";
141 $form->{selectdepartment} .=
142 "<option>$_->{description}--$_->{id}\n"
143 } (@{ $form->{all_departments} });
146 $form->{employee} = "$form->{employee}--$form->{employee_id}";
149 if ($form->{all_employees}) {
150 $form->{selectemployee} = "";
151 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
152 (@{ $form->{all_employees} });
156 $form->{forex} = $form->{exchangerate};
157 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
159 foreach $key (keys %{ $form->{AR_links} }) {
160 foreach $ref (@{ $form->{AR_links}{$key} }) {
161 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
164 if ($key eq "AR_paid") {
165 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
166 $form->{"AR_paid_$i"} =
167 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
170 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
171 $form->{"datepaid_$i"} =
172 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
173 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
174 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
175 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
176 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
178 $form->{paidaccounts} = $i;
182 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
187 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
189 $form->{AR} = $form->{AR_1} unless $form->{id};
192 ($form->datetonum($form->{invdate}, \%myconfig) <=
193 $form->datetonum($form->{closedto}, \%myconfig));
195 $lxdebug->leave_sub();
198 sub prepare_credit_note {
199 $lxdebug->enter_sub();
201 $form->{type} = "credit_note";
202 $form->{formname} = "credit_note";
203 $form->{media} = "screen";
207 map { $form->{$_} =~ s/\"/"/g }
208 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
210 # # get pricegroups for parts
211 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
213 foreach $ref (@{ $form->{invoice_details} }) {
215 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
216 $form->{"discount_$i"} =
217 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
218 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
220 $decimalplaces = ($dec > 2) ? $dec : 2;
222 $form->{"sellprice_$i"} =
223 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
226 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
227 $dec_qty = length $dec_qty;
230 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
232 map { $form->{"${_}_$i"} =~ s/\"/"/g }
233 qw(partnumber description unit partnotes);
234 $form->{rowcount} = $i;
238 $lxdebug->leave_sub();
242 $lxdebug->enter_sub();
244 $payment = qq|<option value=""></option>|;
245 foreach $item (@{ $form->{payment_terms} }) {
246 if ($form->{payment_id} eq $item->{id}) {
247 $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
249 $payment .= qq|<option value="$item->{id}">$item->{description}</option>|;
253 # set option selected
254 foreach $item (qw(AR customer currency department employee contact)) {
255 $form->{"select$item"} =~ s/ selected//;
256 $form->{"select$item"} =~
257 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
261 if ($form->{all_contacts}) {
263 $form->{selectcontact} = "";
264 foreach $item (@{ $form->{all_contacts} }) {
265 if ($form->{cp_id} == $item->{cp_id}) {
266 $form->{selectcontact} .=
267 "<option selected>$item->{cp_name}--$item->{cp_id}";
269 $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
274 #else {$form->{all_contacts} = 0;}
276 $form->{exchangerate} =
277 $form->format_amount(\%myconfig, $form->{exchangerate});
279 $form->{creditlimit} =
280 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
281 $form->{creditremaining} =
282 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
285 if ($form->{currency} ne $form->{defaultcurrency}) {
286 if ($form->{forex}) {
289 . $locale->text('Exchangerate')
290 . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
294 . $locale->text('Exchangerate')
295 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
299 <input type=hidden name=forex value=$form->{forex}>
303 ($form->{selectcustomer})
304 ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
305 : qq|<input name=customer value="$form->{customer}" size=35>|;
309 ($form->{selectcontact})
310 ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
311 : qq|<input name=contact value="$form->{contact}" size=35>|;
315 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
316 <td colspan=3><select name=department>$form->{selectdepartment}</select>
317 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
320 | if $form->{selectdepartment};
322 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
324 if ($form->{business}) {
327 <th align=right>| . $locale->text('Business') . qq|</th>
328 <td>$form->{business}</td>
329 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
331 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
337 $form->{fokus} = "invoice.customer";
339 # use JavaScript Calendar or not
340 $form->{jsscript} = $jscalendar;
342 if ($form->{jsscript}) {
344 # with JavaScript Calendar
346 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
347 <td><input type=button name=invdate id="trigger1" value=|
348 . $locale->text('button') . qq|></td>
351 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
352 <td width="4"><input type=button name=duedate id="trigger2" value=|
353 . $locale->text('button') . qq|></td></td>
356 <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
357 <td width="4"><input type=button name=deliverydate id="trigger3" value=|
358 . $locale->text('button') . qq|></td></td>
363 Form->write_trigger(\%myconfig, "3",
365 "trigger1", "duedate",
367 "deliverydate", "BL",
371 # without JavaScript Calendar
373 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
375 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
377 if ($form->{resubmit} && ($form->{format} eq "html")) {
379 qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
380 } elsif ($form->{resubmit}) {
381 $onload = qq|document.invoice.submit()|;
388 <body onLoad="$onload">
389 <script type="text/javascript" src="js/common.js"></script>
390 <script type="text/javascript" src="js/delivery_customer_selection.js"></script>
391 <script type="text/javascript" src="js/vendor_selection.js"></script>
392 <script type="text/javascript" src="js/calculate_qty.js"></script>
394 <form method=post name="invoice" action=$form->{script}>
397 <input type=hidden name=id value=$form->{id}>
398 <input type=hidden name=action value=$form->{action}>
400 <input type=hidden name=type value=$form->{type}>
401 <input type=hidden name=media value=$form->{media}>
402 <input type=hidden name=format value=$form->{format}>
404 <input type=hidden name=queued value="$form->{queued}">
405 <input type=hidden name=printed value="$form->{printed}">
406 <input type=hidden name=emailed value="$form->{emailed}">
408 <input type=hidden name=title value="$form->{title}">
409 <input type=hidden name=vc value=$form->{vc}>
411 <input type=hidden name=discount value=$form->{discount}>
412 <input type=hidden name=creditlimit value=$form->{creditlimit}>
413 <input type=hidden name=creditremaining value=$form->{creditremaining}>
415 <input type=hidden name=tradediscount value=$form->{tradediscount}>
416 <input type=hidden name=business value=$form->{business}>
418 <input type=hidden name=closedto value=$form->{closedto}>
419 <input type=hidden name=locked value=$form->{locked}>
421 <input type=hidden name=shipped value=$form->{shipped}>
422 <input type=hidden name=lizenzen value=$lizenzen>
426 <th class=listtop>$form->{title}</th>
436 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
437 <td colspan=3>$customer</td>
438 <input type=hidden name=customer_klass value=$form->{customer_klass}>
439 <input type=hidden name=customer_id value=$form->{customer_id}>
440 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
441 <th align=richt nowrap>|
442 . $locale->text('Contact Person') . qq|</th>
443 <td colspan=3>$contact</td>
450 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
451 <td>$form->{creditlimit}</td>
453 <th nowrap>| . $locale->text('Remaining') . qq|</th>
454 <td class="plus$n">$form->{creditremaining}</td>
461 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
462 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
463 <input type=hidden name=selectAR value="$form->{selectAR}">
467 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
468 <td><select name=currency>$form->{selectcurrency}</select></td>
469 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
470 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
471 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
472 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
476 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
477 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
480 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
481 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
488 <button type="button" onclick="delivery_customer_selection_window('delivery_customer_string','delivery_customer_id')">| . $locale->text('Choose Customer') . qq|</button>
490 <td colspan=2><input type=hidden name=delivery_customer_id value="$form->{delivery_customer_id}">
491 <input id=delivery_customer_string name=delivery_customer_string value="$form->{delivery_customer_string}"></td>
495 <button type="button" onclick="vendor_selection_window('delivery_vendor_string','delivery_vendor_id')">| . $locale->text('Choose Vendor') . qq|</button>
497 <td colspan=2><input type=hidden name=delivery_vendor_id value="$form->{delivery_vendor_id}">
498 <input id=delivery_vendor_string name=delivery_vendor_string value="$form->{delivery_vendor_string}"></td>
508 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
509 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
510 <input type=hidden name=selectemployee value="$form->{selectemployee}">
514 <th align=right nowrap>| . $locale->text('Credit Note Number') . qq|</th>
515 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
518 <th align=right>| . $locale->text('Credit Note Date') . qq|</th>
522 <th align=right>| . $locale->text('Due Date') . qq|</th>
526 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
530 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
531 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
534 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
535 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
538 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
539 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
554 <!-- shipto are in hidden variables -->
556 <input type=hidden name=shiptoname value="$form->{shiptoname}">
557 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
558 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
559 <input type=hidden name=shiptocity value="$form->{shiptocity}">
560 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
561 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
562 <input type=hidden name=shiptophone value="$form->{shiptophone}">
563 <input type=hidden name=shiptofax value="$form->{shiptofax}">
564 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
566 <!-- email variables -->
567 <input type=hidden name=message value="$form->{message}">
568 <input type=hidden name=email value="$form->{email}">
569 <input type=hidden name=subject value="$form->{subject}">
570 <input type=hidden name=cc value="$form->{cc}">
571 <input type=hidden name=bcc value="$form->{bcc}">
572 <input type=hidden name=webdav value=$webdav>
573 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
576 foreach $item (split / /, $form->{taxaccounts}) {
578 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
579 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
580 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
583 $lxdebug->leave_sub();
587 $lxdebug->enter_sub();
589 $form->{invtotal} = $form->{invsubtotal};
591 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
594 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
597 $rows = ($rows > $introws) ? $rows : $introws;
599 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
601 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
603 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
606 if ($form->{taxaccounts}) {
608 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
609 . $locale->text('Tax Included') . qq|</b><br><br>|;
612 if (!$form->{taxincluded}) {
614 foreach $item (split / /, $form->{taxaccounts}) {
615 if ($form->{"${item}_base"}) {
616 $form->{"${item}_total"} =
618 $form->{"${item}_base"} * $form->{"${item}_rate"},
620 $form->{invtotal} += $form->{"${item}_total"};
621 $form->{"${item}_total"} =
622 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
626 <th align=right>$form->{"${item}_description"}</th>
627 <td align=right>$form->{"${item}_total"}</td>
633 $form->{invsubtotal} =
634 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
638 <th align=right>| . $locale->text('Subtotal') . qq|</th>
639 <td align=right>$form->{invsubtotal}</td>
645 if ($form->{taxincluded}) {
646 foreach $item (split / /, $form->{taxaccounts}) {
647 if ($form->{"${item}_base"}) {
648 $form->{"${item}_total"} =
650 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
651 (1 + $form->{"${item}_rate"})
654 $form->{"${item}_netto"} =
656 ($form->{"${item}_base"} - $form->{"${item}_total"}),
658 $form->{"${item}_total"} =
659 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
660 $form->{"${item}_netto"} =
661 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
665 <th align=right>Enthaltene $form->{"${item}_description"}</th>
666 <td align=right>$form->{"${item}_total"}</td>
669 <th align=right>Nettobetrag</th>
670 <td align=right>$form->{"${item}_netto"}</td>
678 $form->{oldinvtotal} = $form->{invtotal};
680 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
690 <th align=left>| . $locale->text('Notes') . qq|</th>
691 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
692 <th align=right>| . $locale->text('Payment Terms') . qq|</th>
697 <td><select name=payment_id tabindex=24>$payment
702 <td align=right width=100%>
708 <th align=right>| . $locale->text('Total') . qq|</th>
709 <td align=right>$form->{invtotal}</td>
721 <td><hr size=3 noshade></td>
724 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
727 <td align=left width=30%><b>Dateiname</b></td>
728 <td align=left width=70%><b>Webdavlink</b></td>
730 foreach $file (keys %{ $form->{WEBDAV} }) {
733 <td align=left>$file</td>
734 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
749 <tr class=listheading>
750 <th colspan=6 class=listheading>|
751 . $locale->text('Incoming Payments') . qq|</th>
755 if ($form->{currency} eq $form->{defaultcurrency}) {
756 @column_index = qw(datepaid source memo paid AR_paid);
758 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
761 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
762 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
763 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
764 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
765 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
766 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
771 map { print "$column_data{$_}\n" } @column_index;
776 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
777 for $i (1 .. $form->{paidaccounts}) {
782 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
783 $form->{"selectAR_paid_$i"} =~
784 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
787 $totalpaid += $form->{"paid_$i"};
789 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
790 $form->{"exchangerate_$i"} =
791 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
793 $exchangerate = qq| |;
794 if ($form->{currency} ne $form->{defaultcurrency}) {
795 if ($form->{"forex_$i"}) {
797 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
800 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
805 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
808 $column_data{"paid_$i"} =
809 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
810 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
811 $column_data{"AR_paid_$i"} =
812 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
813 $column_data{"datepaid_$i"} =
814 qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
815 $column_data{"source_$i"} =
816 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
817 $column_data{"memo_$i"} =
818 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
820 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
826 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
827 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
828 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
829 <input type=hidden name=oldtotalpaid value=$totalpaid>
834 <td><hr size=3 noshade></td>
848 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
849 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
853 <input class=submit type=submit name=action value="|
854 . $locale->text('Update') . qq|">
855 <input class=submit type=submit name=action value="|
856 . $locale->text('Ship to') . qq|">
857 <input class=submit type=submit name=action value="|
858 . $locale->text('Print') . qq|">
859 <input class=submit type=submit name=action value="|
860 . $locale->text('E-mail') . qq|">
863 if (!$form->{revtrans}) {
864 if (!$form->{locked}) {
866 <input class=submit type=submit name=action value="|
867 . $locale->text('Post') . qq|">
868 <input class=submit type=submit name=action value="|
869 . $locale->text('Delete') . qq|">
874 if ($invdate > $closedto) {
876 <input class=submit type=submit name=action value="|
877 . $locale->text('Post as new') . qq|">
878 <input class=submit type=submit name=action value="|
879 . $locale->text('Order') . qq|">
884 if ($invdate > $closedto) {
885 print qq|<input class=submit type=submit name=action value="|
886 . $locale->text('Update') . qq|">
887 <input class=submit type=submit name=action value="|
888 . $locale->text('Ship to') . qq|">
889 <input class=submit type=submit name=action value="|
890 . $locale->text('Preview') . qq|">
891 <input class=submit type=submit name=action value="|
892 . $locale->text('E-mail') . qq|">
893 <input class=submit type=submit name=action value="|
894 . $locale->text('Print and Post') . qq|">
895 <input class=submit type=submit name=action value="|
896 . $locale->text('Post') . qq|">|;
902 <input type=hidden name=rowcount value=$form->{rowcount}>
904 <input name=callback type=hidden value="$form->{callback}">
906 <input type=hidden name=path value=$form->{path}>
907 <input type=hidden name=login value=$form->{login}>
908 <input type=hidden name=password value=$form->{password}>
917 $lxdebug->leave_sub();
921 $lxdebug->enter_sub();
923 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
924 qw(exchangerate creditlimit creditremaining);
925 if ($form->{second_run}) {
926 $form->{print_and_post} = 0;
928 &check_name(customer);
932 $form->{exchangerate} = $exchangerate
936 $form->check_exchangerate(
937 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
940 for $i (1 .. $form->{paidaccounts}) {
941 if ($form->{"paid_$i"}) {
944 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
945 } qw(paid exchangerate);
947 $form->{"exchangerate_$i"} = $exchangerate
949 $form->{"forex_$i"} = (
951 $form->check_exchangerate(
952 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
957 $i = $form->{rowcount};
958 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
960 # if last row empty, check the form otherwise retrieve new item
961 if ( ($form->{"partnumber_$i"} eq "")
962 && ($form->{"description_$i"} eq "")
963 && ($form->{"partsgroup_$i"} eq "")) {
965 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
970 IS->retrieve_item(\%myconfig, \%$form);
972 $rows = scalar @{ $form->{item_list} };
974 $form->{"discount_$i"} =
975 $form->format_amount(\%myconfig, $form->{discount} * 100);
978 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
987 $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
989 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
990 qw(partnumber description unit);
991 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
992 keys %{ $form->{item_list}[0] };
994 $form->{"discount_$i"} = $form->{discount} * 100;
996 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
997 ($dec) = ($s =~ /\.(\d+)/);
999 $decimalplaces = ($dec > 2) ? $dec : 2;
1002 $form->{"sellprice_$i"} = $sellprice;
1005 # if there is an exchange rate adjust sellprice
1006 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1007 $form->{"sellprice_$i"} /= $exchangerate;
1010 $form->{"listprice_$i"} /= $exchangerate;
1013 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1014 (1 - $form->{"discount_$i"} / 100);
1015 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1016 map { $form->{"${_}_base"} += $amount }
1017 (split / /, $form->{"taxaccounts_$i"});
1018 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1019 split / /, $form->{"taxaccounts_$i"}
1020 if !$form->{taxincluded};
1022 $form->{creditremaining} -= $amount;
1025 $form->{"${_}_$i"} =
1026 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
1028 } qw(sellprice listprice);
1031 $form->format_amount(\%myconfig, $form->{"qty_$i"});
1034 if ($form->{"inventory_accno_$i"} ne "") {
1035 $form->{"lizenzen_$i"} = qq|<option></option>|;
1036 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1037 $form->{"lizenzen_$i"} .=
1038 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1040 $form->{"lizenzen_$i"} .=
1041 qq|<option value=-1>Neue Lizenz</option>|;
1045 # get pricegroups for parts
1046 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1048 # build up html code for prices_$i
1049 &set_pricegroup($i);
1056 # ok, so this is a new part
1057 # ask if it is a part or service item
1059 if ( $form->{"partsgroup_$i"}
1060 && ($form->{"partsnumber_$i"} eq "")
1061 && ($form->{"description_$i"} eq "")) {
1062 $form->{rowcount}--;
1063 $form->{"discount_$i"} = "";
1067 $form->{"id_$i"} = 0;
1068 $form->{"unit_$i"} = $locale->text('ea');
1075 $lxdebug->leave_sub();
1079 $lxdebug->enter_sub();
1080 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1081 $form->isblank("customer", $locale->text('Customer missing!'));
1083 # if oldcustomer ne customer redo form
1084 if (&check_name(customer)) {
1088 if ($form->{second_run}) {
1089 $form->{print_and_post} = 0;
1094 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1095 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1097 $form->error($locale->text('Cannot post invoice for a closed period!'))
1098 if ($invdate <= $closedto);
1100 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1101 if ($form->{currency} ne $form->{defaultcurrency});
1103 for $i (1 .. $form->{paidaccounts}) {
1104 if ($form->{"paid_$i"}) {
1105 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1107 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1109 $form->error($locale->text('Cannot post payment for a closed period!'))
1110 if ($datepaid <= $closedto);
1112 if ($form->{currency} ne $form->{defaultcurrency}) {
1113 $form->{"exchangerate_$i"} = $form->{exchangerate}
1114 if ($invdate == $datepaid);
1115 $form->isblank("exchangerate_$i",
1116 $locale->text('Exchangerate for payment missing!'));
1121 ($form->{AR}) = split /--/, $form->{AR};
1122 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1124 $form->{label} = $locale->text('Invoice');
1126 $form->{id} = 0 if $form->{postasnew};
1128 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1129 if (!$form->{invnumber} || $form->{postasnew}) {
1130 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
1133 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1134 $form->error($locale->text('Cannot post invoice!'));
1138 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1139 if (IS->post_invoice(\%myconfig, \%$form));
1140 $form->error($locale->text('Cannot post invoice!'));
1143 $lxdebug->leave_sub();
1146 sub print_and_post {
1147 $lxdebug->enter_sub();
1149 $old_form = new Form;
1151 $form->{print_and_post} = 1;
1155 $lxdebug->leave_sub();
1160 $lxdebug->enter_sub();
1162 $form->{preview} = 1;
1163 $old_form = new Form;
1164 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1165 $old_form->{rowcount}++;
1167 &print_form($old_form);
1168 $lxdebug->leave_sub();
1173 $lxdebug->enter_sub();
1174 if ($form->{second_run}) {
1175 $form->{print_and_post} = 0;
1182 <form method=post action=$form->{script}>
1185 # delete action variable
1186 map { delete $form->{$_} } qw(action header);
1188 foreach $key (keys %$form) {
1189 $form->{$key} =~ s/\"/"/g;
1190 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1194 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1197 . $locale->text('Are you sure you want to delete Invoice Number')
1198 . qq| $form->{invnumber}
1202 <input name=action class=submit type=submit value="|
1203 . $locale->text('Yes') . qq|">
1207 $lxdebug->leave_sub();
1211 $lxdebug->enter_sub();
1213 $form->redirect($locale->text('Invoice deleted!'))
1214 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1215 $form->error($locale->text('Cannot delete invoice!'));
1217 $lxdebug->leave_sub();