<?php
include_once('includes.php');
include_once('mysqlUtils.php');
session_start();
$_GET['events'] = implode(',',$eventIDs);
$salesArray = array();
$caraSalesArray = array();
$totalSales = 0;
$totalGoals = 0;
$totalPace = 0;
$top = 0;
$event = mysql_fetch_assoc(mysql_query('SELECT eventID,numSalesman,saleStartDate FROM ps_dealerevents where eventID in (' . $_GET['events'] . ') ORDER BY eventID'));
$apptTbl = 'ps_appointments_' . date("my",strtotime($event['saleStartDate']));
//WITH DEALER NAME///////////
$sql = 'SELECT * FROM
(SELECT eventID,challengeSalesrep,count(*) as salesCount FROM ' . $apptTbl . ' WHERE eventID in (' . $_GET['events'] . ') AND (sold1 is not null AND sold1 != "") group by challengeSalesrep,eventID) as t1
RIGHT JOIN
(SELECT * FROM
(SELECT * FROM
(SELECT dealerID,eventID FROM ps_dealerevents WHERE eventID in (' . $_GET['events'] . ')) as ttt1
INNER JOIN
(SELECT dealerID,dealerName FROM ps_dealers) as ttt2
USING
(dealerID)) as tt1
INNER JOIN
(SELECT * FROM ps_salesrep) as tt2
USING (dealerID)) as t2
ON
(t1.challengeSalesrep = t2.name AND t1.eventID = t2.eventID)';
//////////////////////////////
$exportArray = array();
for($i = 1;$i <=3;$i++)
{
$sql = 'SELECT * FROM
(SELECT eventID,challengeSalesrep,count(*) as salesCount FROM ' . $apptTbl . ' WHERE eventID in (' . $_GET['events'] . ') AND (sold' . $i . ' is not null AND sold' . $i . ' != "") group by challengeSalesrep,eventID) as t1
RIGHT JOIN
(SELECT * FROM
(SELECT dealerID,eventID FROM ps_dealerevents WHERE eventID in (' . $_GET['events'] . ')) as tt1
INNER JOIN
(SELECT * FROM ps_salesrep) as tt2
USING (dealerID)) as t2
ON
(t1.challengeSalesrep = t2.name AND t1.eventID = t2.eventID)';
$results = mysql_query($sql);
while($salesrep = mysql_fetch_assoc($results))
{
$exportArray[] = array('name' => $salesrep['name'],
'eventID' => $salesrep['eventID'],
'goal' => $salesrep['goal'],
'count' => $salesrep['salesCount'],
'salesrepID' => $salesrep['salesrepID']);
}
}
$dataArray = $exportArray;
foreach($dealerships as $dealer)
{
$t = $dealer.'Total';
$$t = 0;
}
foreach($dataArray as $salesrep)
{
$salesArray[$salesrep['salesrepID']]['info'] = $salesrep;
$salesArray[$salesrep['salesrepID']]['count'] = $salesArray[$salesrep['salesrepID']]['count'] + $salesrep['count'];
$salesArray[$salesrep['salesrepID']]['pace'] = $salesArray[$salesrep['salesrepID']]['count'] - $salesrep['goal'];
//$salesArray[$salesrep['salesrepID']] = $tempArray;
$totalGoals += $salesrep['goal'];
$totalSales += $salesrep['count'];
$t = $dealerEvents[$salesrep['eventID']] . 'Total';
$$t += $salesrep['count'];
}
foreach($dealerships as $dealer)
{
$t = $dealer.'Total';
$flashVar .= $dealer . 'Sold=' . $$t . '&';
}
////////////////////////////////
//REGULAR LOGIN/////////////////
////////////////////////////////
/*
include_once('mysqlUtils.php');
$start = '2009-08-01';
$end = '2009-08-31';
if($end < date('Y-m-d')) $today = 31;
else if($start < date('Y-m-d')) $today = date('d');
else $today = 1;
//$today = 16;
$salespersonResults = mysql_query('SELECT * FROM urseprivatesalechallenge_salesperson');
$flashVar = "";
foreach($dealerships as $dealer)
{
$t = $dealer.'Total';
$$t = 0;
$caraT = $dealer.'CaraTotal';
$$caraT = 0;
}
while($salesperson = mysql_fetch_assoc($salespersonResults))
{
$salesArray[$salesperson['salespersonID']]['info'] = $salesperson;
$salesArray[$salesperson['salespersonID']]['count'] = 0;
$totalGoals += $salesperson['goal'];
}
$salesResults = mysql_query('SELECT salesman, count(*) as salesmanCount FROM urseprivatesalechallenge_sales GROUP BY salesman');
while($sales = mysql_fetch_assoc($salesResults))
{
$salesArray[$sales['salesman']]['count'] += $sales['salesmanCount'];
$totalSales += $sales['salesmanCount'];
}
foreach($salesArray as $salesmanID => $info)
{
//$salesArray[$salesmanID]['pace'] = $info['count'] - floor(($info['info']['goal'] / 31) * ($today));
$salesArray[$salesmanID]['pace'] = $info['count'] - $info['info']['goal'];
$totalPace += $salesArray[$salesmanID]['pace'];
if($info['count'] > $top) $top = $info['count'];
foreach($dealerships as $dealer)
{
$t = $dealer.'Total';
if($info['info']['dealer'] == $dealer) $$t += $info['count'];
}
}
foreach($dealerships as $dealer)
{
$t = $dealer.'Total';
$flashVar .= $dealer . 'Sold=' . $$t . '&';
}
//$flashVar .= 'appointments=' . file_get_contents("http://96.53.92.6:8080/appointments/index.php?e=urseprivatesalechallenge&getTotal=") . '&';
//$flashVar .= 'appointments=0&';
*/
function salesSort($a,$b)
{
if($a['info']['eventID'] == $b['info']['eventID']) return $a['count'] < $b['count'];
return $a['info']['eventID'] < $b['info']['eventID'];
}
function dateDiff($startDate, $endDate)
{
// Parse dates for conversion
$startArry = date_parse($startDate);
$endArry = date_parse($endDate);
// Convert dates to Julian Days
$start_date = gregoriantojd($startArry["month"], $startArry["day"], $startArry["year"]);
$end_date = gregoriantojd($endArry["month"], $endArry["day"], $endArry["year"]);
// Return difference
return round(($end_date - $start_date), 0);
}
usort($salesArray,"salesSort");
if($_SESSION['urseprivatesalechallenge']['sortASC']) $sortIcon = '<small>▼</small>';
else $sortIcon = '<small>▲</small>';
include_once('header.php');
?>
<style>
.formTbl th {color:#eeeeee;text-align:left;font-size:10pt;vertical-align:middle;padding:5px 5px;font-weight:normal}
.formTbl input {font-size:8pt}
.headerTbl {}
.headerTbl a{color:white;text-decoration:none;}
.pageTbl a,.listTbl a {color:white;text-decoration:none;font-weight:bold}
.pageTbl td {width:20px;text-align:center;font-weight:bold}
.listTbl {width:800px;;}
.listTbl th {color:#eeeeee;background-image:url('images/thBG.jpg');font-size:9pt;height:20px;vertical-align:middle}
.listTbl td {color:white;border-bottom:1px solid #cccccc;height:30px;vertical-align:middle;text-align:center}
.addTbl td {padding:5px 10px 5px 0px;text-align:left}
.addTbl td input {width:200px}
.center1 { margin-left: auto; margin-right: auto;}
div.centered {text-align: center;}
div.centered table {margin: 0 auto; text-align: left;}
</style>
<script>
function move()
{
window.location.reload();
}
</script>
<body onload="timer=setTimeout('move()',60000)">
<table cellspacing="0" cellpadding="0" class="contentTbl">
<tr>
<td style="">
<table cellspacing="0" cellpadding="0" style="width:100%">
<tr>
<td style="text-align:center;">
<br><br>
<font style="color:white;font-size:25pt;"><?= strtoupper($title) ?></font>
<!-- HTML VERSION -->
<div class="centered">
<table class="center1" cellspacing="0" cellpadding="0" style="width:800px; border:3px solid #000;">
<tr>
<td style="padding:20px">
<center>
<table cellspacing="0" cellpadding="0">
<tr>
<td style="font-size:16pt;color:white;text-align:center;">
<center>
TOTAL SALES
<br>
<div style="font-size:28pt;color:yellow;width:160px; padding:5px;border:2px solid white;text-align:center;vertical-align:middle;">
<?php
$vSoldTotal = 0;
foreach($dealerships as $dealer)
{
$t = $dealer.'Total';
$vSoldTotal += $$t;
}
?>
<?= $vSoldTotal ?>
</div>
</center>
</td>
</tr>
</table>
<br><br>
<table cellspacing="0" cellpadding="0">
<tr>
<?php
$i = 0;
$vSoldTotal = 0;
foreach($dealerships as $dealer)
{
if($i%5 == 0 && $i != 0) echo '</tr><tr>';
$i++;
$t = $dealer.'Total';
?>
<td style="padding:15px;font-size:16pt;color:white;text-align:center;">
<center>
<?= $dealer ?>
<br>
<div style="font-size:28pt;color:yellow;padding:5px;border:2px solid white;text-align:center;vertical-align:middle;">
<?= $$t?>
</div>
</center>
</td>
<?php
}
?>
</tr>
</table>
</div>
</center>
</td>
</tr>
</table>
<br>
<iframe frameborder="0" style="width:1000px;height:<?= $apptHeight ?>px;frameborder:0;border:0px;" src="../../appointments/indexEmbedHtml.php?el=<?= implode(",",$eventIDs) ?>"></iframe>
<!-- HTML VERSION -->
<table cellspacing="0" cellpadding="0" class="headerTbl">
<tr>
<td style="padding:5px 0px;font-weight:bold;vertical-align:bottom;color:white">
<a href="index.php">Salesperson Board</a>
|
<a href="sales.php">Sales Log</a>
|
<a href="index.php">Flash Version</a>
<!--
|
<a href="http://96.53.92.6:8080/appointments/index.php?e=urseprivatesalechallenge" target="_blank">Appointments Board</a>
|
<a href="map.html" target="_blank">Sales Map</a>-->
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" style="width:100%">
<tr>
<td style="font-weight:bold">Total: <?= $totalSales ?> sales</td>
</tr>
</table>
<div style="height:<?= ($perPage * 20) +25 ?>px">
<table cellspacing="0" cellpadding="0" class="listTbl">
<tr>
<th style="width:40%"><a href="?sort=salesperson">Salesperson <font style="font-weight:normal"><i>(Total: <?= count($salesArray) ?>)</i></font> <?= ($_SESSION['urseprivatesalechallenge']['sort'] == 'salesperson' ? $sortIcon : '') ?></a></th>
<th style="width:15%"><a href="?sort=dealer">Dealership <?= ($_SESSION['urseprivatesalechallenge']['sort'] == 'dealer' ? $sortIcon : '') ?></a></th>
<th style="width:15%"><a href="?sort=sales">Sales <?= ($_SESSION['urseprivatesalechallenge']['sort'] == 'sales' ? $sortIcon : '') ?></a></th>
<th style="width:15%"><a href="?sort=goal">Goal <font style="font-weight:normal"><i>(Total: <?= $totalGoals ?>)</i></font> <?= ($_SESSION['urseprivatesalechallenge']['sort'] == 'goal' ? $sortIcon : '') ?></a></th>
<th style="width:15%"><a href="?sort=pace">Pace <?= ($_SESSION['urseprivatesalechallenge']['sort'] == 'back' ? $sortIcon : '') ?></a></th>
</tr>
<?php
foreach($salesArray as $salespersonID => $salespersonInfo)
{
if($currentDealer == "")
{
$isAlternate = false;
$currentDealer = $salespersonInfo['info']['eventID'];
}
else if($currentDealer != $salespersonInfo['info']['eventID'])
{
$isAlternate = !$isAlternate;
$currentDealer = $salespersonInfo['info']['eventID'];
}
if($isAlternate) $bgColor = "#555555";
else $bgColor = "#000000";
?>
<tr style="background-color:<?= $bgColor ?>">
<td><?= $salespersonInfo['info']['name'] ?></td>
<td><?= $dealerEvents[$salespersonInfo['info']['eventID']] ?></td>
<td><?= number_format($salespersonInfo['count']) ?></td>
<td><?= $salespersonInfo['info']['goal'] ?></td>
<td><?= $salespersonInfo['pace'] ?></td>
</tr>
<?php
}
?>
<tr>
<th>Salesperson <font style="font-weight:normal"><i>(Total: <?= count($salesArray) ?>)</i></font></th>
<th></th>
<th></th>
<th>Goal <font style="font-weight:normal"><i>(Total: <?= $totalGoals ?>)</i></font></th>
<th></th>
</tr>
</table>
</div>
<?php
include_once('footer.php');
?>