From a0d17190bf58773644386632ed498c821c9cd0b7 Mon Sep 17 00:00:00 2001 From: Tolotsoa Date: Fri, 5 Sep 2025 01:21:33 +0300 Subject: [PATCH] HOTFIX facture group and simple --- gestion/lib/Controller/InvoiceController.php | 68 +++++++++++--------- gestion/lib/Db/Bdd.php | 10 +++ gestion/lib/Service/MailerService.php | 62 +++++++++--------- 3 files changed, 80 insertions(+), 60 deletions(-) diff --git a/gestion/lib/Controller/InvoiceController.php b/gestion/lib/Controller/InvoiceController.php index 806b612..796581c 100644 --- a/gestion/lib/Controller/InvoiceController.php +++ b/gestion/lib/Controller/InvoiceController.php @@ -1,4 +1,5 @@ currentUserIdNextcloud = $UserId; $this->invoicePdfService = $invoicePdfService; $this->rootFolder = $rootFolder; @@ -54,65 +53,65 @@ class InvoiceController extends Controller $this->mailerService = $mailerService; $this->config = $config; $this->user = $userSession->getUser(); - - try{ - $this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud); - }catch(\OC\User\NoUserException $e){ - } + try { + $this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud); + } catch(\OC\User\NoUserException $e) { + + } parent::__construct($AppName, request: $request); } /** - * @NoAdminRequired - * @NoCSRFRequired + * @NoAdminRequired + * @NoCSRFRequired */ - public function getInvoicePdfContent($factureId){ + public function getInvoicePdfContent($factureId) + { $facture = $this->gestionRepository->getFactureByFactureId($factureId); - if($facture == null) - { + if($facture == null) { return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']); } - $factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->currentUserIdNextcloud); - if($factureGeneratedResponse == null){ + $factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId, $this->currentUserIdNextcloud); + if($factureGeneratedResponse == null) { return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']); } $factureContent = base64_encode($factureGeneratedResponse['content']); return new DataResponse([ "content" => $factureContent - ], 200, ['Content-Type' => 'application/json']); + ], 200, ['Content-Type' => 'application/json']); } /** - * @NoAdminRequired - * @NoCSRFRequired + * @NoAdminRequired + * @NoCSRFRequired */ public function sendInvoicePdfViaMail($factureId, $email = '') { $facture = $this->gestionRepository->getFactureByFactureId($factureId); - if($facture == null) - { + if($facture == null) { return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']); } - $factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->currentUserIdNextcloud); - if($factureGeneratedResponse == null){ + $factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId, $this->currentUserIdNextcloud); + if($factureGeneratedResponse == null) { return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']); } $factureContent = $factureGeneratedResponse["content"]; $factureDate = DateHelpers::convertInvoiceDateToMonthAndYearOnly($facture['date_paiement']); try { - + $message = $this->mailer->createMessage(); $message->setTo(recipients: [$email => "Facture"]); $content = $this->mailer->createAttachment($factureContent, "Facture.pdf", "application/pdf"); $message->attach($content); $message->setSubject("Facture"); - $signature = $this->mailerService->getFooterContent(); + $signature = $this->mailerService->getFooterContent($this->getUserNameForEmailSignature()); + $message->setHtmlBody( - "

Bonjour.

". + "

Bonjour.

". "

Vous trouverez en pièce jointe la facture des soins de " . $factureDate . ".

". $signature ); @@ -120,7 +119,7 @@ class InvoiceController extends Controller if ($appAdminEmail) { $message->setCc([$appAdminEmail]); } - + $this->mailer->send($message); $this->gestionRepository->setFactureSentDate($factureId); } catch (Exception $e) { @@ -128,4 +127,11 @@ class InvoiceController extends Controller } return new DataResponse("E-mail envoyé avec succès à ".$email.".", 200, ['Content-Type' => 'application/json']); } -} \ No newline at end of file + + public function getUserNameForEmailSignature() + { + $configs = json_decode($this->gestionRepository->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD)); + $currentConfig = $configs[0]; + return $currentConfig->nom . " " . $currentConfig->prenom; + } +} diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index 4f8ba57..fe7d65e 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -3352,6 +3352,7 @@ class Bdd if($factureData == null) { return null; } + $products = $this->getDevisProduits($factureData["devis_id"]); $isDevisNegative = $this->isDevisNegative($factureData['devis_id'], $factureData['client_id']); $factureData = $this->setDevisStartAndEndTime($factureData); @@ -3359,6 +3360,11 @@ class Bdd $factureData["products"] = $products; $factureData["configuration"] = $configuration; + // Récupération des informations client et gestion TVA + $client = $this->getClientById($factureData['client_id']); + $hasTva = ($client && isset($client['tva'])) ? ($client['tva'] == 1) : true; + $groupClient = $this->getTvaItracomuIdClient($factureData['client_id']); + $isClientInsideGroup = $factureData["group_id"] != null; if($isClientInsideGroup) { $factureData["client_real_adress"] = $factureData["group_address"]; @@ -3371,11 +3377,15 @@ class Bdd $factureData["client_real_adress"] = $clientAdresses["address"]; $factureData["client_adress_city"] = $clientAdresses["city"]; } + $factureData['is_negative'] = $isDevisNegative; + $factureData["is_tva"] = $hasTva; + $factureData["client_tva_intracommu"] = $groupClient["tva_intracommu"]; $configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse); $factureData["configuration_adresse"] = $configurationAdresses["address"]; $factureData["configuration_adresse_city"] = $configurationAdresses["city"]; + return $factureData; } diff --git a/gestion/lib/Service/MailerService.php b/gestion/lib/Service/MailerService.php index 5314609..d5797d6 100644 --- a/gestion/lib/Service/MailerService.php +++ b/gestion/lib/Service/MailerService.php @@ -29,40 +29,44 @@ namespace OCA\Gestion\Service; use OCA\Gestion\Constants\BddConstant; use OCP\Files\IRootFolder; -class MailerService { - +class MailerService +{ private $adminStorage; - public function __construct( + public function __construct( IRootFolder $rootFolder, - ){ + ) { $this->adminStorage = $rootFolder->getUserFolder(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); } - public function getFooterContent ($userName = "Johann"){ - $wish = "

Vous en souhaitant bonne réception.

"; + public function getFooterContent($userName = "DEKINDT Vanessa") + { + $wish = "

Vous en souhaitant bonne réception.

"; $cordialement = "

Cordialement,

"; $userName = "

{$userName}

" ; - $signatureImage = $this->getSignatureHtmlEmailContent(); - return $wish . $cordialement .$userName . $signatureImage ; - } - - private function getSignatureHtmlEmailContent (){ - $signatureImage = $this->getSignatureContent(); - if (!$signatureImage) { - return ""; - } - return "" ; - } - - private function getSignatureContent(){ - try{ - if(isset($this->adminStorage)){ - $file = $this->adminStorage->get('/.gestion/sign.jpg'); - return $file->getContent(); - } - } - catch(\OCP\Files\NotFoundException $e) {} - - return false; - } + // $signatureImage = $this->getSignatureHtmlEmailContent(); + // return $wish . $cordialement .$userName . $signatureImage ; + return $wish . $cordialement .$userName ; + } + + private function getSignatureHtmlEmailContent() + { + $signatureImage = $this->getSignatureContent(); + if (!$signatureImage) { + return ""; + } + return "" ; + } + + private function getSignatureContent() + { + try { + if(isset($this->adminStorage)) { + $file = $this->adminStorage->get('/.gestion/sign.jpg'); + return $file->getContent(); + } + } catch(\OCP\Files\NotFoundException $e) { + } + + return false; + } }