sync shift sale data updated

This commit is contained in:
Zoey
2019-06-13 14:59:32 +06:30
parent a01a3b7835
commit fee0541e28
2 changed files with 36 additions and 26 deletions

View File

@@ -35,9 +35,19 @@ class ShiftSale < ApplicationRecord
def self.sync_shift_sale_records(shift_sales) def self.sync_shift_sale_records(shift_sales)
if !shift_sales.nil? if !shift_sales.nil?
shift_sales.each do |ss| shift_sales.each do |ss|
unless ShiftSale.exists?(ss['id']) status = nil
shift_sale = nil
if ShiftSale.exists?(ss['id'])
shift_sale = ShiftSale.find(ss['id'])
status = 'updated'
else
shift_sale = ShiftSale.new shift_sale = ShiftSale.new
shift_sale.id = ss['id'] shift_sale.id = ss['id']
status = 'created'
end
shift_sale.cashier_terminal_id = ss['cashier_terminal_id'] shift_sale.cashier_terminal_id = ss['cashier_terminal_id']
shift_sale.shift_started_at = ss['shift_started_at'] shift_sale.shift_started_at = ss['shift_started_at']
shift_sale.shift_closed_at = ss['shift_closed_at'] shift_sale.shift_closed_at = ss['shift_closed_at']
@@ -62,8 +72,8 @@ class ShiftSale < ApplicationRecord
shift_sale.total_receipt = ss['total_receipt'] shift_sale.total_receipt = ss['total_receipt']
shift_sale.total_void = ss['total_void'] shift_sale.total_void = ss['total_void']
shift_sale.save shift_sale.save
puts '....... Shift Sale has been created ......'
end puts "....... Shift Sale has been #{status} ......"
end end
end end
end end

BIN
dump.rdb

Binary file not shown.