<?php
include_once('include.php');
session_start();
if(!isset($_SESSION['titles']) || !isset($_SESSION['positions'])|| !isset($_SESSION['usernames'])){
header("location:index.php");
}
if(isset($_SESSION['usernames'])){
$usrr=$_SESSION['usernames'];}
$flt=racss(1);

$con=mysqli_connect("localhost","salehljr","!2n+l)a3iX~U","salehljr_budgeting");

if(isset($_REQUEST['starts'])){
$starts=$_REQUEST['starts'];}
else{
$starts=date('Y-m-01');}

if(isset($_REQUEST['ends'])){
$ends=$_REQUEST['ends'];}
else{
$ends=date('Y-m-t');}

if(isset($_REQUEST['invnum'])){
$ponum=$_REQUEST['invnum'];}
else{
$ponum='all';}

if(isset($_REQUEST['cusname'])){
$customername=$_REQUEST['cusname'];}
else{
$customername='all';}

if(isset($_REQUEST['pdates'])){
$podates=$_REQUEST['pdates'];}
else{
$podates='all';
}

//if(strtolower($chanell)!='all'){
//$flt=$flt." and chanell='".$chanell."' ";}
//if(strtolower($zones)!='all'){
//$flt=$flt." and zones='".$zones."' ";}
//if(strtolower($regions)!='all'){
//$flt=$flt." and regions='".$regions."' ";}
//if(strtolower($agents)!='all'){
//$flt=$flt." and agent_names='".$agents."' ";}
//if(strtolower($terrys)!='all'){
//$flt=$flt." and territory_names='".$terrys."' ";}

?>
<!doctype html>

<!--<html manifest="myapp.appcache">-->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<ol class="breadcrumb">
<li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
<li class="active">Dashboard</li>
</ol>
</section>
<br>

<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-md-12">
<div class="box box-success">
<div class="box-header">
<h3 class="box-title">Purchase Order Item Details</h3>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">PO-<?php echo $ponum ?></h5>
<p class="card-text">Customer-<?php echo $customername ?></p>
<a class="card-link">PO-Date</a>
<a class="card-link"><?php echo $podates ?></a>
</div>
</div>

<!-- /.box-header -->    
<!--<form method='post' class="form-inline" action='postsupdate.php?'>
<div class="form-group">
<td>From:<i class="fa fa-calendar"></i><input type='text' class="form-control" id='inputField' name='starts' value='<?php echo $starts ?>' autocomplete='off'></td>
</div>
<div class="form-group">
To:<i class="fa fa-calendar"></i><td><input type='text' class="form-control" id='inputField2' name='ends' value='<?php echo $ends ?>'autocomplete='off'></td>
</div>
<div class="btn-group">
 <button type="submit" style="margin:5px"; class="btn btn-info">Generate-Report</button>
   </form>
 <button type="button"  style="margin:5px"; class="btn btn-success" onclick="scopys(1)">Copy-Excel</button>
 Search:<i class="fa fa-search"></i><td><input type='text' class="form-control" style="margin:5px;" id="myInput" placeholder="Type keyword to search" autocomplete='off' onkeyup="myFunction()"></td>
</div>-->

<br>
<div class="box box-primary">    
<div class="box-body table-responsive" style="overflow-x:auto;">
<table id="example" class="table table-bordered table-striped">
<thead>
<thead>
<tr>    
<th rowspan="2" class="text-center" vertical-align: "middle">CPM</th>
<th rowspan="2" class="text-center" vertical-align: "middle">Description</th>
<th rowspan="2" class="text-center" vertical-align: "middle">UOM</th>
<th rowspan="2" class="text-center" vertical-align: "middle">SIH</th>
<th colspan="2" class="text-center">Order</th>
<th colspan="2" class="text-center">GRN</th>
<th colspan="2" class="text-center">Pending</th>
<th rowspan="2" class="text-center" vertical-align: "middle">Update</th>
</tr>
<tr>
<th class="text-center">Qty</th>
<th class="text-center">Value</th>
<th class="text-center">Qty</th>
<th class="text-center">Value</th>
<th class="text-center">Qty</th>
<th class="text-center">Value</th>
</tr>
</thead>
<tbody>

