1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
24 # Inventory invoicing module
26 #======================================================================
32 require "$form->{path}/arap.pl";
33 require "$form->{path}/io.pl";
43 $form->{title} = $locale->text('Add Sales Invoice');
45 $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}" unless $form->{callback};
56 $form->{title} = $locale->text('Edit Sales Invoice');
67 $form->{vc} = 'customer';
70 $form->create_links("AR", \%myconfig, "customer");
73 @curr = split /:/, $form->{currencies};
75 $form->{defaultcurrency} = $curr[0];
77 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
79 if ($form->{all_customer}) {
80 unless ($form->{customer_id}) {
81 $form->{customer_id} = $form->{all_customer}->[0]->{id};
85 IS->get_customer(\%myconfig, \%$form);
86 delete $form->{notes};
87 IS->retrieve_invoice(\%myconfig, \%$form);
89 $form->{oldlanguage_code} = $form->{language_code};
91 $form->get_partsgroup(\%myconfig, { language_code => $form->{language_code} });
92 if (@{ $form->{all_partsgroup} }) {
93 $form->{selectpartsgroup} = "<option>\n";
94 foreach $ref (@ { $form->{all_partsgroup} }) {
95 if ($ref->{translation}) {
96 $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{translation}\n|;
98 $form->{selectpartsgroup} .= qq|<option value="$ref->{partsgroup}--$ref->{id}">$ref->{partsgroup}\n|;
103 if (@{ $form->{all_projects} }) {
104 $form->{selectprojectnumber} = "<option>\n";
105 map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} };
108 $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
109 $form->{oldtransdate} = $form->{transdate};
111 if ($form->{all_customer}) {
112 $form->{customer} = "$form->{customer}--$form->{customer_id}";
113 map { $form->{selectcustomer} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{all_customer} });
117 if ($form->{all_departments}) {
118 $form->{selectdepartment} = "<option>\n";
119 $form->{department} = "$form->{department}--$form->{department_id}";
121 map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} });
124 $form->{employee} = "$form->{employee}--$form->{employee_id}";
126 if ($form->{all_employees}) {
127 $form->{selectemployee} = "";
128 map { $form->{selectemployee} .= qq|<option value="$_->{name}--$_->{id}">$_->{name}\n| } (@{ $form->{all_employees} });
131 if (@{ $form->{all_languages} }) {
132 $form->{selectlanguage} = "<option>\n";
133 map { $form->{selectlanguage} .= qq|<option value="$_->{code}">$_->{description}\n| } @{ $form->{all_languages} };
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->{revtrans}) ? '1' : ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
169 $form->{readonly} = 1 if $myconfig{acs} =~ /AR--Sales Invoice/;
174 sub prepare_invoice {
176 $form->{type} = "invoice";
177 $form->{formname} = "invoice";
178 $form->{format} = "postscript" if $myconfig{printer};
179 $form->{media} = $myconfig{printer};
181 $form->{oldcurrency} = $form->{currency};
185 map { $form->{$_} = $form->quote($form->{$_}) } qw(invnumber ordnumber quonumber shippingpoint shipvia notes intnotes);
187 foreach $ref (@{ $form->{invoice_details} } ) {
189 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref };
191 $form->{"projectnumber_$i"} = qq|$ref->{projectnumber}--$ref->{project_id}|;
192 $form->{"partsgroup_$i"} = qq|$ref->{partsgroup}--$ref->{partsgroup_id}|;
194 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
196 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
198 $decimalplaces = ($dec > 2) ? $dec : 2;
200 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
201 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
202 $form->{"oldqty_$i"} = $form->{"qty_$i"};
204 map { $form->{"${_}_$i"} = $form->quote($form->{"${_}_$i"}) } qw(partnumber sku description unit);
205 $form->{rowcount} = $i;
215 # set option selected
216 foreach $item (qw(AR currency)) {
217 $form->{"select$item"} =~ s/ selected//;
218 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
221 foreach $item (qw(customer department employee)) {
222 $form->{"select$item"} = $form->unescape($form->{"select$item"});
223 $form->{"select$item"} =~ s/ selected//;
224 $form->{"select$item"} =~ s/(<option value="\Q$form->{$item}\E")/$1 selected/;
227 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
231 if ($form->{currency} ne $form->{defaultcurrency}) {
232 if ($form->{forex}) {
233 $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
235 $exchangerate .= qq|<th align=right>|.$locale->text('Exchange Rate').qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
239 <input type=hidden name=forex value=$form->{forex}>
242 if ($form->{selectcustomer}) {
243 $customer = qq|<select name=customer>$form->{selectcustomer}</select>
244 <input type=hidden name="selectcustomer" value="|.
245 $form->escape($form->{selectcustomer},1).qq|">|;
247 $customer = qq|<input name=customer value="$form->{customer}" size=35>|;
252 <th align="right" nowrap>|.$locale->text('Department').qq|</th>
253 <td colspan=3><select name=department>$form->{selectdepartment}</select>
254 <input type=hidden name=selectdepartment value="|.
255 $form->escape($form->{selectdepartment},1).qq|">
258 | if $form->{selectdepartment};
261 $n = ($form->{creditremaining} < 0) ? "0" : "1";
264 if ($form->{business}) {
267 <th align=right>|.$locale->text('Business').qq|</th>
268 <td>$form->{business}</td>
269 <th align=right>|.$locale->text('Trade Discount').qq|</th>
270 <td>|.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| %</td>
281 <form method=post action="$form->{script}#end">
283 <input type=hidden name=id value=$form->{id}>
285 <input type=hidden name=type value=$form->{type}>
286 <input type=hidden name=media value=$form->{media}>
287 <input type=hidden name=format value=$form->{format}>
289 <input type=hidden name=queued value="$form->{queued}">
290 <input type=hidden name=printed value="$form->{printed}">
291 <input type=hidden name=emailed value="$form->{emailed}">
293 <input type=hidden name=title value="$form->{title}">
294 <input type=hidden name=vc value=$form->{vc}>
296 <input type=hidden name=terms value=$form->{terms}>
298 <input type=hidden name=discount value=$form->{discount}>
299 <input type=hidden name=creditlimit value=$form->{creditlimit}>
300 <input type=hidden name=creditremaining value=$form->{creditremaining}>
302 <input type=hidden name=tradediscount value=$form->{tradediscount}>
303 <input type=hidden name=business value="$form->{business}">
305 <input type=hidden name=closedto value=$form->{closedto}>
306 <input type=hidden name=locked value=$form->{locked}>
308 <input type=hidden name=shipped value=$form->{shipped}>
310 <input type=hidden name=oldtransdate value=$form->{oldtransdate}>
315 <th class=listtop>$form->{title}</th>
325 <th align=right nowrap>|.$locale->text('Customer').qq|</th>
326 <td colspan=3>$customer</td>
327 <input type=hidden name=customer_id value=$form->{customer_id}>
328 <input type=hidden name=oldcustomer value="$form->{oldcustomer}">
335 <th nowrap>|.$locale->text('Credit Limit').qq|</th>
336 <td>|.$form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0").qq|</td>
338 <th nowrap>|.$locale->text('Remaining').qq|</th>
339 <td class="plus$n" nowrap>|.$form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0").qq|</td>
346 <th align=right nowrap>|.$locale->text('Record in').qq|</th>
347 <td colspan=3><select name=AR>$form->{selectAR}</select></td>
348 <input type=hidden name=selectAR value="$form->{selectAR}">
352 <th align=right nowrap>|.$locale->text('Currency').qq|</th>
353 <td><select name=currency>$form->{selectcurrency}</select></td>
354 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
355 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
356 <input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
357 <input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
361 <th align=right nowrap>|.$locale->text('Shipping Point').qq|</th>
362 <td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
365 <th align=right nowrap>|.$locale->text('Ship via').qq|</th>
366 <td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
373 <th align=right nowrap>|.$locale->text('Salesperson').qq|</th>
374 <td><select name=employee>$form->{selectemployee}</select></td>
375 <input type=hidden name=selectemployee value="|.
376 $form->escape($form->{selectemployee},1).qq|">
379 <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
380 <td><input name=invnumber size=20 value="$form->{invnumber}"></td>
383 <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
384 <td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>
385 <input type=hidden name=quonumber value="$form->{quonumber}">
388 <th align=right>|.$locale->text('Invoice Date').qq|</th>
389 <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
392 <th align=right>|.$locale->text('Due Date').qq|</th>
393 <td><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
405 <!-- shipto are in hidden variables -->
407 <input type=hidden name=shiptoname value="$form->{shiptoname}">
408 <input type=hidden name=shiptoaddress1 value="$form->{shiptoaddress1}">
409 <input type=hidden name=shiptoaddress2 value="$form->{shiptoaddress2}">
410 <input type=hidden name=shiptocity value="$form->{shiptocity}">
411 <input type=hidden name=shiptostate value="$form->{shiptostate}">
412 <input type=hidden name=shiptozipcode value="$form->{shiptozipcode}">
413 <input type=hidden name=shiptocountry value="$form->{shiptocountry}">
414 <input type=hidden name=shiptocontact value="$form->{shiptocontact}">
415 <input type=hidden name=shiptophone value="$form->{shiptophone}">
416 <input type=hidden name=shiptofax value="$form->{shiptofax}">
417 <input type=hidden name=shiptoemail value="$form->{shiptoemail}">
419 <!-- email variables -->
420 <input type=hidden name=message value="$form->{message}">
421 <input type=hidden name=email value="$form->{email}">
422 <input type=hidden name=subject value="$form->{subject}">
423 <input type=hidden name=cc value="$form->{cc}">
424 <input type=hidden name=bcc value="$form->{bcc}">
426 <input type=hidden name=taxaccounts value="$form->{taxaccounts}">
429 foreach $item (split / /, $form->{taxaccounts}) {
431 <input type=hidden name="${item}_rate" value="$form->{"${item}_rate"}">
432 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
433 <input type=hidden name="${item}_taxnumber" value="$form->{"${item}_taxnumber"}">
443 $form->{invtotal} = $form->{invsubtotal};
445 if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
448 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
451 $rows = ($rows > $introws) ? $rows : $introws;
452 $notes = qq|<textarea name=notes rows=$rows cols=26 wrap=soft>$form->{notes}</textarea>|;
453 $intnotes = qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
455 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
458 if ($form->{taxaccounts}) {
463 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td><th align=left>|.$locale->text('Tax Included').qq|</th>
468 if (!$form->{taxincluded}) {
470 foreach $item (split / /, $form->{taxaccounts}) {
471 if ($form->{"${item}_base"}) {
472 $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
473 $form->{invtotal} += $form->{"${item}_total"};
474 $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
478 <th align=right>$form->{"${item}_description"}</th>
479 <td align=right>$form->{"${item}_total"}</td>
485 $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
489 <th align=right>|.$locale->text('Subtotal').qq|</th>
490 <td align=right>$form->{invsubtotal}</td>
496 $form->{oldinvtotal} = $form->{invtotal};
497 $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
507 <th align=left>|.$locale->text('Notes').qq|</th>
508 <th align=left>|.$locale->text('Internal Notes').qq|</th>
521 <th align=right>|.$locale->text('Total').qq|</th>
522 <td align=right>$form->{invtotal}</td>
534 <tr class=listheading>
535 <th colspan=6 class=listheading>|.$locale->text('Payments')
540 if ($form->{currency} eq $form->{defaultcurrency}) {
541 @column_index = qw(datepaid source memo paid AR_paid);
543 @column_index = qw(datepaid source memo paid exchangerate AR_paid);
546 $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
547 $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
548 $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
549 $column_data{AR_paid} = "<th>".$locale->text('Account')."</th>";
550 $column_data{source} = "<th>".$locale->text('Source')."</th>";
551 $column_data{memo} = "<th>".$locale->text('Memo')."</th>";
556 map { print "$column_data{$_}\n" } @column_index;
561 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
562 for $i (1 .. $form->{paidaccounts}) {
567 $form->{"selectAR_paid_$i"} = $form->{selectAR_paid};
568 $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/;
571 $totalpaid += $form->{"paid_$i"};
572 $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
573 $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
575 $exchangerate = qq| |;
576 if ($form->{currency} ne $form->{defaultcurrency}) {
577 if ($form->{"forex_$i"}) {
578 $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
580 $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
585 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
588 $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
589 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
590 $column_data{"AR_paid_$i"} = qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
591 $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
592 $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
593 $column_data{"memo_$i"} = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
595 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
601 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
602 <input type=hidden name=selectAR_paid value="$form->{selectAR_paid}">
603 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
604 <input type=hidden name=oldtotalpaid value=$totalpaid>
609 <td><hr size=3 noshade></td>
625 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
626 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
628 if (! $form->{readonly}) {
633 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
634 <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|">
635 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
636 <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">
639 if (! $form->{locked}) {
641 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
645 <input class=submit type=submit name=action value="|.$locale->text('Print and Post').qq|">|;
649 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
654 <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
655 <input class=submit type=submit name=action value="|.$locale->text('Sales Order').qq|">
660 if ($transdate > $closedto) {
662 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
663 <input class=submit type=submit name=action value="|.$locale->text('Ship to').qq|">
664 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
665 <input class=submit type=submit name=action value="|.$locale->text('E-mail').qq|">
666 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
670 <input class=submit type=submit name=action value="|.$locale->text('Print and Post').qq|">|;
676 if ($form->{menubar}) {
677 require "$form->{path}/menu.pl";
683 <input type=hidden name=rowcount value=$form->{rowcount}>
685 <input name=callback type=hidden value="$form->{callback}">
687 <input type=hidden name=path value=$form->{path}>
688 <input type=hidden name=login value=$form->{login}>
689 <input type=hidden name=sessionid value=$form->{sessionid}>
704 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate);
706 &check_name(customer);
708 if ($form->{transdate} ne $form->{oldtransdate}) {
709 $form->{duedate} = $form->current_date(\%myconfig, $form->{transdate}, $form->{terms} * 1);
710 $form->{oldtransdate} = $form->{transdate};
714 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'buy')));
717 for $i (1 .. $form->{paidaccounts}) {
718 if ($form->{"paid_$i"}) {
719 map { $form->{"${_}_$j"} = $form->{"${_}_$i"} } qw(datepaid source memo);
720 map { $form->{"${_}_$j"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
722 $form->{"exchangerate_$j"} = $exchangerate if ($form->{"forex_$j"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$j"}, 'buy')));
723 map { delete $form->{"${_}_$i"} } qw(datepaid source memo paid exchangerate forex) if $j != $i;
726 map { delete $form->{"${_}_$i"} } qw(datepaid source memo paid exchangerate forex);
728 $form->{paidaccounts} = $j;
731 $i = $form->{rowcount};
732 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
734 foreach $item (qw(partsgroup projectnumber)) {
735 $form->{"select$item"} = $form->unescape($form->{"select$item"}) if $form->{"select$item"};
738 # if last row empty, check the form otherwise retrieve new item
739 if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
741 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
746 IS->retrieve_item(\%myconfig, \%$form);
748 $rows = scalar @{ $form->{item_list} };
750 $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100);
753 $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1;
762 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
764 map { $form->{item_list}[$i]{$_} = $form->quote($form->{item_list}[$i]{$_}) } qw(partnumber description unit);
765 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
767 $form->{"discount_$i"} = $form->{discount} * 100;
769 $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
770 ($dec) = ($s =~ /\.(\d+)/);
772 $decimalplaces = ($dec > 2) ? $dec : 2;
775 $form->{"sellprice_$i"} = $sellprice;
777 # if there is an exchange rate adjust sellprice
778 $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
779 $form->{"sellprice_$i"} /= $exchangerate;
782 map { $form->{"${_}_$i"} /= $exchangerate } qw(listprice lastcost);
784 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
785 map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts});
786 map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"});
787 map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
789 $form->{creditremaining} -= $amount;
791 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice lastcost);
793 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
799 # ok, so this is a new part
800 # ask if it is a part or service item
802 if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
804 $form->{"discount_$i"} = "";
808 $form->{"id_$i"} = 0;
809 $form->{"unit_$i"} = $locale->text('ea');
822 $form->isblank("transdate", $locale->text('Invoice Date missing!'));
823 $form->isblank("customer", $locale->text('Customer missing!'));
825 # if oldcustomer ne customer redo form
826 if (&check_name(customer)) {
833 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
834 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
836 $form->error($locale->text('Cannot post invoice for a closed period!')) if ($transdate <= $closedto);
838 $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
840 for $i (1 .. $form->{paidaccounts}) {
841 if ($form->{"paid_$i"}) {
842 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
844 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
846 $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
848 if ($form->{currency} ne $form->{defaultcurrency}) {
849 $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
850 $form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));
856 ($form->{AR}) = split /--/, $form->{AR};
857 ($form->{AR_paid}) = split /--/, $form->{AR_paid};
859 $form->{label} = $locale->text('Invoice');
861 $form->{id} = 0 if $form->{postasnew};
863 $form->{invnumber} = $form->update_defaults(\%myconfig, "sinumber") unless $form->{invnumber};
865 $form->redirect($locale->text('Invoice posted!')) if (IS->post_invoice(\%myconfig, \%$form));
866 $form->error($locale->text('Cannot post invoice!'));
873 $form->error($locale->text('Select postscript or PDF!')) if $form->{format} !~ /(postscript|pdf)/;
874 $form->error($locale->text('Select Printer or Queue!')) if $form->{media} eq 'screen';
876 $old_form = new Form;
877 $form->{display_form} = "post";
878 map { $old_form->{$_} = $form->{$_} } keys %$form;
879 $old_form->{rowcount}++;
881 &print_form($old_form);
894 <form method=post action=$form->{script}>
897 # delete action variable
898 map { delete $form->{$_} } qw(action header);
903 <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
905 <h4>|.$locale->text('Are you sure you want to delete Invoice Number').qq| $form->{invnumber}
909 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
920 $form->redirect($locale->text('Invoice deleted!')) if (IS->delete_invoice(\%myconfig, \%$form, $spool));
921 $form->error($locale->text('Cannot delete invoice!'));
929 $form->error($locale->text('Invoice processed!'));