From 75ebf9999009b6f3c5b886141de07ddfd29a2ca2 Mon Sep 17 00:00:00 2001 From: Subash Date: Sat, 16 Aug 2025 23:24:40 +0545 Subject: [PATCH] Update cost calculation display and management in CostCalculator module. Show page Design added for cost calculation --- .../Controllers/CostCalculatorController.php | 129 +++++++++++-- .../views/cost/datatable/action.blade.php | 3 + .../cost/partials/accomodation-cost.blade.php | 4 +- .../views/cost/partials/living-cost.blade.php | 4 +- .../cost/partials/onetime-cost.blade.php | 8 +- .../cost/partials/service-cost.blade.php | 6 +- .../resources/views/cost/show.blade.php | 181 ++++++++++++++++++ 7 files changed, 307 insertions(+), 28 deletions(-) diff --git a/Modules/CostCalculator/app/Http/Controllers/CostCalculatorController.php b/Modules/CostCalculator/app/Http/Controllers/CostCalculatorController.php index c139514..f2ace3e 100644 --- a/Modules/CostCalculator/app/Http/Controllers/CostCalculatorController.php +++ b/Modules/CostCalculator/app/Http/Controllers/CostCalculatorController.php @@ -36,31 +36,39 @@ class CostCalculatorController extends Controller if ($living) { $html .= "
- Living + Living Cost {$living->monthly} /mo | {$living->yearly} /yr
"; } if ($accomodation) { $html .= "
- Accommodation + Rental Cost {$accomodation->monthly} /mo | {$accomodation->yearly} /yr
"; } if ($onetime) { - $html .= "
- One-time - Visa: {$onetime->visa}, Bio: {$onetime->biometrics}, - Sevis: {$onetime->sevis}, App: {$onetime->application} -
"; + $totalOneTime = ($onetime->visa ?? 0) + + ($onetime->biometrics ?? 0) + + ($onetime->sevis ?? 0) + + ($onetime->application ?? 0); + + $html .= "
+ One-time Cost + Sum Up: {$totalOneTime} +
"; } if ($service) { - $html .= "
- Service - Ticket: {$service->flight_ticket}, Ins: {$service->insurance}, - Extra: {$service->extra} -
"; + $totalService = ($service->flight_ticket ?? 0) + + ($service->insurance ?? 0) + + ($service->extra ?? 0); + + $html .= "
+ Service Cost + Sum Up: {$totalService} +
"; } + $html .= ""; return trim($html) ?: '-'; @@ -192,12 +200,57 @@ class CostCalculatorController extends Controller */ public function show($id) { + $cost = CostCalculator::with([ + 'stayTypeLiving', + 'stayTypeAccomodation', + 'stayTypeOnetime', + 'stayTypeService' + ])->findOrFail($id); + $data['title'] = 'View Cost Calculation'; - $data['program'] = CostCalculator::findOrFail($id); - $data['intakeOptions'] = Program::INTAKE; + $data['cost'] = $cost; + + $getBreakdown = function ($stayTypeTitle) use ($cost) { + $living = optional($cost->stayTypeLiving->firstWhere('title', $stayTypeTitle))->pivot; + $accomodation = optional($cost->stayTypeAccomodation->firstWhere('title', $stayTypeTitle))->pivot; + $onetime = optional($cost->stayTypeOnetime->firstWhere('title', $stayTypeTitle))->pivot; + $service = optional($cost->stayTypeService->firstWhere('title', $stayTypeTitle))->pivot; + + return [ + 'living' => [ + 'monthly' => $living->monthly ?? 0, + 'yearly' => $living->yearly ?? 0, + ], + 'accomodation' => [ + 'monthly' => $accomodation->monthly ?? 0, + 'yearly' => $accomodation->yearly ?? 0, + ], + 'onetime' => [ + 'visa' => $onetime->visa ?? 0, + 'biometrics' => $onetime->biometrics ?? 0, + 'sevis' => $onetime->sevis ?? 0, + 'application' => $onetime->application ?? 0, + 'total' => ($onetime->visa ?? 0) + ($onetime->biometrics ?? 0) + ($onetime->sevis ?? 0) + ($onetime->application ?? 0), + ], + 'service' => [ + 'flight_ticket' => $service->flight_ticket ?? 0, + 'insurance' => $service->insurance ?? 0, + 'extra' => $service->extra ?? 0, + 'total' => ($service->flight_ticket ?? 0) + ($service->insurance ?? 0) + ($service->extra ?? 0), + ] + ]; + }; + + $data['breakdowns'] = [ + 'alone' => $getBreakdown('Alone'), + 'with_spouse' => $getBreakdown('With Spouse'), + 'with_spouse_and_child' => $getBreakdown('With Spouse and Child'), + ]; + return view('costcalculator::cost.show', $data); } + /** * Show the form for editing the specified resource. */ @@ -216,11 +269,53 @@ class CostCalculatorController extends Controller */ public function update(Request $request, $id) { - $input = $request->all(); + $input = $request->except(['living_cost', 'accomodation_cost', 'onetime_cost', 'service_cost']); + DB::transaction(function () use ($input, $request, $id) { - $program = CostCalculator::findOrFail($id); - $program->update($input); + $costs = CostCalculator::findOrFail($id); + $costs->update($input); + + $attachLivingData = []; + $attachAccData = []; + $attachOnetimeData = []; + $attachServiceData = []; + + foreach ($request->living_cost as $item) { + $attachLivingData[$item['stay_type_id']] = [ + 'monthly' => $item['monthly'], + 'yearly' => $item['yearly'], + ]; + } + + foreach ($request->accomodation_cost as $item) { + $attachAccData[$item['stay_type_id']] = [ + 'monthly' => $item['monthly'], + 'yearly' => $item['yearly'], + ]; + } + + foreach ($request->onetime_cost as $item) { + $attachOnetimeData[$item['stay_type_id']] = [ + 'visa' => $item['visa'], + 'biometrics' => $item['biometrics'], + 'sevis' => $item['sevis'], + 'application' => $item['application'], + ]; + } + + foreach ($request->service_cost as $item) { + $attachServiceData[$item['stay_type_id']] = [ + 'flight_ticket' => $item['flight_ticket'], + 'insurance' => $item['insurance'], + 'extra' => $item['extra'], + ]; + } + + $costs->stayTypeLiving()->sync($attachLivingData); + $costs->stayTypeAccomodation()->sync($attachAccData); + $costs->stayTypeOnetime()->sync($attachOnetimeData); + $costs->stayTypeService()->sync($attachServiceData); flash()->success('Cost Calculation has been updated!'); }); diff --git a/Modules/CostCalculator/resources/views/cost/datatable/action.blade.php b/Modules/CostCalculator/resources/views/cost/datatable/action.blade.php index 82b1c30..279afb3 100644 --- a/Modules/CostCalculator/resources/views/cost/datatable/action.blade.php +++ b/Modules/CostCalculator/resources/views/cost/datatable/action.blade.php @@ -2,6 +2,9 @@ + + {{-- --}} diff --git a/Modules/CostCalculator/resources/views/cost/partials/accomodation-cost.blade.php b/Modules/CostCalculator/resources/views/cost/partials/accomodation-cost.blade.php index 8dd31e1..1933f20 100644 --- a/Modules/CostCalculator/resources/views/cost/partials/accomodation-cost.blade.php +++ b/Modules/CostCalculator/resources/views/cost/partials/accomodation-cost.blade.php @@ -6,11 +6,11 @@ - {{ html()->text('accomodation_cost[' . $numInc . '][monthly]')->class('form-control')->value($value->monthly ?? null)->placeholder('Monthly') }} + {{ html()->text('accomodation_cost[' . $numInc . '][monthly]')->class('form-control')->value($value->pivot->monthly ?? null)->placeholder('Monthly') }} - {{ html()->text('accomodation_cost[' . $numInc . '][yearly]')->class('form-control')->value($value->yearly ?? null)->placeholder('Yearly') }} + {{ html()->text('accomodation_cost[' . $numInc . '][yearly]')->class('form-control')->value($value->pivot->yearly ?? null)->placeholder('Yearly') }} diff --git a/Modules/CostCalculator/resources/views/cost/partials/living-cost.blade.php b/Modules/CostCalculator/resources/views/cost/partials/living-cost.blade.php index 9a755eb..f9ed099 100644 --- a/Modules/CostCalculator/resources/views/cost/partials/living-cost.blade.php +++ b/Modules/CostCalculator/resources/views/cost/partials/living-cost.blade.php @@ -6,11 +6,11 @@ - {{ html()->text('living_cost[' . $numInc . '][monthly]')->class('form-control')->value($value->monthly ?? null)->placeholder('Monthly') }} + {{ html()->text('living_cost[' . $numInc . '][monthly]')->class('form-control')->value($value->pivot->monthly ?? null)->placeholder('Monthly') }} - {{ html()->text('living_cost[' . $numInc . '][yearly]')->class('form-control')->value($value->yearly ?? null)->placeholder('Yearly') }} + {{ html()->text('living_cost[' . $numInc . '][yearly]')->class('form-control')->value($value->pivot->yearly ?? null)->placeholder('Yearly') }} diff --git a/Modules/CostCalculator/resources/views/cost/partials/onetime-cost.blade.php b/Modules/CostCalculator/resources/views/cost/partials/onetime-cost.blade.php index 02e6db7..e6191d6 100644 --- a/Modules/CostCalculator/resources/views/cost/partials/onetime-cost.blade.php +++ b/Modules/CostCalculator/resources/views/cost/partials/onetime-cost.blade.php @@ -5,19 +5,19 @@ - {{ html()->text('onetime_cost[' . $numInc . '][visa]')->class('form-control')->value($value->visa ?? null)->placeholder('Visa') }} + {{ html()->text('onetime_cost[' . $numInc . '][visa]')->class('form-control')->value($value->pivot->visa ?? null)->placeholder('Visa') }} - {{ html()->text('onetime_cost[' . $numInc . '][biometrics]')->class('form-control')->value($value->biometrics ?? null)->placeholder('Biometrics') }} + {{ html()->text('onetime_cost[' . $numInc . '][biometrics]')->class('form-control')->value($value->pivot->biometrics ?? null)->placeholder('Biometrics') }} - {{ html()->text('onetime_cost[' . $numInc . '][sevis]')->class('form-control')->value($value->sevis ?? null)->placeholder('Sevis') }} + {{ html()->text('onetime_cost[' . $numInc . '][sevis]')->class('form-control')->value($value->pivot->sevis ?? null)->placeholder('Sevis') }} - {{ html()->text('onetime_cost[' . $numInc . '][application]')->class('form-control')->value($value->application ?? null)->placeholder('Application') }} + {{ html()->text('onetime_cost[' . $numInc . '][application]')->class('form-control')->value($value->pivot->application ?? null)->placeholder('Application') }} diff --git a/Modules/CostCalculator/resources/views/cost/partials/service-cost.blade.php b/Modules/CostCalculator/resources/views/cost/partials/service-cost.blade.php index a9ed9f0..bbc0a24 100644 --- a/Modules/CostCalculator/resources/views/cost/partials/service-cost.blade.php +++ b/Modules/CostCalculator/resources/views/cost/partials/service-cost.blade.php @@ -6,15 +6,15 @@ - {{ html()->text('service_cost[' . $numInc . '][flight_ticket]')->class('form-control')->value($value->flight_ticket ?? null)->placeholder('Flight Ticket') }} + {{ html()->text('service_cost[' . $numInc . '][flight_ticket]')->class('form-control')->value($value->pivot->flight_ticket ?? null)->placeholder('Flight Ticket') }} - {{ html()->text('service_cost[' . $numInc . '][insurance]')->class('form-control')->value($value->insurance ?? null)->placeholder('Health Insurance') }} + {{ html()->text('service_cost[' . $numInc . '][insurance]')->class('form-control')->value($value->pivot->insurance ?? null)->placeholder('Health Insurance') }} - {{ html()->text('service_cost[' . $numInc . '][extra]')->class('form-control')->value($value->extra ?? null)->placeholder('Extra') }} + {{ html()->text('service_cost[' . $numInc . '][extra]')->class('form-control')->value($value->pivot->extra ?? null)->placeholder('Extra') }} diff --git a/Modules/CostCalculator/resources/views/cost/show.blade.php b/Modules/CostCalculator/resources/views/cost/show.blade.php index e69de29..63fde2b 100644 --- a/Modules/CostCalculator/resources/views/cost/show.blade.php +++ b/Modules/CostCalculator/resources/views/cost/show.blade.php @@ -0,0 +1,181 @@ +@extends('layouts.app') + +@section('content') +
+ + +
+
+ @foreach ($breakdowns as $type => $breakdown) +
+ + +
+
+ raffle logo +
+
+ + + +
+
+ + +
+

Estimated Cost Calculation For + {{ $cost->country?->title ?? 'N/A' }} ({{ str_replace('_', ' ', $type) }}) +

+
+ + +
+ + +
Recurring Costs
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
MonthlyYearly
Living Cost + {{ $breakdown['living']['monthly'] }} + + {{ $breakdown['living']['yearly'] }} +
Accommodation Cost + {{ $breakdown['accomodation']['monthly'] }} + + {{ $breakdown['accomodation']['yearly'] }} +
Total Recurring + + {{ $breakdown['living']['monthly'] + $breakdown['accomodation']['monthly'] }} + + + + {{ $breakdown['living']['yearly'] + $breakdown['accomodation']['yearly'] }} + +
+
+ + + +
One-time Costs
+
+ + + + + + + + + + + + + + + + + + + + + + + +
Visa{{ $breakdown['onetime']['visa'] }}
Biometrics{{ $breakdown['onetime']['biometrics'] }}
SEVIS{{ $breakdown['onetime']['sevis'] }}
Application{{ $breakdown['onetime']['application'] }}
Total One-time + + {{ $breakdown['onetime']['total'] }} + +
+
+ + +
Service Costs
+
+ + + + + + + + + + + + + + + + + + + +
Flight Ticket{{ $breakdown['service']['flight_ticket'] }}
Insurance{{ $breakdown['service']['insurance'] }}
Extra{{ $breakdown['service']['extra'] }}
Total Service + + {{ $breakdown['service']['total'] }} + +
+
+ + +
+ + + + + + + +
+ Overall Estimated Cost +
+ (Excluding Recurring Costs) +
+
+
+ + {{ $breakdown['service']['total'] + $breakdown['onetime']['total'] }} + +
+
+
+ + +
+
+ @endforeach +
+
+
+@endsection