#
#= customer_ledgers モデル
# Authors:: Sumiyo Yamamoto
# Copyright:: Copyright (C) OrbusNeich Medical K.K.  2010.
#--
# date        name                   note
# 2010.12.6   Sumiyo Yamamoto        新規登録
#-------------------------------------------------------------------------------
#++
class CustomerLedger < CommLogistics::Base::Model::Ledger
  has_many :child_details,
           :class_name => 'CustomerLedgerDetail',
           :dependent => :destroy
           
  def self.pre_search(target_id = nil, date = nil)
    result =  find(
      :all,
      :conditions => ["customer_id = ? AND target_date < ?", target_id, date],
      :order => "target_date DESC"
    ).first
    return result
  end

  def self.next_search(target_id = nil, date = nil)
   result = find(
      :all,
      :conditions => ["customer_id = ? AND target_date > ?", target_id, date],
      :order => "target_date ASC"
    ).first
    return result
  end
  
  named_scope :all_search, lambda {|target_id, date| {
    :conditions => ["customer_id = ? AND target_date = ?", target_id, date.to_s]
  }}
end
