get("invalid parameters"); die(); } } /** * Get a 2d array of the families in the database. * @global type $database * @param string $filter * @return string */ function getPeopleReport($filter = ""): Report { global $database, $Strings; if (empty($filter)) { $report = new Report($Strings->get("People", false)); $filter = ["ORDER" => ["familyname" => "ASC"]]; } else { $report = new Report($Strings->get("$filter", false)); } $join = []; $where = []; $header = []; switch ($filter) { case "Campers": $join = ["[>]campers" => ["camperid" => "camperid"]]; $where = ["people.camperid[!]" => null]; $header = [ $Strings->get("First", false), $Strings->get("Last", false), $Strings->get("Parent", false), $Strings->get("Unit", false), $Strings->get("Rank", false), $Strings->get("Phone", false), $Strings->get("Email", false), $Strings->get("Address", false), $Strings->get("ZIP", false), $Strings->get("Shirt", false), $Strings->get("Sex", false), $Strings->get("Den", false), $Strings->get("Health", false), $Strings->get("Notes", false) ]; break; case "Adults": $join = ["[>]adults" => ["adultid" => "adultid"]]; $where = ["people.adultid[!]" => null]; $header = [ $Strings->get("First", false), $Strings->get("Last", false), $Strings->get("Phone", false), $Strings->get("Email", false), $Strings->get("Address", false), $Strings->get("ZIP", false), $Strings->get("Days", false), $Strings->get("Position", false), $Strings->get("Shirt", false), $Strings->get("Sex", false), $Strings->get("Child Care Ages", false), $Strings->get("Notes", false) ]; break; case "Youth": $join = ["[>]youth" => ["youthid" => "youthid"]]; $where = ["people.youthid[!]" => null]; $header = [ $Strings->get("First", false), $Strings->get("Last", false), $Strings->get("Parent", false), $Strings->get("Phone", false), $Strings->get("Parent Phone", false), $Strings->get("Email", false), $Strings->get("Address", false), $Strings->get("ZIP", false), $Strings->get("Days", false), $Strings->get("Position", false), $Strings->get("Shirt", false), $Strings->get("Sex", false), $Strings->get("Notes", false) ]; break; default: $header = [ $Strings->get("First", false), $Strings->get("Last", false), $Strings->get("Type", false), $Strings->get("Phone", false), $Strings->get("Email", false), $Strings->get("Address", false), $Strings->get("ZIP", false), $Strings->get("Shirt", false), $Strings->get("Sex", false), $Strings->get("Notes", false) ]; } if (empty($join)) { $people = $database->select("people", '*', $where); } else { $people = $database->select("people", $join, '*', $where); } $report->setHeader($header); foreach ($people as $p) { $row = []; $type = "Unknown"; if (!empty($p['camperid'])) { $type = $Strings->get("Camper", false); } else if (!empty($p['adultid'])) { $type = $Strings->get("Adult", false); } else if (!empty($p['youthid'])) { $type = $Strings->get("Youth", false); } switch ($filter) { case "Campers": $row = [ $p['firstname'], $p['lastname'], $p['parentname'], $p['unit'], $p['rank'], $p['phone1'], $p['email'], $p['address'], $p['zip'], $p['shirt'], $p['sex'], $p['den'], $p['health'], $p['notes'] ]; break; case "Adults": $row = [ $p['firstname'], $p['lastname'], $p['phone1'], $p['email'], $p['address'], $p['zip'], $p['days'], $p['position'], $p['shirt'], $p['sex'], $p['child_care'], $p['notes'] ]; break; case "Youth": $row = [ $p['firstname'], $p['lastname'], $p['parentname'], $p['phone1'], $p['phone2'], $p['email'], $p['address'], $p['zip'], $p['days'], $p['position'], $p['shirt'], $p['sex'], $p['notes'] ]; break; default: $row = [ $p['firstname'], $p['lastname'], $type, $p['phone1'] . (empty($p['phone2']) ? "" : " " . $p['phone2']), $p['email'], $p['address'], $p['zip'], $p['shirt'], $p['sex'], $p['notes'] ]; } $report->addDataRow($row); } return $report; } /** * Get a report of the children who need child care. * @global type $database * @return string */ function getChildCareReport(): Report { global $database, $Strings; if (empty($filter)) { $report = new Report($Strings->get("Child Care Ages", false)); $filter = ["ORDER" => ["familyname" => "ASC"]]; } else { $report = new Report($Strings->get("$filter", false)); } $join = []; $where = []; $header = [ $Strings->get("Age", false), $Strings->get("Count", false) ]; $results = $database->select("adults", 'child_care', ["child_care[!]" => null]); $report->setHeader($header); $ages = []; $totalcount = 0; foreach ($results as $r) { $items = preg_split("/[^\d]+/", $r); foreach ($items as $it) { if (!isset($ages[$it])) { $ages[$it] = 1; } else { $ages[$it]++; } $totalcount++; } } ksort($ages); foreach ($ages as $age => $count) { $report->addDataRow(["$age", "$count"]); } $report->addDataRow([$Strings->get("Total", false), "$totalcount"]); return $report; } /** * Get a report of the families who still owe money. * @global type $database * @return string */ function getPaymentReport($filter = ""): Report { global $database, $Strings; $report = new Report($Strings->get("Payments" . ($filter == "due" ? " 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) { if ($filter == "due" && $p["amount"] - $p["amountpaid"] <= 0) { continue; } $familynames = $database->select('people', 'lastname', ['familyid' => $p['familyid']]); $firstnames = $database->select('people', 'firstname', ['familyid' => $p['familyid']]); if (count($familynames) == 0 && $p["amount"] == 0 && $p["amountpaid"] == 0) { continue; } $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": return getPeopleReport("Campers"); break; case "adults": return getPeopleReport("Adults"); break; case "youth": return getPeopleReport("Youth"); break; case "people": return getPeopleReport(""); break; case "childcare": return getChildCareReport(); break; case "payments": return getPaymentReport(); break; case "paymentsdue": return getPaymentReport("due"); break; default: return new Report("error", ["ERROR"], ["Invalid report type."]); } } function generateReport($type, $format) { $report = getReport($type); $report->output($format); }