app/Customize/Controller/ProductController.php line 583

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Controller;
  13. use Carbon\Carbon;
  14. use Eccube\Controller\ProductController as BaseProductController;
  15. use Eccube\Entity\BaseInfo;
  16. use Eccube\Entity\Master\ProductStatus;
  17. use Eccube\Entity\Product;
  18. use Eccube\Event\EccubeEvents;
  19. use Eccube\Event\EventArgs;
  20. use Eccube\Form\Type\AddCartType;
  21. use Eccube\Form\Type\Master\ProductListMaxType;
  22. use Eccube\Form\Type\Master\ProductListOrderByType;
  23. use Eccube\Form\Type\SearchProductType;
  24. use Eccube\Repository\BaseInfoRepository;
  25. use Eccube\Repository\CustomerFavoriteProductRepository;
  26. use Eccube\Repository\Master\ProductListMaxRepository;
  27. use Eccube\Repository\ProductRepository;
  28. use Eccube\Repository\CalendarRepository;
  29. use Eccube\Service\CartService;
  30. use Eccube\Service\PurchaseFlow\PurchaseContext;
  31. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  32. use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination;
  33. use Knp\Component\Pager\PaginatorInterface;
  34. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  35. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  36. use Symfony\Component\HttpFoundation\Request;
  37. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  38. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  39. use Symfony\Component\Routing\Annotation\Route;
  40. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  41. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  42. use Doctrine\ORM\Query\ResultSetMapping;
  43. class ProductController extends BaseProductController
  44. {
  45.     /**
  46.      * @var PurchaseFlow
  47.      */
  48.     protected $purchaseFlow;
  49.     /**
  50.      * @var CustomerFavoriteProductRepository
  51.      */
  52.     protected $customerFavoriteProductRepository;
  53.     /**
  54.      * @var CartService
  55.      */
  56.     protected $cartService;
  57.     /**
  58.      * @var ProductRepository
  59.      */
  60.     protected $productRepository;
  61.     /**
  62.      * @var BaseInfo
  63.      */
  64.     protected $BaseInfo;
  65.     /**
  66.      * @var AuthenticationUtils
  67.      */
  68.     protected $helper;
  69.     /**
  70.      * @var ProductListMaxRepository
  71.      */
  72.     protected $productListMaxRepository;
  73.     /**
  74.      * @var $CalendarRepository
  75.      */
  76.     protected $calendarRepository;
  77.     private $title '';
  78.     /**
  79.      * ProductController constructor.
  80.      *
  81.      * @param PurchaseFlow $cartPurchaseFlow
  82.      * @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
  83.      * @param CartService $cartService
  84.      * @param ProductRepository $productRepository
  85.      * @param BaseInfoRepository $baseInfoRepository
  86.      * @param AuthenticationUtils $helper
  87.      * @param ProductListMaxRepository $productListMaxRepository
  88.      * @param CalendarRepository $calendarRepository
  89.      */
  90.     public function __construct(
  91.         PurchaseFlow $cartPurchaseFlow,
  92.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  93.         CartService $cartService,
  94.         ProductRepository $productRepository,
  95.         BaseInfoRepository $baseInfoRepository,
  96.         AuthenticationUtils $helper,
  97.         ProductListMaxRepository $productListMaxRepository,
  98.         CalendarRepository $calendarRepository
  99.     ) {
  100.         $this->purchaseFlow $cartPurchaseFlow;
  101.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  102.         $this->cartService $cartService;
  103.         $this->productRepository $productRepository;
  104.         $this->BaseInfo $baseInfoRepository->get();
  105.         $this->helper $helper;
  106.         $this->productListMaxRepository $productListMaxRepository;
  107.         $this->calendarRepository $calendarRepository;
  108.     }
  109.     /**
  110.      * 商品一覧画面.
  111.      *
  112.      * @Route("/products/list", name="product_list", methods={"GET"})
  113.      * @Template("Product/list.twig")
  114.      */
  115.     public function index(Request $requestPaginatorInterface $paginator)
  116.     {
  117.       return $this->redirectToRoute('product_detail', ['id' => 1]);
  118.       // url('product_detail', {'id': Product.id})
  119.       // return $this->redirectToRoute('admin_api_webhook_edit', ['id' => $WebHook->getId()]);
  120.       // Doctrine SQLFilter
  121.         if ($this->BaseInfo->isOptionNostockHidden()) {
  122.             $this->entityManager->getFilters()->enable('option_nostock_hidden');
  123.         }
  124.         // handleRequestは空のqueryの場合は無視するため
  125.         if ($request->getMethod() === 'GET') {
  126.             $request->query->set('pageno'$request->query->get('pageno'''));
  127.         }
  128.         // searchForm
  129.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  130.         $builder $this->formFactory->createNamedBuilder(''SearchProductType::class);
  131.         if ($request->getMethod() === 'GET') {
  132.             $builder->setMethod('GET');
  133.         }
  134.         $event = new EventArgs(
  135.             [
  136.                 'builder' => $builder,
  137.             ],
  138.             $request
  139.         );
  140.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_INITIALIZE);
  141.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  142.         $searchForm $builder->getForm();
  143.         $searchForm->handleRequest($request);
  144.         // paginator
  145.         $searchData $searchForm->getData();
  146.         $qb $this->productRepository->getQueryBuilderBySearchData($searchData);
  147.         $event = new EventArgs(
  148.             [
  149.                 'searchData' => $searchData,
  150.                 'qb' => $qb,
  151.             ],
  152.             $request
  153.         );
  154.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_SEARCH);
  155.         $searchData $event->getArgument('searchData');
  156.         $query $qb->getQuery()
  157.             ->useResultCache(true$this->eccubeConfig['eccube_result_cache_lifetime_short']);
  158.         /** @var SlidingPagination $pagination */
  159.         $pagination $paginator->paginate(
  160.             $query,
  161.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  162.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->productListMaxRepository->findOneBy([], ['sort_no' => 'ASC'])->getId()
  163.         );
  164.         $ids = [];
  165.         foreach ($pagination as $Product) {
  166.             $ids[] = $Product->getId();
  167.         }
  168.         $ProductsAndClassCategories $this->productRepository->findProductsWithSortedClassCategories($ids'p.id');
  169.         // addCart form
  170.         $forms = [];
  171.         foreach ($pagination as $Product) {
  172.             /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  173.             $builder $this->formFactory->createNamedBuilder(
  174.                 '',
  175.                 AddCartType::class,
  176.                 null,
  177.                 [
  178.                     'product' => $ProductsAndClassCategories[$Product->getId()],
  179.                     'allow_extra_fields' => true,
  180.                 ]
  181.             );
  182.             $addCartForm $builder->getForm();
  183.             $forms[$Product->getId()] = $addCartForm->createView();
  184.         }
  185.         // 表示件数
  186.         $builder $this->formFactory->createNamedBuilder(
  187.             'disp_number',
  188.             ProductListMaxType::class,
  189.             null,
  190.             [
  191.                 'required' => false,
  192.                 'allow_extra_fields' => true,
  193.             ]
  194.         );
  195.         if ($request->getMethod() === 'GET') {
  196.             $builder->setMethod('GET');
  197.         }
  198.         $event = new EventArgs(
  199.             [
  200.                 'builder' => $builder,
  201.             ],
  202.             $request
  203.         );
  204.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_DISP);
  205.         $dispNumberForm $builder->getForm();
  206.         $dispNumberForm->handleRequest($request);
  207.         // ソート順
  208.         $builder $this->formFactory->createNamedBuilder(
  209.             'orderby',
  210.             ProductListOrderByType::class,
  211.             null,
  212.             [
  213.                 'required' => false,
  214.                 'allow_extra_fields' => true,
  215.             ]
  216.         );
  217.         if ($request->getMethod() === 'GET') {
  218.             $builder->setMethod('GET');
  219.         }
  220.         $event = new EventArgs(
  221.             [
  222.                 'builder' => $builder,
  223.             ],
  224.             $request
  225.         );
  226.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_INDEX_ORDER);
  227.         $orderByForm $builder->getForm();
  228.         $orderByForm->handleRequest($request);
  229.         $Category $searchForm->get('category_id')->getData();
  230.         return [
  231.             'subtitle' => $this->getPageTitle($searchData),
  232.             'pagination' => $pagination,
  233.             'search_form' => $searchForm->createView(),
  234.             'disp_number_form' => $dispNumberForm->createView(),
  235.             'order_by_form' => $orderByForm->createView(),
  236.             'forms' => $forms,
  237.             'Category' => $Category,
  238.         ];
  239.     }
  240.     /**
  241.      * 商品詳細画面.
  242.      *
  243.      * @Route("/products/detail/{id}", name="product_detail", methods={"GET"}, requirements={"id" = "\d+"})
  244.      * @Template("Product/detail.twig")
  245.      * @ParamConverter("Product", options={"repository_method" = "findWithSortedClassCategories"})
  246.      *
  247.      * @param Request $request
  248.      * @param Product $Product
  249.      *
  250.      * @return array
  251.      */
  252.     public function detail(Request $requestProduct $Product)
  253.     {
  254.         if (!$this->checkVisibility($Product)) {
  255.             throw new NotFoundHttpException();
  256.         }
  257.         $builder $this->formFactory->createNamedBuilder(
  258.             '',
  259.             AddCartType::class,
  260.             null,
  261.             [
  262.                 'product' => $Product,
  263.                 'id_add_product_id' => false,
  264.             ]
  265.         );
  266.         $event = new EventArgs(
  267.             [
  268.                 'builder' => $builder,
  269.                 'Product' => $Product,
  270.             ],
  271.             $request
  272.         );
  273.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_DETAIL_INITIALIZE);
  274.         $is_favorite false;
  275.         if ($this->isGranted('ROLE_USER')) {
  276.             $Customer $this->getUser();
  277.             $is_favorite $this->customerFavoriteProductRepository->isFavorite($Customer$Product);
  278.           } else {
  279.             // 非会員の場合、ログイン画面を表示
  280.             //  ログイン後の画面遷移先を設定
  281.             $this->setLoginTargetPath($this->generateUrl('product_detail', ['id' => 1]));
  282.             // $this->session->getFlashBag()->set('eccube.add.favorite', true);
  283.             // $event = new EventArgs(
  284.             //     [
  285.             //         'Product' => $Product,
  286.             //     ],
  287.             //     $request
  288.             // );
  289.             // $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE, $event);
  290.             return $this->redirectToRoute('mypage_login');
  291.           }
  292.         return [
  293.             'title' => $this->title,
  294.             'subtitle' => $Product->getName(),
  295.             'form' => $builder->getForm()->createView(),
  296.             'Product' => $Product,
  297.             'is_favorite' => $is_favorite,
  298.         ];
  299.     }
  300.     /**
  301.      * お気に入り追加.
  302.      *
  303.      * @Route("/products/add_favorite/{id}", name="product_add_favorite", requirements={"id" = "\d+"}, methods={"GET", "POST"})
  304.      */
  305.     public function addFavorite(Request $requestProduct $Product)
  306.     {
  307.         $this->checkVisibility($Product);
  308.         $event = new EventArgs(
  309.             [
  310.                 'Product' => $Product,
  311.             ],
  312.             $request
  313.         );
  314.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_INITIALIZE);
  315.         if ($this->isGranted('ROLE_USER')) {
  316.             $Customer $this->getUser();
  317.             $this->customerFavoriteProductRepository->addFavorite($Customer$Product);
  318.             $this->session->getFlashBag()->set('product_detail.just_added_favorite'$Product->getId());
  319.             $event = new EventArgs(
  320.                 [
  321.                     'Product' => $Product,
  322.                 ],
  323.                 $request
  324.             );
  325.             $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE);
  326.             return $this->redirectToRoute('product_detail', ['id' => $Product->getId()]);
  327.         } else {
  328.             // 非会員の場合、ログイン画面を表示
  329.             //  ログイン後の画面遷移先を設定
  330.             $this->setLoginTargetPath($this->generateUrl('product_add_favorite', ['id' => $Product->getId()], UrlGeneratorInterface::ABSOLUTE_URL));
  331.             $this->session->getFlashBag()->set('eccube.add.favorite'true);
  332.             $event = new EventArgs(
  333.                 [
  334.                     'Product' => $Product,
  335.                 ],
  336.                 $request
  337.             );
  338.             $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_FAVORITE_ADD_COMPLETE);
  339.             return $this->redirectToRoute('mypage_login');
  340.         }
  341.     }
  342.     /**
  343.      * カートに追加.
  344.      *
  345.      * @Route("/products/add_cart/{id}", name="product_add_cart", methods={"POST"}, requirements={"id" = "\d+"})
  346.      */
  347.     public function addCart(Request $requestProduct $Product)
  348.     {
  349.         // エラーメッセージの配列
  350.         $errorMessages = [];
  351.         if (!$this->checkVisibility($Product)) {
  352.             throw new NotFoundHttpException();
  353.         }
  354.         $builder $this->formFactory->createNamedBuilder(
  355.             '',
  356.             AddCartType::class,
  357.             null,
  358.             [
  359.                 'product' => $Product,
  360.                 'id_add_product_id' => false,
  361.             ]
  362.         );
  363.         $event = new EventArgs(
  364.             [
  365.                 'builder' => $builder,
  366.                 'Product' => $Product,
  367.             ],
  368.             $request
  369.         );
  370.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_CART_ADD_INITIALIZE);
  371.         /* @var $form \Symfony\Component\Form\FormInterface */
  372.         $form $builder->getForm();
  373.         $form->handleRequest($request);
  374.         if (!$form->isValid()) {
  375.             // throw new NotFoundHttpException();
  376.         }
  377.         $addCartData $form->getData();
  378.         log_info(
  379.             'カート追加処理開始',
  380.             [
  381.                 'product_id' => $Product->getId(),
  382.                 'product_class_id' => $addCartData['product_class_id'],
  383.                 'quantity' => $addCartData['quantity'],
  384.             ]
  385.         );
  386.         // カートへ追加
  387.         $product_custom = (isset($_POST['product_custom'])) ? $_POST['product_custom'] : '';
  388.         $product_subtotal = (isset($_POST['product_subtotal'])) ? $_POST['product_subtotal'] : 9999999;
  389.         $product_custom_delivery_date = (isset($_POST['product_custom_delivery_date'])) ? $_POST['product_custom_delivery_date'] : '';
  390.         // $_SESSION['cart_ex']['product_custom'] = $product_custom;
  391.         // $_SESSION['cart_ex']['product_subtotal'] = $product_subtotal;
  392.         $parm_data = array('product_custom'=>$product_custom'product_subtotal'=>$product_subtotal'product_custom_delivery_date'=>$product_custom_delivery_date,);
  393.         $this->cartService->addProduct($addCartData['product_class_id'], $addCartData['quantity'], $parm_data);
  394.         log_info(
  395.           'カート追加1',
  396.           [
  397.               'parm_data' => $parm_data
  398.           ]
  399.       );
  400.         // 明細の正規化
  401.         $Carts $this->cartService->getCarts();
  402.         foreach ($Carts as $Cart) {
  403.             $result $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart$this->getUser()));
  404.             log_info(
  405.               'カート追加処理エラー',
  406.               [
  407.                   'hasError' => $result->hasError()
  408.               ]
  409.           );
  410.             // 復旧不可のエラーが発生した場合は追加した明細を削除.
  411.             if ($result->hasError()) {
  412.                 $this->cartService->removeProduct($addCartData['product_class_id']);
  413.                 foreach ($result->getErrors() as $error) {
  414.                     $errorMessages[] = $error->getMessage();
  415.                 }
  416.             }
  417.             foreach ($result->getWarning() as $warning) {
  418.               log_info(
  419.                 'カート追加処理エラー2',
  420.                 [
  421.                     'warning' =>  $warning->getMessage()
  422.                 ]
  423.             );
  424.   
  425.               $errorMessages[] = $warning->getMessage();
  426.             }
  427.         }
  428.         $this->cartService->save();
  429.         log_info(
  430.             'カート追加処理完了',
  431.             [
  432.                 'product_id' => $Product->getId(),
  433.                 'product_class_id' => $addCartData['product_class_id'],
  434.                 'quantity' => $addCartData['quantity'],
  435.             ]
  436.         );
  437.         $event = new EventArgs(
  438.             [
  439.                 'form' => $form,
  440.                 'Product' => $Product,
  441.             ],
  442.             $request
  443.         );
  444.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_PRODUCT_CART_ADD_COMPLETE);
  445.         if ($event->getResponse() !== null) {
  446.             return $event->getResponse();
  447.         }
  448.         if ($request->isXmlHttpRequest()) {
  449.             // ajaxでのリクエストの場合は結果をjson形式で返す。
  450.             // 初期化
  451.             $done null;
  452.             $messages = [];
  453.             if (empty($errorMessages)) {
  454.                 // エラーが発生していない場合
  455.                 $done true;
  456.                 array_push($messagestrans('front.product.add_cart_complete'));
  457.             } else {
  458.                 // エラーが発生している場合
  459.                 $done false;
  460.                 $messages $errorMessages;
  461.             }
  462.             return $this->json(['done' => $done'messages' => $messages]);
  463.         } else {
  464.             // ajax以外でのリクエストの場合はカート画面へリダイレクト
  465.             foreach ($errorMessages as $errorMessage) {
  466.                 $this->addRequestError($errorMessage);
  467.             }
  468.             return $this->redirectToRoute('cart');
  469.         }
  470.     }
  471.     /**
  472.      * ページタイトルの設定
  473.      *
  474.      * @param  array|null $searchData
  475.      *
  476.      * @return str
  477.      */
  478.     protected function getPageTitle($searchData)
  479.     {
  480.         if (isset($searchData['name']) && !empty($searchData['name'])) {
  481.             return trans('front.product.search_result');
  482.         } elseif (isset($searchData['category_id']) && $searchData['category_id']) {
  483.             return $searchData['category_id']->getName();
  484.         } else {
  485.             return trans('front.product.all_products');
  486.         }
  487.     }
  488.     /**
  489.      * 閲覧可能な商品かどうかを判定
  490.      *
  491.      * @param Product $Product
  492.      *
  493.      * @return boolean 閲覧可能な場合はtrue
  494.      */
  495.     protected function checkVisibility(Product $Product)
  496.     {
  497.         $is_admin $this->session->has('_security_admin');
  498.         // 管理ユーザの場合はステータスやオプションにかかわらず閲覧可能.
  499.         if (!$is_admin) {
  500.             // 在庫なし商品の非表示オプションが有効な場合.
  501.             // if ($this->BaseInfo->isOptionNostockHidden()) {
  502.             //     if (!$Product->getStockFind()) {
  503.             //         return false;
  504.             //     }
  505.             // }
  506.             // 公開ステータスでない商品は表示しない.
  507.             if ($Product->getStatus()->getId() !== ProductStatus::DISPLAY_SHOW) {
  508.                 return false;
  509.             }
  510.         }
  511.         return true;
  512.     }
  513.     /**
  514.      * 最短納期を取得
  515.      *
  516.      * @Route("/products/ajax_get_delivery_date/{production_days}", name="product_ajax_get_delivery_date", methods={"GET"}, requirements={"production_days" = "\d+"})
  517.      * 
  518.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  519.      */
  520.     public function getDeliveryDate(Request $request$production_days)
  521.     {
  522.       // Ajax/POSTでない場合は終了する
  523.       // if (!$request->isXmlHttpRequest()) {
  524.       //   throw new BadRequestHttpException();
  525.       // }
  526.       // build rsm here
  527.       $rsm = new ResultSetMapping();
  528.       
  529.       $currntDate date('Y-m-d');
  530.       // $end = '2022-11-30'; # 終了日時
  531.       
  532.       $today Carbon::now();
  533.       // $day1 = $today->copy()->startOfDay();
  534.       // // $firstDateOfNextMonth = $today->copy()->startOfDay()->addDay(1)->startOfDay();
  535.       // $day2 = $today->copy()->startOfDay()->addDay(5)->startOfDay();
  536.       // var_dump($day1);
  537.       // var_dump($day2);
  538.       // $day2
  539.         // カレンダーリスト取得
  540.         // $Calendars = $this->calendarRepository->getHolidayList($day1, $day2);
  541. // var_dump($Calendars);
  542.       // dateを使う
  543.       // for ($i = 1; $i <= $production_days; $i++) {
  544.       $i 0// 加算日
  545.       $w_days 0// 稼働日
  546.       while ($w_days $production_days) {
  547.         $i++;
  548.         // if ($w_days > $production_days) {
  549.         //   break;
  550.         // }
  551.         $day1 $today->copy()->startOfDay()->addDay($i)->startOfDay();
  552.         // $firstDateOfNextMonth = $today->copy()->startOfDay()->addDay(1)->startOfDay();
  553.         $day2 $today->copy()->startOfDay()->addDay($i)->endOfDay();
  554.         // var_dump($day1);
  555.         // echo '<br>';
  556.         // echo '<br>';
  557.         // var_dump($day2);
  558.         // echo '<br>';
  559.         // echo '<br>';
  560.   
  561.         // $day2
  562.           // カレンダーリスト取得
  563.           $Calendars $this->calendarRepository->getHolidayList($day1$day2);
  564.   
  565.           // var_dump(empty($Calendars));
  566.           // var_dump($Calendars);
  567.           // echo '<br>';
  568.           // echo '<br>';
  569.         // $query = $this->entityManager->createNativeQuery('SELECT * FROM `dtb_calendar` WHERE `holiday` = "2022-10-09 15:00:00"', $rsm);
  570.         // $query->setParameter('day1', $p_day . ' 15:00:00');
  571.         // $query->setParameter('day2', date('Y-m-d', strtotime($p_day . '+1 day')));
  572.         
  573.         // $query = $this->entityManager->createNativeQuery('SELECT * FROM `dtb_calendar` WHERE `holiday` >= :day1 AND `holiday` < :day2', $rsm);
  574.         // $query->setParameter('day1', $p_day);
  575.         // $query->setParameter('day2', date('Y-m-d', strtotime($p_day . '+1 day')));
  576.         // $result = $query->getResult();
  577.   
  578.         // var_dump($result);
  579.         // var_dump(empty($result));
  580.         if (empty($Calendars)) {
  581.         $w_days++;
  582.         }
  583.         // echo 'i = '.$i . '<br>';
  584.         // echo 'p_day = '.$p_day . '<br>';
  585.       }
  586.       $p_day date('Y-m-d'strtotime($currntDate '+'.$i.' day'));
  587.       
  588. // echo $p_day . PHP_EOL;;
  589. // echo $p_day;
  590.       return $this->json([
  591.         'production_days' => $production_days,
  592.         'p_day' => $p_day,
  593.       ]);
  594.     }
  595. }