From a012f48a2041b2d8dede13a69d0a5be5eabe1d19 Mon Sep 17 00:00:00 2001 From: Mozgito Date: Mon, 22 Aug 2022 10:26:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=9D=D0=94=D0=A1=20=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=80=D0=BE=D0=B2=20=D0=B2=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++ intaro.retailcrm/description.ru | 2 +- intaro.retailcrm/install/version.php | 4 +-- .../lib/icml/queryparamsmolder.php | 1 + intaro.retailcrm/lib/icml/settingsservice.php | 20 ++++++++++-- intaro.retailcrm/lib/icml/xmlofferbuilder.php | 31 ++++++++++++++++++- 6 files changed, 55 insertions(+), 6 deletions(-) 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'; + } + /** * Возвращает массив обычных свойств *