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 #quote all_customer Bug 133
109 foreach $ref (@{ $form->{all_customer} }) {
110 $ref->{name} = $form->quote($ref->{name});
113 IS->retrieve_invoice(\%myconfig, \%$form);
114 $form->{cp_id} = $cp_id;
117 @curr = split /:/, $form->{currencies};
119 $form->{defaultcurrency} = $curr[0];
121 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
123 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
125 if ($form->{all_customer}) {
126 $form->{customer} = "$form->{customer}--$form->{customer_id}";
127 map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
128 (@{ $form->{all_customer} });
132 if ($form->{all_departments}) {
133 $form->{selectdepartment} = "<option>\n";
134 $form->{department} = "$form->{department}--$form->{department_id}";
137 $form->{selectdepartment} .=
138 "<option>$_->{description}--$_->{id}\n"
139 } (@{ $form->{all_departments} });
142 $form->{employee} = "$form->{employee}--$form->{employee_id}";
145 if ($form->{all_employees}) {
146 $form->{selectemployee} = "";
147 map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
148 (@{ $form->{all_employees} });
152 $form->{forex} = $form->{exchangerate};
153 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
155 foreach $key (keys %{ $form->{AR_links} }) {
156 foreach $ref (@{ $form->{AR_links}{$key} }) {
157 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
160 if ($key eq "AR_paid") {
161 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
162 $form->{"AR_paid_$i"} =
163 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
166 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1;
167 $form->{"datepaid_$i"} =
168 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
169 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
170 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
171 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
172 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
174 $form->{paidaccounts} = $i;
178 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
183 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
185 $form->{AR} = $form->{AR_1} unless $form->{id};
188 ($form->datetonum($form->{invdate}, \%myconfig) <=
189 $form->datetonum($form->{closedto}, \%myconfig));
191 $lxdebug->leave_sub();
194 sub prepare_invoice {
195 $lxdebug->enter_sub();
197 $form->{type} = "invoice";
198 $form->{formname} = "invoice";
199 $form->{media} = "screen";
203 map { $form->{$_} =~ s/\"/"/g }
204 qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
206 # # get pricegroups for parts
207 # IS->get_pricegroups_for_parts(\%myconfig, \%$form);
209 foreach $ref (@{ $form->{invoice_details} }) {
211 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
212 $form->{"discount_$i"} =
213 $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
214 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
216 $decimalplaces = ($dec > 2) ? $dec : 2;
218 $form->{"sellprice_$i"} =
219 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
222 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
223 $dec_qty = length $dec_qty;
226 $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
228 map { $form->{"${_}_$i"} =~ s/\"/"/g }
229 qw(partnumber description unit partnotes);
230 $form->{rowcount} = $i;
234 $lxdebug->leave_sub();
238 $lxdebug->enter_sub();
240 # set option selected
241 foreach $item (qw(AR customer currency department employee contact)) {
242 $form->{"select$item"} =~ s/ selected//;
243 $form->{"select$item"} =~
244 s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
247 #quote customer Bug 133
248 $form->{selectcustomer} = $form->quote($form->{selectcustomer});
251 if ($form->{all_contacts}) {
253 $form->{selectcontact} = "";
254 foreach $item (@{ $form->{all_contacts} }) {
255 if ($form->{cp_id} == $item->{cp_id}) {
256 $form->{selectcontact} .=
257 "<option selected>$item->{cp_name}--$item->{cp_id}";
259 $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
264 #else {$form->{all_contacts} = 0;}
266 $form->{exchangerate} =
267 $form->format_amount(\%myconfig, $form->{exchangerate});
269 $form->{creditlimit} =
270 $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
271 $form->{creditremaining} =
272 $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
275 if ($form->{currency} ne $form->{defaultcurrency}) {
276 if ($form->{forex}) {
279 . $locale->text('Exchangerate')
280 . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
284 . $locale->text('Exchangerate')
285 . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
289 <input type=hidden name=forex value=$form->{forex}>
293 ($form->{selectcustomer})
294 ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
295 : qq|<input name=customer value="$form->{customer}" size=35>|;
299 ($form->{selectcontact})
300 ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
301 : qq|<input name=contact value="$form->{contact}" size=35>|;
305 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
306 <td colspan=3><select name=department>$form->{selectdepartment}</select>
307 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
310 | if $form->{selectdepartment};
312 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
314 if ($form->{business}) {
317 <th align=right>| . $locale->text('Business') . qq|</th>
318 <td>$form->{business}</td>
319 <th align=right>| . $locale->text('Trade Discount') . qq|</th>
321 . $form->format_amount(\%myconfig, $form->{tradediscount} * 100)
327 $form->{fokus} = "invoice.customer";
329 # use JavaScript Calendar or not
330 $form->{jsscript} = $jscalendar;
332 if ($form->{jsscript}) {
334 # with JavaScript Calendar
336 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
337 <td><input type=button name=invdate id="trigger1" value=|
338 . $locale->text('button') . qq|></td>
341 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
342 <td width="4"><input type=button name=duedate id="trigger2" value=|
343 . $locale->text('button') . qq|></td></td>
346 <td width="13"><input name=deliverydate id=deliverydate size=11 title="$myconfig{dateformat}" value=$form->{deliverydate}></td>
347 <td width="4"><input type=button name=deliverydate id="trigger3" value=|
348 . $locale->text('button') . qq|></td></td>
353 Form->write_trigger(\%myconfig, "3",
355 "trigger1", "duedate",
357 "deliverydate", "BL",
361 # without JavaScript Calendar
363 qq|<td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>|;
365 qq|<td width="13"><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>|;
367 if ($form->{resubmit} && ($form->{format} eq "html")) {
369 qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|;
370 } elsif ($form->{resubmit}) {
371 $onload = qq|document.invoice.submit()|;
378 <body onLoad="$onload">
380 <form method=post name="invoice" action=$form->{script}>
383 <input type=hidden name=id value=$form->{id}>
384 <input type=hidden name=action value=$form->{action}>
386 <input type=hidden name=type value=$form->{type}>
387 <input type=hidden name=media value=$form->{media}>
388 <input type=hidden name=format value=$form->{format}>
390 <input type=hidden name=queued value="$form->{queued}">
391 <input type=hidden name=printed value="$form->{printed}">
392 <input type=hidden name=emailed value="$form->{emailed}">
394 <input type=hidden name=title value="$form->{title}">
395 <input type=hidden name=vc value=$form->{vc}>
397 <input type=hidden name=discount value=$form->{discount}>
398 <input type=hidden name=creditlimit value=$form->{creditlimit}>
399 <input type=hidden name=creditremaining value=$form->{creditremaining}>
401 <input type=hidden name=tradediscount value=$form->{tradediscount}>
402 <input type=hidden name=business value=$form->{business}>
404 <input type=hidden name=closedto value=$form->{closedto}>
405 <input type=hidden name=locked value=$form->{locked}>
407 <input type=hidden name=shipped value=$form->{shipped}>
408 <input type=hidden name=lizenzen value=$lizenzen>
412 <th class=listtop>$form->{title}</th>
422 <th align=right nowrap>| . $locale->text('Customer') . qq|</th>
423 <td colspan=3>$customer</td>
424 <input type=hidden name=customer_klass value=$form->{customer_klass}>
425 <input type=hidden name=customer_id value=$form->{customer_id}>
426 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
427 <th align=richt nowrap>|
428 . $locale->text('Contact Person') . qq|</th>
429 <td colspan=3>$contact</td>
436 <th nowrap>| . $locale->text('Credit Limit') . qq|</th>
437 <td>$form->{creditlimit}</td>
439 <th nowrap>| . $locale->text('Remaining') . qq|</th>
440 <td class="plus$n">$form->{creditremaining}</td>
447 <th align=right nowrap>| . $locale->text('Record in') . qq|</th>
448 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
449 <input type=hidden name=selectAR value="$form->{selectAR}">
453 <th align=right nowrap>| . $locale->text('Currency') . qq|</th>
454 <td><select name=currency>$form->{selectcurrency}</select></td>
455 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
456 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
457 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
458 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
462 <th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
463 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
466 <th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
467 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
474 <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
475 <td colspan=2><select name=employee>$form->{selectemployee}</select></td>
476 <input type=hidden name=selectemployee value="$form->{selectemployee}">
480 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
481 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
484 <th align=right>| . $locale->text('Invoice Date') . qq|</th>
488 <th align=right>| . $locale->text('Due Date') . qq|</th>
492 <th align=right>| . $locale->text('Delivery Date') . qq|</th>
496 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
497 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
500 <th align=right nowrap>| . $locale->text('Quotation Number') . qq|</th>
501 <td><input name=quonumber size=11 value="$form->{quonumber}"></td>
504 <th align=right nowrap>| . $locale->text('Customer Order Number') . qq|</th>
505 <td><input name=cusordnumber size=11 value="$form->{cusordnumber}"></td>
520 <!-- shipto are in hidden variables -->
522 <input type=hidden name=shiptoname value="$form->{shiptoname}">
523 <input type=hidden name=shiptostreet value="$form->{shiptostreet}">
524 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
525 <input type=hidden name=shiptocity value="$form->{shiptocity}">
526 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
527 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
528 <input type=hidden name=shiptophone value="$form->{shiptophone}">
529 <input type=hidden name=shiptofax value="$form->{shiptofax}">
530 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
532 <!-- email variables -->
533 <input type=hidden name=message value="$form->{message}">
534 <input type=hidden name=email value="$form->{email}">
535 <input type=hidden name=subject value="$form->{subject}">
536 <input type=hidden name=cc value="$form->{cc}">
537 <input type=hidden name=bcc value="$form->{bcc}">
538 <input type=hidden name=webdav value=$webdav>
539 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
542 foreach $item (split / /, $form->{taxaccounts}) {
544 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
545 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
546 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
549 $lxdebug->leave_sub();
553 $lxdebug->enter_sub();
555 $form->{invtotal} = $form->{invsubtotal};
557 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
560 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
563 $rows = ($rows > $introws) ? $rows : $introws;
565 qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
567 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
569 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
572 if ($form->{taxaccounts}) {
574 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
575 . $locale->text('Tax Included') . qq|</b><br><br>|;
578 if (!$form->{taxincluded}) {
580 foreach $item (split / /, $form->{taxaccounts}) {
581 if ($form->{"${item}_base"}) {
582 $form->{"${item}_total"} =
584 $form->{"${item}_base"} * $form->{"${item}_rate"},
586 $form->{invtotal} += $form->{"${item}_total"};
587 $form->{"${item}_total"} =
588 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
592 <th align=right>$form->{"${item}_description"}</th>
593 <td align=right>$form->{"${item}_total"}</td>
599 $form->{invsubtotal} =
600 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
604 <th align=right>| . $locale->text('Subtotal') . qq|</th>
605 <td align=right>$form->{invsubtotal}</td>
611 if ($form->{taxincluded}) {
612 foreach $item (split / /, $form->{taxaccounts}) {
613 if ($form->{"${item}_base"}) {
614 $form->{"${item}_total"} =
616 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
617 (1 + $form->{"${item}_rate"})
620 $form->{"${item}_netto"} =
622 ($form->{"${item}_base"} - $form->{"${item}_total"}),
624 $form->{"${item}_total"} =
625 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
626 $form->{"${item}_netto"} =
627 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
631 <th align=right>Enthaltene $form->{"${item}_description"}</th>
632 <td align=right>$form->{"${item}_total"}</td>
635 <th align=right>Nettobetrag</th>
636 <td align=right>$form->{"${item}_netto"}</td>
644 $form->{oldinvtotal} = $form->{invtotal};
646 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
656 <th align=left>| . $locale->text('Notes') . qq|</th>
657 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
665 <td align=right width=100%>
671 <th align=right>| . $locale->text('Total') . qq|</th>
672 <td align=right>$form->{invtotal}</td>
684 <td><hr size=3 noshade></td>
687 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
690 <td align=left width=30%><b>Dateiname</b></td>
691 <td align=left width=70%><b>Webdavlink</b></td>
693 foreach $file (keys %{ $form->{WEBDAV} }) {
696 <td align=left>$file</td>
697 <td align=left><a href="$form->{WEBDAV}{$file}">$form->{WEBDAV}{$file}</a></td>
712 <tr class=listheading>
713 <th colspan=6 class=listheading>|
714 . $locale->text('Incoming Payments') . qq|</th>
718 if ($form->{currency} eq $form->{defaultcurrency}) {
719 @column_index = qw(datepaid source memo paid AR_paid);
721 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
724 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
725 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
726 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
727 $column_data{AR_paid} = "<th>" . $locale->text('Account') . "</th>";
728 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
729 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
734 map { print "$column_data{$_}\n" } @column_index;
739 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
740 for $i (1 .. $form->{paidaccounts}) {
745 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
746 $form->{"selectAR_paid_$i"} =~
747 s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
750 $totalpaid += $form->{"paid_$i"};
752 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
753 $form->{"exchangerate_$i"} =
754 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
756 $exchangerate = qq| |;
757 if ($form->{currency} ne $form->{defaultcurrency}) {
758 if ($form->{"forex_$i"}) {
760 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
763 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
768 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
771 $column_data{"paid_$i"} =
772 qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
773 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
774 $column_data{"AR_paid_$i"} =
775 qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
776 $column_data{"datepaid_$i"} =
777 qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
778 $column_data{"source_$i"} =
779 qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
780 $column_data{"memo_$i"} =
781 qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
783 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
789 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
790 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
791 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
792 <input type=hidden name=oldtotalpaid value=$totalpaid>
797 <td><hr size=3 noshade></td>
811 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
812 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
816 <input class=submit type=submit name=action value="|
817 . $locale->text('Update') . qq|">
818 <input class=submit type=submit name=action value="|
819 . $locale->text('Ship to') . qq|">
820 <input class=submit type=submit name=action value="|
821 . $locale->text('Print') . qq|">
822 <input class=submit type=submit name=action value="|
823 . $locale->text('E-mail') . qq|">
826 if (!$form->{revtrans}) {
827 if (!$form->{locked}) {
829 <input class=submit type=submit name=action value="|
830 . $locale->text('Post') . qq|">
831 <input class=submit type=submit name=action value="|
832 . $locale->text('Delete') . qq|">
837 if ($invdate > $closedto) {
839 <input class=submit type=submit name=action value="|
840 . $locale->text('Post as new') . qq|">
841 <input class=submit type=submit name=action value="|
842 . $locale->text('Order') . qq|">
847 if ($invdate > $closedto) {
848 print qq|<input class=submit type=submit name=action value="|
849 . $locale->text('Update') . qq|">
850 <input class=submit type=submit name=action value="|
851 . $locale->text('Ship to') . qq|">
852 <input class=submit type=submit name=action value="|
853 . $locale->text('Preview') . qq|">
854 <input class=submit type=submit name=action value="|
855 . $locale->text('E-mail') . qq|">
856 <input class=submit type=submit name=action value="|
857 . $locale->text('Print and Post') . qq|">
858 <input class=submit type=submit name=action value="|
859 . $locale->text('Post') . qq|">|;
863 if ($form->{menubar}) {
864 require "$form->{path}/menu.pl";
870 <input type=hidden name=rowcount value=$form->{rowcount}>
872 <input name=callback type=hidden value="$form->{callback}">
874 <input type=hidden name=path value=$form->{path}>
875 <input type=hidden name=login value=$form->{login}>
876 <input type=hidden name=password value=$form->{password}>
885 $lxdebug->leave_sub();
889 $lxdebug->enter_sub();
891 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
892 qw(exchangerate creditlimit creditremaining);
893 if ($form->{second_run}) {
894 $form->{print_and_post} = 0;
896 &check_name(customer);
900 $form->{exchangerate} = $exchangerate
904 $form->check_exchangerate(
905 \%myconfig, $form->{currency}, $form->{invdate}, 'buy'
908 for $i (1 .. $form->{paidaccounts}) {
909 if ($form->{"paid_$i"}) {
912 $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
913 } qw(paid exchangerate);
915 $form->{"exchangerate_$i"} = $exchangerate
917 $form->{"forex_$i"} = (
919 $form->check_exchangerate(
920 \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
925 $i = $form->{rowcount};
926 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
928 # if last row empty, check the form otherwise retrieve new item
929 if ( ($form->{"partnumber_$i"} eq "")
930 && ($form->{"description_$i"} eq "")
931 && ($form->{"partsgroup_$i"} eq "")) {
933 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
938 IS->retrieve_item(\%myconfig, \%$form);
940 $rows = scalar @{ $form->{item_list} };
942 $form->{"discount_$i"} =
943 $form->format_amount(\%myconfig, $form->{discount} * 100);
946 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
955 $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"});
957 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g }
958 qw(partnumber description unit);
959 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} }
960 keys %{ $form->{item_list}[0] };
962 $form->{"discount_$i"} = $form->{discount} * 100;
964 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
965 ($dec) = ($s =~ /\.(\d+)/);
967 $decimalplaces = ($dec > 2) ? $dec : 2;
970 $form->{"sellprice_$i"} = $sellprice;
973 # if there is an exchange rate adjust sellprice
974 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
975 $form->{"sellprice_$i"} /= $exchangerate;
978 $form->{"listprice_$i"} /= $exchangerate;
981 $form->{"sellprice_$i"} * $form->{"qty_$i"} *
982 (1 - $form->{"discount_$i"} / 100);
983 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
984 map { $form->{"${_}_base"} += $amount }
985 (split / /, $form->{"taxaccounts_$i"});
986 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) }
987 split / /, $form->{"taxaccounts_$i"}
988 if !$form->{taxincluded};
990 $form->{creditremaining} -= $amount;
994 $form->format_amount(\%myconfig, $form->{"${_}_$i"},
996 } qw(sellprice listprice);
999 $form->format_amount(\%myconfig, $form->{"qty_$i"});
1002 if ($form->{"inventory_accno_$i"} ne "") {
1003 $form->{"lizenzen_$i"} = qq|<option></option>|;
1004 foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
1005 $form->{"lizenzen_$i"} .=
1006 qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
1008 $form->{"lizenzen_$i"} .=
1009 qq|<option value=-1>Neue Lizenz</option>|;
1013 # get pricegroups for parts
1014 IS->get_pricegroups_for_parts(\%myconfig, \%$form);
1016 # build up html code for prices_$i
1017 &set_pricegroup($i);
1024 # ok, so this is a new part
1025 # ask if it is a part or service item
1027 if ( $form->{"partsgroup_$i"}
1028 && ($form->{"partsnumber_$i"} eq "")
1029 && ($form->{"description_$i"} eq "")) {
1030 $form->{rowcount}--;
1031 $form->{"discount_$i"} = "";
1035 $form->{"id_$i"} = 0;
1036 $form->{"unit_$i"} = $locale->text('ea');
1043 $lxdebug->leave_sub();
1047 $lxdebug->enter_sub();
1048 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1049 $form->isblank("customer", $locale->text('Customer missing!'));
1051 # if oldcustomer ne customer redo form
1052 if (&check_name(customer)) {
1056 if ($form->{second_run}) {
1057 $form->{print_and_post} = 0;
1062 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1063 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1065 $form->error($locale->text('Cannot post invoice for a closed period!'))
1066 if ($invdate <= $closedto);
1068 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1069 if ($form->{currency} ne $form->{defaultcurrency});
1071 for $i (1 .. $form->{paidaccounts}) {
1072 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1073 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1075 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1077 $form->error($locale->text('Cannot post payment for a closed period!'))
1078 if ($datepaid <= $closedto);
1080 if ($form->{currency} ne $form->{defaultcurrency}) {
1081 $form->{"exchangerate_$i"} = $form->{exchangerate}
1082 if ($invdate == $datepaid);
1083 $form->isblank("exchangerate_$i",
1084 $locale->text('Exchangerate for payment missing!'));
1089 ($form->{AR}) = split /--/, $form->{AR};
1090 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
1092 $form->{label} = $locale->text('Invoice');
1094 $form->{id} = 0 if $form->{postasnew};
1096 # get new invnumber in sequence if no invnumber is given or if posasnew was requested
1097 if (!$form->{invnumber} || $form->{postasnew}) {
1098 $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber");
1101 if (!(IS->post_invoice(\%myconfig, \%$form))) {
1102 $form->error($locale->text('Cannot post invoice!'));
1106 $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
1107 if (IS->post_invoice(\%myconfig, \%$form));
1108 $form->error($locale->text('Cannot post invoice!'));
1111 $lxdebug->leave_sub();
1114 sub print_and_post {
1115 $lxdebug->enter_sub();
1117 $old_form = new Form;
1119 $form->{print_and_post} = 1;
1123 $lxdebug->leave_sub();
1128 $lxdebug->enter_sub();
1130 $form->{preview} = 1;
1131 $old_form = new Form;
1132 for (keys %$form) { $old_form->{$_} = $form->{$_} }
1133 $old_form->{rowcount}++;
1135 &print_form($old_form);
1136 $lxdebug->leave_sub();
1141 $lxdebug->enter_sub();
1142 if ($form->{second_run}) {
1143 $form->{print_and_post} = 0;
1150 <form method=post action=$form->{script}>
1153 # delete action variable
1154 map { delete $form->{$_} } qw(action header);
1156 foreach $key (keys %$form) {
1157 $form->{$key} =~ s/\"/"/g;
1158 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1162 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1165 . $locale->text('Are you sure you want to delete Invoice Number')
1166 . qq| $form->{invnumber}
1170 <input name=action class=submit type=submit value="|
1171 . $locale->text('Yes') . qq|">
1175 $lxdebug->leave_sub();
1179 $lxdebug->enter_sub();
1181 $form->redirect($locale->text('Invoice deleted!'))
1182 if (IS->delete_invoice(\%myconfig, \%$form, $spool));
1183 $form->error($locale->text('Cannot delete invoice!'));
1185 $lxdebug->leave_sub();