display batch export date on contribution forms

This commit is contained in:
Jon Goldberg 2019-08-13 14:06:08 -04:00
parent 05997ff2f6
commit 6c65142573
No known key found for this signature in database
GPG Key ID: C2D2247364F9DB13
3 changed files with 50 additions and 12 deletions

View File

@ -1,7 +1,7 @@
<?php
require_once 'batchexportperm.civix.php';
use CRM_Batchexportperm_ExtensionUtil as E;
// use CRM_Batchexportperm_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
@ -240,9 +240,27 @@ function _batchexportperm_civicrm_check_permission($contributionId, $errorType =
* @param int $contributionId
*/
function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) {
$exportDate = _getExportData($contributionId);
if (!$exportDate || CRM_Core_Permission::check('edit exported contributions')) {
return TRUE;
}
return FALSE;
}
/**
* Given a contribution ID, return its batch export date.
*
* @param int $contributionId
* @return string|null This contribution's batch export date if it exists.
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_post
*/
function _getExportData($contributionId) {
// See if the contribution has been exported.
// Man, I wish API4 actually worked.
$query = "SELECT ceft.entity_id "
$query = "SELECT cb.modified_date "
. "FROM civicrm_entity_batch ceb "
. "JOIN civicrm_batch cb on ceb.batch_id = cb.id AND ceb.entity_table = 'civicrm_financial_trxn' "
. "JOIN civicrm_entity_financial_trxn ceft ON ceft.entity_table = 'civicrm_contribution' AND ceb.entity_id = ceft.financial_trxn_id "
@ -250,12 +268,8 @@ function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) {
. "JOIN civicrm_option_group cog ON cov.option_group_id = cog.id AND cog.name = 'batch_status' "
. "WHERE ceft.entity_id = %1";
$params = [1 => [$contributionId, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($query, $params);
if ($dao->N === 0 || CRM_Core_Permission::check('edit exported contributions')) {
return TRUE;
}
return FALSE;
$date = CRM_Core_DAO::singleValueQuery($query, $params);
return CRM_Utils_Date::customFormat($date);
}
/**
@ -278,8 +292,13 @@ function batchexportperm_civicrm_post($op, $objectName, $objectId, &$objectRef)
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm
*/
function batchexportperm_civicrm_buildForm($formName, $form) {
if (in_array($formName, ['CRM_Contribute_Form_ContributionView', 'CRM_Contribute_Form_Contribution']) &&
!empty($form->_id)) {
$temp = $form->_id;
$temp2 = }
if ($formName == 'CRM_Contribute_Form_ContributionView' ||
$formName == 'CRM_Contribute_Form_Contribution' && !empty($form->_id)) {
// ContributionView doesn't pass the ID in the form object? Really?
$contributionId = $form->_id ?? CRM_Utils_Request::retrieve('id', 'Positive');
$exportDate = _getExportData($contributionId);
$form->assign('exportDate', $exportDate);
CRM_Core_Region::instance('page-body')->add(['template' => "CRM/Batchexportperm/Form/BatchDetails.tpl"]);
CRM_Core_Resources::singleton()->addScriptFile('org.agbu.batchexportperm', 'js/exportDate.js');
}
}

3
js/exportDate.js Normal file
View File

@ -0,0 +1,3 @@
CRM.$(function ($) {
$('#export-details-accordion').insertBefore('.crm-submit-buttons:last');
});

View File

@ -0,0 +1,16 @@
<div id="export-details-accordion" class="crm-accordion-wrapper">
<div class="crm-accordion-header">
{ts}Export Details{/ts}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
<table>
<tr class="export-details">
<td class="label">Export Date</td>
<td>{$exportDate}</td>
</tr>
</table>
</div><!-- /.crm-accordion-body -->
</div><!-- /.crm-accordion-wrapper -->