function display($defines)
 {
     global $app_strings;
     global $currentModule;
     $title = $app_strings['LBL_COMPOSE_EMAIL_BUTTON_TITLE'];
     $accesskey = $app_strings['LBL_COMPOSE_EMAIL_BUTTON_KEY'];
     $value = $app_strings['LBL_COMPOSE_EMAIL_BUTTON_LABEL'];
     $this->module = 'Emails';
     $to_addrs = '';
     $additionalFormFields = array();
     $additionalFormFields['type'] = 'out';
     // cn: bug 5727 - must override the parents' parent for contacts (which could be an Account)
     $additionalFormFields['parent_type'] = $defines['focus']->module_dir;
     $additionalFormFields['parent_id'] = $defines['focus']->id;
     $additionalFormFields['parent_name'] = $defines['focus']->name;
     if (isset($defines['focus']->email1)) {
         $to_addrs = $defines['focus']->email1;
     } elseif ($defines['focus']->object_name == 'Case') {
         require_once 'modules/Accounts/Account.php';
         $acct = new Account();
         $acct->retrieve($defines['focus']->account_id);
         $to_addrs = $acct->email1;
     }
     if (!empty($to_addrs)) {
         $additionalFormFields['to_email_addrs'] = $to_addrs;
     }
     if (ACLController::moduleSupportsACL($defines['module']) && !ACLController::checkAccess($defines['module'], 'edit', true)) {
         $button = "<input title='{$title}' class='button' type='button' name='button' value='  {$value}  '/>\n";
         return $button;
     }
     $button = $this->_get_form($defines, $additionalFormFields);
     $button .= "<input title='{$title}' accesskey='{$accesskey}' class='button' type='submit' name='button' value='  {$value}  '/>\n";
     $button .= "</form>";
     return $button;
 }
Beispiel #2
0
 function execute(&$bean)
 {
     if ($bean->sales_stage == "completed") {
         $realty_list = $bean->get_linked_beans("realty_opportunities", "Realty");
         if (!empty($bean->contact_id)) {
             $contact = new Contact();
             $contact->retrieve($bean->contact_id);
             foreach ($realty_list as $realty) {
                 if ($realty->operation == 'rent') {
                     $contact->load_relationship("realty_contacts_rent");
                     $contact->realty_contacts_rent->add($realty->id);
                 } elseif ($realty->operation == 'buying') {
                     $contact->load_relationship("realty_contacts_buying");
                     $contact->realty_contacts_buying->add($realty->id);
                 }
             }
         }
         if (!empty($bean->account_id)) {
             $account = new Account();
             $account->retrieve($bean->account_id);
             foreach ($realty_list as $realty) {
                 if ($realty->operation == 'rent') {
                     $account->load_relationship("realty_accounts_rent");
                     $account->realty_accounts_rent->add($realty->id);
                 } elseif ($realty->operation == 'buying') {
                     $account->load_relationship("realty_accounts_buying");
                     $account->realty_accounts_buying->add($realty->id);
                 }
             }
         }
     }
 }
 public function testIDRetrieve()
 {
     self::authorizeFromEnv();
     $d = Account::retrieve('cuD9Rwx8pgmRZRpVe02lsuR9cwp2Bzf7');
     $this->assertSame($d->id, "cuD9Rwx8pgmRZRpVe02lsuR9cwp2Bzf7");
     $this->assertSame($d->email, "*****@*****.**");
 }
Beispiel #4
0
 function process_record_hook(&$bean, $event, $arguments)
 {
     $bean->acct_mgr_c = '';
     $full_copy = new Account();
     $full_copy->retrieve($bean->account_id);
     $full_copy->custom_fields->retrieve();
     $bean->acct_mgr_c = $full_copy->assigned_user_name;
     echo "<!-- FINDMOI " . $bean->acct_mgr_c . " -->\n";
 }
Beispiel #5
0
 public static function tokenLogin($token)
 {
     $sql = "SELECT account_id from account where token='{$token}'";
     $res = pg_query($sql);
     $row = pg_fetch_array($res);
     $id = $row[0];
     if (isset($id)) {
         return Account::retrieve((object) array("id" => $id));
     }
 }
Beispiel #6
0
 function display()
 {
     $this->ev->process();
     //echo "<!-- \n";
     //var_dump($_REQUEST);
     //echo "-->";
     if (empty($this->ev->focus->id) && ($_REQUEST['relate_to'] == 'projects_accounts' || $_REQUEST['return_relationship'] == 'projects_accounts')) {
         $parent = new Account();
         if (isset($_REQUEST['relate_id'])) {
             $parent->retrieve($_REQUEST['relate_id']);
         } else {
             $parent->retrieve($_REQUEST['parent_id']);
         }
         if (isset($parent->id) && $this->ev->fieldDefs['account_id_c']['value'] == "") {
             $this->ev->fieldDefs['account_id_c']['value'] = $parent->id;
             $this->ev->fieldDefs['account_c']['value'] = $parent->name;
         }
     }
     echo $this->ev->display();
 }
