<?php
date_default_timezone_set("Asia/Colombo");
/*error_reporting(0);*/
require "racs.php";
require "vtshowsBBB.php";
session_start();
if(!isset($_SESSION['titles']) || !isset($_SESSION['positions'])|| !isset($_SESSION['usernames'])){
header("location:index.php");}
?>

<html>
<title>Prasanna Mallawa</title>
<head>
<link rel="stylesheet" type="text/css" href="rpmstyless.css">
<link rel="stylesheet" type="text/css" href="disfree.css">
<script>
function rgshows(pr,pv)
{
var dv=document.getElementById("dvshw");
dv.style.display="block";
dv.innerHTML=pv;
dv.style.top=pr.clientY;
dv.style.left='74%';
}

function rghides(pr)
{
document.getElementById("dvshw").style.display='none';
}
</script>

</head>
<body style='font-family:calibri;font-size:small;'>
<?php

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

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

$userdates=date("y-m-d");

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['chanell'])){
$chanell=$_REQUEST['chanell'];}
else{
$chanell='all';}

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['subranges'])){
$subranges=$_REQUEST['subranges'];}
else{
$subranges='all';}

#$flt=racs(1);

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($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 item_names='".$items."' ";}
if(strtolower($ranges)!='all'){
$flt=$flt." and item_ranges='".$ranges."' ";}
if(strtolower($subranges)!='all'){
$flt=$flt." and sub_ranges='".$subranges."' ";}




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

stps('pr');
printf("<div class='sds'>");
dsrdash(1);
printf("</div>");
printf("<div class='mns' style='width:55%%;'>");

$starts=date('Y-m-01');
$ends=date('Y-m-t');
$startss=date('Y-m-d');
$startsss=date('M-Y');

$sqlst="select max(dates) from rd_invoices where dates>='".$starts."' and dates<='".$ends."' ";
$qry=mysqli_query($conn,$sqlst);
if(mysqli_num_rows($qry)==0){
$tdates=date('Y-m-d');}
else{
$rst=mysqli_fetch_row($qry);
$tdates=$rst[0];}
	

printf("<table width=70%%><tr><td width=70%%>
<table width=100%%  style='width:85%%;color:grey;font-size:13;border:1px solid silver;border-collapse:collapse;'><tr style='font-size:13;'>
<td colspan='3' style='font-size:18;color:grey;border-bottom:1px solid silver;' >summary</td>");

printf("<tr style='background:silver;border:0px solid silver;font-size:14;color:white;'><td style='border:1px solid sivler;'>Sale type</td>
<td align='right' style='border:1px solid sivler;'>%s</td><td align='right' style='border:1px solid sivler;border-right:1px solid silver;'>%s</td></tr>",
$tdates,date('Y-M')); 
	
$tdv=0;
$mnv=0;

$sqlst="select invs,tv,mv from (select distinct invoice_types as invs from rd_invoices ".$flt." and  dates>='".$starts."' and dates<='".$ends."') as tps left join 
 (select invoice_types,sum(box_qty*box_price+pcs_qty*pcs_price) as tv from rd_invoices ".$flt." and dates='".$tdates."' group by invoice_types) as tvl on invs=tvl.invoice_types left join 
(select invoice_types,sum(box_qty*box_price+pcs_qty*pcs_price) as mv from rd_invoices ".$flt." and dates>='".$starts."' and dates<='".$ends."' group by invoice_types) as mvs on invs=mvs.invoice_types ";

$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
printf("<tr class='bls'><td>%s</td><td align='right'>%s<td align='right' style='border-right:1px solid silver;'>%s</td></tr>",
$rst[0],number_format($rst[1],0,'.',','),number_format($rst[2],0,'.',','));
$tdv=$tdv+$rst[1];
$mnv=$mnv+$rst[2];
}

printf("<tr class='bls' style='font-weight:bold;font-size:13;color:blue;'><td>Total</td>
<td align='right'>%s<td align='right' style='border-right:1px solid silver;'>%s</td></tr></td>",number_format($tdv,0,'.',','),number_format($mnv,0,'.',','));


$sqlst="select ds,ms,dm,mm,dp,mp from (select sum(scalls) as ds,sum(mcalls) as dm,sum(pcalls) as dp from (select invoice_number,scalls,mcalls,pcalls from rd_invoices ".$flt." and dates='".$tdates."') as asa) as dvs, (select sum(scalls) as ms,sum(mcalls) as mm, sum(pcalls) as mp from (select invoice_number,scalls,mcalls,pcalls from rd_invoices ".$flt." and dates>='".$starts."' and dates<='".$ends."') as bsb) as mvs ";


$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
printf("<tr class='bls' style='font-size:13;border:1px solid silver;'><td>Schedule calls</td><td align='right'>%s</td><td align='right'>%s</td></tr>",number_format($rst[0],0,'.',','),number_format($rst[1],0,'.',','));
printf("<tr class='bls' style='font-size:13;border:1px solid silver;'><td>Made calls</td><td align='right'>%s</td><td align='right'>%s</td></tr>",number_format($rst[2],0,'.',','),number_format($rst[3],0,'.',','));
printf("<tr class='bls' style='font-size:13;border:1px solid silver;'><td>Productive calls</td><td align='right'>%s</td><td align='right'>%s</td></tr></table>",number_format($rst[4],0,'.',','),number_format($rst[5],0,'.',','));
}


$sqlst="select tgs,acs from (select sum(box_qty*box_price+pcs_qty*pcs_price) as tgs from rc_targets ".$flt." and  dates>='".$starts."' and dates<='".$ends."') as tg,
(select sum(box_qty*box_price+pcs_qty*pcs_price) as acs from rd_invoices ".$flt." and  dates>='".$starts."' and dates<='".$ends."') as ac ";
$qry=mysqli_query($conn,$sqlst);
$rst=mysqli_fetch_row($qry);

if($rst[0]==0){
$ach="Budget not set";}
else{
$ach="<br>".round($rst[1]*100/$rst[0],0)."% <br>RD-Sales";}
printf("<td align='center' style='color:red;font-size:20;width:30%%;'>%s</td></tr></table>",$ach);


/////////////////////////////////////////////

/*
printf("<BR>");
printf("<table id='dta' style='width:75%%;font-size:13;border-collapse:collapse;color:#006699;border:1px solid silver;'>");
printf("<tr><td colspan='3' style='color:grey;border:1px solid white;font-size:16;'>Channel wise achievement - %s</td></tr>",date('Y-M'));
printf("<tr style='background:silver;border:1px solid white;text-align:right;'><td style='border:1px solid white;text-align:left;border'>Channel</td><td style='border:1px solid white;'>Target</td>
<td style='border:1px solid white;'>Gros-Sale</td><td style='border:1px solid white;text-align:center;'>Ach:</td><td>Variance</td><td>Discount</td><td>Net-Sale</td></tr>");

$sqlst="select mzones,tgvl,acvl,disvl from (select distinct chanell as mzones from rd_invoices where chanell<>'' and chanell<>'Key Custom' and chanell<>'Direct' order by zone_orders) as ags left join 
(select chanell,sum(box_qty*box_price+pcs_qty*pcs_price) as tgvl from rc_targets ".$flt." and 
dates>='".$starts."' and dates<='".$ends."' group by chanell) as tgs on tgs.chanell=mzones left join (select chanell,sum(box_qty*box_price+pcs_qty*pcs_price) as acvl,sum((box_qty*box_price+pcs_qty*pcs_price)*discount_rates) as disvl from rd_invoices ".$flt." and dates>='".$starts."' and dates<='".$ends."' group by chanell) 
as acs on acs.chanell=mzones ";
 
$tgv=0;
$acv=0;
$dvl=0;
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
$tgv=$tgv+$rst[1];
$acv=$acv+$rst[2];
$dvl=$dvl+$rst[3];

if($rst[1]==0){
$pcs=100;}
else{
$pcs=$rst[2]*100/$rst[1];}
	
printf("<tr style='border-bottom:1px solid silver;'><td>%s</td>
<td align='right'>%s</td><td align='right'>%s</td><td align='center'>%s%%</td><td align='right'>%s</td><td align='right'>%s</td><td align='right'>%s</td></tr>",
$rst[0],number_format($rst[1],0,'.',','),number_format($rst[2],0,'.',','),
number_format($pcs,0,'.',','),number_format($rst[2]-$rst[1],0,'.',','),number_format($rst[3],0,'.',','),number_format($rst[2]+$rst[3],0,'.',','));
}
if($tgv==0){
$pcs=100;}
else{
$pcs=$acv*100/$tgv;}

printf("<tr style='border-bottom:1px solid silver;font-weight:bold;'><td>Total</td>
<td align='right'>%s</td><td align='right'>%s</td><td align='center'>%s%%</td><td align='right'>%s</td><td align='right'>%s</td><td align='right'>%s</td></tr></table>",
number_format($tgv,0,'.',','),number_format($acv,0,'.',','),
number_format($pcs,0,'.',','),number_format($tgv-$acv,0,'.',','),number_format($dvl,0,'.',','),number_format($acv+$dvl,0,'.',','));
*/

printf("<BR>");
printf("<table id='dta' style='width:75%%;font-size:13;border-collapse:collapse;color:#006699;border:1px solid silver;'>");
printf("<tr><td colspan='3' style='color:grey;border:1px solid white;font-size:16;'>Zone wise achievement - %s</td></tr>",date('Y-M'));
printf("<tr style='background:silver;border:1px solid white;text-align:right;'><td style='border:1px solid white;text-align:left;border'>Zone</td><td style='border:1px solid white;'>Target</td>
<td style='border:1px solid white;'>Gros-Sale</td><td style='border:1px solid white;text-align:center;'>Ach:</td><td>Variance</td><td>Discount</td><td>Net-Sale</td></tr>");

$sqlst="select mzones,tgvl,acvl,dvl from (select distinct zones as mzones from rd_invoices where chanell<>''and zones<>'Ch1-Zone-1'and zones<>'Ch1-Zone-2'and zones<>'Ch2-Zone-1'and zones<>'Ch2-Zone-2' and zones<>'Key customer' order by zone_orders) as ags left join 
(select zones,sum(box_qty*box_price+pcs_qty*pcs_price) as tgvl from rc_targets ".$flt." and 
dates>='".$starts."' and dates<='".$ends."' group by zones) as tgs on tgs.zones=mzones left join (select zones,sum(box_qty*box_price+pcs_qty*pcs_price) as acvl,sum((box_qty*box_price+pcs_qty*pcs_price)*discount_rates) as dvl from rd_invoices ".$flt." and dates>='".$starts."' and dates<='".$ends."' group by zones) 
as acs on acs.zones=mzones ";
 
$tgv=0;
$acv=0;
$dvl=0;
 
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
$tgv=$tgv+$rst[1];
$acv=$acv+$rst[2];
$dvl=$dvl+$rst[3];

if($rst[1]==0){
$pcs=100;}
else{
$pcs=$rst[2]*100/$rst[1];}
	
printf("<tr style='border-bottom:1px solid silver;'><td>%s</td>
<td align='right'>%s</td><td align='right'>%s</td><td align='center'>%s%%</td><td align='right'>%s</td><td align='right'>%s</td><td align='right'>%s</td></tr>",
$rst[0],number_format($rst[1],0,'.',','),number_format($rst[2],0,'.',','),
number_format($pcs,0,'.',','),number_format($rst[2]-$rst[1],0,'.',','),number_format($rst[3],0,'.',','),number_format($rst[2]+$rst[3],0,'.',','));
}


if($tgv==0){
$pcs=100;}
else{
$pcs=$acv*100/$tgv;}

printf("<tr style='border-bottom:1px solid silver;font-weight:bold;'><td>Total</td>
<td align='right'>%s</td><td align='right'>%s</td><td align='center'>%s%%</td><td align='right'>%s</td><td align='right'>%s</td><td align='right'>%s</td></tr></table>",
number_format($tgv,0,'.',','),number_format($acv,0,'.',','),
number_format($pcs,0,'.',','),number_format($tgv-$acv,0,'.',','),number_format($dvl,0,'.',','),number_format($acv+$dvl,0,'.',','));

printf("<BR>");
printf("<table id='dtb' style='width:75%%;font-size:13;border-collapse:collapse;color:#006699;border:1px solid silver;'>");
printf("<tr><td colspan='3' style='color:grey;border:1px solid white;font-size:16;'>Group Range wise achievement - %s</td></tr>",date('Y-M'));
printf("<tr style='background:silver;border:1px solid white;text-align:right;'><td style='border:1px solid white;text-align:left;'>Range</td><td style='border:1px solid white;'>Target</td>
<td style='border:1px solid white;'>Gros-Sale</td><td style='border:1px solid white;text-align:center;'>Ach:</td><td>Variance</td><td>Discount</td><td>Net-Sale</td></tr>");

$sqlst="select mzones,tgvl,acvl,dvl from (select distinct item_ranges as mzones from itemsmrd   where item_status='Active' order by item_ranges) as ags left join 
(select item_ranges,sum(box_qty*box_price+pcs_qty*pcs_price) as tgvl from rc_targets ".$flt." and 
dates>='".$starts."' and dates<='".$ends."' group by item_ranges) as tgs on tgs.item_ranges=mzones left join (select item_ranges,sum(box_qty*box_price+pcs_qty*pcs_price) as acvl,sum((box_qty*box_price+pcs_qty*pcs_price)*discount_rates) as dvl from rd_invoices ".$flt." and dates>='".$starts."' and dates<='".$ends."' group by item_ranges) 
as acs on acs.item_ranges=mzones ";

 
$tgv=0;
$acv=0;
$dvl=0;

 
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
$tgv=$tgv+$rst[1];
$acv=$acv+$rst[2];
$dvl=$dvl+$rst[3];

if($rst[1]==0){
$pcs=100;}
else{
$pcs=$rst[2]*100/$rst[1];}
	
printf("<tr style='border-bottom:1px solid silver;'><td>%s</td>
<td align='right'>%s</td><td align='right'>%s</td><td align='center'>%s%%</td><td align='right'>%s</td><td align='right'>%s</td><td align='right'>%s</td></tr>",
$rst[0],number_format($rst[1],0,'.',','),number_format($rst[2],0,'.',','),
number_format($pcs,0,'.',','),number_format($rst[2]-$rst[1],0,'.',','),number_format($rst[3],0,'.',','),number_format($rst[2]+$rst[3],0,'.',','));
}

if($tgv==0){
$pcs=100;}
else{
$pcs=$acv*100/$tgv;}

printf("<tr style='border-bottom:1px solid silver;font-weight:bold;'><td>Total</td>
<td align='right'>%s</td><td align='right'>%s</td><td align='center'>%s%%</td><td align='right'>%s</td><td align='right'>%s</td><td align='right'>%s</td></tr></table>",
number_format($tgv,0,'.',','),number_format($acv,0,'.',','),
number_format($pcs,0,'.',','),number_format($tgv-$acv,0,'.',','),number_format($dvl,0,'.',','),number_format($acv+$dvl,0,'.',','));

/*Range Sales Trend Codes Here */

/*$conn=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");*/

printf("<BR>");
print("<div style='display:block;font-size:14;left:5%%;' id='dta'>");
printf("<table id='dta' style='font-size:13;width:75%%;color:#2E2E2E;'><th style='color:white;font-size:13;background:grey;border:1px solid grey;' colspan='5' align='left'><b>Range Sales trend</th>",$exchrf);

printf("<tr style='border:1px solid silver;color:#006699;'><td padding=1%% align='center' bgcolor='silver' >Range</td>");
$arr=array();
$months=date('m');
$days=date('t');
$years=date('Y');
 
$sqlst="select mranges";
$rsqlst="";

for($cnt=0;$cnt<4;$cnt++){
$arr[$cnt]=0;	
if($months==0){
$months=12;
$years--;}

$dates=date_create($years.'-'.$months);
printf("<td padding=1%% align='center' style='background:silver;'>%s</td>",date_format($dates,'M-Y'));
 
$sqlst=$sqlst.",xx".$months.$years.".vls";
 
$rsqlst=$rsqlst." left join (select item_ranges as tranges,sum(pcs_qty*pcs_price) as vls from rd_invoices ".$flt." and dates>='".$years."-".$months."-1' and
dates<='".$years."-".$months."-".cal_days_in_month(CAL_GREGORIAN,$months,$years)."' group by item_ranges) as xx".$months.$years." on xx".$months.$years.".tranges=mitems.mranges ";
$months--;        
}
 
