| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#! perl -- -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use utf8; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# Booking.pm -- Base class for Bookings. |
|
6
|
|
|
|
|
|
|
# Author : Johan Vromans |
|
7
|
|
|
|
|
|
|
# Created On : Sat Oct 15 23:36:51 2005 |
|
8
|
|
|
|
|
|
|
# Last Modified By: Johan Vromans |
|
9
|
|
|
|
|
|
|
# Last Modified On: Fri Aug 31 19:07:41 2012 |
|
10
|
|
|
|
|
|
|
# Update Count : 208 |
|
11
|
|
|
|
|
|
|
# Status : Unknown, Use with caution! |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package main; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $cfg; |
|
16
|
|
|
|
|
|
|
our $dbh; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package EB::Booking; |
|
19
|
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
39
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
13
|
|
|
21
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
16
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
3
|
use EB; |
|
|
1
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
|
143
|
|
|
24
|
1
|
|
|
1
|
|
3
|
use EB::Format; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1807
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
|
27
|
0
|
|
|
0
|
0
|
|
my ($class) = @_; |
|
28
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
|
29
|
0
|
|
|
|
|
|
return bless {} => $class; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub adm_open { |
|
33
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
34
|
0
|
0
|
|
|
|
|
unless ( $dbh->adm_open ) { |
|
35
|
0
|
|
|
|
|
|
warn("?"._T("De administratie is nog niet geopend")."\n"); |
|
36
|
0
|
|
|
|
|
|
return; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
0
|
|
|
|
|
|
1; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub check_bsk_nr { |
|
42
|
0
|
|
|
0
|
0
|
|
my ($self, $opts) = @_; |
|
43
|
0
|
|
|
|
|
|
my $bsk_nr = $opts->{boekstuk}; |
|
44
|
0
|
|
|
|
|
|
my $bky = $opts->{boekjaar}; |
|
45
|
0
|
0
|
|
|
|
|
$bky = $dbh->adm("bky") unless defined($bky); |
|
46
|
0
|
|
|
|
|
|
my $dbk = $opts->{dagboek}; |
|
47
|
0
|
|
|
|
|
|
my $rr = $dbh->do("SELECT count(*) FROM Boekstukken". |
|
48
|
|
|
|
|
|
|
" WHERE bsk_nr = ? AND bsk_dbk_id = ? AND bsk_bky = ?", |
|
49
|
|
|
|
|
|
|
$bsk_nr, $dbk, $bky); |
|
50
|
0
|
0
|
0
|
|
|
|
return 1 if defined($rr) && $rr->[0] == 0; |
|
51
|
0
|
|
|
|
|
|
warn("?".__x("Boekstuk {bsk} is reeds in gebruik", |
|
52
|
|
|
|
|
|
|
bsk => join(":", |
|
53
|
|
|
|
|
|
|
$dbh->lookup($dbk, qw(Dagboeken dbk_id dbk_desc)), |
|
54
|
|
|
|
|
|
|
$bsk_nr))."\n"); |
|
55
|
0
|
|
|
|
|
|
return; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub bsk_nr { |
|
59
|
0
|
|
|
0
|
0
|
|
my ($self, $opts) = @_; |
|
60
|
0
|
|
|
|
|
|
my $bsk_nr; |
|
61
|
0
|
|
0
|
|
|
|
my $prev = defined($opts->{boekjaar}) && $opts->{boekjaar} ne $dbh->adm("bky"); |
|
62
|
0
|
0
|
|
|
|
|
if ( $bsk_nr = $opts->{boekstuk} ) { |
|
|
|
0
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
unless ( $bsk_nr =~ /^[0-9]+$/ ) { |
|
64
|
0
|
|
|
|
|
|
warn("?"._T("Het boekstuknummer moet een geheel getal (volgnummer) zijn")."\n"); |
|
65
|
0
|
|
|
|
|
|
return; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
0
|
|
|
|
|
return unless $self->check_bsk_nr($opts); |
|
68
|
0
|
0
|
|
|
|
|
my $t = $prev ? "0" : $opts->{dagboek}; |
|
69
|
0
|
|
|
|
|
|
$dbh->set_sequence("bsk_nr_${t}_seq", $bsk_nr+1) |
|
70
|
|
|
|
|
|
|
# if $dbh->get_sequence("bsk_nr_${t}_seq", "noincr") < $bsk_nr; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
elsif ( $prev ) { |
|
73
|
0
|
|
|
|
|
|
warn("?"._T("Boekstukken in voorafgaande boekjaren moeten verplicht worden voorzien van een boekstuknummer")."\n"); |
|
74
|
0
|
|
|
|
|
|
return; |
|
75
|
|
|
|
|
|
|
#$bsk_nr = $dbh->get_sequence("bsk_nr_0_seq"); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
else { |
|
78
|
0
|
|
|
|
|
|
$bsk_nr = $dbh->get_sequence("bsk_nr_".$opts->{dagboek}."_seq"); |
|
79
|
0
|
|
|
|
|
|
$opts->{boekstuk} = $bsk_nr; |
|
80
|
0
|
0
|
|
|
|
|
return unless $self->check_bsk_nr($opts); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
0
|
|
|
|
|
|
$bsk_nr; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub begindate { |
|
86
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $begin; |
|
89
|
|
|
|
|
|
|
my $end; |
|
90
|
0
|
0
|
|
|
|
|
if ( $self->{bky} ne $dbh->adm("bky") ) { |
|
|
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my ($b, $e, $c) = @{$dbh->do("SELECT bky_begin, bky_end, bky_closed". |
|
92
|
|
|
|
|
|
|
" FROM Boekjaren". |
|
93
|
0
|
|
|
|
|
|
" WHERE bky_code = ?", $self->{bky})}; |
|
94
|
0
|
0
|
|
|
|
|
if ( $c ) { |
|
95
|
|
|
|
|
|
|
warn("?".__x("Boekjaar {code} is gesloten, er kan niet meer in worden gewijzigd", |
|
96
|
0
|
|
|
|
|
|
code => $self->{bky})."\n"); |
|
97
|
0
|
|
|
|
|
|
return; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
0
|
|
|
|
|
|
$begin = $b; |
|
100
|
0
|
|
|
|
|
|
$end = $e; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
elsif ( $dbh->adm("closed") ) { |
|
103
|
0
|
|
|
|
|
|
warn("?"._T("De administratie is gesloten en kan niet meer worden gewijzigd")."\n"); |
|
104
|
0
|
|
|
|
|
|
return; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
0
|
|
0
|
|
|
|
$begin ||= $dbh->adm("begin"); |
|
107
|
0
|
0
|
|
|
|
|
return $begin unless wantarray; |
|
108
|
0
|
|
0
|
|
|
|
$end ||= $dbh->adm("end"); |
|
109
|
0
|
|
|
|
|
|
($begin, $end); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub in_bky { |
|
113
|
0
|
|
|
0
|
0
|
|
my ($self, $date, $begin, $end) = @_; |
|
114
|
0
|
0
|
|
|
|
|
if ( $date lt $begin ) { |
|
115
|
0
|
|
|
|
|
|
warn("?".__x("De boekingsdatum {date} valt vóór aanvang van dit boekjaar", |
|
116
|
|
|
|
|
|
|
date => datefmt_full($date))."\n"); |
|
117
|
0
|
|
|
|
|
|
return; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
0
|
0
|
|
|
|
|
if ( $date gt $end ) { |
|
120
|
0
|
|
|
|
|
|
warn("?".__x("De boekingsdatum {date} valt na het einde van dit boekjaar", |
|
121
|
|
|
|
|
|
|
date => datefmt_full($date))."\n"); |
|
122
|
0
|
|
|
|
|
|
return; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
0
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub amount_with_btw { |
|
128
|
0
|
|
|
0
|
0
|
|
my ($self, $amt, $btw_spec) = @_; |
|
129
|
0
|
|
|
|
|
|
my $explicit; |
|
130
|
0
|
0
|
|
|
|
|
if ( $amt =~ /^(.+)\@(.+)$/ ) { |
|
131
|
0
|
|
|
|
|
|
$amt = $1; |
|
132
|
0
|
|
|
|
|
|
$btw_spec = $2; |
|
133
|
0
|
|
|
|
|
|
$explicit = $btw_spec !~ /^[hlgn]?[-+]?[ko]?$/i; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
0
|
|
|
|
|
|
return (amount($amt), $btw_spec, $explicit); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub parse_btw_spec { |
|
139
|
0
|
|
|
0
|
0
|
|
my ($self, $spec, $btw_id, $kstomz) = @_; |
|
140
|
0
|
0
|
|
|
|
|
return (0, undef) unless defined($spec); |
|
141
|
0
|
|
|
|
|
|
$spec = lc($spec); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Quickie for G/N. |
|
144
|
0
|
0
|
0
|
|
|
|
if ( $spec =~ /^([gn])$/ ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
return (0, undef); |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
# Quickie for K/O. |
|
148
|
|
|
|
|
|
|
elsif ( $spec =~ /^([ko])$/ ) { |
|
149
|
0
|
|
|
|
|
|
return ($btw_id, $1 eq 'k'); |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
# Strip off trailing K|O. |
|
152
|
|
|
|
|
|
|
elsif ( $spec =~ /^([hl]|\d+)([-+]?)([ko])$/ || $spec =~ /^(\w+)([-+])([ko])$/ ) { |
|
153
|
0
|
|
|
|
|
|
$kstomz = $3 eq 'k'; |
|
154
|
0
|
|
|
|
|
|
$spec = $1.$2; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=begin deprecated |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# Deprecated since several years... |
|
160
|
|
|
|
|
|
|
elseif ( $spec =~ /^(.*)([iv])(.*)$/ ) { |
|
161
|
|
|
|
|
|
|
$kstomz = $2 eq 'i'; |
|
162
|
|
|
|
|
|
|
$spec = $1.$3; |
|
163
|
|
|
|
|
|
|
warn("!".__x("BTW specificatie {spec}: Gebruik K of O in plaats van I of V", |
|
164
|
|
|
|
|
|
|
spec => $_[0])."\n"); |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# Examine rest. Numeric -> BTW id. |
|
170
|
0
|
0
|
0
|
|
|
|
if ( $spec =~ /^(\d+)([-+])?$/ ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
$btw_id = $1; |
|
172
|
0
|
0
|
|
|
|
|
if ( defined $2 ) { |
|
173
|
0
|
|
|
|
|
|
my $excl = $2 eq '-'; |
|
174
|
0
|
|
|
|
|
|
my $res = $dbh->do("SELECT btw_perc, btw_tariefgroep FROM BTWTabel". |
|
175
|
|
|
|
|
|
|
" WHERE btw_id = ?", |
|
176
|
|
|
|
|
|
|
$btw_id); |
|
177
|
0
|
0
|
|
|
|
|
return unless $res; |
|
178
|
0
|
0
|
|
|
|
|
$res = $dbh->do("SELECT btw_id FROM BTWTabel". |
|
179
|
|
|
|
|
|
|
" WHERE btw_perc = ? AND btw_tariefgroep = ?". |
|
180
|
|
|
|
|
|
|
" AND ".($excl?"NOT ":"")."btw_incl", |
|
181
|
|
|
|
|
|
|
$res->[0], $res->[1]); |
|
182
|
0
|
0
|
|
|
|
|
return unless $res; |
|
183
|
0
|
|
|
|
|
|
$btw_id = $res->[0]; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
# H L H- L- H+ L+ |
|
187
|
|
|
|
|
|
|
elsif ( $spec =~ /^([hl])([-+])?$/ ) { |
|
188
|
0
|
|
|
|
|
|
$btw_id = $1; |
|
189
|
0
|
|
|
|
|
|
my $excl; |
|
190
|
0
|
0
|
|
|
|
|
$excl = $2 eq '-' if defined $2; |
|
191
|
0
|
0
|
|
|
|
|
my $res = $dbh->da("SELECT btw_id, btw_alias, btw_desc FROM BTWTabel". |
|
|
|
0
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
" WHERE btw_tariefgroep = ?". |
|
193
|
|
|
|
|
|
|
" AND ".($excl?"NOT ":"")."btw_incl". |
|
194
|
|
|
|
|
|
|
" ORDER BY btw_id ASC", |
|
195
|
|
|
|
|
|
|
$btw_id eq "h" ? BTWTARIEF_HOOG : BTWTARIEF_LAAG); |
|
196
|
|
|
|
|
|
|
warn("!".__x("BTW aanduiding \"{spec}\" kent meerdere tariefcodes: {list} (code {code} \"{desc}\" is gebruikt)", |
|
197
|
|
|
|
|
|
|
spec => $spec, |
|
198
|
0
|
0
|
|
|
|
|
list => join(" ", map { defined($_->[1]) ? $_->[1] : $_->[0] } @$res), |
|
|
0
|
0
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
code => $res->[0]->[0], |
|
200
|
|
|
|
|
|
|
desc => $res->[0]->[2], |
|
201
|
|
|
|
|
|
|
)."\n") if @$res != 1; |
|
202
|
0
|
|
|
|
|
|
$btw_id = $res->[0]->[0]; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
# alias |
|
205
|
|
|
|
|
|
|
elsif ( $spec =~ /^(\w\w+)([-+])?$/ ) { |
|
206
|
|
|
|
|
|
|
# warn("SPEC: $spec\n"); $dbh->trace(1); |
|
207
|
0
|
|
|
|
|
|
my $res = $dbh->do("SELECT btw_id, btw_perc, btw_tariefgroep FROM BTWTabel". |
|
208
|
|
|
|
|
|
|
" WHERE btw_alias = ?", |
|
209
|
|
|
|
|
|
|
lc $1); |
|
210
|
|
|
|
|
|
|
# $dbh->trace(0); |
|
211
|
0
|
0
|
|
|
|
|
return unless $res; |
|
212
|
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
$btw_id = $res->[0]; |
|
214
|
0
|
0
|
|
|
|
|
if ( defined $2 ) { |
|
215
|
0
|
|
|
|
|
|
my $excl = $2 eq '-'; |
|
216
|
|
|
|
|
|
|
# $dbh->trace(1); |
|
217
|
0
|
0
|
|
|
|
|
$res = $dbh->do("SELECT btw_id FROM BTWTabel". |
|
218
|
|
|
|
|
|
|
" WHERE btw_perc = ? AND btw_tariefgroep = ?". |
|
219
|
|
|
|
|
|
|
" AND ".($excl?"NOT ":"")."btw_incl", |
|
220
|
|
|
|
|
|
|
$res->[1], $res->[2]); |
|
221
|
|
|
|
|
|
|
# $dbh->trace(0); |
|
222
|
0
|
0
|
|
|
|
|
return unless $res; |
|
223
|
0
|
|
|
|
|
|
$btw_id = $res->[0]; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
# warn("SPEC: $spec => $btw_id\n"); |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
# + - |
|
228
|
|
|
|
|
|
|
elsif ( $spec =~ /^([-+])$/ && $btw_id ) { |
|
229
|
0
|
0
|
|
|
|
|
my $res = $dbh->da("SELECT btw_id, btw_desc FROM BTWTabel". |
|
230
|
|
|
|
|
|
|
" WHERE btw_tariefgroep =". |
|
231
|
|
|
|
|
|
|
" ( SELECT btw_tariefgroep FROM BTWTabel". |
|
232
|
|
|
|
|
|
|
" WHERE btw_id = ? )". |
|
233
|
|
|
|
|
|
|
" AND ".($1 eq '-'?"NOT ":"")."btw_incl", |
|
234
|
|
|
|
|
|
|
$btw_id); |
|
235
|
|
|
|
|
|
|
warn("!".__x("BTW aanduiding \"{spec}\" kent meerdere tariefcodes: {list} (code {code} \"{desc}\" is gebruikt)", |
|
236
|
|
|
|
|
|
|
spec => $spec, |
|
237
|
0
|
0
|
|
|
|
|
list => join(" ", map { $_->[0] } @$res), |
|
|
0
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
code => $res->[0]->[0], |
|
239
|
|
|
|
|
|
|
desc => $res->[0]->[1], |
|
240
|
|
|
|
|
|
|
)."\n") if @$res != 1; |
|
241
|
0
|
|
|
|
|
|
$btw_id = $res->[0]->[0]; |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
elsif ( $spec ne '' ) { |
|
244
|
0
|
|
|
|
|
|
return; |
|
245
|
|
|
|
|
|
|
} |
|
246
|
0
|
|
|
|
|
|
($btw_id, $kstomz); |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
#### Class method |
|
250
|
|
|
|
|
|
|
sub norm_btw { |
|
251
|
0
|
|
|
0
|
0
|
|
my ($self, $bsr_amt, $bsr_btw_id) = @_; |
|
252
|
0
|
|
|
|
|
|
my ($btw_perc, $btw_incl); |
|
253
|
0
|
0
|
|
|
|
|
if ( $bsr_btw_id ) { |
|
254
|
0
|
|
|
|
|
|
my $rr = $dbh->do("SELECT btw_perc, btw_incl, btw_tariefgroep". |
|
255
|
|
|
|
|
|
|
" FROM BTWTabel". |
|
256
|
|
|
|
|
|
|
" WHERE btw_id = ?", $bsr_btw_id); |
|
257
|
0
|
|
|
|
|
|
assert($rr, "Unk BTW: $bsr_btw_id"); |
|
258
|
0
|
|
|
|
|
|
($btw_perc, $btw_incl) = @$rr; |
|
259
|
|
|
|
|
|
|
} |
|
260
|
|
|
|
|
|
|
|
|
261
|
0
|
0
|
|
|
|
|
return [ $bsr_amt, 0 ] unless $btw_perc; |
|
262
|
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
|
my $bruto = $bsr_amt; |
|
264
|
0
|
|
|
|
|
|
my $netto = $bsr_amt; |
|
265
|
|
|
|
|
|
|
|
|
266
|
0
|
0
|
|
|
|
|
if ( $btw_incl ) { |
|
267
|
0
|
|
|
|
|
|
$netto = numround($bruto * (1 / (1 + $btw_perc/BTWSCALE))); |
|
268
|
|
|
|
|
|
|
} |
|
269
|
|
|
|
|
|
|
else { |
|
270
|
0
|
|
|
|
|
|
$bruto = numround($netto * (1 + $btw_perc/BTWSCALE)); |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
|
[ $bruto, $bruto - $netto, $btw_perc ]; |
|
274
|
|
|
|
|
|
|
} |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
#### Class method |
|
277
|
|
|
|
|
|
|
sub dcfromtd { |
|
278
|
|
|
|
|
|
|
# Calculate a (debet,credit) pair from a (total,debet) pair. |
|
279
|
0
|
|
|
0
|
0
|
|
my ($total, $debet) = @_; |
|
280
|
0
|
0
|
|
|
|
|
return ($debet, $debet-$total) if defined($debet); |
|
281
|
0
|
0
|
|
|
|
|
return ($total, 0) if $total >= 0; |
|
282
|
0
|
|
|
|
|
|
(0, -$total); |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
#### Class method |
|
286
|
|
|
|
|
|
|
sub journalise { |
|
287
|
0
|
|
|
0
|
0
|
|
my ($self, $bsk_id, $iv, $total) = @_; |
|
288
|
0
|
0
|
0
|
|
|
|
$total = -$total if defined($total) && !$iv; |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# date bsk_id bsr_seq(0) dbk_id (acc_id) amount debcrd desc(bsk) (rel) |
|
291
|
|
|
|
|
|
|
# date (bsk_id) bsr_seq(>0) (dbk_id) acc_id amount debcrd desc(bsr) rel(acc=1200/1600) |
|
292
|
0
|
|
|
|
|
|
my ($jnl_date, $jnl_bsk_id, $jnl_dbk_id, $jnl_acc_id, |
|
293
|
|
|
|
|
|
|
$jnl_amount, $jnl_desc, $jnl_rel); |
|
294
|
|
|
|
|
|
|
|
|
295
|
0
|
|
|
|
|
|
my $rr = $::dbh->do("SELECT bsk_nr, bsk_desc, bsk_dbk_id, bsk_date, bsk_ref". |
|
296
|
|
|
|
|
|
|
" FROM Boekstukken". |
|
297
|
|
|
|
|
|
|
" WHERE bsk_id = ?", $bsk_id); |
|
298
|
0
|
|
|
|
|
|
my ($bsk_nr, $bsk_desc, $bsk_dbk_id, $bsk_date, $bsk_ref) = @$rr; |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
my ($dbktype, $dbkdcsplit, $dbk_acc_id) = |
|
301
|
0
|
|
|
|
|
|
@{$::dbh->do("SELECT dbk_type, dbk_dcsplit, dbk_acc_id". |
|
|
0
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
" FROM Dagboeken". |
|
303
|
|
|
|
|
|
|
" WHERE dbk_id = ?", $bsk_dbk_id)}; |
|
304
|
0
|
|
|
|
|
|
my $sth = $::dbh->sql_exec("SELECT bsr_nr, bsr_date, ". |
|
305
|
|
|
|
|
|
|
"bsr_desc, bsr_amount, bsr_btw_class, bsr_btw_id, ". |
|
306
|
|
|
|
|
|
|
"bsr_btw_acc, bsr_type, bsr_acc_id, bsr_rel_code, bsr_dbk_id". |
|
307
|
|
|
|
|
|
|
" FROM Boekstukregels". |
|
308
|
|
|
|
|
|
|
" WHERE bsr_bsk_id = ?", $bsk_id); |
|
309
|
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
|
my $ret = []; |
|
311
|
0
|
|
|
|
|
|
my $tot = 0; |
|
312
|
0
|
|
|
|
|
|
my ($dtot, $ctot) = (0, 0); |
|
313
|
0
|
|
|
|
|
|
my ($vhtot, $vltot) = (0, 0); |
|
314
|
0
|
|
|
|
|
|
my $nr = 1; |
|
315
|
0
|
|
|
|
|
|
my $vat; # for automatic rounding VAT calc |
|
316
|
|
|
|
|
|
|
my $g_bsr_rel_code; |
|
317
|
|
|
|
|
|
|
|
|
318
|
0
|
|
|
|
|
|
while ( $rr = $sth->fetchrow_arrayref ) { |
|
319
|
0
|
|
|
|
|
|
my ($bsr_nr, $bsr_date, $bsr_desc, $bsr_amount, $bsr_btw_class, |
|
320
|
|
|
|
|
|
|
$bsr_btw_id, $bsr_btw_acc, $bsr_type, $bsr_acc_id, $bsr_rel_code, |
|
321
|
|
|
|
|
|
|
$bsr_rel_dbk) = @$rr; |
|
322
|
0
|
|
|
|
|
|
my $bsr_bsk_id = $bsk_id; |
|
323
|
0
|
|
|
|
|
|
my $btw = 0; |
|
324
|
0
|
|
|
|
|
|
my $amt = $bsr_amount; |
|
325
|
0
|
0
|
0
|
|
|
|
$g_bsr_rel_code = $bsr_rel_code if defined $iv && $bsr_rel_code; |
|
326
|
|
|
|
|
|
|
|
|
327
|
0
|
0
|
0
|
|
|
|
if ( ($bsr_btw_class & BTWKLASSE_BTW_BIT) && $bsr_btw_id && $bsr_btw_acc ) { |
|
|
|
|
0
|
|
|
|
|
|
328
|
|
|
|
|
|
|
( $bsr_amount, $btw, my $perc ) = |
|
329
|
0
|
|
|
|
|
|
@{$self->norm_btw($bsr_amount, $bsr_btw_id)}; |
|
|
0
|
|
|
|
|
|
|
|
330
|
0
|
|
|
|
|
|
$amt = $bsr_amount - $btw; |
|
331
|
0
|
|
|
|
|
|
$vat->{$bsr_btw_acc}->{amt} += $amt; |
|
332
|
0
|
|
|
|
|
|
$vat->{$bsr_btw_acc}->{btw} += $btw; |
|
333
|
0
|
|
|
|
|
|
$vat->{$bsr_btw_acc}->{prc} = $perc; |
|
334
|
|
|
|
|
|
|
} |
|
335
|
0
|
|
|
|
|
|
$tot += $bsr_amount; |
|
336
|
0
|
0
|
|
|
|
|
$dtot += $bsr_amount if $bsr_amount < 0; |
|
337
|
0
|
0
|
|
|
|
|
$ctot += $bsr_amount if $bsr_amount > 0; |
|
338
|
0
|
|
|
|
|
|
my $btwtag = _T("BTW "); |
|
339
|
0
|
0
|
|
|
|
|
push(@$ret, [$bsk_date, $bsk_dbk_id, $bsk_id, $bsr_date, $bsr_nr, $nr++, |
|
340
|
|
|
|
|
|
|
0, $bsr_acc_id, |
|
341
|
|
|
|
|
|
|
$bsr_amount - $btw, undef, $bsr_desc, |
|
342
|
|
|
|
|
|
|
$bsr_type ? ($bsr_rel_code, $bsr_rel_dbk) : (undef, undef), undef]); |
|
343
|
0
|
0
|
|
|
|
|
push(@$ret, [$bsk_date, $bsk_dbk_id, $bsk_id, $bsr_date, $bsr_nr, $nr++, |
|
344
|
|
|
|
|
|
|
1, $bsr_btw_acc, |
|
345
|
|
|
|
|
|
|
$btw, undef, $btwtag.$bsr_desc, |
|
346
|
|
|
|
|
|
|
undef, undef, undef]) if $btw; |
|
347
|
|
|
|
|
|
|
} |
|
348
|
|
|
|
|
|
|
|
|
349
|
0
|
0
|
0
|
|
|
|
if ( defined($total) && $tot != $total |
|
|
|
|
0
|
|
|
|
|
|
350
|
|
|
|
|
|
|
&& $cfg->val(qw(strategy iv_vc), 1) |
|
351
|
|
|
|
|
|
|
) { # mismatch! |
|
352
|
|
|
|
|
|
|
#warn("=> $tot <-> $total\n"); |
|
353
|
|
|
|
|
|
|
# Vaak het gevolg van verschil in BTW berekening per |
|
354
|
|
|
|
|
|
|
# boekingsregel versus per boekstuktotaal. |
|
355
|
|
|
|
|
|
|
|
|
356
|
0
|
|
|
|
|
|
while ( my($k,$v) = each(%$vat) ) { |
|
357
|
|
|
|
|
|
|
# Bereken BTW over totaal van deze tariefgroep. |
|
358
|
0
|
|
|
|
|
|
my $t = numround($v->{amt} * ($v->{prc}/BTWSCALE)); |
|
359
|
0
|
0
|
|
|
|
|
if ( $t != $v->{btw} ) { # Aha! |
|
360
|
|
|
|
|
|
|
#warn("=> [$k] $v->{btw} <-> $t\n"); |
|
361
|
|
|
|
|
|
|
# Corrigeer het totaal, en maak een correctieboekstukregel. |
|
362
|
0
|
|
|
|
|
|
$tot -= $v->{btw} - $t; |
|
363
|
|
|
|
|
|
|
push(@$ret, [$bsk_date, $bsk_dbk_id, $bsk_id, $bsk_date, undef, $nr++, |
|
364
|
|
|
|
|
|
|
1, $k, |
|
365
|
0
|
|
|
|
|
|
$t - $v->{btw}, undef, _T("BTW Afr. ").$bsk_desc, |
|
366
|
|
|
|
|
|
|
undef, undef, undef]); |
|
367
|
|
|
|
|
|
|
warn("!".__x("BTW rek. nr. {acct}, correctie van {amt} uitgevoerd", |
|
368
|
0
|
|
|
|
|
|
acct => $k, amt => numfmt($t-$v->{btw}))."\n"); |
|
369
|
|
|
|
|
|
|
} |
|
370
|
|
|
|
|
|
|
} |
|
371
|
|
|
|
|
|
|
} |
|
372
|
|
|
|
|
|
|
|
|
373
|
0
|
0
|
|
|
|
|
if ( $dbk_acc_id ) { |
|
374
|
0
|
0
|
|
|
|
|
if ( $dbkdcsplit ) { |
|
375
|
0
|
|
|
|
|
|
push(@$ret, [$bsk_date, $bsk_dbk_id, $bsk_id, $bsk_date, undef, $nr++, |
|
376
|
|
|
|
|
|
|
0, $dbk_acc_id, |
|
377
|
|
|
|
|
|
|
-$tot, -$dtot, $bsk_desc, undef, undef, undef]); |
|
378
|
|
|
|
|
|
|
} |
|
379
|
|
|
|
|
|
|
else { |
|
380
|
0
|
|
|
|
|
|
push(@$ret, [$bsk_date, $bsk_dbk_id, $bsk_id, $bsk_date, undef, $nr++, |
|
381
|
|
|
|
|
|
|
0, $dbk_acc_id, |
|
382
|
|
|
|
|
|
|
-$tot, undef, $bsk_desc, undef, undef, undef]); |
|
383
|
|
|
|
|
|
|
} |
|
384
|
|
|
|
|
|
|
} |
|
385
|
|
|
|
|
|
|
|
|
386
|
0
|
|
|
|
|
|
unshift(@$ret, [$bsk_date, $bsk_dbk_id, $bsk_id, $bsk_date, undef, 0, 0, undef, |
|
387
|
|
|
|
|
|
|
undef, undef, $bsk_desc, $g_bsr_rel_code, undef, $bsk_ref]); |
|
388
|
|
|
|
|
|
|
|
|
389
|
0
|
|
|
|
|
|
$ret; |
|
390
|
|
|
|
|
|
|
} |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
1; |