X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FRP.pm;h=47d7db9eed9a405aca31d1b7f7df15a7aea66bbc;hb=3171c37870f8d169128b81f35d9a597c03322f00;hp=358d71e34af756b4eaee9b35393e0e82824340f6;hpb=ab3f3ed87a12c70d9538b1a07fc0e4659dc43d28;p=kivitendo-erp.git diff --git a/SL/RP.pm b/SL/RP.pm index 358d71e34..47d7db9ee 100644 --- a/SL/RP.pm +++ b/SL/RP.pm @@ -884,7 +884,7 @@ sub trial_balance { my $glwhere = ''; my $glsumwhere = ''; my $tofrom; - my ($fromdate, $todate, $hotfix_query); + my ($fromdate, $todate, $fetch_accounts_before_from); if ($form->{fromdate} || $form->{todate}) { if ($form->{fromdate}) { @@ -923,10 +923,13 @@ sub trial_balance { $sumwhere .= $glsumwhere . " AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL) AND (NOT ac.cb_transaction OR ac.cb_transaction IS NULL)"; # get all entries before fromdate, which are not yet fetched - # TODO dpt_where_without_arapgl and project - $hotfix_query = qq|SELECT c.accno, c.description, c.category, SUM(ac.amount) AS amount + # TODO dpt_where_without_arapgl and project - project calculation seems bogus anyway + # TODO use fiscal_year_startdate for the whole trial balance + # anyway, if the last booking is in a deviating fiscal year, this already improves the query + my $fiscal_year_startdate = conv_dateq(get_balance_starting_date($form->{fromdate})); + $fetch_accounts_before_from = qq|SELECT c.accno, c.description, c.category, SUM(ac.amount) AS amount FROM acc_trans ac JOIN chart c ON (c.id = ac.chart_id) WHERE 1 = 1 AND (ac.transdate <= $fromdate) - AND (ac.transdate >= (SELECT date_trunc('YEAR', | . $fromdate . qq|::date))) + AND (ac.transdate >= $fiscal_year_startdate) AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL) AND (NOT ac.cb_transaction OR ac.cb_transaction IS NULL) AND c.accno NOT IN (SELECT c.accno FROM acc_trans ac JOIN chart c ON (c.id = ac.chart_id) WHERE 1 = 1 AND (ac.transdate >= $fromdate) AND (ac.transdate <= $todate) AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL) AND (NOT ac.cb_transaction OR ac.cb_transaction IS NULL)) @@ -988,8 +991,8 @@ sub trial_balance { } $sth->finish; - if (! $form->{method} eq "cash") { - $sth = prepare_execute_query($form, $dbh, $hotfix_query); + if (!$form->{method} ne "cash") { + $sth = prepare_execute_query($form, $dbh, $fetch_accounts_before_from); while ($ref = $sth->fetchrow_hashref("NAME_lc")) { $trb{ $ref->{accno} }{description} = $ref->{description}; $trb{ $ref->{accno} }{charttype} = 'A';