- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_invoice.php
- Класс: \CAllCrmInvoice
- Вызов: CAllCrmInvoice::GetProperties
static function GetProperties($ID, $personTypeId)
{
if(!CModule::IncludeModule('sale'))
{
return false;
}
$result = false;
$bTaxMode = CCrmTax::isTaxMode();
$ID = intval($ID);
$personTypeId = intval($personTypeId);
// if ($ID <= 0 || $personTypeId <= 0) return false;
$locationId = null;
$arPropValues = array();
if ($ID > 0)
{
$query = new Bitrix\Main\Entity\Query(Bitrix\Crm\Invoice\Internals\InvoicePropsValueTable::getEntity());
$query->registerRuntimeField(
'',
new Bitrix\Main\Entity\ReferenceField('LOCATION',
Bitrix\Sale\Location\LocationTable::getEntity(),
[
'=this.PROPERTY.TYPE' => ['?', 'LOCATION'],
'=this.VALUE' => 'ref.CODE'
],
['join_type' => 'LEFT']
)
);
$query->setSelect(
[
'ID',
'ORDER_PROPS_ID',
'VALUE',
'PROPERTY_TYPE' => 'PROPERTY.TYPE',
'LOCATION_ID' => 'LOCATION.ID'
]
);
$query->setFilter(['=ORDER_ID' => $ID, '=PROPERTY.ACTIVE' => 'Y']);
$query->setOrder(['PROPERTY.SORT' => 'ASC']);
$res = $query->exec();
while ($row = $res->fetch())
{
$arPropValues[intval($row['ORDER_PROPS_ID'])] =
$row['PROPERTY_TYPE'] === 'LOCATION' ? $row['LOCATION_ID'] : $row['VALUE'];
}
}
$arFilter = array("ACTIVE" => "Y");
if ($personTypeId > 0)
{
$arFilter["PERSON_TYPE_ID"] = $personTypeId;
}
$dbRes = \Bitrix\Crm\Invoice\Property::getList([
'select' => ["*", 'GROUP_SORT' => 'GROUP.SORT'],
'filter' => $arFilter,
'order' => [
"GROUP_SORT" => "ASC",
"PROPS_GROUP_ID" => "ASC",
"SORT" => "ASC",
"NAME" => "ASC"
]
]);
$propertyGroupId = -1;
$arResult = array();
while ($arProperties = $dbRes->fetch())
{
$arProperties = CSaleOrderPropsAdapter::convertNewToOld($arProperties);
if (intval($arProperties["PROPS_GROUP_ID"]) != $propertyGroupId)
$propertyGroupId = intval($arProperties["PROPS_GROUP_ID"]);
$curVal = $arPropValues[intval($arProperties["ID"])];
if ($arProperties["CODE"] == "LOCATION" && $bTaxMode) // required field
{
$arResult['PR_LOCATION'] = array(
'FIELDS' => $arProperties,
'VALUE' => $curVal == '0' ? '' : $curVal
);
}
$arResult['PR_INVOICE_'.$arProperties['ID']] = array(
'FIELDS' => $arProperties,
'VALUE' => $curVal
);
}
if (count($arResult) > 0)
$result = $arResult;
return $result;
}