PROD-147: Pro-rate creditnote by quantity and allocated amount is also allocated to completed contribution line items #143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
In this PR, we:
Before
The credit note is prorated by line item quantity.

After
The credit note is prorated by line item amount.

Technical Details
For the second change, where we ensure entity financial trxn is created for completed contribution line items allocation:
See here for how CiviCRM by default doesn't create entity allocate payment to completed contribution line items
However, in this PR, using the approach below, we now allocate payment to completed contribution line items
Let's consider a scenario where the contribution total amount is £200 and there are two line items:
Suppose the user pays £200 towards the contribution and then attempts to allocate £100 to the same completed contribution. We aim to distribute this amount proportionally among the line items.
To achieve this, we utilize the following mathematical approach:
Calculation of Proportion:
$\ \text{Proportion} = \frac{\text{Paid Amount}}{\text{Total Amount}} $
The proportion of the paid amount (£100) to the total contribution amount (£200) is computed as:
Allocation to Line Items:
We then use this proportion to determine the amount allocated to each line item: