Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAE-928: Fix discount when the payment plan tab is selected #458

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

asem-compuco
Copy link
Contributor

@asem-compuco asem-compuco commented Mar 14, 2023

Overview

This PR does the following:
Apply the discount when the discount applied on payment plan tab

Before

Rolling + Tax (20%) + Discount (50Percent) = discount not applied
rolling_tax_discount_before

After

Rolling + Tax (20%) + Discount (50Percent) = discount is applied
rolling_tax_discount

Before

Fixed + Tax (20%) + Discount (50Percent) = discount not applied

fixed_tax_discount_before

After

Fixed + Tax (20%) + Discount (50Percent) = discount is applied

fixed_tax_discount_after

Technical Details

  1. The instalments schedule uses PaymentSchedule API to display the instalments, so I modify the api by adding an extra field total_amount, in which when the Membership Type and Payment Plan tab are selected, it will take the value of total_amount input from the Contribution Tab (CiviDiscount when it applies the discount it modifies this value) which later will be used to calculate the discount and display the instalments schedule.
  2. When the form is submitted, I send total_amount to the Contribution and LineItem which they send the values to the PeriodCalculatorType to calculate the discount amount and calculate the new amount and tax.
  3. There is 2 cases in :
  • RollingPeriodTypeCalculator: discount calculated by total_amount (which the total amount after the discount) / (amount + tax) which is the total amount before the discount
  • FixedPeriodTypeCaclulator: the discount can't be computed directly, the total amount sent 3 times (displaying, Contribution, LineItem) given that membership value will be the same in 3 send, but the problem is that total amount altered by proRate Caclulation which also will change the total_amount value which will make a conflict when it sends to Contribution and LineItem, so What I did is to create switch that when it sends for Contribution and LineItem calculates different amount of discount.

@asem-compuco asem-compuco force-pushed the MAE-928-civi-discount branch 4 times, most recently from 3b44811 to 649d0e9 Compare March 17, 2023 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant