src/Controller/OrderController.php line 36

Open in your IDE?
  1. <?php
  2. /**
  3.  * 受注状況用コントローラー
  4.  * 
  5.  */
  6. namespace App\Controller;
  7. use App\Controller\BaseController;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use App\Service\KintoneService;
  12. use App\Service\CommonService;
  13. use DateTime;
  14. class OrderController extends BaseController
  15. {
  16.     protected $kintoneService;
  17.     protected $commonService;
  18.     public function __construct(
  19.         KintoneService $kintoneService,
  20.         CommonService $commonService
  21.     )
  22.     {
  23.         parent::__construct();
  24.         $this->kintoneService $kintoneService;
  25.         $this->commonService $commonService;
  26.     }
  27.     /**
  28.      * @Route("/order", name="order")
  29.      */    
  30.     public function index(Request $request): Response
  31.     {
  32.         $data["date"] = $request->get('search_date'date("Y-m-d"));
  33.         $data["sort_key"] = $request->get('sort_key'"stock");
  34.         $item_codes = [];
  35.         $order_items_day = [];
  36.         $order_items_total = [];
  37.         $current_date = new DateTime($data["date"]);
  38.         $date_count 11;
  39.         for($i=0$i<$date_count$i++){
  40.             $str_date $current_date->format('Y-m-d');
  41.             $date_index[$str_date] = $i;
  42.             $last_date $str_date;
  43.             $current_date->modify('+1 day');
  44.         }
  45.         /*
  46.         //指定日の受注データ取得
  47.         $query = sprintf('出荷予定日_0 = "%s"', $data["date"]);
  48.         $result = $this->kintoneService->requestGets('order', $query);
  49.         $records = $result["records"];
  50.         foreach($records as $record) {
  51.             $sub_table = $record["受注商品テーブル"]["value"];
  52.             foreach($sub_table as $row){
  53.                 $item = $row["value"];
  54.                 $item_code = $item["商品コード"]["value"];
  55.                 $item_name = $item["受注商品名"]["value"];
  56.                 if(preg_match("/^◆_|^運賃_|_200入|_600入| 200入| 600入/", $item_name)) continue;
  57.                 if(!in_array($item_code, $item_codes)) {
  58.                     $item_codes[] = $item_code;
  59.                     for($i=0; $i<$date_count; $i++) $order_items_day[$item_code][$i] = 0;
  60.                     $order_items_total[$item_code] = 0;
  61.                 }
  62.             }
  63.         }
  64.         */
  65.         $limit 100;
  66.         $offset 0;
  67.         while(1) {
  68.             //本日以降の出荷予定日のデータを取得
  69.             $query sprintf('出荷予定日_0 >= "%s" and 出荷予定日_0 <= "%s" offset %d'$data["date"], $last_date$offset);
  70.             $result $this->kintoneService->requestGets('order'$query);
  71.             $records $result["records"];
  72.             //日付ごとの出荷予定数を集計する
  73.             foreach($records as $record) {
  74.                 $items $record["受注商品テーブル"]["value"];
  75.                 $shipping_date $record["出荷予定日_0"]["value"];
  76.                 $key $date_index$shipping_date ];
  77.                 foreach($items as $row){
  78.                     $item $row["value"];
  79.                     $item_code $item["商品コード"]["value"];
  80.                     $item_name $item["受注商品名"]["value"];
  81.                     if(preg_match("/^◆_|^運賃_|_200入|_600入| 200入| 600入|手数料\_/"$item_name)) continue;
  82.                     if(!in_array($item_code$item_codes)) {
  83.                         $item_codes[] = $item_code;
  84.                         for($i=0$i<$date_count$i++) $order_items_day[$item_code][$i] = 0;
  85.                         $order_items_total[$item_code] = 0;
  86.                     }
  87.                     $qty $item["箱数"]["value"] ? $item["箱数"]["value"] : 0;
  88.                     //日単位
  89.                     if(!isset($order_items_day[$item_code])) {
  90.                         for($i=0$i<$date_count$i++) $order_items_day[$item_code][$i] = 0;
  91.                     }
  92.                     $order_items_day[$item_code][$key]+= $qty;
  93.                     if($key 0) {
  94.                         if(!isset($order_items_total[$item_code])) $order_items_total[$item_code] = 0;
  95.                         $order_items_total[$item_code]+= $qty;
  96.                     }
  97.                 }
  98.             }
  99.             $offset += $limit;
  100.             if($result["totalCount"] < $offset) {
  101.                 $totalCount $result["totalCount"];
  102.                 break;
  103.             }
  104.             if($offset >= 10000 ) break;
  105.         }
  106.         //在庫マスタからデータ取得
  107.         $query sprintf('商品コード in (%s) and 手作業 not in ("レ") order by レコード番号''"' join('","'$item_codes) . '"');
  108.         $result $this->kintoneService->requestGets('stock'$query);
  109.         $data["item"] = [];
  110.         foreach($result["records"] as $item) {
  111.             $category_code $item["商品コード_大"]["value"];
  112.             $item_name $item["商品名"]["value"];
  113.             $item_code $item["商品コード"]["value"];
  114.             $limit $item["最低在庫数"]["value"];
  115.             $stock $item["在庫数"]["value"];
  116.             $unit_name $item["最低在庫数用単位"]["value"];
  117.             $film $item["フィルムの種類"]["value"];
  118.             $film_addr $item["フイルム住所・棚番"]["value"];
  119.             $order_item $order_items_day[$item_code];
  120.             $later $order_items_total[$item_code];
  121.             $limit $limit $limit 0;
  122.             $stock $stock $stock 0;
  123.             $data["item"][$item_code] = [
  124.                 "category_code" => $category_code,
  125.                 "name" => $item_name,
  126.                 "film" => $film,
  127.                 "film_addr" => $film_addr,
  128.                 "limit" => $limit,
  129.                 "stock" => $stock,
  130.                 "unit_name" => $unit_name,
  131.                 "day0" => $order_item[0],
  132.                 "day1" => $order_item[1],
  133.                 "day2" => $order_item[2],
  134.                 "day3" => $order_item[3],
  135.                 "day4" => $order_item[4],
  136.                 "day5" => $order_item[5],
  137.                 "day6" => $order_item[6],
  138.                 "day7" => $order_item[7],
  139.                 "day8" => $order_item[8],
  140.                 "day9" => $order_item[9],
  141.                 "day10" => $order_item[10],
  142.                 'later' => $later,
  143.                 "day0_diff" => $this->checkStockDiff($limit$stock$order_item0),
  144.                 'day1_diff' => $this->checkStockDiff($limit$stock$order_item1),
  145.                 'day2_diff' => $this->checkStockDiff($limit$stock$order_item2),
  146.                 'day3_diff' => $this->checkStockDiff($limit$stock$order_item3),
  147.                 'day4_diff' => $this->checkStockDiff($limit$stock$order_item4),
  148.                 'day5_diff' => $this->checkStockDiff($limit$stock$order_item5),
  149.                 'day6_diff' => $this->checkStockDiff($limit$stock$order_item6),
  150.                 'day7_diff' => $this->checkStockDiff($limit$stock$order_item7),
  151.                 'day8_diff' => $this->checkStockDiff($limit$stock$order_item8),
  152.                 'day9_diff' => $this->checkStockDiff($limit$stock$order_item9),
  153.                 'day10_diff' => $this->checkStockDiff($limit$stock$order_item10),
  154.                 'later_diff' => $this->checkStockDiff($limit$stock$order_item10),
  155.             ];
  156.         }
  157.         // カテゴリを配列に持たす
  158.         $org_top_categories $this->commonService->getTopCategoryList();
  159.         $top_categories = [];
  160.         foreach($this->getOriginalConfig("param""categories") as $tmp_cate) {
  161.             foreach($org_top_categories as $key => $category){
  162.                 if(preg_match("/$category/"$tmp_cate)) {
  163.                     $top_categories[$tmp_cate][] = $key;
  164.                 }
  165.             }
  166.         }
  167.         $search["keyword"] = $request->get('search_keyword');
  168.         $search["category_501"] = $request->get('search_category_501');
  169.         $search["category_key"] = $request->get('search_category_key');
  170.         return $this->render('order.html.twig', [
  171.             "data" => $data,
  172.             "search" => $search,
  173.             "top_categories" => $top_categories,
  174.             "json_top_categories" => json_encode($top_categories),
  175.         ]);
  176.     }
  177.     static function checkStockDiff($limit$stock$day$last) {
  178.         $sum 0;
  179.         for($i=0$i<=$last$i++){
  180.             $sum+= $day[$i];
  181.         }
  182.         //$result = $limit - ($stock - $sum);
  183.         $result $sum $stock;
  184.         return $result $result 0;
  185.     }
  186.     //フィールド一覧取得
  187.     /**
  188.      * @Route("/order/get_field", name="order_field")
  189.      */
  190.     public function getOrderField() {
  191.         //$this->kintoneService->setKintoneConf('prod');
  192.         $result $this->kintoneService->requestGetForm("order");
  193.         return $this->render('field.twig', ["title" => "受注管理""fields" => $result["properties"]]);
  194.     }
  195. }