added checks to report page per krissy

git-svn-id: svn://anubis/tipman@7 ce01c143-e732-0410-ac0e-c064f6e6c7ef
This commit is contained in:
Josh Holtrop 2008-09-09 01:29:21 +00:00
parent 88ee1d874e
commit 0ab217099c
2 changed files with 49 additions and 14 deletions

View File

@ -8,3 +8,7 @@ th, td {
border-right: solid 1px #000;
padding: 2px 1ex;
}
.amnt {
text-align: right;
}

View File

@ -22,6 +22,7 @@
$userID = get_userID($_SESSION['user']);
$year = $_GET['year'];
$tip_totals = Array();
$check_totals = Array();
/* Print some header HTML */
print <<<EOP
@ -50,41 +51,71 @@ EOQ
$tip_totals[$row['month']][$row['period']] = $row['tip_total'];
}
/* Now format the tip totals in a nice table */
$qRes = do_query(<<<EOQ
SELECT MONTH(checks.date) AS month,
IF(DAYOFMONTH(checks.date) < 16, 1, 2) AS period,
SUM(checks.amount) AS checks_total
FROM checks
WHERE user = $userID
AND YEAR(checks.date) = $year
GROUP BY month, period;
EOQ
, $dbc);
while (($row = mysql_fetch_assoc($qRes)) !== false)
{
$check_totals[$row['month']][$row['period']] = $row['checks_total'];
}
$yearTotal = 0.0;
/* Now format the totals in a nice table */
$yearTipTotal = 0.0;
$yearChecksTotal = 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>');
print('<tr><th>Month</th><th>Period</th><th>Tips</th><th>Checks</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 */
/* Set the 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;
if (!isset($check_totals[$monthIndex][1]))
$check_totals[$monthIndex][1] = 0;
if (!isset($check_totals[$monthIndex][2]))
$check_totals[$monthIndex][2] = 0;
/* Print a row in the report table */
print('<tr>');
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 class="amnt">$%.2f</td>', $tip_totals[$monthIndex][1]);
printf('<td class="amnt">$%.2f</td>', $check_totals[$monthIndex][1]);
printf('<td rowspan="2" class="amnt">$%.2f</td>',
$tip_totals[$monthIndex][1] + $tip_totals[$monthIndex][2] +
$check_totals[$monthIndex][1] + $check_totals[$monthIndex][2]);
print('</tr><tr>');
printf('<td>16 - %d</td>', date('t', $monthTimestamp));
printf('<td>$%.2f</td>', $tip_totals[$monthIndex][2]);
printf('<td class="amnt">$%.2f</td>', $tip_totals[$monthIndex][2]);
printf('<td class="amnt">$%.2f</td>', $check_totals[$monthIndex][2]);
print("</tr>\n");
/* Increment the year's total tips */
$yearTotal += $tip_totals[$monthIndex][1];
$yearTotal += $tip_totals[$monthIndex][2];
/* Increment the year's totals */
$yearTipTotal += $tip_totals[$monthIndex][1];
$yearTipTotal += $tip_totals[$monthIndex][2];
$yearChecksTotal += $check_totals[$monthIndex][1];
$yearChecksTotal += $check_totals[$monthIndex][2];
}
printf('<tr><td colspan="3" style="font-alignment: right; font-weight: bold;">
Total:</td><td>$%.2f</td></tr>',
$yearTotal);
printf('<tr><td colspan="2"
style="font-alignment: right; font-weight: bold;">Total:</td>
<td class="amnt">$%.2f</td>
<td class="amnt">$%.2f</td>
<td class="amnt">$%.2f</td></tr>',
$yearTipTotal,
$yearChecksTotal,
$yearTipTotal + $yearChecksTotal);
print('</table>');
?>
</body>