order reservation null issue checked

This commit is contained in:
Aung Kyaw Phyoe
2019-01-14 13:48:13 +06:30
parent 0d60e97014
commit 7ad4a38398
2 changed files with 50 additions and 39 deletions

View File

@@ -69,7 +69,7 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController
order_reservation = params order_reservation = params
order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation) order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation)
if flag if !order_reservation_id.nil? && flag
shop = Shop.find_by_id(1) shop = Shop.find_by_id(1)
if !shop.nil? if !shop.nil?
shop_code = shop.shop_code shop_code = shop.shop_code
@@ -90,6 +90,8 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController
from = "" from = ""
end end
ActionCable.server.broadcast "order_reservation_channel",data: order_reservation,shop_code: shop_code,from:from,audio:audio ActionCable.server.broadcast "order_reservation_channel",data: order_reservation,shop_code: shop_code,from:from,audio:audio
elsif order_reservation_id.nil? && !flag
result = { :status => false, :message => "Some error occurred!" }
else else
result = { :status => true, :order_reservation_id => order_reservation_id, :message => "Order reservation is already existed!" } result = { :status => true, :order_reservation_id => order_reservation_id, :message => "Order reservation is already existed!" }
end end

View File

@@ -53,45 +53,54 @@ class OrderReservation < ApplicationRecord
Rails.logger.debug order_reserve.to_s Rails.logger.debug order_reserve.to_s
check_order_reservation = OrderReservation.where("transaction_ref = ?",order_reserve[:reference]) check_order_reservation = OrderReservation.where("transaction_ref = ?",order_reserve[:reference])
if check_order_reservation.empty? if check_order_reservation.empty?
order_reservation = OrderReservation.new OrderReservation.transaction do
order_reservation.order_reservation_type = order_reserve[:order_type] begin
order_reservation.customer_id = order_reserve[:cus_info] order_reservation = OrderReservation.new
order_reservation.requested_time = Time.zone.parse(order_reserve[:requested_time]).utc order_reservation.order_reservation_type = order_reserve[:order_type]
if order_reserve[:pickup_time] order_reservation.customer_id = order_reserve[:cus_info]
order_reservation.pickup_time = Time.zone.parse(order_reserve[:pickup_time]).utc order_reservation.requested_time = Time.zone.parse(order_reserve[:requested_time]).utc
end if order_reserve[:pickup_time]
order_reservation.callback_url = order_reserve[:callback_url] order_reservation.pickup_time = Time.zone.parse(order_reserve[:pickup_time]).utc
order_reservation.transaction_ref = order_reserve[:reference] end
if order_reserve[:order_info] order_reservation.callback_url = order_reserve[:callback_url]
order_reservation.item_count = order_reserve[:order_info][:items].count order_reservation.transaction_ref = order_reserve[:reference]
order_reservation.payment_type = order_reserve[:payment_info][:payment_type] if order_reserve[:order_info]
order_reservation.payment_status = order_reserve[:payment_info][:payment_status] order_reservation.item_count = order_reserve[:order_info][:items].count
order_reservation.payment_ref = order_reserve[:payment_info][:payment_ref] order_reservation.payment_type = order_reserve[:payment_info][:payment_type]
order_reservation.taxes = order_reserve[:payment_info][:taxes].to_json order_reservation.payment_status = order_reserve[:payment_info][:payment_status]
order_reservation.total_amount = order_reserve[:payment_info][:sub_total] order_reservation.payment_ref = order_reserve[:payment_info][:payment_ref]
order_reservation.total_tax = order_reserve[:payment_info][:total_tax] order_reservation.taxes = order_reserve[:payment_info][:taxes].to_json
order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount] order_reservation.total_amount = order_reserve[:payment_info][:sub_total]
order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge] order_reservation.total_tax = order_reserve[:payment_info][:total_tax]
order_reservation.grand_total = order_reserve[:payment_info][:grand_total] order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount]
order_reservation.transaction_fee = order_reserve[:payment_info][:transaction_fee] order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge]
order_reservation.order_remark = order_reserve[:order_info][:order_remark] order_reservation.grand_total = order_reserve[:payment_info][:grand_total]
end order_reservation.transaction_fee = order_reserve[:payment_info][:transaction_fee]
if order_reserve[:reservation_info] order_reservation.order_remark = order_reserve[:order_info][:order_remark]
order_reservation.total_customer = order_reserve[:reservation_info][:total_user] end
# order_reservation.order_remark = order_reserve[:reservation_info][:reservation_note] if order_reserve[:reservation_info]
end order_reservation.total_customer = order_reserve[:reservation_info][:total_user]
order_reservation.save! # order_reservation.order_remark = order_reserve[:reservation_info][:reservation_note]
if order_reserve[:order_info][:items] end
order_reserve[:order_info][:items].each do |oritem| order_reservation.save!
OrderReservationItem.process_order_reservation_item(oritem[:product_code],oritem[:item_instance_code],oritem[:product_name],oritem[:product_alt_name], if order_reserve[:order_info][:items]
oritem[:account_id],oritem[:qty],oritem[:price],oritem[:unit_price], order_reserve[:order_info][:items].each do |oritem|
oritem[:options],nil,order_reservation.id) OrderReservationItem.process_order_reservation_item(oritem[:product_code],oritem[:item_instance_code],oritem[:product_name],oritem[:product_alt_name],
oritem[:account_id],oritem[:qty],oritem[:price],oritem[:unit_price],
oritem[:options],nil,order_reservation.id)
end
end
if order_reserve[:delivery_info]
Delivery.addDeliveryInfo(order_reserve[:delivery_info],order_reservation.id)
end
return order_reservation.id, true
rescue ActiveRecord::StatementInvalid
raise ActiveRecord::Rollback
return nil, false
end end
end end
if order_reserve[:delivery_info]
Delivery.addDeliveryInfo(order_reserve[:delivery_info],order_reservation.id)
end
return order_reservation.id, true
else else
return check_order_reservation[0].id, false return check_order_reservation[0].id, false
end end