<?php 	include_once('../../config.php'); 
		 

			if(isset($_POST['submit']))
			{   
		  
		
				$stmt=$conn->prepare("select  priority from     pw__exclationtbl1 order by id desc");
				 
				$stmt->execute(); 
				$ORDerId = $stmt->fetch(PDO::FETCH_OBJ);

				
				$newDate = date("d-M-Y", strtotime($_POST['dateselect'])); 
				
				if( ($_POST['commodity']==1) || ($_POST['commodity']==2) )
					$_POST['source'] = 1;
				else if( ($_POST['commodity']==3)   || ($_POST['commodity']==4) || ($_POST['commodity']==5) )
					$_POST['source'] = 3;
				if( ($_POST['commodity']==6) || ($_POST['commodity']==7) || ($_POST['commodity']==9) || ($_POST['commodity']==8) )  
					$_POST['source'] = 2;
				
				
				 
				
				$stmt=$conn->prepare("insert into   pw__exclationtbl1(commodity,dateselect,center,indexval,source,priority) values(:commodity,:dateselect,:center,:indexval,:source,:priority)"); 
                $stmt->bindValue(':commodity',$_POST['commodity'], PDO::PARAM_STR); 
                $stmt->bindValue(':dateselect', $newDate, PDO::PARAM_STR); 
                $stmt->bindValue(':center', $_POST['center'], PDO::PARAM_STR);  
                $stmt->bindValue(':indexval', $_POST['index'], PDO::PARAM_STR);  
                $stmt->bindValue(':source', $_POST['source'], PDO::PARAM_STR);  
                $stmt->bindValue(':priority',  $ORDerId->priority, PDO::PARAM_STR);  
                $stmt->execute();    
				header("Location: labor.php ");  
				die;
			}   
		 
?>  
<?php  include ABS_PATH.'/admin/header.php';	?>  


<script>

	function callCom(val1)
	{ 
		  
		  
	 
		if((val1==6)  ||  (val1==7)  || (val1==8) || (val1==9))
			$("#center").hide();
		else
			$("#center").show();
	} 
	
	$(function() 
	{  
			$( "#dateselect" ).datepicker({
			changeMonth: true,
			changeYear: true,
			yearRange: "1930:2050"
			});
	}); 
  
	$(document).ready(function()
	{   

	
	$("#product_frm").validate({
		
		errorElement:'div',
		rules:{ 
			city:{
				required:true				 
			} 
			
			
			
		},
		messages:{				
			 
			 city:{
				required:"Enter city name"				 
			} 
		}
	});


	});
 


</script>
		 
		 <div class="col-md-10">

	  			<div class="row">
	  				<div class="col-md-12">
	  					<div class="content-box-large">
							<div class="panel-heading">
								<div class="panel-title"> <h3> Add New Record </h3></div>    
								
								<div class="panel-options"> 

								   <input type="button"  class="btn btn-warning" name="btnback" id="btnback" value=" Back " onClick="javascript:location.href='labor.php';" />
								  
								</div>
							  
								 
							</div>
							
							
			  				<div class="panel-body">    
			  					<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="product_frm" autocomplete="off">    
								
								  <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Commodity</label>  
									
									 <div class="col-sm-3" > 
									  <select  class="form-control"  name="commodity" onchange="callCom(this.value)">
									 <option value="">Select </option>
									  <option value="1">LABOUR</option>
									  <option value="2">MATERIAL</option>
									  <option value="3">POL</option> 
									  <option value="4">BITUMEN VG-30</option>  
									  <option value="5">BITUMEN VG-10</option>  
									  <option value="6">CEMENT LINE </option> 
									  <option value="7">CEMENT OPC</option>  
									  <option value="8">STEELLMETALIC IRON</option>  
									  <option value="9">STEEL LONG</option> 
									  </select>
									  </select>
								    </div>
									
								 </div>
								 
								 <hr>
								 
								 	 
								  <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Source</label>
								    <div class="col-sm-3" > 
									  <select  class="form-control"  name="source" readonly>
									  <option value="">Select</option>
									  <option value="1">GOVT</option>
									  <option value="2">RBI</option> 
									  <option value="3">Xrefinery</option> 
									  </select>
									  </select>
								    </div>
								 </div>
								 <hr>
								 
								 <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Date</label>
								    <div class="col-sm-3" name="year"> 
									  <input name="dateselect" id="dateselect" class="form-control"   placeholder="Date"   required>
								    </div>
								 </div>
								 <hr>
								  
								 
								  <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Center</label>
								    <div class="col-sm-3">
								       
								    <select  class="form-control" name="center" id="center"  required>
								    <option value="">Select</option> 
									<?php    
										$stmt=$conn->prepare("select  * from    pw__cities order by name ");  
										$stmt->execute(); 
										$AllUsers = $stmt->fetchAll(PDO::FETCH_OBJ); 
										$sr = 1; 

										foreach($AllUsers as $users)
										{  
									?> 
										<option value="<?php echo $users->id;?>"><?php echo $users->name;?></option>
									<?php } ?> 
									</select>
									  
								    </div>
								 </div>
								 <hr>
								 
								 
								 <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Index</label>
								    <div class="col-sm-3">
								      <input name="index" class="form-control"   placeholder="Index"   required>
								    </div>
								 </div>
								 <hr>
							
								   
								  
								  <div class="form-group">
										<label for="inputEmail3" class="col-sm-2 control-label">Add User</label>
										<div class="col-sm-10">
										  <input type="submit"    class="btn btn-primary"  name="submit" value="Add Record">
										</div>
								  </div>   
								</form>
								
								
							
			  				</div>
			  			</div>
	  				</div>
	  				 
	  			</div>

	  			 


	  		<!--  Page content -->
		  </div>
		</div>
    </div>

<?php  include ABS_PATH.'/admin/footer.php';	?>    