Last active
December 10, 2018 13:19
-
-
Save pradpnayak/21c897b0c6821bdc5373c5af88c78172 to your computer and use it in GitHub Desktop.
Add last contribution details on Contri Detail report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_civicrm_alterReportVar(). | |
* | |
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterReportVar | |
*/ | |
function contactgeofields_civicrm_alterReportVar($varType, &$var, &$object) { | |
if ($varType == 'columns') { | |
$var['civicrm_contribution']['fields']['last_contribution_id'] = [ | |
'title' => ts('Last Contri ID'), | |
'dbAlias' => 'last_detail_temp.l_id', | |
]; | |
} | |
if ($varType == 'sql') { | |
$from = $object->getVar('_from'); | |
$where = $object->getVar('_where'); | |
$sql = " | |
CREATE TEMPORARY TABLE civireport_contribution_last_detail_temp DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci AS | |
SELECT * FROM (select @i:=0) as a, ( | |
SELECT now.id, last.id as l_id FROM civicrm_contribution last LEFT JOIN | |
(SELECT contribution_civireport.id, contribution_civireport.contact_id, | |
contribution_civireport.receive_date | |
{$from} | |
{$where} | |
) AS now ON now.contact_id = last.contact_id | |
AND now.id <> last.id AND now.receive_date > last.receive_date | |
WHERE now.id IS NOT NULL | |
ORDER BY now.id, last.receive_date DESC | |
) AS t | |
GROUP BY t.id"; | |
CRM_Core_DAO::executeQuery($sql); | |
$_aclFrom = " LEFT JOIN civireport_contribution_last_detail_temp last_detail_temp ON last_detail_temp.id = contribution_civireport.id "; | |
$from .= $_aclFrom; | |
$object->setACLFromForLastContribution = $object->getVar('_aclFrom'); | |
$aclFrom = $object->getVar('_aclFrom') . $_aclFrom; | |
$object->setVar('_from', $from); | |
$object->setVar('_aclFrom', $aclFrom); | |
$object->setFromForLastContribution = $from; | |
} | |
if ($varType == 'rows') { | |
$object->setVar('_aclFrom', $object->setACLFromForLastContribution); | |
$object->setVar('_from', $object->setFromForLastContribution); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment