Add payment entry and editing (close #8)
This commit is contained in:
parent
270ece840d
commit
e860a97bba
43
action.php
43
action.php
@ -232,4 +232,47 @@ switch ($VARS['action']) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
returnToSender("events_updated");
|
returnToSender("events_updated");
|
||||||
|
case "editpayment":
|
||||||
|
if (!(new User($_SESSION['uid']))->hasPermission("HACHEPORTAL_EDIT")) {
|
||||||
|
returnToSender("no_permission");
|
||||||
|
}
|
||||||
|
if (!$database->has("families", ['familyid' => $VARS['familyid']])) {
|
||||||
|
returnToSender("invalid_parameters");
|
||||||
|
}
|
||||||
|
if (!is_numeric($VARS["amount"]) || $VARS["amount"] < 0) {
|
||||||
|
returnToSender("invalid_parameters");
|
||||||
|
}
|
||||||
|
if (empty($VARS['date']) || strtotime($VARS['date']) === false) {
|
||||||
|
returnToSender("invalid_parameters");
|
||||||
|
}
|
||||||
|
if (!empty($VARS['paymentid']) && $database->has("payments", ['paymentid' => $VARS['paymentid']])) {
|
||||||
|
$database->update("payments", [
|
||||||
|
"familyid" => $VARS["familyid"],
|
||||||
|
"amount" => $VARS["amount"],
|
||||||
|
"paid" => !empty($VARS["paid"]) && $VARS["paid"] == "1" ? true : false,
|
||||||
|
"date" => date("Y-m-d H:i:s", strtotime($VARS['date'])),
|
||||||
|
"type" => $VARS["type"]
|
||||||
|
], [
|
||||||
|
"paymentid" => $VARS["paymentid"]
|
||||||
|
]);
|
||||||
|
$paymentid = $VARS["paymentid"];
|
||||||
|
} else {
|
||||||
|
$database->insert("payments", [
|
||||||
|
"familyid" => $VARS["familyid"],
|
||||||
|
"amount" => $VARS["amount"],
|
||||||
|
"paid" => !empty($VARS["paid"]) && $VARS["paid"] == "1" ? true : false,
|
||||||
|
"date" => date("Y-m-d H:i:s", strtotime($VARS['date'])),
|
||||||
|
"type" => $VARS["type"]
|
||||||
|
]);
|
||||||
|
$paymentid = $database->id();
|
||||||
|
$family = (new Family())->load($VARS['familyid']);
|
||||||
|
if ($family->getExpires() < time()) {
|
||||||
|
$family->setExpires(strtotime("+1 year"));
|
||||||
|
} else {
|
||||||
|
$family->setExpires(strtotime("+1 year", $family->getExpires()));
|
||||||
|
}
|
||||||
|
$family->save();
|
||||||
|
}
|
||||||
|
returnToSender("payment_saved", "&id=$paymentid");
|
||||||
|
break;
|
||||||
}
|
}
|
@ -43,5 +43,8 @@
|
|||||||
"Check": "Check",
|
"Check": "Check",
|
||||||
"Other": "Other",
|
"Other": "Other",
|
||||||
"Free": "Free",
|
"Free": "Free",
|
||||||
"Expires": "Expires"
|
"Expires": "Expires",
|
||||||
|
"Choose...": "Choose...",
|
||||||
|
"Mark as paid": "Mark as paid",
|
||||||
|
"This payment is a membership renewal (automatically add one year to the family's membership)": "This payment is a membership renewal (automatically add one year to the family's membership)"
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,6 @@
|
|||||||
"To remove a child, delete the contents of the Name box.": "To remove a child, delete the contents of the Name box.",
|
"To remove a child, delete the contents of the Name box.": "To remove a child, delete the contents of the Name box.",
|
||||||
"No interests selected.": "No interests selected.",
|
"No interests selected.": "No interests selected.",
|
||||||
"Events updated.": "Events updated.",
|
"Events updated.": "Events updated.",
|
||||||
"You agree to use the information in this directory for homeschool use ONLY. All other purposes, such as soliciting, is strictly prohibited.": "You agree to use the information in this directory for homeschool use ONLY. All other purposes, such as soliciting, is strictly prohibited."
|
"You agree to use the information in this directory for homeschool use ONLY. All other purposes, such as soliciting, is strictly prohibited.": "You agree to use the information in this directory for homeschool use ONLY. All other purposes, such as soliciting, is strictly prohibited.",
|
||||||
|
"Payment saved.": "Payment saved."
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,7 @@
|
|||||||
"Delete Family": "Delete Family",
|
"Delete Family": "Delete Family",
|
||||||
"Events": "Events",
|
"Events": "Events",
|
||||||
"Reports": "Reports",
|
"Reports": "Reports",
|
||||||
"Payments": "Payments"
|
"Payments": "Payments",
|
||||||
|
"Add Payment": "Add Payment",
|
||||||
|
"Edit Payment": "Edit Payment"
|
||||||
}
|
}
|
||||||
|
@ -36,5 +36,9 @@ define("MESSAGES", [
|
|||||||
"events_updated" => [
|
"events_updated" => [
|
||||||
"string" => "Events updated.",
|
"string" => "Events updated.",
|
||||||
"type" => "success"
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"payment_saved" => [
|
||||||
|
"string" => "Payment saved.",
|
||||||
|
"type" => "success"
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
@ -49,6 +49,9 @@ define("PAGES", [
|
|||||||
"static/js/payments.js"
|
"static/js/payments.js"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"editpayment" => [
|
||||||
|
"title" => "Edit Payment"
|
||||||
|
],
|
||||||
"events" => [
|
"events" => [
|
||||||
"title" => "Events",
|
"title" => "Events",
|
||||||
"navbar" => true,
|
"navbar" => true,
|
||||||
|
203
pages/editpayment.php
Normal file
203
pages/editpayment.php
Normal file
@ -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>
|
@ -26,7 +26,7 @@ $payments = $database->select("payments", ['paymentid (id)', 'familyid', 'amount
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th data-priority="0"></th>
|
<th data-priority="0"></th>
|
||||||
<!--<th data-priority="1"><?php $Strings->get('Actions'); ?></th>-->
|
<th data-priority="1"><?php $Strings->get('Actions'); ?></th>
|
||||||
<th data-priority="1"><i class="fas fa-users hidden-sm"></i> <?php $Strings->get('Family'); ?></th>
|
<th data-priority="1"><i class="fas fa-users hidden-sm"></i> <?php $Strings->get('Family'); ?></th>
|
||||||
<th data-priority="1"><i class="fas fa-dollar-sign hidden-sm"></i> <?php $Strings->get('Amount'); ?></th>
|
<th data-priority="1"><i class="fas fa-dollar-sign hidden-sm"></i> <?php $Strings->get('Amount'); ?></th>
|
||||||
<th data-priority="2"><i class="fas fa-calendar hidden-sm"></i> <?php $Strings->get('Date'); ?></th>
|
<th data-priority="2"><i class="fas fa-calendar hidden-sm"></i> <?php $Strings->get('Date'); ?></th>
|
||||||
@ -40,7 +40,7 @@ $payments = $database->select("payments", ['paymentid (id)', 'familyid', 'amount
|
|||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<!-- <td>
|
<td>
|
||||||
<?php
|
<?php
|
||||||
if ($writeaccess) {
|
if ($writeaccess) {
|
||||||
?>
|
?>
|
||||||
@ -48,7 +48,7 @@ $payments = $database->select("payments", ['paymentid (id)', 'familyid', 'amount
|
|||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</td>-->
|
</td>
|
||||||
<td><a href="./app.php?page=viewfamily&id=<?php echo $p['familyid']; ?>"><?php echo (new Family())->load($p['familyid'])->getName(); ?></a></td>
|
<td><a href="./app.php?page=viewfamily&id=<?php echo $p['familyid']; ?>"><?php echo (new Family())->load($p['familyid'])->getName(); ?></a></td>
|
||||||
<td>$<?php echo number_format($p['amount'], 2); ?></td>
|
<td>$<?php echo number_format($p['amount'], 2); ?></td>
|
||||||
<td><?php echo date("Y-m-d H:i:s", strtotime($p['date'])); ?></td>
|
<td><?php echo date("Y-m-d H:i:s", strtotime($p['date'])); ?></td>
|
||||||
@ -62,7 +62,7 @@ $payments = $database->select("payments", ['paymentid (id)', 'familyid', 'amount
|
|||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<th data-priority="0"></th>
|
<th data-priority="0"></th>
|
||||||
<!--<th data-priority="1"><?php $Strings->get('Actions'); ?></th>-->
|
<th data-priority="1"><?php $Strings->get('Actions'); ?></th>
|
||||||
<th data-priority="1"><i class="fas fa-users hidden-sm"></i> <?php $Strings->get('Family'); ?></th>
|
<th data-priority="1"><i class="fas fa-users hidden-sm"></i> <?php $Strings->get('Family'); ?></th>
|
||||||
<th data-priority="1"><i class="fas fa-dollar-sign hidden-sm"></i> <?php $Strings->get('Amount'); ?></th>
|
<th data-priority="1"><i class="fas fa-dollar-sign hidden-sm"></i> <?php $Strings->get('Amount'); ?></th>
|
||||||
<th data-priority="2"><i class="fas fa-calendar hidden-sm"></i> <?php $Strings->get('Date'); ?></th>
|
<th data-priority="2"><i class="fas fa-calendar hidden-sm"></i> <?php $Strings->get('Date'); ?></th>
|
||||||
|
@ -113,7 +113,12 @@ $database->action(function($database) {
|
|||||||
$family->setPhotoPermission($photopermission);
|
$family->setPhotoPermission($photopermission);
|
||||||
|
|
||||||
if ($renewal) {
|
if ($renewal) {
|
||||||
$family->setExpires(strtotime("+1 year", $family->getExpires()));
|
// If membership lapsed, add a whole year, otherwise just extend it
|
||||||
|
if ($family->getExpires() < time()) {
|
||||||
|
$family->setExpires(strtotime("+1 year"));
|
||||||
|
} else {
|
||||||
|
$family->setExpires(strtotime("+1 year", $family->getExpires()));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$family->setExpires(strtotime("+1 year"));
|
$family->setExpires(strtotime("+1 year"));
|
||||||
}
|
}
|
||||||
@ -252,10 +257,10 @@ $database->action(function($database) {
|
|||||||
$notification->setSMTP(SMTP_HOST, SMTP_PORT, SMTP_AUTH, SMTP_USERNAME, SMTP_PASSWORD, SMTP_SECURITY);
|
$notification->setSMTP(SMTP_HOST, SMTP_PORT, SMTP_AUTH, SMTP_USERNAME, SMTP_PASSWORD, SMTP_SECURITY);
|
||||||
if ($renewal) {
|
if ($renewal) {
|
||||||
$notification->setSubject("HACHE renewal notification");
|
$notification->setSubject("HACHE renewal notification");
|
||||||
$notification->setBody("The " .$family->getName() . " family has renewed their HACHE membership.");
|
$notification->setBody("The " . $family->getName() . " family has renewed their HACHE membership.");
|
||||||
} else {
|
} else {
|
||||||
$notification->setSubject("HACHE membership notification");
|
$notification->setSubject("HACHE membership notification");
|
||||||
$notification->setBody("The " .$family->getName() . " family has registered for a HACHE membership.");
|
$notification->setBody("The " . $family->getName() . " family has registered for a HACHE membership.");
|
||||||
}
|
}
|
||||||
$notification->send();
|
$notification->send();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user