Compare commits

...

7 Commits

4 changed files with 56 additions and 93 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
require_once 'batchexportperm.civix.php'; require_once 'batchexportperm.civix.php';
use CRM_Batchexportperm_ExtensionUtil as E; // use CRM_Batchexportperm_ExtensionUtil as E;
/** /**
* Implements hook_civicrm_config(). * Implements hook_civicrm_config().
@ -85,47 +85,6 @@ function batchexportperm_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
*/ */
function batchexportperm_civicrm_managed(&$entities) { function batchexportperm_civicrm_managed(&$entities) {
_batchexportperm_civix_civicrm_managed($entities); _batchexportperm_civix_civicrm_managed($entities);
$entities[] = [
'module' => 'org.agbu.batchexportperm',
'name' => 'batchexportperm_batch_details',
'entity' => 'CustomGroup',
'params' => [
'version' => 3,
'name' => 'batchexportperm_batch_details',
'title' => 'Batch Details',
'extends' => 'Contribution',
'style' => 'Inline',
'collapse_display' => TRUE,
'is_active' => TRUE,
'is_multiple' => FALSE,
'collapse_adv_display' => FALSE,
'is_reserved' => TRUE,
],
];
$entities[] = [
'module' => 'org.agbu.batchexportperm',
'name' => 'export_date',
'entity' => 'CustomField',
'params' => [
'version' => 3,
'name' => 'export_date',
'label' => 'Export Date',
'data_type' => 'Date',
'html_type' => 'Select Date',
'is_required' => FALSE,
'is_searchable' => FALSE,
'is_search_range' => FALSE,
'is_active' => TRUE,
'is_view' => TRUE,
'date_format' => 'mm/dd/yy',
'time_format' => 1,
'text_length' => 255,
'column_name' => 'export_date',
'note_columns' => 150,
'note_rows' => 4,
'custom_group_id' => 'batchexportperm_batch_details',
],
];
} }
/** /**
@ -281,59 +240,51 @@ function _batchexportperm_civicrm_check_permission($contributionId, $errorType =
* @param int $contributionId * @param int $contributionId
*/ */
function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) { function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) {
$customFieldId = civicrm_api3('CustomField', 'getvalue', [
'return' => "id", $exportDate = _getExportData($contributionId);
'custom_group_id' => "batchexportperm_batch_details",
'name' => "export_date", if (!$exportDate || CRM_Core_Permission::check('edit exported contributions')) {
]);
$exportDate = civicrm_api3('Contribution', 'getvalue', [
'return' => "custom_{$customFieldId}",
'id' => $contributionId,
]);
if (empty($exportDate) || CRM_Core_Permission::check('edit exported contributions')) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
/** /**
* Implements hook_civicrm_post(). * 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 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_post
*/ */
function batchexportperm_civicrm_post($op, $objectName, $objectId, &$objectRef) { function _getExportData($contributionId) {
if ($objectName == 'Batch' && $op == 'edit') { // See if the contribution has been exported.
if (CRM_Core_Smarty::singleton()->get_template_vars("batch_status_change_{$objectId}")) { // Man, I wish API4 actually worked.
_batchexportperm_civicrm_update_contribution_exporteddate($objectId); $query = "SELECT cb.modified_date "
CRM_Core_Smarty::singleton()->assign("batch_status_change_{$objectId}", FALSE); . "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 "
. "JOIN civicrm_option_value cov on cov.value = cb.status_id AND cov.label = 'Exported' "
. "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']];
$date = CRM_Core_DAO::singleValueQuery($query, $params);
return CRM_Utils_Date::customFormat($date);
} }
/** /**
* Set export date custom field for contribution when batch is exported. * Display batch eport info on the contribution.
* *
* @param int $batchId * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm
*/ */
function _batchexportperm_civicrm_update_contribution_exporteddate($batchId) { function batchexportperm_civicrm_buildForm($formName, $form) {
$customFieldId = civicrm_api3('CustomField', 'getvalue', [ if ($formName == 'CRM_Contribute_Form_ContributionView' ||
'return' => "id", $formName == 'CRM_Contribute_Form_Contribution' && !empty($form->_id)) {
'custom_group_id' => "batchexportperm_batch_details", // ContributionView doesn't pass the ID in the form object? Really?
'name' => "export_date", $contributionId = $form->_id ?? CRM_Utils_Request::retrieve('id', 'Positive');
]); $exportDate = _getExportData($contributionId);
$sql = "SELECT cc.id contribution_id $form->assign('exportDate', $exportDate);
FROM civicrm_contribution cc CRM_Core_Region::instance('page-body')->add(['template' => "CRM/Batchexportperm/Form/BatchDetails.tpl"]);
INNER JOIN civicrm_entity_financial_trxn ceft CRM_Core_Resources::singleton()->addScriptFile('org.agbu.batchexportperm', 'js/exportDate.js');
ON ceft.entity_id = cc.id AND ceft.entity_table = 'civicrm_contribution'
INNER JOIN civicrm_entity_batch ceb
ON ceb.entity_id = ceft.financial_trxn_id
AND ceb.entity_table = 'civicrm_financial_trxn' AND ceb.batch_id = {$batchId}
GROUP BY cc.id";
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
civicrm_api3('Contribution', 'create', [
'id' => $dao->contribution_id,
"custom_{$customFieldId}" => date('Y-m-d H:i:s'),
]);
} }
} }

View File

@ -14,20 +14,13 @@
<url desc="Support">http://FIXME</url> <url desc="Support">http://FIXME</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url> <url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls> </urls>
<releaseDate>2018-06-29</releaseDate> <releaseDate>2019-08-13</releaseDate>
<version>1.0</version> <version>2.0</version>
<develStage>stable</develStage> <develStage>stable</develStage>
<compatibility> <compatibility>
<ver>4.6</ver> <ver>5.16</ver>
<ver>4.7</ver>
<ver>5.0</ver>
<ver>5.1</ver>
<ver>5.2</ver>
<ver>5.2</ver>
<ver>5.3</ver>
<ver>5.4</ver>
</compatibility> </compatibility>
<comments>This is a new, undeveloped module</comments> <comments></comments>
<civix> <civix>
<namespace>CRM/BatchExportPerm</namespace> <namespace>CRM/BatchExportPerm</namespace>
</civix> </civix>

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 -->