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 #======================================================================
 
  36 require "bin/mozilla/common.pl";
 
  43   $lxdebug->enter_sub();
 
  45   RC->paymentaccounts(\%myconfig, \%$form);
 
  48   map { $selection .= "<option>$_->{accno}--$_->{description}\n" }
 
  51   $form->{title} = $locale->text('Reconciliation');
 
  52   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
 
  53   $form->{"jsscript"} = 1;
 
  55   $onload = qq|focus()|;
 
  56   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
  59 <body onLoad="$onload">
 
  61 <form method=post action=$form->{script}>
 
  65     <th class=listtop>$form->{title}</th>
 
  72           <th align=right nowrap>| . $locale->text('Account') . qq|</th>
 
  73           <td colspan=3><select name=accno>$selection</select>
 
  77           <th align=right>| . $locale->text('From') . qq|</th>
 
  78           <td><input name=fromdate id=fromdate size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
  79      <input type="button" name="fromdate" id="trigger_fromdate" value="?"></td>
 
  80           <th align=right>| . $locale->text('Until') . qq|</th>
 
  81           <td><input name=todate id=todate size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
 
  82      <input type="button" name="todate" id="trigger_todate" value="?"></td>
 
  88     <td><hr size=3 noshade></td>
 
  92 | . $form->write_trigger(\%myconfig, 2,
 
  93                          "fromdate", "BL", "trigger_fromdate",
 
  94                          "todate", "BL", "trigger_todate") . qq|
 
  97 <input type=hidden name=nextsub value=get_payments>
 
  99 <input type=hidden name=login value=$form->{login}>
 
 100 <input type=hidden name=password value=$form->{password}>
 
 102 <input type=submit class=submit name=action value="|
 
 103     . $locale->text('Continue') . qq|">
 
 111   $lxdebug->leave_sub();
 
 114 sub continue { call_sub($form->{"nextsub"}); }
 
 117   $lxdebug->enter_sub();
 
 119   ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
 
 121   RC->payment_transactions(\%myconfig, \%$form);
 
 125   $lxdebug->leave_sub();
 
 129   $lxdebug->enter_sub();
 
 131   @column_index = qw(cleared transdate source name credit debit balance);
 
 133   $column_header{cleared} = "<th> </th>";
 
 134   $column_header{source}  =
 
 135     "<th class=listheading>" . $locale->text('Source') . "</a></th>";
 
 136   $column_header{name} =
 
 137     "<th class=listheading>" . $locale->text('Description') . "</a></th>";
 
 138   $column_header{transdate} =
 
 139     "<th class=listheading>" . $locale->text('Date') . "</a></th>";
 
 141   if ($form->{category} eq 'A') {
 
 142     $column_header{debit} =
 
 143       "<th class=listheading>" . $locale->text('Deposit') . "</a></th>";
 
 144     $column_header{credit} =
 
 145       "<th class=listheading>" . $locale->text('Payment') . "</a></th>";
 
 147     $column_header{debit} =
 
 148       "<th class=listheading>" . $locale->text('Decrease') . "</a></th>";
 
 149     $column_header{credit} =
 
 150       "<th class=listheading>" . $locale->text('Increase') . "</a></th>";
 
 153   $column_header{balance} =
 
 154     "<th class=listheading>" . $locale->text('Balance') . "</a></th>";
 
 156   if ($form->{fromdate}) {
 
 157     $option .= "\n<br>" if ($option);
 
 159         $locale->text('From') . " "
 
 160       . $locale->date(\%myconfig, $form->{fromdate}, 0);
 
 162   if ($form->{todate}) {
 
 163     $option .= "\n<br>" if ($option);
 
 165         $locale->text('Until') . " "
 
 166       . $locale->date(\%myconfig, $form->{todate}, 0);
 
 169   $form->{title} = "$form->{accno}--$form->{account}";
 
 176 <form method=post action=$form->{script}>
 
 180     <th class=listtop>$form->{title}</th>
 
 189         <tr class=listheading>
 
 192   map { print "\n$column_header{$_}" } @column_index;
 
 198   $ml = ($form->{category} eq 'A') ? -1 : 1;
 
 199   $form->{beginningbalance} *= $ml;
 
 200   $clearedbalance = $balance = $form->{beginningbalance};
 
 204   map { $column_data{$_} = "<td> </td>" }
 
 205     qw(cleared transdate source name debit credit);
 
 206   $column_data{balance} =
 
 208     . $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
 
 214   map { print "\n$column_data{$_}" } @column_index;
 
 220   foreach $ref (@{ $form->{PR} }) {
 
 222     $balance += $ref->{amount} * $ml;
 
 223     $cleared += $ref->{amount} * $ml if $ref->{cleared};
 
 225     $column_data{name}   = "<td>$ref->{name} </td>";
 
 226     $column_data{source} = qq|<td>$ref->{source} </a>
 
 228     $column_data{transdate} = "<td>$ref->{transdate} </td>";
 
 230     $column_data{debit}  = "<td> </td>";
 
 231     $column_data{credit} = "<td> </td>";
 
 233     if ($ref->{amount} < 0) {
 
 234       $totaldebits += $ref->{amount} * -1;
 
 235       $column_data{debit} =
 
 237         . $form->format_amount(\%myconfig, $ref->{amount} * -1, 2, " ")
 
 240       $totalcredits += $ref->{amount};
 
 241       $column_data{credit} =
 
 243         . $form->format_amount(\%myconfig, $ref->{amount}, 2, " ")
 
 247     $column_data{balance} =
 
 249       . $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
 
 251     if ($ref->{fx_transaction}) {
 
 252       $i++ unless $id == $ref->{id};
 
 254       $fx += $ref->{amount} * $ml;
 
 255       $column_data{cleared} = qq|<td align=center> 
 
 256       <input type=hidden name="fxoid_$i" value=$ref->{oid}>
 
 259       $i++ unless ($fx_transaction && $id == $ref->{id});
 
 261       $column_data{cleared} = qq|<td>
 
 262       <input name="cleared_$i" type=checkbox class=checkbox value=1 $ref->{cleared}>
 
 263       <input type=hidden name="oid_$i" value=$ref->{oid}>
 
 274     map { print "\n$column_data{$_}" } @column_index;
 
 283   map { $column_data{$_} = "<td> </td>" } @column_index;
 
 285   $column_data{debit} =
 
 286     "<th class=listtotal align=right>"
 
 287     . $form->format_amount(\%myconfig, $totaldebits, 2, " ") . "</th>";
 
 288   $column_data{credit} =
 
 289     "<th class=listtotal align=right>"
 
 290     . $form->format_amount(\%myconfig, $totalcredits, 2, " ") . "</th>";
 
 296   map { print "\n$column_data{$_}" } @column_index;
 
 298   $form->{statementbalance} =
 
 299     $form->parse_amount(\%myconfig, $form->{statementbalance});
 
 301     $form->format_amount(\%myconfig,
 
 302                         $form->{statementbalance} - $clearedbalance - $cleared,
 
 305   $form->{statementbalance} =
 
 306     $form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
 
 308   $clearedbalance = $form->format_amount(\%myconfig, $clearedbalance, 2, 0);
 
 311     $fx       = $form->format_amount(\%myconfig, $fx, 2, 0);
 
 313                 <th align=right nowrap>|
 
 314       . $locale->text('Exchangerate Difference') . qq|</th>
 
 316                 <td align=right>$fx</td>
 
 332                 <th align=right nowrap>| . $locale->text('Cleared Balance') . qq|</th>
 
 334                 <td align=right>$clearedbalance</td>
 
 344                 <th align=right nowrap>| . $locale->text('Statement Balance') . qq|</th>
 
 346                 <td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
 
 349                 <th align=right nowrap>| . $locale->text('Difference') . qq|</th>
 
 351                 <td align=right><input name=null size=11 value=$difference></td>
 
 352                 <input type=hidden name=difference value=$difference>
 
 361     <td><hr size=3 noshade></td>
 
 365 <input type=hidden name=rowcount value=$i>
 
 366 <input type=hidden name=accno value=$form->{accno}>
 
 367 <input type=hidden name=account value="$form->{account}">
 
 369 <input type=hidden name=fromdate value=$form->{fromdate}>
 
 370 <input type=hidden name=todate value=$form->{todate}>
 
 372 <input type=hidden name=login value=$form->{login}>
 
 373 <input type=hidden name=password value=$form->{password}>
 
 376 <input type=submit class=submit name=action value="|
 
 377     . $locale->text('Update') . qq|">
 
 378 <input type=submit class=submit name=action value="|
 
 379     . $locale->text('Select all') . qq|">
 
 380 <input type=submit class=submit name=action value="|
 
 381     . $locale->text('Done') . qq|">
 
 389   $lxdebug->leave_sub();
 
 393   $lxdebug->enter_sub();
 
 395   RC->payment_transactions(\%myconfig, \%$form);
 
 397   foreach $ref (@{ $form->{PR} }) {
 
 398     if (!$ref->{fx_transaction}) {
 
 400       $ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : "";
 
 406   $lxdebug->leave_sub();
 
 410   $lxdebug->enter_sub();
 
 412   RC->payment_transactions(\%myconfig, \%$form);
 
 414   map { $_->{cleared} = "checked" unless $_->{fx_transaction} }
 
 419   $lxdebug->leave_sub();
 
 423   $lxdebug->enter_sub();
 
 426     "$form->{script}?action=reconciliation&login=$form->{login}&password=$form->{password}";
 
 428   $form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
 
 430   RC->reconcile(\%myconfig, \%$form);
 
 433   $lxdebug->leave_sub();