Beispiel #7
0
 public function testNoUpdateDateEnteredWithValue()
 {
     global $disable_date_format;
     $disable_date_format = true;
     $newDateEntered = '2011-01-28 11:05:10';
     $oldDateEntered = $this->_account->date_entered;
     $this->_account->date_entered = $newDateEntered;
     $this->_account->save();
     $acct = new Account();
     $acct->retrieve($this->_account->id);
     $this->assertEquals($acct->date_entered, $oldDateEntered, "Account date_entered should be equal to old date_entered");
     $this->assertNotEquals($acct->date_entered, $newDateEntered, "Account date_entered should not be equal to old date_entered");
 }
 public function testUpdateAdditionalOwners()
 {
     self::authorizeFromEnv();
     $d = Account::create(array('managed' => true));
     $id = $d->id;
     $d->legal_entity->additional_owners = array(array('first_name' => 'Bob'));
     $d->save();
     $d = Account::retrieve($id);
     $this->assertSame(1, count($d->legal_entity->additional_owners));
     $this->assertSame('Bob', $d->legal_entity->additional_owners[0]->first_name);
     $d->legal_entity->additional_owners[0]->last_name = 'Smith';
     $d->save();
     $d = Account::retrieve($id);
     $this->assertSame(1, count($d->legal_entity->additional_owners));
     $this->assertSame('Smith', $d->legal_entity->additional_owners[0]->last_name);
 }
 /**
  * @ticket 49281
  */
 public function testInsertUpdateLongData()
 {
     $acc = new Account();
     $acc->name = "PHPUNIT test";
     $acc->assigned_user_id = $GLOBALS['current_user']->id;
     $acc->sic_code = 'mnbvcxzasdfghjklpoiuytrewqmnbvcxzasdfghjklpoiuytre';
     $acc->save();
     $id = $acc->id;
     SugarTestAccountUtilities::setCreatedAccount(array($id));
     $acc = new Account();
     $acc->retrieve($id);
     $this->assertEquals('mnbvcxzasd', $acc->sic_code);
     $acc->sic_code = 'f094f59daaed0983a6a2e5913ddcc5fb';
     $acc->save();
     $acc = new Account();
     $acc->retrieve($id);
     $this->assertEquals('f094f59daa', $acc->sic_code);
 }
Beispiel #10
0
 function display()
 {
     $this->ev->process();
     //echo "<!-- \n";
     //var_dump($_REQUEST);
     //echo "-->";
     if (empty($this->ev->focus->id) && $_REQUEST['relate_to'] == 'projects_accounts') {
         $parent = new Account();
         $parent->retrieve($_REQUEST['relate_id']);
         if (isset($parent->specialbilling_c) && $this->ev->fieldDefs['specialbilling_c']['value'] == "") {
             $this->ev->fieldDefs['specialbilling_c']['value'] = $parent->specialbilling_c;
         }
         if (isset($parent->name) && $this->ev->fieldDefs['customer_c']['value'] == "") {
             $this->ev->fieldDefs['customer_c']['value'] = $parent->name;
         }
     }
     echo $this->ev->display();
 }
Beispiel #11
0
function loadRel($module, $module_id, $linked_module_id)
{
    if ($module == 'Accounts') {
        $Accounts = new Account();
        $Accounts->retrieve($linked_module_id);
        $Accounts->load_relationships('realty_accounts_interest');
        $Accounts->realty_accounts_interest->add($module_id);
    } elseif ($module == 'Contacts') {
        $Contacts = new Contact();
        $Contacts->retrieve($linked_module_id);
        $Contacts->load_relationships('realty_contacts_interest');
        $Contacts->realty_contacts_interest->add($module_id);
    } elseif ($module == 'Request') {
        $Request = new Request();
        $Request->retrieve($linked_module_id);
        $Request->load_relationships('realty_requests_interest');
        $Request->realty_requests_interest->add($module_id);
    }
}
 function infoParties()
 {
     global $sugar_config;
     $this->sellerInfo = array('PersonTypeCode' => $sugar_config['fact_person_type_code'], 'ResidenceTypeCode' => $sugar_config['fact_residence_type_code'], 'TaxIdentificationNumber' => $sugar_config['fact_tax_number'], 'Address' => $sugar_config['fact_address'], 'PostCode' => $sugar_config['fact_post_code'], 'Town' => $sugar_config['fact_town'], 'Province' => $sugar_config['fact_province'], 'CountryCode' => $sugar_config['fact_country_code']);
     // Names and other attributes depends on person type
     if ($sugar_config['fact_person_type_code'] == 'F') {
         $this->sellerInfo['Name'] = $sugar_config['fact_corporate_name'];
         $this->sellerInfo['FirstSurname'] = $sugar_config['fact_trade_name_surname1'];
         $this->sellerInfo['SecondSurname'] = $sugar_config['fact_registration_surname2'];
     } else {
         $this->sellerInfo['CorporateName'] = $sugar_config['fact_corporate_name'];
         $this->sellerInfo['TradeName'] = $sugar_config['fact_trade_name_surname1'];
         $this->sellerInfo['RegistrationData'] = $sugar_config['fact_registration_surname2'];
     }
     $account = new Account();
     $account->retrieve($this->bean->account_id);
     $nif_field = $sugar_config['fact_account_nif_field'] ? $sugar_config['fact_account_nif_field'] : 'nonexistenfield';
     $this->buyerInfo = array('PersonTypeCode' => 'J', 'ResidenceTypeCode' => 'R', 'TaxIdentificationNumber' => $account->{$nif_field} ? $account->{$nif_field} : '000000', 'CorporateName' => $account->name, 'Address' => $account->billing_address_street, 'PostCode' => $account->billing_address_postalcode ? $account->billing_address_postalcode : '00000', 'Town' => $account->billing_address_city, 'Province' => $account->billing_address_state, 'CountryCode' => 'ESP');
 }