$sqlst=$sqlst." from (select distinct item_ranges as mranges from itemsmrd ".$rlt.") as mitems ";
$sqlst=$sqlst.$rsqlst." order by mranges ";
 
printf("</tr>");

$qry=mysqli_query($conn,$sqlst);
$fcn=mysqli_num_fields($qry);

while($rst=mysqli_fetch_row($qry)){
$ttv=0;

$itemshrf="<a href='#?rpsty=agentsummarys&dtd=dtdaa&starts=".$starts."&ends=".$ends."&regions=".$regions."&agents=".$agents."&territorys=all&ranges=".$rst[0]."&zones=".$zones."&rsms=All&executives=All&reps=All&items=All' target='_blank'>Items</a>";
$agentshrf="<a href='#?rpsty=agentsummarys&dtd=dtdaa&starts=".$starts."&ends=".$ends."&regions=".$regions."&agents=".$agents."&territorys=all&ranges=".$rst[0]."&zones=".$zones."&rsms=All&executives=All&reps=All&items=All' target='_blank'>Agents</a>";
$regionhrf="<a href='#?rpsty=agentsummarys&dtd=dtdaa&starts=".$starts."&ends=".$ends."&regions=".$regions."&agents=".$agents."&territorys=all&ranges=".$rst[0]."&zones=".$zones."&rsms=All&executives=All&reps=All&items=All' target='_blank'>Regions</a>";



for($cn=1;$cn<$fcn;$cn++){
$ttv=$ttv+$rst[$cn];}

if($ttv!=0){
printf("<tr class='cls' style='border:1px solid silver;color:#006699;'><td padding=1%%>%s</td>",$rst[0]);

for($cn=1;$cn<$fcn;$cn++){
$arr[$cn]=$arr[$cn]+$rst[$cn];
$ttv=$ttv+$rst[$cn];
	
printf("<td align='right' padding=1%%>%s</td>",number_format($rst[$cn],0,'.',','));}
printf("</tr>",number_format($ttv,0,'.',','),$itemshrf,$agentshrf,$regionhrf);
$itemshrf="<a href='#?rpsty=agentsummarys&dtd=dtdaa&starts=".$starts."&ends=".$ends."&regions=".$regions."&agents=".$agents."&territorys=all&ranges=all&zones=".$zones."&rsms=All&executives=All&reps=All&items=All' target='_blank'>Items</a>";
$agentshrf="<a href='#?rpsty=agentsummarys&dtd=dtdaa&starts=".$starts."&ends=".$ends."&regions=".$regions."&agents=".$agents."&territorys=all&ranges=all&zones=".$zones."&rsms=All&executives=All&reps=All&items=All' target='_blank'>Agents</a>";
$regionhrf="<a href='#?rpsty=agentsummarys&dtd=dtdaa&starts=".$starts."&ends=".$ends."&regions=".$regions."&agents=".$agents."&territorys=all&ranges=all&zones=".$zones."&rsms=All&executives=All&reps=All&items=All' target='_blank'>Regions</a>";
}
}
$ttv=0;
printf("<tr class='cls' style='font-weight:bold;border:px solid silver;'><td>Total</td>");
for($cn=1;$cn<$fcn;$cn++){
$ttv=$ttv+$arr[$cn];
printf("<td align='right' padding=1%%>%s</td>",number_format($arr[$cn],0,'.',','));}
printf("</tr></table>",$itemshrf,$agentshrf,$regionhrf);
printf("</div>");

