Refactoring von orphaned in AM get_account
[kivitendo-erp.git] / SL / AM.pm
index cbbfae0..b991acf 100644 (file)
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -55,11 +55,14 @@ 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{
     SELECT c.accno, c.description, c.charttype, c.category,
-      c.link, c.pos_bilanz, c.pos_eur, c.new_chart_id, c.valid_from,
+      c.link, c.pos_bilanz, c.pos_eur, c.pos_er, c.new_chart_id, c.valid_from,
       c.pos_bwa, datevautomatik,
       tk.taxkey_id, tk.pos_ustva, tk.tax_id,
       tk.tax_id || '--' || tk.taxkey_id AS tax, tk.startdate
@@ -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;
@@ -301,6 +297,7 @@ sub save_account {
                   pos_bwa   = ?,
                   pos_bilanz = ?,
                   pos_eur = ?,
+                  pos_er = ?,
                   new_chart_id = ?,
                   valid_from = ?,
                   datevautomatik = ?
@@ -315,6 +312,7 @@ sub save_account {
                   conv_i($form->{pos_bwa}),
                   conv_i($form->{pos_bilanz}),
                   conv_i($form->{pos_eur}),
+                  conv_i($form->{pos_er}),
                   conv_i($form->{new_chart_id}),
                   conv_date($form->{valid_from}),
                   ($form->{datevautomatik} eq 'T') ? 'true':'false',