class CustomersDraftsListsController < CommLogistics::Base::Controller::ListController
  def initialize
    @pdf_cls = CustomersDraftsPdf
    @pdf_sort_column = 'bill_date'
  end
  
  def get_record_list
    @control_keys = 'customers_drafts_lists'
    
    ss = CustomersDraftsSearch.new
    #ss.post_where_sentence = ' GROUP BY b.user_position_id '
    ss.date_table = 'r'
    #ss.non_table_columns = ['quantity', 'average_sales_price', 'total_sales_price']
    ss.table_alias = {'receiving_details' => 'rd',
                      'receivings' => 'r'}
    # sortテーブルの置き換えに使用
    join_mcls = [{:tab => 'receivings',
                  :cols => Receiving.column_names}]
    ars = ss.search(FLAG_ON, ReceivingDetail, join_mcls, params, MFIND_V)
    return ars
  end
  
  class CustomersDraftsSearch < Comm::Tool::SqlSearch
    def get_columns_and_tables(tab, join_lists, params, str_vals)
      str_cols = ' rd.receiving_id,
                   r.target_date,
                   r.customer_id,
                   rd.bill_date,
                   rd.bill_number,
                   rd.bank_id,
                   rd.amount,
                   r.note '
      str_tab =  ' FROM receiving_details AS rd LEFT JOIN receivings AS r ON rd.receiving_id=r.id '
      return str_cols, str_tab, str_vals
    end
    
    #空実装
    def set_target_date_to_where(tab, params, str_where)
    end
  
    def set_additional_where(str_where, params)
      add_str_where(str_where, " rd.bill_date>=\'#{params[:start_target_date]}\'")
      add_str_where(str_where, " r.state_code=#{MCODE_STATUS2_COMP}")
    end
  end
  
  # 受取手形一覧
  class CustomersDraftsPdf < CommLogistics::Modules::Print::Controller::PdfList
    def initialize(params, mcls=nil)
      @pdf_basename = 'customer_drafts_list'
      @paging_column = 'bill_date'
      @total_columns = ['amount']
      @total_title_column = 'bill_date'
      super
    end
  end
end