Hey All,
I am trying to perform some simple calculations each time a opportunity is submitted. What i currently have it three fields (all numerical dollar values).
software_amt_c
main_amt_c
services_amt_c
And i want to automatically add these fields together into another field, called amount_usdollar.
Here is my code:
UpdateTotals.php
logic_hooks.phpCode:<?php if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); class update_totals{ function update_totals(&$bean, $event, $arguments){ // make sure the Date Entered and Date Modified match (ie new bug created) // $bean->date_entered is the date created on // $bean->date_modified is the date last modified (should match for new bugs) $bean->amount_usdollar = 1; if (defined($bean->SOFTWARE_AMOUNT_c)) { $software_amount = $bean->SOFTWARE_AMOUNT_c; } else { $software_amount = 0; } if (defined($bean->MAINTENANCE_AMOUNT_c)) { $maintenance_amount = $bean->MAINTENANCE_AMOUNT_c; } else { $maintenance_amount = 0; } if (defined($bean->SERVICES_AMOUNT_c)) { $services_amount = $bean->SERVICES_AMOUNT_c; } else { $services_amount = 0; } $total_opp = $software_amount + $services_amount + $maintenance_amount; $bean->amount_usdollar = $total_opp; var_dump($bean->SOFTWARE_AMOUNT_c); var_dump($bean->MAINTENANCE_AMOUNT_c); var_dump($bean->SERVICES_AMOUNT_c); var_dump($bean->amount_usdollar); } } ?>
When i click submit on the entry, i would expect the totals field to be populated with 30 (all three values are assigned to 10... 10+10+10 = 30 last time i checked.).Code:<?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. // This file copied from the Cases logic_hooks.php file $hook_version = 1; $hook_array = Array(); // position, file, function $hook_array['before_save'] = Array(); $hook_array['before_save'][] = Array(1, 'UpdateTotals', 'custom/modules/Opportunities/UpdateTotals.php', update_totals, update_totals); ?>
The field always stays at 0 regardless ... any help would be greatly appreciated.
Cheers


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks