/usr/share/perl5/EB/Tools/Einde.pm is in eekboek 2.00.03-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | #! perl -- -*- coding: utf-8 -*-
use utf8;
# Einde.pm -- Eindejaarsverwerking
# RCS Info : $Id: Einde.pm,v 1.22 2009/11/04 22:24:03 jv Exp $
# Author : Johan Vromans
# Created On : Sun Oct 16 21:27:40 2005
# Last Modified By: Johan Vromans
# Last Modified On: Wed Nov 4 23:21:55 2009
# Update Count : 246
# Status : Unknown, Use with caution!
package main;
our $cfg;
our $dbh;
package EB::Tools::Einde;
use strict;
use warnings;
our $VERSION = sprintf "%d.%03d", q$Revision: 1.22 $ =~ /(\d+)/g;
use EB;
use EB::Format;
use EB::Report;
use EB::Report::GenBase;
use EB::Report::Journal;
use EB::Report::Open;
sub new {
my ($class) = @_;
$class = ref($class) || $class;
return bless {} => $class;
}
sub perform {
my ($self, $args, $opts) = @_;
# Akties:
# Afboeken resultaatrekeningen -> Winstrekening
# Afboeken BTW I/V H/L -> BTW Betaald
my $tot = 0;
my $date = $cfg->val(qw(internal now), iso8601date());
$date = $dbh->adm("end") unless $date lt $dbh->adm("end");
my $sth;
my $rr;
my $bky = $opts->{boekjaar};
my $def = $opts->{definitief};
my $eb;
if ( $opts->{eb} ) {
unless ( open($eb, '>:encoding(utf-8)', $opts->{eb}) ) {
warn("?", __x("Fout tijdens het aanmaken van bestand {file}: {err}",
file => $opts->{eb}, err => $!."")."\n");
return;
}
$opts->{eb_handle} = $eb;
}
my ($acc_id, $acc_desc, $acc_balance);
warn("?",_T("Geen boekjaar opgegeven")."\n"), return unless $bky;
$rr = $dbh->do("SELECT bky_begin, bky_end, bky_closed".
" FROM Boekjaren".
" WHERE bky_code = ?", $bky);
warn("?",__x("Onbekend boekjaar: {bky}", bky => $bky)."\n"), return unless $rr;
my ($begin, $end, $closed) = @$rr;
if ( $closed ) {
if ( $opts->{verwijder} ) {
warn("?",__x("Boekjaar {bky} is definitief afgesloten", bky => $bky)."\n");
}
else {
warn("?",__x("Boekjaar {bky} is reeds definitief afgesloten", bky => $bky)."\n");
}
return;
}
$dbh->begin_work;
$dbh->sql_exec("DELETE FROM Boekjaarbalans where bkb_bky = ?", $bky)->finish;
$dbh->commit, return if $opts->{verwijder};
$opts->{STYLE} = "journaal";
$opts->{LAYOUT} =
[ { name => "date", title => _T("Datum"), width => $date_width, },
{ name => "desc", title => _T("Boekstuk/Grootboek"), width => 30, },
{ name => "acct", title => _T("Rek"), width => 5, align => ">", },
{ name => "deb", title => _T("Debet"), width => $amount_width, align => ">", },
{ name => "crd", title => _T("Credit"), width => $amount_width, align => ">", },
{ name => "bsk", title => _T("Boekstuk/regel"), width => 30, },
{ name => "rel", title => _T("Relatie"), width => 10, },
];
my $rep;
$rep = EB::Report::GenBase->backend(EB::Report::Journal::, $opts);
my $tbl = EB::Report::->GetTAccountsBal($end);
$sth = $dbh->sql_exec("SELECT acc_id, acc_desc, acc_balance".
" FROM ${tbl}".
" WHERE NOT acc_balres".
" AND acc_balance <> 0".
" ORDER BY acc_id");
my $edt = parse_date($end, undef, 1);
my $dtot = 0;
my $ctot = 0;
my $did;
my $desc;
while ( $rr = $sth->fetchrow_arrayref ) {
($acc_id, $acc_desc, $acc_balance) = @$rr;
$tot += $acc_balance;
$dbh->sql_insert("Boekjaarbalans",
[qw(bkb_bky bkb_acc_id bkb_balance bkb_end)],
$bky, $acc_id, $acc_balance, $end);
unless ( $did++ ) {
$rep->start(_T("Journaal"),
__x("Afsluiting boekjaar {bky}", bky => $bky));
}
unless ( $desc ) {
$rep->add({ _style => 'head',
date => datefmt_full($end),
desc => join(":", "<<"._T("Systeemdagboek").">>", $bky, 1),
});
$desc = "Afboeken Resultaatrekeningen";
}
$acc_balance = -$acc_balance;
$rep->add({ _style => 'data',
date => datefmt_full($end),
desc => $dbh->lookup($acc_id, qw(Accounts acc_id acc_desc)),
acct => $acc_id,
$acc_balance >= 0 ? ( deb => numfmt($acc_balance) )
: ( crd => numfmt(-$acc_balance) ),
bsk => $desc,
});
$dtot += $acc_balance if $acc_balance > 0;
$ctot -= $acc_balance if $acc_balance < 0;
}
if ( $did ) {
my $d = '<< ' . ($tot <= 0 ?
__x("Winst boekjaar {bky}", bky => $bky) :
__x("Verlies boekjaar {bky}", bky => $bky)) . ' >>';
$dbh->sql_insert("Boekjaarbalans",
[qw(bkb_bky bkb_acc_id bkb_balance bkb_end)],
$bky, $dbh->std_acc("winst"), -$tot, $end);
$tot = -$tot;
$rep->add({ _style => 'data',
date => datefmt_full($end),
desc => $d,
acct => $dbh->std_acc("winst"),
$tot >= 0 ? ( crd => numfmt($tot) )
: ( deb => numfmt(-$tot) ),
bsk => $desc,
});
$ctot += $tot if $tot > 0;
$dtot -= $tot if $tot < 0;
}
$tot = 0;
$desc = "";
if ( $dbh->does_btw ) {
## Afboeken BTW
foreach ( @{ $dbh->std_accs } ) {
my $stdacc = $_; # copy for mod
next unless $stdacc =~ /^btw_[iv].$/;
next unless defined( $stdacc = $dbh->std_acc($stdacc, undef) );
($acc_id, $acc_desc, $acc_balance) =
@{$dbh->do("SELECT acc_id,acc_desc,acc_balance".
" FROM ${tbl}".
" WHERE acc_id = ?",
$stdacc)};
next unless $acc_balance;
$tot += $acc_balance;
$dbh->sql_insert("Boekjaarbalans",
[qw(bkb_bky bkb_acc_id bkb_balance bkb_end)],
$bky, $acc_id, $acc_balance, $end);
unless ( $did++ ) {
$rep->start(_T("Journaal"),
__x("Afsluiting boekjaar {bky}", bky => $bky));
}
elsif ( !$desc ) {
# $rep->outline(' ');
}
unless ( $desc ) {
$rep->add({ _style => 'head',
date => datefmt_full($end),
desc => join(":", "<<"._T("Systeemdagboek").">>", $bky, 2),
});
$desc = "Afboeken BTW rekeningen";
}
$acc_balance = -$acc_balance;
$rep->add({ _style => 'data',
date => datefmt_full($end),
desc => $dbh->lookup($acc_id, qw(Accounts acc_id acc_desc)),
acct => $acc_id,
$acc_balance >= 0 ? ( deb => numfmt($acc_balance) )
: ( crd => numfmt(-$acc_balance) ),
bsk => $desc,
});
$dtot += $acc_balance if $acc_balance > 0;
$ctot -= $acc_balance if $acc_balance < 0;
}
if ( $did && $dbh->does_btw ) {
($acc_id, $acc_desc, $acc_balance) =
@{$dbh->do("SELECT acc_id,acc_desc,acc_balance".
" FROM ${tbl}".
" WHERE acc_id = ?",
$dbh->std_acc("btw_ok"))};
$dbh->sql_insert("Boekjaarbalans",
[qw(bkb_bky bkb_acc_id bkb_balance bkb_end)],
$bky, $acc_id, -$tot, $end);
$tot = -$tot;
$rep->add({ _style => 'data',
date => datefmt_full($end),
desc => $acc_desc,
acct => $acc_id,
$tot >= 0 ? ( crd => numfmt($tot) )
: ( deb => numfmt(-$tot) ),
bsk => $desc,
});
$ctot += $tot if $tot > 0;
$dtot -= $tot if $tot < 0;
}
} ## End afboeken BTW
if ( $did ) {
$rep->add({ _style => 'total',
desc => __x("Totaal {pfx}", pfx => __x("Afsluiting boekjaar {bky}", bky => $bky)),
deb => numfmt($dtot),
crd => numfmt($ctot),
});
$rep->finish;
}
if ( $eb ) {
print {$eb} ("\n# ",
__x("Eindbalans bij afsluiting boekjaar {bky}",
bky => $bky),
"\n");
$sth = $dbh->sql_exec("SELECT acc_id, acc_desc, acc_balance, acc_ibalance, acc_debcrd".
" FROM ${tbl}".
" WHERE acc_balres".
" ORDER BY acc_debcrd DESC, acc_id");
my ($dt, $ct);
my $debcrd;
while ( $rr = $sth->fetchrow_arrayref ) {
my ($acc_id, $acc_desc, $acc_balance, $acc_ibalance, $acc_debcrd) = @$rr;
# warn("=> acc $acc_id bal = $acc_balance ibal = $acc_ibalance\n");
if ( my $t = $dbh->do("SELECT bkb_balance".
" FROM Boekjaarbalans".
" WHERE bkb_bky = ?".
" AND bkb_acc_id = ?",
$bky, $acc_id) ) {
$acc_balance -= $t->[0];
}
next unless $acc_balance;
if ( $acc_balance >= 0 ) {
$dt += $acc_balance;
}
else {
$ct -= $acc_balance;
}
$acc_balance = 0 - $acc_balance unless $acc_debcrd;
if ( !defined($debcrd) || $acc_debcrd != $debcrd ) {
print {$eb} ("\n# ",
$acc_debcrd ? _T("Debet") : _T("Credit"),
"\n");
}
printf {$eb} ("adm_balans %-5s %10s # %s\n",
$acc_id, numfmt_plain($acc_balance),
$acc_desc);
$debcrd = $acc_debcrd;
}
die("?".__x("Internal error -- unbalance {arg1} <> {arg2}",
arg1 => numfmt($dt),
arg2 => numfmt($ct))."\n")
unless $dt == $ct;
print {$eb} ("\n# ", _T("Totaal"), "\n",
"adm_balanstotaal ", numfmt_plain($dt), "\n");
print {$eb} ("\n# ",
__x("Openstaande posten bij afsluiting boekjaar {bky}",
bky => $bky),
"\n\n");
my $t = EB::Report::Open->new->perform($opts);
if ( $t ) {
$t =~ s/^./# /;
print {$eb} ($t, "\n");
}
}
else {
EB::Report::Open->new->perform($opts);
}
if ( $def ) {
$dbh->sql_exec("UPDATE Boekjaren".
" SET bky_closed = now()".
" WHERE bky_code = ?", $bky)->finish;
}
$dbh->commit;
close($eb) if $eb;
undef;
}
1;
|