From ed71ba59d8acc23b8284eafc8f7d1c13070adbdd Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Tue, 1 Mar 2016 17:20:37 +0100 Subject: [PATCH] Refactoring von orphaned in AM get_account --- SL/AM.pm | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/SL/AM.pm b/SL/AM.pm index 2cf6a43f1..b991acf39 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -55,6 +55,9 @@ sub get_account { my ($self, $myconfig, $form) = @_; + + my $chart_obj = SL::DB::Manager::Chart->find_by(id => $form->{id}) || die "Can't open chart"; + # connect to database my $dbh = $form->dbconnect($myconfig); my $query = qq{ @@ -173,16 +176,9 @@ sub get_account { $sth->finish; } - # check if we have any transactions - $query = qq|SELECT a.trans_id FROM acc_trans a - WHERE a.chart_id = ?|; - $main::lxdebug->message(LXDebug->QUERY(), "\$query=\n $query"); - $sth = $dbh->prepare($query); - $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})"); - ($form->{orphaned}) = $sth->fetchrow_array; - $form->{orphaned} = !$form->{orphaned}; - $sth->finish; + # check if there any transactions for this chart + $form->{orphaned} = $chart_obj->has_transaction ? 0 : 1; # check if new account is active $form->{new_chart_valid} = 0; -- 2.20.1