class Reports::CustomerController < BaseReportController
  authorize_resource :class => false
    def index
      @membership_type = Lookup.where(lookup_type: 'membership_type')
      from, to = get_date_range_from_params
      customer_filter = params[:customer]

      @shift_sale_range = ''

      @shift = ''
      if params[:shift_name].to_i != 0

        @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED)

        @shift_sale = ShiftSale.find(params[:shift_name])
        if to.blank?
          @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at)
        else
          if @shift_sale.shift_closed_at.blank?
            @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',@shift_sale.shift_started_at)
          else
            @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',@shift_sale.shift_started_at, @shift_sale.shift_closed_at)
          end
        end
      end

      @lookup = Lookup.find_by_lookup_type('reprint_receipt')
      if @lookup.nil?
        @lookup = Lookup.create_reprint_receipt_lookup
      end
      if params[:membership_type] == "0"
        membership_type = ''
      else
        membership_type = params[:membership_type]
      end
        @sale_data = Sale.get_shift_sales_by_customer(@shift_sale_range, @shift, from, to, membership_type, customer_filter)
        @sale_taxes = Sale.get_separate_tax_by_customer(@shift_sale_range, @shift, from, to, nil, customer_filter, membership_type)
        @tax_profiles = TaxProfile.group('name').order('order_by asc') #.limit(2)

        @from       = from
        @to         = to
        # get printer info
        @print_settings = PrintSetting.get_precision_delimiter()
        if @shift.present?
        @shift.each do |sh|
          @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.strftime("%e %b %I:%M%p")
          @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.strftime("%e %b %I:%M%p")
          @shift_data = sh
        end
      end

      respond_to do |format|
        format.html
        format.xls
      end
    end

  end
