<?php
if(basename($_SERVER['PHP_SELF']) == 'requis.php') 
  $kk=" class='current'";
include'connection.php';
 
$custo='';
$conde='';
$t=$p=0;

  // print requesition voucher
if(isset($_POST['repri']))
		{
		$vous=$_POST['vous'];
		$des=$_POST['des'];
		$dte=$_POST['dte'];
			$requi=1;
    include'creceipt.php';
			$t=$p=1;
		    }
		
include'header.php';

// delete an item from a given chart
if(isset($_POST['delo']))
		{
			$rowid=$_POST['rowid'];
			$vous=$_POST['vous'];
			$item=$_POST['item'];
			$vous=$_POST['vous'];
			$des=$_SESSION['Deso'];
			$dte=$_POST['dte'];
$then=mysqli_query($cons, "UPDATE `requis` SET `Status`='1' WHERE `Item`='$item' AND `Voucher`='$vous' AND `Production`!='PRODUCTION B' AND `Destin`='$des' LIMIT 1000");
			$t=$p=1;
		}

// edit an item from a given chart
if(isset($_POST['edit']))
		{
			$rowid=$_POST['rowid'];
			$qty=$_POST['qty'];
			$rqty=$_POST['rqty'];
			$item=$_POST['item'];
			$vous=$_POST['vous'];
			$dte=$_POST['dte'];
			$des=$_SESSION['Deso'];
				$qty=str_replace(',', '', $qty);
			$then=mysqli_query($cons, "UPDATE `requis` SET `Quantity`='$qty', `Requested`='$rqty', `Changed`='1', `Control`='1' WHERE `Number`='$rowid' LIMIT 1");
	$then=mysqli_query($cons, "UPDATE `requis` SET `Quantity`='0', `Changed`='1' WHERE `Number`!='$rowid' AND `Item`='$item' AND `Voucher`='$vous' AND `Production`!='PRODUCTION B' AND `Destin`='$des' LIMIT 1000");
			$t=$p=1;
		}

// search for an item to be added to the chart
if(isset($_POST['search']))
		{
			$custo=$_POST['custo'];
			$vous=$_POST['vous'];
			$p=1;
			$t=2;
		}

// open for a given requisition to mark as taken
if(isset($_POST['open']))
		{
			$vous=$_POST['vous'];
			$des=$_POST['des'];
			$dte=$_POST['dte'];
			$t=$p=1;
		}

		// delete an item from a given chart
if(isset($_POST['deloq']))
		{
			$vous=$_POST['vous'];
			$des=$_POST['des'];
	$then=mysqli_query($cons, "UPDATE `requis` SET `Status`='1' WHERE `Voucher`='$vous' AND `Destin`='$des' AND `Production`!='PRODUCTION B' LIMIT 1000");			
			$pros=$_POST['pros'];
	$and=mysqli_query($cons, "UPDATE `stouse` SET `Status`='1' WHERE `Voucher`='$pros' AND `Action`='PRODUCE' AND `Destin`='$des' LIMIT 1000");
		}



if(isset($_POST['locked']))
		{
			$vous=$_POST['vous'];
			$des=$_POST['des'];
			$locki=$_POST['locki'];
	$then=mysqli_query($cons, "UPDATE `requis` SET `Locked`='$locki' WHERE `Voucher`='$vous' AND `Destin`='$des' AND `Production`!='PRODUCTION B' LIMIT 1000");	
		}

		// Add found item to the chart
		if(isset($_POST['addo']))
		{
			$n=$_POST['n'];
			$vous=$_POST['vous'];
			$dest=$_SESSION['Deso'];
			$des=$_SESSION['Deso'];
			$dte=$_SESSION['Dto'];
			while($n>0){
				$item=$_POST["item$n"];
				$qty=$_POST["qty$n"];
				$pri=$_POST["pri$n"];
				$cost=$_POST["cost$n"];
				$prod=$_POST["prod$n"];
				$dire=$_POST["dire$n"];
				if($qty)
		$so=mysqli_query($cons, "INSERT INTO `requis` (`Number`, `Date`, `User`, `Item`, `Cost`, `Quantity`, `Price`, `Action`, `Destin`, `Voucher`, `Status`, `Direct`, `Production`) VALUES (NULL, '$dte', '$loge', '$item', '$cost', '$qty', '$pri', 'INTERNAL', '$dest', '$vous', '0', '$dire', '$prod')");
			$n--;
			}
			$t=$p=1;
		}

