Make camp days and price adjustments configurable
This commit is contained in:
parent
97dde99d99
commit
16425c5cbb
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -43,14 +43,19 @@
|
||||
<h2 class="d-inline">
|
||||
<?php
|
||||
$daystrs = $database->select("adults", "days");
|
||||
$days = ["Tu" => 0, "We" => 0, "Th" => 0, "Fr" => 0];
|
||||
$days = $SETTINGS["camp_days"];
|
||||
foreach ($days as $short => $long) {
|
||||
$days[$short] = 0;
|
||||
}
|
||||
foreach ($daystrs as $str) {
|
||||
if ($str == "") {
|
||||
continue;
|
||||
}
|
||||
$arr = str_split($str, 2);
|
||||
foreach ($arr as $day) {
|
||||
$days[$day] += 1;
|
||||
if (array_key_exists($day, $days)) {
|
||||
$days[$day] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,14 +74,19 @@
|
||||
<h2 class="d-inline">
|
||||
<?php
|
||||
$daystrs = $database->select("youth", "days");
|
||||
$days = ["Tu" => 0, "We" => 0, "Th" => 0, "Fr" => 0];
|
||||
$days = $SETTINGS["camp_days"];
|
||||
foreach ($days as $short => $long) {
|
||||
$days[$short] = 0;
|
||||
}
|
||||
foreach ($daystrs as $str) {
|
||||
if ($str == "") {
|
||||
continue;
|
||||
}
|
||||
$arr = str_split($str, 2);
|
||||
foreach ($arr as $day) {
|
||||
$days[$day] += 1;
|
||||
if (array_key_exists($day, $days)) {
|
||||
$days[$day] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ require_once __DIR__ . "/../../lib/Email.lib.php";
|
||||
|
||||
function errorBack(string $errormsg) {
|
||||
global $familyid;
|
||||
header("Location: ../?page=signup&error=" . htmlentities($errormsg));
|
||||
//header("Location: ../?page=signup&error=" . htmlentities($errormsg));
|
||||
$database->delete("families", ["familyid" => $familyid]);
|
||||
die($errormsg);
|
||||
}
|
||||
@ -50,6 +50,13 @@ $database->action(function($database) {
|
||||
errorBack("You need to register at least one person.");
|
||||
}
|
||||
|
||||
$campercount = 0;
|
||||
foreach ($people['ids'] as $pid) {
|
||||
if ($people["type"][$pidd] == "camper") {
|
||||
$campercount++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($people['ids'] as $pid) {
|
||||
// Clear these out
|
||||
$camperid = null;
|
||||
@ -119,7 +126,9 @@ $database->action(function($database) {
|
||||
|
||||
$days = "";
|
||||
if (is_array($people["days"][$pid])) {
|
||||
$validdays = ["Tu", "We", "Th", "Fr"];
|
||||
foreach ($SETTINGS["camp_days"] as $short => $long) {
|
||||
$validdays[] = $short;
|
||||
}
|
||||
$days = "";
|
||||
foreach ($people["days"][$pid] as $day) {
|
||||
if (in_array($day, $validdays)) {
|
||||
@ -142,21 +151,28 @@ $database->action(function($database) {
|
||||
$discount = 10.0 * (strlen($days) / 2);
|
||||
$dueusd -= $discount;
|
||||
echo "Subtracting $$discount from the total for an adult volunteer, dueusd is $dueusd\n";
|
||||
// Add shirt cost
|
||||
if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < 4) {
|
||||
echo "Adding $10 for a tshirt.\n";
|
||||
$dueusd += 10.0;
|
||||
// Add shirt charge if not working all days
|
||||
if ($SETTINGS["prices"]["alone_adult_free_tshirt"] === true && $campercount == 0) {
|
||||
// No shirt cost
|
||||
} else if ($SETTINGS["prices"]["adult_tshirt"] !== false) {
|
||||
if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < $SETTINGS["prices"]["adult_tshirt"]) {
|
||||
echo "Adding $10 for a tshirt.\n";
|
||||
$dueusd += 10.0;
|
||||
}
|
||||
}
|
||||
$database->insert("adults", [
|
||||
"position" => $people["position"][$pid],
|
||||
"days" => $days
|
||||
"days" => $days,
|
||||
"child_care" => (empty($people["child_care"][$pid]) ? null : $people["child_care"][$pid])
|
||||
]);
|
||||
$adultid = $database->id();
|
||||
break;
|
||||
case "youth":
|
||||
if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < 2) {
|
||||
echo "Adding $10 for a tshirt.\n";
|
||||
$dueusd += 10.0;
|
||||
if ($SETTINGS["prices"]["youth_tshirt"] !== false) {
|
||||
if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < $SETTINGS["prices"]["youth_tshirt"]) {
|
||||
echo "Adding $10 for a tshirt.\n";
|
||||
$dueusd += 10.0;
|
||||
}
|
||||
}
|
||||
$database->insert("youth", [
|
||||
"position" => $people["position"][$pid],
|
||||
|
@ -118,7 +118,22 @@ if (isset($_SESSION['familyid']) && $database->has('families', ['familyid' => $_
|
||||
</div>
|
||||
<div>
|
||||
<i class="fas fa-calendar-alt fa-fw"></i> A $10 discount is applied for every day an adult volunteers.<br />
|
||||
<i class="fas fa-tshirt fa-fw"></i> Shirts are $10, or free for adults who volunteer all four days.
|
||||
<?php
|
||||
if ($SETTINGS["prices"]["adult_tshirt"] === false) {
|
||||
?>
|
||||
<i class="fas fa-tshirt fa-fw"></i> Shirts and patches are free for adult volunteers.
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<i class="fas fa-tshirt fa-fw"></i> Shirts are $<?php echo $SETTINGS["prices"]["tshirt"]; ?>, or free for adults who volunteer at least <?php echo $SETTINGS["prices"]["adult_tshirt"]; ?> days.
|
||||
<?php
|
||||
if ($SETTINGS["prices"]["alone_adult_free_tshirt"] === true) {
|
||||
?>
|
||||
Shirts are also free for volunteers who are not attending with Cub Scouts.
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -145,7 +160,17 @@ if (isset($_SESSION['familyid']) && $database->has('families', ['familyid' => $_
|
||||
<i class="fas fa-plus"></i> Add Youth
|
||||
</div>
|
||||
<div>
|
||||
<i class="fas fa-tshirt fa-fw"></i> Shirts are $10, or free for youth who volunteer at least two days.
|
||||
<?php
|
||||
if ($SETTINGS["prices"]["youth_tshirt"] === false) {
|
||||
?>
|
||||
<i class="fas fa-tshirt fa-fw"></i> Shirts and patches are free for youth volunteers.
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<i class="fas fa-tshirt fa-fw"></i> Shirts are $<?php echo $SETTINGS["prices"]["tshirt"]; ?>, or free for youth who volunteer at least <?php echo $SETTINGS["prices"]["youth_tshirt"]; ?> days.
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -216,5 +241,8 @@ if (isset($_SESSION['familyid']) && $database->has('families', ['familyid' => $_
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
<script>
|
||||
var stripe_pubkey = '<?php echo $SETTINGS["stripe"]["pubkey"]; ?>';
|
||||
// Hi, don't bother trying to change these values for a discount, the math
|
||||
// is done on the server too so you'll just be wasting your time.
|
||||
var prices = <?php echo json_encode($SETTINGS["prices"]); ?>;
|
||||
</script>
|
||||
<script src="static/signup.js"></script>
|
@ -226,12 +226,7 @@ if (isset($personid) && $database->has('people', ['personid' => $personid])) {
|
||||
"label" => "Available Days",
|
||||
"name" => "days",
|
||||
"type" => "checkboxes",
|
||||
"options" => [
|
||||
"Tu" => "Tuesday",
|
||||
"We" => "Wednesday",
|
||||
"Th" => "Thursday",
|
||||
"Fr" => "Friday",
|
||||
],
|
||||
"options" => $SETTINGS["camp_days"],
|
||||
"error" => "Choose at least one day."
|
||||
],
|
||||
[
|
||||
@ -301,6 +296,17 @@ if (isset($personid) && $database->has('people', ['personid' => $personid])) {
|
||||
"error" => "Choose a gender."
|
||||
],
|
||||
]);
|
||||
if ($type == "adult") {
|
||||
$textboxes = array_merge($textboxes, [
|
||||
[
|
||||
"label" => "If you need child care for younger children, type their ages here",
|
||||
"name" => "child_care",
|
||||
"optional" => true,
|
||||
"width" => 12,
|
||||
"value" => $personinfo["child_care"]
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($textboxes as $item) {
|
||||
?>
|
||||
@ -386,8 +392,8 @@ if (isset($personid) && $database->has('people', ['personid' => $personid])) {
|
||||
?>
|
||||
</div>
|
||||
<?php if ($type == "camper") { ?>
|
||||
<div>
|
||||
<i class="fas fa-info-circle"></i> Tigers (boys entering the first grade in the Fall) must be accompanied by a parent or guardian.
|
||||
</div>
|
||||
<div>
|
||||
<i class="fas fa-info-circle"></i> Tigers (boys entering the first grade in the Fall) must be accompanied by a parent or guardian.
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
@ -87,23 +87,32 @@ function updateTotal() {
|
||||
return $(this).val() != '';
|
||||
}).length * 10.0;
|
||||
|
||||
// Add $10 for adult shirts if they aren't working four days
|
||||
// Add charge for adult shirts
|
||||
totalcharge = totalcharge + $(".person-list-item[data-persontype=adult]").filter(function () {
|
||||
if (prices.adult_tshirt == false) {
|
||||
return false;
|
||||
}
|
||||
var days = $("input[data-name=days]:checked", $(this)).length;
|
||||
if (days < 4 && $("select[data-name=shirt]", $(this)).val() != "NO" && $("select[data-name=shirt]", $(this)).val() != "") {
|
||||
if (prices.alone_adult_free_tshirt == true && $(".person-list-item[data-persontype=camper]").length == 0) {
|
||||
return false;
|
||||
}
|
||||
if (days < prices.adult_tshirt && $("select[data-name=shirt]", $(this)).val() != "NO" && $("select[data-name=shirt]", $(this)).val() != "") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).length * 10.0;
|
||||
}).length * prices.tshirt;
|
||||
|
||||
// Add $10 for youth shirts if they aren't working two days
|
||||
// Add charge for youth shirts
|
||||
totalcharge += $(".person-list-item[data-persontype=youth]").filter(function () {
|
||||
if (prices.youth_tshirt == false) {
|
||||
return false;
|
||||
}
|
||||
var days = $("input[data-name=days]:checked", $(this)).length;
|
||||
if (days < 2 && $("select[data-name=shirt]", $(this)).val() != "NO" && $("select[data-name=shirt]", $(this)).val() != "") {
|
||||
if (days < prices.youth_tshirt && $("select[data-name=shirt]", $(this)).val() != "NO" && $("select[data-name=shirt]", $(this)).val() != "") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).length * 10.0;
|
||||
}).length * prices.tshirt;
|
||||
|
||||
totalcharge = Math.max(totalcharge, 0);
|
||||
|
||||
|
@ -29,6 +29,22 @@ $SETTINGS = [
|
||||
"site_title" => "Camp Portal",
|
||||
// Set to true to disable registration.
|
||||
"disable_registration" => false,
|
||||
"camp_days" => [
|
||||
"Mo" => "Monday",
|
||||
"Tu" => "Tuesday",
|
||||
"We" => "Wednesday"
|
||||
],
|
||||
"prices" => [
|
||||
"camp" => 50.0,
|
||||
"tshirt" => 10.0,
|
||||
// Set to false to make shirts always free, set to a number to make them
|
||||
// free for people who work at least that many days
|
||||
"youth_tshirt" => false,
|
||||
"adult_tshirt" => 3,
|
||||
// Set whether adults get free shirts when they're not bringing Cub Scouts,
|
||||
// regardless of how many days they volunteer
|
||||
"alone_adult_free_tshirt" => true
|
||||
],
|
||||
// Stripe keys for payment processing
|
||||
"stripe" => [
|
||||
"pubkey" => "",
|
||||
|
Loading…
x
Reference in New Issue
Block a user