1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

add other cart items to the first schedule

This commit is contained in:
Sylvain 2020-11-05 14:55:06 +01:00
parent 2fc9fd4028
commit 7833b0924b
4 changed files with 16 additions and 6 deletions

View File

@ -67,6 +67,10 @@
<div class="text-base">{{ 'app.shared.cart.cost_of_the_subscription' | translate }} <span class="text-blue">{{selectedPlan.amount | currency}}</span></div>
</div>
</div>
<div ng-if="selectedPlan.monthly_payment">
<label for="payment_schedule" translate>{{ 'app.shared.cart.monthly_payment' }}</label>
<switch checked="schedule.requested_schedule" id="'payment_schedule'" on-change="togglePaymentSchedule" class-name="'v-middle'"></switch>
</div>
</div>
</div>

View File

@ -5,17 +5,19 @@ class PaymentScheduleService
##
# Compute a payment schedule for a new subscription to the provided plan
# @param plan {Plan}
# @param total {Number} Total amount of the current shopping cart (which includes this plan)
# @param total {Number} Total amount of the current shopping cart (which includes this plan) - without coupon
# @param coupon {Coupon} apply this coupon, if any
##
def compute(plan, total, coupon = nil)
other_items = total - plan.amount
price = if coupon
cs = CouponService.new
other_items = cs.ventilate(total, other_items, coupon)
cs.ventilate(total, plan.amount, coupon)
else
plan.amount
end
ps = PaymentSchedule.new(scheduled: plan, total: price, coupon: coupon)
ps = PaymentSchedule.new(scheduled: plan, total: price + other_items, coupon: coupon)
deadlines = plan.duration / 1.month
per_month = (price / deadlines).truncate
adjustment = if per_month * deadlines != price
@ -26,12 +28,16 @@ class PaymentScheduleService
items = []
(0..deadlines - 1).each do |i|
date = DateTime.current + i.months
amount = if i.zero?
per_month + adjustment + other_items
else
per_month
end
items.push PaymentScheduleItem.new(
amount: per_month + adjustment,
amount: amount,
due_date: date,
payment_schedule: ps
)
adjustment = 0
end
{ payment_schedule: ps, items: items }
end

View File

@ -396,7 +396,7 @@ en:
cost_of_the_subscription: "Cost of the subscription"
subscription_price: "Subscription price"
you_ve_just_selected_a_subscription_html: "You've just selected a <strong>subscription</strong>:"
monthly_payment: "Pay by monthly schedule"
monthly_payment: "Monthly payment"
your_payment_schedule: "Your payment schedule"
confirm_and_pay: "Confirm and pay"
you_have_settled_the_following_TYPE: "You have settled the following {TYPE, select, Machine{machine slots} Training{training} other{elements}}:"

View File

@ -396,7 +396,7 @@ fr:
cost_of_the_subscription: "Coût de l'abonnement"
subscription_price: "Coût de l'abonnement"
you_ve_just_selected_a_subscription_html: "Vous venez de sélectionner un <strong>abonnement</strong> :"
monthly_payment: "Payer par échéancier mensuel"
monthly_payment: "Paiement mensuel"
your_payment_schedule: "Votre échéancier de paiement"
confirm_and_pay: "Valider et payer"
you_have_settled_the_following_TYPE: "Vous avez réglé {TYPE, select, Machine{les créneaux machines suivants} Training{la formation suivante} other{les éléments suivants}} :"