Skip to content

Instantly share code, notes, and snippets.

@hatimalam
Last active March 14, 2016 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatimalam/71b540cebf110aac3239 to your computer and use it in GitHub Desktop.
Save hatimalam/71b540cebf110aac3239 to your computer and use it in GitHub Desktop.
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class CheckOppDiscount {
function check_opp_discount($bean, $event, $arguments) {
//check if discount percentage is >25%
if($bean->opp_discount_c > 25) {
//get assigned user bean
$assigned_user_bean = BeanFactory::getBean("Users", $bean->assigned_user_id);
//fetch assigned user's manager
$manager_id = $assigned_user_bean->reports_to_id;
//create sugar notification
$notification_bean = BeanFactory::getBean("Notifications");
$notification_bean->name = 'Opportunity - {$bean->name} is in danger';
$notification_bean->description = 'Discount percentage is more than 25%.';
$notification_bean->parent_id = $bean->id;
$notification_bean->parent_type = 'Opportunities';
$notification_bean->assigned_user_id = $manager_id;
$notification_bean->severity = "warning";
$notification_bean->is_read = 0;
$notification_bean->save();
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment