- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/recycling/invoicebinder.php
- Класс: Bitrix\Crm\Recycling\InvoiceBinder
- Вызов: InvoiceBinder::unbindEntities
public function unbindEntities($associatedEntityTypeID, $associatedEntityID, array $entityIDs)
{
if($associatedEntityTypeID === \CCrmOwnerType::Contact)
{
$fieldName = 'UF_CONTACT_ID';
}
else if($associatedEntityTypeID === \CCrmOwnerType::Company)
{
$fieldName = 'UF_COMPANY_ID';
}
else if($associatedEntityTypeID === \CCrmOwnerType::Deal)
{
$fieldName = 'UF_DEAL_ID';
}
else
{
$entityTypeName = \CCrmOwnerType::ResolveName($associatedEntityTypeID);
throw new Main\NotSupportedException("Entity '{$entityTypeName}' not supported in current context.");
}
$dbResult = \CCrmInvoice::GetList(
array('ID' => 'ASC'),
array('@ID' => $entityIDs),
false,
false,
array('ID', $fieldName)
);
$entity = new \CCrmInvoice(false);
while($fields = $dbResult->Fetch())
{
if(isset($fields[$fieldName]) && $fields[$fieldName] == $associatedEntityID)
{
$entity->Update(
$fields['ID'],
array($fieldName => null),
$this->getUnbindUpdateOptions((int)$associatedEntityTypeID, [$associatedEntityID]),
);
}
}
}