Pull from master
This commit is contained in:
@@ -157,15 +157,25 @@ class DiningFacility < ApplicationRecord
|
||||
#Send to background job for processing
|
||||
# CheckInBookingJob.perform_later(table)
|
||||
#if ENV["SERVER_MODE"] != 'cloud'
|
||||
ActionCable.server.broadcast "check_in_booking_channel",table: table
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from
|
||||
#end
|
||||
end
|
||||
|
||||
def self.checkin_time
|
||||
table = DiningFacility.get_checkin_booking
|
||||
if table.length > 0
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
ActionCable.server.broadcast "checkin_channel",table: table
|
||||
ActionCable.server.broadcast "checkin_channel",table: table,from:from
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class DisplayImage < ApplicationRecord
|
||||
belongs_to :shop
|
||||
belongs_to :shop
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ class MenuCategory < ApplicationRecord
|
||||
validates_presence_of :code, :name, :menu, :order_by
|
||||
validates_uniqueness_of :code
|
||||
|
||||
default_scope { order('name asc') }
|
||||
default_scope { order('order_by asc') }
|
||||
scope :active, -> {where("is_available = 1")}
|
||||
|
||||
def self.destroyCategory(menu_category)
|
||||
|
||||
@@ -16,7 +16,7 @@ class MenuItem < ApplicationRecord
|
||||
validates_presence_of :item_code, :name, :type, :min_qty,:account_id
|
||||
validates_uniqueness_of :item_code
|
||||
|
||||
default_scope { order('name asc') }
|
||||
default_scope { order('item_code asc') }
|
||||
|
||||
scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') }
|
||||
scope :set_menu_item, -> { where(type: 'SetMenuItem') }
|
||||
|
||||
@@ -71,9 +71,9 @@ class Order < ApplicationRecord
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order => self})
|
||||
|
||||
#Send order to queue one it done!
|
||||
if self.source != "quick_service"
|
||||
process_order_queue
|
||||
end
|
||||
# if self.source != "quick_service"
|
||||
# process_order_queue
|
||||
# end
|
||||
|
||||
#send order to broadcast job
|
||||
send_order_broadcast(booking)
|
||||
@@ -108,9 +108,9 @@ class Order < ApplicationRecord
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order => self})
|
||||
|
||||
#Send order to queue one it done!
|
||||
if self.source != "quick_service"
|
||||
process_order_queue
|
||||
end
|
||||
# if self.source != "quick_service"
|
||||
# process_order_queue
|
||||
# end
|
||||
|
||||
#send order to broadcast job
|
||||
send_order_broadcast(booking)
|
||||
@@ -283,69 +283,7 @@ class Order < ApplicationRecord
|
||||
# Counter number of quantityf
|
||||
end
|
||||
|
||||
#Process order items and send to order queue
|
||||
def process_order_queue
|
||||
print_status = nil
|
||||
cup_status = nil
|
||||
|
||||
#Send to background job for processing
|
||||
order = Order.find(self.id)
|
||||
sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
||||
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
cup_status = `#{"sudo service cups status"}`
|
||||
print_status = check_cup_status(cup_status)
|
||||
end
|
||||
|
||||
if print_status
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, self.table_id, self.source)
|
||||
end
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
else
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
cup_start = `#{"sudo service cups start"}`
|
||||
cup_status = `#{"sudo service cups status"}`
|
||||
print_status = check_cup_status(cup_status)
|
||||
end
|
||||
|
||||
if print_status
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, self.table_id, self.source)
|
||||
end
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
else
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
|
||||
msg = ' Print Error ! Please contact to service'
|
||||
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error'
|
||||
end
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, self.table_id, self.source)
|
||||
end
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
|
||||
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#Process order items and send to order queue
|
||||
def self.pay_process_order_queue(id,table_id)
|
||||
# if ENV["SERVER_MODE"] != 'cloud'
|
||||
@@ -378,9 +316,13 @@ class Order < ApplicationRecord
|
||||
type = 'order'
|
||||
#Send to background job for processing
|
||||
# OrderBroadcastJob.perform_later(table,type)
|
||||
#if ENV["SERVER_MODE"] != 'cloud'
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type
|
||||
#end
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -534,11 +476,78 @@ class Order < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
#if ENV["SERVER_MODE"] != 'cloud'
|
||||
ActionCable.server.broadcast "second_display_channel",data: @data_array,status:@status
|
||||
#end
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "second_display_channel",data: @data_array,status:@status,from:from
|
||||
end
|
||||
|
||||
#Process order items and send to order queue
|
||||
# def process_order_queue
|
||||
# print_status = nil
|
||||
# cup_status = nil
|
||||
|
||||
# #Send to background job for processing
|
||||
# order = Order.find(self.id)
|
||||
# sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
||||
|
||||
# if ENV["SERVER_MODE"] != 'cloud'
|
||||
# cup_status = `#{"sudo service cups status"}`
|
||||
# print_status = check_cup_status(cup_status)
|
||||
# end
|
||||
|
||||
# if print_status
|
||||
# if !sidekiq.nil?
|
||||
# OrderQueueProcessorJob.perform_later(self.id, self.table_id)
|
||||
# else
|
||||
# if order
|
||||
# oqs = OrderQueueStation.new
|
||||
# oqs.process_order(order, self.table_id, self.source)
|
||||
# end
|
||||
# # assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
|
||||
# # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
# end
|
||||
# else
|
||||
# if ENV["SERVER_MODE"] != 'cloud'
|
||||
# cup_start = `#{"sudo service cups start"}`
|
||||
# cup_status = `#{"sudo service cups status"}`
|
||||
# print_status = check_cup_status(cup_status)
|
||||
# end
|
||||
|
||||
# if print_status
|
||||
# if !sidekiq.nil?
|
||||
# OrderQueueProcessorJob.perform_later(self.id, self.table_id)
|
||||
# else
|
||||
# if order
|
||||
# oqs = OrderQueueStation.new
|
||||
# oqs.process_order(order, self.table_id, self.source)
|
||||
# end
|
||||
# # assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
|
||||
# # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
# end
|
||||
# else
|
||||
# if ENV["SERVER_MODE"] != 'cloud'
|
||||
|
||||
# msg = ' Print Error ! Please contact to service'
|
||||
# ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error'
|
||||
# end
|
||||
# if !sidekiq.nil?
|
||||
# OrderQueueProcessorJob.perform_later(self.id, self.table_id)
|
||||
# else
|
||||
# if order
|
||||
# oqs = OrderQueueStation.new
|
||||
# oqs.process_order(order, self.table_id, self.source)
|
||||
# end
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def generate_custom_id
|
||||
|
||||
@@ -116,7 +116,19 @@ class OrderQueueStation < ApplicationRecord
|
||||
order = Order.find(order_id)
|
||||
order_items = order.order_items
|
||||
|
||||
Order.pay_process_order_queue(order_id,table_id)
|
||||
# Order.pay_process_order_queue(order_id,table_id)
|
||||
# if order
|
||||
# oqs = OrderQueueStation.new
|
||||
# oqs.process_order(order, table_id)
|
||||
# end
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
|
||||
|
||||
if table_id.to_i > 0
|
||||
# get dining
|
||||
dining = DiningFacility.find(table_id)
|
||||
|
||||
@@ -317,9 +317,15 @@ class OrderReservation < ApplicationRecord
|
||||
end
|
||||
order_reservation = OrderReservation.where("status='new'")
|
||||
if order_reservation.length > 0
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
ActionCable.server.broadcast "check_new_order_channel",data: order_reservation, shop_code: shop_code
|
||||
end
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
ActionCable.server.broadcast "check_new_order_channel",data: order_reservation, shop_code: shop_code,from:from
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
# if ENV["SERVER_MODE"] == 'cloud'
|
||||
# ActionCable.server.broadcast "check_new_order_channel",data: order_reservation, shop_code: shop_code
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -332,9 +338,15 @@ class OrderReservation < ApplicationRecord
|
||||
end
|
||||
order_reservation = OrderReservation.where("status='accepted' and requested_time <= '#{Time.now.utc}'")
|
||||
if order_reservation.length > 0
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
ActionCable.server.broadcast "check_order_send_to_kitchen_channel",data: order_reservation, shop_code: shop_code
|
||||
end
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
ActionCable.server.broadcast "check_order_send_to_kitchen_channel",data: order_reservation, shop_code: shop_code,from:from
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
# if ENV["SERVER_MODE"] == 'cloud'
|
||||
# ActionCable.server.broadcast "check_order_send_to_kitchen_channel",data: order_reservation, shop_code: shop_code
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -347,9 +359,15 @@ class OrderReservation < ApplicationRecord
|
||||
end
|
||||
order_reservation = OrderReservation.where("status='send_to_kitchen' and requested_time <= '#{Time.now.utc}'")
|
||||
if order_reservation.length > 0
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
ActionCable.server.broadcast "check_order_ready_to_delivery_channel",data: order_reservation, shop_code: shop_code
|
||||
end
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
ActionCable.server.broadcast "check_order_ready_to_delivery_channel",data: order_reservation, shop_code: shop_code,from:from
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
# if ENV["SERVER_MODE"] == 'cloud'
|
||||
# ActionCable.server.broadcast "check_order_ready_to_delivery_channel",data: order_reservation, shop_code: shop_code
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -136,7 +136,9 @@ class Promotion < ApplicationRecord
|
||||
else
|
||||
item = OrderItem.find_by_item_code(promo_product)
|
||||
end
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion", item.price)
|
||||
source = Order.find(item.order_id).source
|
||||
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion", item.price,source)
|
||||
|
||||
puts "Charged - " + charge_qty.to_s
|
||||
puts "FOC - " + foc_qty.to_s
|
||||
@@ -150,10 +152,12 @@ class Promotion < ApplicationRecord
|
||||
promotion_qty = foc_qty
|
||||
end
|
||||
item = OrderItem.find_by_item_instance_code(promo_product)
|
||||
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price,source)
|
||||
end
|
||||
|
||||
def self.update_existing_item(qty, item, sale_id, type, item_price)
|
||||
|
||||
def self.update_existing_item(qty, item, sale_id, type, item_price,source)
|
||||
|
||||
sale_item = SaleItem.new
|
||||
sale_item.product_code = item.item_code
|
||||
@@ -171,50 +175,54 @@ class Promotion < ApplicationRecord
|
||||
sale_item.sale_id = sale_id
|
||||
sale_item.save
|
||||
sale = Sale.find(sale_id)
|
||||
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount)
|
||||
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount,nil,source)
|
||||
end
|
||||
|
||||
|
||||
def self.give_promotion_nett_off(same, promo_product, foc_min_qty, orderitem, sale_id)
|
||||
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
||||
|
||||
|
||||
if same
|
||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
||||
else
|
||||
foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
|
||||
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
||||
end
|
||||
end
|
||||
|
||||
def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, sale_id)
|
||||
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
||||
|
||||
if same
|
||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||
item = OrderItem.find_by_item_instance_code(orderitem[0]) # need to specify with menu item instance
|
||||
price = item.price.to_i - promo_product.net_price.to_i
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
|
||||
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
||||
else
|
||||
foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
|
||||
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
||||
price = item.price - promo_product.net_price
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
||||
end
|
||||
end
|
||||
|
||||
def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, sale_id)
|
||||
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
||||
|
||||
if same
|
||||
foc_qty = orderitem[1].to_i / foc_min_qty
|
||||
item = OrderItem.find_by_item_instance_code(orderitem[0])
|
||||
# total = orderitem[1].to_i * item.price
|
||||
total = item.price
|
||||
price = calculate_discount(total, promo_product.percentage)
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
|
||||
else
|
||||
foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
|
||||
# give total qty is 1
|
||||
@@ -224,7 +232,8 @@ class Promotion < ApplicationRecord
|
||||
# total = item.price * foc_qty
|
||||
total = item.price
|
||||
price = calculate_discount(total, promo_product.percentage)
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price)
|
||||
source = Order.find(item.order_id).source
|
||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -425,6 +425,7 @@ class Sale < ApplicationRecord
|
||||
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||
customer = Customer.find(sale.customer_id)
|
||||
# #Creat new tax records
|
||||
|
||||
if sale.payment_status != 'foc'
|
||||
tax_profiles.each do |tax|
|
||||
# customer.tax_profiles.each do |cus_tax|
|
||||
@@ -456,28 +457,27 @@ class Sale < ApplicationRecord
|
||||
sale_tax.save
|
||||
end
|
||||
else
|
||||
sale_tax = SaleTax.new(:sale => sale)
|
||||
sale_tax.tax_name = tax.name
|
||||
sale_tax.tax_rate = tax.rate
|
||||
sale_tax = SaleTax.new(:sale => sale)
|
||||
sale_tax.tax_name = tax.name
|
||||
sale_tax.tax_rate = tax.rate
|
||||
|
||||
# substract , to give after discount
|
||||
total_tax = total_taxable - total_discount
|
||||
#include or execulive
|
||||
if tax.inclusive
|
||||
rate = tax.rate
|
||||
divided_value = (100 + rate)/rate
|
||||
sale_tax.tax_payable_amount = total_tax / divided_value
|
||||
else
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||
end
|
||||
#new taxable amount is standard rule for step by step
|
||||
if shop.calc_tax_order
|
||||
total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||
end
|
||||
|
||||
sale_tax.inclusive = tax.inclusive
|
||||
sale_tax.save
|
||||
# substract , to give after discount
|
||||
total_tax = total_taxable - total_discount
|
||||
#include or execulive
|
||||
if tax.inclusive
|
||||
rate = tax.rate
|
||||
divided_value = (100 + rate)/rate
|
||||
sale_tax.tax_payable_amount = total_tax / divided_value
|
||||
else
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||
end
|
||||
#new taxable amount is standard rule for step by step
|
||||
if shop.calc_tax_order
|
||||
total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||
end
|
||||
sale_tax.inclusive = tax.inclusive
|
||||
sale_tax.save
|
||||
end
|
||||
end
|
||||
# end
|
||||
@@ -2542,32 +2542,32 @@ 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:%i') between ? and ?",from,to,from_time,to_time)
|
||||
.sum("a.qty")
|
||||
query = query.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name 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)
|
||||
.count()
|
||||
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)
|
||||
.sum("a.qty")
|
||||
query = query.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.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' || 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)
|
||||
.sum("a.qty")
|
||||
query = query.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name 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)
|
||||
.count()
|
||||
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)
|
||||
.sum("a.qty")
|
||||
query = query.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to)
|
||||
.count()
|
||||
end
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
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:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id)
|
||||
.sum("a.qty")
|
||||
query = query.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name 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)
|
||||
.count()
|
||||
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)
|
||||
.sum("a.qty")
|
||||
query = query.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name 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)
|
||||
.count()
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2575,19 +2575,19 @@ end
|
||||
else
|
||||
if current_user.nil?
|
||||
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")
|
||||
.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||
.count()
|
||||
else
|
||||
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")
|
||||
.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||
.count()
|
||||
else
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if !shift.nil?
|
||||
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') = ? and sales.shift_sale_id=?",today,shift.id)
|
||||
.sum("a.qty")
|
||||
.where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id)
|
||||
.count()
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2697,7 +2697,7 @@ end
|
||||
end
|
||||
|
||||
def self.all_receipts
|
||||
query = Sale.select("sale_payments.created_at as receipt_close_time,
|
||||
query = Sale.select("sales.*,sale_payments.created_at as receipt_close_time,
|
||||
case when (sale_audits.action='SALEPAYMENT') then sale_audits.remark else 0 end as remark,
|
||||
case when (sale_taxes.tax_name='Service Charges') then sale_taxes.tax_payable_amount else 0 end as service_charges,
|
||||
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
|
||||
|
||||
@@ -609,7 +609,12 @@ class SalePayment < ApplicationRecord
|
||||
#Send to background job for processing
|
||||
# OrderBroadcastJob.perform_later(table,type)
|
||||
#if ENV["SERVER_MODE"] != 'cloud'
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
from = request.subdomain + "." + request.domain
|
||||
else
|
||||
from = ""
|
||||
end
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
||||
#end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user