From 25a8381681c995d16fa55cff9c1a4191e1795254 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Mon, 18 Jun 2018 16:05:54 +0630 Subject: [PATCH 1/2] Add Check in out pdf --- app/controllers/api/bill_controller.rb | 34 ++++++++ .../api/check_in_process_controller.rb | 34 ++++++++ .../origami/check_in_process_controller.rb | 33 +++++++ .../origami/request_bills_controller.rb | 39 ++++++++- app/models/printer/order_queue_printer.rb | 34 ++++++++ app/pdf/check_in_out_pdf.rb | 85 +++++++++++++++++++ 6 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 app/pdf/check_in_out_pdf.rb diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 8d8af8b2..4d60a2b6 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -31,6 +31,31 @@ class Api::BillController < Api::ApiController end end + if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + #bill channel + check_in_out_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all + unique_code="CheckInOutPdf" + if !check_in_out_pdf.empty? + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'CheckInOutPdf' + unique_code="CheckInOutPdf" + end + end + end + end + + booking = Booking.find_by_booking_id(booking.booking_id) + + # print when complete click + print_settings = PrintSetting.find_by_unique_code(unique_code) + order_queue_printer = Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_check_in_out(print_settings, booking, table) + + from = getCloudDomain #get sub domain in cloud mode + end + elsif (params[:order_id]) @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier) @@ -88,6 +113,15 @@ class Api::BillController < Api::ApiController # printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts, member_info, shop_details) end + #get cloud domain + def getCloudDomain + from = "" + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + end + + return from + end private def bill_params diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb index 492e345e..cf2767ef 100644 --- a/app/controllers/api/check_in_process_controller.rb +++ b/app/controllers/api/check_in_process_controller.rb @@ -81,6 +81,30 @@ class Api::CheckInProcessController < Api::ApiController else render :json => { :status => true } end + + if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + check_in_out_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all + unique_code="CheckInOutPdf" + if !check_in_out_pdf.empty? + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'CheckInOutPdf' + unique_code="CheckInOutPdf" + end + end + end + end + + booking = Booking.find_by_booking_id(booking.booking_id) + table = DiningFacility.find(params[:dining_id]) + + # print when complete click + print_settings = PrintSetting.find_by_unique_code(unique_code) + order_queue_printer = Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_check_in_out(print_settings, booking, table) + from = getCloudDomain #get sub domain in cloud mode + end else render :json => { :status => true } end @@ -121,6 +145,16 @@ class Api::CheckInProcessController < Api::ApiController end end + #get cloud domain + def getCloudDomain + from = "" + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + end + + return from + end + private def check_in_process_params params.permit(:dining_id,:booking_id,:time) diff --git a/app/controllers/origami/check_in_process_controller.rb b/app/controllers/origami/check_in_process_controller.rb index ad3efee0..d763aac1 100644 --- a/app/controllers/origami/check_in_process_controller.rb +++ b/app/controllers/origami/check_in_process_controller.rb @@ -29,6 +29,29 @@ class Origami::CheckInProcessController < BaseOrigamiController :checkin_by=>current_login_employee.name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign", :reserved_at => checkout_at, :reserved_by => current_login_employee.name }) @booking.save! end + + if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + check_in_out_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all + unique_code="CheckInOutPdf" + if !check_in_out_pdf.empty? + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'CheckInOutPdf' + unique_code="CheckInOutPdf" + end + end + end + end + booking = Booking.find_by_booking_id(@booking.booking_id) + table = DiningFacility.find(params[:dining_id]) + + # print when complete click + print_settings = PrintSetting.find_by_unique_code(unique_code) + order_queue_printer = Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_check_in_out(print_settings, booking, table) + from = getCloudDomain #get sub domain in cloud mode + end end respond = {:status => 'ok'} respond_to do |format| @@ -36,4 +59,14 @@ class Origami::CheckInProcessController < BaseOrigamiController end end + #get cloud domain + def getCloudDomain + from = "" + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + end + + return from + end + end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 3d2c90aa..a38f6408 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -38,16 +38,43 @@ class Origami::RequestBillsController < ApplicationController # Promotion Activation Promotion.promo_activate(@sale) + #bill channel if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain else from = "" end + ActionCable.server.broadcast "bill_channel",table: table, from: from if order.source == "quick_service" result = {:status=> @status, :data => @sale.sale_id } render :json => result.to_json + else + if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + #bill channel + check_in_out_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all + unique_code="CheckInOutPdf" + if !check_in_out_pdf.empty? + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'CheckInOutPdf' + unique_code="CheckInOutPdf" + end + end + end + end + + booking = Booking.find_by_booking_id(bk_order.booking_id) + + # print when complete click + print_settings = PrintSetting.find_by_unique_code(unique_code) + order_queue_printer = Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_check_in_out(print_settings, booking, table) + + from = getCloudDomain #get sub domain in cloud mode + end end else @status = false @@ -76,5 +103,15 @@ class Origami::RequestBillsController < ApplicationController # printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details) end - + + #get cloud domain + def getCloudDomain + from = "" + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + end + + return from + end + end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index e4eebc69..6c22d003 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -296,6 +296,40 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker left join menu_items as item ON item.item_code = order_items.item_code") .where("b.booking_id = '#{ id }'") end + end + # Check in-out time + def print_check_in_out(print_settings,booking, table) + #Use CUPS service + #Generate PDF + #Print + # Must be one print + if print_settings.print_copies == 0 + print_settings.print_copies = 1 + print_settings.save! + end + sale_id = booking.sale_id + filename = "tmp/check_in_out_#{sale_id}" + ".pdf" + + pdf = CheckInOutPdf.new(print_settings,booking, table) + print_setting = PrintSetting.all + + # if order_item[0].price != 0 + if !print_setting.empty? + print_setting.each do |print_settings| + if print_settings.unique_code == 'CheckInOutPdf' + pdf = CheckInOutPdf.new(print_settings,booking, table) + end + end + end + + pdf.render_file filename + + print_settings.print_copies = 1 + print_settings.save! + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, print_settings.printer_name) + end end end diff --git a/app/pdf/check_in_out_pdf.rb b/app/pdf/check_in_out_pdf.rb new file mode 100644 index 00000000..08b9eba8 --- /dev/null +++ b/app/pdf/check_in_out_pdf.rb @@ -0,0 +1,85 @@ +class CheckInOutPdf < Prawn::Document + include ActionView::Helpers::NumberHelper + attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size, :item_height,:qty_width,:total_width,:item_description_width + def initialize(print_settings,booking, table) + self.page_width = print_settings.page_width + self.page_height = print_settings.page_height + self.header_font_size = print_settings.header_font_size.to_i + self.item_font_size = print_settings.item_font_size.to_i + self.margin = 0 + self.price_width = 40 # No Need for item + self.qty_width = 40 + self.total_width = 40 # No Need for item + self.item_width = self.page_width - (self.qty_width - self.margin) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) + self.label_width=90 + self.order_no_font_size = 8 + + super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) + + # db font setup + if print_settings.font != "" + font_families.update("#{print_settings.font}" => { + :normal => "public/fonts/#{print_settings.font}.ttf", + :italic => "public/fonts/#{print_settings.font}.ttf", + :bold => "public/fonts/#{print_settings.font}.ttf", + :bold_italic => "public/fonts/#{print_settings.font}.ttf" + }) + + font "#{print_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + end + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" + + if table.type == "Table" + text "Table - #{table.name}", :size => self.header_font_size,:align => :center, :left_margin => -20 + elsif table.type == "Room" + text "Room - #{table.name}", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + + + stroke_horizontal_rule + move_down 3 + + #check_in_out_info + check_in_out_info(booking.checkin_by) + + # check_time + check_time(booking.checkin_at,booking.checkout_at) + end + + # Write Check in-out Information to PDF + def check_in_out_info(checkin_by) + + move_down 2 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "CheckBy : #{checkin_by} ", :size => self.order_no_font_size,:align => :left + end + + stroke_horizontal_rule + + move_down 5 + + end + + # Write Check time to PDF + def check_time(checkin_at, checkout_at) + + y_position = cursor + bounding_box([0,y_position], :width => self.item_width) do + text "Check In : #{checkin_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + end + + move_down 2 + + y_position = cursor + bounding_box([0,y_position], :width => self.item_width) do + text "Check Out : #{checkout_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + end + end +end From 234c00f1051ba6f0855af91d6fa755c561c1103a Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Mon, 18 Jun 2018 16:14:59 +0630 Subject: [PATCH 2/2] pull from master --- app/assets/javascripts/origami.js | 2 +- app/controllers/home_controller.rb | 21 +- .../origami/dashboard_controller.rb | 21 +- .../origami/in_duties_controller.rb | 96 +-- app/controllers/reports/induty_controller.rb | 66 +++ app/models/in_duty.rb | 30 + app/models/sale.rb | 545 ++++++------------ app/views/home/dashboard.html.erb | 26 +- app/views/layouts/_left_sidebar.html.erb | 3 + app/views/origami/cash_ins/new.html.erb | 2 +- app/views/origami/dashboard/index.html.erb | 18 +- app/views/origami/home/show.html.erb | 5 +- app/views/origami/in_duties/_form.html.erb | 14 +- .../origami/in_duties/assign_in_duty.html.erb | 6 +- .../origami/in_duties/index_in_duty.html.erb | 48 +- .../origami/moveroom/move_dining.html.erb | 8 +- .../origami/movetable/move_dining.html.erb | 8 +- .../pending_order/completed_sale.html.erb | 11 +- app/views/origami/sales/show.html.erb | 2 +- .../induty/_shift_sale_report_filter.html.erb | 127 ++++ app/views/reports/induty/index.html.erb | 181 ++++++ app/views/reports/induty/index.xls.erb | 55 ++ .../settings/set_menu_items/_form.html.erb | 22 +- .../settings/simple_menu_items/_form.html.erb | 21 +- config/locales/en.yml | 3 + config/locales/mm.yml | 3 + config/routes.rb | 13 +- 27 files changed, 810 insertions(+), 547 deletions(-) create mode 100644 app/controllers/reports/induty_controller.rb create mode 100755 app/views/reports/induty/_shift_sale_report_filter.html.erb create mode 100644 app/views/reports/induty/index.html.erb create mode 100755 app/views/reports/induty/index.xls.erb diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index c5e8c56b..f9550317 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -196,7 +196,7 @@ $(document).on('turbolinks:load', function() { $(document).on('click', '.access_modal', function(event){ type = $(this).data("type"); - $(".ok").attr("data-action",type) + $(".ok").attr("data-action",type); $('#AccessCodeModal').modal('show'); }); diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 325cb241..eb532898 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -110,8 +110,8 @@ class HomeController < ApplicationController else @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() end - @top_products = Sale.top_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty') - @bottom_products = Sale.bottom_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty') + @top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top").sum('i.qty') + @bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom").sum('i.qty') @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) @@ -119,17 +119,15 @@ class HomeController < ApplicationController .sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)') @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance) - @total_sale = Sale.total_sale(today,current_user,@from,@to,@from_time,@to_time) - @total_count = Sale.total_count(today,current_user,@from,@to,@from_time,@to_time) - @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time) - @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time) + @total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time) + @total_payment_trans = Sale.total_payment_trans(today,current_user,@from,@to,@from_time,@to_time) @sale_data = Array.new @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to,@from_time,@to_time) if !@total_payment_methods.nil? @total_payment_methods.each do |payment| - if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" || payment.payment_method == "paymal" || payment.payment_method == "dinga" || payment.payment_method == "JunctionPay" + if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time) @sale_data.push({'card' => pay.payment_amount}) else @@ -139,12 +137,9 @@ class HomeController < ApplicationController end end @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time) - @total_customer = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) - @total_dinein = Sale.total_dinein(today,current_user,@from,@to,@from_time,@to_time) - @total_takeaway = Sale.total_takeaway(today,current_user,@from,@to,@from_time,@to_time) - @total_other_customer = Sale.total_other_customer(today,current_user,@from,@to,@from_time,@to_time) - @total_membership = Sale.total_membership(today,current_user,@from,@to,@from_time,@to_time) - + @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) + # @total_other_customer = Sale.total_other_customer(today,current_user) + @total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time) @total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time) @account_data = Array.new diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index ab7bde82..af182356 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -3,8 +3,6 @@ class Origami::DashboardController < BaseOrigamiController def index @shop = Shop.first - - today = DateTime.now.strftime('%Y-%m-%d') # @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() # @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() @@ -18,16 +16,18 @@ class Origami::DashboardController < BaseOrigamiController # .sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)') # @inventories = StockJournal.inventory_balances(today).sum(:balance) - @total_sale = Sale.total_sale(today,current_user) - @total_count = Sale.total_count(today,current_user) - @total_card = Sale.total_card_sale(today,current_user) - @total_credit = Sale.credit_payment(today,current_user) + # @total_sale = Sale.total_sale(today,current_user) + # @total_count = Sale.total_count(today,current_user) + # @total_card = Sale.total_card_sale(today,current_user) + # @total_credit = Sale.credit_payment(today,current_user) + + @display_type = Lookup.find_by_lookup_type("display_type") @sale_data = Array.new @total_payment_methods = Sale.total_payment_methods(today,current_user) if !@total_payment_methods.nil? @total_payment_methods.each do |payment| - if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" + if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" pay = Sale.payment_sale('card', today, current_user) @sale_data.push({'card' => pay.payment_amount}) else @@ -39,11 +39,8 @@ class Origami::DashboardController < BaseOrigamiController @sale_data = nil end @summ_sale = Sale.summary_sale_receipt(today,current_user) - @total_customer = Sale.total_customer(today,current_user) - @total_dinein = Sale.total_dinein(today,current_user) - @total_takeaway = Sale.total_takeaway(today,current_user) - @total_other_customer = Sale.total_other_customer(today,current_user) - @total_membership = Sale.total_membership(today,current_user) + @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) + # @total_other_customer = Sale.total_other_customer(today,current_user) @total_order = Sale.total_order(today,current_user) @total_accounts = Sale.total_account(today,current_user) diff --git a/app/controllers/origami/in_duties_controller.rb b/app/controllers/origami/in_duties_controller.rb index 9846516e..7ac2d306 100755 --- a/app/controllers/origami/in_duties_controller.rb +++ b/app/controllers/origami/in_duties_controller.rb @@ -1,14 +1,12 @@ class Origami::InDutiesController < BaseOrigamiController before_action :set_in_duty, only: %i[show edit update edit_in_duty update_for_in_duty destroy destroy_in_duty] - # GET /in_duties - # GET /in_duties.json - def index - @in_duties = InDuty.all - end - + def index_in_duty - @duty_in = InDuty.where('dinning_id=?', params[:table_id]) - @table = DiningFacility.find(params[:table_id]) + @sale_id = params[:sale_id] + booking = Booking.where("sale_id=?",@sale_id).first + @booking_id = booking.booking_id + @duty_in = InDuty.where('dinning_id=? and sale_id=?', booking.dining_facility_id, @sale_id) + @table = DiningFacility.find(booking.dining_facility_id) @in_duty = InDuty.new @duties_in = Kaminari.paginate_array(@duty_in).page(params[:page]).per(10) end @@ -31,11 +29,14 @@ class Origami::InDutiesController < BaseOrigamiController def edit_in_duty @in_duty = InDuty.find(params[:id]) - @table = DiningFacility.find(params[:table_id]) + @sale_id = params[:sale_id] + booking = Booking.where("sale_id=?",@sale_id).first + @booking_id = booking.booking_id + @table = DiningFacility.find(booking.dining_facility_id) @commissioner = @in_duty.commissioner - # render json: {in_duty: @in_duty, commissioner: @commissioner} - render partial: 'form' + render json: {in_duty: @in_duty, commissioner: @commissioner} + # render partial: 'form' end def assign_in_duty @@ -45,20 +46,6 @@ class Origami::InDutiesController < BaseOrigamiController # POST /in_duties # POST /in_duties.json - def create - @in_duty = InDuty.new(in_duty_params) - - respond_to do |format| - if @in_duty.save - format.html { redirect_to origami_in_duties_path, notice: 'In duty was successfully created.' } - format.json { render :show, status: :created, location: @in_duty } - else - format.html { render :new } - format.json { render json: @in_duty.errors, status: :unprocessable_entity } - end - end - end - def create_for_in_duty # this one use for create and update in_duty = in_duty_params @@ -66,8 +53,8 @@ class Origami::InDutiesController < BaseOrigamiController # in_time = in_time.change(offset: '+06:30') # out_time = DateTime.new in_duty['out_time(1i)'].to_i, in_duty['out_time(2i)'].to_i, in_duty['out_time(3i)'].to_i, in_duty['out_time(4i)'].to_i, in_duty['out_time(5i)'].to_i # out_time = out_time.change(offset: '+06:30') - puts in_duty.to_json - puts "sssssssssssssssssss" + # puts in_duty.to_json + # puts "sssssssssssssssssss" @in_duty = InDuty.new in_duty_id = in_duty[:id] unless in_duty_id.empty? @@ -75,6 +62,8 @@ class Origami::InDutiesController < BaseOrigamiController end @in_duty.dinning_id = in_duty_params[:dinning_id] + @in_duty.booking_id = in_duty_params[:booking_id] + @in_duty.sale_id = in_duty_params[:sale_id] @in_duty.commissioner_ids = in_duty_params[:commissioner_ids] @in_duty.in_time = in_duty['in_time'] @in_duty.out_time = in_duty['out_time'] @@ -97,38 +86,18 @@ class Origami::InDutiesController < BaseOrigamiController # PATCH/PUT /in_duties/1 # PATCH/PUT /in_duties/1.json - def update - in_duty = in_duty_params - in_time = DateTime.new in_duty['in_time(1i)'].to_i, in_duty['in_time(2i)'].to_i, in_duty['in_time(3i)'].to_i, in_duty['in_time(4i)'].to_i, in_duty['in_time(5i)'].to_i - in_time = in_time.change(offset: '+06:30') - out_time = DateTime.new in_duty['out_time(1i)'].to_i, in_duty['out_time(2i)'].to_i, in_duty['out_time(3i)'].to_i, in_duty['out_time(4i)'].to_i, in_duty['out_time(5i)'].to_i - out_time = out_time.change(offset: '+06:30') - @in_duty.commissioner_ids = in_duty_params[:commissioner_ids] - @in_duty.in_time = in_time - @in_duty.out_time = out_time - respond_to do |format| - if @in_duty.save - format.html { redirect_to origami_index_in_duty_path(in_duty_params[:dinning_id]), notice: 'In duty was successfully updated.' } - format.json { render :show, status: :ok, location: @in_duty } - else - format.html { render :edit } - format.json { render json: @in_duty.errors, status: :unprocessable_entity } - end - end - end - def update_for_in_duty in_duty = in_duty_params - in_time = DateTime.new in_duty['in_time(1i)'].to_i, in_duty['in_time(2i)'].to_i, in_duty['in_time(3i)'].to_i, in_duty['in_time(4i)'].to_i, in_duty['in_time(5i)'].to_i - in_time = in_time.change(offset: '+06:30') - out_time = DateTime.new in_duty['out_time(1i)'].to_i, in_duty['out_time(2i)'].to_i, in_duty['out_time(3i)'].to_i, in_duty['out_time(4i)'].to_i, in_duty['out_time(5i)'].to_i - out_time = out_time.change(offset: '+06:30') + # in_time = DateTime.new in_duty['in_time(1i)'].to_i, in_duty['in_time(2i)'].to_i, in_duty['in_time(3i)'].to_i, in_duty['in_time(4i)'].to_i, in_duty['in_time(5i)'].to_i + # in_time = in_time.change(offset: '+06:30') + # out_time = DateTime.new in_duty['out_time(1i)'].to_i, in_duty['out_time(2i)'].to_i, in_duty['out_time(3i)'].to_i, in_duty['out_time(4i)'].to_i, in_duty['out_time(5i)'].to_i + # out_time = out_time.change(offset: '+06:30') @in_duty.commissioner_ids = in_duty_params[:commissioner_ids] - @in_duty.in_time = in_time - @in_duty.out_time = out_time + @in_duty.in_time = in_duty_params[:in_time] + @in_duty.out_time = in_duty_params[:out_time] respond_to do |format| if @in_duty.save - format.html { redirect_to origami_index_in_duty_path(in_duty_params[:dinning_id]), notice: 'In duty was successfully updated.' } + format.html { redirect_to origami_index_in_duty_path(in_duty_params[:sale_id]), notice: 'In duty was successfully updated.' } format.json { render :show, status: :ok, location: @in_duty } else format.html { render :edit } @@ -139,22 +108,15 @@ class Origami::InDutiesController < BaseOrigamiController # DELETE /in_duties/1 # DELETE /in_duties/1.json - def destroy - @in_duty.destroy - respond_to do |format| - format.html { redirect_to origami_in_duties_path, notice: 'In duty was successfully removed.' } - format.json { head :no_content } - end - end - def destroy_in_duty @table_id = params[:table_id] + @sale_id = params[:sale_id] + booking = Booking.where("sale_id=?",@sale_id).first + @booking_id = booking.booking_id @in_duty.destroy - respond_to do |format| - format.html { redirect_to origami_index_in_duty_path, notice: 'In duty was successfully removed.' } - format.json { head :no_content } - end + flash[:notice] = 'In duty was successfully destroyed.' + render :json => {:status=> "Success", :url => origami_index_in_duty_path }.to_json end private @@ -166,7 +128,7 @@ class Origami::InDutiesController < BaseOrigamiController # Never trust parameters from the scary internet, only allow the white list through. def in_duty_params - params.require(:in_duty).permit(:id, :dinning_id, :commissioner_ids, :in_time, :out_time) + params.require(:in_duty).permit(:id, :dinning_id, :booking_id, :sale_id, :commissioner_ids, :in_time, :out_time) end end diff --git a/app/controllers/reports/induty_controller.rb b/app/controllers/reports/induty_controller.rb new file mode 100644 index 00000000..f4bcc34f --- /dev/null +++ b/app/controllers/reports/induty_controller.rb @@ -0,0 +1,66 @@ +class Reports::IndutyController < BaseReportController + authorize_resource :class => false + def index + @commissioners = Commissioner.all #.where("is_active='1'") + + from, to = get_date_range_from_params + + @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + @shift = '' + if params[:shift_name].to_i != 0 + 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 + + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + + @commissioner = params[:commissioner] + @induty_data = InDuty.get_induty_by_shift(@shift_sale_range,@shift,from,to,@commissioner) + + @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 = get_date_range_from_params + + @induty_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + @commissioner = params[:commissioner] + + date_arr = Array.new + @induty_data.each do |induty| + local_opening_date = induty.opening_date.nil? ? '-' : induty.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = induty.closing_date.nil? ? '-' : induty.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = induty.opening_date.nil? ? '-' : induty.opening_date.utc + closing_date = induty.closing_date.nil? ? '-' : induty.closing_date.utc + shift_id = induty.id.nil? ? '-' : induty.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 + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end +end diff --git a/app/models/in_duty.rb b/app/models/in_duty.rb index 485787c7..9fbf67be 100755 --- a/app/models/in_duty.rb +++ b/app/models/in_duty.rb @@ -1,4 +1,34 @@ class InDuty < ApplicationRecord belongs_to :dining_facility, foreign_key: 'dinning_id' belongs_to :commissioner, foreign_key: 'commissioner_ids' + + def self.get_induty_by_shift(shift_sale_range,shift,from,to,commissioner) + ## => left join -> show all sales although no orders + if commissioner.blank? + commissioner = '' + else + if commissioner.present? + commissioner = " and CAST(in_duties.commissioner_ids AS SIGNED INTEGER) = #{commissioner}" + end + end + + query = InDuty.select("in_duties.*,sales.receipt_no, commissioners.name,dining_facilities.name as dining_name") + .joins(" LEFT JOIN commissioners on commissioners.id = CAST(in_duties.commissioner_ids AS SIGNED INTEGER)") + .joins(" LEFT JOIN dining_facilities on dining_facilities.id = in_duties.dinning_id") + .joins(" JOIN sales on sales.sale_id = in_duties.sale_id") + if shift.present? + query = query.where("sales.shift_sale_id in (?) #{commissioner} and sales.sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a) + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .group("sales.sale_id, in_duties.commissioner_ids") + elsif shift_sale_range.present? + query = query.where("sales.sale_status='completed' #{commissioner} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a) + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .group("sales.sale_id, in_duties.commissioner_ids") + else + query = query.where("sales.sale_status='completed' and sales.receipt_date between ? and ? #{commissioner} and sale_payments.payment_amount != 0",from,to) + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .group("sales.sale_id, in_duties.commissioner_ids") + end + return query + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 6c5ed5b6..9fec2ad3 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1256,7 +1256,7 @@ end return tax end - def self.top_products(today,current_user,from,to,from_time,to_time) + def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type) if !from.nil? && !to.nil? if current_user.nil? query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + @@ -1269,8 +1269,13 @@ end query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ " and sale_status= 'completed'") end - query = query.group('mi.name') + if type == "top" + query = query.group('mi.name') .order("SUM(i.qty) DESC").limit(20) + elsif type == "bottom" + query = query.group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + @@ -1283,8 +1288,13 @@ end query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ " and sale_status= 'completed'") end - query = query.group('mi.name') + if type == "top" + query = query.group('mi.name') .order("SUM(i.qty) DESC").limit(20) + elsif type == "bottom" + query = query.group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? @@ -1298,8 +1308,13 @@ end query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") end - query = query.group('mi.name') + if type == "top" + query = query.group('mi.name') .order("SUM(i.qty) DESC").limit(20) + elsif type == "bottom" + query = query.group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + end end end end @@ -1311,7 +1326,11 @@ end .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ " and sale_status= 'completed'") .group('mi.name') - .order("SUM(i.qty) DESC").limit(20) + if type == "top" + query = query.order("SUM(i.qty) DESC").limit(20) + elsif type == "bottom" + query = query.order("SUM(i.qty) ASC").limit(20) + end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + @@ -1320,7 +1339,11 @@ end .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ " and sale_status= 'completed'") .group('mi.name') - .order("SUM(i.qty) DESC").limit(20) + if type == "top" + query = query.order("SUM(i.qty) DESC").limit(20) + elsif type == "bottom" + query = query.order("SUM(i.qty) ASC").limit(20) + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? @@ -1330,88 +1353,11 @@ end .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") .group('mi.name') - .order("SUM(i.qty) DESC").limit(20) - end - end - end - end - end - - def self.bottom_products(today,current_user,from,to,from_time,to_time) - if !from.nil? && !to.nil? - if current_user.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,mi.name as product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") - if !from_time.nil? && !to_time.nil? - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") - else - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and sale_status= 'completed'") - end - query = query.group('mi.name') - .order("SUM(i.qty) ASC").limit(20) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,mi.name as product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") - if !from_time.nil? && !to_time.nil? - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") - else - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and sale_status= 'completed'") - end - query = query.group('mi.name') - .order("SUM(i.qty) ASC").limit(20) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,mi.name as product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") - if !from_time.nil? && !to_time.nil? - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and sale_status= 'completed' and shift_sale_id='#{shift.id}'") - else - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30') between '#{from}' and '#{to}'"+ - " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") - end - query = query.group('mi.name') - .order("SUM(i.qty) ASC").limit(20) - end - end - end - else - if current_user.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,mi.name as product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") - .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - "and sale_status= 'completed'") - .group('mi.name') - .order("SUM(i.qty) ASC").limit(20) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,mi.name as product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") - .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - "and sale_status= 'completed'") - .group('mi.name') - .order("SUM(i.qty) ASC").limit(20) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,mi.name as product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") - .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - " and sale_status= 'completed' and shift_sale_id=#{shift.id}") - .group('mi.name') - .order("SUM(i.qty) ASC").limit(20) + if type == "top" + query = query.order("SUM(i.qty) DESC").limit(20) + elsif type == "bottom" + query = query.order("SUM(i.qty) ASC").limit(20) + end end end end @@ -1544,207 +1490,102 @@ end end end - def self.total_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? if !from_time.nil? && !to_time.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time).sum("grand_total") + total = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count").where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) else - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to).sum("grand_total") + total = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count").where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time).sum("grand_total") + total = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count").where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) else - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to).sum("grand_total") + total = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count").where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? if !from_time.nil? && !to_time.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) - .sum("grand_total") + total = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count").where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) else - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) - .sum("grand_total") + total = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count").where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) end end end end else if current_user.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today).sum("grand_total") + total = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count").where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today).sum("grand_total") + total = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count").where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',today,today,shift.id) - .sum("grand_total") + total = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count").where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',today,today,shift.id) end end end end end - def self.total_count(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_payment_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? if !from_time.nil? && !to_time.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time).count + query = Sale.select('(CASE WHEN (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") THEN SUM(sp.payment_amount) ELSE 0 END) as total_card, (CASE WHEN (sp.payment_method="creditnote") THEN SUM(sp.payment_amount) ELSE 0 END) as total_credit') + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") else - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to).count + query = Sale.select('(CASE WHEN (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") THEN SUM(sp.payment_amount) ELSE 0 END) as total_card, (CASE WHEN (sp.payment_method="creditnote") THEN SUM(sp.payment_amount) ELSE 0 END) as total_credit') + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time).count + query = Sale.select('(CASE WHEN (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") THEN SUM(sp.payment_amount) ELSE 0 END) as total_card, (CASE WHEN (sp.payment_method="creditnote") THEN SUM(sp.payment_amount) ELSE 0 END) as total_credit') + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") else - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to).count + query = Sale.select('(CASE WHEN (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") THEN SUM(sp.payment_amount) ELSE 0 END) as total_card, (CASE WHEN (sp.payment_method="creditnote") THEN SUM(sp.payment_amount) ELSE 0 END) as total_credit') + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? if !from_time.nil? && !to_time.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and shift_sale_id = ?',from,to,from_time,to_time,shift.id).count + query = Sale.select('(CASE WHEN (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") THEN SUM(sp.payment_amount) ELSE 0 END) as total_card, (CASE WHEN (sp.payment_method="creditnote") THEN SUM(sp.payment_amount) ELSE 0 END) as total_credit') + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") else - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id = ?',from,to,shift.id).count + query = Sale.select('(CASE WHEN (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") THEN SUM(sp.payment_amount) ELSE 0 END) as total_card, (CASE WHEN (sp.payment_method="creditnote") THEN SUM(sp.payment_amount) ELSE 0 END) as total_credit') + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") end end end end else if current_user.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',today,today).count + query = Sale.select('(CASE WHEN (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") THEN SUM(sp.payment_amount) ELSE 0 END) as total_card, (CASE WHEN (sp.payment_method="creditnote") THEN SUM(sp.payment_amount) ELSE 0 END) as total_credit') + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',today,today).count + query = Sale.select('(CASE WHEN (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") THEN SUM(sp.payment_amount) ELSE 0 END) as total_card, (CASE WHEN (sp.payment_method="creditnote") THEN SUM(sp.payment_amount) ELSE 0 END) as total_credit') + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id = ?',today,today,shift.id).count - end - end - end - end - end - - def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - if !from.nil? && !to.nil? - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time) + query = Sale.select('(CASE WHEN (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") THEN SUM(sp.payment_amount) ELSE 0 END) as total_card, (CASE WHEN (sp.payment_method="creditnote") THEN SUM(sp.payment_amount) ELSE 0 END) as total_credit') + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',today,today,shift.id) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - else - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - if !from_time.nil? && !to_time.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - else - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and shift_sale_id=?',from,to,from_time,to_time,shift.id) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - else - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and shift_sale_id=?',from,to,shift.id) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - end - end - end - end - else - if current_user.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',today,today) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',today,today) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and shift_sale_id=?',today,today,shift.id) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - end - end - end - end - end - - def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - if !from.nil? && !to.nil? - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - else - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - if !from_time.nil? && !to_time.nil? - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - else - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - else - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',from,to,shift.id) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - end - end - end - end - else - if current_user.nil? - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',today,today,shift.id) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") end end end @@ -1972,57 +1813,62 @@ end end def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - dinein_cnt = self.total_dinein(today,current_user,from,to,from_time,to_time) - takeaway_cnt = self.total_takeaway(today,current_user,from,to,from_time,to_time) + total_dinein_takeaway = self.total_dinein_takeaway(today,current_user,from,to,from_time,to_time) + dinein_cnt = 0 + takeaway_cnt = 0 + if !total_dinein_takeaway[0].nil? + dinein_cnt = total_dinein_takeaway[0].total_dinein_cus + takeaway_cnt = total_dinein_takeaway[0].total_take_cus + end membership_cnt = self.total_membership(today,current_user,from,to,from_time,to_time) total_cus = 0 if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil? - total_cus = dinein_cnt.total_dinein_cus.to_int + takeaway_cnt.total_take_cus.to_int + membership_cnt.total_memb_cus.to_int + total_cus = dinein_cnt.to_int + takeaway_cnt.to_int + membership_cnt.total_memb_cus.to_int end - return total_cus + return total_cus, dinein_cnt, takeaway_cnt, membership_cnt.total_memb_cus end - def self.total_dinein(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_dinein_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? if !from_time.nil? && !to_time.nil? - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to,from_time,to_time) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.membership_id is null',from,to,from_time,to_time) .first() else - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.membership_id is null',from,to) .first() end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to,from_time,to_time) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.membership_id is null',from,to,from_time,to_time) .first() else - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.membership_id is null',from,to) .first() end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? if !from_time.nil? && !to_time.nil? - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) .first() else - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) .first() end end @@ -2030,22 +1876,22 @@ end end else if current_user.nil? - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.membership_id is null',today) .first() else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.membership_id is null',today) .first() else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) .first() end end @@ -2053,75 +1899,6 @@ end end end - def self.total_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - if !from.nil? && !to.nil? - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZsales.receipt_date,"%H:%i") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to,from_time,to_time) - .first() - else - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) - .first() - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - if !from_time.nil? && !to_time.nil? - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to,from_time,to_time) - .first() - else - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) - .first() - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - .first() - else - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) - .first() - end - end - end - end - else - if current_user.nil? - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) - .first() - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) - .first() - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) - .first() - end - end - end - end - end - def self.total_membership(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? @@ -2187,68 +1964,68 @@ end end end - def self.total_other_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - if !from.nil? && !to.nil? - if current_user.nil? - query = Sale.select("count(sales.customer_id) as total_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - if !from_time.nil? && !to_time.nil? - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) - .first() - else - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to) - .first() - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = Sale.select("count(sales.customer_id) as total_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - if !from_time.nil? && !to_time.nil? - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) - .first() - else - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to) - .first() - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.select("count(sales.customer_id) as total_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - if !from_time.nil? && !to_time.nil? - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - .first() - else - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) - .first() - end - end - end - end - else - if current_user.nil? - query = Sale.select("count(sales.customer_id) as total_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) - .first() - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = Sale.select("count(sales.customer_id) as total_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) - .first() - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.select("count(sales.customer_id) as total_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) - .first() - end - end - end - end - end + # def self.total_other_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + # if !from.nil? && !to.nil? + # if current_user.nil? + # query = Sale.select("count(sales.customer_id) as total_cus") + # .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + # if !from_time.nil? && !to_time.nil? + # query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) + # .first() + # else + # query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to) + # .first() + # end + # else + # if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' + # query = Sale.select("count(sales.customer_id) as total_cus") + # .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + # if !from_time.nil? && !to_time.nil? + # query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) + # .first() + # else + # query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to) + # .first() + # end + # else + # shift = ShiftSale.current_open_shift(current_user.id) + # if !shift.nil? + # query = Sale.select("count(sales.customer_id) as total_cus") + # .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + # if !from_time.nil? && !to_time.nil? + # query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + # .first() + # else + # query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) + # .first() + # end + # end + # end + # end + # else + # if current_user.nil? + # query = Sale.select("count(sales.customer_id) as total_cus") + # .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + # .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) + # .first() + # else + # if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' + # query = Sale.select("count(sales.customer_id) as total_cus") + # .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + # .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) + # .first() + # else + # shift = ShiftSale.current_open_shift(current_user.id) + # if !shift.nil? + # query = Sale.select("count(sales.customer_id) as total_cus") + # .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + # .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + # .first() + # end + # end + # end + # end + # end def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 6131e656..a4b64cce 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -24,7 +24,9 @@
<%= t :sale_count %>
-
+ <% if !@total_trans[0].nil? %> +
+ <% end %>
@@ -35,7 +37,9 @@
<%= t :total_sale %>
-
+ <% if !@total_trans[0].nil? %> +
+ <% end %>
@@ -47,7 +51,9 @@
<%= t :total_credit %>
-
+ <% if !@total_payment_trans[0].nil? %> +
+ <% end %>
@@ -58,7 +64,9 @@
<%= t :total_card %>
-
+ <% if !@total_payment_trans[0].nil? %> +
+ <% end %>
@@ -272,25 +280,25 @@ <% if !@total_dinein.nil? %> <%= t("views.right_panel.detail.dine_in") %> : - <%= @total_dinein.total_dinein_cus %> + <%= @total_dinein %> <% end %> <% if !@total_takeaway.nil? %> <%= t("views.right_panel.detail.takeaway") %> : - <%= @total_takeaway.total_take_cus %> + <%= @total_takeaway %> <% end %> - <% if !@total_other_customer.nil? %> + <% if !@total_membership.nil? %> <%= t("views.right_panel.detail.membership") %> : - <%= @total_membership.total_memb_cus %> + <%= @total_membership %> <% end %> diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 4862acfe..f83284ae 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -161,6 +161,9 @@
  • Commission
  • +
  • + Induty +
  • Stock Check
  • diff --git a/app/views/origami/cash_ins/new.html.erb b/app/views/origami/cash_ins/new.html.erb index 0b27a62f..1297249b 100755 --- a/app/views/origami/cash_ins/new.html.erb +++ b/app/views/origami/cash_ins/new.html.erb @@ -61,7 +61,7 @@ var payment_method = ""; $('.payment-type').on('click',function(){ - $('.payment-type').css("background-color","#7a62d3") + $('.payment-type').css("background-color","#7a62d3"); $(this).css("background-color","green"); var type = $(this).attr('data-id') if(type == 'cash'){ diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 4b7c6f2c..87220f83 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -137,25 +137,25 @@ <% if !@total_dinein.nil? %> <%= t("views.right_panel.detail.dine_in") %> : - <%= @total_dinein.total_dinein_cus %> + <%= @total_dinein %> <% end %> <% if !@total_takeaway.nil? %> <%= t("views.right_panel.detail.takeaway") %> : - <%= @total_takeaway.total_take_cus %> + <%= @total_takeaway %> <% end %> - <% if !@total_other_customer.nil? %> + <% if !@total_membership.nil? %> <%= t("views.right_panel.detail.membership") %> : - <%= @total_membership.total_memb_cus %> + <%= @total_membership %> <% end %> @@ -219,7 +219,13 @@ $(function() { }); $(".qs_view").on('click', function() { - if ($('#server_mode').val() != "cloud") { + var display_type = '<%= @display_type %>'; + if (display_type.length>0) { + display_type = '<%= @display_type %>'; + }else{ + display_type = null; + } + if ($('#server_mode').val() != "cloud" && display_type == 2) { document.getElementById('second_view').click(); } window.location.href = '/origami/quick_service'; diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 1552d872..58ba3838 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -991,8 +991,9 @@ }); $('#in_duties').on('click', function () { - var dining_id = "<%= @dining.id %>" - window.location.href = '/origami/assign_in_duty/'+ dining_id; + var dining_id = "<%= @dining.id %>"; + var sale_id = "<%= @obj_sale.sale_id rescue "" %>"; + window.location.href = '/origami/assign_in_duty/'+ sale_id; }); $('#void').on('click', function () { diff --git a/app/views/origami/in_duties/_form.html.erb b/app/views/origami/in_duties/_form.html.erb index 07cee2cf..800e356a 100755 --- a/app/views/origami/in_duties/_form.html.erb +++ b/app/views/origami/in_duties/_form.html.erb @@ -5,6 +5,8 @@ <%= f.error_notification %> <%= f.hidden_field :id, :class => "form-control col-md-6 " %> + <%= f.hidden_field :booking_id, :value => @booking_id %> + <%= f.hidden_field :sale_id, :value => @sale_id %>
    <%= f.hidden_field :dinning_id, :value => @table.id, :class => "form-control col-md-4 " %> @@ -21,9 +23,9 @@ date_range <% if !@in_duty.in_time.nil?%> - + <% else %> - + <% end %>
    @@ -34,19 +36,19 @@ date_range <% if !@in_duty.out_time.nil?%> - + <% else %> - + <% end %>
    -
    +
    <%= f.submit "Create In Duty", :class => 'btn bg-blue' %>
    diff --git a/app/views/origami/in_duties/assign_in_duty.html.erb b/app/views/origami/in_duties/assign_in_duty.html.erb index f24b16d9..8a4b24c8 100755 --- a/app/views/origami/in_duties/assign_in_duty.html.erb +++ b/app/views/origami/in_duties/assign_in_duty.html.erb @@ -53,11 +53,13 @@ $(function() { var commissioner_ids = $('#in_duty_commissioner_ids').val(); var in_time = $('#in_duty_in_time').val(); var out_time = $('#in_duty_out_time').val(); - var dining_id = '<%= @table.id %>' + var dining_id = '<%= @table.id %>'; + var sale_id = '<%= @sale_id %>'; + var booking_id = '<%= @booking_id %>'; $.ajax({ type: "POST", url: ajax_url, - data: 'dining_id=' + dining_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time, + data: 'dining_id=' + dining_id + "sale_id=" + sale_id + "booking_id=" + booking_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time, success: function (result) { window.location.href = '/origami/assign_in_duty/'+ dining_id; } diff --git a/app/views/origami/in_duties/index_in_duty.html.erb b/app/views/origami/in_duties/index_in_duty.html.erb index 72fcff96..16a8a03f 100755 --- a/app/views/origami/in_duties/index_in_duty.html.erb +++ b/app/views/origami/in_duties/index_in_duty.html.erb @@ -32,7 +32,7 @@ <%= in_duty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> <%= in_duty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> - @@ -68,7 +68,8 @@ var in_duty_id = $(this).attr('data-ref'); var table_id = "<%= @table.id %>"; - var url = "/origami/assign_in_duty/table/" + table_id + "/in_duty/" + in_duty_id + "/edit"; + var sale_id = "<%= @sale_id %>"; + var url = "/origami/assign_in_duty/table/" + sale_id + "/in_duty/" + in_duty_id + "/edit"; $.ajax({ type: "GET", @@ -76,25 +77,30 @@ data: {}, success: function (data) { - debugger; - $('.partial').empty().append(data); -// $('#in_duty_id').val(data.in_duty.id); -// $('#in_duty_commissioner_ids').val(data.commissioner.id); -// $('#in_duty_in_time').val(data.in_duty.in_time); -// $('#in_duty_out_time').val(data.in_duty.out_time); -// -// $('#update').removeAttr('disabled').val(''); -// $('#update').attr('value', 'Update'); -// $('#create').attr('disabled', 'disabled'); -// -// $("#new_in_duty").attr('class', 'simple_form edit_in_duty'); -// var id = "edit_in_duty_" + in_duty_id; -// $("#new_in_duty").attr('id', id); -// -// $(".edit_in_duty").attr('id', id); -// $(".edit_in_duty").attr('action', '/origami/edit_in_duty/' + $('#in_duty_id').val()); -// $(".edit_in_duty").attr('action', '/origami/edit_in_duty/' + $('#in_duty_id').val()); -// $(".patch_method").html(''); + // debugger; + // $('.partial').empty().append(data); + var inT = new Date(data.in_duty.in_time); + var in_time = ((inT.getDate() >= 10 ? inT.getDate() : '0'+inT.getDate()) +"-"+ (inT.getMonth() >= 10 ? inT.getMonth() : '0'+inT.getMonth()) +"-"+ inT.getFullYear() +" - "+ (inT.getHours()>10? inT.getHours() : '0'+inT.getHours()) +":"+ (inT.getMinutes() >= 10? inT.getMinutes() : '0'+inT.getMinutes())); + var outT = new Date(data.in_duty.out_time); + var out_time = ((outT.getDate() >= 10? outT.getDate() : '0'+outT.getDate()) +"-"+ (outT.getMonth() >= 10 ? outT.getMonth() : '0'+outT.getMonth()) +"-"+ outT.getFullYear() +" - "+ (outT.getHours()>10? outT.getHours() : '0'+outT.getHours()) +":"+ (outT.getMinutes() >= 10? outT.getMinutes() : '0'+outT.getMinutes())); + + $('#in_duty_id').val(data.in_duty.id); + $('#in_duty_commissioner_ids').val(data.commissioner.id); + $('#in_duty_in_time').val(in_time); + $('#in_duty_out_time').val(out_time); + + // $('#update').removeAttr('disabled').val(''); + // $('#update').attr('value', 'Update'); + // $('#create').attr('disabled', 'disabled'); + + $("#new_in_duty").attr('class', 'simple_form edit_in_duty'); + var id = "edit_in_duty_" + data.in_duty.id; + $("#new_in_duty").attr('id', data.in_duty.id); + + $(".edit_in_duty").attr('id', data.in_duty.id); + $(".edit_in_duty").attr('action', '/origami/edit_in_duty/' + $('#in_duty_id').val()); + $(".edit_in_duty").attr('action', '/origami/edit_in_duty/' + $('#in_duty_id').val()); + $(".patch_method").html(''); // setInterval(function () { // $('.partial').load('/controller_name/action_name'); diff --git a/app/views/origami/moveroom/move_dining.html.erb b/app/views/origami/moveroom/move_dining.html.erb index 84ad9da9..20080feb 100755 --- a/app/views/origami/moveroom/move_dining.html.erb +++ b/app/views/origami/moveroom/move_dining.html.erb @@ -27,7 +27,7 @@ <% if table.get_checkout_booking.nil? %>
    <% else %> -
    +
    <% end %>
    <%= table.name %> @@ -35,9 +35,9 @@
    <% else %> <% if table.get_checkout_booking.nil? %> -
    +
    <% else %> -
    +
    <% end %>
    <%= table.name %> @@ -350,7 +350,7 @@ end var dining_name = $(this).attr("data-name"); var dining_id = $(this).attr("data-id"); var change_from = "<%= @dining.id %>"; - if ((dining_id == change_from) || (dining_name==undefined)) { + if ((dining_id == change_from)) { swal({ title: "Alert!!", text: 'Please select another table !', diff --git a/app/views/origami/movetable/move_dining.html.erb b/app/views/origami/movetable/move_dining.html.erb index c15aeea8..06dc386b 100755 --- a/app/views/origami/movetable/move_dining.html.erb +++ b/app/views/origami/movetable/move_dining.html.erb @@ -26,7 +26,7 @@ <% if table.get_checkout_booking.nil? %>
    <% else %> -
    +
    <% end %>
    <%= table.name %> @@ -34,9 +34,9 @@
    <% else %> <% if table.get_checkout_booking.nil? %> -
    +
    <% else %> -
    +
    <% end %>
    <%= table.name %> @@ -351,7 +351,7 @@ end var dining_name = $(this).attr("data-name"); var dining_id = $(this).attr("data-id"); var change_from = "<%= @dining.id %>"; - if ((dining_id == change_from) || (dining_name==undefined)) { + if (dining_id == change_from) { swal({ title: "Alert!!", text: 'Please select another table !', diff --git a/app/views/origami/pending_order/completed_sale.html.erb b/app/views/origami/pending_order/completed_sale.html.erb index 1b7194f5..46dc035d 100644 --- a/app/views/origami/pending_order/completed_sale.html.erb +++ b/app/views/origami/pending_order/completed_sale.html.erb @@ -324,13 +324,12 @@ $(document).ready(function(){ swal("Opps","You are not authorized for void","warning") } }); +}); - $(document).on('click', '.access_modal', function(event){ - type = $(this).data("type"); - $(".ok").attr("data-action",type) - $('#AccessCodeModal').modal('show'); - }); - +$(document).on('click', '.access_modal', function(event){ + type = $(this).data("type"); + $(".ok").attr("data-action",type); + $('#AccessCodeModal').modal('show'); }); function check_emp_access_code(access_code,type) { diff --git a/app/views/origami/sales/show.html.erb b/app/views/origami/sales/show.html.erb index 9ca1cd72..b373fd45 100755 --- a/app/views/origami/sales/show.html.erb +++ b/app/views/origami/sales/show.html.erb @@ -410,7 +410,7 @@ $('#back').on('click',function(){ $(document).on('click', '.access_modal', function(event){ type = $(this).data("type"); - $(".ok").attr("data-action",type) + $(".ok").attr("data-action",type); $('#AccessCodeModal').modal('show'); }); $('#void').on('click', function () { diff --git a/app/views/reports/induty/_shift_sale_report_filter.html.erb b/app/views/reports/induty/_shift_sale_report_filter.html.erb new file mode 100755 index 00000000..6b9526ab --- /dev/null +++ b/app/views/reports/induty/_shift_sale_report_filter.html.erb @@ -0,0 +1,127 @@ +
    + <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
    +
    + + +
    + + <% if defined? commissioners %> +
    + + +
    + <% end %> +
    + + + +
    +
    + + +
    +
    + + +
    +
    +
    + +
    +
    + <% end %> + + <% end %> +
    + + diff --git a/app/views/reports/induty/index.html.erb b/app/views/reports/induty/index.html.erb new file mode 100644 index 00000000..fe1c72cf --- /dev/null +++ b/app/views/reports/induty/index.html.erb @@ -0,0 +1,181 @@ + +
    +
    + <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :commissioners => true, :shift_name => true, :report_path =>reports_induty_index_path} %> + +
    + + + +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + <% if !@induty_data.nil? %> + <% induty_arr = Array.new %> + <% @induty_data.each do |induty| %> + + + + + + + + + <% end %> + <% end %> + +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
     <%= t("views.right_panel.detail.receipt_no") %><%= t :commissioners %><%= t :table %><%= t("views.right_panel.detail.in_time") %><%= t("views.right_panel.detail.out_time") %>
     <%= induty.receipt_no %><%= induty.name %><%= induty.dining_name %><%= induty.in_time.utc.getlocal.strftime("%d-%m-%Y - %I:%M") %><%= induty.out_time.utc.getlocal.strftime("%d-%m-%Y - %I:%M") %>
    +
    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/app/views/reports/induty/index.xls.erb b/app/views/reports/induty/index.xls.erb new file mode 100755 index 00000000..e0097faf --- /dev/null +++ b/app/views/reports/induty/index.xls.erb @@ -0,0 +1,55 @@ + + + + + + + +
    +
    +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + <% if !@induty_data.nil? %> + <% induty_arr = Array.new %> + <% @induty_data.each do |induty| %> + + + + + + + + <% end %> + <% end %> + +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
    <%= t("views.right_panel.detail.receipt_no") %><%= t :commissioners %><%= t :table %><%= t("views.right_panel.detail.in_time") %><%= t("views.right_panel.detail.out_time") %>
    <%= induty.receipt_no %><%= induty.name %><%= induty.dining_name %><%= induty.in_time.utc.getlocal.strftime("%d-%m-%Y - %I:%M") %><%= induty.out_time.utc.getlocal.strftime("%d-%m-%Y - %I:%M") %>
    +
    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/app/views/settings/set_menu_items/_form.html.erb b/app/views/settings/set_menu_items/_form.html.erb index 0f8eed54..428800ef 100755 --- a/app/views/settings/set_menu_items/_form.html.erb +++ b/app/views/settings/set_menu_items/_form.html.erb @@ -1,7 +1,7 @@
    - <%= simple_form_for([:settings,@category, @settings_menu_item]) do |f| %> + <%= simple_form_for([:settings,@category, @settings_menu_item],:html => {:onsubmit=>"return validateForm()"}) do |f| %> <%= f.error_notification %>
    @@ -92,4 +92,22 @@
    - + diff --git a/app/views/settings/simple_menu_items/_form.html.erb b/app/views/settings/simple_menu_items/_form.html.erb index 39932bdd..ba94e801 100755 --- a/app/views/settings/simple_menu_items/_form.html.erb +++ b/app/views/settings/simple_menu_items/_form.html.erb @@ -1,7 +1,7 @@
    - <%= simple_form_for([:settings,@category, @settings_menu_item]) do |f| %> + <%= simple_form_for([:settings,@category, @settings_menu_item],:html => {:onsubmit=>"return validateForm()"}) do |f| %> <%= f.error_notification %>
    @@ -88,4 +88,23 @@
    + diff --git a/config/locales/en.yml b/config/locales/en.yml index f3596417..4f96ef4e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -487,6 +487,9 @@ en: order_reservation: "Order Reservation" cooking_time: "Cooking Time" township: "Township" + induty_report: "Induty Report" + in_time: "In Time" + out_time: "Out Time" code_txt: "code " charge_txt: "charge" diff --git a/config/locales/mm.yml b/config/locales/mm.yml index 3f58eac9..c6ea5dfa 100644 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -481,6 +481,9 @@ mm: order_reservation: "Order Reservation" cooking_time: "Cooking Time" township: "Township" + induty_report: "Induty Report" + in_time: "In Time" + out_time: "Out Time" code_txt: "ကုတ်ဒ် " charge_txt: "ကောက်ခံသည်" diff --git a/config/routes.rb b/config/routes.rb index 3cfb71de..24916f39 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -131,13 +131,13 @@ scope "(:locale)", locale: /en|mm/ do post 'cancel_all_void' => 'sale_edit#cancel_all_void' post 'apply_void' => 'sale_edit#apply_void' # in_duties - get '/table/:table_id/assign_in_duty' => 'in_duties#assign_in_duty', as: 'assign_in_duty' - get 'assign_in_duty/:table_id' => 'in_duties#index_in_duty', as: 'index_in_duty' - post 'assign_in_duty/:table_id' => 'in_duties#create_for_in_duty' + get '/table/:sale_id/assign_in_duty' => 'in_duties#assign_in_duty', as: 'assign_in_duty' + get 'assign_in_duty/:sale_id' => 'in_duties#index_in_duty', as: 'index_in_duty' + post 'assign_in_duty/:sale_id' => 'in_duties#create_for_in_duty' - get 'assign_in_duty/table/:table_id/in_duty/:id/edit' => 'in_duties#edit_in_duty' ,as: 'edit_in_duty' + get 'assign_in_duty/table/:sale_id/in_duty/:id/edit' => 'in_duties#edit_in_duty' ,as: 'edit_in_duty' patch 'edit_in_duty/:id' => 'in_duties#update_for_in_duty', as: 'update_for_in_duty' - delete 'table/:table_id/destroy_in_duty/:id' => 'in_duties#destroy_in_duty', as: 'destroy_in_duty' + delete 'table/:table_id/:sale_id/destroy_in_duty/:id' => 'in_duties#destroy_in_duty', as: 'destroy_in_duty' get 'table/:dining_id/movetable' => "movetable#move_dining" get 'table/:dining_id/moveroom' => "moveroom#move_dining" @@ -454,9 +454,12 @@ scope "(:locale)", locale: /en|mm/ do resources :payment_method resources :product_sale, :only => [:index, :show] resources :order_reservation, :only => [:index, :show] + resources :induty, :only => [:index, :show] + get "saleitem/get_shift_by_date", to: "saleitem#show", as: "get_shift_by_sale_item" get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date" get "order_reservation/get_shift_by_date", to: "order_reservation#show", as: "get_shift_by_order_reservation" + get "induty/get_shift_by_date", to: "induty#show", as: "get_shift_by_induty" end