diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js index 033f521b..1668e17f 100755 --- a/app/assets/javascripts/cable.js +++ b/app/assets/javascripts/cable.js @@ -8,13 +8,7 @@ // Temp Disable (function() { this.App || (this.App = {}); - - // var hostname = location.hostname; - // var port = location.port; - // var host = hostname + ":" + port + "/cable" - // console.log(host); - // App.cable = ActionCable.createConsumer(); - // console.log(App.cable); + App.cable = ActionCable.createConsumer(); }).call(this); diff --git a/app/assets/javascripts/channels/bill.js b/app/assets/javascripts/channels/bill.js index 97666e32..7fa2b77e 100755 --- a/app/assets/javascripts/channels/bill.js +++ b/app/assets/javascripts/channels/bill.js @@ -6,15 +6,19 @@ App.order = App.cable.subscriptions.create('BillChannel', { disconnected: function() {}, received: function(data) { - if($('.table_'+data.table.id).hasClass('blue')){ - $('.table_'+data.table.id).removeClass('blue'); - $('.table_'+data.table.id).addClass('red'); - }else{ - $('.table_'+data.table.id).removeClass('orange'); - $('.table_'+data.table.id).addClass('red'); - } - $('.new_text_'+data.table.id).removeClass('hide'); - $('.new_text_'+data.table.id).text('billed'); + var hostname = location.hostname.trim(); + if(data.from == "" || hostname == data.from) + { + if($('.table_'+data.table.id).hasClass('blue')){ + $('.table_'+data.table.id).removeClass('blue'); + $('.table_'+data.table.id).addClass('red'); + }else{ + $('.table_'+data.table.id).removeClass('orange'); + $('.table_'+data.table.id).addClass('red'); + } + $('.new_text_'+data.table.id).removeClass('hide'); + $('.new_text_'+data.table.id).text('billed'); + } } }); diff --git a/app/assets/javascripts/channels/check_new_order.js b/app/assets/javascripts/channels/check_new_order.js index ced5b3c2..f4d4aa9f 100644 --- a/app/assets/javascripts/channels/check_new_order.js +++ b/app/assets/javascripts/channels/check_new_order.js @@ -19,7 +19,9 @@ App.check_new_order = App.cable.subscriptions.create('CheckNewOrderChannel', { }); // alert(order_lists); - checkNewOrderAlert(shop_code, order_lists); + if (typeof checkNewOrderAlert !== 'undefined' && $.isFunction(checkNewOrderAlert)) { + checkNewOrderAlert(shop_code, order_lists); + } // $("#notify_new_order_lists").text(order_lists); // if($("#"+shop_code+"_notify_new_order").hasClass("hidden")){ // $("#"+shop_code+"_notify_new_order").removeClass("hidden"); diff --git a/app/assets/javascripts/channels/check_order_ready_to_delivery.js b/app/assets/javascripts/channels/check_order_ready_to_delivery.js index 4ec3ea08..3f7f53b1 100644 --- a/app/assets/javascripts/channels/check_order_ready_to_delivery.js +++ b/app/assets/javascripts/channels/check_order_ready_to_delivery.js @@ -19,7 +19,9 @@ App.check_order_ready_to_delivery = App.cable.subscriptions.create('CheckOrderRe }); // alert(order_lists); - checkOrderReadyToKitchenAlert(shop_code, order_lists); + if (typeof checkOrderReadyToKitchenAlert !== 'undefined' && $.isFunction(checkOrderReadyToKitchenAlert)) { + checkOrderReadyToKitchenAlert(shop_code, order_lists); + } // $("#notify_order_ready_to_delivery_lists").text(order_lists); // if($("#notify_order_ready_to_delivery").hasClass("hidden")){ // $("#"+shop_code+"_notify_order_ready_to_delivery").removeClass("hidden"); diff --git a/app/assets/javascripts/channels/check_order_send_to_kitchen.js b/app/assets/javascripts/channels/check_order_send_to_kitchen.js index 5e8751b1..892e0590 100644 --- a/app/assets/javascripts/channels/check_order_send_to_kitchen.js +++ b/app/assets/javascripts/channels/check_order_send_to_kitchen.js @@ -19,7 +19,9 @@ App.check_order_send_to_kitchen = App.cable.subscriptions.create('CheckOrderSend }); // alert(order_lists); - checkOrderSendToKitchen(shop_code, order_lists); + if (typeof checkOrderSendToKitchen !== 'undefined' && $.isFunction(checkOrderSendToKitchen)) { + checkOrderSendToKitchen(shop_code, order_lists); + } // $("#notify_order_send_to_kitchen_lists").text(order_lists); // if($("#notify_order_send_to_kitchen").hasClass("hidden")){ // $("#"+shop_code+"_notify_order_send_to_kitchen").removeClass("hidden"); diff --git a/app/assets/javascripts/order_reservation.js b/app/assets/javascripts/order_reservation.js index fb210f6b..1a1e6e64 100644 --- a/app/assets/javascripts/order_reservation.js +++ b/app/assets/javascripts/order_reservation.js @@ -308,13 +308,26 @@ function show_order_detail(url,sr_no){ item_price = items[i].unit_price; } var total = items[i].qty * item_price; + if(items[i].options!='[]'){ + row = '' + +''+items[i].item_name + +'
' + +' '+items[i].options+'
'+ + ''+items[i].qty+ ' X'+items[i].unit_price+'' + +'' + +''+ total +'' + +''; + }else{ row = '' - +''+items[i].item_name - +'
'+items[i].qty+ ' X'+items[i].unit_price+'' - +'' - +''+ total +'' - +''; - $('.summary-items').append(row); + +''+items[i].item_name + +'
'+ + ''+items[i].qty+ ' X'+items[i].unit_price+'' + +'' + +''+ total +'' + +''; + } + + $('.summary-items').append(row); } if(data.discount_amount > 0){ @@ -565,5 +578,5 @@ function getOrderMonth(month){ function getOrderDay(day){ var DAYS = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]; - return DAYS[day]; + return DAYS[day - 1]; } \ No newline at end of file diff --git a/app/channels/order_channel.rb b/app/channels/order_channel.rb index d261e48b..6f899707 100755 --- a/app/channels/order_channel.rb +++ b/app/channels/order_channel.rb @@ -1,5 +1,5 @@ class OrderChannel < ApplicationCable::Channel - def subscribed + def subscribed stream_from "order_channel" end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 0c50a5da..3d2c90aa 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -38,10 +38,13 @@ class Origami::RequestBillsController < ApplicationController # Promotion Activation Promotion.promo_activate(@sale) - #bill channel - #if ENV["SERVER_MODE"] != 'cloud' - ActionCable.server.broadcast "bill_channel",table: table - #end + #bill channel + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain + "." + request.domain + else + from = "" + end + ActionCable.server.broadcast "bill_channel",table: table, from: from if order.source == "quick_service" result = {:status=> @status, :data => @sale.sale_id } render :json => result.to_json diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 0f27567a..b9b2c5d4 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -52,7 +52,7 @@ class Origami::SaleEditController < BaseOrigamiController end # FOr Sale Audit action_by = current_user.name - if access_code != "null" + if access_code != "null" && current_user.role == "cashier" action_by = Employee.find_by_emp_id(access_code).name end remark = "Void Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}" @@ -88,7 +88,7 @@ class Origami::SaleEditController < BaseOrigamiController order = Order.find(order_id) action_by = current_user.name - if access_code != "null" + if access_code != "null" && current_user.role == "cashier" action_by = Employee.find_by_emp_id(access_code).name end remark = "FOC Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}Receipt No #{saleObj.receipt_no}" @@ -132,7 +132,7 @@ class Origami::SaleEditController < BaseOrigamiController saleitemObj.taxable_price = update_qty.to_f * update_price.to_f action_by = current_user.name - if access_code != "null" + if access_code != "null" && current_user.role == "cashier" action_by = Employee.find_by_emp_id(access_code).name end remark = "Update Qty #{update_qty} Price [#{saleitemObj.price}]| Receipt No #{sale.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}" @@ -185,7 +185,7 @@ class Origami::SaleEditController < BaseOrigamiController order = Order.find(order_id) action_by = current_user.name - if access_code != "null" + if access_code != "null" && current_user.role == "cashier" action_by = Employee.find_by_emp_id(access_code).name end remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}" diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 45676492..891cd398 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -73,7 +73,7 @@ class Origami::VoidController < BaseOrigamiController # FOr Sale Audit action_by = current_user.name - if access_code != "null" + if access_code != "null" && current_user.role == "cashier" action_by = Employee.find_by_emp_id(access_code).name end diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb index 9cfde698..d008a54d 100755 --- a/app/controllers/origami/waste_spoile_controller.rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -55,7 +55,7 @@ class Origami::WasteSpoileController < BaseOrigamiController # FOr Sale Audit action_by = current_user.name - if access_code != "null" + if access_code != "null" && current_user.role == "cashier" action_by = Employee.find_by_emp_id(access_code).name end # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 057f6f9b..0b4ccc77 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -53,7 +53,7 @@ class OrderReservation < ApplicationRecord order_reservation = OrderReservation.new order_reservation.order_reservation_type = order_reserve[:order_type] order_reservation.customer_id = order_reserve[:cus_info] - order_reservation.requested_time = Time.parse(order_reserve[:requested_time]).utc + order_reservation.requested_time = Time.zone.parse(order_reserve[:requested_time]).utc order_reservation.callback_url = order_reserve[:callback_url] order_reservation.transaction_ref = order_reserve[:reference] if order_reserve[:order_info] diff --git a/app/models/sale.rb b/app/models/sale.rb index a5533031..6f7817bc 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1294,7 +1294,7 @@ end query = query.group('mi.name') .order("SUM(i.qty) DESC").limit(20) else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") @@ -1335,7 +1335,7 @@ end .group('mi.name') .order("SUM(i.qty) DESC").limit(20) else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") @@ -1375,7 +1375,7 @@ end query = query.group('mi.name') .order("SUM(i.qty) ASC").limit(20) else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") @@ -1416,7 +1416,7 @@ end .group('mi.name') .order("SUM(i.qty) ASC").limit(20) else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") @@ -1452,7 +1452,7 @@ end query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") .order('receipt_date') else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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) @@ -1470,7 +1470,7 @@ end 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 - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') end end @@ -1479,20 +1479,20 @@ end if current_user.nil? query = Sale.select("grand_total") .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) - .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("grand_total") .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) - .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("grand_total") .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) - .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') end end @@ -1513,7 +1513,7 @@ end query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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? @@ -1546,7 +1546,7 @@ end .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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") .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'") @@ -1575,7 +1575,7 @@ end 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 current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time).sum("grand_total") else @@ -1596,14 +1596,14 @@ end end else if current_user.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total") + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today).sum("grand_total") else - if current_user.role == 'administrator' || current_user.role == 'manager' - total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total") + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today).sum("grand_total") else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',today,today,shift.id) .sum("grand_total") end end @@ -1620,7 +1620,7 @@ end 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 current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time).count else @@ -1639,14 +1639,14 @@ end end else if current_user.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',today,today).count else - if current_user.role == 'administrator' || current_user.role == 'manager' - total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',today,today).count else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id = ?',today,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 shift_sale_id = ?',today,today,shift.id).count end end end @@ -1666,7 +1666,7 @@ end .sum("sp.payment_amount") end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',from,to,from_time,to_time) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") @@ -1693,18 +1693,18 @@ end end else if current_user.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today,today) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else - if current_user.role == 'administrator' || current_user.role == 'manager' - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today) + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today,today) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and shift_sale_id=?',today,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 (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay") and shift_sale_id=?',today,today,shift.id) .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .sum("sp.payment_amount") end @@ -1726,7 +1726,7 @@ end .sum("payment_amount") end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") @@ -1753,18 +1753,18 @@ end end else if current_user.nil? - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today) + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") else - if current_user.role == 'administrator' || current_user.role == 'manager' - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today) + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ? and s.shift_sale_id=?',today,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 s.shift_sale_id=?',today,today,shift.id) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") end @@ -1786,7 +1786,7 @@ end .first() end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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:%i") between ? and ?',from,to,from_time,to_time) @@ -1814,18 +1814,18 @@ end else if current_user.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(receipt_date,"%Y-%m-%d") = ?',today) + .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) .first() else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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(receipt_date,"%Y-%m-%d") = ?',today) + .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) .first() else shift = ShiftSale.current_open_shift(current_user.id) if !shift.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(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) + .where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) .first() end end @@ -1846,7 +1846,7 @@ end .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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:%i") between ? and ?',from,to,from_time,to_time) @@ -1874,18 +1874,18 @@ end else if current_user.nil? query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") end end @@ -1918,7 +1918,7 @@ 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() end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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' @@ -1969,7 +1969,7 @@ end 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 - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")',today) @@ -2021,7 +2021,7 @@ end .first() end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? query = Sale.select("count(sales.customer_id) as total_dinein_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") @@ -2054,20 +2054,20 @@ end if current_user.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(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) .first() else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) .first() else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("count(sales.customer_id) as total_dinein_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) .first() end end @@ -2090,7 +2090,7 @@ end .first() end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' if !from_time.nil? && !to_time.nil? query = Sale.select("count(sales.customer_id) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") @@ -2123,20 +2123,20 @@ end if current_user.nil? query = Sale.select("count(sales.customer_id) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) .first() else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("count(sales.customer_id) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) .first() else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("count(sales.customer_id) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) .first() end end @@ -2159,7 +2159,7 @@ end .first() end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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") @@ -2188,20 +2188,20 @@ end if current_user.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(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today) .first() else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today) .first() else shift = ShiftSale.current_open_shift(current_user.id) if !shift.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(sales.receipt_date,"%Y-%m-%d") = ? 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=?',today,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and ((c.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=?',today,shift.id) .first() end end @@ -2222,7 +2222,7 @@ end .first() end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("count(sales.customer_id) as total_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") if !from_time.nil? && !to_time.nil? @@ -2251,20 +2251,20 @@ end if current_user.nil? query = Sale.select("count(sales.customer_id) as total_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) .first() else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("count(sales.customer_id) as total_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) .first() else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("count(sales.customer_id) as total_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) .first() end end @@ -2286,7 +2286,7 @@ end .first() end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("count(distinct a.order_id) as total_order") .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") @@ -2318,14 +2318,14 @@ end query = Sale.select("count(distinct a.order_id) as total_order") .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") - .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) .first() else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("count(distinct a.order_id) as total_order") .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") - .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) .first() else shift = ShiftSale.current_open_shift(current_user.id) @@ -2333,7 +2333,7 @@ end query = Sale.select("count(distinct a.order_id) as total_order") .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") - .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) + .where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) .first() end end @@ -2353,7 +2353,7 @@ end 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 else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("distinct b.id as account_id, b.title as title") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_id") @@ -2381,20 +2381,20 @@ end query = Sale.select("distinct b.id as account_id, b.title as title") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.select("distinct b.id as account_id, b.title as title") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? query = Sale.select("distinct b.id as account_id, b.title as title") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) end end end @@ -2414,7 +2414,7 @@ end .first() end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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? @@ -2446,7 +2446,7 @@ end .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .first() else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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") .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) @@ -2478,7 +2478,7 @@ end .order("SUM(a.qty) DESC") .first() else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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? @@ -2514,7 +2514,7 @@ end .order("SUM(a.qty) DESC") .first() else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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") .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) @@ -2548,7 +2548,7 @@ end .sum("a.qty") end else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' 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:%i') between ? and ?",from,to,from_time,to_time) @@ -2577,7 +2577,7 @@ end .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .sum("a.qty") else - if current_user.role == 'administrator' || current_user.role == 'manager' + if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .sum("a.qty") diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 5c1f8c01..7dc29463 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -532,7 +532,7 @@ class ReceiptBillPdf < Prawn::Document break; end end - if sale_data.payment_status == "foc" + if sale_data.payment_status == "foc" || sale_data.payment_status == "waste" || sale_data.payment_status == "spoile" y_position = cursor stroke_horizontal_rule @@ -540,12 +540,19 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 70 stroke_horizontal_rule - end + end - bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - move_down 73 - text "Acknowledged By" , :size => self.item_font_size,:align => :center - end + if sale_data.payment_status == "foc" + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 73 + text "Acknowledged By" , :size => self.item_font_size,:align => :center + end + elsif sale_data.payment_status == "waste" || sale_data.payment_status == "spoile" + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 73 + text "Approved By" , :size => self.item_font_size,:align => :center + end + end end end diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 865202b0..6131e656 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -119,7 +119,7 @@
- <% if current_user.role == 'administrator' || current_user.role == 'manager' %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' %>
@@ -176,9 +176,9 @@
<% end %> - <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'cashier' %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'cashier' %> <% if !@summ_sale.nil? %> - <% if current_user.role == 'administrator' || current_user.role == 'manager' %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' %>
@@ -249,12 +249,12 @@
- <% if current_user.role == 'administrator' || current_user.role == 'manager' %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' %>
<% end %> <% end %> - <% if current_user.role == 'administrator' || current_user.role == 'manager' %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' %>
<% else %> @@ -298,11 +298,11 @@
<% end %>
- <% if current_user.role == 'administrator' || current_user.role == 'manager' %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' %>
<% end %> - <% if current_user.role == 'administrator' || current_user.role == 'manager' %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' %>
<% else %> @@ -349,7 +349,7 @@
- <% if current_user.role == 'administrator' || current_user.role == 'manager' %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' %> <% end %> <% end %> diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index c9b681b8..99120a0b 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -14,7 +14,7 @@
- <%= f.input :adult, input_html: { value: @survey_data.adult, class: 'col-md-10', :onChange => "total_customer();" }%> + <%= f.input :adult, input_html: { value: @survey_data.adult, class: 'col-md-10', :onkeyup => "total_customer();" }%>
@@ -332,10 +332,34 @@ var cashier_type = "<%= @cashier_type %>"; case 'num': var input_value = $(this).attr("data-value"); if (original_value == "0.0"){ - $('.addfocus').val(input_value); + var value = $('.addfocus').val(input_value); + if ($("#survey_child").hasClass('addfocus')){ + var child = $("#survey_child").val()+value; + var adult = $("#survey_adult").val() || 0; + var result = parseInt(child) + parseInt(adult); + $("#survey_total_customer").val(result); + } + if ($("#survey_adult").hasClass('addfocus')){ + var adult = $("#survey_adult").val()+value; + var child = $("#survey_child").val() || 0; + var result = parseInt(child) + parseInt(adult); + $("#survey_total_customer").val(result); + } } else{ - $('.addfocus').val(original_value + '' + input_value); + var value = $('.addfocus').val(original_value + '' + input_value); + if ($("#survey_child").hasClass('addfocus')){ + var child = $("#survey_child").val()+value; + var adult = $("#survey_adult").val() || 0; + var result = parseInt(child) + parseInt(adult); + $("#survey_total_customer").val(result); + } + if ($("#survey_adult").hasClass('addfocus')){ + var adult = $("#survey_adult").val()+value; + var child = $("#survey_child").val() || 0; + var result = parseInt(child) + parseInt(adult); + $("#survey_total_customer").val(result); + } } break; @@ -351,7 +375,18 @@ var cashier_type = "<%= @cashier_type %>"; break; case 'clr': - $('.addfocus').val(""); + $('.addfocus').val(""); + if($("#survey_child").hasClass('addfocus')){ + $("#survey_child").val(""); + var adult = $("#survey_adult").val() || 0; + var result = parseInt(adult); + $("#survey_total_customer").val(result); + }else if($("#survey_adult").hasClass('addfocus')){ + $("#survey_adult").val(""); + var child = $("#survey_child").val() || 0; + var result = parseInt(child); + $("#survey_total_customer").val(result); + } break; } event.handled = true; @@ -464,4 +499,6 @@ var cashier_type = "<%= @cashier_type %>"; var result = parseInt(child) + parseInt(adult); $("#survey_total_customer").val(result); } + + \ No newline at end of file diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index b84bca54..e0eb7455 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -20,11 +20,11 @@ class ActionController::Base end else #check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end + if check_license + current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path + end end end