- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_document_deal.php
- Класс: \CCrmDocumentDeal
- Вызов: CCrmDocumentDeal::createTestDocument
static function createTestDocument(string $documentType, array $fields, int $createdById): ?string
{
if (empty($fields))
{
return null;
}
$documentInfo = self::GetDocumentInfo($documentType);
if (empty($documentInfo))
{
$documentInfo['TYPE'] = $documentType;
}
$fields = self::performTypeCast($documentInfo, $fields);
$fields = self::performTypeCast4CategoryAndStage($fields);
$deal = new CCrmDeal(true);
$id = $deal->Add(
$fields,
true,
[
'DISABLE_USER_FIELD_CHECK' => true,
'REGISTER_SONET_EVENT' => true,
'CURRENT_USER' => $createdById,
]
);
if (!$id || $id <= 0)
{
throw new Exception($deal->LAST_ERROR);
}
if (isset($arFields['TRACKING_SOURCE_ID']))
{
Crm\Tracking\UI\Details::saveEntityData(\CCrmOwnerType::Deal, $id, $arFields);
}
$CCrmBizProc = new CCrmBizProc('DEAL');
if (false === $CCrmBizProc->CheckFields(false, true))
{
throw new Exception($CCrmBizProc->LAST_ERROR);
}
if (!$CCrmBizProc->StartWorkflow($id))
{
throw new Exception($CCrmBizProc->LAST_ERROR);
}
// no automation
return \CCrmOwnerType::DealName . '_' . $id;
}