From b3dae02cef6142c95c82db95445880cb4448525e Mon Sep 17 00:00:00 2001 From: Jeremy Quinton Date: Tue, 10 Jul 2018 10:36:42 +0200 Subject: [PATCH] Tax improvements 1) remove logic for calculating Tax out of the blade view and into a service. 2) implemented service in the correct controller. --- .../Controllers/EventCheckoutController.php | 17 +++++++++++---- app/Services/Order.php | 21 +++++++++++++++++++ .../EventCreateOrderSection.blade.php | 18 +++++----------- 3 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 app/Services/Order.php diff --git a/app/Http/Controllers/EventCheckoutController.php b/app/Http/Controllers/EventCheckoutController.php index b83fd0fa..c5f78b6d 100644 --- a/app/Http/Controllers/EventCheckoutController.php +++ b/app/Http/Controllers/EventCheckoutController.php @@ -12,6 +12,7 @@ use App\Models\OrderItem; use App\Models\QuestionAnswer; use App\Models\ReservedTickets; use App\Models\Ticket; +use App\Services\Order as OrderService; use Carbon\Carbon; use Cookie; use DB; @@ -245,11 +246,19 @@ class EventCheckoutController extends Controller $secondsToExpire = Carbon::now()->diffInSeconds($order_session['expires']); + $event = Event::findorFail($order_session['event_id']); + + $order = new OrderService(); + $orderCosts = $order->calculateFinalCosts($order_session['order_total'], + $order_session['total_booking_fee'], + $event); + $data = $order_session + [ - 'event' => Event::findorFail($order_session['event_id']), + 'event' => $event, 'secondsToExpire' => $secondsToExpire, 'is_embedded' => $this->is_embedded, - ]; + 'order_costs' => $orderCosts + ]; if ($this->is_embedded) { return view('Public.ViewEvent.Embedded.EventPageCheckout', $data); @@ -326,7 +335,7 @@ class EventCheckoutController extends Controller // Calculating grand total including tax $grand_total = $ticket_order['order_total'] + $ticket_order['organiser_booking_fee']; - $tax_amt = ($grand_total * $event->organiser->taxvalue) / 100; + $tax_amt = ($grand_total * $event->organiser->tax_value) / 100; $grand_total = $tax_amt + $grand_total; $transaction_data = [ @@ -533,7 +542,7 @@ class EventCheckoutController extends Controller // Calculating grand total including tax $grand_total = $ticket_order['order_total'] + $ticket_order['organiser_booking_fee']; - $tax_amt = ($grand_total * $event->organiser->taxvalue) / 100; + $tax_amt = ($grand_total * $event->organiser->tax_value) / 100; $order->taxamt = $tax_amt; $order->save(); diff --git a/app/Services/Order.php b/app/Services/Order.php new file mode 100644 index 00000000..924ee0d4 --- /dev/null +++ b/app/Services/Order.php @@ -0,0 +1,21 @@ +organiser->charge_tax == 1) ? ($orderTotalWithBookingFee * $event->organiser->tax_value)/100 + : 0; + + $grandTotal = $orderTotalWithBookingFee + $taxAmount; + + return ['orderTotalWithBookingFee' => money($orderTotalWithBookingFee, $event->currency), + 'taxAmount' => money($taxAmount, $event->currency), + 'grandTotal' => money($grandTotal, $event->currency )]; + } + +} diff --git a/resources/views/Public/ViewEvent/Partials/EventCreateOrderSection.blade.php b/resources/views/Public/ViewEvent/Partials/EventCreateOrderSection.blade.php index e78d662a..38552b59 100644 --- a/resources/views/Public/ViewEvent/Partials/EventCreateOrderSection.blade.php +++ b/resources/views/Public/ViewEvent/Partials/EventCreateOrderSection.blade.php @@ -35,25 +35,17 @@ @if($order_total > 0)