Exemplo n.º 1
0
 public static function IsProductInDeal($dealID, $productID)
 {
     $res = 0;
     $ar = CCrmProductRow::LoadRows('D', $dealID);
     foreach ($ar as $kk => $vv) {
         if ($vv['PRODUCT_ID'] == $productID) {
             $res = 1;
             break;
         }
     }
     return $res;
 }
Exemplo n.º 2
0
    }
    unset($productRow);
    $arResult['FORMATTED_SUM'] = CCrmCurrency::MoneyToString($arResult['SUM'], $arResult['CURRENCY_ID']);
} elseif ($entityTypeID === CCrmOwnerType::Lead) {
    $dbRes = CCrmLead::GetListEx(array(), array('ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('TITLE', 'CURRENCY_ID', 'OPPORTUNITY'));
    $arOwner = $dbRes ? $dbRes->Fetch() : null;
    if ($arOwner) {
        $arResult['TITLE'] = isset($arOwner['TITLE']) ? $arOwner['TITLE'] : '';
        $arResult['CURRENCY_ID'] = isset($arOwner['CURRENCY_ID']) ? $arOwner['CURRENCY_ID'] : CCrmCurrency::GetBaseCurrencyID();
        $arResult['SUM'] = isset($arOwner['OPPORTUNITY']) ? $arOwner['OPPORTUNITY'] : 0.0;
    } else {
        $arResult['TITLE'] = '';
        $arResult['CURRENCY_ID'] = CCrmCurrency::GetBaseCurrencyID();
        $arResult['SUM'] = 0.0;
    }
    $productRows = CCrmProductRow::LoadRows(CCrmOwnerTypeAbbr::Lead, $entityID);
    foreach ($productRows as &$productRow) {
        $productRow['FORMATTED_PRICE'] = CCrmCurrency::MoneyToString($productRow['PRICE'], $arResult['CURRENCY_ID']);
        $arResult['ITEMS'][] = $productRow;
    }
    unset($productRow);
    $arResult['FORMATTED_SUM'] = CCrmCurrency::MoneyToString($arResult['SUM'], $arResult['CURRENCY_ID']);
} elseif ($entityTypeID === CCrmOwnerType::Invoice) {
    $dbRes = CCrmInvoice::GetList(array(), array('ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ORDER_TOPIC', 'CURRENCY', 'PRICE', 'TAX_VALUE'));
    $arOwner = $dbRes ? $dbRes->Fetch() : null;
    if ($arOwner) {
        $arResult['TITLE'] = isset($arOwner['ORDER_TOPIC']) ? $arOwner['ORDER_TOPIC'] : '';
        $arResult['CURRENCY_ID'] = isset($arOwner['CURRENCY']) ? $arOwner['CURRENCY'] : CCrmCurrency::GetBaseCurrencyID();
        $arResult['SUM'] = isset($arOwner['PRICE']) ? round(doubleval($arOwner['PRICE']), 2) : 0.0;
        $arResult['TAX_SUM'] = isset($arOwner['TAX_VALUE']) ? round(doubleval($arOwner['TAX_VALUE']), 2) : 0.0;
    } else {
Exemplo n.º 3
0
        ShowError(GetMessage('CRM_LEAD_EDIT_NOT_FOUND', array('#ID#' => $arParams['ENTITY_ID'])));
        return;
    }
    $arFields['FM'] = array();
    $dbMultiFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'LEAD', 'ELEMENT_ID' => $entityID));
    if ($dbMultiFields) {
        while ($arMultiField = $dbMultiFields->Fetch()) {
            $arFields['FM'][$arMultiField['TYPE_ID']][$arMultiField['ID']] = array('VALUE' => $arMultiField['VALUE'], 'VALUE_TYPE' => $arMultiField['VALUE_TYPE']);
        }
    }
    CCrmMobileHelper::PrepareLeadItem($arFields, $arParams, array('STATUS_LIST' => $arResult['STATUS_LIST'], 'SOURCE_LIST' => $arResult['SOURCE_LIST']));
}
$currencyID = $arFields['~CURRENCY_ID'];
$arResult['ENTITY'] = $arFields;
unset($arFields);
$arResult['PRODUCT_ROWS'] = $entityID > 0 ? CCrmProductRow::LoadRows('L', $entityID) : array();
foreach ($arResult['PRODUCT_ROWS'] as &$productRow) {
    $price = isset($productRow['PRICE']) ? doubleval($productRow['PRICE']) : 0.0;
    $qty = isset($productRow['QUANTITY']) ? doubleval($productRow['QUANTITY']) : 0;
    $sum = $productRow['SUM'] = $price * $qty;
    $productRow['FORMATTED_PRICE'] = CCrmCurrency::MoneyToString($price, $currencyID);
    $productRow['FORMATTED_SUM'] = CCrmCurrency::MoneyToString($sum, $currencyID);
    $productRow['CURRENCY_ID'] = $currencyID;
}
unset($productRow);
$sid = bitrix_sessid();
$serviceURLTemplate = $arParams["SERVICE_URL_TEMPLATE"] ? $arParams["SERVICE_URL_TEMPLATE"] : '#SITE_DIR#bitrix/components/bitrix/mobile.crm.lead.edit/ajax.php?site_id=#SITE#&sessid=#SID#';
$arResult['SERVICE_URL'] = CComponentEngine::makePathFromTemplate($serviceURLTemplate, array('SID' => $sid));
$productRowServiceURLTemplate = $arParams["PRODUCT_ROW_URL_TEMPLATE"] ? $arParams["PRODUCT_ROW_URL_TEMPLATE"] : '#SITE_DIR#bitrix/components/bitrix/mobile.crm.product_row.edit/ajax.php?site_id=#SITE#&sessid=#SID#';
$arResult['PRODUCT_ROW_SERVICE_URL'] = CComponentEngine::makePathFromTemplate($productRowServiceURLTemplate, array('SID' => $sid));
$arResult['STATUS_SELECTOR_URL'] = CComponentEngine::makePathFromTemplate($arParams['STATUS_SELECTOR_URL_TEMPLATE'], array('type_id' => 'STATUS', 'context_id' => $contextID));
Exemplo n.º 4
0
 public static function LoadProductRows($ID)
 {
     return CCrmProductRow::LoadRows(self::OWNER_TYPE, $ID);
 }
