38 |
38 |
use Data::Dumper;
|
39 |
39 |
use SL::DBUtils;
|
40 |
40 |
|
|
41 |
use strict;
|
|
42 |
|
41 |
43 |
sub all_accounts {
|
42 |
44 |
$main::lxdebug->enter_sub();
|
43 |
45 |
|
44 |
46 |
my ($self, $myconfig, $form, $chart_id) = @_;
|
45 |
47 |
|
46 |
|
my %amount;
|
|
48 |
my (%amount, $acc_cash_where);
|
47 |
49 |
|
48 |
50 |
# connect to database
|
49 |
51 |
my $dbh = $form->dbconnect($myconfig);
|
... | ... | |
104 |
106 |
|
105 |
107 |
$form->{CA} = [];
|
106 |
108 |
|
107 |
|
while (my $ca = $sth->fetchrow_hashref(NAME_lc)) {
|
|
109 |
while (my $ca = $sth->fetchrow_hashref("NAME_lc")) {
|
108 |
110 |
$ca->{amount} = $amount{ $ca->{accno} };
|
109 |
111 |
if ($ca->{amount} < 0) {
|
110 |
112 |
$ca->{debit} = $ca->{amount} * -1;
|
... | ... | |
145 |
147 |
# $where .= " AND ac.transdate <= '$form->{todate}'";
|
146 |
148 |
# }
|
147 |
149 |
|
148 |
|
my (@values, @where_values, @subwhere_values);
|
|
150 |
my (@values, @where_values, @subwhere_values, $subwhere);
|
149 |
151 |
if ($form->{fromdate}) {
|
150 |
152 |
$where .= qq| AND ac.transdate >= ?|;
|
151 |
153 |
$subwhere .= qq| AND transdate >= ?|;
|
... | ... | |
163 |
165 |
|
164 |
166 |
my $sortorder = join ', ',
|
165 |
167 |
$form->sort_columns(qw(transdate reference description));
|
166 |
|
my $false = ($myconfig->{dbdriver} eq 'Pg') ? FALSE: q|'0'|;
|
|
168 |
my $false = ($myconfig->{dbdriver} eq 'Pg') ? "FALSE" : q|'0'|;
|
167 |
169 |
|
168 |
170 |
# Oracle workaround, use ordinal positions
|
169 |
171 |
my %ordinal = (transdate => 4,
|
... | ... | |
236 |
238 |
($form->{old_balance_credit}) = selectrow_query($form, $dbh, $query, $form->{fromdate}, $form->{fromdate}, $form->{accno});
|
237 |
239 |
|
238 |
240 |
# get current saldo
|
239 |
|
my $todate = ($form->{todate} ne "") ? " AND ac.transdate <= '$form->{todate}' " : "";
|
|
241 |
$todate = ($form->{todate} ne "") ? " AND ac.transdate <= '$form->{todate}' " : "";
|
240 |
242 |
$query = qq|SELECT sum(ac.amount) FROM acc_trans ac LEFT JOIN chart c ON (ac.chart_id = c.id) WHERE ((select date_trunc('year', ac.transdate::date)) >= (select date_trunc('year', ?::date))) $todate AND c.accno = ? AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL)|;
|
241 |
243 |
($form->{saldo_new}) = selectrow_query($form, $dbh, $query, $form->{fromdate}, $form->{accno});
|
242 |
244 |
|
243 |
245 |
#get current balance
|
244 |
|
my $todate = ($form->{todate} ne "") ? " AND ac.transdate <= '$form->{todate}' " : "";
|
|
246 |
$todate = ($form->{todate} ne "") ? " AND ac.transdate <= '$form->{todate}' " : "";
|
245 |
247 |
$query = qq|SELECT sum(ac.amount) FROM acc_trans ac LEFT JOIN chart c ON (ac.chart_id = c.id) WHERE ((select date_trunc('year', ac.transdate::date)) >= (select date_trunc('year', ?::date))) $todate AND c.accno = ? AND ac.amount < 0 AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL)|;
|
246 |
248 |
($form->{current_balance_debit}) = selectrow_query($form, $dbh, $query, $form->{fromdate}, $form->{accno});
|
247 |
249 |
|
248 |
|
my $todate = ($form->{todate} ne "") ? " AND ac.transdate <= '$form->{todate}' " : "";
|
|
250 |
$todate = ($form->{todate} ne "") ? " AND ac.transdate <= '$form->{todate}' " : "";
|
249 |
251 |
$query = qq|SELECT sum(ac.amount) FROM acc_trans ac LEFT JOIN chart c ON (ac.chart_id = c.id)WHERE ((select date_trunc('year', ac.transdate::date)) >= (select date_trunc('year', ?::date))) $todate AND c.accno = ? AND ac.amount > 0 AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL)|;
|
250 |
252 |
($form->{current_balance_credit}) = selectrow_query($form, $dbh, $query, $form->{fromdate}, $form->{accno});
|
251 |
253 |
}
|
... | ... | |
301 |
303 |
qq|WHERE | . $where . $dpt_where . $project .
|
302 |
304 |
qq| AND ac.chart_id = ? | .
|
303 |
305 |
qq| AND ac.trans_id = a.id | .
|
304 |
|
qq| AND a.vendor_id = v.id |;
|
|
306 |
qq| AND a.vendor_id = v.id | .
|
305 |
307 |
qq| AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL)| .
|
306 |
308 |
push(@values,
|
307 |
309 |
@where_values, @department_values, @project_values, $id,
|
... | ... | |
315 |
317 |
$fromdate_where =~ s/ac\./a\./;
|
316 |
318 |
$todate_where =~ s/ac\./a\./;
|
317 |
319 |
|
|
320 |
# strict check 20.10.2009 sschoeling
|
|
321 |
# the previous version contained the var $ar_ap_cash_where, which was ONLY set by
|
|
322 |
# RP->trial_balance() I tried to figure out which bizarre flow through the
|
|
323 |
# program would happen to set that var, so that it would be used here later on,
|
|
324 |
# (which would be nonsense, since you would normally load chart before
|
|
325 |
# claculating balance of said charts) and then decided that any mechanic that
|
|
326 |
# complex should fail anyway.
|
|
327 |
|
|
328 |
# if anyone is missing a time check on charts, that broke arounf the time
|
|
329 |
# trial_balance was rewritten, this would be it
|
|
330 |
|
318 |
331 |
$query .=
|
319 |
332 |
qq|UNION ALL | .
|
320 |
333 |
|
... | ... | |
331 |
344 |
$todate_where .
|
332 |
345 |
$dpt_where .
|
333 |
346 |
$project .
|
334 |
|
$ar_ap_cash_where .
|
335 |
347 |
qq|UNION ALL | .
|
336 |
348 |
|
337 |
349 |
qq|SELECT a.id, a.invnumber, v.name, a.transdate, | .
|
... | ... | |
346 |
358 |
$fromdate_where .
|
347 |
359 |
$todate_where .
|
348 |
360 |
$dpt_where .
|
349 |
|
$project .
|
350 |
|
$ar_ap_cash_where;
|
|
361 |
$project;
|
351 |
362 |
push(@values,
|
352 |
363 |
$id, @department_values, @project_values,
|
353 |
364 |
$id, @department_values, @project_values);
|
... | ... | |
363 |
374 |
my $sort = grep({ $form->{sort} eq $_ } qw(transdate reference description)) ? $form->{sort} : 'transdate';
|
364 |
375 |
|
365 |
376 |
$query .= qq|ORDER BY $sort|;
|
366 |
|
$sth = prepare_execute_query($form, $dbh, $query, @values);
|
|
377 |
my $sth = prepare_execute_query($form, $dbh, $query, @values);
|
367 |
378 |
|
368 |
379 |
#get detail information for each transaction
|
369 |
|
$trans_query =
|
|
380 |
my $trans_query =
|
370 |
381 |
qq|SELECT accno, | .
|
371 |
382 |
qq|amount, transdate FROM acc_trans LEFT JOIN chart ON (chart_id=chart.id) WHERE | .
|
372 |
383 |
qq|trans_id = ? AND sign(amount) <> sign(?) AND chart_id <> ? AND transdate = ?|;
|
373 |
384 |
my $trans_sth = $dbh->prepare($trans_query);
|
374 |
385 |
|
375 |
386 |
$form->{CA} = [];
|
376 |
|
while (my $ca = $sth->fetchrow_hashref(NAME_lc)) {
|
|
387 |
while (my $ca = $sth->fetchrow_hashref("NAME_lc")) {
|
377 |
388 |
# ap
|
378 |
389 |
if ($ca->{module} eq "ap") {
|
379 |
390 |
$ca->{module} = ($ca->{invoice}) ? 'ir' : 'ap';
|
... | ... | |
397 |
408 |
#get detail information for this transaction
|
398 |
409 |
$trans_sth->execute($ca->{id}, $ca->{amount}, $ca->{chart_id}, $ca->{transdate}) ||
|
399 |
410 |
$form->dberror($trans_query . " (" . join(", ", $ca->{id}) . ")");
|
400 |
|
while (my $trans = $trans_sth->fetchrow_hashref(NAME_lc)) {
|
|
411 |
while (my $trans = $trans_sth->fetchrow_hashref("NAME_lc")) {
|
401 |
412 |
if (($ca->{transdate} eq $trans->{transdate}) && ($ca->{amount} * $trans->{amount} < 0)) {
|
402 |
413 |
if ($trans->{amount} < 0) {
|
403 |
414 |
$trans->{debit} = $trans->{amount} * -1;
|
strictness für Menu und Ca