<?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" 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>
<link rel="stylesheet" type="text/css" href="rdsty.css">
<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 arreps=new Array();
var arritems= new Array();
var arrprices=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];
arreps[cn]=tmpa[6];}
itemprf();
}}
httpr.open("POST","pragentsrqst.php?actp=items&sprftypes=mrsales",true);
httpr.send();

}



function itemprf()
{
	
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("###");
arritems[cn]=tmpa[0];
arrprices[cn]=tmpa[1];}
}}
httpr.open("POST","pragentsrqst.php?actp=items&sprftypes=itemprf&sgtypes=marketreturns",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==27){
terlst.style.display="none";
document.getElementById("agn").focus();
}


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

if(keys==13){
terlst.size=0;
terlst.style.display="none";
document.getElementById("mdiscounts").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=arreps[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[6].cells[1].innerHTML=arrsms[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=arreps[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];
}
}

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




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 sendups(pr)
{
var dt=document.getElementById("dtd");
var ln=dt.rows.length;

str="actp=mradds&mdates="+document.getElementById("datepicker").value;
str=str+"&magents="+encodeURIComponent(document.getElementById("agdetails").rows[3].cells[1].innerHTML);
str=str+"&mdiscounts="+document.getElementById("mdiscounts").value;
str=str+"&mcn="+ln;


for(var cnt=1;cnt<ln;cnt++){
if(dt.rows[cnt].cells[7].innerText!='Undo'){
str=str+"&items"+cnt+"="+encodeURIComponent(dt.rows[cnt].cells[0].innerHTML);
str=str+"&prices"+cnt+"="+dt.rows[cnt].cells[1].innerHTML;
str=str+"&qtys"+cnt+"="+dt.rows[cnt].cells[2].innerHTML;
str=str+"&mreasons"+cnt+"="+dt.rows[cnt].cells[4].innerHTML;
str=str+"&mactions"+cnt+"="+dt.rows[cnt].cells[5].innerHTML;
str=str+"&areas="+document.getElementById("areas").value;
}
}


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("<td>");
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("sdv").style.display="none";
document.getElementById("dva").style.display="none";
document.getElementById("tdt").style.fontSize=15;
document.getElementById("tdt").innerHTML="Upload successful<br><br>MR number: "+tmps[1]+"<a href='mrnotes.php?mrnumbers="+tmps[1]+"&dates="+tmps[2]+"' target='_blank'> (Open Return note)</a><a href='mrpdf.php?mrnumber="+tmps[1]+"&dates="+tmps[2]+"&actps=1' target='_blank'> (Open PDF)</a><br>";}

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

}




function selitems(pr)
{
var keys=window.event.keyCode;
var sitems=document.getElementById("sitems");
var tx=document.getElementById("items");
var vl=tx.value;

document.getElementById("itemslst").style.top=tx.style.top+tx.style.clientHeight;
document.getElementById("itemslst").style.left=tx.style.left;
document.getElementById("itemslst").style.display="block";



if(keys==13 && tx.length>0){
pr.preventDefault();
sitems.size=0;
sitems.style.display="none";
document.getElementById("rates").focus();
}

if(keys==40){
if(sitems.length>0){
sitems.selectedIndex=0;
sitems.focus();}

}


var cn=0;

if(keys!=13 & keys!=8){
sitems.length=0;
sitems.size=0;

for(var cnt=0;cnt<arritems.length;cnt++){
var tmpa=arritems[cnt].toLowerCase();
var tmpb=vl.toLowerCase();

var rst=tmpa.indexOf(tmpb);



if(rst>=0){
var options=document.createElement("option");
options.text=arritems[cnt];
sitems.add(options);
cn++;}
}

if(cn>30){
sitems.size=30;}
else{
sitems.size=cn;}

sitems.style.display="block";

}

}




function selitemsclk(pr)
{
var sitems=document.getElementById("sitems");
var tx=document.getElementById("items");
var vl=sitems.options[sitems.selectedIndex].value;

tx.value=vl;

for(var cnt=0;cnt<arritems.length;cnt++){
if(arritems[cnt]==tx.value){
document.getElementById("rates").value=arrprices[cnt];}}

sitems.style.display="none";
tx.focus();

}




