<?php

namespace App\Http\Controllers;
use DB;
use Illuminate\Http\Request;

class HomeController extends Controller
{
	/*
		// public function Test(){
		// 	$datenow = GETDATE()." 23:00:00.000";
		// 	$dateAll = GETDATE()." 00:00:00.000";
		// 	$datemid = GETDATE()." 23:59:59.000";
			
		// 	$data["pdieFull"] =DB::SELECT("select SUM(qty_in_lot) as pdieFull 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE diebond_plan_start_dt >= '".$dateAll."' AND diebond_plan_start_dt <= '".$datemid."'");
			
		// 	$data["pdieNow"] =DB::SELECT("select SUM(qty_in_lot) as pdieNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE diebond_plan_start_dt >= '".$dateAll."' AND diebond_plan_start_dt <= '".$datenow."'");

		// 	$data["povenFull"] =DB::SELECT("select SUM(qty_in_lot) as povenFull 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE oven_diebond_plan_start_dt >= '".$dateAll."' AND oven_diebond_plan_start_dt <= '".$datemid."'");
		// 	$data["povenNow"] =DB::SELECT("select SUM(qty_in_lot) as povenNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE oven_diebond_plan_start_dt >= '".$dateAll."' AND oven_diebond_plan_start_dt <= '".$datenow."'");

		// 	$data["pwireFull"] =DB::SELECT("select SUM(qty_in_lot) as pwireFull 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE wirebond_plan_start_dt >= '".$dateAll."' AND wirebond_plan_start_dt <= '".$datemid."'");
		// 	$data["pwireNow"] =DB::SELECT("select SUM(qty_in_lot) as pwireNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE wirebond_plan_start_dt >=  '".$dateAll."' AND wirebond_plan_start_dt <= '".$datenow."'");

		// 	$data["pbondinFull"] =DB::SELECT("select SUM(qty_in_lot) as pbondinFull 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE bonding_ins_plan_start_dt >= '".$dateAll."' AND bonding_ins_plan_start_dt <= '".$datemid."'");
		// 	$data["pbondinNow"] =DB::SELECT("select SUM(qty_in_lot) as pbondinNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE bonding_ins_plan_start_dt >= '".$dateAll."' AND bonding_ins_plan_start_dt <= '".$datenow."'");

		// 	$data["pmoldFull"] =DB::SELECT("select SUM(qty_in_lot) as pmoldFull 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE mold_plan_start_dt >= '".$dateAll."' AND mold_plan_start_dt <= '".$datemid."'");
		// 	$data["pmoldNow"] =DB::SELECT("select SUM(qty_in_lot) as pmoldNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE mold_plan_start_dt >= '".$dateAll."' AND mold_plan_start_dt <= '".$datenow."'");

		// 	$data["povenmoldFull"] =DB::SELECT("select SUM(qty_in_lot) as povenmoldFull 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE oven_mold_plan_start_dt >= '".$dateAll."' AND oven_mold_plan_start_dt <= '".$datemid."'");
		// 	$data["povenmoldNow"] =DB::SELECT("select SUM(qty_in_lot) as povenmoldNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE oven_mold_plan_start_dt >= '".$dateAll."' AND oven_mold_plan_start_dt <= '".$datenow."'");

		// 	$data["pdicerFull"] =DB::SELECT("select SUM(qty_in_lot) as pdicerFull 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE dicer_plan_start_dt >= '".$dateAll."' AND dicer_plan_start_dt <= '".$datemid."'");
		// 	$data["pdicerNow"] =DB::SELECT("select SUM(qty_in_lot) as pdicerNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE dicer_plan_start_dt >= '".$dateAll."' AND dicer_plan_start_dt <= '".$datenow."'");

		// 	$data["pappeaFull"] =DB::SELECT("select SUM(qty_in_lot) as pappeaFull 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE appearance_plan_start_dt >= '".$dateAll."' AND appearance_plan_start_dt <= '".$datemid."'");
		// 	$data["pappeaNow"] =DB::SELECT("select SUM(qty_in_lot) as pappeaNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE appearance_plan_start_dt >= '".$dateAll."' AND appearance_plan_start_dt <= '".$datenow."'");

		// 	$data["pcalssFull"] =DB::SELECT("select SUM(qty_in_lot) as pcalssFull 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE classify_plan_start_dt >= '".$dateAll."' AND classify_plan_start_dt <= '".$datemid."'");
			
		// 	$data["pcalssNow"] =DB::SELECT("select SUM(qty_in_lot) as pcalssNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE classify_plan_start_dt >= '".$dateAll."' AND classify_plan_start_dt <= '".$datenow."'");

		// 	//input

		// 	$data["indieNow"] =DB::SELECT("select SUM(qty_in_lot) as indieNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE diebond_act_start_dt >= '".$dateAll."' AND diebond_act_start_dt <= '".$datenow."'");

		// 	$data["inovenNow"] =DB::SELECT("select SUM(diebond_output) as inovenNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE oven_diebond_act_start_dt >= '".$dateAll."' AND oven_diebond_act_start_dt <= '".$datenow."'");

		// 	$data["inwirebondNow"] =DB::SELECT("select SUM(diebond_output) as inwirebondNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE wirebond_act_start_dt >= '".$dateAll."' AND wirebond_act_start_dt <= '".$datenow."'");

		// 	$data["inbondingNow"] =DB::SELECT("select SUM(wirebond_output ) as inbondingNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE bonding_ins_act_start_dt >= '".$dateAll."' AND bonding_ins_act_start_dt <= '".$datenow."'");

		// 	$data["inmoldNow"] =DB::SELECT("select SUM(bonding_ins_output) as inmoldNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE mold_act_start_dt >= '".$dateAll."' AND mold_act_start_dt <= '".$datenow."'");

		// 	$data["inovenmoldNow"] =DB::SELECT("select SUM(mold_output) as inovenmoldNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE oven_mold_act_start_dt >= '".$dateAll."' AND oven_mold_act_start_dt <= '".$datenow."'");

		// 	$data["indicerNow"] =DB::SELECT("select SUM(mold_output) as indicerNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE dicer_act_start_dt >= '".$dateAll."' AND dicer_act_start_dt <= '".$datenow."'");

		// 	$data["inappearaNow"] =DB::SELECT("select SUM(dicer_output) as inappearaNow 
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE appearance_act_start_dt >= '".$dateAll."' AND appearance_act_start_dt <= '".$datenow."'");
		
		// 	$data["incalssNow"] =DB::SELECT("select SUM(input) as incalssNow
		// 	from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		// 	(select classify_lot
		// 	from [WMSASIDB].[dbo].[ProductionPlan] 
		// 	WHERE classify_act_start_dt >= '".$dateAll."' AND classify_act_start_dt <= '".$datenow."')");
		

		// 	//output
		// 	$data["outdieend"] =DB::SELECT("select SUM(diebond_output) as outdieend
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE diebond_act_end_dt >= '".$dateAll."'  AND diebond_act_end_dt <= '".$datenow."'");

		// 	$data["outovenend"] =DB::SELECT("select SUM(diebond_output) as outovenend
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE oven_diebond_act_end_dt >= '".$dateAll."' AND oven_diebond_act_end_dt <= '".$datenow."'");

		// 	$data["outwirebondend"] =DB::SELECT("select SUM(diebond_output) as outwirebondend
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE wirebond_act_end_dt >= '".$dateAll."' AND wirebond_act_end_dt <= '".$datenow."'");

		// 	$data["outbondingend"] =DB::SELECT("select SUM(wirebond_output) as outbondingend
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE bonding_ins_act_end_dt >= '".$dateAll."' AND bonding_ins_act_end_dt <= '".$datenow."'");

		// 	$data["outmoldend"] =DB::SELECT("select SUM(wirebond_output) as outmoldend
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE mold_act_end_dt >= '".$dateAll."' AND mold_act_end_dt <= '".$datenow."'");

		// 	$data["outoven_moldend"] =DB::SELECT("select SUM(mold_output) as outoven_moldend
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE oven_mold_act_end_dt >= '".$dateAll."' AND oven_mold_act_end_dt <= '".$datenow."'");

		// 	$data["outdicer_actend"] =DB::SELECT("select SUM(mold_output) as outdicer_actend
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE dicer_act_end_dt >= '".$dateAll."' AND dicer_act_end_dt <= '".$datenow."'");

		// 	$data["outappearanceend"] =DB::SELECT("select SUM(dicer_output) as outappearanceend
		// 	from [WMSASIDB].[dbo].[ProductionPlan]
		// 	WHERE appearance_act_end_dt >= '".$dateAll."' AND appearance_act_end_dt <= '".$datenow."'");

		// 	$data["outclassifyend"] =DB::SELECT("select SUM(output) as outclassifyend
		// 	from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		// 	(select classify_lot
		// 	from [WMSASIDB].[dbo].[ProductionPlan] 
		// 	WHERE classify_act_end_dt >= '".$dateAll."' AND classify_act_end_dt <= '".$datenow."')");

		// 	//NG

		// 	$data["ngbonding"] =DB::SELECT("select SUM(qty) as ngbonding
		// 	from [WMSASIDB].[dbo].[NGFactorList] 
		// 	WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'BONDING_INS' ");

		// 	$data["ngmold"] =DB::SELECT("select SUM(qty) as ngmold
		// 	from [WMSASIDB].[dbo].[NGFactorList] 
		// 	WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'MOLD' ");

		// 	$data["ngdicer"] =DB::SELECT("select SUM(qty) as ngdicer
		// 	from [WMSASIDB].[dbo].[NGFactorList] 
		// 	WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'DICER' ");

		// 	$data["ngappear"] =DB::SELECT("select SUM(qty) as ngappear
		// 	from [WMSASIDB].[dbo].[NGFactorList] 
		// 	WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'APPEARANCE' ");

		// 	$data["ngclassify"] =DB::SELECT("select SUM(qty) as ngclassify from [WMSASIDB].[dbo].[ClassifyOutput]
		// 	where output_type = 'NG' AND create_dt >='".$dateAll."'  AND create_dt <= '".$datenow."'");
			
		// 	// **** top3 *****
		// 	 		/// BONDING_INS
		// 	$data["t3bonding"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		// 	WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		// 	AND process = 'BONDING_INS'
		// 	GROUP BY ng_code, ng_name ORDER BY sumqty desc");	

		// 	$data["t3mold"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		// 	WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		// 	AND process = 'MOLD'
		// 	GROUP BY ng_code, ng_name ORDER BY sumqty desc");
			
		// 	$data["t3dicer"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		// 	WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		// 	AND process = 'DICER'
		// 	GROUP BY ng_code, ng_name ORDER BY sumqty desc");
			
		// 	$data["t3appea"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		// 	WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		// 	AND process = 'APPEARANCE'
		// 	GROUP BY ng_code, ng_name ORDER BY sumqty desc");	

		// 	$data["t3classi"] =DB::SELECT(" select top 2 output_name, SUM(qty) as sumng 
		// 	from [WMSASIDB].[dbo].[ClassifyOutput] 
		// 	where create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND output_type = 'NG'
		// 	GROUP BY output_name ORDER BY sumng desc");

		// 	// dd($data);


		// 	return view("sss.display",$data);
		// }
	*/

