class RestorationsController < CommLogistics::Base::Controller::SuperiorStock
  include Comm::Module::Controller::Logging
  include CommLogistics::Modules::Print::Controller
  include CommLogistics::Modules::Controller::ShowFilter
  include CommLogistics::Modules::Controller::ExtIndexFilter
  
  def initialize
    @mcls = Restoration
    @pdf_cls = RestorationPdfOut
  end
  
  class RestorationPdfOut < PdfBase
    def initialize(params, mcls=nil)
      @print_rec_num_per_sheet = 43
      @exists_extra_column = true
      @params = params
      super
    end
    
    #== 親レコード用
    def make_sheet_add_for_main(ar)
      @output_date ||= get_output_date
      {'output_date' => @output_date}
    end
    #== 子レコード用
    def make_sheet_add_for_detail(ar, detail_ar)
      @slip_total ||= 0
      @slip_total += detail_ar.quantity
      return {}
    end
    #== 1親レコード終了時の処理
    def make_sheet_on_change_parent(ar, pdata, page)
      current_page = page - 1
      detail_name = @mcls.name.underscore+'_detail'
      seq = pdata[current_page][detail_name].length
      #明細レコードが改ページピッタリの場合は次ページに回す
      if seq == @print_rec_num_per_sheet
        current_page = page
        seq = 0
        pdata[current_page][detail_name] ||= {}
      end
      pdata[current_page][detail_name][seq] = {'product_dn' => '伝票計', 'quantity' => @slip_total}
      @slip_total = 0
    end
  end
end