<?php 
require("../connection.php");
include("../user.php");
$user_id=$_SESSION['user'];
$username=$_SESSION['user_name'];
$branch_id=$_SESSION['branch_id'];
$ho_access=$_SESSION['ha'];


$branchid=$_REQUEST['branchid'];
?>
<style>
td{
	
	text-transform:uppercase;
}
</style>
<table id="example" class="table table-striped table-bordered" >
        <thead>
		
            <tr>
                <th style="background:#007bff;color:white;">S.No</th>
                <th style="background:#007bff;color:white;">CATEGORY</th>
                <th style="background:#007bff;color:white;">IN-TRANSIST</th>
                <th style="background:#007bff;color:white;">AVAILABLE</th>
                <th style="background:#007bff;color:white;">ISSUE</th>
                <th style="background:#007bff;color:white;">REPAIR</th>
                <th style="background:#007bff;color:white;">SCRAB</th>
                <th style="background:#007bff;color:white;">TOTAL</th>
               
            </tr>
			
        </thead>
		<?php
		  $stck=mysqli_query($con,"SELECT cm.prefix_name as category_name,cm.category as catgry,sum(case when im.status='0' then 1 else 0 end) as available, 
sum(case when im.status='1' then 1 else 0 end) as issue,sum(case when im.status='2' then 1 else 0 end) as repair,sum(case when im.status='3' then 1 else 0 end) as scrab,sum(case when im.status='4' then 1 else 0 end) as intransist,count(im.asset_id) as total
FROM `item_master` im right join category_master cm on cm.id=im.category_id where im.branch_id='$branchid'
group by cm.category");
	 
	 $s=1;
		$avl=0;
		$avl1=0;
		$avl2=0;
		$avl3=0;
		$avl4=0;
		$avl5=0;
		while($type=mysqli_fetch_array($stck))
				{		 
		?>		
        <tbody>
		
            <tr>
            <td><?PHP echo $s++;?></td>
            <td><?php echo $type['category_name'];?></td>
            <td><?php echo $type['intransist'];?></td>
            <td><?php echo $type['available'];?></td>
            <td><?php echo $type['issue'];?></td>
            <td><?php echo $type['repair'];?></td>
            <td><?php echo $type['scrab'];?></td>
            <td style="color:green;background:white;"><?php echo $type['total'];?></td>
						
				<?php
				$avl=$avl+$type['intransist'];
				$avl1=$avl1+$type['available'];
				$avl2=$avl2+$type['issue'];
				$avl3=$avl3+$type['repair'];
				$avl4=$avl4+$type['scrab'];
				$avl5=$avl5+$type['total'];
				}
				 
				?>
		</tbody>
		<tr>
		<th style="background:white;">Total</th>
		<th style="background:white;"></th>
		<th style="color:blue;background:white;"><?php echo $avl;?></th>
		<th style="color:blue;background:white;"><?php echo $avl1;?></th>
		<th style="color:blue;background:white;"><?php echo $avl2;?></th>
		<th style="color:blue;background:white;"><?php echo $avl3;?></th>
		<th style="color:blue;background:white;"><?php echo $avl4;?></th>
		<th style="color:blue;background:white;"><?php echo $avl5;?></th>
		</tr>
		

    </table>