Add insurance months prices grid while fetch stopped insurance

This commit is contained in:
Djery-Tom 2022-05-06 10:28:06 +01:00
parent a259cc654b
commit 06402e1cae
1 changed files with 13 additions and 11 deletions

View File

@ -100,7 +100,7 @@ class InsuranceController extends Controller
ON nhc.network_id = n.id WHERE n.country_id = :countryId AND cw.type = 'ilink_sante' AND n.status = 1", ['countryId' => $request->input('country_id')]);
foreach ($insurances as $network) {
$this->formatInsuranceNetwork($network);
$network->months_prices = $this->fetchInsuranceNetworkMonthsAndYearsPrices($network->nhc_id);
}
}
return $this->successResponse($insurances);
@ -148,18 +148,18 @@ class InsuranceController extends Controller
if (!$insurance_network)
return $this->errorResponse(trans('errors.network_not_found'));
$this->formatInsuranceNetwork($insurance_network);
$insurance_network->months_prices = $this->fetchInsuranceNetworkMonthsAndYearsPrices($insurance_network->nhc_id);
return $this->successResponse($insurance_network);
}
private function formatInsuranceNetwork($insurance_network): void
private function fetchInsuranceNetworkMonthsAndYearsPrices($nh_network_config_id)
{
$months_prices = DB::select("SELECT id , number_of_months , min_amount , max_insurance_coverage_amount, waiting_period_days, payment_period , number_of_fractions FROM nh_months_prices_grid
WHERE nh_network_config_id = :nhc_id ORDER BY number_of_fractions ASC",
['nhc_id' => $insurance_network->nhc_id]);
['nhc_id' => $nh_network_config_id]);
$years_prices = DB::select("SELECT min_age , max_age , markup_percentage FROM nh_years_prices_grid WHERE nh_network_config_id = :nhc_id",
['nhc_id' => $insurance_network->nhc_id]);
['nhc_id' => $nh_network_config_id]);
foreach ($months_prices as $mp) {
foreach ($years_prices as $cp) {
@ -178,9 +178,7 @@ class InsuranceController extends Controller
}
}
$insurance_network->months_prices = $months_prices;
unset($insurance_network->nhc_id);
return $months_prices;
}
@ -323,6 +321,10 @@ class InsuranceController extends Controller
$b->insurance_remaining_amount = $this->toMoneyWithCurrencyCode(($monthPrice->max_insurance_coverage_amount ?? 0) - $b->insurance_coverage_amount, $currency_code);
}
if ($type == 'STOPPED') {
$insurance->months_prices = $this->fetchInsuranceNetworkMonthsAndYearsPrices($insurance->nhNetworkConfig->id);
}
unset($insurance->nhNetworkConfig);
}
@ -707,9 +709,9 @@ class InsuranceController extends Controller
* ),
* @OA\Property(
* property="month_price_id",
* description = "Mot de passe",
* type="string",
* example= "12345"
* description = "ID du type de paiement",
* type="integer",
* example= 12
* ),
* ),
* ),