Example #1
0
    					'TEXT' => GetMessage('CRM_QUOTE_BIZPROC_LIST'),
    					'MENU' => $arBizprocList
    				);
    			endif;
    		endif;*/
    if ($arQuote['DELETE'] && !$arResult['INTERNAL']) {
        $arActions[] = array('SEPARATOR' => true);
        $arActions[] = array('ICONCLASS' => 'delete', 'TITLE' => GetMessage('CRM_QUOTE_DELETE_TITLE'), 'TEXT' => GetMessage('CRM_QUOTE_DELETE'), 'ONCLICK' => "crm_quote_delete_grid('" . CUtil::JSEscape(GetMessage('CRM_QUOTE_DELETE_TITLE')) . "', '" . CUtil::JSEscape(GetMessage('CRM_QUOTE_DELETE_CONFIRM')) . "', '" . CUtil::JSEscape(GetMessage('CRM_QUOTE_DELETE')) . "', '" . CUtil::JSEscape($arQuote['PATH_TO_QUOTE_DELETE']) . "')");
    }
    $contactID = isset($arQuote['~CONTACT_ID']) ? intval($arQuote['~CONTACT_ID']) : 0;
    $companyID = isset($arQuote['~COMPANY_ID']) ? intval($arQuote['~COMPANY_ID']) : 0;
    $leadID = isset($arQuote['~LEAD_ID']) ? intval($arQuote['~LEAD_ID']) : 0;
    $dealID = isset($arQuote['~DEAL_ID']) ? intval($arQuote['~DEAL_ID']) : 0;
    $resultItem = array('id' => $arQuote['ID'], 'actions' => $arActions, 'data' => $arQuote, 'editable' => !$arQuote['EDIT'] ? $arResult['INTERNAL'] ? 'N' : $arColumns : 'Y', 'columns' => array('QUOTE_NUMBER' => '<a target="_self" href="' . $arQuote['PATH_TO_QUOTE_SHOW'] . '">' . $arQuote['QUOTE_NUMBER'] . '</a>', 'QUOTE_SUMMARY' => CCrmViewHelper::RenderInfo1($arQuote['PATH_TO_QUOTE_SHOW'], isset($arQuote['QUOTE_NUMBER']) ? $arQuote['QUOTE_NUMBER'] : '[' . $arQuote['ID'] . ']', $arQuote['TITLE'], '_self'), 'QUOTE_CLIENT' => $contactID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID, 'TITLE' => isset($arQuote['~CONTACT_FORMATTED_NAME']) ? $arQuote['~CONTACT_FORMATTED_NAME'] : '[' . $contactID . ']', 'PREFIX' => "QUOTE_{$arQuote['~ID']}", 'DESCRIPTION' => isset($arQuote['~COMPANY_TITLE']) ? $arQuote['~COMPANY_TITLE'] : '')) : ($companyID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID, 'TITLE' => isset($arQuote['~COMPANY_TITLE']) ? $arQuote['~COMPANY_TITLE'] : '[' . $companyID . ']', 'PREFIX' => "QUOTE_{$arQuote['~ID']}"), $arQuote['PATH_TO_COMPANY_SHOW'], isset($arQuote['COMPANY_TITLE']) ? $arQuote['COMPANY_TITLE'] : '', '') : ''), 'COMPANY_ID' => $companyID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID, 'TITLE' => isset($arQuote['~COMPANY_TITLE']) ? $arQuote['~COMPANY_TITLE'] : '[' . $companyID . ']', 'PREFIX' => "QUOTE_{$arQuote['~ID']}"), $arQuote['PATH_TO_COMPANY_SHOW'], isset($arQuote['COMPANY_TITLE']) ? $arQuote['COMPANY_TITLE'] : '', '') : '', 'LEAD_ID' => $leadID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Lead, 'ENTITY_ID' => $leadID, 'TITLE' => isset($arQuote['~LEAD_TITLE']) ? $arQuote['~LEAD_TITLE'] : '[' . $leadID . ']', 'PREFIX' => "QUOTE_{$arQuote['~ID']}"), $arQuote['PATH_TO_LEAD_SHOW'], isset($arQuote['LEAD_TITLE']) ? $arQuote['LEAD_TITLE'] : '', '') : '', 'DEAL_ID' => $dealID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $dealID, 'TITLE' => isset($arQuote['~DEAL_TITLE']) ? $arQuote['~DEAL_TITLE'] : '[' . $dealID . ']', 'PREFIX' => "QUOTE_{$arQuote['~ID']}"), $arQuote['PATH_TO_DEAL_SHOW'], isset($arQuote['DEAL_TITLE']) ? $arQuote['DEAL_TITLE'] : '', '') : '', 'CONTACT_ID' => $contactID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID, 'TITLE' => isset($arQuote['~CONTACT_FORMATTED_NAME']) ? $arQuote['~CONTACT_FORMATTED_NAME'] : '[' . $contactID . ']', 'PREFIX' => "QUOTE_{$arQuote['~ID']}")) : '', 'TITLE' => '<a target="_self" href="' . $arQuote['PATH_TO_QUOTE_SHOW'] . '"
					class="' . '"
					' . '>' . $arQuote['TITLE'] . '</a>', 'CLOSED' => $arQuote['CLOSED'] == 'Y' ? GetMessage('MAIN_YES') : GetMessage('MAIN_NO'), 'ASSIGNED_BY' => $arQuote['~ASSIGNED_BY'] > 0 ? '<a href="' . $arQuote['PATH_TO_USER_PROFILE'] . '" id="balloon_' . $arResult['GRID_ID'] . '_' . $arQuote['ID'] . '">' . $arQuote['ASSIGNED_BY'] . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arQuote['~ASSIGNED_BY'] . ', "balloon_' . $arResult['GRID_ID'] . '_' . $arQuote['ID'] . '", "");</script>' : '', 'COMMENTS' => htmlspecialcharsback($arQuote['COMMENTS']), 'SUM' => '<nobr>' . $arQuote['FORMATTED_OPPORTUNITY'] . '</nobr>', 'OPPORTUNITY' => '<nobr>' . $arQuote['OPPORTUNITY'] . '</nobr>', 'DATE_CREATE' => '<nobr>' . FormatDate('SHORT', MakeTimeStamp($arQuote['DATE_CREATE'])) . '</nobr>', 'DATE_MODIFY' => '<nobr>' . FormatDate('SHORT', MakeTimeStamp($arQuote['DATE_MODIFY'])) . '</nobr>', 'CURRENCY_ID' => CCrmCurrency::GetCurrencyName($arQuote['CURRENCY_ID']), 'PRODUCT_ID' => isset($arQuote['PRODUCT_ROWS']) ? htmlspecialcharsbx(CCrmProductRow::RowsToString($arQuote['PRODUCT_ROWS'])) : '', 'STATUS_ID' => CCrmViewHelper::RenderQuoteStatusControl(array('PREFIX' => "{$arResult['GRID_ID']}_PROGRESS_BAR_", 'ENTITY_ID' => $arQuote['~ID'], 'CURRENT_ID' => $arQuote['~STATUS_ID'], 'SERVICE_URL' => '/bitrix/components/bitrix/crm.quote.list/list.ajax.php')), 'CREATED_BY' => $arQuote['~CREATED_BY'] > 0 ? '<a href="' . $arQuote['PATH_TO_USER_CREATOR'] . '" id="balloon_' . $arResult['GRID_ID'] . '_' . $arQuote['ID'] . '">' . $arQuote['CREATED_BY_FORMATTED_NAME'] . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arQuote['~CREATED_BY'] . ', "balloon_' . $arResult['GRID_ID'] . '_' . $arQuote['ID'] . '", "");</script>' : '', 'MODIFY_BY' => $arQuote['~MODIFY_BY'] > 0 ? '<a href="' . $arQuote['PATH_TO_USER_MODIFIER'] . '" id="balloon_' . $arResult['GRID_ID'] . '_' . $arQuote['ID'] . '">' . $arQuote['MODIFY_BY_FORMATTED_NAME'] . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arQuote['~MODIFY_BY'] . ', "balloon_' . $arResult['GRID_ID'] . '_' . $arQuote['ID'] . '", "");</script>' : '', 'ENTITIES_LINKS' => $arQuote['FORMATTED_ENTITIES_LINKS'], 'CLOSEDATE' => empty($arQuote['CLOSEDATE']) ? '' : '<nobr>' . $arQuote['CLOSEDATE'] . '</nobr>') + $arResult['QUOTE_UF'][$sKey]);
    if ($arQuote['IN_COUNTER_FLAG'] === true) {
        if ($resultItem['columnClasses']['CLOSEDATE'] != '') {
            $resultItem['columnClasses']['CLOSEDATE'] .= ' ';
        } else {
            $resultItem['columnClasses']['CLOSEDATE'] = '';
        }
        $resultItem['columnClasses']['CLOSEDATE'] .= 'crm-list-quote-today';
    }
    if ($arQuote['EXPIRED_FLAG'] === true) {
        if ($resultItem['columnClasses']['CLOSEDATE'] != '') {
            $resultItem['columnClasses']['CLOSEDATE'] .= ' ';
        } else {
            $resultItem['columnClasses']['CLOSEDATE'] = '';
        }
        $resultItem['columnClasses']['CLOSEDATE'] .= 'crm-list-quote-time-expired';
Example #2
0
 if ($currencyID === '') {
     $currencyID = CCrmCurrency::GetBaseCurrencyID();
 }
 $fields['CURRENCY_ID'] = $currencyID;
 $productDataFieldName = 'PRODUCT_ROWS';
 $processProductRows = isset($data['PROCESS_PRODUCT_ROWS']) ? $data['PROCESS_PRODUCT_ROWS'] === 'Y' : false;
 $productRows = array();
 if ($processProductRows) {
     $productRows = isset($data[$productDataFieldName]) ? $data[$productDataFieldName] : array();
     if (!empty($productRows)) {
         foreach ($productRows as &$productRow) {
             $productRow['CUSTOMIZED'] = 'Y';
         }
         unset($productRow);
         $params = array('CONTACT_ID' => 0, 'COMPANY_ID' => 0, 'CURRENCY_ID' => $fields['CURRENCY_ID']);
         $result = CCrmProductRow::CalculateTotalInfo('L', 0, false, $params, $productRows);
         $fields['OPPORTUNITY'] = isset($result['OPPORTUNITY']) ? $result['OPPORTUNITY'] : 0.0;
     }
 }
 $assignedByID = isset($data['ASSIGNED_BY_ID']) ? intval($data['ASSIGNED_BY_ID']) : 0;
 if ($assignedByID <= 0) {
     $assignedByID = intval($curUser->GetID());
 }
 $fields['ASSIGNED_BY_ID'] = $assignedByID;
 if (isset($data['FM']) && is_array($data['FM']) && !empty($data['FM'])) {
     $fields['FM'] = $data['FM'];
 }
 $entity = new CCrmLead(false);
 if (!$entity->CheckFields($fields, !$isNew ? $ID : false, array('DISABLE_USER_FIELD_CHECK' => true))) {
     __CrmMobileLeadEditEndResonse(array('ERROR' => strip_tags(preg_replace("/<br[^>]*>/", "\n", $entity->LAST_ERROR))));
 } else {
Example #3
0
     			$arFields['ORIGIN_ID'] = $originId;
     		}*/
     $ID = $CCrmQuote->Add($arFields, true, array('REGISTER_SONET_EVENT' => false));
     $bSuccess = $ID !== false;
     if ($bSuccess) {
         $arResult['ELEMENT']['ID'] = $ID;
     }
 }
 if ($bSuccess) {
     // Save settings
     if (is_array($productRowSettings) && count($productRowSettings) > 0) {
         $arSettings = CCrmProductRow::LoadSettings(CCrmQuote::OWNER_TYPE, $arResult['ELEMENT']['ID']);
         foreach ($productRowSettings as $k => $v) {
             $arSettings[$k] = $v;
         }
         CCrmProductRow::SaveSettings(CCrmQuote::OWNER_TYPE, $arResult['ELEMENT']['ID'], $arSettings);
     }
     unset($arSettings);
 }
 if ($bSuccess && $processProductRows && ($bEdit || !empty($arProd))) {
     // Suppress owner synchronization
     $bSuccess = $CCrmQuote::SaveProductRows($arResult['ELEMENT']['ID'], $arProd, true, true, false);
     if (!$bSuccess) {
         $arResult['ERROR_MESSAGE'] = GetMessage('PRODUCT_ROWS_SAVING_ERROR');
     }
 }
 if ($bSuccess) {
     if ($arFields['CONTACT_ID'] > 0 && $arFields['COMPANY_ID'] > 0 && isset($_POST['NEW_CONTACT_ID']) && $arFields['CONTACT_ID'] == $_POST['NEW_CONTACT_ID']) {
         $CrmContact = new CCrmContact();
         $arContactFields = array('COMPANY_ID' => $arFields['COMPANY_ID']);
         $bSuccess = $CrmContact->Update($arFields['CONTACT_ID'], $arContactFields, false, true, array('DISABLE_USER_FIELD_CHECK' => true));
Example #4
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 {
Example #5
0
<td><?php 
                    echo CCrmProductRow::GetPrice($productRow, '');
                    ?>
</td><?php 
                    ?>
<td><?php 
                    echo CCrmProductRow::GetQuantity($productRow, '');
                    ?>
</td><?php 
                    continue;
                } elseif ($headerID === 'OPPORTUNITY') {
                    // Special logic for OPPORTUNITY: replace it by product row sum if it specified
                    if (isset($productRow['PRODUCT_ID']) && intval($productRow['PRODUCT_ID']) > 0) {
                        ?>
<td><?php 
                        echo round(CCrmProductRow::GetPrice($productRow) * CCrmProductRow::GetQuantity($productRow), 2);
                        ?>
</td><?php 
                    } else {
                        ?>
<td><?php 
                        echo isset($arDeal['OPPORTUNITY']) ? strval($arDeal['OPPORTUNITY']) : '';
                        ?>
</td><?php 
                    }
                    continue;
                }
                if (!isset($dealData[$headerID])) {
                    switch ($arHead['id']) {
                        case 'STAGE_ID':
                            $stageID = !empty($arDeal['STAGE_ID']) ? $arDeal['STAGE_ID'] : '';
Example #6
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;
 }
Example #7
0
 public function executePhase()
 {
     if ($this->currentPhase === QuoteConversionPhase::DEAL_CREATION || $this->currentPhase === QuoteConversionPhase::INVOICE_CREATION) {
         if ($this->currentPhase === QuoteConversionPhase::DEAL_CREATION) {
             $entityTypeID = \CCrmOwnerType::Deal;
         } else {
             $entityTypeID = \CCrmOwnerType::Invoice;
         }
         $entityTypeName = \CCrmOwnerType::ResolveName($entityTypeID);
         $config = $this->config->getItem($entityTypeID);
         if (!$config->isActive()) {
             return false;
         }
         /** @var \CCrmPerms $permissions */
         $permissions = $this->getUserPermissions();
         $entityID = isset($this->contextData[$entityTypeName]) ? $this->contextData[$entityTypeName] : 0;
         if ($entityID > 0) {
             if ($entityTypeID === \CCrmOwnerType::Deal) {
                 if (!\CCrmDeal::Exists($entityID)) {
                     throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND);
                 }
                 $this->resultData[$entityTypeName] = $entityID;
             } else {
                 if (!\CCrmInvoice::Exists($entityID)) {
                     throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND);
                 }
                 if (!\CCrmInvoice::CheckUpdatePermission($entityID, $permissions)) {
                     throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::UPDATE_DENIED);
                 }
                 $entity = new \CCrmInvoice(false);
                 $fields = array('UF_QUOTE_ID' => $this->entityID);
                 try {
                     $entity->Update($entityID, $fields);
                 } catch (Main\DB\SqlQueryException $e) {
                 }
                 $this->resultData[$entityTypeName] = $entityID;
             }
             return true;
         }
         if (!\CCrmAuthorizationHelper::CheckCreatePermission($entityTypeName, $permissions)) {
             throw new EntityConversionException(\CCrmOwnerType::Quote, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::CREATE_DENIED);
         }
         if (UserFieldSynchronizer::needForSynchronization(\CCrmOwnerType::Quote, $entityTypeID)) {
             throw new EntityConversionException(\CCrmOwnerType::Quote, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::NOT_SYNCHRONIZED);
         }
         if (!ConversionSettings::getCurrent()->isAutocreationEnabled()) {
             throw new EntityConversionException(\CCrmOwnerType::Quote, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::AUTOCREATION_DISABLED);
         }
         if ($entityTypeID === \CCrmOwnerType::Deal && \CCrmBizProcHelper::HasAutoWorkflows($entityTypeID, \CCrmBizProcEventType::Create)) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::HAS_WORKFLOWS);
         }
         /** @var QuoteConversionMapper $mapper */
         $mapper = $this->getMapper();
         $map = self::prepareMap($entityTypeID);
         $fields = $mapper->map($map);
         if (empty($fields)) {
             throw new EntityConversionException(\CCrmOwnerType::Quote, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::EMPTY_FIELDS);
         }
         if ($entityTypeID === \CCrmOwnerType::Deal) {
             $entity = new \CCrmDeal(false);
             if (!$entity->CheckFields($fields)) {
                 throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::INVALID_FIELDS, $entity->LAST_ERROR);
             }
             $productRows = isset($fields['PRODUCT_ROWS']) && is_array($fields['PRODUCT_ROWS']) ? $fields['PRODUCT_ROWS'] : array();
             if (!empty($productRows)) {
                 $result = \CCrmProductRow::CalculateTotalInfo('D', 0, false, $fields, $productRows);
                 $fields['OPPORTUNITY'] = isset($result['OPPORTUNITY']) ? $result['OPPORTUNITY'] : 1.0;
                 $fields['TAX_VALUE'] = isset($result['TAX_VALUE']) ? $result['TAX_VALUE'] : 0.0;
             }
             $entityID = $entity->Add($fields);
             if ($entityID <= 0) {
                 throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR);
             }
             if (!empty($productRows)) {
                 \CCrmDeal::SaveProductRows($entityID, $productRows, false, false, false);
             }
             $this->resultData[\CCrmOwnerType::DealName] = $entityID;
         } else {
             $entity = new \CCrmInvoice(false);
             if (!$entity->CheckFields($fields)) {
                 throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::INVALID_FIELDS, $entity->LAST_ERROR);
             }
             $entityID = $entity->Add($fields);
             if ($entityID <= 0) {
                 throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR);
             }
             $this->resultData[\CCrmOwnerType::InvoiceName] = $entityID;
         }
         return true;
     } elseif ($this->currentPhase === DealConversionPhase::FINALIZATION) {
         $fields = array();
         if (isset($this->resultData[\CCrmOwnerType::DealName])) {
             $fields['DEAL_ID'] = $this->resultData[\CCrmOwnerType::DealName];
         }
         if (!empty($fields)) {
             $entity = new \CCrmQuote(false);
             $entity->Update($this->entityID, $fields);
         }
         return true;
     }
     return false;
 }
