<?php
if(basename($_SERVER['PHP_SELF']) == 'requit.php') 
$fn=" class='current'";
include'header.php';
include'connection.php';
$dato=$datos=$Date;
$custo=$conde='';
$m=$vous=$p=0;

        // Search for result;
    if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$p=1;
		}



        // delete the whole requisition
    if(isset($_POST['delos']))
		{
			$rowid=$_POST['rowid'];
	$then=mysqli_query($conn, "DELETE FROM `stouse` WHERE `Voucher`='$rowid' AND `Action`='REQUISE' ORDER BY `Number` DESC LIMIT 100");
		}
		
		
		// delete the whole requisition
    if(isset($_POST['edits']))
		{
			$vous=$_POST['rowid'];
			$m=1;
		}


		            // create new requisition
			        if(isset($_POST['save_req']))
							{	
                                $ct=0;						
							$nx=$_POST['nx'];
							$vous=$_POST['vous'];
							$dato=$_POST['dato'];
							$coome=str_replace("'", "`", $_POST['coome']);
							$own=str_replace("'", "`", $_POST['own']);
							$phone=$_POST['phone'];
							$taker=$_POST['taker'];
		
					if(!$vous){
	  $rece=mysqli_query($conn, "SELECT `Voucher` FROM `stouse` WHERE `Voucher`!='0' AND `Action`='REQUISE' ORDER BY `Voucher` DESC LIMIT 1");
				$re=mysqli_fetch_assoc($rece);
					$vou=$re['Voucher']+1;
							}
					else{
					    $vou=$vous;
	$so=mysqli_query($conn, "DELETE FROM `stouse` WHERE `Status`='0' AND `Voucher`='$vou' AND `Action`='REQUISE'");
					}

			for($i=1; $i<=$nx; $i++){
				$qty=preg_replace('/,/', '', $_POST["qty$i"]);
				$pri=preg_replace('/,/', '', $_POST["pri$i"]);
				$ite=str_replace("'", "`", $_POST["ite$i"]);
	
	$see=mysqli_query($conn, "SELECT `Number`, `Quantity` FROM `items` WHERE `Item`='$ite'");
	if($fee=mysqli_num_rows($see)){
	    $ree=mysqli_fetch_assoc($see);
	    $ito=$ree['Number'];
	    $qtin=$ree['Quantity'];
	}
	else{
	    $then=mysqli_query($conn, "INSERT INTO `items` (`Type`, `Item`, `Price`, `Quantity`, `Label`, `Descri`, `Status`) VALUES ('Spare Part', '$ite', '$pri', '0', 'Variable Asset', '', '0')");
	    $ito=mysqli_insert_id($conn);
	    $qtin=0;
	}
							
				if($qty>0){
					$ct++;
	$so=mysqli_query($conn, "INSERT INTO `stouse` (`Date`, `Time`, `User`, `Item`, `Cost`, `Quantity`, `Price`, `Action`, `Destin`, `Voucher`, `Invoice`, `Status`, `Closing`, `Upda`, `Person`, `Comment`, `Otype`) VALUES ('$dato', '$Time', '$loge', '999999', '$pri', '$qty', '$pri', 'REQUISE', '$taker', '$vou', '$ite', '0', '$qtin', '0', '$own', '$coome', '$phone')");
								}
				
						}

					}
	
	
		
    // Delete the current chart
	if(isset($_POST['delox']))
		{
	$so=mysqli_query($conn, "DELETE FROM `stouse` WHERE `Status`='0' AND `Voucher`='0' AND `Action`='REQUISE' AND `User`='$loge'");
		}
		
		// approve a given requisition
    if(isset($_POST['approve']))
		{
			$k=$_POST['k'];
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			for($a=1; $a<=$k; $a++){
			    $nuo=$_POST["nuo$a"];
			    $appo=$_POST["appo$a"];
	$then=mysqli_query($conn, "UPDATE `stouse` SET `Approved`='$appo', `Approby`='$loge' WHERE `Number`='$nuo' AND `Action`='REQUISE' ORDER BY `Number` DESC LIMIT 1");
			}
		}
		
		
		$_SESSION['Lin']="requit.php";
		$_SESSION['Lim']="Requisition Forms";
