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 Sales Invoice');
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";
56 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
58 $form->error("Access Denied");
62 $form->{format} = "pdf";
66 $lxdebug->leave_sub();
70 $lxdebug->enter_sub();
72 $form->{title} = $locale->text('Edit Sales Invoice');
74 if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR")
76 $form->error("Access Denied");
78 if ($form->{print_and_post}) {
79 $form->{action} = "print";
80 $form->{resubmit} = 1;
86 $lxdebug->leave_sub();
90 $lxdebug->enter_sub();
92 $form->{vc} = 'customer';
95 $form->{webdav} = $webdav;
96 $form->{lizenzen} = $lizenzen;
98 $form->create_links("AR", \%myconfig, "customer");
100 if ($form->{all_customer}) {
101 unless ($form->{customer_id}) {
102 $form->{customer_id} = $form->{all_customer}->[0]->{id};
105 $cp_id = $form->{cp_id};
106 IS->get_customer(\%myconfig, \%$form);
108 IS->retrieve_invoice(\%myconfig, \%$form);
109 $form->{cp_id} = $cp_id;
112 @curr = split /:/, $form->{currencies};
114 $form->{defaultcurrency} = $curr[0];
116 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
118 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
120 if ($form->{all_customer}) {
121 $form->{customer} = "$form->{customer}--$form->{customer_id}";
122 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
123 (@{ $form->{all_customer} });
127 if ($form->{all_departments}) {
128 $form->{selectdepartment} = "<option>\n";
129 $form->{department} = "$form->{department}--$form->{department_id}";
132 $form->{selectdepartment} .=
133 "<option>$_->{description}--$_->{id}\n"
134 } (@{ $form->{all_departments} });
137 $form->{employee} = "$form->{employee}--$form->{employee_id}";
140 if ($form->{all_employees}) {
141 $form->{selectemployee} = "";
142 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
143 (@{ $form->{all_employees} });
147 $form->{forex} = $form->{exchangerate};
148 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
150 foreach $key (keys %{ $form->{AR_links} }) {
151 foreach $ref (@{ $form->{AR_links}{$key} }) {
152 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
155 if ($key eq "AR_paid") {
156 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
157 $form->{"AR_paid_$i"} =
158 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
161 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
162 $form->{"datepaid_$i"} =
163 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
164 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
165 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
166 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
167 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
169 $form->{paidaccounts} = $i;
173 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
178 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
180 $form->{AR} = $form->{AR_1} unless $form->{id};
183 ($form->datetonum($form->{invdate}, \%myconfig) <=
184 $form->datetonum($form->{closedto}, \%myconfig));
186 $lxdebug->leave_sub();
189 sub prepare_invoice {
190 $lxdebug->enter_sub();
192 $form->{type} = "invoice";
193 $form->{formname} = "invoice";
194 $form->{media} = "screen";
198 map { $form->{$_} =~ s/\"/"/g }
199 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
201 # # get pricegroups for parts
202 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
204 foreach $ref (@{ $form->{invoice_details} }) {
206 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
207 $form->{"discount_$i"} =
208 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
209 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
211 $decimalplaces = ($dec > 2) ? $dec : 2;
213 $form->{"sellprice_$i"} =
214 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
217 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
218 $dec_qty = length $dec_qty;
221 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
223 map { $form->{"${_}_$i"} =~ s/\"/"/g }
224 qw(partnumber description unit partnotes);
225 $form->{rowcount} = $i;
229 $lxdebug->leave_sub();
233 $lxdebug->enter_sub();
235 # set option selected
236 foreach $item (qw(AR customer currency department employee contact)) {
237 $form->{"select$item"} =~ s/ selected//;
238 $form->{"select$item"} =~
239 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
243 if ($form->{all_contacts}) {
245 $form->{selectcontact} = "";
246 foreach $item (@{ $form->{all_contacts} }) {
247 if ($form->{cp_id} == $item->{cp_id}) {
248 $form->{selectcontact} .=
249 "<option selected>$item->{cp_name}--$item->{cp_id}";
251 $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
256 #else {$form->{all_contacts} = 0;}
258 $form->{exchangerate} =
259 $form->format_amount(\%myconfig, $form->{exchangerate});
261 $form->{creditlimit} =
262 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
263 $form->{creditremaining} =
264 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
267 if ($form->{currency} ne $form->{defaultcurrency}) {
268 if ($form->{forex}) {
271 . $locale->text('Exchangerate')
272 . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
276 . $locale->text('Exchangerate')
277 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
281 <input type=hidden name=forex value=$form->{forex}>
285 ($form->{selectcustomer})
286 ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
287 : qq|<input name=customer value="$form->{customer}" size=35>|;
291 ($form->{selectcontact})
292 ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
293 : qq|<input name=contact value="$form->{contact}" size=35>|;
297 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
298 <td colspan=3><select name=department>$form->{selectdepartment}</select>
299 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
302 | if $form->{selectdepartment};
304 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
306 if ($form->{business}) {
309 <th align=right>| . $locale->text('Business') . qq|</th>
310 <td>$form->{business}</td>
311 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
313 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
319 $form->{fokus} = "invoice.customer";
321 # use JavaScript Calendar or not
322 $form->{jsscript} = $jscalendar;
324 if ($form->{jsscript}) {
326 # with JavaScript Calendar
328 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
329 <td><input type=button name=invdate id="trigger1" value=|
330 . $locale->text('button') . qq|></td>
333 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
334 <td width="4"><input type=button name=duedate id="trigger2" value=|
335 . $locale->text('button') . qq|></td></td>
338 <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
339 <td width="4"><input type=button name=deliverydate id="trigger3" value=|
340 . $locale->text('button') . qq|></td></td>
345 Form->write_trigger(\%myconfig, "3",
347 "trigger1", "duedate",
349 "deliverydate", "BL",
353 # without JavaScript Calendar
355 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
357 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
359 if ($form->{resubmit} && ($form->{format} eq "html")) {
361 qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
362 } elsif ($form->{resubmit}) {
363 $onload = qq|document.invoice.submit()|;
370 <body onLoad="$onload">
372 <form method=post name="invoice" action=$form->{script}>
375 <input type=hidden name=id value=$form->{id}>
376 <input type=hidden name=action value=$form->{action}>
378 <input type=hidden name=type value=$form->{type}>
379 <input type=hidden name=media value=$form->{media}>
380 <input type=hidden name=format value=$form->{format}>
382 <input type=hidden name=queued value="$form->{queued}">
383 <input type=hidden name=printed value="$form->{printed}">
384 <input type=hidden name=emailed value="$form->{emailed}">
386 <input type=hidden name=title value="$form->{title}">
387 <input type=hidden name=vc value=$form->{vc}>
389 <input type=hidden name=discount value=$form->{discount}>
390 <input type=hidden name=creditlimit value=$form->{creditlimit}>
391 <input type=hidden name=creditremaining value=$form->{creditremaining}>
393 <input type=hidden name=tradediscount value=$form->{tradediscount}>
394 <input type=hidden name=business value=$form->{business}>
396 <input type=hidden name=closedto value=$form->{closedto}>
397 <input type=hidden name=locked value=$form->{locked}>
399 <input type=hidden name=shipped value=$form->{shipped}>
400 <input type=hidden name=lizenzen value=$lizenzen>
404 <th class=listtop>$form->{title}</th>
414 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
415 <td colspan=3>$customer</td>
416 <input type=hidden name=customer_klass value=$form->{customer_klass}>
417 <input type=hidden name=customer_id value=$form->{customer_id}>
418 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
419 <th align=richt nowrap>|
420 . $locale->text('Contact Person') . qq|</th>
421 <td colspan=3>$contact</td>
428 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
429 <td>$form->{creditlimit}</td>
431 <th nowrap>| . $locale->text('Remaining') . qq|</th>
432 <td class="plus$n">$form->{creditremaining}</td>
439 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
440 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
441 <input type=hidden name=selectAR value="$form->{selectAR}">
445 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
446 <td><select name=currency>$form->{selectcurrency}</select></td>
447 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
448 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
449 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
450 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
454 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
455 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
458 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
459 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
466 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
467 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
468 <input type=hidden name=selectemployee value="$form->{selectemployee}">
472 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
473 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
476 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
480 <th align=right>| . $locale->text('Due Date') . qq|</th>
484 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
488 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
489 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
492 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
493 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
496 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
497 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
512 <!-- shipto are in hidden variables -->
514 <input type=hidden name=shiptoname value="$form->{shiptoname}">
515 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
516 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
517 <input type=hidden name=shiptocity value="$form->{shiptocity}">
518 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
519 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
520 <input type=hidden name=shiptophone value="$form->{shiptophone}">
521 <input type=hidden name=shiptofax value="$form->{shiptofax}">
522 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
524 <!-- email variables -->
525 <input type=hidden name=message value="$form->{message}">
526 <input type=hidden name=email value="$form->{email}">
527 <input type=hidden name=subject value="$form->{subject}">
528 <input type=hidden name=cc value="$form->{cc}">
529 <input type=hidden name=bcc value="$form->{bcc}">
530 <input type=hidden name=webdav value=$webdav>
531 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
534 foreach $item (split / /, $form->{taxaccounts}) {
536 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
537 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
538 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
541 $lxdebug->leave_sub();
545 $lxdebug->enter_sub();
547 $form->{invtotal} = $form->{invsubtotal};
549 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
552 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
555 $rows = ($rows > $introws) ? $rows : $introws;
557 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
559 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
561 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
564 if ($form->{taxaccounts}) {
566 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
567 . $locale->text('Tax Included') . qq|</b><br><br>|;
570 if (!$form->{taxincluded}) {
572 foreach $item (split / /, $form->{taxaccounts}) {
573 if ($form->{"${item}_base"}) {
574 $form->{"${item}_total"} =
576 $form->{"${item}_base"} * $form->{"${item}_rate"},
578 $form->{invtotal} += $form->{"${item}_total"};
579 $form->{"${item}_total"} =
580 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
584 <th align=right>$form->{"${item}_description"}</th>
585 <td align=right>$form->{"${item}_total"}</td>
591 $form->{invsubtotal} =
592 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
596 <th align=right>| . $locale->text('Subtotal') . qq|</th>
597 <td align=right>$form->{invsubtotal}</td>
603 if ($form->{taxincluded}) {
604 foreach $item (split / /, $form->{taxaccounts}) {
605 if ($form->{"${item}_base"}) {
606 $form->{"${item}_total"} =
608 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
609 (1 + $form->{"${item}_rate"})
612 $form->{"${item}_netto"} =
614 ($form->{"${item}_base"} - $form->{"${item}_total"}),
616 $form->{"${item}_total"} =
617 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
618 $form->{"${item}_netto"} =
619 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
623 <th align=right>Enthaltene $form->{"${item}_description"}</th>
624 <td align=right>$form->{"${item}_total"}</td>
627 <th align=right>Nettobetrag</th>
628 <td align=right>$form->{"${item}_netto"}</td>
636 $form->{oldinvtotal} = $form->{invtotal};
638 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
648 <th align=left>| . $locale->text('Notes') . qq|</th>
649 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
657 <td align=right width=100%>
663 <th align=right>| . $locale->text('Total') . qq|</th>
664 <td align=right>$form->{invtotal}</td>
676 <td><hr size=3 noshade></td>
679 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
682 <td align=left width=30%><b>Dateiname</b></td>
683 <td align=left width=70%><b>Webdavlink</b></td>
685 foreach $file (keys %{ $form->{WEBDAV} }) {
688 <td align=left>$file</td>
689 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
704 <tr class=listheading>
705 <th colspan=6 class=listheading>|
706 . $locale->text('Incoming Payments') . qq|</th>
710 if ($form->{currency} eq $form->{defaultcurrency}) {
711 @column_index = qw(datepaid source memo paid AR_paid);
713 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
716 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
717 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
718 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
719 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
720 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
721 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
726 map { print "$column_data{$_}\n" } @column_index;
731 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
732 for $i (1 .. $form->{paidaccounts}) {
737 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
738 $form->{"selectAR_paid_$i"} =~
739 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
742 $totalpaid += $form->{"paid_$i"};
744 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
745 $form->{"exchangerate_$i"} =
746 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
748 $exchangerate = qq| |;
749 if ($form->{currency} ne $form->{defaultcurrency}) {
750 if ($form->{"forex_$i"}) {
752 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
755 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
760 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
763 $column_data{"paid_$i"} =
764 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
765 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
766 $column_data{"AR_paid_$i"} =
767 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
768 $column_data{"datepaid_$i"} =
769 qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
770 $column_data{"source_$i"} =
771 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
772 $column_data{"memo_$i"} =
773 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
775 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
781 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
782 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
783 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
784 <input type=hidden name=oldtotalpaid value=$totalpaid>
789 <td><hr size=3 noshade></td>
803 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
804 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
808 <input class=submit type=submit name=action value="|
809 . $locale->text('Update') . qq|">
810 <input class=submit type=submit name=action value="|
811 . $locale->text('Ship to') . qq|">
812 <input class=submit type=submit name=action value="|
813 . $locale->text('Print') . qq|">
814 <input class=submit type=submit name=action value="|
815 . $locale->text('E-mail') . qq|">
818 if (!$form->{revtrans}) {
819 if (!$form->{locked}) {
821 <input class=submit type=submit name=action value="|
822 . $locale->text('Post') . qq|">
823 <input class=submit type=submit name=action value="|
824 . $locale->text('Delete') . qq|">
829 if ($invdate > $closedto) {
831 <input class=submit type=submit name=action value="|
832 . $locale->text('Post as new') . qq|">
833 <input class=submit type=submit name=action value="|
834 . $locale->text('Order') . qq|">
839 if ($invdate > $closedto) {
840 print qq|<input class=submit type=submit name=action value="|
841 . $locale->text('Update') . qq|">
842 <input class=submit type=submit name=action value="|
843 . $locale->text('Ship to') . qq|">
844 <input class=submit type=submit name=action value="|
845 . $locale->text('Preview') . qq|">
846 <input class=submit type=submit name=action value="|
847 . $locale->text('E-mail') . qq|">
848 <input class=submit type=submit name=action value="|
849 . $locale->text('Print and Post') . qq|">
850 <input class=submit type=submit name=action value="|
851 . $locale->text('Post') . qq|">|;
855 if ($form->{menubar}) {
856 require "$form->{path}/menu.pl";
862 <input type=hidden name=rowcount value=$form->{rowcount}>
864 <input name=callback type=hidden value="$form->{callback}">
866 <input type=hidden name=path value=$form->{path}>
867 <input type=hidden name=login value=$form->{login}>
868 <input type=hidden name=password value=$form->{password}>
877 $lxdebug->leave_sub();
881 $lxdebug->enter_sub();
883 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
884 qw(exchangerate creditlimit creditremaining);
885 if ($form->{second_run}) {
886 $form->{print_and_post} = 0;
888 &check_name(customer);
892 $form->{exchangerate} = $exchangerate
896 $form->check_exchangerate(
897 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
900 for $i (1 .. $form->{paidaccounts}) {
901 if ($form->{"paid_$i"}) {
904 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
905 } qw(paid exchangerate);
907 $form->{"exchangerate_$i"} = $exchangerate
909 $form->{"forex_$i"} = (
911 $form->check_exchangerate(
912 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
917 $i = $form->{rowcount};
918 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
920 # if last row empty, check the form otherwise retrieve new item
921 if ( ($form->{"partnumber_$i"} eq "")
922 && ($form->{"description_$i"} eq "")
923 && ($form->{"partsgroup_$i"} eq "")) {
925 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
930 IS->retrieve_item(\%myconfig, \%$form);
932 $rows = scalar @{ $form->{item_list} };
934 $form->{"discount_$i"} =
935 $form->format_amount(\%myconfig, $form->{discount} * 100);
938 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
947 $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
949 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
950 qw(partnumber description unit);
951 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
952 keys %{ $form->{item_list}[0] };
954 $form->{"discount_$i"} = $form->{discount} * 100;
956 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
957 ($dec) = ($s =~ /\.(\d+)/);
959 $decimalplaces = ($dec > 2) ? $dec : 2;
962 $form->{"sellprice_$i"} = $sellprice;
965 # if there is an exchange rate adjust sellprice
966 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
967 $form->{"sellprice_$i"} /= $exchangerate;
970 $form->{"listprice_$i"} /= $exchangerate;
973 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
974 (1 - $form->{"discount_$i"} / 100);
975 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
976 map { $form->{"${_}_base"} += $amount }
977 (split / /, $form->{"taxaccounts_$i"});
978 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
979 split / /, $form->{"taxaccounts_$i"}
980 if !$form->{taxincluded};
982 $form->{creditremaining} -= $amount;
986 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
988 } qw(sellprice listprice);
991 $form->format_amount(\%myconfig, $form->{"qty_$i"});
994 if ($form->{"inventory_accno_$i"} ne "") {
995 $form->{"lizenzen_$i"} = qq|<option></option>|;
996 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
997 $form->{"lizenzen_$i"} .=
998 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1000 $form->{"lizenzen_$i"} .=
1001 qq|<option value=-1>Neue Lizenz</option>|;
1005 # get pricegroups for parts
1006 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1008 # build up html code for prices_$i
1009 &set_pricegroup($i);
1016 # ok, so this is a new part
1017 # ask if it is a part or service item
1019 if ( $form->{"partsgroup_$i"}
1020 && ($form->{"partsnumber_$i"} eq "")
1021 && ($form->{"description_$i"} eq "")) {
1022 $form->{rowcount}--;
1023 $form->{"discount_$i"} = "";
1027 $form->{"id_$i"} = 0;
1028 $form->{"unit_$i"} = $locale->text('ea');
1035 $lxdebug->leave_sub();
1039 $lxdebug->enter_sub();
1040 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1041 $form->isblank("customer", $locale->text('Customer missing!'));
1043 # if oldcustomer ne customer redo form
1044 if (&check_name(customer)) {
1048 if ($form->{second_run}) {
1049 $form->{print_and_post} = 0;
1054 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1055 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1057 $form->error($locale->text('Cannot post invoice for a closed period!'))
1058 if ($invdate <= $closedto);
1060 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1061 if ($form->{currency} ne $form->{defaultcurrency});
1063 for $i (1 .. $form->{paidaccounts}) {
1064 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1065 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1067 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1069 $form->error($locale->text('Cannot post payment for a closed period!'))
1070 if ($datepaid <= $closedto);
1072 if ($form->{currency} ne $form->{defaultcurrency}) {
1073 $form->{"exchangerate_$i"} = $form->{exchangerate}
1074 if ($invdate == $datepaid);
1075 $form->isblank("exchangerate_$i",
1076 $locale->text('Exchangerate for payment missing!'));
1081 ($form->{AR}) = split /--/, $form->{AR};
1082 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1084 $form->{label} = $locale->text('Invoice');
1086 $form->{id} = 0 if $form->{postasnew};
1088 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1089 if (!$form->{invnumber} || $form->{postasnew}) {
1090 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
1093 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1094 $form->error($locale->text('Cannot post invoice!'));
1098 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1099 if (IS->post_invoice(\%myconfig, \%$form));
1100 $form->error($locale->text('Cannot post invoice!'));
1103 $lxdebug->leave_sub();
1106 sub print_and_post {
1107 $lxdebug->enter_sub();
1109 $old_form = new Form;
1111 $form->{print_and_post} = 1;
1115 $lxdebug->leave_sub();
1120 $lxdebug->enter_sub();
1122 $form->{preview} = 1;
1123 $old_form = new Form;
1124 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1125 $old_form->{rowcount}++;
1127 &print_form($old_form);
1128 $lxdebug->leave_sub();
1133 $lxdebug->enter_sub();
1134 if ($form->{second_run}) {
1135 $form->{print_and_post} = 0;
1142 <form method=post action=$form->{script}>
1145 # delete action variable
1146 map { delete $form->{$_} } qw(action header);
1148 foreach $key (keys %$form) {
1149 $form->{$key} =~ s/\"/"/g;
1150 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1154 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1157 . $locale->text('Are you sure you want to delete Invoice Number')
1158 . qq| $form->{invnumber}
1162 <input name=action class=submit type=submit value="|
1163 . $locale->text('Yes') . qq|">
1167 $lxdebug->leave_sub();
1171 $lxdebug->enter_sub();
1173 $form->redirect($locale->text('Invoice deleted!'))
1174 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1175 $form->error($locale->text('Cannot delete invoice!'));
1177 $lxdebug->leave_sub();