From 873123c7a6fbd7abd4c9913502b1ec06d17f91ef Mon Sep 17 00:00:00 2001 From: Vangelis Pantazis Date: Fri, 7 Jul 2023 13:53:12 +0300 Subject: [PATCH 1/2] Adds 'reset status' functionality. Implements #383 --- api/v3/BankingTransaction.php | 33 +++++++++++++++++ templates/CRM/Banking/Page/Review.tpl | 52 +++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/api/v3/BankingTransaction.php b/api/v3/BankingTransaction.php index 2572c8b2..59c123b9 100755 --- a/api/v3/BankingTransaction.php +++ b/api/v3/BankingTransaction.php @@ -22,6 +22,39 @@ */ require_once 'CRM/Banking/Helpers/OptionValue.php'; +/** + * Adjust Metadata for Reset action + * + * The metadata is used for setting defaults, documentation & validation + * @param array $params array or parameters determined by getfields + */ +function _civicrm_api3_banking_transaction_reset_spec(&$params) { + $params['trx_id'] = array( + 'title' => 'Transaction ID', + 'description' => 'The transaction ID to perform the status reset', + 'required' => TRUE, + 'type' => CRM_Utils_Type::T_INT, + ); +} + +/** + * civicrm_api3_banking_transaction_reset + * Resets a transaction's status into the status NEW + * Will also remove any suggestions stored into this transaction + * + * @param mixed $params + * @return void + */ +function civicrm_api3_banking_transaction_reset($params) { + // update the transaction + if (is_numeric($params['trx_id'])) { + // Get the status ID for new (not-analysed transaction) + $status_id_new = (int) banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'new'); + CRM_Core_DAO::executeQuery("UPDATE `civicrm_bank_tx` SET `status_id` = ({$status_id_new}), suggestions = NULL WHERE `id` = '{$params['trx_id']}'"); + return civicrm_api3_create_success('Status reset complete'); + } + +} /** * Add an BankingTransaction for a contact diff --git a/templates/CRM/Banking/Page/Review.tpl b/templates/CRM/Banking/Page/Review.tpl index 3c9a177a..0f789004 100755 --- a/templates/CRM/Banking/Page/Review.tpl +++ b/templates/CRM/Banking/Page/Review.tpl @@ -48,6 +48,7 @@ {else}
{ts domain='org.project60.banking'}Confirm and Exit{/ts}
{ts domain='org.project60.banking'}Skip and Exit{/ts}
+
{ts domain='org.project60.banking'}Reset status{/ts}
{/if} {/if} {if $new_ui_enabled && $back_to_statement_lines} @@ -188,6 +189,57 @@ function analysePayment() { ); } +/** + * Resets a transaction into the status "New" + */ +function resetPayment() { + const response = confirm('{/literal}{ts domain='org.project60.banking'}The analysis of this transaction will be reset into its initial state and all saved suggestions will be reset. Are you sure you want to do that?{/ts}{literal}'); + if (!response) { + return; + } + + var reload_regex = new RegExp("(execute=)[0-9]+", 'ig'); + + // disable ALL buttons + cj(".button").addClass('disabled'); + cj(".button").attr("onclick",""); + + // remove old suggestions + cj(".suggestions").remove(); + cj("#generating_suggestions").show(); + + // show busy indicator + + // AJAX call the analyser + var query = {'q': 'civicrm/ajax/rest', 'sequential': 1}; + // set the list or s_list parameter depending on the page mode + query['trx_id'] = "{/literal}{$payment->id}{literal}"; + console.log(query); + CRM.api('BankingTransaction', 'reset', query, + {success: function(data) { + if (!data['is_error']) { + // remove 'execute' bit from URL before reload + var newURL = window.location.href.replace(reload_regex, ''); + if (window.location.href == newURL) { + window.location.reload(false); + } else { + window.location = newURL; + } + } else { + cj('
' + data['error_message'] + '
').dialog({ + modal: true, + buttons: { + Ok: function() { + window.location = window.location.href.replace(reload_regex, ''); + } + } + }); + } + } + } + ); +} + /** * common function to bring CiviCRM 4.5+ popups into the game */ From 3750882af47bc45834143663469a0891de3823bb Mon Sep 17 00:00:00 2001 From: Vangelis Pantazis Date: Fri, 7 Jul 2023 16:11:12 +0300 Subject: [PATCH 2/2] Adds configuration form for the reset button. Rework on the display --- CRM/Admin/Form/Setting/BankingSettings.php | 11 +++++++++++ CRM/Banking/Page/Review.php | 3 +++ .../CRM/Admin/Form/Setting/BankingSettings.tpl | 6 ++++++ templates/CRM/Banking/Page/Review.tpl | 15 ++++++++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CRM/Admin/Form/Setting/BankingSettings.php b/CRM/Admin/Form/Setting/BankingSettings.php index 846cc448..23ffd33e 100644 --- a/CRM/Admin/Form/Setting/BankingSettings.php +++ b/CRM/Admin/Form/Setting/BankingSettings.php @@ -101,6 +101,13 @@ function buildQuickForm() { ['class' => 'huge'] ); + // allow status reset on transactions + $this->add( + 'checkbox', + 'allow_trx_reset', + E::ts("Allow status reset on ignored transactions"), + ''); + // store bank accounts $this->add( 'checkbox', @@ -171,6 +178,7 @@ function setDefaultValues() { $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['allow_trx_reset'] = Civi::settings()->get('allow_trx_reset'); $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'); @@ -207,6 +215,9 @@ function postProcess() { CRM_Core_BAO_Navigation::resetNavigation(); } + // allow trx status reset + Civi::settings()->set('allow_trx_reset', !empty($values['allow_trx_reset'])); + // process menu entry Civi::settings()->set('json_editor_mode', $new_menu_position); diff --git a/CRM/Banking/Page/Review.php b/CRM/Banking/Page/Review.php index fa121841..f1c84d8c 100755 --- a/CRM/Banking/Page/Review.php +++ b/CRM/Banking/Page/Review.php @@ -95,6 +95,9 @@ function run() { } } + $allow_trx_reset = CRM_Core_BAO_Setting::getItem('CiviBanking', 'allow_trx_reset'); + $this->assign('allow_trx_reset', $allow_trx_reset); + // parse structured data $this->assign('btxstatus', $choices[$btx_bao->status_id]); $this->assign('payment', $btx_bao); diff --git a/templates/CRM/Admin/Form/Setting/BankingSettings.tpl b/templates/CRM/Admin/Form/Setting/BankingSettings.tpl index 03e27379..23efa873 100644 --- a/templates/CRM/Admin/Form/Setting/BankingSettings.tpl +++ b/templates/CRM/Admin/Form/Setting/BankingSettings.tpl @@ -51,6 +51,12 @@
+
+
{$form.allow_trx_reset.label}
+
{$form.allow_trx_reset.html}
+
+
+

