feat: Implement multi-step cost calculator with dynamic form handling and styling enhancements
This commit is contained in:
@@ -10,6 +10,8 @@ use Modules\CCMS\Models\Institution;
|
||||
use Modules\CCMS\Models\Page;
|
||||
use Modules\CCMS\Models\Service;
|
||||
use Modules\CCMS\Models\Test;
|
||||
use Modules\CostCalculator\Models\CostCalculator;
|
||||
use Modules\CostCalculator\Models\StayType;
|
||||
use Modules\CourseFinder\Models\Coop;
|
||||
use Modules\CourseFinder\Models\Program;
|
||||
use Modules\CourseFinder\Models\ProgramLevel;
|
||||
@@ -243,13 +245,65 @@ class WebsiteController extends Controller
|
||||
public function costCalculator(Request $request)
|
||||
{
|
||||
$data['programs'] = $this->programService->findAll($request);
|
||||
$data['programss'] = Program::where('status', 1)->pluck('title', 'id');
|
||||
$data['countryOptions'] = Country::where('status', 1)->where('parent_id', null)->pluck('title', 'id');
|
||||
$data['programLevelOptions'] = ProgramLevel::where('status', 1)->pluck('title', 'id');
|
||||
$data['intakeOptions'] = Program::INTAKE;
|
||||
$data['coopOptions'] = Coop::where('status', 1)->pluck('title', 'id');
|
||||
$data['testOptions'] = Test::where('status', 1)->where('parent_id', null)->pluck('title', 'id');
|
||||
$data['statusOptions'] = config('constants.page_status_options');
|
||||
$data['livingStatusOptions'] = StayType::where('status', 1)->pluck('title', 'id');
|
||||
|
||||
|
||||
return view("client.raffles.pages.cost-calculator", $data);
|
||||
}
|
||||
|
||||
public function getCost(Request $request, $id)
|
||||
{
|
||||
$cost = CostCalculator::with([
|
||||
'stayTypeLiving',
|
||||
'stayTypeAccomodation',
|
||||
'stayTypeOnetime',
|
||||
'stayTypeService'
|
||||
])->findOrFail($id);
|
||||
|
||||
$data['title'] = 'View Cost Calculation';
|
||||
$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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user