generated from compucorp/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
FOSFASPRT-78: Add native overpayment support #260
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f5699b
FOSFASPRT-78: Add native overpayment support
erawat 071563a
FOSFASPRT-78: Calculate tax based on overpayment financial type
erawat 0a83586
FOSFASPRT-78: Use Accounts Receivable for overpayment allocation
erawat 7bbc5a3
FOSFASPRT-78: Add summary line to overpayment financial type help text
erawat 6cba5b3
FOSFASPRT-78: Get AR account from company for multi-company support
erawat 9b0db0c
FOSFASPRT-78: Change credit note reference to just show contribution ID
erawat d472b55
FOSFASPRT-78: Remove tax calculation from overpayment credit note
erawat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
CRM/Financeextras/Form/Contribute/OverpaymentAllocate.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| <?php | ||
|
|
||
| use Civi\Api4\CreditNote; | ||
| use Civi\Api4\Contribution; | ||
| use Civi\Financeextras\Utils\OverpaymentUtils; | ||
| use CRM_Financeextras_ExtensionUtil as E; | ||
|
|
||
| /** | ||
| * Form to allocate overpayment to a new credit note. | ||
| */ | ||
| class CRM_Financeextras_Form_Contribute_OverpaymentAllocate extends CRM_Core_Form { | ||
|
|
||
| /** | ||
| * Contribution ID. | ||
| * | ||
| * @var int | ||
| */ | ||
| protected $contributionId; | ||
| /** | ||
| * Contribution data. | ||
| * | ||
| * @var array | ||
| */ | ||
| protected $contribution; | ||
| /** | ||
| * Overpayment amount. | ||
| * | ||
| * @var float | ||
| */ | ||
| protected $overpaymentAmount; | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function preProcess() { | ||
| $this->contributionId = CRM_Utils_Request::retrieve('contribution_id', 'Positive', $this, TRUE); | ||
|
|
||
| // Validate eligibility. | ||
| if (!OverpaymentUtils::isEligibleForOverpaymentAllocation($this->contributionId)) { | ||
| throw new CRM_Core_Exception(E::ts('This contribution is not eligible for overpayment allocation.')); | ||
| } | ||
|
|
||
| $this->contribution = Contribution::get(FALSE) | ||
| ->addWhere('id', '=', $this->contributionId) | ||
| ->addSelect('*', 'contact_id.display_name') | ||
| ->execute() | ||
| ->first(); | ||
|
|
||
| $this->overpaymentAmount = OverpaymentUtils::getOverpaymentAmount($this->contributionId); | ||
|
|
||
| CRM_Utils_System::setTitle(E::ts('Allocate overpayment to credit note')); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function buildQuickForm() { | ||
| $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $this->contribution['currency'], 'symbol', 'name'); | ||
| $formattedAmount = CRM_Utils_Money::format($this->overpaymentAmount, $this->contribution['currency']); | ||
|
|
||
| $this->assign('message', E::ts('Allocate an overpaid amount to a new credit note. The credit can then be applied to future invoices. This cannot be undone.')); | ||
| $this->assign('overpaymentAmount', $formattedAmount); | ||
| $this->assign('contactName', $this->contribution['contact_id.display_name']); | ||
|
|
||
| $this->addButtons([ | ||
| [ | ||
| 'type' => 'submit', | ||
| 'name' => E::ts('Save'), | ||
| 'isDefault' => TRUE, | ||
| ], | ||
| [ | ||
| 'type' => 'cancel', | ||
| 'name' => E::ts('Cancel'), | ||
| ], | ||
| ]); | ||
|
|
||
| parent::buildQuickForm(); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function postProcess() { | ||
| try { | ||
| $result = CreditNote::allocateOverpayment(FALSE) | ||
| ->setContributionId($this->contributionId) | ||
| ->execute() | ||
| ->first(); | ||
|
|
||
| CRM_Core_Session::setStatus( | ||
| E::ts('Overpayment allocated to credit note "%1" successfully.', [1 => $result['cn_number']]), | ||
| E::ts('Success'), | ||
| 'success' | ||
| ); | ||
| } | ||
| catch (\Throwable $th) { | ||
| CRM_Core_Session::setStatus( | ||
| E::ts('Error allocating overpayment: %1', [1 => $th->getMessage()]), | ||
| E::ts('Error'), | ||
| 'error' | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] SQL query is difficult to read and maintain as a single concatenated string. Consider using a multi-line heredoc or nowdoc syntax for better readability and maintainability.