sync data record
This commit is contained in:
@@ -60,6 +60,20 @@ class Booking < ApplicationRecord
|
||||
.order("sale_id DESC")
|
||||
end
|
||||
|
||||
def self.get_sync_data(sale_id)
|
||||
@orders = Order.select('orders.*')
|
||||
.joins('left join booking_orders on booking_orders.order_id = orders.order_id')
|
||||
.joins('left join bookings on bookings.booking_id = booking_orders.booking_id')
|
||||
.where('bookings.sale_id=?', sale_id)
|
||||
|
||||
@order_items = OrderItem.select('order_items.*')
|
||||
.joins('left join booking_orders on booking_orders.order_id = order_items.order_id')
|
||||
.joins('left join bookings on bookings.booking_id = booking_orders.booking_id')
|
||||
.where('bookings.sale_id=?', sale_id)
|
||||
|
||||
return @orders, @order_items
|
||||
end
|
||||
|
||||
private
|
||||
def generate_custom_id
|
||||
self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI")
|
||||
|
||||
@@ -560,4 +560,25 @@ class Order < ApplicationRecord
|
||||
self.date = Time.now.utc
|
||||
end
|
||||
|
||||
def self.sync_order_records(orders)
|
||||
if !orders.nil?
|
||||
orders.each do |o|
|
||||
unless Order.exists?(o.order_id)
|
||||
order = Order.new()
|
||||
order.order_id = o.order_id
|
||||
order.date = o.date
|
||||
order.source = o.source
|
||||
order.order_type = o.order_type
|
||||
order.customer_id = o.customer_id
|
||||
order.item_count = o.item_count
|
||||
order.quantity_count = o.quantity_count
|
||||
order.status = o.status
|
||||
order.waiters = o.waiters
|
||||
order.guest_info = o.guest_info
|
||||
order.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -65,6 +65,33 @@ class OrderItem < ApplicationRecord
|
||||
return order_details
|
||||
end
|
||||
|
||||
def self.sync_order_item_records(order_items)
|
||||
if !order_items.nil?
|
||||
order_items.each do |item|
|
||||
unless OrderItem.exists?(item.order_items_id)
|
||||
order_item = OrderItem.new()
|
||||
order_item.order_items_id = item.order_items_id
|
||||
order_item.order_id = item.order_id
|
||||
order_item.order_item_status = item.order_item_status
|
||||
order_item.item_order_by = item.item_order_by
|
||||
order_item.item_code = item.item_code
|
||||
order_item.item_instance_code = item.item_instance_code
|
||||
order_item.item_name = item.item_name
|
||||
order_item.alt_name = item.alt_name
|
||||
order_item.account_id = item.account_id
|
||||
order_item.qty = item.qty
|
||||
order_item.price = item.price
|
||||
order_item.remark = item.remark
|
||||
order_item.options = item.options
|
||||
order_item.set_menu_items = item.set_menu_items
|
||||
order_item.taxable = item.taxable
|
||||
order_item.completed_by = item.completed_by
|
||||
order_item.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def generate_custom_id
|
||||
self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI")
|
||||
|
||||
Reference in New Issue
Block a user