Skip to content

Commit

Permalink
[#382] merged 'recently closed' tab into 0.8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Apr 26, 2023
2 parents 6034824 + 0b39051 commit 1120b97
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 102 deletions.
86 changes: 52 additions & 34 deletions extension/CRM/Admin/Form/Setting/BankingSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function buildQuickForm() {
'1' => E::ts("Simplified user interface"),
'0' => E::ts("Traditional user interface")
);
$new_ui = $this->add(
$this->add(
'select',
'new_ui',
E::ts('Statement User interface'),
Expand All @@ -45,7 +45,7 @@ function buildQuickForm() {
1 => E::ts("In Contribution Menu"),
2 => E::ts("No Menu"));

$menu_position = $this->add(
$this->add(
'select',
'menu_position',
E::ts('CiviBanking Menu Position'),
Expand All @@ -62,7 +62,7 @@ function buildQuickForm() {
'form' => E::ts("Form Editor"),
);

$json_editor_mode = $this->add(
$this->add(
'select',
'json_editor_mode',
E::ts('Configuration Editor Default Mode'),
Expand All @@ -71,50 +71,66 @@ function buildQuickForm() {
);

// logging
$log_level = $this->add(
$this->add(
'select',
'banking_log_level',
E::ts('Log Level'),
CRM_Banking_Helpers_Logger::getLoglevels()
);

$log_file = $this->add(
$this->add(
'select',
'recently_completed_cutoff',
E::ts("Show Completed Statements (Recent)"),
[
0 => E::ts('disabled'),
1 => E::ts('last month'),
3 => E::ts('last quarter'),
6 => E::ts('last %1 months', [1 => "6"]),
12 => E::ts('last %1 months', [1 => "12"]),
24 => E::ts('last %1 years', [1 => "2"]),
60 => E::ts('last %1 years', [1 => "5"]),
],
TRUE
);

$this->add(
'text',
'banking_log_file',
E::ts('Log File'),
['class' => 'huge']
);

// store bank accounts
$this->addElement(
$this->add(
'checkbox',
'reference_store_disabled',
E::ts("Don't store bank accounts automatically"),
'');

// normalise bank account references?
$this->addElement(
$this->add(
'checkbox',
'reference_normalisation',
E::ts('Normalise bank account references'),
'');

// validate bank account references?
$this->addElement(
$this->add(
'checkbox',
'reference_validation',
E::ts('Validate bank account references'),
'');
// validate bank account references?
$this->addElement(
$this->add(
'text',
'reference_matching_probability',
E::ts('Probability of contact matching based on bank account'),
'');
$this->addRule('reference_matching_probability', E::ts('Not a valid number. A valid number is 1.0 or 0.9'), 'numeric');

// validate bank account references?
$this->addElement(
$this->add(
'checkbox',
'lenient_dedupe',
E::ts('Lenient bank account dedupe'),
Expand Down Expand Up @@ -149,23 +165,24 @@ function buildQuickForm() {
* @return array
*/
function setDefaultValues() {
$defaults = array();

$defaults['new_ui'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'new_ui');
$defaults['menu_position'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'menu_position');
$defaults['json_editor_mode'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'json_editor_mode');
$defaults['banking_log_level'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'banking_log_level');
$defaults['banking_log_file'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'banking_log_file');
$defaults['reference_store_disabled'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'reference_store_disabled');
$defaults['reference_normalisation'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'reference_normalisation');
$defaults['reference_matching_probability'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'reference_matching_probability');
$defaults = [];
$defaults['new_ui'] = Civi::settings()->get('new_ui');
$defaults['menu_position'] = Civi::settings()->get('menu_position');
$defaults['json_editor_mode'] = Civi::settings()->get('json_editor_mode');
$defaults['banking_log_level'] = Civi::settings()->get('banking_log_level');
$defaults['banking_log_file'] = Civi::settings()->get('banking_log_file');
$defaults['reference_store_disabled'] = Civi::settings()->get('reference_store_disabled');
$defaults['reference_normalisation'] = Civi::settings()->get('reference_normalisation');
$defaults['recently_completed_cutoff'] = Civi::settings()->get('recently_completed_cutoff');
$defaults['reference_matching_probability'] = Civi::settings()->get('reference_matching_probability');
$defaults['reference_validation'] = Civi::settings()->get('reference_validation');
$defaults['lenient_dedupe'] = Civi::settings()->get('lenient_dedupe');
$defaults[CRM_Banking_Config::SETTING_TRANSACTION_LIST_CUTOFF]
= Civi::settings()->get(CRM_Banking_Config::SETTING_TRANSACTION_LIST_CUTOFF);

if ($defaults['reference_matching_probability'] === null) {
$defaults['reference_matching_probability'] = '1.0';
}
$defaults['reference_validation'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'reference_validation');
$defaults['lenient_dedupe'] = CRM_Core_BAO_Setting::getItem('CiviBanking', 'lenient_dedupe');
$defaults[CRM_Banking_Config::SETTING_TRANSACTION_LIST_CUTOFF]
= CRM_Banking_Config::transactionViewCutOff();

return $defaults;
}
Expand All @@ -185,24 +202,25 @@ function postProcess() {
$new_ui_style = (int) $values['new_ui'];

if ($old_menu_position != $new_menu_position || $old_ui_style != $new_ui_style) {
CRM_Core_BAO_Setting::setItem($new_ui_style, 'CiviBanking', 'new_ui');
CRM_Core_BAO_Setting::setItem($new_menu_position, 'CiviBanking', 'menu_position');
Civi::settings()->set('new_ui', $new_ui_style);
Civi::settings()->set('menu_position', $new_menu_position);
CRM_Core_BAO_Navigation::resetNavigation();
}

// process menu entry
CRM_Core_BAO_Setting::setItem($values['json_editor_mode'], 'CiviBanking', 'json_editor_mode');
Civi::settings()->set('json_editor_mode', $new_menu_position);

// log levels
CRM_Core_BAO_Setting::setItem($values['banking_log_level'], 'CiviBanking', 'banking_log_level');
CRM_Core_BAO_Setting::setItem($values['banking_log_file'], 'CiviBanking', 'banking_log_file');
Civi::settings()->set('banking_log_level', $values['banking_log_level']);
Civi::settings()->set('banking_log_file', $values['banking_log_file']);

// process reference normalisation / validation
CRM_Core_BAO_Setting::setItem(!empty($values['reference_store_disabled']),'CiviBanking', 'reference_store_disabled');
CRM_Core_BAO_Setting::setItem(!empty($values['reference_normalisation']), 'CiviBanking', 'reference_normalisation');
CRM_Core_BAO_Setting::setItem($values['reference_matching_probability'], 'CiviBanking', 'reference_matching_probability');
CRM_Core_BAO_Setting::setItem(!empty($values['reference_validation']), 'CiviBanking', 'reference_validation');
CRM_Core_BAO_Setting::setItem(!empty($values['lenient_dedupe']), 'CiviBanking', 'lenient_dedupe');
Civi::settings()->set('reference_store_disabled', !empty($values['reference_store_disabled']));
Civi::settings()->set('reference_normalisation', !empty($values['reference_normalisation']));
Civi::settings()->set('reference_validation', !empty($values['reference_validation']));
Civi::settings()->set('lenient_dedupe', !empty($values['lenient_dedupe']));
Civi::settings()->set('reference_matching_probability', $values['reference_matching_probability']);
Civi::settings()->set('recently_completed_cutoff', $values['recently_completed_cutoff']);

// display settings
Civi::settings()->set(CRM_Banking_Config::SETTING_TRANSACTION_LIST_CUTOFF,
Expand Down
18 changes: 17 additions & 1 deletion extension/CRM/Banking/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,20 @@ public static function transactionViewCutOff() {
}
return $cutoff;
}
}

/**
* Return a sql INTERVAL expression to cut off the completed transactions horizon
*
* @return string
* SQL interval expression
*/
public static function getRecentlyCompletedStatementCutoff() : string
{
$config_setting = (int) Civi::settings()->get('recently_completed_cutoff');
if (!empty($config_setting)) {
return "INTERVAL {$config_setting} MONTH";
} else {
return '';
}
}
}
2 changes: 1 addition & 1 deletion extension/CRM/Banking/Helpers/URLBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function banking_helper_buildURL($base, $set_params, $keep_params=array(), $dele
if ($keep_param_source==NULL) $keep_param_source = $_REQUEST;

$params = array();
// take over selected parameters from sourc
// take over selected parameters from source
foreach ($keep_params as $key) {
if (isset($keep_param_source[$key])) {
$params[$key] = $keep_param_source[$key];
Expand Down
14 changes: 8 additions & 6 deletions extension/CRM/Banking/Page/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function run() {
if ($plugin->id == $plugin_id) {
$this->assign('plugin_list', array($plugin));
break;
}
}
}

// RUN the importer
Expand Down Expand Up @@ -70,7 +70,7 @@ function run() {
} else {
CRM_Core_Session::setStatus(E::ts('Importer needs a file to proceed.'), E::ts('No input file'), 'alert');
}

// TODO: RUN the processor
if (isset($_REQUEST['process']) && $_REQUEST['process']=="on") {
CRM_Core_Session::setStatus(E::ts('Automated running not yet implemented'), E::ts('Not implemented'), 'alert');
Expand Down Expand Up @@ -98,11 +98,11 @@ function run() {
foreach ($plugin_list as $plugin) {
$class = $plugin->getClass();
if ($class::does_import_files()) {
$has_file_source[$plugin->id] = 'true';
$has_file_source[$plugin->id] = 'true';
} else {
$has_file_source[$plugin->id] = 'false';
$has_file_source[$plugin->id] = 'false';
}

}
$this->assign('has_file_source', $has_file_source);
}
Expand All @@ -112,7 +112,9 @@ function run() {
if ($new_ui_enabled) {
$this->assign('url_payments', CRM_Utils_System::url('civicrm/banking/statements'));
} else {
$this->assign('url_payments', CRM_Utils_System::url('civicrm/banking/payments', 'show=statements'));
$this->assign('url_payments', CRM_Utils_System::url(
'civicrm/banking/payments',
'show=statements&recent=' . empty($_REQUEST['recent']) ? 0 : 1));
}
$this->assign('url_action', CRM_Utils_System::url('civicrm/banking/import'));

Expand Down
Loading

0 comments on commit 1120b97

Please sign in to comment.