Skip to content

dev/core#3871 Write-off feature for pledges - #36395

Open
yashodha wants to merge 2 commits into
civicrm:masterfrom
yashodha:dev_3871
Open

dev/core#3871 Write-off feature for pledges#36395
yashodha wants to merge 2 commits into
civicrm:masterfrom
yashodha:dev_3871

Conversation

@yashodha

@yashodha yashodha commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Overview

Write-off feature for pledges

https://lab.civicrm.org/dev/core/-/issues/3871

Functional specifications:

On a pledge, in Edit Scheduled Payment, we can delete a pledge payment. The total pledge amount is reduced by the amount of the scheduled payment and the balance due is recalculated.
But in this scenario, the pledge status is left as is.

We can also cancel a pledge. All scheduled payments are canceled but the pledge status is set to canceled and the pledge balance and the total pledge amount are not recalculated. So I propose a new feature for the write-off.

  • Add the menu option “Write Off” before Cancel.
  • All scheduled payments are canceled like for a pledge cancellation.
  • Pledge status is changed to Completed.
  • Total pledge amount is reduced by the existing pledge balance amount.
  • Pledge balance is set to $0.
  • An activity of type “Pledge write-off” is created and recorded on the contact.
    • Activity Subject=total pledge amount
    • Activity Date and time = date and time of the action
    • Activity Status=Completed
    • Actions available on the activity should be View and File on case only like for the activity type Contribution.
  • The option Write-Off is available only for a pledge that has at least one pledge payment. If no pledge payment has been recorded with a pledge, write-off doesn’t make any sense, so we should have only the options to delete or cancel a pledge.
    • if pledge status =Pending or Overdue > Show only Cancel and Delete
    • if pledge status = In progress > show only Write-Off and Delete
    • if pledge status = Completed or Canceled > show only Delete

@civibot

civibot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
PR commands & links...
  • /rebase <branch-name> will rebase your branch and change the base of the PR.
  • /squash will combine all commits (keeping only the first commit messsage).
  • /port <branch-name> will create a copy of this PR against a different branch.
  • /lintroll will automatically fix linting errors, amending commits as needed.
  • retest this please will rerun the tests and rebuild the demo site.
  • 📖 Review standards
  • 🗒️ Review template (brief or verbose)

➡️ Online demo of this PR 🔗

@civibot civibot Bot added the master label Aug 3, 2026
@civibot

civibot Bot commented Aug 3, 2026

Copy link
Copy Markdown

The issue associated with the Pull Request can be viewed at https://lab.civicrm.org/dev/core/-/issues/3871

@yashodha

yashodha commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@mlutfy @colemanw

I have addressed the comments from the original PR #24777.
The PR provides support for the upgrade as well. Thanks!

Comment thread CRM/Pledge/BAO/Pledge.php Outdated
'status_id' => 'Completed',
]);

$result = civicrm_api3('Activity', 'create', [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api3 is deprecated.

Comment thread CRM/Pledge/BAO/Pledge.php Outdated

//write off the pledge as completed by updating the status
//and the pledge amount
$result = civicrm_api3('Pledge', 'create', [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls use api4

@yashodha

yashodha commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@colemanw done, thanks!

@colemanw

colemanw commented Aug 3, 2026

Copy link
Copy Markdown
Member

/squash
@yashodha this needs regen.

  1. Go to https://github.com/yashodha/civicrm-core/actions/workflows/regen.yml
  2. Click "Run Workflow" on the right
  3. Select "From branch": dev_3871
  4. Autocommit? "y"

@civicrm-builder

Copy link
Copy Markdown

❌ Command Execution Failed

The workflow failed to execute the command. Please check the action run logs for details.

@yashodha

yashodha commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@colemanw I have added the generated data as well. Thanks!

@colemanw

colemanw commented Aug 3, 2026

Copy link
Copy Markdown
Member

/squash

@colemanw colemanw added the merge ready PR will be merged after a few days if there are no objections label Aug 3, 2026
@colemanw

colemanw commented Aug 3, 2026

Copy link
Copy Markdown
Member

I haven't tested this but from a code perspective it seems merge-ready.

@yashodha

yashodha commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@colemanw thanks!

@mlutfy

mlutfy commented Aug 4, 2026

Copy link
Copy Markdown
Member

Not a blocker, to avoid the hassle of another regen, however:

I did a bit of testing on the sandbox and wasn't sure:

  • How to get pledges in a state when I can do a write-off?
  • Recording an overdue pledge says that pledges must be pending or overdue -- most likely unrelated to this PR.
pledges.webm

https://core-36395-7nhxqsa.civi.bid/civicrm/contact/view?reset=1&cid=32

SELECT @max_wt := max(weight) from civicrm_option_value where option_group_id=@option_group_id_activity_type;
SELECT @pledgeCompId := id FROM `civicrm_component` where `name` like 'CiviPledge';

INSERT INTO civicrm_option_value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will insert duplicates if the upgrade step is run twice. You could do something like IF NOT EXISTS (SELECT ...), or can always do it in php.

INSERT INTO civicrm_option_value
(option_group_id, {localize field='label'}label{/localize}, {localize field='description'}description{/localize}, value, name, weight, filter, component_id)
VALUES
(@option_group_id_activity_type, {localize}'{ts escape="sql"}Pledge write-off{/ts}'{/localize},{localize}''{/localize}, (SELECT @max_val := @max_val+1), 'Pledge write-off', (SELECT @max_wt := @max_wt+1), 0, @pledgeCompId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor notes:

  • Do some languages translate '' differently? I'm not sure it's needed to localize that.
  • (SELECT @max_wt := @max_wt+1) isn't necessary, can just do @max_wt+1. If you were inserting a bunch in a row then you might want to increment it this way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do some languages translate '' differently? I'm not sure it's needed to localize that

It would be simpler to not include description in the INSERT.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demeritcowboy demeritcowboy removed the merge ready PR will be merged after a few days if there are no objections label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants