diff --git a/Modules/CostCalculator/app/Services/CostCalculatorService.php b/Modules/CostCalculator/app/Services/CostCalculatorService.php index 136dcee..a040396 100644 --- a/Modules/CostCalculator/app/Services/CostCalculatorService.php +++ b/Modules/CostCalculator/app/Services/CostCalculatorService.php @@ -3,6 +3,7 @@ namespace Modules\CostCalculator\Services; use Modules\CostCalculator\Models\CostCalculator; +use Modules\CourseFinder\Models\Program; class CostCalculatorService { @@ -13,20 +14,12 @@ class CostCalculatorService $query->where('country_id', $request->country_id); } - if ($request->filled('programlevel_id')) { - $query->where("programlevel_id", $request->programlevel_id); + if ($request->filled('stay_type_id')) { + $query->where("stay_type_id", $request->stay_type_id); } if ($request->filled('program_id')) { - $query->where("program_id", $request->program_id); - } - - if ($request->filled('living_status_id')) { - $query->where("living_status_id", $request->living_status_id); - } - - if ($request->filled('status')) { - $query->where('status', $request->status); + Program::where('status', 1)-> where('id', $request->program_id)->get(); } })->latest()->paginate(10)->withQueryString(); diff --git a/app/Http/Controllers/WebsiteController.php b/app/Http/Controllers/WebsiteController.php index 2382e27..330e024 100644 --- a/app/Http/Controllers/WebsiteController.php +++ b/app/Http/Controllers/WebsiteController.php @@ -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'), + ]; + } } diff --git a/resources/views/client/raffles/layouts/app.blade.php b/resources/views/client/raffles/layouts/app.blade.php index a4d34a4..e546a73 100644 --- a/resources/views/client/raffles/layouts/app.blade.php +++ b/resources/views/client/raffles/layouts/app.blade.php @@ -49,7 +49,8 @@ - + @stack('css') +