feat(promotion code): Promotion code system done
I added the features for users to use promotion code and for promoters to create on their events. May be rewrite to discount code?
This commit is contained in:
@@ -90,10 +90,34 @@ class Order < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
# Calculate total from ticket prices only (platform fee deducted from promoter payout)
|
||||
# Calculate total from ticket prices minus promotion code discounts
|
||||
def calculate_total!
|
||||
ticket_total = tickets.sum(:price_cents)
|
||||
update!(total_amount_cents: ticket_total)
|
||||
discount_total = promotion_codes.sum(:discount_amount_cents)
|
||||
|
||||
# Ensure total doesn't go below zero
|
||||
final_total = [ticket_total - discount_total, 0].max
|
||||
update!(total_amount_cents: final_total)
|
||||
end
|
||||
|
||||
# Subtotal amount before discounts
|
||||
def subtotal_amount_cents
|
||||
tickets.sum(:price_cents)
|
||||
end
|
||||
|
||||
# Subtotal amount in euros
|
||||
def subtotal_amount_euros
|
||||
subtotal_amount_cents / 100.0
|
||||
end
|
||||
|
||||
# Total discount amount from all promotion codes
|
||||
def discount_amount_cents
|
||||
promotion_codes.sum(:discount_amount_cents)
|
||||
end
|
||||
|
||||
# Discount amount in euros
|
||||
def discount_amount_euros
|
||||
discount_amount_cents / 100.0
|
||||
end
|
||||
|
||||
# Platform fee: €0.50 fixed + 1.5% of ticket price, per ticket
|
||||
|
||||
Reference in New Issue
Block a user