really added report page
git-svn-id: svn://anubis/tipman@4 ce01c143-e732-0410-ac0e-c064f6e6c7ef
This commit is contained in:
parent
695b195432
commit
159338a18c
88
report.php
Normal file
88
report.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
include_once("vars.inc");
|
||||
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user'])) /* disallow access unless authenticated */
|
||||
{
|
||||
header("Location: $MY_SERVER/login.php");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (
|
||||
!isset($_GET['year']) && preg_match('/^\d+$/', $_GET['year'])
|
||||
)
|
||||
{
|
||||
print('<html><body>No year specified</body></html>');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Some variables */
|
||||
$user = $_SESSION['user'];
|
||||
$year = $_GET['year'];
|
||||
$tip_totals = Array();
|
||||
|
||||
/* Print some header HTML */
|
||||
print <<<EOP
|
||||
<html>
|
||||
<head>
|
||||
<title>TipMan Report for $year</title>
|
||||
</head>
|
||||
<body>
|
||||
EOP;
|
||||
|
||||
/* Do a query to get the tip totals per period */
|
||||
$dbc = connect_db();
|
||||
$qRes = do_query(<<<EOQ
|
||||
SELECT MONTH(tips.date) AS month,
|
||||
IF(DAYOFMONTH(tips.date) < 16, 1, 2) AS period,
|
||||
SUM(tips.amount) AS tip_total
|
||||
FROM tips
|
||||
WHERE user = $user
|
||||
AND YEAR(tips.date) = $year
|
||||
GROUP BY month, period;
|
||||
EOQ
|
||||
, $dbc);
|
||||
while (($row = mysql_fetch_assoc($qRes)) !== false)
|
||||
{
|
||||
$tip_totals[$row['month']][$row['period']] = $row['tip_total'];
|
||||
}
|
||||
|
||||
/* Now format the tip totals in a nice table */
|
||||
|
||||
$yearTotal = 0.0;
|
||||
print('<table border="0" cellspacing="0" cellpadding="3" style="border: solid 1px #000;">');
|
||||
print('<tr><th>Month</th><th>Period</th><th>Amount</th><th>Total</th></tr>');
|
||||
for ($monthIndex = 1; $monthIndex <= 12; $monthIndex++)
|
||||
{
|
||||
/* Get a timestamp for the current month */
|
||||
$monthTimestamp = mktime(0, 0, 0, $monthIndex, 1, $year);
|
||||
|
||||
/* Set the tip totals for each period to 0 if they are not set */
|
||||
if (!isset($tip_totals[$monthIndex][1]))
|
||||
$tip_totals[$monthIndex][1] = 0;
|
||||
if (!isset($tip_totals[$monthIndex][2]))
|
||||
$tip_totals[$monthIndex][2] = 0;
|
||||
|
||||
/* Print a row in the report table */
|
||||
print('<td>');
|
||||
printf('<td rowspan="2">%s</td>', date('F', $monthTimestamp));
|
||||
print('<td>1 - 15</td>');
|
||||
printf('<td>$%.2f</td>', $tip_totals[$monthIndex][1]);
|
||||
printf('<td rowspan="2">$%.2f</td>',
|
||||
$tip_totals[$monthIndex][1] + $tip_totals[$monthIndex][2]);
|
||||
printf('<td>16 - %d</td>', date('t', $monthTimestamp));
|
||||
printf('<td>$%.2f</td>', $tip_totals[$monthIndex][2]);
|
||||
print("</tr>\n");
|
||||
|
||||
/* Increment the year's total tips */
|
||||
$yearTotal += $tip_totals[$monthIndex][1];
|
||||
$yearTotal += $tip_totals[$monthIndex][2];
|
||||
}
|
||||
printf('<tr><td colspan="3" style="font-alignment: right; font-weight: bold;">
|
||||
Total:</td><td>$%.2f</td></tr>',
|
||||
$yearTotal);
|
||||
print('</table>');
|
||||
?>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user