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|">|;
900 if ($form->{menubar}) {
901 require "$form->{path}/menu.pl";
907 <input type=hidden name=rowcount value=$form->{rowcount}>
909 <input name=callback type=hidden value="$form->{callback}">
911 <input type=hidden name=path value=$form->{path}>
912 <input type=hidden name=login value=$form->{login}>
913 <input type=hidden name=password value=$form->{password}>
922 $lxdebug->leave_sub();
926 $lxdebug->enter_sub();
928 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
929 qw(exchangerate creditlimit creditremaining);
930 if ($form->{second_run}) {
931 $form->{print_and_post} = 0;
933 &check_name(customer);
937 $form->{exchangerate} = $exchangerate
941 $form->check_exchangerate(
942 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
945 for $i (1 .. $form->{paidaccounts}) {
946 if ($form->{"paid_$i"}) {
949 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
950 } qw(paid exchangerate);
952 $form->{"exchangerate_$i"} = $exchangerate
954 $form->{"forex_$i"} = (
956 $form->check_exchangerate(
957 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
962 $i = $form->{rowcount};
963 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
965 # if last row empty, check the form otherwise retrieve new item
966 if ( ($form->{"partnumber_$i"} eq "")
967 && ($form->{"description_$i"} eq "")
968 && ($form->{"partsgroup_$i"} eq "")) {
970 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
975 IS->retrieve_item(\%myconfig, \%$form);
977 $rows = scalar @{ $form->{item_list} };
979 $form->{"discount_$i"} =
980 $form->format_amount(\%myconfig, $form->{discount} * 100);
983 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
992 $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
994 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
995 qw(partnumber description unit);
996 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
997 keys %{ $form->{item_list}[0] };
999 $form->{"discount_$i"} = $form->{discount} * 100;
1001 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
1002 ($dec) = ($s =~ /\.(\d+)/);
1004 $decimalplaces = ($dec > 2) ? $dec : 2;
1007 $form->{"sellprice_$i"} = $sellprice;
1010 # if there is an exchange rate adjust sellprice
1011 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
1012 $form->{"sellprice_$i"} /= $exchangerate;
1015 $form->{"listprice_$i"} /= $exchangerate;
1018 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
1019 (1 - $form->{"discount_$i"} / 100);
1020 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
1021 map { $form->{"${_}_base"} += $amount }
1022 (split / /, $form->{"taxaccounts_$i"});
1023 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
1024 split / /, $form->{"taxaccounts_$i"}
1025 if !$form->{taxincluded};
1027 $form->{creditremaining} -= $amount;
1030 $form->{"${_}_$i"} =
1031 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
1033 } qw(sellprice listprice);
1036 $form->format_amount(\%myconfig, $form->{"qty_$i"});
1039 if ($form->{"inventory_accno_$i"} ne "") {
1040 $form->{"lizenzen_$i"} = qq|<option></option>|;
1041 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1042 $form->{"lizenzen_$i"} .=
1043 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1045 $form->{"lizenzen_$i"} .=
1046 qq|<option value=-1>Neue Lizenz</option>|;
1050 # get pricegroups for parts
1051 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1053 # build up html code for prices_$i
1054 &set_pricegroup($i);
1061 # ok, so this is a new part
1062 # ask if it is a part or service item
1064 if ( $form->{"partsgroup_$i"}
1065 && ($form->{"partsnumber_$i"} eq "")
1066 && ($form->{"description_$i"} eq "")) {
1067 $form->{rowcount}--;
1068 $form->{"discount_$i"} = "";
1072 $form->{"id_$i"} = 0;
1073 $form->{"unit_$i"} = $locale->text('ea');
1080 $lxdebug->leave_sub();
1084 $lxdebug->enter_sub();
1085 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1086 $form->isblank("customer", $locale->text('Customer missing!'));
1088 # if oldcustomer ne customer redo form
1089 if (&check_name(customer)) {
1093 if ($form->{second_run}) {
1094 $form->{print_and_post} = 0;
1099 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1100 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1102 $form->error($locale->text('Cannot post invoice for a closed period!'))
1103 if ($invdate <= $closedto);
1105 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1106 if ($form->{currency} ne $form->{defaultcurrency});
1108 for $i (1 .. $form->{paidaccounts}) {
1109 if ($form->{"paid_$i"}) {
1110 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1112 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1114 $form->error($locale->text('Cannot post payment for a closed period!'))
1115 if ($datepaid <= $closedto);
1117 if ($form->{currency} ne $form->{defaultcurrency}) {
1118 $form->{"exchangerate_$i"} = $form->{exchangerate}
1119 if ($invdate == $datepaid);
1120 $form->isblank("exchangerate_$i",
1121 $locale->text('Exchangerate for payment missing!'));
1126 ($form->{AR}) = split /--/, $form->{AR};
1127 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1129 $form->{label} = $locale->text('Invoice');
1131 $form->{id} = 0 if $form->{postasnew};
1133 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1134 if (!$form->{invnumber} || $form->{postasnew}) {
1135 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
1138 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1139 $form->error($locale->text('Cannot post invoice!'));
1143 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1144 if (IS->post_invoice(\%myconfig, \%$form));
1145 $form->error($locale->text('Cannot post invoice!'));
1148 $lxdebug->leave_sub();
1151 sub print_and_post {
1152 $lxdebug->enter_sub();
1154 $old_form = new Form;
1156 $form->{print_and_post} = 1;
1160 $lxdebug->leave_sub();
1165 $lxdebug->enter_sub();
1167 $form->{preview} = 1;
1168 $old_form = new Form;
1169 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1170 $old_form->{rowcount}++;
1172 &print_form($old_form);
1173 $lxdebug->leave_sub();
1178 $lxdebug->enter_sub();
1179 if ($form->{second_run}) {
1180 $form->{print_and_post} = 0;
1187 <form method=post action=$form->{script}>
1190 # delete action variable
1191 map { delete $form->{$_} } qw(action header);
1193 foreach $key (keys %$form) {
1194 $form->{$key} =~ s/\"/"/g;
1195 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1199 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1202 . $locale->text('Are you sure you want to delete Invoice Number')
1203 . qq| $form->{invnumber}
1207 <input name=action class=submit type=submit value="|
1208 . $locale->text('Yes') . qq|">
1212 $lxdebug->leave_sub();
1216 $lxdebug->enter_sub();
1218 $form->redirect($locale->text('Invoice deleted!'))
1219 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1220 $form->error($locale->text('Cannot delete invoice!'));
1222 $lxdebug->leave_sub();