Vendor/Customer Name in FlattenToForm setzen
[kivitendo-erp.git] / SL / DB / Chart.pm
index ee7ad6a..d51332f 100644 (file)
@@ -77,20 +77,25 @@ 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;
+  $self->db->dbh->selectrow_array('select exists(select 1 from acc_trans where chart_id = ?)', {}, $self->id);
+}
 
-  $id ? return 1 : return 0;
+sub new_chart_valid {
+  my ($self) = @_;
 
-};
+  if ( $self->valid_from && DateTime->today >= $self->valid_from ) {
+    return 1;
+  } else {
+    return 0;
+  };
+}
 
 sub displayable_name {
   my ($self) = @_;
@@ -161,6 +166,10 @@ the asofdate as the current day, and the accounting_method "accrual".
 Returns a formatted version of C<get_balance>, taking the absolute value and
 adding the translated abbreviation for debit or credit after the number.
 
+=item C<number_of_transactions>
+
+Returns number of transactions that exist for this chart in acc_trans.
+
 =item C<has_transaction>
 
 Returns 1 or 0, depending whether the chart has a transaction in the database
@@ -171,6 +180,12 @@ or not.
 Returns the date of the last transaction of the chart in the database, which
 may lie in the future.
 
+=item C<new_chart_valid>
+
+Checks whether a follow-up chart is configured, and returns 1 or 0 depending on
+whether the valid_from date is before or after the current date.
+Is this even used anywhere?
+
 =back
 
 =head1 BUGS