From fea07b8edfb2b41496aa383e6df80d0f2139e57f Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Tue, 1 Mar 2016 15:23:46 +0100 Subject: [PATCH] SL::DB::Chart - Refactoring der Transaktionsmethoden MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ... der Methoden number_of_transactions und has_transaction. Machen fast das Gleiche, aber has_transaction liefert nur 0 oder 1 zurück, und ist schneller. --- SL/DB/Chart.pm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/SL/DB/Chart.pm b/SL/DB/Chart.pm index ee7ad6a69..0c8636c81 100644 --- a/SL/DB/Chart.pm +++ b/SL/DB/Chart.pm @@ -77,20 +77,15 @@ sub formatted_balance_dc { sub number_of_transactions { my ($self) = @_; - - my ($acc_trans) = $self->db->dbh->selectrow_array('select count(acc_trans_id) from acc_trans where chart_id = ?', {}, $self->id); - - return $acc_trans; + require SL::DB::AccTransaction; + return SL::DB::Manager::AccTransaction->get_all_count( where => [ chart_id => $self->id ] ); }; sub has_transaction { my ($self) = @_; - my ($id) = $self->db->dbh->selectrow_array('select acc_trans_id from acc_trans where chart_id = ? limit 1', {}, $self->id) || 0; - - $id ? return 1 : return 0; - -}; + $self->db->dbh->selectrow_array('select exists(select 1 from acc_trans where chart_id = ?)', {}, $self->id); +} sub displayable_name { my ($self) = @_; @@ -161,6 +156,10 @@ the asofdate as the current day, and the accounting_method "accrual". Returns a formatted version of C, taking the absolute value and adding the translated abbreviation for debit or credit after the number. +=item C + +Returns number of transactions that exist for this chart in acc_trans. + =item C Returns 1 or 0, depending whether the chart has a transaction in the database -- 2.20.1