?>
<div class="container-fluid main-content">
        <div class="page-title">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
        Materials
          </h2>
                 </div>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">

   

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

	   <li class="list-group-item">
              <a href="#" data-toggle='modal' data-target='#myModo'>
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create New Item
                </p>
              </a></li> 

	   <li class="list-group-item">
              <a href="repair.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Repair & Services
                </p>
              </a></li> 
                  
			  <li class="list-group-item active">
              <a href="requit.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Requisition Forms
                </p>
              </a></li> 
              
              <li class="list-group-item">
              <a href="#" data-toggle='modal' data-target='#myModos'>
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Store Consumption
                </p>
              </a></li>
              
            <?php
    if($_SESSION['Rsi']){
        ?>           
			  <li class="list-group-item">
              <a href="receive.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Receive Items
                </p>
              </a></li>
    <?php
    }
    ?>
         </ul><br><br> 
	

			<li class="list-group-item" style="border:1px dashed #cccccc; border-radius:5px; margin:0px 0px 4px 0px;">
	  <a href="createsu.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Create Suppliers
                </p>
              </a></li>	
  </div>
                    
      
              <?php
        // create a new requisition
        if(isset($_POST['new_req']))
		    $m=1;
	        ?>
       
        <div class="col-lg-10" style="margin-top:-20px;">
                  <div class="row hidden-print">
         <form action="" method="post" class="form-horizontal"> 
            <div class="col-md-1"> </div><div class="col-md-2"> 
            <?php
            if(!$m){
            ?>
      <button class="btn btn-info btn-block" type="submit" name="new_req"><i class="lnr lnr-layers"></i> &nbsp; CREATE NEW </button>
        <?php
        }
        else{
            if($vous){
if($_SESSION['Cancel'] OR $_SESSION['Eccr']){
$tags="#exampleModals";
$disa="";
}
else{
    $tags="#";
    $disa="disabled";
}
     echo"<div class='modal fade' id='exampleModals' 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 
    <label class='pull-right text-right'>$vous </label></h5>

      </div>
      <div class='modal-body' style='height:40px;'>
        <h5 style='color:#ff0033'>Are you sure you want to delete this requisition?</h5>
      </div><form method='post' action=''><input type='hidden' name='rowid' value='$vous'>
      <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='submit' name='delos' class='btn btn-sm btn-danger'>YES</button>
      </div></form>
    </div>
  </div>
</div>";
    echo"<button type='button' class='btn btn-block btn-danger hidden-print' name='delos' title='Delete this requisition' data-placement='top' style='font-size:12px;' data-toggle='modal' data-target='$tags' $disa><i class='lnr lnr-trash'></i> &nbsp; DELETE REQUISITION </button>";
        }
        }
        ?>
        </div>
        
            <div class="col-md-4"> </div><div class="col-lg-5">
            
            <div class="col-lg-4"> 
           <div class="input-group date" data-provide="datepicker">
      <input class="form-control form-center" name="dato" type="text" value="<?php echo $dato ?>" onkeypress="return isNumberKey(event)" style="padding-left:2px; padding-right:2px;" required><span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
			</div></div>


		  <div class="col-lg-4"> 
           <div class="input-group date" data-provide="datepicker">	
      <input class="form-control form-center" name="datos" type="text" value="<?php echo $datos ?>" onkeypress="return isNumberKey(event)" style="padding-left:2px; padding-right:2px;" required><span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
              </div></div>                      
                       
                       <div class="col-lg-3">
                        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
        
        
        
        <div class="col-md-1"> </div></form>
            </div>
                </div>
               <?php
        // create a new requisition
    if($m)
		{
	?>	    
	<hr><div class="row">
            <div class="col-lg-12">
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix"><div class="col-lg-12">
    <div class="col-lg-12"><br>
         <form action="" method="post" class="form-horizontal">
        <table class="table table-hover" style="border:1px solid #f9f9f9; border:0px; margin-top:-40px;"><thead>	   
		 <?php  
	echo"<tr><th width='5%' style='border:0px;'> &nbsp; </th>
		<th style='border:0px; padding-left:60px;' colspan='3'> ITEM NAME </th>
		<th width='15%' class='text-center' style='border:0px;'>  QUANTITY </th>
		<th width='15%' class='text-center' style='border:0px;'> PRICE </th>
		    </tr></thead><tbody>";

        $nx=1;                   $coome=$own=$phon=''; 
		$stl="style='border:0px; padding:2px 5px 2px 5px;'";	  
    $do=mysqli_query($conn, "SELECT *FROM `stouse` WHERE `Voucher`='$vous' AND `Action`='REQUISE' ORDER BY `Number` DESC");
            $fo=mysqli_num_rows($do);
		while($ro=mysqli_fetch_assoc($do)){
	$qto=number_format($ro['Quantity'], 2);
	$itom=$ro['Invoice'];
	$pct=number_format($ro['Price'], 2);
	$Date=$ro['Date'];
	$coome=$ro['Comment'];
	$taker=$ro['Destin'];
	$phone=$ro['Otype'];
	$own=$ro['Person'];
	$l=5;

print("<tr title='$itom'><td $stl><div align='center'> $nx </td>
<td colspan='3' $stl><div align='left'><input type='text' class='form-control' name='ite$nx' style='border:1px solid teal; height:26px;' value='$itom' list='ites' autocomplete='off'><datalist style='border:1px solid blue;' id='ites'>");
		
$doi=mysqli_query($conn, "SELECT `Item` FROM `items` UNION DISTINCT SELECT `Invoice` AS `Item` FROM `stouse` WHERE (`Action`='REQUISE' AND `Date`>='$dase') GROUP BY `Item` ORDER BY `Item` ASC");
		while($roi=mysqli_fetch_assoc($doi)){
			$iname=$roi['Item'];
	echo"<option value='$iname'></option>";
		}
		
					echo("</datalist></div></td>
<td $stl><INPUT TYPE=hidden NAME='nx' VALUE='$nx'><input type='text' class='form-control text-right' name='qty$nx' style='text-align:right; background-color:Transparent; height:26px;' onkeypress='return isNumberKey(event)' onkeyup='format(this);' value='$qto'></td>
<td $stl><div align='right'><input type='text' class='form-control text-right' name='pri$nx' style='background-color:Transparent; height:26px;' onkeypress='return isNumberKey(event)' onkeyup='format(this);' value='$pct'></td></tr>");	
					$nx++;

		}
			   
			   if(($nx+$l)<11)
			        $l=11-$nx;
		
    	for($k=1; $k<=$l; $k++){		
	print("<tr title='$itom'><td $stl><div align='center'> $nx </td>
	<td colspan='3' $stl><input type='text' name='ite$nx' class='form-control' style='background-color:Transparent; height:26px;' list='ites' maxlenght='60' autocomplete='off'><datalist style='border:1px solid blue;' id='ites'>");
		
$doi=mysqli_query($conn, "SELECT `Item` FROM `items` UNION DISTINCT SELECT `Invoice` AS `Item` FROM `stouse` WHERE (`Action`='REQUISE' AND `Date`>='$dase') GROUP BY `Item` ORDER BY `Item` ASC");
		while($roi=mysqli_fetch_assoc($doi)){
			$iname=$roi['Item'];
	echo"<option value='$iname'></option>";
		}
		
					echo("</datalist></div></td>
	
    <td $stl><INPUT TYPE=hidden NAME='nx' VALUE='$nx'><input type='text' name='qty$nx' class='form-control text-right' style='background-color:Transparent; height:26px;' onkeypress='return isNumberKey(event)' onkeyup='format(this);'></td>
    
    <td $stl><div align='right'><input type='text' class='form-control text-right' name='pri$nx' style='background-color:Transparent; height:26px;' onkeypress='return isNumberKey(event)' onkeyup='format(this);'></td></tr>");	
					$nx++;
		}
	
	if($fo)
	$bt="UPDATE";
	else
	$bt="SAVE";
	print("</tbody><thead><tr style='height:20px;'>
	<td colspan='6' style='border:0px;'> <hr> </td></tr>
	
	
	<tr>
	<td align='right' style='border:0px;' colspan='2' width='10%'><b> Contact </b></td>
	
	<td style='border:0px;' colspan='2'><input type='text' name='own' class='form-control' style='background-color:Transparent; height:36px;' value='$own' placeholder='Requested By (Fullname Here)' required></td>
	
	<td colspan='2' style='border:0px;'><input type='text' name='phone' class='form-control' style='text-align:center; background-color:Transparent; height:36px;' value='$phone' placeholder='Telephone'></td></tr>
	
	<tr><td align='right' style='border:0px;' colspan='2' width='10%'><b> Purpose </b></td>
	<td colspan='4' style='border:0px;' colspan='2'><input type='text' class='form-control' name='coome' style='background-color:Transparent; height:36px;' value='$coome' title='Write Comment here' placeholder='Write Comment Here'></td></tr>


    <tr><td colspan='2' style='border:0px;'> </td><td style='border:0px;'>
    <select name='taker' class='form-control' style='width:80%;' required>
        <option value=''> SELECT A SUPPLIER </option>");
 
    $top=mysqli_query($conn, "SELECT `Supplier` FROM `suppliers` WHERE `Status`='2' AND `Supplier`!='' GROUP BY `Supplier` ORDER BY `Supplier` ASC LIMIT 2000");
				while($rop=mysqli_fetch_assoc($top)){
							$sup=$rop['Supplier'];
				if($taker==$sup)
					$t='selected';
				else
					$t='';
			echo"<option value='$sup' $t> $sup </option>";
						}
					
    print("</select></td>
    <td style='border:0px;'><div align='right'><b>
    	Due Date &nbsp;&nbsp; </td><td style='border:0px;' colspan='2'><center> 
        <input type='text' name='dato' class='form-control date' data-provide='datepicker' style='text-align:center; background-color:Transparent; height:36px;' value='$Date' title='Due date' onkeypress='return isNumberKey(event)'></td></tr></thead></table>");   
		   
		 
		 
   echo"<div class='form-group'>
  <div class='col-md-1'></div>
  <div class='col-md-10'><INPUT TYPE=hidden NAME='vous' VALUE='$vous'><br><br>  
    <button class='btn btn-lg btn-block btn-primary' type='submit' name='save_req'><i class='lnr lnr-chevron-up-circle'></i> $bt </button>
    <br><br><br></div><div class='col-md-1'></div></div><br><br><br></form>";  
		    
    		    
		}
		else{
		    if($p)
		$dor=mysqli_query($conn, "SELECT `stouse`.*, SUM(`Approved`) AS `Appro`, SUM(`Quantity`*`Price`) AS 'Tot', SUM(`Approved`*`Price`) AS 'Top', COUNT(DISTINCT(`Invoice`)) AS 'Ite', COUNT(DISTINCT(`Item`)) AS 'Ites' FROM `stouse` WHERE `Date` BETWEEN '$dato' AND '$datos' AND `Status`='0' AND `Voucher`!='0' AND `Action`='REQUISE' GROUP BY `Voucher` ORDER BY `Number` DESC LIMIT 1500");
		    else
		$dor=mysqli_query($conn, "SELECT `stouse`.*, SUM(`Approved`) AS `Appro`, SUM(`Quantity`*`Price`) AS 'Tot', SUM(`Approved`*`Price`) AS 'Top', COUNT(DISTINCT(`Invoice`)) AS 'Ite', COUNT(DISTINCT(`Item`)) AS 'Ites' FROM `stouse` WHERE `Status`='0' AND `Voucher`!='0' AND `Action`='REQUISE' GROUP BY `Voucher` ORDER BY `Number` DESC LIMIT 15");
				if($for=mysqli_num_rows($dor)){
?>
 <div class="row">
            <div class="col-lg-12" style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $for " ?></b></span> <span class="pull-right hidden-print"><?php echo $bra ?>&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 table-hover">     
                                      <thead>
                    <tr role="row">
                     <th class="hidden-xs"> No </th>
                       <th class='text-center'> Due&nbsp;Date </th>
                        <th> System&nbsp;User </th>
                       <th> Supplier </th><th> Items </th>
	<th class='text-right'>Total&nbsp;Amount&nbsp;&nbsp;&nbsp;&nbsp;</th>
	<th width='14%' class='text-right'>Approved&nbsp;Amount</th>
	<th width='14%' class='text-right' colspan='2'>Total&nbsp;Balance</th>
    <th width='14%' class="hidden-xs hidden-print" style="width:40px; text-align:center;" colspan='4'> Options </th></tr>
                    </thead>
                                        <tbody>
										<?php
	$n=1;			$tol=0;            
					while($ror=mysqli_fetch_assoc($dor)){
						$code=$ror['Voucher'];
						$date=$ror['Date'];
						$user=$ror['User'];
						$dest=$ror['Destin'];
						$tot=$ror['Tot'];
						$top=$ror['Top'];
						$bal=$tot-$top;
						if($ror['Ite']>$ror['Ites'])
						    $ite=$ror['Ite'];
						else
						    $ite=$ror['Ites'];
						$des=$ror['Destin'];
						$appo=$ror['Appro']; 
						$idso=$dso="";
						
						if($appo){
						    $idso="disabled";
							$stl="style='padding:1px;'";
						}
						else{
                            $dso="disabled";
						    $stl="style='padding:1px; color:red'";
						}
					
	$toto=number_format($tot, 2);               $topo=number_format($top, 2);
	$balo=number_format($bal, 2);
	
	print("<tr><td $stl class=hidden-xs><div align='center'>$code&nbsp;&nbsp;</td>
		<td class='text-center' $stl> $date </td><td $stl> $user </td>
		<td $stl> $des </td><td class='text-center' $stl> $ite </td>
		<td $stl><div align='right'> $toto &nbsp;</td>
		<td $stl><div align='right'> $topo &nbsp;</td>
		<td $stl><div align='right'> $balo &nbsp;</td><td width='1%' $stl>");
						
	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' style='color:#000000;'>
        <h5 class='modal-title' id='exampleModalLabel'>DELETE CONFIRMATION 
        <label class='pull-right text-right'> $des: $toto </h5>

      </div>
      <div class='modal-body' style='height:40px; color:#000000;'>
        <h5 style='color:#ff0033'>Are you sure you want to delete this requisition?</h5>
      </div><form method='post' action=''>
      <input type='hidden' name='rowid' value='$code'>
      <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='delos' class='btn btn-sm btn-danger'>YES</button>
      </div></form>
    </div>
  </div>
</div>";


	echo"<div class='modal fade' id='eModal$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' style='color:#000000;'>
        <h5 class='modal-title' id='exampleModalLabel'>EDIT CONFIRMATION 
        <label class='pull-right text-right'> $des: $toto </h5>

      </div>
      <div class='modal-body' style='height:40px; color:#000000;'>
        <h5 style='color:#ff0033'>Are you sure you want to edit this requisition?</h5>
      </div><form method='post' action=''>
      <input type='hidden' name='rowid' value='$code'>
      <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='submit' name='edits' class='btn btn-sm btn-danger' $idso>YES</button>
      </div></form>
    </div>
  </div>
</div>";


	echo"<div class='modal fade' id='Modalp$n' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'><div class='modal-header' style='color:#000000;'>
        <h5 class='modal-title' id='exampleModalLabel'>APPROVAL PROCESS 
        <label class='pull-right text-right'> $des: $toto </h5>

      </div><form method='post' action=''>
      <div class='modal-body' style='height:auto; color:#000000;'>
      <table class='table table-striped table-hover'>     
            <thead><tr role='row'>
        <th width='3%' style='padding:1px; text-align:center;'> No </th>
        <th style='padding:1px; text-align:center'> Item Name </th>
        <th style='padding:1px; text-align:center'> Store </th>
        <th style='padding:1px; text-align:center; color:blue;'> Quantity </th>
        <th style='padding:1px; text-align:center'> Price/Unit </th>
        <th width='10%' style='padding:1px; text-align:center'> Approved </th>
            </tr></thead><tbody>";
        
              $k=1;               
    $st="style='padding:0px; color:#000000; background-color:transparent; font-size:13px;'"; 
    $stl="style='padding:0px; color:blue; background-color:transparent; font-size:13px;'";
        $one=mysqli_query($conn, "SELECT `Number`, `Invoice`, `Quantity`, `Price`, `Approved`, `Closing` FROM `stouse` WHERE `Action`='REQUISE' AND `Voucher`='$code' ORDER BY `Number` ASC");
        while($rone=mysqli_fetch_assoc($one)){
            $nuo=$rone['Number'];
            $itz=$rone['Invoice'];
    $seu=mysqli_query($conn, "SELECT `Unit` FROM `items` WHERE `Item`='$itz' ORDER BY `Number` DESC LIMIT 1");
    if($feu=mysqli_num_rows($seu)){
    $reu=mysqli_fetch_assoc($seu);
            $uni=$reu['Unit'];
    }
    else
        $uni="&nbsp;&nbsp;&nbsp;&nbsp;";
            $clo=number_format($rone['Closing'], 2);
            $qtz=number_format($rone['Quantity'], 2);
            $prz=number_format($rone['Price'], 2);
            $apz=number_format($rone['Approved'], 2);
            if(!$rone['Approved'])
                $apz='';
                
            if($_SESSION['PMS'])
                $idso="";
       echo"<tr><td class='text-right' $st> $k &nbsp;</td><td $st> $itz </td>
       <td class='text-right' $st> $clo </td><td class='text-right' $stl> $qtz&nbsp;$uni </td><td class='text-right' $st> $prz &nbsp;&nbsp;</td><td class='text-center' $st> <input class='form-control form-center' name='appo$k' type='text' style='padding:1px; height:20px; width:90px;' value='$apz' ondblclick=this.value='$qtz' autocomplete='off' $diso><input type='hidden' name='k' value='$k'><input type='hidden' name='nuo$k' value='$nuo'></td></tr>"; 
            $k++;
        }
      
      echo"</tbody></table></div>
      <div class='modal-header text-right' style='margin-top:-10px; height:50px; padding-top:10px; border:0px solid blue;'><input type='hidden' name='dato' value='$dato'><input type='hidden' name='datos' value='$datos'><button type='button' class='btn btn-sm btn-danger' data-dismiss='modal' style='width:80px;'> CANCEL </button>
        <button type='submit' name='approve' class='btn btn-sm btn-success' style='width:80px;' $diso> SAVE </button>
        </div></form>
            </div>
        </div>
    </div>";

			
if($_SESSION['Cancel'] OR $_SESSION['Eccr']){
$tags="#exampleModal$n";
$disa="";
}
else{
    $tags="#";
    $disa="disabled";
}

		print("</td><td class='hidden-xs hidden-print' align='right' style='width:10px; padding:0px;'><button type='button' class='btn btn-xs btn-danger hidden-print' style='height:24px; padding:0px; margin:2px;' title='Delete' data-toggle='modal' data-target='$tags' $disa>&nbsp;&nbsp;<i class='lnr lnr-trash'></i>&nbsp;&nbsp;</button></td>
						
		<td class='hidden-xs hidden-print' align='right' style='width:10px; padding:0px;'><button type='button' class='btn btn-xs btn-warning hidden-print'  style='height:24px; padding:0px; margin:2px;' title='Edit' data-toggle='modal' data-target='#eModal$n' $idso>&nbsp;&nbsp;<i class='lnr lnr-pencil'></i>&nbsp;&nbsp;</button></td>
						  
		<td class='hidden-xs hidden-print' align='right' style='width:10px; padding:0px;'><button type='button' class='btn btn-xs btn-info hidden-print' style='height:24px; padding:0px; margin:2px;' title='Approve' data-toggle='modal' data-target='#Modalp$n' $disa>&nbsp;&nbsp;<i class='lnr lnr-history'></i>&nbsp;&nbsp;</button></td>
						  
		<form action='purder.php' method='post'><td class='hidden-xs hidden-print' align='right' style='width:10px; padding:0px;'>
                <input type='hidden' name='rowid' value='$code'>
                <input type='hidden' name='date' value='$date'>
				<input type='hidden' name='dest' value='$dest'>
				<input type='hidden' name='p' value='0'>
				<input type='hidden' name='user' value='$user'>
					<input type='hidden' name='pago' value='requit.php'>
				<button type='submit' class='btn btn-xs btn-success hidden-print' name='opens' style='height:24px; padding:0px; margin:2px;' title='Open' data-toggle='tooltip' data-placement='top' $dso>&nbsp;&nbsp;<i class='lnr lnr-download'></i>&nbsp;&nbsp;</button></td></form></tr>");
						  $n++;				$tol+=$tot;
						}
					$toto=number_format($tol, 2);
						$tos="0.00";
						?>
						
                    </tbody>

					 <thead>
					<tr><th class="hidden-xs"> </th><th colspan='3'><div align='center'> Grand Total </th>
					<th colspan='2'><div align='right'><?php echo $toto ?>&nbsp;&nbsp;&nbsp;</th>
					<th><div align='right'><?php echo $tos ?>&nbsp;&nbsp;&nbsp;</th>
					<th colspan='2'><div align='right'><?php echo $toto ?>&nbsp;&nbsp;&nbsp;</th>
					<th colspan='4' class="hidden-print"><div align='center'> -- </th></tr>
                  </table><br><br>
                    
                        </div></div>
                  
                  <span class="pull-right hidden-print"><?php echo $bra ?>&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><br><br>

				  <?php




				}
				else
						echo"<div class='row'>
            <div class='col-lg-12' style='margin-top:-20px;'>
          <span class='pull-right hidden-print'> $bra &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'>
			<br><br><br><br><br><br>
	<div style='text-align:center; font-size:24px; color:#ff9999'> Report not available on selected date </div><br><br><br><br><br><br><br>";
					}
			
			
					?>
                                      
                
              </div>
            </div></div>
                  </div>

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