1
0
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:
Peng DU 2016-09-20 16:54:23 +02:00
parent c98a497b21
commit 802e239d5b

View File

@ -132,6 +132,7 @@ class Reservation < ActiveRecord::Base
unless coupon_code.nil?
cp = Coupon.find_by_code(coupon_code)
if not cp.nil? and cp.status(user.id) == 'active'
@coupon = cp
total = invoice.invoice_items.map(&:amount).map(&:to_i).reduce(:+)
unless on_site
invoice_items << Stripe::InvoiceItem.create(
@ -389,6 +390,9 @@ class Reservation < ActiveRecord::Base
plan = Plan.find(plan_id)
total += plan.amount
end
if @coupon
total = (total - (total * @coupon.percent_off / 100.0)).to_i
end
wallet_amount = (user.wallet.amount * 100).to_i
wallet_amount >= total ? total : wallet_amount