fix api addorder and foc payment status

This commit is contained in:
Thein Lin Kyaw
2019-12-20 16:38:21 +06:30
parent 33afe167f7
commit 99c943a865
4 changed files with 25 additions and 18 deletions

View File

@@ -230,7 +230,7 @@ class Origami::AddordersController < BaseOrigamiController
end
end
def process_order_queue(order_id,table_id,order_source)
def process_order_queue(order_id, table_id, order_source)
#Send to background job for processing
order = Order.find(order_id)
sidekiq = Lookup.find_by_lookup_type("sidekiq")

View File

@@ -550,11 +550,14 @@ class Origami::PaymentsController < BaseOrigamiController
current_balance = nil
order_source = params[:type]
if(Sale.exists?(sale_id))
if Sale.exists?(sale_id)
saleObj = Sale.find(sale_id)
#calculate cash acmount
cash = saleObj.total_amount
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
if saleObj.discount_type == "member_discount"
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
saleObj.compute_by_sale_items(0, nil, order_source)
@@ -562,9 +565,6 @@ class Origami::PaymentsController < BaseOrigamiController
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
bookings = Booking.where("sale_id='#{sale_id}'")
if bookings[0].dining_facility_id.to_i > 0
table = DiningFacility.find(bookings[0].dining_facility_id)
@@ -573,8 +573,6 @@ class Origami::PaymentsController < BaseOrigamiController
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
end
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")

View File

@@ -402,7 +402,7 @@ class Order < ApplicationRecord
end
#Process order items and send to order queue
def self.process_order_queue(order_id,table_id,source)
def self.process_order_queue(order_id, table_id, source)
print_status = nil
cup_status = nil
@@ -422,7 +422,7 @@ class Order < ApplicationRecord
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
oqs.process_order(order, table_id, source)
end
from = getCloudDomain #get sub domain in cloud mode
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)

View File

@@ -77,18 +77,26 @@ class SalePayment < ApplicationRecord
if payment_for
invoice_sale_payments = SalePayment.get_sale_payment_for_credit(invoice)
amount_due = SalePayment.get_credit_amount_due_left(self.sale_id)[0] ? SalePayment.get_credit_amount_due_left(self.sale_id)[0].payment_amount.to_f : 0
puts "amount_due => #{amount_due}"
else
invoice_sale_payments = invoice.sale_payments
amount_due = invoice.grand_total
puts "amount_due => #{amount_due}"
end
puts "amount_due => #{amount_due}"
invoice_sale_payments.each do |payment|
if (payment.payment_status == "paid" )
amount_due = amount_due - payment.payment_amount
end
end
puts "Cash Amount -> #{cash_amount}"
if (amount_due > 0)
puts "payment_method -> #{payment_method}"
puts "Amount Due => #{amount_due}"
if amount_due > 0
payment_status = false
membership_data = nil
#route to payment type
@@ -118,6 +126,7 @@ class SalePayment < ApplicationRecord
when "paypar"
payment_status = paypar_payment
when "foc"
puts ">>>>> FOC <<<<<"
payment_status = foc_payment
when "paymal"
payment_status,membership_data = paymal_payment
@@ -418,19 +427,19 @@ class SalePayment < ApplicationRecord
def foc_payment
payment_status = false
sale = self.sale
# add to sale item with foc
sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }'")
sale_items = sale.sale_items
sale_items.each do|item|
SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price)
SaleItem.update_existing_item(item.qty, item, sale.sale_id, "foc", item.unit_price, item.price)
end
sale = Sale.find(self.sale.sale_id)
sale.compute_by_sale_items(sale.total_discount,'','','',"foc")
self.payment_method = "foc"
self.payment_amount = self.received_amount
# self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
self.outstanding_amount = 0.00
self.payment_status = "paid"
payment_status = self.save!
@@ -654,12 +663,12 @@ class SalePayment < ApplicationRecord
is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" }
if (sale.grand_total <= all_received_amount)
sale.payment_status = "paid"
if is_credit
sale.payment_status = "outstanding"
elsif is_foc
end
if is_foc
sale.payment_status = "foc"
else
sale.payment_status = "paid"
end
sale.sale_status = "completed"