<!DOCTYPE html>
<?php
$id=$_GET['id'];
@$userid=$_GET['userid'];
require_once('../Db/dbconfig.php');
?>
<html>
<head>
<link href="../css/styles.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://kit.fontawesome.com/c17eae44a3.js" crossorigin="anonymous"></script>

<style type="text/css">
select.rou{
 border: 1px solid #ccc;
  -moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;

-moz-box-shadow: 2px 2px 3px #666;
-webkit-box-shadow: 2px 2px 3px #666;
box-shadow: 2px 2px 3px #666;
font-size: 18px;
padding: 4px 7px;
outline: 0;
-webkit-appearance: none;
}
#round{
 border: 1px solid #ccc;
 -moz-border-radius: 10px;
 -webkit-border-radius: 10px;
 border-radius: 10px;
	
 -moz-box-shadow: 2px 2px 3px #666;
 -webkit-box-shadow: 2px 2px 3px #666;
 box-shadow: 2px 2px 3px #666;
 font-size: 15px;
 padding: 4px 7px;
 outline: 0;
 -webkit-appearance: none;
}
</style>
</head>
<body>
<div class="page-header">
  <h3 class="page-title"  >
    <span class="page-title-icon bg-gradient-primary text-white mr-2">
    <i class="fas fa-cart-arrow-down fa-xs" style="color: black"></i>
    </span><b>Purchase Edit</b></h3>
</div>
 <div class="card-body" style="background-color:#8FBC8F">
 <form action="" method="post" enctype='multipart/form-data' id="purchaseForm">
 <?php 
	$insertcount=0;
	  $query="select pur.p_id, pur.inv_no, pur.dat, pur.`time`, pur.cha_no, pur.vno, p.item as item_category,p.id as itemCatId, p2.description as item,p2.id as despId,s.name as supplier_name,s.id as supid, p3.item as ptype,
