示例#1
0
    $personTypeID = $personTypes['CONTACT'];
}
$arResult['PERSON_TYPE_ID'] = $personTypeID;
$arResult['PAYER_INFO_FORMAT'] = $personTypeID > 0 ? CCrmMobileHelper::PrepareInvoiceClientInfoFormat($personTypeID) : '';
//<-- PERSON_TYPE_ID
// PAY_SYSTEM -->
$arResult['PAY_SYSTEMS'] = CCrmPaySystem::GetPaySystemsListItems($personTypeID);
if ($entityID > 0) {
    $paySystemID = isset($arFields['~PAY_SYSTEM_ID']) ? intval($arFields['~PAY_SYSTEM_ID']) : 0;
} elseif (!empty($arResult['PAY_SYSTEMS'])) {
    $paySystemID = $arFields['~PAY_SYSTEM_ID'] = $arFields['PAY_SYSTEM_ID'] = array_shift(array_keys($arResult['PAY_SYSTEMS']));
}
//<-- PAY_SYSTEM
// INVOICE_PROPERTIES -->
$arFields['INVOICE_PROPERTIES'] = array();
$properties = CCrmInvoice::GetProperties($entityID, $personTypeID);
if (!is_array($properties)) {
    $properties = array();
}
if ($entityID === 0) {
    CCrmInvoice::__RewritePayerInfo($companyID, $contactID, $properties);
}
$arFields['INVOICE_PROPERTIES'] = $properties;
$arResult['PAYER_REQUISITES'] = $personTypeID > 0 ? CCrmMobileHelper::PrepareInvoiceClientRequisites($personTypeID, $properties) : array();
//<-- INVOICE_PROPERTIES
CCrmMobileHelper::PrepareInvoiceItem($arFields, $arParams, array('PAY_SYSTEMS' => $arResult['PAY_SYSTEMS'], 'INVOICE_PROPERTIES' => $properties), array('ENABLE_MULTI_FIELDS' => true, 'ENABLE_PAYER_INFO' => true, 'ENABLE_LOCATION' => true));
$arResult['ENABLE_LOCATION'] = $taxMode === 'EXT';
// PRODUCT_ROWS, TAX_INFOS, SUM_BRUTTO, SUM_NETTO -->
$arResult['PRODUCT_ROWS'] = array();
if ($entityID > 0) {
    $rows = CCrmInvoice::GetProductRows($entityID);
 public function map(EntityConversionMap $map, array $options = null)
 {
     $srcFields = $this->getSourceFields();
     if (empty($srcFields)) {
         return array();
     }
     $dstFields = array();
     $dstEntityTypeID = $map->getDestinationEntityTypeID();
     foreach ($map->getItems() as $item) {
         $dstFieldID = $item->getDestinationField();
         //Skip empty binding
         if ($dstFieldID === '-') {
             continue;
         }
         $srcFieldID = $item->getSourceField();
         if ((!isset($srcFields[$srcFieldID]) || $srcFields[$srcFieldID] === '') && $srcFieldID !== 'PRODUCT_ROWS') {
             $altSrcFieldID = '';
             foreach ($item->getAlternativeSourceFields() as $fieldID) {
                 if (isset($srcFields[$fieldID])) {
                     $altSrcFieldID = $fieldID;
                     break;
                 }
             }
             if ($altSrcFieldID !== '') {
                 $srcFieldID = $altSrcFieldID;
             }
         }
         if ($dstFieldID === '') {
             $dstFieldID = $srcFieldID;
         }
         if (strpos($srcFieldID, 'UF_') === 0 && strpos($dstFieldID, 'UF_') === 0) {
             self::mapUserField(\CCrmOwnerType::Deal, $srcFieldID, $srcFields, $dstEntityTypeID, $dstFieldID, $dstFields, $options);
         } elseif ($srcFieldID === 'PRODUCT_ROWS') {
             $productRows = \CCrmDeal::LoadProductRows($this->srcEntityID);
             if (count($productRows) > 0) {
                 if ($dstEntityTypeID === \CCrmOwnerType::Invoice) {
                     $currencyID = isset($srcFields['CURRENCY_ID']) ? $srcFields['CURRENCY_ID'] : '';
                     if ($currencyID === '' || !\CCrmCurrency::IsExists($currencyID)) {
                         $currencyID = \CCrmCurrency::GetBaseCurrencyID();
                     }
                     $actualRows = \CCrmInvoice::ProductRows2BasketItems($productRows, $currencyID, \CCrmInvoice::GetCurrencyID());
                     if (count($actualRows) > 0) {
                         foreach ($actualRows as &$productRow) {
                             unset($productRow['ID']);
                         }
                         unset($productRow);
                         $dstFields[$dstFieldID] = $actualRows;
                     }
                 } else {
                     foreach ($productRows as &$productRow) {
                         unset($productRow['ID']);
                     }
                     unset($productRow);
                     $dstFields[$dstFieldID] = $productRows;
                 }
             }
         } elseif (isset($srcFields[$srcFieldID])) {
             $dstFields[$dstFieldID] = $srcFields[$srcFieldID];
         }
     }
     if (!empty($dstFields)) {
         if ($dstEntityTypeID === \CCrmOwnerType::Invoice) {
             $dstFields['UF_DEAL_ID'] = $this->srcEntityID;
             //region Prepare Invoice Properties
             $dstFields['INVOICE_PROPERTIES'] = array();
             $invoiceEntity = new \CCrmInvoice(false);
             $companyID = isset($dstFields['UF_COMPANY_ID']) ? (int) $dstFields['UF_COMPANY_ID'] : 0;
             $contactID = isset($dstFields['UF_CONTACT_ID']) ? (int) $dstFields['UF_CONTACT_ID'] : 0;
             $personTypeID = 0;
             $personTypes = \CCrmPaySystem::getPersonTypeIDs();
             if ($companyID > 0 && isset($personTypes['COMPANY'])) {
                 $personTypeID = $personTypes['COMPANY'];
             } elseif (isset($personTypes['CONTACT'])) {
                 $personTypeID = $personTypes['CONTACT'];
             }
             $properties = $invoiceEntity->GetProperties(0, $personTypeID);
             if (is_array($properties)) {
                 \CCrmInvoice::__RewritePayerInfo($companyID, $contactID, $invoiceProperties);
                 foreach ($properties as $property) {
                     $dstFields['INVOICE_PROPERTIES'][$property['FIELDS']['ID']] = $property['VALUE'];
                 }
             }
             //endregion
         } elseif ($dstEntityTypeID === \CCrmOwnerType::Quote) {
             $dstFields['DEAL_ID'] = $this->srcEntityID;
         }
     }
     return $dstFields;
 }
示例#3
0
 public static function PrepareInvoiceItem(&$item, &$params, $enums = array(), $options = array())
 {
     $itemID = intval($item['~ID']);
     if (isset($params['INVOICE_SHOW_URL_TEMPLATE'])) {
         $item['SHOW_URL'] = CComponentEngine::makePathFromTemplate($params['INVOICE_SHOW_URL_TEMPLATE'], array('invoice_id' => $itemID));
     }
     if (isset($params['INVOICE_EDIT_URL_TEMPLATE'])) {
         $item['EDIT_URL'] = CComponentEngine::makePathFromTemplate($params['INVOICE_EDIT_URL_TEMPLATE'], array('invoice_id' => $itemID));
     }
     if (!isset($item['~ACCOUNT_NUMBER'])) {
         $item['~ACCOUNT_NUMBER'] = $item['ACCOUNT_NUMBER'] = '';
     }
     if (!isset($item['~DATE_BILL'])) {
         $item['~DATE_BILL'] = $item['DATE_BILL'] = '';
     } else {
         $item['~DATE_BILL'] = ConvertTimeStamp(MakeTimeStamp($item['~DATE_BILL']), 'SHORT', SITE_ID);
         $item['DATE_BILL'] = htmlspecialcharsbx($item['~DATE_BILL']);
     }
     if (!isset($item['~DATE_PAY_BEFORE'])) {
         $item['~DATE_PAY_BEFORE'] = $item['DATE_PAY_BEFORE'] = '';
         $item['DATE_PAY_BEFORE_STAMP'] = 0;
     }
     if ($item['~DATE_PAY_BEFORE'] !== '') {
         $item['~DATE_PAY_BEFORE'] = ConvertTimeStamp(MakeTimeStamp($item['~DATE_PAY_BEFORE']), 'SHORT', SITE_ID);
         $item['DATE_PAY_BEFORE'] = htmlspecialcharsbx($item['~DATE_PAY_BEFORE']);
     }
     if (!isset($item['~ORDER_TOPIC'])) {
         $item['~ORDER_TOPIC'] = $item['ORDER_TOPIC'] = '';
     }
     // COMMENTS -->
     if (!isset($item['~COMMENTS'])) {
         $item['~COMMENTS'] = $item['COMMENTS'] = '';
     }
     if (!isset($item['~USER_DESCRIPTION'])) {
         $item['~USER_DESCRIPTION'] = $item['USER_DESCRIPTION'] = '';
     }
     //<-- COMMENTS
     // STATUS -->
     if (!isset($item['~STATUS_ID'])) {
         $item['~STATUS_ID'] = $item['STATUS_ID'] = '';
     }
     $statusID = $item['~STATUS_ID'];
     if ($statusID !== '') {
         $statuses = self::GetStatusList('INVOICE_STATUS');
         if (!isset($statuses[$statusID])) {
             $item['~STATUS_TEXT'] = $item['STATUS_TEXT'];
         } else {
             $item['~STATUS_TEXT'] = $statuses[$statusID];
             $item['STATUS_TEXT'] = htmlspecialcharsbx($item['~STATUS_TEXT']);
         }
     }
     //<-- STATUS
     //PRICE, CURRENCY -->
     $price = isset($item['~PRICE']) ? doubleval($item['~PRICE']) : 0.0;
     $item['~PRICE'] = $item['PRICE'] = $price;
     $currencyID = isset($item['~CURRENCY']) ? $item['~CURRENCY'] : '';
     if ($currencyID === '') {
         $currencyID = $item['~CURRENCY'] = CCrmCurrency::GetBaseCurrencyID();
         $item['CURRENCY'] = htmlspecialcharsbx($currencyID);
     }
     $item['~CURRENCY_NAME'] = CCrmCurrency::GetCurrencyName($currencyID);
     $item['CURRENCY_NAME'] = htmlspecialcharsbx($item['~CURRENCY_NAME']);
     $item['~FORMATTED_PRICE'] = CCrmCurrency::MoneyToString($price, $currencyID);
     $item['FORMATTED_PRICE'] = strip_tags($item['~FORMATTED_PRICE']);
     //<-- PRICE, CURRENCY
     //DEAL -->
     $dealID = isset($item['~UF_DEAL_ID']) ? intval($item['~UF_DEAL_ID']) : 0;
     $item['~DEAL_ID'] = $item['DEAL_ID'] = $dealID;
     if ($dealID <= 0) {
         $item['~DEAL_TITLE'] = $item['DEAL_TITLE'] = '';
     } else {
         $item['~DEAL_TITLE'] = CCrmOwnerType::GetCaption(CCrmOwnerType::Deal, $dealID);
         $item['DEAL_TITLE'] = htmlspecialcharsbx($item['~DEAL_TITLE']);
     }
     //<-- DEAL
     // LOCATION -->
     if (is_array($options) && isset($options['ENABLE_LOCATION']) && $options['ENABLE_LOCATION']) {
         $properties = is_array($enums) && isset($enums['INVOICE_PROPERTIES']) && is_array($enums['INVOICE_PROPERTIES']) ? $enums['INVOICE_PROPERTIES'] : null;
         $locationID = is_array($properties) && isset($properties['PR_LOCATION']) ? intval($properties['PR_LOCATION']['VALUE']) : 0;
         $item['~LOCATION_ID'] = $item['LOCATION_ID'] = $locationID;
         $item['~LOCATION_NAME'] = $locationID > 0 ? CCrmInvoice::ResolveLocationName($locationID) : '';
         $item['LOCATION_NAME'] = htmlspecialcharsbx($item['~LOCATION_NAME']);
     }
     //<-- LOCATION
     $enableMultiFields = is_array($options) && isset($options['ENABLE_MULTI_FIELDS']) && $options['ENABLE_MULTI_FIELDS'];
     //CONTACT -->
     $contactID = isset($item['UF_CONTACT_ID']) ? intval($item['UF_CONTACT_ID']) : 0;
     $item['~CONTACT_ID'] = $item['CONTACT_ID'] = $contactID;
     $contact = null;
     if ($contactID > 0) {
         $dbContact = CCrmContact::GetListEx(array(), array('=ID' => $contactID), false, false, array('NAME', 'SECOND_NAME', 'LAST_NAME', 'POST', 'PHOTO'));
         $contact = $dbContact ? $dbContact->Fetch() : null;
     }
     if (!$contact) {
         $item['~CONTACT_FULL_NAME'] = $item['CONTACT_FULL_NAME'] = $item['~CONTACT_POST'] = $item['CONTACT_POST'] = '';
         $item['~CONTACT_PHOTO'] = $item['CONTACT_PHOTO'] = 0;
         if ($enableMultiFields) {
             $item['CONTACT_FM'] = array();
         }
     } else {
         $item['~CONTACT_FULL_NAME'] = CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('LOGIN' => '', 'NAME' => isset($contact['NAME']) ? $contact['NAME'] : '', 'SECOND_NAME' => isset($contact['SECOND_NAME']) ? $contact['SECOND_NAME'] : '', 'LAST_NAME' => isset($contact['LAST_NAME']) ? $contact['LAST_NAME'] : ''), false, false);
         $item['CONTACT_FULL_NAME'] = htmlspecialcharsbx($item['~CONTACT_FULL_NAME']);
         $item['~CONTACT_POST'] = isset($contact['POST']) ? $contact['POST'] : '';
         $item['CONTACT_POST'] = htmlspecialcharsbx($item['~CONTACT_POST']);
         $item['~CONTACT_PHOTO'] = $item['CONTACT_PHOTO'] = isset($contact['PHOTO']) ? intval($contact['PHOTO']) : 0;
         if ($enableMultiFields) {
             $item['CONTACT_FM'] = array();
             $dbMultiFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'CONTACT', 'ELEMENT_ID' => $contactID));
             if ($dbMultiFields) {
                 while ($multiFields = $dbMultiFields->Fetch()) {
                     $item['CONTACT_FM'][$multiFields['TYPE_ID']][] = array('VALUE' => $multiFields['VALUE'], 'VALUE_TYPE' => $multiFields['VALUE_TYPE']);
                 }
             }
         }
     }
     //<-- CONTACT
     //COMPANY -->
     $companyID = isset($item['UF_COMPANY_ID']) ? intval($item['UF_COMPANY_ID']) : 0;
     $item['~COMPANY_ID'] = $item['COMPANY_ID'] = $companyID;
     $company = null;
     if ($companyID > 0) {
         $dbCompany = CCrmCompany::GetListEx(array(), array('=ID' => $companyID), false, false, array('TITLE', 'LOGO'));
         $company = $dbCompany ? $dbCompany->Fetch() : null;
     }
     if (!$company) {
         $item['~COMPANY_TITLE'] = $item['COMPANY_TITLE'] = '';
         $item['~COMPANY_LOGO'] = $item['COMPANY_LOGO'] = 0;
     } else {
         $item['~COMPANY_TITLE'] = isset($company['TITLE']) ? $company['TITLE'] : '';
         $item['COMPANY_TITLE'] = htmlspecialcharsbx($item['~COMPANY_TITLE']);
         $item['~COMPANY_LOGO'] = $item['COMPANY_LOGO'] = isset($company['LOGO']) ? intval($company['LOGO']) : 0;
         if ($enableMultiFields) {
             $item['COMPANY_FM'] = array();
             $dbMultiFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'COMPANY', 'ELEMENT_ID' => $companyID));
             if ($dbMultiFields) {
                 while ($multiFields = $dbMultiFields->Fetch()) {
                     $item['COMPANY_FM'][$multiFields['TYPE_ID']][] = array('VALUE' => $multiFields['VALUE'], 'VALUE_TYPE' => $multiFields['VALUE_TYPE']);
                 }
             }
         }
     }
     //<-- COMPANY
     $personTypeID = CCrmInvoice::ResolvePersonTypeID($companyID, $contactID);
     // PAYER_INFO -->
     if (is_array($options) && isset($options['ENABLE_PAYER_INFO']) && $options['ENABLE_PAYER_INFO']) {
         if ($companyID <= 0 && $contactID <= 0) {
             $item['~PAYER_INFO'] = $item['PAYER_INFO'] = '';
         } else {
             // Get invoice properties
             $properties = isset($item['INVOICE_PROPERTIES']) ? $item['INVOICE_PROPERTIES'] : null;
             if (!is_array($properties) && $personTypeID > 0) {
                 $properties = CCrmInvoice::GetProperties($itemID, $personTypeID);
                 if ($itemID <= 0) {
                     CCrmInvoice::__RewritePayerInfo($companyID, $contactID, $properties);
                 }
             }
             $item['~PAYER_INFO'] = is_array($properties) ? CCrmInvoice::__MakePayerInfoString($properties) : '';
             $item['PAYER_INFO'] = htmlspecialcharsbx($item['~PAYER_INFO']);
         }
     }
     //<-- PAYER_INFO
     // PAY_SYSTEM -->
     if (!isset($item['~PAY_SYSTEM_ID'])) {
         $item['~PAY_SYSTEM_ID'] = $item['PAY_SYSTEM_ID'] = '';
     }
     $paySystemID = $item['~PAY_SYSTEM_ID'];
     $paySystems = is_array($enums) && isset($enums['PAY_SYSTEMS']) && is_array($enums['PAY_SYSTEMS']) ? $enums['PAY_SYSTEMS'] : ($personTypeID > 0 ? CCrmPaySystem::GetPaySystemsListItems($personTypeID) : array());
     if (isset($paySystems[$paySystemID])) {
         $item['~PAY_SYSTEM_NAME'] = $paySystems[$paySystemID];
         $item['PAY_SYSTEM_NAME'] = htmlspecialcharsbx($item['~PAY_SYSTEM_NAME']);
     } else {
         $item['~PAY_SYSTEM_NAME'] = $item['PAY_SYSTEM_NAME'] = '';
     }
     //<-- PAY_SYSTEM
     // RESPONSIBLE -->
     $responsibleID = isset($item['~RESPONSIBLE_ID']) ? intval($item['~RESPONSIBLE_ID']) : 0;
     $item['RESPONSIBLE_SHOW_URL'] = '';
     $item['~RESPONSIBLE_FORMATTED_NAME'] = '';
     if ($responsibleID > 0) {
         $item['RESPONSIBLE_SHOW_URL'] = $params['USER_PROFILE_URL_TEMPLATE'] !== '' ? CComponentEngine::makePathFromTemplate($params['USER_PROFILE_URL_TEMPLATE'], array('user_id' => $responsibleID)) : '';
         $item['~RESPONSIBLE_FORMATTED_NAME'] = CUser::FormatName($params['NAME_TEMPLATE'], array('LOGIN' => isset($item['~RESPONSIBLE_LOGIN']) ? $item['~RESPONSIBLE_LOGIN'] : '', 'NAME' => isset($item['~RESPONSIBLE_NAME']) ? $item['~RESPONSIBLE_NAME'] : '', 'LAST_NAME' => isset($item['~RESPONSIBLE_LAST_NAME']) ? $item['~RESPONSIBLE_LAST_NAME'] : '', 'SECOND_NAME' => isset($item['~RESPONSIBLE_SECOND_NAME']) ? $item['~RESPONSIBLE_SECOND_NAME'] : ''), true, false);
     }
     $item['RESPONSIBLE_FORMATTED_NAME'] = htmlspecialcharsbx($item['~RESPONSIBLE_FORMATTED_NAME']);
     //<-- RESPONSIBLE
 }
