X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FRP.pm;h=47d7db9eed9a405aca31d1b7f7df15a7aea66bbc;hb=0fe023a4ee7e467bfb5f23a87800b8723c8ccacd;hp=3d730265849d7c9b9255aa470f6397b065851263;hpb=5e2cb6ed074776434a00757503b29224e489804b;p=kivitendo-erp.git diff --git a/SL/RP.pm b/SL/RP.pm index 3d7302658..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); + my ($fromdate, $todate, $fetch_accounts_before_from); if ($form->{fromdate} || $form->{todate}) { if ($form->{fromdate}) { @@ -921,6 +921,19 @@ sub trial_balance { $where .= $tofrom . " AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL) AND (NOT ac.cb_transaction OR ac.cb_transaction IS NULL)"; $saldowhere .= $glsaldowhere . " AND (NOT ac.cb_transaction OR ac.cb_transaction IS NULL)"; $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 - 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 >= $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)) + GROUP BY c.accno, c.description, c.category ORDER BY accno|; } $query = qq| @@ -978,6 +991,17 @@ sub trial_balance { } $sth->finish; + 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'; + $trb{ $ref->{accno} }{category} = $ref->{category}; + $trb{ $ref->{accno} }{amount} += $ref->{amount}; + } + $sth->finish; + } + # prepare query for each account my ($q_drcr, $drcr, $q_project_drcr, $project_drcr);