<?php
date_default_timezone_set("Asia/Colombo");
require "racs.php";
require "vtshowsBBB.php";
require "showshp.php";
session_start();
if(!isset($_SESSION['titles']) || !isset($_SESSION['positions'])|| !isset($_SESSION['usernames'])){
header("location:index.php");
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="vtxstyles.css">
<link rel="stylesheet" type="text/css" href="rpmstyless.css">
<link rel="stylesheet" type="text/css" href="rdsty.css">
<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" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script>

var arzones=new Array();
var arregions=new Array();
var arrsms=new Array();
var aragents=new Array();
var artypes=new Array();
var arterrys=new Array();
var arsubregions=new Array();

$(function(){
       $("#datepicker").datepicker({ dateFormat: "yy-mm-dd"}).val()
       });
function agentprf()
{
	
var httpr= new XMLHttpRequest();
httpr.onreadystatechange=function(){
if(httpr.readyState==4 && httpr.status==200){
var vl=httpr.responseText;

var tmp=vl.split("<td>");
for(cn=0;cn<tmp.length;cn++){
var tmpa=tmp[cn].split("###");
arzones[cn]=tmpa[0];
arregions[cn]=tmpa[1];
arrsms[cn]=tmpa[2];
aragents[cn]=tmpa[3];
artypes[cn]=tmpa[4];
arterrys[cn]=tmpa[5];
arsubregions[cn]=tmpa[7];}

}}
httpr.open("POST","pragentsrqst.php?actp=items&sprftypes=dsrsales",true);
httpr.send();

}



function agsrcs(pr)
{

//var keys=pr.keyCode;
var keys=window.event.keyCode;

var schtxt=document.getElementById("agn").value;
var schagents=document.getElementById("terlst");
var sz=0;
schagents.style.display="block";
schagents.size=10;

if(keys==40){
schagents.selectedIndex=0;
schagents.focus();}


if(keys==8 && document.getElementById("agn").length==0){
pr.preventDefault();}

if(keys==13){
schagents.style.display="none";
document.getElementById("terlst").focus();}

schagents.length=0;
var tmpa=schtxt.toLowerCase();

for(var cnt=0;cnt<arterrys.length;cnt++){
var tmpb=arterrys[cnt].toLowerCase();
var tmpd=aragents[cnt].toLowerCase();

var rsta=tmpb.indexOf(tmpa);
var rstb=tmpd.indexOf(tmpa);

if(rsta>=0 || rstb>=0 ){
sz++;
var options=document.createElement("option");
var stra=arterrys[cnt]+" - "+aragents[cnt];
options.text=stra;
schagents.add(options);}
}

alert(sz);

if(sz>10){
size=10;}

schagents.size=sz;

}



function selterr(pr)
{
//var keys=pr.keyCode;
var keys=window.event.keyCode;

var terlst=document.getElementById("terlst");
var vl=terlst.options[terlst.selectedIndex].value;
var dt=document.getElementById("agdetails");


if(keys==8){
pr.preventDefault();
document.getElementById("agn").focus();
}

if(keys==13){
terlst.size=0;
terlst.style.display="none";
document.getElementById("sales2").focus();
pr.preventDefault();
}

var str=vl.split(" - ");

for(var cnt=0;cnt<aragents.length;cnt++){
if(arterrys[cnt]==str[0] && aragents[cnt]==str[1]){
dt.rows[1].cells[1].innerHTML=arzones[cnt];
dt.rows[2].cells[1].innerHTML=arregions[cnt];
dt.rows[3].cells[1].innerHTML=aragents[cnt];
dt.rows[4].cells[1].innerHTML=artypes[cnt];
dt.rows[5].cells[1].innerHTML=arterrys[cnt];
dt.rows[6].cells[1].innerHTML=arrsms[cnt];
dt.rows[7].cells[1].innerHTML=arsubregions[cnt];
}
}
}



function selterrclk(pr)
{
//var keys=pr.keyCode;
var keys=window.event.keyCode;

var terlst=document.getElementById("terlst");
var vl=terlst.options[terlst.selectedIndex].value;
var dt=document.getElementById("agdetails");

var sz=0;

var str=vl.split(" - ");

for(var cnt=0;cnt<aragents.length;cnt++){
if(arterrys[cnt]==str[0] && aragents[cnt]==str[1]){
dt.rows[1].cells[1].innerHTML=arzones[cnt];
dt.rows[2].cells[1].innerHTML=arregions[cnt];
dt.rows[3].cells[1].innerHTML=aragents[cnt];
dt.rows[4].cells[1].innerHTML=artypes[cnt];
dt.rows[5].cells[1].innerHTML=arterrys[cnt];
dt.rows[6].cells[1].innerHTML=arrsms[cnt];
dt.rows[7].cells[1].innerHTML=arsubregions[cnt];
}
}

terlst.style.display="none";
document.getElementById("sales2").focus();

}


function stfrs(pr)
{
var keys=pr.keyCode;
var dt=document.getElementById("dtd");
var rw=pr.target.parentNode.parentNode.rowIndex;

pr.target.style.backgroundColor="white";


if(keys==40){
pr.preventDefault();
document.getElementById("frees"+(rw+1)).focus();}

if(keys==38){
pr.preventDefault();
document.getElementById("frees"+(rw-1)).focus();}

if(keys==13){
var vl=document.getElementById("frees"+rw).value;
if(isNaN(vl) && vl!=''){
pr.target.style.backgroundColor="red";}
else{
document.getElementById("frees"+(rw+1)).focus();}
}

}


function onfcs(pr)
{
document.getElementById("dtd").rows[pr].style.backgroundColor="grey";
document.getElementById("dtd").rows[pr].style.fontWeight="bold";
document.getElementById("dtd").rows[pr].style.color="yellow";
}


function outfcs(pr)
{
gfcs(pr);
rw=pr.parentNode.parentNode.rowIndex;
document.getElementById("dtd").rows[rw].style.backgroundColor="#F2F2F2";
document.getElementById("dtd").rows[rw].style.fontWeight="normal";
document.getElementById("dtd").rows[rw].style.color="black";
}


function rtdiscky(pr)
{
vl=pr.target.value;

if(pr.keyCode==13||pr.keyCode==40){
if(isNaN(vl)){
alert("Check the value");
pr.target.focus();}
else{
document.getElementById("wsdiscs").focus();}
}
if(pr.keyCode!=13 && pr.keyCode!=40 && pr.keyCode!=38){
var tvl=parseFloat(document.getElementById("dstots").rows[0].cells[1].innerHTML);
var wsdisc=document.getElementById("wsdiscs").value;
if(wsdisc=='' ||isNaN(wsdisc)){
wsdisc=0;}
var vl=parseFloat(vl);

document.getElementById("dstots").rows[1].cells[1].innerHTML=vl.toFixed(2);
document.getElementById("dstots").rows[3].cells[1].innerHTML=(tvl-vl-wsdisc).toFixed(2);}


}



function wsdiscky(pr)
{
vl=pr.target.value;

if(pr.keyCode==13||pr.keyCode==40){
if(isNaN(vl)){
alert("Check the value");
pr.target.focus();}
else{
document.getElementById("mrks").focus();}
}
if(pr.keyCode!=13 && pr.keyCode!=40 && pr.keyCode!=38){
var tvl=parseFloat(document.getElementById("dstots").rows[0].cells[1].innerHTML);
var rtdisc=parseFloat(document.getElementById("rtdiscs").value);
if(rtdisc=='' ||isNaN(rtdisc)){
rtdisc=0;}
var vl=parseFloat(vl);

document.getElementById("dstots").rows[2].cells[1].innerHTML=(vl).toFixed(2);
document.getElementById("dstots").rows[3].cells[1].innerHTML=(tvl-vl-rtdisc).toFixed(2);}

if(pr.keyCode==38){
document.getElementById('rtdiscs').focus();}

}



function mrkky(pr)
{
vl=pr.target.value;


if(pr.keyCode==13 || pr.keyCode==40){
if(isNaN(vl)){
alert("Check the value");
pr.target.focus();}
else{
document.getElementById("scalls").focus();}
}
if(pr.keyCode!=13 && pr.keyCode!=40 && pr.keyCode!=38){
var vl=parseFloat(vl);
document.getElementById("dstots").rows[4].cells[1].innerHTML=vl.toFixed(2);}

if(pr.keyCode==38){
document.getElementById('wsdiscs').focus();}

}




function scallky(pr)
{
vl=pr.target.value;

if(pr.keyCode==38){
document.getElementById("mrks").focus();}

if(pr.keyCode==13||pr.keyCode==40){
if(isNaN(vl)){
alert("Check the value");
pr.target.focus();}
else{
document.getElementById("mcalls").focus();}
}
if(pr.keyCode!=13 && pr.keyCode!=40 && pr.keyCode!=38){
var vl=parseFloat(vl);
document.getElementById("dstots").rows[5].cells[1].innerHTML=vl.toFixed(2);}


if(pr.keyCode==38){
document.getElementById('mrks').focus();}

}



function mcallky(pr)
{
vl=pr.target.value;

if(pr.keyCode==38){
document.getElementById("scalls").focus();}

if(pr.keyCode==13||pr.keyCode==40){
if(isNaN(vl)){
alert("Check the value");
pr.target.focus();}
else{
document.getElementById("pcalls").focus();}
}
if(pr.keyCode!=13 && pr.keyCode!=40 && pr.keyCode!=38){
if((pr.keyCode>=48 && pr.keyCode<=57) || pr.keyCode==08 || pr.keyCode==127){
pr.keyCode=null;}

var vl=parseFloat(vl);
document.getElementById("dstots").rows[6].cells[1].innerHTML=vl.toFixed(2);}

if(pr.keyCode==38){
document.getElementById('scalls').focus();}

}



function pcallky(pr)
{
vl=pr.target.value;

if(pr.keyCode==13||pr.keyCode==38){
if(isNaN(vl)){
alert("Check the value");
pr.target.focus();}
if(pr.keyCode!=13 && pr.keyCode!=40 && pr.keyCode!=38){
document.getElementById("pcalls").focus();}
}
if(pr.keyCode!=13 && pr.keyCode!=40 && pr.keyCode!=38){
var vl=parseFloat(vl);
document.getElementById("dstots").rows[7].cells[1].innerHTML=vl.toFixed(2);}

if(pr.keyCode==38){
document.getElementById('mcalls').focus();}

}




function gfcs(pr)
{
vl=pr.value;
if(isNaN(vl)&&vl!=''){
pr.target.style.backgroundColor="red";}

}



function foutsagents()
{
//document.getElementById("schagents").style.display="none";
document.getElementById("schtxt").focus();
}



function agclicks()
{
var schagents=document.getElementById("schagents");
var schtxt=document.getElementById("schtxt");

var vl=schagents.options[schagents.selectedIndex].text;
schtxt.value=vl;
schagents.size=0;
//schagents.style.display="none";
schtxt.focus();
}




function fdtfinds(pr)
{

var vl=document.getElementById("dtfinds").value;
var fvl=document.getElementById("sranges").options[document.getElementById("sranges").selectedIndex].value;
var dt=document.getElementById("dtd");
var cn=dt.rows.length;
var vls=vl.toLowerCase();

for(var cnt=2;cnt<cn;cnt++){
	
var tmp=dt.rows[cnt].cells[0].innerHTML;
var tmpa=tmp.toLowerCase();
var tmp=dt.rows[cnt].cells[1].innerHTML;
var tmpb=tmp.toLowerCase();
var sta=tmpa.indexOf(vls);
var stb=tmpb.indexOf(vls);

if((sta>=0 || stb>=0 ) && vls.length>0 && (fvl==dt.rows[cnt].cells[0].innerText || fvl=='All')){
dt.rows[cnt].style.display="table-row";}
else{
dt.rows[cnt].style.display="none";}

if(vls.length==0){
dt.rows[cnt].style.display="table-row";}
}

}


function trdns(pr)
{
var keys=window.event.keyCode;
var rw=pr.target.parentNode.parentNode.rowIndex;
var nrw=rw+1;
var prw=rw-1;

if(keys==40){
document.getElementById("sales"+nrw).focus();}

if(keys==38){
document.getElementById("sales"+prw).focus();}

}



function stqtys(pr)
{

var keys=window.event.keyCode;
var rw=pr.target.parentNode.parentNode.rowIndex;
var dt=document.getElementById("dtd");
var tt=document.getElementById("dstots");
var tots=0;
var discs=0;

var nrw=rw+1;
var prw=rw-1;


pr.target.style.backgroundColor="white";

var vl=pr.target.value;

if(isNaN(vl) && vl!=''){
pr.target.style.backgroundColor="red";}
else{
var rvl=vl*dt.rows[rw].cells[2].innerHTML;
if(rvl>0){
dt.rows[rw].cells[5].innerHTML=rvl.toFixed(2);

for(cnt=2;cnt<dt.rows.length;cnt++){
var tmp=parseFloat(dt.rows[cnt].cells[5].innerHTML);
if(!isNaN(tmp)){
tots=tots+tmp;
}}

tt.rows[0].cells[1].innerHTML=tots.toFixed(2);
tt.rows[3].cells[1].innerHTML=(tots-discs).toFixed(2);

}


else{
dt.rows[rw].cells[5].innerHTML="";}

if(keys==13){
document.getElementById("sales"+nrw).focus();}
}

}



function scacts(pr)
{
var dt=document.getElementById("dtd");
ln=dt.rows.length;
var sts=document.getElementById("checkins").value;

rests(1);

if(sts=="Go Back"){
document.getElementById("uploads").disabled=true;

document.getElementById("checkins").value="Check in";
}

if(sts=="Check in"){
chks(1);}

}




function chks(pr)
{

var dt=document.getElementById("dtd");
var ln=dt.rows.length;
var tsv=0;
var ersts=0;

for(var cnt=0;cnt<ln;cnt++){
dt.rows[cnt].style.display="table-row";}
document.getElementById("sranges").selectedIndex=0;

for(var cnt=2;cnt<ln;cnt++){
var svl=document.getElementById("sales"+cnt).value;
var fvl=document.getElementById("frees"+cnt).value;
if(svl!=''){
svl=parseInt(svl);}
if(fvl!=''){
fvl=parseInt(fvl);}

if((svl!="" && isNaN(svl)) || (fvl!="" && isNaN(fvl))){
ersts++;
dt.rows[cnt].style.backgroundColor="red";}

if(parseFloat(dt.rows[cnt].cells[5].innerHTML)){
tsv=tsv+parseFloat(dt.rows[cnt].cells[5].innerHTML);}
}


if(document.getElementById("rtdiscs").value=="" || document.getElementById("rtdiscs").value==0){
document.getElementById("rtdiscs").value="0.00";}

if(document.getElementById("wsdiscs").value=="" || document.getElementById("wsdiscs").value==0){
document.getElementById("wsdiscs").value="0.00";}

if(document.getElementById("mrks").value=="" || document.getElementById("mrks").value==0){
document.getElementById("mrks").value="0.00";}

if(document.getElementById("scalls").value=="" || document.getElementById("scalls").value==0){
document.getElementById("scalls").value="0.00";}

if(document.getElementById("mcalls").value=="" || document.getElementById("mcalls").value==0){
document.getElementById("mcalls").value="0.00";}

if(document.getElementById("pcalls").value=="" || document.getElementById("pcalls").value==0){
document.getElementById("pcalls").value="0.00";}


if(isNaN(document.getElementById("rtdiscs").value)){
ersts++;
document.getElementById("rtdiscs").style.backgroundColor="red";}

if(isNaN(document.getElementById("wsdiscs").value)){
ersts++;
document.getElementById("wsdiscs").style.backgroundColor="red";}


if(isNaN(document.getElementById("mrks").value)){
ersts++;
document.getElementById("mrks").style.backgroundColor="red";}

if(isNaN(document.getElementById("scalls").value)){
ersts++;
document.getElementById("scalls").style.backgroundColor="red";}

if(isNaN(document.getElementById("mcalls").value)){
ersts++;
document.getElementById("mcalls").style.backgroundColor="red";}

if(isNaN(document.getElementById("pcalls").value)){
ersts++;
document.getElementById("pcalls").style.backgroundColor="red";}


//if(tsv==0){
//ersts++;
//document.getElementById("dstots").rows[0].style.backgroundColor="red";}

//if(tsv!=document.getElementById("dstots").rows[0].cells[1].innerHTML){
//ersts++;
//document.getElementById("dstots").rows[0].style.backgroundColor="red";}


var rtdiscs=parseFloat(document.getElementById("rtdiscs").value).toFixed(2);
var wsdiscs=parseFloat(document.getElementById("wsdiscs").value).toFixed(2);
var mrks=parseFloat(document.getElementById("mrks").value).toFixed(2);
var scalls=parseFloat(document.getElementById("scalls").value).toFixed(2);
var mcalls=parseFloat(document.getElementById("mcalls").value).toFixed(2);
var pcalls=parseFloat(document.getElementById("pcalls").value).toFixed(2);



if(rtdiscs!=document.getElementById("dstots").rows[1].cells[1].innerHTML){
ersts++;
document.getElementById("dstots").rows[1].style.backgroundColor="red";}

if(wsdiscs!=document.getElementById("dstots").rows[2].cells[1].innerHTML){
ersts++;
document.getElementById("dstots").rows[2].style.backgroundColor="red";}

if(mrks!=document.getElementById("dstots").rows[4].cells[1].innerHTML){
ersts++;
document.getElementById("dstots").rows[4].style.backgroundColor="red";}

if(scalls!=document.getElementById("dstots").rows[5].cells[1].innerHTML){
ersts++;
document.getElementById("dstots").rows[5].style.backgroundColor="red";}

if(mcalls!=document.getElementById("dstots").rows[6].cells[1].innerHTML){
ersts++;
document.getElementById("dstots").rows[6].style.backgroundColor="red";}

if(pcalls!=document.getElementById("dstots").rows[7].cells[1].innerHTML){
ersts++;
document.getElementById("dstots").rows[7].style.backgroundColor="red";}


var ags=document.getElementById("agdetails").rows[3].cells[1].innerText;

var sts=0;
for(var cnt=0;cnt<aragents.length;cnt++){
if(aragents[cnt]==ags){
sts=1;}
}

if(sts==0){
ersts++;
document.getElementById("agdetails").rows[3].style.backgroundColor="red";}


var dts=document.getElementById("datepicker");
if(dts.value==""){
ersts++;
dts.style.backgroundColor="red";}

if(new Date(dts.value)=="Invalid Date"){
ersts++;
dts.style.backgroundColor="red";}

if(ersts==0){
stupds(1);}

}



function stupds(pr)
{

var dt=document.getElementById("dtd");
var ln=dt.rows.length;

for(var cnt=2;cnt<ln;cnt++){
if(document.getElementById("sales"+cnt).value=="" && document.getElementById("frees"+cnt).value==""){
dt.rows[cnt].style.display="none";}
}

document.getElementById("checkins").value="Go Back";
document.getElementById("daysm").style.display="none";
document.getElementById("uploads").disabled=false;

for(var cnt=2;cnt<ln;cnt++){
document.getElementById("sales"+cnt).disabled=true;
document.getElementById("frees"+cnt).disabled=true;}

document.getElementById("datepicker").disabled=true;
document.getElementById("terlst").disabled=true;
document.getElementById("agn").disabled=true;
document.getElementById("dtfinds").disabled=true;
}



function rests(pr)
{
var dt=document.getElementById("dtd");
var at=document.getElementById("agdetails");
var tt=document.getElementById("dstots");

document.getElementById("daysm").style.display="block";

var ln=dt.rows.length;


for(var cnt=2;cnt<ln;cnt++){
dt.rows[cnt].style.backgroundColor="#F2F2F2";
document.getElementById("sales"+cnt).style.backgroundColor="white";
document.getElementById("frees"+cnt).style.backgroundColor="white";
dt.rows[cnt].style.display="table-row";
}


for(var cnt=1;cnt<at.rows.length;cnt++){
at.rows[cnt].style.backgroundColor="#F2F2F2";}

for(var cnt=0;cnt<tt.rows.length;cnt++){
tt.rows[cnt].style.backgroundColor="white";}

document.getElementById("datepicker").style.backgroundColor="white";

for(var cnt=2;cnt<ln;cnt++){
document.getElementById("sales"+cnt).disabled=false;
document.getElementById("frees"+cnt).disabled=false;}

document.getElementById("datepicker").disabled=false;
document.getElementById("terlst").disabled=false;
document.getElementById("agn").disabled=false;
document.getElementById("dtfinds").disabled=false;
}



function sendups(pr)
{

var dt=document.getElementById("dtd");
var tt=document.getElementById("dstots");
var str;
var cn=0;
var ln=dt.rows.length;
var qtys=0;
var frees=0;
var rddcvalues=0;
var rdmrk=0;
var rdscalls=0;
var rdmcalls=0;
var rdpcalls=0;


str="actp=rduploads&rddates="+document.getElementById("datepicker").value;
str=str+"&rdagents="+encodeURIComponent(document.getElementById("agdetails").rows[3].cells[1].innerText);
str=str+"&rtdcvalues="+tt.rows[1].cells[1].innerHTML;
str=str+"&wsdcvalues="+tt.rows[2].cells[1].innerHTML;
str=str+"&rdmrks="+tt.rows[4].cells[1].innerHTML;
str=str+"&rdscalls="+tt.rows[5].cells[1].innerHTML;
str=str+"&rdmcalls="+tt.rows[6].cells[1].innerHTML;
str=str+"&rdpcalls="+tt.rows[7].cells[1].innerHTML;
str=str+"&routes="+document.getElementById("routes").value;

for(var cnt=2;cnt<ln;cnt++){
qtys=document.getElementById("sales"+cnt).value;
frees= document.getElementById("frees"+cnt).value;

if(qtys!=0 || frees!=0 && dt.rows[cnt].style.display!='none'){
str=str+"&prices"+cn+"="+dt.rows[cnt].cells[2].innerHTML;
str=str+"&items"+cn+"="+encodeURIComponent(dt.rows[cnt].cells[1].innerText);

if(qtys==""){
qtys=0;}

if(frees==""){
frees=0;}

str=str+"&qtys"+cn+"="+qtys;
str=str+"&frees"+cn+"="+frees;
cn++;
}

}

str=str+"&rws="+cn;

dt.style.display="none";
tt.style.display="none";
document.getElementById("dsms").style.display="none";
document.getElementById("agdetails").style.display="none";
document.getElementById("srg").style.display="none";
document.getElementById("fra").style.display="none";
document.getElementById("frb").style.display="none";
document.getElementById("frc").style.display="none";
document.getElementById("frd").style.display="none";
document.getElementById("fre").style.display="none";
document.getElementById("frj").style.display="none";
//document.getElementById("frca").style.display="none";

document.getElementById("tdt").style.fontSize=16;
document.getElementById("tdt").innerHTML="Uploading...";


var httpr= new XMLHttpRequest();
httpr.onreadystatechange=function(){
if(httpr.readyState==4 && httpr.status==200){
var tmps=httpr.responseText.split("####");
if(tmps[0]=="errors"){
document.getElementById("tdt").style.fontSize=16;
alert("Upload not successful<br><br>Check the data");}
if(tmps[0]=="oks"){
document.getElementById("tdt").style.fontSize=16;
document.getElementById("tdt").innerHTML="Upload successful<br><br>Your reference: "+tmps[1]+"<a href='#?invoices="+tmps[1]+"&dates="+tmps[2]+"'> (Open)</a><br>"+tmps[3];
}

}}
httpr.open("POST","dbopensalesuploads.php",true);
httpr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpr.send(str);
document.getElementById("uploads").disabled=true;

//document.write(str);
}


function sranges(pr)
{
var keys=pr.keyCodes;
var dt=document.getElementById("dtd");
var ln=dt.rows.length;

if(keys==8){
pr.preventDefault();}

var vl=pr.target.options[pr.target.selectedIndex].value;

if(vl=='All'){
for(var cnt=2;cnt<ln;cnt++){
dt.rows[cnt].style.display="table-row";}
}

if(vl!='All'){
for(var cnt=2;cnt<ln;cnt++){
dt.rows[cnt].style.display="none";
if(dt.rows[cnt].cells[0].innerText==vl){
dt.rows[cnt].style.display="table-row";}
}
}
}
</script>
</head>
<body style="font-family:calibri;font-size:small" onload="agentprf()">
</body>
</html>
<?php



stps('pr');
printf("<div class='sds'>");
dsrdash(1);
printf("</div>");


$conn=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");
$sqlst="select rdadds from acs where user_names='".$_SESSION['usernames']."' ";
$qry=mysqli_query($conn,$sqlst);

$rst=mysqli_fetch_row($qry);
if($rst[0]==0){
printf("<div style='position:absolute;top:100;left:200;font-size:16;'>Access Denied</div>");}
else{

printf("<div class='fts'><div><table style='font-size:13;width:100%%;border:1px solid silver;background:#F2F2F2;' id='daysm'>");
printf("<tr><td colspan='2' style='background:silver;font-size:12;'><b>Other details</b></td></tr>");
printf("<tr><td>W/S discount</td><td align='center'><input type='text' id='rtdiscs' name='rtdiscs' style='font-size:12;text-align:right;' size=4 onkeyup=\"rtdiscky(event)\" onblur=\"gfcs(this)\"></td></tr>");
printf("<tr><td>Retail Discount</td><td align='center'><input type='text' id='wsdiscs' name='wsdiscs' style='font-size:12;text-align:right;' size=4 onkeyup=\"wsdiscky(event)\" onblur=\"gfcs(this)\"></td></tr>");
printf("<tr><td>Market returns</td><td align='center'><input type='text' id='mrks' name='mrks' style='font-size:12;text-align:right;' size=4 onkeyup=\"mrkky(event)\" onblur=\"gfcs(this)\"></td></tr>");
printf("<tr><td>Schedule calls</td><td align='center'><input type='text' id='scalls' name='scalls' style='font-size:12;text-align:right;' size=4 onkeyup=\"scallky(event)\" onblur=\"gfcs(this)\"></td></tr>");
printf("<tr><td>Made calls</td><td align='center'><input type='text' id='mcalls' name='mcalls' style='font-size:12;text-align:right;' size=4 onkeyup=\"mcallky(event)\" onblur=\"gfcs(this)\"></td></tr>");
printf("<tr><td>Productive calls</td><td align='center'><input type='text' id='pcalls' name='pcalls' style='font-size:12;text-align:right;' size=4 onkeyup=\"pcallky(event)\"></td></tr>");
printf("</table></div>");

printf("<BR>");

printf("<div><table id='agdetails' style='font-size:12;border:1px solid silver;width:100%%;background:#F2F2F2;'>");
printf("<tr class='cls'><td colspan='2' style='background:silver;'><b>Area details</b></td></tr>");
printf("<tr class='cls'><td>Zone</td><td></td></tr>");
printf("<tr class='cls'><td>Region</td><td></td></tr>");
printf("<tr class='cls'><td>Agent</td><td></td></tr>");
printf("<tr class='cls'><td>Type</td><td></td></tr>");
printf("<tr class='cls'><td>Territory</td><td></td></tr>");
printf("<tr class='cls'><td>RSM</td><td></td></tr>");
printf("<tr class='cls'><td>Rep</td><td></td></tr>");
printf("<tr class='cls'><td>Route</td><td><input type='text' id='routes'></td>");
printf("</table></div>");

printf("<BR>");

printf("<table style='font-size:13;' id='dsms'><tr style='border-bottom:1px solid silver;'><td width=200><b><font color=grey>Day summary</font></td></tr></table>");
printf("<table style='font-size:13;width:100%%;'   id='dstots'>");
printf("<tr><td>Gross sales</td><td align='right'>%s</td></tr>",number_format(0,2,'.',','));
printf("<tr><td>W/S Discount</td><td align='right'>%s</td></tr>",number_format(0,2,'.',','));
printf("<tr><td>Retail Discount</td><td align='right'>%s</td></tr>",number_format(0,2,'.',','));
printf("<tr><td>Net sales</td><td align='right'>%s</td></tr>",number_format(0,2,'.',','));
printf("<tr><td>Market return</td><td align='right'>%s</td></tr>",number_format(0,2,'.',','));
printf("<tr><td>Schedule calls</td><td align='right'>%s</td></tr>",number_format(0,2,'.',','));
printf("<tr><td>Made calls</td><td align='right'>%s</td></tr>",number_format(0,2,'.',','));
printf("<tr><td>Productive calls</td><td align='right'>%s</td></tr>",number_format(0,2,'.',','));
printf("<tr></tr><tr><td colspan='2' align='center'><br>
<input type='button' value='Check in' id='checkins' style='width:95%%;color:#0066cc;background:white;border-radius:3px;font-weight:bold;border:1px solid #0066cc;height:100%%;'
 onmouseover=\"this.style.backgroundColor='#0066cc';this.style.color='white';\" onmouseout=\"this.style.backgroundColor='white';this.style.color='#0066cc';\" onclick=\"scacts(1)\"></td></tr>");
printf("<tr></tr><tr><td colspan='2' align='center'><br>
<input type='button' value='Upload now' id='uploads' disabled style='width:95%%;color:#0066cc;background:white;border-radius:3px;font-weight:bold;border:1px solid #0066cc;height:100%%;'
 onmouseover=\"this.style.backgroundColor='#0066cc';this.style.color='white';\" onmouseout=\"this.style.backgroundColor='white';this.style.color='#0066cc';\" onclick=\"sendups(1)\"></td></tr>");
printf("</table></table>");



printf("</div><div class='srg' id='srg'></div>");
printf("<div class='mains'>");

$conn=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");
printf("<div class='fra' id='fra'>Date</div><div class='frb' id='frb'><input type='text' size=10 class='starts'  name='starts' value='%s' id='datepicker'></div>",$starts);
printf("<div class='frc' id='frc' style='left:20%%;'>Territory</div><div class='frd' id='frd' style='left:26%%;'><input type='text class='ends' size=25 name='agn' id='agn' onkeyup=\"agsrcs(event)\" onclick=\"agsrcs(event)\"></div>");
printf("<div class='fre' id='fre' style='left:75%%;top:18;'>Search</div><div class='frj' id='frj' style='left:80%%;'><input type='text' id='dtfinds' onchange=\"fdtfinds(event)\" onkeyup=\"fdtfinds(event)\" onclick=\"fdtfinds(event)\"></div>");
printf("<div class='frca' id='frcs' style='left:26%%;'><select id='terlst' onchange=\"selterr(event)\" onkeydown=\"selterr(event)\" onclick=\"selterrclk(event)\" style='z-index:1;display:none;'><option>All</option></select></div>");


printf("<div class='tdt' id='tdt' style='width:100%%;'><br><table id='dtd' style='font-size:13;border:1px solid silver;'><th border='white' bgcolor='silver' colspan='6' style='border:1px solid white;'><b>Open Stock</th>");
#printf("<tr bgcolor='grey' style='color:#E6E6E6;font-weight:bold;font-size:14;'><td width=15%% align='center'  style='border:1px solid white' >Range</td>");
printf("<tr bgcolor='grey' style='color:#E6E6E6;font-weight:bold;font-size:14;'><td width=15%% align='center'  style='border:1px solid white' >");
printf("<select id='sranges' onchange=\"sranges(event)\" style='border:1px solid grey;background:silver;'><option>All</option>");
$sqlst="select distinct item_ranges from itemsmrd where item_status='ACTIVE' order by item_ranges";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
printf("<option>%s</option>",$rst[0]);}
printf("</select></td>");

printf("<td width=40%% align='center'  style='border:1px solid white' >Item</td><td width=10%% align='center'  style='border:1px solid white' >Rate</td>
<td width=10%% align='center'  style='border:1px solid white' >Open Qty (pcs)</td><td width=10%% align='center' style='border:1px solid white' >Free issue(pcs)</td>");
printf("<td width=10%% align='center'  style='border:1px solid white' >Sale value</td></tr>");

$sqlst="select item_ranges,sub_ranges ,item_name,whole_sale_price/rd_uom from itemsmrd where item_status='ACTIVE' order by item_ranges,sub_ranges,packet_weight,item_name";

#echo $sqlst;
$qry=mysqli_query($conn,$sqlst);


$cnt=1;

while($rst=mysqli_fetch_row($qry)){
$cnt++;
printf("<tr class='cls' style='background:#F2F2F2;'><td>%s</td><td>%s</td><td align='right' style='padding-right:2%%;'>%s</td><td align='center'><input type='text' size=6  style='text-align:right;font-sie:12;' id='sales%s' onkeydown=\"trdns(event)\" onkeyup=\"stqtys(event)\" onfocus=\"onfcs(this.parentNode.parentNode.rowIndex)\" onblur=\"outfcs(this)\"></td><td align='center'><input type='text' size=6 id='frees%s' style='text-align:right;font-sie:13;' onkeydown=\"stfrs(event)\" onfocus=\"onfcs(this.parentNode.parentNode.rowIndex)\" onblur=\"outfcs(this)\"></td><td align='right'></td></tr>",
$rst[0],$rst[2],number_format($rst[3],2,'.',',') ,$cnt,$cnt);
}
}
printf("</div>");



?>