function nselitems(pr)
{
var keys=pr.keyCode;
var sitems=document.getElementById("sitems");
var tx=document.getElementById("items");

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

if(keys==27){
sitems.style.display="none";
tx.focus();}

if(keys==13){
tx.value=sitems.options[sitems.selectedIndex].value;

for(var cnt=0;cnt<arritems.length;cnt++){
if(arritems[cnt]==tx.value){
document.getElementById("rates").value=arrprices[cnt];}}
sitems.style.display="none";
document.getElementById("rates").focus();
}


if(keys==38){
if(sitems.selectedIndex==0 || sitems.length==0){
tx.setSelectionRange(0,tx.value.length);
tx.focus();}
}


}


function nselrates(pr)
{
var keys=pr.keyCode;

if(keys==13){
document.getElementById("qtys").focus();}

}


function nselqtys(pr)
{
var keys=pr.keyCode;

var vl=document.getElementById("rates").value*document.getElementById("qtys").value;
document.getElementById("dtm").rows[1].cells[3].innerHTML=vl.toFixed(2);

if(keys==13){
document.getElementById("mreasons").focus();}
}



function nselreasons(pr)
{
var keys=pr.keyCode;

if(keys==13){
document.getElementById("mactions").focus();}

}


function nselactions(pr)
{
var keys=pr.keyCode;

if(keys==13){
document.getElementById("madds").focus();}

}



function ndiscs(pr)
{

var keys=pr.keyCode;

dtots(1);

if(keys==13){
document.getElementById("items").focus();}

}


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

document.getElementById("madds").value="Edit";

dt.rows[pr].cells[6].innerHTML="Editing...";
dt.rows[pr].style.color="orange";

document.getElementById("items").value=dt.rows[pr].cells[0].innerText;
document.getElementById("rates").value=dt.rows[pr].cells[1].innerText;
document.getElementById("qtys").value=dt.rows[pr].cells[2].innerText;
document.getElementById("dtm").rows[1].cells[3].innerHTML=dt.rows[pr].cells[3].innerText;
document.getElementById("mreasons").value=dt.rows[pr].cells[4].innerText;
document.getElementById("mactions").value=dt.rows[pr].cells[5].innerText;

for(var cnt=1;cnt<ln;cnt++){
if(cnt!=pr){
dt.rows[cnt].cells[6].innerHTML="Edit";}
}

}



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

dt.rows[pr].cells[6].innerHTML="Edit";
dt.rows[pr].cells[7].innerHTML="<a href='javascript:undos("+pr+");'>Undo</a>";

for(var rcn=0;rcn<dt.rows[pr].cells.length-1;rcn++){
dt.rows[pr].cells[rcn].innerHTML=dt.rows[pr].cells[rcn].innerHTML.strike();}

dtots(1);

}



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

dt.rows[pr].cells[7].innerHTML="<a href='javascript:dels("+pr+");'>Del</a>";

for(var rcn=0;rcn<dt.rows[pr].cells.length-1;rcn++){
dt.rows[pr].cells[rcn].innerHTML=dt.rows[pr].cells[rcn].innerText;}

dt.rows[pr].cells[6].innerHTML="<a href='javascript:edits("+pr+");'>Edit</a>";
dtots();

}





