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_id, flag = OrderReservation.addOrderReservationInfo(order_reservation)
if flag
if !order_reservation_id.nil? && flag
shop = Shop.find_by_id(1)
if !shop.nil?
shop_code = shop.shop_code
@@ -90,6 +90,8 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController
from = ""
end
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
result = { :status => true, :order_reservation_id => order_reservation_id, :message => "Order reservation is already existed!" }
end

View File

@@ -53,45 +53,54 @@ class OrderReservation < ApplicationRecord
Rails.logger.debug order_reserve.to_s
check_order_reservation = OrderReservation.where("transaction_ref = ?",order_reserve[:reference])
if check_order_reservation.empty?
order_reservation = OrderReservation.new
order_reservation.order_reservation_type = order_reserve[:order_type]
order_reservation.customer_id = order_reserve[:cus_info]
order_reservation.requested_time = Time.zone.parse(order_reserve[:requested_time]).utc
if order_reserve[:pickup_time]
order_reservation.pickup_time = Time.zone.parse(order_reserve[:pickup_time]).utc
OrderReservation.transaction do
begin
order_reservation = OrderReservation.new
order_reservation.order_reservation_type = order_reserve[:order_type]
order_reservation.customer_id = order_reserve[:cus_info]
order_reservation.requested_time = Time.zone.parse(order_reserve[:requested_time]).utc
if order_reserve[:pickup_time]
order_reservation.pickup_time = Time.zone.parse(order_reserve[:pickup_time]).utc
end
order_reservation.callback_url = order_reserve[:callback_url]
order_reservation.transaction_ref = order_reserve[:reference]
if order_reserve[:order_info]
order_reservation.item_count = order_reserve[:order_info][:items].count
order_reservation.payment_type = order_reserve[:payment_info][:payment_type]
order_reservation.payment_status = order_reserve[:payment_info][:payment_status]
order_reservation.payment_ref = order_reserve[:payment_info][:payment_ref]
order_reservation.taxes = order_reserve[:payment_info][:taxes].to_json
order_reservation.total_amount = order_reserve[:payment_info][:sub_total]
order_reservation.total_tax = order_reserve[:payment_info][:total_tax]
order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount]
order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge]
order_reservation.grand_total = order_reserve[:payment_info][:grand_total]
order_reservation.transaction_fee = order_reserve[:payment_info][:transaction_fee]
order_reservation.order_remark = order_reserve[:order_info][:order_remark]
end
if order_reserve[:reservation_info]
order_reservation.total_customer = order_reserve[:reservation_info][:total_user]
# order_reservation.order_remark = order_reserve[:reservation_info][:reservation_note]
end
order_reservation.save!
if order_reserve[:order_info][:items]
order_reserve[:order_info][:items].each do |oritem|
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
order_reservation.callback_url = order_reserve[:callback_url]
order_reservation.transaction_ref = order_reserve[:reference]
if order_reserve[:order_info]
order_reservation.item_count = order_reserve[:order_info][:items].count
order_reservation.payment_type = order_reserve[:payment_info][:payment_type]
order_reservation.payment_status = order_reserve[:payment_info][:payment_status]
order_reservation.payment_ref = order_reserve[:payment_info][:payment_ref]
order_reservation.taxes = order_reserve[:payment_info][:taxes].to_json
order_reservation.total_amount = order_reserve[:payment_info][:sub_total]
order_reservation.total_tax = order_reserve[:payment_info][:total_tax]
order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount]
order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge]
order_reservation.grand_total = order_reserve[:payment_info][:grand_total]
order_reservation.transaction_fee = order_reserve[:payment_info][:transaction_fee]
order_reservation.order_remark = order_reserve[:order_info][:order_remark]
end
if order_reserve[:reservation_info]
order_reservation.total_customer = order_reserve[:reservation_info][:total_user]
# order_reservation.order_remark = order_reserve[:reservation_info][:reservation_note]
end
order_reservation.save!
if order_reserve[:order_info][:items]
order_reserve[:order_info][:items].each do |oritem|
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
else
return check_order_reservation[0].id, false
end