Example #8
0
     $bSep = false;
     if ($arResult['PERMS']['ADD'] && $arLead['STATUS_ID'] != 'CONVERTED') {
         if ($arResult['CONVERT']) {
             $bSep = true;
             $arActions[] = array('SEPARATOR' => true);
             $arActions[] = array('ICONCLASS' => 'convert', 'TITLE' => GetMessage('CRM_LEAD_CONVERT_TITLE'), 'TEXT' => GetMessage('CRM_LEAD_CONVERT'), 'ONCLICK' => "jsUtils.Redirect([], '" . CUtil::JSEscape($arLead['PATH_TO_LEAD_CONVERT']) . "');");
         }
     }
 }
 if ($arLead['DELETE']) {
     if (!$bSep) {
         $arActions[] = array('SEPARATOR' => true);
     }
     $arActions[] = array('ICONCLASS' => 'delete', 'TITLE' => GetMessage('CRM_LEAD_DELETE_TITLE'), 'TEXT' => GetMessage('CRM_LEAD_DELETE'), 'ONCLICK' => "crm_lead_delete_grid('" . CUtil::JSEscape(GetMessage('CRM_LEAD_DELETE_TITLE')) . "', '" . CUtil::JSEscape(GetMessage('CRM_LEAD_DELETE_CONFIRM')) . "', '" . CUtil::JSEscape(GetMessage('CRM_LEAD_DELETE')) . "', '" . CUtil::JSEscape($arLead['PATH_TO_LEAD_DELETE']) . "')");
 }
 $resultItem = array('id' => $arLead['ID'], 'actions' => $arActions, 'data' => $arLead, 'editable' => !$arLead['EDIT'] ? $arColumns : true, 'columns' => array('LEAD_SUMMARY' => CCrmViewHelper::RenderInfo($arLead['PATH_TO_LEAD_SHOW'], isset($arLead['TITLE']) ? $arLead['TITLE'] : '[' . $arLead['ID'] . ']', $arLead['LEAD_SOURCE_NAME'], '_self'), 'ACTIVITY_ID' => CCrmViewHelper::RenderNearestActivity(array('ENTITY_TYPE_NAME' => CCrmOwnerType::ResolveName(CCrmOwnerType::Lead), 'ENTITY_ID' => $arLead['ID'], 'GRID_MANAGER_ID' => $gridManagerID, 'ACTIVITY_ID' => isset($arLead['~ACTIVITY_ID']) ? intval($arLead['~ACTIVITY_ID']) : 0, 'ACTIVITY_SUBJECT' => isset($arLead['~ACTIVITY_SUBJECT']) ? $arLead['~ACTIVITY_SUBJECT'] : '', 'ACTIVITY_TIME' => isset($arLead['~ACTIVITY_TIME']) ? $arLead['~ACTIVITY_TIME'] : '', 'ACTIVITY_EXPIRED' => isset($arLead['~ACTIVITY_EXPIRED']) ? $arLead['~ACTIVITY_EXPIRED'] : false, 'MENU_ITEMS' => $arActivityMenuItems)), 'COMMENTS' => htmlspecialcharsback($arLead['COMMENTS']), 'ADDRESS' => nl2br($arLead['ADDRESS']), 'ASSIGNED_BY' => $arLead['~ASSIGNED_BY'] > 0 ? '<a href="' . $arLead['PATH_TO_USER_PROFILE'] . '" id="balloon_' . $arResult['GRID_ID'] . '_' . $arLead['ID'] . '">' . $arLead['ASSIGNED_BY'] . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arLead['~ASSIGNED_BY'] . ', "balloon_' . $arResult['GRID_ID'] . '_' . $arLead['ID'] . '", "");</script>' : '', 'STATUS_DESCRIPTION' => nl2br($arLead['STATUS_DESCRIPTION']), 'SOURCE_DESCRIPTION' => nl2br($arLead['SOURCE_DESCRIPTION']), 'DATE_CREATE' => '<nobr>' . FormatDate('SHORT', MakeTimeStamp($arLead['DATE_CREATE'])) . '</nobr>', 'DATE_MODIFY' => '<nobr>' . FormatDate('SHORT', MakeTimeStamp($arLead['DATE_MODIFY'])) . '</nobr>', 'SUM' => '<nobr>' . $arLead['FORMATTED_OPPORTUNITY'] . '</nobr>', 'OPPORTUNITY' => '<nobr>' . $arLead['~OPPORTUNITY'] . '</nobr>', 'CURRENCY_ID' => CCrmCurrency::GetCurrencyName($arLead['~CURRENCY_ID']), 'PRODUCT_ID' => isset($arLead['PRODUCT_ROWS']) ? htmlspecialcharsbx(CCrmProductRow::RowsToString($arLead['PRODUCT_ROWS'])) : '', 'STATUS_ID' => CCrmViewHelper::RenderLeadStatusControl(array('PREFIX' => "{$arResult['GRID_ID']}_PROGRESS_BAR_", 'ENTITY_ID' => $arLead['~ID'], 'CURRENT_ID' => $arLead['~STATUS_ID'], 'SERVICE_URL' => '/bitrix/components/bitrix/crm.lead.list/list.ajax.php', 'LEAD_CONVERT_URL' => $arLead['PATH_TO_LEAD_CONVERT'], 'READ_ONLY' => !(isset($arLead['EDIT']) && $arLead['EDIT'] === true))), 'SOURCE_ID' => $arLead['LEAD_SOURCE_NAME'], 'CREATED_BY' => $arLead['~CREATED_BY'] > 0 ? '<a href="' . $arLead['PATH_TO_USER_CREATOR'] . '" id="balloon_' . $arResult['GRID_ID'] . '_' . $arLead['ID'] . '">' . $arLead['CREATED_BY_FORMATTED_NAME'] . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arLead['~CREATED_BY'] . ', "balloon_' . $arResult['GRID_ID'] . '_' . $arLead['ID'] . '", "");</script>' : '', 'MODIFY_BY' => $arLead['~MODIFY_BY'] > 0 ? '<a href="' . $arLead['PATH_TO_USER_MODIFIER'] . '" id="balloon_' . $arResult['GRID_ID'] . '_' . $arLead['ID'] . '">' . $arLead['MODIFY_BY_FORMATTED_NAME'] . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arLead['~MODIFY_BY'] . ', "balloon_' . $arResult['GRID_ID'] . '_' . $arLead['ID'] . '", "");</script>' : '') + CCrmViewHelper::RenderListMultiFields($arLead, "LEAD_{$arLead['ID']}_", array('ENABLE_SIP' => true, 'SIP_PARAMS' => array('ENTITY_TYPE' => 'CRM_' . CCrmOwnerType::LeadName, 'ENTITY_ID' => $arLead['ID']))) + $arResult['LEAD_UF'][$sKey]);
 if (isset($arLead['~BIRTHDATE'])) {
     $resultItem['columns']['BIRTHDATE'] = '<nobr>' . FormatDate('SHORT', MakeTimeStamp($arLead['~BIRTHDATE'])) . '</nobr>';
 }
 $userActivityID = isset($arLead['~ACTIVITY_ID']) ? intval($arLead['~ACTIVITY_ID']) : 0;
 $commonActivityID = isset($arLead['~C_ACTIVITY_ID']) ? intval($arLead['~C_ACTIVITY_ID']) : 0;
 if ($userActivityID > 0) {
     $resultItem['columns']['ACTIVITY_ID'] = CCrmViewHelper::RenderNearestActivity(array('ENTITY_TYPE_NAME' => CCrmOwnerType::ResolveName(CCrmOwnerType::Lead), 'ENTITY_ID' => $arLead['~ID'], 'ENTITY_RESPONSIBLE_ID' => $arLead['~ASSIGNED_BY'], 'GRID_MANAGER_ID' => $gridManagerID, 'ACTIVITY_ID' => $userActivityID, 'ACTIVITY_SUBJECT' => isset($arLead['~ACTIVITY_SUBJECT']) ? $arLead['~ACTIVITY_SUBJECT'] : '', 'ACTIVITY_TIME' => isset($arLead['~ACTIVITY_TIME']) ? $arLead['~ACTIVITY_TIME'] : '', 'ACTIVITY_EXPIRED' => isset($arLead['~ACTIVITY_EXPIRED']) ? $arLead['~ACTIVITY_EXPIRED'] : '', 'ALLOW_EDIT' => $arLead['EDIT'], 'MENU_ITEMS' => $arActivityMenuItems));
     $counterData = array('CURRENT_USER_ID' => $currentUserID, 'ENTITY' => $arLead, 'ACTIVITY' => array('RESPONSIBLE_ID' => $currentUserID, 'TIME' => isset($arLead['~ACTIVITY_TIME']) ? $arLead['~ACTIVITY_TIME'] : '', 'IS_CURRENT_DAY' => isset($arLead['~ACTIVITY_IS_CURRENT_DAY']) ? $arLead['~ACTIVITY_IS_CURRENT_DAY'] : false));
     if (CCrmUserCounter::IsReckoned(CCrmUserCounter::CurrentLeadActivies, $counterData)) {
         $resultItem['columnClasses'] = array('ACTIVITY_ID' => 'crm-list-deal-today');
     }
 } elseif ($commonActivityID > 0) {
     $resultItem['columns']['ACTIVITY_ID'] = CCrmViewHelper::RenderNearestActivity(array('ENTITY_TYPE_NAME' => CCrmOwnerType::ResolveName(CCrmOwnerType::Lead), 'ENTITY_ID' => $arLead['~ID'], 'ENTITY_RESPONSIBLE_ID' => $arLead['~ASSIGNED_BY'], 'GRID_MANAGER_ID' => $gridManagerID, 'ACTIVITY_ID' => $commonActivityID, 'ACTIVITY_SUBJECT' => isset($arLead['~C_ACTIVITY_SUBJECT']) ? $arLead['~C_ACTIVITY_SUBJECT'] : '', 'ACTIVITY_TIME' => isset($arLead['~C_ACTIVITY_TIME']) ? $arLead['~C_ACTIVITY_TIME'] : '', 'ACTIVITY_RESPONSIBLE_ID' => isset($arLead['~C_ACTIVITY_RESP_ID']) ? intval($arLead['~C_ACTIVITY_RESP_ID']) : 0, 'ACTIVITY_RESPONSIBLE_LOGIN' => isset($arLead['~C_ACTIVITY_RESP_LOGIN']) ? $arLead['~C_ACTIVITY_RESP_LOGIN'] : '', 'ACTIVITY_RESPONSIBLE_NAME' => isset($arLead['~C_ACTIVITY_RESP_NAME']) ? $arLead['~C_ACTIVITY_RESP_NAME'] : '', 'ACTIVITY_RESPONSIBLE_LAST_NAME' => isset($arLead['~C_ACTIVITY_RESP_LAST_NAME']) ? $arLead['~C_ACTIVITY_RESP_LAST_NAME'] : '', 'ACTIVITY_RESPONSIBLE_SECOND_NAME' => isset($arLead['~C_ACTIVITY_RESP_SECOND_NAME']) ? $arLead['~C_ACTIVITY_RESP_SECOND_NAME'] : '', 'NAME_TEMPLATE' => $arParams['NAME_TEMPLATE'], 'PATH_TO_USER_PROFILE' => $arParams['PATH_TO_USER_PROFILE'], 'ALLOW_EDIT' => $arLead['EDIT'], 'MENU_ITEMS' => $arActivityMenuItems));
 } else {
     $resultItem['columns']['ACTIVITY_ID'] = CCrmViewHelper::RenderNearestActivity(array('ENTITY_TYPE_NAME' => CCrmOwnerType::ResolveName(CCrmOwnerType::Lead), 'ENTITY_ID' => $arLead['~ID'], 'ENTITY_RESPONSIBLE_ID' => $arLead['~ASSIGNED_BY'], 'GRID_MANAGER_ID' => $gridManagerID, 'ALLOW_EDIT' => $arLead['EDIT'], 'MENU_ITEMS' => $arActivityMenuItems));
Example #9
0
 private static function PrepareShoppingCartItems(&$productRows, $currencyID, $siteId)
 {
     $items = array();
     foreach ($productRows as $k => &$v) {
         $item = array();
         $item['PRODUCT_ID'] = isset($v['PRODUCT_ID']) ? intval($v['PRODUCT_ID']) : 0;
         $isCustomized = isset($v['CUSTOMIZED']) && $v['CUSTOMIZED'] === 'Y';
         if ($item['PRODUCT_ID'] > 0 && !$isCustomized) {
             $item['MODULE'] = 'catalog';
             $item['PRODUCT_PROVIDER_CLASS'] = 'CCatalogProductProvider';
         } else {
             $item['MODULE'] = $item['PRODUCT_PROVIDER_CLASS'] = '';
         }
         if ($isCustomized) {
             $item['CUSTOM_PRICE'] = 'Y';
         }
         $item['TABLE_ROW_ID'] = $k;
         $item['QUANTITY'] = isset($v['QUANTITY']) ? doubleval($v['QUANTITY']) : 0;
         $item['QUANTITY_DEFAULT'] = $item['QUANTITY'];
         $item['PRICE'] = isset($v['PRICE']) ? doubleval($v['PRICE']) : 0.0;
         $item['PRICE_DEFAULT'] = $item['PRICE'];
         $item['CURRENCY'] = $currencyID;
         // discount info
         $item['CRM_PR_FIELDS'] = array();
         $item['CRM_PR_FIELDS']['DISCOUNT_TYPE_ID'] = isset($v['DISCOUNT_TYPE_ID']) ? intval($v['DISCOUNT_TYPE_ID']) : \Bitrix\Crm\Discount::PERCENTAGE;
         $item['CRM_PR_FIELDS']['DISCOUNT_RATE'] = isset($v['DISCOUNT_RATE']) ? round(doubleval($v['DISCOUNT_RATE']), 2) : 0.0;
         $item['CRM_PR_FIELDS']['DISCOUNT_SUM'] = isset($v['DISCOUNT_SUM']) ? round(doubleval($v['DISCOUNT_SUM']), 2) : 0.0;
         // tax info
         $taxRate = isset($v['TAX_RATE']) ? round(doubleval($v['TAX_RATE']), 2) : 0.0;
         $allowLDTax = CCrmTax::isTaxMode();
         if ($allowLDTax) {
             $item['CRM_PR_FIELDS']['TAX_RATE'] = 0.0;
             $item['CRM_PR_FIELDS']['TAX_INCLUDED'] = 'N';
         } else {
             $item['CRM_PR_FIELDS']['TAX_RATE'] = $taxRate;
             $item['CRM_PR_FIELDS']['TAX_INCLUDED'] = isset($v['TAX_INCLUDED']) && $v['TAX_INCLUDED'] === 'Y' ? 'Y' : 'N';
         }
         // price netto, price brutto
         $exclusivePrice = $taxRate !== 0.0 ? CCrmProductRow::CalculateExclusivePrice($item['PRICE'], $taxRate) : $item['PRICE'];
         if ($item['CRM_PR_FIELDS']['DISCOUNT_TYPE_ID'] === \Bitrix\Crm\Discount::MONETARY) {
             $priceNetto = $exclusivePrice + $item['CRM_PR_FIELDS']['DISCOUNT_SUM'];
             $item['CRM_PR_FIELDS']['PRICE_NETTO'] = round($priceNetto, 2);
         } else {
             $discoutRate = $item['CRM_PR_FIELDS']['DISCOUNT_RATE'];
             $discoutSum = $discoutRate < 100 ? \Bitrix\Crm\Discount::calculateDiscountByDiscountPrice($exclusivePrice, $discoutRate) : $item['CRM_PR_FIELDS']['DISCOUNT_SUM'];
             $priceNetto = $exclusivePrice + $discoutSum;
             $item['CRM_PR_FIELDS']['PRICE_NETTO'] = round($priceNetto, 2);
         }
         if ($item['CRM_PR_FIELDS']['DISCOUNT_SUM'] === 0.0) {
             $item['CRM_PR_FIELDS']['PRICE_BRUTTO'] = $item['PRICE'];
         } else {
             $item['CRM_PR_FIELDS']['PRICE_BRUTTO'] = round(CCrmProductRow::CalculateInclusivePrice($priceNetto, $item['CRM_PR_FIELDS']['TAX_RATE']), 2);
         }
         if (isset($v['VAT_RATE'])) {
             $item['VAT_RATE'] = $v['VAT_RATE'];
         } elseif (isset($v['TAX_RATE'])) {
             $item['VAT_RATE'] = $v['TAX_RATE'] / 100;
         }
         if (isset($v['MEASURE_CODE'])) {
             $item['MEASURE_CODE'] = $v['MEASURE_CODE'];
         }
         if (isset($v['MEASURE_NAME'])) {
             $item['MEASURE_NAME'] = $v['MEASURE_NAME'];
         }
         $item['NAME'] = isset($v['NAME']) ? $v['NAME'] : (isset($v['PRODUCT_NAME']) ? $v['PRODUCT_NAME'] : '');
         $item['LID'] = $siteId;
         $item['CAN_BUY'] = 'Y';
         $items[] =& $item;
         unset($item);
     }
     unset($v);
     return $items;
 }
Example #10
0
 public static function ProductRows2BasketItems($arProductRows, $srcCurrencyID = '', $dstCurrencyID = '')
 {
     $basketItems = array();
     $srcCurrencyID = strval($srcCurrencyID);
     $dstCurrencyID = strval($dstCurrencyID);
     if (strlen($srcCurrencyID) <= 0 || strlen($dstCurrencyID) <= 0) {
         $srcCurrencyID = $dstCurrencyID = '';
     }
     foreach ($arProductRows as $row) {
         $freshRow = array();
         $freshRow['ID'] = isset($row['ID']) ? intval($row['ID']) : 0;
         $freshRow['PRODUCT_ID'] = isset($row['PRODUCT_ID']) ? intval($row['PRODUCT_ID']) : 0;
         $freshRow['PRODUCT_NAME'] = isset($row['PRODUCT_NAME']) ? strval($row['PRODUCT_NAME']) : '';
         $freshRow['QUANTITY'] = isset($row['QUANTITY']) ? round(doubleval($row['QUANTITY']), 2) : 0.0;
         $freshRow['PRICE'] = isset($row['PRICE']) ? round(doubleval($row['PRICE']), 2) : 0.0;
         if ($dstCurrencyID != $srcCurrencyID) {
             $freshRow['PRICE'] = CCrmCurrency::ConvertMoney($freshRow['PRICE'], $srcCurrencyID, $dstCurrencyID);
         }
         $taxRate = isset($row['TAX_RATE']) ? round(doubleval($row['TAX_RATE']), 2) : 0.0;
         $freshRow['VAT_RATE'] = $taxRate / 100;
         $discountTypeID = isset($row['DISCOUNT_TYPE_ID']) ? intval($row['DISCOUNT_TYPE_ID']) : \Bitrix\Crm\Discount::UNDEFINED;
         if ($discountTypeID !== \Bitrix\Crm\Discount::PERCENTAGE && $discountTypeID !== \Bitrix\Crm\Discount::MONETARY) {
             $discountTypeID = \Bitrix\Crm\Discount::PERCENTAGE;
         }
         if ($discountTypeID === \Bitrix\Crm\Discount::PERCENTAGE) {
             $discountRate = isset($row['DISCOUNT_RATE']) ? round(doubleval($row['DISCOUNT_RATE']), 2) : 0.0;
             $exclusivePrice = CCrmProductRow::CalculateExclusivePrice($freshRow['PRICE'], $taxRate);
             $freshRow['DISCOUNT_PRICE'] = round(\Bitrix\Crm\Discount::calculateDiscountSum($exclusivePrice, $discountRate), 2);
         } else {
             $freshRow['DISCOUNT_PRICE'] = isset($row['DISCOUNT_SUM']) ? round(doubleval($row['DISCOUNT_SUM']), 2) : 0.0;
             if ($dstCurrencyID != $srcCurrencyID) {
                 $freshRow['DISCOUNT_PRICE'] = CCrmCurrency::ConvertMoney($freshRow['DISCOUNT_PRICE'], $srcCurrencyID, $dstCurrencyID);
             }
         }
         $freshRow['MEASURE_CODE'] = isset($row['MEASURE_CODE']) ? intval($row['MEASURE_CODE']) : 0;
         $freshRow['MEASURE_NAME'] = isset($row['MEASURE_NAME']) ? strval($row['MEASURE_NAME']) : '';
         $freshRow['CUSTOMIZED'] = isset($row['CUSTOMIZED']) ? $row['CUSTOMIZED'] === 'Y' ? 'Y' : 'N' : 'Y';
         $basketItems[] = $freshRow;
     }
     return $basketItems;
 }
Example #11
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;
 }
