<?php
if(basename($_SERVER['PHP_SELF']) == 'cmainsto.php') 
  $cs=" class='current'";
include'header.php';
$_SESSION['Dato']="";
$custo='';
$conde='';
$l1=1;
$l2=40;
$lim=2;
$client=$condi='';

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['delo']))
		{
			$rowid=$_POST['rowid'];
			$custo=$_POST['custo'];
		$then=mysqli_query($conn, "UPDATE `citems` SET `Status`='1' WHERE `Number`='$rowid' LIMIT 1");
		}

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

	$lim=20;	
		if($custo){
			$conde="AND (`Iname` LIKE '%$custo%' OR `Descri` LIKE '%$custo%' OR `Ecode`='$custo')";
		}
		else{
			$conde='';
		}
		
		if($custo=='*'){
			$conde="";
			$lim=1200;
		}
		
		if($client){
			$conde="AND `Type` = '$client'";
			$lim=1200;
		}

		$do=mysqli_query($conn, "UPDATE `cstouse` SET `Ticked`='0' WHERE `Ticked`!='0'");

$do=mysqli_query($conn, "SELECT *FROM `citems` WHERE `Store`<='2' AND `Status`='0' $conde ORDER BY `Star` DESC LIMIT $lim");
$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>
     
        <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>	    
			  
			   <li class="list-group-item">
              <a href="crequit.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Requisition Forms
                </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
}
?>
                       
            </ul><br><br><br>
<center>
<?php
if($_SESSION['Phys']=='1')
echo"<a href='ccount.php' class='btn btn-info' style='width:100%'><i class='lnr lnr-layers'>&nbsp;Physical Count</i></a>";
?>
		</center><br>
  <div class="text-success text-center">Use <b>*</b> to display all items</div>
  </div>
                    
           
           
       
        <div class="col-lg-10">
                  <div class="row">
                      
                      <div class="col-lg-1 hidden-print"> </div>
         <form action="" method="post" class="form-horizontal" enctype="multipart/form-data" name='myform'>
           <div class="col-lg-2 hidden-print"> <select class="form-control" name="client"   id='category' onchange='submitForm();' required>
				<option value='' selected='selected'>Select Type</option>
			<?php
			$doi=mysqli_query($conn, "SELECT *FROM `citype` WHERE `Location`='0' AND `Type`!='' ORDER BY `Type` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$code=$roi['Number'];
				$fna=$roi['Type'];
				if($client==$code)
					$k='selected';
				else
					$k='';
			echo"<option value='$code' $k> $fna </option>";
			}
			?>   
                            </select> </div>
          
         </form><div class="col-lg-1 hidden-print"> </div>
           

        <form action="" method="post" class="form-horizontal ">                  
                       <div class="col-lg-8 hidden-print"><div class="col-lg-3"> 					
					   
					   </div>
            <div class="col-lg-6"> 
      <input class="form-control"  name="custo" type="text" id="csearchs" autofocus="autofocus" required>
			</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> 
                      
                     
                  
            </form> 
             
               
            </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">
			 <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>&nbsp;&nbsp;</span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">
               
            <table class="table table-striped table-hover">     
                    <thead><tr role="row">
        <th class="hidden-xs"> No </th><th> Item&nbsp;Type </th>
        <th> Item&nbsp;Name </th><th> Description </th>
		<th class='text-center'> Cost/Unit </th>
<th><div align='center'> Opening </th><th><div align='center'> Received </th>
		<th><div align='center'> Used/Out </th><th><div align='center'> Closing </th><th class="hidden-xs hidden-print">&nbsp;&nbsp;</th>
    <th class="hidden-xs" style="width:40px; text-align:center;" colspan='2'> Options </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);			
			$pri=$ro['Price'];			$prio=number_format($pri, 2);
			$qt=$ro['Quantity'];				$qty=number_format($qt, 2);
			
			$smin=$ro['Smin'];
			$sval=$ro['Svalue'];
			$bmin=$ro['Bvalue'];
			$bval=$ro['Bvalue'];

				$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 taken items
	$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' OR (`Action`='SALES' AND `Invoice`='MAIN STORE')) ORDER BY `Number` DESC");
		while($ror=mysqli_fetch_assoc($dor)){
						$act=$ror['Action'];
						$qts=$ror['Quantity'];
if($act=='RECEIVE')
	$rec+=$qts;

if($act=='TAKEN' OR $act=='SALES')
	$use+=$qts;
		}
         $rece=number_format($rec, 2);					$uses=number_format($use, 2);				$open=number_format($qt-$rec+$use, 2);

		 if($_SESSION['Cancel']){
			 $dbutn='submit';
			 $disa='';
		 }
		 else{
			 $dbutn='button';
			 $disa='disabled';
		 }
	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&nbsp;/&nbsp;$unit </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' class='hidden-xs hidden-print'>&nbsp;&nbsp;");
				
				
				
				
				echo"<div class='modal fade' id='exampleModal$n' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true' 
		style='top:220px;'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <h5 class='modal-title' id='exampleModalLabel'>DELETE CONFIRMATION 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $iname </h5>

      </div>
      <div class='modal-body' style='height:40px;'>
        <h5 style='color:#ff0033'>Are you sure you want to delete this item?</h5>
      </div><form method='post' action=''><input type='hidden' name='rowid' value='$code'><input type='hidden' name='custo' value='$custo'>
      <div class='modal-footer' style='margin-top:-10px; height:50px; padding-top:5px; border:0px solid blue;'>
        <button type='button' class='btn btn-sm btn-success' data-dismiss='modal'>&nbsp;NO&nbsp;</button>
        <button type='$dbutn' name='delo' class='btn btn-sm btn-danger' $disa>YES</button>
      </div></form>
    </div>
  </div>
</div>";



print("</td><form method=post action='ccrete.php'><td class='hidden-xs hidden-print' align='right' style='width:20px; padding:0px;'>
        <input type='hidden' name='rowid' value='$code'>
    <button type='submit' class='btn btn-xs btn-warning hidden-print' name='open' style='height:20px; padding:0px; margin-top:2px; margin-botton:2px;' title='Edit' data-toggle='tooltip' data-placement='top'>
						  &nbsp;&nbsp;<i class='lnr lnr-pencil'></i>&nbsp;&nbsp;</button></td></form>
						  
	<form method=post action=''><td class='hidden-xs hidden-print' align='right' style='width:20px; padding:0px;'>
	<div title='Delete' data-toggle='tooltip' data-placement='top'>
    <input type='hidden' name='rowid' value='$code'><input type='hidden' name='custo' value='$custo'>

	<button type='button' class='btn btn-xs btn-danger hidden-print' style='height:20px; padding:0px; margin-top:2px; margin-botton:2px;' data-placement='top' data-toggle='modal' data-target='#exampleModal$n' $disa>&nbsp;&nbsp;<i class='lnr lnr-trash'></i>&nbsp;&nbsp;</button></div></td></form></tr>");
						  $n++;
						}
						$toto=number_format($tot);			$tco=number_format($tco);
						?>
						
                    </tbody>
                  </table>

					 <div class="col-md-12"><hr>
                  <div class="pull-right">
                 <span class="pull-right hidden-print">
			 <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>&nbsp;&nbsp;</span>
              </div></div>

                  </div>                     
                
              </div>
            </div></div>
                  </div>
      
   </div></div></div>  
   <?php
   include'footer.php';
   ?>
