mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
calcul total price of reservation with coupon when use wallet
This commit is contained in:
parent
c98a497b21
commit
802e239d5b
@ -132,6 +132,7 @@ class Reservation < ActiveRecord::Base
|
|||||||
unless coupon_code.nil?
|
unless coupon_code.nil?
|
||||||
cp = Coupon.find_by_code(coupon_code)
|
cp = Coupon.find_by_code(coupon_code)
|
||||||
if not cp.nil? and cp.status(user.id) == 'active'
|
if not cp.nil? and cp.status(user.id) == 'active'
|
||||||
|
@coupon = cp
|
||||||
total = invoice.invoice_items.map(&:amount).map(&:to_i).reduce(:+)
|
total = invoice.invoice_items.map(&:amount).map(&:to_i).reduce(:+)
|
||||||
unless on_site
|
unless on_site
|
||||||
invoice_items << Stripe::InvoiceItem.create(
|
invoice_items << Stripe::InvoiceItem.create(
|
||||||
@ -389,6 +390,9 @@ class Reservation < ActiveRecord::Base
|
|||||||
plan = Plan.find(plan_id)
|
plan = Plan.find(plan_id)
|
||||||
total += plan.amount
|
total += plan.amount
|
||||||
end
|
end
|
||||||
|
if @coupon
|
||||||
|
total = (total - (total * @coupon.percent_off / 100.0)).to_i
|
||||||
|
end
|
||||||
wallet_amount = (user.wallet.amount * 100).to_i
|
wallet_amount = (user.wallet.amount * 100).to_i
|
||||||
|
|
||||||
wallet_amount >= total ? total : wallet_amount
|
wallet_amount >= total ? total : wallet_amount
|
||||||
|
Loading…
x
Reference in New Issue
Block a user