Example #12
0
 protected function innerDelete($ID, &$errors)
 {
     $entity = CCrmProductRow::GetByID($ID);
     if (!is_array($entity)) {
         $errors[] = "Product Row not found";
         return false;
     }
     if (!CCrmAuthorizationHelper::CheckDeletePermission(CCrmProductRow::ResolveOwnerTypeName($entity['OWNER_TYPE']), $entity['OWNER_ID'])) {
         $errors[] = 'Access denied.';
         return false;
     }
     $result = CCrmProductRow::Delete($ID, true, true);
     if ($result !== true) {
         $errors[] = CCrmProductRow::GetLastError();
     }
     return $result;
 }
Example #13
0
    $APPLICATION->IncludeComponent('bitrix:crm.company.edit', 'convert', array('ELEMENT_ID' => 0, 'FORM_ID' => $arResult['FORM_ID'], 'INTERNAL_FILTER' => true, 'CONVERT' => true, 'VALUES' => $arResult['ELEMENT']['COMPANY']), false);
    $sVal = ob_get_contents();
    ob_end_clean();
    $arResult['FIELDS']['tab_convert'][] = array('id' => 'LEAD_COMPANY_CONVERT', 'name' => GetMessage('CRM_FIELD_LEAD_COMPANY'), 'colspan' => true, 'type' => 'custom', 'value' => $sVal);
}
if (!$CrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'ADD')) {
    $arDealVals = $arResult['ELEMENT']['DEAL'];
    if (!isset($arDealVals['PRODUCT_ROWS'])) {
        $arProductRows = CCrmLead::LoadProductRows($arParams['ELEMENT_ID']);
        if (count($arProductRows) > 0) {
            $arDealVals['PRODUCT_ROWS'] = $arProductRows;
        }
    }
    $componentSettings = array('ELEMENT_ID' => 0, 'FORM_ID' => $arResult['FORM_ID'], 'INTERNAL_FILTER' => true, 'CONVERT' => true, 'VALUES' => $arDealVals, 'VARS_FROM_FORM' => $bVarsFromForm, 'PATH_TO_PRODUCT_EDIT' => $arResult['PATH_TO_PRODUCT_EDIT'], 'PATH_TO_PRODUCT_SHOW' => $arResult['PATH_TO_PRODUCT_SHOW']);
    // load product row settings
    $productRowSettings = CCrmProductRow::LoadSettings('L', $arParams['ELEMENT_ID']);
    if (isset($productRowSettings['ENABLE_TAX'])) {
        $componentSettings['ENABLE_TAX'] = (bool) $productRowSettings['ENABLE_TAX'] ? 'Y' : 'N';
    }
    if (isset($productRowSettings['ENABLE_DISCOUNT'])) {
        $componentSettings['ENABLE_DISCOUNT'] = (bool) $productRowSettings['ENABLE_DISCOUNT'] ? 'Y' : 'N';
    }
    unset($productRowSettings);
    ob_start();
    $APPLICATION->IncludeComponent('bitrix:crm.deal.edit', 'convert', $componentSettings, false);
    $sVal = ob_get_contents();
    ob_end_clean();
    $arResult['FIELDS']['tab_convert'][] = array('id' => 'LEAD_DEAL_CONVERT', 'name' => GetMessage('CRM_FIELD_LEAD_DEAL'), 'colspan' => true, 'type' => 'custom', 'value' => $sVal);
}
$this->IncludeComponentTemplate();
include_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/components/bitrix/crm.lead/include/nav.php';
Example #14
0
 public static function Delete($ID)
 {
     global $DB, $APPLICATION;
     $ID = intval($ID);
     $arProduct = self::GetByID($ID);
     if (!is_array($arProduct)) {
         // Is no exists
         return true;
     }
     $rowsCount = CCrmProductRow::GetList(array(), array('PRODUCT_ID' => $ID), array(), false, array());
     if ($rowsCount > 0 || CCrmInvoice::HasProductRows($ID)) {
         self::RegisterError(GetMessage('CRM_COULD_NOT_DELETE_PRODUCT_ROWS_EXIST', array('#NAME#' => $arProduct['~NAME'])));
         return false;
     }
     foreach (GetModuleEvents('crm', 'OnBeforeCrmProductDelete', true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID)) === false) {
             return false;
         }
     }
     //$DB->StartTransaction();
     //$APPLICATION->ResetException();
     //		$sql = 'DELETE FROM '.CCrmProduct::TABLE_NAME.' WHERE ID = '.$ID;
     //		if(!$DB->Query($sql, true))
     //		{
     //			//$DB->Rollback();
     //			return false;
     //		}
     CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID);
     if (self::IsIBlockElementExists($ID)) {
         $element = new CIBlockElement();
         if (!$element->Delete($ID)) {
             //$DB->Rollback();
             if ($ex = $APPLICATION->GetException()) {
                 self::RegisterError($ex->GetString());
             }
             return false;
         }
     }
     //$DB->Commit();
     foreach (GetModuleEvents('crm', 'OnCrmProductDelete', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID));
     }
     return true;
 }