	public function loadData(){	

		// code date current 
		// -----------------
		// $date = date("Y-m-d");
		// $dateOne = date("Y-m-d", strtotime("+1 day", strtotime($date))); 
		// $datenow = date("Y-m-d h:i:sa");
		// $dateAll = date('Y-m-d')." 07:59:00.000";
		// $datemid = $dateOne." 08:00:00.000";

		// $dateshow = date('d-m-Y');
		// $timeshow = date('h:i:sa');
		// $data["dateshow"] = $dateshow;
		// $data["timeshow"] = $timeshow;

		// $data['datestring'] = date("m")."'M ".date("d")."'D (".date("D").")";

		// =======================================================================================


		// code fix date for testing 
		// -------------------------
		//$date = "2023-09-07"; // change date here.
		$date = date("Y-m-d");
		$dateOne = date("Y-m-d", strtotime("+1 day", strtotime($date)));  
		$datenow = $date." ".date("h:i:sa");
		$dateAll = "$date 07:59:00.000";
		$datemid = $dateOne." 08:00:00.000";
		
		$data["dateshow"] = date('d-m-Y', strtotime($date));
		$data["timeshow"] = date('h:i:sa');

		$data['datestring'] = date("m",strtotime($date))."'M ".date("d",strtotime($date))."'D (".date("D",strtotime($date)).")";

		// ========================================================================================


		$data["pdieFull"] =DB::SELECT("select SUM(qty_in_lot) as pdieFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_plan_start_dt >= '".$dateAll."' AND diebond_plan_start_dt <= '".$datemid."'");
		
		$data["pdieNow"] =DB::SELECT("select SUM(qty_in_lot) as pdieNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_plan_start_dt >= '".$dateAll."' AND diebond_plan_start_dt <= '".$datenow."'");

		$data["povenFull"] =DB::SELECT("select SUM(qty_in_lot) as povenFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_plan_start_dt >= '".$dateAll."' AND oven_diebond_plan_start_dt <= '".$datemid."'");

		$data["povenNow"] =DB::SELECT("select SUM(qty_in_lot) as povenNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_plan_start_dt >= '".$dateAll."' AND oven_diebond_plan_start_dt <= '".$datenow."'");

		$data["pwireFull"] =DB::SELECT("select SUM(qty_in_lot) as pwireFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_plan_start_dt >= '".$dateAll."' AND wirebond_plan_start_dt <= '".$datemid."'");

		$data["pwireNow"] =DB::SELECT("select SUM(qty_in_lot) as pwireNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_plan_start_dt >=  '".$dateAll."' AND wirebond_plan_start_dt <= '".$datenow."'");

		$data["pbondinFull"] =DB::SELECT("select SUM(qty_in_lot) as pbondinFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_plan_start_dt >= '".$dateAll."' AND bonding_ins_plan_start_dt <= '".$datemid."'");
		
		$data["pbondinNow"] =DB::SELECT("select SUM(qty_in_lot) as pbondinNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_plan_start_dt >= '".$dateAll."' AND bonding_ins_plan_start_dt <= '".$datenow."'");

		$data["pmoldFull"] =DB::SELECT("select SUM(qty_in_lot) as pmoldFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_plan_start_dt >= '".$dateAll."' AND mold_plan_start_dt <= '".$datemid."'");
		$data["pmoldNow"] =DB::SELECT("select SUM(qty_in_lot) as pmoldNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_plan_start_dt >= '".$dateAll."' AND mold_plan_start_dt <= '".$datenow."'");

		$data["povenmoldFull"] =DB::SELECT("select SUM(qty_in_lot) as povenmoldFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_plan_start_dt >= '".$dateAll."' AND oven_mold_plan_start_dt <= '".$datemid."'");

		$data["povenmoldNow"] =DB::SELECT("select SUM(qty_in_lot) as povenmoldNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_plan_start_dt >= '".$dateAll."' AND oven_mold_plan_start_dt <= '".$datenow."'");

		$data["pdicerFull"] =DB::SELECT("select SUM(qty_in_lot) as pdicerFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_plan_start_dt >= '".$dateAll."' AND dicer_plan_start_dt <= '".$datemid."'");

		$data["pdicerNow"] =DB::SELECT("select SUM(qty_in_lot) as pdicerNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_plan_start_dt >= '".$dateAll."' AND dicer_plan_start_dt <= '".$datenow."'");

		$data["pappeaFull"] =DB::SELECT("select SUM(qty_in_lot) as pappeaFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_plan_start_dt >= '".$dateAll."' AND appearance_plan_start_dt <= '".$datemid."'");

		$data["pappeaNow"] =DB::SELECT("select SUM(qty_in_lot) as pappeaNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_plan_start_dt >= '".$dateAll."' AND appearance_plan_start_dt <= '".$datenow."'");

		$data["pcalssFull"] =DB::SELECT("select SUM(qty_in_lot) as pcalssFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE classify_plan_start_dt >= '".$dateAll."' AND classify_plan_start_dt <= '".$datemid."'");

		$data["pcalssNow"] =DB::SELECT("select SUM(qty_in_lot) as pcalssNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE classify_plan_start_dt >= '".$dateAll."' AND classify_plan_start_dt <= '".$datenow."'");

		//input pcs

		$data["indieNow"] =DB::SELECT("select SUM(qty_in_lot) as indieNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_act_start_dt >= '".$dateAll."' AND diebond_act_start_dt <= '".$datenow."'");

		$data["inovenNow"] =DB::SELECT("select SUM(diebond_output) as inovenNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_act_start_dt >= '".$dateAll."' AND oven_diebond_act_start_dt <= '".$datenow."'");

		$data["inwirebondNow"] =DB::SELECT("select SUM(diebond_output) as inwirebondNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_act_start_dt >= '".$dateAll."' AND wirebond_act_start_dt <= '".$datenow."'");

		$data["inbondingNow"] =DB::SELECT("select SUM(wirebond_output ) as inbondingNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_act_start_dt >= '".$dateAll."' AND bonding_ins_act_start_dt <= '".$datenow."'");

		$data["inmoldNow"] =DB::SELECT("select SUM(bonding_ins_output) as inmoldNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_act_start_dt >= '".$dateAll."' AND mold_act_start_dt <= '".$datenow."'");

		$data["inovenmoldNow"] =DB::SELECT("select SUM(mold_output) as inovenmoldNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_act_start_dt >= '".$dateAll."' AND oven_mold_act_start_dt <= '".$datenow."'");

		$data["indicerNow"] =DB::SELECT("select SUM(mold_output) as indicerNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_act_start_dt >= '".$dateAll."' AND dicer_act_start_dt <= '".$datenow."'");

		$data["inappearaNow"] =DB::SELECT("select SUM(dicer_output) as inappearaNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_act_start_dt >= '".$dateAll."' AND appearance_act_start_dt <= '".$datenow."'");
	
		$data["incalssNow"] =DB::SELECT("select SUM(input) as incalssNow
		from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		(select classify_lot
		from [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE classify_act_start_dt >= '".$dateAll."' AND classify_act_start_dt <= '".$datenow."')");

		// input Lot

		$data["indieNowlot"] =DB::SELECT("select count(lot_no) as indieNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_act_start_dt >= '".$dateAll."' AND diebond_act_start_dt <= '".$datenow."'");
		
		$data["inovenNowlot"] =DB::SELECT("select COUNT(lot_no) as inovenNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_act_start_dt >= '".$dateAll."' AND oven_diebond_act_start_dt <= '".$datenow."'");

		$data["inwirebondNowlot"] =DB::SELECT("select COUNT(lot_no) as inwirebondNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_act_start_dt >= '".$dateAll."' AND wirebond_act_start_dt <= '".$datenow."'");

		$data["inbondingNowlot"] =DB::SELECT("select COUNT(lot_no) as inbondingNowlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_act_start_dt >= '".$dateAll."' AND bonding_ins_act_start_dt <= '".$datenow."'");

		$data["inmoldNowlot"] =DB::SELECT("select COUNT(lot_no)  as inmoldNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_act_start_dt >= '".$dateAll."' AND mold_act_start_dt <= '".$datenow."'");

		$data["inovenmoldNowlot"] =DB::SELECT("select COUNT(lot_no) as inovenmoldNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_act_start_dt >= '".$dateAll."' AND oven_mold_act_start_dt <= '".$datenow."'");

		$data["indicerNowlot"] =DB::SELECT("select COUNT(lot_no) as indicerNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_act_start_dt >= '".$dateAll."' AND dicer_act_start_dt <= '".$datenow."'");

		$data["inappearaNowlot"] =DB::SELECT("select COUNT(lot_no) as inappearaNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_act_start_dt >= '".$dateAll."' AND appearance_act_start_dt <= '".$datenow."'");
	
		$data["incalssNowlot"] =DB::SELECT("select COUNT(classify_lot) as incalssNowlot
		from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		(select classify_lot
		from [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE classify_act_start_dt >= '".$dateAll."' AND classify_act_start_dt <= '".$datenow."')");


		//output
		$data["outdieend"] =DB::SELECT("select SUM(diebond_output) as outdieend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_act_end_dt >= '".$dateAll."'  AND diebond_act_end_dt <= '".$datenow."'");

		$data["outovenend"] =DB::SELECT("select SUM(diebond_output) as outovenend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_act_end_dt >= '".$dateAll."' AND oven_diebond_act_end_dt <= '".$datenow."'");

		$data["outwirebondend"] =DB::SELECT("select SUM(diebond_output) as outwirebondend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_act_end_dt >= '".$dateAll."' AND wirebond_act_end_dt <= '".$datenow."'");

		$data["outbondingend"] =DB::SELECT("select SUM(wirebond_output) as outbondingend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_act_end_dt >= '".$dateAll."' AND bonding_ins_act_end_dt <= '".$datenow."'");

		$data["outmoldend"] =DB::SELECT("select SUM(wirebond_output) as outmoldend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_act_end_dt >= '".$dateAll."' AND mold_act_end_dt <= '".$datenow."'");

		$data["outoven_moldend"] =DB::SELECT("select SUM(mold_output) as outoven_moldend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_act_end_dt >= '".$dateAll."' AND oven_mold_act_end_dt <= '".$datenow."'");

		$data["outdicer_actend"] =DB::SELECT("select SUM(mold_output) as outdicer_actend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_act_end_dt >= '".$dateAll."' AND dicer_act_end_dt <= '".$datenow."'");

		$data["outappearanceend"] =DB::SELECT("select SUM(dicer_output) as outappearanceend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_act_end_dt >= '".$dateAll."' AND appearance_act_end_dt <= '".$datenow."'");

		$data["outclassifyend"] =DB::SELECT("select SUM(output) as outclassifyend
		from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		(select classify_lot
		from [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE classify_act_end_dt >= '".$dateAll."' AND classify_act_end_dt <= '".$datenow."')");


		//output lot	
		$data["outdieendlot"] =DB::SELECT("select COUNT(lot_no) as outdieendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_act_end_dt >= '".$dateAll."'  AND diebond_act_end_dt <= '".$datenow."'");

		$data["outovenendlot"] =DB::SELECT("select COUNT(lot_no) as outovenendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_act_end_dt >= '".$dateAll."' AND oven_diebond_act_end_dt <= '".$datenow."'");

		$data["outwirebondendlot"] =DB::SELECT("select COUNT(lot_no) as outwirebondendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_act_end_dt >= '".$dateAll."' AND wirebond_act_end_dt <= '".$datenow."'");

		$data["outbondingendlot"] =DB::SELECT("select COUNT(lot_no) as outbondingendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_act_end_dt >= '".$dateAll."' AND bonding_ins_act_end_dt <= '".$datenow."'");

		$data["outmoldendlot"] =DB::SELECT("select COUNT(lot_no) as outmoldendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_act_end_dt >= '".$dateAll."' AND mold_act_end_dt <= '".$datenow."'");

		$data["outoven_moldendlot"] =DB::SELECT("select COUNT(lot_no) as outoven_moldendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_act_end_dt >= '".$dateAll."' AND oven_mold_act_end_dt <= '".$datenow."'");

		$data["outdicer_actendlot"] =DB::SELECT("select COUNT(lot_no) as outdicer_actendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_act_end_dt >= '".$dateAll."' AND dicer_act_end_dt <= '".$datenow."'");

		$data["outappearanceendlot"] =DB::SELECT("select COUNT(lot_no) as outappearanceendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_act_end_dt >= '".$dateAll."' AND appearance_act_end_dt <= '".$datenow."'");

		$data["outclassifyendlot"] =DB::SELECT("select COUNT(classify_lot) as outclassifyendlot
		from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		(select classify_lot
		from [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE classify_act_end_dt >= '".$dateAll."' AND classify_act_end_dt <= '".$datenow."')");		


		//NG

		$data["ngbonding"] =DB::SELECT("select SUM(qty) as ngbonding
		from [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'BONDING_INS' ");

		$data["ngmold"] =DB::SELECT("select SUM(qty) as ngmold
		from [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'MOLD' ");

		$data["ngdicer"] =DB::SELECT("select SUM(qty) as ngdicer
		from [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'DICER' ");

		$data["ngappear"] =DB::SELECT("select SUM(qty) as ngappear
		from [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'APPEARANCE' ");

		$data["ngclassify"] =DB::SELECT("select SUM(qty) as ngclassify from [WMSASIDB].[dbo].[ClassifyOutput]
		where output_type = 'NG' AND create_dt >='".$dateAll."'  AND create_dt <= '".$datenow."'");
		 
		// **** top3 *****
		 		/// BONDING_INS
		$data["t3bonding"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		AND process = 'BONDING_INS'
		GROUP BY ng_code, ng_name ORDER BY sumqty desc");	

		$data["t3mold"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		AND process = 'MOLD'
		GROUP BY ng_code, ng_name ORDER BY sumqty desc");
		
		$data["t3dicer"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		AND process = 'DICER'
		GROUP BY ng_code, ng_name ORDER BY sumqty desc");
		
		$data["t3appea"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		AND process = 'APPEARANCE'
		GROUP BY ng_code, ng_name ORDER BY sumqty desc");	

		$data["t3classi"] =DB::SELECT(" select top 2 output_name, SUM(qty) as sumng 
		from [WMSASIDB].[dbo].[ClassifyOutput] 
		where create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND output_type = 'NG'
		GROUP BY output_name ORDER BY sumng desc");

		// dd($data);

		// remark 

		$data["remarkdie"] =DB::SELECT("select top 2 lot_no, dienond_remark AS remark , count(dienond_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."'  AND create_dt <= '".$datenow."' AND process = 'DIE_BOND' AND dienond_remark is not null
		GROUP BY lot_no, dienond_remark ORDER BY total_remark desc");
		
		$data["remarkoven"] =DB::SELECT("select top 2 lot_no, oven_diebond_remark AS remark , count(oven_diebond_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE  create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'OVEN_DIE_BOND' AND oven_diebond_remark is not null
		GROUP BY lot_no, oven_diebond_remark ORDER BY total_remark desc");

		$data["remarkwirebond"] =DB::SELECT("select top 2 lot_no, wirebond_remark AS remark , count(wirebond_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'WIRE_BOND' AND wirebond_remark is not null
		GROUP BY lot_no, wirebond_remark ORDER BY total_remark desc");

		// $data["remarkbonding"] = array();

		$data["remarkmold"] =DB::SELECT("select top 2 lot_no, mold_remark AS remark , count(mold_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'MOLD' AND mold_remark is not null
		GROUP BY lot_no, mold_remark ORDER BY total_remark desc");

		$data["remarkovenmold"] =DB::SELECT("select top 2 lot_no, oven_mold_remark AS remark , count(oven_mold_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'OVEN_MOLD' AND oven_mold_remark is not null
		GROUP BY lot_no, oven_mold_remark ORDER BY total_remark desc");

		$data["remarkdicer"] =DB::SELECT("select top 2 lot_no, dicer_remark AS remark , count(dicer_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'DICER' AND dicer_remark is not null
		GROUP BY lot_no, dicer_remark ORDER BY total_remark desc");

		$data["remarkappearance"] = array();

		$data["remarkclassif"] =DB::SELECT("select top 2 lot_no, classify_remark AS remark , count(classify_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'CLASSIFY' AND classify_remark is not null
		GROUP BY lot_no, classify_remark ORDER BY total_remark desc");




		echo json_encode($data);
	}

	public function index(){
		//return view("sss.display2");
		header( "refresh: 1; url=/display/screen1" );
	}

	public function screen1(){
		return view("display.screen1");
	}

	public function loadDataScreen2(){
		// code date current 
		// -----------------
		// $date = date("Y-m-d");
		// $dateOne = date("Y-m-d", strtotime("+1 day", strtotime($date))); 
		// $datenow = date("Y-m-d h:i:sa");
		// $dateAll = date('Y-m-d')." 07:59:00.000";
		// $datemid = $dateOne." 08:00:00.000";

		// $dateshow = date('d-m-Y');
		// $timeshow = date('h:i:sa');
		// $data["dateshow"] = $dateshow;
		// $data["timeshow"] = $timeshow;

		// $data['datestring'] = date("m")."'M ".date("d")."'D (".date("D").")";

		// =======================================================================================


		// code fix date for testing 
		// -------------------------
		$date = "2023-09-20"; // change date here.
		//$date = date("Y-m-d");
		$timeshow = date("h:i:sa");
		$H_check = date("H");
		$H_check = 20;
		if( $H_check>=8 && $H_check<20 ){
			$dateOne = $date;
			//$dateOne = date("Y-m-d", strtotime("-1 day", strtotime($date)));  
			$dateAll = "$date 08:00:00.000";
			$datemid = $dateOne." 19:59:59.000";
			// $dateOne = date("Y-m-d", strtotime("-1 day", strtotime($date))); 
			// $dateAll = "$dateOne 20:00:00.000";
			// $datemid = $date." 19:59:59.000";
			//$list_hours = array("08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00");
		}else{
			$dateOne = date("Y-m-d", strtotime("+1 day", strtotime($date)));  
			$dateAll = "$date 20:00:00.000";
			//$dateAll = "$date 08:00:00.000";
			$datemid = $dateOne." 07:59:59.000";
			// $dateOne = date("Y-m-d", strtotime("+1 day", strtotime($date)));  
			// $dateAll = "$date 08:00:00.000";
			// $datemid = $dateOne." 07:59:59.000";
			//$list_hours = array("20:00","21:00","22:00","23:00","00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00");
		}
		
		// $dateOne = $date; 
		// $datemid = date("Y-m-d", strtotime("+1 day", strtotime($date)))." 07:59:59.000";

		$datenow = $date." ".$timeshow;
		$data["timeshow"] = $timeshow;
		$data["dateshow"] = date('d M Y', strtotime($date));

		$data["dateAll"] = $dateAll;
		$data["datemid"] = $datemid;
		$data['H_check'] = $H_check;
		//$data['datestring'] = date("m",strtotime($date))."'M ".date("d",strtotime($date))."'D (".date("D",strtotime($date)).")";

		// ========================================================================================

		$data['lot_not_start'] = DB::SELECT("SELECT ISNULL(SUM(IIF(ISNULL(diebond_act_start_dt,1)=1,1,0)),0) AS notstart
											FROM [WMSASIDB].[dbo].[ProductionPlan]
											WHERE diebond_act_start_dt >= '$dateAll' AND diebond_act_start_dt <= '$datemid'");

		$data['lot_finish'] = DB::SELECT("SELECT  ISNULL(SUM(IIF(ISNULL(classify_act_end_dt,0)=0,0,1)),0) AS finish
											FROM [WMSASIDB].[dbo].[ProductionPlan]
											WHERE (diebond_act_start_dt >= '$dateAll' AND diebond_act_start_dt <= '$datemid') AND ( classify_act_end_dt >= '$dateAll' AND classify_act_end_dt <= '$datemid')");

		$data['lot_data'] = DB::SELECT("SELECT  lot_no, 
												diebond_plan_start_dt AS diebond_plan,  
												IIF(ISNULL(diebond_plan_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), diebond_plan_start_dt, 121),':00' ) ) AS block_diebond_plan,
												IIF(ISNULL(diebond_plan_start_dt,'')='','', CONVERT(VARCHAR(5), diebond_plan_start_dt, 114 )) AS diebond_plan_time,

												diebond_act_start_dt AS diebond_act, 
												IIF(ISNULL(diebond_act_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), diebond_act_start_dt, 121),':00' ) ) AS block_diebond_act,
												IIF(ISNULL(diebond_act_start_dt,'')='','', CONVERT(VARCHAR(5), diebond_act_start_dt, 114)) AS diebond_act_time,

												oven_diebond_plan_start_dt AS oven_diebond_plan, 
												IIF(ISNULL(oven_diebond_plan_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), oven_diebond_plan_start_dt, 121),':00' ) ) AS block_ovediebond_plan,
												IIF(ISNULL(oven_diebond_plan_start_dt,'')='','', CONVERT(VARCHAR(5), oven_diebond_plan_start_dt, 114)) AS ovediebond_plan_time,

												oven_diebond_act_start_dt AS oven_diebond_act,
												IIF(ISNULL(oven_diebond_act_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), oven_diebond_act_start_dt, 121),':00' ) ) AS block_ovediebond_act,
												IIF(ISNULL(oven_diebond_act_start_dt,'')='','', CONVERT(VARCHAR(5), oven_diebond_act_start_dt, 114)) AS ovediebond_act_time,

												wirebond_plan_start_dt AS wirebond_plan,
												IIF(ISNULL(wirebond_plan_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), wirebond_plan_start_dt, 121),':00' ) ) AS block_wirebond_plan,
												IIF(ISNULL(wirebond_plan_start_dt,'')='','', CONVERT(VARCHAR(5), wirebond_plan_start_dt, 114)) AS wirebond_plan_time,

												wirebond_act_start_dt AS wirebond_act,
												IIF(ISNULL(wirebond_act_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), wirebond_act_start_dt, 121),':00' ) ) AS block_wirebond_act,
												IIF(ISNULL(wirebond_act_start_dt,'')='','', CONVERT(VARCHAR(5), wirebond_act_start_dt, 114)) AS wirebond_act_time,

												bonding_ins_plan_start_dt AS bonding_ins_plan,
												IIF(ISNULL(bonding_ins_plan_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), bonding_ins_plan_start_dt, 121),':00' ) ) AS block_bondingins_plan,
												IIF(ISNULL(bonding_ins_plan_start_dt,'')='','', CONVERT(VARCHAR(5), bonding_ins_plan_start_dt, 114)) AS bondingins_plan_time,

												bonding_ins_act_start_dt AS bonding_ins_act,
												IIF(ISNULL(bonding_ins_act_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), bonding_ins_act_start_dt, 121),':00' ) ) AS block_bondingins_act,
												IIF(ISNULL(bonding_ins_act_start_dt,'')='','', CONVERT(VARCHAR(5), bonding_ins_act_start_dt, 114)) AS bondingins_act_time,

												mold_plan_start_dt AS mold_plan,
												IIF(ISNULL(mold_plan_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), mold_plan_start_dt, 121),':00' ) ) AS block_mold_plan,
												IIF(ISNULL(mold_plan_start_dt,'')='','', CONVERT(VARCHAR(5), mold_plan_start_dt, 114)) AS mold_plan_time,

												mold_act_start_dt AS mold_act,
												IIF(ISNULL(mold_act_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), mold_act_start_dt, 121),':00' ) ) AS block_mold_act,
												IIF(ISNULL(mold_act_start_dt,'')='','', CONVERT(VARCHAR(5), mold_act_start_dt, 114)) AS mold_act_time,

												oven_mold_plan_start_dt AS oven_mold_plan,
												IIF(ISNULL(oven_mold_plan_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), oven_mold_plan_start_dt, 121),':00' ) ) AS block_ovemold_plan,
												IIF(ISNULL(oven_mold_plan_start_dt,'')='','', CONVERT(VARCHAR(5), oven_mold_plan_start_dt, 114)) AS ovemold_plan_time,

												oven_mold_act_start_dt AS oven_mold_act,
												IIF(ISNULL(oven_mold_act_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), oven_mold_act_start_dt, 121),':00' ) ) AS block_ovemold_act,
												IIF(ISNULL(oven_mold_act_start_dt,'')='','', CONVERT(VARCHAR(5), oven_mold_act_start_dt, 114)) AS ovemold_act_time,

												dicer_plan_start_dt AS dicer_plan,
												IIF(ISNULL(dicer_plan_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), dicer_plan_start_dt, 121),':00' ) ) AS block_dicer_plan,
												IIF(ISNULL(dicer_plan_start_dt,'')='','', CONVERT(VARCHAR(5), dicer_plan_start_dt, 114)) AS dicer_plan_time,

												dicer_act_start_dt AS dicer_act,
												IIF(ISNULL(dicer_act_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), dicer_act_start_dt, 121),':00' ) ) AS block_dicer_act,
												IIF(ISNULL(dicer_act_start_dt,'')='','', CONVERT(VARCHAR(5), dicer_act_start_dt, 114)) AS dicer_act_time,

												appearance_plan_start_dt AS appea_plan,
												IIF(ISNULL(appearance_plan_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), appearance_plan_start_dt, 121),':00' ) ) AS block_appea_plan,
												IIF(ISNULL(appearance_plan_start_dt,'')='','', CONVERT(VARCHAR(5), appearance_plan_start_dt, 114)) AS appea_plan_time,

												appearance_act_start_dt AS appea_act,
												IIF(ISNULL(appearance_act_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), appearance_act_start_dt, 121),':00' ) ) AS block_appea_act_time,
												IIF(ISNULL(appearance_act_start_dt,'')='','', CONVERT(VARCHAR(5), appearance_act_start_dt, 114)) AS appea_act_time,

												classify_plan_start_dt AS classi_plan,
												IIF(ISNULL(classify_plan_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), classify_plan_start_dt, 121),':00' ) ) AS block_classi_plan,
												IIF(ISNULL(classify_plan_start_dt,'')='','', CONVERT(VARCHAR(5), classify_plan_start_dt, 114)) AS classi_plan_time,

												classify_act_start_dt AS classi_act,
												IIF(ISNULL(classify_act_start_dt,'')='','', CONCAT( CONVERT(VARCHAR(13), classify_act_start_dt, 121),':00' ) ) AS block_classi_act,
												IIF(ISNULL(classify_act_start_dt,'')='','', CONVERT(VARCHAR(5), classify_act_start_dt, 114)) AS classi_act_time

										FROM [WMSASIDB].[dbo].[ProductionPlan]
										WHERE diebond_act_start_dt >= '$dateAll' AND diebond_act_start_dt <= '$datemid'
										ORDER BY lot_no, diebond_plan 	");

		echo json_encode($data);
	}

	public function screen2(){
		return view("display.screen2");
	}

	public function loadDataScreen3(){	

		// code date current 
		// -----------------
		// $date = date("Y-m-d");
		// $dateOne = date("Y-m-d", strtotime("+1 day", strtotime($date))); 
		// $datenow = date("Y-m-d h:i:sa");
		// $dateAll = date('Y-m-d')." 07:59:00.000";
		// $datemid = $dateOne." 08:00:00.000";

		// $dateshow = date('d-m-Y');
		// $timeshow = date('h:i:sa');
		// $data["dateshow"] = $dateshow;
		// $data["timeshow"] = $timeshow;

		// $data['datestring'] = date("m")."'M ".date("d")."'D (".date("D").")";

		// =======================================================================================


		// code fix date for testing 
		// -------------------------
		//$date = "2023-09-07"; // change date here.
		$date = date("Y-m-d");
		$dateOne = date("Y-m-d", strtotime("+1 day", strtotime($date)));  
		$datenow = $date." ".date("h:i:sa");
		$dateAll = "$date 07:59:00.000";
		$datemid = $dateOne." 08:00:00.000";
		
		$data["dateshow"] = date('d-m-Y', strtotime($date));
		$data["timeshow"] = date('h:i:sa');

		$data['datestring'] = date("m",strtotime($date))."'M ".date("d",strtotime($date))."'D (".date("D",strtotime($date)).")";

		// ========================================================================================


		$data["pdieFull"] =DB::SELECT("select SUM(qty_in_lot) as pdieFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_plan_start_dt >= '".$dateAll."' AND diebond_plan_start_dt <= '".$datemid."'");
		
		$data["pdieNow"] =DB::SELECT("select SUM(qty_in_lot) as pdieNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_plan_start_dt >= '".$dateAll."' AND diebond_plan_start_dt <= '".$datenow."'");

		$data["povenFull"] =DB::SELECT("select SUM(qty_in_lot) as povenFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_plan_start_dt >= '".$dateAll."' AND oven_diebond_plan_start_dt <= '".$datemid."'");

		$data["povenNow"] =DB::SELECT("select SUM(qty_in_lot) as povenNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_plan_start_dt >= '".$dateAll."' AND oven_diebond_plan_start_dt <= '".$datenow."'");

		$data["pwireFull"] =DB::SELECT("select SUM(qty_in_lot) as pwireFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_plan_start_dt >= '".$dateAll."' AND wirebond_plan_start_dt <= '".$datemid."'");

		$data["pwireNow"] =DB::SELECT("select SUM(qty_in_lot) as pwireNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_plan_start_dt >=  '".$dateAll."' AND wirebond_plan_start_dt <= '".$datenow."'");

		$data["pbondinFull"] =DB::SELECT("select SUM(qty_in_lot) as pbondinFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_plan_start_dt >= '".$dateAll."' AND bonding_ins_plan_start_dt <= '".$datemid."'");
		
		$data["pbondinNow"] =DB::SELECT("select SUM(qty_in_lot) as pbondinNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_plan_start_dt >= '".$dateAll."' AND bonding_ins_plan_start_dt <= '".$datenow."'");

		$data["pmoldFull"] =DB::SELECT("select SUM(qty_in_lot) as pmoldFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_plan_start_dt >= '".$dateAll."' AND mold_plan_start_dt <= '".$datemid."'");
		$data["pmoldNow"] =DB::SELECT("select SUM(qty_in_lot) as pmoldNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_plan_start_dt >= '".$dateAll."' AND mold_plan_start_dt <= '".$datenow."'");

		$data["povenmoldFull"] =DB::SELECT("select SUM(qty_in_lot) as povenmoldFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_plan_start_dt >= '".$dateAll."' AND oven_mold_plan_start_dt <= '".$datemid."'");

		$data["povenmoldNow"] =DB::SELECT("select SUM(qty_in_lot) as povenmoldNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_plan_start_dt >= '".$dateAll."' AND oven_mold_plan_start_dt <= '".$datenow."'");

		$data["pdicerFull"] =DB::SELECT("select SUM(qty_in_lot) as pdicerFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_plan_start_dt >= '".$dateAll."' AND dicer_plan_start_dt <= '".$datemid."'");

		$data["pdicerNow"] =DB::SELECT("select SUM(qty_in_lot) as pdicerNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_plan_start_dt >= '".$dateAll."' AND dicer_plan_start_dt <= '".$datenow."'");

		$data["pappeaFull"] =DB::SELECT("select SUM(qty_in_lot) as pappeaFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_plan_start_dt >= '".$dateAll."' AND appearance_plan_start_dt <= '".$datemid."'");

		$data["pappeaNow"] =DB::SELECT("select SUM(qty_in_lot) as pappeaNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_plan_start_dt >= '".$dateAll."' AND appearance_plan_start_dt <= '".$datenow."'");

		$data["pcalssFull"] =DB::SELECT("select SUM(qty_in_lot) as pcalssFull 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE classify_plan_start_dt >= '".$dateAll."' AND classify_plan_start_dt <= '".$datemid."'");

		$data["pcalssNow"] =DB::SELECT("select SUM(qty_in_lot) as pcalssNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE classify_plan_start_dt >= '".$dateAll."' AND classify_plan_start_dt <= '".$datenow."'");

		//input pcs

		$data["indieNow"] =DB::SELECT("select SUM(qty_in_lot) as indieNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_act_start_dt >= '".$dateAll."' AND diebond_act_start_dt <= '".$datenow."'");

		$data["inovenNow"] =DB::SELECT("select SUM(diebond_output) as inovenNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_act_start_dt >= '".$dateAll."' AND oven_diebond_act_start_dt <= '".$datenow."'");

		$data["inwirebondNow"] =DB::SELECT("select SUM(diebond_output) as inwirebondNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_act_start_dt >= '".$dateAll."' AND wirebond_act_start_dt <= '".$datenow."'");

		$data["inbondingNow"] =DB::SELECT("select SUM(wirebond_output ) as inbondingNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_act_start_dt >= '".$dateAll."' AND bonding_ins_act_start_dt <= '".$datenow."'");

		$data["inmoldNow"] =DB::SELECT("select SUM(bonding_ins_output) as inmoldNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_act_start_dt >= '".$dateAll."' AND mold_act_start_dt <= '".$datenow."'");

		$data["inovenmoldNow"] =DB::SELECT("select SUM(mold_output) as inovenmoldNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_act_start_dt >= '".$dateAll."' AND oven_mold_act_start_dt <= '".$datenow."'");

		$data["indicerNow"] =DB::SELECT("select SUM(mold_output) as indicerNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_act_start_dt >= '".$dateAll."' AND dicer_act_start_dt <= '".$datenow."'");

		$data["inappearaNow"] =DB::SELECT("select SUM(dicer_output) as inappearaNow 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_act_start_dt >= '".$dateAll."' AND appearance_act_start_dt <= '".$datenow."'");
	
		$data["incalssNow"] =DB::SELECT("select SUM(input) as incalssNow
		from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		(select classify_lot
		from [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE classify_act_start_dt >= '".$dateAll."' AND classify_act_start_dt <= '".$datenow."')");

		// input Lot

		$data["indieNowlot"] =DB::SELECT("select count(lot_no) as indieNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_act_start_dt >= '".$dateAll."' AND diebond_act_start_dt <= '".$datenow."'");
		
		$data["inovenNowlot"] =DB::SELECT("select COUNT(lot_no) as inovenNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_act_start_dt >= '".$dateAll."' AND oven_diebond_act_start_dt <= '".$datenow."'");

		$data["inwirebondNowlot"] =DB::SELECT("select COUNT(lot_no) as inwirebondNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_act_start_dt >= '".$dateAll."' AND wirebond_act_start_dt <= '".$datenow."'");

		$data["inbondingNowlot"] =DB::SELECT("select COUNT(lot_no) as inbondingNowlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_act_start_dt >= '".$dateAll."' AND bonding_ins_act_start_dt <= '".$datenow."'");

		$data["inmoldNowlot"] =DB::SELECT("select COUNT(lot_no)  as inmoldNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_act_start_dt >= '".$dateAll."' AND mold_act_start_dt <= '".$datenow."'");

		$data["inovenmoldNowlot"] =DB::SELECT("select COUNT(lot_no) as inovenmoldNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_act_start_dt >= '".$dateAll."' AND oven_mold_act_start_dt <= '".$datenow."'");

		$data["indicerNowlot"] =DB::SELECT("select COUNT(lot_no) as indicerNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_act_start_dt >= '".$dateAll."' AND dicer_act_start_dt <= '".$datenow."'");

		$data["inappearaNowlot"] =DB::SELECT("select COUNT(lot_no) as inappearaNowlot 
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_act_start_dt >= '".$dateAll."' AND appearance_act_start_dt <= '".$datenow."'");
	
		$data["incalssNowlot"] =DB::SELECT("select COUNT(classify_lot) as incalssNowlot
		from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		(select classify_lot
		from [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE classify_act_start_dt >= '".$dateAll."' AND classify_act_start_dt <= '".$datenow."')");


		//output
		$data["outdieend"] =DB::SELECT("select SUM(diebond_output) as outdieend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_act_end_dt >= '".$dateAll."'  AND diebond_act_end_dt <= '".$datenow."'");

		$data["outovenend"] =DB::SELECT("select SUM(diebond_output) as outovenend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_act_end_dt >= '".$dateAll."' AND oven_diebond_act_end_dt <= '".$datenow."'");

		$data["outwirebondend"] =DB::SELECT("select SUM(diebond_output) as outwirebondend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_act_end_dt >= '".$dateAll."' AND wirebond_act_end_dt <= '".$datenow."'");

		$data["outbondingend"] =DB::SELECT("select SUM(wirebond_output) as outbondingend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_act_end_dt >= '".$dateAll."' AND bonding_ins_act_end_dt <= '".$datenow."'");

		$data["outmoldend"] =DB::SELECT("select SUM(wirebond_output) as outmoldend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_act_end_dt >= '".$dateAll."' AND mold_act_end_dt <= '".$datenow."'");

		$data["outoven_moldend"] =DB::SELECT("select SUM(mold_output) as outoven_moldend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_act_end_dt >= '".$dateAll."' AND oven_mold_act_end_dt <= '".$datenow."'");

		$data["outdicer_actend"] =DB::SELECT("select SUM(mold_output) as outdicer_actend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_act_end_dt >= '".$dateAll."' AND dicer_act_end_dt <= '".$datenow."'");

		$data["outappearanceend"] =DB::SELECT("select SUM(dicer_output) as outappearanceend
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_act_end_dt >= '".$dateAll."' AND appearance_act_end_dt <= '".$datenow."'");

		$data["outclassifyend"] =DB::SELECT("select SUM(output) as outclassifyend
		from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		(select classify_lot
		from [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE classify_act_end_dt >= '".$dateAll."' AND classify_act_end_dt <= '".$datenow."')");


		//output lot	
		$data["outdieendlot"] =DB::SELECT("select COUNT(lot_no) as outdieendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE diebond_act_end_dt >= '".$dateAll."'  AND diebond_act_end_dt <= '".$datenow."'");

		$data["outovenendlot"] =DB::SELECT("select COUNT(lot_no) as outovenendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_diebond_act_end_dt >= '".$dateAll."' AND oven_diebond_act_end_dt <= '".$datenow."'");

		$data["outwirebondendlot"] =DB::SELECT("select COUNT(lot_no) as outwirebondendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE wirebond_act_end_dt >= '".$dateAll."' AND wirebond_act_end_dt <= '".$datenow."'");

		$data["outbondingendlot"] =DB::SELECT("select COUNT(lot_no) as outbondingendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE bonding_ins_act_end_dt >= '".$dateAll."' AND bonding_ins_act_end_dt <= '".$datenow."'");

		$data["outmoldendlot"] =DB::SELECT("select COUNT(lot_no) as outmoldendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE mold_act_end_dt >= '".$dateAll."' AND mold_act_end_dt <= '".$datenow."'");

		$data["outoven_moldendlot"] =DB::SELECT("select COUNT(lot_no) as outoven_moldendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE oven_mold_act_end_dt >= '".$dateAll."' AND oven_mold_act_end_dt <= '".$datenow."'");

		$data["outdicer_actendlot"] =DB::SELECT("select COUNT(lot_no) as outdicer_actendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE dicer_act_end_dt >= '".$dateAll."' AND dicer_act_end_dt <= '".$datenow."'");

		$data["outappearanceendlot"] =DB::SELECT("select COUNT(lot_no) as outappearanceendlot
		from [WMSASIDB].[dbo].[ProductionPlan]
		WHERE appearance_act_end_dt >= '".$dateAll."' AND appearance_act_end_dt <= '".$datenow."'");

		$data["outclassifyendlot"] =DB::SELECT("select COUNT(classify_lot) as outclassifyendlot
		from [WMSASIDB].[dbo].[ClassifyLot] WHERE classify_lot IN
		(select classify_lot
		from [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE classify_act_end_dt >= '".$dateAll."' AND classify_act_end_dt <= '".$datenow."')");		


		//NG

		$data["ngbonding"] =DB::SELECT("select SUM(qty) as ngbonding
		from [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'BONDING_INS' ");

		$data["ngmold"] =DB::SELECT("select SUM(qty) as ngmold
		from [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'MOLD' ");

		$data["ngdicer"] =DB::SELECT("select SUM(qty) as ngdicer
		from [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'DICER' ");

		$data["ngappear"] =DB::SELECT("select SUM(qty) as ngappear
		from [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'APPEARANCE' ");

		$data["ngclassify"] =DB::SELECT("select SUM(qty) as ngclassify from [WMSASIDB].[dbo].[ClassifyOutput]
		where output_type = 'NG' AND create_dt >='".$dateAll."'  AND create_dt <= '".$datenow."'");
		 
		// **** top3 *****
		 		/// BONDING_INS
		$data["t3bonding"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		AND process = 'BONDING_INS'
		GROUP BY ng_code, ng_name ORDER BY sumqty desc");	

		$data["t3mold"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		AND process = 'MOLD'
		GROUP BY ng_code, ng_name ORDER BY sumqty desc");
		
		$data["t3dicer"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		AND process = 'DICER'
		GROUP BY ng_code, ng_name ORDER BY sumqty desc");
		
		$data["t3appea"] =DB::SELECT("select top 2 ng_code,ng_name, SUM(qty) as sumqty FROM [WMSASIDB].[dbo].[NGFactorList] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."'
		AND process = 'APPEARANCE'
		GROUP BY ng_code, ng_name ORDER BY sumqty desc");	

		$data["t3classi"] =DB::SELECT(" select top 2 output_name, SUM(qty) as sumng 
		from [WMSASIDB].[dbo].[ClassifyOutput] 
		where create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND output_type = 'NG'
		GROUP BY output_name ORDER BY sumng desc");

		// dd($data);

		// remark 

		$data["remarkdie"] =DB::SELECT("select top 2 lot_no, dienond_remark AS remark , count(dienond_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."'  AND create_dt <= '".$datenow."' AND process = 'DIE_BOND' AND dienond_remark is not null
		GROUP BY lot_no, dienond_remark ORDER BY total_remark desc");
		
		$data["remarkoven"] =DB::SELECT("select top 2 lot_no, oven_diebond_remark AS remark , count(oven_diebond_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE  create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'OVEN_DIE_BOND' AND oven_diebond_remark is not null
		GROUP BY lot_no, oven_diebond_remark ORDER BY total_remark desc");

		$data["remarkwirebond"] =DB::SELECT("select top 2 lot_no, wirebond_remark AS remark , count(wirebond_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'WIRE_BOND' AND wirebond_remark is not null
		GROUP BY lot_no, wirebond_remark ORDER BY total_remark desc");

		// $data["remarkbonding"] = array();

		$data["remarkmold"] =DB::SELECT("select top 2 lot_no, mold_remark AS remark , count(mold_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'MOLD' AND mold_remark is not null
		GROUP BY lot_no, mold_remark ORDER BY total_remark desc");

		$data["remarkovenmold"] =DB::SELECT("select top 2 lot_no, oven_mold_remark AS remark , count(oven_mold_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'OVEN_MOLD' AND oven_mold_remark is not null
		GROUP BY lot_no, oven_mold_remark ORDER BY total_remark desc");

		$data["remarkdicer"] =DB::SELECT("select top 2 lot_no, dicer_remark AS remark , count(dicer_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'DICER' AND dicer_remark is not null
		GROUP BY lot_no, dicer_remark ORDER BY total_remark desc");

		$data["remarkappearance"] = array();

		$data["remarkclassif"] =DB::SELECT("select top 2 lot_no, classify_remark AS remark , count(classify_remark) AS total_remark FROM [WMSASIDB].[dbo].[ProductionPlan] 
		WHERE create_dt >= '".$dateAll."' AND create_dt <= '".$datenow."' AND process = 'CLASSIFY' AND classify_remark is not null
		GROUP BY lot_no, classify_remark ORDER BY total_remark desc");




		echo json_encode($data);
	}

	public function screen3(){
		return view("sss.screen3");
	}
}
