<table id="datatableid3" class="table table-striped table-bordered table-hover">
			<thead class="thead-dark">
				<tr style="background-color:#336699">
					<th class="center">
						
					</th>
					<th>Sr. No</th>
					<th>Sent From</th>
					<th>Product Name</th>
					<th>Final Product</th>
					<th>Quantity</th>	
					<th>Type</th>
					<th>Sent DateTime</th>
					<th>Scrap</th>
					<th>Water Weight</th>
					<th style="display: none;"></th>
					<th style="display: none;"></th>
					<th style="display: none;"></th>
										
					<th>Send To</th>
					<?php
						if(@$name == 'superadmin'){
					?>
					<th>Delete</th>
					<th>Edit</th>
					<?php
						}
					?>
					
				</tr>
			</thead>
			<tbody>
			<?php 
				$sql = "select adm.storageId,frmd.depart as frmdpt,adm.send_to_quantity ,adm.final_product as finalproductId,adm.send_to_qtny_type as qtytypeid,adm.water_wt ,adm.waste, adm.id,adm.productItem_id, adm.send_from ,adm.send_to, adm.created_at as senddttime ,
					fp.item as finalprodct,qt.q_name from admin_dpts_mul adm,final_product fp ,quantity_type qt, department frmd where adm.final_product = fp.id and adm.send_to_qtny_type = qt.id and adm.send_from = frmd.id and adm.send_to = '".@$dptId."' and adm.send_to_quantity !=0";
				$result = $con->query($sql);

				if ($result->num_rows > 0) 
				{
				    // output data of each row
		    		while($row = $result->fetch_assoc()) 
		    		{
			?>
			<tr style="background-color:#AFF3CA">
				<td class="center">
					
					<p style="display: none"><?php echo $row['id']?></p>
				</td>
				<td>
					<p><?php echo $row['id']?></p>
				</td>
				<td>
					<p><?php echo $row['frmdpt']?></p>
				</td>
				<td>
					<p>
						<?php  
						$sql1="select group_concat(description) as items from productitem p where id in (".$row['productItem_id'].");";
					    $res=mysqli_query($con,$sql1);
						while($row1 = mysqli_fetch_array($res))
						{
							echo $row1['items'];
						} 
						?>
					
					</p>
				</td>

				<td>
					<p><?php echo $row['finalprodct']?></p>
				</td>
				<td>
					<p><?php 

					if($row['qtytypeid'] == '1' or $row['qtytypeid'] == '3'){
						if($row['send_to_quantity'] != 0){
							echo ($row['send_to_quantity']/1000);
						}else{
							echo $row['send_to_quantity'];
						}
					}else{
						echo $row['send_to_quantity'];
					}
					?>
					</p>
				</td>
				<td>
					<p><?php echo $row['q_name']?></p>
				</td>
				<td>
					<p><?php 
						$date = new DateTime($row['senddttime'], new DateTimeZone('MST'));
						$date->setTimezone(new DateTimeZone('Asia/Kolkata'));
						echo $date->format('Y-m-d H:i:s');
					?></p>
				</td>
				<td>
					<p>
						<?php 
						 if(!empty($row['waste'])){
						 	$sql1="select name from waster_type p where id =".$row['waste'].";";
						    $res=mysqli_query($con,$sql1);
							while($row1 = mysqli_fetch_array($res))
							{
								echo $row1['name'];
							} 
						 }
						?>
							
					</p>
				</td>
				<td>
					<p>
						<?php 

						if($row['water_wt'] != 0){
							echo ($row['water_wt']/1000);
						}else{
							echo $row['water_wt'];
						}
					
						?>
					
					</p>
				</td>
				<td style="display: none;"><?php echo $row['qtytypeid']?></td>
				<td style="display: none;"><?php echo $row['finalproductId']?></td>
				<td style="display: none;">
					<?php 
						
					 	$sql1="select * from total_purchase_qty tpq where id in (".$row['storageId'].") and ptype = 2";
					    $res=mysqli_query($con,$sql1);
						if (mysqli_num_rows($res) > 0) 
						{
							echo 2;
						}else{
							echo 0;
						}
						 
					?>	
				</td>
				<td>
						<button type="button" name="sendbtn" class="btn btn-primary sendbtn" title="Send"><i class="ace-icon fa fa-plus bigger-130"></i></button>
				</td> 
				 <?php
					if(@$name == 'superadmin'){
				?>
				<td>
						<button type="button" class="btn btn-primary deletebtn" title="Delete"><i class="ace-icon fa fa-trash-o"></i></button>
				</td>
				<td>
						<button type="button" name="edit" class="btn btn-primary editbtn" title="Edit"><i class="ace-icon fa fa-edit"></i></button>
				</td>
				<?php
					}
				?> 
			</tr>
			<?php
					}
				}

			?>
			</tbody>
		</table>

		<!--Send Modal Raw Material-->
		<div id="single_sendr" 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">Send</h4>
		        <button type="button" class="close" data-dismiss="modal">&times;</button>
		        
		      </div>
		      <div class="modal-body">
		       
				<form id="adminFormr">
				<input type="hidden" class="form-control" id="adminIdr" name="adminIdr">
				<div class="form-group">
					<?php 
			       
			        $productnmlbl='Final Product Name';
			       
			    	?>
				    <label for="item"><?php echo $productnmlbl;?> : </label>
				    <input type="text" class="form-control" id="itemr" name="itemr" readonly>
				</div>	
				
				<div class="form-group" style="width: 220px">
				    <label style="width:150px;" for="quan">Total Quantity : </label>
					<input style="width:100px;" type="text" id="quanr" name="quanr" class="rounded" disabled>
					<input type="text" class="rounded" style="width:100px;"  id="rqty_typ" name="rqty_typ" disabled>
					<input type="hidden" class="rounded" id="qty_typIdr" name="qty_typIdr">
				</div>	
				
				<div class="form-group">
				    <div class="form-group" id="rqty21" >
					<label style="width:150px;" for="qty">Input Quantity :</label>
				    <input type="text" style="width:120px;" maxlength="6" class="rounded" id="riko" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Kilo</label>
					<input type="text" style="width:100px;" maxlength="3" class="rounded" id="rigr" pattern="^(0|[1-9][0-9]*)$" value ="0"><label>gram</label>
					
				</div>
				<div class="form-group" id="rqty22" style="display:none">
					<label style="width:150px;" for="qty">Input Quantity :</label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="ripiec" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Pieces</label>
				</div>
				<div class="form-group" id="rqty23" style="display:none">
					<label style="width:150px;" for="qty">Input Quantity :</label>
					<input type="text" style="width:120px;" maxlength="6" class="rounded" id="rilitr" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Litre</label>
					<input type="text" style="width:100px;" maxlength="3" class="rounded" id="rimltr" pattern="^(0|[1-9][0-9]*)$" value ="0">ml
				</div>
				<div class="form-group" id="rqty24" style="display:none">
					<label style="width:150px;" for="qty">Input Quantity :</label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="rimtr" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Meter</label>
				</div>
				<div class="form-group" id="rqty25" style="display:none">
					<label style="width:150px;" for="qty">Input Quantity :</label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="rift" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Feet</label>
				</div>
					<input type="hidden" id="rinitialqty" name="rinitialqty" class="rounded">
				</div>	
				<div class="dropdown-divider"></div>
				<div class="form-group">
			      <label style="width:150px;" for="no"><b>Send To Department:</b></label>
			      <select style="width:170px;" id="rdpt" name="rdpt" onchange="rdepartmentCheck()" class="rou" required>
			        <?php 
			        if($dptId == '9'){
			        	$sql1="select * from department where id = 10";
			        }else{
						$sql1="select * from department where id not in (".@$dptId.",13)";
					}
					$res=mysqli_query($con,$sql1);
					while($row1 = mysqli_fetch_array($res))
					{
				        	
					?>
					<option value="<?php echo $row1['id']; ?>"><?php echo $row1['depart']; ?></option> 
					<?php
			        	
					}
					?>
			        </select>
					<button type="button" class="btn btn-primary" style="display: none" id="rothrdept" data-toggle="tooltip" data-placement="bottom" title="Add Other Department" ><i class="ace-icon fa fa-plus bigger-130"></i></button>
		        
				</div>	
				<?php
					if($dptId != '9'){
	    		?>
				<div class="form-group" >
		            <label  style="width:150px;"for="no"><b>Final Product :</b></label>
		            <select name="rfin_product" id="rfin_product" class="rou">
					<?php 
					 $sql1="select * from final_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>
					
				   <button type="button" class="btn btn-primary finalproductBtn" data-toggle="tooltip" data-placement="bottom" title="Add product" ><i class="ace-icon fa fa-plus bigger-130"></i></button>
				</div>	
				<?php
					}
				?>
				
				<div class="form-group" id="rsendqty_typDiv">
				    <label style="width:150px;"><b>Quantity Type</b></label>
				    <select style="width:150px;" class="rou" id="rsendqty_typ" name="rsendqty_typ" onchange="rchangefunc()" required>
					  <?php 
					  	if($dptId != '9'){
	    					$sendQtyLbl = 'Send Quantity';
	    				}else{
					  		$sendQtyLbl= 'Per Box Quantity';
					  	}
						$sql1="select * from quantity_type";
					    $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>
				</div>
				<div class="form-group">
				    <input style="width:150px;" type="hidden" id="rsend_to_quantity" name="rsend_to_quantity">
				<div class="form-group" id="rqty11" >
					<label style="width:150px;" for="qty"><b><?php echo $sendQtyLbl;?> :</b></label>
				    <input type="text" style="width:120px;" maxlength="6" class="rounded" id="rko" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Kilo</label>
					<input type="text" style="width:100px;" maxlength="3" class="rounded" id="rgr" pattern="^(0|[1-9][0-9]*)$" value ="0"><label>gram</label>
					
				</div>
				<div class="form-group" id="rqty12" style="display:none">
					<label style="width:150px;" for="qty"><b><?php echo $sendQtyLbl;?> :</b></label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="rpiec" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Pieces</label>
				</div>
				<div class="form-group" id="rqty13" style="display:none">
					<label style="width:150px;" for="qty"><b><?php echo $sendQtyLbl;?> :</b></label>
					<input type="text" style="width:120px;" maxlength="6" class="rounded" id="rlitr" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Litre</label>
					<input type="text" style="width:100px;" maxlength="3" class="rounded" id="rmltr" pattern="^(0|[1-9][0-9]*)$" value ="0">ml
				</div>
				<div class="form-group" id="rqty14" style="display:none">
					<label style="width:150px;" for="qty"><b><?php echo $sendQtyLbl;?> :</b></label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="rmtr" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Meter</label>
				</div>
				<div class="form-group" id="rqty15" style="display:none">
					<label style="width:150px;" for="qty"><b><?php echo $sendQtyLbl;?> :</b></label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="rft" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Feet</label>
				</div>
				</div>
				
				 <div class="form-group">
					 <label style="width:150px;" for="no"><b>Waste Type :</b></label>
		       <select style="width:150px;" id="rwtype" name="rwtype" class="rou" required>
		        <?php 
		        
					if($dptId == '9'){
			        	$sql1="select * from waster_type where id = 4";
			        }else{
						$sql1="select * from waster_type";
					}
							
					$res=mysqli_query($con,$sql1);
					while($row1 = mysqli_fetch_array($res))
					{
				?>
					<option value="<?php echo $row1['id']; ?>"><?php echo $row1['name']; ?></option> 
					<?php
					}
					?>
					</select>	
				  </div>

		      <div class="form-group" id="rwaste_qty_typDiv">
		            <label style="width:150px;" for="waste_qty_typ"><b>Waste Quantity Type :</b></label>
		            <select style="width:150px;" class="rou" id="rwaste_qty_typ" name="rwaste_qty_typ" onchange="rchangeWasteQtyType()" required>
		              <?php 
						$sql1="select * from quantity_type";
					    $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="hidden" class="rounded" style="width:100px;"  id="rwaste_qty" name="rwaste_qty" readonly>
		      </div>

			   <div class="form-group">
			    <div class="form-group" id="rqty16" >
				<label style="width:150px;" for="waste_qty"><b>Waste Quantity :</b></label>
	            <input type="text" style="width:120px;" maxlength="6" class="rounded" id="rwko" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Kilo</label>
				<input type="text" style="width:100px;" maxlength="3" class="rounded" id="rwgr" pattern="^(0|[1-9][0-9]*)$" value ="0"><label>gram</label>
				
				</div>
				<div class="form-group" id="rqty17" style="display:none">
				<label style="width:150px;" for="waste_qty"><b>Waste Quantity :</b></label>
				<input type="text" style="width:150px;" maxlength="6" class="rounded" id="rwpiec" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Pieces</label>
				</div>
				<div class="form-group" id="rqty18" style="display:none">
				<label style="width:150px;" for="waste_qty"><b>Waste Quantity :</b></label>
				<input type="text" style="width:120px;" maxlength="6" class="rounded" id="rwlitr" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Litre</label>
				<input type="text" style="width:100px;" maxlength="3" class="rounded" id="rwmltr" pattern="^(0|[1-9][0-9]*)$" value ="0">ml
				</div>
				 <div class="form-group" id="rqty19" style="display:none">
				<label style="width:150px;" for="waste_qty"><b>Waste Quantity :</b></label>
				<input type="text" style="width:150px;" maxlength="6" class="rounded" id="rwmtr" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Meter</label>
				</div>
				<div class="form-group" id="rqty20" style="display:none">
				<label style="width:150px;" for="waste_qty"><b>Waste Quantity :</b></label>
				<input type="text" style="width:150px;" maxlength="6" class="rounded" id="rwft" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Feet</label>
				</div>
			  </div>

			  <?php if($dptId == '9'){ ?>
			  	<div class="form-group" id="rpacking_type_div">
		            <label id="rpackaging_label" style="width:150px;" for="packaging_qt"><b>No. of Boxes</b></label>
		            <input type="text" style="width:100px;" maxlength="6" class="rounded" id="rpackaging_qt" name="rpackaging_qt" pattern="^(0|[1-9][0-9]*)$" value ="0">
		        </div>
		      <div class="form-group">
			      <label style="width:150px;"><b>Send Rejection To Department:</b></label>
			      <select style="width:170px;" id="rwastedpt" name="rwastedpt" class="rou" required>
			      	 <option value="0" disabled selected>Please select....</option>
			        <?php 
			        $sql1="select * from department where id not in (".@$dptId.",13,10)";
							
							$res=mysqli_query($con,$sql1);
						while($row1 = mysqli_fetch_array($res))
						{
				        	
					?>
					<option value="<?php echo $row1['id']; ?>"><?php echo $row1['depart']; ?></option> 
					<?php
			        	
						}
					?>
			        </select>
				        
				</div>	
			<?php } ?>

			  <button type="submit" name="radminSend" id="radminSend" class="p-1 mb-1 bg-primary text-white rounded">Submit</button>
			  <button type="button" class="p-1 mb-2 bg-danger text-white rounded" data-dismiss="modal">Close</button>
			</form> 

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

		  </div>
		</div>

		<!--Edit Modal-->
		<div id="reditModal" 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">Edit Product</h4>
		        <button type="button" class="close" data-dismiss="modal">&times;</button>
		        
		      </div>
		      <div class="modal-body">
		       
			<form id="reditForm">
			<input type="hidden" class="form-control" id="reditadminId" name="reditadminId">
			<div class="form-group">
				    <label for="item">Product Name : </label>
				    <input type="text" class="form-control" id="redititem" name="redititem" disabled>
				</div>
				<div class="form-group" >
		            <label  style="width:150px;"for="no"><b>Final Product :</b></label>
		            <select name="reditfin_product" id="reditfin_product" class="rou">
					<?php 
					 $sql1="select * from final_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>
					
				   <button type="button" class="btn btn-primary finalproductBtn" data-toggle="tooltip" data-placement="bottom" title="Add product" ><i class="ace-icon fa fa-plus bigger-130"></i></button>
				</div>	
				<div class="form-group">
				<input type="hidden" class="rounded" style="width:100px;"  id="rptypeId" disabled>
				<label style="width:150px;" for="qty"><b>Old Send Quantity :</b></label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="roldqty" disabled><label id="roldqtytype"></label>
				</div>
			  <div class="form-group">
				    <label style="width:150px;"><b>Quantity Type</b></label>
				    <select style="width:150px;" class="rou" id="reditsendqty_typ" name="reditsendqty_typ" onchange="changefuncEdit()" required>
					  <?php 
						$sql1="select * from quantity_type";
					    $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>
				</div>
				<div class="form-group">
				    <input style="width:150px;" type="hidden" id="reditsend_to_quantity" name="reditsend_to_quantity">
				<div class="form-group" id="rqty31" >
					<label style="width:150px;" for="qty"><b>Send Quantity :</b></label>
				    <input type="text" style="width:120px;" maxlength="6" class="rounded" id="reko" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Kilo</label>
					<input type="text" style="width:100px;" maxlength="3" class="rounded" id="regr" pattern="^(0|[1-9][0-9]*)$" value ="0"><label>gram</label>
					
				</div>
				<div class="form-group" id="rqty32" style="display:none">
					<label style="width:150px;" for="qty"><b>Send Quantity :</b></label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="repiec" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Pieces</label>
				</div>
				<div class="form-group" id="rqty33" style="display:none">
					<label style="width:150px;" for="qty"><b>Send Quantity :</b></label>
					<input type="text" style="width:120px;" maxlength="6" class="rounded" id="relitr" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Litre</label>
					<input type="text" style="width:100px;" maxlength="3" class="rounded" id="remltr" pattern="^(0|[1-9][0-9]*)$" value ="0">ml
				</div>
				<div class="form-group" id="rqty34" style="display:none">
					<label style="width:150px;" for="qty"><b>Send Quantity :</b></label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="remtr" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Meter</label>
				</div>
				<div class="form-group" id="rqty35" style="display:none">
					<label style="width:150px;" for="qty"><b>Send Quantity :</b></label>
					<input type="text" style="width:150px;" maxlength="6" class="rounded" id="reft" pattern="^[0-9]+(\.[0-9]{1,4})?$" title="Enter a Valid Input" value="0"><label>Feet</label>
				</div>
				</div>

				<div class="form-group" id="reditwateractivityDiv">
		    	<div class="form-group">
				<label style="width:150px;" for="qty"><b>Old Extra Weight Added by Water :</b></label>
				<input type="text" style="width:150px;" maxlength="6" class="rounded" id="roldextrawaterwt" disabled><label>Kilogram</label>
				</div>
		      	<input type="hidden" class="rounded" style="width:100px;"  id="reditextrawaterwt" name="reditextrawaterwt" readonly>
		        <label style="width:150px;" for="extrawaterwt"><b>Extra Weight Added by Water : </b></label>
		        <input type="text" style="width:120px;" maxlength="6" class="rounded" id="reditextrawaterwtko" pattern="^(0|[1-9][0-9]*)$" title="Enter a Valid Input" value="0"><label>Kilo</label>
					<input type="text" style="width:100px;" maxlength="3" class="rounded" id="reditextrawaterwtgr" pattern="^(0|[1-9][0-9]*)$" value ="0"><label>gram</label>
		      	</div>

		      <button type="submit" id = "rupdateProds" name="rupdateProds" class="btn btn-gradient-primary mr-2">Update</button>
				  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			</form> 

		      </div>
		     
		    </div>

		  </div>
		</div>
