From 65e16af4f996ff042cd7b8da0466a3b1a9b3793f Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 15 Mar 2022 15:15:08 -0600 Subject: [PATCH] Add payment due report --- lib/reports.php | 46 ++++++++++++++++++++++++++++++++++++++++++++-- pages/reports.php | 14 ++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/reports.php b/lib/reports.php index e17d64d..7709581 100644 --- a/lib/reports.php +++ b/lib/reports.php @@ -233,10 +233,8 @@ function getChildCareReport(): Report { $Strings->get("Count", false) ]; - $results = $database->select("adults", 'child_care', ["child_care[!]" => null]); - $report->setHeader($header); $ages = []; @@ -266,6 +264,47 @@ function getChildCareReport(): Report { return $report; } +/** + * Get a report of the families who still owe money. + * @global type $database + * @return string + */ +function getPaymentDueReport(): Report { + global $database, $Strings; + + $report = new Report($Strings->get("Payments Due", false)); + $filter = ["ORDER" => ["familyname" => "ASC"]]; + + $join = []; + $where = []; + + $header = [ + $Strings->get("Family", false), + $Strings->get("Total", false), + $Strings->get("Paid", false), + $Strings->get("Due", false), + $Strings->get("First Names", false) + ]; + + $payments = $database->select("payments", ['familyid', 'paymentid (id)', 'amount', 'amountpaid']); + + foreach ($payments as $p) { + $familynames = $database->select('people', 'lastname', ['familyid' => $p['familyid']]); + $firstnames = $database->select('people', 'firstname', ['familyid' => $p['familyid']]); + $report->addDataRow([ + implode(", ", array_unique($familynames)), + number_format($p["amount"], 2), + number_format($p["amountpaid"], 2), + number_format($p["amount"] - $p["amountpaid"], 2), + implode(", ", $firstnames) + ]); + } + + $report->setHeader($header); + + return $report; +} + function getReport($type): Report { switch ($type) { case "campers": @@ -283,6 +322,9 @@ function getReport($type): Report { case "childcare": return getChildCareReport(); break; + case "paymentsdue": + return getPaymentDueReport(); + break; default: return new Report("error", ["ERROR"], ["Invalid report type."]); } diff --git a/pages/reports.php b/pages/reports.php index c48d228..8e55dc1 100644 --- a/pages/reports.php +++ b/pages/reports.php @@ -84,6 +84,20 @@ get("CSV"); ?> + +
+

get("Payments Still Due"); ?>

+ + get("Spreadsheet (ODS)"); ?> + +
+ + get("HTML"); ?> + + + get("CSV"); ?> + +
\ No newline at end of file