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 #======================================================================
26 #======================================================================
33 require "$form->{path}/arap.pl";
41 # setup customer/vendor selection for open invoices
42 CP->get_openvc(\%myconfig, \%$form);
44 if ($form->{"all_$form->{vc}"}) {
45 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} };
48 $form->{arap} = ($form->{vc} eq 'customer') ? "AR" : "AP";
50 CP->paymentaccounts(\%myconfig, \%$form);
52 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{PR} };
55 @curr = split /:/, $form->{currencies};
57 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} = $curr[0];
59 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
61 $form->{media} = "screen";
73 $vclabel = ucfirst $form->{vc};
74 $vclabel = $locale->text($vclabel);
76 if ($form->{vc} eq 'customer') {
77 $form->{title} = $locale->text('Receipt');
78 $rclabel = $locale->text('Reference');
79 $form->{type} = 'receipt';
81 $form->{title} = $locale->text('Payment');
82 $rclabel = $locale->text('Check');
83 $form->{type} = 'check';
86 # $locale->text('Customer')
87 # $locale->text('Vendor')
89 if ($form->{$form->{vc}} eq "") {
90 map { $form->{"addr$_"} = "" } (1 .. 4);
93 if ($form->{currency} ne $form->{defaultcurrency}) {
94 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
98 <th align=right nowrap>|.$locale->text('Exchangerate').qq|</th>
99 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
105 <th align=right nowrap>|.$locale->text('Exchangerate').qq|</th>
106 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
112 foreach $item ($form->{vc}, account, currency) {
113 $form->{"select$item"} =~ s/ selected//;
114 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
117 $vc = ($form->{"select$form->{vc}"}) ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>| : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
124 <form method=post action=$form->{script}>
126 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
127 <input type=hidden name=closedto value=$form->{closedto}>
128 <input type=hidden name=vc value=$form->{vc}>
129 <input type=hidden name=type value=$form->{type}>
131 <table border=0 width=100%>
133 <th class=listtop>$form->{title}</th>
143 <th align=right>$vclabel</th>
145 <input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">
146 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
147 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
150 <th align=right nowrap>|.$locale->text('Address').qq|</th>
154 <td>$form->{addr1}</td>
157 <td>$form->{addr2}</td>
160 <td>$form->{addr3}</td>
163 <td>$form->{addr4}</td>
167 <input type=hidden name=addr1 value="$form->{addr1}">
168 <input type=hidden name=addr2 value="$form->{addr2}">
169 <input type=hidden name=addr3 value="$form->{addr3}">
170 <input type=hidden name=addr4 value="$form->{addr4}">
177 <th align=right nowrap>|.$locale->text('Account').qq|</th>
178 <td colspan=3><select name=account>$form->{selectaccount}</select>
179 <input type=hidden name=selectaccount value="$form->{selectaccount}">
183 <th align=right nowrap>|.$locale->text('Date').qq|</th>
184 <td><input name=datepaid value="$form->{datepaid}" title="$myconfig{dateformat}" size=11></td>
187 <th align=right nowrap>|.$locale->text('Currency').qq|</th>
188 <td><select name=currency>$form->{selectcurrency}</select></td>
189 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
190 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
194 <th align=right nowrap>$rclabel</th>
195 <td colspan=3><input name=source value="$form->{source}" size=10></td>
198 <th align=right nowrap>|.$locale->text('Amount').qq|</th>
199 <td colspan=3><input name=amount size=10 value=|.$form->format_amount(\%myconfig, $form->{amount}, 2).qq|></td>
202 <th align=right nowrap>|.$locale->text('From').qq|</th>
203 <td><input name=transdatefrom size=11 title="$myconfig{dateformat}" value=$form->{transdatefrom}></td>
204 <th align=right nowrap>|.$locale->text('to').qq|</th>
205 <td><input name=transdateto size=11 title="$myconfig{dateformat}" value=$form->{transdateto}></td>
206 <input type=hidden name=oldtransdatefrom value=$form->{oldtransdatefrom}>
207 <input type=hidden name=oldtransdateto value=$form->{oldtransdateto}>
222 @column_index = qw(invnumber transdate amount due paid selectpaid);
224 $colspan = $#column_index + 1;
227 <input type=hidden name=column_index value="id @column_index">
232 <th class=listheading colspan=$colspan>|.$locale->text('Invoices').qq|</th>
236 $column_data{invnumber} = qq|<th nowrap>|.$locale->text('Invoice')."</th>";
237 $column_data{transdate} = qq|<th nowrap>|.$locale->text('Date')."</th>";
238 $column_data{amount} = qq|<th nowrap>|.$locale->text('Amount')."</th>";
239 $column_data{due} = qq|<th nowrap>|.$locale->text('Due')."</th>";
240 $column_data{paid} = qq|<th nowrap>|.$locale->text('Applied')."</th>";
241 $column_data{selectpaid} = qq|<th nowrap>|.$locale->text('Paid in full')."</th>";
246 map { print "$column_data{$_}\n" } @column_index;
251 for $i (1 .. $form->{rowcount}) {
253 $form->{"selectpaid_$i"} = "checked" if $form->{"selectpaid_$i"};
254 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(amount due paid);
256 $totalamount += $form->{"amount_$i"};
257 $totaldue += $form->{"due_$i"};
258 $totalpaid += $form->{"paid_$i"};
260 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid);
262 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
263 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
264 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
265 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
266 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
267 $column_data{amount} = qq|<td align=right width=15%>$form->{"amount_$i"}</td>
268 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
269 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
270 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
272 $column_data{paid} = qq|<td align=right width=15%>|;
273 if ($form->{"selectpaid_$i"}) {
274 $column_data{paid} .= qq|<input type=hidden name="paid_$i" value=$form->{"paid_$i"}>$form->{"paid_$i"}</td>|;
276 $column_data{paid} .= qq|<input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
278 $column_data{selectpaid} = qq|<td align=center width=10%><input name="selectpaid_$i" type=checkbox class=checkbox $form->{"selectpaid_$i"}></td>|;
284 map { print "$column_data{$_}\n" } @column_index;
290 map { $column_data{$_} = "<td> </td>" } @column_index;
292 $column_data{amount} = qq|<th align=right>|.$form->format_amount(\%myconfig, $totalamount, 2, " ").qq|</th>|;
293 $column_data{due} = qq|<th align=right>|.$form->format_amount(\%myconfig, $totaldue, 2, " ").qq|</th>|;
294 $column_data{paid} = qq|<th align=right>|.$form->format_amount(\%myconfig, $totalpaid, 2, " ").qq|</th>|;
299 map { print "$column_data{$_}\n" } @column_index;
312 $form->{OP}{$form->{media}} = "checked";
316 <td><hr size=3 noshade></td>
319 <input type=hidden name=rowcount value=$form->{rowcount}>
321 <input type=hidden name=path value=$form->{path}>
322 <input type=hidden name=login value=$form->{login}>
323 <input type=hidden name=password value=$form->{password}>
326 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
327 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
331 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">
332 <input class=radio type=radio name=media value=screen $form->{OP}{screen}> |.$locale->text('Screen');
334 if ($myconfig{printer}) {
336 <input class=radio type=radio name=media value=printer $form->{OP}{printer}> |.$locale->text('Printer');
352 my ($new_name_selected) = @_;
354 # get customer and invoices
355 $updated = &check_name($form->{vc});
357 $updated = 1 if (($form->{oldtransdatefrom} ne $form->{transdatefrom}) || ($form->{oldtransdateto} ne $form->{transdateto}));
358 $form->{oldtransdatefrom} = $form->{transdatefrom};
359 $form->{oldtransdateto} = $form->{transdateto};
361 if ($new_name_selected || $updated) {
362 CP->get_openinvoices(\%myconfig, \%$form);
366 if ($form->{currency} ne $form->{oldcurrency}) {
367 $form->{oldcurrency} = $form->{currency};
369 CP->get_openinvoices(\%myconfig, \%$form);
375 $buysell = ($form->{vc} eq 'customer') ? "buy" : "sell";
377 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, $buysell)));
379 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
382 $form->{rowcount} = 0;
385 foreach $ref (@{ $form->{PR} }) {
387 $form->{"id_$i"} = $ref->{id};
388 $form->{"invnumber_$i"} = $ref->{invnumber};
389 $form->{"transdate_$i"} = $ref->{transdate};
390 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
391 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
392 $form->{"due_$i"} = $form->round_amount(($ref->{amount} - $ref->{paid}) / $ref->{exchangerate}, 2);
393 $amount = $form->round_amount($amount - $form->{"due_$i"}, 2);
394 $form->{"selectpaid_$i"} = 1 if $amount > 0;
396 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid);
399 $form->{rowcount} = $i;
403 $amount = $form->{amount};
404 for $i (1 .. $form->{rowcount}) {
406 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(amount due paid);
408 if ($form->{"selectpaid_$i"}) {
409 $amount -= $form->{"due_$i"};
412 $form->{"selectpaid_$i"} = 0;
414 $form->{"paid_$i"} = $form->{"due_$i"};
418 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid);
433 $form->redirect($locale->text('Payment posted!')) if (CP->process_payment(\%myconfig, \%$form));
434 $form->error($locale->text('Cannot post payment!'));
443 ($whole, $form->{decimal}) = split /\./, $form->{amount};
445 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
446 $m = "*" x (24 - length $form->{amount});
447 $form->{amount} = $locale->text($form->{currency})."$m$form->{amount}";
449 $form->{decimal} .= "00";
450 $form->{decimal} = substr($form->{decimal}, 0, 2);
452 $check = new CP $myconfig{countrycode};
454 $form->{text_amount} = $check->num2text($whole);
456 &{ "$form->{vc}_details" };
458 $form->{format} = ($form->{media} eq 'screen') ? "pdf" : "postscript";
459 $form->{templates} = "$myconfig{templates}";
460 $form->{IN} = "$form->{type}.tex";
461 $form->{OUT} = "| $myconfig{printer}" if ($form->{media} eq 'printer');
463 $form->{company} = $myconfig{company};
464 $form->{address} = $myconfig{address};
466 @a = qw(name invnumber company address text_amount addr1 addr2 addr3 addr4);
467 $form->format_string(@a);
469 $form->parse_template(\%myconfig, $userspath);
471 $form->{callback} = "";
473 $label = uc $form->{type};
475 # $locale->text('Check printed!')
476 # $locale->text('Check printing failed!')
477 # $locale->text('Receipt printed!')
478 # $locale->text('Receipt printing failed!')
480 $form->redirect($locale->text("$label printed!"));
481 $form->error($locale->text("$label printing failed!"));
486 sub customer_details { IS->customer_details(\%myconfig, \%$form) };
487 sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };
493 $form->{callback} = "$form->{script}?action=payment&vc=$form->{vc}&path=$form->{path}&login=$form->{login}&password=$form->{password}";
495 $form->redirect unless $form->{rowcount};
497 if ($form->{currency} ne $form->{oldcurrency}) {
502 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
503 $form->error($locale->text('Amount missing!')) unless $form->{amount};
505 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
506 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
508 $form->error($locale->text('Cannot process payment for a closed period!')) if ($datepaid <= $closedto);
510 $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
511 for $i (1 .. $form->{rowcount}) {
512 $totalpaid += $form->parse_amount(\%myconfig, $form->{"paid_$i"});
513 if ($form->{"paid_$i"}) {
514 push(@{ $form->{paid} }, $form->{"paid_$i"});
515 push(@{ $form->{due} }, $form->{"due_$i"});
516 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
517 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
521 $totalpaid = $form->round_amount($totalpaid, 2);
523 $form->error($locale->text('Nothing applied!')) unless $totalpaid;
524 $form->error($locale->text('Amount does not equal applied!')) if ($form->{amount} != $totalpaid);