Beispiel #13
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();
 }
<?php

require_once 'custom/include/fpdf17/fpdf.php';
require_once "custom/send_mail.php";
require_once 'custom/Presentation/generate.php';
global $sugar_config, $db;
echo "<h3>Генерация презентации</h3><br/>";
$emails = array();
$contact = new Account();
$contact->retrieve($_GET['id']);
$assigned_user_id = $contact->assigned_user_id;
$ass = new User();
$ass->retrieve($assigned_user_id);
$sqlemail = "SELECT email_addresses.email_address \n\t\t\tFROM email_addresses\n\t\t\tLEFT JOIN email_addr_bean_rel ON email_addr_bean_rel.email_address_id = email_addresses.id AND email_addr_bean_rel.deleted = 0\n\t\t\tWHERE email_addresses.deleted = 0 \n\t\t\tAND bean_id = '{$contact->id}' ";
$resultemail = $db->query($sqlemail);
while ($rowemail = $db->fetchByAssoc($resultemail)) {
    $emails[] = $rowemail['email_address'];
}
$sqla = "SELECT realty_id FROM realty_accounts_m_to_m_table WHERE presentation_checked=1 AND account_id = '" . $contact->id . "' AND deleted = 0";
$resulta = $db->query($sqla);
while ($row = $db->fetchByAssoc($resulta)) {
    $pdf = GeneratePresentation($row['realty_id']);
    $realty = new Realty();
    $realty->retrieve($row['realty_id']);
    /*require_once('custom/sms/sms.php');
      $sms = new sms();
      //$sms->parent_type = 'Users';
      $sms->retrieve_settings();
      //$sms->parent_id = $user->id;
      //$sms->pname = $user->full_name;
      //$type = ($bean->object_name == "Call")?"Вам назначен звонок ":"Вам назначена Встреча ";
 function parse_template_bean($string, $bean_name, &$focus)
 {
     global $current_user;
     global $beanFiles, $beanList;
     $repl_arr = array();
     // cn: bug 9277 - create a replace array with empty strings to blank-out invalid vars
     $acct = new Account();
     $contact = new Contact();
     $lead = new Lead();
     $prospect = new Prospect();
     foreach ($lead->field_defs as $field_def) {
         if ($field_def['type'] == 'relate' && empty($field_def['custom_type']) || $field_def['type'] == 'assigned_user_name') {
             continue;
         }
         $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('contact_' . $field_def['name'] => '', 'contact_account_' . $field_def['name'] => ''));
     }
     foreach ($prospect->field_defs as $field_def) {
         if ($field_def['type'] == 'relate' && empty($field_def['custom_type']) || $field_def['type'] == 'assigned_user_name') {
             continue;
         }
         $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('contact_' . $field_def['name'] => '', 'contact_account_' . $field_def['name'] => ''));
     }
     foreach ($contact->field_defs as $field_def) {
         if ($field_def['type'] == 'relate' && empty($field_def['custom_type']) || $field_def['type'] == 'assigned_user_name') {
             continue;
         }
         $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('contact_' . $field_def['name'] => '', 'contact_account_' . $field_def['name'] => ''));
     }
     foreach ($acct->field_defs as $field_def) {
         if ($field_def['type'] == 'relate' && empty($field_def['custom_type']) || $field_def['type'] == 'assigned_user_name') {
             continue;
         }
         $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('account_' . $field_def['name'] => '', 'account_contact_' . $field_def['name'] => ''));
     }
     // cn: end bug 9277 fix
     // feel for Parent account, only for Contacts traditionally, but written for future expansion
     if (isset($focus->account_id) && !empty($focus->account_id)) {
         $acct->retrieve($focus->account_id);
     }
     if ($bean_name == 'Contacts') {
         // cn: bug 9277 - email templates not loading account/opp info for templates
         if (!empty($acct->id)) {
             foreach ($acct->field_defs as $field_def) {
                 if ($field_def['type'] == 'relate' && empty($field_def['custom_type']) || $field_def['type'] == 'assigned_user_name') {
                     continue;
                 }
                 if ($field_def['type'] == 'enum') {
                     $translated = translate($field_def['options'], 'Accounts', $acct->{$field_def}['name']);
                     if (isset($translated) && !is_array($translated)) {
                         $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('account_' . $field_def['name'] => $translated, 'contact_account_' . $field_def['name'] => $translated));
                     } else {
                         // unset enum field, make sure we have a match string to replace with ""
                         $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('account_' . $field_def['name'] => '', 'contact_account_' . $field_def['name'] => ''));
                     }
                 } else {
                     // bug 47647 - allow for fields to translate before adding to template
                     $translated = self::_convertToType($field_def['type'], $acct->{$field_def}['name']);
                     $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('account_' . $field_def['name'] => $translated, 'contact_account_' . $field_def['name'] => $translated));
                 }
             }
         }
         if (!empty($focus->assigned_user_id)) {
             $user = new User();
             $user->retrieve($focus->assigned_user_id);
             $repl_arr = EmailTemplate::_parseUserValues($repl_arr, $user);
         }
     } elseif ($bean_name == 'Users') {
         /**
          * This section of code will on do work when a blank Contact, Lead,
          * etc. is passed in to parse the contact_* vars.  At this point,
          * $current_user will be used to fill in the blanks.
          */
         $repl_arr = EmailTemplate::_parseUserValues($repl_arr, $current_user);
     } else {
         // assumed we have an Account in focus
         foreach ($contact->field_defs as $field_def) {
             if ($field_def['type'] == 'relate' && empty($field_def['custom_type']) || $field_def['type'] == 'assigned_user_name' || $field_def['type'] == 'link') {
                 continue;
             }
             if ($field_def['type'] == 'enum') {
                 $translated = translate($field_def['options'], 'Accounts', $contact->{$field_def}['name']);
                 if (isset($translated) && !is_array($translated)) {
                     $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('contact_' . $field_def['name'] => $translated, 'contact_account_' . $field_def['name'] => $translated));
                 } else {
                     // unset enum field, make sure we have a match string to replace with ""
                     $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('contact_' . $field_def['name'] => '', 'contact_account_' . $field_def['name'] => ''));
                 }
             } else {
                 if (isset($contact->{$field_def}['name'])) {
                     // bug 47647 - allow for fields to translate before adding to template
                     $translated = self::_convertToType($field_def['type'], $contact->{$field_def}['name']);
                     $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array('contact_' . $field_def['name'] => $translated, 'contact_account_' . $field_def['name'] => $translated));
                 }
                 // if
             }
         }
     }
     ///////////////////////////////////////////////////////////////////////
     ////	LOAD FOCUS DATA INTO REPL_ARR
     foreach ($focus->field_defs as $field_def) {
         if (isset($focus->{$field_def}['name'])) {
             if ($field_def['type'] == 'relate' && empty($field_def['custom_type']) || $field_def['type'] == 'assigned_user_name') {
                 continue;
             }
             if ($field_def['type'] == 'enum' && isset($field_def['options'])) {
                 $translated = translate($field_def['options'], $bean_name, $focus->{$field_def}['name']);
                 if (isset($translated) && !is_array($translated)) {
                     $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array(strtolower($beanList[$bean_name]) . "_" . $field_def['name'] => $translated));
                 } else {
                     // unset enum field, make sure we have a match string to replace with ""
                     $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array(strtolower($beanList[$bean_name]) . "_" . $field_def['name'] => ''));
                 }
             } else {
                 // bug 47647 - translate currencies to appropriate values
                 $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array(strtolower($beanList[$bean_name]) . "_" . $field_def['name'] => self::_convertToType($field_def['type'], $focus->{$field_def}['name'])));
             }
         } else {
             if ($field_def['name'] == 'full_name') {
                 $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array(strtolower($beanList[$bean_name]) . '_full_name' => $focus->get_summary_text()));
             } else {
                 $repl_arr = EmailTemplate::add_replacement($repl_arr, $field_def, array(strtolower($beanList[$bean_name]) . "_" . $field_def['name'] => ''));
             }
         }
     }
     // end foreach()
     krsort($repl_arr);
     reset($repl_arr);
     //20595 add nl2br() to respect the multi-lines formatting
     if (isset($repl_arr['contact_primary_address_street'])) {
         $repl_arr['contact_primary_address_street'] = nl2br($repl_arr['contact_primary_address_street']);
     }
     if (isset($repl_arr['contact_alt_address_street'])) {
         $repl_arr['contact_alt_address_street'] = nl2br($repl_arr['contact_alt_address_street']);
     }
     foreach ($repl_arr as $name => $value) {
         if ($value != '' && is_string($value)) {
             $string = str_replace("\${$name}", $value, $string);
         } else {
             $string = str_replace("\${$name}", ' ', $string);
         }
     }
     return $string;
 }
