class Reports::SaleitemController < BaseReportController authorize_resource :class => false def index @account = Account.all from, to = get_date_range_from_params 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 account_type = params[:account_type] @type = params[:sale_type] @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @account_cate_count = Hash.new {|hash, key| hash[key] = 0} @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} @sale_data.each {|cate| @menu_cate_count[cate.account_id] += 1} @totalByAccount = Hash.new {|hash, key| hash[key] = 0} @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} @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.utc.getlocal.strftime("%e %b %I:%M%p") @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") @shift_data = sh end end respond_to do |format| format.html format.xls end end def show from, to, report_type = get_date_range_from_params @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc shift_id = sale.id.nil? ? '-' : sale.id str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} date_arr.push(str) end # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} # @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} out = {:status => 'ok', :message => date_arr} respond_to do |format| format.json { render json: out } end end def print_sale_items type = params[:type] account = params[:account] from_date = to_date = '-' if !params[:from].nil? from_date = Date.parse(params[:from]) end if !params[:to].nil? to_date = Date.parse(params[:to]) end shift = params[:shift_name] shift_name = "All Shifts" if shift.to_i > 0 shift_name = params[:shift_from].to_s+" - ".to_s+params[:shift_to].to_s end period_name = get_period_name(params[:period]) shop_details = shop_detail # get printer info print_settings = PrintSetting.find_by_unique_code('CloseCashierPdf') # SaleItemsPdf printer = Printer::CashierStationPrinter.new(print_settings) printer.print_sale_items_report(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, params[:sale_items], params[:menu_cate_count]) respond_to do |format| format.html { redirect_to '/en/reports/saleitem/', notice: 'Printing Completed.'} format end end def get_period_name(period) period_name = '-' unless period.nil? or period.blank? case period.to_i when PERIOD["today"] period_name = "Today" when PERIOD["yesterday"] period_name = "Yesterday" when PERIOD["this_week"] period_name = "This Week" when PERIOD["last_week"] period_name = "Last Week" when PERIOD["last_7"] period_name = "Last 7 days" when PERIOD["this_month"] period_name = "This Month" when PERIOD["last_month"] period_name = "Last Month" when PERIOD["last_30"] period_name = "Last 30 Days" when PERIOD["this_year"] period_name = "This Year" when PERIOD["last_year"] period_name = "Last Year" end end return period_name end end