Example #15
0
        echo CUtil::PhpToJSObject(array('ERROR' => 'PRODUCT_ROWS_SAVING_ERROR'));
    } else {
        echo CUtil::PhpToJSObject(array('SAVE_PRODUCT_ROWS' => 'OK'));
    }
} elseif ($mode === 'REMOVE_PRODUCT') {
    if ($perms->HavePerm($ownerName, BX_CRM_PERM_NONE, 'WRITE')) {
        echo CUtil::PhpToJSObject(array('ERROR' => 'PERMISSION_DENIED'));
        die;
    }
    $ID = isset($_POST['ID']) ? intval($_POST['ID']) : 0;
    if ($ID <= 0) {
        echo CUtil::PhpToJSObject(array('ERROR' => 'ID_NOT_FOUND'));
        die;
    }
    if (!CCrmProductRow::Delete($ID)) {
        echo CUtil::PhpToJSObject(array('ERROR' => CCrmProductRow::GetLastError()));
    } else {
        echo CUtil::PhpToJSObject(array('DELETED_PRODUCT_ID' => $ID));
    }
} elseif ($mode === 'CALCULATE_TOTALS') {
    if ($perms->HavePerm($ownerName, BX_CRM_PERM_NONE, 'WRITE')) {
        echo CUtil::PhpToJSObject(array('ERROR' => 'PERMISSION_DENIED'));
        die;
    }
    $productRows = isset($_POST['PRODUCTS']) && is_array($_POST['PRODUCTS']) ? $_POST['PRODUCTS'] : array();
    $totalDiscount = 0.0;
    foreach ($productRows as &$productRow) {
        $productRow['ID'] = isset($productRow['ID']) ? intval($productRow['ID']) : 0;
        $productRow['PRODUCT_ID'] = isset($productRow['PRODUCT_ID']) ? intval($productRow['PRODUCT_ID']) : 0;
        $productRow['PRODUCT_NAME'] = isset($productRow['PRODUCT_NAME']) ? $productRow['PRODUCT_NAME'] : '';
        $productRow['QUANTITY'] = isset($productRow['QUANTITY']) ? doubleval($productRow['QUANTITY']) : 1.0;
Example #16
0
 public function SynchronizeProductRows($ID)
 {
     $arTotalInfo = CCrmProductRow::CalculateTotalInfo(CCrmQuote::OWNER_TYPE, $ID);
     if (is_array($arTotalInfo)) {
         $arFields = array('OPPORTUNITY' => isset($arTotalInfo['OPPORTUNITY']) ? $arTotalInfo['OPPORTUNITY'] : 0.0, 'TAX_VALUE' => isset($arTotalInfo['TAX_VALUE']) ? $arTotalInfo['TAX_VALUE'] : 0.0);
         $entity = new CCrmQuote();
         $entity->Update($ID, $arFields);
     }
 }
 public static function isIncludesUsedProducts($iblockId, $sectionId)
 {
     $iblockId = intval($iblockId);
     $sectionId = intval($sectionId);
     if ($iblockId <= 0 || $sectionId <= 0) {
         return false;
     }
     $result = false;
     $stepSize = 500;
     $element = new CIBlockElement();
     $rs = $element->GetList(array('SORT' => 'ASC'), array('IBLOCK_ID' => $iblockId, 'SECTION_ID' => $sectionId, 'INCLUDE_SUBSECTIONS' => 'Y', 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID'));
     if ($rs) {
         $i = 0;
         $arProductId = array();
         while ($row = $rs->Fetch()) {
             $i++;
             $arProductId[] = $row['ID'];
             if ($i === $stepSize) {
                 $rowsCount = CCrmProductRow::GetList(array(), array('PRODUCT_ID' => $arProductId), array(), false, array());
                 if ($rowsCount > 0 || CCrmInvoice::HasProductRows($arProductId)) {
                     $result = true;
                 }
                 $i = 0;
                 $arProductId = array();
             }
             if ($result) {
                 break;
             }
         }
         if (!$result && count($arProductId) > 0) {
             $rowsCount = CCrmProductRow::GetList(array(), array('PRODUCT_ID' => $arProductId), array(), false, array());
             if ($rowsCount > 0 || CCrmInvoice::HasProductRows($arProductId)) {
                 $result = true;
             }
         }
     }
     return $result;
 }
Example #18
0
    $arDeal['PATH_TO_COMPANY_SHOW'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_COMPANY_SHOW'], array('company_id' => $arDeal['COMPANY_ID']));
    $arDeal['CONTACT_NAME'] = CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('NAME' => $arDeal['NAME'], 'LAST_NAME' => $arDeal['LAST_NAME'], 'SECOND_NAME' => $arDeal['SECOND_NAME']), true, false);
    $strCard = '
<div class="bx-user-info-data-cont-video bx-user-info-fields" id="bx_user_info_data_cont_1">
	<div class="bx-user-info-data-name">
		<a href="' . $arDeal['PATH_TO_DEAL_SHOW'] . '">' . htmlspecialcharsbx($arDeal['TITLE']) . '</a>
	</div>
	<div class="bx-user-info-data-info">';
    if (!empty($arDeal['STAGE_ID'])) {
        $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_STAGE_ID') . '</span>:
		<span class="fields enumeration">' . $arResult['STAGE_LIST'][$arDeal['STAGE_ID']] . '</span>
		<br />';
    }
    $arProductRows = CCrmDeal::LoadProductRows($arDeal['ID']);
    if (count($arProductRows) > 0) {
        $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_PRODUCTS') . '</span>:<span class="fields enumeration">' . htmlspecialcharsbx(CCrmProductRow::RowsToString($arProductRows)) . '</span><br />';
    }
    if (!empty($arDeal['OPPORTUNITY'])) {
        $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_OPPORTUNITY') . '</span>:
		<span class="fields enumeration"><nobr>' . number_format($arDeal['OPPORTUNITY'], 2, ',', ' ') . ' ' . htmlspecialcharsbx(CCrmCurrency::GetCurrencyName($arDeal['CURRENCY_ID'])) . '</nobr></span>
		<br />';
    }
    if (!empty($arDeal['PROBABILITY'])) {
        $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_PROBABILITY') . '</span>:
		<span class="fields enumeration">' . intval($arDeal['PROBABILITY']) . '%</span>
		<br />';
    }
    $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_DATE_MODIFY') . '</span>:
		<span class="fields enumeration">' . FormatDate('x', MakeTimeStamp($arDeal['DATE_MODIFY']), time() + CTimeZone::GetOffset()) . '</span>
		<br />
		<br />';
Example #19
0
 foreach ($arResult['SELECTED_HEADERS'] as $headerID) {
     $arHead = isset($arHeaders[$headerID]) ? $arHeaders[$headerID] : null;
     if (!$arHead) {
         continue;
     }
     $headerID = $arHead['id'];
     if ($headerID === 'PRODUCT_ID') {
         // Special logic for PRODUCT_ROWS: expand product in 3 columns
         echo '"', isset($productRow['PRODUCT_NAME']) ? str_replace('"', '""', $productRow['PRODUCT_NAME']) : '', '";';
         echo '"', CCrmProductRow::GetPrice($productRow, ''), '";';
         echo '"', CCrmProductRow::GetQuantity($productRow, ''), '";';
         continue;
     } elseif ($headerID === 'OPPORTUNITY') {
         // Special logic for OPPORTUNITY: replace it by product row sum if it specified
         if (isset($productRow['PRODUCT_ID']) && intval($productRow['PRODUCT_ID']) > 0) {
             echo '"', round(CCrmProductRow::GetPrice($productRow) * CCrmProductRow::GetQuantity($productRow), 2), '";';
         } else {
             echo '"', isset($arLead['OPPORTUNITY']) ? strval($arLead['OPPORTUNITY']) : '', '";';
         }
         continue;
     }
     if (!isset($leadData[$headerID])) {
         switch ($headerID) {
             case 'STATUS_ID':
                 $statusID = !empty($arLead['STATUS_ID']) ? $arLead['STATUS_ID'] : '';
                 $leadData['STATUS_ID'] = isset($arResult['STATUS_LIST'][$statusID]) ? $arResult['STATUS_LIST'][$statusID] : $statusID;
                 break;
             case 'SOURCE_ID':
                 $sourceID = !empty($arLead['SOURCE_ID']) ? $arLead['SOURCE_ID'] : '';
                 $leadData['SOURCE_ID'] = isset($arResult['SOURCE_LIST'][$sourceID]) ? $arResult['SOURCE_LIST'][$sourceID] : $sourceID;
                 break;
Example #20
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));
Example #21
0
    $arResult['PREFIX'] = htmlspecialcharsbx($ownerID > 0 ? strtolower($ownerName) . '_' . strval($ownerID) : 'new_' . strtolower($ownerName));
}
$arResult['ID'] = isset($arParams['ID']) ? $arParams['ID'] : '';
if ($arResult['ID'] === '') {
    $arResult['ID'] = $arResult['PREFIX'] . '_product_editor';
}
//$arResult['CONTAINER_CLASS'] = htmlspecialcharsbx(strtolower($ownerName).'-product-rows');
$arResult['PRODUCT_DATA_FIELD_NAME'] = isset($arParams['PRODUCT_DATA_FIELD_NAME']) ? $arParams['PRODUCT_DATA_FIELD_NAME'] : 'PRODUCT_ROW_DATA';
$arResult['ENABLE_CUSTOM_PRODUCTS'] = isset($arParams['ENABLE_CUSTOM_PRODUCTS']) ? strtoupper($arParams['ENABLE_CUSTOM_PRODUCTS']) === 'Y' : true;
$arResult['ENABLE_RAW_CATALOG_PRICING'] = !isset($arParams['ENABLE_RAW_CATALOG_PRICING']) || strtoupper($arParams['ENABLE_RAW_CATALOG_PRICING']) === 'Y';
$arResult['TAX_INFOS'] = $arResult['ALLOW_TAX'] ? CCrmTax::GetVatRateInfos() : array();
$arResult['ENABLE_TAX'] = isset($arParams['ENABLE_TAX']) ? $arParams['ENABLE_TAX'] === 'Y' : false;
$arResult['ENABLE_DISCOUNT'] = isset($arParams['ENABLE_DISCOUNT']) ? $arParams['ENABLE_DISCOUNT'] === 'Y' : false;
$settings = array();
if ($ownerID > 0) {
    $settings = CCrmProductRow::LoadSettings($ownerType, $ownerID);
    if (isset($settings['ENABLE_TAX'])) {
        $arResult['ENABLE_TAX'] = (bool) $settings['ENABLE_TAX'];
    }
    if (isset($settings['ENABLE_DISCOUNT'])) {
        $arResult['ENABLE_DISCOUNT'] = (bool) $settings['ENABLE_DISCOUNT'];
    }
}
$arResult['SITE_ID'] = SITE_ID;
$arResult['CAN_ADD_PRODUCT'] = $perms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'WRITE');
// measure list items
$measureListItems = array('' => GetMessage('CRM_MEASURE_NOT_SELECTED'));
$measures = \Bitrix\Crm\Measure::getMeasures(100);
if (is_array($measures)) {
    foreach ($measures as $measure) {
        $measureListItems[$measure['ID']] = $measure['SYMBOL'];
Example #22
0
         $arResult['duplicate']++;
         if ($enableDupFile) {
             __CrmImportWriteDataToFile($duplicateFilePath, isset($_SESSION['CRM_IMPORT_FILE_HEADERS']) ? $_SESSION['CRM_IMPORT_FILE_HEADERS'] : null, $arLead['__CSV_DATA__']);
         }
     } else {
         $arLead['PERMISSION'] = 'IMPORT';
         if (!$CCrmLead->Add($arLead)) {
             $arResult['error']++;
             $arResult['error_data'][] = array('message' => $arLead['RESULT_MESSAGE'], 'data' => $arLead['__CSV_DATA__']);
             __CrmImportWriteDataToFile($errataFilePath, isset($_SESSION['CRM_IMPORT_FILE_HEADERS']) ? $_SESSION['CRM_IMPORT_FILE_HEADERS'] : null, $arLead['__CSV_DATA__']);
         } else {
             if (!empty($arLead)) {
                 if (isset($arLead['PRODUCT_ROWS']) && count($arLead['PRODUCT_ROWS']) > 0) {
                     if (!CCrmLead::SaveProductRows($arLead['ID'], $arLead['PRODUCT_ROWS'])) {
                         $arResult['error']++;
                         $arResult['error_data'][] = array('message' => CCrmProductRow::GetLastError(), 'data' => $arLead['__CSV_DATA__']);
                         __CrmImportWriteDataToFile($errataFilePath, isset($_SESSION['CRM_IMPORT_FILE_HEADERS']) ? $_SESSION['CRM_IMPORT_FILE_HEADERS'] : null, $arLead['__CSV_DATA__']);
                     }
                 }
                 $arResult['import']++;
             }
         }
     }
 }
 $_SESSION['CRM_IMPORT_FILE_POS'] = $filePos;
 $_SESSION['CRM_IMPORT_FILE_FIRST_HEADER'] = false;
 if ($arResult['error'] > 0) {
     $arResult['errata_url'] = SITE_DIR . 'bitrix/components/bitrix/crm.lead.import/show_file.php?name=errata';
 }
 if ($enableDupFile && $arResult['duplicate'] > 0) {
     $arResult['duplicate_url'] = SITE_DIR . 'bitrix/components/bitrix/crm.lead.import/show_file.php?name=duplicate';
Example #23
0
 public function executePhase()
 {
     if ($this->currentPhase === LeadConversionPhase::COMPANY_CREATION || $this->currentPhase === LeadConversionPhase::CONTACT_CREATION || $this->currentPhase === LeadConversionPhase::DEAL_CREATION) {
         if ($this->currentPhase === LeadConversionPhase::COMPANY_CREATION) {
             $entityTypeID = \CCrmOwnerType::Company;
         } elseif ($this->currentPhase === LeadConversionPhase::CONTACT_CREATION) {
             $entityTypeID = \CCrmOwnerType::Contact;
         } else {
             $entityTypeID = \CCrmOwnerType::Deal;
         }
         $entityTypeName = \CCrmOwnerType::ResolveName($entityTypeID);
         $config = $this->config->getItem($entityTypeID);
         if (!$config->isActive()) {
             return false;
         }
         /** @var \CCrmPerms $permissions */
         $permissions = $this->getUserPermissions();
         $entityID = isset($this->contextData[$entityTypeName]) ? $this->contextData[$entityTypeName] : 0;
         if ($entityID > 0) {
             if ($entityTypeID === \CCrmOwnerType::Company) {
                 if (!\CCrmCompany::Exists($entityID)) {
                     throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Company, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND);
                 }
                 $entity = new \CCrmCompany(false);
             } elseif ($entityTypeID === \CCrmOwnerType::Contact) {
                 if (!\CCrmContact::Exists($entityID)) {
                     throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Contact, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND);
                 }
                 $entity = new \CCrmContact(false);
             } else {
                 if (!\CCrmDeal::Exists($entityID)) {
                     throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND);
                 }
                 $entity = new \CCrmDeal(false);
             }
             if (!\CCrmAuthorizationHelper::CheckUpdatePermission($entityTypeName, $entityID, $permissions)) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::UPDATE_DENIED);
             }
             $fields = array('LEAD_ID' => $this->entityID);
             $entity->Update($entityID, $fields);
             $this->resultData[$entityTypeName] = $entityID;
             return true;
         }
         if (!\CCrmAuthorizationHelper::CheckCreatePermission($entityTypeName, $permissions)) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::CREATE_DENIED);
         }
         if (UserFieldSynchronizer::needForSynchronization(\CCrmOwnerType::Lead, $entityTypeID)) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::NOT_SYNCHRONIZED);
         }
         if (!ConversionSettings::getCurrent()->isAutocreationEnabled()) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::AUTOCREATION_DISABLED);
         }
         if (\CCrmBizProcHelper::HasAutoWorkflows($entityTypeID, \CCrmBizProcEventType::Create)) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::HAS_WORKFLOWS);
         }
         /** @var LeadConversionMapper $mapper */
         $mapper = $this->getMapper();
         $map = self::prepareMap($entityTypeID);
         $fields = $mapper->map($map);
         if (empty($fields)) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::EMPTY_FIELDS);
         }
         if ($entityTypeID === \CCrmOwnerType::Company) {
             $entity = new \CCrmCompany(false);
             $entityID = $entity->Add($fields);
             if ($entityID <= 0) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Company, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR);
             }
             //region BizProcess
             $arErrors = array();
             \CCrmBizProcHelper::AutoStartWorkflows(\CCrmOwnerType::Company, $entityID, \CCrmBizProcEventType::Create, $arErrors);
             //endregion
             $this->resultData[\CCrmOwnerType::CompanyName] = $entityID;
         } elseif ($entityTypeID === \CCrmOwnerType::Contact) {
             if (isset($this->resultData[\CCrmOwnerType::CompanyName])) {
                 $fields['COMPANY_ID'] = $this->resultData[\CCrmOwnerType::CompanyName];
             }
             $entity = new \CCrmContact(false);
             if (!$entity->CheckFields($fields)) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::INVALID_FIELDS, $entity->LAST_ERROR);
             }
             $entityID = $entity->Add($fields);
             if ($entityID <= 0) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Contact, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR);
             }
             //region BizProcess
             $arErrors = array();
             \CCrmBizProcHelper::AutoStartWorkflows(\CCrmOwnerType::Contact, $entityID, \CCrmBizProcEventType::Create, $arErrors);
             //endregion
             $this->resultData[\CCrmOwnerType::ContactName] = $entityID;
         } else {
             if (isset($this->resultData[\CCrmOwnerType::ContactName])) {
                 $fields['CONTACT_ID'] = $this->resultData[\CCrmOwnerType::ContactName];
             }
             if (isset($this->resultData[\CCrmOwnerType::CompanyName])) {
                 $fields['COMPANY_ID'] = $this->resultData[\CCrmOwnerType::CompanyName];
             }
             $productRows = isset($fields['PRODUCT_ROWS']) && is_array($fields['PRODUCT_ROWS']) ? $fields['PRODUCT_ROWS'] : array();
             if (!empty($productRows)) {
                 $result = \CCrmProductRow::CalculateTotalInfo('D', 0, false, $fields, $productRows);
                 $fields['OPPORTUNITY'] = isset($result['OPPORTUNITY']) ? $result['OPPORTUNITY'] : 1.0;
                 $fields['TAX_VALUE'] = isset($result['TAX_VALUE']) ? $result['TAX_VALUE'] : 0.0;
             }
             $entity = new \CCrmDeal(false);
             $entityID = $entity->Add($fields);
             if ($entityID <= 0) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR);
             }
             if (!empty($productRows)) {
                 \CCrmDeal::SaveProductRows($entityID, $productRows, false, false, false);
             }
             //region BizProcess
             $arErrors = array();
             \CCrmBizProcHelper::AutoStartWorkflows(\CCrmOwnerType::Deal, $entityID, \CCrmBizProcEventType::Create, $arErrors);
             //endregion
             $this->resultData[\CCrmOwnerType::DealName] = $entityID;
         }
         return true;
     } elseif ($this->currentPhase === LeadConversionPhase::FINALIZATION) {
         $result = \CCrmLead::GetListEx(array(), array('=ID' => $this->entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('STATUS_ID'));
         $presentFields = is_object($result) ? $result->Fetch() : null;
         if (is_array($presentFields)) {
             $fields = array();
             $statusID = isset($presentFields['STATUS_ID']) ? $presentFields['STATUS_ID'] : '';
             if ($statusID !== 'CONVERTED') {
                 $fields['STATUS_ID'] = 'CONVERTED';
             }
             if (isset($this->resultData[\CCrmOwnerType::CompanyName])) {
                 $fields['COMPANY_ID'] = $this->resultData[\CCrmOwnerType::CompanyName];
             }
             if (isset($this->resultData[\CCrmOwnerType::ContactName])) {
                 $fields['CONTACT_ID'] = $this->resultData[\CCrmOwnerType::ContactName];
             }
             if (!empty($fields)) {
                 $entity = new \CCrmLead(false);
                 if ($entity->Update($this->entityID, $fields)) {
                     //region BizProcess
                     $arErrors = array();
                     \CCrmBizProcHelper::AutoStartWorkflows(\CCrmOwnerType::Lead, $this->entityID, \CCrmBizProcEventType::Edit, $arErrors);
                     //endregion
                 }
             }
         }
         return true;
     }
     return false;
 }
