139 lines
6.3 KiB
PHP
Executable File
139 lines
6.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\InsuranceState;
|
|
use App\Models\CountriesCurrency;
|
|
use App\Models\Network;
|
|
use App\Models\NhInsurance;
|
|
use App\Models\User;
|
|
use App\Models\WalletsUser;
|
|
use App\Traits\ApiResponser;
|
|
use App\Traits\Helper;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Log;
|
|
use stdClass;
|
|
|
|
class InsuredController extends Controller
|
|
{
|
|
/**
|
|
* @OA\Get(
|
|
* path="/insured",
|
|
* summary="Rechercher un assuré (par reseau , par nom ou par numero de telephone)",
|
|
* tags={"Assurés"},
|
|
* security={{"api_key":{}}},
|
|
* @OA\Parameter(
|
|
* parameter="network_id",
|
|
* name="network_id",
|
|
* description="ID du reseau",
|
|
* @OA\Schema(
|
|
* type="integer"
|
|
* ),
|
|
* in="query",
|
|
* required=true
|
|
* ),
|
|
* @OA\Parameter(
|
|
* parameter="insured_id",
|
|
* name="insured_id",
|
|
* description="Numero d'assuré",
|
|
* @OA\Schema(
|
|
* type="string"
|
|
* ),
|
|
* in="query",
|
|
* required=false
|
|
* ),
|
|
* @OA\Parameter(
|
|
* parameter="name",
|
|
* name="name",
|
|
* description="Nom de l'utilisateur",
|
|
* @OA\Schema(
|
|
* type="string"
|
|
* ),
|
|
* in="query",
|
|
* required=false
|
|
* ),
|
|
* @OA\Parameter(
|
|
* parameter="phone",
|
|
* name="phone",
|
|
* description="Telephone de l'utilisateur",
|
|
* @OA\Schema(
|
|
* type="string"
|
|
* ),
|
|
* in="query",
|
|
* required=false
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="OK",
|
|
* @OA\JsonContent(
|
|
* ref="#/components/schemas/ApiResponse",
|
|
* example = {
|
|
* "status" : 200,
|
|
* "response" : {{"id":13,"network_id":250,"user_id":348,"insured_id":"PWXVMZNXN39P","months_grid_id":77,"bonus_amount":"50000.00","number_of_beneficiaries":1,"total_bonus_amount":"115000.00","insurance_coverage_amount":"546560.00",
|
|
* "start_at":"2022-03-31T00:00:00.000000Z","end_at":"2023-03-31T00:00:00.000000Z","state":"PAID","created_at":"2022-03-31T11:49:07.000000Z","updated_at":"2022-04-12T17:15:26.000000Z","insurance_consumed_amount":"546\u202f560 FCFA","insurance_remaining_amount":"-46\u202f560 FCFA",
|
|
* "user":{"id":348,"firstname":null,"lastname":"Manga test 5","phone":"+241074848105","email":"jmangansongo.cfao@yahoo.fr","identification":{"firstname":"","lastname":" Manga test 5","user_image":"U-1606826475.jpg","document_image_front":"D-F-1606826475.jpg",
|
|
* "document_image_back":"D-B-1606826475.jpg","id_user":348}},"network":{"id":250,"name":"Cnamgs-pharmacies"},"beneficiaries":{{"id":5,"lastname":"Zele","firstname":"Brice","gender":"M","birthdate":"1997-01-01T00:00:00.000000Z","affiliation":"CHILD","bonus_amount":"65000.00",
|
|
* "insurance_coverage_amount":"0.00","birthdate_proof":"CERTIFICATE","birthdate_proof_doc":"NH-e451b9e3-a02b-4f84-b74a-d0028cc814b0.jpg","justice_doc":null,"marriage_certificate_doc":null,"id_document_type":null,"id_document_front":null,"id_document_back":null,
|
|
* "profile_image":null,"created_at":"2021-12-01T11:12:27.000000Z","updated_at":"2021-12-01T11:12:27.000000Z","laravel_through_key":13,"insurance_consumed_amount":"0 FCFA","insurance_remaining_amount":"500\u202f000 FCFA","affiliation_tr":"ENFANT"}},
|
|
* "months_grid":{"id":77,"nh_network_config_id":1,"number_of_months":12,"min_amount":35040,"max_insurance_coverage_amount":"500000.00","waiting_period_days":null,"payment_period":"ONE_TIME","payment_duration_months":null,"number_of_fractions":1,
|
|
* "created_at":"2022-03-28T22:23:12.000000Z","updated_at":"2022-03-28T22:23:12.000000Z"}}},
|
|
* "error":null
|
|
* }
|
|
* )
|
|
* )
|
|
* )
|
|
*/
|
|
public function getInsured(Request $request)
|
|
{
|
|
$insured_id = $request->input('insured_id');
|
|
$name = $request->input('name');
|
|
$phone = $request->input('phone');
|
|
$network_id = $request->input('network_id');
|
|
$network = Network::find($network_id);
|
|
if (!isset($network)) {
|
|
return $this->errorResponse(trans('errors.network_not_found'));
|
|
}
|
|
|
|
$currency_code = $network->country->currency_code;
|
|
$datetime = $this->getCurrentTimeByCountryCode($network->country->code_country);
|
|
|
|
$q = NhInsurance::with(['user:id,firstname,lastname,phone,email', 'user.identification:firstname,lastname,user_image,document_image_front,document_image_back,id_user',
|
|
'network:id,name', 'beneficiaries', 'nhNetworkConfig', 'monthsGrid'])->where('network_id', $network_id)
|
|
->whereIn('state', [InsuranceState::PAID, InsuranceState::PARTIALLY_PAID, InsuranceState::SUSPENDED])->where('start_at', '<=', $datetime);
|
|
|
|
if (!empty($insured_id)) {
|
|
$q = $q->where('insured_id', $insured_id);
|
|
}
|
|
|
|
if (!empty($name)) {
|
|
$q = $q->whereHas('user', function ($query) use ($name) {
|
|
return $query->where('lastname', 'like', '%' . $name . '%')->orWhere('firstname', 'like', '%' . $name . '%');
|
|
});
|
|
}
|
|
|
|
if (!empty($phone)) {
|
|
$q = $q->whereHas('user', function ($query) use ($phone) {
|
|
return $query->where('phone', 'like', '%' . $phone . '%');
|
|
});
|
|
}
|
|
|
|
$insured = $q->get();
|
|
foreach ($insured as $i) {
|
|
$monthPrice = $i->monthsGrid;
|
|
$i->insurance_consumed_amount = $this->toMoneyWithCurrencyCode($i->insurance_coverage_amount, $currency_code);
|
|
$i->insurance_remaining_amount = $this->toMoneyWithCurrencyCode(($monthPrice->max_insurance_coverage_amount ?? 0) - $i->insurance_coverage_amount, $currency_code);
|
|
foreach ($i->beneficiaries as $b) {
|
|
$b->insurance_consumed_amount = $this->toMoneyWithCurrencyCode($b->insurance_coverage_amount, $currency_code);
|
|
$b->insurance_remaining_amount = $this->toMoneyWithCurrencyCode(($monthPrice->max_insurance_coverage_amount ?? 0) - $b->insurance_coverage_amount, $currency_code);
|
|
}
|
|
|
|
unset($i->nhNetworkConfig);
|
|
}
|
|
return $this->successResponse($insured);
|
|
}
|
|
}
|