Tax improvements
1) remove logic for calculating Tax out of the blade view and into a service. 2) implemented service in the correct controller.
This commit is contained in:
parent
2fa609de26
commit
b3dae02cef
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class Order
|
||||
{
|
||||
|
||||
public function calculateFinalCosts($orderTotal, $totalBookingFee, $event)
|
||||
{
|
||||
$orderTotalWithBookingFee = $orderTotal + $totalBookingFee;
|
||||
$taxAmount = ($event->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 )];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -35,25 +35,17 @@
|
|||
</div>
|
||||
@if($order_total > 0)
|
||||
<div class="panel-footer">
|
||||
@php
|
||||
$grand_total = $order_total + $total_booking_fee;
|
||||
@endphp
|
||||
<h5>
|
||||
@lang("Public_ViewEvent.total"): <span style="float: right;"><b>{{ money($grand_total + $total_booking_fee,$event->currency) }}</b></span>
|
||||
@lang("Public_ViewEvent.total"): <span style="float: right;"><b>{{ $order_costs['orderTotalWithBookingFee'] }}</b></span>
|
||||
</h5>
|
||||
@if($event->organiser->taxname && $event->organiser->taxvalue && $event->organiser->taxvalue > 0)
|
||||
@if($event->organiser->charge_tax)
|
||||
<h5>
|
||||
{{ $event->organiser->taxname }} ({{ $event->organiser->taxvalue }}%):
|
||||
@php
|
||||
// Calculating grand total including tax
|
||||
$tax_amt = ($grand_total * $event->organiser->taxvalue) / 100;
|
||||
$grand_total = $tax_amt + $grand_total;
|
||||
@endphp
|
||||
<span style="float: right;"><b>{{ money($tax_amt,$event->currency) }}</b></span>
|
||||
{{ $event->organiser->tax_name }} ({{ $event->organiser->tax_value }}%):
|
||||
<span style="float: right;"><b>{{ $order_costs['taxAmount'] }}</b></span>
|
||||
</h5>
|
||||
<h5>
|
||||
<strong>Grand Total:</strong>
|
||||
<span style="float: right;"><b>{{ money($grand_total,$event->currency) }}</b></span>
|
||||
<span style="float: right;"><b>{{ $order_costs['orderTotalWithBookingFee'] }}</b></span>
|
||||
</h5>
|
||||
@endif
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue