<?php 
include_once("header-footer/header.php")
?>

<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
 <script>
  
  $( function() 
  {
    $( "#datepicker" ).datepicker();
    $( "#datepicker1" ).datepicker();
    $( "#Extention" ).datepicker();
    $( "#timeLimit" ).datepicker();
    $( "#basicIndices" ).datepicker();
  } );
  
  </script>
<script>
        $(document).ready(function()
        {   
             //// if( ($(window).width()) > 599) 
             //window.location.href  = URL+'/error/default.php';
          
        	$("#_frm").validate({
        		
        		errorElement:'div',
        		rules:{ 
        		    
        		    
        		    Title:{
        				required:true,
        				maxlength:300,
        				minlength:3 
        			}, 
        			AggNo:{
        				required:true 
        			},
        			workOrder:{
        				required:true 
        			}, 
        			workcomm:{
        				required:true 
        			},
        			cost:{
        				required:true,
        				maxlength:10,
        			} 
        			
        		},
        		messages:{
                   
        			Title:{
        				required:"Enter project title",
        				maxlength:"Maximum  300 charaters allow",
        				minlength:"Minimum 3 charaters required"  
        			},
        			AggNo:{
        				required:"Enter agreement no "
        			},
        			workOrder:{
        				required:"Select date of work order "
        			},
        			workcomm:{
        				required:"Select date : order of commencement  "
        			},
        			cost:{
        				required:"Enter project cost",
    					maxlength:"Maximum  19 digits allow",
        			}      
        			 
        		}
        	}); 
        }); 
		
		function selectCmd(val)
		{    
			 
			var randNo = "<?php echo $_REQUEST['randNo'];?>";  
			$.ajax({
			type: 'POST',
			url: "ajax/default.php",
			//async: false,			  
			data: {addCity_names:1,center:val,commodity:$("#commodity").val(),randNo:randNo},	  
			success: function(ajaxresult)
			{ 
			
					 
				 var obj = jQuery.parseJSON(ajaxresult);
				   
				     
				 $("#before1").val(obj['mon1']);
				 $("#before2").val(obj['mon2']);
				 $("#before3").val(obj['mon3']);
				 
				 
				 $("#index1").val(obj['ival1']);
				 $("#index2").val(obj['ival2']);
				 $("#index3").val(obj['ival3']);
				 
				    
				 
				 var avg = parseFloat(((parseFloat(obj['ival1']))+(parseFloat(obj['ival2']))+(parseFloat(obj['ival3'])))/3).toFixed(2);
				 $("#avg").val(avg);
				 
				  
				 if(obj['source1']==1) 
					$("#source").val("Govt");
				 else if(obj['source1']==1) 
					$("#source").val("RBI");
				else if(obj['source1']==3) 
					$("#source").val("Xrefinery");	
				
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) { 
			alert('Error');
			}
			});
			
				
		}
        </script>
        
        <style>
          .FormRegister
          {
              border: 1px solid #c2c2c2;
              margin: 1px;
              border-radius: 3px;
          }
        </style>
        
    	<link href="<?php echo ROOTPATH;?>/view/css/screen-600.css" rel="stylesheet" type="text/css">
               <?php 
	    include_once(ABS_PATH."/menu.php");
	?> 
               
                <div class="container mt-35">
                    <div class="row justify-content-center FormRegister">
                            <div class="col-12 p-3 text-center"> 
                                    <h3 class="card-title">
											<?php 
												if(isset($_SESSION['comdTY']))
														echo "Commodity Added";
												else
														echo "Add New Commodity";
 										?>
									
									</h3>
									
									<a  class="btn btn-primary mb-2" href="Myworks.php"> GO Back</a>
                            </div>    
                                  <form method="post" autocomplete="off" id="_frm">   
                                            <div class="row"> 
                                                    
                                                    <div class="col-md-12 mb-1">  
														<select  class="form-control"  name="commodity" id="commodity" > 
														<option value="">Select Commodity</option>
														<option value="1" <?php if($Result->cmdt==1) echo "selected";?> >LABOUR</option>
														<option value="2" <?php if($Result->cmdt==2) echo "selected";?>>MATERIAL</option>
														<option value="3" <?php if($Result->cmdt==3) echo "selected";?>>POL</option> 
														<option value="4" <?php if($Result->cmdt==4) echo "selected";?>>BITUMEN VG-30</option>  
														<option value="5" <?php if($Result->cmdt==5) echo "selected";?>>BITUMEN VG-10</option>  
														<option value="6" <?php if($Result->cmdt==6) echo "selected";?>>CEMENT LINE </option> 
														<option value="7" <?php if($Result->cmdt==7) echo "selected";?>>CEMENT OPC</option>  
														<option value="8" <?php if($Result->cmdt==8) echo "selected";?>>STEELLMETALIC IRON</option>  
														<option value="9" <?php if($Result->cmdt==9) echo "selected";?>>STEEL LONG</option> 
														</select> 
                                                    </div>
                                                    
													
													<div class="col-md-12 text-center"> 
        										    	
													 
														<div class="col-md-12 mb-1">  
														<select  class="form-control"  name="grade"  > 
														<option value="">Select Grade </option>
														<option value="1" <?php if($Result->grade==1) echo "selected";?>>Vg 30(60/70)</option>
														<option value="2" <?php if($Result->grade==2) echo "selected";?>>Vg 10(80/100)</option>
														<option value="3" <?php if($Result->grade==3) echo "selected";?> >Steel TMT</option>   
														</select> 
									  
                                                    </div>
                                                    
													
        										    </div>
													
													
														
													<div class="col-md-12 text-center">   
														<select   class="form-control mb-1"  name="center" id="center"    onchange="selectCmd(this.value);" >
														<option value="">Select Center</option> 
														<option value="1">Default</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 if($Result->center==$users->id) echo "selected";?> ><?php echo $users->name;?></option>
														<?php } ?> 
														</select>


        										    </div>
													
													
													
													<div class="col-md-12 text-center"> 
														Percentage %
        										  <input  type="number" name="percentage"  class="form-control mb-1" value="<?php echo $Result->perc;?>"
												  />
        										    </div>
													
													
														
													<div class="col-md-12 text-center"> 
														CSR
        										    	<input  type="text" name="csr"  class="form-control mb-1" value="<?php echo $Result->csr;?>"    />
        										    </div>
													
													
													
													
													<div class="col-md-12 text-center"> 
														Source
        										    	<input  name="source" id="source"  class="form-control mb-1" readonly   value="<?php echo $Result->source;?>"   />
        										    </div>
													
													
                                                    <div class="col-md-6 text-center"> 
														Before Date 1
        										    	<input  name="before1" readonly id="before1"  class="form-control mb-1"  value="<?php echo $Result->dat1;?>" required />
        										    </div>
													         
															 
													<div class="col-md-6 text-center"> 
														Index 1
        										    	<input  name="index1" readonly id="index1"  class="form-control mb-1"  value="<?php echo $Result->index1;?>"   required />
        										    </div>
													
                                                    <div class="col-md-6 text-center"> 
														Before Date 2
        										    	<input  name="before2" id="before2" readonly  class="form-control mb-1"  value="<?php echo $Result->dat1;?>"  required />
        										    </div>
													
													 <div class="col-md-6 text-center"> 
														Index 2
        										    	<input  name="index2" readonly id="index2"  class="form-control mb-1"  value="<?php echo $Result->index2;?>"   required />
        										    </div>
													
													<div class="col-md-6 text-center"> 
														Before Date 3
        										    	<input  name="before3" id="before3" readonly  class="form-control mb-1"  value="<?php echo $Result->dat1;?>"   required />
        										    </div>  
													
													
													<div class="col-md-6 text-center"> 
														Index 3
        										    	<input  name="index3" readonly id="index3"  class="form-control mb-1" value="<?php echo $Result->index3;?>"   required />
        										    </div>
													   
													
													<div class="col-md-12 text-center"> 
														Average
        										    	<input  value="<?php echo $Result->avgdta;?>"   name="avg" id="avg"  type="text" class="form-control mb-1"   readonly required />
        										    </div>
												  
													
                                                    <div class="col-md-12 text-center">
        										    	<input  type="submit" class="btn btn-primary mb-2" name="submitLogin" value="Update Record" > 
        										    </div> 
        										    
                                            </div>  
                                    </form>  
                    </div>       
                </div>
				 
				
               
 
              
       
<?php 
include_once("header-footer/footer.php");
unset($_SESSION['comdTY']); 
?> 