From fc8b2d3b731f52b8c17d2795a02e0e9624de0a1c Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 5 Apr 2018 11:49:42 +0630 Subject: [PATCH 01/10] Pull from master --- app/assets/javascripts/addorder.js | 92 ++++++++++++++----- app/assets/javascripts/custom.js | 20 ++++ app/controllers/api/survey_controller.rb | 47 ++++++++++ .../origami/request_bills_controller.rb | 4 +- .../reports/saleitem_controller.rb | 24 +++-- app/models/license.rb | 41 ++++++--- app/models/sale.rb | 9 ++ app/models/sale_payment.rb | 2 +- app/views/layouts/login_dashboard.html.erb | 4 +- app/views/origami/addorders/detail.html.erb | 8 +- app/views/reports/saleitem/index.html.erb | 3 +- config/license.yml | 15 +++ config/routes.rb | 5 +- config/secrets.yml | 2 +- 14 files changed, 222 insertions(+), 54 deletions(-) create mode 100644 app/controllers/api/survey_controller.rb create mode 100644 config/license.yml diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 31209c99..a8de44b1 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -315,6 +315,7 @@ $(function() { $(".options-list").empty(); rowCount = $('.selected-instance'); + setCount = $('.selected-set'); item_options = $(this).data('option'); min_qty = $(this).data('min-qty'); @@ -335,19 +336,19 @@ $(function() { $(".options-list").append(row); } } - if($(this).hasClass('selected-instance') == true){ - sub_total = $('#set_total_price').text(); - name = $(this).data('name'); - price = $(this).data('price'); - // qty = $('#set_change_qty').val(); - qty = document.getElementById("set_count").value; - total = qty*price; - var total_price = +sub_total - +total; - $(this).removeClass('selected-instance'); - $(".options-list").empty(); - $(this).removeAttr('data-options'); - $('#instance_option').text('') - }else { + // if($(this).hasClass('selected-instance') == true){ + // sub_total = $('#set_total_price').text(); + // name = $(this).data('name'); + // price = $(this).data('price'); + // // qty = $('#set_change_qty').val(); + // qty = document.getElementById("set_count").value; + // total = qty*price; + // var total_price = +sub_total - +total; + // $(this).removeClass('selected-instance'); + // $(".options-list").empty(); + // $(this).removeAttr('data-options'); + // $('#instance_option').text('') + // }else { if (rowCount.length+1 <= max_qty) { sub_total = $('#set_total_price').text(); name = $(this).data('name'); @@ -358,12 +359,55 @@ $(function() { total = qty*price; var total_price = +sub_total + +total; $(this).addClass('selected-instance'); + + set = "
" + + +'
' + +' ' + +''+$(this).data('name')+'' + +'
' + +'
' + + +' ' + +'
' + // +'' + +'
' + $(".selected-set-list").append(set); + }else{ + swal("Alert !", 'Maximum Qty is ' + max_qty + " items", "warning"); } - } + // } $('#set_unit_price').text(price); $('#set_total_price').text(total_price); }); //End selecct attribute buttom + + // click add order + $(document).on('click', '#remove_set', function(event){ + code = $(this).parent().parent('.selected-set').attr('data-code'); + instance = $(".selected-instance"); + console.log(code) + $(instance).each(function(i){ + if ($(instance[i]).attr('data-code')==code){ + console.log($(instance[i])) + $(instance[i]).removeClass("selected-instance") + } + }); + $(this).parent().parent('.selected-set').remove(); + }); // click add order $(document).on('click', '.set_order', function(event){ @@ -637,15 +681,17 @@ $(function() { if(group == "set_menu"){ - - instance = $(".selected-instance"); - $(instance).each(function(i){ - if ($(instance[i]).attr('data-code')==code){ - option_arr = get_selected_attributes('selected-option'); - $(instance[i]).attr('data-options',JSON.stringify(option_arr)); - $(instance[i]).children().children('#instance_option').text(option_arr); - } - }); + option_arr = get_selected_attributes('selected-option'); + $(".selected-set:last").attr('data-options',JSON.stringify(option_arr)); + $(".selected-set:last").children().children('#instance_option').text(option_arr); + // instance = $(".selected-instance"); + // $(instance).each(function(i){ + // if ($(instance[i]).attr('data-code')==code){ + // option_arr = get_selected_attributes('selected-option'); + // $(instance[i]).attr('data-options',JSON.stringify(option_arr)); + // $(instance[i]).children().children('#instance_option').text(option_arr); + // } + // }); } if(group == "set_menu_default"){ diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index c6e6a47b..043fbb03 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -32,6 +32,26 @@ $(document).ready(function() { railBorderRadius: '0', touchScrollStep : 50 }); + + $('#modal-slimscroll').slimScroll({ + height: height-$('#modal-slimscroll').attr('data-height'), + size: '5px', + color: 'rgba(0,0,0,0.5)', + alwaysVisible: false, + borderRadius: '0', + railBorderRadius: '0', + touchScrollStep : 45 + }); + + $('#modal-set-slimscroll').slimScroll({ + height: height-$('#modal-slimscroll').attr('data-height'), + size: '5px', + color: 'rgba(0,0,0,0.5)', + alwaysVisible: false, + borderRadius: '0', + railBorderRadius: '0', + touchScrollStep : 45 + }); // $('.delete').click(function(){ // var method = $(this).attr('data-method'); diff --git a/app/controllers/api/survey_controller.rb b/app/controllers/api/survey_controller.rb new file mode 100644 index 00000000..879c9ea7 --- /dev/null +++ b/app/controllers/api/survey_controller.rb @@ -0,0 +1,47 @@ +class Api::SurveyController < Api::ApiController + skip_before_action :authenticate + + def index + dining_facility = DiningFacility.find(params[:id]) + survey_data = Survey.find_by_dining_name(dining_facility.name) + countries = Lookup.collection_of("country") + if !countries.nil? || !survey_data.nil? + render :json => { :status => true, :data => { :countries => countries, :survey_data => survey_data} } + else + render :json => { :status => true, :error_message => "There is no data" } + end + end + + def create + dining_facility = DiningFacility.find(params[:id]) + cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id) + shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) + + if params[:survey_id] + survey = Survey.find(params[:survey_id]) + else + survey = Survey.new + end + survey.dining_name = dining_facility.name + survey.shift_id = shift_by_terminal.id + survey.child = params[:child] + survey.adult = params[:adult] + survey.male = params[:male] + survey.female = params[:female] + survey.local = params[:local] + survey.created_by = current_login_employee.name + survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] + survey.foreigner = params[:foreigner].to_json + survey.save! + + render :json => { :status => true } + end + + # private + # def survey_params + # params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, + # :dining_name,:created_by,:total_customer,:total_amount) + # end + +end \ No newline at end of file diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index e2553a83..cdd1f442 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -16,7 +16,7 @@ class Origami::RequestBillsController < ApplicationController bk_order = BookingOrder.find_by_order_id(order_id) order = Order.find(order_id) check_booking = Booking.find_by_booking_id(bk_order.booking_id) - + table = DiningFacility.find(check_booking.dining_facility_id) if check_booking.sale_id.nil? # Create Sale if it doesn't exist @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source) @@ -33,6 +33,8 @@ class Origami::RequestBillsController < ApplicationController # Promotion Activation Promotion.promo_activate(@sale) + #bill channel + ActionCable.server.broadcast "bill_channel",table: table if order.source == "quick_service" result = {:status=> @status, :data => @sale.sale_id } render :json => result.to_json diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index 24c812eb..92604b04 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -3,18 +3,26 @@ class Reports::SaleitemController < BaseReportController def index from, to = get_date_range_from_params - shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale_range = '' shift = '' if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? + 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) + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end end end + @type = params[:sale_type] @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type) @@ -54,8 +62,8 @@ class Reports::SaleitemController < BaseReportController def show from, to, report_type = get_date_range_from_params - - @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) +puts "aaaaaaaaaaaaaaaaaaaaaaaaaa" + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| @@ -68,8 +76,8 @@ class Reports::SaleitemController < BaseReportController date_arr.push(str) end - @totalByAccount = Hash.new {|hash, key| hash[key] = 0} - @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + # @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} out = {:status => 'ok', :message => date_arr} diff --git a/app/models/license.rb b/app/models/license.rb index ac82721c..ed8e3eb8 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -134,24 +134,36 @@ class License def verify_license api_token = read_license_no_decrypt("api_token") @params = { query: {lookup_type: "application", api_token: api_token} } - response = self.class.get("/verify", @params) + + begin + response = self.class.get("/verify", @params) + @varified = response.parsed_response + Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s + if (@varified["status"]) + if (!check_expired(@varified["renewable_date"])) + return true + end + else + delete_license_file + end - rescue SocketError => e - Rails.logger.debug "In Socket errror" - return true - rescue => e - @varified = response.parsed_response - Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - if (@varified["status"]) - if (!check_expired(@varified["renewable_date"])) - return true - end - else - delete_license_file - end + rescue SocketError => e + Rails.logger.debug "In SocketError No Internet connection ! " + return true + rescue HTTParty::Error + Rails.logger.debug "Server Error HTTParty" + return true + rescue Net::OpenTimeout + Rails.logger.debug "connection Timeout" + return true + rescue OpenURI::HTTPError + Rails.logger.debug "Can't connect server" + return true + end return false end + # Check Expired before 30 days def check_expiring(renewal_date_str) if !renewal_date_str.empty? @@ -164,7 +176,6 @@ class License def check_expired(renewal_date_str) expired_date_str = read_license("renewable_date") renewal_date = DateTime.parse(renewal_date_str) - if(renewal_date_str != expired_date_str) update_license("renewable_date", renewal_date_str) end diff --git a/app/models/sale.rb b/app/models/sale.rb index 49c27448..363ff77b 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -806,6 +806,15 @@ def self.get_by_shift_sale(from,to,status) return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to) end +def self.get_by_shift_sale_by_item(from,to,status) + query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date, + shift_closed_at As closing_date," + + " grand_total AS grand_total, cash_sales AS cash," + + "total_taxes AS total_tax,total_discounts As total_discount") + .order("shift_sales.id DESC") + return query = query.where("shift_sales.shift_started_at >= ?" , from) +end + def self.get_item_query(type) if type == "revenue" || type.nil? diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 4621adba..5cd7ea40 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -472,7 +472,7 @@ class SalePayment < ApplicationRecord elsif paid_amount.to_f > 0 #|| paid_amount != "0.0" table_update_status(sObj) update_shift - elsif method_status && paid_amount.to_f == 0 + elsif method_status && paid_amount.to_f == 0 && is_credit == 0 table_update_status(sObj) update_shift end diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index d3e4729d..ec0469fe 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -11,8 +11,8 @@ - - + <%= stylesheet_link_tag 'login', media: 'all', 'data-turbolinks-track': 'reload' %> diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 607f4c0e..93569170 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -405,9 +405,15 @@

-
+ +
diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index a972443f..a3937ec2 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -325,7 +325,8 @@ var str = ''; var param_shift = '<%= params[:shift_name]%>'; - url = '<%= reports_get_shift_by_date_path %>'; + url = '<%= reports_get_shift_by_sale_item_path %>'; + console.log(url) $.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){ console.log(data) diff --git a/config/license.yml b/config/license.yml new file mode 100644 index 00000000..9f4d1542 --- /dev/null +++ b/config/license.yml @@ -0,0 +1,15 @@ +iv_key: rwOZKWcQho6fE4V+A2zFuQ== +shop_name: AMZ_Test +email: aungmyo.zaw@code2lab.com +telephone: +fax: +address: +dbhost: dNzh66R80remB694OEds96OpuyZ4wmHeHFdQh0KwjYFvTInK6+pCN/y6HdbyIlqqjcBHkqPjkjzw45PznLn7hA== +dbschema: 4vooJDxgWdFv/8V7Qx8tzR/8B8T2c5U4XvYcF+2KOoA= +dbusername: Xc8ELRsW7N/f8KsVikMBlg== +dbpassword: HMg+TbLxmfYrDFI4IIAd4g== +api_token: bisryXiEnbTJlZwghAnIByQpiRUMouu +app_token: LycQXJYBZGeCygjIEKdlBXnjIGMiMzgmt +plan_sku: 84hdnSCgkfhvItY7uB/pPQ== +renewable_date: 8E6Ecz8QXAMSlKZnIzn0pQ== +plan_name: 4cMIO0n/JzGFPIccXM6u5A== diff --git a/config/routes.rb b/config/routes.rb index 94db2ebd..2c25db97 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,6 +78,8 @@ scope "(:locale)", locale: /en|mm/ do post "check_in" => "check_in_process#check_in_process" post "request_time" => "check_in_process#request_time" post "call_waiter" => "call_waiters#index" + get "survey/:id" => "survey#index" + post "survey/:id" => "survey#create" end @@ -417,8 +419,9 @@ scope "(:locale)", locale: /en|mm/ do resources :stock_check, :only => [:index, :show] resources :payment_method resources :product_sale, :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" + end # ----------- Inventory --------------------------- diff --git a/config/secrets.yml b/config/secrets.yml index 076b6691..0282c5fc 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -12,7 +12,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 - sx_provision_url: connect.smartsales.dev/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api + sx_provision_url: connect.smartsales.asia/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L From e607fea8a3a1d037c3c5aa731a788d0453179625 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 5 Apr 2018 13:30:29 +0630 Subject: [PATCH 02/10] Modified in all pdf can access Header & Item Font Size from Database --- README.md | 7 ++++++- app/pdf/call_waiter_pdf.rb | 7 +++---- app/pdf/close_cashier_customise_pdf.rb | 4 ++-- app/pdf/close_cashier_pdf.rb | 4 ++-- app/pdf/crm_order_pdf.rb | 5 ++--- app/pdf/move_table_pdf.rb | 7 +++---- app/pdf/order_item_pdf.rb | 10 +++------- app/pdf/order_item_slim_pdf.rb | 10 +++------- app/pdf/order_set_item_pdf.rb | 10 +++------- app/pdf/order_summary_pdf.rb | 10 +++------- app/pdf/order_summary_set_pdf.rb | 8 ++------ app/pdf/order_summary_slim_pdf.rb | 8 ++------ app/pdf/queue_no_pdf.rb | 5 ++--- app/pdf/receipt_bill_a5_pdf.rb | 4 ++-- app/pdf/receipt_bill_pdf.rb | 4 ++-- app/pdf/stock_result_pdf.rb | 6 +++--- 16 files changed, 43 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index e19f7a51..ce5402ac 100755 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ For Extra Time For Order Item & Order Summary Slim *** change OrderItemPdf to OrderItemSlimPdf and OrderSummaryPdf to OrderSummarySlimPdf 1) settings/print_settings + (a) Font is present => {Header font size:11, Item Font Size:9} + (b) Font is blank => {Header font size:12, Item Font Size:10} 2) settings/lookups => { type:print_settings, name:OrderSlimPdf, value:1 } * no need to change these files { app/controllers/oqs/edit_controller.rb @@ -53,7 +55,7 @@ For Order Item & Order Summary Slim For ReceiptBillA5Pdf *** change ReceiptBillPdf to ReceiptBillA5Pdf - 1) settings/print_settings , width:680, height:1450 + 1) settings/print_settings , width:680, height:1450, Header font Size:16, Item font size:14 2) settings/lookups => { type:print_settings, name:ReceiptBillA5Pdf, value:1 } For ReceiptBillAltName options @@ -62,6 +64,9 @@ For ReceiptBillAltName options For OrderSetPdf options *** change OrderItemPdf to OrderSetItemPdf and OrderSummaryPdf to OrderSummarySetPdf 1) settings/lookups => { type:print_settings, name:OrderSetPdf, value:1 } + 2) settings/print_settings + (a) Font is present => {Header font size:11, Item Font Size:9} + (b) Font is blank => {Header font size:12, Item Font Size:10} For Bank Integration setting 1) rake db:migrate for card_sale_trans, card_settle_trans diff --git a/app/pdf/call_waiter_pdf.rb b/app/pdf/call_waiter_pdf.rb index a1ea756b..314d0c33 100644 --- a/app/pdf/call_waiter_pdf.rb +++ b/app/pdf/call_waiter_pdf.rb @@ -3,6 +3,8 @@ class CallWaiterPdf < Prawn::Document def initialize(printer_settings, table,time,shop_detail) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 5 self.price_width = 35 self.qty_width = 20 @@ -27,9 +29,6 @@ class CallWaiterPdf < Prawn::Document fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end - self.header_font_size = 10 - self.item_font_size = 8 - header( shop_detail.name, printer_settings.name) call_waiter(table) @@ -68,4 +67,4 @@ class CallWaiterPdf < Prawn::Document # end -end +end \ No newline at end of file diff --git a/app/pdf/close_cashier_customise_pdf.rb b/app/pdf/close_cashier_customise_pdf.rb index bcc27724..0080373c 100644 --- a/app/pdf/close_cashier_customise_pdf.rb +++ b/app/pdf/close_cashier_customise_pdf.rb @@ -5,6 +5,8 @@ class CloseCashierCustomisePdf < Prawn::Document def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges) self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 5 self.price_width = 60 self.qty_width = 20 @@ -36,8 +38,6 @@ class CloseCashierCustomisePdf < Prawn::Document end # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - self.header_font_size = 10 - self.item_font_size = 8 #precision checked if printer_settings.precision.to_i > 2 diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 7ac7a130..04bbdcf8 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -5,6 +5,8 @@ class CloseCashierPdf < Prawn::Document def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount) self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 5 self.price_width = 60 self.qty_width = 20 @@ -36,8 +38,6 @@ class CloseCashierPdf < Prawn::Document end # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - self.header_font_size = 10 - self.item_font_size = 8 #precision checked if printer_settings.precision.to_i > 2 diff --git a/app/pdf/crm_order_pdf.rb b/app/pdf/crm_order_pdf.rb index a33b5fce..070f5654 100755 --- a/app/pdf/crm_order_pdf.rb +++ b/app/pdf/crm_order_pdf.rb @@ -3,6 +3,8 @@ class CrmOrderPdf < Prawn::Document def initialize(booking,order_items,printer_settings) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 10 # self.price_width = self.p_width / 2 self.price_width=80 @@ -31,9 +33,6 @@ class CrmOrderPdf < Prawn::Document font "#{printer_settings.font}" fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end - - self.header_font_size = 10 - self.item_font_size = 9 header( printer_settings.printer_name, printer_settings.name) stroke_horizontal_rule diff --git a/app/pdf/move_table_pdf.rb b/app/pdf/move_table_pdf.rb index 7b4ad8e4..954f88e9 100644 --- a/app/pdf/move_table_pdf.rb +++ b/app/pdf/move_table_pdf.rb @@ -3,6 +3,8 @@ class MoveTablePdf < Prawn::Document def initialize(printer_settings,to,from,shop_detail,date,type,moved_by) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 5 self.price_width = 35 self.qty_width = 20 @@ -27,9 +29,6 @@ class MoveTablePdf < Prawn::Document fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end - self.header_font_size = 10 - self.item_font_size = 8 - header(printer_settings.name,type) call_move_table(to,from,date,type,moved_by) @@ -56,4 +55,4 @@ class MoveTablePdf < Prawn::Document end -end \ No newline at end of file +end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 58682d8a..89ddcdb6 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -4,6 +4,8 @@ class OrderItemPdf < Prawn::Document def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 @@ -26,13 +28,7 @@ class OrderItemPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] - - self.header_font_size = 11 - self.item_font_size = 9 - else - self.header_font_size = 12 - self.item_font_size = 10 + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" diff --git a/app/pdf/order_item_slim_pdf.rb b/app/pdf/order_item_slim_pdf.rb index 05add2c9..607adf14 100755 --- a/app/pdf/order_item_slim_pdf.rb +++ b/app/pdf/order_item_slim_pdf.rb @@ -4,6 +4,8 @@ class OrderItemSlimPdf < Prawn::Document def initialize(print_settings,order_item_slim, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 @@ -26,13 +28,7 @@ class OrderItemSlimPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] - - self.header_font_size = 11 - self.item_font_size = 9 - else - self.header_font_size = 12 - self.item_font_size = 10 + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" diff --git a/app/pdf/order_set_item_pdf.rb b/app/pdf/order_set_item_pdf.rb index ce06081f..9668a0f5 100755 --- a/app/pdf/order_set_item_pdf.rb +++ b/app/pdf/order_set_item_pdf.rb @@ -4,6 +4,8 @@ class OrderSetItemPdf < Prawn::Document def initialize(print_settings,order_set_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 @@ -26,13 +28,7 @@ class OrderSetItemPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] - - self.header_font_size = 11 - self.item_font_size = 9 - else - self.header_font_size = 12 - self.item_font_size = 10 + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 17cf905c..5d5b9da8 100755 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -4,6 +4,8 @@ class OrderSummaryPdf < Prawn::Document def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 @@ -25,13 +27,7 @@ class OrderSummaryPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] - - self.header_font_size = 11 - self.item_font_size = 9 - else - self.header_font_size = 12 - self.item_font_size = 10 + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" diff --git a/app/pdf/order_summary_set_pdf.rb b/app/pdf/order_summary_set_pdf.rb index 14b2f796..a16265d2 100755 --- a/app/pdf/order_summary_set_pdf.rb +++ b/app/pdf/order_summary_set_pdf.rb @@ -4,6 +4,8 @@ class OrderSummarySetPdf < Prawn::Document def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 @@ -26,12 +28,6 @@ class OrderSummarySetPdf < Prawn::Document font "#{print_settings.font}" fallback_fonts ["Courier", "Helvetica", "Times-Roman"] - - self.header_font_size = 11 - self.item_font_size = 9 - else - self.header_font_size = 12 - self.item_font_size = 10 end # font "public/fonts/Zawgyi-One.ttf" diff --git a/app/pdf/order_summary_slim_pdf.rb b/app/pdf/order_summary_slim_pdf.rb index c88061ea..e082203f 100755 --- a/app/pdf/order_summary_slim_pdf.rb +++ b/app/pdf/order_summary_slim_pdf.rb @@ -4,6 +4,8 @@ class OrderSummarySlimPdf < Prawn::Document def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 @@ -26,12 +28,6 @@ class OrderSummarySlimPdf < Prawn::Document font "#{print_settings.font}" fallback_fonts ["Courier", "Helvetica", "Times-Roman"] - - self.header_font_size = 11 - self.item_font_size = 9 - else - self.header_font_size = 12 - self.item_font_size = 10 end # font "public/fonts/Zawgyi-One.ttf" diff --git a/app/pdf/queue_no_pdf.rb b/app/pdf/queue_no_pdf.rb index cce7eb94..adf824eb 100755 --- a/app/pdf/queue_no_pdf.rb +++ b/app/pdf/queue_no_pdf.rb @@ -3,6 +3,8 @@ class QueueNoPdf < Prawn::Document def initialize(printer_settings, queue) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 5 self.price_width = 35 self.qty_width = 20 @@ -27,9 +29,6 @@ class QueueNoPdf < Prawn::Document fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end - self.header_font_size = 10 - self.item_font_size = 8 - header( "Beauty In the Pot", printer_settings.name) queue_no(queue) diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 604d99dd..a7cf21e2 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -5,6 +5,8 @@ class ReceiptBillA5Pdf < Prawn::Document def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 15 self.price_width = 120 self.qty_width = 50 @@ -43,8 +45,6 @@ class ReceiptBillA5Pdf < Prawn::Document end # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - self.header_font_size = 16 - self.item_font_size = 14 if printer_settings.delimiter delimiter = "," diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index c0299033..8bae5f60 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -6,6 +6,8 @@ class ReceiptBillPdf < Prawn::Document def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 0 self.price_width = 60 self.qty_width = 25 @@ -44,8 +46,6 @@ class ReceiptBillPdf < Prawn::Document end # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - self.header_font_size = 10 - self.item_font_size = 8 if printer_settings.delimiter delimiter = "," diff --git a/app/pdf/stock_result_pdf.rb b/app/pdf/stock_result_pdf.rb index 510ab317..dec667f7 100755 --- a/app/pdf/stock_result_pdf.rb +++ b/app/pdf/stock_result_pdf.rb @@ -4,6 +4,8 @@ class StockResultPdf < Prawn::Document def initialize(printer_settings, stockcheck, stockcheck_items, checker_name, shop_details) self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size + self.item_font_size = printer_settings.item_font_size self.margin = 5 self.price_width = 40 self.qty_width = 20 @@ -35,9 +37,7 @@ class StockResultPdf < Prawn::Document end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - self.header_font_size = 10 - self.item_font_size = 8 +# font "public/fonts/padauk.ttf" header(shop_details) From 39e887c7a55d73f52ef49902761c718761c75052 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 5 Apr 2018 14:30:43 +0630 Subject: [PATCH 03/10] Pull from master --- app/models/license.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/license.rb b/app/models/license.rb index ed8e3eb8..13931376 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -356,7 +356,8 @@ class License f.write("job.push.period.time.ms=10000\n") f.write("job.pull.period.time.ms=10000\n") f.write("initial.load.create.first=true\n") - f.write("initial.load.use.extract.job.enabled=true\n") + f.write("initial.load.use.extract.job.enabled=true\n") + f.write("rest.api.enable=true\n") f.close # read from license file @@ -379,7 +380,8 @@ class License f.write("external.id=001\n") f.write("job.routing.period.time.ms=5000\n") f.write("job.push.period.time.ms=10000\n") - f.write("job.pull.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + f.write("rest.api.enable=true\n") # f.write("initial.load.create.first=true\n") # f.write("initial.load.use.extract.job.enabled=true\n") f.close From 769698e09e0c73555314eca27561a94189309d79 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 5 Apr 2018 18:23:29 +0630 Subject: [PATCH 04/10] Add MoveTablePdf and FOC update error --- .../origami/movetable_controller.rb | 23 ++++-- app/models/printer/receipt_printer.rb | 4 +- app/models/sale_payment.rb | 2 +- app/pdf/move_table_pdf.rb | 79 ++++++++++++++++--- app/pdf/order_item_pdf.rb | 4 +- app/pdf/order_summary_pdf.rb | 4 +- 6 files changed, 93 insertions(+), 23 deletions(-) diff --git a/app/controllers/origami/movetable_controller.rb b/app/controllers/origami/movetable_controller.rb index 20aaf0c5..3844293e 100755 --- a/app/controllers/origami/movetable_controller.rb +++ b/app/controllers/origami/movetable_controller.rb @@ -62,9 +62,19 @@ class Origami::MovetableController < BaseOrigamiController bookings = Booking.where('dining_facility_id=?',change_from) booking_array = Array.new - bookings.each do | booking | - if booking.sale_id.nil? && booking.booking_status != 'moved' - booking_array.push(booking) + order_items = Array.new + if !bookings.nil? + bookings.each do | booking | + if booking.sale_id.nil? && booking.booking_status != 'moved' + booking_array.push(booking) + end + + booking.booking_orders.each do |booking_order| + order = Order.find(booking_order.order_id) + order.order_items.each do |order_item| + order_items.push(order_item) + end + end end end @@ -82,12 +92,13 @@ class Origami::MovetableController < BaseOrigamiController #print_settings = PrintSetting.find_by_unique_code(unique_code) printer_array = [] printer_array = PrintSetting.where(:unique_code => unique_code) + for i in 0..pdf_no if i != pdf_no print_settings = printer_array[i] - printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_move_table(print_settings,@to,@from ,@shop,@date,@type,@moved_by) + printer = Printer::ReceiptPrinter.new(print_settings) + printer.print_move_table(print_settings,@to,@from ,@shop,@date,@type,@moved_by,order_items) end end - end + end end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 447543f2..26c31c6f 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -239,11 +239,11 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Move Table Print - def print_move_table(printer_settings,to,from,shop_detail,date,type,moved_by) + def print_move_table(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) #Use CUPS service #Generate PDF #Print - pdf = MoveTablePdf.new(printer_settings,to,from,shop_detail,date,type,moved_by) + pdf = MoveTablePdf.new(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) pdf.render_file "tmp/print_move_table.pdf" self.print("tmp/print_move_table.pdf") end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 5cd7ea40..beb478fb 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -255,7 +255,7 @@ class SalePayment < ApplicationRecord payment_status = false # add to sale item with foc - sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and status is null") + sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }'") sale_items.each do|item| SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) diff --git a/app/pdf/move_table_pdf.rb b/app/pdf/move_table_pdf.rb index 954f88e9..f3f05572 100644 --- a/app/pdf/move_table_pdf.rb +++ b/app/pdf/move_table_pdf.rb @@ -1,18 +1,19 @@ class MoveTablePdf < Prawn::Document - attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width - def initialize(printer_settings,to,from,shop_detail,date,type,moved_by) + 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,:item_height,:qty_width,:total_width,:item_description_width + def initialize(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size self.item_font_size = printer_settings.item_font_size - self.margin = 5 - self.price_width = 35 - self.qty_width = 20 - self.total_width = 35 - self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) - self.item_height = 15 - self.item_description_width = (self.page_width-20) / 2 - self.label_width = 100 + 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 super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -37,6 +38,12 @@ class MoveTablePdf < Prawn::Document stroke_horizontal_rule move_down 5 + add_lining_item(order_items, printer_settings.precision) + + move_down 5 + stroke_horizontal_rule + move_down 5 + end def header (name,type) @@ -54,5 +61,57 @@ class MoveTablePdf < Prawn::Document text "Moved By : #{moved_by}", :left_margin => -10, :size => self.header_font_size end + def add_lining_item(order_items, precision) + y_position = cursor + + bounding_box([0,y_position], :width => self.item_width) do + text "Item", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "Qty", :size => self.item_font_size,:align => :left + end + + stroke_horizontal_rule + move_down 5 + + add_item(order_items, precision) + end + + # Add order items under order info + def add_item(order_items, precision) + y_position = cursor + + move_down 5 + + order_items.each do|odi| + # check for item not to show + # if odi.price != 0 + y_position = cursor + + # bounding_box([0,y_position], :width => self.item_width + 60, :height => self.item_height) do + # text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left + # end + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + end + + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left + end + + if !(odi.alt_name).empty? + move_down 4 + font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + end + end + + end + end end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 89ddcdb6..717a0665 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -4,8 +4,8 @@ class OrderItemPdf < Prawn::Document def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height - self.header_font_size = printer_settings.header_font_size - self.item_font_size = printer_settings.item_font_size + self.header_font_size = print_settings.header_font_size + self.item_font_size = print_settings.item_font_size self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 5d5b9da8..9bf30615 100755 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -4,8 +4,8 @@ class OrderSummaryPdf < Prawn::Document def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height - self.header_font_size = printer_settings.header_font_size - self.item_font_size = printer_settings.item_font_size + self.header_font_size = print_settings.header_font_size + self.item_font_size = print_settings.item_font_size self.margin = 0 self.price_width = 40 # No Need for item self.qty_width = 40 From 57ff3e8a65239b6923ec7d900ba8913a9eb6fe65 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Fri, 6 Apr 2018 13:47:59 +0630 Subject: [PATCH 05/10] Edit Print_setting --- app/controllers/print_settings_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/print_settings_controller.rb b/app/controllers/print_settings_controller.rb index 991f4ad2..3bf37ae8 100755 --- a/app/controllers/print_settings_controller.rb +++ b/app/controllers/print_settings_controller.rb @@ -85,7 +85,7 @@ class PrintSettingsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def print_setting_params - params.require(:print_setting).permit(:name, :unique_code, :template, :printer_name, :brand_name, :printer_type, :font, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space) + params.require(:print_setting).permit(:name, :unique_code, :template, :printer_name, :font,:header_font_size, :item_font_size, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space) end #Shop Name in Navbor From 3c1be9a185306234e5325212f7d9a36d3fe00edb Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Fri, 6 Apr 2018 15:19:08 +0630 Subject: [PATCH 06/10] Edit From_time & To_time filter in dashboard --- app/models/sale.rb | 128 ++++++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 363ff77b..f96d3ca1 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -50,7 +50,7 @@ class Sale < ApplicationRecord charges = DiningCharge.where('dining_facility_id=?',booking.dining_facility_id).take if !charges.nil? block_count, diningprice = DiningCharge.amount_calculate(charges, booking.checkin_at, booking.checkout_at) - dining_time = booking.checkin_at.strftime('%H:%M %p').to_s + " - " + booking.checkout_at.strftime('%H:%M %p').to_s + dining_time = booking.checkin_at.strftime('%H:%i %p').to_s + " - " + booking.checkout_at.strftime('%H:%i %p').to_s create_saleitem_diningcharges(charges, block_count, diningprice, booking.dining_facility.name, dining_time) end @@ -1189,7 +1189,7 @@ end .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:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + " 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'") @@ -1203,7 +1203,7 @@ end .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:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + " 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'") @@ -1218,7 +1218,7 @@ end .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:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + " 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'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") @@ -1270,7 +1270,7 @@ end .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:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + " 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'") @@ -1284,7 +1284,7 @@ end .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:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + " 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'") @@ -1299,7 +1299,7 @@ end .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:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + " 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}'") @@ -1348,7 +1348,7 @@ end if current_user.nil? query = Sale.select("grand_total") if !from_time.nil? && !to_time.nil? - query = query.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:%M") between ? and ?',from,to,from_time,to_time) + query = query.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 query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) end @@ -1358,7 +1358,7 @@ end if current_user.role == 'administrator' || current_user.role == 'manager' query = Sale.select("grand_total") if !from_time.nil? && !to_time.nil? - query = query.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:%M") between ? and ?',from,to,from_time,to_time) + query = query.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 query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) end @@ -1369,7 +1369,7 @@ end if !shift.nil? query = Sale.select("grand_total") if !from_time.nil? && !to_time.nil? - query = query.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:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) + query = query.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 query = query.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 @@ -1409,7 +1409,7 @@ end query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") else query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") end @@ -1420,7 +1420,7 @@ end query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") else query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") end @@ -1432,7 +1432,7 @@ end query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and shift_sale_id='#{shift.id}'") + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and shift_sale_id='#{shift.id}'") else query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and shift_sale_id='#{shift.id}'") end @@ -1473,14 +1473,14 @@ end 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:%M") between ? and ?',from,to,from_time,to_time).sum("grand_total") + 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") 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") end else if current_user.role == 'administrator' || current_user.role == 'manager' 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:%M") between ? and ?',from,to,from_time,to_time).sum("grand_total") + 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") 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") end @@ -1488,7 +1488,7 @@ end 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:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) + 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") 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) @@ -1518,14 +1518,14 @@ end 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:%M") between ? and ?',from,to,from_time,to_time).count + 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 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 end else if current_user.role == 'administrator' || current_user.role == 'manager' 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:%M") between ? and ?',from,to,from_time,to_time).count + 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 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 end @@ -1533,7 +1533,7 @@ end 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:%M") between ? and ? and shift_sale_id = ?',from,to,from_time,to_time,shift.id).count + 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 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 end @@ -1560,7 +1560,7 @@ end 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:%M") 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")',from,to,from_time,to_time) + 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")',from,to,from_time,to_time) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else @@ -1571,7 +1571,7 @@ end else if current_user.role == 'administrator' || current_user.role == 'manager' 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:%M") 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")',from,to,from_time,to_time) + 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")',from,to,from_time,to_time) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else @@ -1583,7 +1583,7 @@ end 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:%M") 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") and shift_sale_id=?',from,to,from_time,to_time,shift.id) + 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") 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 @@ -1620,7 +1620,7 @@ end 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:%M") between ? and ?',from,to,from_time,to_time) + 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 @@ -1631,7 +1631,7 @@ end else if current_user.role == 'administrator' || current_user.role == 'manager' 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:%M") between ? and ?',from,to,from_time,to_time) + 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 @@ -1643,7 +1643,7 @@ end 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:%M") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id) + 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 @@ -1681,7 +1681,7 @@ end if current_user.nil? if !from_time.nil? && !to_time.nil? query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .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:%M") between ? and ?',from,to,from_time,to_time) + .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) .first() else query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') @@ -1692,7 +1692,7 @@ end if current_user.role == 'administrator' || current_user.role == 'manager' if !from_time.nil? && !to_time.nil? query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .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:%M") between ? and ?',from,to,from_time,to_time) + .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) .first() else query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') @@ -1704,7 +1704,7 @@ end if !shift.nil? if !from_time.nil? && !to_time.nil? query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .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:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) + .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) .first() else query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') @@ -1741,7 +1741,7 @@ end if current_user.nil? if !from_time.nil? && !to_time.nil? query = Sale.select("distinct sp.payment_method") - .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:%M") between ? and ?',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 ?',from,to,from_time,to_time) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") else query = Sale.select("distinct sp.payment_method") @@ -1752,7 +1752,7 @@ end if current_user.role == 'administrator' || current_user.role == 'manager' if !from_time.nil? && !to_time.nil? query = Sale.select("distinct sp.payment_method") - .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:%M") between ? and ?',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 ?',from,to,from_time,to_time) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") else query = Sale.select("distinct sp.payment_method") @@ -1764,7 +1764,7 @@ end if !shift.nil? if !from_time.nil? && !to_time.nil? query = Sale.select("distinct sp.payment_method") - .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:%M") between ? and ? 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 sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") else query = Sale.select("distinct sp.payment_method") @@ -1799,16 +1799,16 @@ end def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) time_query = '' if !from_time.nil? && !to_time.nil? - time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'" + time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" end if !from.nil? && !to.nil? if current_user.nil? if !from_time.nil? && !to_time.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - 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:%M") 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")',from,to,from_time,to_time) + 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 (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to,from_time,to_time) else - query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) end query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() else @@ -1825,9 +1825,9 @@ end if !from_time.nil? && !to_time.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - 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:%M") 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")',from,to,from_time,to_time) + 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 (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to,from_time,to_time) else - query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' 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:%M') between ? and ?",from,to,from_time,to_time) + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' 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) end query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() else @@ -1845,9 +1845,9 @@ end if !from_time.nil? && !to_time.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' - 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:%M") 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") and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + 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 (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) else - query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' 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:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' 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 sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) end query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() else @@ -1915,7 +1915,7 @@ end if !from_time.nil? && !to_time.nil? query = Sale.select("count(sales.customer_id) as total_dinein_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:%M") 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.customer_type = "Dinein" 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") @@ -1928,7 +1928,7 @@ end if !from_time.nil? && !to_time.nil? query = Sale.select("count(sales.customer_id) as total_dinein_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:%M") 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.customer_type = "Dinein" 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") @@ -1942,7 +1942,7 @@ end if !from_time.nil? && !to_time.nil? query = Sale.select("count(sales.customer_id) as total_dinein_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:%M") 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.customer_type = "Dinein" 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") @@ -1984,7 +1984,7 @@ end 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:%M") between ? and ? and c.customer_type = "Takeaway" 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_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") @@ -1997,7 +1997,7 @@ end 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:%M") between ? and ? and c.customer_type = "Takeaway" 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.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") @@ -2011,7 +2011,7 @@ end 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:%M") 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) + .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") @@ -2053,7 +2053,7 @@ end if !from_time.nil? && !to_time.nil? query = Sale.select("count(distinct sales.customer_id) as total_memb_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:%M") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not 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.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to,from_time,to_time) .first() else query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") @@ -2066,7 +2066,7 @@ end if !from_time.nil? && !to_time.nil? query = Sale.select("count(distinct sales.customer_id) as total_memb_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:%M") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not 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.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to,from_time,to_time) .first() else query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") @@ -2080,7 +2080,7 @@ end query = Sale.select("count(distinct sales.customer_id) as total_memb_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:%M") between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id).first() + 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 = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not 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 = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,shift.id).first() end @@ -2118,7 +2118,7 @@ end 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:%M") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) + 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) @@ -2129,7 +2129,7 @@ end 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:%M") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) + 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) @@ -2141,7 +2141,7 @@ end 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:%M") 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) + 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) @@ -2182,7 +2182,7 @@ end .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") .joins("JOIN orders as b ON b.order_id = a.order_id") if !from_time.nil? && !to_time.nil? - query = query.where('b.status = "billed" 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:%M") between ? and ?',from,to,from_time,to_time) + query = query.where('b.status = "billed" 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) .first() else query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) @@ -2194,7 +2194,7 @@ end .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") .joins("JOIN orders as b ON b.order_id = a.order_id") if !from_time.nil? && !to_time.nil? - query = query.where('b.status = "billed" 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:%M") between ? and ?',from,to,from_time,to_time) + query = query.where('b.status = "billed" 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) .first() else query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) @@ -2207,7 +2207,7 @@ end .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") .joins("JOIN orders as b ON b.order_id = a.order_id") if !from_time.nil? && !to_time.nil? - query = query.where('b.status = "billed" 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:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + query = query.where('b.status = "billed" 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 sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) .first() else query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) @@ -2261,7 +2261,7 @@ end .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_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:%M") between ? and ?',from,to,from_time,to_time) + 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 ?',from,to,from_time,to_time) 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 ?',from,to) end @@ -2272,7 +2272,7 @@ end .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_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:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + 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 sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) 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 sales.shift_sale_id=?',from,to,shift.id) end @@ -2310,7 +2310,7 @@ end query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' 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:%M') between ? and ?",from,to,from_time,to_time) + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' 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) .first() else query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) @@ -2321,7 +2321,7 @@ end query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' 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:%M') between ? and ?",from,to,from_time,to_time) + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' 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) .first() else query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) @@ -2333,7 +2333,7 @@ end query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' 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:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' 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 sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) .first() else query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) @@ -2373,7 +2373,7 @@ end query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and 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:%M') between ? and ?",from,to,from_time,to_time) + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and 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) else query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) end @@ -2385,7 +2385,7 @@ end query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and 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:%M') between ? and ?",from,to,from_time,to_time) + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and 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) else query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) end @@ -2398,7 +2398,7 @@ end query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and 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:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and 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 sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) else query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) end @@ -2444,7 +2444,7 @@ end if current_user.nil? query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' 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:%M') between ? and ?",from,to,from_time,to_time) + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' 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) .sum("a.qty") else query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) @@ -2454,7 +2454,7 @@ end if current_user.role == 'administrator' || current_user.role == 'manager' query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' 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:%M') between ? and ?",from,to,from_time,to_time) + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' 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) .sum("a.qty") else query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) @@ -2465,7 +2465,7 @@ end if !shift.nil? query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") if !from_time.nil? && !to_time.nil? - query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' 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:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' 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 sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) .sum("a.qty") else query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) From 30da4f37b32109520a6698f73715f2dbf4447de7 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Fri, 6 Apr 2018 17:51:00 +0630 Subject: [PATCH 07/10] Add Shop Name in Login Page --- app/assets/stylesheets/login.scss | 8 ++++++++ app/views/layouts/login_dashboard.html.erb | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/app/assets/stylesheets/login.scss b/app/assets/stylesheets/login.scss index ed0b36f9..aa743e4b 100755 --- a/app/assets/stylesheets/login.scss +++ b/app/assets/stylesheets/login.scss @@ -101,3 +101,11 @@ font-size: 111px; padding : 20px 0 20px 0; } + +/* Shop Name in Login Page */ +.current-shop-name{ + color : #FFFFFF; + font-size: 25px; + font-weight: bold; + margin : 0 0 25px 0; +} \ No newline at end of file diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index 329e9240..c660d906 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -65,6 +65,13 @@

+
+
+
+ <%= shop_detail.name %> +
+
+
From 460ed991af0008b6fafcd7c390ec785226b73a87 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Fri, 6 Apr 2018 18:16:20 +0630 Subject: [PATCH 08/10] Edit Addorder.js and Shop name --- app/assets/javascripts/addorder.js | 4 ---- app/assets/stylesheets/login.scss | 4 ++-- app/views/layouts/login.html.erb | 7 +++++++ app/views/layouts/login_dashboard.html.erb | 4 ++-- config/secrets.yml | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 9563131d..e49f7446 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -409,11 +409,7 @@ $(function() { +'
' $(".selected-set-list").append(set); }else{ -<<<<<<< HEAD - swal("Alert !", 'Maximum Qty is ' + max_qty + " items", "warning"); -======= swal("Alert !", 'Maximum Select is ' + max_qty + " items", "warning"); ->>>>>>> 8217b7c2f27f5b38b27425929d01b789da0583fd } // } $('#set_unit_price').text(price); diff --git a/app/assets/stylesheets/login.scss b/app/assets/stylesheets/login.scss index aa743e4b..a1058d25 100755 --- a/app/assets/stylesheets/login.scss +++ b/app/assets/stylesheets/login.scss @@ -105,7 +105,7 @@ /* Shop Name in Login Page */ .current-shop-name{ color : #FFFFFF; - font-size: 25px; + font-size: 21px; font-weight: bold; - margin : 0 0 25px 0; + margin : 0 0 20px 0; } \ No newline at end of file diff --git a/app/views/layouts/login.html.erb b/app/views/layouts/login.html.erb index e83a11d0..d6c6c955 100755 --- a/app/views/layouts/login.html.erb +++ b/app/views/layouts/login.html.erb @@ -79,6 +79,13 @@ Version - 1.0.1

+
+
+
+ <%= shop_detail.name %> +
+
+
<%= simple_form_for(@login_form, url: login_path, method: "post") do |f| %>
diff --git a/app/views/layouts/login_dashboard.html.erb b/app/views/layouts/login_dashboard.html.erb index c660d906..5db72f79 100755 --- a/app/views/layouts/login_dashboard.html.erb +++ b/app/views/layouts/login_dashboard.html.erb @@ -67,8 +67,8 @@
-
- <%= shop_detail.name %> +
+ <%= shop_detail.name %>
diff --git a/config/secrets.yml b/config/secrets.yml index 111e1843..076b6691 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -13,7 +13,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 sx_provision_url: connect.smartsales.dev/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api - server_mode: cloud + server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L From 74aa6caaab0d11b21b88350d8dd5e319d9d8b679 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Fri, 6 Apr 2018 18:19:47 +0630 Subject: [PATCH 09/10] For pull --- app/controllers/base_origami_controller.rb | 25 ++++--- app/controllers/origami/home_controller.rb | 11 +-- app/models/printer/cashier_station_printer.rb | 10 ++- app/models/printer/order_queue_printer.rb | 56 ++++++++++---- app/models/printer/receipt_printer.rb | 75 ++++++++++++++----- app/views/origami/home/index.html.erb | 4 + ...0180406080240_create_order_reservations.rb | 26 +++++++ ...06080359_create_order_reservation_items.rb | 25 +++++++ .../20180406080436_create_deliveries.rb | 18 +++++ 9 files changed, 197 insertions(+), 53 deletions(-) create mode 100644 db/migrate/20180406080240_create_order_reservations.rb create mode 100644 db/migrate/20180406080359_create_order_reservation_items.rb create mode 100644 db/migrate/20180406080436_create_deliveries.rb diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index b627ae01..86fb4ec3 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -16,8 +16,19 @@ class BaseOrigamiController < ActionController::Base end def check_user - if current_user.nil? - redirect_to root_path + token_status = false + authenticate_with_http_token do |token, options| + if token + token_status = true + session[:webview] = true + session[:session_token] = token + end + end + + if !token_status + if current_user.nil? + redirect_to root_path + end end end @@ -38,13 +49,9 @@ class BaseOrigamiController < ActionController::Base #check webview def check_mobile status = false - authenticate_with_http_token do |token, options| - if token - session[:webview] = true - end - session[:session_token] = token - end - + puts "check mobile" + puts session[:session_token] + puts session[:webview] if session[:webview] && request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i status = true end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 5ed006a1..8e00ef80 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -3,11 +3,7 @@ class Origami::HomeController < BaseOrigamiController before_action :set_dining, only: [:show] def index - @webview = false - if check_mobile - @webview = true - end - + @webview = check_mobile @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @@ -19,10 +15,7 @@ class Origami::HomeController < BaseOrigamiController # origami table detail def show - @webview = false - if check_mobile - @webview = true - end + @webview = check_mobile @tables = Table.all.active.order('status desc') @rooms = Room.all.active.order('status desc') diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index d4817346..63239cdc 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -8,7 +8,10 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker #Print pdf = CashierStationOpening.new pdf.render_file "tmp/cashier_station_#{order_id}_closing_#{time}.pdf" - self.print("tmp/cashier_station_#{order_id}_closing_#{time}.pdf") + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print("tmp/cashier_station_#{order_id}_closing_#{time}.pdf") + end end # def print_close_cashier(receipt_no) @@ -59,7 +62,10 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker end pdf.render_file filename - self.print(filename, cashier_terminal.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, cashier_terminal.printer_name) + end end #sqa end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 4a8b1653..62e6f0a7 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -39,14 +39,20 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker pdf.render_file filename if oqs.print_copy - self.print(filename, oqs.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end #For print copy # pdf.render_file filename.gsub(".","-copy.") # self.print(filename.gsub(".","-copy."), oqs.printer_name) else print_settings.print_copies = 1 print_settings.save! - self.print(filename, oqs.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end end # end end @@ -96,13 +102,19 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # pdf.render_file "tmp/order_item.pdf" pdf.render_file filename - if oqs.print_copy - self.print(filename, oqs.printer_name) - # self.print(filename.gsub(".","-copy."), oqs.printer_name) + if oqs.print_copy + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + # self.print(filename.gsub(".","-copy."), oqs.printer_name) + end else print_settings.print_copies = 1 print_settings.save! - self.print(filename, oqs.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end end #end end @@ -130,14 +142,20 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker pdf.render_file filename if oqs.print_copy - self.print(filename, oqs.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end #For print copy # pdf.render_file filename.gsub(".","-copy.") # self.print(filename.gsub(".","-copy."), oqs.printer_name) else print_settings.print_copies = 1 print_settings.save! - self.print(filename, oqs.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end end end end @@ -183,15 +201,20 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker pdf.render_file filename if oqs.print_copy - self.print(filename, oqs.printer_name) - + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end #For print copy # pdf.render_file filename.gsub(".","-copy.") # self.print(filename.gsub(".","-copy."), oqs.printer_name) else print_settings.print_copies = 1 print_settings.save! - self.print(filename, oqs.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end end #end end @@ -219,15 +242,20 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker pdf.render_file filename if oqs.print_copy - self.print(filename, oqs.printer_name) - + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end #For print copy # pdf.render_file filename.gsub(".","-copy.") # self.print(filename.gsub(".","-copy."), oqs.printer_name) else print_settings.print_copies = 1 print_settings.save! - self.print(filename, oqs.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end end end end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 26c31c6f..8562fca6 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -24,7 +24,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end end pdf.render_file "tmp/order_item_queue_#{order_id}_#{order_item_id}" + ".pdf" - self.print("tmp/receipt.pdf") + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print("tmp/receipt.pdf") + end end def print_receipt_payment_by_card(booking_id) @@ -52,8 +55,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end end pdf.render_file filename - - self.print(filename) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename) + end end def print_receipt_payment_by_account(sale_id) @@ -81,8 +86,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end end pdf.render_file filename - - self.print(filename) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename) + end end def print_receipt_payment_by_vochure(sale_id) @@ -110,8 +117,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end end pdf.render_file filename - - self.print(filename) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename) + end end def print_receipt_payment_by_giftcard(sale_id) @@ -139,8 +148,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end end pdf.render_file filename - - self.print(filename) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename) + end end def print_receipt_payment_by_foc(sale_id) @@ -168,8 +179,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end end pdf.render_file filename - - self.print(filename) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename) + end end #Bill Receipt Print @@ -205,13 +218,19 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf" pdf.render_file filename if printed_status != 'Paid' - self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name) + end end else filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" pdf.render_file filename if printed_status != 'Paid' - self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name) + end end end @@ -225,7 +244,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker def print_stock_check_result(print_settings,stockcheck, stockcheck_items,checker_name, shop_details) pdf = StockResultPdf.new(print_settings,stockcheck, stockcheck_items,checker_name, shop_details) pdf.render_file "tmp/print_stock_check_result.pdf" - self.print("tmp/print_stock_check_result.pdf") + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print("tmp/print_stock_check_result.pdf") + end end #Queue No Print @@ -235,7 +257,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Print pdf = QueueNoPdf.new(printer_settings,queue) pdf.render_file "tmp/print_queue_no.pdf" - self.print("tmp/print_queue_no.pdf") + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print("tmp/print_queue_no.pdf") + end end #Move Table Print @@ -255,7 +280,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Print pdf = CrmOrderPdf.new(booking,order_items,setting) pdf.render_file "tmp/print_crm_order.pdf" - self.print("tmp/print_crm_order.pdf") + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print("tmp/print_crm_order.pdf") + end end #Queue No Print @@ -265,7 +293,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Print pdf = CallWaiterPdf.new(printer_settings,table,time,shop_detail) pdf.render_file "tmp/print_call_waiter.pdf" - self.print("tmp/print_call_waiter.pdf") + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print("tmp/print_call_waiter.pdf") + end end #print receipt pdf from js @@ -276,10 +307,16 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker # else begin if count == 1 - self.print(filename, printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, printer_name) + end else filename = "public/receipts/receipt_bill_#{receipt_no}_#{count}.pdf" - self.print(filename, printer_name) + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, printer_name) + end end count -= 1 diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 38f0cc79..5e280697 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -140,7 +140,11 @@