Update cost calculation display and management in CostCalculator module.
Show page Design added for cost calculation
This commit is contained in:
@@ -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!');
|
||||
});
|
||||
|
Reference in New Issue
Block a user