update foc and pdf

This commit is contained in:
Aung Myo
2017-08-15 15:14:55 +06:30
parent 74200bb2e7
commit e4a2d58e5e
10 changed files with 146 additions and 39 deletions

View File

@@ -46,6 +46,8 @@ class SalePayment < ApplicationRecord
payment_status = giftcard_payment
when "paypar"
payment_status = paypar_payment
when "foc"
payment_status = foc_payment
else
puts "it was something else"
end
@@ -164,6 +166,17 @@ class SalePayment < ApplicationRecord
return payment_status
end
def foc_payment
payment_status = false
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.payment_status = "paid"
payment_method = self.save!
sale_update_payment_status(self.received_amount)
return payment_status
end
def creditnote_payment(customer_id)
payment_status = false
@@ -257,11 +270,15 @@ class SalePayment < ApplicationRecord
all_received_amount = 0.0
sObj = Sale.find(self.sale_id)
is_credit = 0
is_foc = 0
sObj.sale_payments.each do |spay|
all_received_amount += spay.payment_amount.to_f
if spay.payment_method == "creditnote"
is_credit = 1
end
if spay.payment_method == "foc"
is_foc = 1
end
end
if (self.sale.grand_total <= all_received_amount)
if is_credit == 0
@@ -269,9 +286,16 @@ class SalePayment < ApplicationRecord
else
self.sale.payment_status = "outstanding"
end
if is_foc == 0
self.sale.payment_status = "paid"
else
self.sale.payment_status = "foc"
end
self.sale.sale_status = "completed"
if MembershipSetting.find_by_rebate(1)
if MembershipSetting.find_by_rebate(1) && is_foc == 0
response = rebat(sObj)
if !response.nil?