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


$catgryid=$_REQUEST['catgryid'];

//echo $catgryid;
?>
<script>
$(document).ready(function() {
		$('#example').DataTable();
		} );
</script>

<?php  
$cat_name=mysqli_query($con,"select category  from category_master where id='$catgryid'");
$catname=mysqli_fetch_array($cat_name)
   ?>
  <h4><center>CATEGORY-<b style="color:blue;text-transform:uppercase;"><?php echo  $catname['category']; ?></b></center></h4>

<table id="example" class="table table-striped table-bordered"  >
        <thead>
		     <tr>
               <th>s.no</th>
               <th>Branch</th>
               <th>asset-id</th>
               <th>po no.</th>
               <th>Issue date</th>
               <th>employee code</th>
               <th>employee name</th>
               <th>department</th>
               <th>location</th>
               <th>warranty</th>
               <th>status</th>
			</tr>
			
        </thead>
		<?php 
		if($ho_access=="yes")
		{
		
		  $catgry=mysqli_query($con,"SELECT ism.id as id_no, ismt.item_code,ismt.category,ism.issue_date,em.employee_name,em.emp_no,ism.emp_dept,lm.location,ism.expire_date,im.po_no,sm.name as issue,bm.branch_name,ism.issue_date,case when ism.expire_date=CURDATE() THEN 'TODAY EXPIRED' when ism.expire_date>CURDATE() THEN 'PROCESSING' else 'EXPIRED' end as ex_date  FROM `issue_master` ism  join `issue_master_table` ismt on ism.id=ismt.issue_master_id join item_master im on ismt.item_code=im.asset_id join category_master cm on cm.id=ismt.category join employee_master em on em.emp_no=ism.emp_code join location_master lm on lm.id=ism.location join status_master sm on im.status=sm.status_no join branch_master bm on im.branch_id=bm.id where ismt.category='$catgryid'");
		
	 }
		else{
			
			 $catgry=mysqli_query($con,"SELECT  ism.id as id_no,ismt.item_code,ismt.category,ism.issue_date,em.employee_name,em.emp_no,ism.emp_dept,lm.location,ism.expire_date,im.po_no,sm.name as issue,bm.branch_name,ism.issue_date,case when ism.expire_date=CURDATE() THEN 'TODAY EXPIRED' when ism.expire_date>CURDATE() THEN 'PROCESSING' else 'EXPIRED' end as ex_date  FROM `issue_master` ism  join `issue_master_table` ismt on ism.id=ismt.issue_master_id join item_master im on ismt.item_code=im.asset_id join category_master cm on cm.id=ismt.category join employee_master em on em.emp_no=ism.emp_code join location_master lm on lm.id=ism.location join status_master sm on im.status=sm.status_no join branch_master bm on im.branch_id=bm.id where ismt.category='$catgryid' and im.branch_id='$branch_id'");
		
		
		}
		
	 $s=1;
	 ?>
	  <tbody>
	 <?php
		while($type=mysqli_fetch_array($catgry))
				{
					
	
		 
		?>
		
       
		<tr>
           <td><?php echo $s++;?></td>
           <td><?php echo $type['branch_name'];?></td>
           <td><?php echo $type['item_code'];?></td>
           <td><?php echo $type['po_no'];?></td>
           <td><?php echo date("d-m-Y",strtotime($type['issue_date']));?></td>
           <td><?php echo $type['emp_no'];?></td>
           <td><?php echo $type['employee_name'];?></td>
           <td><?php echo $type['emp_dept'];?></td>
           <td><?php echo $type['location'];?></td>
          <?php if($type['ex_date']=='TODAY EXPIRED') { ?>
            <td style="color:Green;font-weight:400;"><?php echo $type['ex_date']; ?></td>
			<?php } elseif($type['ex_date']=='PROCESSING') { ?>
			<td style="color:Orange;font-weight:400;"><?php echo $type['ex_date']; ?></td>
			<?php } else { ?>
			<td  style="color:Red;font-weight:400;"><?php echo $type['ex_date']; ?></td>
			<?php } ?>
		   <?php
		   $sts=$type['issue'];
		   if($sts=="available")
		   {
		   ?>
		   <td style="color:green;"><?php echo $type['issue'];?></td>
		    <?php
		   }
		   if($sts=="issue")
			    {
		   ?>
		   <td style="color:blue;"><?php echo $type['issue'];?></td>
		    <?php
		   }
		    if($sts=="repair")
			    {
		   ?>
		   <td style="color:red;"><?php echo $type['issue'];?></td>
		    <?php
		   }
		    if($sts=="scrap")
			    {
		   ?>
		   <td style="color:black;"><?php echo $type['issue'];?></td>
		    <?php
		   }
		    if($sts=="in-movement")
			    {
		   ?>
		   <td style="color:orange;"><?php echo $type['issue'];?></td>
		    <?php
		   }
		   ?>
	     </tr>	
		
		<?php
		}
		?>
</tbody>
    </table>
			