From e860a97bbadcbbbb7ca2af8308cf1f12387be736 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 11 Dec 2018 20:42:41 -0700 Subject: [PATCH] Add payment entry and editing (close #8) --- action.php | 43 ++++++ langs/en/labels.json | 5 +- langs/en/messages.json | 3 +- langs/en/titles.json | 4 +- langs/messages.php | 4 + pages.php | 3 + pages/editpayment.php | 203 ++++++++++++++++++++++++++++ pages/payments.php | 8 +- public/actions/submitmembership.php | 11 +- 9 files changed, 274 insertions(+), 10 deletions(-) create mode 100644 pages/editpayment.php diff --git a/action.php b/action.php index 3b62b21..a559371 100644 --- a/action.php +++ b/action.php @@ -232,4 +232,47 @@ switch ($VARS['action']) { } } 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; } \ No newline at end of file diff --git a/langs/en/labels.json b/langs/en/labels.json index 429fd9a..6c2aefe 100644 --- a/langs/en/labels.json +++ b/langs/en/labels.json @@ -43,5 +43,8 @@ "Check": "Check", "Other": "Other", "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)" } diff --git a/langs/en/messages.json b/langs/en/messages.json index ff489f1..e680ef8 100644 --- a/langs/en/messages.json +++ b/langs/en/messages.json @@ -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.", "No interests selected.": "No interests selected.", "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." } diff --git a/langs/en/titles.json b/langs/en/titles.json index cc90524..579aed0 100644 --- a/langs/en/titles.json +++ b/langs/en/titles.json @@ -7,5 +7,7 @@ "Delete Family": "Delete Family", "Events": "Events", "Reports": "Reports", - "Payments": "Payments" + "Payments": "Payments", + "Add Payment": "Add Payment", + "Edit Payment": "Edit Payment" } diff --git a/langs/messages.php b/langs/messages.php index d4130c7..0b3c6f7 100644 --- a/langs/messages.php +++ b/langs/messages.php @@ -36,5 +36,9 @@ define("MESSAGES", [ "events_updated" => [ "string" => "Events updated.", "type" => "success" + ], + "payment_saved" => [ + "string" => "Payment saved.", + "type" => "success" ] ]); diff --git a/pages.php b/pages.php index a95c139..3ab5200 100644 --- a/pages.php +++ b/pages.php @@ -49,6 +49,9 @@ define("PAGES", [ "static/js/payments.js" ] ], + "editpayment" => [ + "title" => "Edit Payment" + ], "events" => [ "title" => "Events", "navbar" => true, diff --git a/pages/editpayment.php b/pages/editpayment.php new file mode 100644 index 0000000..62eaf1f --- /dev/null +++ b/pages/editpayment.php @@ -0,0 +1,203 @@ +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; +} +?> + +
+ +
+ +

+
+ get("Edit Payment"); + } else { + $Strings->get("Add Payment"); + } + ?> +
+ + get("Cancel"); ?> + +

+ +
+
+ + 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) { + ?> + +
"> +
+ +
+
+ +
+ + " + name="" + class="form-control" + placeholder="" + aria-label="" + maxlength="" + + value="" + required /> + + + +
+
+
+ + + +
+
+ > + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + + + " /> + + + +
+ +
\ No newline at end of file diff --git a/pages/payments.php b/pages/payments.php index e517f61..60c6c0a 100644 --- a/pages/payments.php +++ b/pages/payments.php @@ -26,7 +26,7 @@ $payments = $database->select("payments", ['paymentid (id)', 'familyid', 'amount - + get('Actions'); ?> get('Family'); ?> get('Amount'); ?> get('Date'); ?> @@ -40,7 +40,7 @@ $payments = $database->select("payments", ['paymentid (id)', 'familyid', 'amount ?> - + load($p['familyid'])->getName(); ?> $ @@ -62,7 +62,7 @@ $payments = $database->select("payments", ['paymentid (id)', 'familyid', 'amount - + get('Actions'); ?> get('Family'); ?> get('Amount'); ?> get('Date'); ?> diff --git a/public/actions/submitmembership.php b/public/actions/submitmembership.php index 7b225fc..884aa4c 100644 --- a/public/actions/submitmembership.php +++ b/public/actions/submitmembership.php @@ -113,7 +113,12 @@ $database->action(function($database) { $family->setPhotoPermission($photopermission); 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 { $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); if ($renewal) { $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 { $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(); } catch (Exception $e) {