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

PROD-147: Pro-rate creditnote by quantity and allocated amount is also allocated to completed contribution line items #143

Merged
merged 2 commits into from
Feb 21, 2024

Conversation

olayiwola-compucorp
Copy link
Contributor

@olayiwola-compucorp olayiwola-compucorp commented Feb 8, 2024

Overview

In this PR, we:

  • Prorate credit notes created from contributions by quantity instead of by the line-item amount.
  • We ensure allocated amount is also allocated to completed contribution line items (i.e. entity financial trxn is created for completed contribution line items).

Before

The credit note is prorated by line item quantity.
11zzzzzzzz

After

The credit note is prorated by line item amount.
asasasasasa

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:

  1. Line Item 1 has a subtotal of £100.
  2. Line Item 2 also has a subtotal of £100.

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:

  1. Calculation of Proportion:
    The proportion of the paid amount (£100) to the total contribution amount (£200) is computed as:
    $\ \text{Proportion} = \frac{\text{Paid Amount}}{\text{Total Amount}} $

  2. Allocation to Line Items:
    We then use this proportion to determine the amount allocated to each line item:

    • For Line Item 1: $\ \text{LineItem1[amount]} = \text{Proportion} \times \text{LineItem1[Subtotal]} $
    • For Line Item 2: $\ \text{LineItem2[amount]} = \text{Proportion} \times \text{LineItem2[Subtotal]} $

@jamienovick
Copy link
Contributor

@olayiwola-compucorp could we submit this as a pr to core? I think this is actually a core bug so I think we could patch it directly but maybe you / @omarabuhussein / @erawat feel differently?

@olayiwola-compucorp olayiwola-compucorp changed the title PROD-147: Pro-rate creditnote by quantity and update how Payment amount is divided between line items PROD-147: Pro-rate creditnote by quantity and ensure entity financial trxn is created for completed contribution allocation Feb 19, 2024
@olayiwola-compucorp olayiwola-compucorp changed the title PROD-147: Pro-rate creditnote by quantity and ensure entity financial trxn is created for completed contribution allocation PROD-147: Pro-rate creditnote by quantity and allocated amount is also allocated to completed contribution line items Feb 19, 2024
@olayiwola-compucorp
Copy link
Contributor Author

olayiwola-compucorp commented Feb 19, 2024

PR to correct line item payment calculation submitted to core civicrm/civicrm-core#29350

This PR now contains credit note specific changes @erawat

@olayiwola-compucorp olayiwola-compucorp changed the base branch from master to PROD-147-workstream February 21, 2024 11:40
@olayiwola-compucorp olayiwola-compucorp merged commit 97590fe into PROD-147-workstream Feb 21, 2024
2 checks passed
@olayiwola-compucorp olayiwola-compucorp deleted the PROD-147-prorata-quantity branch February 21, 2024 11:40
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.

3 participants