p3.id as ptypeId, pur.l_no, qt.q_name as quantity_type,qt.id as qtyTypId, pur.quantity, pur.moisture,pur.lab_report,pur.lap_report_file from purchase pur,product p,productitem p2,supplier s,productype p3,quantity_type qt where 
pur.item_category = p.id and pur.item = p2.id and pur.supplier_name = s.id and pur.ptype = p3.id 
and pur.quantity_type = qt.id and pur.p_id =$id;";
	  $result = $con->query($query);
	  while($row = $result->fetch_assoc()) 
	  {	
?>
 <div class="form-group">
    <label style="width:150px;" style="size:150px;" class="r" for="l_no"><b>Vendors Code</b></label>
    <input type="text" style="width:250px;" id="l_no" class="rounded" name="l_no" placeholder="Vendors Code" value="<?php echo $row['l_no']; ?>" required>
	<label style="width:700px;"></label>
	 <label style="width:110px;" id="round" for="no"><b>Challen Number</b></label>
    <input style="width:80px;" type="text" class="rounded" id="cha_no" name="cha_no" value="<?php echo $row['cha_no']; ?>">
 </div>
<div class="form-group">
    <label style="width:150px;" for="no"><b>Invoice Number</b></label>
    <input type="text" style="width:250px;" id="inv_no" class="rounded" placeholder="invoice no" name="inv_no" value="<?php echo $row['inv_no']; ?>">
</div>
<div class="form-group">
    <label style="width:150px;" for="dat"><b>Date</b></label>
	
    <input style="width:250px;" class="rounded" type="date" id="dat" name="dat"  value="<?php echo $row['dat']; ?>" required>
</div>
<div class="form-group">
    <label style="width:150px;" for="no"><b>Time</b></label>
    <input style="width:250px;" class="rounded" type="time" id="time" name="time" value="<?php echo $row['time']; ?>" required>
</div>
<div class="form-group">
    <label style="width:150px;" for="no"><b>Vehicle Number</b></label>
    <input type="text" style="width:250px;" id="vno" class="rounded" name="vno" value="<?php echo $row['vno']; ?>" required>
</div>
<div class="form-group">
    <label  style="width:150px;"for="no"><b>Item Category</b></label>
                       
	<select name="item_category" id="item_category" style="width:250px;" class="rou" disabled>
	<option value="<?php echo $row['itemCatId']; ?>"><?php echo $row['item_category']; ?></option> 
	</select> 
	<!-- <button type="button" class="btn bg-gradient-primary text-white mr-2 add" data-toggle="tooltip" data-placement="bottom" title="Add product" style="background-color:#b134eb ;"><i class="ace-icon fa fa-plus bigger-130"></i></button> -->
</div>
<div class="form-group" id="pol">
    <label  style="width:150px;"for="no"><b>Item Description</b></label>
   	<input type="hidden" class="rounded" style="width:100px;"  id="hiddenDesp" value="<?php echo $row['despId']; ?>" readonly>
	<select name="item" id="item" style="width:250px;" class="rou" disabled>
	<option value="<?php echo $row['despId']; ?>"><?php echo $row['item']; ?></option> 
	</select> 
	<!-- <button type="button" class="btn bg-gradient-primary text-white mr-2 editinv" data-toggle="tooltip" data-placement="bottom" title="Add Inventory" style="background-color:#b134eb ;"><i class="fas fa-cart-arrow-down"></i></button>	 -->		
</div>
<div class="form-group">
   <label style="width:150px;" for="sname"><b>Supplier Name</b></label>
   <select name="sname" id="supplier_name" style="width:250px;" class="rou" required>
   	<option value="<?php echo$row['supid']; ?>"><?php echo $row['supplier_name']; ?></option>
   <?php 
		$sql="select * from supplier where name !='".$row['supplier_name']."'";
	    $res=mysqli_query($con,$sql);
		while($row1 = mysqli_fetch_array($res))
		{ 
	?>
	<option value="<?php echo $row1['id']; ?>"><?php echo $row1['name']; ?></option>
	<?php
		}
	?>
	</select>
	<button type="button" class="btn bg-gradient-primary text-white mr-2 editbtn" data-toggle="tooltip" data-placement="bottom" title="Add Supplier" style="background-color:#b134eb ;"><i class="fa fa-user-plus"></i></button>
</div>
<div class="form-group">
    <label style="width:150px;" for="item"><b>Product Type</b></label>
    <select style="width:250px;" class="rou" id="ptype" name="ptype" disabled>
    <option value="<?php echo $row['ptypeId']; ?>"><?php echo $row['ptype']; ?></option> 
	<!-- <?php 
		$sql1="select * from productype where item !='".$row['ptype']."'";
	    $res=mysqli_query($con,$sql1);
		while($row1 = mysqli_fetch_array($res))
		{
	?>
	<option value="<?php echo $row1['id']; ?>"><?php echo $row1['item']; ?></option> 
    <?php
		}
	?> -->
	</select> 
	 <button type="button" class="btn bg-gradient-primary text-white mr-2 productype" data-toggle="tooltip" data-placement="bottom" title="Add product type" style="background-color:#b134eb ;"><i class="ace-icon fa fa-plus bigger-130"></i></button>
					
</div>
<div class="form-group">
    <label style="width:150px;" for="qty_typ"><b>Quantity Type</b></label>
    <select style="width:250px;" class="rou" id="qty_typ" name="qty_typ" onchange="changefunc()" disabled>
    <option value="<?php 
		$quantitytype = $row['qtyTypId'];
		echo $quantitytype; ?>">
		<?php echo $row['quantity_type']; ?>
	</option> 
    <!-- <?php 
		$sql1="select * from quantity_type where id !=".$row['qtyTypId'];
	    $res=mysqli_query($con,$sql1);
		while($row1 = mysqli_fetch_array($res))
		{
		?>
		<option value="<?php echo $row1['id']; ?>"><?php echo $row1['q_name']; ?></option> 
	    <?php
		}
	?> -->
    </select>
	<input type="text" style="width:80px;"  id="qty" name="qty" value="<?php 
		if($quantitytype == '1' or $quantitytype == '3'){
			if($row['quantity'] != 0){
				echo ($row['quantity']/1000);
			}else{
				echo $row['quantity'];
			}
		}else{
			echo $row['quantity'];
		}
	?>" readonly>
</div>
<div class="form-group" id="qty11" >
	<label style="width:150px;" for="qty"><b>Quantity</b></label>
    <input type="text" style="width:250px;" maxlength="6" class="rounded" id="ko" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Kilo</label>
	<input type="text" style="width:250px;" maxlength="3" class="rounded" id="gr" pattern="^(0|[1-9][0-9]*)$" value ="0"><label>gram</label>
	
</div>
<div class="form-group" id="qty12" style="display:none">
	<label style="width:150px;" for="qty"><b>Quantity</b></label>
	<input type="text" style="width:250px;" maxlength="6" class="rounded" id="piec" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Pieces</label>
</div>
<div class="form-group" id="qty13" style="display:none">
	<label style="width:150px;" for="qty"><b>Quantity</b></label>
	<input type="text" style="width:250px;" maxlength="6" class="rounded" id="litr" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Litre</label>
	<input type="text" style="width:250px;" maxlength="3" class="rounded" id="mltr" pattern="^(0|[1-9][0-9]*)$" value ="0">ml
</div>
<div class="form-group" id="qty14" style="display:none">
	<label style="width:150px;" for="qty"><b>Quantity</b></label>
	<input type="text" style="width:250px;" maxlength="6" class="rounded" id="mtr" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Meter</label>
</div>
<div class="form-group" id="qty15" style="display:none">
	<label style="width:150px;" for="qty"><b>Quantity</b></label>
	<input type="text" style="width:250px;" maxlength="6" class="rounded" id="ft" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Feet</label>
</div>
<div class="form-group">
    <label style="width:150px;" for="moisture"><b>Moisture</b></label>
    <input type="text" style="width:250px;" id="moisture" class="rounded" name="moisture" maxlength="2" placeholder="%"  oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" value="<?php echo $row['moisture']; ?>" required>%
 </div>
 <div class="form-group">
    <label style="width:150px;" for="lap_report"><b>Lab report</b></label>
    <input type="text" class="form-control" id="lab_report" name="lab_report"  placeholder="Lab report"  value="<?php echo $row['lab_report']; ?>"required>
</div>
<div class="form-group">
    <label><b>Lab report File upload</b></label>
    <input type="file" name="labfile" id="labfile" class="file-upload-default" onchange="loadfile(event)" value="<?php echo $row['lap_report_file']; ?>">
    <div class="input-group col-xs-12">
      <input type="text"  class="form-control file-upload-info" disabled placeholder="Lab report Upload Image" id="lap_input" value="<?php echo $row['lap_report_file']; ?>">
    </div>
					
	<div>
		<img id="preview" height="100" width="100" > 
	</div>
</div>
<?php 
  }
 ?>
    <button type="submit"  class="btn btn-primary" id = "purchaseSubmit" name="submit">Submit</button>
    <!-- <button class="btn btn-danger">Cancel</button> -->
