Skip to content

Commit

Permalink
[#382] integration of cut-off setting
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Mar 30, 2023
1 parent a6e8bef commit 48ced16
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
17 changes: 16 additions & 1 deletion extension/CRM/Banking/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ public static function lenientDedupe() {
return TRUE;
}
}
}

/**
* Return a sql INTERVAL expression to cut off the completed transactions horizon
*
* @return string
* SQL interval expression
*/
public static function getStatementCutoff()
{
$config_setting = (int) Civi::settings()->get('recently_completed_cutoff');
if (!empty($config_setting)) {
return "INTERVAL {$config_setting} MONTH";
}
}

}
19 changes: 4 additions & 15 deletions extension/CRM/Banking/Page/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ function run() {
// PAYMENT MODE REQUESTED
$this->build_paymentPage($payment_states);
$list_type = 'list';
CRM_Utils_System::setTitle(E::ts('Bank Transactions'));
} else {
// STATEMENT MODE REQUESTED
$this->build_statementPage($payment_states);
$list_type = 's_list';
CRM_Utils_System::setTitle(E::ts('Bank Statements'));
}

// URLs
Expand All @@ -51,6 +53,7 @@ function run() {

$this->assign('url_show_payments_new', banking_helper_buildURL('civicrm/banking/payments', $this->_pageParameters(array('status_ids'=>$payment_states['new']['id']))));
$this->assign('url_show_payments_analysed', banking_helper_buildURL('civicrm/banking/payments', $this->_pageParameters(array('status_ids'=>$payment_states['suggestions']['id']))));
$this->assign('url_show_payments_recently_completed', banking_helper_buildURL('civicrm/banking/payments', $this->_pageParameters(array('recent' => 1, 'status_ids'=>$payment_states['processed']['id'].",".$payment_states['ignored']['id']))));
$this->assign('url_show_payments_completed', banking_helper_buildURL('civicrm/banking/payments', $this->_pageParameters(array('status_ids'=>$payment_states['processed']['id'].",".$payment_states['ignored']['id']))));

$this->assign('url_review_selected_payments', banking_helper_buildURL('civicrm/banking/review', array($list_type=>"__selected__")));
Expand Down Expand Up @@ -127,7 +130,7 @@ function build_statementPage($payment_states) {
$this->assign('count_completed', $closed_statement_count);

// add restricted completed list (if enabled)
$cutoff_interval = $this->getStatementCutoff();
$cutoff_interval = CRM_Banking_Config::getStatementCutoff();
if (empty($cutoff_interval)) {
$where_clause = " TRUE ";
$this->assign('url_show_payments_recently_completed', false);
Expand Down Expand Up @@ -546,18 +549,4 @@ function _pageParameters($override=array()) {
}
return $params;
}

/**
* Return a sql INTERVAL expression to cut off the completed transactions horizon
*
* @return string
* SQL interval expression
*/
protected function getStatementCutoff()
{
$config_setting = (int) Civi::settings()->get('recently_completed_cutoff');
if (!empty($config_setting)) {
return "INTERVAL {$config_setting} MONTH";
}
}
}
11 changes: 11 additions & 0 deletions extension/CRM/Banking/Page/Statements.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public function run() {
$statementsWhereClauses = array();
$statementsWhereClauses[] = "1";

// if requested, add the restriction to 'recent' statements
$recent = CRM_Utils_Request::retrieve('recent', 'Integer', $null, false, 0);
if ($recent) {
// add restricted completed list (if enabled)
$cutoff_interval = CRM_Banking_Config::getStatementCutoff();
if (!empty($cutoff_interval)) {
$paramCount++;
$statementsWhereClauses[] = " (btxb.starting_date >= DATE(NOW() - {$cutoff_interval})) ";
}
}

$target_ba_id = CRM_Utils_Request::retrieve('target_ba_id', 'Integer', CRM_Core_DAO::$_nullObject, false, -1);
if ($target_ba_id > 0) {
$paramCount++;
Expand Down

0 comments on commit 48ced16

Please sign in to comment.