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";
48 $lxdebug->enter_sub();
50 $form->{title} = $locale->text('Add Sales Invoice');
52 $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}" unless $form->{callback};
54 $form{jsscript} = "date";
56 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") {
57 $form->error("Access Denied")
64 $lxdebug->leave_sub();
69 $lxdebug->enter_sub();
71 $form->{title} = $locale->text('Edit Sales Invoice');
73 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") {
74 $form->error("Access Denied")
81 $lxdebug->leave_sub();
86 $lxdebug->enter_sub();
88 $form->{vc} = 'customer';
91 $form->{webdav} = $webdav;
92 $form->{lizenzen} = $lizenzen;
94 $form->create_links("AR", \%myconfig, "customer");
96 if ($form->{all_customer}) {
97 unless ($form->{customer_id}) {
98 $form->{customer_id} = $form->{all_customer}->[0]->{id};
101 $cp_id = $form->{cp_id};
102 IS->get_customer(\%myconfig, \%$form);
104 IS->retrieve_invoice(\%myconfig, \%$form);
105 $form->{cp_id} = $cp_id;
108 @curr = split /:/, $form->{currencies};
110 $form->{defaultcurrency} = $curr[0];
112 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
114 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
116 if ($form->{all_customer}) {
117 $form->{customer} = "$form->{customer}--$form->{customer_id}";
118 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} });
122 if ($form->{all_departments}) {
123 $form->{selectdepartment} = "<option>\n";
124 $form->{department} = "$form->{department}--$form->{department_id}";
126 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
129 $form->{employee} = "$form->{employee}--$form->{employee_id}";
131 if ($form->{all_employees}) {
132 $form->{selectemployee} = "";
133 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_employees} });
137 $form->{forex} = $form->{exchangerate};
138 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
140 foreach $key (keys %{ $form->{AR_links} }) {
141 foreach $ref (@{ $form->{AR_links}{$key} }) {
142 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
145 if ($key eq "AR_paid") {
146 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
147 $form->{"AR_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
149 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1;
150 $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
151 $form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
152 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source};
153 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i-1]->{memo};
155 $form->{paidaccounts} = $i;
158 $form->{$key} = "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
163 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
165 $form->{AR} = $form->{AR_1} unless $form->{id};
167 $form->{locked} = ($form->datetonum($form->{invdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
170 $lxdebug->leave_sub();
174 sub prepare_invoice {
175 $lxdebug->enter_sub();
177 $form->{type} = "invoice";
178 $form->{formname} = "invoice";
179 $form->{format} = "html";
180 $form->{media} = "screen";
184 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
186 foreach $ref (@{ $form->{invoice_details} } ) {
188 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref };
189 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
191 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
193 $decimalplaces = ($dec > 2) ? $dec : 2;
195 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
196 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
198 map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit partnotes);
199 $form->{rowcount} = $i;
202 $lxdebug->leave_sub();
208 $lxdebug->enter_sub();
210 # set option selected
211 foreach $item (qw(AR customer currency department employee contact)) {
212 $form->{"select$item"} =~ s/ selected//;
213 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
217 if ($form->{all_contacts}) {
219 $form->{selectcontact} = "";
220 foreach $item (@{$form->{all_contacts}}) {
221 if ($form->{cp_id} == $item->{cp_id})
223 $form->{selectcontact} .= "<option selected>$item->{cp_name}--$item->{cp_id}";
227 $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
231 #else {$form->{all_contacts} = 0;}
233 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
235 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
236 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
240 if ($form->{currency} ne $form->{defaultcurrency}) {
241 if ($form->{forex}) {
242 $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
244 $exchangerate .= qq|<th align=right>|.$locale->text('Exchangerate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
248 <input type=hidden name=forex value=$form->{forex}>
251 $customer = ($form->{selectcustomer}) ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">| : qq|<input name=customer value="$form->{customer}" size=35>|;
254 $contact = ($form->{selectcontact}) ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">| : qq|<input name=contact value="$form->{contact}" size=35>|;
258 <th align="right" nowrap>|.$locale->text('Department').qq|</th>
259 <td colspan=3><select name=department>$form->{selectdepartment}</select>
260 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
263 | if $form->{selectdepartment};
266 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
269 if ($form->{business}) {
272 <th align=right>|.$locale->text('Business').qq|</th>
273 <td>$form->{business}</td>
274 <th align=right>|.$locale->text('Trade Discount').qq|</th>
275 <td>|.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %</td>
280 $form->{fokus} = "invoice.customer";
282 # use JavaScript Calendar or not
283 $form->{jsscript} = $jscalendar;
285 if ($form->{jsscript})
287 # with JavaScript Calendar
289 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
290 <td><input type=button name=invdate id="trigger1" value=|.$locale->text('button').qq|></td>
293 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
294 <td width="4"><input type=button name=duedate id="trigger2" value=|.$locale->text('button').qq|></td></td>
298 $jsscript = Form->write_trigger(\%myconfig, "2","invdate","BL","trigger1","duedate","BL","trigger2");
302 # without JavaScript Calendar
303 $button1 = qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
304 $button2 = qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
310 <body onLoad="fokus()">
312 <form method=post name="invoice" action=$form->{script}>
315 <input type=hidden name=id value=$form->{id}>
317 <input type=hidden name=type value=$form->{type}>
318 <input type=hidden name=media value=$form->{media}>
319 <input type=hidden name=format value=$form->{format}>
321 <input type=hidden name=queued value="$form->{queued}">
322 <input type=hidden name=printed value="$form->{printed}">
323 <input type=hidden name=emailed value="$form->{emailed}">
325 <input type=hidden name=title value="$form->{title}">
326 <input type=hidden name=vc value=$form->{vc}>
328 <input type=hidden name=discount value=$form->{discount}>
329 <input type=hidden name=creditlimit value=$form->{creditlimit}>
330 <input type=hidden name=creditremaining value=$form->{creditremaining}>
332 <input type=hidden name=tradediscount value=$form->{tradediscount}>
333 <input type=hidden name=business value=$form->{business}>
335 <input type=hidden name=closedto value=$form->{closedto}>
336 <input type=hidden name=locked value=$form->{locked}>
338 <input type=hidden name=shipped value=$form->{shipped}>
339 <input type=hidden name=lizenzen value=$lizenzen>
343 <th class=listtop>$form->{title}</th>
353 <th align=right nowrap>|.$locale->text('Customer').qq|</th>
354 <td colspan=3>$customer</td>
355 <input type=hidden name=customer_id value=$form->{customer_id}>
356 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
357 <th align=richt nowrap>|.$locale->text('Contact Person').qq|</th>
358 <td colspan=3>$contact</td>
365 <th nowrap>|.$locale->text('Credit Limit').qq|</th>
366 <td>$form->{creditlimit}</td>
368 <th nowrap>|.$locale->text('Remaining').qq|</th>
369 <td class="plus$n">$form->{creditremaining}</td>
376 <th align=right nowrap>|.$locale->text('Record in').qq|</th>
377 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
378 <input type=hidden name=selectAR value="$form->{selectAR}">
382 <th align=right nowrap>|.$locale->text('Currency').qq|</th>
383 <td><select name=currency>$form->{selectcurrency}</select></td>
384 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
385 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
386 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
387 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
391 <th align=right nowrap>|.$locale->text('Shipping Point').qq|</th>
392 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
395 <th align=right nowrap>|.$locale->text('Ship via').qq|</th>
396 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
403 <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
404 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
405 <input type=hidden name=selectemployee value="$form->{selectemployee}">
409 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
410 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
413 <th align=right>|.$locale->text('Invoice Date').qq|</th>
417 <th align=right>|.$locale->text('Due Date').qq|</th>
421 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
422 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
425 <th align=right nowrap>|.$locale->text('Quotation Number').qq|</th>
426 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
429 <th align=right nowrap>|.$locale->text('Customer Order Number').qq|</th>
430 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
445 <!-- shipto are in hidden variables -->
447 <input type=hidden name=shiptoname value="$form->{shiptoname}">
448 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
449 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
450 <input type=hidden name=shiptocity value="$form->{shiptocity}">
451 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
452 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
453 <input type=hidden name=shiptophone value="$form->{shiptophone}">
454 <input type=hidden name=shiptofax value="$form->{shiptofax}">
455 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
457 <!-- email variables -->
458 <input type=hidden name=message value="$form->{message}">
459 <input type=hidden name=email value="$form->{email}">
460 <input type=hidden name=subject value="$form->{subject}">
461 <input type=hidden name=cc value="$form->{cc}">
462 <input type=hidden name=bcc value="$form->{bcc}">
463 <input type=hidden name=webdav value=$webdav>
464 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
467 foreach $item (split / /, $form->{taxaccounts}) {
469 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
470 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
471 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
474 $lxdebug->leave_sub();
480 $lxdebug->enter_sub();
482 $form->{invtotal} = $form->{invsubtotal};
484 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
487 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
490 $rows = ($rows > $introws) ? $rows : $introws;
491 $notes = qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
492 $intnotes = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
494 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
497 if ($form->{taxaccounts}) {
499 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|.$locale->text('Tax Included').qq|</b><br><br>|;
502 if (!$form->{taxincluded}) {
504 foreach $item (split / /, $form->{taxaccounts}) {
505 if ($form->{"${item}_base"}) {
506 $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
507 $form->{invtotal} += $form->{"${item}_total"};
508 $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
512 <th align=right>$form->{"${item}_description"}</th>
513 <td align=right>$form->{"${item}_total"}</td>
519 $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
523 <th align=right>|.$locale->text('Subtotal').qq|</th>
524 <td align=right>$form->{invsubtotal}</td>
530 if ($form->{taxincluded}) {
531 foreach $item (split / /, $form->{taxaccounts}) {
532 if ($form->{"${item}_base"}) {
533 $form->{"${item}_total"} = $form->round_amount(($form->{"${item}_base"} * $form->{"${item}_rate"} / (1 + $form->{"${item}_rate"})) , 2);
534 $form->{"${item}_netto"} = $form->round_amount(($form->{"${item}_base"}-$form->{"${item}_total"}), 2);
535 $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
536 $form->{"${item}_netto"} = $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
541 <th align=right>Enthaltene $form->{"${item}_description"}</th>
542 <td align=right>$form->{"${item}_total"}</td>
545 <th align=right>Nettobetrag</th>
546 <td align=right>$form->{"${item}_netto"}</td>
556 $form->{oldinvtotal} = $form->{invtotal};
557 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
567 <th align=left>|.$locale->text('Notes').qq|</th>
568 <th align=left>|.$locale->text('Internal Notes').qq|</th>
576 <td align=right width=100%>
582 <th align=right>|.$locale->text('Total').qq|</th>
583 <td align=right>$form->{invtotal}</td>
595 <td><hr size=3 noshade></td>
598 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
601 <td align=left width=30%><b>Dateiname</b></td>
602 <td align=left width=70%><b>Webdavlink</b></td>
604 foreach $file (keys %{ $form->{WEBDAV}}) {
607 <td align=left>$file</td>
608 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
623 <tr class=listheading>
624 <th colspan=6 class=listheading>|.$locale->text('Incoming Payments')
629 if ($form->{currency} eq $form->{defaultcurrency}) {
630 @column_index = qw(datepaid source memo paid AR_paid);
632 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
635 $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
636 $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
637 $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
638 $column_data{AR_paid} = "<th>".$locale->text('Account')."</th>";
639 $column_data{source} = "<th>".$locale->text('Source')."</th>";
640 $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
645 map { print "$column_data{$_}\n" } @column_index;
650 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
651 for $i (1 .. $form->{paidaccounts}) {
656 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
657 $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
660 $totalpaid += $form->{"paid_$i"};
661 $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
662 $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
664 $exchangerate = qq| |;
665 if ($form->{currency} ne $form->{defaultcurrency}) {
666 if ($form->{"forex_$i"}) {
667 $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
669 $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
674 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
677 $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
678 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
679 $column_data{"AR_paid_$i"} = qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
680 $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
681 $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
682 $column_data{"memo_$i"} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
684 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
690 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
691 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
692 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
693 <input type=hidden name=oldtotalpaid value=$totalpaid>
698 <td><hr size=3 noshade></td>
716 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
717 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
721 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
722 <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|">
723 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
724 <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">
727 if (!$form->{revtrans}) {
728 if (!$form->{locked}) {
730 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
731 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
736 if ($invdate > $closedto) {
738 <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
739 <input class=submit type=submit name=action value="|.$locale->text('Order').qq|">
744 if ($invdate > $closedto) {
745 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
746 <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|">
747 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
748 <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">
749 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
753 if ($form->{menubar}) {
754 require "$form->{path}/menu.pl";
760 <input type=hidden name=rowcount value=$form->{rowcount}>
762 <input name=callback type=hidden value="$form->{callback}">
764 <input type=hidden name=path value=$form->{path}>
765 <input type=hidden name=login value=$form->{login}>
766 <input type=hidden name=password value=$form->{password}>
775 $lxdebug->leave_sub();
780 $lxdebug->enter_sub();
782 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
784 &check_name(customer);
788 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy')));
790 for $i (1 .. $form->{paidaccounts}) {
791 if ($form->{"paid_$i"}) {
792 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
794 $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy')));
798 $i = $form->{rowcount};
799 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
801 # if last row empty, check the form otherwise retrieve new item
802 if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
804 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
809 IS->retrieve_item(\%myconfig, \%$form);
811 $rows = scalar @{ $form->{item_list} };
813 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
816 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
825 $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
827 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
828 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
830 $form->{"discount_$i"} = $form->{discount} * 100;
832 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
833 ($dec) = ($s =~ /\.(\d+)/);
835 $decimalplaces = ($dec > 2) ? $dec : 2;
838 $form->{"sellprice_$i"} = $sellprice;
840 # if there is an exchange rate adjust sellprice
841 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
842 $form->{"sellprice_$i"} /= $exchangerate;
845 $form->{"listprice_$i"} /= $exchangerate;
847 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
848 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
849 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
850 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
852 $form->{creditremaining} -= $amount;
855 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice);
857 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
860 if ($form->{"inventory_accno_$i"} ne "") {
861 $form->{"lizenzen_$i"} = qq|<option></option>|;
862 foreach $item (@{ $form->{LIZENZEN}{$form->{"id_$i"}}}) {
863 $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
865 $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
875 # ok, so this is a new part
876 # ask if it is a part or service item
878 if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
880 $form->{"discount_$i"} = "";
884 $form->{"id_$i"} = 0;
885 $form->{"unit_$i"} = $locale->text('ea');
892 $lxdebug->leave_sub();
898 $lxdebug->enter_sub();
900 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
901 $form->isblank("customer", $locale->text('Customer missing!'));
903 # if oldcustomer ne customer redo form
904 if (&check_name(customer)) {
911 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
912 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
914 $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto);
916 $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
918 for $i (1 .. $form->{paidaccounts}) {
919 if ($form->{"paid_$i"}) {
920 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
922 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
924 $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
926 if ($form->{currency} ne $form->{defaultcurrency}) {
927 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
928 $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
934 ($form->{AR}) = split /--/, $form->{AR};
935 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
937 $form->{label} = $locale->text('Invoice');
939 $form->{id} = 0 if $form->{postasnew};
941 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber") unless $form->{invnumber};
943 $form->redirect($form->{label}." $form->{invnumber} ".$locale->text('posted!')) if (IS->post_invoice(\%myconfig, \%$form));
944 $form->error($locale->text('Cannot post invoice!'));
946 $lxdebug->leave_sub();
953 $lxdebug->enter_sub();
960 <form method=post action=$form->{script}>
963 # delete action variable
964 map { delete $form->{$_} } qw(action header);
966 foreach $key (keys %$form) {
967 $form->{$key} =~ s/\"/"/g;
968 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
972 <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
974 <h4>|.$locale->text('Are you sure you want to delete Invoice Number').qq| $form->{invnumber}
978 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
983 $lxdebug->leave_sub();
989 $lxdebug->enter_sub();
991 $form->redirect($locale->text('Invoice deleted!')) if (IS->delete_invoice(\%myconfig, \%$form, $spool));
992 $form->error($locale->text('Cannot delete invoice!'));
994 $lxdebug->leave_sub();