convert batchexportperm to use actual batch data; displaying export data is WIP
This commit is contained in:
parent
9f2da42ae1
commit
05997ff2f6
@ -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' => 1,
|
|
||||||
'is_active' => TRUE,
|
|
||||||
'is_multiple' => FALSE,
|
|
||||||
'collapse_adv_display' => 0,
|
|
||||||
'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,17 +240,19 @@ 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', [
|
// See if the contribution has been exported.
|
||||||
'return' => "id",
|
// Man, I wish API4 actually worked.
|
||||||
'custom_group_id' => "batchexportperm_batch_details",
|
$query = "SELECT ceft.entity_id "
|
||||||
'name' => "export_date",
|
. "FROM civicrm_entity_batch ceb "
|
||||||
]);
|
. "JOIN civicrm_batch cb on ceb.batch_id = cb.id AND ceb.entity_table = 'civicrm_financial_trxn' "
|
||||||
$exportDate = civicrm_api3('Contribution', 'get', [
|
. "JOIN civicrm_entity_financial_trxn ceft ON ceft.entity_table = 'civicrm_contribution' AND ceb.entity_id = ceft.financial_trxn_id "
|
||||||
'return' => "custom_{$customFieldId}",
|
. "JOIN civicrm_option_value cov on cov.value = cb.status_id AND cov.label = 'Exported' "
|
||||||
'id' => $contributionId,
|
. "JOIN civicrm_option_group cog ON cov.option_group_id = cog.id AND cog.name = 'batch_status' "
|
||||||
'sequential' => 1,
|
. "WHERE ceft.entity_id = %1";
|
||||||
])['values'][0]["custom_{$customFieldId}"];
|
$params = [1 => [$contributionId, 'Integer']];
|
||||||
if (empty($exportDate) || CRM_Core_Permission::check('edit exported contributions')) {
|
$dao = CRM_Core_DAO::executeQuery($query, $params);
|
||||||
|
|
||||||
|
if ($dao->N === 0 || CRM_Core_Permission::check('edit exported contributions')) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -312,29 +273,13 @@ function batchexportperm_civicrm_post($op, $objectName, $objectId, &$objectRef)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 (in_array($formName, ['CRM_Contribute_Form_ContributionView', 'CRM_Contribute_Form_Contribution']) &&
|
||||||
'return' => "id",
|
!empty($form->_id)) {
|
||||||
'custom_group_id' => "batchexportperm_batch_details",
|
$temp = $form->_id;
|
||||||
'name' => "export_date",
|
$temp2 = }
|
||||||
]);
|
|
||||||
$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'),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user