Merge branch 'r-1902001-01' into foodcourt
This commit is contained in:
@@ -74,6 +74,8 @@ class SalePayment < ApplicationRecord
|
||||
#get all payment for this invoices
|
||||
if payment_for
|
||||
amount_due = SalePayment.get_credit_amount_due_left(self.sale_id).first.payment_amount
|
||||
elsif payment_method == 'foc'
|
||||
amount_due = invoice.total_amount
|
||||
else
|
||||
amount_due = invoice.sale_payments
|
||||
.map(&:payment_amount).reduce(invoice.grand_total, :-)
|
||||
@@ -140,9 +142,6 @@ class SalePayment < ApplicationRecord
|
||||
remark = "#{self.sale_payment_id}||#{shift_sale_id} -> #{remark}"
|
||||
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by.name)
|
||||
if payment_method == "cash"
|
||||
update_shift_for_credit_payment
|
||||
end
|
||||
else
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by.name)
|
||||
end
|
||||
@@ -235,14 +234,15 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id)
|
||||
membership_actions_data = PaymentMethodSetting.find_by_payment_method("Redeem")
|
||||
membership_actions_data = PaymentMethodSetting.find_by_payment_method("Redeem")
|
||||
if !membership_actions_data.nil?
|
||||
|
||||
url = paypar_url.to_s + membership_actions_data.gateway_url.to_s
|
||||
merchant_uid = membership_actions_data.merchant_account_id
|
||||
auth_token = membership_actions_data.auth_token
|
||||
campaign_type_id = JSON.parse(membership_actions_data.additional_parameters)["campaign_type_id"]
|
||||
campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"]
|
||||
sale_data = Sale.find_by_sale_id(sale_id)
|
||||
account_no = Customer.find_by_customer_id(self.sale.customer_id).paypar_account_no
|
||||
|
||||
if sale_data
|
||||
others = 0
|
||||
@@ -259,7 +259,7 @@ class SalePayment < ApplicationRecord
|
||||
redeem_amount:received_amount,
|
||||
receipt_no:sale_data.receipt_no,
|
||||
campaign_type_id:campaign_type_id,
|
||||
account_no:"",
|
||||
account_no: account_no,
|
||||
merchant_uid:merchant_uid,
|
||||
auth_token:auth_token}.to_json,
|
||||
:headers => {
|
||||
@@ -371,12 +371,8 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
private
|
||||
def cash_payment(payment_for=false)
|
||||
status = false
|
||||
sale_payments_data = SalePayment.find_by_sale_id(self.sale_id)
|
||||
if sale_payments_data.nil?
|
||||
status = true
|
||||
end
|
||||
|
||||
sale_payments_data = SalePayment.find_by_sale_id(self.sale_id)
|
||||
payment_status = false
|
||||
|
||||
self.payment_method = "cash"
|
||||
@@ -391,8 +387,11 @@ class SalePayment < ApplicationRecord
|
||||
self.payment_status = "paid"
|
||||
payment_status = self.save!
|
||||
if !payment_for
|
||||
sale_update_payment_status(self.received_amount,status)
|
||||
sale_update_payment_status(self.received_amount)
|
||||
else
|
||||
update_shift_for_credit_payment()
|
||||
end
|
||||
|
||||
balance_amount =0.0
|
||||
outstanding_amount =0.0
|
||||
if self.sale.grand_total.to_f > self.received_amount.to_f
|
||||
@@ -408,6 +407,7 @@ class SalePayment < ApplicationRecord
|
||||
def foc_payment
|
||||
payment_status = false
|
||||
sale = self.sale
|
||||
sale.sale_payments.update_all(payment_status: "cancelled")
|
||||
# add to sale item with foc
|
||||
sale_items = sale.sale_items
|
||||
|
||||
@@ -424,7 +424,7 @@ class SalePayment < ApplicationRecord
|
||||
self.payment_status = "paid"
|
||||
payment_status = self.save!
|
||||
# sale_update_payment_status(self.received_amount)
|
||||
sale_update_payment_status(0)
|
||||
sale_update_payment_status(0, true)
|
||||
return payment_status
|
||||
end
|
||||
|
||||
@@ -501,7 +501,7 @@ class SalePayment < ApplicationRecord
|
||||
#Next time - validate if the vochure number is valid - within
|
||||
customer_data = Customer.find_by_customer_id(self.sale.customer_id)
|
||||
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id)
|
||||
membership_data = redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id)
|
||||
|
||||
#record an payment in sale-audit
|
||||
remark = "#{membership_data} Redeem- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} "
|
||||
@@ -630,22 +630,32 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
def sale_update_payment_status(paid_amount, check_foc = false)
|
||||
#update amount_outstanding
|
||||
if ['completed'].include? sale.sale_status
|
||||
return
|
||||
end
|
||||
sale = self.sale
|
||||
total_payment_amount = sale.sale_payments.reload.sum(&:payment_amount)
|
||||
sale_payments = sale.sale_payments.reload
|
||||
|
||||
is_credit = sale_payments.any? { |x| x.payment_method == "creditnote" }
|
||||
is_foc = sale_payments.any? { |x| x.payment_method == "foc" } || check_foc
|
||||
|
||||
if is_foc
|
||||
total_payment_amount = 0.0
|
||||
else
|
||||
total_payment_amount = sale_payments.sum(&:payment_amount)
|
||||
end
|
||||
|
||||
sale.amount_received = sale.amount_received.to_f + paid_amount.to_f
|
||||
sale.amount_changed = total_payment_amount - sale.grand_total.to_f
|
||||
|
||||
is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" }
|
||||
is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" }
|
||||
|
||||
if sale.grand_total <= total_payment_amount && sale.sale_status == "new"
|
||||
if is_foc
|
||||
sale.payment_status = 'foc'
|
||||
sale.sale_status = 'completed'
|
||||
elsif sale.grand_total <= total_payment_amount && sale.sale_status == "new"
|
||||
sale.payment_status = "paid"
|
||||
if is_credit
|
||||
sale.payment_status = "outstanding"
|
||||
end
|
||||
if is_foc
|
||||
sale.payment_status = "foc"
|
||||
end
|
||||
|
||||
sale.sale_status = "completed"
|
||||
|
||||
@@ -672,26 +682,25 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sale.save!
|
||||
sale.save!
|
||||
|
||||
if check_foc
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
elsif paid_amount.to_f == 0 && !is_credit
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
end
|
||||
if check_foc
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
elsif paid_amount.to_f == 0 && !is_credit
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
end
|
||||
end
|
||||
|
||||
# update for cashier shift
|
||||
def update_shift
|
||||
current_shift_user = Employee.find_by_id(self.action_by.id)
|
||||
shift = ShiftSale.current_open_shift(current_shift_user)
|
||||
shift = ShiftSale.current_open_shift(self.action_by.id)
|
||||
|
||||
if shift.nil?
|
||||
current_shift_user = Employee.find_by_id(self.sale.cashier_id)
|
||||
@@ -717,7 +726,10 @@ class SalePayment < ApplicationRecord
|
||||
# update for shift with credit payment
|
||||
def update_shift_for_credit_payment
|
||||
shift_credit = ShiftSale.find_by_id(self.sale.shift_sale_id)
|
||||
shift = ShiftSale.find_by_id(ShiftSale.current_shift)
|
||||
shift = self.action_by.current_shift
|
||||
if !shift.nil?
|
||||
shift = ShiftSale.current_shift
|
||||
end
|
||||
if !shift.nil?
|
||||
credit_payment_left = get_credit_payment_left[0].payment_amount.to_f
|
||||
if self.payment_method == "cash"
|
||||
@@ -726,7 +738,6 @@ class SalePayment < ApplicationRecord
|
||||
else
|
||||
# extra_changed_amount = self.received_amount.to_f + credit_payment_left
|
||||
shift.cash_sales = shift.cash_sales.to_f + (self.received_amount.to_f + credit_payment_left)
|
||||
|
||||
self.sale.amount_received = self.sale.amount_received.to_f - credit_payment_left
|
||||
self.sale.amount_changed = self.sale.amount_changed.to_f - credit_payment_left
|
||||
self.sale.save!
|
||||
|
||||
Reference in New Issue
Block a user