Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.exchange1c/lib/ |
Upload File : |
<?php namespace Wbs24\Exchange1c; use Bitrix\Main\SystemException; class Report { use Exception; public function __construct($objects = []) { $this->Catalog = $objects['Catalog'] ?? new Catalog($objects); } public function createNotFoundProductsReport($products) { $warehousesInfo = $this->Catalog->getWarehousesInfo(); $formattedProducts = $this->formatProducts($products, $warehousesInfo); $htmlHead = '<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Not found report</title> </head> <body>' .date('Y.m.d H:i:s').'<hr>' ; $htmlFooter = '</body> </html>' ; $this->createReport('not_found.html', $htmlHead.$formattedProducts.$htmlFooter, [ 'writeMethod' => 'w', 'format' => 'html', ]); } protected function formatProducts(array $products, array $warehousesInfo): string { $text = ''; foreach ($products as $product) { $sku = $product['sku'] ?? ''; //$size = $product['size'] ?? ''; //$color = $product['color'] ?? ''; $stocks = $product['stocks'] ?? []; $availableQuantity = $product['availableQuantity'] ?? ''; $text .= $sku //.' / '.$size //.' / '.$color ; if ($stocks) { $text .= ' / '; foreach ($stocks as $k => $stock) { $stockId = $stock['stockId'] ?? ''; $quantity = $stock['quantity'] ?? 0; $id = $this->convertWarehouseXmlIdToId($stockId, $warehousesInfo); $text .= ($k ? ' | ' : '').$id.' - '.$quantity; } } if ($availableQuantity) $text .= ' / '.$availableQuantity; $text .= "<br>\r\n"; } return $text; } protected function convertWarehouseXmlIdToId($xmlId, $warehousesInfo) { $foundId = $xmlId; if ($xmlId) { foreach ($warehousesInfo as $info) { if ($xmlId == $info['XML_ID']) $foundId = $info['ID']; } } return $foundId; } }