</form>
</div>

<!-- Add inventory Modal -->
<div id="add_inv" class="modal fade" role="dialog" tabindex="-1" aria-hidden="true"> 
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
         <h4 class="modal-title">Add Inventory</h4>
		 <button type="button" onclick="clearForm('add_name')" class="close" data-dismiss="modal">&times;</button>
       
      </div>
      <div class="modal-body">
       
		<form name="add_name" id="add_name">
		
		<table class="table table-bordered" id="dynamic_field">
				
			<tr>
			<div class="form-group">
                <label  style="width:150px;"for="no"><b>Item Category</b></label>
            
				<select name="items" id="items" style="width:250px;" class="rou">
				<?php 
					$sql1="select * from product";
				    $res=mysqli_query($con,$sql1);
					while($row1 = mysqli_fetch_array($res))
					{
				?>
				<option value="<?php echo $row1['id']; ?>"><?php echo $row1['item']; ?></option> 
				<?php
				}
				?>

				</select> 
						
			</div>
					   
				<td><input type="text" name="name[]" id="name" placeholder="Enter Item Description" class="form-control name_list"></td>
				<td><button type="button" name="addp" id="addp" class="btn btn-success">Add More</button></td>
			</tr>
		
		</table>
			
		  <b id="mesgInv"></b>			
		  <input type="button" name="submit" id="submitInv" style="background-color:#FF6666" class="btn bg-gradient-primary text-white mr-2" value="Submit"/>
		  <button type="button" class="btn btn-danger" data-dismiss="modal" onclick="clearForm('add_name')">Close</button>
		</form> 

      </div>
      <div class="modal-footer">
       
      </div>
    </div>

  </div>
