vendor/lm/engine-inventory-matrix/src/InventoryMatrix.php line 69

Open in your IDE?
  1. <?php
  2. namespace Lm\Engine\InventoryMatrix;
  3. use Lm\Engine\EC\Entity\GoodsWithRelated;
  4. use Lm\Engine\InventoryMatrix\Service\InventoryMatrixService;
  5. use Lm\Engine\InventoryMatrix\Models\GoodsSetPurchaseModel;
  6. use Lm\Engine\SokujitsuHassou\SokujitsuHassou;
  7. use Twig\Environment;
  8. use Twig\Loader\FilesystemLoader;
  9. class InventoryMatrix
  10. {
  11.     /**
  12.      * Format stock arrival date to a human-readable format
  13.      *
  14.      * @param string $date 入荷予定日 (YYYY-MM-DD 形式)
  15.      * @return string 変換された入荷予定日(例: "3月上旬")
  16.      * @throws \InvalidArgumentException 無効な日付形式の場合に例外をスロー
  17.      */
  18.     public function formatStockArrivalDate(string $date)
  19.     {
  20.         // YYYY-MM-DD 形式かどうかを確認
  21.         if (!preg_match('/^\d{4}-\d{2}-\d{2}$/'$date)) {
  22.             throw new \InvalidArgumentException('無効な日付形式です。YYYY-MM-DD 形式で入力してください。');
  23.         }
  24.         $timestamp strtotime($date);
  25.         if ($timestamp === false) {
  26.             throw new \InvalidArgumentException('無効な日付です。');
  27.         }
  28.         $month = (int)date('n'$timestamp);
  29.         $day = (int)date('j'$timestamp);
  30.         if ($day >= && $day <= 10) {
  31.             return "{$month}月上旬〜順次";
  32.         } elseif ($day >= 11 && $day <= 20) {
  33.             return "{$month}月中旬〜順次";
  34.         } else {
  35.             return "{$month}月下旬〜順次";
  36.         }
  37.     }
  38.     /***
  39.      * Handle get Matrix Stock from GoodId
  40.      * @param GoodsWithRelated|int $goods
  41.      * @param bool|true $readOnly
  42.      * @param array|null &$color
  43.      * @param array|null &$size
  44.      * @return null|string
  45.      * @throws \Twig\Error\LoaderError
  46.      * @throws \Twig\Error\RuntimeError
  47.      * @throws \Twig\Error\SyntaxError
  48.      */
  49.     public function getMatrixStock($goods$readOnly true, &$color null, &$size null)
  50.     {
  51.         /**
  52.          * @var GoodsWithRelated $goods
  53.          */
  54.         $goods GoodsWithRelated::factory($goods);
  55.         $goodsId $goods->getGoodsId();
  56.         //
  57.         $model = new GoodsSetPurchaseModel();
  58.         $inventoryMatrixService = new InventoryMatrixService();
  59.         list($jan$janColor) = $inventoryMatrixService->getGoodsJanById($goodsId);
  60.         $color $inventoryMatrixService->getGoodsColorSelectSql($goodsId);
  61.         $size $inventoryMatrixService->getGoodsSizeListById($goodsId);
  62.         $sokujitsu $inventoryMatrixService->getGoodsSameDayShipping($goodsId1);
  63.         $yoyaku $inventoryMatrixService->getGoodsReservation($goodsId1);
  64.         $yoteibi $inventoryMatrixService->getGoodsStockDate($goodsId1);
  65.         $sellingColor $inventoryMatrixService->getSellingColorSql($goodsIdcount($color));
  66.         try {
  67.             $stock $inventoryMatrixService->getGoodsStock($goodsId1);
  68.         } catch (\Exception $e) {
  69.             // throw new NotFoundHttpException('お探しの商品が見つかりませんでした', $e);
  70.             return null;
  71.         }
  72.         $matrixData = [];
  73.         $matrixData_cnt = [];
  74.         $line 0;
  75.         $sizeMax 8;
  76.         $max 0;
  77.         foreach ($color as $v1) {
  78.             //
  79.             if (!isset($yoyaku[$v1["gcl_id"]])) {
  80.                 continue;
  81.             }
  82.             $line++;
  83.             $line2 0;
  84.             $no 1;
  85.             foreach ($size as $v2) {
  86.                 if ($line2 % ($sizeMax) === 0) {
  87.                     $no++;
  88.                 } else {
  89.                     $max $line2 % ($sizeMax);
  90.                 }
  91.                 $tmpYoteibi NULL;
  92.                 if (!empty($yoteibi[$v1["gcl_id"]][$v2["gp_id"]]) and $sokujitsu[$v1["gcl_id"]][$v2["gp_id"]] <= SokujitsuHassou::FLG_NONE) {
  93.                     $tmpYoteibi $this->formatStockArrivalDate($yoteibi[$v1["gcl_id"]][$v2["gp_id"]]);
  94.                 }
  95.                 $children = [];
  96.                 foreach (['main''sub''other'] as $type)
  97.                     if (!empty($v1["{$type}_gcl_id"]) && !empty($v2["{$type}_gp_id"])) $children[] = [
  98.                         'gclId' => $v1["{$type}_gcl_id"],
  99.                         'gpId' => $v2["{$type}_gp_id"],
  100.                     ];
  101.                 $matrixData_cnt[$no] = $max;
  102.                 $matrixData[$no][$line][$line2] = [
  103.                     'line' => $line,
  104.                     'product_id' => $jan[$v1["gcl_id"]][$v2["gp_id"]],
  105.                     'shiire_color' => $janColor[$v1["gcl_id"]][$v2["gp_id"]],
  106.                     'color' => $v1,
  107.                     'size' => $v2,
  108.                     'yoyaku' => $yoyaku[$v1["gcl_id"]][$v2["gp_id"]],
  109.                     'yoteibi' => $tmpYoteibi,
  110.                     'stock' => $stock[$v1["gcl_id"]][$v2["gp_id"]],
  111.                     'sokujitsu' => $sokujitsu[$v1["gcl_id"]][$v2["gp_id"]],
  112.                     'children' => $children,
  113.                 ];
  114.                 $line2++;
  115.             }
  116.         }
  117.         // Get goods set purchase
  118.         $getAsGoodsSetPurchase $model->getAsGoodsSetPurchaseById($goodsId);
  119.         $mainGspName '';
  120.         if ($getAsGoodsSetPurchase) {
  121.             $flattened = [];
  122.             foreach ($getAsGoodsSetPurchase as $goods) {
  123.                 if ($type GoodsSetPurchaseModel::GOODS_SET_PURCHASE_TYPE_LIST[$goods['gsp_type']])
  124.                     foreach ($goods as $key => $value) {
  125.                         $flattened["{$type['name']}_{$key}"] = $value;
  126.                     }
  127.             }
  128.             if ($flattened) {
  129.                 $mainGspName $flattened['main_gsp_name'];
  130.             }
  131.         }
  132.         $viewsPath realpath(__DIR__) . '/View/';
  133.         $loader = new FilesystemLoader($viewsPath);
  134.         $twig = new Environment($loader);
  135.         $template $twig->load('matrix_stock.twig');
  136.         $html $template->render([
  137.             'matrixData' => $matrixData,
  138.             'goodsId' => $goodsId,
  139.             'sellingColor' => $sellingColor,
  140.             'readOnly' => $readOnly,
  141.             'getAsGoodsSetPurchase' => $getAsGoodsSetPurchase,
  142.             'mainGspName' => $mainGspName
  143.         ]);
  144.         return $html;
  145.     }
  146. }