<?php
require("php_con.php");
if(isset($_GET['system_product_id'])&&isset($_GET['pad_product_id'])&&isset($_GET['pad_qty'])){
	
	$e_qury=mysqli_query($connation,"SELECT * FROM product_details WHERE product_barcode='$_GET[pad_product_id]'");
	if(mysqli_num_rows($e_qury)>0){
	$e_resalt=mysqli_fetch_assoc($e_qury);
	
	mysqli_query($connation,"INSERT INTO
	product_affect_details (pad_id, pad_main_product, pad_product_id, pad_qty)
	VALUES (NULL, '$_GET[system_product_id]', '$e_resalt[product_id]', '$_GET[pad_qty]')");
	}
}

if(isset($_GET['pad_id'])){
	mysqli_query($connation,"DELETE FROM product_affect_details WHERE pad_id='$_GET[pad_id]'");
}
?>

<table style="font-size: 14px;" class="table table-sm mb-2 table-bordered">
	<tbody>
		<tr class="table-active">
			<td>Product</td>
			<td>Qty</td>
			<td style="width: 10px;">&nbsp;</td>
		</tr>
<?php
$affect_btn="";
if(isset($_GET['system_product_id'])){
$pad_qury=mysqli_query($connation,"SELECT *
FROM product_affect_details pad INNER JOIN product_details pd ON pad.pad_product_id=pd.product_id
WHERE pad.pad_main_product='$_GET[system_product_id]'
ORDER BY pad.pad_id ASC");
	
if(mysqli_num_rows($pad_qury)>0){$affect_btn=1;}else{$affect_btn=0;}
	
while($pad_resalt=mysqli_fetch_assoc($pad_qury)){
?>
		<tr>
			<td><?php echo $pad_resalt['product_name']; ?></td>
			<td><?php echo (float)$pad_resalt['pad_qty']; ?></td>
			<td><i class="fa fa-trash text-danger" style="cursor: pointer;" onClick="remove_afect_item('<?php echo $pad_resalt['pad_id']; ?>');"></i></td>
		</tr>
<?php } } ?>
	</tbody>
</table>

Affected other stocks <b><?php if($affect_btn==1){ ?><span class="text-success">On</span><?php }else{ ?><span class="text-danger">Off</span><?php } ?></b>

<input name="product_affect_stock" type="checkbox" id="product_affect_stock" style="display: none;" <?php if($affect_btn==1){echo "checked";} ?>>

<?php
if(isset($_GET['system_product_id'])){
if(!$affect_btn==1){
mysqli_query($connation,"UPDATE product_details SET product_affect_stock='0' WHERE product_id='$_GET[system_product_id]'");
}
else{
mysqli_query($connation,"UPDATE product_details SET product_affect_stock='1' WHERE product_id='$_GET[system_product_id]'");
}
}
?>