Hi,
I am new user of SuiteCRM.
I have followed https://suitecrm.com/forum/suitecrm-7-0-discussion/3284-creating-a-calculated-field-to-count-days-until-a-date?limitstart=0 to create a “weighted_amount” field for an opportunity, which would be equal to amount * probability (and am surprised it does not already exist, by the way - did I miss something?)
The field works great in the detail view, but shows as “€0.00” in the list view, and don’t understand why. I have used the Repair > Quick repair and rebuild but it does not help.
Also what is strange is that despite the field is a varchar it appears as a Currency (well, at some point in time, I changed to Currency in the code, but went back to varchar afterwards as I had issues to fix, but I don’t understand where the memory of this change could be stored, if it is stored somewhere)
Could you please advise? you will find below my code. I have used Studio to change the layouts in order to add the field in the detail view and list view. And by the way, had to add the “studio” => “visible” key in the PHP code, which mysteriously disappears once I repair and rebuild. Not sure to use the right approach, please correct me on the right way to do as well, I could not find documentation other than the SugarCRM one.
Many thanks in advance, and best regards
cat Ext/Vardefs/vardefs.ext.php
<?php
//WARNING: The contents of this file are auto-generated
// created: 2016-05-28 02:01:16
$dictionary['Opportunity']['fields']['jjwg_maps_lng_c']['inline_edit']=1;
// created: 2016-05-28 02:01:16
$dictionary['Opportunity']['fields']['jjwg_maps_lat_c']['inline_edit']=1;
// created: 2016-05-28 02:01:16
$dictionary['Opportunity']['fields']['jjwg_maps_geocode_status_c']['inline_edit']=1;
// created: 2016-05-28 02:01:17
$dictionary['Opportunity']['fields']['jjwg_maps_address_c']['inline_edit']=1;
$dictionary['Opportunity']['fields']['weighted_amount'] = array(
'name' => 'weighted_amount',
'vname' => 'LBL_WEIGHTED_AMOUNT',
'type' => 'varchar',
'len' => '10',
'source' => 'non-db',
);
------
cat 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(1, 'Opportunities push feed', 'modules/Opportunities/SugarFeeds/OppFeed.php','OppFeed', 'pushFeed');
$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');
$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array(1, 'Weighted amount = amount * proba', 'custom/modules/Opportunities/OpportunitiesWeightedAmountLogicHook.php', 'OpportunitiesWeightedAmountLogicHook', 'after_retrieve');
$hook_array['process_record'] = Array();
$hook_array['process_record'][] = Array(1, 'Weighted amount = amount * proba', 'custom/modules/Opportunities/OpportunitiesWeightedAmountLogicHook.php', 'OpportunitiesWeightedAmountLogicHook', 'process_record');
?>
----------
cat OpportunitiesWeightedAmountLogicHook.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die ('Not a valid Entry Point');
class OpportunitiesWeightedAmountLogicHook {
function after_retrieve ($bean, $event, $arguments) {
$this->compute_weighted_amount ($bean);
}
function process_record ($bean, $event, $arguments) {
$this->compute_weighted_amount ($bean);
}
function compute_weighted_amount ($bean, $event, $arguments) {
$focus = $bean->custom_fields->retrieve();
$amount = $bean->amount;
$prob = $bean->probability / 100.0;
$bean->weighted_amount = $amount * $prob;
}
}
?>