<?php
$sqlst="select po_number,po_date,customer_names,po_itemname,po_qty,po_gross from po_details where  po_number='".$ponum."' and customer_names='".$customername."' group by po_itemname order by po_number";
$qry=mysqli_query($con,$sqlst);
while($rst=mysqli_fetch_row($qry)){
$cpm='Trading';    
$uom='KG';
$sih='1000';
    
?> 
<tr>
<td><?php echo $cpm ?></td>
<td><?php echo $rst[3];?></td>
<td><?php echo $uom?></td>
<td><?php echo $sih?></td>
<td><?php echo $rst[4]?></td>
<td align='center'><?php echo number_format($rst[5],0,'.',','); ?></td>
<td><?php echo $rst[4]?></td>
<td align='center'><?php echo number_format($rst[5],0,'.',','); ?></td>
<td><?php echo $rst[4]-$rst[4]?></td>
<td align='center'><?php echo number_format($rst[5]-$rst[5],0,'.',','); ?></td>
<?php
echo "<td>
<a href='#modalposts' onClick='showModal(this)' class='btn btn-warning btn-xs' data-toggle='modal'>+Update</a>
</td>";

?>
</tr>
<?php } ?>
</tbody>
</table>	
</div>
</div>
</div>
</section>
</div>

<!-- //Modal Suplier cheque Banking -->  
<div class="modal msk-fade" id="modalposts" tabindex="-1" role="salehljr" aria-labelledby="modalposts" aria-hidden="true">  
<div class="modal-salehljr">
<div class="container">
<div class="row ">	
<div class="col-md-6">
<div class="panel">
<div class="panel-heading bg-green">               
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title custom_align" id="Heading">Update PO Status</h4>
</div>
<div class="panel-body"> <!-- Start of modal body--> 
<form role="form" name="myroute" action="postatusupdate.php" onsubmit="return validaterout()" method="post" >
<div class="form-group" id="ponum">
<label for="ponumberss">Po-Number</label>
<input class="form-control" type="text" id="ponumber" name="ponumber" disabled="on" value="<?php echo $ponum ?>">
</div> 
<div class="form-group" id="prnum">
<label for="prnumberss">PR-Number</label>
<input class="form-control" type="text" id="prnumber" name="prnumber" autocomplete="off" placeholder="Enter purchase request Number">
</div> 
<div class="form-group" id="prdates">
<label for="prdts">PR-Date</label>
<input class="form-control" type="text" id="datepicker" name="prdate">
</div>
<div class="form-group" id="ridates">
<label for="ridts">RIH-Date</label>
<input class="form-control" type="text" id="datepickers" name="ridate">
</div>
</div><!--/.modal body-->
<div class="panel-footer bg-gray-light">
<input type="hidden" name="do" value="chq_sts">
<input type="hidden" name="usrname" value="<?php if (isset($usrr)) echo $usrr ?>" >
<button type="submit" class="btn btn-info" id="btnSubmit">Update</button>
</div>
</div>
</div>
</div>                                 
</div>		 
</div>     
</div>
</form>

<?php include_once('footer.php');?>

<script>
  $(function () {
    $('#example1').DataTable()
    $('#example2').DataTable({
      'paging'      : true,
      'lengthChange': false,
      'searching'   : false,
      'ordering'    : true,
      'info'        : true,
      'autoWidth'   : false,
    })
  })
  
  
function myFunction() {
var $rows = $('#example tr');
$('#myInput').keyup(function() {
    var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
    
    $rows.show().filter(function() {
        var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
        return !~text.indexOf(val);
    }).hide();
});
}
  
 function scopys(pr)
{
var dts=document.getElementById("example");
var sels=window.getSelection();
sels.removeAllRanges();
var ranges=document.createRange();
ranges.selectNodeContents(dts);
sels.addRange(ranges);
document.execCommand("copy");
swal('Coppied!', 'Open Excel sheet press CTRL+V', 'success');
sels.removeAllRanges();
} 

 //Date picker
    $('#datepicker').datepicker({
        format: 'yyyy/mm/dd',
      autoclose: true
    })
    
//Date picker
    $('#datepickers').datepicker({
        format: 'yyyy/mm/dd',
      autoclose: true
    })    
    
function c_color(){
    if (document.getElementById('ClColor').value >'5000') {
        document.getElementById('ClColor').style.color = "white";
        document.getElementById('ClColor').style.background="red";
    }
}    
    
    </script>
</body>
</html>