Example #24
0
 $currencyID = isset($data['CURRENCY_ID']) ? $data['CURRENCY_ID'] : '';
 if ($currencyID === '') {
     $currencyID = CCrmCurrency::GetBaseCurrencyID();
 }
 $fields['CURRENCY_ID'] = $currencyID;
 $productDataFieldName = 'PRODUCT_ROWS';
 $processProductRows = isset($data['PROCESS_PRODUCT_ROWS']) ? $data['PROCESS_PRODUCT_ROWS'] === 'Y' : false;
 $productRows = array();
 if ($processProductRows) {
     $productRows = isset($data[$productDataFieldName]) ? $data[$productDataFieldName] : array();
     if (!empty($productRows)) {
         foreach ($productRows as &$productRow) {
             $productRow['CUSTOMIZED'] = 'Y';
         }
         unset($productRow);
         $result = CCrmProductRow::CalculateTotalInfo('D', 0, false, $fields, $productRows);
         $fields['OPPORTUNITY'] = isset($result['OPPORTUNITY']) ? $result['OPPORTUNITY'] : 0.0;
         $fields['TAX_VALUE'] = isset($result['TAX_VALUE']) ? $result['TAX_VALUE'] : 0.0;
     }
 }
 $assignedByID = isset($data['ASSIGNED_BY_ID']) ? intval($data['ASSIGNED_BY_ID']) : 0;
 if ($assignedByID <= 0) {
     $assignedByID = intval($curUser->GetID());
 }
 $fields['ASSIGNED_BY_ID'] = $assignedByID;
 $entity = new CCrmDeal(false);
 if (!$entity->CheckFields($fields, !$isNew ? $ID : false, array('DISABLE_USER_FIELD_CHECK' => true))) {
     __CrmMobileDealEditEndResonse(array('ERROR' => strip_tags(preg_replace("/<br[^>]*>/", "\n", $entity->LAST_ERROR))));
 } else {
     //$DB->StartTransaction();
     $successed = false;
Example #25
0
         $arFields['ORIGIN_ID'] = $originId;
     }
     $ID = $CCrmDeal->Add($arFields, true, array('REGISTER_SONET_EVENT' => true));
     $bSuccess = $ID !== false;
     if ($bSuccess) {
         $arResult['ELEMENT']['ID'] = $ID;
     }
 }
 if ($bSuccess) {
     // Save settings
     if (is_array($productRowSettings) && count($productRowSettings) > 0) {
         $arSettings = CCrmProductRow::LoadSettings('D', $arResult['ELEMENT']['ID']);
         foreach ($productRowSettings as $k => $v) {
             $arSettings[$k] = $v;
         }
         CCrmProductRow::SaveSettings('D', $arResult['ELEMENT']['ID'], $arSettings);
     }
     unset($arSettings);
 }
 if ($bSuccess && !$isExternal && $processProductRows && ($bEdit || !empty($arProd))) {
     // Suppress owner synchronization
     $bSuccess = $CCrmDeal::SaveProductRows($arResult['ELEMENT']['ID'], $arProd, true, true, false);
     if (!$bSuccess) {
         $arResult['ERROR_MESSAGE'] = GetMessage('PRODUCT_ROWS_SAVING_ERROR');
     }
 }
 if ($bSuccess) {
     if ($arFields['CONTACT_ID'] > 0 && $arFields['COMPANY_ID'] > 0 && isset($_POST['NEW_CONTACT_ID']) && $arFields['CONTACT_ID'] == $_POST['NEW_CONTACT_ID']) {
         $CrmContact = new CCrmContact();
         $arContactFields = array('COMPANY_ID' => $arFields['COMPANY_ID']);
         $bSuccess = $CrmContact->Update($arFields['CONTACT_ID'], $arContactFields, false, true, array('DISABLE_USER_FIELD_CHECK' => true));
 private function SaveOrderDataProducts($arOrder, $dealId)
 {
     if (!isset($arOrder["ITEMS"]) || !is_array($arOrder["ITEMS"])) {
         return false;
     }
     if (!$this->catalogId) {
         if ($this->arExternalSale == null) {
             $this->arExternalSale = CCrmExternalSale::GetDefaultSettings($this->externalSaleId);
         }
         $this->catalogId = CCrmCatalog::GetCatalogId($this->arExternalSale["NAME"], $this->externalSaleId, SITE_ID);
         if (!$this->catalogId) {
             if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                 $this->AddError($ex->GetID(), $ex->GetString());
             } else {
                 $this->AddError("CCA", "Catalog creation error");
             }
             return false;
         }
     }
     $arProductRows = array();
     foreach ($arOrder["ITEMS"] as $arItem) {
         $productId = 0;
         $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => $arItem["ID"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1));
         if ($arProduct = $dbProduct->Fetch()) {
             $productId = $arProduct["ID"];
         }
         $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => $arItem["ID"]);
         if ($productId == 0) {
             $res = CCrmProduct::Add($arFields);
             if ($res > 0) {
                 $productId = (int) $res;
             }
         } else {
             $res = CCrmProduct::Update($productId, $arFields);
         }
         if (!$res) {
             if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                 $this->AddError($ex->GetID(), $ex->GetString());
             } else {
                 $this->AddError("CDA", "Product creation error");
             }
             continue;
         }
         $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => $arItem["PRICE"], 'QUANTITY' => $arItem["QUANTITY"]);
     }
     if (is_array($arOrder["TAXES"])) {
         foreach ($arOrder["TAXES"] as $arItem) {
             if (intval($arItem["IN_PRICE"]) > 0) {
                 continue;
             }
             $productId = 0;
             $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => "tax_" . $arItem["NAME"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1));
             if ($arProduct = $dbProduct->Fetch()) {
                 $productId = $arProduct["ID"];
             }
             $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => "tax_" . $arItem["NAME"]);
             if ($productId == 0) {
                 $res = CCrmProduct::Add($arFields);
                 $productId = intval($res);
             } else {
                 $res = CCrmProduct::Update($productId, $arFields);
             }
             if (!$res) {
                 if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                     $this->AddError($ex->GetID(), $ex->GetString());
                 } else {
                     $this->AddError("CDA", "Product creation error");
                 }
                 continue;
             }
             $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => $arItem["PRICE"], 'QUANTITY' => 1);
         }
     }
     if (is_array($arOrder["DISCOUNTS"])) {
         foreach ($arOrder["DISCOUNTS"] as $arItem) {
             if (intval($arItem["IN_PRICE"]) > 0) {
                 continue;
             }
             $productId = 0;
             $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => "discount_" . $arItem["NAME"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1));
             if ($arProduct = $dbProduct->Fetch()) {
                 $productId = $arProduct["ID"];
             }
             $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => "discount_" . $arItem["NAME"]);
             if ($productId == 0) {
                 $res = CCrmProduct::Add($arFields);
                 $productId = intval($res);
             } else {
                 $res = CCrmProduct::Update($productId, $arFields);
             }
             if (!$res) {
                 if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                     $this->AddError($ex->GetID(), $ex->GetString());
                 } else {
                     $this->AddError("CDA", "Product creation error");
                 }
                 continue;
             }
             $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => -$arItem["PRICE"], 'QUANTITY' => 1);
         }
     }
     CCrmProductRow::SaveRows("D", $dealId, $arProductRows, null, false, false);
     return true;
 }
