From 22605b96cc7929185ba73b5811da61b463a2c7a7 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sun, 31 Mar 2019 18:58:50 -0500 Subject: [PATCH] Pricing updates --- index.php | 7 ++++++- src/.env.example | 8 ++++++-- src/functions.php | 52 ++++++++++++++++++++++++++++++++++++++++++----- views/family.php | 24 ++++++++++++++++++---- views/step1.php | 7 +++++++ 5 files changed, 86 insertions(+), 12 deletions(-) diff --git a/index.php b/index.php index b73fafa..b2b3148 100644 --- a/index.php +++ b/index.php @@ -13,7 +13,9 @@ require __DIR__ . '/src/functions.php'; $dotenv = \Dotenv\Dotenv::create(__DIR__ . '/src'); $dotenv->load(); $dotenv->required([ - 'EVENT_TICKET_PRICE', + 'EVENT_TICKET_PRICE_1', + 'EVENT_TICKET_PRICE_2', + 'EVENT_TICKET_PRICE_3', 'ENHANCER_TICKET_PRICE', 'CHILDCARE_PRICE', 'CABANA_PRICE', @@ -39,6 +41,9 @@ $router->set404(function () { echo '404, route not found!'; }); +// Get event pricing based on dates +list($_SERVER['EVENT_TICKET_PRICE'], $_SERVER['TABLE_TICKET_PRICE']) = getEventPricing(new DateTime('now', new DateTimeZone('America/Chicago'))); + $router->before('GET|POST', '/admin/.*', function() { session_start(); diff --git a/src/.env.example b/src/.env.example index 5287d60..c452ca6 100644 --- a/src/.env.example +++ b/src/.env.example @@ -1,5 +1,9 @@ -EVENT_TICKET_PRICE="55" -TABLE_TICKET_PRICE="350" +EVENT_TICKET_PRICE_1="55" +TABLE_TICKET_PRICE_1="350" +EVENT_TICKET_PRICE_2="65" +TABLE_TICKET_PRICE_2="450" +EVENT_TICKET_PRICE_3="75" +TABLE_TICKET_PRICE_3="500" ENHANCER_TICKET_PRICE="20" CHILDCARE_PRICE="25" CABANA_PRICE="250" diff --git a/src/functions.php b/src/functions.php index 9789688..ff14e6a 100644 --- a/src/functions.php +++ b/src/functions.php @@ -21,6 +21,47 @@ function getInteger($variable, $postiveOnly = true) return $variable; } +/** + * Calculate Event Pricing based on date + * + * @param DateTime $date + * @return array + * @throws Exception + */ +function getEventPricing($date = null) +{ + $priceIncrease1 = new DateTime('4/1/2019', new DateTimeZone('America/Chicago')); + $priceIncrease2 = new DateTime('5/1/2019', new DateTimeZone('America/Chicago')); + + if (empty($date)) { + return [ + $_SERVER['EVENT_TICKET_PRICE_1'], + $_SERVER['TABLE_TICKET_PRICE_1'], + ]; + } + + $interval = $date->diff($priceIncrease1); + if ($interval->invert !== 0) { + return [ + $_SERVER['EVENT_TICKET_PRICE_2'], + $_SERVER['TABLE_TICKET_PRICE_2'], + ]; + } + + $interval = $date->diff($priceIncrease2); + if ($interval->invert !== 0) { + return [ + $_SERVER['EVENT_TICKET_PRICE_3'], + $_SERVER['TABLE_TICKET_PRICE_3'], + ]; + }else { + return [ + $_SERVER['EVENT_TICKET_PRICE_1'], + $_SERVER['TABLE_TICKET_PRICE_1'], + ]; + } +} + /** * Converts possible float or string to cents * @@ -69,9 +110,9 @@ function eventPricing($qty) // If pricing is 8 or more then we need to factor in table reservations if ($qty > 7) { - $tableQty = (int) ($qty / 8); + $tableQty = (int)($qty / 8); $eventQty = $qty - ($tableQty * 8); - }else { + } else { $eventQty = $qty; } @@ -86,13 +127,14 @@ function shoppingCartTotal($price) '; } -function checkIfTicketsAreOnSale() { +function checkIfTicketsAreOnSale() +{ $todaysDate = new DateTime('now', new DateTimeZone('America/Chicago')); $dateOnSale = new DateTime('3/15/2019 8:00am', new DateTimeZone('America/Chicago')); $interval = $todaysDate->diff($dateOnSale); - if($interval->days >= 0 && $interval->invert === 0) { - header('Location: /notify?d='.$dateOnSale->format('c')); + if ($interval->days >= 0 && $interval->invert === 0) { + header('Location: /notify?d=' . $dateOnSale->format('c')); } } \ No newline at end of file diff --git a/views/family.php b/views/family.php index 35716d7..ee37a2a 100644 --- a/views/family.php +++ b/views/family.php @@ -1,15 +1,31 @@

Nature's Classroom Institute & Montessori School Presents

-
Saturday June 1st, 2019 5:00pm-11:30pm
+ +
Saturday June 1st, 2019 5:00pm-11:30pm
W336 S8455 Hwy E, Mukwonago, WI 53149
-

Are you a current NCI family or alum?

- Yes  - No + diff($aprilIncrease); + if ($interval->invert == 0) { ?> +

Are you a current NCI family or alum?

+ Yes  + No + + Purchase Tickets  + +


diff --git a/views/step1.php b/views/step1.php index 29d13d1..6469e59 100644 --- a/views/step1.php +++ b/views/step1.php @@ -1,7 +1,14 @@ +diff($aprilIncrease); +if ($interval->invert == 0) { ?> value; if ($tickets <= 25) { ?>