Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
b7e090a190 | |||
428ee00b04 | |||
6c65142573 | |||
05997ff2f6 | |||
9f2da42ae1 | |||
fe8053a414 | |||
a4ba86b09e |
@ -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().
|
||||
@ -85,47 +85,6 @@ function batchexportperm_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
|
||||
*/
|
||||
function batchexportperm_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
|
||||
*/
|
||||
function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) {
|
||||
$customFieldId = civicrm_api3('CustomField', 'getvalue', [
|
||||
'return' => "id",
|
||||
'custom_group_id' => "batchexportperm_batch_details",
|
||||
'name' => "export_date",
|
||||
]);
|
||||
$exportDate = civicrm_api3('Contribution', 'getvalue', [
|
||||
'return' => "custom_{$customFieldId}",
|
||||
'id' => $contributionId,
|
||||
]);
|
||||
if (empty($exportDate) || CRM_Core_Permission::check('edit exported contributions')) {
|
||||
|
||||
$exportDate = _getExportData($contributionId);
|
||||
|
||||
if (!$exportDate || CRM_Core_Permission::check('edit exported contributions')) {
|
||||
return TRUE;
|
||||
}
|
||||
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
|
||||
*/
|
||||
function batchexportperm_civicrm_post($op, $objectName, $objectId, &$objectRef) {
|
||||
if ($objectName == 'Batch' && $op == 'edit') {
|
||||
if (CRM_Core_Smarty::singleton()->get_template_vars("batch_status_change_{$objectId}")) {
|
||||
_batchexportperm_civicrm_update_contribution_exporteddate($objectId);
|
||||
CRM_Core_Smarty::singleton()->assign("batch_status_change_{$objectId}", FALSE);
|
||||
}
|
||||
}
|
||||
function _getExportData($contributionId) {
|
||||
// See if the contribution has been exported.
|
||||
// Man, I wish API4 actually worked.
|
||||
$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 "
|
||||
. "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) {
|
||||
$customFieldId = civicrm_api3('CustomField', 'getvalue', [
|
||||
'return' => "id",
|
||||
'custom_group_id' => "batchexportperm_batch_details",
|
||||
'name' => "export_date",
|
||||
]);
|
||||
$sql = "SELECT cc.id contribution_id
|
||||
FROM civicrm_contribution cc
|
||||
INNER JOIN civicrm_entity_financial_trxn ceft
|
||||
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'),
|
||||
]);
|
||||
function batchexportperm_civicrm_buildForm($formName, $form) {
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
15
info.xml
15
info.xml
@ -14,20 +14,13 @@
|
||||
<url desc="Support">http://FIXME</url>
|
||||
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
|
||||
</urls>
|
||||
<releaseDate>2018-06-29</releaseDate>
|
||||
<version>1.0</version>
|
||||
<releaseDate>2019-08-13</releaseDate>
|
||||
<version>2.0</version>
|
||||
<develStage>stable</develStage>
|
||||
<compatibility>
|
||||
<ver>4.6</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>
|
||||
<ver>5.16</ver>
|
||||
</compatibility>
|
||||
<comments>This is a new, undeveloped module</comments>
|
||||
<comments></comments>
|
||||
<civix>
|
||||
<namespace>CRM/BatchExportPerm</namespace>
|
||||
</civix>
|
||||
|
3
js/exportDate.js
Normal file
3
js/exportDate.js
Normal file
@ -0,0 +1,3 @@
|
||||
CRM.$(function ($) {
|
||||
$('#export-details-accordion').insertBefore('.crm-submit-buttons:last');
|
||||
});
|
16
templates/CRM/Batchexportperm/Form/BatchDetails.tpl
Normal file
16
templates/CRM/Batchexportperm/Form/BatchDetails.tpl
Normal 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 -->
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user