- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/entitymanagefacility.php
- Класс: Bitrix\Crm\EntityManageFacility
- Вызов: EntityManageFacility::addDeal
public function addDeal(array &$fields, $updateSearch = true, $options = array())
{
$this->clearErrors();
if (!$this->canAddDeal())
{
return null;
}
if ($this->selector->getCompanyId())
{
$fields['COMPANY_ID'] = $this->selector->getCompanyId();
if (!$this->selector->getContactId())
{
$userPermissions = \CCrmPerms::getUserPermissions($this->getUserId($fields));
$fields['CONTACT_IDS'] = array_filter(
Binding\ContactCompanyTable::getCompanyContactIDs($fields['COMPANY_ID']),
function ($contactId) use ($userPermissions)
{
return \CCrmContact::CheckReadPermission($contactId, $userPermissions);
}
);
}
}
if ($this->selector->getContactId())
{
$fields['CONTACT_ID'] = $this->selector->getContactId();
}
if (!isset($options['DISABLE_USER_FIELD_CHECK']))
{
$options['DISABLE_USER_FIELD_CHECK'] = true;
}
// use entity configuration setting when create
if (!isset($fields['OPENED']) || empty($fields['OPENED']))
{
$fields['OPENED'] = Settings\DealSettings::getCurrent()->getOpenedFlag() ? 'Y' : 'N';
}
$deal = new \CCrmDeal(false);
$dealId = $deal->add($fields, $updateSearch, $options);
if (!$dealId)
{
$this->errors[] = $deal->LAST_ERROR;
return null;
}
$this->traceEntity(\CCrmOwnerType::Deal, $dealId);
return $dealId;
}