Update cost calculation display and management in CostCalculator module.

Show page Design added for cost calculation
This commit is contained in:
2025-08-16 23:24:40 +05:45
parent 6d6d1c9a8a
commit 75ebf99990
7 changed files with 307 additions and 28 deletions

View File

@@ -36,31 +36,39 @@ class CostCalculatorController extends Controller
if ($living) {
$html .= "<div style='margin-bottom: 6px;'>
<span style='background:#e3f2fd; padding:2px 4px; border-radius:4px; font-weight:600;'>Living</span>
<span style='background:#e3f2fd; padding:2px 4px; border-radius:4px; font-weight:600;'>Living Cost</span>
<b>{$living->monthly}</b> <i>/mo</i> | <b>{$living->yearly}</b> <i>/yr</i>
</div>";
}
if ($accomodation) {
$html .= "<div style='margin-bottom: 6px;'>
<span style='background:#fff3e0; padding:2px 4px; border-radius:4px; font-weight:600;'>Accommodation</span>
<span style='background:#fff3e0; padding:2px 4px; border-radius:4px; font-weight:600;'>Rental Cost</span>
<b>{$accomodation->monthly}</b> <i>/mo</i> | <b>{$accomodation->yearly}</b> <i>/yr</i>
</div>";
}
if ($onetime) {
$html .= "<div style='margin-bottom: 6px;'>
<span style='background:#e8f5e9; padding:2px 4px; border-radius:4px; font-weight:600;'>One-time</span>
Visa: <b>{$onetime->visa}</b>, Bio: <b>{$onetime->biometrics}</b>,
Sevis: <b>{$onetime->sevis}</b>, App: <b>{$onetime->application}</b>
</div>";
$totalOneTime = ($onetime->visa ?? 0)
+ ($onetime->biometrics ?? 0)
+ ($onetime->sevis ?? 0)
+ ($onetime->application ?? 0);
$html .= "<div style='margin-bottom: 12px; font-size: 13px;'>
<span style='background:#e8f5e9; padding:2px 4px; border-radius:4px; font-weight:600;'>One-time Cost</span>
Sum Up: <b>{$totalOneTime}</b>
</div>";
}
if ($service) {
$html .= "<div style='margin-bottom: 6px;'>
<span style='background:#f3e5f5; padding:2px 4px; border-radius:4px; font-weight:600;'>Service</span>
Ticket: <b>{$service->flight_ticket}</b>, Ins: <b>{$service->insurance}</b>,
Extra: <b>{$service->extra}</b>
</div>";
$totalService = ($service->flight_ticket ?? 0)
+ ($service->insurance ?? 0)
+ ($service->extra ?? 0);
$html .= "<div style='margin-bottom: 12px; font-size: 13px;'>
<span style='background:#f3e5f5; padding:2px 4px; border-radius:4px; font-weight:600;'>Service Cost</span>
Sum Up: <b>{$totalService}</b>
</div>";
}
$html .= "</div>";
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!');
});

View File

@@ -2,6 +2,9 @@
<a href="{{ route('cost.edit', $id) }}" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Edit"
class="link-success fs-15 edit-item-btn"><i class=" ri-edit-2-line"></i></a>
<a href="{{ route('cost.show', $id) }}" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="View"
class="link-success fs-15"><i class="ri-eye-line"></i></a>
{{-- <a data-link="{{ route('cost.toggle', $id) }}" data-bs-toggle="tooltip" data-bs-placement="bottom"
data-bs-title="Toggle" data-status="{{ $status == 1 ? 'Draft' : 'Published' }}"
class="link-info fs-15 toggle-item"><i class="{{ $status == 1 ? 'ri-toggle-line' : 'ri-toggle-fill' }}"></i></a> --}}

View File

