Files
HotLunches/invoice-payments.php
2026-10-19 15:22:52 -07:00

43 lines
1.2 KiB
PHP

<?php
include "db.php";
$Months = array();
$currYr = date("Y",time());
for ($yr = 2009; $yr <= $currYr; $yr++) {
for ($mo = 1; $mo <= 12; $mo++) {
if ($yr == 2009 && $mo < 8) continue;
$month = sprintf("%4d-%02d",$yr,$mo);
$Months[$month] = array(0,0);
}
}
$query = "SELECT SUBSTRING(payment_date,1,7) AS pdate, SUM(subtotal) AS subtotal, SUM(amount_paid) AS amount FROM invoice_header GROUP BY 1 ORDER BY pdate";
$results = db_query($query);
if (db_num_rows($results)) {
while ($row = db_fetch_assoc($results)) {
extract($row);
$Months[$pdate] = array($subtotal,$amount);
// echo("$pdate $subtotal $amount\n");
}
}
for ($yr = 2009; $yr <= $currYr; $yr++) {
$ytd = 0;
for ($mo = 1; $mo <= 12; $mo++) {
if ($yr == 2009 && $mo < 8) continue;
$month = sprintf("%4d-%02d",$yr,$mo);
$subtotal = $Months[$month][0];
$amount = $Months[$month][1];
$ytd += $subtotal;
printf("%7s %12s %12s %12s\n",$month,'$'.number_format($subtotal,2),'$'.number_format($amount,2),'$'.number_format($ytd,2));
}
printf(". . . . . %7s %12s\n",$yr,'$'.number_format($ytd,2));
}
?>