<?php 

require_once("config/configDB.php"); 
require "userPermission.php";
require "financial_year_calculation.php";


$accountyear        = $financialYearStart."-".$financialYearEnd;
$sql_InvoiceQuery   = mysqli_query($conn,"SELECT count(*) as invoice FROM explosive_utiliz_hdr WHERE accountyear='$accountyear' and status='' ");
$rowInvoiceCount    = mysqli_fetch_array($sql_InvoiceQuery,MYSQLI_ASSOC);
$invoice_count      = $rowInvoiceCount['invoice']+1;


$sql_customer = mysqli_query($conn,"SELECT id,sname FROM supplier_master WHERE isdelete='1' and stype='Contractor' order by sname ASC ");
$row_customer = '';
?>

<!DOCTYPE html>
<html>
<head>
<?php 
      require 'meta.php'; 
      require 'header.php'; 
?>

<script>
function my()
{
//alert("ji");	
var one=parseInt(document.getElementById("one").value);
var two=parseInt(document.getElementById("two").value);
//var twoandhalf=parseInt(document.getElementById("twoandhalf").value);
var three=parseInt(document.getElementById("three").value);
var four=parseInt(document.getElementById("four").value);
//var five=parseInt(document.getElementById("five").value);
var six=parseInt(document.getElementById("six").value);
//var seven=parseInt(document.getElementById("seven").value);
//var sevenandhalf=parseInt(document.getElementById("sevenandhalf").value);
var eight=parseInt(document.getElementById("eight").value);


//var result=one+two+twoandhalf+three+four+five+six+seven+sevenandhalf+eight;
//var result2=((1*one)+(2*two)+(2.5*twoandhalf)+(3*three)+(4*four)+(5*five)+(6*six)+(7*seven)+(sevenandhalf*7.5)+(8*eight));


var result=one+two+three+four+six+eight;

//alert(result);

var result2=((1*one)+(2*two)+(3*three)+(4*four)+(6*six)+(8*eight));


	document.getElementById("hole").value=result;
	document.getElementById("totalfeet").value=result2;
	
	
	
	
}
function cost()
{
var cost_feet=parseFloat(document.getElementById("cost_feet").value);	
	var total_feet=document.getElementById("totalfeet").value;
	
	
	document.getElementById("total_cost").value=parseFloat(cost_feet*total_feet);
	
}


</script>

<script src="js/venusjs.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
		$('#submitb').hide();
        $(".add-row").click(function(){
            var explosivename = $("#explosivename").val();
            var qty = $("#qty").val();
			var pname = $("#pname").val();
			
			var markup = "<tr><td><input type='checkbox' name='record'></td><td>"+pname+"<input type='hidden' name='explosiveID[]' value='" + explosivename + "' class='form-control input-lg'></td><td>"+qty+"<input type='hidden' name='qty[]' value='" + qty + "' class='form-control input-lg'></td></tr>";
            $("table tbody").append(markup);
			
			$('#qty').val('');
			
			 $('#explosivename').val(null).trigger('change');
			 $('#submitb').show();
        });
        
        // Find and remove selected table rows
        $(".delete-row").click(function(){
            $("table tbody").find('input[name="record"]').each(function(){
            	if($(this).is(":checked")){
                    $(this).parents("tr").remove();
					
                }
				
            });
        });
    });    
</script>






</head>
<body>
    <?php require 'menu.php' ?>
