function CustomScheduler()
{
    global $sugar_config, $db;
    $timeDate = new TimeDate();
    $timeDateNow = $timeDate->getNow(true)->asDb();
    $days_offset = 15;
    $GLOBALS['log']->fatal("Checking Opportunities...");
    $query = "select opportunities.id from opportunities\n\twhere opportunities.sales_stage != 'Closed Won'\n\tand DATEDIFF(opportunities.date_modified,'" . $timeDateNow . "') < " . $days_offset . "\n\tand !opportunities.deleted";
    $GLOBALS['log']->fatal("Query: " . $query);
    $res = $db->query($query, true, 'Error: ');
    while ($row = $db->fetchByAssoc($res)) {
        $opportunity = new Opportunity();
        if (!is_null($opportunity->retrieve($row['id']))) {
            $user = new User();
            if (!is_null($user->retrieve($opportunity->assigned_user_id))) {
                $emailsTo = array();
                $emailSubject = "Opportunity Alert";
                $emailBody = "The following Opportunity has " . $days_offset . " days without changes.<br /><br />\n\t\t\t\tName: " . $opportunity->name . "<br />\n\t\t\t\tAccount: " . $opportunity->account_name . "<br />\n\t\t\t\tAmount: " . $opportunity->amount . "<br />\n\t\t\t\tSales Stage: " . $opportunity->sales_stage . "<br />\n\t\t\t\tDate Close: " . $opportunity->date_closed . "<br /><br />\n\t\t\t\tYou can see the opportunity here:<br />\n\t\t\t\t<a href=\"" . $sugar_config['site_url'] . "/index.php?module=Opportunities&action=DetailView&record=" . $opportunity->id . "\">" . $opportunity->name . "</a>";
                $emailsTo[] = $user->email1;
                SendEmail($emailsTo, $emailSubject, $emailBody);
            }
        }
    }
    $GLOBALS['log']->fatal("Opportunities checked");
    return true;
}
Example #2
0
 /**
  * Tests that currency-related properties are filled in at model layer
  * even when opportunity currency is the default one.
  */
 public function testDefaultCurrencyFieldsArePopulated()
 {
     $opportunity = new Opportunity();
     // disable row level security just to simplify the test
     $opportunity->disable_row_level_security = true;
     $opportunity->retrieve($this->opportunity->id);
     $this->assertNotEmpty($opportunity->currency_name);
     $this->assertNotEmpty($opportunity->currency_symbol);
 }
 function addRealty(&$bean)
 {
     $bean->load_relationship("realty_contracts");
     $bean->realty_contracts->delete($bean->id);
     $opp = new Opportunity();
     $opp->retrieve($bean->opp_id);
     $realty_list = $opp->get_linked_beans('realty_opportunities', 'Opportunities');
     foreach ($realty_list as $realty) {
         $bean->realty_contracts->add($realty->id);
     }
 }
Example #4
0
 /**
  * main method that runs reminding process
  * @return boolean
  */
 public function process()
 {
     $admin = new Administration();
     $admin->retrieveSettings();
     $GLOBALS['log']->info('----->test');
     $opportunities = $this->getOpportunitiesForRemind();
     foreach ($opportunities as $id) {
         echo "----->id:{$id}";
         $recipients = $this->getRecipients($id);
         $bean = new Opportunity();
         $bean->retrieve($id);
         if ($this->sendReminders($bean, $admin, $recipients)) {
             $bean->date_remind = 0;
             $bean->save();
         }
     }
     return true;
 }
