Esempio n. 1
0
        } else {
            if (strpos($k, 'UF_') !== 0 && $k != 'LOGIC') {
                $arFilter['%' . $k] = $v;
                unset($arFilter[$k]);
            }
        }
    }
}
$obRes = CCrmDeal::GetListEx(array(), $arFilter, false, false, array('ID', 'TITLE', 'STAGE_ID', 'OPPORTUNITY', 'CURRENCY_ID'));
$arResult['DEAL'] = array();
$arResult['STAGE_COUNT'] = array();
$arResult['FUNNEL'] = array();
$iDealCount = 0;
while ($arDeal = $obRes->GetNext()) {
    //Normalizing for compatibility
    $currencyID = CCrmCurrency::NormalizeCurrencyID($arDeal['CURRENCY_ID']);
    $stageID = $arDeal['STAGE_ID'];
    $opportunity = (double) $arDeal['OPPORTUNITY'];
    if (!isset($arResult['STAGE_COUNT'][$stageID])) {
        $arResult['STAGE_COUNT'][$stageID]['COUNT'] = 1;
        $arResult['STAGE_COUNT'][$stageID]['COUNT_FUNNEL'] = 1;
        $arResult['STAGE_COUNT'][$stageID]['OPPORTUNITY'] = array($currencyID => $opportunity);
        $arResult['STAGE_COUNT'][$stageID]['OPPORTUNITY_FUNNEL'] = array($currencyID => $opportunity);
    } else {
        $arResult['STAGE_COUNT'][$stageID]['COUNT']++;
        $arResult['STAGE_COUNT'][$stageID]['COUNT_FUNNEL']++;
        if (!isset($arResult['STAGE_COUNT'][$stageID]['OPPORTUNITY'][$currencyID])) {
            $arResult['STAGE_COUNT'][$stageID]['OPPORTUNITY'][$currencyID] = 0;
        }
        $arResult['STAGE_COUNT'][$stageID]['OPPORTUNITY'][$currencyID] += $opportunity;
        if (!isset($arResult['STAGE_COUNT'][$stageID]['OPPORTUNITY_FUNNEL'][$currencyID])) {