<?

// Level 9 이하만 사용 가능
$func->checkLevelModal(9);

// Forecast 기능 제한 (Admin : 1, Staff : 5, Driver : 9 만 가능)
$permit = array("1", "5", "9");
if (in_array($_SESSION['ss_LEVEL'], $permit)) {
    //$setTag = "ENABLED";
}
else {
		//$setTag = "DISABLED";	
		$msg = "Sorry, You don't have permission. Please contact Administrator.";
		$func -> modalMsg ($msg, "/index_intranet.php");
		exit();
}

if ($_SESSION['ss_LEVEL'] == 9) {
	$qrySTR = " AND (m_uid = '".$_SESSION['ss_UID']."') ";
	$setORDDATE = "D";
	$setORDDATEINPUT = date('Y-m-d');
}
else {
	$qrySTR ="";
	$setORDDATE = "+1D";
	$setORDDATEINPUT = date('Y-m-d', strtotime('+1 Weekday'));
}


// Get Driver Info
$qry_driver = "SELECT * FROM tbl_member WHERE m_level = 9 AND m_status = 'A' ".$qrySTR." ORDER by m_initial ASC ";
$rt_driver = $jdb->nQuery($qry_driver, "list error"); 

while($lt_driver=mysqli_fetch_array($rt_driver, MYSQLI_ASSOC)) {

	if ($lt_driver['m_uid'] == $searchDriver) $selectStr = "selected";
	else $selectStr = "";
	
	$c_driveruidSTR .= "
								<option value='".$lt_driver['m_uid']."' $selectStr>".$lt_driver['m_initial']."</option>";
								
}


// Get Area Info
$qry_area = "SELECT * FROM tbl_area GROUP BY a_text ORDER BY a_text ASC ";
$rt_area = $jdb->nQuery($qry_area, "list error"); 

$area_cnt=1;
while($lt_area=mysqli_fetch_array($rt_area, MYSQLI_ASSOC)) {
	
	if ($area_cnt%6 == 0) $areaSTR = "<br>";
	else $areaSTR = "";
	
	$a_textSTR .= "
                  <label class='container-chk'>".$lt_area['a_text']."
                    <input type='checkbox' name='c_area[]' id='c_area_".$lt_area['a_uid']."' value=\"".$lt_area['a_text']."\" checked=\"checked\">
                    <span class='checkmark'></span>
                  </label>".$areaSTR;
	$area_cnt++;
}



// Get Bin (Main Container) Info
// 불필요 (2024.01.17)
/*
$bin_cnt=1;
foreach ($arrBin AS $key=>$value)
{
	//echo "[$key][$value]";   => [0][Waiting][1][Confirmed][E][Declined]...
	
	if ($bin_cnt%4 == 0) $binSTR = "<br>";
	else $binSTR = "";
	
	$c_maincontainerSTR .= "
                  <label class=\"container-chk\">".$value."
                    <input type=\"checkbox\" name=\"c_maincontainer[]\" id='c_area_".$key."' value=\"".$key."\" checked=\"checked\">
                    <span class=\"checkmark\"></span>
                  </label>".$binSTR;
	$bin_cnt++;
}
*/

$getNextDay = date('Y-m-d', strtotime('1 days'));

?>


<script type="text/javascript">
$(document).ready(function(){

		// Decimal (ex 11, 11.0)
		$("#c_fullquantity_a, #c_fullquantity_b, #c_fullcycle").on("input", function(evt) {
				var self = $(this);
				self.val(self.val().replace(/[^0-9\.]/g, ''));
				if ((evt.which != 46 || self.val().indexOf('.') != -1) && (evt.which < 48 || evt.which > 57)) 
				{
				 evt.preventDefault();
				}
		});
			
		/* $("#checkAll").click(function () {
		     $('input:checkbox').not('#notcheckbox').prop('checked', this.checked);
		 });
		*/
		 $("#checkallarea").click(function () {
		     $('#checkboxarea input:checkbox').not('this').prop('checked', this.checked);
		 });

		 $("#checkallbin").click(function () {
		     $('#checkboxbin input:checkbox').not('this').prop('checked', this.checked);
		 });
 
});
</script>

<script type="text/javascript">
$(document).ready(function(){

$(function () {
	
	//var array = ["2023-05-27","2023-05-29"];
	var array = [];
	
	$('#orderdate').datepicker({ 

					dateFormat: 'yy-mm-dd',
									minDate: "<?=$setORDDATE?>", 
									//maxDate: "+5D",
									//maxDate: "+1M +10D",
		              //showOn: "button",
		              //yearRange: '-50:+5',
		              buttonImage: "/images/cal_red.png",
		              //beforeShowDay: $.datepicker.noWeekends,
		              buttonImageOnly: true,
		              //showOn: "both",
		              changeMonth: true,
		              changeYear: true,
		              firstDay: 7,
									beforeShowDay: function(date) {
											// Sat, Sunday
											// if(date.getDay()==6||date.getDay()==0) return [false,"","Not available"];
											
											//if(date.getDay()==0) return [false,"","Not available"];
											
											// Specific Date
									    if($.inArray($.datepicker.formatDate('yy-mm-dd', date ), array) > -1)
									    {
									        return [false,"","Not available"];
									    }
									    else
									    {
									        return [true,'',"Available"];
									    }
									}			                            
	});
});
	
});
</script>

