diff --git a/CHANGELOG.md b/CHANGELOG.md index dddaf254..af05a87f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2022-08-22 v.6.1.5 +- Корректировка получения НДС товаров в каталоге + ## 2022-07-21 v.6.1.4 - Исправление ошибки при записи товаров в HL блок лояльности diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index 2e6ad6dc..70b299e5 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Исправление ошибки при записи товаров в HL блок лояльности \ No newline at end of file +- Корректировка получения НДС товаров в каталоге \ No newline at end of file diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 9e90a379..0fb01188 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ '6.1.4', - 'VERSION_DATE' => '2022-07-21 12:00:00' + 'VERSION' => '6.1.5', + 'VERSION_DATE' => '2022-08-22 11:00:00' ]; diff --git a/intaro.retailcrm/lib/icml/queryparamsmolder.php b/intaro.retailcrm/lib/icml/queryparamsmolder.php index d7ccd55c..5bb952f3 100644 --- a/intaro.retailcrm/lib/icml/queryparamsmolder.php +++ b/intaro.retailcrm/lib/icml/queryparamsmolder.php @@ -57,6 +57,7 @@ class QueryParamsMolder 'CATALOG_GROUP_' . $basePriceId, 'ID', 'LID', + 'VAT_ID', ]; return $params; diff --git a/intaro.retailcrm/lib/icml/settingsservice.php b/intaro.retailcrm/lib/icml/settingsservice.php index be6d5265..267872db 100644 --- a/intaro.retailcrm/lib/icml/settingsservice.php +++ b/intaro.retailcrm/lib/icml/settingsservice.php @@ -6,6 +6,7 @@ use Bitrix\Highloadblock\HighloadBlockTable; use CCatalog; use CCatalogGroup; use CCatalogSku; +use CCatalogVat; use CIBlock; use Intaro\RetailCrm\Service\Hl; use RetailcrmConfigProvider; @@ -79,12 +80,17 @@ class SettingsService /** * @var string */ - public $setupProfileName = ''; + public $setupProfileName = ''; /** * @var array */ - public $priceTypes = []; + public $priceTypes = []; + + /** + * @var array + */ + public $vatRates = []; /** * @var \Intaro\RetailCrm\Icml\SettingsService|null @@ -110,6 +116,7 @@ class SettingsService = $this->getSingleSetting('SETUP_PROFILE_NAME') ?? GetMessage('PROFILE_NAME_EXAMPLE'); $this->getPriceTypes(); + $this->getVatRates(); } /** @@ -136,6 +143,15 @@ class SettingsService } } + public function getVatRates() + { + $dbVatRate = CCatalogVat::GetListEx(['SORT' => 'ASC'], ['ACTIVE' => 'Y'], false, false, ['ID', 'NAME', 'RATE']); + + while ($arVatRate = $dbVatRate->Fetch()) { + $this->vatRates[$arVatRate['ID']] = $arVatRate; + } + } + /** * @param string $selected * @param string $key diff --git a/intaro.retailcrm/lib/icml/xmlofferbuilder.php b/intaro.retailcrm/lib/icml/xmlofferbuilder.php index 8106309c..9955a210 100644 --- a/intaro.retailcrm/lib/icml/xmlofferbuilder.php +++ b/intaro.retailcrm/lib/icml/xmlofferbuilder.php @@ -4,6 +4,7 @@ namespace Intaro\RetailCrm\Icml; use Bitrix\Catalog\ProductTable; use Bitrix\Main\ArgumentException; +use Intaro\RetailCrm\Component\ServiceLocator; use Intaro\RetailCrm\Icml\Utils\IcmlUtils; use Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo; use Intaro\RetailCrm\Model\Bitrix\Xml\OfferParam; @@ -82,11 +83,17 @@ class XmlOfferBuilder * @var \Intaro\RetailCrm\Model\Bitrix\Xml\XmlOffer */ private $xmlOffer; + /** * @var array */ private $categories; + /** + * @var array + */ + private $vatRates; + /** * IcmlDataManager constructor. * @@ -100,6 +107,9 @@ class XmlOfferBuilder { $this->setup = $setup; $this->purchasePriceNull = RetailcrmConfigProvider::getCrmPurchasePrice(); + /** @var \Intaro\RetailCrm\Icml\SettingsService $settingsService */ + $settingsService = ServiceLocator::get(SettingsService::class); + $this->vatRates = $settingsService->vatRates; $this->measures = $this->prepareMeasures($measure); $this->defaultServerName = $defaultServerName; } @@ -240,7 +250,7 @@ class XmlOfferBuilder $this->xmlOffer->name = $item['NAME']; $this->xmlOffer->xmlId = $item['EXTERNAL_ID'] ?? ''; $this->xmlOffer->productName = $item['NAME']; - $this->xmlOffer->vatRate = $item['CATALOG_VAT'] ?? 'none'; + $this->xmlOffer->vatRate = $this->getVatRate($item); $this->xmlOffer->unitCode = $this->getUnitCode($item['CATALOG_MEASURE'], $item['ID']); } @@ -267,6 +277,25 @@ class XmlOfferBuilder return null; } + /** + * Возвращает значение активной ставки НДС, если она указана в товаре + * + * @param array $product + * @return string + */ + private function getVatRate(array $product): string + { + if (!empty($product['VAT_ID']) && array_key_exists($product['VAT_ID'], $this->vatRates)) { + return $this->vatRates[$product['VAT_ID']]['RATE']; + } + + if (!empty($product['CATALOG_VAT_ID']) && array_key_exists($product['CATALOG_VAT_ID'], $this->vatRates)) { + return $this->vatRates[$product['CATALOG_VAT_ID']]['RATE']; + } + + return 'none'; + } + /** * Возвращает массив обычных свойств *