$rece=mysqli_query($cons, "SELECT `Voucher` FROM `stouse` WHERE `Voucher`!='0' ORDER BY `Voucher` DESC LIMIT 1");
				$re=mysqli_fetch_assoc($rece);
					$vou=$re['Voucher']+1;
					
	// Take a given requisition from main store ***********************************************
	if(isset($_POST['takere']) AND ($_POST['form_token'] == $_SESSION['form_token']))
		{
			$vous=$_POST['vous'];
			$taker=$_POST['taker'];
			$dato=$_POST['dato'];
			$des=$_POST['des'];

		$rece=mysqli_query($cons, "SELECT `Voucher` FROM `stouse` WHERE `Voucher`!='0' ORDER BY `Voucher` DESC LIMIT 1");
				$re=mysqli_fetch_assoc($rece);
					$vou=$re['Voucher']+1;

	$do=mysqli_query($cons, "SELECT *, SUM(Quantity) AS 'QTS' FROM `requis` WHERE `Voucher`='$vous' AND `Status`='0' AND `Destin`='$des' GROUP BY `Item` ORDER BY `Number` ASC");
			while($ro=mysqli_fetch_assoc($do)){
				$code=$ro['Number'];
				$item=$ro['Item'];
				$qty=$ro['QTS'];
				$pri=$ro['Price'];
				$cost=$ro['Price'];
				$des=$ro['Destin'];
				$pro=$ro['Produce'];

				if($qty){
	$so=mysqli_query($cons, "INSERT INTO `stouse` (`Number`, `Date`, `User`, `Item`, `Cost`, `Quantity`, `Price`, `Action`, `Destin`, `Voucher`, `Status`, `Person`, `Requis`,	`Produce`, `Upda`) VALUES (NULL, '$dato', '$loge', '$item', '$cost', '$qty', '$pri', 'TAKEN', '$des', '$vou', '0', '$taker', '$vous', '$pro', '1')");
		
$soso=mysqli_query($cons, "UPDATE `items` SET `Quantity`=`Quantity`-'$qty', `Star`=`Star`+'1' WHERE `Number`='$item' ORDER BY `Number` ASC LIMIT 1");
                }

$then=mysqli_query($cons, "UPDATE `requis` SET `Upda`='1' WHERE `Item`='$item' AND `Voucher`='$vous' AND `Destin`='$des' ORDER BY `Number` ASC LIMIT 1000");
			}
		}

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

		if($p=='1'){
			$btn="submit";
			$rdn="";
		}
		else{
			$btn="button";
			$rdn="readonly='readonly'";
		}	
