You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
9.9 KiB
PHP

<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
redirectIfNotLoggedIn();
$editing = false;
$data = [
"id" => "",
"family" => "",
"amount" => 0.0,
"amountpaid" => 0.0,
"date" => date("Y-m-d"),
"type" => ""
];
if (!empty($_GET['id']) && $database->has('payments', ['paymentid' => $_GET['id']])) {
$editing = true;
$payment = $database->get("payments", ['paymentid (id)', "familyid (family)", "amount", "amountpaid", "date", "type"], ["paymentid" => $_GET['id']]);
$payment["date"] = date("Y-m-d", strtotime($payment["date"]));
$data = $payment;
}
?>
<div class="modal fade" id="familysearchmodal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Find Family</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<input type="text" id="familysearchbox" class="form-control" placeholder="Type to Search" />
<div class="list-group" id="familysearchresults">
</div>
</div>
</div>
</div>
</div>
<form action="action.php" method="post" id="editform">
<div class="card">
<h3 class="card-header d-flex">
<div>
<i class="fas fa-edit"></i> <?php
if ($editing) {
$Strings->get("Edit Payment");
} else {
$Strings->get("Add Payment");
}
?>
</div>
<a href="./app.php?page=payments" class="ml-auto btn btn-outline-info btn-sm">
<i class="fas fa-times"></i> <?php $Strings->get("Cancel"); ?>
</a>
</h3>
<div class="card-body">
<div class="row">
<div class="col-12 col-md-2">
<div class="form-group mb-3">
<label class="mb-0">Family ID:</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="btn btn-default" id="familysearchbtn"><i class="fas fa-search"></i></span>
</div>
<input type="number"
name="familyid"
value="<?php echo $data['family']; ?>"
class="form-control"
placeholder=""
aria-label="Family ID"
maxlength="5"
required />
<div class="invalid-feedback">
Enter a family ID.
</div>
</div>
</div>
</div>
<?php
$textboxes = [
[
"label" => "Total Amount",
"icon" => "fas fa-dollar-sign",
"name" => "amount",
"type" => "number",
"maxlength" => 5,
"step" => "0.01",
"value" => $data["amount"],
"width" => 2,
"error" => "Enter a dollar amount."
],
[
"label" => "Amount Paid",
"icon" => "fas fa-dollar-sign",
"name" => "amountpaid",
"type" => "number",
"maxlength" => 5,
"step" => "0.01",
"value" => $data["amountpaid"],
"width" => 2,
"error" => "Enter a dollar amount."
],
[
"label" => "Date",
"icon" => "fas fa-calendar",
"name" => "date",
"type" => "date",
"value" => $data["date"],
"width" => 3,
"error" => "Choose a date for the payment."
],
[
"label" => "Type",
"icon" => "fas fa-money-bill",
"name" => "type",
"type" => "select",
"value" => $data["type"],
"options" => [
"" => $Strings->get("Choose...", false),
"Online" => "Online",
"Cash" => "Cash",
"Check" => "Check",
"Camp Coupon/Scout Bucks" => "Camp Coupon/Scout Bucks",
"Free" => "Free",
"Multiple" => "Multiple",
"Other" => "Other"
],
"width" => 3,
"error" => "Select a payment type."
]
];
foreach ($textboxes as $item) {
?>
<div class="col-12 col-md-<?php echo (empty($item['width']) ? "4" : $item['width']); ?>">
<div class="form-group mb-3">
<label class="mb-0"><?php echo $item['label']; ?>:</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="<?php echo $item['icon']; ?>"></i></span>
</div>
<?php if (empty($item['type']) || $item['type'] != "select") { ?>
<input type="<?php echo (empty($item['type']) ? "text" : $item['type']); ?>"
name="<?php echo $item['name']; ?>"
class="form-control"
placeholder=""
aria-label="<?php echo $item['label']; ?>"
maxlength="<?php echo $item['maxlength']; ?>"
<?php
if (!empty($item['pattern'])) {
?>
pattern="<?php echo $item['pattern']; ?>"
<?php
}
?>
<?php
if (!empty($item['step'])) {
?>
step="<?php echo htmlspecialchars($item['step']); ?>"
<?php
}
?>
<?php
if (!empty($item['value'])) {
?>
value="<?php echo htmlspecialchars($item['value']); ?>"
<?php
}
?>required />
<?php } else if ($item['type'] == "select") { ?>
<select class="form-control"
name="<?php echo $item['name']; ?>"
aria-label="<?php echo $item['label']; ?>"
required>
<?php
foreach ($item['options'] as $value => $label) {
$selected = "";
if (!empty($item['value']) && $value == $item['value']) {
$selected = " selected";
}
echo "<option value=\"$value\"$selected>$label</option>\n";
}
?>
</select>
<?php
}
?>
<div class="invalid-feedback">
<?php echo $item['error']; ?>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<input type="hidden" name="source" value="editpayment" />
<input type="hidden" name="action" value="editpayment" />
<?php
if ($editing) {
?>
<input type="hidden" name="paymentid" value="<?php echo $data["id"]; ?>" />
<?php
}
?>
<div class="card-footer d-flex">
<button type="submit" class="btn btn-success mr-1" id="savebutton">
<i class="fas fa-save"></i> <?php $Strings->get("Save"); ?>
</button>
</div>
</div>
</form>