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 #======================================================================
37 require "$form->{path}/io.pl";
38 require "$form->{path}/arap.pl";
45 $lxdebug->enter_sub();
47 $form->{title} = $locale->text('Add Sales Invoice');
50 "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}"
51 unless $form->{callback};
53 $form{jsscript} = "date";
55 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
57 $form->error("Access Denied");
64 $lxdebug->leave_sub();
68 $lxdebug->enter_sub();
70 $form->{title} = $locale->text('Edit Sales Invoice');
72 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
74 $form->error("Access Denied");
81 $lxdebug->leave_sub();
85 $lxdebug->enter_sub();
87 $form->{vc} = 'customer';
90 $form->{webdav} = $webdav;
91 $form->{lizenzen} = $lizenzen;
93 $form->create_links("AR", \%myconfig, "customer");
95 if ($form->{all_customer}) {
96 unless ($form->{customer_id}) {
97 $form->{customer_id} = $form->{all_customer}->[0]->{id};
100 $cp_id = $form->{cp_id};
101 IS->get_customer(\%myconfig, \%$form);
103 IS->retrieve_invoice(\%myconfig, \%$form);
104 $form->{cp_id} = $cp_id;
107 @curr = split /:/, $form->{currencies};
109 $form->{defaultcurrency} = $curr[0];
111 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
113 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
115 if ($form->{all_customer}) {
116 $form->{customer} = "$form->{customer}--$form->{customer_id}";
117 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
118 (@{ $form->{all_customer} });
122 if ($form->{all_departments}) {
123 $form->{selectdepartment} = "<option>\n";
124 $form->{department} = "$form->{department}--$form->{department_id}";
127 $form->{selectdepartment} .=
128 "<option>$_->{description}--$_->{id}\n"
129 } (@{ $form->{all_departments} });
132 $form->{employee} = "$form->{employee}--$form->{employee_id}";
135 if ($form->{all_employees}) {
136 $form->{selectemployee} = "";
137 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
138 (@{ $form->{all_employees} });
142 $form->{forex} = $form->{exchangerate};
143 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
145 foreach $key (keys %{ $form->{AR_links} }) {
146 foreach $ref (@{ $form->{AR_links}{$key} }) {
147 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
150 if ($key eq "AR_paid") {
151 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
152 $form->{"AR_paid_$i"} =
153 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
156 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
157 $form->{"datepaid_$i"} =
158 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
159 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
160 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
161 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
162 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
164 $form->{paidaccounts} = $i;
168 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
173 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
175 $form->{AR} = $form->{AR_1} unless $form->{id};
178 ($form->datetonum($form->{invdate}, \%myconfig) <=
179 $form->datetonum($form->{closedto}, \%myconfig));
181 $lxdebug->leave_sub();
184 sub prepare_invoice {
185 $lxdebug->enter_sub();
187 $form->{type} = "invoice";
188 $form->{formname} = "invoice";
189 $form->{format} = "html";
190 $form->{media} = "screen";
194 map { $form->{$_} =~ s/\"/"/g }
195 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
197 foreach $ref (@{ $form->{invoice_details} }) {
199 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
200 $form->{"discount_$i"} =
201 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
203 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
205 $decimalplaces = ($dec > 2) ? $dec : 2;
207 $form->{"sellprice_$i"} =
208 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
210 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
212 map { $form->{"${_}_$i"} =~ s/\"/"/g }
213 qw(partnumber description unit partnotes);
214 $form->{rowcount} = $i;
217 $lxdebug->leave_sub();
221 $lxdebug->enter_sub();
223 # set option selected
224 foreach $item (qw(AR customer currency department employee contact)) {
225 $form->{"select$item"} =~ s/ selected//;
226 $form->{"select$item"} =~
227 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
231 if ($form->{all_contacts}) {
233 $form->{selectcontact} = "";
234 foreach $item (@{ $form->{all_contacts} }) {
235 if ($form->{cp_id} == $item->{cp_id}) {
236 $form->{selectcontact} .=
237 "<option selected>$item->{cp_name}--$item->{cp_id}";
239 $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
244 #else {$form->{all_contacts} = 0;}
246 $form->{exchangerate} =
247 $form->format_amount(\%myconfig, $form->{exchangerate});
249 $form->{creditlimit} =
250 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
251 $form->{creditremaining} =
252 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
255 if ($form->{currency} ne $form->{defaultcurrency}) {
256 if ($form->{forex}) {
259 . $locale->text('Exchangerate')
260 . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
264 . $locale->text('Exchangerate')
265 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
269 <input type=hidden name=forex value=$form->{forex}>
273 ($form->{selectcustomer})
274 ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
275 : qq|<input name=customer value="$form->{customer}" size=35>|;
279 ($form->{selectcontact})
280 ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
281 : qq|<input name=contact value="$form->{contact}" size=35>|;
285 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
286 <td colspan=3><select name=department>$form->{selectdepartment}</select>
287 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
290 | if $form->{selectdepartment};
292 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
294 if ($form->{business}) {
297 <th align=right>| . $locale->text('Business') . qq|</th>
298 <td>$form->{business}</td>
299 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
301 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
307 $form->{fokus} = "invoice.customer";
309 # use JavaScript Calendar or not
310 $form->{jsscript} = $jscalendar;
312 if ($form->{jsscript}) {
314 # with JavaScript Calendar
316 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
317 <td><input type=button name=invdate id="trigger1" value=|
318 . $locale->text('button')
322 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
323 <td width="4"><input type=button name=duedate id="trigger2" value=|
324 . $locale->text('button')
330 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
331 "duedate", "BL", "trigger2");
334 # without JavaScript Calendar
336 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
338 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
344 <body onLoad="fokus()">
346 <form method=post name="invoice" action=$form->{script}>
349 <input type=hidden name=id value=$form->{id}>
351 <input type=hidden name=type value=$form->{type}>
352 <input type=hidden name=media value=$form->{media}>
353 <input type=hidden name=format value=$form->{format}>
355 <input type=hidden name=queued value="$form->{queued}">
356 <input type=hidden name=printed value="$form->{printed}">
357 <input type=hidden name=emailed value="$form->{emailed}">
359 <input type=hidden name=title value="$form->{title}">
360 <input type=hidden name=vc value=$form->{vc}>
362 <input type=hidden name=discount value=$form->{discount}>
363 <input type=hidden name=creditlimit value=$form->{creditlimit}>
364 <input type=hidden name=creditremaining value=$form->{creditremaining}>
366 <input type=hidden name=tradediscount value=$form->{tradediscount}>
367 <input type=hidden name=business value=$form->{business}>
369 <input type=hidden name=closedto value=$form->{closedto}>
370 <input type=hidden name=locked value=$form->{locked}>
372 <input type=hidden name=shipped value=$form->{shipped}>
373 <input type=hidden name=lizenzen value=$lizenzen>
377 <th class=listtop>$form->{title}</th>
387 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
388 <td colspan=3>$customer</td>
389 <input type=hidden name=customer_id value=$form->{customer_id}>
390 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
391 <th align=richt nowrap>|
392 . $locale->text('Contact Person')
394 <td colspan=3>$contact</td>
401 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
402 <td>$form->{creditlimit}</td>
404 <th nowrap>| . $locale->text('Remaining') . qq|</th>
405 <td class="plus$n">$form->{creditremaining}</td>
412 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
413 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
414 <input type=hidden name=selectAR value="$form->{selectAR}">
418 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
419 <td><select name=currency>$form->{selectcurrency}</select></td>
420 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
421 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
422 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
423 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
427 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
428 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
431 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
432 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
439 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
440 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
441 <input type=hidden name=selectemployee value="$form->{selectemployee}">
445 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
446 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
449 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
453 <th align=right>| . $locale->text('Due Date') . qq|</th>
457 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
458 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
461 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
462 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
465 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
466 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
481 <!-- shipto are in hidden variables -->
483 <input type=hidden name=shiptoname value="$form->{shiptoname}">
484 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
485 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
486 <input type=hidden name=shiptocity value="$form->{shiptocity}">
487 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
488 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
489 <input type=hidden name=shiptophone value="$form->{shiptophone}">
490 <input type=hidden name=shiptofax value="$form->{shiptofax}">
491 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
493 <!-- email variables -->
494 <input type=hidden name=message value="$form->{message}">
495 <input type=hidden name=email value="$form->{email}">
496 <input type=hidden name=subject value="$form->{subject}">
497 <input type=hidden name=cc value="$form->{cc}">
498 <input type=hidden name=bcc value="$form->{bcc}">
499 <input type=hidden name=webdav value=$webdav>
500 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
503 foreach $item (split / /, $form->{taxaccounts}) {
505 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
506 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
507 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
510 $lxdebug->leave_sub();
514 $lxdebug->enter_sub();
516 $form->{invtotal} = $form->{invsubtotal};
518 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
521 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
524 $rows = ($rows > $introws) ? $rows : $introws;
526 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
528 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
530 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
533 if ($form->{taxaccounts}) {
535 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
536 . $locale->text('Tax Included')
540 if (!$form->{taxincluded}) {
542 foreach $item (split / /, $form->{taxaccounts}) {
543 if ($form->{"${item}_base"}) {
544 $form->{"${item}_total"} =
546 $form->{"${item}_base"} * $form->{"${item}_rate"},
548 $form->{invtotal} += $form->{"${item}_total"};
549 $form->{"${item}_total"} =
550 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
554 <th align=right>$form->{"${item}_description"}</th>
555 <td align=right>$form->{"${item}_total"}</td>
561 $form->{invsubtotal} =
562 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
566 <th align=right>| . $locale->text('Subtotal') . qq|</th>
567 <td align=right>$form->{invsubtotal}</td>
573 if ($form->{taxincluded}) {
574 foreach $item (split / /, $form->{taxaccounts}) {
575 if ($form->{"${item}_base"}) {
576 $form->{"${item}_total"} =
578 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
579 (1 + $form->{"${item}_rate"})
582 $form->{"${item}_netto"} =
584 ($form->{"${item}_base"} - $form->{"${item}_total"}),
586 $form->{"${item}_total"} =
587 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
588 $form->{"${item}_netto"} =
589 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
593 <th align=right>Enthaltene $form->{"${item}_description"}</th>
594 <td align=right>$form->{"${item}_total"}</td>
597 <th align=right>Nettobetrag</th>
598 <td align=right>$form->{"${item}_netto"}</td>
606 $form->{oldinvtotal} = $form->{invtotal};
608 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
618 <th align=left>| . $locale->text('Notes') . qq|</th>
619 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
627 <td align=right width=100%>
633 <th align=right>| . $locale->text('Total') . qq|</th>
634 <td align=right>$form->{invtotal}</td>
646 <td><hr size=3 noshade></td>
649 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
652 <td align=left width=30%><b>Dateiname</b></td>
653 <td align=left width=70%><b>Webdavlink</b></td>
655 foreach $file (keys %{ $form->{WEBDAV} }) {
658 <td align=left>$file</td>
659 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
674 <tr class=listheading>
675 <th colspan=6 class=listheading>|
676 . $locale->text('Incoming Payments')
681 if ($form->{currency} eq $form->{defaultcurrency}) {
682 @column_index = qw(datepaid source memo paid AR_paid);
684 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
687 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
688 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
689 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
690 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
691 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
692 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
697 map { print "$column_data{$_}\n" } @column_index;
702 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
703 for $i (1 .. $form->{paidaccounts}) {
708 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
709 $form->{"selectAR_paid_$i"} =~
710 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
713 $totalpaid += $form->{"paid_$i"};
715 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
716 $form->{"exchangerate_$i"} =
717 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
719 $exchangerate = qq| |;
720 if ($form->{currency} ne $form->{defaultcurrency}) {
721 if ($form->{"forex_$i"}) {
723 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
726 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
731 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
734 $column_data{"paid_$i"} =
735 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
736 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
737 $column_data{"AR_paid_$i"} =
738 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
739 $column_data{"datepaid_$i"} =
740 qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
741 $column_data{"source_$i"} =
742 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
743 $column_data{"memo_$i"} =
744 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
746 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
752 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
753 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
754 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
755 <input type=hidden name=oldtotalpaid value=$totalpaid>
760 <td><hr size=3 noshade></td>
774 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
775 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
779 <input class=submit type=submit name=action value="|
780 . $locale->text('Update') . qq|">
781 <input class=submit type=submit name=action value="|
782 . $locale->text('Ship to') . qq|">
783 <input class=submit type=submit name=action value="|
784 . $locale->text('Print') . qq|">
785 <input class=submit type=submit name=action value="|
786 . $locale->text('E-mail') . qq|">
789 if (!$form->{revtrans}) {
790 if (!$form->{locked}) {
792 <input class=submit type=submit name=action value="|
793 . $locale->text('Post') . qq|">
794 <input class=submit type=submit name=action value="|
795 . $locale->text('Delete') . qq|">
800 if ($invdate > $closedto) {
802 <input class=submit type=submit name=action value="|
803 . $locale->text('Post as new') . qq|">
804 <input class=submit type=submit name=action value="|
805 . $locale->text('Order') . qq|">
810 if ($invdate > $closedto) {
811 print qq|<input class=submit type=submit name=action value="|
812 . $locale->text('Update') . qq|">
813 <input class=submit type=submit name=action value="|
814 . $locale->text('Ship to') . qq|">
815 <input class=submit type=submit name=action value="|
816 . $locale->text('Print') . qq|">
817 <input class=submit type=submit name=action value="|
818 . $locale->text('E-mail') . qq|">
819 <input class=submit type=submit name=action value="|
820 . $locale->text('Post') . qq|">|;
824 if ($form->{menubar}) {
825 require "$form->{path}/menu.pl";
831 <input type=hidden name=rowcount value=$form->{rowcount}>
833 <input name=callback type=hidden value="$form->{callback}">
835 <input type=hidden name=path value=$form->{path}>
836 <input type=hidden name=login value=$form->{login}>
837 <input type=hidden name=password value=$form->{password}>
846 $lxdebug->leave_sub();
850 $lxdebug->enter_sub();
852 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
853 qw(exchangerate creditlimit creditremaining);
855 &check_name(customer);
859 $form->{exchangerate} = $exchangerate
863 $form->check_exchangerate(
864 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
867 for $i (1 .. $form->{paidaccounts}) {
868 if ($form->{"paid_$i"}) {
871 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
872 } qw(paid exchangerate);
874 $form->{"exchangerate_$i"} = $exchangerate
876 $form->{"forex_$i"} = (
878 $form->check_exchangerate(
879 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
884 $i = $form->{rowcount};
885 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
887 # if last row empty, check the form otherwise retrieve new item
888 if ( ($form->{"partnumber_$i"} eq "")
889 && ($form->{"description_$i"} eq "")
890 && ($form->{"partsgroup_$i"} eq "")) {
892 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
897 IS->retrieve_item(\%myconfig, \%$form);
899 $rows = scalar @{ $form->{item_list} };
901 $form->{"discount_$i"} =
902 $form->format_amount(\%myconfig, $form->{discount} * 100);
905 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
914 $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
916 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
917 qw(partnumber description unit);
918 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
919 keys %{ $form->{item_list}[0] };
921 $form->{"discount_$i"} = $form->{discount} * 100;
923 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
924 ($dec) = ($s =~ /\.(\d+)/);
926 $decimalplaces = ($dec > 2) ? $dec : 2;
929 $form->{"sellprice_$i"} = $sellprice;
932 # if there is an exchange rate adjust sellprice
933 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
934 $form->{"sellprice_$i"} /= $exchangerate;
937 $form->{"listprice_$i"} /= $exchangerate;
940 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
941 (1 - $form->{"discount_$i"} / 100);
942 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
943 map { $form->{"${_}_base"} += $amount }
944 (split / /, $form->{"taxaccounts_$i"});
945 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
946 split / /, $form->{"taxaccounts_$i"}
947 if !$form->{taxincluded};
949 $form->{creditremaining} -= $amount;
953 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
955 } qw(sellprice listprice);
958 $form->format_amount(\%myconfig, $form->{"qty_$i"});
961 if ($form->{"inventory_accno_$i"} ne "") {
962 $form->{"lizenzen_$i"} = qq|<option></option>|;
963 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
964 $form->{"lizenzen_$i"} .=
965 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
967 $form->{"lizenzen_$i"} .=
968 qq|<option value=-1>Neue Lizenz</option>|;
978 # ok, so this is a new part
979 # ask if it is a part or service item
981 if ( $form->{"partsgroup_$i"}
982 && ($form->{"partsnumber_$i"} eq "")
983 && ($form->{"description_$i"} eq "")) {
985 $form->{"discount_$i"} = "";
989 $form->{"id_$i"} = 0;
990 $form->{"unit_$i"} = $locale->text('ea');
997 $lxdebug->leave_sub();
1001 $lxdebug->enter_sub();
1003 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1004 $form->isblank("customer", $locale->text('Customer missing!'));
1006 # if oldcustomer ne customer redo form
1007 if (&check_name(customer)) {
1014 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1015 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1017 $form->error($locale->text('Cannot post invoice for a closed period!'))
1018 if ($invdate <= $closedto);
1020 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1021 if ($form->{currency} ne $form->{defaultcurrency});
1023 for $i (1 .. $form->{paidaccounts}) {
1024 if ($form->{"paid_$i"}) {
1025 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1027 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1029 $form->error($locale->text('Cannot post payment for a closed period!'))
1030 if ($datepaid <= $closedto);
1032 if ($form->{currency} ne $form->{defaultcurrency}) {
1033 $form->{"exchangerate_$i"} = $form->{exchangerate}
1034 if ($invdate == $datepaid);
1035 $form->isblank("exchangerate_$i",
1036 $locale->text('Exchangerate for payment missing!'));
1041 ($form->{AR}) = split /--/, $form->{AR};
1042 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1044 $form->{label} = $locale->text('Invoice');
1046 $form->{id} = 0 if $form->{postasnew};
1048 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber")
1049 unless $form->{invnumber};
1052 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1053 if (IS->post_invoice(\%myconfig, \%$form));
1054 $form->error($locale->text('Cannot post invoice!'));
1056 $lxdebug->leave_sub();
1060 $lxdebug->enter_sub();
1067 <form method=post action=$form->{script}>
1070 # delete action variable
1071 map { delete $form->{$_} } qw(action header);
1073 foreach $key (keys %$form) {
1074 $form->{$key} =~ s/\"/"/g;
1075 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1079 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1082 . $locale->text('Are you sure you want to delete Invoice Number')
1083 . qq| $form->{invnumber}
1087 <input name=action class=submit type=submit value="|
1088 . $locale->text('Yes') . qq|">
1092 $lxdebug->leave_sub();
1096 $lxdebug->enter_sub();
1098 $form->redirect($locale->text('Invoice deleted!'))
1099 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1100 $form->error($locale->text('Cannot delete invoice!'));
1102 $lxdebug->leave_sub();