diff --git a/CRM/Admin/Form/Setting/BankingSettings.php b/CRM/Admin/Form/Setting/BankingSettings.php index 647d73cb..ac51f382 100644 --- a/CRM/Admin/Form/Setting/BankingSettings.php +++ b/CRM/Admin/Form/Setting/BankingSettings.php @@ -117,6 +117,13 @@ public function buildQuickForm() { 'positiveInteger' ); + // 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', @@ -187,6 +194,7 @@ public function setDefaultValues() { $defaults['banking_log_level'] = Civi::settings()->get('banking_log_level'); $defaults['banking_log_file'] = Civi::settings()->get('banking_log_file'); $defaults[CRM_Banking_Config::SETTING_MAX_CONTACTS_ON_LOOKUP] = CRM_Banking_Config::getMaxContactsOnLookup(); + $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'); @@ -222,6 +230,9 @@ public function postProcess(): void { 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', $values['json_editor_mode']); diff --git a/CRM/Banking/Page/Review.php b/CRM/Banking/Page/Review.php index fdb8420a..c3f1e20e 100755 --- a/CRM/Banking/Page/Review.php +++ b/CRM/Banking/Page/Review.php @@ -101,6 +101,9 @@ public 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/api/v3/BankingTransaction.php b/api/v3/BankingTransaction.php index edfbcae3..648c7b94 100755 --- a/api/v3/BankingTransaction.php +++ b/api/v3/BankingTransaction.php @@ -23,6 +23,40 @@ * */ +/** + * 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/Admin/Form/Setting/BankingSettings.tpl b/templates/CRM/Admin/Form/Setting/BankingSettings.tpl index d632b69f..a01d3af8 100644 --- a/templates/CRM/Admin/Form/Setting/BankingSettings.tpl +++ b/templates/CRM/Admin/Form/Setting/BankingSettings.tpl @@ -57,6 +57,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 0bc42fb6..3751a651 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} @@ -51,14 +62,17 @@ {/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}
@@ -188,6 +202,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 */