class MOdrRemise < ApplicationRecord
  belongs_to :m_odr
  


  
  QI_DYNAMICS = %w(iban_from bic_from bank_name bank_subject)

  eval(QI_DYNAMICS_CORE)
    
  has_many :m_odr_virements, :dependent => :nullify
  
  def self.qi_table_order
    {
      :m_odr_name => "ODR",
      :created_at => {:name => "Date", :reorder => true},
      :state => {:name => "Etat", :reorder => true},
      :confirmed => {:name => "Confirmé ?", :reorder => true},
      :nbr_virements => "Nbr virements",
      :actions => "Actions",
     
    }
    
  end
  
  def self.valid_sort
    r = []
    self.qi_table_order.each do |key, value|
      if value.instance_of? Hash
        if value[:reorder] and value[:reorder] == true
          r << key.to_s if value[:reorder]
        end
      end
    end
    return r
    
    
  end
  
  def m_odr_name
    self.m_odr.name if self.m_odr
  end
  
  
  
  def nbr_virements
    self.m_odr_virements.count
  end
  
  def ca_iban_from 
    self.m_odr.iban if self.m_odr
  end
  
  def ca_bic_from 
   self.m_odr.bic if self.m_odr
  end
  
  def ca_bank_name
    self.m_odr.bank_name if self.m_odr
  end
  
  def ca_bank_subject
    self.m_odr.bank_subject if self.m_odr
  end
  
end
