From: G. Richardson Date: Tue, 1 Mar 2016 16:20:37 +0000 (+0100) Subject: Refactoring von orphaned in AM get_account X-Git-Tag: release-3.4.1~377 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ed71ba59d8acc23b8284eafc8f7d1c13070adbdd;p=kivitendo-erp.git Refactoring von orphaned in AM get_account --- 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;