Add profile image to beneficiary images, add month price while renew insurance and add payment method while pay insurance invoice

This commit is contained in:
Djery-Tom 2022-05-05 10:02:30 +01:00
parent 365121cea0
commit a259cc654b
6 changed files with 150 additions and 39 deletions

View File

@ -95,45 +95,94 @@ class InsuranceController extends Controller
ON nhc.network_id = n.id JOIN nh_insurances nhi ON nhi.network_id = n.id WHERE nhi.user_id = :user_id AND cw.type = 'ilink_sante' AND n.status = 1", ['user_id' => $user_id]);
} else {
$country = CountriesCurrency::findOrFail($request->input('country_id'));
$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.family_coverage_sharing, nhc.id as nhc_id
FROM networks n JOIN configWallet cw ON cw.id_network = n.id JOIN nh_networks_configs nhc
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 $insurance) {
$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->nhc_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->nhc_id]);
foreach ($months_prices as $mp) {
foreach ($years_prices as $cp) {
$cp->amount = $this->toMoneyWithCurrencyCode(round((100 + $cp->markup_percentage) * $mp->min_amount / 100), $country->currency_code ?? 'XAF');
}
$mp->min_amount = $this->toMoneyWithCurrencyCode($mp->min_amount, $country->currency_code ?? 'XAF');
$mp->max_insurance_coverage_amount = $this->toMoneyWithCurrencyCode($mp->max_insurance_coverage_amount, $country->currency_code ?? 'XAF');
$mp->payment_period = trans('states.' . $mp->payment_period);
$mp->child_prices = $years_prices;
}
foreach ($months_prices as $mp) {
foreach ($mp->child_prices as $cp) {
unset($cp->markup_percentage);
}
}
$insurance->months_prices = $months_prices;
unset($insurance->nhc_id);
foreach ($insurances as $network) {
$this->formatInsuranceNetwork($network);
}
}
return $this->successResponse($insurances);
}
/**
* @OA\Get(
* path="/insurances/networks/{id}",
* summary="Afficher les infos sur un reseau d'assurance",
* tags={"Assurances"},
* security={{"api_key":{}}},
* @OA\Parameter(
* parameter="id",
* name="id",
* description="ID du reseau",
* in="path",
* required=false,
* @OA\Schema(
* type="integer",
* default=78
* )
* ),
* @OA\Response(
* response=200,
* description="OK",
* @OA\JsonContent(
* ref="#/components/schemas/ApiResponse",
* example = {
* "status" : 200,
* "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"}}}},
* "error":null
* }
* )
* )
* )
*/
public function getSingleInsuranceNetwork($id)
{
$insurance_network = current(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.family_coverage_sharing, nhc.id as nhc_id
FROM networks n JOIN configWallet cw ON cw.id_network = n.id JOIN nh_networks_configs nhc
ON nhc.network_id = n.id WHERE nhc.network_id = :network_id AND cw.type = 'ilink_sante' AND n.status = 1", ['network_id' => $id]));
if (!$insurance_network)
return $this->errorResponse(trans('errors.network_not_found'));
$this->formatInsuranceNetwork($insurance_network);
return $this->successResponse($insurance_network);
}
private function formatInsuranceNetwork($insurance_network): void
{
$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]);
$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]);
foreach ($months_prices as $mp) {
foreach ($years_prices as $cp) {
$cp->amount = $this->toMoneyWithCurrencyCode(round((100 + $cp->markup_percentage) * $mp->min_amount / 100), $country->currency_code ?? 'XAF');
}
$mp->min_amount = $this->toMoneyWithCurrencyCode($mp->min_amount, $country->currency_code ?? 'XAF');
$mp->max_insurance_coverage_amount = $this->toMoneyWithCurrencyCode($mp->max_insurance_coverage_amount, $country->currency_code ?? 'XAF');
$mp->payment_period = trans('states.' . $mp->payment_period);
$mp->child_prices = $years_prices;
}
foreach ($months_prices as $mp) {
foreach ($mp->child_prices as $cp) {
unset($cp->markup_percentage);
}
}
$insurance_network->months_prices = $months_prices;
unset($insurance_network->nhc_id);
}
/**
* @OA\Get(
@ -305,7 +354,7 @@ class InsuranceController extends Controller
* @OA\Schema(ref="#/components/schemas/add_beneficiaries"),
* example = {"password" : "1234", "beneficiaries":{{"lastname":"Djery","firstname":"DI","gender":"M","birthdate":"2001-10-05",
* "affiliation":"CHILD","birthdate_proof":"CERTIFIED_COPY","birthdate_proof_doc":"birth.jpg","justice_doc":"just.png","marriage_certificate_doc":"mariage.png",
* "id_document_type":"CNI","id_document_front":"cni_front.jpg","id_document_back":"cni_front.jpg"}}}
* "id_document_type":"CNI","id_document_front":"cni_front.jpg","id_document_back":"cni_front.jpg","profile_image":"profile_image.jpg"}}}
* )
* ),
* @OA\Response(
@ -353,6 +402,7 @@ class InsuranceController extends Controller
'beneficiaries.*.id_document_type' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
'beneficiaries.*.id_document_front' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
'beneficiaries.*.id_document_back' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
'beneficiaries.*.profile_image' => 'required|string',
]);
$insurance = NhInsurance::findOrFail($id);
@ -655,6 +705,12 @@ class InsuranceController extends Controller
* type="string",
* example= "12345"
* ),
* @OA\Property(
* property="month_price_id",
* description = "Mot de passe",
* type="string",
* example= "12345"
* ),
* ),
* ),
* ),
@ -673,6 +729,7 @@ class InsuranceController extends Controller
{
$this->validate($request, [
'password' => 'required|string',
'month_price_id' => 'required|integer|exists:nh_months_prices_grid,id'
]);
$insurance = NhInsurance::findOrFail($id);
@ -695,6 +752,10 @@ class InsuranceController extends Controller
if (!isset($networkConfig) || $networkConfig->configWallet->type != 'ilink_sante')
return $this->errorResponse(trans('errors.nano_health_not_activated'));
$monthPrice = $networkConfig->monthsPricesGrid()->where('id', $request->input('month_price_id'))->first();
if (!isset($monthPrice))
return $this->errorResponse(trans('errors.incorrect_selected_amount'));
// Verification de l'age du beneficiaire
$insuredAge = date_diff(date_create($user->identification->birth_date), date_create('now'))->y;
if ($insuredAge > $networkConfig->age_limit_of_insured_and_spouse) {
@ -704,8 +765,6 @@ class InsuranceController extends Controller
if (sizeof($insurance->beneficiaries) > $networkConfig->max_number_of_beneficiaries)
return $this->errorResponse(trans('errors.number_of_beneficiaries_exceeded'));
$monthPrice = $insurance->monthsGrid;
$currency = $this->getNetworkCurrency($insurance->network_id);
try {
@ -727,6 +786,7 @@ class InsuranceController extends Controller
$datetime = $this->getCurrentTimeByCountryCode($user->network->country->code_country);
$insurance->update([
'months_grid_id' => $monthPrice->id,
'number_of_beneficiaries' => sizeof($insurance->beneficiaries),
'total_bonus_amount' => $total_bonus_amount,
'bonus_amount' => $bonus_amount,

View File

@ -201,9 +201,15 @@ class InsuranceInvoiceController extends Controller
* type="number",
* example = 32450,
* description="Montant à payer"
* ),
* @OA\Property(property="payment_method",
* type="string",
* enum = {"wallet" ,"mobile_money","card"},
* example = "wallet",
* description="Methode de paiement"
* )
* ),
* example = {"password":"adbc1215448", "amount" : 50000 }
* example = {"password":"adbc1215448", "amount" : 50000 , "payment_method" : "wallet" }
* )
* ),
* @OA\Response(
@ -221,10 +227,12 @@ class InsuranceInvoiceController extends Controller
{
$this->validate($request, [
'password' => 'required|string',
'amount' => 'required|numeric|min:0'
'amount' => 'required|numeric|min:0',
'payment_method' => 'required|in:wallet,mobile_money,card'
]);
$amountToPaid = $request->input('amount');
$payment_method = $request->input('payment_method');
$invoice = NhInsurancesInvoice::findOrFail($id);
$datetime = $this->getCurrentTimeByCountryCode($invoice->insurance->network->country->code_country);
@ -261,7 +269,7 @@ class InsuranceInvoiceController extends Controller
return $this->errorResponse(trans('errors.minimum amount_to_paid', ['amount' => $this->toMoneyWithCurrencyCode($invoice->amount_per_split, $currency)]));
}
if ($user->wallet->balance < $amountToPaid) {
if ($payment_method == 'wallet' && $user->wallet->balance < $amountToPaid) {
$remains_amount = $amountToPaid - $user->wallet->balance;
return $this->errorResponse(trans('errors.insufficient_balance', ['amount' => $this->toMoneyWithCurrencyCode($remains_amount, $currency)]));
}
@ -275,7 +283,9 @@ class InsuranceInvoiceController extends Controller
$walletHyperviseur->save();
$user->balance_nano_health += $amountToPaid;
$user->wallet->balance -= $amountToPaid;
if ($payment_method == 'wallet') {
$user->wallet->balance -= $amountToPaid;
}
$user->wallet->save();
$user->save();

View File

@ -276,6 +276,11 @@ class InsuranceSubscriptionController extends Controller
* example="id_document_back.jpg",
* description="Pièce identité verso"
* ),
* @OA\Property(property="profile_image",
* type="string",
* example="profile_image.jpg",
* description="Profile image"
* ),
* )
*/
$this->validate($request, [
@ -295,6 +300,7 @@ class InsuranceSubscriptionController extends Controller
'beneficiaries.*.id_document_type' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
'beneficiaries.*.id_document_front' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
'beneficiaries.*.id_document_back' => 'required_if:beneficiaries.*.affiliation,SPOUSE|string',
'beneficiaries.*.profile_image' => 'required|string',
]);
$user = User::findOrFail($request->input('user_id'));
@ -409,7 +415,7 @@ class InsuranceSubscriptionController extends Controller
if ($request->hasfile('files')) {
foreach ($request->file('files') as $file) {
$filename = $this->uploadImage($file, 'NH', 'insurances-subscriptions-docs');
array_push($files, $filename);
$files[] = $filename;
}
}