Example #27
0
            $arBizprocList = array();
            foreach ($arDeal['BIZPROC_LIST'] as $arBizproc) {
                $arBizprocList[] = array('ICONCLASS' => 'bizproc', 'TITLE' => $arBizproc['DESCRIPTION'], 'TEXT' => $arBizproc['NAME'], 'ONCLICK' => "jsUtils.Redirect([], '" . CUtil::JSEscape($arBizproc['PATH_TO_BIZPROC_START']) . "');");
            }
            $arActions[] = array('ICONCLASS' => 'bizproc', 'TITLE' => GetMessage('CRM_DEAL_BIZPROC_LIST_TITLE'), 'TEXT' => GetMessage('CRM_DEAL_BIZPROC_LIST'), 'MENU' => $arBizprocList);
        }
    }
    if ($arDeal['DELETE'] && !$arResult['INTERNAL']) {
        $arActions[] = array('SEPARATOR' => true);
        $arActions[] = array('ICONCLASS' => 'delete', 'TITLE' => GetMessage('CRM_DEAL_DELETE_TITLE'), 'TEXT' => GetMessage('CRM_DEAL_DELETE'), 'ONCLICK' => "crm_deal_delete_grid('" . CUtil::JSEscape(GetMessage('CRM_DEAL_DELETE_TITLE')) . "', '" . CUtil::JSEscape(GetMessage('CRM_DEAL_DELETE_CONFIRM')) . "', '" . CUtil::JSEscape(GetMessage('CRM_DEAL_DELETE')) . "', '" . CUtil::JSEscape($arDeal['PATH_TO_DEAL_DELETE']) . "')");
    }
    $contactID = isset($arDeal['~CONTACT_ID']) ? intval($arDeal['~CONTACT_ID']) : 0;
    $companyID = isset($arDeal['~COMPANY_ID']) ? intval($arDeal['~COMPANY_ID']) : 0;
    $resultItem = array('id' => $arDeal['ID'], 'actions' => $arActions, 'data' => $arDeal, 'editable' => !$arDeal['EDIT'] ? $arResult['INTERNAL'] ? 'N' : $arColumns : 'Y', 'columns' => array('DEAL_SUMMARY' => CCrmViewHelper::RenderInfo($arDeal['PATH_TO_DEAL_SHOW'], isset($arDeal['TITLE']) ? $arDeal['TITLE'] : '[' . $arDeal['ID'] . ']', $arDeal['DEAL_TYPE_NAME'], '_self'), 'DEAL_CLIENT' => $contactID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID, 'TITLE' => isset($arDeal['~CONTACT_FORMATTED_NAME']) ? $arDeal['~CONTACT_FORMATTED_NAME'] : '[' . $contactID . ']', 'PREFIX' => "DEAL_{$arDeal['~ID']}", 'DESCRIPTION' => isset($arDeal['~COMPANY_TITLE']) ? $arDeal['~COMPANY_TITLE'] : '')) : ($companyID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID, 'TITLE' => isset($arDeal['~COMPANY_TITLE']) ? $arDeal['~COMPANY_TITLE'] : '[' . $companyID . ']', 'PREFIX' => "DEAL_{$arDeal['~ID']}"), $arDeal['PATH_TO_COMPANY_SHOW'], isset($arDeal['COMPANY_TITLE']) ? $arDeal['COMPANY_TITLE'] : '', '') : ''), 'COMPANY_ID' => $companyID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID, 'TITLE' => isset($arDeal['~COMPANY_TITLE']) ? $arDeal['~COMPANY_TITLE'] : '[' . $companyID . ']', 'PREFIX' => "DEAL_{$arDeal['~ID']}"), $arDeal['PATH_TO_COMPANY_SHOW'], isset($arDeal['COMPANY_TITLE']) ? $arDeal['COMPANY_TITLE'] : '', '') : '', 'CONTACT_ID' => $contactID > 0 ? CCrmViewHelper::PrepareClientInfo(array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID, 'TITLE' => isset($arDeal['~CONTACT_FORMATTED_NAME']) ? $arDeal['~CONTACT_FORMATTED_NAME'] : '[' . $contactID . ']', 'PREFIX' => "DEAL_{$arDeal['~ID']}")) : '', 'TITLE' => '<a target="_self" href="' . $arDeal['PATH_TO_DEAL_SHOW'] . '"
					class="' . ($arDeal['BIZPROC_STATUS'] != '' ? 'bizproc bizproc_status_' . $arDeal['BIZPROC_STATUS'] : '') . '"
					' . ($arDeal['BIZPROC_STATUS_HINT'] != '' ? 'onmouseover="BX.hint(this, \'' . CUtil::JSEscape($arDeal['BIZPROC_STATUS_HINT']) . '\');"' : '') . '>' . $arDeal['TITLE'] . '</a>', 'CLOSED' => $arDeal['CLOSED'] == 'Y' ? GetMessage('MAIN_YES') : GetMessage('MAIN_NO'), 'ASSIGNED_BY' => $arDeal['~ASSIGNED_BY'] > 0 ? '<a href="' . $arDeal['PATH_TO_USER_PROFILE'] . '" id="balloon_' . $arResult['GRID_ID'] . '_' . $arDeal['ID'] . '">' . $arDeal['ASSIGNED_BY'] . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arDeal['~ASSIGNED_BY'] . ', "balloon_' . $arResult['GRID_ID'] . '_' . $arDeal['ID'] . '", "");</script>' : '', 'COMMENTS' => htmlspecialcharsback($arDeal['COMMENTS']), 'SUM' => '<nobr>' . $arDeal['FORMATTED_OPPORTUNITY'] . '</nobr>', 'OPPORTUNITY' => '<nobr>' . $arDeal['OPPORTUNITY'] . '</nobr>', 'PROBABILITY' => intval($arDeal['PROBABILITY']) . '%', 'DATE_CREATE' => '<nobr>' . FormatDate('SHORT', MakeTimeStamp($arDeal['DATE_CREATE'])) . '</nobr>', 'DATE_MODIFY' => '<nobr>' . FormatDate('SHORT', MakeTimeStamp($arDeal['DATE_MODIFY'])) . '</nobr>', 'TYPE_ID' => isset($arResult['TYPE_LIST'][$arDeal['TYPE_ID']]) ? $arResult['TYPE_LIST'][$arDeal['TYPE_ID']] : $arDeal['TYPE_ID'], 'EVENT_ID' => isset($arResult['EVENT_LIST'][$arDeal['EVENT_ID']]) ? $arResult['EVENT_LIST'][$arDeal['EVENT_ID']] : $arDeal['EVENT_ID'], 'CURRENCY_ID' => CCrmCurrency::GetCurrencyName($arDeal['CURRENCY_ID']), 'PRODUCT_ID' => isset($arDeal['PRODUCT_ROWS']) ? htmlspecialcharsbx(CCrmProductRow::RowsToString($arDeal['PRODUCT_ROWS'])) : '', 'STATE_ID' => isset($arResult['STATE_LIST'][$arDeal['STATE_ID']]) ? $arResult['STATE_LIST'][$arDeal['STATE_ID']] : $arDeal['STATE_ID'], 'STAGE_ID' => CCrmViewHelper::RenderDealStageControl(array('PREFIX' => "{$arResult['GRID_ID']}_PROGRESS_BAR_", 'ENTITY_ID' => $arDeal['~ID'], 'CURRENT_ID' => $arDeal['~STAGE_ID'], 'SERVICE_URL' => '/bitrix/components/bitrix/crm.deal.list/list.ajax.php', 'READ_ONLY' => !(isset($arDeal['EDIT']) && $arDeal['EDIT'] === true))), 'ORIGINATOR_ID' => isset($arDeal['ORIGINATOR_NAME']) ? $arDeal['ORIGINATOR_NAME'] : '', 'CREATED_BY' => $arDeal['~CREATED_BY'] > 0 ? '<a href="' . $arDeal['PATH_TO_USER_CREATOR'] . '" id="balloon_' . $arResult['GRID_ID'] . '_' . $arDeal['ID'] . '">' . $arDeal['CREATED_BY_FORMATTED_NAME'] . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arDeal['~CREATED_BY'] . ', "balloon_' . $arResult['GRID_ID'] . '_' . $arDeal['ID'] . '", "");</script>' : '', 'MODIFY_BY' => $arDeal['~MODIFY_BY'] > 0 ? '<a href="' . $arDeal['PATH_TO_USER_MODIFIER'] . '" id="balloon_' . $arResult['GRID_ID'] . '_' . $arDeal['ID'] . '">' . $arDeal['MODIFY_BY_FORMATTED_NAME'] . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arDeal['~MODIFY_BY'] . ', "balloon_' . $arResult['GRID_ID'] . '_' . $arDeal['ID'] . '", "");</script>' : '') + $arResult['DEAL_UF'][$sKey]);
    $userActivityID = isset($arDeal['~ACTIVITY_ID']) ? intval($arDeal['~ACTIVITY_ID']) : 0;
    $commonActivityID = isset($arDeal['~C_ACTIVITY_ID']) ? intval($arDeal['~C_ACTIVITY_ID']) : 0;
    if ($userActivityID > 0) {
        $resultItem['columns']['ACTIVITY_ID'] = CCrmViewHelper::RenderNearestActivity(array('ENTITY_TYPE_NAME' => CCrmOwnerType::ResolveName(CCrmOwnerType::Deal), 'ENTITY_ID' => $arDeal['~ID'], 'ENTITY_RESPONSIBLE_ID' => $arDeal['~ASSIGNED_BY'], 'GRID_MANAGER_ID' => $gridManagerID, 'ACTIVITY_ID' => $userActivityID, 'ACTIVITY_SUBJECT' => isset($arDeal['~ACTIVITY_SUBJECT']) ? $arDeal['~ACTIVITY_SUBJECT'] : '', 'ACTIVITY_TIME' => isset($arDeal['~ACTIVITY_TIME']) ? $arDeal['~ACTIVITY_TIME'] : '', 'ACTIVITY_EXPIRED' => isset($arDeal['~ACTIVITY_EXPIRED']) ? $arDeal['~ACTIVITY_EXPIRED'] : '', 'ALLOW_EDIT' => $arDeal['EDIT'], 'MENU_ITEMS' => $arActivityMenuItems));
        $counterData = array('CURRENT_USER_ID' => $currentUserID, 'ENTITY' => $arDeal, 'ACTIVITY' => array('RESPONSIBLE_ID' => $currentUserID, 'TIME' => isset($arDeal['~ACTIVITY_TIME']) ? $arDeal['~ACTIVITY_TIME'] : '', 'IS_CURRENT_DAY' => isset($arDeal['~ACTIVITY_IS_CURRENT_DAY']) ? $arDeal['~ACTIVITY_IS_CURRENT_DAY'] : false));
        if (CCrmUserCounter::IsReckoned(CCrmUserCounter::CurrentDealActivies, $counterData)) {
            $resultItem['columnClasses'] = array('ACTIVITY_ID' => 'crm-list-deal-today');
        }
    } elseif ($commonActivityID > 0) {
        $resultItem['columns']['ACTIVITY_ID'] = CCrmViewHelper::RenderNearestActivity(array('ENTITY_TYPE_NAME' => CCrmOwnerType::ResolveName(CCrmOwnerType::Deal), 'ENTITY_ID' => $arDeal['~ID'], 'ENTITY_RESPONSIBLE_ID' => $arDeal['~ASSIGNED_BY'], 'GRID_MANAGER_ID' => $gridManagerID, 'ACTIVITY_ID' => $commonActivityID, 'ACTIVITY_SUBJECT' => isset($arDeal['~C_ACTIVITY_SUBJECT']) ? $arDeal['~C_ACTIVITY_SUBJECT'] : '', 'ACTIVITY_TIME' => isset($arDeal['~C_ACTIVITY_TIME']) ? $arDeal['~C_ACTIVITY_TIME'] : '', 'ACTIVITY_RESPONSIBLE_ID' => isset($arDeal['~C_ACTIVITY_RESP_ID']) ? intval($arDeal['~C_ACTIVITY_RESP_ID']) : 0, 'ACTIVITY_RESPONSIBLE_LOGIN' => isset($arDeal['~C_ACTIVITY_RESP_LOGIN']) ? $arDeal['~C_ACTIVITY_RESP_LOGIN'] : '', 'ACTIVITY_RESPONSIBLE_NAME' => isset($arDeal['~C_ACTIVITY_RESP_NAME']) ? $arDeal['~C_ACTIVITY_RESP_NAME'] : '', 'ACTIVITY_RESPONSIBLE_LAST_NAME' => isset($arDeal['~C_ACTIVITY_RESP_LAST_NAME']) ? $arDeal['~C_ACTIVITY_RESP_LAST_NAME'] : '', 'ACTIVITY_RESPONSIBLE_SECOND_NAME' => isset($arDeal['~C_ACTIVITY_RESP_SECOND_NAME']) ? $arDeal['~C_ACTIVITY_RESP_SECOND_NAME'] : '', 'NAME_TEMPLATE' => $arParams['NAME_TEMPLATE'], 'PATH_TO_USER_PROFILE' => $arParams['PATH_TO_USER_PROFILE'], 'ALLOW_EDIT' => $arDeal['EDIT'], 'MENU_ITEMS' => $arActivityMenuItems));
    } else {
        $resultItem['columns']['ACTIVITY_ID'] = CCrmViewHelper::RenderNearestActivity(array('ENTITY_TYPE_NAME' => CCrmOwnerType::ResolveName(CCrmOwnerType::Deal), 'ENTITY_ID' => $arDeal['~ID'], 'ENTITY_RESPONSIBLE_ID' => $arDeal['~ASSIGNED_BY'], 'GRID_MANAGER_ID' => $gridManagerID, 'ALLOW_EDIT' => $arDeal['EDIT'], 'MENU_ITEMS' => $arActivityMenuItems));
        $counterData = array('CURRENT_USER_ID' => $currentUserID, 'ENTITY' => $arDeal);
        if (CCrmUserCounter::IsReckoned(CCrmUserCounter::CurrentDealActivies, $counterData)) {
            $resultItem['columnClasses'] = array('ACTIVITY_ID' => 'crm-list-enitity-action-need');