{ts domain='org.project60.banking'}Bank Account Settings{/ts}

diff --git a/templates/CRM/Banking/Page/Review.tpl b/templates/CRM/Banking/Page/Review.tpl index 0f789004..5dc9ab12 100755 --- a/templates/CRM/Banking/Page/Review.tpl +++ b/templates/CRM/Banking/Page/Review.tpl @@ -14,6 +14,17 @@ +--------------------------------------------------------*} {* This page is generated by CRM/Banking/Page/Review.php *} + {assign var="resetLink" value=""} + + {if $btxstatus.label eq 'Ignored'} + {if $allow_trx_reset} + + {capture name="resetLink" assign="resetLink"} +
{ts domain='org.project60.banking'}Reset status{/ts}
+ {/capture} + {/if} + {/if} +
{foreach from=$summary_blocks item=block} {$block} @@ -48,18 +59,20 @@ {else}
{ts domain='org.project60.banking'}Confirm and Exit{/ts}
{ts domain='org.project60.banking'}Skip and Exit{/ts}
-
{ts domain='org.project60.banking'}Reset status{/ts}
{/if} {/if} {if $new_ui_enabled && $back_to_statement_lines} + {$resetLink}
{ts domain='org.project60.banking'}Back to statement lines{/ts}
{elseif $new_ui_enabled && !$back_to_statement_lines} + {$resetLink}
{ts domain='org.project60.banking'}Back to statements{/ts}
{else} + {$resetLink}
{ts domain='org.project60.banking'}Back to transaction list{/ts}