update for order process
Add activereocrd-import gem for bulk insert
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -44,6 +44,9 @@ gem 'rack-cors'
|
|||||||
# Multi-tenancy for shops
|
# Multi-tenancy for shops
|
||||||
gem 'acts_as_tenant'
|
gem 'acts_as_tenant'
|
||||||
|
|
||||||
|
# Activerecord-Import is a library for bulk inserting data using ActiveRecord.
|
||||||
|
gem 'activerecord-import'
|
||||||
|
|
||||||
# image upload
|
# image upload
|
||||||
gem 'carrierwave', '~> 1.0'
|
gem 'carrierwave', '~> 1.0'
|
||||||
gem 'mini_magick'
|
gem 'mini_magick'
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ GEM
|
|||||||
activemodel (= 5.1.7)
|
activemodel (= 5.1.7)
|
||||||
activesupport (= 5.1.7)
|
activesupport (= 5.1.7)
|
||||||
arel (~> 8.0)
|
arel (~> 8.0)
|
||||||
|
activerecord-import (1.0.3)
|
||||||
|
activerecord (>= 3.2)
|
||||||
activesupport (5.1.7)
|
activesupport (5.1.7)
|
||||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||||
i18n (>= 0.7, < 2)
|
i18n (>= 0.7, < 2)
|
||||||
@@ -320,6 +322,7 @@ PLATFORMS
|
|||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
activerecord-import
|
||||||
acts_as_tenant
|
acts_as_tenant
|
||||||
aescrypt
|
aescrypt
|
||||||
axlsx (= 2.0.1)
|
axlsx (= 2.0.1)
|
||||||
|
|||||||
@@ -288,6 +288,10 @@ For Number Formats
|
|||||||
=> settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros,
|
=> settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros,
|
||||||
value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] }
|
value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] }
|
||||||
|
|
||||||
|
For Booking checkin time limit
|
||||||
|
settings/lookups =>
|
||||||
|
{ lookup_type: checkin_time_limit, name: CheckinTimeLimit, value: total hours before checkout (e.g., '48')) }
|
||||||
|
|
||||||
/* Customer Types in lookups */
|
/* Customer Types in lookups */
|
||||||
1) settings/lookups => { type:customer_type, name: Dinein, value:Dinein }
|
1) settings/lookups => { type:customer_type, name: Dinein, value:Dinein }
|
||||||
2) settings/lookups => { type:customer_type, name: Takeaway, value: Takeaway }
|
2) settings/lookups => { type:customer_type, name: Takeaway, value: Takeaway }
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
render :json => { :status => false, :error_message => "Operation failed!" }
|
render :json => { :status => false, :error_message => "Operation failed!" }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
booking = dining_facility.get_current_checkout_booking
|
booking = dining_facility.current_checkout_booking
|
||||||
if booking.nil?
|
if booking.nil?
|
||||||
lookup_checkout_time = Lookup.collection_of("checkout_time")
|
lookup_checkout_time = Lookup.collection_of("checkout_time")
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Oqs::HomeController < BaseOqsController
|
|||||||
zone_id = qid.zone_id
|
zone_id = qid.zone_id
|
||||||
i=i+1
|
i=i+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i })
|
@queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i })
|
||||||
end
|
end
|
||||||
@@ -57,14 +57,6 @@ class Oqs::HomeController < BaseOqsController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# booking_id = dining.get_new_booking
|
|
||||||
# BookingOrder.where("booking_id='#{ booking_id }'").find_each do |bo|
|
|
||||||
# order=Order.find(bo.order_id);
|
|
||||||
# order.order_items.each do |oi|
|
|
||||||
# items.push(oi)
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
render :json => items.to_json
|
render :json => items.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -88,7 +80,7 @@ class Oqs::HomeController < BaseOqsController
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Query for OQS with delivery status
|
# Query for OQS with delivery status
|
||||||
def queue_items_query(status)
|
def queue_items_query(status)
|
||||||
AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type as type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at")
|
AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type as type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at")
|
||||||
.joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id
|
.joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id
|
||||||
left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id
|
left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id
|
||||||
|
|||||||
@@ -38,10 +38,11 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
@booking = @table.get_booking
|
@booking = @table.get_booking
|
||||||
if @booking
|
if @booking
|
||||||
@booking_id = @booking.booking_id
|
@booking_id = @booking.booking_id
|
||||||
@obj_order = @booking.orders.first
|
if @obj_order = @booking.orders.first
|
||||||
@customer = @obj_order.customer
|
@customer = @obj_order.customer
|
||||||
@date = @obj_order.created_at
|
@date = @obj_order.created_at
|
||||||
@order_items = @booking.order_items
|
@order_items = @booking.order_items
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -108,21 +109,21 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
items_arr = []
|
items_arr = []
|
||||||
JSON.parse(params[:order_items]).each { |i|
|
JSON.parse(params[:order_items]).each { |i|
|
||||||
i["item_instance_code"] = i["item_instance_code"].downcase.to_s
|
i["item_instance_code"] = i["item_instance_code"].downcase.to_s
|
||||||
if i["item_instance_code"].include? "ext"
|
if i["item_instance_code"].include? "ext"
|
||||||
is_extra_time = true
|
is_extra_time = true
|
||||||
arr_exts = i["item_instance_code"].split("_")
|
arr_exts = i["item_instance_code"].split("_")
|
||||||
if arr_exts[1].match(/^(\d)+$/)
|
if arr_exts[1].match(/^(\d)+$/)
|
||||||
time = arr_exts[1].to_i*60*i["quantity"].to_i
|
time = arr_exts[1].to_i*60*i["quantity"].to_i
|
||||||
extra_time = Time.at(time)
|
extra_time = Time.at(time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if i["parent_order_item_id"];
|
if i["parent_order_item_id"]
|
||||||
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
|
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
|
||||||
else
|
else
|
||||||
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
|
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
|
||||||
end
|
end
|
||||||
items_arr.push(items)
|
items_arr.push(items)
|
||||||
}
|
}
|
||||||
# begin
|
# begin
|
||||||
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0
|
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0
|
||||||
customer_id = "CUS-000000000002" # for no customer id from mobile
|
customer_id = "CUS-000000000002" # for no customer id from mobile
|
||||||
@@ -159,16 +160,13 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
table = DiningFacility.find(@booking.dining_facility_id)
|
table = DiningFacility.find(@booking.dining_facility_id)
|
||||||
type = 'order'
|
type = 'order'
|
||||||
from = getCloudDomain #get sub domain in cloud mode
|
from = getCloudDomain #get sub domain in cloud mode
|
||||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
ActionCable.server.broadcast "order_channel", table: table,type:type,from:from
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:order_source] != "quick_service" && params[:order_source] != "food_court"
|
if params[:order_source] != "quick_service" && params[:order_source] != "food_court"
|
||||||
process_order_queue(@order.order_id,@order.table_id,@order.source)
|
process_order_queue(@order.order_id,@order.table_id,@order.source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# Order.send_customer_view(@booking)
|
||||||
# Order.send_customer_view(@booking)
|
|
||||||
|
|
||||||
if current_user.role != "waiter" && params[:create_type] == "create_pay"
|
if current_user.role != "waiter" && params[:create_type] == "create_pay"
|
||||||
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
|
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
|
||||||
@@ -232,66 +230,34 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process_order_queue(order_id,table_id,order_source)
|
def process_order_queue(order_id,table_id,order_source)
|
||||||
print_status = nil
|
#Send to background job for processing
|
||||||
cup_status = nil
|
order = Order.find(order_id)
|
||||||
|
sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
||||||
|
|
||||||
#Send to background job for processing
|
if ENV["SERVER_MODE"] != 'cloud'
|
||||||
order = Order.find(order_id)
|
cup_status = `#{"sudo service cups status"}`
|
||||||
sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
if !check_cup_status(cup_status)
|
||||||
if ENV["SERVER_MODE"] != 'cloud'
|
cup_start = `#{"sudo service cups start"}`
|
||||||
cup_status = `#{"sudo service cups status"}`
|
cup_status = `#{"sudo service cups status"}`
|
||||||
print_status = check_cup_status(cup_status)
|
if !check_cup_status(cup_status)
|
||||||
end
|
from = ''
|
||||||
|
msg = 'Print Error ! Please contact to service'
|
||||||
if print_status
|
ActionCable.server.broadcast "call_waiter_channel", table: msg, time:'print_error', from: from
|
||||||
if !sidekiq.nil?
|
|
||||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
|
||||||
else
|
|
||||||
if order
|
|
||||||
oqs = OrderQueueStation.new
|
|
||||||
oqs.process_order(order, table_id, order_source)
|
|
||||||
end
|
|
||||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_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(order_id, table_id)
|
|
||||||
else
|
|
||||||
if order
|
|
||||||
oqs = OrderQueueStation.new
|
|
||||||
oqs.process_order(order, table_id, order_source)
|
|
||||||
end
|
|
||||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
|
||||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if ENV["SERVER_MODE"] != 'cloud'
|
|
||||||
from = ""
|
|
||||||
msg = ' Print Error ! Please contact to service'
|
|
||||||
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error',from:from
|
|
||||||
end
|
|
||||||
if !sidekiq.nil?
|
|
||||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
|
||||||
else
|
|
||||||
if order
|
|
||||||
oqs = OrderQueueStation.new
|
|
||||||
oqs.process_order(order, table_id, order_source)
|
|
||||||
end
|
|
||||||
|
|
||||||
from = getCloudDomain #get sub domain in cloud mode
|
|
||||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
|
||||||
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if !sidekiq.nil?
|
||||||
|
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||||
|
else
|
||||||
|
if order
|
||||||
|
oqs = OrderQueueStation.new
|
||||||
|
oqs.process_order(order, table_id, order_source)
|
||||||
|
end
|
||||||
|
from = getCloudDomain #get sub domain in cloud mode
|
||||||
|
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||||
|
ActionCable.server.broadcast "order_queue_station_channel", order: assign_order, from: from
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_cup_status(status)
|
def check_cup_status(status)
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ class Origami::HomeController < BaseOrigamiController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@webview = check_mobile
|
@webview = check_mobile
|
||||||
|
@tables = Table.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).all.active.order('status desc')
|
||||||
@tables = Table.unscope(:order).includes(:zone).all.active.order('status desc')
|
@rooms = Room.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).all.active.order('status desc')
|
||||||
@rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc')
|
|
||||||
@complete = Sale.completed_sale("cashier")
|
@complete = Sale.completed_sale("cashier")
|
||||||
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
|
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
|
||||||
|
|
||||||
@@ -22,8 +21,8 @@ class Origami::HomeController < BaseOrigamiController
|
|||||||
@print_settings = PrintSetting.get_precision_delimiter()
|
@print_settings = PrintSetting.get_precision_delimiter()
|
||||||
@webview = check_mobile
|
@webview = check_mobile
|
||||||
|
|
||||||
@tables = Table.unscope(:order).includes(:zone).all.active.order('status desc')
|
@tables = Table.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).all.active.order('status desc')
|
||||||
@rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc')
|
@rooms = Room.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).all.active.order('status desc')
|
||||||
@complete = Sale.completed_sale("cashier")
|
@complete = Sale.completed_sale("cashier")
|
||||||
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
|
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
|
||||||
@customers = Customer.pluck("customer_id, name")
|
@customers = Customer.pluck("customer_id, name")
|
||||||
@@ -36,75 +35,41 @@ class Origami::HomeController < BaseOrigamiController
|
|||||||
@shop = shop_detail
|
@shop = shop_detail
|
||||||
@membership = MembershipSetting::MembershipSetting
|
@membership = MembershipSetting::MembershipSetting
|
||||||
@payment_methods = PaymentMethodSetting.all
|
@payment_methods = PaymentMethodSetting.all
|
||||||
@dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ")
|
@dining_booking = @dining.current_bookings
|
||||||
#@dining_booking = @dining.bookings.active.where("created_at between '#{DateTime.now.utc - 12.hours}' and '#{DateTime.now.utc}'")
|
|
||||||
@order_items = Array.new
|
@order_items = Array.new
|
||||||
@dining_booking.each do |booking|
|
@dining_booking.each do |booking|
|
||||||
if booking.sale_id.nil? && booking.booking_status != 'moved'
|
if @obj_sale || @booking.blank?
|
||||||
@order_items = Array.new
|
@booking = booking
|
||||||
# @assigned_order_items = Array.new
|
end
|
||||||
if booking.booking_orders.empty?
|
|
||||||
@booking = booking
|
if booking.sale_id
|
||||||
else
|
@obj_sale = booking.sale
|
||||||
booking.booking_orders.each do |booking_order|
|
@sale_array.push(@obj_sale)
|
||||||
order = Order.find(booking_order.order_id)
|
@sale_taxes = @obj_sale.sale_taxes
|
||||||
if (order.status == "new")
|
@status_sale = 'sale'
|
||||||
@obj_order = order
|
else
|
||||||
@customer = order.customer
|
@order_items += booking.order_items
|
||||||
@date = order.created_at
|
@obj_order = booking.orders.first
|
||||||
@booking= booking
|
end
|
||||||
order.order_items.each do |item|
|
|
||||||
@order_items.push(item)
|
if @obj_sale || @customer.blank?
|
||||||
# assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id)
|
if obj = @obj_sale || @obj_order
|
||||||
# if !assigned_order_items.nil?
|
@customer = obj.customer
|
||||||
# @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id})
|
@date = obj.created_at
|
||||||
# end
|
|
||||||
end
|
|
||||||
@account_arr = Array.new
|
|
||||||
if @customer.tax_profiles
|
|
||||||
accounts = @customer.tax_profiles
|
|
||||||
@account_arr =[]
|
|
||||||
accounts.each do |acc|
|
|
||||||
account = TaxProfile.find_by_id(acc)
|
|
||||||
if !account.nil?
|
|
||||||
@account_arr.push(account)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@status_order = 'order'
|
|
||||||
else
|
|
||||||
sale = Sale.find(booking.sale_id)
|
|
||||||
if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste'
|
|
||||||
@sale_array.push(sale)
|
|
||||||
if @status_order == 'order'
|
|
||||||
@status_order = 'sale'
|
|
||||||
end
|
|
||||||
@booking= booking
|
|
||||||
@date = sale.created_at
|
|
||||||
@status_sale = 'sale'
|
|
||||||
@obj_sale = sale
|
|
||||||
@customer = sale.customer
|
|
||||||
accounts = @customer.tax_profiles
|
|
||||||
@account_arr =[]
|
|
||||||
accounts.each do |acc|
|
|
||||||
account = TaxProfile.find_by_id(acc)
|
|
||||||
if !account.nil?
|
|
||||||
@account_arr.push(account)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@sale_taxes = []
|
|
||||||
sale_taxes = SaleTax.where("sale_id = ?", sale.sale_id)
|
|
||||||
if !sale_taxes.empty?
|
|
||||||
sale_taxes.each do |sale_tax|
|
|
||||||
@sale_taxes.push(sale_tax)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @obj_sale
|
||||||
|
@status_order = 'sale'
|
||||||
|
else
|
||||||
|
@status_order = 'order'
|
||||||
|
end
|
||||||
|
|
||||||
|
if (@obj_sale || @account_arr.blank?) && @customer
|
||||||
|
@account_arr = TaxProfile.find_by(id: @customer.tax_profiles)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#for bank integration
|
#for bank integration
|
||||||
@checkout_time = Lookup.collection_of('checkout_time')
|
@checkout_time = Lookup.collection_of('checkout_time')
|
||||||
|
|||||||
@@ -31,100 +31,72 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
#shop detail
|
||||||
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
## shop_detail = Shop.current_shop
|
||||||
# Print for First Bill to Customer
|
# customer= Customer.where('customer_id=' +.customer_id)
|
||||||
unique_code = "ReceiptBillPdf"
|
customer = Customer.find(sale_data.customer_id)
|
||||||
print_settings = PrintSetting.all
|
# rounding adjustment
|
||||||
if !print_settings.nil?
|
if shop_detail.is_rounding_adj
|
||||||
print_settings.each do |setting|
|
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
|
||||||
if setting.unique_code == 'ReceiptBillPdf'
|
rounding_adj = new_total - sale_data.grand_total
|
||||||
unique_code = "ReceiptBillPdf"
|
sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
|
||||||
elsif setting.unique_code == 'ReceiptBillStarPdf'
|
end
|
||||||
unique_code = "ReceiptBillStarPdf"
|
#end rounding adjustment
|
||||||
end
|
#record for sale audit
|
||||||
end
|
action_by = current_user.name
|
||||||
|
type = "FIRST_BILL"
|
||||||
|
|
||||||
|
remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}"
|
||||||
|
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
|
||||||
|
# get member information
|
||||||
|
rebate = MembershipSetting.find_by_rebate(1)
|
||||||
|
if customer.membership_id != nil && rebate
|
||||||
|
# member_info = Customer.get_member_account(customer)
|
||||||
|
# current_balance = SaleAudit.paymal_search(sale_id)
|
||||||
|
current_balance = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
# find order id by sale id
|
||||||
|
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
|
||||||
|
|
||||||
|
# Calculate price_by_accounts
|
||||||
|
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items)
|
||||||
|
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
|
||||||
|
|
||||||
|
other_amount = SaleItem.calculate_other_charges(sale_items)
|
||||||
|
|
||||||
|
print_settings = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first
|
||||||
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||||
|
|
||||||
|
#TODO :: KBZPAY ( QR )
|
||||||
|
# On/Off setting ( show or not qr )
|
||||||
|
# qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD"
|
||||||
|
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
|
||||||
|
|
||||||
|
status = false
|
||||||
|
qr = nil
|
||||||
|
|
||||||
|
if !kbz_pay_method.nil?
|
||||||
|
if kbz_pay_method.is_active == true
|
||||||
|
sale_payment = SalePayment.new
|
||||||
|
sale_payment.process_kbz_payment(sale_id, sale_data.grand_total, 0, 'pending')
|
||||||
|
|
||||||
|
status, qr = KbzPay.pay(sale_data.grand_total.to_i, sale_payment.sale_payment_id, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if !receipt_bill_a5_pdf.empty?
|
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil)
|
||||||
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
|
||||||
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
|
||||||
if receipt_bilA5[1] == '1'
|
|
||||||
unique_code = "ReceiptBillA5Pdf"
|
|
||||||
else
|
|
||||||
unique_code = unique_code#{}"ReceiptBillPdf"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
#shop detail
|
result = {
|
||||||
## shop_detail = Shop.current_shop
|
:filepath => filename,
|
||||||
# customer= Customer.where('customer_id=' +.customer_id)
|
:printer_model => print_settings.brand_name,
|
||||||
customer = Customer.find(sale_data.customer_id)
|
:printer_url => print_settings.api_settings
|
||||||
# rounding adjustment
|
}
|
||||||
if shop_detail.is_rounding_adj
|
|
||||||
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
|
|
||||||
rounding_adj = new_total - sale_data.grand_total
|
|
||||||
sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
|
|
||||||
end
|
|
||||||
#end rounding adjustment
|
|
||||||
#record for sale audit
|
|
||||||
action_by = current_user.name
|
|
||||||
type = "FIRST_BILL"
|
|
||||||
|
|
||||||
remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}"
|
# status, qr = KbzPay.query(sale_payment.sale_payment_id)
|
||||||
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
|
|
||||||
# get member information
|
|
||||||
rebate = MembershipSetting.find_by_rebate(1)
|
|
||||||
if customer.membership_id != nil && rebate
|
|
||||||
# member_info = Customer.get_member_account(customer)
|
|
||||||
# current_balance = SaleAudit.paymal_search(sale_id)
|
|
||||||
current_balance = 0
|
|
||||||
end
|
|
||||||
# get printer info
|
|
||||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
||||||
|
|
||||||
# find order id by sale id
|
# Mobile Print
|
||||||
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
|
render :json => result.to_json
|
||||||
|
|
||||||
# Calculate price_by_accounts
|
|
||||||
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items)
|
|
||||||
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
|
|
||||||
|
|
||||||
other_amount = SaleItem.calculate_other_charges(sale_items)
|
|
||||||
|
|
||||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
|
||||||
|
|
||||||
#TODO :: KBZPAY ( QR )
|
|
||||||
# On/Off setting ( show or not qr )
|
|
||||||
# qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD"
|
|
||||||
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
|
|
||||||
|
|
||||||
status = false
|
|
||||||
qr = nil
|
|
||||||
|
|
||||||
if !kbz_pay_method.nil?
|
|
||||||
if kbz_pay_method.is_active == true
|
|
||||||
sale_payment = SalePayment.new
|
|
||||||
sale_payment.process_kbz_payment(sale_id, sale_data.grand_total, 0, 'pending')
|
|
||||||
|
|
||||||
status, qr = KbzPay.pay(sale_data.grand_total.to_i, sale_payment.sale_payment_id, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil)
|
|
||||||
|
|
||||||
result = {
|
|
||||||
:filepath => filename,
|
|
||||||
:printer_model => print_settings.brand_name,
|
|
||||||
:printer_url => print_settings.api_settings
|
|
||||||
}
|
|
||||||
|
|
||||||
# status, qr = KbzPay.query(sale_payment.sale_payment_id)
|
|
||||||
|
|
||||||
# Mobile Print
|
|
||||||
render :json => result.to_json
|
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ class AssignedOrderItem < ApplicationRecord
|
|||||||
|
|
||||||
def self.assigned_order_item_by_job(order_id)
|
def self.assigned_order_item_by_job(order_id)
|
||||||
order_item = AssignedOrderItem.select("assigned_order_items.assigned_order_item_id,
|
order_item = AssignedOrderItem.select("assigned_order_items.assigned_order_item_id,
|
||||||
assigned_order_items.order_queue_station_id,
|
assigned_order_items.order_queue_station_id,
|
||||||
oqs.id as station_id, oqs.station_name,
|
oqs.id as station_id, oqs.station_name,
|
||||||
oqs.is_active, oqpz.zone_id,
|
oqs.is_active, oqpz.zone_id,
|
||||||
df.name as zone, df.type as table_type,
|
df.name as zone, df.type as table_type,
|
||||||
odt.order_id, odt.item_code, odt.item_instance_code, odt.item_name,
|
odt.order_id, odt.item_code, odt.item_instance_code, odt.item_name,
|
||||||
odt.price, odt.qty, odt.item_order_by, odt.options,
|
odt.price, odt.qty, odt.item_order_by, odt.options,
|
||||||
cus.name as customer_name, odt.created_at")
|
cus.name as customer_name, odt.created_at")
|
||||||
.joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id
|
.joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id
|
||||||
left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id
|
left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id
|
||||||
@@ -62,6 +62,11 @@ class AssignedOrderItem < ApplicationRecord
|
|||||||
return order_item
|
return order_item
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
def self.generate_ids(count = 1)
|
||||||
|
SeedGenerator.generate_ids(self.name, "AOI", count)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def generate_custom_id
|
def generate_custom_id
|
||||||
if self.assigned_order_item_id.nil?
|
if self.assigned_order_item_id.nil?
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ class Booking < ApplicationRecord
|
|||||||
has_many :booking_orders
|
has_many :booking_orders
|
||||||
has_many :orders, :through => :booking_orders
|
has_many :orders, :through => :booking_orders
|
||||||
has_many :order_items, :through => :orders
|
has_many :order_items, :through => :orders
|
||||||
|
|
||||||
scope :active, -> {where("booking_status != 'moved'")}
|
scope :active, -> {where("booking_status != 'moved'")}
|
||||||
scope :today, -> {where("created_at >= #{Time.now.utc}")}
|
scope :today, -> {where("created_at >= #{Time.now.utc}")}
|
||||||
|
scope :assign, -> { where(booking_status: 'assign')}
|
||||||
|
scope :within_time_limit, -> { where(checkin_at: Lookup.get_checkin_time_limit.hours.ago..DateTime::Infinity.new) }
|
||||||
|
|
||||||
def self.sync_booking_records(bookings)
|
def self.sync_booking_records(bookings)
|
||||||
if !bookings.nil?
|
if !bookings.nil?
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ class DiningFacility < ApplicationRecord
|
|||||||
has_many :dining_charges
|
has_many :dining_charges
|
||||||
has_many :in_juties
|
has_many :in_juties
|
||||||
|
|
||||||
|
has_many :bookings
|
||||||
|
has_many :current_bookings, -> { left_joins(:sale).assign.within_time_limit.merge(Booking.where(checkout_at: nil).or(Booking.merge(Sale.where(sale_status: ['new', nil])))) }, class_name: "Booking"
|
||||||
|
has_one :current_checkin_booking, -> { assign.within_time_limit.where(checkout_at: nil) }, class_name: "Booking"
|
||||||
|
has_one :current_checkout_booking, -> { left_joins(:sale).assign.within_time_limit.where.not(checkout_at: nil).merge(Sale.where(sale_status: ['new', nil])) }, class_name: "Booking"
|
||||||
|
has_one :current_reserved_booking, -> { left_joins(:sale).assign.within_time_limit.where.not(reserved_at: nil).merge(Sale.where(sale_status: nil)) }, class_name: "Booking"
|
||||||
|
|
||||||
TABLE_TYPE = "Table"
|
TABLE_TYPE = "Table"
|
||||||
ROOM_TYPE = "Room"
|
ROOM_TYPE = "Room"
|
||||||
|
|
||||||
@@ -21,7 +27,7 @@ class DiningFacility < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_booking
|
def get_booking
|
||||||
booking = self.get_current_booking
|
booking = self.current_checkin_booking
|
||||||
if booking
|
if booking
|
||||||
if booking.dining_facility_id.to_i == self.id
|
if booking.dining_facility_id.to_i == self.id
|
||||||
if booking.booking_status == 'assign'
|
if booking.booking_status == 'assign'
|
||||||
@@ -36,23 +42,8 @@ class DiningFacility < ApplicationRecord
|
|||||||
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null
|
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_moved_booking
|
|
||||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
|
||||||
Booking.where(dining_facility_id: self.id, booking_status: 'moved', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_new_booking
|
|
||||||
# query for new
|
|
||||||
Booking.where(dining_facility_id: self.id, booking_status: 'assign', sale_id: nil, checkout_at: nil).first
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_current_checkout_booking
|
|
||||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
|
||||||
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_checkout_booking
|
def get_checkout_booking
|
||||||
booking = self.get_current_checkout_booking
|
booking = self.current_reserved_booking
|
||||||
if booking
|
if booking
|
||||||
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
|
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
|
||||||
free_time_min = 0
|
free_time_min = 0
|
||||||
@@ -91,7 +82,7 @@ class DiningFacility < ApplicationRecord
|
|||||||
|
|
||||||
def self.get_checkin_booking
|
def self.get_checkin_booking
|
||||||
checkin_time_lookup = Lookup.get_checkin_time_limit
|
checkin_time_lookup = Lookup.get_checkin_time_limit
|
||||||
bookings = Booking.where(booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago)
|
bookings = self.current_checkin_booking
|
||||||
arr_booking = Array.new
|
arr_booking = Array.new
|
||||||
if bookings
|
if bookings
|
||||||
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
|
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class Lookup < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.collection_of(type)
|
def self.collection_of(type)
|
||||||
Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] }
|
Lookup.where("lookup_type" => type ).pluck("name, value")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_shift_sale_lookup
|
def self.create_shift_sale_lookup
|
||||||
|
|||||||
@@ -31,26 +31,24 @@ class MenuItem < ApplicationRecord
|
|||||||
|
|
||||||
# Work with item_code = item_instance_code
|
# Work with item_code = item_instance_code
|
||||||
def self.search_by_item_code(item_code)
|
def self.search_by_item_code(item_code)
|
||||||
menu_item_hash = Hash.new
|
MenuItem.joins(:menu_item_instances)
|
||||||
mt_instance = MenuItemInstance.find_by_item_instance_code(item_code)
|
.where(menu_item_instances: {item_instance_code: item_code})
|
||||||
if (!mt_instance.nil?)
|
.pluck(:type, :account_id, :item_code, :item_instance_code, :name, :alt_name, "menu_item_instances.item_instance_name AS item_instance_name", :price, :promotion_price, :is_on_promotion, "menu_item_instances.is_available", :taxable)
|
||||||
menu_item = MenuItem.find(mt_instance.menu_item_id)
|
.map { |type, account_id, item_code, item_instance_code, item_name, item_alt_name, item_instance_name, price, promotion_price, is_on_promotion, is_available, taxable|
|
||||||
menu_item_hash[:type] = menu_item.type
|
{
|
||||||
menu_item_hash[:account_id] = menu_item.account_id
|
type: type,
|
||||||
menu_item_hash[:item_code] = menu_item.item_code
|
account_id: account_id,
|
||||||
menu_item_hash[:item_instance_code] = mt_instance.item_instance_code
|
item_code: item_code,
|
||||||
menu_item_hash[:name] = menu_item.name.to_s + " - " + mt_instance.item_instance_name.to_s
|
item_instance_code: item_instance_code,
|
||||||
menu_item_hash[:alt_name] = menu_item.alt_name.to_s # + " - " + mt_instance.item_instance_name.to_s
|
name: item_name.to_s + (' - ' + item_instance_name.to_s) || '',
|
||||||
menu_item_hash[:price] = mt_instance.price
|
alt_name: item_alt_name || '',
|
||||||
menu_item_hash[:promotion_price] = mt_instance.promotion_price
|
price: price,
|
||||||
menu_item_hash[:is_on_promotion] = mt_instance.is_on_promotion
|
promotion_price: promotion_price,
|
||||||
menu_item_hash[:is_available] = mt_instance.is_available
|
is_on_promotion: is_on_promotion,
|
||||||
menu_item_hash[:taxable] = menu_item.taxable
|
is_available: is_available,
|
||||||
|
taxable: taxable
|
||||||
return menu_item_hash
|
}
|
||||||
end
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.deleteRecursive(menu_item)
|
def self.deleteRecursive(menu_item)
|
||||||
|
|||||||
@@ -26,16 +26,11 @@ class Order < ApplicationRecord
|
|||||||
def generate
|
def generate
|
||||||
booking = nil
|
booking = nil
|
||||||
if self.new_booking
|
if self.new_booking
|
||||||
if self.table_id.to_i > 0
|
|
||||||
table_id = self.table_id
|
|
||||||
else
|
|
||||||
table_id = nil
|
|
||||||
end
|
|
||||||
#add extra time
|
#add extra time
|
||||||
if self.is_extra_time && self.extra_time
|
if self.is_extra_time && self.extra_time
|
||||||
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
|
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
|
||||||
:checkin_at => Time.now.utc,:checkout_at => Time.now.utc + self.extra_time.to_i,
|
:checkin_at => Time.now.utc, :checkout_at => Time.now.utc + self.extra_time.to_i,
|
||||||
:checkin_by => self.employee_name,
|
:checkin_by => self.employee_name,
|
||||||
:booking_status => "assign" })
|
:booking_status => "assign" })
|
||||||
else
|
else
|
||||||
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
|
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
|
||||||
@@ -50,7 +45,6 @@ class Order < ApplicationRecord
|
|||||||
# table.status = "occupied"
|
# table.status = "occupied"
|
||||||
# table.save
|
# table.save
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
booking = Booking.find(self.booking_id)
|
booking = Booking.find(self.booking_id)
|
||||||
#add extra time
|
#add extra time
|
||||||
@@ -70,7 +64,7 @@ class Order < ApplicationRecord
|
|||||||
|
|
||||||
self.adding_line_items
|
self.adding_line_items
|
||||||
#Add Order Table and Room relation afrer order creation
|
#Add Order Table and Room relation afrer order creation
|
||||||
BookingOrder.create({:booking_id => booking.booking_id, :order => self})
|
booking.orders << self
|
||||||
|
|
||||||
#Send order to queue one it done!
|
#Send order to queue one it done!
|
||||||
# if self.source != "quick_service"
|
# if self.source != "quick_service"
|
||||||
@@ -107,7 +101,7 @@ class Order < ApplicationRecord
|
|||||||
|
|
||||||
self.adding_line_items
|
self.adding_line_items
|
||||||
#Add Order Table and Room relation afrer order creation
|
#Add Order Table and Room relation afrer order creation
|
||||||
BookingOrder.create({:booking_id => booking.booking_id, :order => self})
|
booking.orders << self
|
||||||
|
|
||||||
#Send order to queue one it done!
|
#Send order to queue one it done!
|
||||||
# if self.source != "quick_service"
|
# if self.source != "quick_service"
|
||||||
@@ -118,7 +112,6 @@ class Order < ApplicationRecord
|
|||||||
send_order_broadcast(booking)
|
send_order_broadcast(booking)
|
||||||
|
|
||||||
return true, booking
|
return true, booking
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@@ -133,49 +126,49 @@ class Order < ApplicationRecord
|
|||||||
def adding_line_items
|
def adding_line_items
|
||||||
if self.items
|
if self.items
|
||||||
#re-order to
|
#re-order to
|
||||||
ordered_list = re_order_items(self.items)
|
items = re_order_items(self.items)
|
||||||
|
|
||||||
#loop to add all items to order
|
#loop to add all items to order
|
||||||
ordered_list.each do |item|
|
item_instance_codes = items.map { |i| i[:item_instance_code] }
|
||||||
|
menu_items = MenuItem.search_by_item_code(item_instance_codes)
|
||||||
|
menu_items += Product.search_by_product_code(item_instance_codes) if menu_items.length < item_instance_codes.length
|
||||||
|
|
||||||
menu_item = MenuItem.search_by_item_code(item[:item_instance_code])
|
new_order_items = []
|
||||||
|
items.each do |order_item|
|
||||||
# For Product while item code not in menu item
|
menu_item = menu_items.find { |i| i[:item_instance_code].downcase == order_item[:item_instance_code].downcase }
|
||||||
if menu_item.nil?
|
sub_order_items = []
|
||||||
menu_item = Product.search_by_product_code(item[:item_instance_code])
|
if order_item[:sub_items].length > 0
|
||||||
end
|
sub_menu_items = MenuItem.search_by_item_code(order_item[:sub_items].map { |i| i[:item_instance_code] })
|
||||||
|
order_item[:sub_items].each do |sub_order_item|
|
||||||
#if (!menu_item.nil?)
|
sub_menu_item = sub_menu_items.find { |i| i[:item_instance_code] == sub_order_item[:item_instance_code] }
|
||||||
# Rails.logger.debug menu_item
|
sub_order_items << { item_instance_code: sub_order_item[:item_instance_code], item_instance_name: sub_menu_item[:name], quantity: sub_order_item[:quantity], price: sub_menu_item[:price], options: sub_order_item[:options] }
|
||||||
set_order_items = Array.new
|
|
||||||
##If menu Item set item - must add child items to order as well, where price is only take from menu_item
|
|
||||||
if (menu_item[:type] == "SetMenuItem")
|
|
||||||
if (item.include? 'sub_items') || (item.include? :sub_items)
|
|
||||||
item[:sub_items].each do |si|
|
|
||||||
# Retrive instance's Price
|
|
||||||
set_item = MenuItem.search_by_item_code(si[:item_instance_code])
|
|
||||||
set_order_items.push({"item_instance_code"=>si[:item_instance_code], "item_instance_name"=>set_item[:name], "quantity"=>si[:quantity], "price"=>set_item[:price], "options"=>si[:options]})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
set_order_items = set_order_items.to_json
|
|
||||||
else
|
|
||||||
set_order_items = nil
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
sub_order_items = sub_order_items.to_json
|
||||||
|
new_order_items << OrderItem.new({
|
||||||
|
order_id: id,
|
||||||
|
item_code: menu_item[:item_code],
|
||||||
|
item_instance_code: order_item[:item_instance_code],
|
||||||
|
item_name: menu_item[:name],
|
||||||
|
alt_name: menu_item[:alt_name],
|
||||||
|
account_id: menu_item[:account_id],
|
||||||
|
qty: order_item[:quantity],
|
||||||
|
price: menu_item[:price],
|
||||||
|
options: order_item[:options],
|
||||||
|
set_menu_items: sub_order_items,
|
||||||
|
item_order_by: employee_name,
|
||||||
|
taxable: menu_item[:taxable]
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
# not insert with price 0
|
ids = OrderItem.generate_ids(new_order_items.length)
|
||||||
# puts item[:price]
|
new_order_items.each_with_index do |order_item, index|
|
||||||
# puts item
|
order_item.order_items_id = ids[index]
|
||||||
# if(item[:price] != 0 )
|
end
|
||||||
# OrderItem.processs_item(menu_item[:item_code], menu_item[:name], menu_item[:account_id],
|
|
||||||
# item[:quantity],menu_item[:price], item[:options], set_order_items, self.id,
|
|
||||||
# self.employee_name)
|
|
||||||
# end
|
|
||||||
|
|
||||||
OrderItem.processs_item(menu_item[:item_code], item[:item_instance_code], menu_item[:name], menu_item[:alt_name], menu_item[:account_id],
|
OrderItem.import new_order_items, validate: false
|
||||||
item[:quantity],menu_item[:price], item[:options], set_order_items, self.id,
|
|
||||||
self.employee_name, menu_item[:taxable])
|
|
||||||
|
|
||||||
#end
|
new_order_items.each do |order_item|
|
||||||
|
order_item.run_callbacks(:save) { true }
|
||||||
end
|
end
|
||||||
|
|
||||||
self.item_count = self.order_items.count
|
self.item_count = self.order_items.count
|
||||||
@@ -186,7 +179,6 @@ class Order < ApplicationRecord
|
|||||||
self.errors.add(:order_items, :blank, message: "Order items cannot be blank")
|
self.errors.add(:order_items, :blank, message: "Order items cannot be blank")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_items_status_to_billed(items)
|
def update_items_status_to_billed(items)
|
||||||
@@ -213,66 +205,8 @@ class Order < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def re_order_items(form_items) #reorder inputs items as parents and child
|
def re_order_items(items) #reorder inputs items as parents and child
|
||||||
parent_id = Array.new
|
new_items = items.select { |i| i[:parent_order_item_id].blank? }.map { |x| x[:sub_items] = items.select { |y| x[:order_item_id] == y[:parent_order_item_id] }; x }
|
||||||
parents = Array.new
|
|
||||||
parents_and_children_items = Array.new
|
|
||||||
|
|
||||||
new_items_list = Array.new
|
|
||||||
|
|
||||||
form_items.each do |parent|
|
|
||||||
if !parent[:parent_order_item_id].nil?
|
|
||||||
if (!parent_id.include?(parent[:parent_order_item_id]))
|
|
||||||
parent_id.push(parent[:parent_order_item_id])
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Rails.logger.debug "Parent Id count -> " + parent_id.count.to_s
|
|
||||||
|
|
||||||
|
|
||||||
parent_id.each do |pid|
|
|
||||||
form_items.each do |item|
|
|
||||||
Rails.logger.debug "Adding - Parents -> " + pid.to_s + " - " + item[:order_item_id].to_s
|
|
||||||
if (pid == item[:order_item_id])
|
|
||||||
parents.push(item)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Rails.logger.debug "Parents count -> " + parents.count.to_s
|
|
||||||
|
|
||||||
parents.each do |parent|
|
|
||||||
children = Array.new
|
|
||||||
form_items.each do |item|
|
|
||||||
if (parent[:order_item_id] == item[:parent_order_item_id] )
|
|
||||||
children.push(item)
|
|
||||||
#Items to remove for new list
|
|
||||||
parents_and_children_items.push(item)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
parent[:sub_items] = children
|
|
||||||
end
|
|
||||||
Rails.logger.debug "Parent/children Items to remove -> " + parents_and_children_items.count.to_s
|
|
||||||
|
|
||||||
#Remove process items
|
|
||||||
#c = a.reject{ |e| b.include? e }
|
|
||||||
|
|
||||||
new_items_list = form_items - parents_and_children_items
|
|
||||||
|
|
||||||
|
|
||||||
Rails.logger.debug "New list count -> " + new_items_list.count.to_s
|
|
||||||
|
|
||||||
#Add parent to the list
|
|
||||||
#new_items_list = new_items_list + parents
|
|
||||||
|
|
||||||
Rails.logger.debug "Re-Order List (Parent)-"
|
|
||||||
|
|
||||||
Rails.logger.debug parents
|
|
||||||
|
|
||||||
Rails.logger.debug "Re-Order List -"
|
|
||||||
Rails.logger.debug new_items_list
|
|
||||||
|
|
||||||
return new_items_list
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ class OrderItem < ApplicationRecord
|
|||||||
before_create :generate_custom_id
|
before_create :generate_custom_id
|
||||||
|
|
||||||
#Associations
|
#Associations
|
||||||
belongs_to :order, autosave: true
|
belongs_to :order, autosave: true
|
||||||
# belongs_to :order, counter_cache: true
|
# belongs_to :order, counter_cache: true
|
||||||
|
|
||||||
#Validation
|
#Validation
|
||||||
validates_presence_of :item_code, :item_name, :qty
|
validates_presence_of :item_code, :item_name, :qty
|
||||||
@@ -102,7 +102,13 @@ class OrderItem < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
def self.generate_ids(count = 1)
|
||||||
|
SeedGenerator.generate_ids(self.name, "ODI", count)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate_custom_id
|
def generate_custom_id
|
||||||
if self.order_items_id.nil?
|
if self.order_items_id.nil?
|
||||||
self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI")
|
self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI")
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
class OrderQueueStation < ApplicationRecord
|
class OrderQueueStation < ApplicationRecord
|
||||||
has_many :assigned_order_items
|
has_many :assigned_order_items
|
||||||
has_many :order_items
|
has_many :order_items
|
||||||
has_many :order_queue_process_by_zones
|
has_many :order_queue_process_by_zones
|
||||||
has_many :zones, through: :order_queue_process_by_zones
|
has_many :zones, through: :order_queue_process_by_zones
|
||||||
belongs_to :employee
|
belongs_to :employee
|
||||||
|
|
||||||
@@ -14,110 +14,53 @@ class OrderQueueStation < ApplicationRecord
|
|||||||
# validations
|
# validations
|
||||||
validates_presence_of :station_name, :printer_name
|
validates_presence_of :station_name, :printer_name
|
||||||
|
|
||||||
def process_order (order, table_id, order_source = nil, pdf_status = nil ,change_to=nil,current_user=nil)
|
def process_order(order, table_id, order_source = nil, pdf_status = nil ,change_to=nil, current_user=nil)
|
||||||
|
|
||||||
oqs_stations = OrderQueueStation.active
|
oqs_stations = OrderQueueStation.active
|
||||||
|
|
||||||
|
|
||||||
order_items = order.order_items
|
order_items = order.order_items
|
||||||
|
|
||||||
if table_id.to_i > 0
|
if table_id.to_i > 0
|
||||||
# get dining
|
# get dining
|
||||||
dining = DiningFacility.find(table_id)
|
dining = DiningFacility.find(table_id)
|
||||||
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}")
|
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}").pluck(:order_queue_station_id)
|
||||||
booking = Booking.find_by_dining_facility_id(dining.id)
|
oqs_stations = oqs_stations.select { |s| oqs_by_zones.include? s.id }
|
||||||
|
end
|
||||||
# ToDo per item per printer
|
|
||||||
|
|
||||||
oqs_by_zones.each do |oqpbz|
|
assigned_order_items = []
|
||||||
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
|
oqs_order_items_by_zones = []
|
||||||
is_auto_printed = false
|
|
||||||
oqs_order_items = []
|
|
||||||
|
|
||||||
if oqs.is_active
|
# ToDo per item per printer
|
||||||
#Get List of items -
|
oqs_stations.each do |oqs|
|
||||||
pq_items = JSON.parse(oqs.processing_items)
|
oqs_order_items = nil
|
||||||
#Loop through the processing items
|
oqs_order_items = order_items.select { |i| JSON.parse(oqs.processing_items).include? i.item_code }
|
||||||
pq_items.each do |pq_item|
|
assigned_order_items += oqs_order_items.map { |i| AssignedOrderItem.new({ order: order, item_code: i.item_code, instance_code: i.item_instance_code, order_queue_station: oqs, print_status: false, delivery_status: false }) }
|
||||||
#Processing through the looping items
|
oqs_order_items_by_zones << { oqs: oqs, oqs_order_items: oqs_order_items }
|
||||||
order_items.each do |order_item|
|
|
||||||
if (pq_item == order_item.item_code)
|
if oqs.auto_print && order_source != "quick_service"
|
||||||
# if oqs.id == oqpbz.order_queue_station_id
|
if oqs_order_items.length > 0
|
||||||
# #Same Order_items can appear in two location.
|
if oqs.cut_per_item
|
||||||
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
print_slip_item(oqs, order, oqs_order_items, pdf_status, change_to, current_user, table_id)
|
||||||
# else
|
else
|
||||||
|
print_slip(oqs, order, oqs_order_items, pdf_status, change_to, current_user, table_id)
|
||||||
if (order_item.qty > 0)
|
|
||||||
if pdf_status.nil?
|
|
||||||
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs)
|
|
||||||
end
|
|
||||||
oqs_order_items.push(order_item)
|
|
||||||
end
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if oqs.auto_print && order_source != "quick_service"
|
|
||||||
if oqs_order_items.length > 0
|
|
||||||
if oqs.cut_per_item
|
|
||||||
print_slip_item(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id)
|
|
||||||
else
|
|
||||||
print_slip(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id)
|
|
||||||
end
|
|
||||||
is_auto_printed = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
oqs_stations.each do |oqs|
|
|
||||||
is_auto_printed = false
|
|
||||||
oqs_order_items = []
|
|
||||||
|
|
||||||
if oqs.is_active
|
if pdf_status.nil?
|
||||||
#Get List of items -
|
ids = AssignedOrderItem.generate_ids(assigned_order_items.length)
|
||||||
pq_items = JSON.parse(oqs.processing_items)
|
assigned_order_items.each_with_index do |assigned_order_item, index|
|
||||||
#Loop through the processing items
|
assigned_order_item.assigned_order_item_id = ids[index]
|
||||||
pq_items.each do |pq_item|
|
|
||||||
#Processing through the looping items
|
|
||||||
order_items.each do |order_item|
|
|
||||||
if (pq_item == order_item.item_code)
|
|
||||||
# if oqs.id == oqpbz.order_queue_station_id
|
|
||||||
# #Same Order_items can appear in two location.
|
|
||||||
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
|
||||||
# else
|
|
||||||
|
|
||||||
if (order_item.qty > 0)
|
|
||||||
if pdf_status.nil?
|
|
||||||
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs)
|
|
||||||
end
|
|
||||||
oqs_order_items.push(order_item)
|
|
||||||
end
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if oqs.auto_print && order_source != "quick_service"
|
|
||||||
if oqs_order_items.length > 0
|
|
||||||
if oqs.cut_per_item
|
|
||||||
print_slip_item(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id)
|
|
||||||
else
|
|
||||||
print_slip(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id)
|
|
||||||
end
|
|
||||||
is_auto_printed = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end #end else
|
|
||||||
|
AssignedOrderItem.import assigned_order_items, validate: false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pay_process_order_queue (order_id, table_id)
|
def pay_process_order_queue (order_id, table_id)
|
||||||
|
|
||||||
oqs_stations = OrderQueueStation.active
|
oqs_stations = OrderQueueStation.active
|
||||||
|
|
||||||
order = Order.find(order_id)
|
order = Order.find(order_id)
|
||||||
order_items = order.order_items
|
order_items = order.order_items
|
||||||
|
|
||||||
@@ -129,22 +72,22 @@ class OrderQueueStation < ApplicationRecord
|
|||||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||||
# if ENV["SERVER_MODE"] == 'cloud'
|
# if ENV["SERVER_MODE"] == 'cloud'
|
||||||
# from = request.subdomain + "." + request.domain
|
# from = request.subdomain + "." + request.domain
|
||||||
# else
|
# else
|
||||||
# from = ""
|
# from = ""
|
||||||
# end
|
# end
|
||||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
|
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
|
||||||
|
|
||||||
if table_id.to_i > 0
|
if table_id.to_i > 0
|
||||||
# get dining
|
# get dining
|
||||||
dining = DiningFacility.find(table_id)
|
dining = DiningFacility.find(table_id)
|
||||||
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}")
|
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}")
|
||||||
booking = Booking.find_by_dining_facility_id(dining.id)
|
booking = Booking.find_by_dining_facility_id(dining.id)
|
||||||
|
|
||||||
# ToDo per item per printer
|
# ToDo per item per printer
|
||||||
|
|
||||||
oqs_by_zones.each do |oqpbz|
|
oqs_by_zones.each do |oqpbz|
|
||||||
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
|
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
|
||||||
is_auto_printed = false
|
is_auto_printed = false
|
||||||
oqs_order_items = []
|
oqs_order_items = []
|
||||||
|
|
||||||
if oqs.is_active
|
if oqs.is_active
|
||||||
@@ -157,26 +100,26 @@ class OrderQueueStation < ApplicationRecord
|
|||||||
if (pq_item == order_item.item_code)
|
if (pq_item == order_item.item_code)
|
||||||
if (order_item.qty > 0)
|
if (order_item.qty > 0)
|
||||||
oqs_order_items.push(order_item)
|
oqs_order_items.push(order_item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if oqs.auto_print
|
if oqs.auto_print
|
||||||
if oqs_order_items.length > 0
|
if oqs_order_items.length > 0
|
||||||
if oqs.cut_per_item
|
if oqs.cut_per_item
|
||||||
print_slip_item(oqs, order, oqs_order_items)
|
print_slip_item(oqs, order, oqs_order_items)
|
||||||
else
|
else
|
||||||
print_slip(oqs, order, oqs_order_items)
|
print_slip(oqs, order, oqs_order_items)
|
||||||
end
|
end
|
||||||
is_auto_printed = true
|
is_auto_printed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
oqs_stations.each do |oqs|
|
oqs_stations.each do |oqs|
|
||||||
is_auto_printed = false
|
is_auto_printed = false
|
||||||
oqs_order_items = []
|
oqs_order_items = []
|
||||||
|
|
||||||
if oqs.is_active
|
if oqs.is_active
|
||||||
@@ -186,107 +129,63 @@ class OrderQueueStation < ApplicationRecord
|
|||||||
pq_items.each do |pq_item|
|
pq_items.each do |pq_item|
|
||||||
#Processing through the looping items
|
#Processing through the looping items
|
||||||
order_items.each do |order_item|
|
order_items.each do |order_item|
|
||||||
if (pq_item == order_item.item_code)
|
if (pq_item == order_item.item_code)
|
||||||
if (order_item.qty > 0)
|
if (order_item.qty > 0)
|
||||||
oqs_order_items.push(order_item)
|
oqs_order_items.push(order_item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if oqs.auto_print
|
if oqs.auto_print
|
||||||
if oqs_order_items.length > 0
|
if oqs_order_items.length > 0
|
||||||
if oqs.cut_per_item
|
if oqs.cut_per_item
|
||||||
print_slip_item(oqs, order, oqs_order_items)
|
print_slip_item(oqs, order, oqs_order_items)
|
||||||
else
|
else
|
||||||
print_slip(oqs, order, oqs_order_items)
|
print_slip(oqs, order, oqs_order_items)
|
||||||
end
|
end
|
||||||
is_auto_printed = true
|
is_auto_printed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end #end else
|
end #end else
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
#Print order_items in 1 slip
|
#Print order_items in 1 slip
|
||||||
def print_slip(oqs, order, order_items ,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
|
def print_slip(oqs, order, order_items ,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
|
||||||
if pdf_status.nil?
|
if pdf_status.nil?
|
||||||
printer = PrintSetting.all.order("id ASC")
|
if print_settings = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
|
||||||
unique_code="OrderSummaryPdf"
|
order_queue_printer = Printer::OrderQueuePrinter.new(print_settings)
|
||||||
|
order_queue_printer.print_order_summary(print_settings, oqs, order.order_id, order_items, print_status="")
|
||||||
if !printer.empty?
|
end
|
||||||
printer.each do |printer_setting|
|
|
||||||
if printer_setting.unique_code == 'OrderSummaryPdf'
|
|
||||||
unique_code="OrderSummaryPdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
|
|
||||||
unique_code="OrderSummarySlimPdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
|
|
||||||
unique_code="OrderSummarySetPdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
|
|
||||||
unique_code="OrderSummaryCustomisePdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
|
|
||||||
unique_code="OrderSummarySetCustomisePdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
|
|
||||||
unique_code="OrderSummarySlimCustomisePdf"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
||||||
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
|
|
||||||
order_queue_printer.print_order_summary(print_settings, oqs,order.order_id, order_items, print_status="")
|
|
||||||
else
|
else
|
||||||
move_print_pdf(change_to,current_user,table_id,order_items,oqs)
|
move_print_pdf(change_to,current_user,table_id,order_items,oqs)
|
||||||
end
|
end
|
||||||
|
|
||||||
assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id)
|
AssignedOrderItem.where("order_id = ?", order.order_id).update_all(print_status: true)
|
||||||
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#Print order_item in 1 slip per item
|
#Print order_item in 1 slip per item
|
||||||
def print_slip_item(oqs, order, assigned_items,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
|
def print_slip_item(oqs, order, assigned_items,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
|
||||||
|
|
||||||
if pdf_status.nil?
|
if pdf_status.nil?
|
||||||
printer = PrintSetting.all.order("id ASC")
|
|
||||||
unique_code="OrderItemPdf"
|
|
||||||
|
|
||||||
if !printer.empty?
|
|
||||||
printer.each do |printer_setting|
|
|
||||||
if printer_setting.unique_code == 'OrderItemPdf'
|
|
||||||
unique_code="OrderItemPdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderItemStarPdf'
|
|
||||||
unique_code="OrderItemStarPdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderItemSlimPdf'
|
|
||||||
unique_code="OrderItemSlimPdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderSetItemPdf'
|
|
||||||
unique_code="OrderSetItemPdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderItemCustomisePdf'
|
|
||||||
unique_code="OrderItemCustomisePdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderSetItemCustomisePdf'
|
|
||||||
unique_code="OrderSetItemCustomisePdf"
|
|
||||||
elsif printer_setting.unique_code == 'OrderItemSlimCustomisePdf'
|
|
||||||
unique_code="OrderItemSlimCustomisePdf"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first()
|
# order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first()
|
||||||
# print when complete click
|
# print when complete click
|
||||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
if print_settings = PrintSetting.where("unique_code REGEXP ?", "order.*item.*pdf").first
|
||||||
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
|
order_queue_printer = Printer::OrderQueuePrinter.new(print_settings)
|
||||||
if !assigned_items.nil?
|
if !assigned_items.nil?
|
||||||
assigned_items.each do |order_item|
|
assigned_items.each do |order_item|
|
||||||
order_queue_printer.print_order_item(print_settings, oqs,order_item.order_id, order_item.order_items_id, print_status="" )
|
order_queue_printer.print_order_item(print_settings, oqs,order_item.order_id, order_item.order_items_id, print_status="" )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
move_print_pdf(change_to,current_user,table_id,assigned_items,oqs)
|
move_print_pdf(change_to,current_user,table_id,assigned_items,oqs)
|
||||||
end
|
end
|
||||||
|
|
||||||
assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id)
|
AssignedOrderItem.where("order_id = ?", order.order_id).update_all(print_status: true)
|
||||||
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_print_pdf(change_to,current_user,change_from,order_items,oqs)
|
def move_print_pdf(change_to,current_user,change_from,order_items,oqs)
|
||||||
@@ -298,7 +197,7 @@ class OrderQueueStation < ApplicationRecord
|
|||||||
@moved_by = current_user
|
@moved_by = current_user
|
||||||
@date = DateTime.now
|
@date = DateTime.now
|
||||||
@shop = Shop.current_shop
|
@shop = Shop.current_shop
|
||||||
unique_code = "MoveTablePdf"
|
unique_code = "MoveTablePdf"
|
||||||
# pdf_no = PrintSetting.where(:unique_code => unique_code).count
|
# pdf_no = PrintSetting.where(:unique_code => unique_code).count
|
||||||
print_settings = PrintSetting.find_by_unique_code(unique_code)
|
print_settings = PrintSetting.find_by_unique_code(unique_code)
|
||||||
# printer_array = []
|
# printer_array = []
|
||||||
@@ -307,10 +206,10 @@ class OrderQueueStation < ApplicationRecord
|
|||||||
# for i in 0..pdf_no
|
# for i in 0..pdf_no
|
||||||
# if i != pdf_no
|
# if i != pdf_no
|
||||||
# print_settings = printer_array[i]
|
# print_settings = printer_array[i]
|
||||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||||
printer.print_move_table(print_settings,@to,@from ,@shop,@date,@type,@moved_by,order_items,oqs)
|
printer.print_move_table(print_settings,@to,@from ,@shop,@date,@type,@moved_by,order_items,oqs)
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,41 +1,18 @@
|
|||||||
class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||||
|
|
||||||
def print_order_item(print_settings,oqs, order_id, order_item_id, print_status, before_updated_qty="", options="")
|
def print_order_item(print_settings, oqs, order_id, order_item_id, print_status, before_updated_qty="", options="")
|
||||||
# Must be one print
|
# Must be one print
|
||||||
if print_settings.print_copies == 0
|
if print_settings.print_copies == 0
|
||||||
print_settings.print_copies = 1
|
print_settings.print_copies = 1
|
||||||
print_settings.save!
|
print_settings.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
order_item = print_query('order_item', order_item_id) #OrderItem.find_by_item_code(item_code)
|
order_item = print_query('order_item', order_item_id) #OrderItem.find_by_item_code(item_code)
|
||||||
options = order_item[0].options
|
options = order_item[0].options
|
||||||
# filename = "tmp/order_item_#{order_id}_#{order_item_id}" + ".pdf"
|
|
||||||
|
|
||||||
# pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
|
||||||
print_setting = PrintSetting.all
|
|
||||||
|
|
||||||
# check for item not to show
|
# check for item not to show
|
||||||
pdf = ''
|
|
||||||
# if order_item[0].price != 0
|
# if order_item[0].price != 0
|
||||||
if !print_setting.empty?
|
pdf = print_settings.unique_code.constantize.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
||||||
print_setting.each do |print_settings|
|
|
||||||
if print_settings.unique_code == 'OrderItemPdf'
|
|
||||||
pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemStarPdf'
|
|
||||||
pdf = OrderItemStarPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemSlimPdf'
|
|
||||||
pdf = OrderItemSlimPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSetItemPdf'
|
|
||||||
pdf = OrderSetItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemCustomisePdf'
|
|
||||||
pdf = OrderItemCustomisePdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSetItemCustomisePdf'
|
|
||||||
pdf = OrderSetItemCustomisePdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemSlimCustomisePdf'
|
|
||||||
pdf = OrderItemSlimCustomisePdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# end
|
# end
|
||||||
|
|
||||||
shop = Shop.current_shop
|
shop = Shop.current_shop
|
||||||
@@ -77,9 +54,6 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
|||||||
print_settings.save!
|
print_settings.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
print_setting = PrintSetting.all.order("id ASC")
|
|
||||||
order=print_query('order_summary', order_id)
|
|
||||||
|
|
||||||
shop = Shop.current_shop
|
shop = Shop.current_shop
|
||||||
directory_name = 'public/orders_'+shop.shop_code
|
directory_name = 'public/orders_'+shop.shop_code
|
||||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||||
@@ -87,8 +61,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
|||||||
# For Print Per Item
|
# For Print Per Item
|
||||||
if oqs.cut_per_item
|
if oqs.cut_per_item
|
||||||
|
|
||||||
order_items.each do|odi|
|
order_items.each do |odi|
|
||||||
odi_item=print_query('order_item', odi.order_items_id)
|
odi_item = print_query('order_item', odi.order_items_id)
|
||||||
|
|
||||||
filename = directory_name + "/order_item_#{order_id}" + ".pdf"
|
filename = directory_name + "/order_item_#{order_id}" + ".pdf"
|
||||||
# filename = "tmp/order_item_#{order_id}" + ".pdf"
|
# filename = "tmp/order_item_#{order_id}" + ".pdf"
|
||||||
@@ -97,67 +71,33 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
|||||||
|
|
||||||
# check for item not to show
|
# check for item not to show
|
||||||
#if odi.price != 0
|
#if odi.price != 0
|
||||||
pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
|
pdf = print_settings.unique_code.constantize.new(print_settings, odi_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
||||||
if !print_setting.empty?
|
|
||||||
print_setting.each do |print_settings|
|
|
||||||
if print_settings.unique_code == 'OrderItemPdf'
|
|
||||||
pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemStarPdf'
|
|
||||||
pdf = OrderItemStarPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemSlimPdf'
|
|
||||||
pdf = OrderItemSlimPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSetItemPdf'
|
|
||||||
pdf = OrderSetItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemCustomisePdf'
|
|
||||||
pdf = OrderItemCustomisePdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSetItemCustomisePdf'
|
|
||||||
pdf = OrderSetItemCustomisePdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemSlimCustomisePdf'
|
|
||||||
pdf = OrderItemSlimCustomisePdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# pdf.render_file "tmp/order_item.pdf"
|
# pdf.render_file "tmp/order_item.pdf"
|
||||||
pdf.render_file filename
|
pdf.render_file filename
|
||||||
if oqs.print_copy
|
if oqs.print_copy
|
||||||
#no print in cloud server
|
#no print in cloud server
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
self.print(filename, oqs.printer_name)
|
self.print(filename, oqs.printer_name)
|
||||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||||
end
|
|
||||||
else
|
|
||||||
print_settings.print_copies = 1
|
|
||||||
print_settings.save!
|
|
||||||
#no print in cloud server
|
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
|
||||||
self.print(filename, oqs.printer_name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
print_settings.print_copies = 1
|
||||||
|
print_settings.save!
|
||||||
|
#no print in cloud server
|
||||||
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
|
self.print(filename, oqs.printer_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
#end
|
#end
|
||||||
end
|
end
|
||||||
# For Print Order Summary
|
# For Print Order Summary
|
||||||
else
|
else
|
||||||
|
order = print_query('order_summary', order_id)
|
||||||
|
|
||||||
filename = directory_name + "/order_summary_#{order_id}" + ".pdf"
|
filename = directory_name + "/order_summary_#{order_id}" + ".pdf"
|
||||||
# filename = "tmp/order_summary_#{order_id}" + ".pdf"
|
# filename = "tmp/order_summary_#{order_id}" + ".pdf"
|
||||||
pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
|
pdf = print_settings.unique_code.constantize.new(print_settings, order, print_status, order_items, oqs.use_alternate_name, before_updated_qty)
|
||||||
if !print_setting.empty?
|
|
||||||
print_setting.each do |print_settings|
|
|
||||||
if print_settings.unique_code == 'OrderSummaryPdf'
|
|
||||||
pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummarySlimPdf'
|
|
||||||
pdf = OrderSummarySlimPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummarySetPdf'
|
|
||||||
pdf = OrderSummarySetPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummaryCustomisePdf'
|
|
||||||
pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummarySetCustomisePdf'
|
|
||||||
pdf = OrderSummarySetCustomisePdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummarySlimCustomisePdf'
|
|
||||||
pdf = OrderSummarySlimCustomisePdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
pdf.render_file filename
|
pdf.render_file filename
|
||||||
if oqs.print_copy
|
if oqs.print_copy
|
||||||
@@ -190,7 +130,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
|||||||
|
|
||||||
print_setting = PrintSetting.all.order("id ASC")
|
print_setting = PrintSetting.all.order("id ASC")
|
||||||
|
|
||||||
order=print_query('booking_summary', booking_id)
|
order = print_query('booking_summary', booking_id)
|
||||||
|
|
||||||
shop = Shop.current_shop
|
shop = Shop.current_shop
|
||||||
directory_name = 'public/orders_'+shop.shop_code
|
directory_name = 'public/orders_'+shop.shop_code
|
||||||
@@ -206,69 +146,33 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
|||||||
|
|
||||||
# check for item not to show
|
# check for item not to show
|
||||||
#if odi.price != 0
|
#if odi.price != 0
|
||||||
pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
pdf = print_settings.unique_code.constantize.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
||||||
if !print_setting.empty?
|
|
||||||
print_setting.each do |print_settings|
|
|
||||||
if print_settings.unique_code == 'OrderItemPdf'
|
|
||||||
pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemStarPdf'
|
|
||||||
pdf = OrderItemStarPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemSlimPdf'
|
|
||||||
pdf = OrderItemSlimPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSetItemPdf'
|
|
||||||
pdf = OrderSetItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemCustomisePdf'
|
|
||||||
pdf = OrderItemCustomisePdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSetItemCustomisePdf'
|
|
||||||
pdf = OrderSetItemCustomisePdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderItemSlimCustomisePdf'
|
|
||||||
pdf = OrderItemSlimCustomisePdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pdf.render_file filename
|
|
||||||
|
|
||||||
if oqs.print_copy
|
pdf.render_file filename
|
||||||
#no print in cloud server
|
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
if oqs.print_copy
|
||||||
self.print(filename, oqs.printer_name)
|
#no print in cloud server
|
||||||
end
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
#For print copy
|
self.print(filename, oqs.printer_name)
|
||||||
# pdf.render_file filename.gsub(".","-copy.")
|
|
||||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
|
||||||
else
|
|
||||||
print_settings.print_copies = 1
|
|
||||||
print_settings.save!
|
|
||||||
#no print in cloud server
|
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
|
||||||
self.print(filename, oqs.printer_name)
|
|
||||||
end
|
|
||||||
end
|
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!
|
||||||
|
#no print in cloud server
|
||||||
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
|
self.print(filename, oqs.printer_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
#end
|
#end
|
||||||
end
|
end
|
||||||
# For Print Order Summary
|
# For Print Order Summary
|
||||||
else
|
else
|
||||||
# filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
|
# filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
|
||||||
filename = directory_name + "/booking_summary_#{booking_id}" + ".pdf"
|
filename = directory_name + "/booking_summary_#{booking_id}" + ".pdf"
|
||||||
pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
pdf = print_settings.unique_code.constantize.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
||||||
|
|
||||||
if !print_setting.empty?
|
|
||||||
print_setting.each do |print_settings|
|
|
||||||
if print_settings.unique_code == 'OrderSummaryPdf'
|
|
||||||
pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummarySlimPdf'
|
|
||||||
pdf = OrderSummarySlimPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummarySetPdf'
|
|
||||||
pdf = OrderSummarySetPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummaryCustomisePdf'
|
|
||||||
pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummarySetCustomisePdf'
|
|
||||||
pdf = OrderSummarySetCustomisePdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
elsif print_settings.unique_code == 'OrderSummarySlimCustomisePdf'
|
|
||||||
pdf = OrderSummarySlimCustomisePdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
pdf.render_file filename
|
pdf.render_file filename
|
||||||
if oqs.print_copy
|
if oqs.print_copy
|
||||||
@@ -293,36 +197,23 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
|||||||
|
|
||||||
# Query for OQS with status
|
# Query for OQS with status
|
||||||
def print_query(type, id)
|
def print_query(type, id)
|
||||||
|
query = OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
||||||
|
.joins("left join orders ON orders.order_id = order_items.order_id")
|
||||||
|
.joins("left join booking_orders AS bo ON bo.order_id=order_items.order_id")
|
||||||
|
.joins("left join bookings AS b ON b.booking_id = bo.booking_id")
|
||||||
|
.joins("left join dining_facilities AS df ON df.id = b.dining_facility_id")
|
||||||
|
.joins("left join customers as cus ON cus.customer_id = orders.customer_id")
|
||||||
|
.joins("left join menu_items as item ON item.item_code = order_items.item_code")
|
||||||
|
|
||||||
if type == "order_item"
|
if type == "order_item"
|
||||||
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
query.where("order_items.order_items_id = '#{ id }'")
|
||||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
|
||||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
|
||||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
|
||||||
left join dining_facilities AS df ON df.id = b.dining_facility_id
|
|
||||||
left join customers as cus ON cus.customer_id = orders.customer_id
|
|
||||||
left join menu_items as item ON item.item_code = order_items.item_code")
|
|
||||||
.where("order_items.order_items_id = '#{ id }'")
|
|
||||||
.group("order_items.item_code")
|
.group("order_items.item_code")
|
||||||
elsif type == "order_summary"
|
elsif type == "order_summary"
|
||||||
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
query.where("orders.order_id = '#{ id }'")
|
||||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
|
||||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
|
||||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
|
||||||
left join dining_facilities AS df ON df.id = b.dining_facility_id
|
|
||||||
left join customers as cus ON cus.customer_id = orders.customer_id
|
|
||||||
left join menu_items as item ON item.item_code = order_items.item_code")
|
|
||||||
.where("orders.order_id = '#{ id }'")
|
|
||||||
.group("order_items.order_items_id")
|
.group("order_items.order_items_id")
|
||||||
else
|
else
|
||||||
# order summary for booking
|
# order summary for booking
|
||||||
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
|
query.where("b.booking_id = '#{ id }'")
|
||||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
|
||||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
|
||||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
|
||||||
left join dining_facilities AS df ON df.id = b.dining_facility_id
|
|
||||||
left join customers as cus ON cus.customer_id = orders.customer_id
|
|
||||||
left join menu_items as item ON item.item_code = order_items.item_code")
|
|
||||||
.where("b.booking_id = '#{ id }'")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,26 +4,9 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
#Use CUPS service
|
#Use CUPS service
|
||||||
#Generate PDF
|
#Generate PDF
|
||||||
#Print
|
#Print
|
||||||
printer = PrintSetting.all
|
printer = PrintSetting.where("unique_code REGEXP ?", "order.*item.*pdf").first
|
||||||
pdf = OrderItemPdf.new
|
pdf = printer.unique_code.constantize.new
|
||||||
|
|
||||||
if !printer.empty?
|
|
||||||
printer.each do |printer_setting|
|
|
||||||
if printer_setting.unique_code == 'OrderItemPdf'
|
|
||||||
pdf = OrderItemPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderItemSlimPdf'
|
|
||||||
pdf = OrderItemSlimPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSetItemPdf'
|
|
||||||
pdf = OrderSetItemPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderItemCustomisePdf'
|
|
||||||
pdf = OrderItemCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSetItemCustomisePdf'
|
|
||||||
pdf = OrderSetItemCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderItemSlimCustomisePdf'
|
|
||||||
pdf = OrderItemSlimCustomisePdf.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pdf.render_file "tmp/order_item_queue_#{order_id}_#{order_item_id}" + ".pdf"
|
pdf.render_file "tmp/order_item_queue_#{order_id}_#{order_item_id}" + ".pdf"
|
||||||
#no print in cloud server
|
#no print in cloud server
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
@@ -36,26 +19,9 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
#Generate PDF
|
#Generate PDF
|
||||||
#Print
|
#Print
|
||||||
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
||||||
printer = PrintSetting.all
|
printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
|
||||||
pdf = OrderSummaryPdf.new
|
pdf = printer.unique_code.constantize.new
|
||||||
|
|
||||||
if !printer.empty?
|
|
||||||
printer.each do |printer_setting|
|
|
||||||
if printer_setting.unique_code == 'OrderSummaryPdf'
|
|
||||||
pdf = OrderSummaryPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
|
|
||||||
pdf = OrderSummarySlimPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
|
|
||||||
pdf = OrderSummarySetPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
|
|
||||||
pdf = OrderSummaryCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
|
|
||||||
pdf = OrderSummarySetCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
|
|
||||||
pdf = OrderSummarySlimCustomisePdf.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pdf.render_file filename
|
pdf.render_file filename
|
||||||
#no print in cloud server
|
#no print in cloud server
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
@@ -67,26 +33,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
#Use CUPS service
|
#Use CUPS service
|
||||||
#Generate PDF
|
#Generate PDF
|
||||||
#Print
|
#Print
|
||||||
printer = PrintSetting.all
|
printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
|
||||||
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
||||||
pdf = OrderSummaryPdf.new
|
pdf = printer.unique_code.constantize.new
|
||||||
if !printer.empty?
|
|
||||||
printer.each do |printer_setting|
|
|
||||||
if printer_setting.unique_code == 'OrderSummaryPdf'
|
|
||||||
pdf = OrderSummaryPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
|
|
||||||
pdf = OrderSummarySlimPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
|
|
||||||
pdf = OrderSummarySetPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
|
|
||||||
pdf = OrderSummaryCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
|
|
||||||
pdf = OrderSummarySetCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
|
|
||||||
pdf = OrderSummarySlimCustomisePdf.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pdf.render_file filename
|
pdf.render_file filename
|
||||||
#no print in cloud server
|
#no print in cloud server
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
@@ -98,26 +48,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
#Use CUPS service
|
#Use CUPS service
|
||||||
#Generate PDF
|
#Generate PDF
|
||||||
#Print
|
#Print
|
||||||
printer = PrintSetting.all
|
printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
|
||||||
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
||||||
pdf = OrderSummaryPdf.new
|
pdf = printer.unique_code.constantize.new
|
||||||
if !printer.empty?
|
|
||||||
printer.each do |printer_setting|
|
|
||||||
if printer_setting.unique_code == 'OrderSummaryPdf'
|
|
||||||
pdf = OrderSummaryPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
|
|
||||||
pdf = OrderSummarySlimPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
|
|
||||||
pdf = OrderSummarySetPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
|
|
||||||
pdf = OrderSummaryCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
|
|
||||||
pdf = OrderSummarySetCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
|
|
||||||
pdf = OrderSummarySlimCustomisePdf.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pdf.render_file filename
|
pdf.render_file filename
|
||||||
#no print in cloud server
|
#no print in cloud server
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
@@ -129,26 +63,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
#Use CUPS service
|
#Use CUPS service
|
||||||
#Generate PDF
|
#Generate PDF
|
||||||
#Print
|
#Print
|
||||||
printer = PrintSetting.all
|
printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
|
||||||
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
||||||
pdf = OrderSummaryPdf.new
|
pdf = printer.unique_code.constantize.new
|
||||||
if !printer.empty?
|
|
||||||
printer.each do |printer_setting|
|
|
||||||
if printer_setting.unique_code == 'OrderSummaryPdf'
|
|
||||||
pdf = OrderSummaryPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
|
|
||||||
pdf = OrderSummarySlimPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
|
|
||||||
pdf = OrderSummarySetPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
|
|
||||||
pdf = OrderSummaryCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
|
|
||||||
pdf = OrderSummarySetCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
|
|
||||||
pdf = OrderSummarySlimCustomisePdf.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pdf.render_file filename
|
pdf.render_file filename
|
||||||
#no print in cloud server
|
#no print in cloud server
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
@@ -160,26 +78,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
#Use CUPS service
|
#Use CUPS service
|
||||||
#Generate PDF
|
#Generate PDF
|
||||||
#Print
|
#Print
|
||||||
printer = PrintSetting.all
|
printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
|
||||||
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
|
||||||
pdf = OrderSummaryPdf.new
|
pdf = printer.unique_code.constantize.new
|
||||||
if !printer.empty?
|
|
||||||
printer.each do |printer_setting|
|
|
||||||
if printer_setting.unique_code == 'OrderSummaryPdf'
|
|
||||||
pdf = OrderSummaryPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
|
|
||||||
pdf = OrderSummarySlimPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
|
|
||||||
pdf = OrderSummarySetPdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
|
|
||||||
pdf = OrderSummaryCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
|
|
||||||
pdf = OrderSummarySetCustomisePdf.new
|
|
||||||
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
|
|
||||||
pdf = OrderSummarySlimCustomisePdf.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
pdf.render_file filename
|
pdf.render_file filename
|
||||||
#no print in cloud server
|
#no print in cloud server
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
@@ -192,31 +94,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
#Use CUPS service
|
#Use CUPS service
|
||||||
#Generate PDF
|
#Generate PDF
|
||||||
#Print
|
#Print
|
||||||
if !printer_settings.nil?
|
if printer_settings
|
||||||
if !printer_settings.unique_code.strip.downcase.include? ("receiptbillorder")
|
if !printer_settings.unique_code.match?(/receiptbillorder/i)
|
||||||
pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
|
if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf
|
||||||
settings = PrintSetting.all
|
pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
|
||||||
if !settings.nil?
|
else
|
||||||
settings.each do |setting|
|
pdf = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code.constantize.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
|
||||||
if setting.unique_code == 'ReceiptBillPdf'
|
|
||||||
pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
|
|
||||||
elsif setting.unique_code == 'ReceiptBillStarPdf'
|
|
||||||
pdf = ReceiptBillStarPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
|
||||||
if !receipt_bill_a5_pdf.empty?
|
|
||||||
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
|
||||||
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
|
||||||
if receipt_bilA5[1] == '1'
|
|
||||||
pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
|
|
||||||
# else
|
|
||||||
# pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
#doemal online order pdf template
|
#doemal online order pdf template
|
||||||
|
|||||||
@@ -5,29 +5,23 @@ class Product < ApplicationRecord
|
|||||||
mount_uploader :image_path, ProductImageUploader
|
mount_uploader :image_path, ProductImageUploader
|
||||||
|
|
||||||
def self.search_by_product_code(item_code)
|
def self.search_by_product_code(item_code)
|
||||||
account = Account.find_by_title('Product')
|
Product.joins("JOIN accounts ON accounts.title = 'Product'")
|
||||||
if !account.nil?
|
.where(item_code: item_code)
|
||||||
account_id = account.id
|
.pluck("accounts.id AS account_id", :item_code, :name, :alt_name, :unit_price, :taxable)
|
||||||
else
|
.map { |account_id, item_code, item_name, item_alt_name, price, taxable|
|
||||||
account_id = 1
|
{
|
||||||
end
|
type: 'Product',
|
||||||
|
account_id: account_id,
|
||||||
menu_item_hash = Hash.new
|
item_code: item_code,
|
||||||
mt_instance = Product.find_by_item_code(item_code)
|
item_instance_code: item_code,
|
||||||
if (!mt_instance.nil?)
|
name: item_name || '',
|
||||||
menu_item_hash[:type] = 'Product'
|
alt_name: item_name || '',
|
||||||
menu_item_hash[:account_id] = account_id
|
price: price,
|
||||||
menu_item_hash[:item_code] = mt_instance.item_code
|
promotion_price: 0,
|
||||||
menu_item_hash[:item_instance_code] = mt_instance.item_code
|
is_on_promotion: 0,
|
||||||
menu_item_hash[:name] = mt_instance.name.to_s
|
is_available: 0,
|
||||||
menu_item_hash[:alt_name] = mt_instance.alt_name.to_s
|
taxable: taxable
|
||||||
menu_item_hash[:price] = mt_instance.unit_price
|
}
|
||||||
menu_item_hash[:promotion_price] = 0
|
}
|
||||||
menu_item_hash[:is_on_promotion] = 0
|
end
|
||||||
menu_item_hash[:is_available] = 0
|
|
||||||
menu_item_hash[:taxable] = mt_instance.taxable
|
|
||||||
|
|
||||||
return menu_item_hash
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -684,14 +684,6 @@ class Sale < ApplicationRecord
|
|||||||
self.total_tax = total_tax_amount
|
self.total_tax = total_tax_amount
|
||||||
end
|
end
|
||||||
|
|
||||||
def product_get_unit_price(item_code)
|
|
||||||
menu_item_hash =MenuItem.search_by_item_code(item_code)
|
|
||||||
if (menu_instance_code)
|
|
||||||
return menu_ item_hash[:item_instance_code], menu_item_hash[:price]
|
|
||||||
end
|
|
||||||
return nil,nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def link_order_sale(order_id)
|
def link_order_sale(order_id)
|
||||||
#create if it doesn't exist
|
#create if it doesn't exist
|
||||||
saleOrder = SaleOrder.where("sale_id=? and order_id=?", self.id, order_id).take
|
saleOrder = SaleOrder.where("sale_id=? and order_id=?", self.id, order_id).take
|
||||||
|
|||||||
@@ -9,13 +9,22 @@ class SeedGenerator < ApplicationRecord
|
|||||||
|
|
||||||
cur_val, next_val = self.update_seed(model_name)
|
cur_val, next_val = self.update_seed(model_name)
|
||||||
|
|
||||||
if (cur_val == 0)
|
padding_len = 15 - prefix.length
|
||||||
cur_val, next_val = self.execute_query(model_name)
|
saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust(padding_len,'0')
|
||||||
|
return saleOrderId
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.generate_ids(model, prefix, count = 1)
|
||||||
|
model_name = self.get_model_name(model)
|
||||||
|
|
||||||
|
if ENV["SERVER_MODE"] == 'cloud'
|
||||||
|
prefix = "C#{prefix}"
|
||||||
end
|
end
|
||||||
|
|
||||||
padding_len = 15 - prefix.length
|
start = self.update_seed(model_name, count)
|
||||||
saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0')
|
stop = start + count - 1
|
||||||
return saleOrderId
|
length = 15 - prefix.length
|
||||||
|
(start..stop).map { |c| "#{prefix}-#{c.to_s.rjust(length, '0')}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sync_seed_generator_records(seed_generators)
|
def self.sync_seed_generator_records(seed_generators)
|
||||||
@@ -58,7 +67,7 @@ class SeedGenerator < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return new_receipt_no
|
return new_receipt_no
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate for 4 digit Code
|
# Generate for 4 digit Code
|
||||||
@@ -85,7 +94,7 @@ class SeedGenerator < ApplicationRecord
|
|||||||
# padding_len = 6 - prefix.length
|
# padding_len = 6 - prefix.length
|
||||||
# count = 5-prefix.length
|
# count = 5-prefix.length
|
||||||
# end
|
# end
|
||||||
# next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0')
|
# next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0')
|
||||||
# return next_code
|
# return next_code
|
||||||
# end
|
# end
|
||||||
|
|
||||||
@@ -100,41 +109,13 @@ class SeedGenerator < ApplicationRecord
|
|||||||
return model_name
|
return model_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.execute_query(model)
|
def self.update_seed(model, count = 1)
|
||||||
current = 0
|
SeedGenerator.transaction do
|
||||||
nex = 0
|
seed = SeedGenerator.lock.find_by_model(model)
|
||||||
|
seed.next = seed.next + (count * seed.increase_by)
|
||||||
sql = "INSERT INTO seed_generators (model, created_at, updated_at)
|
seed.current = seed.next - seed.increase_by
|
||||||
VALUES('#{ model }', NOW(), NOW())
|
seed.save!
|
||||||
ON DUPLICATE KEY UPDATE current = current + 1, next = next + 1;"
|
seed.next_before_last_save
|
||||||
|
|
||||||
select_sql = "select * from seed_generators where model='#{model}';"
|
|
||||||
ActiveRecord::Base.connection.execute(sql);
|
|
||||||
select_result = ActiveRecord::Base.connection.execute(select_sql);
|
|
||||||
|
|
||||||
select_result.each do |row|
|
|
||||||
current = row [3]
|
|
||||||
nex = row[4]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return current, nex
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.update_seed(model)
|
|
||||||
current = 0
|
|
||||||
nex = 0
|
|
||||||
|
|
||||||
update_sql = "UPDATE seed_generators set current = next, next = next + 1 WHERE model='#{model}';"
|
|
||||||
select_sql = "select * from seed_generators where model='#{model}';"
|
|
||||||
update_result = ActiveRecord::Base.connection.execute(update_sql);
|
|
||||||
|
|
||||||
select_result = ActiveRecord::Base.connection.execute(select_sql);
|
|
||||||
|
|
||||||
select_result.each do |row|
|
|
||||||
current = row [3]
|
|
||||||
nex = row[4]
|
|
||||||
end
|
|
||||||
|
|
||||||
return current, nex
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
<% end%>
|
<% end%>
|
||||||
<!-- else quick_service or cashier for table -->
|
<!-- else quick_service or cashier for table -->
|
||||||
<% else %>
|
<% else %>
|
||||||
<% if @table.get_current_checkout_booking.nil? %>
|
<% if @table.current_checkout_booking.nil? %>
|
||||||
<% if !menu.code.include? "SPL" %>
|
<% if !menu.code.include? "SPL" %>
|
||||||
<li class="nav-item ">
|
<li class="nav-item ">
|
||||||
<p class="hidden menu-id"><%= menu.id %></p>
|
<p class="hidden menu-id"><%= menu.id %></p>
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
<% end%>
|
<% end%>
|
||||||
<!-- else quick_service or cashier for table -->
|
<!-- else quick_service or cashier for table -->
|
||||||
<% else %>
|
<% else %>
|
||||||
<% if @table.get_current_checkout_booking.nil? %>
|
<% if @table.current_checkout_booking.nil? %>
|
||||||
<% if !menu.code.include? "SPL" %>
|
<% if !menu.code.include? "SPL" %>
|
||||||
<div class="card custom-card testimonial-card animated fadeInRight menu_category sub_click" data-id="<%=menu.id%>">
|
<div class="card custom-card testimonial-card animated fadeInRight menu_category sub_click" data-id="<%=menu.id%>">
|
||||||
<div class='card-block custom-card-block'>
|
<div class='card-block custom-card-block'>
|
||||||
@@ -199,7 +199,7 @@
|
|||||||
<div class="col-md-3 col-lg-3 col-sm-3">Table : <%=@table.name%></div>
|
<div class="col-md-3 col-lg-3 col-sm-3">Table : <%=@table.name%></div>
|
||||||
<p class="hidden" id="table_id"><%=@table_id%></p>
|
<p class="hidden" id="table_id"><%=@table_id%></p>
|
||||||
<p class="hidden" id="table_type"><%=@table.type%></p>
|
<p class="hidden" id="table_type"><%=@table.type%></p>
|
||||||
<p class="hidden" id="table_get_current"><%=@table.get_current_checkout_booking%></p>
|
<p class="hidden" id="table_get_current"><%=@table.current_checkout_booking%></p>
|
||||||
<% end%>
|
<% end%>
|
||||||
|
|
||||||
<p class="hidden" id="booking_id"><%=@booking_id%></p>
|
<p class="hidden" id="booking_id"><%=@booking_id%></p>
|
||||||
@@ -231,7 +231,7 @@
|
|||||||
<p class="hidden" id="table_type"><%=@table.type%></p>
|
<p class="hidden" id="table_type"><%=@table.type%></p>
|
||||||
<p class="hidden" id="booking_id"><%=@booking_id%></p>
|
<p class="hidden" id="booking_id"><%=@booking_id%></p>
|
||||||
<p class="hidden" id="customer_id"><%=@customer ? @customer.customer_id : ''%></p>
|
<p class="hidden" id="customer_id"><%=@customer ? @customer.customer_id : ''%></p>
|
||||||
<p class="hidden" id="table_get_current"><%=@table.get_current_checkout_booking%></p>
|
<p class="hidden" id="table_get_current"><%=@table.current_checkout_booking%></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3 col-lg-3 col-sm-3">
|
<div class="col-md-3 col-lg-3 col-sm-3">
|
||||||
<button type="button" class="btn btn-xs btn-danger waves-effect" id='clear_all'>Clear
|
<button type="button" class="btn btn-xs btn-danger waves-effect" id='clear_all'>Clear
|
||||||
|
|||||||
Reference in New Issue
Block a user