</div>

<!-- Add Product Modal -->
<div id="ad_product" class="modal fade" role="dialog" tabindex="-1" aria-hidden="true"> 
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Add Product</h4>
		<button type="button" onclick="clearForm('user_form')" class="close" data-dismiss="modal">&times;</button>
        
      </div>
      <div class="modal-body">
       
		<form method="POST" id="user_form">
		
		<div class="form-group">
            <label>Product Name</label>
            <input type="text" class="form-control" id="pname" name="pname" required>
        </div>
        <b id="mesg"></b>
		<input type="button" name="add_product" id="add_product" style="background-color:#FF6666" class="btn btn-default" value="Submit"/>
		<button type="button" style="background:radial-gradient(#FFF176, #ff3300)" class="btn btn-default" data-dismiss="modal" onclick="clearForm('user_form')">Close</button>
		</form> 

      </div>
      <div class="modal-footer">
       
      </div>
    </div>

  </div>
</div>

<!-- Add Product type Modal -->
<div id="ad_productype" class="modal fade" role="dialog" tabindex="-1" aria-hidden="true"> 
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
        <div class="modal-header">
	        <h4 class="modal-title">Add Product Type</h4>
			<button type="button" onclick="clearForm('user_form2')" class="close" data-dismiss="modal">&times;</button>
        </div>
        <div class="modal-body">
       
		<form method="POST" id="user_form2">
			<div class="form-group">
                <label>Product Type</label>
                <input type="text" class="form-control" id="ptname" name="ptname" placeholder="Enter product type" required>
            </div>
            <b id="mesg2"></b>
		 	<input type="button" name="productype" id="productype" style="background-color:#FF6666" class="btn btn-default" value="Submit"/>
		    <button type="button" style="background:radial-gradient(#FFF176, #ff3300)" class="btn btn-default" data-dismiss="modal" onclick="clearForm('user_form2')">Close</button>
		</form> 

      </div>
      <div class="modal-footer">
       
      </div>
      </div>

  </div>
</div>

<!-- Update Supplier Modal -->
<div id="add_sup" class="modal fade" role="dialog" tabindex="-1" aria-hidden="true"> 
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
         <h4 class="modal-title">Add Supplier</h4>
		 <button type="button" onclick="clearForm('user_form1')" class="close" data-dismiss="modal">&times;</button>
       
      </div>
      <div class="modal-body">
       
		<form method="post" id="user_form1">
			<div class="form-group">
               <label for="sname">Supplier Name</label>
                       
               <input type="text" class="form-control" name="sname" id="sname" required>
                      
            </div>
            <div class="form-group">
                <label for="phone">Phone</label>
                <input type="text" class="form-control" maxlength="10" name="phone" id="phone"  oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" required>
            </div>
            <div class="form-group">
                <label for="email">Email address</label>
                <input type="email" class="form-control" name="email" id="email" placeholder="Email" required>
            </div>
			<div class="form-group">
                <label for="address">Address</label>
                <textarea class="form-control" id="address" rows="4" name="address" required></textarea>
            </div>
                      
                     
		 
		 <b id="mesg1"></b>
		 
		  <input type="button" name="add" id="add" style="background-color:#FF6666" class="btn btn-default" value="Submit"/>
		   <button type="button" class="btn btn-default" data-dismiss="modal" onclick="clearForm('user_form1')">Close</button>
		</form> 

      </div>
      <div class="modal-footer">
       
      </div>
    </div>

  </div>
</div>
</body>