<script type="text/javascript">
$(document).ready(function(){
	var jvdptId = '<?php echo @$dptId; ?>';

	var t = $('#datatableid3').DataTable( {
	rowReorder: true,
	"order": [[ 7, "desc" ]],
    columnDefs: [
        { orderable: true, targets: '_all' }
        
    ]
	} );

	if(jvdptId == 9){
		document.getElementById('rdpt').disabled = true;
		document.getElementById('rwtype').disabled = true;
		document.getElementById('rsendqty_typDiv').style.display = 'none';
		document.getElementById('rwaste_qty_typDiv').style.display = 'none';
	}

	$('#datatableid3').on('click','.sendbtn',function() {
			
		$('#single_sendr').modal('show');

		$tr = $(this).closest('tr');

		var data = $tr.children('td').map(function(){
			return $(this).text();
		}).get();

		$('#adminIdr').val(data[0].trim());
		$('#itemr').val(data[4].trim());
		$('#quanr').val(data[5].trim());
		$('#rqty_typ').val(data[6].trim());
		
		$('#qty_typIdr').val(data[10].trim());
						
		if(jvdptId == 9){
			$('#rsendqty_typ').val(data[10].trim());
			$('#rwaste_qty_typ').val(data[10].trim());
			rchangefunc();
		  	rchangeWasteQtyType();
		  	rdepartmentCheck();
		}
		rchangeInitialQtyType();
				
	});

	$('#datatableid3').on('click','.editbtn',function() {
			
		$('#reditModal').modal('show');

		$tr = $(this).closest('tr');

		var data = $tr.children('td').map(function(){
			return $(this).text();
		}).get();

		$('#reditadminId').val(data[0].trim());
		$('#redititem').val(data[3].trim());
		$('#roldqty').val(data[5].trim());
		$('#roldqtytype').html(data[6].trim());
		
		$('#reditfin_product').val(data[11].trim());
		
		$('#reditsendqty_typ').val(data[10].trim());

		$('#roldextrawaterwt').val(data[9].trim());

		var ptypId = data[12].trim();
		
		$('#rptypeId').val(ptypId);
		console.log('ptypId',ptypId);
		if(ptypId == '2'){
			document.getElementById("reditwateractivityDiv").style.display = "block";
		}else{
			document.getElementById("reditwateractivityDiv").style.display = "none";
		}

		rchangefuncEdit();
		
	});

	$('#datatableid3').on('click','.deletebtn',function() {
		$tr = $(this).closest('tr');

		var datatb = $tr.children('td').map(function(){
			return $(this).text();
		}).get();

		var adminId = datatb[0].trim();
		if (confirm("Are You Sure?")) {
		$.ajax( {
	        url: '../controller/multiple_raw_material_controller.php',
	        method: 'POST',
	        data:'type=validateProductIsProcessed&adminId='+adminId,
	        
	        success: function(data1){
	          console.log('Msg',data1);
	          if(data1.status == true){
		        alert('This Product has been processed furthur, first please delete from processed departments to delete this!.'); 
		      }else{

		      	$.ajax( {
			        url: '../controller/multiple_raw_material_controller.php',
			        method: 'POST',
			        data:'type=adminDelete&adminId='+adminId+'&userId=<?php echo @$userid; ?>',
			        
			        success: function(data2){
			          console.log('Msg',data2);
			          if(data2.status == true){
			          	alert('Product deleted and Quantity reverted to '+data2.revertDpt); 
			          	window.location.reload();
			      	  }else{
			      	  	alert('Failed To Delete Product'); 
			      	  }
			        },
			        error: function(r) {
			          alert('Unable To Delete Product'); 
			        }
			      } );
	      	  	
	      	  }
	        },
	        error: function(r) {
	          alert('Unable To Edit Product'); 
	        }
	      } );
		}
	});

	$('#rothrdept').on('click',function() {
			
		$('#ad_dpt').modal('show');
	});

	$("#adminFormr").submit(function(e) {
    document.getElementById("radminSend").disabled=true;
    //prevent Default functionality
    e.preventDefault();
    //do your own request an handle the results
   	
   	var selectedValue = $('#rsendqty_typ').val();
   	console.log('Slected data',selectedValue);
   if(selectedValue == "1")
	{
		var kilogrm = (parseInt($('#rko').val()) * 1000)+parseInt($('#rgr').val());
		$('#rsend_to_quantity').val(kilogrm);
	}else if(selectedValue == "3")
	{
		var milliltr = (parseInt($('#rlitr').val()) * 1000)+parseInt($('#rmltr').val());
		$('#rsend_to_quantity').val(milliltr);
	}else if(selectedValue == "2")
	{
		$('#rsend_to_quantity').val($('#rpiec').val());
	}else if(selectedValue == "4")
	{
		$('#rsend_to_quantity').val($('#rmtr').val());
		
	}else if(selectedValue == "5")
	{
		$('#rsend_to_quantity').val($('#rft').val());
	}

	var selectedValue2 = $('#rwaste_qty_typ').val();
   	//console.log('Slected data',selectedValue);
   	if(selectedValue2 == "1")
	{
		var kilogrm = (parseInt($('#rwko').val()) * 1000)+parseInt($('#rwgr').val());
		$('#rwaste_qty').val(kilogrm);
	}else if(selectedValue2 == "3")
	{	var milliltr = (parseInt($('#rwlitr').val()) * 1000)+parseInt($('#rwmltr').val());
		$('#rwaste_qty').val(milliltr);
	}else if(selectedValue2 == "2")
	{
		$('#rwaste_qty').val($('#rwpiec').val());
	}else if(selectedValue2 == "4")
	{
		$('#rwaste_qty').val($('#rwmtr').val());
		
	}else if(selectedValue2 == "5")
	{
		$('#rwaste_qty').val($('#rwft').val());
	}

	var totalqt = parseFloat($('#quanr').val());
	var selectedValue3 = $('#qty_typIdr').val();
	if(selectedValue3 == "1")
	{
		var kilogrm = (parseInt($('#riko').val()) * 1000)+parseInt($('#rigr').val());
		$('#rinitialqty').val(kilogrm);
		totalqt = totalqt * 1000;
	}else if(selectedValue3 == "3")
	{	var milliltr = (parseInt($('#rilitr').val()) * 1000)+parseInt($('#rimltr').val());
		$('#rinitialqty').val(milliltr);
		totalqt = totalqt * 1000;
	}else if(selectedValue3 == "2")
	{
		$('#rinitialqty').val($('#ripiec').val());
	}else if(selectedValue3 == "4")
	{
		$('#rinitialqty').val($('#rimtr').val());
		
	}else if(selectedValue3 == "5")
	{
		$('#rinitialqty').val($('#rift').val());
	}
	
	var formData = new FormData(this);

	if(jvdptId == 9){
		formData.append('type','adminPackageSendToStockMl');
		formData.append('userId',<?php echo @$userid; ?>);

		var sendqty = parseFloat($('#rinitialqty').val());
		console.log('#rwastedpt',$('#rwastedpt').val());

	   if(isNaN($('#rsend_to_quantity').val()) || $('#rsend_to_quantity').val() == ''){
			alert('Invalid or Empty Value in Sending Quantity');
	    	document.getElementById("radminSend").disabled=false;
	   }else if(isNaN($('#rinitialqty').val()) || $('#rinitialqty').val() == ''){
			alert('Invalid or Empty Value in Input Quantity');
	    	document.getElementById("radminSend").disabled=false;
	   }else if(isNaN($('#rwaste_qty').val()) || $('#rwaste_qty').val() == ''){
			alert('Invalid or Empty Value in Waste Quantity');
	   		document.getElementById("radminSend").disabled=false;
	   }else if(sendqty > totalqt){
	    	alert('Input Quantity cannot exceed Total Quantity');
	    	document.getElementById("radminSend").disabled=false;
	   }else if(sendqty == 0){
			alert('Input Quantity cannot be 0');
			document.getElementById("radminSend").disabled=false;
	   }else if(parseFloat($('#rsend_to_quantity').val()) == 0){
			alert('Send Quantity cannot be 0');
			document.getElementById("adminSend").disabled=false;
	   }else if(parseFloat($('#rpackaging_qt').val()) == 0){
			alert('Boxes cannot be 0');
			document.getElementById("radminSend").disabled=false;
	   }else if(parseFloat($('#rwaste_qty').val()) != 0 && $('#rwastedpt').val() == null){
			alert('Please Select a department to send rejected quantity');
			document.getElementById("radminSend").disabled=false;
	   }else if((parseFloat($('#rsend_to_quantity').val()) * parseFloat($('#rpackaging_qt').val())) > sendqty){
			alert('Total Quantity in boxes cannot exceed input quantity');
			document.getElementById("radminSend").disabled=false;
	   }else if(((parseFloat($('#rsend_to_quantity').val()) * parseFloat($('#rpackaging_qt').val()))+ parseFloat($('#rwaste_qty').val())) > sendqty){
			alert('Overall Quantity cannot exceed input quantity');
			document.getElementById("radminSend").disabled=false;
	   }else{
		     $.ajax( {
	        url: '../controller/multiple_raw_material_controller.php',
	        type: 'POST',
	        data: formData,
	        processData: false,
	        contentType: false,

	        success: function(data){
	          console.log('Msg',data);
	          if(data.status == true){
	          	if(parseFloat($('#rwaste_qty').val()) != 0){
	          		alert('Product sent to Stock and rejected product(s) sent to '+$( "#rwastedpt option:selected" ).text()); 
	          	}else{
	          		alert('Product sent to Stock'); 		
	          	}
		        
		        window.location.reload();
	      	  }else{
	      	  	alert('Failed To Send Product'); 
	      	  	document.getElementById("radminSend").disabled=false;
	      	  }
	        },
	        error: function(r) {
	          alert('Unable To Send Product'); 
	          document.getElementById("radminSend").disabled=false;
	        }
	      } );
		}
	}else{
		formData.append('type','adminSendml');
		formData.append('sendFrom',<?php echo @$dptId; ?>);
		formData.append('userId',<?php echo @$userid; ?>);

		var sendqty = parseFloat($('#rinitialqty').val());
		console.log('sendqty data',sendqty);

	   if(isNaN($('#rsend_to_quantity').val()) || $('#rsend_to_quantity').val() == ''){
			alert('Invalid or Empty Value in Sending Quantity');
	    	document.getElementById("radminSend").disabled=false;
	   }else if(isNaN($('#rinitialqty').val()) || $('#rinitialqty').val() == ''){
			alert('Invalid or Empty Value in Input Quantity');
	    	document.getElementById("radminSend").disabled=false;
	   }else if(isNaN($('#rwaste_qty').val()) || $('#rwaste_qty').val() == ''){
			alert('Invalid or Empty Value in Waste Quantity');
	   		document.getElementById("radminSend").disabled=false;
	   }else if(sendqty > totalqt){
	    	alert('Input Quantity cannot exceed Total Quantity');
	    	document.getElementById("radminSend").disabled=false;
	    }else if(sendqty == 0){
			alert('Input Quantity cannot be 0');
			document.getElementById("radminSend").disabled=false;
	    }else if(parseFloat($('#send_to_quantity').val()) == 0){
			alert('Send Quantity cannot be 0');
			document.getElementById("radminSend").disabled=false;
	    }else{
		     $.ajax( {
		        url: '../controller/multiple_raw_material_controller.php',
		        type: 'POST',
		        data: formData,
		        processData: false,
		        contentType: false,

		        success: function(data){
		          console.log('Msg',data);
		          if(data.status == true){
			        alert('Product sent to '+data.dpt); 
			        window.location.reload();
		      	  }else{
		      	  	alert('Failed To Send Product'); 
		      	  	document.getElementById("radminSend").disabled=false;
		      	  }
		        },
		        error: function(r) {
		          alert('Unable To Send Product'); 
		          document.getElementById("radminSend").disabled=false;
		        }
		      } );
		}
	}
	
});

$("#reditForm").submit(function(e) {
    document.getElementById("rupdateProds").disabled=true;
    //prevent Default functionality
    e.preventDefault();
    //do your own request an handle the results
   	
   	var selectedValue = $('#reditsendqty_typ').val();
   	console.log('Slected data',selectedValue);
   if(selectedValue == "1")
	{
		var kilogrm = (parseInt($('#reko').val()) * 1000)+parseInt($('#regr').val());
		$('#reditsend_to_quantity').val(kilogrm);
	}else if(selectedValue == "3")
	{
		var milliltr = (parseInt($('#relitr').val()) * 1000)+parseInt($('#remltr').val());
		$('#reditsend_to_quantity').val(milliltr);
	}else if(selectedValue == "2")
	{
		$('#reditsend_to_quantity').val($('#repiec').val());
	}else if(selectedValue == "4")
	{
		$('#reditsend_to_quantity').val($('#remtr').val());
		
	}else if(selectedValue == "5")
	{
		$('#reditsend_to_quantity').val($('#reft').val());
	}
	
	var formData = new FormData(this);
	if($('#rptypeId').val() == '2'){
		var kilogrm = (parseInt($('#reditextrawaterwtko').val()) * 1000)+parseInt($('#reditextrawaterwtgr').val());
		formData.set('reditextrawaterwt',kilogrm);
	} 

	formData.append('type','adminEdit');
	formData.append('userId',<?php echo @$userid; ?>);
		
    $.ajax( {
        url: '../controller/multiple_raw_material_controller.php',
        type: 'POST',
        data: formData,
        processData: false,
        contentType: false,

        success: function(data){
          console.log('Msg',data);
          if(data.status == true){
	        alert('Product Updated!'); 
	        window.location.reload();
      	  }else{
      	  	alert(data.msg); 
      	  	document.getElementById("rupdateProds").disabled=false;
      	  }
        },
        error: function(r) {
          alert('Unable To Update Product'); 
          document.getElementById("rupdateProds").disabled=false;
        }
    } );
	
});
});

