class Origami::CreditSalesController < BaseOrigamiController
  def show
    @cashier_type = 'cashier'
    @webview = false
    if check_mobile
      @webview = true  
    end
    
    @tables = Table.unscoped.all.active.order('status desc')
    @rooms = Room.unscoped.all.active.order('status desc')
    @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d'))
    @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
    @customers = Customer.pluck("customer_id, name")

    @sale = Sale.find_by_sale_id(params[:sale_id])
    @sale_payment = SalePayment.select("SUM(payment_amount) as payment_amount")
                  .where("sale_id = ? and payment_method=?", @sale.sale_id, "creditnote")
    
    @sale_taxes = []
    sale_taxes = SaleTax.where("sale_id = ?", @sale.sale_id)
    if !sale_taxes.empty?
      sale_taxes.each do |sale_tax|
        @sale_taxes.push(sale_tax)
      end
    end
  end
 
end
