Improve GET /generate-invoice

This commit is contained in:
Djery-Tom 2022-02-14 16:08:54 +01:00
parent 861c1296c9
commit f351fe5ada
5 changed files with 39 additions and 5 deletions

View File

@ -19,6 +19,36 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
class InvoiceController extends Controller class InvoiceController extends Controller
{ {
/**
* @OA\Get(
* path="/generate-invoice",
* summary="Facturer les feuilles de soins",
* tags={"Factures"},
* security={{"api_key":{}}},
* @OA\Parameter(
* parameter="network_agent_id",
* name="network_agent_id",
* description="ID de l'agent dans le reseau",
* @OA\Schema(
* type="integer"
* ),
* in="query",
* required=true
* ),
* @OA\Response(
* response=200,
* description="OK",
* @OA\JsonContent(
* ref="#/components/schemas/ApiResponse",
* example = {
* "status" : 200,
* "response" : "La facture a été générée",
* "error":null
* }
* )
* )
* )
*/
// Generer les factures periodiquement pour chaque agent // Generer les factures periodiquement pour chaque agent
public function generateInvoice(Request $request) public function generateInvoice(Request $request)
{ {
@ -30,7 +60,7 @@ class InvoiceController extends Controller
$hyper = AgentPlus::where('network_id', $agent->network_id)->where('category', 'hyper')->first(); $hyper = AgentPlus::where('network_id', $agent->network_id)->where('category', 'hyper')->first();
$config = NhNetworksConfig::where('network_id', $agent->network_id)->first(); $config = NhNetworksConfig::where('network_id', $agent->network_id)->first();
if (!isset($config)) { if (!isset($config)) {
return $this->errorResponse("Le nano sante n'est pas actif pour ce reseau"); return $this->errorResponse(__('errors.nano_health_not_activated'));
} }
// executer le script chaque Dimanche a minuit // executer le script chaque Dimanche a minuit
@ -62,7 +92,7 @@ class InvoiceController extends Controller
->where('created_at', '>=', $start_at)->where('created_at', '<=', $end_at)->orderBy('created_at', 'DESC')->get(); ->where('created_at', '>=', $start_at)->where('created_at', '<=', $end_at)->orderBy('created_at', 'DESC')->get();
if (sizeof($sheets) == 0) { if (sizeof($sheets) == 0) {
return $this->errorResponse("Aucune feuille de soins acceptée"); return $this->errorResponse(__('errors.no_sheet_accepted'));
} }
foreach ($sheets as $sheet) { foreach ($sheets as $sheet) {
@ -135,7 +165,7 @@ class InvoiceController extends Controller
Log::error($t->getMessage() . " :\n" . $t->getTraceAsString()); Log::error($t->getMessage() . " :\n" . $t->getTraceAsString());
} }
return $this->successResponse("Invoice generated"); return $this->successResponse(__('messages.invoice_generated'));
} }
/** /**

View File

@ -48,5 +48,6 @@ return [
'insurance_not_in_order' => "This insurance is not in order", 'insurance_not_in_order' => "This insurance is not in order",
"insurance_expired" => "Your insurance is :state. You cannot perform this operation", "insurance_expired" => "Your insurance is :state. You cannot perform this operation",
'cannot_renew_insurance' => "Your insurance is not stopped, you cannot renew it", 'cannot_renew_insurance' => "Your insurance is not stopped, you cannot renew it",
'already_insured' => "Vous avez deja souscrit à cette assurance" 'already_insured' => "Vous avez deja souscrit à cette assurance",
'no_sheet_accepted' => "No care sheet accepted"
]; ];

View File

@ -173,4 +173,5 @@ Your insurance has been renewed.
- Number of months: :months - Number of months: :months
", ",
'insurance_renew_paid' => "Insurance renewal paid", 'insurance_renew_paid' => "Insurance renewal paid",
"invoice_generated" => "Invoice has been generated"
]; ];

View File

@ -48,5 +48,6 @@ return [
'insurance_not_in_order' => "Cette assurance n'est pas en règle", 'insurance_not_in_order' => "Cette assurance n'est pas en règle",
"insurance_expired" => "Votre assurance est :state. Vous ne pouvez pas effectuer cette opération", "insurance_expired" => "Votre assurance est :state. Vous ne pouvez pas effectuer cette opération",
'cannot_renew_insurance' => "Votre assurance n'est pas en arrêt , vous ne pouvez pas la renouveler", 'cannot_renew_insurance' => "Votre assurance n'est pas en arrêt , vous ne pouvez pas la renouveler",
'already_insured' => "Vous avez deja souscrit à cette assurance" 'already_insured' => "Vous avez deja souscrit à cette assurance",
'no_sheet_accepted' => "Aucune feuille de soins acceptée"
]; ];

View File

@ -190,4 +190,5 @@ Votre assurance a été renouvelée.
- Nombre de mois : :months - Nombre de mois : :months
", ",
'insurance_renew_paid' => "Renouvellement de l'assurance payée", 'insurance_renew_paid' => "Renouvellement de l'assurance payée",
"invoice_generated" => "La facture a été générée"
]; ];