AnsweredAssumed Answered

Calculate  the number of days in a current stage: SOLVED

Question asked by arturo.hernandez on Jul 14, 2015
Latest reply on Jul 29, 2015 by jihed jihed
I had to calculate the number of days of an Account in the current status. This is how I solve it, I hope this can help you...

in logic_hooks.php:


    $hook_version = 1;
    $hook_array = Array();
    $hook_array['before_save'] = Array();
    $hook_array['before_save'][] = Array(
        //Processing index. For sorting the array.
        //Label. A string value to identify the hook.
        //The PHP file where your class is located.
        //The class the method is in.
        //The method to call.

$hook_array['before_save'][] = Array(
        1, 'calculate', 'custom/modules/Accounts/logic_hooks_class.php', 'days_in_stage_class', 'before_save_current_stage'


in logic_hooks_class.php:

function before_save_current_stage($bean, $event, $arguments)
        $a = $bean->fetched_row['current_stage_c']; 
        $b = $bean->current_stage_c;
        if($b !== $a)
                 $bean->days_in_current_stage_c = 0;
                 $today = date('Y-m-d H:i:s');
                 $bean->date_in_stage_c = $today;
                $diff = ($now - strtotime($bean->fetched_row['date_in_stage_c']))/(60*60*24);
                $bean->days_in_current_stage_c = $diff;

If someone have any question, please feel confident to contact me.