Beispiel #16
0
 $class_name = $beanList[$_REQUEST['load_module']];
 require_once $beanFiles[$class_name];
 $contact = new $class_name();
 if ($contact->retrieve($_REQUEST['load_id'])) {
     $link_id = $class_name . '_id';
     $focus->{$link_id} = $_REQUEST['load_id'];
     $focus->contact_name = isset($contact->full_name) ? $contact->full_name : $contact->name;
     $focus->to_addrs_names = $focus->contact_name;
     $focus->to_addrs_ids = $_REQUEST['load_id'];
     //Retrieve the email address.
     //If Opportunity or Case then Oppurtinity/Case->Accounts->(email_addr_bean_rel->email_addresses)
     //If Contacts, Leads etc.. then Contact->(email_addr_bean_rel->email_addresses)
     $sugarEmailAddress = new SugarEmailAddress();
     if ($class_name == 'Opportunity' || $class_name == 'aCase') {
         $account = new Account();
         if ($contact->account_id != null && $account->retrieve($contact->account_id)) {
             $sugarEmailAddress->handleLegacyRetrieve($account);
             if (isset($account->email1)) {
                 $focus->to_addrs_emails = $account->email1;
                 $focus->to_addrs = "{$focus->contact_name} <{$account->email1}>";
             }
         }
     } else {
         $sugarEmailAddress->handleLegacyRetrieve($contact);
         if (isset($contact->email1)) {
             $focus->to_addrs_emails = $contact->email1;
             $focus->to_addrs = "{$focus->contact_name} <{$contact->email1}>";
         }
     }
     if (!empty($_REQUEST['parent_type']) && empty($app_list_strings['record_type_display'][$_REQUEST['parent_type']])) {
         if (!empty($app_list_strings['record_type_display'][$_REQUEST['load_module']])) {
require_once 'custom/include/fpdf17/fpdf.php';
require_once "custom/send_mail.php";
// require_once('custom/sms/sms.php');
require_once 'custom/Presentation/generate.php';
global $sugar_config, $db;
echo "<h3>Генерация презентации</h3><br/>";
$realty = new Realty();
$realty->retrieve($_GET['id']);
$pdf = GeneratePresentation($_GET['id']);
echo " <br/><b>Ссылка для скачивания презентации - <a href='{$pdf}'>{$pdf}</a></b><br/>";
$sql = "SELECT account_id FROM realty_accounts_m_to_m_table WHERE presentation_checked=1 AND realty_id = '{$_GET['id']}' AND deleted = 0";
$result = $db->query($sql);
while ($row = $db->fetchByAssoc($result)) {
    $emails = array();
    $account = new Account();
    $account->retrieve($row['account_id']);
    $assigned_user_id = $account->assigned_user_id;
    $ass = new User();
    $ass->retrieve($assigned_user_id);
    //----- сбор ответственных для аккаунтов
    //    $j = 0;
    //    $assigned['accounts'][$j]['email'] = $account->id;
    //    $assigned['accounts'][$j]['assigned_user_id'] = $account->assigned_user_id;
    //    $j++;
    // --------------------------------------
    /*$assigned_user_id = $account->assigned_user_id;
      $sms = new sms();
      $sms->retrieve_settings();
      $resp = $sms->send_message($ass->phone_mobile, 'Презентация отправлена');
      $resp = $sms->send_message($account->phone_office, 'Вам на почту отправлена презентация');*/
    /*$presentations = new Presentations();
 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));
                 }
             }
         }
     }
 }
         $xtpl->assign('FORMBODY', $oppForm->buildTableForm($duplicateOpps));
         $xtpl->parse('main.formnoborder');
         $xtpl->parse('main');
         $xtpl->out('main');
         return;
     }
 }
 if (!empty($_POST['selectedContact'])) {
     $contact = new Contact();
     $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'])) {
require_once 'modules/Quotes/Quote.php';
require_once 'modules/Accounts/Account.php';
require_once 'modules/Contacts/Contact.php';
require_once 'include/database/PearDatabase.php';
//require_once('include/Localization/Localization.php');
global $app_list_strings;
global $mod_strings;
$focus = new Quote();
$quote_id = $_REQUEST['record'];
$focus->retrieve($quote_id);
//$quote_id = $focus->quotenum;
$quote_title = $focus->name;
$quote_num = $focus->quotenum;
$account_id = $focus->account_id;
$account = new Account();
$account->retrieve($account_id);
$account_name = $account->name;
$phone = $account->phone_office . " / " . $account->phone_fax;
$contact_name = $focus->billtocontactname;
// Quote Information
$valid_till = $focus->validuntil;
$bill_street = $focus->billtoaddress;
$bill_city = $focus->billtocity;
$bill_state = $focus->billtostate;
$bill_code = $focus->billpostalcode;
$bill_country = $focus->billtocountry;
$ship_street = $account->shipping_address_street;
$ship_city = $account->shipping_address_city;
$ship_state = $account->shipping_address_state;
$ship_code = $account->shipping_address_postalcode;
$ship_country = $account->shipping_address_country;
 /**
  * @expectedException Stripe\Error\Permission
  */
 public function testPermission()
 {
     $this->mockRequest('GET', '/v1/accounts/acct_DEF', array(), $this->permissionErrorResponse(), 403);
     Account::retrieve('acct_DEF');
 }
Beispiel #22
0
<?php

$Accounts = new Account();
$accounts_id = $_REQUEST['parent_record_id'];
$realty_id = $_REQUEST['id_record'];
$Accounts->retrieve($accounts_id);
$Accounts->load_relationships('realty_accounts_interest');
$Accounts->realty_accounts_interest->add($realty_id);
function add_create_account($seed)
{
    global $current_user;
    $account_name = $seed->account_name;
    $account_id = $seed->account_id;
    $assigned_user_id = $current_user->id;
    // check if it already exists
    $focus = new Account();
    if ($focus->ACLAccess('Save')) {
        $class = get_class($seed);
        $temp = new $class();
        $temp->retrieve($seed->id);
        if (!isset($account_name) || $account_name == '') {
            return;
        }
        if (!isset($seed->accounts)) {
            $seed->load_relationship('accounts');
        }
        if ($seed->account_name == '' && isset($temp->account_id)) {
            $seed->accounts->delete($seed->id, $temp->account_id);
            return;
        }
        // attempt to find by id first
        $ret = $focus->retrieve($account_id, true, false);
        // if it doesn't exist by id, attempt to find by name (non-deleted)
        if (empty($ret)) {
            $query = "select {$focus->table_name}.id, {$focus->table_name}.deleted from {$focus->table_name} ";
            $query .= " WHERE name='" . $seed->db->quote($account_name) . "'";
            $query .= " ORDER BY deleted ASC";
            $result = $seed->db->query($query, true);
            $row = $seed->db->fetchByAssoc($result, false);
            if (!empty($row['id'])) {
                $focus->retrieve($row['id']);
            }
        } else {
            if ($focus->deleted) {
                $query2 = "delete from {$focus->table_name} WHERE id='" . $seed->db->quote($focus->id) . "'";
                $seed->db->query($query2, true);
                // it was deleted, create new
                $focus = BeanFactory::newBean('Accounts');
            }
        }
        // if we didnt find the account, so create it
        if (empty($focus->id)) {
            $focus->name = $account_name;
            if (isset($assigned_user_id)) {
                $focus->assigned_user_id = $assigned_user_id;
                $focus->modified_user_id = $assigned_user_id;
            }
            $focus->save();
        }
        if ($seed->accounts != null && $temp->account_id != null && $temp->account_id != $focus->id) {
            $seed->accounts->delete($seed->id, $temp->account_id);
        }
        if (isset($focus->id) && $focus->id != '') {
            $seed->account_id = $focus->id;
        }
    }
}
 /**
  * @expectedException Stripe\Error\RateLimit
  */
 public function testRateLimit()
 {
     $this->mockRequest('GET', '/v1/accounts/acct_DEF', array(), $this->rateLimitErrorResponse(), 429);
     Account::retrieve('acct_DEF');
 }
Beispiel #25
0
 public function testIDRetrieve()
 {
     $this->mockRequest('GET', '/v1/accounts/acct_DEF', array(), $this->managedAccountResponse('acct_DEF'));
     $account = Account::retrieve('acct_DEF');
     $this->assertSame($account->id, 'acct_DEF');
 }
Beispiel #26
0
 /**
  * @group 53223
  */
 public function testOneToManyRelationshipModule2Modult()
 {
     $_REQUEST['relate_id'] = $this->parentAccount->id;
     $_REQUEST['relate_to'] = $this->relationship->getName();
     // create new account
     $objAccount = new Account();
     $objAccount->name = "AccountBug53223" . $_REQUEST['relate_to'] . time();
     $objAccount->save();
     SugarTestAccountUtilities::setCreatedAccount(array($objAccount->id));
     // Retrieve new data
     $this->parentAccount->retrieve($this->parentAccount->id);
     $objAccount->retrieve($objAccount->id);
     $this->parentAccount->load_relationship($this->relationship->getName());
     $objAccount->load_relationship($this->relationship->getName());
     // Getting data of subpanel of parent bean
     $_REQUEST['module'] = 'Accounts';
     $_REQUEST['action'] = 'DetailView';
     $_REQUEST['record'] = $this->parentAccount->id;
     $_SERVER['REQUEST_METHOD'] = 'GET';
     unset($GLOBALS['focus']);
     $subpanels = new SubPanelDefinitions($this->parentAccount, 'Accounts');
     $subpanelDef = $subpanels->load_subpanel($this->relationship->getName() . 'accounts_ida');
     $subpanel = new SubPanel('Accounts', $this->parentAccount->id, 'default', $subpanelDef);
     $subpanel->setTemplateFile('include/SubPanel/SubPanelDynamic.html');
     $subpanel->display();
     $actual = $this->getActualOutput();
     $this->assertContains($objAccount->name, $actual, 'Account name is not displayed in subpanel of parent account');
     ob_clean();
     // Getting data of subpanel of child bean
     $_REQUEST['module'] = 'Accounts';
     $_REQUEST['action'] = 'DetailView';
     $_REQUEST['record'] = $objAccount->id;
     $_SERVER['REQUEST_METHOD'] = 'GET';
     unset($GLOBALS['focus']);
     $subpanels = new SubPanelDefinitions($objAccount, 'Accounts');
     $subpanelDef = $subpanels->load_subpanel($this->relationship->getName() . 'accounts_ida');
     $subpanel = new SubPanel('Accounts', $objAccount->id, 'default', $subpanelDef);
     $subpanel->setTemplateFile('include/SubPanel/SubPanelDynamic.html');
     $subpanel->display();
     $actual = $this->getActualOutput();
     $this->assertNotContains($this->parentAccount->name, $actual, 'Parent account name is displayed in subpanel of child aaccount');
 }
 *    (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:  Deletes an Account record and then redirects the browser to the 
 * defined return URL.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
require_once 'modules/Accounts/Account.php';
global $mod_strings;
$focus = new Account();
if (!isset($_REQUEST['record'])) {
    sugar_die($mod_strings['ERR_DELETE_RECORD']);
}
$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 SendToERP($bean)
 {
     if ($bean->sales_stage === "Closed Won" && $bean->sales_stage != $bean->fetched_row['sales_stage']) {
         $account = new Account();
         if (!is_null($account->retrieve($bean->account_id))) {
             $url = "<your-erp-rest-url>";
             $fields = array('account_id' => $account->id, 'account_name' => $account->name, 'opportunity_id' => $bean->id, 'opportunity_name' => $bean->name, 'opportunity_amount' => $bean->amount);
             $curl = curl_init($url);
             curl_setopt($curl, CURLOPT_POST, true);
             curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
             $response = curl_exec($curl);
             SugarApplication::appendErrorMessage('The Opportunity ' . $bean->name . ' has been sent to ERP');
         }
     }
 }
 function handleCreateCase($email, $userId)
 {
     global $current_user, $mod_strings, $current_language;
     $mod_strings = return_module_language($current_language, "Emails");
     $GLOBALS['log']->debug('In handleCreateCase');
     $c = new aCase();
     $this->getCaseIdFromCaseNumber($email->name, $c);
     if (!$this->handleCaseAssignment($email) && $this->isMailBoxTypeCreateCase()) {
         // create a case
         $GLOBALS['log']->debug('retrieveing email');
         $email->retrieve($email->id);
         $c = new aCase();
         $c->description = $email->description;
         $c->assigned_user_id = $userId;
         $c->name = $email->name;
         $c->status = 'New';
         $c->priority = 'P1';
         if (!empty($email->reply_to_email)) {
             $contactAddr = $email->reply_to_email;
         } else {
             $contactAddr = $email->from_addr;
         }
         $GLOBALS['log']->debug('finding related accounts with address ' . $contactAddr);
         if ($accountIds = $this->getRelatedId($contactAddr, 'accounts')) {
             if (sizeof($accountIds) == 1) {
                 $c->account_id = $accountIds[0];
                 $acct = new Account();
                 $acct->retrieve($c->account_id);
                 $c->account_name = $acct->name;
             }
             // if
         }
         // if
         $c->save(true);
         $caseId = $c->id;
         $c = new aCase();
         $c->retrieve($caseId);
         if ($c->load_relationship('emails')) {
             $c->emails->add($email->id);
         }
         // if
         if ($contactIds = $this->getRelatedId($contactAddr, 'contacts')) {
             if (!empty($contactIds) && $c->load_relationship('contacts')) {
                 $c->contacts->add($contactIds);
             }
             // if
         }
         // if
         $c->email_id = $email->id;
         $email->parent_type = "Cases";
         $email->parent_id = $caseId;
         // assign the email to the case owner
         $email->assigned_user_id = $c->assigned_user_id;
         $email->name = str_replace('%1', $c->case_number, $c->getEmailSubjectMacro()) . " " . $email->name;
         $email->save();
         $GLOBALS['log']->debug('InboundEmail created one case with number: ' . $c->case_number);
         $createCaseTemplateId = $this->get_stored_options('create_case_email_template', "");
         if (!empty($this->stored_options)) {
             $storedOptions = unserialize(base64_decode($this->stored_options));
         }
         if (!empty($createCaseTemplateId)) {
             $fromName = "";
             $fromAddress = "";
             if (!empty($this->stored_options)) {
                 $fromAddress = $storedOptions['from_addr'];
                 $fromName = from_html($storedOptions['from_name']);
                 $replyToName = !empty($storedOptions['reply_to_name']) ? from_html($storedOptions['reply_to_name']) : $fromName;
                 $replyToAddr = !empty($storedOptions['reply_to_addr']) ? $storedOptions['reply_to_addr'] : $fromAddress;
             }
             // if
             $defaults = $current_user->getPreferredEmail();
             $fromAddress = !empty($fromAddress) ? $fromAddress : $defaults['email'];
             $fromName = !empty($fromName) ? $fromName : $defaults['name'];
             $to[0]['email'] = $contactAddr;
             // handle to name: address, prefer reply-to
             if (!empty($email->reply_to_name)) {
                 $to[0]['display'] = $email->reply_to_name;
             } elseif (!empty($email->from_name)) {
                 $to[0]['display'] = $email->from_name;
             }
             $et = new EmailTemplate();
             $et->retrieve($createCaseTemplateId);
             if (empty($et->subject)) {
                 $et->subject = '';
             }
             if (empty($et->body)) {
                 $et->body = '';
             }
             if (empty($et->body_html)) {
                 $et->body_html = '';
             }
             $et->subject = "Re:" . " " . str_replace('%1', $c->case_number, $c->getEmailSubjectMacro() . " " . $c->name);
             $html = trim($email->description_html);
             $plain = trim($email->description);
             $email->email2init();
             $email->from_addr = $email->from_addr_name;
             $email->to_addrs = $email->to_addrs_names;
             $email->cc_addrs = $email->cc_addrs_names;
             $email->bcc_addrs = $email->bcc_addrs_names;
             $email->from_name = $email->from_addr;
             $email = $email->et->handleReplyType($email, "reply");
             $ret = $email->et->displayComposeEmail($email);
             $ret['description'] = empty($email->description_html) ? str_replace("\n", "\n<BR/>", $email->description) : $email->description_html;
             $reply = new Email();
             $reply->type = 'out';
             $reply->to_addrs = $to[0]['email'];
             $reply->to_addrs_arr = $to;
             $reply->cc_addrs_arr = array();
             $reply->bcc_addrs_arr = array();
             $reply->from_name = $fromName;
             $reply->from_addr = $fromAddress;
             $reply->reply_to_name = $replyToName;
             $reply->reply_to_addr = $replyToAddr;
             $reply->name = $et->subject;
             $reply->description = $et->body . "<div><hr /></div>" . $email->description;
             if (!$et->text_only) {
                 $reply->description_html = $et->body_html . "<div><hr /></div>" . $email->description;
             }
             $GLOBALS['log']->debug('saving and sending auto-reply email');
             //$reply->save(); // don't save the actual email.
             $reply->send();
         }
         // if
     } else {
         if (!empty($email->reply_to_email)) {
             $contactAddr = $email->reply_to_email;
         } else {
             $contactAddr = $email->from_addr;
         }
         $this->handleAutoresponse($email, $contactAddr);
     }
 }
 public function testJobUsers()
 {
     $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
     $user1 = SugarTestUserUtilities::createAnonymousUser();
     $user2 = SugarTestUserUtilities::createAnonymousUser();
     $job = $this->createJob(array("name" => "Test User 1", "status" => SchedulersJob::JOB_STATUS_RUNNING, "assigned_user_id" => $user1->id, "target" => "function::SchedulersJobsTest::staticJobFunctionAccount", "data" => "useracc1"));
     $job->runJob();
     $job->retrieve($job->id);
     $this->assertEquals(SchedulersJob::JOB_SUCCESS, $job->resolution, "Wrong resolution");
     $this->assertEquals(SchedulersJob::JOB_STATUS_DONE, $job->status, "Wrong status");
     $job = $this->createJob(array("name" => "Test User 2", "status" => SchedulersJob::JOB_STATUS_RUNNING, "assigned_user_id" => $user2->id, "target" => "function::SchedulersJobsTest::staticJobFunctionAccount", "data" => "useracc2"));
     $job->runJob();
     $job->retrieve($job->id);
     $this->assertEquals(SchedulersJob::JOB_SUCCESS, $job->resolution, "Wrong resolution");
     $this->assertEquals(SchedulersJob::JOB_STATUS_DONE, $job->status, "Wrong status");
     $a1 = new Account();
     $a1->retrieve('useracc1');
     $this->assertEquals($user1->id, $a1->created_by, "Wrong creating user ID for account 1");
     $a2 = new Account();
     $a2->retrieve('useracc2');
     $this->assertEquals($user2->id, $a2->created_by, "Wrong creating user ID for account 2");
 }