Exemplo n.º 5
0
 public static function OnAccountCurrencyChange()
 {
     $accountCurrencyID = CCrmCurrency::GetAccountCurrencyID();
     if (!isset($accountCurrencyID[0])) {
         return;
     }
     $rs = self::GetList(array('ID' => 'ASC'), array(), array('ID', 'CURRENCY_ID', 'OPPORTUNITY', 'TAX_VALUE', 'EXCH_RATE'));
     $entity = new CCrmDeal(false);
     while ($arParams = $rs->Fetch()) {
         $ID = intval($arParams['ID']);
         $entity->Update($ID, $arParams, false, false);
         $arRows = CCrmProductRow::LoadRows('D', $ID);
         $context = array();
         if (isset($arParams['CURRENCY_ID'])) {
             $context['CURRENCY_ID'] = $arParams['CURRENCY_ID'];
         }
         if (isset($arParams['EXCH_RATE'])) {
             $context['EXCH_RATE'] = $arParams['EXCH_RATE'];
         }
         if (count($arRows) > 0) {
             CCrmProductRow::SaveRows('D', $ID, $arRows, $context);
         }
     }
 }
Exemplo n.º 6
0
if (isset($arParams['PRODUCT_ROWS']) && is_array($arParams['PRODUCT_ROWS'])) {
    $arResult['PRODUCT_ROWS'] = $arParams['PRODUCT_ROWS'];
    foreach ($arResult['PRODUCT_ROWS'] as &$arProdRow) {
        $productID = intval($arProdRow['PRODUCT_ID']);
        if (isset($arProdRow['PRODUCT_NAME'])) {
            continue;
        }
        $dbRes = CCrmProduct::GetList(array(), array('ID' => $productID), array('NAME'));
        $arProdRow['PRODUCT_NAME'] = is_array($arRes = $dbRes->Fetch()) ? $arRes['NAME'] : '[' . strval($productID) . ']';
    }
    unset($arProdRow);
} else {
    if ($arResult['INVOICE_MODE']) {
        $arResult['PRODUCT_ROWS'] = CCrmInvoice::GetProductRows($ownerID);
    } else {
        $arResult['PRODUCT_ROWS'] = $ownerID > 0 ? CCrmProductRow::LoadRows($ownerType, $ownerID) : array();
    }
}
if ($bCopy) {
    foreach ($arResult['PRODUCT_ROWS'] as &$row) {
        if (isset($row['ID'])) {
            $row['ID'] = 0;
        }
    }
    unset($row);
}
// Determine person type
$arPersonTypes = CCrmPaySystem::getPersonTypeIDs();
$personTypeId = 0;
$arResult['CLIENT_TYPE_NAME'] = "CONTACT";
if (isset($arParams['PERSON_TYPE_ID']) && isset($arPersonTypes['COMPANY']) && isset($arPersonTypes['CONTACT'])) {
Exemplo n.º 7
0
 public static function CalculateTotalInfo($ownerType, $ownerID, $checkPerms = true, $params = null, $rows = null, $totalInfo = array())
 {
     if (!is_array($totalInfo)) {
         $totalInfo = array();
     }
     $result = false;
     if (isset($totalInfo['OPPORTUNITY']) && isset($totalInfo['TAX_VALUE'])) {
         $result = array('OPPORTUNITY' => round(doubleval($totalInfo['OPPORTUNITY']), 2), 'TAX_VALUE' => round(doubleval($totalInfo['TAX_VALUE']), 2));
     } else {
         $arParams = null;
         if ($ownerID <= 0) {
             $arParams = $params;
         } else {
             if ($ownerType === 'L') {
                 $arParams = CCrmLead::GetByID($ownerID, $checkPerms);
             } elseif ($ownerType === 'D') {
                 $arParams = CCrmDeal::GetByID($ownerID, $checkPerms);
             } elseif ($ownerType === CCrmQuote::OWNER_TYPE) {
                 $arParams = CCrmQuote::GetByID($ownerID, $checkPerms);
             }
         }
         if (!is_array($arParams)) {
             return $result;
         }
         $arRows = null;
         if (is_array($rows)) {
             $arRows = $rows;
         } elseif ($ownerID > 0) {
             $arRows = CCrmProductRow::LoadRows($ownerType, $ownerID);
         }
         if (!is_array($arRows)) {
             return $result;
         }
         $currencyID = isset($params['CURRENCY_ID']) ? $params['CURRENCY_ID'] : '';
         if ($currencyID === '') {
             $currencyID = CCrmCurrency::GetBaseCurrencyID();
         }
         $companyID = isset($params['COMPANY_ID']) ? intval($params['COMPANY_ID']) : 0;
         $contactID = isset($params['CONTACT_ID']) ? intval($params['CONTACT_ID']) : 0;
         // Determine person type
         $personTypeId = 0;
         $arPersonTypes = CCrmPaySystem::getPersonTypeIDs();
         if ($companyID > 0 && isset($arPersonTypes['COMPANY'])) {
             $personTypeId = $arPersonTypes['COMPANY'];
         } elseif ($contactID > 0 && isset($arPersonTypes['CONTACT'])) {
             $personTypeId = $arPersonTypes['CONTACT'];
         }
         $enableSaleDiscount = false;
         $siteID = '';
         if (defined('SITE_ID')) {
             $siteID = SITE_ID;
         } else {
             $obSite = CSite::GetList($by = 'def', $order = 'desc', array('ACTIVE' => 'Y'));
             if ($obSite && ($arSite = $obSite->Fetch())) {
                 $siteID = $arSite["LID"];
             }
             unset($obSite, $arSite);
         }
         $calculateOptions = array();
         if (CCrmTax::isTaxMode()) {
             $calculateOptions['LOCATION_ID'] = isset($arParams['LOCATION_ID']) ? $arParams['LOCATION_ID'] : '';
         }
         $calculated = CCrmSaleHelper::Calculate($arRows, $currencyID, $personTypeId, $enableSaleDiscount, $siteID, $calculateOptions);
         $result = array('OPPORTUNITY' => isset($calculated['PRICE']) ? round(doubleval($calculated['PRICE']), 2) : 1.0, 'TAX_VALUE' => isset($calculated['TAX_VALUE']) ? round(doubleval($calculated['TAX_VALUE']), 2) : 0.0);
     }
     return $result;
 }