View File

@ -28,6 +28,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property string|null $id_document_type
* @property string|null $id_document_front
* @property string|null $id_document_back
* @property string|null $profile_image
* @property string|null $deleted_at
* @property Carbon $created_at
* @property Carbon $updated_at
@ -57,7 +58,8 @@ class NhHavingRight extends Model
'marriage_certificate_doc',
'id_document_type',
'id_document_front',
'id_document_back'
'id_document_back',
'profile_image'
];
public function getAffiliationTrAttribute()

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddProfileImageToNhHavingRights extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('nh_having_rights', function (Blueprint $table) {
$table->string('profile_image')->nullable()->after('id_document_back')->comment("Photo de profil");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('nh_having_rights', function (Blueprint $table) {
$table->dropColumn('profile_image');
});
}
}

View File

@ -20,6 +20,7 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
$router->group(['prefix' => '/insurances'], function () use ($router) {
$router->get('', 'InsuranceController@getInsurances');
$router->get('networks', 'InsuranceController@getInsurancesNetworks');
$router->get('networks/{id}', 'InsuranceController@getSingleInsuranceNetwork');
$router->put('{id}/add-beneficiaries', 'InsuranceController@addBeneficiaries');
$router->put('{id}/delete-beneficiaries', 'InsuranceController@deleteBeneficiaries');
$router->put('{id}/stop', 'InsuranceController@stopInsurance');