module Comm
  module BaseModel
    #支払方法を取得するためのメソッドをもつクラス
    #Customer / Supplierが継承する
    class PaymentMaster < PermanentMaster
      # 抽象クラス設定（対応するテーブルが存在しない）
      self.abstract_class = true
      #== 該当のcustomer/supplierの支払方法を取得する。
      #[target] Customer or Supplier
      #[id]  
      # * 戻り値
      #[payments]
      def self.get_payments(id) #receivables/payablesのcutoff_dateを
        ar = find(:first, :conditions => ["id = ?", id])
        payments = []
        cutoff_type_code = ar.cutoff_type_code #月一回締め...週締め...毎日締めなど
        #支払方法は3つまで
        [1,2,3].each do |i|
          payment_type_code = eval("ar.payment_type_#{i}_code") || 0
          if payment_type_code > 0 #支払方法が定義されていたら
            payment = {
             :cutoff_type_code => cutoff_type_code,
             :payment_condition_price => nil, 
             :payment_condition_code => nil, 
             :payment_condition_duty_type_code => nil,
             :payment_site => nil,
             :bill_site => nil
            }
            payment[:payment_condition_price] = eval("ar.payment_condition_#{i}_price") if i > 1
            payment[:payment_condition_code] = eval("ar.payment_condition_#{i}_code") if i > 1
            payment[:payment_condition_duty_type_code] = eval("ar.payment_condition_#{i}_duty_type_code") if i > 1
            payment[:payment_type_code] = payment_type_code
            payment[:payment_site] = eval("ar.payment_#{i}_site")
            payment[:bill_site] = eval("ar.bill_#{i}_site")
            payments.push(payment)
          end
        end
        return payments
      end
    end
  end
end
