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

fix #409: add option to preserve original receive_date #413

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CRM/Banking/PluginImpl/Matcher/DefaultOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function __construct($config_name) {
if (!isset($config->default_financial_type_id)) $config->default_financial_type_id = 1;
if (!isset($config->createnew_value_propagation)) $config->createnew_value_propagation = array();
if (!isset($config->manual_default_financial_type_id)) $config->manual_default_financial_type_id = NULL;
if (!isset($config->preserve_receive_date)) $config->preserve_receive_date = 0; // Set to 1 to preserve the receive_date (instead of overwriting it with the booking_date). See issue #409.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see this follows existing formatting, but conditions (if) without brackets ({…}) should really be avoided. Also, the comment should be put above the condition.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (!isset($config->preserve_receive_date)) $config->preserve_receive_date = 0; // Set to 1 to preserve the receive_date (instead of overwriting it with the booking_date). See issue #409.
// Set to 1/TRUE to preserve the receive_date (instead of overwriting it with the booking_date). See issue #409.
$config->preserve_receive_date = (bool) ($config->preserve_receive_date ?? FALSE);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I agree with the changes, even though I think it doesn't necessarily contribute to the readability of the code to suddenly deviate from the scheme in the nth repeated line.


if (!isset($config->ignore_enabled)) $config->ignore_enabled = true;
if (!isset($config->ignore_probability)) $config->ignore_probability = 0.1;
Expand Down Expand Up @@ -123,6 +124,8 @@ public function match(CRM_Banking_BAO_BankTransaction $btx, CRM_Banking_Matcher_
* the bank transaction this is related to
*/
public function execute($suggestion, $btx) {
$config = $this->_plugin_config;

if ($suggestion->getId()==="manual") {
$cids = $suggestion->getParameter('contribution_ids');
$contribution_count = 0;
Expand Down Expand Up @@ -155,7 +158,9 @@ public function execute($suggestion, $btx) {
} else {
// ...otherwise, we close it
$query['contribution_status_id'] = $completed_status;
$query['receive_date'] = date('YmdHis', strtotime($btx->booking_date));
if (!$config->preserve_receive_date) {
$query['receive_date'] = date('YmdHis', strtotime($btx->booking_date));
}
}

CRM_Banking_Helpers_IssueMitigation::mitigate358($query);
Expand Down
5 changes: 4 additions & 1 deletion CRM/Banking/PluginImpl/Matcher/ExistingContribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function __construct($config_name) {
if (!isset($config->date_penalty)) $config->date_penalty = 1.0;
if (!isset($config->payment_instrument_penalty)) $config->payment_instrument_penalty = 0.0;
if (!isset($config->financial_type_penalty)) $config->financial_type_penalty = 0.0;
if (!isset($config->preserve_receive_date)) $config->preserve_receive_date = 0; // Set to 1 to preserve the receive_date (instead of overwriting it with the booking_date). See issue #409.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here as above.


// amount check / amount penalty
if (!isset($config->amount_check)) $config->amount_check = "1";
Expand Down Expand Up @@ -415,7 +416,9 @@ public function execute($suggestion, $btx) {
// depending on mode...
if ($this->_plugin_config->mode != "cancellation") {
$query['contribution_status_id'] = banking_helper_optionvalue_by_groupname_and_name('contribution_status', 'Completed');
$query['receive_date'] = date('YmdHis', strtotime($btx->booking_date));
if (!$config->preserve_receive_date) {
$query['receive_date'] = date('YmdHis', strtotime($btx->booking_date));
}
} else {
$query['contribution_status_id'] = banking_helper_optionvalue_by_groupname_and_name('contribution_status', 'Cancelled');
$query['cancel_date'] = date('YmdHis', strtotime($btx->booking_date));
Expand Down