2021-10-19 14:35:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2021-10-27 12:48:07 +00:00
|
|
|
use App\Events\InsuranceEvent;
|
2021-10-28 12:48:07 +00:00
|
|
|
use App\InsuranceSubscriptionAffiliation;
|
2021-10-19 14:35:01 +00:00
|
|
|
use App\InsuranceSubscriptionState;
|
|
|
|
use App\Models\CountriesCurrency;
|
|
|
|
use App\Models\Identification;
|
2021-11-04 17:07:15 +00:00
|
|
|
use App\Models\NhInsurance;
|
2021-10-19 14:35:01 +00:00
|
|
|
use App\Models\NhInsurancesHavingRight;
|
|
|
|
use App\Models\NhInsurancesSubscription;
|
|
|
|
use App\Models\NhInsurancesSubscriptionsHistory;
|
2021-10-20 13:05:23 +00:00
|
|
|
use App\Models\NhMonthsPricesGrid;
|
2021-10-19 14:35:01 +00:00
|
|
|
use App\Models\NhNetworksConfig;
|
2021-11-01 14:26:21 +00:00
|
|
|
use App\Models\User;
|
2021-10-19 14:35:01 +00:00
|
|
|
use App\Traits\Helper;
|
2021-10-20 13:05:23 +00:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2021-10-19 14:35:01 +00:00
|
|
|
use Illuminate\Http\Request;
|
2021-10-21 12:07:35 +00:00
|
|
|
use Illuminate\Http\UploadedFile;
|
2021-10-19 14:35:01 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
class InsuranceController extends Controller
|
|
|
|
{
|
|
|
|
use Helper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OA\Get(
|
2021-10-27 12:48:07 +00:00
|
|
|
* path="/insurances",
|
|
|
|
* summary="Afficher la liste des assurances ( par pays )",
|
2021-10-19 14:35:01 +00:00
|
|
|
* tags={"Assurances"},
|
|
|
|
* security={{"api_key":{}}},
|
|
|
|
* @OA\Parameter(
|
2021-10-27 12:48:07 +00:00
|
|
|
* parameter="country_id",
|
|
|
|
* name="country_id",
|
2021-10-19 14:35:01 +00:00
|
|
|
* description="ID du pays",
|
2021-10-27 12:48:07 +00:00
|
|
|
* in="query",
|
2021-10-19 14:35:01 +00:00
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="integer",
|
|
|
|
* default=78
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="OK",
|
|
|
|
* @OA\JsonContent(
|
|
|
|
* ref="#/components/schemas/ApiResponse",
|
|
|
|
* example = {
|
|
|
|
* "status" : 200,
|
2021-10-20 13:05:23 +00:00
|
|
|
* "response" : {{"id":250,"name":"Cnamgs-pharmacies", "age_limit_of_insured_and_spouse" : 30 ,
|
|
|
|
* "age_limit_of_child_beneficiary": 25 , "max_number_of_beneficiaries":"5", "months_prices":{{"id": 1,"number_of_months":"3","min_amount":"150000 XAF"}}}},
|
2021-10-19 14:35:01 +00:00
|
|
|
* "error":null
|
|
|
|
* }
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
*/
|
2021-10-27 12:48:07 +00:00
|
|
|
public function getInsurances(Request $request)
|
2021-10-19 14:35:01 +00:00
|
|
|
{
|
2021-10-27 12:48:07 +00:00
|
|
|
$this->validate($request, [
|
|
|
|
'country_id' => 'nullable|integer|exists:countries,id'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$country = CountriesCurrency::findOrFail($request->input('country_id'));
|
2021-10-19 14:35:01 +00:00
|
|
|
|
2021-10-20 13:05:23 +00:00
|
|
|
$insurances = DB::select("SELECT n.id , n.name , nhc.age_limit_of_insured_and_spouse, nhc.age_limit_of_child_beneficiary, nhc.max_number_of_beneficiaries, nhc.id as nhc_id
|
|
|
|
FROM networks n JOIN configWallet cw ON cw.id_network = n.id JOIN nh_networks_configs nhc
|
2021-10-27 12:48:07 +00:00
|
|
|
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')]);
|
2021-10-19 14:35:01 +00:00
|
|
|
|
|
|
|
foreach ($insurances as $insurance) {
|
|
|
|
$months_prices = DB::select("SELECT id, number_of_months , min_amount FROM nh_months_prices_grid WHERE nh_network_config_id = :nhc_id",
|
|
|
|
['nhc_id' => $insurance->nhc_id]);
|
|
|
|
|
|
|
|
foreach ($months_prices as $mp) {
|
|
|
|
$mp->min_amount = $this->toMoneyWithCurrencyCode($mp->min_amount, $country->currency_code ?? 'XAF');
|
|
|
|
}
|
|
|
|
$insurance->months_prices = $months_prices;
|
|
|
|
unset($insurance->nhc_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->successResponse($insurances);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|