示例#4
0
$personTypeID = 0;
// payer information
if ($companyID > 0 || $contactID > 0) {
    // Determine person type
    $arPersonTypes = CCrmPaySystem::getPersonTypeIDs();
    if (isset($arPersonTypes['COMPANY']) && isset($arPersonTypes['CONTACT'])) {
        if ($companyID > 0) {
            $personTypeID = $arPersonTypes['COMPANY'];
        } elseif ($contactID > 0) {
            $personTypeID = $arPersonTypes['CONTACT'];
        }
    }
    // Get invoice properties
    $arInvoiceProperties = array();
    if ($arResult['ELEMENT_ID'] > 0) {
        $tmpArProps = CCrmInvoice::GetProperties($arResult['ELEMENT_ID'], $personTypeID);
        if ($tmpArProps !== false) {
            $arInvoiceProperties = $tmpArProps;
            if ($bTaxMode && !isset($arFields['PR_LOCATION']) && isset($arInvoiceProperties['PR_LOCATION'])) {
                $arResult['ELEMENT']['PR_LOCATION'] = $arInvoiceProperties['PR_LOCATION']['VALUE'];
            }
        }
        unset($tmpArProps);
    }
    $arResult['ELEMENT']['PAYER_INFO'] = CCrmInvoice::__MakePayerInfoString($arInvoiceProperties);
}
$arResult['PAY_SYSTEM_LIST'] = $personTypeID > 0 ? CCrmPaySystem::GetPaySystemsListItems($personTypeID) : array();
if (isset($arResult['ELEMENT']['PAY_SYSTEM_ID']) && isset($arResult['PAY_SYSTEM_LIST'][$arResult['ELEMENT']['PAY_SYSTEM_ID']])) {
    $arResult['ELEMENT']['PAY_SYSTEM_NAME'] = $arResult['PAY_SYSTEM_LIST'][$arResult['ELEMENT']['PAY_SYSTEM_ID']];
}
$isExternal = $arResult['IS_EXTERNAL'] = isset($arResult['ELEMENT']['ORIGINATOR_ID']) && isset($arResult['ELEMENT']['ORIGIN_ID']) && intval($arResult['ELEMENT']['ORIGINATOR_ID']) > 0 && intval($arResult['ELEMENT']['ORIGIN_ID']) > 0;
示例#5
0
     $contactID = 0;
 }
 $personTypeID = isset($data['PERSON_TYPE_ID']) ? intval($data['PERSON_TYPE_ID']) : 0;
 $resolvedPersonTypeID = $companyID > 0 || $contactID > 0 ? CCrmInvoice::ResolvePersonTypeID($companyID, $contactID) : 0;
 $paySystemID = isset($data['PAY_SYSTEM_ID']) ? intval($data['PAY_SYSTEM_ID']) : 0;
 $paySystems = CCrmPaySystem::GetPaySystemsListItems($resolvedPersonTypeID);
 $resolvedPaySystemID = 0;
 if ($personTypeID === $resolvedPersonTypeID && $paySystemID > 0 && array_key_exists($paySystemID, $paySystems)) {
     // Pay system does not changed
     $resolvedPaySystemID = $paySystemID;
 } elseif (!empty($paySystems)) {
     // Take first pay system
     $resolvedPaySystemID = array_shift(array_keys($paySystems));
 }
 $arFields = array('ID' => $ID, 'PRODUCT_ROWS' => $productRows, 'PAY_SYSTEM_ID' => $resolvedPaySystemID, 'PERSON_TYPE_ID' => $resolvedPersonTypeID);
 $properties = CCrmInvoice::GetProperties($ID, $resolvedPersonTypeID);
 if (!is_array($properties)) {
     $properties = array();
 }
 if (isset($data['LOCATION_ID']) && !isset($data['LOC_CITY'])) {
     //HACK: see CCrmInvoice::ParsePropertiesValuesFromPost
     $data['LOC_CITY'] = $data['LOCATION_ID'];
 }
 $propertyValues = CCrmInvoice::ParsePropertiesValuesFromPost($resolvedPersonTypeID, $data, $properties);
 if (isset($propertyValues['PROPS_VALUES']) && isset($propertyValues['PROPS_INDEXES'])) {
     $arFields['INVOICE_PROPERTIES'] = $propertyValues['PROPS_VALUES'];
     foreach ($propertyValues['PROPS_INDEXES'] as $name => $index) {
         if (!isset($arFields[$name])) {
             $arFields[$name] = $propertyValues['PROPS_VALUES'][$index];
         }
     }
示例#6
0
        } elseif ($info['CONTACT'] > 0) {
            $personTypeId = $arPersonTypes['CONTACT'];
        }
        unset($info);
    } else {
        if (intval($arFields['UF_COMPANY_ID']) > 0) {
            $personTypeId = $arPersonTypes['COMPANY'];
        } elseif (intval($arFields['UF_CONTACT_ID']) > 0) {
            $personTypeId = $arPersonTypes['CONTACT'];
        }
    }
}
// Get invoice properties
$arInvoiceProperties = array();
if ($bEdit || $bCopy || $bProcessPost || $bCreateFromQuote || $bCreateFromDeal || $bCreateFromCompany || $bCreateFromContact) {
    $tmpArProps = $CCrmInvoice->GetProperties($arParams['ELEMENT_ID'], $personTypeId);
    if ($tmpArProps !== false) {
        $arInvoiceProperties = $tmpArProps;
        if ($bTaxMode && !isset($arFields['PR_LOCATION']) && isset($arInvoiceProperties['PR_LOCATION'])) {
            $arFields['PR_LOCATION'] = $arInvoiceProperties['PR_LOCATION']['VALUE'];
        }
    }
    unset($tmpArProps);
}
$bVatMode = CCrmTax::isVatMode();
if (isset($arFields['~COMMENTS'])) {
    $arFields['COMMENTS'] = htmlspecialcharsbx($arFields['~COMMENTS']);
}
if (isset($arFields['~USER_DESCRIPTION'])) {
    $arFields['USER_DESCRIPTION'] = htmlspecialcharsbx($arFields['~USER_DESCRIPTION']);
}
 private static function getInvoiceDataByID($ID)
 {
     $arInvoice = CCrmInvoice::GetByID($ID);
     if (!is_array($arInvoice)) {
         throw new RestException('Not found.');
     }
     $arProperties = CCrmInvoice::GetProperties($ID, $arInvoice['PERSON_TYPE_ID']);
     $arAllowedProperties = CCrmInvoice::GetPropertiesInfo($arInvoice['PERSON_TYPE_ID'], true);
     $arAllowedProperties = is_array($arAllowedProperties[$arInvoice['PERSON_TYPE_ID']]) ? array_keys($arAllowedProperties[$arInvoice['PERSON_TYPE_ID']]) : array();
     $arPropertiesResult = array();
     foreach ($arProperties as $k => $v) {
         if ($k !== 'PR_LOCATION') {
             if (in_array($v['FIELDS']['CODE'], $arAllowedProperties)) {
                 $arPropertiesResult[$v['FIELDS']['CODE']] = $v['VALUE'];
             }
         } else {
             $arInvoice['PR_LOCATION'] = $v['VALUE'];
         }
     }
     $arProducts = CCrmInvoice::GetProductRows($ID);
     $result = $arInvoice;
     if (count($arPropertiesResult) > 0) {
         // ua company name hack
         if (!isset($arPropertiesResult['COMPANY']) && isset($arPropertiesResult['COMPANY_NAME'])) {
             $arPropertiesResult['COMPANY'] = $arPropertiesResult['COMPANY_NAME'];
             unset($arPropertiesResult['COMPANY_NAME']);
         }
         $result['INVOICE_PROPERTIES'] = $arPropertiesResult;
     }
     if (count($arProducts) > 0) {
         $result['PRODUCT_ROWS'] = $arProducts;
     }
     return $result;
 }