<div class="container-fluid">
<h2 class="text-center">Compressor & Explosive Utiliz Details</h2><br>
    <form class="form-horizontal" action="explosiveutilizMasterInsert.php" method="post" id="spareMasterForm" onSubmit="return checkForm(this);" autocomplete="off">

    <div class="form-group">
      <label class="control-label col-sm-2" for="email">Utilize Code</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" placeholder="Enter Utilize Code" name="utilize_code" required value="<?php echo $invoice_count; ?>" readonly>
      </div>
      <label class="control-label col-sm-2">Date</label>
        <div class="col-sm-4">
        <input class="form-control input-lg datepicker-invoicedate" type="text" name="utilizedate" id="utilizedate" autocomplete="off" data-bv-field="invoicedate" value="<?php echo $utilizedate; ?>">
        </div>
    </div>
    
    <div class="form-group">
     <label class="control-label col-sm-2">Contractor Name</label>
        <div class="col-sm-4">
        
        <select class="form-control input-lg " name="contractor" rquired>
        <option value="">Please Select the Contractor </option>
        <?php
        while($row = mysqli_fetch_array($sql_customer)){
        ?>
        <option value="<?php echo $row['id'] ?>" > <?php echo $row['sname']; ?> </option>
        <?php
        //echo "<option value='".$row['id']."'>".$row['cname']."</option>";
        }
        ?>
        </select>
        </div>
        
      <label class="control-label col-sm-2">Process&nbsp;Type</label>
        <div class="col-sm-4">
        <select class="form-control input-lg " name="process_type"  id="process_type" rquired>
        <option value="">Please Select the Process </option>
        <option value="Compressor">Compressor</option>
        <option value="ELGI">ELGI</option>
        </select>
        </div>
    </div>
    
    <div class="form-group">        
        <label class="control-label col-sm-2">Starting Hrs</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg hrs"  name="starting_hrs" id="starting_hrs" autocomplete="off"  value="0"  required>
        </div>
		<label class="control-label col-sm-2">Closing Hrs</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg hrs"  name="closing_hrs" id="closing_hrs" autocomplete="off" value="0"  required  >
        </div>
    </div>
    
     <div class="form-group">        
        <label class="control-label col-sm-2">Starting Unit</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg unit"  name="starting_unit" id="starting_unit" autocomplete="off"  value="0"  required>
        </div>
		<label class="control-label col-sm-2">Closing Unit</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg unit"  name="closing_unit" id="closing_unit" autocomplete="off" value="0"  required  >
        </div>
    </div>
    
    <div class="form-group">        
        <label class="control-label col-sm-2">Total Hrs</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg "  name="running_hrs" id="running_hrs" autocomplete="off"  value="0"  required readonly>
        </div>
		<label class="control-label col-sm-2">Total Unit</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="running_unit" id="running_unit" autocomplete="off" value="0"  required readonly>
        </div>
    </div>
	
    <div class="form-group">        
        <label class="control-label col-sm-2">1</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="one" id="one" autocomplete="off"  value="0" onBlur="my();cost();" required>
        </div>
		<label class="control-label col-sm-2">2</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="two" id="two" autocomplete="off" value="0" onBlur="my();cost();" required  >
        </div>
    </div>
    
     <div class="form-group">  
     <label class="control-label col-sm-2">3</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="three" id="three" autocomplete="off" value="0" onBlur="my();cost();" required>
        </div>
        
         <label class="control-label col-sm-2">4</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="four" id="four" autocomplete="off" value="0" onBlur="my();cost();" required>
        </div>
        </div>
        
         <div class="form-group">        
        
		
		<label class="control-label col-sm-2">6</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="six" id="six" autocomplete="off" value="0" onBlur="my();cost();" required>
        </div>
        
        
             <label class="control-label col-sm-2">8</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="eight" id="eight" autocomplete="off"  value="0" onBlur="my();cost();" required>
        </div>
        
        </div>
        
    
   <!-- <div class="form-group">    
    <label class="control-label col-sm-2">2 1/2</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="twoandhalf" id="twoandhalf" autocomplete="off" value="0" onBlur="my();cost();" required>
        </div>
       
           
        <label class="control-label col-sm-2">5</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"   name="five" id="five" autocomplete="off" value="0" onBlur="my();cost();" required>
        </div>
      
    </div>
    
    
	 <div class="form-group">        
        <label class="control-label col-sm-2">7</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="seven" id="seven" autocomplete="off" value="0" onBlur="my();cost();" required>
        </div>
          <label class="control-label col-sm-2">7 1/2</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="sevenandhalf" id="sevenandhalf" autocomplete="off"  value="0" onBlur="my();cost();" required>
        </div>
    </div>-->
	 
	 
	 
	 <div class="form-group"> 
     
     <label class="control-label col-sm-2">Hole</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="hole" id="hole" autocomplete="off" required  >
        </div>
            
        <label class="control-label col-sm-2">Feet</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="totalfeet" id="totalfeet" autocomplete="off"  required>
        </div>
		
    </div>
	 <div class="form-group">    
    <!-- <label class="control-label col-sm-2">Total&nbsp;Labour</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="labour" autocomplete="off" required >
        </div>  -->
        
        <div class="form-group">
        <label class="control-label col-sm-2">Cost Per Feet</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="cost_feet" id="cost_feet"autocomplete="off" required onKeyUp="cost()"         value="0"  >
        </div>
          
           <label class="control-label col-sm-2">Total Cost</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="total_cost" id="total_cost" autocomplete="off" required >
        </div>
          
        <label class="control-label col-sm-2" style="display:none;">E.D</label>
        <div class="col-sm-4" style="display:none;">
        <input type="text" class="form-control input-lg"  name="ed" autocomplete="off"  >
        </div>
		
    </div>
	 
     <div class="form-group" style="display:none;"> 
     <label class="control-label col-sm-2">90</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="thotta90" autocomplete="off"  >
        </div>    
        
        <label class="control-label col-sm-2">Nonel 3m</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="nonel3m" autocomplete="off"  >
        </div> 
        </div>
        
         <div class="form-group" style="display:none;">  
     <label class="control-label col-sm-2">Nonel4m</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="nonel4m" autocomplete="off"  >
        </div>    
        
        <label class="control-label col-sm-2">DD</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="dd" autocomplete="off"  >
        </div> 
        </div>   
            
		
        
    </div>
    <div class="form-group"> 
   
        
        <label class="control-label col-sm-2">Remark</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="remark" id="remark" autocomplete="off"  >
        </div>
        
         <label class="control-label col-sm-2">Available&nbsp;Qty</label>
        <div class="col-sm-4">
        <input type="text" class="form-control input-lg"  name="avail_qty" id="given_qty" autocomplete="off" readonly  >
        </div>
        
        </div>
    
    <div class="container">

