Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into crm
This commit is contained in:
@@ -16,6 +16,10 @@ class OrderQueueStation < ApplicationRecord
|
||||
oqpbz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id)
|
||||
|
||||
order_items = order.order_items
|
||||
|
||||
# get dining
|
||||
booking = Booking.find_by_dining_facility_id(dining.id)
|
||||
|
||||
#Assign OQS id to order Items
|
||||
oqs_stations.each do |oqs|
|
||||
#Get List of items -
|
||||
@@ -26,29 +30,53 @@ class OrderQueueStation < ApplicationRecord
|
||||
#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.
|
||||
# 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
|
||||
|
||||
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
||||
else
|
||||
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
||||
end
|
||||
# end
|
||||
|
||||
if oqs.auto_print
|
||||
print_slip(oqs, order, order_items)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#Print OQS where printing is require
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
#Print order_items in 1 slip
|
||||
def print_slip
|
||||
def print_slip(oqs, order, order_items)
|
||||
unique_code="OrderSummaryPdf"
|
||||
|
||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
||||
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
|
||||
order_queue_printer.print_order_summary(oqs,order.order_id, print_status="")
|
||||
|
||||
AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai|
|
||||
# update print status for order items
|
||||
ai.print_status=true
|
||||
ai.save
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#Print order_items in 1 slip per item
|
||||
def print_slip_item
|
||||
#Print order_item in 1 slip per item
|
||||
def print_slip_item(oqs, assigned_order_item)
|
||||
unique_code="OrderItemPdf"
|
||||
|
||||
# print when complete click
|
||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
||||
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
|
||||
order_queue_printer.print_order_item(oqs,item.order_id, item.item_code, print_status="" )
|
||||
|
||||
# update print status for completed same order items
|
||||
assigned_order_item.each do |ai|
|
||||
ai.print_status=true
|
||||
ai.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,66 +1,128 @@
|
||||
class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
|
||||
def print_order_item(oqs,order_id, item_code)
|
||||
def print_order_item(oqs,order_id, item_code, print_status)
|
||||
#Use CUPS service
|
||||
#Generate PDF
|
||||
#Print
|
||||
order_item= print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code)
|
||||
pdf = OrderItemPdf.new(order_item[0])
|
||||
pdf.render_file "tmp/receipt.pdf"
|
||||
order_item = print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code)
|
||||
|
||||
filename = "tmp/order_item_#{order_item[0].item_name}" + ".pdf"
|
||||
pdf = OrderItemPdf.new(order_item[0], print_status)
|
||||
pdf.render_file filename
|
||||
|
||||
if oqs.print_copy
|
||||
self.print("tmp/receipt.pdf", oqs.printer_name)
|
||||
self.print("tmp/receipt.pdf", oqs.printer_name)
|
||||
self.print(filename, oqs.printer_name)
|
||||
|
||||
#For print copy
|
||||
pdf.render_file filename.gsub(".","-copy.")
|
||||
self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
self.print("tmp/receipt.pdf", oqs.printer_name)
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
end
|
||||
|
||||
def print_order_summary(oqs,order_id)
|
||||
# Query for per order
|
||||
def print_order_summary(oqs, order_id, print_status)
|
||||
#Use CUPS service
|
||||
#Generate PDF
|
||||
#Print
|
||||
order=print_query('order_summary',order_id)
|
||||
#Print
|
||||
order=print_query('order_summary', order_id)
|
||||
# For Print Per Item
|
||||
if oqs.cut_per_item
|
||||
order.each do|odi|
|
||||
pdf = OrderItemPdf.new(odi)
|
||||
pdf.render_file "tmp/receipt.pdf"
|
||||
filename = "tmp/order_item_#{odi.item_name}" + ".pdf"
|
||||
pdf = OrderItemPdf.new(odi, print_status)
|
||||
# pdf.render_file "tmp/order_item.pdf"
|
||||
pdf.render_file filename
|
||||
if oqs.print_copy
|
||||
self.print("tmp/receipt.pdf", oqs.printer_name)
|
||||
self.print("tmp/receipt.pdf", oqs.printer_name)
|
||||
self.print(filename, oqs.printer_name)
|
||||
self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
self.print("tmp/receipt.pdf", oqs.printer_name)
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
end
|
||||
# For Print Order Summary
|
||||
else
|
||||
filename = "tmp/order_summary_#{order_id}" + ".pdf"
|
||||
pdf = OrderSummaryPdf.new(order)
|
||||
filename = "tmp/order_summary_#{ order_id }" + ".pdf"
|
||||
pdf = OrderSummaryPdf.new(order, print_status)
|
||||
pdf.render_file filename
|
||||
self.print(filename, oqs.printer_name)
|
||||
if oqs.print_copy
|
||||
self.print(filename, oqs.printer_name)
|
||||
|
||||
#For print copy
|
||||
pdf.render_file filename.gsub(".","-copy.")
|
||||
self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Print for orders in booking
|
||||
def print_booking_summary(oqs, booking_id, print_status)
|
||||
order=print_query('booking_summary', booking_id)
|
||||
# For Print Per Item
|
||||
if oqs.cut_per_item
|
||||
order.each do|odi|
|
||||
filename = "tmp/order_item_#{odi.item_name}" + ".pdf"
|
||||
pdf = OrderItemPdf.new(odi, print_status)
|
||||
pdf.render_file filename
|
||||
|
||||
if oqs.print_copy
|
||||
self.print(filename, oqs.printer_name)
|
||||
|
||||
#For print copy
|
||||
pdf.render_file filename.gsub(".","-copy.")
|
||||
self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
end
|
||||
# For Print Order Summary
|
||||
else
|
||||
filename = "tmp/booking_summary_#{ booking_id }" + ".pdf"
|
||||
pdf = OrderSummaryPdf.new(order, print_status)
|
||||
pdf.render_file filename
|
||||
if oqs.print_copy
|
||||
self.print(filename, oqs.printer_name)
|
||||
|
||||
#For print copy
|
||||
pdf.render_file filename.gsub(".","-copy.")
|
||||
self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Query for OQS with status
|
||||
def print_query(type, code)
|
||||
if type == 'order_item'
|
||||
def print_query(type, id)
|
||||
if type == "order_item"
|
||||
OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
|
||||
.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")
|
||||
.where("order_items.item_code='" + code + "'")
|
||||
.where("order_items.item_code = '#{ id }'")
|
||||
.group("order_items.item_code")
|
||||
else
|
||||
elsif type == "order_summary"
|
||||
OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
|
||||
.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")
|
||||
.where("orders.order_id='" + code + "'")
|
||||
.group("order_items.item_code")
|
||||
.where("orders.order_id = '#{ id }'")
|
||||
else
|
||||
# order summary for booking
|
||||
OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
|
||||
.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")
|
||||
.where("b.booking_id = '#{ id }'")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -32,48 +32,49 @@ class SaleItem < ApplicationRecord
|
||||
|
||||
# Calculate food total and beverage total
|
||||
def self.calculate_food_beverage(sale_items)
|
||||
food_prices=0
|
||||
beverage_prices=0
|
||||
|
||||
sale_items.each do |si|
|
||||
food_price, beverage_price = self.get_price(si.sale_item_id)
|
||||
|
||||
food_prices = food_prices + food_price
|
||||
beverage_prices = beverage_prices + beverage_price
|
||||
rebateacc = Account.where("rebate=?",true)
|
||||
puts "Account that can rebate"
|
||||
rebateacc.each do |i|
|
||||
puts i.title
|
||||
end
|
||||
puts food_prices
|
||||
puts beverage_prices
|
||||
return food_prices, beverage_prices
|
||||
prices=0
|
||||
sale_items.each do |si|
|
||||
price = self.get_price(si.sale_item_id,rebateacc)
|
||||
|
||||
prices = prices + price
|
||||
end
|
||||
return prices
|
||||
end
|
||||
|
||||
# get food price or beverage price for item
|
||||
def self.get_price(sale_item_id)
|
||||
food_price=0
|
||||
beverage_price=0
|
||||
def self.get_price(sale_item_id,rebateacc)
|
||||
price=0
|
||||
|
||||
item=SaleItem.select("sale_items.price , menu_items.account_id")
|
||||
.joins("left join menu_items on menu_items.item_code = sale_items.product_code")
|
||||
.where("sale_items.sale_item_id=?", sale_item_id.to_s)
|
||||
if item[0].account_id == 1
|
||||
food_price = item[0].price
|
||||
else
|
||||
beverage_price = item[0].price
|
||||
end
|
||||
|
||||
return food_price, beverage_price
|
||||
end
|
||||
|
||||
def self.get_overall_discount(sale_id)
|
||||
price = 0.0
|
||||
item=SaleItem.where("product_code=?", sale_id)
|
||||
|
||||
item.each do|i|
|
||||
price += i.price
|
||||
rebateacc.each do |i|
|
||||
if item[0].account_id == i.id
|
||||
price = item[0].price
|
||||
end
|
||||
end
|
||||
|
||||
return price
|
||||
end
|
||||
|
||||
# def self.get_overall_discount(sale_id)
|
||||
# price = 0.0
|
||||
# item=SaleItem.where("product_code=?", sale_id)
|
||||
#
|
||||
# item.each do|i|
|
||||
# price += i.price
|
||||
# end
|
||||
#
|
||||
# return price
|
||||
# end
|
||||
|
||||
private
|
||||
def generate_custom_id
|
||||
self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI")
|
||||
|
||||
@@ -258,7 +258,9 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
def rebat(sObj)
|
||||
food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items)
|
||||
rebate_prices = SaleItem.calculate_food_beverage(sObj.sale_items)
|
||||
puts "rebate_prices"
|
||||
puts rebate_prices
|
||||
generic_customer_id = sObj.customer.membership_id
|
||||
if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0
|
||||
paypar = sObj.sale_payments
|
||||
@@ -268,12 +270,10 @@ class SalePayment < ApplicationRecord
|
||||
payparcost = payparcost + pp.payment_amount
|
||||
end
|
||||
end
|
||||
overall_dis = SaleItem.get_overall_discount(sObj.id)
|
||||
total_amount = food_prices - payparcost + overall_dis
|
||||
puts "total_amount"
|
||||
puts food_prices
|
||||
puts payparcost
|
||||
puts total_amount
|
||||
# overall_dis = SaleItem.get_overall_discount(sObj.id)
|
||||
overall_dis = sObj.total_discount
|
||||
|
||||
total_amount = rebate_prices - payparcost + overall_dis
|
||||
if total_amount > 0
|
||||
receipt_no = sObj.receipt_no
|
||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
|
||||
Reference in New Issue
Block a user