function tadds(pr)
{

var items=document.getElementById("items").value;
var qtys=document.getElementById("qtys").value;
var rates=document.getElementById("rates").value;
var reasons=document.getElementById("mreasons").options[document.getElementById("mreasons").selectedIndex].value;
var actions=document.getElementById("mactions").options[document.getElementById("mactions").selectedIndex].value;
var dt=document.getElementById("dtd");
var atypes=document.getElementById("madds").value;


var ast=0;
for(var cnt=0;cnt<arritems.length;cnt++){
if(arritems[cnt]==items){
ast++;}
}

if(atypes=="Add" && ast>0){

if(ast>0){
var rw=dtd.insertRow(-1);
rw.className="cls";
var td=rw.insertCell(-1);
td.innerHTML=items;
var td=rw.insertCell(-1);
td.innerHTML=parseFloat(rates).toFixed(2);
td.style.textAlign="right";
var td=rw.insertCell(-1);
td.style.textAlign="right";
td.innerHTML=parseFloat(qtys).toFixed(2);
td.style.paddingRight='2px';
td.style.textAlign="right";
var td=rw.insertCell(-1);
td.style.paddingRight='2px';
td.innerHTML=parseFloat((qtys*rates)).toFixed(2);
td.style.textAlign="right";
td.style.paddingRight='6px';
var td=rw.insertCell(-1);
td.innerHTML=reasons;
var td=rw.insertCell(-1);
td.innerHTML=actions;
var td=rw.insertCell(-1);
td.innerHTML="<a href='javascript:edits("+rw.rowIndex+");'>Edit</a>";
var td=rw.insertCell(-1);
td.innerHTML="<a href='javascript:dels("+rw.rowIndex+");'>Del</a>";;
}
}

if(atypes=="Edit" && ast>0){
var ecn=0;

for(var cnt=1;cnt<dt.rows.length;cnt++){
if(dt.rows[cnt].cells[6].innerText=="Editing..."){
ecn=cnt;}
}

dt.rows[ecn].cells[0].innerHTML=items;
dt.rows[ecn].cells[1].innerHTML=rates;
dt.rows[ecn].cells[2].innerHTML=qtys;
dt.rows[ecn].cells[3].innerHTML=parseFloat((qtys*rates)).toFixed(2);
dt.rows[ecn].cells[4].innerHTML=reasons;
dt.rows[ecn].cells[5].innerHTML=actions;
dt.rows[ecn].cells[6].innerHTML="<a href='javascript:edits("+ecn+");'>Edit</a>";
dt.rows[ecn].cells[7].innerHTML="<a href='javascript:dels("+ecn+");'>Del</a>";
dt.rows[ecn].style.color="Black";

for(var cnt=1;cnt<dt.rows.length;cnt++){
dt.rows[cnt].cells[6].innerHTML="<a href='javascript:edits("+cnt+");'>Edit</a>";}
document.getElementById("madds").value="Add";
}


document.getElementById("items").value="";
document.getElementById("qtys").value="";
document.getElementById("rates").value="";
document.getElementById("mreasons").selectedIndex=0;
document.getElementById("mactions").selectedIndex=0;
document.getElementById("dtm").rows[1].cells[3].innerHTML="0.00";
document.getElementById("items").focus();

dtots(1);

}


function dtots(pr)
{

var dt=document.getElementById("dtd");
var dsc=parseFloat(document.getElementById("mdiscounts").value);
var vls=0;
var rcn=0;

for(var cnt=1;cnt<dt.rows.length;cnt++){
if(dt.rows[cnt].cells[7].innerText!="Undo"){
var vls=vls+(parseFloat(dt.rows[cnt].cells[1].innerText)*parseFloat(dt.rows[cnt].cells[2].innerText));
rcn++;}
}

var discs=vls*dsc/100;

document.getElementById("dstots").rows[0].cells[1].innerHTML=vls.toFixed(2);
document.getElementById("dstots").rows[1].cells[1].innerHTML=discs.toFixed(2);
document.getElementById("dstots").rows[2].cells[1].innerHTML=(vls-discs).toFixed(2);
document.getElementById("dstots").rows[3].cells[1].innerHTML=rcn.toFixed(2);

}




function chks(pr)
{

if(document.getElementById("checkins").value=="Go back")
{
document.getElementById("datepicker").disabled=false;
document.getElementById("agn").disabled=false;
document.getElementById("mdiscounts").disabled=false;
document.getElementById("items").disabled=false;
document.getElementById("rates").disabled=false;
document.getElementById("qtys").disabled=false;
document.getElementById("mreasons").disabled=false;
document.getElementById("mactions").disabled=false;
document.getElementById("madds").disabled=false;

document.getElementById("uploads").disabled=true;
document.getElementById("checkins").value="Check in";
}
else{

var stc=0;

document.getElementById("datepicker").disabled=true;
document.getElementById("agn").disabled=true;
document.getElementById("mdiscounts").disabled=true;
document.getElementById("items").disabled=true;
document.getElementById("rates").disabled=true;
document.getElementById("qtys").disabled=true;
document.getElementById("mreasons").disabled=true;
document.getElementById("mactions").disabled=true;
document.getElementById("madds").disabled=true;


if(document.getElementById("agdetails").rows[3].cells[1].innerText.length==0){
document.getElementById("agdetails").rows[3].cells[0].style.background="red";
document.getElementById("agdetails").rows[3].cells[1].style.background="red";
stc++;}

var vl=parseFloat(document.getElementById("dstots").rows[0].cells[1].innerText);

if(isNaN(vl)){
document.getElementById("dstots").rows[0].cells[0].style.background="red";
document.getElementById("dstots").rows[0].cells[1].style.background="red";
stc++;}


if(document.getElementById("dstots").rows[0].cells[1].innerText=="" || vl==0){
document.getElementById("dstots").rows[0].cells[0].style.background="red";
document.getElementById("dstots").rows[0].cells[1].style.background="red";
stc++;}


if(document.getElementById("datepicker").value==""){
document.getElementById("datepicker").style.background="red";
stc++;}

if(document.getElementById("mdiscounts").value.length==0){
document.getElementById("mdiscounts").style.background="red";
stc++;}


if(stc==0){
document.getElementById("uploads").disabled=false;}
document.getElementById("checkins").value="Go back";
}


}


