module CommLogistics::Modules::MngAccounting
  include CommLogistics::Modules::MngReceivablePayable
  include CommLogistics::Modules::MngLedger
  
  def update_accounting(calc_type, details=nil)
    
    if (self.cutoff_type_code || 0) > 0 #都度払いと締め区分未設定の場合は実行しない。
      init_accounting(details)
      
      # 売掛/買掛の更新
      update_receivable_payable(calc_type) 
      
      # 得意先/仕入先元帳の更新
      update_ledger(calc_type) 
    end
    
    true
  end
  
  #送られてきたパラメータから消費税を計算するために必要なパラメータをセットする。
  #findしてマスターから取ってくるのではなく、パラメータからセットする。 edited by shimizu
  def get_req_total_duty_calc_weight(klass=@acnt_target_class, id=@acnt_target_id)
    # 請求書合計で、課税で、税抜き価格の場合。
    if self.respond_to?("duty_calc_type_code") && self.duty_calc_type_code == MCODE_CALC_DUTY_REQ_TOTAL && 
       self.respond_to?("duty_type_code") && self.duty_type_code == MCODE_DUTY_TYPE_CODE_ON && 
       self.respond_to?("price_duty_type_code") && self.price_duty_type_code == MCODE_PRICE_DUTY_TYPE_EXC
      calc_weight = {:duty_rate => self.duty_rate, :fraction_method_code=>self.fraction_method_code, :frac_digit_code => self.frac_digit_code}
    else
      calc_weight = nil
    end
    return calc_weight
  end
#  def get_req_total_duty_calc_weight(klass=@acnt_target_class, id=@acnt_target_id)
#    company_ar = klass.find(id)
#    if company_ar and company_ar.duty_calc_type_code == MCODE_CALC_DUTY_REQ_TOTAL
#      calc_weight = 0.01 * company_ar.duty_rate
#    else
#      calc_weight = nil
#    end
#    return calc_weight
#  end
end