Add payment entry and editing (close #8)
parent
270ece840d
commit
e860a97bba
@ -0,0 +1,203 @@
|
||||
<?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();
|
||||
$user = new User($_SESSION['uid']);
|
||||
if (!$user->hasPermission("HACHEPORTAL_EDIT")) {
|
||||
header("Location: ./app.php?msg=no_permission");
|
||||
die();
|
||||
}
|
||||
|
||||
$editing = false;
|
||||
$data = [
|
||||
"id" => "",
|
||||
"family" => "",
|
||||
"amount" => 1.0,
|
||||
"date" => date("Y-m-d"),
|
||||
"type" => "",
|
||||
"paid" => true
|
||||
];
|
||||
|
||||
if (!empty($_GET['id']) && $database->has('payments', ['paymentid' => $_GET['id']])) {
|
||||
$editing = true;
|
||||
$payment = $database->get("payments", ['paymentid (id)', "familyid (family)", "amount", "date", "type", "paid"], ["paymentid" => $_GET['id']]);
|
||||
$payment["date"] = date("Y-m-d", strtotime($payment["date"]));
|
||||
$payment["paid"] = ($payment["paid"] == 1 ? true : false);
|
||||
$data = $payment;
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="action.php" method="post">
|
||||
|
||||
<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">
|
||||
|
||||
<?php
|
||||
$families = $database->select("families", ["familyid (id)", "familyname (name)", "mother_name", "father_name"]);
|
||||
$familylist = [
|
||||
"" => $Strings->get("Choose...", false)
|
||||
];
|
||||
foreach ($families as $f) {
|
||||
$familylist[$f['id']] = "$f[name], $f[father_name] and $f[mother_name]";
|
||||
}
|
||||
$textboxes = [
|
||||
[
|
||||
"label" => "Family",
|
||||
"icon" => "fas fa-users",
|
||||
"name" => "familyid",
|
||||
"type" => "select",
|
||||
"value" => $data["family"],
|
||||
"options" => $familylist
|
||||
],
|
||||
[
|
||||
"label" => "Amount",
|
||||
"icon" => "fas fa-dollar-sign",
|
||||
"name" => "amount",
|
||||
"type" => "number",
|
||||
"maxlength" => 5,
|
||||
"value" => $data["amount"],
|
||||
"width" => 2
|
||||
],
|
||||
[
|
||||
"label" => "Date",
|
||||
"icon" => "fas fa-calendar",
|
||||
"name" => "date",
|
||||
"type" => "date",
|
||||
"maxlength" => 20,
|
||||
"value" => $data["date"],
|
||||
"width" => 3
|
||||
],
|
||||
[
|
||||
"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",
|
||||
"Free" => "Free",
|
||||
"Other" => "Other"
|
||||
],
|
||||
"width" => 3
|
||||
]
|
||||
];
|
||||
|
||||
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['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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="col-12 col-md-4">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" value="1" name="paid" id="paid" <?php
|
||||
if ($data["paid"]) {
|
||||
echo "checked";
|
||||
}
|
||||
?>>
|
||||
<label class="form-check-label" for="paid">
|
||||
<?php $Strings->get("Mark as paid"); ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!$editing) { ?>
|
||||
<div class="col-12 col-md-4">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" value="1" name="extendmembership" id="extendmembership" checked>
|
||||
<label class="form-check-label" for="extendmembership">
|
||||
<?php $Strings->get("This payment is a membership renewal (automatically add one year to the family's membership)"); ?>
|
||||
</label>
|
||||
</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">
|
||||
<i class="fas fa-save"></i> <?php $Strings->get("Save"); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
Loading…
Reference in New Issue