order from app

This commit is contained in:
Myat Zin Wai Maw
2019-11-28 15:52:50 +06:30
parent fe5dc6bb5a
commit 09e7650452
8 changed files with 91 additions and 74 deletions

View File

@@ -64,77 +64,89 @@ class Api::OrdersController < Api::ApiController
def create
Rails.logger.debug "Order Source - " + params[:order_source].to_s
Rails.logger.debug "Table ID - " + params[:table_id].to_s
@shop = Shop.find_by_shop_code(params[:shop_code])
current_shift = ShiftSale.current_shift(@shop.shop_code)
if current_shift.nil?
@status = false
@message = "No Current Open Shift for This Employee"
else
current_user =Employee.find(current_shift.employee_id)
if checkin_checkout_time(params[:booking_id])
if checkin_checkout_time(params[:booking_id])
if params[:booking_id].present?
booking = Booking.find(params[:booking_id])
end
if params[:table_id].present?
if booking.nil? || booking.dining_facility_id.to_i != params[:table_id].to_i
table = DiningFacility.find(params[:table_id])
booking = table.get_current_booking
if params[:booking_id].present?
booking = Booking.find(params[:booking_id])
end
if params[:table_id].present?
if booking.nil? || booking.dining_facility_id.to_i != params[:table_id].to_i
table = DiningFacility.find(params[:table_id])
booking = table.get_current_booking
end
end
end
#for extratime
is_extra_time = false
extra_time = ''
#for extratime
is_extra_time = false
extra_time = ''
params[:order_items].each { |i|
i["item_instance_code"] = i["item_instance_code"].downcase.to_s
if i["item_instance_code"].include? "ext"
is_extra_time = true
arr_exts = i["item_instance_code"].split("_")
if arr_exts[1].match(/^(\d)+$/)
time = arr_exts[1].to_i*60*i["quantity"].to_i
extra_time = Time.at(time)
params[:order_items].each { |i|
i["item_instance_code"] = i["item_instance_code"].downcase.to_s
if i["item_instance_code"].include? "ext"
is_extra_time = true
arr_exts = i["item_instance_code"].split("_")
if arr_exts[1].match(/^(\d)+$/)
time = arr_exts[1].to_i*60*i["quantity"].to_i
extra_time = Time.at(time)
end
end
}
#end extra time
# begin
@order = Order.new
@order.source = params[:order_source]
@order.order_type = params[:order_type]
@order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
@order.items = params[:order_items]
@order.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id
@order.new_booking = true
@order.waiters = current_login_employee.name
@order.employee_name = current_login_employee.name
@order.shop_code =@shop.shop_code
@order.is_extra_time = is_extra_time
@order.extra_time = extra_time
#Create Table Booking or Room Booking
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
@order.new_booking = true
else
@order.new_booking = false
@order.booking_id = booking.booking_id
end
@status, @booking = @order.generate
if @status && @booking
Order.process_order_queue(@order.order_id,@order.table_id,@order.source)
end
if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id)
type = 'order'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
end
# # for parallel order
# remoteIP = ""
# begin
# @status, @booking = @order.generate
# remoteIP = request.remote_ip
# end while request.remote_ip != remoteIP
if current_user.role != "waiter" && params[:create_type] == "create_pay"
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court') || (@order.source == 'app')
@status, @sale = Sale.request_bill(@order,current_user,current_user)
end
end
}
#end extra time
# begin
@order = Order.new
@order.source = params[:order_source]
@order.order_type = params[:order_type]
@order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
@order.items = params[:order_items]
@order.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id
@order.new_booking = true
@order.waiters = current_login_employee.name
@order.employee_name = current_login_employee.name
@order.is_extra_time = is_extra_time
@order.extra_time = extra_time
#Create Table Booking or Room Booking
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
@order.new_booking = true
else
@order.new_booking = false
@order.booking_id = booking.booking_id
return return_json_status_with_code(406, "Checkout time is over!")
end
@status, @booking = @order.generate
if @status && @booking
Order.process_order_queue(@order.order_id,@order.table_id,@order.source)
end
if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id)
type = 'order'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
end
# # for parallel order
# remoteIP = ""
# begin
# @status, @booking = @order.generate
# remoteIP = request.remote_ip
# end while request.remote_ip != remoteIP
else
return return_json_status_with_code(406, "Checkout time is over!")
end
end

