finish devis new model, WIP frontend part when generating devis and multiple devis

This commit is contained in:
Tiavina 2025-01-13 11:54:47 +03:00
parent c1a69f0d73
commit bd5b27b32f
6 changed files with 607 additions and 6 deletions

View File

@ -145,5 +145,9 @@ return [
//testTalk
['name' => 'page#testTalk', 'url' => '/testTalk', 'verb' => 'POST'],
//devis pdf
['name' => 'page#exportDevisToPdf', 'url' => '/devis/exportDevisToPdf', 'verb' => 'POST'],
['name' => 'page#exportDevisByClientAndMonthYearToPdf', 'url' => '/devis/exportDevisByClientAndMonthYearToPdf', 'verb' => 'POST'],
]
];

View File

@ -21,11 +21,11 @@ use \IntlDateFormatter;
use \FPDF;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Service\Certificate\CertificateService;
use OCA\Gestion\Service\Devis\Pdf\DevisPdfService;
use OCA\Gestion\Service\ExportClientStatisticService;
use OCA\Gestion\Service\ExportThanatoStatisticService;
use OCA\Gestion\Service\InvoicePdfService;
use OCA\Gestion\Service\TalkService;
use Ramsey\Uuid\Uuid;
date_default_timezone_set('Europe/Paris');
@ -68,6 +68,9 @@ class PageController extends Controller {
/** @var TalkService */
private $talkService;
/** @var DevisPdfService */
private $devisPdfService;
/**
* Constructor
*/
@ -85,7 +88,8 @@ class PageController extends Controller {
ExportClientStatisticService $exportClientStatisticService,
InvoicePdfService $invoicePdfService,
CertificateService $certificateService,
TalkService $talkService) {
TalkService $talkService,
DevisPdfService $devisPdfService) {
parent::__construct($AppName, $request);
@ -100,6 +104,7 @@ class PageController extends Controller {
$this->certificateService = $certificateService;
$this->defaultImagePath = $this->sharedImagePath.self::DEFAULT_NEXTCLOUD_ADMIN.'/files/.gestion/';
$this->talkService = $talkService;
$this->devisPdfService = $devisPdfService;
//$this->fpdf = $fpdf;
if ($userSession->isLoggedIn()) {
@ -2966,4 +2971,38 @@ class PageController extends Controller {
}
catch(\OCP\Files\NotFoundException $e) { }
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $devisId
*
*/
public function exportDevisToPdf($devisId){
try{
$devisFilenames = $this->devisPdfService->generateDevisPdfByDevisId($devisId,$this->idNextcloud);
return json_encode($devisFilenames);
}
catch(\OCP\Files\NotFoundException $e) { }
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param string $clientId
* @param string $month
* @param string $year
*
*/
public function exportDevisByClientAndMonthYearToPdf($clientId,$month,$year){
try{
$devisFilename = $this->devisPdfService->generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$this->idNextcloud);
return $devisFilename;
}
catch(\OCP\Files\NotFoundException $e) { }
}
}

View File

@ -2062,7 +2062,7 @@ class Bdd {
return $devis;
}
private function setDevisStartAndEndTime($devis){
public function setDevisStartAndEndTime($devis){
$calendarData = $this->getCalendarDataByCalendarObjectUuid($devis["calendar_uuid"]);
$devisTimeValue = VCalendarHelpers::GetStartAndEndTimeFromVCalendarString($calendarData);
$devis["startTime"] = $devisTimeValue["startTime"];
@ -2200,7 +2200,7 @@ class Bdd {
return null;
}
private function getDevisProduits($devisId){
public function getDevisProduits($devisId){
$sql = "SELECT
produit_devis.id,
produit_devis.produit_id,
@ -2411,6 +2411,48 @@ class Bdd {
return $factureData;
}
private function getDevisByClientAndMonthYear($clientId,$month,$year){
$sql = "SELECT
devis.id as devis_id,
devis.date as devis_date,
devis.num as calendar_uuid,
devis.comment as devis_comment,
devis.id_client as devis_id_client,
client.nom as client_nom,
client.entreprise as client_entreprise,
client.adresse as client_adresse,
defunt.nom as defunt_nom,
defunt.sexe as defunt_sexe,
lieu.nom as lieu_nom,
lieu.adresse as lieu_adresse,
thanato.nom as thanato_nom,
thanato.prenom as thanato_prenom
FROM ".$this->tableprefix."devis as devis
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
WHERE devis.id_client = ? AND
YEAR(devis.date) = ?";
$conditions = [$clientId,$year];
if($month != 0){
$conditions[] = $month;
$sql .= " AND MONTH(devis.date) = ?";
}
$sql .= ";";
$devisList = $this->execSQLNoJsonReturn(
$sql,
$conditions);
return $devisList;
}
public function getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$configuration){
$devisList = $this->getDevisByClientAndMonthYear($clientId,$month,$year);
return $devisList;
}
public function getInvoicePdfDataByClientAndMonthYear($clientId,$month,$year,$configuration){
$invoices = $this->getInvoiceByClientAndMonthYear($clientId,$month,$year);
$firstClient = $this->getFirstClient();
@ -2473,6 +2515,38 @@ class Bdd {
return $factures;
}
public function getDevisPdfDataByDevisId($devisId){
$sql = "SELECT
devis.id as devis_id,
devis.date as devis_date,
devis.num as calendar_uuid,
devis.devis_full_number as devis_full_number,
devis.comment as devis_comment,
client.nom as client_nom,
client.entreprise as client_entreprise,
client.adresse as client_adresse,
defunt.nom as defunt_nom,
defunt.sexe as defunt_sexe,
lieu.nom as lieu_nom,
lieu.adresse as lieu_adresse,
thanato.nom as thanato_nom,
thanato.prenom as thanato_prenom
FROM ".$this->tableprefix."devis as devis
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
WHERE devis.id = ?
;";
$devis = $this->execSQLNoJsonReturn(
$sql,
[$devisId]);
if(!empty($devis)){
return $devis[0];
}
return null;
}
private function getFactureByIdWithDevis($factureId){
$sql = "SELECT
facture.id,

View File

@ -12,8 +12,8 @@ class FileExportHelpers
}
public static function GetAddressAndCityFromAddress(string $adresse){
$adresseResult = "";
$cityResult = "";
$adresseResult = "Aucun adresse";
$cityResult = "Aucune ville";
$adresses = explode("-",$adresse);
if(isset($adresses[0])){
$adresseResult = self::RemoveSpaceFromString($adresses[0]);

View File

@ -0,0 +1,294 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Gestion\Service\Devis\Pdf;
use DateTime;
use \FPDF;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Helpers\PriceHelpers;
class DevisPdfHandler extends FPDF {
private $multipleDevisData = [];
private $devisData = [];
private $logo = null;
private $logoPath = "/var/www/html/data/admin/files/.gestion/";
function Header()
{
if($this->logo != "nothing"){
$this->Image($this->logoPath."logo.png", 10, 10, 75, 25);
}
else{
$this->Cell(55,30,'');
}
}
function Footer()
{
$this->SetY(-40);
$this->SetFont('Arial', '', 7);
$this->MultiCell(0,5,utf8_decode(html_entity_decode('Tout retard de paiement entraînera de plein droit une pénalité de retard de 3 fois le taux légal ( Loi 2008-776 du 4 août 2008) et une indemnité forfaitaire de 40 EUR pour frais de recouvrement sera appliquée.')));
$this->Ln(1);
$this->MultiCell(0,5,utf8_decode(html_entity_decode('Si les frais de recouvrement sont supérieurs à ce montant forfaitaire, une indemnisation complémentaire sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du code de commerce ).
')));
$this->SetY(-15);
$this->SetFont('Arial', 'B', 8);
$this->Cell(0, 10, utf8_decode(html_entity_decode($this->devisData['configuration']->legal_one)), 0, 0, 'C');
}
public function SetDevisPdfData(array $devisData,$logo = null){
$this->devisData = $devisData;
$this->logo = $logo;
}
public function SetMultipleDevisPdfData(array $multipleDevisData,$logo = null){
$this->multipleDevisData = $multipleDevisData;
$this->logo = $logo;
}
private function DrawDevisCompanyAndClientInfo(){
$this->SetY(40);
$this->SetFont('Arial', '', 12);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->devisData['configuration']->entreprise), 0, 0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->devisData['client_nom']), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->devisData['configuration_adresse']), 0, 0);
$this->Cell(0, 7, trim(FileExportHelpers::FormatTextForExport($this->devisData['client_real_adress'])), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport($this->devisData['configuration_adresse_city']), 0, 0);border:
$this->Cell(0, 7, trim(FileExportHelpers::FormatTextForExport($this->devisData['client_adress_city'])), 0, 1,'R');
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->devisData['configuration']->telephone),0,0);
$this->Cell(0, 7, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->devisData['siret'], 0, 1,'R');
$this->Cell(0, 7, 'Mail : ' . $this->devisData['configuration']->mail, 0, 1);
$this->Ln(3);
}
private function DrawDevisInfoTable(){
$this->SetFont('Arial', 'B', 11);
$this->Cell(30, 7, 'DATE', 1, 0, 'C');
$this->Cell(80, 7, 'CLIENT', 1, 0, 'C');
$this->Cell(40, 7, 'DEVIS', 1, 1, 'C');
$this->SetFont('Arial', '', 10);
$this->Cell(30, 7, $this->devisData['devis_date'], 1, 0, 'C');
$this->Cell(80, 7, utf8_decode(html_entity_decode($this->devisData['client_nom'])), 1, 0, 'C');
$this->Cell(40, 7, $this->devisData['devis_full_number'], 1, 1, 'C');
$this->Ln(8);
}
private function DrawArticlesTable(){
$this->SetLineWidth(0.1);
$this->Rect(10, 105, 190, 100, "D");
// cadre titre des colonnes
$this->Line(10, 115, 200,115);
// les traits verticaux colonnes
$this->Line(35, 105, 35, 205);
$this->Line(135, 105, 135, 205);
$this->Line(155, 105, 155, 205);
$this->Line(175, 105, 175, 205);
}
private function DrawArticlesTableHeader(){
$tvaValue = $this->devisData["configuration"]->tva_default;
$this->SetFont('Arial','',10);
$this->SetXY( 10,106 );
$this->Cell( 20, 8, "Date", 0, 0, 'C');
$this->SetXY( 35,106 );
$this->Cell( 100, 8, "Description", 0, 0, 'C');
$this->SetXY( 135,106 );
$this->Cell( 20, 8, "Prix Uni. HT", 0, 0, 'C');
$this->SetXY( 155,106 );
$this->Cell( 20, 8, 'TVA ' . $tvaValue . '%', 0, 0, 'C');
$this->SetXY( 175,106 );
$this->Cell( 25, 8, "Prix Uni. TTC", 0, 0, 'C');
}
public function DrawArticlesTableValueAndReturnTotalPrice(){
$this->SetFont('Arial','',10);
$tvaValue = $this->devisData["configuration"]->tva_default;
$totalHt = 0;
$totalTtc = 0;
$totalTva = 0;
$products = $this->devisData["products"];
$yValue = 116;
foreach($products as $product){
$valueHt = $product['produit_price'];
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue);
$totalHt+=$valueHt;
$totalTtc+=$valueTtc;
$productDescription = $product["produit_description"];
$dateValue = "";
if($product === end($products)){
$dateValue = $this->devisData['devis_date'];
$productDescription .= " de " . FileExportHelpers::GetSexeLabel($this->devisData['defunt_sexe']) . ' '. $this->devisData["defunt_nom"];
}
$tvaAmount = $valueTtc - $valueHt;
$this->SetXY( 10,$yValue );
$this->Cell(20, 6, $dateValue, 0,0);
$this->SetXY( 35,$yValue );
$this->MultiAlignCell(100, 6, utf8_decode(html_entity_decode($productDescription)),0,'0',);
$this->SetXY( 135,$yValue );
$this->Cell(20, 6, number_format($valueHt,2,'.','').chr(128), 0, 0, 'C');
$this->SetXY( 155,$yValue );
$this->Cell(20, 6, number_format($tvaAmount,2,'.','').chr(128), 0, 0, 'C');
$this->SetXY( 175,$yValue );
$this->Cell(25, 6, number_format($valueTtc,2,'.','').chr(128), 0, 1, 'C');
$yValue += 12;
$totalTva += $tvaAmount;
}
return [
"TOTAL HT" => $totalHt,
"TVA ".$tvaValue. "%" => $totalTva,
"TOTAL TTC" => $totalTtc
];
}
private function DrawBankAndTotalPriceInfo($totalPriceArray){
$this->SetY(210);
$this->SetFont('Arial', '', 9);
$this->MultiCell(0,5,utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de ". $this->devisData['configuration']->entreprise)));
$this->MultiCell(0,5,utf8_decode(html_entity_decode("en indiquant le numéro de facture, ou par virement :")));
$this->Ln(1);
//Table IBAN
$this->SetFont('Arial', '', 11);
$ibanWidth = 90;
$ibanCursorY = $this->GetY();
$this->Cell($ibanWidth, 7, 'IBAN : FR76 1360 6000 1436 5418 1800 038', 1, 1, 'C');
$ibanCursorX = $this->GetX();
$this->Cell($ibanWidth, 7, 'Code SWIFT : AGRI FR PP 836', 1, 1, 'C');
//TABLE HT
$ibanLastPositionX = $ibanCursorX+$ibanWidth + 20;
$startOfArrayX = $ibanLastPositionX;
$startOfArrayY = $ibanCursorY;
foreach($totalPriceArray as $label => $price){
$this->SetXY($startOfArrayX,$startOfArrayY);
$this->Cell(40, 7, $label, 1, 1, 'C');
$this->SetXY($startOfArrayX + 40,$startOfArrayY);
$this->Cell(40, 7, number_format($price,2,'.','').chr(128), 1, 1, 'C');
$startOfArrayY += 7;
}
}
public function SetMultipleDevisContent(){
foreach($this->multipleDevisData as $devisData){
$this->devisData = $devisData;
$this->SetDevisContent();
}
}
public function SetDevisContent(){
$this->AddPage();
$this->SetMargins(10,0,10);
$this->DrawDevisCompanyAndClientInfo();
$this->DrawDevisInfoTable();
$this->DrawArticlesTable();
$this->DrawArticlesTableHeader();
$totalPriceValue = $this->DrawArticlesTableValueAndReturnTotalPrice();
$this->DrawBankAndTotalPriceInfo($totalPriceValue);
}
function MultiAlignCell($w,$h,$text,$border=0,$ln=0,$align='L',$fill=false)
{
// Store reset values for (x,y) positions
$x = $this->GetX() + $w;
$y = $this->GetY();
// Make a call to FPDF's MultiCell
$this->MultiCell($w,$h,$text,$border,$align,$fill);
// Reset the line position to the right, like in Cell
if( $ln==0 )
{
$this->SetXY($x,$y);
}
}
function NbLines($w, $txt)
{
// Compute the number of lines a MultiCell of width w will take
if(!isset($this->CurrentFont))
$this->Error('No font has been set');
$cw = $this->CurrentFont['cw'];
if($w==0)
$w = $this->w-$this->rMargin-$this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
$s = str_replace("\r",'',(string)$txt);
$nb = strlen($s);
if($nb>0 && $s[$nb-1]=="\n")
$nb--;
$sep = -1;
$i = 0;
$j = 0;
$l = 0;
$nl = 1;
while($i<$nb)
{
$c = $s[$i];
if($c=="\n")
{
$i++;
$sep = -1;
$j = $i;
$l = 0;
$nl++;
continue;
}
if($c==' ')
$sep = $i;
$l += $cw[$c];
if($l>$wmax)
{
if($sep==-1)
{
if($i==$j)
$i++;
}
else
$i = $sep+1;
$sep = -1;
$j = $i;
$l = 0;
$nl++;
}
else
$i++;
}
return $nl;
}
}

View File

@ -0,0 +1,190 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Gestion\Service\Devis\Pdf;
use DateTime;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCP\Files\IRootFolder;
class DevisPdfService {
/** @var Bdd */
private $gestionBdd;
/** @var IRootFolder */
private $rootFolder;
private const DEFAULT_NEXTCLOUD_ADMIN = "admin";
public function __construct(
Bdd $gestionBdd,
IRootFolder $rootFolder) {
$this->gestionBdd = $gestionBdd;
$this->rootFolder = $rootFolder;
}
private function getLogo(){
$storage = $this->rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
try{
try {
if(isset($storage)){
$file = $storage->get('/.gestion/logo.png');
}else{
return "nothing";
}
} catch(\OCP\Files\NotFoundException $e) {
$file = $storage->get('/.gestion/logo.jpeg');
}
}
catch(\OCP\Files\NotFoundException $e) {
return "nothing";
}
return base64_encode($file->getContent());
}
private function getDevisPdfFilename($devisData){
$filename = "DEVIS-";
$defuntNom = str_replace('&nbsp;',' ',$devisData['defunt_nom']);
$devisLocation = str_replace('&nbsp;',' ',$devisData['lieu_nom']);
return $filename.$defuntNom.'-'.$devisLocation;
}
private function formatMultipleDevisToPdfFormat($multipleDevisData,$configuration){
foreach($multipleDevisData as &$devis){
$devis = $this->formatDevisDataToPdfDataFormat($devis,$configuration);
}
return $multipleDevisData;
}
private function formatDevisDataToPdfDataFormat($devis,$configuration){
$devisDate = $devis['devis_date'];
$devisDate = DateTime::createFromFormat('Y-m-d',$devisDate);
$devisDate = $devisDate->format('d-m-Y');
$devis['devis_date'] = $devisDate;
$devis['configuration'] = $configuration;
$products = $this->gestionBdd->getDevisProduits($devis["devis_id"]);
$devis = $this->gestionBdd->setDevisStartAndEndTime($devis);
$firstClient = $this->gestionBdd->getFirstClient();
$devis["siret"] = $firstClient != null ? $firstClient['legal_one'] : '';
$devis["products"] = $products;
$clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($devis["client_adresse"]);
$devis["client_real_adress"] = $clientAdresses["address"];
$devis["client_adress_city"] = $clientAdresses["city"];
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
$devis["configuration_adresse"] = $configurationAdresses["address"];
$devis["configuration_adresse_city"] = $configurationAdresses["city"];
return $devis;
}
public function generateDevisPdfByDevisId($devisId,$idNextCloud){
$storage = $this->rootFolder->getUserFolder($idNextCloud);
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$logo = $this->getLogo();
$devisPdfData = $this->gestionBdd->getDevisPdfDataByDevisId($devisId);
if($devisPdfData == null){
return "";
}
$devisPdfDataFormatted = $this->formatDevisDataToPdfDataFormat($devisPdfData,$currentConfig);
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
$devisPdfFolders = $this->getDevisPdfFolder($devisPdfDataFormatted,$clean_folder);
$pdf = new DevisPdfHandler();
$pdf->SetDevisPdfData($devisPdfDataFormatted,$logo);
$pdf->SetDevisContent();
$pdfContent = $pdf->Output('','S');
$pdfFilename = $this->getDevisPdfFilename($devisPdfDataFormatted);
$filenames = [];
foreach($devisPdfFolders as $folder){
try {
$storage->newFolder($folder);
}
catch(\OCP\Files\NotPermittedException $e) {
}
$ff_pdf = $folder.$pdfFilename.'.pdf';
$storage->newFile($ff_pdf);
$file_pdf = $storage->get($ff_pdf);
$file_pdf->putContent($pdfContent);
$filenames[] = $ff_pdf;
}
return $filenames;
}
private function getDevisPdfFolder(array $devisPdfData,$racinePath){
$clientRacineFolder = $racinePath.'CLIENTS/'.strtoupper($devisPdfData["client_entreprise"]).'/';
$defuntsFolder = $clientRacineFolder.'DEFUNTS/'.strtoupper($devisPdfData['defunt_nom']).'/'.'DEVIS'.'/';
$devisDate = $devisPdfData['devis_date'];
$devisDatetime = new DateTime($devisDate);
$devisDateYear = $devisDatetime->format('Y');
$devisMonth = DateHelpers::GetDateWithFormatDayAndMonthPlainString($devisPdfData['devis_date']);
$devisByYearFolder = $clientRacineFolder."$devisDateYear".'/'.$devisMonth.'/'.'DEVIS'.'/';
return [
$defuntsFolder,
$devisByYearFolder
];
}
private function GetMultipleDevisFilename($multipleDevisData,$month,$year){
$filename = "";
foreach($multipleDevisData as $devis){
$filename = strtoupper($devis["client_entreprise"]);
$filename .= $month != 0 ? '_'.DateHelpers::GetMonthPlainString($month) :'';
$filename .= "_".$year;
break;
}
return $filename;
}
public function generateMultipleDevisPdfByClientAndMonthYear($clientId,$month,$year,$idNextCloud){
$storage = $this->rootFolder->getUserFolder($idNextCloud);
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$logo = $this->getLogo();
$mulitpleDevisData = $this->gestionBdd->getDevisPdfDataByClientAndMonthYear($clientId,$month,$year,$currentConfig);
if(empty($mulitpleDevisData)){
return null;
}
$multipleDevisDataFormatted = $this->formatMultipleDevisToPdfFormat($mulitpleDevisData,$currentConfig);
$pdf = new DevisPdfHandler();
$pdf->SetMultipleDevisPdfData($multipleDevisDataFormatted,$logo);
$pdf->SetMultipleDevisContent();
$racinePath = html_entity_decode(string: $currentConfig->path).'/';
$clientRacineFolder = $racinePath.'CLIENTS/'.strtoupper($multipleDevisDataFormatted[0]["client_entreprise"]).'/';
$filename = 'DEVIS'.'_'.$this->GetMultipleDevisFilename($multipleDevisDataFormatted,$month,$year);
$filenamePath = $clientRacineFolder.$filename.'.pdf';
$pdfContent = $pdf->Output('','S');
try {
$storage->newFolder($clientRacineFolder);
}
catch(\OCP\Files\NotPermittedException $e) {
}
$storage->newFile($filenamePath);
$file_pdf = $storage->get($filenamePath);
$file_pdf->putContent($pdfContent);
return $filenamePath;
}
}