<?php
if(basename($_SERVER['PHP_SELF']) == 'controrepo.php') 
  $cm=" class='current'";
include'header.php';
include'connection.php';
$dato=$datos=$Date;
$custo="UNSTABLE";
$a=$b=$u="";

    if(isset($_POST['custo']))
		{
		$custo=$_POST['custo'];
		}
		
		if($custo=='ALL')
		    $a="selected";
		if($custo=='BALANCED')
		    $b="selected";
		if($custo=='UNSTABLE')
		    $u="selected";

$do=mysqli_query($conn, "SELECT *FROM `items` WHERE `Status`='0' ORDER BY `Item` ASC");
?>

<script>
    function onSelectChange(){
 document.getElementById('frm').submit();
}
</script>
<div class="container-fluid main-content">
        <div class="page-title hidden-xs hidden-print">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Store Report
          </h2>
                 </div>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">

    <li class="list-group-item">
	  <a href="storepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Store Status
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="recerepo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;S.In &nbsp;Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="coutrepo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;S.Out &nbsp;Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="xrecerepo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Receiving Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="requirepo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Requisition Report
                </p>
              </a></li>
                  
			  <li class="list-group-item">
              <a href="consurepo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Consumption Report
                </p>
              </a></li> 
                  
			  <li class="list-group-item">
              <a href="balrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Item Balance Report
                </p>
              </a></li>   
                  
			  <li class="list-group-item">
              <a href="suprepo.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Suppliers Report
                </p>
              </a></li> 
                  
			  <li class="list-group-item">
              <a href="counting.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Counting Papers
                </p>
              </a></li>  
                  
			  <li class="list-group-item active">
              <a href="controrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Control Report
                </p>
              </a></li> 
                       
            </ul><br><br><br>
  </div>
                    
           
           
       
        <div class="col-lg-10">
                  <div class="row">
         
           <div class="col-lg-2 hidden-print">  </div>

        <form action="" method="post" class="form-horizontal" id="frm">  
                       
            <div class="col-lg-3 hidden-print"> </div> 
			
			<div class="col-lg-3 hidden-print"> </div>

		  <div class="col-lg-3 hidden-print"> 
<select class='form-control' name='custo' style='font-size:16px; height:34px;' required onchange="onSelectChange();">
	 <option value='ALL' <?php echo $a ?>> ALL ITEMS </option>
	 <option value='BALANCED' <?php echo $b ?>> BALANCED </option>
	 <option value='UNSTABLE' <?php echo $u ?>> UNSTABLE </option>
	        </select></div>
                  
            </form> 
             
               
            </div>
             <div class="row">
            <div class="col-lg-12" style='margin-top:-20px;'>
			 <span class="pull-right">&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
			 
		<span class="pull-right hidden-print">
		&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="exporttable" class="hidden-print" title='Export to excell' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-line-spacing"></i></a></span>
		
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">
               
    <table class="table table-striped table-hover" id="htmltable">     
        <thead><tr role="row"><th> No </th>
                        <th><div align='center'> ITEM&nbsp;NAME </th>
                       <th><div align='center'> ITEM&nbsp;TYPE </th>
                       <th><div align='center'> COST </th>
					   <th><div align='center'> SYSTEM </th>
						 <th><div align='center'> RECEIVED </th>
						 <th><div align='center'> CONSUMED </th>
						 <th><div align='center'> COUNTED </th>
							<th><div align='center'>BALANCE</th>
                     </tr>
                    </thead>
                                        <tbody>
					<?php
					$n=1;				$to=0;
						while($ro=mysqli_fetch_assoc($do)){
				$code=$ro['Number'];
			$item=$ro['Item'];
			$type=$ro['Type'];
			$pri=$ro['Price'];
			$qty=$ro['Quantity'];               $qto=number_format($qty, 2);
			$lab=$ro['Label'];
			$des=$ro['Descri'];
			$prio=number_format($pri, 2);
			$stl="style='padding:1px;'";
			
			// ******************** Received and used after datos *******
			
		$iseen=mysqli_query($conn, "SELECT SUM(`Quantity`) AS 'New' FROM `stouse` WHERE `Item`='$code' AND `Status`='0' AND `Store`='1' AND `Action`='RECEIVE'");
					$ireen=mysqli_fetch_assoc($iseen);
						$new=$ireen['New'];

		$iseeu=mysqli_query($conn, "SELECT SUM(`Quantity`) AS 'Use' FROM `stouse` WHERE `Item`='$code' AND `Status`='0' AND `Store`='1' AND `Action`='USED'");
					$ireeu=mysqli_fetch_assoc($iseeu);
						$use=$ireeu['Use'];
						
			$clo=$new-$use;	                 $cloo=number_format($clo, 2);	
						
			$newo=number_format($new, 2);					
			$useo=number_format($use, 2);
			$ope=number_format($qty-$clo, 2);
			
			if(($qty-$clo)!=0 AND $custo=='ALL')
			$stl="style='padding:1px; color:red;'";
		 
		 if($custo=='ALL' OR ($custo=='BALANCED' AND ($qty-$clo)==0)  OR ($custo=='UNSTABLE' AND ($qty-$clo)!=0)){
		print("<tr><td $stl><div align='right'>$n&nbsp;&nbsp;</td>
	                    <td $stl> $item </td><td $stl> $type </td>
	<td $stl class='text-right' style='padding-right:10px;'> $prio </div></td>
	                    <td $stl class='text-right'> $qto </td>
						<td $stl class='text-right'> $newo </td>
						<td $stl class='text-right'> $useo </td>
						<td $stl class='text-right'> $cloo </td>
						<td $stl class='text-right'> $ope </td>
	</tr>");
							$n++;
		 }
						}
						$to=number_format($to, 2);					
						?>
						
                    </tbody></table>
              </div></div>

                  </div>                     
                
              </div><span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
			 
	<span class="pull-right hidden-print">
		&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="exporttable" class="hidden-print" title='Export to excell' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-line-spacing"></i></a></span>
            </div></div>
                  </div>
        
   <?php
   include'footer.php';
   ?>
