Skip to content

Commit

Permalink
Merge pull request #392 from VangelisP/dev-383
Browse files Browse the repository at this point in the history
Adds 'reset status' functionality. Implements #383
  • Loading branch information
bjendres authored Jul 21, 2023
2 parents 549a8a6 + 3750882 commit 3a67fb2
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CRM/Admin/Form/Setting/BankingSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions CRM/Banking/Page/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 33 additions & 0 deletions api/v3/BankingTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions templates/CRM/Admin/Form/Setting/BankingSettings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
<div class="clear"></div>
</div>

<div class="crm-section">
<div class="label">{$form.allow_trx_reset.label}</div>
<div class="content">{$form.allow_trx_reset.html}</div>
<div class="clear"></div>
</div>

<br/>
<h3>{ts domain='org.project60.banking'}Bank Account Settings{/ts}</h3>

Expand Down
65 changes: 65 additions & 0 deletions templates/CRM/Banking/Page/Review.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
<!-- Check the form configuration button -->
{capture name="resetLink" assign="resetLink"}
<a href="#" class="button" onclick="resetPayment()"><span title="{ts domain='org.project60.banking'}Reset status{/ts}"><div class="icon next-icon ui-icon-cancel"></div>{ts domain='org.project60.banking'}Reset status{/ts}</span></a>
{/capture}
{/if}
{/if}

<div id="btx">
{foreach from=$summary_blocks item=block}
{$block}
Expand Down Expand Up @@ -51,14 +62,17 @@
{/if}
{/if}
{if $new_ui_enabled && $back_to_statement_lines}
{$resetLink}
<a href="{$url_back}" class="button" style="float:right;">
<span title="{ts domain='org.project60.banking'}Back{/ts}"><div class="icon back-icon ui-icon-arrowreturnthick-1-w"></div>{ts domain='org.project60.banking'}Back to statement lines{/ts}</span>
</a>
{elseif $new_ui_enabled && !$back_to_statement_lines}
{$resetLink}
<a href="{$url_back}" class="button" style="float:right;">
<span title="{ts domain='org.project60.banking'}Back{/ts}"><div class="icon back-icon ui-icon-arrowreturnthick-1-w"></div>{ts domain='org.project60.banking'}Back to statements{/ts}</span>
</a>
{else}
{$resetLink}
<a href="{$url_back}" class="button" style="float:right;">
<span title="{ts domain='org.project60.banking'}Back{/ts}"><div class="icon back-icon ui-icon-arrowreturnthick-1-w"></div>{ts domain='org.project60.banking'}Back to transaction list{/ts}</span>
</a>
Expand Down Expand Up @@ -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('<div title="{/literal}{ts domain='org.project60.banking'}Error{/ts}{literal}"><span class="ui-icon ui-icon-alert" style="float:left;"></span>' + data['error_message'] + '</div>').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
*/
Expand Down

0 comments on commit 3a67fb2

Please sign in to comment.