From a01a3b7835f0d2fbf2a6747634159746f8619d42 Mon Sep 17 00:00:00 2001 From: Zoey Date: Thu, 13 Jun 2019 14:51:25 +0630 Subject: [PATCH] sync records --- app/controllers/api/sync_controller.rb | 4 ++- .../reports/receipt_no_controller.rb | 5 ++- app/models/assigned_order_item.rb | 19 +++++++++++ app/models/booking.rb | 31 +++++++++++++++++- dump.rdb | Bin 1214649 -> 1214653 bytes 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/sync_controller.rb b/app/controllers/api/sync_controller.rb index 93596c81..83acf8f6 100644 --- a/app/controllers/api/sync_controller.rb +++ b/app/controllers/api/sync_controller.rb @@ -10,6 +10,8 @@ class Api::SyncController < Api::ApiController SaleAudit.sync_sale_audit_records(params[:sale_audits]) SalePayment.sync_sale_payment_records(params[:sale_payments]) SaleTax.sync_sale_tax_records(params[:sale_taxes]) - ShiftSale.sync_shift_sale_records(params[:shift_sale_records]) + ShiftSale.sync_shift_sale_records(params[:shift_sales]) + Booking.sync_booking_records(params[:bookings]) + AssignedOrderItem.sync_assigned_order_item_records(params[:assigned_order_items]) end end \ No newline at end of file diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index b016b08d..318aec49 100755 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -71,11 +71,12 @@ authorize_resource :class => false end def sync_data - @orders, @order_items, @sales, @sale_items, @sale_taxes, @sale_payments, @sale_orders, @sale_audits, @shift_sales = Booking.get_sync_data(params[:sale_id]) + @orders, @order_items, @sales, @sale_items, @sale_taxes, @sale_payments, @sale_orders, @sale_audits, @bookings, @assigned_order_items, @shift_sales = Booking.get_sync_data(params[:sale_id]) # Here comes to call the sync api # url = "http://192.168.1.176:3000/en/api/sync_data" url = Lookup.sync_url + # token = Lookup.token begin @result = HTTParty.post(url.to_str, @@ -87,6 +88,8 @@ authorize_resource :class => false :sale_audits => @sale_audits, :sale_payments => @sale_payments, :sale_taxes => @sale_taxes, + :bookings => @bookings, + :assigned_order_items => @assigned_order_items, :shift_sales => @shift_sales }.to_json, :headers => { diff --git a/app/models/assigned_order_item.rb b/app/models/assigned_order_item.rb index 64570f7d..8f1d0694 100755 --- a/app/models/assigned_order_item.rb +++ b/app/models/assigned_order_item.rb @@ -7,6 +7,25 @@ class AssignedOrderItem < ApplicationRecord belongs_to :order belongs_to :order_queue_station + def self.sync_assigned_order_item_records(assigned_order_items) + if !assigned_order_items.nil? + assigned_order_items.each do |items| + unless AssignedOrderItem.exists?(items['assigned_order_item_id']) + order_item = AssignedOrderItem.new + order_item.assigned_order_item_id = item['assigned_order_item_id'] + order_item.item_code = item['item_code'] + order_item.instance_code = item['instance_code'] + order_item.order_queue_station_id = item['order_queue_station_id'] + order_item.order_id = item['order_id'] + order_item.print_status = item['print_status'] + order_item.delivery_status = item['delivery_status'] + order_item.save + puts '....... Assigned Order Item has been created .......' + end + end + end + end + def self.assigned_order_item (order, item_code, instance_code, order_queue_station ) assigned_order_item = AssignedOrderItem.new() assigned_order_item.order = order diff --git a/app/models/booking.rb b/app/models/booking.rb index 13345d36..da8f5410 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -11,6 +11,29 @@ class Booking < ApplicationRecord scope :active, -> {where("booking_status != 'moved'")} scope :today, -> {where("created_at >= #{Time.now.utc}")} + def self.sync_booking_records(bookings) + if !bookings.nil? + bookings.each do |b| + unless Booking.exists?(b['booking_id']) + booking = Booking.new + booking.booking_id = b['booking_id'] + booking.dining_facility_id = b['dining_facility_id'] + booking.checkin_at = b['checkin_at'] + booking.checkin_by = b['checkin_by'] + booking.checkout_at = b['checkout_at'] + booking.checkout_by = b['checkout_by'] + booking.reserved_at = b['reserved_at'] + booking.reserved_by = b['reserved_by'] + booking.booking_status = b['booking_status'] + booking.sale_id = b['sale_id'] + booking.customer_id = b['customer_id'] + booking.save + puts '....... Booking has been created ......' + end + end + end + end + def self.update_dining_facility(booking_arr, newd, old) table = DiningFacility.find(newd) exist = table.get_booking @@ -69,6 +92,12 @@ class Booking < ApplicationRecord .joins('left join sale_orders on sale_orders.order_id = order_items.order_id') .where('sale_orders.sale_id=?', sale_id) + @assigned_order_items = AssignedOrderItem.select('assigned_order_items.*') + .joins('left join sale_orders on sale_orders.order_id=assigned_order_items.order_id') + .where('sale_orders.sale_id=?', sale_id) + + @bookings = Booking.where('sale_id=?', sale_id) + @sales = Sale.where("sale_id=?", sale_id) @sale_items = SaleItem.where("sale_id=?", sale_id) @@ -85,7 +114,7 @@ class Booking < ApplicationRecord .joins('left join sales on sales.shift_sale_id = shift_sales.id') .where('sales.sale_id=?', sale_id) - return @orders, @order_items, @sales, @sale_items, @sale_taxes, @sale_payments, @sale_orders, @sale_audits, @shift_sales + return @orders, @order_items, @sales, @sale_items, @sale_taxes, @sale_payments, @sale_orders, @sale_audits, @bookings, @assigned_order_items, @shift_sales end private diff --git a/dump.rdb b/dump.rdb index 55cbda5a05f7ca99e0341267da4bc7d2acce6a7d..c1f013489d1f99408322c5a5a6269f21efecf0c8 100644 GIT binary patch delta 629 zcmZ9~Plysx9KiAUqoeMcn-6MfBlm4|Fi4v>|I|IrFa(RG5aD4Dp}AQJ{wd9aZKkcJ zduxS-7hO_1_lG)|3+3$YsY8bj{kdh(DJYhpg0kqjSwV--Y2NVt{dlk23_flKR}ctV zn3LbEg?!?)C!I)dJer$p>Yq4a@Ws))fS=UBR5e03BJ>bLu!M;)6C7b7tb~miBgP3k zv4e0B6U0u!*@@7gRAvuq3)sE{X7ITxDDG#V4T*{%c@-qes%tEl%jTl#L_UA&tXiZC z8Mug7uL4g9#$&qioe5_{u>f^M-39kiXJ#yY_6nrcTZ||PYB~1P6kW)YUwTxaGC?K# zthaTC69pOh{G~UGZn&(z(l)h2T4LCD;~y1p(aAtN=?7#l68yXmi4bp9fqLwtp&Nt0 zwfXIuwa->6ZB7&g9w~C09@RGf)DE}qbCOJ!K_w;p)bYEw|8Z zSKu_A%fVIiXw^%@RWIY`OTcwv(*`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