class PComptaElement < ActiveRecord::Base
  belongs_to :p_customer
  belongs_to :element, :polymorphic => true
  before_save do
    
    
    
    if self.solde_ok?
      self.solde = true
    else
      self.solde = false
      
    end
    
    true
  end
  
  def solde_ok?
    if self.element
      if self.element_type == "PDocument"
        if self.element.paid
          return true
        else
          return false
        end
          
      elsif self.element_type == "PPayment"
        if self.element.reste_to_affect == 0.0 
          return true
        else
          return false
        end
      end
    else
      false
    end
  end
end
