<?php
if(basename($_SERVER['PHP_SELF']) == 'stobal.php') 
  $cm=" class='current'";
include'header.php';
include'connection.php';
$custo='';
$conde='';
$l1=1;
$l2=40;
$lim=2;

if(isset($_GET['lim']))
		{
			$lim=$_GET['lim'];
			$l1=$l1+(40*$lim);
			$l2=$l2+(40*$lim);
			$lim++;
		}
if(isset($_GET['xlim']))
		{
			$xlim=$_GET['xlim'];
			$l1=$l1+(40*$xlim);
			$l2=$l2+(40*$xlim);
			$xlim--;
		}

if(isset($_POST['search']))
		{
			$custo=$_POST['custo'];
		}

		
		if($custo)
			$conde="AND `Number`='$custo'";

$dop=mysqli_query($cons, "SELECT *FROM `itype` WHERE `Location`='0' $conde GROUP BY `Type` ORDER BY `Type` ASC LIMIT 1400");
$fop=mysqli_num_rows($dop);
?>

<div class="container-fluid main-content">
        <div class="page-title 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="storeport.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Store Report
                </p>
              </a></li>  

	 <li class="list-group-item">
	  <a href="inrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;S.In Report
                </p>
              </a></li>  
      
    <li class="list-group-item">
	  <a href="outrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;S.Out Report
                </p>
              </a></li> 

			   <li class="list-group-item">
              <a href="delirepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Delivery Report
                </p>
              </a></li> 

			   <li class="list-group-item">
              <a href="recerepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Receiving Report
                </p>
              </a></li>

			  <li class="list-group-item">
              <a href="purrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Purchase Report
                </p>
              </a></li>   

	 <li class="list-group-item">
	  <a href="dispatch.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Count Report
                </p>
              </a></li>       

	 <li class="list-group-item active">
	  <a href="stobal.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Item Report
                </p>
              </a></li>  
                         
            </ul>
  </div>
                    
           
           
       
        <div class="col-lg-10">
                  <div class="row">
         
           <div class="col-lg-2 hidden-print"> </div>
          
         
           

        <form action="" method="post" class="form-horizontal ">                  
                       <div class="col-lg-10 hidden-print">
		<div class="col-lg-5 hidden-print"> 					
					   
					   </div>
            <div class="col-lg-4 hidden-print"> 
      <select class="form-control" name="custo">
          <option value=''> Select a Type </option>
			<?php
			$i=1;               $type=$tyno=array();
	$dois=mysqli_query($cons, "SELECT *FROM `itype` GROUP BY `Type` ORDER BY `Type` ASC");
			while($rois=mysqli_fetch_assoc($dois)){
				$fna=$rois['Type'];
				$nuo=$rois['Number'];
				$type[$i]=$fna;
				$tyno[$i]=$nuo;
				if($custo==$nuo)
					$t='selected';
				else
					$t='';
			echo"<option value='$nuo' $t> $fna </option>";
			    $i++;
			}
			?>		</select>
		 </div>
                    
                       
                       <div class="col-lg-2">
                        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div> </div>
                      
                     
                  
          </form> 

<form action='' method='post'>
<div id="testmodal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Confirmation</h4>
            </div>
            <div class="modal-body">
<div class="col-lg-6"> 
             <select class="form-control" name="store" required><option value='' selected='selected'> SELECT STORE </option>
<option value='0'> MAIN STORE </option><option value='1'> DIRECT USE </option></select>
</div>
<div class="col-lg-6"> 
		 <input name='passkey' class="form-control sm" type='password' style='text-align:center;' placeholder="Enter your password" required>
	</div>	
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="submit" name='resetall' class="btn btn-primary">Reset All</button>
            </div>
        </div>
    </div>
