I am trying to display the sum of a column on the Opportunities listview in the way described in the below article:
I used the logic hook given by user âWebberâ to try and show the total for âamountâ at the bottom of the View Opportunities page, but seem to have broken the Opportunities module altogether, as trying to view Opportunities or Create Opportunities leads me to a screen saying âAn error has occurred: There was an error processing your request, please try again at a later time.â
I am wondering if the html code portion was not upgrade safe from the time it was posted (3 years ago) until now, and how to move from here in terms of getting it to work with 7.10.5.
I am using SuiteP theme, and am posting my .php files below (all credit on code goes to user âWebberâ)
custom/modules/Opportunities/logic_hooks.php
<?php
// Do not store anything in this file that is not part of the array or the hook version. This file will
// be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(77, 'updateGeocodeInfo', 'modules/Opportunities/OpportunitiesJjwg_MapsLogicHook.php','OpportunitiesJjwg_MapsLogicHook', 'updateGeocodeInfo');
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(77, 'updateRelatedMeetingsGeocodeInfo', 'modules/Opportunities/OpportunitiesJjwg_MapsLogicHook.php','OpportunitiesJjwg_MapsLogicHook', 'updateRelatedMeetingsGeocodeInfo');
$hook_array['after_save'][] = Array(78, 'updateRelatedProjectGeocodeInfo', 'modules/Opportunities/OpportunitiesJjwg_MapsLogicHook.php','OpportunitiesJjwg_MapsLogicHook', 'updateRelatedProjectGeocodeInfo');
$hook_array['after_relationship_add'] = Array();
$hook_array['after_relationship_add'][] = Array(77, 'addRelationship', 'modules/Opportunities/OpportunitiesJjwg_MapsLogicHook.php','OpportunitiesJjwg_MapsLogicHook', 'addRelationship');
$hook_array['after_relationship_delete'] = Array();
$hook_array['after_relationship_delete'][] = Array(77, 'deleteRelationship', 'modules/Opportunities/OpportunitiesJjwg_MapsLogicHook.php','OpportunitiesJjwg_MapsLogicHook', 'deleteRelationship');
//above this comment was default arrays, below was added by instruction of referenced article
$hook_array['after_retrieve'] = Array();
$hook_array['process_record'] = Array();
$hook_array['after_ui_frame'] = Array();
$hook_array['process_record'][] = Array(1, 'callForEachRecord', 'custom/modules/Opportunities/OpportunitiesaddTotalToOpp_LogicHook.php','addTotalToOpp', 'callForEachRecord');
$hook_array['after_ui_frame'][] = Array(1, 'addSumToPage', 'custom/modules/Opportunities/OpportunitiesaddTotalToOpp_LogicHook.php','addTotalToOpp', 'addSumToPage');
?>
custom/modules/Opportunities/OpportunitiesaddTotalToOpp_LogicHook.php
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class addTotalToOpp {
protected static $yourSum = 0;
function callForEachRecord(&$focus, $event, $arguments) {
$focus->custom_fields->retrieve();
self::$yourSum += $focus->amount;
}
function addSumToPage(&$focus, $event, $arguments) {
if ($GLOBALS['action'] == 'index' || $GLOBALS['action'] == 'ListView') {
$yourSum = self::$yourSum;
echo <<<EOHTML
<script type="text/javascript">
<!--
$('<p align="center" vertical-align="middle"><b>Total Amount: {$yourSum}</b></p>').insertBefore('.paginationChangeButtons');
-->
</script>
EOHTML;
}
}
}
?>