-
Notifications
You must be signed in to change notification settings - Fork 41
Adds 'reset status' functionality #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,9 @@ | |
| } | ||
| } | ||
|
|
||
| $allow_trx_reset = CRM_Core_BAO_Setting::getItem('CiviBanking', 'allow_trx_reset'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
| $this->assign('allow_trx_reset', $allow_trx_reset); | ||
|
|
||
| // parse structured data | ||
| $this->assign('btxstatus', $choices[$btx_bao->status_id]); | ||
| $this->assign('payment', $btx_bao); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Check failure on line 32 in api/v3/BankingTransaction.php
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PHP type hints? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am unsure about type hints here. |
||
| $params['trx_id'] = array( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Short array syntax |
||
| '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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
| * @return void | ||
| */ | ||
| function civicrm_api3_banking_transaction_reset($params) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PHP type hints? |
||
| // update the transaction | ||
| if (is_numeric($params['trx_id'])) { | ||
|
Check failure on line 51 in api/v3/BankingTransaction.php
|
||
| // 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'); | ||
|
Check failure on line 53 in api/v3/BankingTransaction.php
|
||
| CRM_Core_DAO::executeQuery("UPDATE `civicrm_bank_tx` SET `status_id` = ({$status_id_new}), suggestions = NULL WHERE `id` = '{$params['trx_id']}'"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The backticks should either be dropped or used consequently, i.e. also for for |
||
| return civicrm_api3_create_success('Status reset complete'); | ||
|
Check failure on line 55 in api/v3/BankingTransaction.php
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Add an BankingTransaction for a contact | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,17 @@ | |
| +--------------------------------------------------------*} | ||
| {* This page is generated by CRM/Banking/Page/Review.php *} | ||
|
|
||
| {assign var="resetLink" value=""} | ||
|
|
||
| {if $btxstatus.label eq 'Ignored'} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
| {if $allow_trx_reset} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it makes sense to combine it with the |
||
| <!-- 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} | ||
|
|
@@ -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 escape='htmlattribute' 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 escape='htmlattribute' 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 escape='htmlattribute' 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> | ||
|
|
@@ -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'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, we should use
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. camelCase for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I am unsure about the proper use of camelCase in CiviCRM. Coming from Drupal I was told "stick to Drupal's style and you're fine". https://docs.civicrm.org/dev/en/latest/standards/#civicrm-vs-drupal says:
I did not found anything CiviCRM specific about naming variables. The linked https://www.drupal.org/docs/develop/standards is labeled "[Obsolete]" and links to https://project.pages.drupalcode.org/coding_standards/ Both of those say:
Since
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of double and single quotes isn't consistent. (Here and in the rest of the code.) |
||
|
|
||
| // disable ALL buttons | ||
| cj(".button").addClass('disabled'); | ||
| cj(".button").attr("onclick",""); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a space after |
||
|
|
||
| // 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 | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of
empty()you could use(bool) ($values['allow_trx_reset'] ?? FALSE).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least for me
is more readable than