Add child_care field for adults with young children
This commit is contained in:
parent
16425c5cbb
commit
56526cb8ce
13
action.php
13
action.php
@ -58,6 +58,7 @@ switch ($VARS['action']) {
|
||||
"den" => "",
|
||||
"health" => "",
|
||||
"notes" => "",
|
||||
"child_care" => null,
|
||||
"position" => ""
|
||||
];
|
||||
if (!empty($VARS['personid']) && $database->has("people", ['personid' => $VARS['personid']])) {
|
||||
@ -204,9 +205,18 @@ switch ($VARS['action']) {
|
||||
}
|
||||
break;
|
||||
case "adult":
|
||||
if (!empty($people["child_care"])) {
|
||||
$items = preg_split("/[^\d]+/", $people["child_care"]);
|
||||
$ages = [];
|
||||
foreach ($items as $it) {
|
||||
$ages[] = $it;
|
||||
}
|
||||
$people["child_care"] = implode(",", $ages);
|
||||
}
|
||||
$data = [
|
||||
"position" => $people["position"],
|
||||
"days" => $days
|
||||
"days" => $days,
|
||||
"child_care" => empty($people["child_care"]) ? null : $people["child_care"]
|
||||
];
|
||||
if ($editing) {
|
||||
$database->update("adults", $data, ['adultid' => $person['adultid']]);
|
||||
@ -255,7 +265,6 @@ switch ($VARS['action']) {
|
||||
} else {
|
||||
$database->insert("people", $data);
|
||||
}
|
||||
|
||||
} catch (Exception $ex) {
|
||||
errorBack($ex->getMessage());
|
||||
}
|
||||
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -33,6 +33,9 @@
|
||||
"Den": "Den",
|
||||
"Health": "Health",
|
||||
"Notes": "Notes",
|
||||
"Child Care Ages": "Child Care Ages",
|
||||
"Age": "Age",
|
||||
"Count": "Count",
|
||||
"Total": "Total",
|
||||
"Yes": "Yes",
|
||||
"No": "No",
|
||||
|
@ -29,7 +29,7 @@ if (LOADED) {
|
||||
/**
|
||||
* Get a 2d array of the families in the database.
|
||||
* @global type $database
|
||||
* @param array $filter Medoo WHERE clause.
|
||||
* @param string $filter
|
||||
* @return string
|
||||
*/
|
||||
function getPeopleReport($filter = ""): Report {
|
||||
@ -80,6 +80,7 @@ function getPeopleReport($filter = ""): Report {
|
||||
$Strings->get("Position", false),
|
||||
$Strings->get("Shirt", false),
|
||||
$Strings->get("Sex", false),
|
||||
$Strings->get("Child Care Ages", false),
|
||||
$Strings->get("Notes", false)
|
||||
];
|
||||
break;
|
||||
@ -168,6 +169,7 @@ function getPeopleReport($filter = ""): Report {
|
||||
$p['position'],
|
||||
$p['shirt'],
|
||||
$p['sex'],
|
||||
$p['child_care'],
|
||||
$p['notes']
|
||||
];
|
||||
break;
|
||||
@ -208,6 +210,62 @@ function getPeopleReport($filter = ""): Report {
|
||||
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;
|
||||
}
|
||||
|
||||
function getReport($type): Report {
|
||||
switch ($type) {
|
||||
case "campers":
|
||||
@ -222,6 +280,9 @@ function getReport($type): Report {
|
||||
case "people":
|
||||
return getPeopleReport("");
|
||||
break;
|
||||
case "childcare":
|
||||
return getChildCareReport();
|
||||
break;
|
||||
default:
|
||||
return new Report("error", ["ERROR"], ["Invalid report type."]);
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ $data = [
|
||||
"days" => "",
|
||||
"den" => "",
|
||||
"health" => "",
|
||||
"notes" => ""
|
||||
"notes" => "",
|
||||
"child_care" => ""
|
||||
];
|
||||
$type = "camper";
|
||||
if (!empty($VARS['type']) && preg_match("/(camper|adult|youth)/", $VARS['type'])) {
|
||||
@ -58,7 +59,7 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
|
||||
$data = array_merge($data, $database->get('campers', ['parentname', 'rank', 'den', 'health'], ['camperid' => $data["camperid"]]));
|
||||
} else if (!empty($data["adultid"])) {
|
||||
$type = "adult";
|
||||
$data = array_merge($data, $database->get('adults', ['days', 'position'], ['adultid' => $data["adultid"]]));
|
||||
$data = array_merge($data, $database->get('adults', ['days', 'position', 'child_care'], ['adultid' => $data["adultid"]]));
|
||||
} else if (!empty($data["youthid"])) {
|
||||
$type = "youth";
|
||||
$data = array_merge($data, $database->get('youth', ['days', 'position', 'parentname'], ['youthid' => $data["youthid"]]));
|
||||
@ -382,6 +383,17 @@ if (!empty($VARS['id']) && $database->has('people', ['personid' => $VARS['id']])
|
||||
]
|
||||
]);
|
||||
}
|
||||
if ($type == "adult") {
|
||||
$textboxes = array_merge($textboxes, [
|
||||
[
|
||||
"label" => "Child care ages",
|
||||
"name" => "child_care",
|
||||
"optional" => true,
|
||||
"width" => 6,
|
||||
"value" => $data["child_care"]
|
||||
],
|
||||
]);
|
||||
}
|
||||
$textboxes = array_merge($textboxes, [
|
||||
[
|
||||
"label" => "Notes",
|
||||
|
@ -15,7 +15,7 @@
|
||||
</h3>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-3">
|
||||
<div class="col-12 col-md-3 mb-4">
|
||||
<h4><?php $Strings->get("Campers"); ?></h4>
|
||||
<a class="btn btn-success mb-1" href="./lib/reports.php?type=campers&format=ods">
|
||||
<i class="fas fa-table"></i> <?php $Strings->get("Spreadsheet (ODS)"); ?>
|
||||
@ -29,7 +29,7 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-3">
|
||||
<div class="col-12 col-md-3 mb-4">
|
||||
<h4><?php $Strings->get("Adults"); ?></h4>
|
||||
<a class="btn btn-success mb-1" href="./lib/reports.php?type=adults&format=ods">
|
||||
<i class="fas fa-table"></i> <?php $Strings->get("Spreadsheet (ODS)"); ?>
|
||||
@ -43,7 +43,7 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-3">
|
||||
<div class="col-12 col-md-3 mb-4">
|
||||
<h4><?php $Strings->get("Youth"); ?></h4>
|
||||
<a class="btn btn-success mb-1" href="./lib/reports.php?type=youth&format=ods">
|
||||
<i class="fas fa-table"></i> <?php $Strings->get("Spreadsheet (ODS)"); ?>
|
||||
@ -57,7 +57,7 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-3">
|
||||
<div class="col-12 col-md-3 mb-4">
|
||||
<h4><?php $Strings->get("People"); ?></h4>
|
||||
<a class="btn btn-success mb-1" href="./lib/reports.php?type=people&format=ods">
|
||||
<i class="fas fa-table"></i> <?php $Strings->get("Spreadsheet (ODS)"); ?>
|
||||
@ -70,6 +70,20 @@
|
||||
<i class="fas fa-file-csv"></i> <?php $Strings->get("CSV"); ?>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-md-3 mb-4">
|
||||
<h4><?php $Strings->get("Child Care Ages"); ?></h4>
|
||||
<a class="btn btn-success mb-1" href="./lib/reports.php?type=childcare&format=ods">
|
||||
<i class="fas fa-table"></i> <?php $Strings->get("Spreadsheet (ODS)"); ?>
|
||||
</a>
|
||||
<br />
|
||||
<a class="btn btn-orange btn-sm mr-1" href="./lib/reports.php?type=childcare&format=html">
|
||||
<i class="fab fa-html5"></i> <?php $Strings->get("HTML"); ?>
|
||||
</a>
|
||||
<a class="btn btn-secondary btn-sm" href="./lib/reports.php?type=childcare&format=csv">
|
||||
<i class="fas fa-file-csv"></i> <?php $Strings->get("CSV"); ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -160,6 +160,14 @@ $database->action(function($database) {
|
||||
$dueusd += 10.0;
|
||||
}
|
||||
}
|
||||
if (!empty($people["child_care"][$pid])) {
|
||||
$items = preg_split("/[^\d]+/", $people["child_care"][$pid]);
|
||||
$ages = [];
|
||||
foreach ($items as $it) {
|
||||
$ages[] = $it;
|
||||
}
|
||||
$people["child_care"][$pid] = implode(",", $ages);
|
||||
}
|
||||
$database->insert("adults", [
|
||||
"position" => $people["position"][$pid],
|
||||
"days" => $days,
|
||||
|
Loading…
x
Reference in New Issue
Block a user