<?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="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>
<script>


function fdtfinds(pr)
{
var vl=document.getElementById("dtfinds").value;
var dt=document.getElementById("dtd");
var cn=dt.rows.length;
var vls=vl.toLowerCase();

for(var cnt=3;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){
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 nadditems(pr)
{

var nranges=document.getElementById("nranges").options[document.getElementById("nranges").selectedIndex].text;
var nsubranges=document.getElementById("nsubranges").options[document.getElementById("nsubranges").selectedIndex].text;
var npackets=document.getElementById("npackets").value;
var nweights=document.getElementById("nweights").value;
var nretails=document.getElementById("nretails").value;
var ndsrates=document.getElementById("ndsrates").value;
var nmrrates=document.getElementById("nmrrates").value;
var nws=document.getElementById("nws").value;

var nitems=document.getElementById("nitems").value;

var nstarts=document.getElementById("inputField").value;
var nends=document.getElementById("inputField2").value;

if(nstarts==""){
nstarts=0;}
if(nends==0){
nends=0;}

if(nitems==""){
alert("Check the item name");}
else
{
var rstr="pragentsrqst.php?actp=actions&sprftypes=nadditems&nranges="+nranges+"&nsubranges="+nsubranges+"&nitems="+encodeURIComponent(nitems)+
"&npackets="+npackets+"&nweights="+nweights+"&nretails="+nretails+"&nws="+nws+"&ndsrates="+ndsrates+"&nmrrates="+nmrrates+"&nstarts="+nstarts+"&nends="+nends;

var httpr= new XMLHttpRequest();
httpr.onreadystatechange=function(){
if(httpr.readyState==4 && httpr.status==200){
alert(httpr.responseText);

if(httpr.responseText=='Adding successful'){
alert("Adding successful");
location.reload();}
else{
alert("Adding error");}
}}


httpr.open("POST",rstr,true);
httpr.send();	
}
	
}


</script>

</head>



<body style="font-family:calibri;font-size:small" onload="mnh('amnc','agentsb')">
<div class="hdn"></div>

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

<div class="tops" align="center">P2R Zone sales summary</div>
<div class="homes"><a href="index.php" style='color:#A9BCF5;'>Sign out</a></div>

</body>

</html>




<?php

$grt=0;
$grq=0;
$arr=array();
$arvl=array();
$tvt=0;

showshps();

$starts=$_REQUEST['starts'];
$ends=$_REQUEST['ends'];
$months=date('m');
$days=date('t');
$years=date('Y');

if($starts==0 || $starts==''){
$starts=$years."-".$months."-01";}
if($ends==0 || $ends==''){
$ends=$years."-".$months."-".$days;}

printf("</div>");



if(isset($_REQUEST['zones'])){
$zones=$_REQUEST['zones'];}
else{
$zones="All";}

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

if(isset($_REQUEST['territorys'])){
$territorys=$_REQUEST['territorys'];}
else{
$territorys="All";}

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

if(isset($_REQUEST['rsms'])){
$rsms=$_REQUEST['rsms'];}
else{
$rsms="All";}

if(isset($_REQUEST['executives'])){
$executives=$_REQUEST['executives'];}
else{
$executives="All";}

if(isset($_REQUEST['reps'])){
$reps=$_REQUEST['reps'];}
else{
$reps="All";}

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

if(isset($_REQUEST['subranges'])){
$subranges=$_REQUEST['subranges'];}
else{
$subranges="All";}

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

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


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


$conn=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_diana");
$sqlst="select pradmrq from acs where user_names='".$_SESSION['usernames']."' ";
$qry=mysqli_query($conn,$sqlst);
if(mysqli_num_rows($qry)==0){
printf("Access denied");}
else{

$seflt=" where agent_name is not null and ( ";

$sesqlst="select * from acs where user_names='".$_SESSION['usernames']."'";
$seqry=mysqli_query($conn,$sesqlst);

$cnt=mysqli_num_rows($seqry);

while($serst=mysqli_fetch_row($seqry)){
$cnt--;

$seflt=$seflt." ( agent_name is not null ";

if(strtolower($serst[1])!='all'){
$seflt=$seflt." and zone='".$serst[1]."' ";}
if(strtolower($serst[2])!='all'){
$seflt=$seflt." and region='".$serst[2]."' ";}
if(strtolower($serst[3])!='all'){
$seflt=$seflt." and territory_name='".$serst[3]."' ";}
if(strtolower($serst[4])!='all'){
$seflt=$seflt." and agent_name='".$serst[4]."' ";}

$seflt=$seflt.") ";

if($cnt>0){
$seflt=$seflt." or ";}
}

$seflt=$seflt.") ";
#echo $seflt;

$rpsty="regions=".$regions."&agents=".$agents."&territorys=all&ranges=all&zones=".$zones."&rsms=All&executives=All&reps=All&items=All'"; 

printf("<form method='post' action='wptrzonesummarys.php?%s'>",$rpsty);


printf("<BR>");
print("<div style='display:block;font-size:14;' id='tdta'>");
printf("<BR><BR>");
printf("<table id='dtd' style='font-size:13;width:100%%;border:1px solid silver;'><th bgcolor='silver' colspan='2' align='center'><b>New Item creation</th>");

printf("<tr class='cls'><td>Main range</td><td><select id='nranges'>");
$sqlst="select distinct item_ranges from itemsmrd where item_status='ACTIVE' ";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
printf("<option>%s</option>",$rst[0]);}
printf("</select></td></tr>");

printf("<tr class='cls'><td>Sub range</td><td><select id='nsubranges'>");
$sqlst="select distinct sub_ranges from itemsmrd where item_status='ACTIVE' ";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){
printf("<option>%s</option>",$rst[0]);}
printf("</select></td></tr>");

printf("<tr class='cls'><td>Packets per box</td><td><input type='text' id='npackets' size=10></td></tr>");
printf("<tr class='cls'><td>Packet weight (grams)</td><td><input type='text' id='nweights' size=10></td></tr>");
printf("<tr class='cls'><td>Retail price</td><td><input type='text' id='nretails' size=10></td></tr>");
printf("<tr class='cls'><td>W/S price</td><td><input type='text' id='nws' size=10></td></tr>");
printf("<tr class='cls'><td>Discout rate (%%)</td><td><input type='text' id='ndsrates' size=10></td></tr>");
printf("<tr class='cls'><td>MR discout rate (%%)</td><td><input type='text' id='nmrrates' size=10></td></tr>");

printf("<tr class='cls'><td>Item name</td><td><input type='text' id='nitems' size=50></td></tr>");

printf("<tr><td colspan='2'>Past period for which the agent is in operation (Optional)</td></tr>");
printf("<tr class='cls'><td>From</td><td><input type='text' id='inputField' size=15></td></tr>");
printf("<tr class='cls'><td>To</td><td><input type='text' id='inputField2' size=15></td></tr>");

printf("<tr class='cls'><td>Are you sure</td><td><input type='button' value='Add Item' style='width:60%%;height:150%%;' onclick=\"nadditems(1)\">");

printf("</table><BR><BR>Remark: The new supplier profile will be linked to all the past records in Primary records for the given date range.</div>");
}


?>