Example #5
0
 function display()
 {
     global $mod_strings, $app_strings, $app_list_strings, $sugar_config, $beanFiles, $current_user;
     $this->ss->assign("MOD", $mod_strings);
     $this->ss->assign("APP_LIST", $app_list_strings);
     // IF THE PROJECT IS CREATED FROM AN OPP
     if (isset($_REQUEST['CreateFromOpp']) && $_REQUEST['CreateFromOpp'] == 'true') {
         // CREATE DEFAULT PROJECT LINK WITH OPPORTUNITY
         require_once $beanFiles['Opportunity'];
         $link_opportunity = new Opportunity();
         $link_opportunity->retrieve($_REQUEST['return_id']);
         $this->bean->opportunities_id = $link_opportunity->id;
         $this->bean->opportunities_name = $link_opportunity->name;
         $this->bean->accounts_name = $link_opportunity->account_name;
         $this->bean->accounts_id = $link_opportunity->account_id;
         $this->bean->id = $this->bean->save();
         $_REQUEST['record'] = $this->bean->id;
     }
     // IF THE PROJECT IS CREATED FROM AN ACCOUNT
     if (isset($_REQUEST['CreateFromAcc']) && $_REQUEST['CreateFromAcc'] == 'true') {
         // CREATE DEFAULT PROJECT LINK WITH OPPORTUNITY
         require_once $beanFiles['Account'];
         $link_account = new Account();
         $link_account->retrieve($_REQUEST['return_id']);
         $this->bean->accounts_name = $link_account->name;
         $this->bean->accounts_id = $link_account->id;
         $this->bean->id = $this->bean->save();
         $_REQUEST['record'] = $this->bean->id;
     }
     // Build Stat url
     /*$edit_url = "";
       if (isset($current_user->tilkee_token_c) && !empty($current_user->tilkee_token_c) && !empty($this->bean->edit_url)) {
           $edit_url = $this->bean->edit_url.'&access_token='.$current_user->tilkee_token_c;
       }*/
     $this->ss->assign("EDIT_URL", $this->bean->edit_url);
     parent::display();
 }
 *
 * All copies of the Covered Code must include on each user interface screen:
 *    (i) the "Powered by SugarCRM" logo and
 *    (ii) the SugarCRM copyright notice
 * in the same form as they appear in the distribution.  See full license for
 * requirements.
 *
 * The Original Code is: SugarCRM Open Source
 * The Initial Developer of the Original Code is SugarCRM, Inc.
 * Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.;
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 ********************************************************************************/
/*********************************************************************************
 * Description:  TODO: To be written.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
require_once 'modules/Opportunities/Opportunity.php';
$focus = new Opportunity();
if (!isset($_REQUEST['record'])) {
    sugar_die("A record number must be specified to delete the opportunity.");
}
$focus->retrieve($_REQUEST['record']);
if (!$focus->ACLAccess('Delete')) {
    ACLController::displayNoAccess(true);
    sugar_cleanup(true);
}
$focus->mark_deleted($_REQUEST['record']);
header("Location: index.php?module=" . $_REQUEST['return_module'] . "&action=" . $_REQUEST['return_action'] . "&record=" . $_REQUEST['return_id']);
 function send_nexmo_msg($bean, $event, $arguments)
 {
     if ($bean->object_name == "Opportunity") {
         $account = new Account();
         $account->retrieve($bean->account_id);
         $current_opportunity = new Opportunity();
         $current_opportunity->retrieve($bean->id);
         $account_name = $account->retrieve($bean->account_id)->name;
         //getting account name
         $opportunity_name = $bean->name;
         //getting opportunity name
         $saved_opportunity_amount = round($current_opportunity->amount_usdollar * $bean->base_rate, 2);
         //getting already opportunity amount
         $opportunity_amount = round($bean->amount_usdollar * $bean->base_rate, 2);
         //getting opportunity amount
         $saved_opportunity_amount = number_format($saved_opportunity_amount, 2);
         $opportunity_amount = number_format($opportunity_amount, 2);
         $currency_symbol = $bean->currency_symbol;
         if ($currency_symbol == "") {
             $currency_symbol = "\$";
         }
         $administration = new Administration();
         $administration->retrieveSettings();
         $api_key = $administration->settings['Nexmo_api_key'];
         // getting saved api key
         $api_secret = $administration->settings['Nexmo_api_secret'];
         // getting saved api secret
         if (isset($administration->settings['Nexmo_budget'])) {
             $min_budget = $administration->settings['Nexmo_budget'];
             // getting saved minimum budget
         } else {
             $min_budget = 0;
         }
         $send_msg = $administration->settings['Nexmo_send_msg'];
         // getting saved send msg flag
         $msg_from = file_get_contents('https://rest.nexmo.com/account/numbers/' . $api_key . '/' . $api_secret);
         //fetching from number
         $msg_from = (array) json_decode($msg_from);
         $msg_from = $msg_from['numbers'][0]->msisdn;
         $sms_text = "A new opportunity '" . $opportunity_name . "' for " . $account_name . " with probable value " . $currency_symbol . $opportunity_amount . " has been added.";
         if ($saved_opportunity_amount > $min_budget) {
             $sms_text = "An opportunity '" . $opportunity_name . "' for " . $account_name . " has been updated with probable value " . $currency_symbol . $opportunity_amount;
         }
         if (isset($opportunity_amount) && $opportunity_amount > 0 && $opportunity_amount > $min_budget && $send_msg == true) {
             global $current_user;
             $reports_to_id = "";
             if (isset($current_user->reports_to_id)) {
                 $reports_to_id = $current_user->reports_to_id;
             }
             if ($reports_to_id != "") {
                 $manager = new User();
                 $manager->retrieve($reports_to_id);
                 $to_number = "";
                 if (isset($manager->phone_mobile)) {
                     $to_number = $manager->phone_mobile;
                 }
                 if ($to_number != "" && $saved_opportunity_amount != $opportunity_amount) {
                     // send message only if amount is udpated
                     //error_log('http://rest.nexmo.com/sms/xml?api_key='.$api_key.'&api_secret='.$api_secret.'&from='.$msg_from.'&to='.$to_number.'&text='.urlencode($sms_text));
                     $response = file_get_contents('http://rest.nexmo.com/sms/xml?api_key=' . $api_key . '&api_secret=' . $api_secret . '&from=' . $msg_from . '&to=' . $to_number . '&text=' . urlencode($sms_text));
                 }
             }
         }
     }
 }
     $contact->retrieve($_POST['selectedContact']);
 } else {
     $contact = $contactForm->handleSave('Contacts', false, false);
 }
 if (!empty($_POST['selectedAccount'])) {
     $account = new Account();
     $account->retrieve($_POST['selectedAccount']);
 } else {
     if (isset($_POST['newaccount']) && $_POST['newaccount'] == 'on') {
         $account = $accountForm->handleSave('Accounts', false, false);
     }
 }
 if (isset($_POST['newopportunity']) && $_POST['newopportunity'] == 'on') {
     if (!empty($_POST['selectedOpportunity'])) {
         $opportunity = new Opportunity();
         $opportunity->retrieve($_POST['selectedOpportunity']);
     } else {
         if (isset($account)) {
             $_POST['Opportunitiesaccount_id'] = $account->id;
             $_POST['Opportunitiesaccount_name'] = $account->name;
         }
         if (isset($_POST['Contactslead_source']) && !empty($_POST['Contactslead_source'])) {
             $_POST['Opportunitieslead_source'] = $_POST['Contactslead_source'];
         }
         $opportunity = $oppForm->handleSave('Opportunities', false, false);
     }
 }
 require_once 'modules/Notes/NoteFormBase.php';
 $noteForm = new NoteFormBase();
 if (isset($account)) {
     $_POST['AccountNotesparent_id'] = $account->id;
Example #9
0
 function update_tilkee_project_API(&$bean, $event, $arguments = null)
 {
     if ($event != 'after_save') {
         return;
     }
     global $beanFiles;
     // Update linked Opportunity sales_stage if project archived
     if ($bean->status == 'archived' && !empty($bean->opportunities_id)) {
         if (file_exists($beanFiles['Opportunity'])) {
             require_once $beanFiles['Opportunity'];
             $current_opportunity = new Opportunity();
             $current_opportunity->retrieve($bean->opportunities_id);
             if ($bean->won == 'true') {
                 if ($current_opportunity->sales_stage != 'Closed Won') {
                     $current_opportunity->sales_stage = 'Closed Won';
                     $current_opportunity->save();
                 }
             }
             if ($bean->won == 'false') {
                 if ($current_opportunity->sales_stage != 'Closed Lost') {
                     $current_opportunity->sales_stage = 'Closed Lost';
                     $current_opportunity->save();
                 }
             }
         }
     }
     // If the project just create
     if (empty($bean->tilkee_id)) {
         // appel de l'API de creation du projet et Mise a jour des infos du projet
         $bean->create_from_API();
         //} else {
         // appel de l'API de mise à jour du projet et Mise a jour des infos du projet
         //$bean->update_from_API($this->won, ($this->status=='archived')?'true':'false');
     }
 }
 public function testsave()
 {
     $opportunity = new Opportunity();
     $opportunity->name = 'test';
     $opportunity->description = 'test description';
     $opportunity->sales_stage = 'Value Proposition';
     $result = $opportunity->save();
     //test for record ID to verify that record is saved
     $this->assertTrue(isset($opportunity->id));
     $this->assertEquals(36, strlen($opportunity->id));
     $this->assertEquals(-99, $opportunity->currency_id);
     $this->assertEquals(30, $opportunity->probability);
     //mark the record as deleted and verify that this record cannot be retrieved anymore.
     $opportunity->mark_deleted($opportunity->id);
     $result = $opportunity->retrieve($opportunity->id);
     $this->assertEquals(null, $result);
 }