2021-11-15 15:01:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
2021-11-15 15:59:42 +00:00
|
|
|
* path="/insured",
|
2021-11-19 16:07:42 +00:00
|
|
|
* summary="Rechercher un assuré (par reseau , par nom ou par numero de telephone)",
|
2021-11-15 15:01:54 +00:00
|
|
|
* tags={"Assurés"},
|
|
|
|
* security={{"api_key":{}}},
|
2021-11-19 16:07:42 +00:00
|
|
|
* @OA\Parameter(
|
|
|
|
* parameter="network_id",
|
|
|
|
* name="network_id",
|
|
|
|
* description="ID du reseau",
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="integer"
|
|
|
|
* ),
|
|
|
|
* in="query",
|
|
|
|
* required=true
|
|
|
|
* ),
|
2022-01-18 11:00:05 +00:00
|
|
|
* @OA\Parameter(
|
|
|
|
* parameter="insured_id",
|
|
|
|
* name="insured_id",
|
|
|
|
* description="Numero d'assuré",
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string"
|
|
|
|
* ),
|
|
|
|
* in="query",
|
|
|
|
* required=false
|
|
|
|
* ),
|
2021-11-15 15:01:54 +00:00
|
|
|
* @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":4,"network_id":250,"user_id":349,"insured_id":"GJKS8ZGBEJTL","number_of_months":3,"bonus_amount":"150000.00",
|
|
|
|
* "number_of_beneficiaries":2,"total_bonus_amount":"495000.00","start_at":"2021-11-11T21:54:02.000000Z","end_at":"2022-02-11T21:54:02.000000Z",
|
2021-11-19 16:07:42 +00:00
|
|
|
* "state":"PAID","created_at":"2021-11-11T20:54:02.000000Z","updated_at":"2021-11-11T20:54:02.000000Z","user":{"id":349,
|
|
|
|
* "firstname":null,"lastname":"Tom Di","phone":"+237690716648","email":"ddoubletom@gmail.com"},"network":{"id":250,"name":"Cnamgs-pharmacies"}}},
|
2021-11-15 15:01:54 +00:00
|
|
|
* "error":null
|
|
|
|
* }
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
*/
|
2021-11-15 15:59:42 +00:00
|
|
|
public function getInsured(Request $request)
|
2021-11-15 15:01:54 +00:00
|
|
|
{
|
2022-01-18 11:00:05 +00:00
|
|
|
$insured_id = $request->input('insured_id');
|
2021-11-15 15:01:54 +00:00
|
|
|
$name = $request->input('name');
|
|
|
|
$phone = $request->input('phone');
|
2021-11-19 16:07:42 +00:00
|
|
|
$network_id = $request->input('network_id');
|
2022-02-28 14:53:07 +00:00
|
|
|
$currency_code = $this->getNetworkCurrency($network_id);
|
2021-11-15 15:01:54 +00:00
|
|
|
|
2022-02-28 14:53:07 +00:00
|
|
|
$q = NhInsurance::with(['user:id,firstname,lastname,phone,email', 'network:id,name', 'beneficiaries', 'nhNetworkConfig'])->where('network_id', $network_id);
|
2021-11-15 15:01:54 +00:00
|
|
|
|
2022-01-18 11:00:05 +00:00
|
|
|
if (!empty($insured_id)) {
|
|
|
|
$q = $q->where('insured_id', $insured_id);
|
|
|
|
}
|
|
|
|
|
2022-01-03 16:36:06 +00:00
|
|
|
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();
|
2022-02-28 14:53:07 +00:00
|
|
|
foreach ($insured as $i) {
|
|
|
|
$monthPrice = $i->nhNetworkConfig->monthsPricesGrid()->where('number_of_months', $i->number_of_months)->first();
|
|
|
|
$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);
|
|
|
|
}
|
2021-11-15 15:01:54 +00:00
|
|
|
return $this->successResponse($insured);
|
|
|
|
}
|
|
|
|
}
|