entering formula in sugar logic

i wanted to calculate no of days between two dates. using logic hook created two files in custom/modules/(module Name)/logic_hooks.php and custom/modules/(module Name)/class_name.php files.

using this formula wanted to calculate the no of months but the syntax is somewhere wrong. any suggestion?

$no_of_months = floor(divide(subtract(daysUntil($contarctenddate),daysUntil($contarctstartdate)),30)) ;

Full function is below

class updatePMSchedule {
function updatefirstpmschedule (&$bean, $event, $arguments) {
$contarctstartdate = $bean-> contract_start_date;
$contarctenddate = $bean-> contract_end_date;
$no_of_months = floor(divide(subtract(daysUntil($contarctenddate),daysUntil($contarctstartdate)),30)) ;
}
}

Break the long nested series of calls for your math expression, into one line per function call, assign each return value from to a variable.

seems sugar logic is not available in CE. made a function and it works.

	function dateDifference($date_1 , $date_2 , $differenceFormat = '%a' )
	{
	  $datetime1 = date_create($date_1);
	  $datetime2 = date_create($date_2);    
	   $interval = date_diff($datetime1, $datetime2);    
	   return $interval->format($differenceFormat);    
	}

Sugar Logic is available on Sugar Pro and Enterprise.

SA could implement a compatible version - let’s call it SuiteLogic - for SuiteCRM.

For now, you can do a “Logic hook” - check out the SugarCRM developer guide, and these pages for more.
http://www.atcoresystems.com/blog/how-to-create-a-logic-hook-in-sugarcrm/
http://academe.co.uk/2013/02/sugarcrm-module-builder-adding-logic-hooks/
http://technossips.com/how-to/computer/how-to-create-logic-hooks-in-sugar-crm/

1 Like