<?php
if(basename($_SERVER['PHP_SELF']) == 'ccount.php') 
  $cs=" class='current'";
include'header.php';
$_SESSION['Dato']="";
$custo='';
$conde='';

if(isset($_POST['adjust']))
		{
			$custo=$_POST['custo'];
			$qts=$_POST['qts'];
$see=mysqli_query($conn, "SELECT `Number`, `Quantity` FROM `citems` WHERE `Iname`='$custo' AND `Status`='0' LIMIT 1");
$ree=mysqli_fetch_assoc($see);
$nuo=$ree['Number'];
$qtin=$ree['Quantity'];
	$so=mysqli_query($conn, "UPDATE `citems` SET `Quantity`=`Quantity`+'$qts' WHERE `Iname`='$custo' AND `Status`='0' LIMIT 1");
$soso=mysqli_query($conn, "INSERT INTO `ccount` (`Number`, `Item`, `Qtin`, `Qton`, `Date`, `User`) VALUES (NULL, '$nuo', '$qtin', '$qts', '$Date', '$loge')");
		}


if(isset($_POST['resetall']))
		{
			$passkey=md5($_POST['passkey']);
$store=$_POST['store'];
$che=mysqli_query($conn, "SELECT *FROM `employees` WHERE `Password`='$passkey' AND `Access`='ADMINISTRATOR' LIMIT 1");
if($fe=mysqli_num_rows($che))
			$so=mysqli_query($conn, "UPDATE `citems` SET `Quantity`='0' WHERE `Iname`!='' AND `Status`>='0' AND `Quantity`!='0' LIMIT 1000");
else
$pto=3669;
		}

		
		if($custo){
			$conde="AND (`Iname` LIKE '%$custo%' OR `Descri` LIKE '%$custo%')";
		}
		else{
			$conde='';
		}

$do=mysqli_query($conn, "SELECT *FROM `citems` WHERE `Store`<='2' AND `Status`='0' $conde ORDER BY `Iname` ASC LIMIT 1400");
$fo=mysqli_num_rows($do);
?>
<div class="container-fluid main-content">
        <div class="page-title hidden-print">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Construction
          </h2>
                 </div>

<script>
$(document).ready(function(){
  var show_btn=$('.show-modal');
  var show_btn=$('.show-modal');
  //$("#testmodal").modal('show');
  
    show_btn.click(function(){
      $("#testmodal").modal('show');
  })
});

$(function() {
        $('#element').on('click', function( e ) {
            Custombox.open({
                target: '#testmodal-1',
                effect: 'fadein'
            });
            e.preventDefault();
        });
    });
</script>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">

   

    <li class="list-group-item active">
	  <a href="cmainsto.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Store Status
                </p>
              </a></li> 

	   <li class="list-group-item">
              <a href="ccrete.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create New Items
                </p>
              </a></li> 	
                  
			  <li class="list-group-item">
              <a href="creceive.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Receive Items
                </p>
              </a></li>
			  
			   <li class="list-group-item">
              <a href="ctaken.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Store Consumption
                </p>
              </a></li>	   
<?php
if($_SESSION['Spay']){
    ?>
			  <li class="list-group-item">
              <a href="cbillpay.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Supplier Payment
                </p>
              </a></li> 
              <?php
}

if($_SESSION['Phys']){
    ?>
			  
			   <li class="list-group-item">
              <a href="ccounting.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Inventories List
                </p>
              </a></li> <li class="list-group-item">
              <a href="cconfig.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Monthly Inventories
                </p>
              </a></li> 
                   <?php
}
?>
            </ul><br><br>
            <?php
if($_SESSION['Phys']){
    ?>
<center>
			<a href="ccount.php" class="btn btn-info" style="width:100%"><i class="lnr lnr-layers">&nbsp;Physical Count</i></a>
			</center><br>
			<?php
}
?>
  <div class="text-success text-center">This operation will increase or descrease quantity accordingly.</div>

  </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-2 hidden-print"> 					
					   
					   </div>
            <div class="col-lg-4 hidden-print"> 
      <input class="form-control"  name="custo" type="text" id="csearchs" autofocus="autofocus" required>
			</div>  

		 <div class="col-lg-2 hidden-print">
		 <input name='qts' class='form-control sm' type='text' style='text-align:center;' placeholder='Quantity'>
		 </div>
                    
                       
                       <div class="col-lg-2 hidden-print">
                        <button class="btn  btn-primary btn-block" type="submit" name="adjust"><i class="lnr lnr-checkmark-circle"></i> Adjust </button>
                   
					  </div>

<div class="col-lg-1">
                    
<div id="element" class="btn btn-danger show-modal"><i class="lnr lnr-cross-circle"></i> Reset All </div>
                   
					  </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">Reset 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'> CONSTRUCTION </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" style="width:90px;">Close</button>
                <button type="submit" name='resetall' class="btn btn-primary"  style="width:90px;">Reset All</button>
            </div>
        </div>
    </div>
</div>
</form>
             
			<div class="divFooter"><center><u><b> STORE COUNT 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" $fo " ?></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> Description </th>
						 <th> Cost 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>
                     </tr>
                    </thead>
                                        <tbody>
					<?php
					$n=1;		
						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);

				$stn="padding:1px;";

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

				$dox=mysqli_query($conn, "SELECT *FROM `cunit` 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($conn, "SELECT *FROM `cstouse` 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($conn, "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'> $descri </td>
                        <td style='$stn'><div align='right'> $costo </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></tr>");
						  $n++;
						}
						$toto=number_format($tot);			$tco=number_format($tco);
						?>
						
                    </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';
   ?>