function rchangefunc() {
	var y = document.getElementById("rsendqty_typ");
	var selectedValue = y.options[y.selectedIndex].value;
	
	if(selectedValue == "1")
	{
		$('#rqty11').show();
		$('#rqty12').hide();
		$('#rqty13').hide();
		$('#rqty14').hide();
		$('#rqty15').hide();
		
	}else if(selectedValue == "2")
	{
		$('#rqty12').show();
		$('#rqty11').hide();
		$('#rqty13').hide();
		$('#rqty14').hide();
		$('#rqty15').hide();
		
	}else if(selectedValue == "4")
	{
		$('#rqty12').hide();
		$('#rqty11').hide();
		$('#rqty13').hide();
		$('#rqty14').show();
		$('#rqty15').hide();
		
	}else if(selectedValue == "5")
	{
		$('#rqty12').hide();
		$('#rqty11').hide();
		$('#rqty13').hide();
		$('#rqty14').hide();
		$('#rqty15').show();
		
	}else
	{
		$('#rqty13').show();
		$('#rqty11').hide();
		$('#rqty12').hide();
		$('#rqty14').hide();
		$('#rqty15').hide();
		
	}
}

function rchangeInitialQtyType() {
	
	var selectedValue = $('#qty_typIdr').val();
	
	if(selectedValue == "1")
	{
		$('#rqty21').show();
		$('#rqty22').hide();
		$('#rqty23').hide();
		$('#rqty24').hide();
		$('#rqty25').hide();
		
	}else if(selectedValue == "2")
	{
		$('#rqty22').show();
		$('#rqty21').hide();
		$('#rqty23').hide();
		$('#rqty24').hide();
		$('#rqty25').hide();
		
	}else if(selectedValue == "4")
	{
		$('#rqty22').hide();
		$('#rqty21').hide();
		$('#rqty23').hide();
		$('#rqty24').show();
		$('#rqty25').hide();
		
	}else if(selectedValue == "5")
	{
		$('#rqty22').hide();
		$('#rqty21').hide();
		$('#rqty23').hide();
		$('#rqty24').hide();
		$('#rqty25').show();
		
	}else
	{
		$('#rqty23').show();
		$('#rqty21').hide();
		$('#rqty22').hide();
		$('#rqty24').hide();
		$('#rqty25').hide();
		
	}
}

