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

$fdate=$_REQUEST['fdate'];
$tdate=$_REQUEST['tdate'];
$pono=$_REQUEST['pono'];

//echo $fdate;
//echo $tdate;
//echo $pono;
?>
<script>
$(document).ready(function() {
		$('#example').DataTable();
		} );
</script>
<table id="example" class="table table-striped table-bordered" >
        <thead>
            <tr>
                <th>S.No</th>
                <th>Branch</th>
                <th>PO Number</th>
                <th>PO Date</th>
				<th>Invoice Number</th>
                <th>Invoice Date</th>
				<th>Vendor</th>
				<th>Category Name</th>
                <th>Quantity</th>
                <th>Expiry Date</th>
                <th>Status</th>
            </tr>
        </thead>
		
			<?php 
				if($ho_access=="yes")
		{
		$expry=mysqli_query($con,"select inm.po_no,inm.po_date,inm.invoice_no,inm.invoice_date,vm.vendor_name,inm.expired_date,bm.branch_name,cm.category,ict.quantity,case when inm.expired_date=CURDATE() THEN 'TODAY EXPIRED' when inm.expired_date>CURDATE() THEN 'PROCESSING' else 'EXPIRED' end as ex_date from inward_master inm join  inward_create_table ict on inm.po_no=ict.po_id join vendor_master vm on inm.vendor=vm.id join branch_master bm on inm.branch=bm.id join category_master cm on ict.category=cm.id where inm.po_date between '$fdate' and '$tdate' and inm.po_no='$pono'");
		 }
		else{
			
			$expry=mysqli_query($con,"select inm.po_no,inm.po_date,inm.invoice_no,inm.invoice_date,vm.vendor_name,inm.expired_date,bm.branch_name,cm.category,ict.quantity,case when inm.expired_date=CURDATE() THEN 'TODAY EXPIRED' when inm.expired_date>CURDATE() THEN 'PROCESSING' else 'EXPIRED' end as ex_date from inward_master inm join  inward_create_table ict on inm.po_no=ict.po_id join vendor_master vm on inm.vendor=vm.id join branch_master bm on inm.branch=bm.id join category_master cm on ict.category=cm.id where inm.po_date between '$fdate' and '$tdate' and inm.po_no='$pono' and inm.branch='$branch_id'");
		 }
	 $s=1; 
		while($type=mysqli_fetch_array($expry))
				{
					
	
		 
		?>
        <tbody>
		
            <tr>
            <td><?php echo $s++;?></td>
            <td><?php echo $type['branch_name'];?></td>
            <td><?php echo $type['po_no'];?></td>
            <td><?php echo date("d-m-Y",strtotime($type['po_date']));?></td>
			<td><?php echo $type['invoice_no'];?></td>
			<td><?php echo date("d-m-Y",strtotime($type['invoice_date']));?></td>
			<td><?php echo $type['vendor_name'];?></td>
			<td><?php echo $type['category'];?></td>
            <td><?php echo $type['quantity'];?></td>
            <td><?php echo date("d-m-Y",strtotime($type['expired_date']));?></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 } ?>	
            </tr>
				
		</tbody>
				<?php
				}
				?>
    </table>