# encoding: utf-8
class OrderStaticDetail < ActiveRecord::Base
  has_paper_trail
  self.table_name = "order_static_details"
  validates :begin_date,presence: true

  STATUS_ENUM = [["处理中,已完成,待收货",""],["未支付","unpay"],["已关闭","closed"],["待确认","unconfirmed"],["处理中","processing"],["已完成","complete"],["待收货","dispatch"],["已退款","refunded"]]
  def begin_date_fomat
    if !self.begin_date.nil?
      return self.begin_date.strftime
    end
  end
  def end_date_fomat
    if !self.end_date.nil?
      return self.end_date.strftime
    end
  end
  rails_admin do
    navigation_label '统计汇总'
    weight -500
    parent OrderStatic
    list do
      filters [:begin_date,:end_date, :state,:is_send]
      field :id
      field :begin_date_fomat
      field :end_date_fomat
      field :begin_date do
        visible false
      end
      field :end_date do
        visible false
      end
      field :state, :enum do
        enum do
          STATUS_ENUM
        end
      end
      field :product_id
      field :product_name
      field :nums
      field :total do
        visible true
        label "总金额(元)"
        formatted_value do
          value!=0 ? (value/100.0):0
        end
      end
      field :is_send
      field :created_at
      field :updated_at
    end

    show do
      field :id
      field :begin_date
      field :end_date
      field :state, :enum do
        enum do
          STATUS_ENUM
        end
      end
      field :product_id
      field :product_name
      field :nums
      field :total do
        visible true
        label "总金额(元)"
        formatted_value do
          value!=0 ? (value/100.0):0
        end
      end
      field :is_send
      field :created_at
      field :updated_at
    end

    edit do
      field :begin_date
      field :end_date
      field :state, :enum do
        enum do
          STATUS_ENUM
        end
      end
      field :product_id
      field :product_name
      field :nums
      field :total
      field :is_send
    end
  end

end
