<?php 
require("../connection.php");
include("../user.php");
$user_id=$_SESSION['user'];
$username=$_SESSION['user_name'];
$branch_id=$_SESSION['branch_id'];
$ho_access=$_SESSION['ha'];
//$row=mysqli_query($con,"select * from log_entry order by id  DESC");		
?>
<html>
<head>
  <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?php echo TITLE;?></title>
    <meta name="description" content="Ela Admin - HTML5 Admin Template">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="apple-touch-icon" href="../images/bluebase.png">
    <link rel="shortcut icon" href="../images/bluebase.png">

    <link rel="stylesheet" href="../css/normalize.min.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/themify-icons.css">
    <link rel="stylesheet" href="../css/pe-icon-7-stroke.min.css">
    <link rel="stylesheet" href="../css/flag-icon.min.css">
    <link rel="stylesheet" href="../assets/css/cs-skin-elastic.css">
    <link rel="stylesheet" href="../assets/css/style.css">
    <link href="../css/chartist.min.css" rel="stylesheet">
    <link href="../css/jqvmap.min.css" rel="stylesheet">

    <link href="../css/weather-icons.css" rel="stylesheet" />
    <link href="../css/fullcalendar.min.css" rel="stylesheet" />

<script src="../js/jquery-1.12.4.min.js"></script>
<script src="../js/jquery-3.3.1.js"></script>
<script src="../js/jquery.dataTables.min.js"></script>


    <script src="../js/popper.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script src="../js/jquery.matchHeight.min.js"></script>
    <script src="../assets/js/main.js"></script>
    <script src="../js/jquery-3.3.1.min.js"></script>
   <style>
    #weatherWidget .currentDesc 
	{
        color: #ffffff!important;
    }
        .traffic-chart {
            min-height: 335px;
        }
        #flotPie1  {
            height: 150px;
        }
        #flotPie1 td {
            padding:3px;
        }
        #flotPie1 table {
            top: 20px!important;
            right: -10px!important;
        }
        .chart-container {
            display: table;
            min-width: 270px ;
            text-align: left;
            padding-top: 10px;
            padding-bottom: 10px;
        }
        #flotLine5  {
             height: 105px;
        }

        #flotBarChart {
            height: 150px;
        }
        #cellPaiChart{
            height: 160px;
        }
th{
	text-transform:uppercase;
}
td{
	text-transform:uppercase;
}
    </style>

<link rel="stylesheet" href="/project_temp/datatable/css/jquery.dataTables.min.css">
<script src="/project_temp/datatable/js/jquery.datatables.min.js"></script>
<!-- button --><link rel="stylesheet" type="text/css" href="/project_temp/button/css/buttons.css" /><!-- button -->

<script>
$(document).ready(function() {
		$('#example').DataTable();
		} );
</script>
</head>
<body>
 <?php require('../sidemenu.php');?>
  <!-- /#left-panel -->
    <!-- Right Panel -->
    <div id="right-panel" class="right-panel">
        <!-- Header-->
        <?php require('../header.php');?>
		<div class="content">
            <!-- Animated -->
            <div class="animated fadeIn">
			<div style="background-color:white;margin-bottom:10px;">
	<strong style="color:blue"><center>STOCK REPORT</center></strong>
	</div>
	<?php 
	if($ho_access=="yes")
	{
	?>  
	<div class="row form-group">
		<div class="col col-md-3"><label for="text-input" class=" form-control-label">Branch</label><span style="color:red;">*</span></div>
		<div class="col-12 col-md-9"><select id="branch" name="branch" placeholder="select Branch" onchange="stock_branch(this.value)" class="form-control"autocomplete="off" required>
		<option value="" selected disabled>Select Branch</option>
		 <?php
					  $brn=mysqli_query($con,"SELECT * FROM branch_master where  status='0' order by id asc");
					while($brc=mysqli_fetch_array($brn))
					{
					?>
						  <option value="<?php echo $brc['id']; ?>"><?php echo strtoupper($brc['branch_name']); ?></option>
						  
						    <?php

					}
					
					?>
					
		</select></div>
		</div>
	<div id="stock_report">	
<table id="example" class="table table-striped table-bordered" >
        <thead>
		
            <tr>
                <th>S.No</th>
                <th>CATEGORY</th>
                <th>IN-TRANSIST</th>
                <th>AVAILABLE</th>
                <th>ISSUE</th>
                <th>REPAIR</th>
                <th>SCRAB</th>
                <th>TOTAL</th>
               
            </tr>
			
        </thead>
		<?php
		  $stck=mysqli_query($con,"SELECT 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 
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['catgry'];?></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;"><?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>Total</th>
		<th></th>
		<th style="color:blue;"><?php echo $avl;?></th>
		<th style="color:blue;"><?php echo $avl1;?></th>
		<th style="color:blue;"><?php echo $avl2;?></th>
		<th style="color:blue;"><?php echo $avl3;?></th>
		<th style="color:blue;"><?php echo $avl4;?></th>
		<th style="color:blue;"><?php echo $avl5;?></th>
		</tr>
		

    </table>
	
	<?php
	}
	else {
	?>

		<table id="example" class="table table-striped table-bordered" >
        <thead>
		
            <tr>
                <th>S.No</th>
                <th>CATEGORY</th>
                <th>IN-TRANSIST</th>
                <th>AVAILABLE</th>
                <th>ISSUE</th>
                <th>REPAIR</th>
                <th>SCRAB</th>
                <th>TOTAL</th>
               
            </tr>
			
        </thead>
		<?php
		  $stck=mysqli_query($con,"SELECT 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
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['catgry'];?></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;"><?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>Total</th>
		<th></th>
		<th style="color:blue;"><?php echo $avl;?></th>
		<th style="color:blue;"><?php echo $avl1;?></th>
		<th style="color:blue;"><?php echo $avl2;?></th>
		<th style="color:blue;"><?php echo $avl3;?></th>
		<th style="color:blue;"><?php echo $avl4;?></th>
		<th style="color:blue;"><?php echo $avl5;?></th>
		</tr>
		

    </table>
		
	<?php
	}
	?>
	</div>
	</div>
	</div>
	<div class="clearfix"></div>
	</div>
	</body>
	</html>
	
 <?php require("../mainjavascript.js");?>