?>
<div class="container-fluid main-content">
        <div class="page-title">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
        Production
          </h2>
                 </div>
     
        <div class="row"> 
  <div class="col-lg-2 hidden-print">
   
   <ul class="list-group">

	 <li class="list-group-item">
	  <a href="mpro.php">
                <p>
                <i class="lnr lnr-plus-circle"></i>&nbsp;Make a Production
                </p>
              </a></li> 

	 <li class="list-group-item">
	  <a href="iconfig.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Item Configuration
                </p>
              </a></li> 

    <li class="list-group-item">
	  <a href="oper.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Receive Item
				<?php
				if($pfequo)
					echo"<span class='badge' style='float:right; font-size:12px; margin-right:0px; margin-top:0px; height:18px; background-color:#5CF7CE; width:auto;'> $pfequo </span>";
					?>
                </p>
              </a></li> 

	   <li class="list-group-item active">
              <a href="requis.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Requisitions
				<?php
				if($fequo)
					echo"<span class='badge' style='float:right; font-size:12px; margin-right:0px; margin-top:0px; height:18px; background-color:#ff66cc; width:auto;'> $fequo </span>";
					?>
                </p>
              </a></li>
                       
            </ul>
  </div>
                    
           
           
       
        <div class="col-lg-10">
                  <div class="row">
         
           <div class="col-lg-4"> </div>
          
         
           

        <form action="" method="post" class="form-horizontal ">                  
                       <div class="col-lg-8 no-print"><div class="col-lg-3"> 					
					   
					   </div>
            <div class="col-lg-6"> 
      <input class="form-control" name="custo" type="text" id="searchu" <?php echo $rdn ?> required>
	  <?php
		echo"<input type='hidden' name='vous' value='$vous'>";
		?>
			</div>                      
                       
                       <div class="col-lg-2">
                        <button class="btn  btn-primary btn-block" type="<?php echo $btn ?>" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div> 
                      
                     
                  
            </form> 
             
               
            </div>
               <?php




















			    if($t==2){
		$do=mysqli_query($cons, "SELECT *FROM `items` WHERE `Store`<='2' AND `Status`='0' $conde ORDER BY `Number` DESC LIMIT $lim");
				if($fo=mysqli_num_rows($do)){
				   ?>
                 
             <div class="row">
            <div class="col-lg-12" style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fo " ?></b></span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">

								 <form action="" method="post" class="form-horizontal "> 
				<table class="table table-striped">     
                                      <thead>
                    <tr role="row">
                     <th class="hidden-xs"> No </th>
                       <th> Item&nbsp;Name </th>
                        <th> Description </th>
                       <th> Item&nbsp;Type </th>
                       <th>&nbsp;&nbsp;Qty&nbsp;In&nbsp;&nbsp;</th>
                       <th> Count&nbsp;Unit </th>
						 <th> Cost&nbsp;Price </th>
                        <th><div align='center'> Quantity </th>
						<th class="hidden-xs hidden-print">Total&nbsp;Amount</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);
			$prod=$ro['Production'];
			$dire=$ro['Direct'];
			$store=$ro['Store'];
if($store=='2')			
			$cost=$ro['Price'];	
else			
			$cost=$ro['Cost'];

$costo=number_format($cost, 2);	

$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'];
          $b=$n*10;
		print("<tr>
                        <td class=hidden-xs><div align='center'>$n&nbsp;&nbsp;</td>
						<td> $iname </td><td> $descri </td><td> $type </td><td><div align='right'> $qty </td><td> $unit </td>
						<td><input name='pri$n' class='form-control' type='text' onkeyup='multiplyBy$n();' onkeypress='return isNumberKey(event)' 
						style='text-align:right; width:130px; height:24px;' id='box$b' value='$cost'></td>
						<td><input name='qty$n' class='form-control' type='text' onkeyup='multiplyBy$n();' onkeypress='return isNumberKey(event)' style='text-align:right; width:120px; height:24px; margin:0px 0px 0px 0px' id='box$n'></td>
						<td class='hidden-xs hidden-print' width='10%'><div align='right' style='border:1px solid #cccccc; width:120px; height:24px; border-radius:5px; padding:0px 10px 0px 0px;'><input type='hidden' name='item$n' value='$code'>
<input type='hidden' name='dire$n' value='$dire'><input type='hidden' name='prod$n' value='$prod'>
						<span class='dollars' style='text-align:right; width:130px; height:24px; font-size:18px; color:#66cccc; float:center; text-align:right;' id='result$n' onchange='format(this);'></span></div><input type='hidden' name='cost$n' value='$cost'></td></tr>");
						  $n++;
						}
						$toto=number_format($tot);			$tco=number_format($tco);
						?>
						
                    </tbody>
                  </table>

				   <div class="row"><br>
                  <div class="col-lg-10"><hr></div><div class="col-lg-2">
                 <?php echo"<input type='hidden' name='n' value='$n'><input type='hidden' name='vous' value='$vous'>"; ?>
                 <button class="btn btn-sm btn-block btn-primary hidden-print" type="submit" name="addo" style="margin:0px 0px 0px -15px;">
				 <i class="lnr lnr-plus-circle"></i> Add to Cart </button>
              </div></div></form>
				  <?php
				}