function rchangeWasteQtyType(){
	var y = document.getElementById("rwaste_qty_typ");
	var selectedValue = y.options[y.selectedIndex].value;
	
	if(selectedValue == "1")
	{
		$('#rqty16').show();
		$('#rqty17').hide();
		$('#rqty18').hide();
		$('#rqty19').hide();
		$('#rqty20').hide();
		
	}else if(selectedValue == "2")
	{
		$('#rqty17').show();
		$('#rqty16').hide();
		$('#rqty18').hide();
		$('#rqty19').hide();
		$('#rqty20').hide();
		
	}else if(selectedValue == "4")
	{
		$('#rqty16').hide();
		$('#rqty17').hide();
		$('#rqty18').hide();
		$('#rqty19').show();
		$('#rqty20').hide();
		
	}else if(selectedValue == "5")
	{
		$('#rqty16').hide();
		$('#rqty17').hide();
		$('#rqty18').hide();
		$('#rqty20').show();
		$('#rqty19').hide();
	}else
	{
		$('#rqty16').hide();
		$('#rqty17').hide();
		$('#rqty19').hide();
		$('#rqty18').show();
		$('#rqty20').hide();
		
	}
}

function rdepartmentCheck(){
  var x = document.getElementById("rdpt").value;

  if( x == '12'){
    document.getElementById("rothrdept").style.display = "initial";
  }else{
    document.getElementById("rothrdept").style.display = "none";
  }

  var existing = '<?php echo @$dptId; ?>';
  var p_div = document.getElementById("rpacking_type_div");
  if(existing == '9' && x == '10'){
  	p_div.style.display = "block";
    document.getElementById("rpackaging_qt").required = true;
    
  }else{
  	p_div.style.display = "none";
  	document.getElementById("rpackaging_qt").required = false;
  }

}

function rchangefuncEdit(){
	var selectedValue = $('#reditsendqty_typ').val();
	
	if(selectedValue == "1")
	{
		$('#rqty31').show();
		$('#rqty32').hide();
		$('#rqty33').hide();
		$('#rqty34').hide();
		$('#rqty35').hide();
		
	}else if(selectedValue == "2")
	{
		$('#rqty32').show();
		$('#rqty31').hide();
		$('#rqty33').hide();
		$('#rqty34').hide();
		$('#rqty35').hide();
		
	}else if(selectedValue == "4")
	{
		$('#rqty32').hide();
		$('#rqty31').hide();
		$('#rqty33').hide();
		$('#rqty34').show();
		$('#rqty35').hide();
		
	}else if(selectedValue == "5")
	{
		$('#rqty32').hide();
		$('#rqty31').hide();
		$('#rqty33').hide();
		$('#rqty34').hide();
		$('#rqty35').show();
		
	}else
	{
		$('#rqty33').show();
		$('#rqty31').hide();
		$('#rqty32').hide();
		$('#rqty34').hide();
		$('#rqty35').hide();
		
	}
}
	
</script>
