- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/statistics/companyactivitystreamstatisticentry.php
- Класс: Bitrix\Crm\Statistics\CompanyActivityStreamStatisticEntry
- Вызов: CompanyActivityStreamStatisticEntry::register
static function register($ownerID, array $entityFields = null, array $options = null)
{
if(!is_int($ownerID))
$ownerID = (int)$ownerID;
if($ownerID <= 0)
throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
if(!is_array($options))
$options = array();
$date = isset($options['DATE']) ? $options['DATE'] : null;
if(!$date)
throw new Main\ArgumentException('Options DATE must be specified.', 'DATE');
$providerId = isset($options['PROVIDER_ID']) ? $options['PROVIDER_ID'] : null;
if(!$providerId)
throw new Main\ArgumentException('Options PROVIDER_ID must be specified.', 'PROVIDER_ID');
$providerTypeId = isset($options['PROVIDER_TYPE_ID']) ? $options['PROVIDER_TYPE_ID'] : null;
if(!$providerTypeId)
throw new Main\ArgumentException('Options PROVIDER_TYPE_ID must be specified.', 'PROVIDER_TYPE_ID');
$value = isset($options['VALUE']) && is_array($options['VALUE']) ? $options['VALUE'] : null;
if(!$value)
throw new Main\ArgumentException('Options VALUE must be specified.', 'VALUE');
if(!is_array($entityFields))
{
$dbResult = \CCrmCompany::GetListEx(
array(),
array('=ID' => $ownerID, 'CHECK_PERMISSIONS' => 'N'),
false,
false,
array('ASSIGNED_BY_ID')
);
$entityFields = is_object($dbResult) ? $dbResult->Fetch() : null;
if(!is_array($entityFields))
{
return false;
}
}
$responsibleID = isset($entityFields['ASSIGNED_BY_ID']) ? (int)$entityFields['ASSIGNED_BY_ID'] : 0;
$incomingQty = isset($value[StatisticsStream::Incoming]) ? (int)$value[StatisticsStream::Incoming] : 0;
$outgoingQty = isset($value[StatisticsStream::Outgoing]) ? (int)$value[StatisticsStream::Outgoing] : 0;
$reversingQty = isset($value[StatisticsStream::Reversing]) ? (int)$value[StatisticsStream::Reversing] : 0;
$missingQty = isset($value[StatisticsStream::Missing]) ? (int)$value[StatisticsStream::Missing] : 0;
if ($incomingQty === 0 && $outgoingQty === 0 && $reversingQty === 0)
{
CompanyActivityStreamStatisticsTable::delete(array(
'OWNER_ID' => $ownerID,
'DEADLINE_DATE' => $date,
'PROVIDER_ID' => $providerId,
'PROVIDER_TYPE_ID' => $providerTypeId
));
return true;
}
$present = self::get($ownerID, $date, $providerId, $providerTypeId);
if(is_array($present))
{
if($responsibleID === (int)$present['RESPONSIBLE_ID']
&& $incomingQty === (int)$present['INCOMING_QTY']
&& $outgoingQty === (int)$present['OUTGOING_QTY']
&& $reversingQty === (int)$present['REVERSING_QTY']
&& $missingQty === (int)$present['MISSING_QTY']
)
return true;
if($responsibleID !== (int)$present['RESPONSIBLE_ID'])
{
CompanyActivityStreamStatisticsTable::synchronize(
$ownerID,
array('RESPONSIBLE_ID' => $responsibleID)
);
}
}
$data = array(
'OWNER_ID' => $ownerID,
'DEADLINE_DATE' => $date,
'PROVIDER_ID' => $providerId,
'PROVIDER_TYPE_ID' => $providerTypeId,
'RESPONSIBLE_ID' => $responsibleID,
'INCOMING_QTY' => $incomingQty,
'OUTGOING_QTY' => $outgoingQty,
'REVERSING_QTY' => $reversingQty,
'MISSING_QTY' => $missingQty
);
CompanyActivityStreamStatisticsTable::upsert($data);
return true;
}