<?php 
require("../connection.php");
include("../user.php");
$user_id=$_SESSION['user'];
$username=$_SESSION['user_name'];
$branch=$_SESSION['division_name'];
// $row=mysqli_query($con,"select cm.id as cid,cm.category_type,cm.category_brand,cm.category_description,cm.category_id,cm.amount,cm.total_amount,cm.availability,mm.name as measurement,case when cm.status='0' then 'ACTIVE' when cm.status='1' then 'INACTIVE' end as sts,tm.type as dept from category_master cm inner join measurement_master mm on mm.id = cm.measurement inner join type_master tm on tm.id = cm.department where cm.status in(0,1) and cm.availability > 0 order by cm.id desc");	
// $row = mysqli_query($con, "
//     SELECT 
//         cm.id AS cid,
//         cm.category_type,
//         cm.category_brand,
//         cm.category_description,
//         cm.category_id,
//         cm.amount,
//         cm.total_amount,
//         cm.availability,
//         mm.name AS measurement,
//         CASE 
//             WHEN cm.status = 0 THEN 'ACTIVE'
//             WHEN cm.status = 1 THEN 'INACTIVE'
//         END AS sts,
//         tm.type AS dept
//     FROM 
//         category_master cm
//     LEFT JOIN 
//         measurement_master mm ON mm.id = cm.measurement
//     LEFT JOIN 
//         type_master tm ON tm.id = cm.department
//     WHERE 
//         cm.status IN (0,1) AND cm.availability > 0
//     ORDER BY 
//         cm.id DESC
// ");
$row = mysqli_query($con, "
    SELECT 
        cm.id AS cid,
        cm.category_type,
        cm.category_brand,
        cm.category_description,
        cm.category_id,
        cm.amount,
        cm.total_amount,
        cm.availability,
        mm.name AS measurement,
        CASE 
            WHEN cm.status = 0 THEN 'ACTIVE'
            WHEN cm.status = 1 THEN 'INACTIVE'
        END AS sts,
        tm.type AS dept
    FROM 
        category_master cm
    LEFT JOIN 
        measurement_master mm ON mm.id = cm.measurement
    LEFT JOIN 
        type_master tm ON tm.id = cm.department
    ORDER BY 
        cm.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>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
    <link rel="stylesheet" href="/asset_temp/datatable/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="/asset_temp/button/css/buttons.css" />
    <script src="/asset_temp/datatable/js/jquery.dataTables.min.js"></script>
    <script src="../js/jquery.table2excel.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;
        }

    </style>

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


</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>LIST OF STOCK</center></strong>
        	</div>
        	<button class="button button--moema button--text-thick button--text-upper button--size-s" style="padding:1.5px;" onclick="createcategory()"><i class="fa fa-puzzle-piece">CREATE</i></button>
        	<button class="button button--moema button--text-thick button--text-upper button--size-s" style="padding:1.5px;" onclick="uploadexcel()"><i class="fa fa-upload">UPLOAD</i></button>		
        	<div style="margin-bottom:10px;">
                <input type="button" class="btn btn-success" value="Export to Excel" onclick="ExportStock()" />
                <button class="btn btn-primary" onclick="printDivStock()"><i class="fa fa-print"></i> Print</button>
            </div>
                
            <div id="DivIdToPrint">
                <table id="stockexample" class="table table-striped table-bordered" style="text-transform:uppercase;" >
                <thead>
                    <tr>
                        <th>S.No</th>
                        <th>Stock ID</th>
                        <th>Stock Name</th>
                        <th>Stock Brand</th>
                        <th>Department</th>
                        <th>Stock Description</th>
                        <th>Stock Availability</th>
                        <th>Measurement_type</th>
                        <th>Stock Price</th>
                        <th>Total Amount</th>
                        <!-- <th>Measurement</th> -->
                        <th>Status</th>
                        <th>Action</th>
                        
                    </tr>
                </thead>
        		
                <tbody>
        		<?php 
        		$s=1;
        				while($type=mysqli_fetch_array($row))
        				{
        					?>
                    <tr>
                        <td><?php echo $s++ ;?></td>
                        <td><?php echo $type['category_id'];?></td>
                        <td><?php echo $type['category_type'];?></td>
                        <td><?php echo $type['category_brand'];?></td>
                        <td><?php echo $type['dept'];?></td>
                        <td><?php echo $type['category_description'];?></td>
                        <td><?php echo $type['availability'];?></td>
                        <td><?php echo $type['measurement'];?></td> 
                        <td><?php echo $type['amount'];?></td>
                        <td><?php echo $type['total_amount'];?></td>
                        <td><?php echo $type['sts']; ?></td>
                        <?php	
                             $stat=$type['sts'];				
                           if($stat=="ACTIVE")
        				   {
        					   ?>
                            <td class="text-left">
                              <button type="button" class="btn btn-link btn-round" id="<?php echo $type['cid'];?>"title="Edit Stock" onclick="editcategory(this.id)"><i class="fa fa-edit"></i></button>
        					  <button type="button" onclick="deactivate_category(this.id)" id="<?php echo $type['cid'];?>"class="btn btn-link btn-round" title="Inactive"><i class="fa fa-eye-slash"></i></button>
        					  <button type="button" onclick="delete_category(this.id)" id="<?php echo $type['cid']; ?>"class="btn btn-link btn-round" title="Delete"><i class="fa fa-trash"></i></button> 
        					</td>
        					  
                              
        					<?php
        				   }
        					else
        					{
        						?>
        						
        						<td>&emsp;&emsp;<button type="button" onclick="activate_category(this.id)" id="<?php echo $type['cid'];?>"class="btn btn-link btn-round" title="Active"><i class="fa fa-eye"></i></button></td>
        					<?php
        					}	
        					?>
        					
        			
                          </tr>
                        <?php
        				}
        				?>
                          
        		</tbody>
            </table>
        </div>
	</div>
	</div>
	<div class="clearfix"></div>
	</div>
	</body>
	</html>
	
 <?php require("../mainjavascript.js");?>