</script>

</head>

<body style="font-family:calibri;font-size:small" onload="agentprf()">
<div class="hdn"></div>

<?php
printf("<div class='ses'>%s (%s)</div>",$_SESSION['titles'],$_SESSION['positions']);
?>

<div class="tops" align="center">Market return - range summary</div>
<div class="homes"><a href="index.php" style='color:#A9BCF5;'>Sign out</a></div>

</body>

</html>




<?php



mrshowshps();

$conn=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_dianaold");
$sqlst="select mradds 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 id='dva'>");
printf("<div class='fts'><BR><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>Area</td><td><input type='text' id='areas' size=20></td></tr>");
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:14;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>Net sales</td><td align='right'>%s</td></tr>",number_format(0,2,'.',','));
printf("<tr><td>No. of items</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=\"chks(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></div>");



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


printf("<div id='sdv'><div class='fra' id='fra'>Date</div><div class='frb' id='frb' style='border-radius:2px;'><input type='text' size=10 class='starts'  name='starts' value='%s' id='datepicker' autocomplete='off'></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;'>Discount rate %%</div><div class='frj' id='frj' style='left:85%%;'><input type='text' size=2 id='mdiscounts'  style='text-align:right;' onkeydown=\"ndiscs(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></div>");


printf("<div class='tdt' id='tdt' style='width:97%%;'><br><table id='dtm' style='font-size:13;border-bottom:5px solid silver;border-left:5px solid silver;border-right:5px solid silver;background:silver;color:grey;border-radius:2px;'>");
printf("<tr style='text-align:center;'><td width=40%%>Item</td><td width=5%%>Rate</td><td width=5%%>Qty</td><td width=10%%>Value</td><td width=18%%>Reasons</td><td width=18%%>Actions</td><td width=40%%></td></tr>");


printf("<tr><td><input type='text' id='items' style='font-size:12;width:95%%;' onkeyup=\"selitems(event)\" onclick=\"selitems(event)\" ></td>
<td><input type='text' id='rates' size=6  style='font-size:12;text-align:center;' onkeydown=\"nselrates(event)\"></td><td>
<input type='text' id='qtys' size=6  style='font-size:12;text-align:right;' onkeydown=\"nselqtys(event)\"></td><td align='center'></td><td><select id='mreasons' onkeydown=\"nselreasons(event)\"><option></option>");

$sqlst="select distinct sub_reason from mreasons order by reason_orders ";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
printf("<option>%s</option>",$rst[0]);}
printf("</select></td>");

printf("<td><select id='mactions' onkeydown=\"nselactions(event)\"><option></option>");
$sqlst="select distinct action_title from mactions";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
printf("<option>%s</option>",$rst[0]);}
printf("</select></td>");

printf("<td><input type='button' value='Add' id='madds' onclick=\"tadds(event)\" style='border:1px solid grey;'></td></tr></table>");

printf("<div id='itemslst' style='position:absolute;display:none;'><select id='sitems' style='border:1px solid silver;' onkeydown=\"nselitems(event)\" onfocusout=\"this.style.display='none';\" onclick=\"selitemsclk(event)\"><option>Select</option></select></div>");


printf("<br><div id='tdts'><table style='width:100%%;font-size:13;' id='dtd'><tr class='cls' style='background:silver;'><td>Item</td><td align='center'>Rate</td><td align='center'>Qty</td><td align='center'>Value</td><td>Reason</td><td>Action</td>
<td>Edit</td><td>Delete</td></tr></table></div>");


printf("</div>");

}

?>