<script>
var pid='';
$(document).ready(function(){
	var userid = '<?php echo @$userid; ?>';
	
 	$.urlParam = function(name){
	    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
	    return results[1] || 0;
  	}
    
    pid =  $.urlParam('id') ;
    //getItemDesctp($('#item_category').val());
    //$("#item").val($('#hiddenDesp').val()).change();
    $("#preview").attr("src","../controller/"+$('#lap_input').val());

    changefunc();

	/*$('.editinv').on('click',function() {
		$('#add_inv').modal('show');
	});*/

	$('.productype').on('click',function() {
			
		$('#ad_productype').modal('show');
			
	});

	/*$('.add').on('click',function() {
			
		$('#ad_product').modal('show');
	});*/

	$('.editbtn').on('click',function() {
			
		$('#add_sup').modal('show');
	});

	$("#purchaseForm").submit(function(e) {
    document.getElementById("purchaseSubmit").disabled=true;
    //prevent Default functionality
    e.preventDefault();
    //do your own request an handle the results
   	var formData = new FormData(this);

   	var selectedValue =$('#qty_typ').val();
   	
   	if(selectedValue == "1")
	{
		var kilogrm = (parseInt($('#ko').val()) * 1000)+parseInt($('#gr').val());
		if(kilogrm !=0){
			formData.set('qty',kilogrm);
		}
		
	}else if(selectedValue == "3")
	{
		var milliltr = (parseInt($('#litr').val()) * 1000)+parseInt($('#mltr').val());
		if(milliltr !=0){
		formData.set('qty',milliltr);
		}
	}else if(selectedValue == "2")
	{
		if($('#piec').val() !='0'){
			formData.set('qty',$('#piec').val());
		}
	}else if(selectedValue == "4")
	{
		if($('#mtr').val() !='0'){
			formData.set('qty',$('#mtr').val());
		}
		
	}else if(selectedValue == "5")
	{
		if($('#ft').val() !='0'){
			formData.set('qty',$('#ft').val());
		}
	}

	formData.append('lap_report_file',$('#lap_input').val());

	var file = $('#labfile')[0].files[0]
	if (file){
	  formData.append('isfileUploaded',1);
	}else{
	  formData.append('isfileUploaded',0);
	}

	formData.append('type','update_pur');
	formData.append('p_id',pid);
	formData.append('userId',userid);

     $.ajax( {
        url: '../controller/purchase_controller.php',
        type: 'POST',
        data: formData,
        processData: false,
        contentType: false,

        success: function(data){
          console.log('Msg',data);
          if(data.status == true){
	        alert('Purchase Item Updated successfully'); 
	        window.location.reload();
      	  }else{
      	  	alert('Failed To Update Item'); 
      	  	document.getElementById("purchaseSubmit").disabled=false;
      	  }
        },
        error: function(r) {
          alert('Unable to Update Item'); 
          document.getElementById("purchaseSubmit").disabled=false;
        }
      } );

	});

	/*$('#add_product').click(function(){
		var data=$('#user_form').serialize()+'&type=add_product';
		var productnm = $('#pname').val();
		$.ajax({
			url:'../controller/purchase_controller.php',
			type:'POST',
			data:data,
			success:function(response){
				console.log('Result',response);
				if(response.status == true){
					alert(response.msg);
					$('#item_category').append($('<option>', {
					    value: response.rowId,
					    text: productnm
					}));
					$('#items').append($('<option>', {
					    value: response.rowId,
					    text: productnm
					}));

					$('#ad_product').modal('hide');
					clearForm('user_form');

				}else{
					alert(response.msg);
				}
			}
		});
	});*/

	$('#add').click(function(){
		var data=$('#user_form1').serialize()+'&type=addSup';
		var snm = $('#sname').val();
		$.ajax({
			url:'../controller/purchase_controller.php',
			type:'POST',
			data:data,
			success:function(response){
				console.log('Result s',response);
				if(response.status == true){
					alert(response.msg);
					$('#supplier_name').append($('<option>', {
					    value: response.rowId,
					    text: snm
					}));

					$('#add_sup').modal('hide');
					clearForm('user_form1');
				}else{
					alert(response.msg);
				}
			}
		});
	});

	$('#productype').click(function(){
		var data=$('#user_form2').serialize()+'&type=productype';
		var prodtypname = $('#ptname').val();
		$.ajax({
			url:'../controller/purchase_controller.php',
			type:'POST',
			data:data,
			success:function(response){
				console.log('Result pt',response);
				if(response.status == true){
					alert(response.msg);
					$('#ptype').append($('<option>', {
					    value: response.rowId,
					    text: prodtypname
					}));

					$('#ad_productype').modal('hide');
					clearForm('user_form2');
				}else{
					alert(response.msg);
				}
			}
		});
	});

	//addMoreInv();

	
});