/* code end here*/


/////////////////////////////////////////////////

printf("<BR>");
printf("</tr></table></div>");

printf("<div class='rds' style='left:65%%;'>");
#printf("<BR><table style='font-size:13;'>");
#printf("<tr><td>%s - Invoice list</td></tr>",date('Y-m-d'));
#printf("<tr><td>%s - Item list</td></tr>",date('Y-m-d'));
#printf("<tr><td>%s - Agents list</td></tr>",date('Y-m-d'));
#printf("</tr></table>");

$sprt="?actp=rtp&zones=all&regions=all&agents=all&agenttypes=all&terrys=all&items=all&ranges=all&subranges=all&starts=".
$tdates."&ends=".$tdates."' target='_blank'";


printf("<BR><table style='width:95%%;height:9%%;font-size:13;color:silver;'>
<tr><td style='background:none;text-align:left;color:#006699;'>%s</td>
<td style='border-left:1px solid silver;background:none;text-align:center'><a href='#?%s>Goto invoices</a></td>
<td style='border-left:1px solid silver;background:none;text-align:center'><a href='#?%s>Goto Agents</a></td>
<td style='border-left:1px solid silver;background:none;text-align:center'><a href='#?%s>Goto Items</a></td>
</tr></table>",$tdates,$sprt,$sprt,$sprt);

printf("<BR><table style='font-size:13;border:0px solid silver;border-collapse:collapse;width:95%%;color:grey;'>
<th colspan='2' style='font-size:18;color:grey;font-weight:normal;text-align:left;border-bottom:1px solid silver;'>Daily sales-$startss</th>
<tr style='background:silver;font-size:14;color:white;text-align:center;border:1px solid silver;'><td width=45%%>Date</td><td width=55%%>Sale</td></tr>");

$sqlst="select dates,sum((box_qty*box_price)+(pcs_qty*pcs_price)) from rd_invoices ".$flt." and dates>='".date('Y-m-01').
"' and dates<='".date('Y-m-t')."' group by dates order by dates";
$qry=mysqli_query($conn,$sqlst);

while($rst=mysqli_fetch_row($qry)){
printf("<tr style='border:1px solid silver;'><td>%s</td><td align='right'>%s</td></tr>",$rst[0],number_format($rst[1],0,'.',','));	
}
printf("</table>");
printf("</div>");

printf("<div class='rdss' style='left:85%%;'>");
printf("<BR><table style='font-size:13;border:0px solid silver;border-collapse:collapse;width:95%%;color:white;'>
<th colspan='2' style='font-size:14;color:yellow;font-weight:normal;text-align:left;border-bottom:1px solid silver;'>Progress-$startsss</th>
<tr style='background:#A695BE;font-size:14;color:white;text-align:center;border:1px solid silver;'><td width=45%%>Employee</td><td width=55%%>DSR-Counts</td></tr>");
////$startsss
///dates>='".date('Y-m-01')."'
///dates<='".date('Y-m-t')."'
$sqlst="select user_names,count(distinct invoice_number)as disco from rd_invoices ".$flt." and user_dates>='".date('Y-m-01')."' and user_dates<='".date('Y-m-t')."' group by user_names order by disco desc";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
$tgvtx=$tgvtx+$rst[1];
printf("<tr style='border:1px solid silver;'><td>%s</td><td align='right'>%s</td></tr>",$rst[0],number_format($rst[1],0,'.',','));	
}
printf("<tr style='border-bottom:1px solid silver;font-weight:bold;color:yellow'><td>Total</td>
<td align='right'>%s</td></tr>",
number_format($tgvtx,0,'.',','));

printf("</table>");
printf("</div>");

//$nwdate=$startss-strtotime('-30');
//echo date('Y-m-d', strtotime('-30 days'));
//echo $newdate = date("m-Y", strtotime("-1 months"));
$today = date('y-m-d');
$newdate = date('y-m-d', strtotime('-1 months', strtotime($today))); 
echo $newdate;

printf("<div class='rdsss' style='left:85%%;'>");
printf("<BR><table style='font-size:13;border:0px solid silver;border-collapse:collapse;width:95%%;color:white;'>
<th colspan='2' style='font-size:14;color:yellow;font-weight:normal;text-align:left;border-bottom:1px solid silver;'>Progress-$startss</th>
<tr style='background:#A695BE;font-size:14;color:white;text-align:center;border:1px solid silver;'><td width=45%%>Employee</td><td width=55%%>DSR-Counts</td></tr>");
$sqlst="select user_names,count(distinct invoice_number)as cc from rd_invoices ".$flt." and user_dates='".$startss."' group by user_names order by user_names desc";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
$tgvtt=$tgvtt+$rst[1];

printf("<tr style='border:1px solid silver;'><td>%s</td><td align='right'>%s</td></tr>",$rst[0],number_format($rst[1],0,'.',','));	
}
printf("<tr style='border-bottom:1px solid silver;font-weight:bold;color:yellow'><td>Total</td>
<td align='right'>%s</td></tr>",
number_format($tgvtt,0,'.',','));

printf("</table>");
printf("</div>");

printf("<div class='rdsssv' style='left:85%%;'>");
printf("<BR><table style='font-size:13;border:0px solid silver;border-collapse:collapse;width:95%%;color:white;'>
<th colspan='2' style='font-size:14;color:yellow;font-weight:normal;text-align:left;border-bottom:1px solid silver;'>Dsr-$startsss</th>
<tr style='background:#A695BE;font-size:14;color:white;text-align:center;border:1px solid silver;'><td width=45%%>Employee</td><td width=55%%>Entries</td></tr>");
$sqlst="select user_names,count(distinct invoice_number)as disco from rd_invoices ".$flt." and dates>='".date('Y-m-01').
"' and dates<='".date('Y-m-t')."' group by user_names order by user_names desc";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
$tgvtxd=$tgvtxd+$rst[1];
printf("<tr style='border:1px solid silver;'><td>%s</td><td align='right'>%s</td></tr>",$rst[0],number_format($rst[1],0,'.',','));	
}
printf("<tr style='border-bottom:1px solid silver;font-weight:bold;color:yellow'><td>Total</td>
<td align='right'>%s</td></tr>",
number_format($tgvtxd,0,'.',','));

printf("</table>");
printf("</div>");

printf("<div class='rdssvt' style='left:85%%;'>");
printf("<BR><table style='font-size:13;border:0px solid silver;border-collapse:collapse;width:95%%;color:white;'>
<th colspan='2' style='font-size:14;color:yellow;font-weight:normal;text-align:left;border-bottom:1px solid silver;'>Progress-$startss</th>
<tr style='background:#A695BE;font-size:14;color:white;text-align:center;border:1px solid silver;'><td width=45%%>Employee</td><td width=55%%>Discounts</td></tr>");
$sqlst="select user_names,count(distinct dis_numbers)as cc from dis_free ".$flt." and user_dates='".$startss."' group by user_names order by user_names desc";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
$tgvttx=$tgvttx+$rst[1];

printf("<tr style='border:1px solid silver;'><td>%s</td><td align='right'>%s</td></tr>",$rst[0],number_format($rst[1],0,'.',','));	
}
printf("<tr style='border-bottom:1px solid silver;font-weight:bold;color:yellow'><td>Total</td>
<td align='right'>%s</td></tr>",
number_format($tgvttx,0,'.',','));

printf("</table>");
printf("</div>");




printf("<div class='shws' style='display:none;' id='dvshw'>Prasanna Mallawa</div>");
}
?>
</div>
</body>
</html>


