X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAM.pm;h=f13fcc7eebbec2dac1e79c9f1aa05264675ec93e;hb=b47574cb2bdd79d3c172f67d94d3eada4bd3f981;hp=2cf6a43f14c07f0fc816fdc48a3ad517c32e398c;hpb=14d71a6d1215e4fc67136c060fd21cd6c59602af;p=kivitendo-erp.git diff --git a/SL/AM.pm b/SL/AM.pm index 2cf6a43f1..f13fcc7ee 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,29 +176,13 @@ 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; - if ($form->{new_chart_id}) { - $query = qq|SELECT current_date-valid_from FROM chart - WHERE id = ?|; - $main::lxdebug->message(LXDebug->QUERY(), "\$query=\n $query"); - my ($count) = selectrow_query($form, $dbh, $query, $form->{id}); - if ($count >=0) { - $form->{new_chart_valid} = 1; - } - $sth->finish; - } + # The old sql query was broken since at least 2006 and always returned 0 + $form->{new_chart_valid} = $chart_obj->new_chart_valid; $dbh->disconnect;