View File

@@ -1,5 +1,5 @@
class Api::PaymentsController < Api::ApiController
skip_before_action :authenticate
#Payment by Invoice ID
# Payment Method - [Cash | CreditNote | VISA | MASTER | etc..]
@@ -27,7 +27,9 @@ class Api::PaymentsController < Api::ApiController
if !sale.nil?
if sale.sale_status == "new"
if !params[:card_no].empty?
@status, @message = send_account_paymal(sale.grand_total, params[:card_no], sale.receipt_no)
current_shift = ShiftSale.current_shift(sale.shop_code)
current_login_employee =Employee.find(current_shift.employee_id)
@status, @message = send_account_paymal(sale.grand_total, params[:card_no], sale.receipt_no,current_login_employee)
if @status
sale_payment = SalePayment.new
status, @sale, @membership_data = sale_payment.process_payment(sale, current_login_employee, sale.grand_total, "paymal",params[:card_no])
@@ -67,15 +69,15 @@ class Api::PaymentsController < Api::ApiController
end
end
def send_account_paymal(amount, account_no, receipt_no)
def send_account_paymal(amount, account_no, receipt_no,current_login_employee)
sale = Sale.find_by_receipt_no(receipt_no)
@out = []
action_by = current_login_employee.name
@status = true
@message = ""
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",sale.shop_code)
if membership_setting.gateway_url
member_actions =MembershipAction.find_by_membership_type("get_account_balance")
member_actions =MembershipAction.find_by_membership_type_and_shop_code("get_account_balance",sale.shop_code)
if member_actions.gateway_url
@campaign_type_id = nil
url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s

View File

@@ -18,7 +18,7 @@ module LoginVerification
def current_shop
begin
shop_code ='263'
shop_code ='262'
@shop =Shop.find_by_shop_code(shop_code)
return @shop
rescue
@@ -42,7 +42,7 @@ module LoginVerification
#Shop Name in Navbor
def shop_detail
shop_code ='263'
shop_code ='262'
@shop = Shop.find_by_shop_code(shop_code)
return @shop
end

View File

@@ -168,15 +168,17 @@ class Origami::CustomersController < BaseOrigamiController
sale = Sale.find_by_receipt_no(receipt_no)
@out = []
action_by = current_user.name
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",@shop.shop_code)
if membership_setting.gateway_url
member_actions =MembershipAction.find_by_membership_type("get_account_balance")
member_actions =MembershipAction.find_by_membership_type_and_shop_code("get_account_balance",@shop.shop_code)
if member_actions.gateway_url
@campaign_type_id = nil
url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s
merchant_uid= member_actions.merchant_account_id
auth_token = member_actions.auth_token.to_s
membership_data = SalePayment.get_paypar_account_data(url,membership_setting.auth_token,merchant_uid,auth_token,account_no,amount,receipt_no)
puts membership_data.to_json
if membership_data["status"]==true
remark = "Payment by account no Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Transaction ref: #{membership_data[:transaction_ref]} | Reload amount #{membership_data[:reload_amount]} | Old Balance Amount #{membership_data[:old_balance_amount]} | DateTime : #{membership_data[:date]}"
sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" )

View File

@@ -5,11 +5,12 @@ if @status == true
json.order_items do
json.array! @order.order_items, :item_code, :item_name, :qty, :options, :remark,:price
end
json.sale_id @sale.sale_id
else
json.status :error
if @error_messages
json.error_messages @error_messages
else
json.error_messages @order.errors
json.error_messages @message
end
end

View File

@@ -1 +1 @@
5392
3453