else{
						echo"<div class='row'>
            <div class='col-lg-12' style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Store Voucher No : <b> $vou </b></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:#ff3333'> Item not found found for your search [$custo] </div><br><br><br><br><br><br><br>";
					}  
			}















			   elseif($t==0){
		$do=mysqli_query($cons, "SELECT *FROM `requis` WHERE `Voucher`!='0' AND `Status`='0' AND `Upda`='0' AND `Production`!='PRODUCTION B' GROUP BY `Destin`, `Voucher` ORDER BY `Voucher` ASC LIMIT 40");
				if($fo=mysqli_num_rows($do)){
				   ?>
                 
             <div class="row">
            <div class="col-lg-12" style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fo " ?></b></span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">

								 <form action="" method="post" class="form-horizontal "> 
				<table class="table table-striped">     
                                      <thead>
                    <tr role="row">
                     <th class="hidden-xs"> No </th>
                       <th> Voucher&nbsp;No </th>
                       <th> Done&nbsp;By </th>
                       <th> Due&nbsp;Date </th>	
                        <th> Source </th>
                        <th> Destination </th>
                       <th> Items </th>
						<th><div align='right'>Total&nbsp;Amount&nbsp;&nbsp;&nbsp;&nbsp;</th>
                        <th class="hidden-xs hidden-print" style="width:40px; text-align:center;" colspan='3'> Options </th>
                     </tr>
                    </thead>
                                        <tbody>
					<?php
					$n=1;		
						while($ro=mysqli_fetch_assoc($do)){
				$vou=$ro['Voucher'];
				$dte=$ro['Date'];
				$des=$ro['Destin'];
				$user=$ro['User'];
				$dire=$ro['Direct'];
                $locked=$ro['Locked'];
					$sour="MAIN STORE";
					
				$to=0;
$dor=mysqli_query($cons, "SELECT `Price`, `Produce`, SUM(Quantity) AS 'QTO' FROM `requis` WHERE `Status`='0' AND `Upda`='0' AND `Voucher`='$vou' AND `Destin`='$des' AND `Production`!='PRODUCTION B' GROUP BY `Item` ORDER BY `Number` ASC");
			$for=mysqli_num_rows($dor);
				while($ror=mysqli_fetch_assoc($dor)){
				$pri=$ror['Price'];
				$qty=$ror['QTO'];
				$pro=$ror['Produce'];
			$to+=$pri*$qty;
				}			
						$too=number_format($to, 2);
						$_SESSION['Deso']='';

if($_SESSION['Cancel']=='1')
$btx='submit';
else
$btx='button';

if($_SESSION['Lock']=='1')
$btxi='submit';
else
$btxi='button';

$doti=mysqli_query($cons, "SELECT *FROM `production` WHERE `Convert`='$des' ORDER BY `Number` ASC");
if($foti=mysqli_num_rows($doti)){
	$roti=mysqli_fetch_assoc($doti);
		$deso=$roti['Name'];
}
else
$deso=$des;

if($locked=='1'){
$lc="<i class='lnr lnr-lock' style='color: red;'></i>";
$lh="<input type='hidden' name='locki' value='0'>";
}
else{
$lc='';
$lh="<input type='hidden' name='locki' value='1'>";
}

		print("<tr><td class=hidden-xs><div align='center'>$n&nbsp;&nbsp;</td>
<td><div align='right' style='padding-right:30px;'> $lc $vou </td><td> $user </td>
						<td> $dte </td><td> $deso </td><td> $sour </td><td> &nbsp;&nbsp; $for </td>
<td><div align='right'> $too &nbsp;&nbsp; </td>

				<form method=post action=''><td class='hidden-xs hidden-print' align='right' style='width:40px; padding:0px;'>
                              <input type='hidden' name='vous' value='$vou'> <input type='hidden' name='dte' value='$dte'>
				<input type='hidden' name='des' value='$des'>
                          <button type='submit' class='btn btn-xs btn-success hidden-print' name='open' style='height:18px; padding:0px; margin:0px;'>
						  &nbsp;&nbsp;<i class='lnr lnr-download'></i>&nbsp;&nbsp;</button></td></form>



 <form method=post action=''><td class='hidden-xs hidden-print' align='right' style='width:40px; padding:0px;'> $lh
                              <input type='hidden' name='vous' value='$vou'><input type='hidden' name='pros' value='$pro'>
				<input type='hidden' name='des' value='$des'><input type='hidden' name='dte' value='$dte'>
                          <button type='$btxi' class='btn btn-xs btn-warning hidden-print' name='locked' style='height:18px; padding:0px; margin:0px;'>
						  &nbsp;&nbsp;<i class='lnr lnr-lock'></i>&nbsp;&nbsp;</button></td></form>


						  
						  <form method=post action=''><td class='hidden-xs hidden-print' align='right' style='width:40px; padding:0px;'>
                              <input type='hidden' name='vous' value='$vou'><input type='hidden' name='pros' value='$pro'>
				<input type='hidden' name='des' value='$des'><input type='hidden' name='dte' value='$dte'>
                          <button type='$btx' class='btn btn-xs btn-danger hidden-print' name='deloq' style='height:18px; padding:0px; margin:0px;'>
						  &nbsp;&nbsp;<i class='lnr lnr-trash'></i>&nbsp;&nbsp;</button></td></form></tr>");
						  $n++;
						}
						$toto=number_format($tot);			$tco=number_format($tco);
						?>
						
                    </tbody>
                  </table>

				  
				  <?php
				}
				 else{
						echo"<div class='row'>
            <div class='col-lg-12' style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Requisition Voucher No : <b> $vou </b></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:#ff3333'> There is no pedding requisition </div><br><br><br><br><br><br><br>";
					}  
			}
				   else{
		$dor=mysqli_query($cons, "SELECT *, SUM(Quantity) AS 'QTY', SUM(Requested) AS 'RQTY' FROM `requis` WHERE `Status`='0' AND `Voucher`='$vous' AND `Action`='INTERNAL' AND `Upda`='0' AND `Destin`='$des' AND `Production`!='PRODUCTION B' AND `Date`='$dte' GROUP BY `Item` ORDER BY `Itype` DESC, `Number` ASC");
				if($for=mysqli_num_rows($dor)){
?>
 <div class="row">
            <div class="col-lg-12" style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Requisition Voucher No : <b><?php echo" $vou " ?></b></span><form action="" method="post">
        <?php
        echo"<input type='hidden' name='vous' value='$vous'>
        <input type='hidden' name='des' value='$des'>
        <input type='hidden' name='dte' value='$dte'>
        <input type='hidden' name='requi' value='1'>";
        ?>
			 <span class="pull-right">&nbsp;&nbsp;&nbsp;&nbsp;<button type='submit' name="repri" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top' style="padding:0px; margin:2px; border:0px; background-color:transparent;"><i class="lnr lnr-printer"></i></button>&nbsp;&nbsp;&nbsp;&nbsp;</span>
            </form><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;Name </th>
                        <th> Description </th>
                       <th> Item&nbsp;Type </th>
                       <th colspan='2'>&nbsp;&nbsp;Qty&nbsp;In&nbsp;&nbsp;</th>
						 <th> Cost&nbsp;Price </th>
						 <th><div align='center'> Request </th>
						 <th><div align='center'> Buffer </th>
                        <th><div align='center'> Given </th>
						<th>Total&nbsp;Amount</th>
                        <th class="hidden-xs hidden-print" style="width:40px; text-align:center;" colspan='2'> Options </th>
                     </tr>
                    </thead>
                                        <tbody>
										<?php
	$n=1;			$tot=0;
			  $click=0;
					while($ror=mysqli_fetch_assoc($dor)){
						$code=$ror['Number'];
						$item=$ror['Item'];
						$sale=$ror['Price'];
						$qt=$ror['QTY'];
						$des=$ror['Destin'];
						$vous=$ror['Voucher'];
						$count=$ror['Count'];
						$chk=$ror['Changed'];
						$rqt=$ror['RQTY'];
$dte=$ror['Date'];
$crt=$ror['Control'];
$crtqt=$qt;
$qts=$qt;

	$do=mysqli_query($cons, "SELECT *FROM `items` WHERE `Status`='0' AND `Number`='$item' ORDER BY `Number` DESC LIMIT $lim");
		$ro=mysqli_fetch_assoc($do);
			$iname=$ro['Iname'];
			$kin=$ro['Type'];
			$descri=$ro['Descri'];
			$uno=$ro['Unit'];	
			$qin=$ro['Quantity'];
			$store=$ro['Store'];
if($store=='2')				
			$cost=$ro['Cost'];
else			
			$cost=$ro['Cost'];	

	$qty=number_format($rqt, 2);			$costo=number_format($cost, 2);			$sales=number_format($sale, 2);			$qto=number_format($qt, 2);
		$crtqto=number_format($crtqt, 2);
	
			if($des=='PRODUCTION A'){
				$burr=$ro['Produ'];
		
		if($burr>$rqt){
				/*	$qt="0.00";
	$then=mysqli_query($cons, "UPDATE `requis` SET `Quantity`='0', `Changed`='1' WHERE `Item`='$item' AND `Voucher`='$vous' AND `Changed`='0' AND `Production`='PRODUCTION A' AND `Destin`='$des' AND `Date`='$dte' AND `Upda`='0' LIMIT 1000");
*/
				}
				else{
			/*		$qt=$rqt-$burr;
	$then=mysqli_query($cons, "UPDATE `requis` SET `Quantity`='$qto', `Changed`='1' WHERE `Number`='$code' AND `Item`='$item' AND `Voucher`='$vous' AND `Changed`='0' AND `Destin`='$des' AND `Date`='$dte' AND `Upda`='0' LIMIT 1000");
	$and=mysqli_query($cons, "UPDATE `requis` SET `Quantity`='0', `Changed`='1' WHERE `Number`!='$code' AND `Item`='$item' AND `Voucher`='$vous' AND `Changed`='0' AND `Production`='PRODUCTION A' AND `Destin`='$des' AND `Date`='$dte' AND `Upda`='0' LIMIT 1000");
*/
				}
			}


if($des=='PRODUCTION B'){
				$burr=$ro['Prodi'];
		
		if($burr>$rqt){
				/*	$qt="0.00";
	$then=mysqli_query($cons, "UPDATE `requis` SET `Quantity`='0', `Changed`='1' WHERE `Item`='$item' AND `Voucher`='$vous' AND `Changed`='0' AND `Production`='PRODUCTION B' AND `Destin`='$des' AND `Date`='$dte' AND `Upda`='0' LIMIT 1000");
*/
				}
				else{
				/*	$qt=$rqt-$burr;
	$then=mysqli_query($cons, "UPDATE `requis` SET `Quantity`='$qto', `Changed`='1' WHERE `Number`='$code' AND `Item`='$item' AND `Voucher`='$vous' AND `Changed`='0' AND `Upda`='0' LIMIT 1000");
	$and=mysqli_query($cons, "UPDATE `requis` SET `Quantity`='0', `Changed`='1' WHERE `Number`!='$code' AND `Item`='$item' AND `Voucher`='$vous' AND `Changed`='0' AND `Production`='PRODUCTION B' AND `Upda`='0' LIMIT 1000");
*/
				}
			}
			else{
				if($des=='PRODUCTION A'){
					$burr=$ro['Produ'];
					}
				elseif($des=='PRODUCTION B'){
					$burr=$ro['Prodi'];
					}
					else{
				$dois=mysqli_query($cons, "SELECT `Number` FROM `branches` WHERE `Name`='$des' ORDER BY `Number` ASC LIMIT 1");
						$rois=mysqli_fetch_assoc($dois);
							$bra=$rois['Number'];					
							$buffer="S$bra";
							$burr=$ro["$buffer"];
							}
				}


				$_SESSION['Deso']=$des;				$_SESSION['Dto']=$dte;
			
	$burro=number_format($burr, 2);					$rqto=number_format($rqt, 2);		
									$qto=number_format($qt, 2);

			if($count=='0')
				$stn="color:#3333cc;";
			else
				$stn="";

$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'];

	$then=mysqli_query($cons, "UPDATE `requis` SET `Price`='$cost' WHERE `Number`='$code' LIMIT 1");

          $to=$cost*$qt;				$too=number_format($to, 2);			$qino=number_format($qin, 2);
		  if($qin<$qt){
			  $stn="color:red;";
			  $click++;
		  }
if($crt)
$qto=$crtqto;

if($burr>$qto)
$brd="border:1px solid blue;";
else
$brd="";
		print("<tr title='Voucher: $vous'><form action='' method='post'>
                        <td class=hidden-xs style='$stl $stn'><div align='center'>$n&nbsp;&nbsp;</td>
						<td style='$stl $stn'> $iname </td><td style='$stl $stn'> $descri </td><td style='$stl $stn'> $type </td>
						<td style='$stl $stn'><div align='right'> $qino </td>
						<td style='$stl $stn'> $unit </td><td style='$stl $stn'><div align='right'>&nbsp;$costo&nbsp;&nbsp;&nbsp;&nbsp;</td>
						<td style='$stl $stn'><div align='right'><b> $rqto </td><td style='$stl $stn'><div align='right'> $burro </td>
						<td><div align='right'><input name='qty' class='form-control' type='text' onkeyup='format(this);' onkeypress='return isNumberKey(event);' onChange=this.style.color='#ff3366' style='text-align:right; width:80px; height:20px; margin:0px 0px 0px 0px; padding:0px 10px 0px 0px; $brd $stn' value='$qto'></td><td style='$stl $stn'><div align='right'>$too&nbsp;&nbsp;&nbsp;&nbsp;
<input type='hidden' name='dte' value='$dte'></td>
						
						
						<td class='hidden-xs hidden-print' align='right' style='width:40px; padding:0px;'>
         <input type='hidden' name='rowid' value='$code'><input type='hidden' name='vous' value='$vous'>
<input type='hidden' name='item' value='$item'><input type='hidden' name='rqty' value='$rqt'>
                          <button type='submit' class='btn btn-xs btn-warning hidden-print' name='edit' style='height:18px; padding:0px;' 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:40px; padding:0px;'>
						  <input type='hidden' name='item' value='$item'><input type='hidden' name='dte' value='$dte'>
                              <input type='hidden' name='rowid' value='$code'><input type='hidden' name='vous' value='$vous'>
                          <button type='submit' class='btn btn-xs btn-danger hidden-print' name='delo' style='height:18px; padding:0px;' title='Delete' data-toggle='tooltip' data-placement='top'>
						  &nbsp;&nbsp;<i class='lnr lnr-trash'></i>&nbsp;&nbsp;</button></td></form></tr>");
						  $n++;				$tot+=$to;
						}
						$toto=number_format($tot, 2);			
						?>
						
                    </tbody>

					 <thead>
					<tr><th class="hidden-xs"> </th><th colspan='7'><div align='center'> Grand Total </th>
					<th colspan='3'><div align='right'><?php echo $toto ?>&nbsp;&nbsp;&nbsp;&nbsp;</th><th colspan='2'><div align='center'> -- </th></tr>
                  </table><br>

				  <label class="control-label col-md-1"> </label>

				  <form method='post' action=''><label class="control-label col-md-3">
			  <select class="form-control" name="des" required>			
			 <?php
				echo"<option value='$des' selected='selected'> $des </option>";						
			echo"</select><input type='hidden' name='vous' value='$vous'>
							  <input type='hidden' name='des' value='$des'>";
			?></label>

	<label class="control-label col-md-3">
<input list="take" name="taker" class="form-control" placeholder="TAKEN BY" OnKeyup="return cUpper(this);" required></label>
<datalist id="take">
 <?php
			 $top=mysqli_query($cons, "SELECT `Person` FROM `stouse` WHERE `Status`='0' AND `Person`!='' GROUP BY `Person` ORDER BY `Date` DESC LIMIT 20");
						while($rop=mysqli_fetch_assoc($top)){
							$sup=$rop['Person'];
			echo"<option value='$sup'>";
						}
						?>
</datalist>
		</label>

	<label class="control-label col-md-2">
	<input name="dato" id="from" class="form-control sm" type="text" style="text-align:center;" VALUE="<?php echo $Date ?>" onclick="return pageScroll()"></label>
	<?php
	if($click=='0'){
			$btl='submit';
$tle="title='Save' data-toggle='tooltip' data-placement='top'";
}
	else{
		$btl="button";
$tle="title='Some items are missing in your store' data-toggle='tooltip' data-placement='top'";
}

// form token 
        $form_token = uniqid();
 
        // create form token session variable and store generated id in it.
        $_SESSION['form_token'] = $form_token;
  	  echo"<input type='hidden' name='form_token' value='$form_token'>";
	?>
			 <label class="control-label col-md-2">
			 <button class="btn btn-md btn-block btn-info" type="<?php echo $btl ?>" name="takere" <?php echo $tle ?>  onclick='disableSubmitButton();'><i class="lnr lnr-plus-circle"></i> TAKEN </button>
			 </label></form>

			  <form action='' method='post'><label class="control-label col-md-1" style='text-align:right;'>
			  <?php
				  if($n>3 AND $_SESSION['Cancel']=='1'){
				  echo"<input type='hidden' name='vous' value='$vous'>  
				  <input type='hidden' name='des' value='$des'>
	<button type='submit' class='btn btn-md btn-danger hidden-print' name='deloreq' style='width:90%;'>&nbsp;&nbsp;<i class='lnr lnr-trash'></i>&nbsp;&nbsp;</button>";
			  }
	?>
			 </label></form>

		<?php
				}
					else{
						echo"<div class='row'>
            <div class='col-lg-12' style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Requisition Voucher No : <b> $vou </b></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'>There is no pending requisition </div><br><br><br><br><br><br><br>";
					}
			}
					?>
                                      
                
              </div>
            </div></div>
                  </div>
      
   </div></div></div>  

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