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 #======================================================================
 
  30 # Account reconciliation module
 
  32 #======================================================================
 
  41   $lxdebug->enter_sub();
 
  43   RC->paymentaccounts(\%myconfig, \%$form);
 
  46   map { $selection .= "<option>$_->{accno}--$_->{description}\n" }
 
  49   $form->{title} = $locale->text('Reconciliation');
 
  51   $form->{"jsscript"} = 1;
 
  57 <form method=post action=$form->{script}>
 
  61     <th class=listtop>$form->{title}</th>
 
  68           <th align=right nowrap>| . $locale->text('Account') . qq|</th>
 
  69           <td colspan=3><select name=accno>$selection</select>
 
  73           <th align=right>| . $locale->text('From') . qq|</th>
 
  74           <td><input name=fromdate id=fromdate size=11 title="$myconfig{dateformat}">
 
  75      <input type="button" name="fromdate" id="trigger_fromdate" value="?"></td>
 
  76           <th align=right>| . $locale->text('Until') . qq|</th>
 
  77           <td><input name=todate id=todate size=11 title="$myconfig{dateformat}">
 
  78      <input type="button" name="todate" id="trigger_todate" value="?"></td>
 
  84     <td><hr size=3 noshade></td>
 
  88 | . $form->write_trigger(\%myconfig, 2,
 
  89                          "fromdate", "BL", "trigger_fromdate",
 
  90                          "todate", "BL", "trigger_todate") . qq|
 
  93 <input type=hidden name=nextsub value=get_payments>
 
  95 <input type=hidden name=path value=$form->{path}>
 
  96 <input type=hidden name=login value=$form->{login}>
 
  97 <input type=hidden name=password value=$form->{password}>
 
  99 <input type=submit class=submit name=action value="|
 
 100     . $locale->text('Continue') . qq|">
 
 108   $lxdebug->leave_sub();
 
 111 sub continue { &{ $form->{nextsub} } }
 
 114   $lxdebug->enter_sub();
 
 116   ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
 
 118   RC->payment_transactions(\%myconfig, \%$form);
 
 122   $lxdebug->leave_sub();
 
 126   $lxdebug->enter_sub();
 
 128   @column_index = qw(cleared transdate source name credit debit balance);
 
 130   $column_header{cleared} = "<th> </th>";
 
 131   $column_header{source}  =
 
 132     "<th class=listheading>" . $locale->text('Source') . "</a></th>";
 
 133   $column_header{name} =
 
 134     "<th class=listheading>" . $locale->text('Description') . "</a></th>";
 
 135   $column_header{transdate} =
 
 136     "<th class=listheading>" . $locale->text('Date') . "</a></th>";
 
 138   if ($form->{category} eq 'A') {
 
 139     $column_header{debit} =
 
 140       "<th class=listheading>" . $locale->text('Deposit') . "</a></th>";
 
 141     $column_header{credit} =
 
 142       "<th class=listheading>" . $locale->text('Payment') . "</a></th>";
 
 144     $column_header{debit} =
 
 145       "<th class=listheading>" . $locale->text('Decrease') . "</a></th>";
 
 146     $column_header{credit} =
 
 147       "<th class=listheading>" . $locale->text('Increase') . "</a></th>";
 
 150   $column_header{balance} =
 
 151     "<th class=listheading>" . $locale->text('Balance') . "</a></th>";
 
 153   if ($form->{fromdate}) {
 
 154     $option .= "\n<br>" if ($option);
 
 156         $locale->text('From') . " "
 
 157       . $locale->date(\%myconfig, $form->{fromdate}, 0);
 
 159   if ($form->{todate}) {
 
 160     $option .= "\n<br>" if ($option);
 
 162         $locale->text('Until') . " "
 
 163       . $locale->date(\%myconfig, $form->{todate}, 0);
 
 166   $form->{title} = "$form->{accno}--$form->{account}";
 
 173 <form method=post action=$form->{script}>
 
 177     <th class=listtop>$form->{title}</th>
 
 186         <tr class=listheading>
 
 189   map { print "\n$column_header{$_}" } @column_index;
 
 195   $ml = ($form->{category} eq 'A') ? -1 : 1;
 
 196   $form->{beginningbalance} *= $ml;
 
 197   $clearedbalance = $balance = $form->{beginningbalance};
 
 201   map { $column_data{$_} = "<td> </td>" }
 
 202     qw(cleared transdate source name debit credit);
 
 203   $column_data{balance} =
 
 205     . $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
 
 211   map { print "\n$column_data{$_}" } @column_index;
 
 217   foreach $ref (@{ $form->{PR} }) {
 
 219     $balance += $ref->{amount} * $ml;
 
 220     $cleared += $ref->{amount} * $ml if $ref->{cleared};
 
 222     $column_data{name}   = "<td>$ref->{name} </td>";
 
 223     $column_data{source} = qq|<td>$ref->{source} </a>
 
 225     $column_data{transdate} = "<td>$ref->{transdate} </td>";
 
 227     $column_data{debit}  = "<td> </td>";
 
 228     $column_data{credit} = "<td> </td>";
 
 230     if ($ref->{amount} < 0) {
 
 231       $totaldebits += $ref->{amount} * -1;
 
 232       $column_data{debit} =
 
 234         . $form->format_amount(\%myconfig, $ref->{amount} * -1, 2, " ")
 
 237       $totalcredits += $ref->{amount};
 
 238       $column_data{credit} =
 
 240         . $form->format_amount(\%myconfig, $ref->{amount}, 2, " ")
 
 244     $column_data{balance} =
 
 246       . $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
 
 248     if ($ref->{fx_transaction}) {
 
 249       $i++ unless $id == $ref->{id};
 
 251       $fx += $ref->{amount} * $ml;
 
 252       $column_data{cleared} = qq|<td align=center> 
 
 253       <input type=hidden name="fxoid_$i" value=$ref->{oid}>
 
 256       $i++ unless ($fx_transaction && $id == $ref->{id});
 
 258       $column_data{cleared} = qq|<td>
 
 259       <input name="cleared_$i" type=checkbox class=checkbox value=1 $ref->{cleared}>
 
 260       <input type=hidden name="oid_$i" value=$ref->{oid}>
 
 271     map { print "\n$column_data{$_}" } @column_index;
 
 280   map { $column_data{$_} = "<td> </td>" } @column_index;
 
 282   $column_data{debit} =
 
 283     "<th class=listtotal align=right>"
 
 284     . $form->format_amount(\%myconfig, $totaldebits, 2, " ") . "</th>";
 
 285   $column_data{credit} =
 
 286     "<th class=listtotal align=right>"
 
 287     . $form->format_amount(\%myconfig, $totalcredits, 2, " ") . "</th>";
 
 293   map { print "\n$column_data{$_}" } @column_index;
 
 295   $form->{statementbalance} =
 
 296     $form->parse_amount(\%myconfig, $form->{statementbalance});
 
 298     $form->format_amount(\%myconfig,
 
 299                         $form->{statementbalance} - $clearedbalance - $cleared,
 
 302   $form->{statementbalance} =
 
 303     $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
 
 305   $clearedbalance = $form->format_amount(\%myconfig, $clearedbalance, 2, 0);
 
 308     $fx       = $form->format_amount(\%myconfig, $fx, 2, 0);
 
 310                 <th align=right nowrap>|
 
 311       . $locale->text('Exchangerate Difference') . qq|</th>
 
 313                 <td align=right>$fx</td>
 
 329                 <th align=right nowrap>| . $locale->text('Cleared Balance') . qq|</th>
 
 331                 <td align=right>$clearedbalance</td>
 
 341                 <th align=right nowrap>| . $locale->text('Statement Balance') . qq|</th>
 
 343                 <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
 
 346                 <th align=right nowrap>| . $locale->text('Difference') . qq|</th>
 
 348                 <td align=right><input name=null size=11 value=$difference></td>
 
 349                 <input type=hidden name=difference value=$difference>
 
 358     <td><hr size=3 noshade></td>
 
 362 <input type=hidden name=rowcount value=$i>
 
 363 <input type=hidden name=accno value=$form->{accno}>
 
 364 <input type=hidden name=account value="$form->{account}">
 
 366 <input type=hidden name=fromdate value=$form->{fromdate}>
 
 367 <input type=hidden name=todate value=$form->{todate}>
 
 369 <input type=hidden name=path value=$form->{path}>
 
 370 <input type=hidden name=login value=$form->{login}>
 
 371 <input type=hidden name=password value=$form->{password}>
 
 374 <input type=submit class=submit name=action value="|
 
 375     . $locale->text('Update') . qq|">
 
 376 <input type=submit class=submit name=action value="|
 
 377     . $locale->text('Select all') . qq|">
 
 378 <input type=submit class=submit name=action value="|
 
 379     . $locale->text('Done') . qq|">|;
 
 381   if ($form->{menubar}) {
 
 382     require "$form->{path}/menu.pl";
 
 393   $lxdebug->leave_sub();
 
 397   $lxdebug->enter_sub();
 
 399   RC->payment_transactions(\%myconfig, \%$form);
 
 401   foreach $ref (@{ $form->{PR} }) {
 
 402     if (!$ref->{fx_transaction}) {
 
 404       $ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : "";
 
 410   $lxdebug->leave_sub();
 
 414   $lxdebug->enter_sub();
 
 416   RC->payment_transactions(\%myconfig, \%$form);
 
 418   map { $_->{cleared} = "checked" unless $_->{fx_transaction} }
 
 423   $lxdebug->leave_sub();
 
 427   $lxdebug->enter_sub();
 
 430     "$form->{script}?path=$form->{path}&action=reconciliation&login=$form->{login}&password=$form->{password}";
 
 432   $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
 
 434   RC->reconcile(\%myconfig, \%$form);
 
 437   $lxdebug->leave_sub();