@@ -6,11 +6,11 @@
</td>
<td class="d-flex flex-column gap-2">
{{ 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') }}
</td>
<td>
{{ 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') }}
</td>
<td class="align-middle">

View File

@@ -6,11 +6,11 @@
</td>
<td class="d-flex flex-column gap-2">
{{ 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') }}
</td>
<td>
{{ 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') }}
</td>
<td class="align-middle">

View File

@@ -5,19 +5,19 @@
</td>
<td class="d-flex flex-column gap-2">
{{ 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') }}
</td>
<td>
{{ 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') }}
</td>
<td>
{{ 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') }}
</td>
<td>
{{ 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') }}
</td>
<td class="align-middle">

View File

@@ -6,15 +6,15 @@
</td>
<td class="d-flex flex-column gap-2">
{{ 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') }}
</td>
<td>
{{ 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') }}
</td>
<td>
{{ 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') }}
</td>
<td class="align-middle">

View File

@@ -0,0 +1,181 @@
@extends('layouts.app')
@section('content')
<div class="container-fluid">
<x-dashboard.breadcumb :title="$title" />
<div class="row justify-content-center">
<div class="col-lg-11">
@foreach ($breakdowns as $type => $breakdown)
<div class="card shadow-lg border-0 rounded-4 mb-5">
<!-- Header -->
<div class="bg-warning-subtle position-relative">
<div class="card-body p-5 text-center">
<a class="navbar-brand flex p-0 relative w-140" href="{{ url('/') }}" rel="home"><span
class="navbar-brand-inner post-rel"><img src="{{ asset(setting('logo')) }}"
alt="raffle logo" /></span></a>
</div>
<div class="shape">
<svg xmlns="http://www.w3.org/2000/svg" width="1440" height="60"
preserveAspectRatio="none" viewBox="0 0 1440 60">
<path d="M 0,4 C 144,13 432,48 720,49 C 1008,50 1296,17 1440,9L1440 60L0 60z"
style="fill: var(--vz-secondary-bg);"></path>
</svg>
</div>
</div>
<!-- Header -->
<div class="text-center">
<p class="mb-0 fs-5 test-muted"><i>Estimated Cost Calculation For
{{ $cost->country?->title ?? 'N/A' }}</i> (<strong
class="text-capitalize">{{ str_replace('_', ' ', $type) }}</strong>)
</p>
</div>
<!-- Body -->
<div class="card-body p-4">
<!-- Living & Accommodation -->
<h5 class="fw-bold mt-4 text-primary">Recurring Costs</h5>
<div class="table-responsive">
<table
class="table table-bordered table-striped shadow-sm rounded align-middle text-center">
<thead class="">
<tr class="fw-bold text-uppercase">
<th></th>
<th>Monthly</th>
<th>Yearly</th>
</tr>
</thead>
<tbody class="small">
<tr>
<td class="fw-semibold text-muted">Living Cost</td>
<td class="">
{{ $breakdown['living']['monthly'] }}
</td>
<td class="">
{{ $breakdown['living']['yearly'] }}
</td>
</tr>
<tr>
<td class="fw-semibold text-muted">Accommodation Cost</td>
<td class="">
{{ $breakdown['accomodation']['monthly'] }}
</td>
<td class="">
{{ $breakdown['accomodation']['yearly'] }}
</td>
</tr>
<tr class="table-success">
<td class="fw-bold text-uppercase">Total Recurring</td>
<td class="fw-bold">
<span class="badge bg-success fs-6 px-3 py-2">
{{ $breakdown['living']['monthly'] + $breakdown['accomodation']['monthly'] }}
</span>
</td>
<td class="fw-bold">
<span class="badge bg-success fs-6 px-3 py-2">
{{ $breakdown['living']['yearly'] + $breakdown['accomodation']['yearly'] }}
</span>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Living & Accommodation -->
<!-- One-time Costs -->
<h5 class="fw-bold mt-4 text-primary">One-time Costs</h5>
<div class="table-responsive">
<table class="table table-hover align-middle table-striped border rounded shadow-sm">
<tbody class="small">
<tr>
<td class="fw-semibold text-muted">Visa</td>
<td class="text-end">{{ $breakdown['onetime']['visa'] }}</td>
</tr>
<tr>
<td class="fw-semibold text-muted">Biometrics</td>
<td class="text-end">{{ $breakdown['onetime']['biometrics'] }}</td>
</tr>
<tr>
<td class="fw-semibold text-muted">SEVIS</td>
<td class="text-end">{{ $breakdown['onetime']['sevis'] }}</td>
</tr>
<tr>
<td class="fw-semibold text-muted">Application</td>
<td class="text-end">{{ $breakdown['onetime']['application'] }}</td>
</tr>
<tr class="table-success">
<td class="fw-bold text-uppercase">Total One-time</td>
<td class="fw-bold text-end">
<span class="badge bg-success fs-6 px-3 py-2">
{{ $breakdown['onetime']['total'] }}
</span>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Service Costs -->
<h5 class="fw-bold mt-4 text-primary">Service Costs</h5>
<div class="table-responsive">
<table class="table table-hover align-middle table-striped border rounded shadow-sm">
<tbody class="small">
<tr>
<td class="fw-semibold text-muted">Flight Ticket</td>
<td class="text-end">{{ $breakdown['service']['flight_ticket'] }}</td>
</tr>
<tr>
<td class="fw-semibold text-muted">Insurance</td>
<td class="text-end">{{ $breakdown['service']['insurance'] }}</td>
</tr>
<tr>
<td class="fw-semibold text-muted">Extra</td>
<td class="text-end">{{ $breakdown['service']['extra'] }}</td>
</tr>
<tr class="table-success">
<td class="fw-bold text-uppercase">Total Service</td>
<td class="fw-bold text-end">
<span class="badge bg-success fs-6 px-3 py-2">
{{ $breakdown['service']['total'] }}
</span>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Overall -->
<div class="table-responsive mt-4">
<table class="table shadow-lg rounded-4 text-center align-middle"
style="background: #f8f9fa;">
<thead style="background: linear-gradient(90deg, #4e54c8, #8f94fb);">
<tr>
<th class="fs-5 fw-bold text-white text-uppercase py-3">
Overall Estimated Cost
<div class="small fw-normal fst-italic text-light mt-1">
(Excluding Recurring Costs)
</div>
</th>
<th class="p-3">
<div class="d-flex justify-content-center align-items-center h-100">
<span class="badge bg-warning text-dark fs-4 px-4 py-3">
{{ $breakdown['service']['total'] + $breakdown['onetime']['total'] }}
</span>
</div>
</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
@endsection