<script>
$(document).ready(function(){
	
	//$("#email").val("");
	//$('#userinfo')[0].reset();
	
  $("#forecast").validate({
    // Specify validation rules
    ignore: ".ignore",
    rules: {
      orderdate: {
        required: true,
      },
    },
    messages: {
       
				orderdate: {
						required: "Please Input Order Date",
				},			
    },
    
    errorElement : 'div',
    
    /*submitHandler: function(form) {
    		if (grecaptcha.getResponse(1) == '') alert("Error");
    		else form.submit();
    	
  	}*/
        
  });
  

});
</script>


<style>
.error{
	color: red;
	font-weight: 200;
	padding:-1em;
}		
</style>


  <main id="main" class="main">

    <!-- ======= Breadcrumbs ======= -->
    <div class="breadcrumbs">
      <div class="container">

        <div class="d-flex justify-content-between align-items-center">
          <h2>FORECAST INFORMATION</h2>
          <ol>
            <li><a href="index.html">HOME</a></li>
            <li>FORECAST</li>
          </ol>
        </div>

      </div>
    </div><!-- End Breadcrumbs -->

    <section class="page">


     <div class="container" data-aos="fade-up">

        <div class="wrap-border">

				<FORM NAME=forecast id=forecast class="form-forecast-search" METHOD=POST ACTION=/index_intranet.php >
				<input type=hidden name=view value="forecast_list">
				<input type=hidden name=actionStr value="FORECAST">
				
				<input type=hidden name=c_type_w value="W">
				<input type=hidden name=c_type_p value="P">
				<input type=hidden name=c_type_r value="R">
				<input type=hidden name=c_type_o value="O">

            <table class="td-search">
              <tr>
                <td class="td-title"> <label for="Driver">Driver</label></td>
                <td>
                  <select name="c_driveruid" id="c_driveruid" class="custom-select">
                    <?=$c_driveruidSTR?>
                  </select>
                </td>
              </tr>
              <tr>
                <td class="td-title"><label for="Area">Area</label></td>
                <td id="checkboxarea">   

<?=$a_textSTR?>
                	
<!--
                  <label class="container-chk">GTA
                    <input type="checkbox" name="c_area" id="c_area" checked="checked">
                    <span class="checkmark"></span>
                  </label>
                  <label class="container-chk">Hamilton
                    <input type="checkbox" checked="checked">
                    <span class="checkmark"></span>
                  </label>
-->


                  <label class="container-chk">All
                    <input type="checkbox" name="c_areaall" id="checkallarea" value="1">
                    <span class="checkmark"></span>
                  </label>

                </td>
              </tr>
              <tr>
                <td class="td-title"><label for="Liter">Liter</label></td>
                <td>
                	<input type="text" id="c_fullquantity_a" name="c_fullquantity_a" placeholder="500">
                	 &nbsp;&#8806; &nbsp;Liter &nbsp;&#60;&nbsp;
                	<input type="text" id="c_fullquantity_b" name="c_fullquantity_b" placeholder="500">
                </td>
              </tr>

<!--
              <tr>
                <td class="td-title"> <label for="Cycle">Cycle</label></td>
                <td><input type="text" id="c_fullcycle" name="c_fullcycle" placeholder="60"></td>
              </tr>
-->

<? if ($fflag == 1) { ?>
              <tr>
                <td class="td-title"><label for="Bin">Bin</label></td>
                <td id="checkboxbin">

<?=$c_maincontainerSTR?>
                	
<!--
                  <label class="container-chk">800B
                    <input type="checkbox" name="c_maincontainer" checked="checked">
                    <span class="checkmark"></span>
                  </label>

                  <label class="container-chk">600B
                    <input type="checkbox" checked="checked">
                    <span class="checkmark"></span>
                  </label>
-->

                  <label class="container-chk">All
                    <input type="checkbox" name="c_maincontainerall" id="checkallbin" value="1">
                    <span class="checkmark"></span>
                  </label>

                </td>
              </tr>
<? } ?>

              <tr>
                <td class="td-title"> <label for="Cycle">Order Date</label></td>
                <td><input type="text" id="orderdate" name="orderdate" value="<?=$setORDDATEINPUT?>" placeholder="" required='required' readonly>     </td>
              </tr>              
              <tr>
                <td colspan="2">                 
                   <div class="text-center"><button class="btn-primary" type="submit">SEARCH</button></div>
                </td>

              </tr>
            </table>
  
            
            
  
          </FORM>
      </div><!--wrap-border-->
  
 



      </div><!--container Ends-->
        

    </section>

  </main><!-- End #main -->


