<?php
require "racs.php";
//require "vtshowsBBB.php";
require "fgstyles.php";
session_start();

if(!isset($_SESSION['titles']) || !isset($_SESSION['positions'])|| !isset($_SESSION['usernames'])){
header("location:index.php");}
?>
<html>
<title>Donation-Pending Status</title>
<head>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script src="datesps.js"></script>
<link rel="stylesheet" type="text/css" href="vtxstyles.css">
<script>
function scopys(pr)
{
var dts=document.getElementById("dt");

var sels=window.getSelection();
sels.removeAllRanges();
var ranges=document.createRange();
ranges.selectNodeContents(dts);
sels.addRange(ranges);
document.execCommand("copy");
alert("Copied - successfull");
sels.removeAllRanges();
}


function srgs(pr)
{
var sv=document.getElementById('srctxt').value.toLowerCase();
var dt=document.getElementById('dt');
var rn=dt.rows.length;
for(var cnt=1;cnt<rn-1;cnt++){
tvl=dt.rows[cnt].cells[0].innerText.toLowerCase();
rvl=dt.rows[cnt].cells[1].innerText.toLowerCase();
svl=dt.rows[cnt].cells[2].innerText.toLowerCase();

if(sv.length>1 && (tvl.indexOf(sv)>=0 || rvl.indexOf(sv)>=0 || svl.indexOf(sv)>=0)){
dt.rows[cnt].style.display='table-row';}
else{
dt.rows[cnt].style.display='none';}
if(sv.length<=1){
dt.rows[cnt].style.display='table-row';}	
}
}
</script>
</head>
<body style='font-family:calibri;font-size:small;'>
<?php

if($flt=="access failed"){
printf("<div style='font-color:red;'>>Access failed\nContanct Sales and Marketing division</div>");
}
else{

$conn=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_diana");

if(isset($_REQUEST['starts'])){
echo "starts ok";	
$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['zones'])){
$zones=$_REQUEST['zones'];}
else{
$zones='all';}

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

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

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

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

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

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

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

if(isset($_REQUEST['invoicenumbers'])){
$invoicenumbers=$_REQUEST['invoicenumbers'];}
else{
$subranges='all';}

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

$flt=racs(1);
if(strtolower($zones)!='all'){
$flt=$flt." and zones='".$zones."' ";}
if(strtolower($regions)!='all'){
$flt=$flt." and regions='".$regions."' ";}
if(strtolower($subregions)!='all'){
$flt=$flt." and sub_regions='".$subregions."' ";}
if(strtolower($agents)!='all'){
$flt=$flt." and agent_names='".$agents."' ";}
if(strtolower($agenttypes)!='all'){
$flt=$flt." and agent_types='".$agenttypes."' ";}
if(strtolower($terrys)!='all'){
$flt=$flt." and territory_names='".$terrys."' ";}
if(strtolower($items)!='all'){
$flt=$flt." and itemcodes='".$items."' ";}
if(strtolower($ranges)!='all'){
$flt=$flt." and item_ranges='".$ranges."' ";}
if(strtolower($stores)!='all'){
$flt=$flt." and stores_names='".$stores."' ";}

//$flt=racs(1);
//$flt=" where dates>='".$starts."' and dates<='".$ends."' ";
//if(strtolower($invoicenumbers)!='all'){
//$flt=$flt." and invoice_number='".$invoicenumbers."' ";}

stps(1);
printf("<div style='position:absolute;left:1%%;top:5%%;width:15%%;'>");
stksnew(1);//prshows('pr','zone','gobs','sales','Periodic sales',$zones,$regions,$agents,$agenttypes,$terrys,$ranges,$subranges,$items);

printf("</div>");


printf("<div style='position:absolute;left:15%%;top:5%%;width:80%%;'>");
printf("<div style='font-size:18;font-weight:bold;color:#3498DB;'>Pending status Dates Fixed 2022-0-28]</div>");

printf("<form method='post' action='vtprspnvdnt.php?agents=%s&items=%s&invoicenumbers=%s'>",$agents,$invoicenumbers,$agents);
printf("<br><table id='fms' style='width:100%%'><tr>");

printf("<td><input type='text' id='inputField' name='starts' size=8  value='%s'
style='font-size:13;background:#CACACA;border:1px solid #006699;border-radius:1px;font-family:calibri;color:#006699;'>",$starts);
printf(" - <input type='text' id='inputField2' name='ends' size=8  value='%s'
style='font-size:13;background:#CACACA;border:1px solid #006699;border-radius:1px;font-family:calibri;color:#006699;'>",$ends);
printf(" <input type='submit' value='Go'  style='font-size:13;background:#CACACA;color:#006699;border:1.5px solid #006699;border-radius:1pxfont-size:13;'></form>");


printf("<td align='right' style='color:grey;font-size:12;'>Search
<input type='text' autocomplete='off' id='srctxt' size=28 style='font-family:calibri;font-size:13;border:1px solid silver;border-radius:1.5px;' onkeyup=\"srgs(event)\"></td>
<td style='font-size:12;color:green;text-align:center;background:silver;border:1px solid white;' onclick=\"scopys(1)\">Copy</td></tr></table>");

printf("<table id='dt' style='width:100%%;color:grey;border-collapse:collapse;font-size:13;'>");
printf("<tr valign='top' style='border:1px solid silver;background:silver;color:#006699;text-align:center;font-weight:bold;'>
<td style='border:1px solid white;width:8%%;'>Date</td>
<td style='border:1px solid white;width:8%%;'>Invoice</td>
<td style='border:1px solid white;width:20%%;'>Agent</td>
<td style='border:1px solid white;width:20%%;'>Code</td>
<td style='border:1px solid white;width:20%%;'>Item</td>
<td style='border:1px solid white;width:6%%;'>MRP</td>
<td style='border:1px solid white;width:6%%;'>Pending qty</td>
<td style='border:1px solid white;width:8%%;'>Pending value</td></tr>");

$sflt="";
$fstores=$_REQUEST['fstores'];
if($fstores!='All'){
$sflt=" and locations='".$fstores."' ";}

$sqlst="select dates,invoice_number,agent_names,item_names,box_mrp,(pcs_qty-dv_pcs_qty) as pendings,(pcs_qty-dv_pcs_qty)*pcs_price as 
pvls,itemcodes from rc_orgdonation ".$flt." and dates>='2022-03-28' and dates<='".$ends."' and (pcs_qty-dv_pcs_qty)>0";

//where vqtys>tqtys and vvls>tvls";

$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){

//$dhrf="<a href='vtprstdvnotes.php?actp=dvnts&ddates=".$rst[0]."&dinvoicenumbers=".$rst[1]."' target='_blank'>Delivery note</a>";
	 
printf("<tr  valign='top' style='border:1px solid silver;color:#006699;'>
<td width='8%%'>%s</td>
<td width='8%%'>%s</td>
<td width='30%%'>%s</td>
<td width='5%%'>%s</td>
<td width='300%%'>%s</td>
<td align='right' width='6%%'>%s</td>
<td align='right' width='8%%'>%s</td>
<td align='right' width='6%%'>%s</td>
</tr>",

$rst[0],
$rst[1],
$rst[2],
$rst[7],
$rst[3],
number_format($rst[4],0,'.',','),
number_format($rst[5],0,'.',','),
number_format($rst[6],0,'.',','));
}
printf("</div>");
}
?>
</div>
</body>
</html>