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,16 +43,21 @@
|
|||||||
<h2 class="d-inline">
|
<h2 class="d-inline">
|
||||||
<?php
|
<?php
|
||||||
$daystrs = $database->select("adults", "days");
|
$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) {
|
foreach ($daystrs as $str) {
|
||||||
if ($str == "") {
|
if ($str == "") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$arr = str_split($str, 2);
|
$arr = str_split($str, 2);
|
||||||
foreach ($arr as $day) {
|
foreach ($arr as $day) {
|
||||||
|
if (array_key_exists($day, $days)) {
|
||||||
$days[$day] += 1;
|
$days[$day] += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($days as $day => $count) {
|
foreach ($days as $day => $count) {
|
||||||
?>
|
?>
|
||||||
@ -69,16 +74,21 @@
|
|||||||
<h2 class="d-inline">
|
<h2 class="d-inline">
|
||||||
<?php
|
<?php
|
||||||
$daystrs = $database->select("youth", "days");
|
$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) {
|
foreach ($daystrs as $str) {
|
||||||
if ($str == "") {
|
if ($str == "") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$arr = str_split($str, 2);
|
$arr = str_split($str, 2);
|
||||||
foreach ($arr as $day) {
|
foreach ($arr as $day) {
|
||||||
|
if (array_key_exists($day, $days)) {
|
||||||
$days[$day] += 1;
|
$days[$day] += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($days as $day => $count) {
|
foreach ($days as $day => $count) {
|
||||||
?>
|
?>
|
||||||
|
@ -12,7 +12,7 @@ require_once __DIR__ . "/../../lib/Email.lib.php";
|
|||||||
|
|
||||||
function errorBack(string $errormsg) {
|
function errorBack(string $errormsg) {
|
||||||
global $familyid;
|
global $familyid;
|
||||||
header("Location: ../?page=signup&error=" . htmlentities($errormsg));
|
//header("Location: ../?page=signup&error=" . htmlentities($errormsg));
|
||||||
$database->delete("families", ["familyid" => $familyid]);
|
$database->delete("families", ["familyid" => $familyid]);
|
||||||
die($errormsg);
|
die($errormsg);
|
||||||
}
|
}
|
||||||
@ -50,6 +50,13 @@ $database->action(function($database) {
|
|||||||
errorBack("You need to register at least one person.");
|
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) {
|
foreach ($people['ids'] as $pid) {
|
||||||
// Clear these out
|
// Clear these out
|
||||||
$camperid = null;
|
$camperid = null;
|
||||||
@ -119,7 +126,9 @@ $database->action(function($database) {
|
|||||||
|
|
||||||
$days = "";
|
$days = "";
|
||||||
if (is_array($people["days"][$pid])) {
|
if (is_array($people["days"][$pid])) {
|
||||||
$validdays = ["Tu", "We", "Th", "Fr"];
|
foreach ($SETTINGS["camp_days"] as $short => $long) {
|
||||||
|
$validdays[] = $short;
|
||||||
|
}
|
||||||
$days = "";
|
$days = "";
|
||||||
foreach ($people["days"][$pid] as $day) {
|
foreach ($people["days"][$pid] as $day) {
|
||||||
if (in_array($day, $validdays)) {
|
if (in_array($day, $validdays)) {
|
||||||
@ -142,22 +151,29 @@ $database->action(function($database) {
|
|||||||
$discount = 10.0 * (strlen($days) / 2);
|
$discount = 10.0 * (strlen($days) / 2);
|
||||||
$dueusd -= $discount;
|
$dueusd -= $discount;
|
||||||
echo "Subtracting $$discount from the total for an adult volunteer, dueusd is $dueusd\n";
|
echo "Subtracting $$discount from the total for an adult volunteer, dueusd is $dueusd\n";
|
||||||
// Add shirt cost
|
// Add shirt charge if not working all days
|
||||||
if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < 4) {
|
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";
|
echo "Adding $10 for a tshirt.\n";
|
||||||
$dueusd += 10.0;
|
$dueusd += 10.0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$database->insert("adults", [
|
$database->insert("adults", [
|
||||||
"position" => $people["position"][$pid],
|
"position" => $people["position"][$pid],
|
||||||
"days" => $days
|
"days" => $days,
|
||||||
|
"child_care" => (empty($people["child_care"][$pid]) ? null : $people["child_care"][$pid])
|
||||||
]);
|
]);
|
||||||
$adultid = $database->id();
|
$adultid = $database->id();
|
||||||
break;
|
break;
|
||||||
case "youth":
|
case "youth":
|
||||||
if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < 2) {
|
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";
|
echo "Adding $10 for a tshirt.\n";
|
||||||
$dueusd += 10.0;
|
$dueusd += 10.0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$database->insert("youth", [
|
$database->insert("youth", [
|
||||||
"position" => $people["position"][$pid],
|
"position" => $people["position"][$pid],
|
||||||
"days" => $days
|
"days" => $days
|
||||||
|
@ -118,7 +118,22 @@ if (isset($_SESSION['familyid']) && $database->has('families', ['familyid' => $_
|
|||||||
</div>
|
</div>
|
||||||
<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-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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -145,7 +160,17 @@ if (isset($_SESSION['familyid']) && $database->has('families', ['familyid' => $_
|
|||||||
<i class="fas fa-plus"></i> Add Youth
|
<i class="fas fa-plus"></i> Add Youth
|
||||||
</div>
|
</div>
|
||||||
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -216,5 +241,8 @@ if (isset($_SESSION['familyid']) && $database->has('families', ['familyid' => $_
|
|||||||
<script src="https://js.stripe.com/v3/"></script>
|
<script src="https://js.stripe.com/v3/"></script>
|
||||||
<script>
|
<script>
|
||||||
var stripe_pubkey = '<?php echo $SETTINGS["stripe"]["pubkey"]; ?>';
|
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>
|
||||||
<script src="static/signup.js"></script>
|
<script src="static/signup.js"></script>
|
@ -226,12 +226,7 @@ if (isset($personid) && $database->has('people', ['personid' => $personid])) {
|
|||||||
"label" => "Available Days",
|
"label" => "Available Days",
|
||||||
"name" => "days",
|
"name" => "days",
|
||||||
"type" => "checkboxes",
|
"type" => "checkboxes",
|
||||||
"options" => [
|
"options" => $SETTINGS["camp_days"],
|
||||||
"Tu" => "Tuesday",
|
|
||||||
"We" => "Wednesday",
|
|
||||||
"Th" => "Thursday",
|
|
||||||
"Fr" => "Friday",
|
|
||||||
],
|
|
||||||
"error" => "Choose at least one day."
|
"error" => "Choose at least one day."
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -301,6 +296,17 @@ if (isset($personid) && $database->has('people', ['personid' => $personid])) {
|
|||||||
"error" => "Choose a gender."
|
"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) {
|
foreach ($textboxes as $item) {
|
||||||
?>
|
?>
|
||||||
|
@ -87,23 +87,32 @@ function updateTotal() {
|
|||||||
return $(this).val() != '';
|
return $(this).val() != '';
|
||||||
}).length * 10.0;
|
}).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 () {
|
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;
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
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 () {
|
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;
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}).length * 10.0;
|
}).length * prices.tshirt;
|
||||||
|
|
||||||
totalcharge = Math.max(totalcharge, 0);
|
totalcharge = Math.max(totalcharge, 0);
|
||||||
|
|
||||||
|
@ -29,6 +29,22 @@ $SETTINGS = [
|
|||||||
"site_title" => "Camp Portal",
|
"site_title" => "Camp Portal",
|
||||||
// Set to true to disable registration.
|
// Set to true to disable registration.
|
||||||
"disable_registration" => false,
|
"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 keys for payment processing
|
||||||
"stripe" => [
|
"stripe" => [
|
||||||
"pubkey" => "",
|
"pubkey" => "",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user