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') . qq|></td>
321 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
322 <td width="4"><input type=button name=duedate id="trigger2" value=|
323 . $locale->text('button') . qq|></td></td>
328 Form->write_trigger(\%myconfig, "2", "invdate", "BL", "trigger1",
329 "duedate", "BL", "trigger2");
332 # without JavaScript Calendar
334 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
336 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
338 if ($form->{resubmit}) {
339 $onload = "document.invoice.submit()";
346 <body onLoad="$onload">
348 <form method=post name="invoice" action=$form->{script}>
351 <input type=hidden name=id value=$form->{id}>
352 <input type=hidden name=action value=$form->{action}>
354 <input type=hidden name=type value=$form->{type}>
355 <input type=hidden name=media value=$form->{media}>
356 <input type=hidden name=format value=$form->{format}>
358 <input type=hidden name=queued value="$form->{queued}">
359 <input type=hidden name=printed value="$form->{printed}">
360 <input type=hidden name=emailed value="$form->{emailed}">
362 <input type=hidden name=title value="$form->{title}">
363 <input type=hidden name=vc value=$form->{vc}>
365 <input type=hidden name=discount value=$form->{discount}>
366 <input type=hidden name=creditlimit value=$form->{creditlimit}>
367 <input type=hidden name=creditremaining value=$form->{creditremaining}>
369 <input type=hidden name=tradediscount value=$form->{tradediscount}>
370 <input type=hidden name=business value=$form->{business}>
372 <input type=hidden name=closedto value=$form->{closedto}>
373 <input type=hidden name=locked value=$form->{locked}>
375 <input type=hidden name=shipped value=$form->{shipped}>
376 <input type=hidden name=lizenzen value=$lizenzen>
380 <th class=listtop>$form->{title}</th>
390 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
391 <td colspan=3>$customer</td>
392 <input type=hidden name=customer_id value=$form->{customer_id}>
393 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
394 <th align=richt nowrap>|
395 . $locale->text('Contact Person') . qq|</th>
396 <td colspan=3>$contact</td>
403 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
404 <td>$form->{creditlimit}</td>
406 <th nowrap>| . $locale->text('Remaining') . qq|</th>
407 <td class="plus$n">$form->{creditremaining}</td>
414 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
415 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
416 <input type=hidden name=selectAR value="$form->{selectAR}">
420 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
421 <td><select name=currency>$form->{selectcurrency}</select></td>
422 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
423 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
424 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
425 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
429 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
430 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
433 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
434 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
441 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
442 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
443 <input type=hidden name=selectemployee value="$form->{selectemployee}">
447 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
448 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
451 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
455 <th align=right>| . $locale->text('Due Date') . qq|</th>
459 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
460 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
463 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
464 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
467 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
468 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
483 <!-- shipto are in hidden variables -->
485 <input type=hidden name=shiptoname value="$form->{shiptoname}">
486 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
487 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
488 <input type=hidden name=shiptocity value="$form->{shiptocity}">
489 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
490 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
491 <input type=hidden name=shiptophone value="$form->{shiptophone}">
492 <input type=hidden name=shiptofax value="$form->{shiptofax}">
493 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
495 <!-- email variables -->
496 <input type=hidden name=message value="$form->{message}">
497 <input type=hidden name=email value="$form->{email}">
498 <input type=hidden name=subject value="$form->{subject}">
499 <input type=hidden name=cc value="$form->{cc}">
500 <input type=hidden name=bcc value="$form->{bcc}">
501 <input type=hidden name=webdav value=$webdav>
502 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
505 foreach $item (split / /, $form->{taxaccounts}) {
507 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
508 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
509 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
512 $lxdebug->leave_sub();
516 $lxdebug->enter_sub();
518 $form->{invtotal} = $form->{invsubtotal};
520 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
523 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
526 $rows = ($rows > $introws) ? $rows : $introws;
528 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
530 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
532 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
535 if ($form->{taxaccounts}) {
537 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
538 . $locale->text('Tax Included') . qq|</b><br><br>|;
541 if (!$form->{taxincluded}) {
543 foreach $item (split / /, $form->{taxaccounts}) {
544 if ($form->{"${item}_base"}) {
545 $form->{"${item}_total"} =
547 $form->{"${item}_base"} * $form->{"${item}_rate"},
549 $form->{invtotal} += $form->{"${item}_total"};
550 $form->{"${item}_total"} =
551 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
555 <th align=right>$form->{"${item}_description"}</th>
556 <td align=right>$form->{"${item}_total"}</td>
562 $form->{invsubtotal} =
563 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
567 <th align=right>| . $locale->text('Subtotal') . qq|</th>
568 <td align=right>$form->{invsubtotal}</td>
574 if ($form->{taxincluded}) {
575 foreach $item (split / /, $form->{taxaccounts}) {
576 if ($form->{"${item}_base"}) {
577 $form->{"${item}_total"} =
579 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
580 (1 + $form->{"${item}_rate"})
583 $form->{"${item}_netto"} =
585 ($form->{"${item}_base"} - $form->{"${item}_total"}),
587 $form->{"${item}_total"} =
588 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
589 $form->{"${item}_netto"} =
590 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
594 <th align=right>Enthaltene $form->{"${item}_description"}</th>
595 <td align=right>$form->{"${item}_total"}</td>
598 <th align=right>Nettobetrag</th>
599 <td align=right>$form->{"${item}_netto"}</td>
607 $form->{oldinvtotal} = $form->{invtotal};
609 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
619 <th align=left>| . $locale->text('Notes') . qq|</th>
620 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
628 <td align=right width=100%>
634 <th align=right>| . $locale->text('Total') . qq|</th>
635 <td align=right>$form->{invtotal}</td>
647 <td><hr size=3 noshade></td>
650 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
653 <td align=left width=30%><b>Dateiname</b></td>
654 <td align=left width=70%><b>Webdavlink</b></td>
656 foreach $file (keys %{ $form->{WEBDAV} }) {
659 <td align=left>$file</td>
660 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
675 <tr class=listheading>
676 <th colspan=6 class=listheading>|
677 . $locale->text('Incoming Payments') . qq|</th>
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>
756 <input type=hidden name=print_and_post value=$form->{print_and_post}>
757 <input type=hidden name=second_run value=$form->{second_run}>
762 <td><hr size=3 noshade></td>
776 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
777 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
781 <input class=submit type=submit name=action value="|
782 . $locale->text('Update') . qq|">
783 <input class=submit type=submit name=action value="|
784 . $locale->text('Ship to') . qq|">
785 <input class=submit type=submit name=action value="|
786 . $locale->text('Print') . qq|">
787 <input class=submit type=submit name=action value="|
788 . $locale->text('E-mail') . qq|">
791 if (!$form->{revtrans}) {
792 if (!$form->{locked}) {
794 <input class=submit type=submit name=action value="|
795 . $locale->text('Post') . qq|">
796 <input class=submit type=submit name=action value="|
797 . $locale->text('Delete') . qq|">
802 if ($invdate > $closedto) {
804 <input class=submit type=submit name=action value="|
805 . $locale->text('Post as new') . qq|">
806 <input class=submit type=submit name=action value="|
807 . $locale->text('Order') . qq|">
812 if ($invdate > $closedto) {
813 print qq|<input class=submit type=submit name=action value="|
814 . $locale->text('Update') . qq|">
815 <input class=submit type=submit name=action value="|
816 . $locale->text('Ship to') . qq|">
817 <input class=submit type=submit name=action value="|
818 . $locale->text('Preview') . qq|">
819 <input class=submit type=submit name=action value="|
820 . $locale->text('E-mail') . qq|">
821 <input class=submit type=submit name=action value="|
822 . $locale->text('Print and Post') . qq|">
823 <input class=submit type=submit name=action value="|
824 . $locale->text('Post') . qq|">|;
828 if ($form->{menubar}) {
829 require "$form->{path}/menu.pl";
835 <input type=hidden name=rowcount value=$form->{rowcount}>
837 <input name=callback type=hidden value="$form->{callback}">
839 <input type=hidden name=path value=$form->{path}>
840 <input type=hidden name=login value=$form->{login}>
841 <input type=hidden name=password value=$form->{password}>
850 $lxdebug->leave_sub();
854 $lxdebug->enter_sub();
856 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
857 qw(exchangerate creditlimit creditremaining);
859 &check_name(customer);
863 $form->{exchangerate} = $exchangerate
867 $form->check_exchangerate(
868 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
871 for $i (1 .. $form->{paidaccounts}) {
872 if ($form->{"paid_$i"}) {
875 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
876 } qw(paid exchangerate);
878 $form->{"exchangerate_$i"} = $exchangerate
880 $form->{"forex_$i"} = (
882 $form->check_exchangerate(
883 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
888 $i = $form->{rowcount};
889 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
891 # if last row empty, check the form otherwise retrieve new item
892 if ( ($form->{"partnumber_$i"} eq "")
893 && ($form->{"description_$i"} eq "")
894 && ($form->{"partsgroup_$i"} eq "")) {
896 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
901 IS->retrieve_item(\%myconfig, \%$form);
903 $rows = scalar @{ $form->{item_list} };
905 $form->{"discount_$i"} =
906 $form->format_amount(\%myconfig, $form->{discount} * 100);
909 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
918 $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
920 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
921 qw(partnumber description unit);
922 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
923 keys %{ $form->{item_list}[0] };
925 $form->{"discount_$i"} = $form->{discount} * 100;
927 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
928 ($dec) = ($s =~ /\.(\d+)/);
930 $decimalplaces = ($dec > 2) ? $dec : 2;
933 $form->{"sellprice_$i"} = $sellprice;
936 # if there is an exchange rate adjust sellprice
937 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
938 $form->{"sellprice_$i"} /= $exchangerate;
941 $form->{"listprice_$i"} /= $exchangerate;
944 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
945 (1 - $form->{"discount_$i"} / 100);
946 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
947 map { $form->{"${_}_base"} += $amount }
948 (split / /, $form->{"taxaccounts_$i"});
949 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
950 split / /, $form->{"taxaccounts_$i"}
951 if !$form->{taxincluded};
953 $form->{creditremaining} -= $amount;
957 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
959 } qw(sellprice listprice);
962 $form->format_amount(\%myconfig, $form->{"qty_$i"});
965 if ($form->{"inventory_accno_$i"} ne "") {
966 $form->{"lizenzen_$i"} = qq|<option></option>|;
967 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
968 $form->{"lizenzen_$i"} .=
969 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
971 $form->{"lizenzen_$i"} .=
972 qq|<option value=-1>Neue Lizenz</option>|;
982 # ok, so this is a new part
983 # ask if it is a part or service item
985 if ( $form->{"partsgroup_$i"}
986 && ($form->{"partsnumber_$i"} eq "")
987 && ($form->{"description_$i"} eq "")) {
989 $form->{"discount_$i"} = "";
993 $form->{"id_$i"} = 0;
994 $form->{"unit_$i"} = $locale->text('ea');
1001 $lxdebug->leave_sub();
1005 $lxdebug->enter_sub();
1007 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1008 $form->isblank("customer", $locale->text('Customer missing!'));
1010 # if oldcustomer ne customer redo form
1011 if (&check_name(customer)) {
1018 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1019 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1021 $form->error($locale->text('Cannot post invoice for a closed period!'))
1022 if ($invdate <= $closedto);
1024 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1025 if ($form->{currency} ne $form->{defaultcurrency});
1027 for $i (1 .. $form->{paidaccounts}) {
1028 if ($form->{"paid_$i"}) {
1029 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1031 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1033 $form->error($locale->text('Cannot post payment for a closed period!'))
1034 if ($datepaid <= $closedto);
1036 if ($form->{currency} ne $form->{defaultcurrency}) {
1037 $form->{"exchangerate_$i"} = $form->{exchangerate}
1038 if ($invdate == $datepaid);
1039 $form->isblank("exchangerate_$i",
1040 $locale->text('Exchangerate for payment missing!'));
1045 ($form->{AR}) = split /--/, $form->{AR};
1046 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1048 $form->{label} = $locale->text('Invoice');
1050 $form->{id} = 0 if $form->{postasnew};
1052 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber")
1053 unless $form->{invnumber};
1055 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1056 $form->error($locale->text('Cannot post invoice!'));
1060 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1061 if (IS->post_invoice(\%myconfig, \%$form));
1062 $form->error($locale->text('Cannot post invoice!'));
1065 $lxdebug->leave_sub();
1068 sub print_and_post {
1069 $lxdebug->enter_sub();
1071 $old_form = new Form;
1073 $form->{print_and_post} = 1;
1076 $lxdebug->leave_sub();
1081 $lxdebug->enter_sub();
1083 $form->{preview} = 1;
1084 $old_form = new Form;
1085 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1086 $old_form->{rowcount}++;
1088 &print_form($old_form);
1089 $lxdebug->leave_sub();
1094 $lxdebug->enter_sub();
1101 <form method=post action=$form->{script}>
1104 # delete action variable
1105 map { delete $form->{$_} } qw(action header);
1107 foreach $key (keys %$form) {
1108 $form->{$key} =~ s/\"/"/g;
1109 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1113 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1116 . $locale->text('Are you sure you want to delete Invoice Number')
1117 . qq| $form->{invnumber}
1121 <input name=action class=submit type=submit value="|
1122 . $locale->text('Yes') . qq|">
1126 $lxdebug->leave_sub();
1130 $lxdebug->enter_sub();
1132 $form->redirect($locale->text('Invoice deleted!'))
1133 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1134 $form->error($locale->text('Cannot delete invoice!'));
1136 $lxdebug->leave_sub();