Update fundraising dashboard tables to be live

Add a colour_to_percent converter to calculate colour ranges between 0 and 100, ranging from red to green through yellow
Remove the query output from donors search results
This commit is contained in:
james 2009-10-06 21:00:12 +00:00
parent a4d4cc11cc
commit 6c61b26b1f
3 changed files with 88 additions and 24 deletions

View File

@ -25,6 +25,7 @@
require("../common.inc.php");
require_once("../user.inc.php");
user_auth_required('committee', 'admin');
echo "<br />\n";
//$q=mysql_query("SELECT * FROM award_sponsors WHERE year='".$config['FAIRYEAR']."' ORDER BY organization");
//we want to show all years, infact that year field probably shouldnt even be there.
@ -38,7 +39,7 @@
$sql.=") ";
}
$query="SELECT * FROM sponsors WHERE 1 $sql ORDER BY organization";
echo "query=$query";
// echo "query=$query";
$q=mysql_query($query);

View File

@ -40,39 +40,83 @@ $(document).ready(function() {
</script>
<h3><?=i18n("Fundraising Goals and Progress Year to Date")?></h3>
<?
$q=mysql_query("SELECT * FROM fundraising_goals WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY deadline");
?>
<table class="tableview">
<tr>
<th>Goal</th>
<th>Budget Amount</th>
<th>Amount Received</th>
<th>% to Budget</th>
<th>Deadline</th>
</tr>
<tr>
<td>Science Fair - Operating</td><td>5000</td><td>3000</td><td>60%</td><td>March 30 2010</td></tr>
<td>Science Fair - Awards</td><td>1000</td><td>650</td><td>65%</td><td>December 1 2000</td></tr>
<td>Science Olympics</td><td>5000</td><td>3000</td><td>20%</td><td>July 30 2010</td></tr>
<th><?=i18n("Goal")?></th>
<th><?=i18n("Budget Amount")?></th>
<th><?=i18n("Amount Received")?></th>
<th><?=i18n("% to Budget")?></th>
<th><?=i18n("Deadline")?></th>
</tr>
<?
while($r=mysql_fetch_object($q)) {
//lookup all donations made towards this goal
$recq=mysql_query("SELECT SUM(value) AS received FROM fundraising_donations WHERE fundraising_goal='$r->goal' AND fiscalyear='{$config['FISCALYEAR']}' AND status='received'");
echo mysql_error();
$recr=mysql_fetch_object($recq);
$received=$recr->received;
if($r->budget)
$percent=round($received/$r->budget*100,1);
else
$percent=0;
echo "<tr><td>$r->name</td>";
echo "<td style=\"text-align: right;\">".format_money($r->budget,false)."</td>";
echo "<td style=\"text-align: right;\">".format_money($received,false)."</td>";
$col=colour_to_percent($percent);
echo "<td style=\"text-align: center; background-color: $col;\">{$percent}%</td>";
echo "<td>".format_date($r->deadline)."</td></tr>\n";
}
?>
</table>
<br />
<h3><?=i18n("Current Campaigns")?></h3>
<table class="tableview">
<tr>
<th>Name</th>
<th>Type</th>
<th>Start Date</th>
<th>End Date</th>
<th>Goal</th>
<th>Target($)</th>
<th>Received</th>
<th>% to Budget</th>
<th><?=i18n("Name")?></th>
<th><?=i18n("Type")?></th>
<th><?=i18n("Start Date")?></th>
<th><?=i18n("End Date")?></th>
<th><?=i18n("Goal")?></th>
<th><?=i18n("Target($)")?></th>
<th><?=i18n("Received")?></th>
<th><?=i18n("% to Budget")?></th>
</tr>
<tr>
<td>Parents</td><td>Mailing</td><td>December 1 2009</td><td>March 31 2010</td><td>Science Fair - Operating</td><td>1000</td><td>300</td><td>30%</td></tr>
<td>Business - Cash</td><td>Personal</td><td>September 1 2009</td><td>December 1 2009</td><td>Science Fair - Awards</td><td>1000</td><td>650</td><td>65%</td></tr>
<td>Business - Cash</td><td>Personal</td><td>Descember 1 2009</td><td>March 31 2010</td><td>Science Fair - Operating</td><td>3000</td><td>2700</td><td>90%</td></tr>
<td>Business - In-kind</td><td>Phone</td><td>January 1 2010</td><td>February 28 2010</td><td>Science Fair - Operating</td><td>1000</td><td>0</td><td>0%</td></tr>
<?
$q=mysql_query("SELECT * FROM fundraising_campaigns WHERE fiscalyear='{$config['FISCALYEAR']}'");
while($r=mysql_fetch_object($q)) {
$goalq=mysql_query("SELECT * FROM fundraising_goals WHERE goal='{$r->fundraising_goal}' AND fiscalyear='{$config['FISCALYEAR']}'");
$goalr=mysql_fetch_object($goalq);
$recq=mysql_query("SELECT SUM(value) AS received FROM fundraising_donations WHERE fundraising_campaigns_id='$r->id' AND fiscalyear='{$config['FISCALYEAR']}' AND status='received'");
echo mysql_error();
$recr=mysql_fetch_object($recq);
$received=$recr->received;
if($r->budget)
$percent=round($received/$r->target*100,1);
else
$percent=0;
$col=colour_to_percent($percent);
echo "<tr>\n";
echo " <td>$r->name</td>\n";
echo " <td>$r->type</td>\n";
echo " <td>".format_date($r->startdate)."</td>\n";
echo " <td>".format_date($r->enddate)."</td>";
echo " <td>$goalr->name</td>";
echo " <td style=\"text-align: right;\">".format_money($r->target,false)."</td>\n";
echo " <td style=\"text-align: right;\">".format_money($received,false)."</td>\n";
echo " <td style=\"text-align: center; background-color: $col;\">{$percent}%</td>\n";
echo "</tr>\n";
}
?>
</tr>
</table>
<br />

View File

@ -1188,5 +1188,24 @@ function error_($str, $i18n_array=array(), $timeout=-1)
notice_($str, $i18n_array, $timeout, 'error');
}
//this function returns a HTML colour code ranging between red and green, with yellow in the middle based on the percent passed into it
function colour_to_percent($percent) {
//0 is red
//50 is yellow
//100 is green
if($percent<=50) $red=255;
else $red=(100-$percent)*2/100*255;;
if($percent>50) $green=255;
else $green=($percent)*2/100*255;;
// echo "red=$red";
// echo "green=$green";
$str="#".sprintf("%02s",dechex($red)).sprintf("%02s",dechex($green))."00";
return $str;
}
?>