function loadfile(event){
	var output=document.getElementById('preview');
	output.src=URL.createObjectURL(event.target.files[0]);
};

function changefunc() {
	var y = document.getElementById("qty_typ");
	var selectedValue = y.options[y.selectedIndex].value;
	
	if(selectedValue == "1")
	{
		$('#qty11').show();
		$('#qty12').hide();
		$('#qty13').hide();
		$('#qty14').hide();
		$('#qty15').hide();
		
	}else if(selectedValue == "2")
	{
		$('#qty12').show();
		$('#qty11').hide();
		$('#qty13').hide();
		$('#qty14').hide();
		$('#qty15').hide();
		
	}else if(selectedValue == "4")
	{
		$('#qty12').hide();
		$('#qty11').hide();
		$('#qty13').hide();
		$('#qty14').show();
		$('#qty15').hide();
		
	}else if(selectedValue == "5")
	{
		$('#qty12').hide();
		$('#qty11').hide();
		$('#qty13').hide();
		$('#qty14').hide();
		$('#qty15').show();
		
	}else
	{
		$('#qty13').show();
		$('#qty11').hide();
		$('#qty12').hide();
		$('#qty14').hide();
		$('#qty15').hide();
		
	}
}

function clearForm(formname){
	$("#"+formname).trigger("reset");

	if(formname == 'user_form'){
		$('#mesg').text('');
		$('#add_product').show();
	}else if(formname == 'user_form1'){
		$('#mesg1').text('');
		$('#add').show();
	}else if(formname == 'user_form2'){
		$('#mesg2').text('');
		$('#productype').show();
	}else if(formname == 'add_name'){
		$('#mesgInv').text('');
		$("#dynamic_field").find("tr:gt(0)").remove();
	}
}

/*function addMoreInv(){
	var i=1;  
	$('#addp').click(function(){
		i++;
		$('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text" name="name[]" id="name" placeholder="Enter Item Description" class="form-control name_list"></td><td><button name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
	});
	$(document).on('click','.btn_remove',function(){
		var button_id=$(this).attr("id");
		$("#row"+button_id+"").remove();
	});
	
	$('#submitInv').click(function(){

		$.ajax({
			url:"../controller/purchase_controller.php",
			method:"POST",
			data:$('#add_name').serialize()+'&type=validateInventory',
			success:function(data)
			{
				if(data.status == true){
					$.ajax({
						url:"../controller/purchase_controller.php",
						method:"POST",
						data:$('#add_name').serialize()+'&type=addInventory',
						success:function(data)
						{
							alert(data);
							$('#add_name')[0].reset();
							$("#dynamic_field").find("tr:gt(0)").remove();
							$('#add_inv').modal('hide');
							getItemDesctp($("#item_category").val());
						}
					});
				}else{
					$('#mesgInv').text(data.msg);
				}
				
			}
		});
		
	});
}*/

function getItemDesctp(value){
$.ajax( {
    url: '../controller/purchase_controller.php',
    type: 'POST',
    data: 'value='+value+'&type=getItemDesp',

    success: function(data){
      console.log('Msg',data);
      if(data.status == true){
      	  $('#item').empty();
          $('#item').append(data.data);
  	  }else{
  	  	$('#item').empty();
  	  }
    },
    error: function(r) {
      console.log(r);
      $('#item').empty();
    }
  } );
}

</script>
</html>