#
#== 繰越処理
#
class CommLogistics::Base::Model::AccountCarry < CommLogistics::Base::Model::Superior
  self.abstract_class = true
  include CommLogistics::Modules::MngAccounting

protected
  def create_exec_do(main, details)
    # メイン取引処理（id取得のため、最初に実施）
    self.attributes = main
    unless save
      raise EMJ0003 + EMD0004
    end
    
    # 買掛/売掛、仕入先/得意先元帳処理
#    if CommLogistics::Tools::Status.complete?(main[:state_code], :state_code)
#      update_accounting(CALC_ADD)
#    end
    update_account_info(main)
    true
  end
  
  def destroy_exec_do
    # 買掛/売掛、仕入先/得意先元帳処理
#    if CommLogistics::Tools::Status.complete?(self.state_code, :state_code)
#      update_accounting(CALC_SUB)
#    end
    update_account_info(self, nil, false)
  end
  
  def update_account_info(main, details=nil, is_create=true)
    state_code = get_value_by_name(main, 'state_code')
    if CommLogistics::Tools::Status.complete?(state_code, :state_code)
      calc_type = is_create ? CALC_ADD : CALC_SUB
      update_accounting(calc_type)
    end
  end
end