</div>
</form>
             
			<div class="divFooter"><center><u><b>MAIN STORE REPORT </b></u></center></div>

             <div class="row">
            <div class="col-lg-12" style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fop " ?></b></span>
			 <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>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">
               
                                 <table class="table table-striped">     
                                      <thead>
                    <tr role="row">
                     <th class="hidden-xs"> No </th>
                       <th> Item&nbsp;Type </th>
                       <th> Item&nbsp;Name </th>
						 <th> Cost&nbsp;Price </th>
                       <th> Sales&nbsp;Price </th>
                        <th><div align='center'> Open. </th><th><div align='center'> New </th>
						<th><div align='center'> Used </th><th><div align='center'> &nbsp;&nbsp;Clos. </th>
                     <th><div align='center'> Total&nbsp;Cost </th><th><div align='center'> Total&nbsp;Sales </th></tr>
                    </thead>
                                        <tbody>
					<?php
						$n=1;			$itco=$itsa=0;
			while($rop=mysqli_fetch_assoc($dop)){
			   $typ=$rop['Type'];
			   $tyn=$rop['Number'];
	$xtco=$xtsa=0;
	$do=mysqli_query($cons, "SELECT *FROM `items` WHERE `Store`<='2' AND `Status`='0' AND `Type`='$tyn' ORDER BY `Iname` ASC LIMIT 1400");
	        $fo=mysqli_num_rows($do);
	        
		while($ro=mysqli_fetch_assoc($do)){
				$code=$ro['Number'];
				$iname=$ro['Iname'];
			$kin=$ro['Type'];
			$descri=$ro['Descri'];
			$uno=$ro['Unit'];			
			$cost=$ro['Cost'];			$costo=number_format($cost, 2);
			$qt=$ro['Quantity'];				$qty=number_format($qt, 2);			
			$pri=$ro['Price'];			$prio=number_format($pri, 2);

$tco=$qt*$cost;
$tsa=$qt*$pri;
$tcoo=number_format($tco, 2);
$tsao=number_format($tsa, 2);
			
			$smin=$ro['Smin'];
			$sval=$ro['Svalue'];
			$bmin=$ro['Bvalue'];
			$bval=$ro['Bvalue'];

				$stn="padding:1px;";

$doi=mysqli_query($cons, "SELECT *FROM `itype` WHERE `Number`='$kin' ORDER BY `Number` ASC");
		$roi=mysqli_fetch_assoc($doi);
				$type=$roi['Type'];

				$dox=mysqli_query($cons, "SELECT *FROM `unit` WHERE `Number`='$uno' ORDER BY `Number` ASC");
					$rox=mysqli_fetch_assoc($dox);
							$unit=$rox['Unit'];

	// received and used item
	$rec=$use=0;
	$dor=mysqli_query($cons, "SELECT *FROM `stouse` WHERE `Item`='$code' AND `Status`='0' AND `Voucher`!='0' AND `Upda`='1' AND `Date`='$Date' AND (`Action`='RECEIVE' OR `Action`='TAKEN') ORDER BY `Number` DESC");
		while($ror=mysqli_fetch_assoc($dor)){
						$act=$ror['Action'];
						$qts=$ror['Quantity'];
if($act=='RECEIVE')
	$rec+=$qts;

if($act=='TAKEN')
	$use+=$qts;
		}
         $rece=number_format($rec, 2);					$uses=number_format($use, 2);				$open=number_format($qt-$rec+$use, 2); //$so=mysqli_query($cons, "UPDATE `items` SET `Quantity`='$qty' WHERE `Number`='$code' AND `Status`='0' LIMIT 1");
		print("<tr>
                        <td class='hidden-xs' style='$stn'>
                        <div align='center'>$n&nbsp;&nbsp;</td>
                        <td style='$stn'> $type </td>
						<td style='$stn'> $iname </td>
                        <td style='$stn'><div align='right'> $costo </td>
						<td style='$stn'><div align='right'> $prio </td>
						<td style='$stn'><div align='right'> $open </td>
						<td style='$stn'><div align='right'> $rece </td><td style='$stn'><div align='right'> $uses </td>
						<td style='$stn'><div align='right'> $qty </td>
<td style='$stn'><div align='right'> $tcoo </td><td style='$stn'><div align='right'> $tsao </td></tr>");
						  $n++;			$xtco+=$tco;			$xtsa+=$tsa;
$itco+=$tco;  			$itsa+=$tsa;
						}
						$set=mysqli_query($cons, "UPDATE `itype` SET `Count`='$fo' WHERE `Number`='$tyn'");
				
$xtcoo=number_format($xtco, 2);
$xtsao=number_format($xtsa, 2);		   
			   echo"<tr><th> </th><th colspan='8'> $typ </th>
<th><div align='right'> $xtcoo </th><th><div align='right'> $xtsao </th></tr>";
}
$xtcoo=number_format($itco, 2);
$xtsao=number_format($itsa, 2);		   
			   echo"<tr><th> </th><th colspan='8'> GRAND-TOTAL </th>
<th><div align='right'> $xtcoo </th><th><div align='right'> $xtsao </th></tr>";
						?>
						
                    </tbody>
                  </table>

					 <div class="col-md-12 hidden-print">
                  <div class="pull-right">
                  <ul class="pagination">
                      <li class="activei">
					  <?php
					  if($l1!=0){
						  ?>
					    <a href="#">
                        &nbsp;<<&nbsp; </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<?php
					 }
						?>
                       
						<?php
						echo"<a href='#'>";
						?>
                        >>                        </a>
                      </li>
                    </ul>
              </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>                       
              
            </div></div>
                  </div>
      
   </div></div></div>  
   <?php
   include'footer.php';
   ?>