<div class=" col-sm-12">
<div class=" col-sm-1">&nbsp;</div>
    <div class=" col-sm-6">
    <label>Explosive Name</label>
    <select class="form-control input-lg" id="explosivename">
    <option>Select</option>
    <?php
	$qry=mysqli_query($conn,"Select * from product_master where product_type='Explosive'");
	while($rowp=mysqli_fetch_array($qry))
	{
		
	?>
    <option value="<?php echo $rowp['id'];?>"><?php echo $rowp['productname'];?></option>
    <?php
	}
	?>
    </select>
    <input type="hidden" id="pname">
      </div>
      <div class=" col-sm-3">
      <label>Qty</label>
        <input type="text" id="qty" placeholder="used qty"    onFocus="this.value=''" class="form-control input-lg"> 
        </div>
        
        
        
        
        <div class=" col-sm-2">
        <label>&nbsp;</label>
    	<input type="button" class="add-row btn-primary" value="Add Row" style="margin:30px;"  >
        </div>
        </div>

<table class="table  table-bordered " cellspacing="0" >

        <thead>
            <tr>
                <th>Select</th>
                <td>Explosive Name</td>
                <th>Qty</th>
            
            </tr>
        </thead>
        <tbody>
            <tr>
                
            </tr>
        </tbody>
        <tfoot>
        <tr>
        <td> <button type="button" class="delete-row btn btn-danger" style="color:#FFFFFF;" >Delete Row</button></td>
        
        </tr>
        </tfoot>
    </table>



    
</div>
	 
    <div class="form-group">        
      <div class="col-sm-12 text-center">
        <button type="submit" name="myButton" id="submitb" class="btn btn-primary btn-lg">Save</button>
      </div>
    </div>

  </form>   
</div>
<?php require 'footer.php' ?>
<script type="text/javascript">var base_url = "<?= $base_url ?>";</script>


<script>
$(document).ready(function(){
  
  var date_input=$('input[name="utilizedate"]'); //our date input has the name "date"
	var container=$('form >  .datepicker-invoicedate').length>0 ? $('form > .datepicker-invoicedate').parent() : "body";
	date_input.datepicker({ format: 'yyyy-mm-dd',container: container,todayHighlight: true,autoclose: true  });
    
  $('input[name="utilizedate"]').datepicker( "setDate", new Date()); 

});
</script>
<script>

  var checkForm = function(form) {

    //
    // validate form fields
    //

    form.myButton.disabled = true;
    return true;
  };


</script>

<script>

$(document).ready(function(){

$('#starting_unit').attr('readonly', true);
$('#closing_unit').attr('readonly', true);

  $("#process_type").change(function(){
 
 var process_type=$(this).val();
 
 if(process_type=='ELGI')
 {
 $('#starting_unit').attr('readonly', false);
$('#closing_unit').attr('readonly', false);
 }
 
 else
 {
 $('#starting_unit').val(0);
  $('#closing_unit').val(0);
 $('#starting_unit').attr('readonly', true);
$('#closing_unit').attr('readonly', true);
 }
});


$(".hrs").keyup(function(){
   var statring_hrs=$('#starting_hrs').val();
   var closing_hrs=$('#closing_hrs').val();
   
   var result_hrs=parseFloat(closing_hrs)-parseFloat(statring_hrs);
   $('#running_hrs').val(result_hrs);
   
});

$(".unit").keyup(function(){
   var starting_unit=$('#starting_unit').val();
   var closing_unit=$('#closing_unit').val();
   
   var result_unit=parseFloat(closing_unit)-parseFloat(starting_unit);
   $('#running_unit').val(result_unit);
   
});

});

</script>

<script>
$(document).ready(function(){ 
$('#explosivename').change(function(){  
//alert("ji");
	
	  var explosivename=$('#explosivename').val();
	   var given_date=$('#utilizedate').val();
	 // alert(explosivename);
	 
	             $.ajax({  
                     url:"explosiveoutpickdetails.php",  
                     method:"POST",  
                     data:   {explosivename:explosivename,utilizedate:given_date},
                     success:function(data)  
                     {  
					     // alert(data);
						  var data2 = data.split("||");
						  $('#given_qty').val("");  
                          $('#given_qty').val(data2[0]);
						   $('#pname').val("");  
                          $('#pname').val(data2[1]);
						  
						   $("#given_qty").css("color", "red");
						  
                         
						  
						
                         
                     }  
                });  
      }); 
});
</script>
</body>
</html>