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", "invdate", "BL", "trigger1",
346 "duedate", "BL", "trigger2",
347 "deliverydate", "BL", "trigger3");
350 # without JavaScript Calendar
352 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
354 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
356 if ($form->{resubmit} && ($form->{format} eq "html")) {
357 $onload = qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
358 } elsif($form->{resubmit}) {
359 $onload = qq|document.invoice.submit()|;
366 <body onLoad="$onload">
368 <form method=post name="invoice" action=$form->{script}>
371 <input type=hidden name=id value=$form->{id}>
372 <input type=hidden name=action value=$form->{action}>
374 <input type=hidden name=type value=$form->{type}>
375 <input type=hidden name=media value=$form->{media}>
376 <input type=hidden name=format value=$form->{format}>
378 <input type=hidden name=queued value="$form->{queued}">
379 <input type=hidden name=printed value="$form->{printed}">
380 <input type=hidden name=emailed value="$form->{emailed}">
382 <input type=hidden name=title value="$form->{title}">
383 <input type=hidden name=vc value=$form->{vc}>
385 <input type=hidden name=discount value=$form->{discount}>
386 <input type=hidden name=creditlimit value=$form->{creditlimit}>
387 <input type=hidden name=creditremaining value=$form->{creditremaining}>
389 <input type=hidden name=tradediscount value=$form->{tradediscount}>
390 <input type=hidden name=business value=$form->{business}>
392 <input type=hidden name=closedto value=$form->{closedto}>
393 <input type=hidden name=locked value=$form->{locked}>
395 <input type=hidden name=shipped value=$form->{shipped}>
396 <input type=hidden name=lizenzen value=$lizenzen>
400 <th class=listtop>$form->{title}</th>
410 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
411 <td colspan=3>$customer</td>
412 <input type=hidden name=customer_klass value=$form->{customer_klass}>
413 <input type=hidden name=customer_id value=$form->{customer_id}>
414 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
415 <th align=richt nowrap>|
416 . $locale->text('Contact Person') . qq|</th>
417 <td colspan=3>$contact</td>
424 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
425 <td>$form->{creditlimit}</td>
427 <th nowrap>| . $locale->text('Remaining') . qq|</th>
428 <td class="plus$n">$form->{creditremaining}</td>
435 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
436 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
437 <input type=hidden name=selectAR value="$form->{selectAR}">
441 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
442 <td><select name=currency>$form->{selectcurrency}</select></td>
443 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
444 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
445 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
446 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
450 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
451 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
454 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
455 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
462 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
463 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
464 <input type=hidden name=selectemployee value="$form->{selectemployee}">
468 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
469 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
472 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
476 <th align=right>| . $locale->text('Due Date') . qq|</th>
480 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
484 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
485 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
488 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
489 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
492 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
493 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
508 <!-- shipto are in hidden variables -->
510 <input type=hidden name=shiptoname value="$form->{shiptoname}">
511 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
512 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
513 <input type=hidden name=shiptocity value="$form->{shiptocity}">
514 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
515 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
516 <input type=hidden name=shiptophone value="$form->{shiptophone}">
517 <input type=hidden name=shiptofax value="$form->{shiptofax}">
518 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
520 <!-- email variables -->
521 <input type=hidden name=message value="$form->{message}">
522 <input type=hidden name=email value="$form->{email}">
523 <input type=hidden name=subject value="$form->{subject}">
524 <input type=hidden name=cc value="$form->{cc}">
525 <input type=hidden name=bcc value="$form->{bcc}">
526 <input type=hidden name=webdav value=$webdav>
527 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
530 foreach $item (split / /, $form->{taxaccounts}) {
532 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
533 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
534 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
537 $lxdebug->leave_sub();
541 $lxdebug->enter_sub();
543 $form->{invtotal} = $form->{invsubtotal};
545 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
548 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
551 $rows = ($rows > $introws) ? $rows : $introws;
553 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
555 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
557 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
560 if ($form->{taxaccounts}) {
562 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
563 . $locale->text('Tax Included') . qq|</b><br><br>|;
566 if (!$form->{taxincluded}) {
568 foreach $item (split / /, $form->{taxaccounts}) {
569 if ($form->{"${item}_base"}) {
570 $form->{"${item}_total"} =
572 $form->{"${item}_base"} * $form->{"${item}_rate"},
574 $form->{invtotal} += $form->{"${item}_total"};
575 $form->{"${item}_total"} =
576 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
580 <th align=right>$form->{"${item}_description"}</th>
581 <td align=right>$form->{"${item}_total"}</td>
587 $form->{invsubtotal} =
588 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
592 <th align=right>| . $locale->text('Subtotal') . qq|</th>
593 <td align=right>$form->{invsubtotal}</td>
599 if ($form->{taxincluded}) {
600 foreach $item (split / /, $form->{taxaccounts}) {
601 if ($form->{"${item}_base"}) {
602 $form->{"${item}_total"} =
604 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
605 (1 + $form->{"${item}_rate"})
608 $form->{"${item}_netto"} =
610 ($form->{"${item}_base"} - $form->{"${item}_total"}),
612 $form->{"${item}_total"} =
613 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
614 $form->{"${item}_netto"} =
615 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
619 <th align=right>Enthaltene $form->{"${item}_description"}</th>
620 <td align=right>$form->{"${item}_total"}</td>
623 <th align=right>Nettobetrag</th>
624 <td align=right>$form->{"${item}_netto"}</td>
632 $form->{oldinvtotal} = $form->{invtotal};
634 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
644 <th align=left>| . $locale->text('Notes') . qq|</th>
645 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
653 <td align=right width=100%>
659 <th align=right>| . $locale->text('Total') . qq|</th>
660 <td align=right>$form->{invtotal}</td>
672 <td><hr size=3 noshade></td>
675 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
678 <td align=left width=30%><b>Dateiname</b></td>
679 <td align=left width=70%><b>Webdavlink</b></td>
681 foreach $file (keys %{ $form->{WEBDAV} }) {
684 <td align=left>$file</td>
685 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
700 <tr class=listheading>
701 <th colspan=6 class=listheading>|
702 . $locale->text('Incoming Payments') . qq|</th>
706 if ($form->{currency} eq $form->{defaultcurrency}) {
707 @column_index = qw(datepaid source memo paid AR_paid);
709 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
712 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
713 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
714 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
715 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
716 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
717 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
722 map { print "$column_data{$_}\n" } @column_index;
727 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
728 for $i (1 .. $form->{paidaccounts}) {
733 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
734 $form->{"selectAR_paid_$i"} =~
735 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
738 $totalpaid += $form->{"paid_$i"};
740 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
741 $form->{"exchangerate_$i"} =
742 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
744 $exchangerate = qq| |;
745 if ($form->{currency} ne $form->{defaultcurrency}) {
746 if ($form->{"forex_$i"}) {
748 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
751 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
756 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
759 $column_data{"paid_$i"} =
760 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
761 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
762 $column_data{"AR_paid_$i"} =
763 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
764 $column_data{"datepaid_$i"} =
765 qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
766 $column_data{"source_$i"} =
767 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
768 $column_data{"memo_$i"} =
769 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
771 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
777 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
778 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
779 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
780 <input type=hidden name=oldtotalpaid value=$totalpaid>
785 <td><hr size=3 noshade></td>
799 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
800 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
804 <input class=submit type=submit name=action value="|
805 . $locale->text('Update') . qq|">
806 <input class=submit type=submit name=action value="|
807 . $locale->text('Ship to') . qq|">
808 <input class=submit type=submit name=action value="|
809 . $locale->text('Print') . qq|">
810 <input class=submit type=submit name=action value="|
811 . $locale->text('E-mail') . qq|">
814 if (!$form->{revtrans}) {
815 if (!$form->{locked}) {
817 <input class=submit type=submit name=action value="|
818 . $locale->text('Post') . qq|">
819 <input class=submit type=submit name=action value="|
820 . $locale->text('Delete') . qq|">
825 if ($invdate > $closedto) {
827 <input class=submit type=submit name=action value="|
828 . $locale->text('Post as new') . qq|">
829 <input class=submit type=submit name=action value="|
830 . $locale->text('Order') . qq|">
835 if ($invdate > $closedto) {
836 print qq|<input class=submit type=submit name=action value="|
837 . $locale->text('Update') . qq|">
838 <input class=submit type=submit name=action value="|
839 . $locale->text('Ship to') . qq|">
840 <input class=submit type=submit name=action value="|
841 . $locale->text('Preview') . qq|">
842 <input class=submit type=submit name=action value="|
843 . $locale->text('E-mail') . qq|">
844 <input class=submit type=submit name=action value="|
845 . $locale->text('Print and Post') . qq|">
846 <input class=submit type=submit name=action value="|
847 . $locale->text('Post') . qq|">|;
851 if ($form->{menubar}) {
852 require "$form->{path}/menu.pl";
858 <input type=hidden name=rowcount value=$form->{rowcount}>
860 <input name=callback type=hidden value="$form->{callback}">
862 <input type=hidden name=path value=$form->{path}>
863 <input type=hidden name=login value=$form->{login}>
864 <input type=hidden name=password value=$form->{password}>
873 $lxdebug->leave_sub();
877 $lxdebug->enter_sub();
879 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
880 qw(exchangerate creditlimit creditremaining);
881 if ($form->{second_run}) {
882 $form->{print_and_post} = 0;
884 &check_name(customer);
888 $form->{exchangerate} = $exchangerate
892 $form->check_exchangerate(
893 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
896 for $i (1 .. $form->{paidaccounts}) {
897 if ($form->{"paid_$i"}) {
900 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
901 } qw(paid exchangerate);
903 $form->{"exchangerate_$i"} = $exchangerate
905 $form->{"forex_$i"} = (
907 $form->check_exchangerate(
908 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
913 $i = $form->{rowcount};
914 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
916 # if last row empty, check the form otherwise retrieve new item
917 if ( ($form->{"partnumber_$i"} eq "")
918 && ($form->{"description_$i"} eq "")
919 && ($form->{"partsgroup_$i"} eq "")) {
921 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
926 IS->retrieve_item(\%myconfig, \%$form);
928 $rows = scalar @{ $form->{item_list} };
930 $form->{"discount_$i"} =
931 $form->format_amount(\%myconfig, $form->{discount} * 100);
934 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
943 $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
945 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
946 qw(partnumber description unit);
947 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
948 keys %{ $form->{item_list}[0] };
950 $form->{"discount_$i"} = $form->{discount} * 100;
952 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
953 ($dec) = ($s =~ /\.(\d+)/);
955 $decimalplaces = ($dec > 2) ? $dec : 2;
958 $form->{"sellprice_$i"} = $sellprice;
961 # if there is an exchange rate adjust sellprice
962 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
963 $form->{"sellprice_$i"} /= $exchangerate;
966 $form->{"listprice_$i"} /= $exchangerate;
969 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
970 (1 - $form->{"discount_$i"} / 100);
971 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
972 map { $form->{"${_}_base"} += $amount }
973 (split / /, $form->{"taxaccounts_$i"});
974 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
975 split / /, $form->{"taxaccounts_$i"}
976 if !$form->{taxincluded};
978 $form->{creditremaining} -= $amount;
982 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
984 } qw(sellprice listprice);
987 $form->format_amount(\%myconfig, $form->{"qty_$i"});
990 if ($form->{"inventory_accno_$i"} ne "") {
991 $form->{"lizenzen_$i"} = qq|<option></option>|;
992 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
993 $form->{"lizenzen_$i"} .=
994 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
996 $form->{"lizenzen_$i"} .=
997 qq|<option value=-1>Neue Lizenz</option>|;
1001 # get pricegroups for parts
1002 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1004 # build up html code for prices_$i
1005 &set_pricegroup($i);
1012 # ok, so this is a new part
1013 # ask if it is a part or service item
1015 if ( $form->{"partsgroup_$i"}
1016 && ($form->{"partsnumber_$i"} eq "")
1017 && ($form->{"description_$i"} eq "")) {
1018 $form->{rowcount}--;
1019 $form->{"discount_$i"} = "";
1023 $form->{"id_$i"} = 0;
1024 $form->{"unit_$i"} = $locale->text('ea');
1031 $lxdebug->leave_sub();
1035 $lxdebug->enter_sub();
1036 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1037 $form->isblank("customer", $locale->text('Customer missing!'));
1039 # if oldcustomer ne customer redo form
1040 if (&check_name(customer)) {
1044 if ($form->{second_run}) {
1045 $form->{print_and_post} = 0;
1050 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1051 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1053 $form->error($locale->text('Cannot post invoice for a closed period!'))
1054 if ($invdate <= $closedto);
1056 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1057 if ($form->{currency} ne $form->{defaultcurrency});
1059 for $i (1 .. $form->{paidaccounts}) {
1060 if ($form->{"paid_$i"}) {
1061 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1063 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1065 $form->error($locale->text('Cannot post payment for a closed period!'))
1066 if ($datepaid <= $closedto);
1068 if ($form->{currency} ne $form->{defaultcurrency}) {
1069 $form->{"exchangerate_$i"} = $form->{exchangerate}
1070 if ($invdate == $datepaid);
1071 $form->isblank("exchangerate_$i",
1072 $locale->text('Exchangerate for payment missing!'));
1077 ($form->{AR}) = split /--/, $form->{AR};
1078 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1080 $form->{label} = $locale->text('Invoice');
1082 $form->{id} = 0 if $form->{postasnew};
1084 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1085 if (!$form->{invnumber} || $form->{postasnew}) {
1086 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber")
1089 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1090 $form->error($locale->text('Cannot post invoice!'));
1094 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1095 if (IS->post_invoice(\%myconfig, \%$form));
1096 $form->error($locale->text('Cannot post invoice!'));
1099 $lxdebug->leave_sub();
1102 sub print_and_post {
1103 $lxdebug->enter_sub();
1105 $old_form = new Form;
1107 $form->{print_and_post} = 1;
1111 $lxdebug->leave_sub();
1116 $lxdebug->enter_sub();
1118 $form->{preview} = 1;
1119 $old_form = new Form;
1120 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1121 $old_form->{rowcount}++;
1123 &print_form($old_form);
1124 $lxdebug->leave_sub();
1129 $lxdebug->enter_sub();
1130 if ($form->{second_run}) {
1131 $form->{print_and_post} = 0;
1138 <form method=post action=$form->{script}>
1141 # delete action variable
1142 map { delete $form->{$_} } qw(action header);
1144 foreach $key (keys %$form) {
1145 $form->{$key} =~ s/\"/"/g;
1146 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1150 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1153 . $locale->text('Are you sure you want to delete Invoice Number')
1154 . qq| $form->{invnumber}
1158 <input name=action class=submit type=submit value="|
1159 . $locale->text('Yes') . qq|">
1163 $lxdebug->leave_sub();
1167 $lxdebug->enter_sub();
1169 $form->redirect($locale->text('Invoice deleted!'))
1170 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1171 $form->error($locale->text('Cannot delete invoice!'));
1173 $lxdebug->leave_sub();