kivitendo/bin/mozilla/rc.pl @ 89834c12
d319704a | Moritz Bunkus | #=====================================================================
|
||
# LX-Office ERP
|
||||
# Copyright (C) 2004
|
||||
# Based on SQL-Ledger Version 2.1.9
|
||||
# Web http://www.lx-office.org
|
||||
#
|
||||
#=====================================================================
|
||||
# SQL-Ledger Accounting
|
||||
# Copyright (c) 2002
|
||||
#
|
||||
# Author: Dieter Simader
|
||||
# Email: dsimader@sql-ledger.org
|
||||
# Web: http://www.sql-ledger.org
|
||||
#
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#======================================================================
|
||||
#
|
||||
# Account reconciliation module
|
||||
#
|
||||
#======================================================================
|
||||
use SL::RC;
|
||||
40782548 | Moritz Bunkus | require "bin/mozilla/common.pl";
|
||
8f35ef1f | Sven Schöling | use strict;
|
||
d319704a | Moritz Bunkus | 1;
|
||
# end of main
|
||||
sub reconciliation {
|
||||
b390c388 | Sven Schöling | $::lxdebug->enter_sub;
|
||
$::auth->assert('cash');
|
||||
8f35ef1f | Sven Schöling | |||
b390c388 | Sven Schöling | RC->paymentaccounts(\%::myconfig, $::form);
|
||
d319704a | Moritz Bunkus | |||
b390c388 | Sven Schöling | $::form->header;
|
||
print $::form->parse_html_template('rc/step1', {
|
||||
selection_sub => sub { ("$_[0]{accno}--$_[0]{description}")x2 },
|
||||
});
|
||||
d319704a | Moritz Bunkus | |||
b390c388 | Sven Schöling | $::lxdebug->leave_sub;
|
||
d319704a | Moritz Bunkus | }
|
||
8f35ef1f | Sven Schöling | sub continue { call_sub($main::form->{"nextsub"}); }
|
||
d319704a | Moritz Bunkus | |||
sub get_payments {
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
d319704a | Moritz Bunkus | |||
8f35ef1f | Sven Schöling | $main::auth->assert('cash');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
|
||
RC->payment_transactions(\%myconfig, \%$form);
|
||||
&display_form;
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub display_form {
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
8f35ef1f | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
8f35ef1f | Sven Schöling | $main::auth->assert('cash');
|
||
d319704a | Moritz Bunkus | |||
8f35ef1f | Sven Schöling | my @column_index = qw(cleared transdate source name credit debit balance);
|
||
my %column_header;
|
||||
d319704a | Moritz Bunkus | $column_header{cleared} = "<th> </th>";
|
||
$column_header{source} =
|
||||
"<th class=listheading>" . $locale->text('Source') . "</a></th>";
|
||||
$column_header{name} =
|
||||
"<th class=listheading>" . $locale->text('Description') . "</a></th>";
|
||||
$column_header{transdate} =
|
||||
"<th class=listheading>" . $locale->text('Date') . "</a></th>";
|
||||
if ($form->{category} eq 'A') {
|
||||
$column_header{debit} =
|
||||
"<th class=listheading>" . $locale->text('Deposit') . "</a></th>";
|
||||
$column_header{credit} =
|
||||
"<th class=listheading>" . $locale->text('Payment') . "</a></th>";
|
||||
} else {
|
||||
$column_header{debit} =
|
||||
"<th class=listheading>" . $locale->text('Decrease') . "</a></th>";
|
||||
$column_header{credit} =
|
||||
"<th class=listheading>" . $locale->text('Increase') . "</a></th>";
|
||||
}
|
||||
$column_header{balance} =
|
||||
"<th class=listheading>" . $locale->text('Balance') . "</a></th>";
|
||||
8f35ef1f | Sven Schöling | my $option;
|
||
d319704a | Moritz Bunkus | if ($form->{fromdate}) {
|
||
$option .= "\n<br>" if ($option);
|
||||
$option .=
|
||||
$locale->text('From') . " "
|
||||
b3e7f016 | Moritz Bunkus | . $locale->date(\%myconfig, $form->{fromdate}, 0);
|
||
d319704a | Moritz Bunkus | }
|
||
if ($form->{todate}) {
|
||||
$option .= "\n<br>" if ($option);
|
||||
$option .=
|
||||
96b6e28f | Moritz Bunkus | $locale->text('Until') . " "
|
||
b3e7f016 | Moritz Bunkus | . $locale->date(\%myconfig, $form->{todate}, 0);
|
||
d319704a | Moritz Bunkus | }
|
||
$form->{title} = "$form->{accno}--$form->{account}";
|
||||
$form->header;
|
||||
print qq|
|
||||
<body>
|
||||
<form method=post action=$form->{script}>
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<th class=listtop>$form->{title}</th>
|
||||
</tr>
|
||||
<tr height="5"></tr>
|
||||
<tr>
|
||||
<td>$option</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table width=100%>
|
||||
b65a230d | Sven Schöling | <tr class=listheading>
|
||
d319704a | Moritz Bunkus | |;
|
||
map { print "\n$column_header{$_}" } @column_index;
|
||||
print qq|
|
||||
</tr>
|
||||
|;
|
||||
8f35ef1f | Sven Schöling | my $ml = ($form->{category} eq 'A') ? -1 : 1;
|
||
d319704a | Moritz Bunkus | $form->{beginningbalance} *= $ml;
|
||
8f35ef1f | Sven Schöling | my $balance = $form->{beginningbalance};
|
||
my $clearedbalance = $balance;
|
||||
my $i = 0;
|
||||
my $id = 0;
|
||||
d319704a | Moritz Bunkus | |||
8f35ef1f | Sven Schöling | my %column_data;
|
||
d319704a | Moritz Bunkus | map { $column_data{$_} = "<td> </td>" }
|
||
qw(cleared transdate source name debit credit);
|
||||
$column_data{balance} =
|
||||
"<td align=right>"
|
||||
. $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
|
||||
8f35ef1f | Sven Schöling | my $j = 0;
|
||
d319704a | Moritz Bunkus | print qq|
|
||
b65a230d | Sven Schöling | <tr class=listrow$j>
|
||
d319704a | Moritz Bunkus | |;
|
||
map { print "\n$column_data{$_}" } @column_index;
|
||||
print qq|
|
||||
b65a230d | Sven Schöling | </tr>
|
||
d319704a | Moritz Bunkus | |;
|
||
8f35ef1f | Sven Schöling | my $cleared;
|
||
my $totaldebits;
|
||||
my $totalcredits;
|
||||
my $fx_transaction;
|
||||
my $fx;
|
||||
foreach my $ref (@{ $form->{PR} }) {
|
||||
d319704a | Moritz Bunkus | |||
$balance += $ref->{amount} * $ml;
|
||||
$cleared += $ref->{amount} * $ml if $ref->{cleared};
|
||||
$column_data{name} = "<td>$ref->{name} </td>";
|
||||
$column_data{source} = qq|<td>$ref->{source} </a>
|
||||
</td>|;
|
||||
$column_data{transdate} = "<td>$ref->{transdate} </td>";
|
||||
$column_data{debit} = "<td> </td>";
|
||||
$column_data{credit} = "<td> </td>";
|
||||
if ($ref->{amount} < 0) {
|
||||
$totaldebits += $ref->{amount} * -1;
|
||||
$column_data{debit} =
|
||||
"<td align=right>"
|
||||
. $form->format_amount(\%myconfig, $ref->{amount} * -1, 2, " ")
|
||||
. "</td>";
|
||||
} else {
|
||||
$totalcredits += $ref->{amount};
|
||||
$column_data{credit} =
|
||||
"<td align=right>"
|
||||
. $form->format_amount(\%myconfig, $ref->{amount}, 2, " ")
|
||||
. "</td>";
|
||||
}
|
||||
$column_data{balance} =
|
||||
"<td align=right>"
|
||||
. $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
|
||||
if ($ref->{fx_transaction}) {
|
||||
$i++ unless $id == $ref->{id};
|
||||
$fx_transaction = 1;
|
||||
$fx += $ref->{amount} * $ml;
|
||||
$column_data{cleared} = qq|<td align=center>
|
||||
<input type=hidden name="fxoid_$i" value=$ref->{oid}>
|
||||
</td>|;
|
||||
} else {
|
||||
$i++ unless ($fx_transaction && $id == $ref->{id});
|
||||
$fx_transaction = 0;
|
||||
$column_data{cleared} = qq|<td>
|
||||
<input name="cleared_$i" type=checkbox class=checkbox value=1 $ref->{cleared}>
|
||||
<input type=hidden name="oid_$i" value=$ref->{oid}>
|
||||
</td>|;
|
||||
}
|
||||
$id = $ref->{id};
|
||||
$j++;
|
||||
$j %= 2;
|
||||
print qq|
|
||||
b65a230d | Sven Schöling | <tr class=listrow$j>
|
||
d319704a | Moritz Bunkus | |;
|
||
map { print "\n$column_data{$_}" } @column_index;
|
||||
print qq|
|
||||
b65a230d | Sven Schöling | </tr>
|
||
d319704a | Moritz Bunkus | |;
|
||
}
|
||||
# print totals
|
||||
map { $column_data{$_} = "<td> </td>" } @column_index;
|
||||
$column_data{debit} =
|
||||
"<th class=listtotal align=right>"
|
||||
. $form->format_amount(\%myconfig, $totaldebits, 2, " ") . "</th>";
|
||||
$column_data{credit} =
|
||||
"<th class=listtotal align=right>"
|
||||
. $form->format_amount(\%myconfig, $totalcredits, 2, " ") . "</th>";
|
||||
print qq|
|
||||
b65a230d | Sven Schöling | <tr class=listtotal>
|
||
d319704a | Moritz Bunkus | |;
|
||
map { print "\n$column_data{$_}" } @column_index;
|
||||
$form->{statementbalance} =
|
||||
$form->parse_amount(\%myconfig, $form->{statementbalance});
|
||||
8f35ef1f | Sven Schöling | my $difference =
|
||
d319704a | Moritz Bunkus | $form->format_amount(\%myconfig,
|
||
$form->{statementbalance} - $clearedbalance - $cleared,
|
||||
2, 0);
|
||||
$form->{statementbalance} =
|
||||
$form->format_amount(\%myconfig, $form->{statementbalance}, 2, 0);
|
||||
$clearedbalance = $form->format_amount(\%myconfig, $clearedbalance, 2, 0);
|
||||
8f35ef1f | Sven Schöling | my $exchdiff;
|
||
d319704a | Moritz Bunkus | if ($fx) {
|
||
081a4f97 | Moritz Bunkus | $fx = $form->format_amount(\%myconfig, $fx, 2, 0);
|
||
d319704a | Moritz Bunkus | $exchdiff = qq|
|
||
b65a230d | Sven Schöling | <th align=right nowrap>| . $locale->text('Exchangerate Difference') . qq|</th>
|
||
<td width=10%></td>
|
||||
<td align=right>$fx</td>
|
||||
d319704a | Moritz Bunkus | |;
|
||
}
|
||||
print qq|
|
||||
b65a230d | Sven Schöling | </tr>
|
||
d319704a | Moritz Bunkus | </table>
|
||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table width=100%>
|
||||
<tr valign=top>
|
||||
b65a230d | Sven Schöling | <td>
|
||
<table>
|
||||
<tr>
|
||||
<th align=right nowrap>| . $locale->text('Cleared Balance') . qq|</th>
|
||||
<td width=10%></td>
|
||||
<td align=right>$clearedbalance</td>
|
||||
</tr>
|
||||
<tr>
|
||||
$exchdiff
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td align=right>
|
||||
<table>
|
||||
<tr>
|
||||
<th align=right nowrap>| . $locale->text('Statement Balance') . qq|</th>
|
||||
<td width=10%></td>
|
||||
<td align=right><input name=statementbalance size=11 value=$form->{statementbalance}></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align=right nowrap>| . $locale->text('Difference') . qq|</th>
|
||||
<td width=10%></td>
|
||||
<td align=right><input name=null size=11 value=$difference></td>
|
||||
<input type=hidden name=difference value=$difference>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
d319704a | Moritz Bunkus | </table>
|
||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><hr size=3 noshade></td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type=hidden name=rowcount value=$i>
|
||||
<input type=hidden name=accno value=$form->{accno}>
|
||||
<input type=hidden name=account value="$form->{account}">
|
||||
<input type=hidden name=fromdate value=$form->{fromdate}>
|
||||
<input type=hidden name=todate value=$form->{todate}>
|
||||
<br>
|
||||
<input type=submit class=submit name=action value="|
|
||||
. $locale->text('Update') . qq|">
|
||||
<input type=submit class=submit name=action value="|
|
||||
. $locale->text('Select all') . qq|">
|
||||
<input type=submit class=submit name=action value="|
|
||||
8ec0d29a | Moritz Bunkus | . $locale->text('Done') . qq|">
|
||
d319704a | Moritz Bunkus | |||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|;
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub update {
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
8f35ef1f | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
$main::auth->assert('cash');
|
||||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | RC->payment_transactions(\%myconfig, \%$form);
|
||
8f35ef1f | Sven Schöling | my $i;
|
||
foreach my $ref (@{ $form->{PR} }) {
|
||||
d319704a | Moritz Bunkus | if (!$ref->{fx_transaction}) {
|
||
$i++;
|
||||
$ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : "";
|
||||
}
|
||||
}
|
||||
&display_form;
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub select_all {
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
d319704a | Moritz Bunkus | |||
8f35ef1f | Sven Schöling | $main::auth->assert('cash');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | RC->payment_transactions(\%myconfig, \%$form);
|
||
map { $_->{cleared} = "checked" unless $_->{fx_transaction} }
|
||||
@{ $form->{PR} };
|
||||
&display_form;
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub done {
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
d319704a | Moritz Bunkus | |||
8f35ef1f | Sven Schöling | $main::auth->assert('cash');
|
||
8c7e4493 | Moritz Bunkus | |||
$form->{callback} = "$form->{script}?action=reconciliation";
|
||||
d319704a | Moritz Bunkus | |||
$form->error($locale->text('Out of balance!')) if ($form->{difference} *= 1);
|
||||
RC->reconcile(\%myconfig, \%$form);
|
||||
$form->redirect;
|
||||
8f35ef1f | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|