1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
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 #======================================================================
32 #======================================================================
40 require "$form->{path}/arap.pl";
47 $lxdebug->enter_sub();
50 $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
51 $form->{arap} = lc $form->{ARAP};
53 # setup customer/vendor selection for open invoices
54 if ($form->{all_vc}) {
55 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
57 CP->get_openvc(\%myconfig, \%$form);
60 $form->{"select$form->{vc}"} = "";
62 if ($form->{"all_$form->{vc}"}) {
63 $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
64 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} };
68 if (@{ $form->{all_departments} }) {
69 $form->{selectdepartment} = "<option>\n";
70 $form->{department} = "$form->{department}--$form->{department_id}";
72 map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} });
75 CP->paymentaccounts(\%myconfig, \%$form);
77 $form->{selectaccount} = "";
78 $form->{"select$form->{ARAP}"} = "";
80 map { $form->{selectaccount} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{PR}{"$form->{ARAP}_paid"} };
81 map { $form->{"select$form->{ARAP}"} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{PR}{$form->{ARAP}} };
84 @curr = split /:/, $form->{currencies};
86 $form->{defaultcurrency} = $form->{currency} = $form->{oldcurrency} = $curr[0];
88 $form->{selectcurrency} = "";
89 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
91 $form->{media} = "screen";
96 $lxdebug->leave_sub();
102 $lxdebug->enter_sub();
105 $vclabel = ucfirst $form->{vc};
106 $vclabel = $locale->text($vclabel);
108 if ($form->{type} eq 'receipt') {
109 $form->{title} = $locale->text('Receipt');
110 $form->{origtitle} = "Receipt";
112 if ($form->{type} eq 'check') {
113 $form->{title} = $locale->text('Payment');
114 $form->{origtitle} = "Payment";
117 # $locale->text('Customer')
118 # $locale->text('Vendor')
120 if ($form->{$form->{vc}} eq "") {
121 map { $form->{"addr$_"} = "" } (1 .. 4);
124 if ($form->{currency} ne $form->{defaultcurrency}) {
125 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
126 if ($form->{forex}) {
129 <th align=right nowrap>|.$locale->text('Exchangerate').qq|</th>
130 <td colspan=3><input type=hidden name=exchangerate size=10 value=$form->{exchangerate}>$form->{exchangerate}</td>
136 <th align=right nowrap>|.$locale->text('Exchangerate').qq|</th>
137 <td colspan=3><input name=exchangerate size=10 value=$form->{exchangerate}></td>
143 foreach $item ($form->{vc}, account, currency, $form->{ARAP}, department) {
144 $form->{"select$item"} =~ s/ selected//;
145 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
148 $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}}">|;
150 if ($form->{all_vc}) {
152 $form->{openinvoices} = "";
155 $form->{openinvoices} = 1;
158 # $locale->text('AR')
159 # $locale->text('AP')
163 <th align="right" nowrap>|.$locale->text('Department').qq|</th>
164 <td><select name=department>$form->{selectdepartment}</select>
165 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
169 | if $form->{selectdepartment};
171 $form->{jsscript} = $jscalendar;
173 if ($form->{jsscript})
175 # with JavaScript Calendar
177 <td><input name=datepaid id=datepaid size=11 title="$myconfig{dateformat}" value="$form->{datepaid}">
178 <input type=button name=datepaid id="trigger1" value=|.$locale->text('button').qq|></td>
181 $jsscript = Form->write_trigger(\%myconfig,"1","datepaid","BL","trigger1","","","");
185 # without JavaScript Calendar
187 <td><input name=transdatefrom id=transdatefrom size=11 title="$myconfig{dateformat}"></td>|;
192 $arap = lc $form->{ARAP};
197 <form method=post action=$form->{script}>
199 <input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
200 <input type=hidden name=closedto value=$form->{closedto}>
201 <input type=hidden name=vc value=$form->{vc}>
202 <input type=hidden name=type value=$form->{type}>
203 <input type=hidden name=formname value=$form->{type}>
204 <input type=hidden name=queued value="$form->{queued}">
205 <input type=hidden name=arap value=$arap>
206 <input type=hidden name=ARAP value=$form->{ARAP}>
207 <input type=hidden name=openinvoices value=$form->{openinvoices}>
208 <input type=hidden name=title value="$form->{title}">
209 <input type=hidden name=origtitle value="$form->{origtitle}">
213 <th class=listtop>$form->{title}</th>
224 <input name=all_vc type=checkbox style=checkbox value=Y $allvc>
225 <input type=hidden name="oldall_vc" value="$form->{all_vc}"></td>
226 <th align=left>|.$locale->text('All').qq|</th>
229 <th align=right>$vclabel</th>
231 <input type=hidden name="select$form->{vc}" value="$form->{"select$form->{vc}"}">
232 <input type=hidden name="$form->{vc}_id" value=$form->{"$form->{vc}_id"}>
233 <input type=hidden name="old$form->{vc}" value="$form->{"old$form->{vc}"}">
236 <th align=right nowrap>|.$locale->text('Address').qq|</th>
240 <td>$form->{street}</td>
243 <td>$form->{zipcode}</td>
246 <td>$form->{city}</td>
249 <td>$form->{country}</td>
253 <input type=hidden name=street value="$form->{street}">
254 <input type=hidden name=zipcode value="$form->{zipcode}">
255 <input type=hidden name=city value="$form->{city}">
256 <input type=hidden name=country value="$form->{country}">
259 <th align=right>|.$locale->text('Memo').qq|</th>
260 <td colspan=2><input name="memo" size=30 value="$form->{memo}"></td>
268 <th align=right nowrap>|.$locale->text($form->{ARAP}).qq|</th>
269 <td colspan=3><select name=$form->{ARAP}>$form->{"select$form->{ARAP}"}</select>
271 <input type=hidden name="select$form->{ARAP}" value="$form->{"select$form->{ARAP}"}">
274 <th align=right nowrap>|.$locale->text('Account').qq|</th>
275 <td colspan=3><select name=account>$form->{selectaccount}</select>
276 <input type=hidden name=selectaccount value="$form->{selectaccount}">
280 <th align=right nowrap>|.$locale->text('Date').qq|</th>
284 <th align=right nowrap>|.$locale->text('Currency').qq|</th>
285 <td><select name=currency>$form->{selectcurrency}</select></td>
286 <input type=hidden name=selectcurrency value="$form->{selectcurrency}">
287 <input type=hidden name=oldcurrency value=$form->{oldcurrency}>
291 <th align=right nowrap>|.$locale->text('Source').qq|</th>
292 <td colspan=3><input name=source value="$form->{source}" size=10></td>
295 <th align=right nowrap>|.$locale->text('Amount').qq|</th>
296 <td colspan=3><input name=amount size=10 value=|.$form->format_amount(\%myconfig, $form->{amount}, 2).qq|></td>
308 $lxdebug->leave_sub();
313 $lxdebug->enter_sub();
316 @column_index = qw(invnumber transdate amount due checked paid);
318 $colspan = $#column_index + 1;
320 $invoice = $locale->text('Invoices');
323 <input type=hidden name=column_index value="id @column_index">
328 <th class=listheading colspan=$colspan>$invoice</th>
332 $column_data{invnumber} = qq|<th nowrap class=listheading>|.$locale->text('Invoice')."</th>";
333 $column_data{transdate} = qq|<th nowrap class=listheading>|.$locale->text('Date')."</th>";
334 $column_data{amount} = qq|<th nowrap class=listheading>|.$locale->text('Amount')."</th>";
335 $column_data{due} = qq|<th nowrap class=listheading>|.$locale->text('Due')."</th>";
336 $column_data{paid} = qq|<th nowrap class=listheading>|.$locale->text('Amount')."</th>";
337 $column_data{checked} = qq|<th nowrap class=listheading>|.$locale->text('Select')."</th>";
342 map { print "$column_data{$_}\n" } @column_index;
347 for $i (1 .. $form->{rowcount}) {
349 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(amount due paid);
351 $totalamount += $form->{"amount_$i"};
352 $totaldue += $form->{"due_$i"};
353 $totalpaid += $form->{"paid_$i"};
355 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid);
357 $column_data{invnumber} = qq|<td>$form->{"invnumber_$i"}</td>
358 <input type=hidden name="invnumber_$i" value="$form->{"invnumber_$i"}">
359 <input type=hidden name="id_$i" value=$form->{"id_$i"}>|;
360 $column_data{transdate} = qq|<td width=15%>$form->{"transdate_$i"}</td>
361 <input type=hidden name="transdate_$i" value=$form->{"transdate_$i"}>|;
362 $column_data{amount} = qq|<td align=right width=15%>$form->{"amount_$i"}</td>
363 <input type=hidden name="amount_$i" value=$form->{"amount_$i"}>|;
364 $column_data{due} = qq|<td align=right width=15%>$form->{"due_$i"}</td>
365 <input type=hidden name="due_$i" value=$form->{"due_$i"}>|;
367 $column_data{paid} = qq|<td align=right width=15%><input name="paid_$i" size=10 value=$form->{"paid_$i"}></td>|;
369 $form->{"checked_$i"} = ($form->{"checked_$i"}) ? "checked" : "";
370 $column_data{checked} = qq|<td align=center width=10%><input name="checked_$i" type=checkbox style=checkbox $form->{"checked_$i"}></td>|;
376 map { print "$column_data{$_}\n" } @column_index;
382 map { $column_data{$_} = "<td> </td>" } @column_index;
384 $column_data{amount} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalamount, 2, " ").qq|</th>|;
385 $column_data{due} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totaldue, 2, " ").qq|</th>|;
386 $column_data{paid} = qq|<th class=listtotal align=right>|.$form->format_amount(\%myconfig, $totalpaid, 2, " ").qq|</th>|;
391 map { print "$column_data{$_}\n" } @column_index;
399 $lxdebug->leave_sub();
404 $lxdebug->enter_sub();
407 $form->{DF}{$form->{format}} = "selected";
408 $form->{OP}{$form->{media}} = "selected";
411 <option value=screen $form->{OP}{screen}>|.$locale->text('Screen');
413 if ($myconfig{printer} && $latex) {
415 <option value=printer $form->{OP}{printer}>|.$locale->text('Printer');
419 <option value=queue $form->{OP}{queue}>|.$locale->text('Queue');
421 <option value=postscript $form->{DF}{postscript}>|.$locale->text('Postscript').qq|
422 <option value=pdf $form->{DF}{pdf}>|.$locale->text('PDF');
428 <td><hr size=3 noshade></td>
431 <input type=hidden name=rowcount value=$form->{rowcount}>
433 <input type=hidden name=path value=$form->{path}>
434 <input type=hidden name=login value=$form->{login}>
435 <input type=hidden name=password value=$form->{password}>
438 <input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
439 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
443 <input class=submit type=submit name=action value="|.$locale->text('Print').qq|">|;
447 <select name=format>$format</select>
448 <select name=media>$media</select>
451 if ($form->{menubar}) {
452 require "$form->{path}/menu.pl";
463 $lxdebug->leave_sub();
468 $lxdebug->enter_sub();
470 my ($new_name_selected) = @_;
473 if ($form->{vc} eq 'customer') {
479 # if we switched to all_vc
480 if ($form->{all_vc} ne $form->{oldall_vc}) {
482 $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
484 $form->{"select$form->{vc}"} = "";
486 if ($form->{all_vc}) {
487 $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
489 if ($form->{"all_$form->{vc}"}) {
490 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} };
493 CP->get_openvc(\%myconfig, \%$form);
495 if ($form->{"all_$form->{vc}"}) {
496 $newvc = qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
497 map { $form->{"select$form->{vc}"} .= "<option>$_->{name}--$_->{id}\n" } @{ $form->{"all_$form->{vc}"} };
500 # if the name is not the same
501 if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
502 $form->{$form->{vc}} = $newvc;
507 # get customer and invoices
508 $updated = &check_name($form->{vc});
510 if ($new_name_selected || $updated) {
511 CP->get_openinvoices(\%myconfig, \%$form);
512 ($newvc) = split /--/, $form->{$form->{vc}};
513 $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;;
517 if ($form->{currency} ne $form->{oldcurrency}) {
518 $form->{oldcurrency} = $form->{currency};
520 CP->get_openinvoices(\%myconfig, \%$form);
526 $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{datepaid}, $buysell)));
528 $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
531 $form->{rowcount} = 0;
533 $form->{queued} = "";
536 foreach $ref (@{ $form->{PR} }) {
538 $form->{"id_$i"} = $ref->{id};
539 $form->{"invnumber_$i"} = $ref->{invnumber};
540 $form->{"transdate_$i"} = $ref->{transdate};
541 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
542 $form->{"amount_$i"} = $ref->{amount} / $ref->{exchangerate};
543 $form->{"due_$i"} = ($ref->{amount} - $ref->{paid}) / $ref->{exchangerate};
544 $form->{"checked_$i"} = "";
545 $form->{"paid_$i"} = "";
548 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due);
551 $form->{rowcount} = $i;
555 $amount = $form->{amount};
556 for $i (1 .. $form->{rowcount}) {
558 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(amount due paid);
560 if ($form->{"checked_$i"}) {
562 if (!$form->{"paid_$i"}) {
563 $form->{"paid_$i"} = $form->{"due_$i"};
566 $amount -= $form->{"paid_$i"};
568 $form->{"paid_$i"} = "";
571 map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(amount due paid);
579 $lxdebug->leave_sub();
583 $lxdebug->enter_sub();
588 if ($form->{currency} ne $form->{defaultcurrency}) {
589 $form->error($locale->text('Exchangerate missing!')) unless $form->{exchangerate};
592 $msg1 = "$form->{origtitle} posted!";
593 $msg2 = "Cannot post $form->{origtitle}!";
595 # $locale->text('Payment posted!')
596 # $locale->text('Receipt posted!')
597 # $locale->text('Cannot post Payment!')
598 # $locale->text('Cannot post Receipt!')
600 $form->redirect($locale->text($msg1)) if (CP->process_payment(\%myconfig, \%$form));
601 $form->error($locale->text($msg2));
603 $lxdebug->leave_sub();
608 $lxdebug->enter_sub();
613 ($whole, $form->{decimal}) = split /\./, $form->{amount};
615 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
617 $form->{decimal} .= "00";
618 $form->{decimal} = substr($form->{decimal}, 0, 2);
620 $check = new CP $myconfig{countrycode};
622 $form->{text_amount} = $check->num2text($whole);
624 &{ "$form->{vc}_details" };
626 $form->{callback} = "";
628 $form->{templates} = "$myconfig{templates}";
629 $form->{IN} = "$form->{formname}.tex";
631 if ($form->{format} eq 'postscript') {
632 $form->{postscript} = 1;
634 if ($form->{format} eq 'pdf') {
638 if ($form->{media} eq 'printer') {
639 $form->{OUT} = "| $myconfig{printer}";
641 if ($form->{media} eq 'queue') {
642 %queued = split / /, $form->{queued};
644 if ($filename = $queued{$form->{formname}}) {
645 unlink "$spool/$filename";
646 $filename =~ s/\..*$//g;
651 $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
652 $form->{queued} = "$form->{formname} $filename";
653 $form->{OUT} = ">$spool/$filename";
655 $form->update_status(\%myconfig);
659 $form->{company} = $myconfig{company};
660 $form->{address} = $myconfig{address};
662 @a = qw(name invnumber company address text_amount street zipcode city country memo);
663 $form->format_string(@a);
665 $form->parse_template(\%myconfig, $userspath);
667 if ($form->{media} ne 'screen') {
668 $form->{callback} = "$form->{script}?action=payment&vc=$form->{vc}&path=$form->{path}&login=$form->{login}&password=$form->{password}&all_vc=$form->{all_vc}";
670 $form->redirect if (CP->process_payment(\%myconfig, \%$form));
671 $form->error($locale->text('Cannot post payment!'));
674 $lxdebug->leave_sub();
678 sub customer_details { IS->customer_details(\%myconfig, \%$form) };
679 sub vendor_details { IR->vendor_details(\%myconfig, \%$form) };
683 $lxdebug->enter_sub();
686 &check_name($form->{vc});
688 if ($form->{currency} ne $form->{oldcurrency}) {
693 $form->error($locale->text('Date missing!')) unless $form->{datepaid};
695 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
696 $datepaid = $form->datetonum($form->{datepaid}, \%myconfig);
698 $form->error($locale->text('Cannot process payment for a closed period!')) if ($datepaid <= $closedto);
700 $amount = $form->parse_amount(\%myconfig, $form->{amount});
701 $form->{amount} = $amount;
704 for $i (1 .. $form->{rowcount}) {
705 if ($form->{"paid_$i"}) {
706 $amount -= $form->parse_amount($myconfig, $form->{"paid_$i"});
708 push(@{ $form->{paid} }, $form->{"paid_$i"});
709 push(@{ $form->{due} }, $form->{"due_$i"});
710 push(@{ $form->{invnumber} }, $form->{"invnumber_$i"});
711 push(@{ $form->{invdate} }, $form->{"transdate_$i"});
715 if ($form->round_amount($amount, 2) != 0) {
716 push(@{ $form->{paid} }, $form->format_amount(\%myconfig, $amount, 2));
717 push(@{ $form->{due} }, $form->format_amount(\%myconfig, 0, "0"));
718 push(@{ $form->{invnumber} }, ($form->{ARAP} eq 'AR') ? $locale->text('Deposit') : $locale->text('Prepayment'));
719 push(@{ $form->{invdate} }, $form->{datepaid});
722 $lxdebug->leave_sub();