protected function fixRollupFormulas() { $oldFormula = 'rollupCurrencySum($revenuelineitems, "{{field}}")'; $newFormula = 'rollupConditionalSum($revenuelineitems, "{{field}}", "sales_stage", forecastSalesStages(true, false))'; // the field set we need $fields = array('best_case' => 'best_case', 'amount' => 'likely_case', 'worst_case' => 'worst_case'); // get the get_widget helper and the StandardField Helper SugarAutoLoader::load('modules/DynamicFields/FieldCases.php'); SugarAutoLoader::load('modules/ModuleBuilder/parsers/StandardField.php'); // we are working with opportunities $bean = BeanFactory::getBean('Opportunities'); // loop over each field foreach ($fields as $field => $rollup_field) { // get the field defs $field_defs = $bean->getFieldDefinition($field); // load the field type up $f = get_widget($field_defs['type']); // populate the row from the vardefs that were loaded $f->populateFromRow($field_defs); if ($f->formula == str_replace('{{field}}', $rollup_field, $oldFormula)) { $f->formula = str_replace('{{field}}', $rollup_field, $newFormula); // now lets save, since these are OOB field, we use StandardField $df = new StandardField($bean->module_name); $df->setup($bean); $f->module = $bean; $f->save($df); } } // lets fix up the data now to excluded closed lost $this->fixRollupAmountsToExcludeClosedLostValues(); }
/** * Method to get Localization object * * @return Localization */ public static function getObject() { $class = __CLASS__; if (SugarAutoLoader::load('custom/include/Localization/Localization.php')) { $class = SugarAutoLoader::customClass($class); } return new $class(); }
public function run() { // get the opportunity settings $settings = Opportunity::getSettings(); // if this key is not setup, then there is a 99.99% chance that it has never been set, // so it should be setup. if (!isset($settings['opps_view_by']) || empty($settings['opps_view_by'])) { SugarAutoLoader::load('modules/Opportunities/OpportunitiesDefaults.php'); OpportunitiesDefaults::setupOpportunitiesSettings(); // reload the settings now Opportunity::getSettings(true); } }
/** * @param string $data The job data set for this particular Scheduled Job instance * @return boolean true if the run succeeded; false otherwise */ public function run($data) { $settings = Opportunity::getSettings(); if (isset($settings['opps_view_by']) && $settings['opps_view_by'] !== 'RevenueLineItems') { $GLOBALS['log']->fatal("Opportunity are not being used with Revenue Line Items. " . __CLASS__ . " should not be running"); return false; } $args = json_decode(html_entity_decode($data), true); $this->job->runnable_ran = true; // use the processWorksheetDataChunk to run the code. SugarAutoLoader::load('modules/Opportunities/include/OpportunityWithRevenueLineItem.php'); OpportunityWithRevenueLineItem::processOpportunityIds($args['data']); $this->job->succeedJob(); $this->notifyAssignedUser(); return true; }
public function preDisplay() { if (session_id()) { // kill old session session_destroy(); } SugarAutoLoader::load('custom/include/RestService.php'); $restServiceClass = SugarAutoLoader::customClass('RestService'); $service = new $restServiceClass(); SugarOAuth2Server::getOAuth2Server(); // to load necessary classes SugarAutoLoader::requireWithCustom('clients/base/api/OAuth2Api.php'); $oapiClassName = SugarAutoLoader::customClass('OAuth2Api'); $oapi = new $oapiClassName(); $args = $_REQUEST; $args['client_id'] = 'sugar'; $args['client_secret'] = ''; if (!empty($_REQUEST['SAMLResponse'])) { $args['grant_type'] = SugarOAuth2Storage::SAML_GRANT_TYPE; $args['assertion'] = $_REQUEST['SAMLResponse']; } else { if (empty($args['grant_type'])) { $args['grant_type'] = OAuth2::GRANT_TYPE_USER_CREDENTIALS; if (!empty($args['user_name']) && isset($args['user_password'])) { // old-style login, let's translate it $args['username'] = $args['user_name']; $args['password'] = $args['user_password']; } } } try { $this->authorization = $oapi->token($service, $args); } catch (Exception $e) { $GLOBALS['log']->error("Login exception: " . $e->getMessage()); sugar_die($e->getMessage()); } if (!empty($_REQUEST['dataOnly'])) { $this->dataOnly = true; } if (!empty($_REQUEST['platform'])) { $this->platform = $_REQUEST['platform']; } parent::preDisplay(); }
public function run() { if (version_compare($this->from_version, '7.2', '<')) { $sql = "SELECT d.dashboard_module,\n d.view_name,\n d.assigned_user_id,\n (SELECT d1.dashboard_type\n FROM dashboards AS d1\n WHERE d1.dashboard_module = d.dashboard_module\n AND d1.view_name = d.view_name\n AND d1.assigned_user_id = d.assigned_user_id\n AND d1.dashboard_type = 'help-dashboard') as has_help_dashboard\n FROM dashboards AS d\n GROUP BY d.assigned_user_id,\n d.dashboard_module,\n d.view_name;"; $results = $this->db->query($sql); // get the view defs from the help-dashboard.php file if it exists $viewdefs = array(); if (SugarAutoLoader::load('clients/base/layouts/help-dashboard/help-dashboard.php') && isset($viewdefs['base']['layout']['help-dashboard']['metadata'])) { $helpDashboardMeta = json_encode($viewdefs['base']['layout']['help-dashboard']['metadata']); } else { $helpDashboardMeta = '{"components":[{"rows":[[{"view":{"type":"help-dashlet","label":"LBL_DEFAULT_HELP_DASHLET_TITLE"},"width":12}]],"width":12}]}'; } while ($row = $this->db->fetchByAssoc($results)) { if (!empty($row['has_help_dashboard'])) { continue; } $sqlInsert = "INSERT INTO dashboards (id, name, date_entered, date_modified, modified_user_id, created_by,\n description, deleted, assigned_user_id, dashboard_module, view_name, metadata, dashboard_type)\n VALUES\n ('" . create_guid() . "', 'LBL_DEFAULT_HELP_DASHLET_TITLE',\n '" . $GLOBALS['timedate']->nowDb() . "', '" . $GLOBALS['timedate']->nowDb() . "',\n '" . $row['assigned_user_id'] . "', '" . $row['assigned_user_id'] . "', NULL, 0,\n '" . $row['assigned_user_id'] . "', '" . $row['dashboard_module'] . "', '" . $row['view_name'] . "',\n '" . $helpDashboardMeta . "', 'help-dashboard');"; $this->db->query($sqlInsert); } } }
public function runRebuildExtensions(array $modules = array('Forecasts')) { SugarAutoLoader::load('modules/Administration/QuickRepairAndRebuild.php'); $rac = new RepairAndClear(); $rac->show_output = false; $rac->module_list = $modules; $rac->clearVardefs(); $rac->rebuildExtensions($modules); }
/** * Fix the Opportunity Data to have the correct data once we go back from having RLI's to only have Opps * * - Takes the lowest sales_stage from all the RLIs * - Takes the lowest date_closed from all the RLIs * - Sets commit_stage to empty * - Sets sales_status to empty * * This is all done via a Query since we delete all the RLI's and we didn't want to keep any of them around. * * @throws SugarQueryException */ protected function setOpportunityDataFromRevenueLineItems() { // need to figure out the best way to roll this up before truncating the table. $app_list_strings = return_app_list_strings_language($GLOBALS['current_language']); // get the sales_stage from the RLI module /* @var $rli RevenueLineItem */ $rli = BeanFactory::getBean('RevenueLineItems'); $def = $rli->getFieldDefinition('sales_stage'); $db = DBManagerFactory::getInstance(); $list_value = array(); // get the `options` param so we make sure if they customized it to use their custom version $sqlCase = ''; $list = $def['options']; if (!empty($list) && isset($app_list_strings[$list])) { $i = 0; $order_by_arr = array(); foreach ($app_list_strings[$list] as $key => $value) { $list_value[$i] = $key; if ($key == '') { $order_by_arr[] = "WHEN (sales_stage='' OR sales_stage IS NULL) THEN " . $i++; } else { $order_by_arr[] = "WHEN sales_stage=" . $db->quoted($key) . " THEN " . $i++; } } $sqlCase = "min(CASE " . implode("\n", $order_by_arr) . " ELSE {$i} END)"; } $fcsettings = Forecast::getSettings(); $stage_cases = array(); $closed_stages = array_merge($fcsettings['sales_stage_won'], $fcsettings['sales_stage_lost']); foreach ($closed_stages as $stage) { $stage_cases[] = $db->quoted($stage); } $stage_cases = implode(',', $stage_cases); $sq = new SugarQuery(); $sq->select(array('opportunity_id'))->fieldRaw($sqlCase, 'sales_stage')->fieldRaw($this->dateClosedMigration . '(CASE when sales_stage IN (' . $stage_cases . ') THEN date_closed END)', 'dc_closed')->fieldRaw($this->dateClosedMigration . '(CASE when sales_stage NOT IN (' . $stage_cases . ') THEN date_closed END)', 'dc_open')->fieldRaw($this->dateClosedMigration . '(CASE when sales_stage IN (' . $stage_cases . ') THEN date_closed_timestamp END)', 'dct_closed')->fieldRaw($this->dateClosedMigration . '(CASE when sales_stage NOT IN (' . $stage_cases . ') THEN date_closed_timestamp END)', 'dct_open'); $sq->from($rli); $sq->groupBy('opportunity_id'); $results = $sq->execute(); foreach ($results as $result) { $sql = 'UPDATE opportunities SET date_closed = ' . $db->quoted(!empty($result['dc_open']) ? $result['dc_open'] : $result['dc_closed']) . ', date_closed_timestamp = ' . $db->quoted(!empty($result['dct_open']) ? $result['dct_open'] : $result['dct_closed']) . ', sales_stage = ' . $db->quoted($list_value[$result['sales_stage']]) . ', probability = ' . $db->quoted($app_list_strings['sales_probability_dom'][$list_value[$result['sales_stage']]]) . ', sales_status = ' . $db->quoted('') . ', commit_stage = ' . $db->quoted('') . ' WHERE id = ' . $db->quoted($result['opportunity_id']); $db->query($sql); } if ($this->isForecastSetup()) { SugarAutoLoader::load('include/SugarQueue/jobs/SugarJobUpdateOpportunities.php'); SugarJobUpdateOpportunities::updateOpportunitiesForForecasting(); } }
public function __construct() { SugarAutoLoader::load('modules/ModuleBuilder/parsers/ParserFactory.php'); $this->bean = BeanFactory::getBean('Opportunities'); }
/** * This is left here for legacy, just calling the new methods * @deprecated * @param int $perJob The Number of records to put in a job * @return array|string An array of jobs ids that were created, unless * there is one, the it's just that single job id */ function updateOpportunitiesForForecasting($perJob = 100) { SugarAutoLoader::load('include/SugarQueue/jobs/SugarJobUpdateOpportunities.php'); return SugarJobUpdateOpportunities::updateOpportunitiesForForecasting($perJob); }
/** * @param ServiceBase $api * @param $worksheetColumns */ public function setWorksheetColumns(ServiceBase $api, $worksheetColumns, $forecastBy) { SugarAutoLoader::load('modules/Forecasts/include/ForecastReset.php'); $fr = new ForecastReset(); $fr->updateConfigWorksheetColumnsMetadata($forecastBy); $fr->setWorksheetColumns($api->platform, $worksheetColumns, $forecastBy); }
protected function toggleRevenueLineItemQuickCreate($enable = false) { SugarAutoLoader::load('modules/Administration/views/view.configureshortcutbar.php'); $cscb = new ViewConfigureshortcutbar(); $modules = $cscb->getQuickCreateModules(); $enModules = array(); foreach ($modules['enabled'] as $module => $def) { $enModules[$module] = $def['order']; } $hasRLI = isset($enModules['RevenueLineItems']); if ($enable === true && $hasRLI === false) { $enModules['RevenueLineItems'] = count($enModules); } elseif ($enable === false && $hasRLI === true) { unset($enModules['RevenueLineItems']); } else { return; } $cscb->saveChangesToQuickCreateMetadata($modules['enabled'], $modules['disabled'], $enModules); }
<?php if (!defined('sugarEntry')) { define('sugarEntry', true); } /* * Your installation or use of this SugarCRM file is subject to the applicable * terms available at * http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/. * If you do not agree to all of the applicable terms or do not have the * authority to bind the entity as an authorized representative, then do not * install or use this SugarCRM file. * * Copyright (C) SugarCRM Inc. All rights reserved. */ ob_start(); chdir(dirname(__FILE__) . '/../'); define('ENTRY_POINT_TYPE', 'api'); require 'include/entryPoint.php'; require_once "include/api/RestService.php"; SugarAutoLoader::load('custom/include/RestService.php'); $restServiceClass = SugarAutoLoader::customClass('RestService'); global $service; $service = new $restServiceClass(); $service->execute();
/** * Call this method to convert the data as well, this should be called after `doMetadataConvert` */ public function doDataConvert() { $this->resetForecastData('RevenueLineItems'); // fix the reports SugarAutoLoader::load('modules/Opportunities/include/OpportunityReports.php'); $reports = new OpportunityReports(); $reports->migrateToRevenueLineItems(); $this->createRevenueLineItems(); }
/** * Actually do the work of assigning a quota from the worksheets * * @param string $quota The amount of the quota * @param string $type What type is the quota * @param string $user_id Who is the quota for * @param string $timeperiod_id What timeperiod is the quota for * @param bool $disableActivityStream Should we disable activity streams and create our own entry */ protected function _assignQuota($quota, $type, $user_id, $timeperiod_id, $disableActivityStream = false) { if ($disableActivityStream) { Activity::disable(); $current_quota = $this->getQuota($user_id, $timeperiod_id, $type); } // get the updated quota back, this is needed because current_quota might be empty // as it could very well not exist yet. $quota = $this->commitQuota($quota, $user_id, $timeperiod_id, $type); $new_quota = $this->recalcQuotas($user_id, $timeperiod_id, true); if ($disableActivityStream) { Activity::enable(); if ($new_quota !== $current_quota->amount) { $args = array('isUpdate' => !empty($current_quota->amount), 'dataChanges' => array('amount' => array('field_name' => 'amount', 'field_type' => 'currency', 'before' => $current_quota->amount, 'after' => $new_quota))); // Manually Create the Activity Stream Entry! SugarAutoLoader::load('modules/ActivityStream/Activities/ActivityQueueManager.php'); $aqm = new ActivityQueueManager(); $aqm->eventDispatcher($quota, 'after_save', $args); } } }