<?php



include 'connect.php';



echo"<title>STOCK REPORT</title>";



echo"<style>



b,table

{

	font-family:arial;

	font-size:12px;

}



table tr,td

{

	padding:0 3px;

}



</style>";



if(isset($_GET['factory']))

{

$factory=$_GET['factory'];



$fac=mysqli_query($conn,"select * from factory where ID='$factory'");

$fac1=mysqli_fetch_assoc($fac);



echo"<center><b>Factory : ".$fac1['factory']."</b><br /></center>



<table border='1' style='border-collapse:collapse; width:85%; margin:auto; border:1px solid #999;'>

<thead><tr><th style='width:40%;'>Product</th><th style='width:15%;'>Purchase / Production</th><th style='width:15%;'>Sales</th><th style='width:15%;'>Balance</th></tr></thead>";



$prod=mysqli_query($conn,"select * from product order by product asc");

while($prod1=mysqli_fetch_assoc($prod))

{



$pur=mysqli_query($conn,"select sum(qty) as qty from purchase where product='$prod1[ID]' and factory='$factory'");

$pur1=mysqli_fetch_assoc($pur);



$sal=mysqli_query($conn,"select sum(qty) as qty from invoice where product='$prod1[ID]' and factory='$factory'");

$sal1=mysqli_fetch_assoc($sal);



$prodc=mysqli_query($conn,"select sum(input_qty) as qty from production where input_product='$prod1[ID]' and factory='$factory'");

$prodc1=mysqli_fetch_assoc($prodc);



$prodct=mysqli_query($conn,"select sum(output_qty) as qty from production where output_product='$prod1[ID]' and factory='$factory'");

$prodct1=mysqli_fetch_assoc($prodct);



$bal=$pur1['qty']-$sal1['qty']-$prodc1['qty']+$prodct1['qty'];



$purq=$pur1['qty']+$prodct1['qty'];

$salq=$sal1['qty']+$prodc1['qty'];



echo"<tr><td>".$prod1['product']."</td><td style='text-align:right;'>".$purq."</td><td style='text-align:right;'>".$salq."</td>

<td style='text-align:right;'>".$bal."</td></tr>";

	

}



echo"</table><br />";



}



?>