HOTFIX facture group and simple

This commit is contained in:
Tolotsoa 2025-09-05 01:21:33 +03:00
parent 25b27a7f32
commit a0d17190bf
3 changed files with 80 additions and 60 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OCA\Gestion\Controller; namespace OCA\Gestion\Controller;
use OCA\Gestion\Constants\BddConstant; use OCA\Gestion\Constants\BddConstant;
@ -16,7 +17,7 @@ use OCA\Gestion\Service\InvoicePdfService;
use OCP\IUserSession; use OCP\IUserSession;
date_default_timezone_set('Europe/Paris'); date_default_timezone_set('Europe/Paris');
class InvoiceController extends Controller class InvoiceController extends Controller
{ {
private Bdd $gestionRepository; private Bdd $gestionRepository;
private InvoicePdfService $invoicePdfService; private InvoicePdfService $invoicePdfService;
@ -43,9 +44,7 @@ class InvoiceController extends Controller
IMailer $mailer, IMailer $mailer,
MailerService $mailerService, MailerService $mailerService,
IUserSession $userSession IUserSession $userSession
) {
)
{
$this->currentUserIdNextcloud = $UserId; $this->currentUserIdNextcloud = $UserId;
$this->invoicePdfService = $invoicePdfService; $this->invoicePdfService = $invoicePdfService;
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
@ -55,27 +54,27 @@ class InvoiceController extends Controller
$this->config = $config; $this->config = $config;
$this->user = $userSession->getUser(); $this->user = $userSession->getUser();
try{ try {
$this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud); $this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud);
}catch(\OC\User\NoUserException $e){ } catch(\OC\User\NoUserException $e) {
} }
parent::__construct($AppName, request: $request); parent::__construct($AppName, request: $request);
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
*/ */
public function getInvoicePdfContent($factureId){ public function getInvoicePdfContent($factureId)
{
$facture = $this->gestionRepository->getFactureByFactureId($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']); return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']);
} }
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->currentUserIdNextcloud); $factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId, $this->currentUserIdNextcloud);
if($factureGeneratedResponse == null){ if($factureGeneratedResponse == null) {
return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']); return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']);
} }
$factureContent = base64_encode($factureGeneratedResponse['content']); $factureContent = base64_encode($factureGeneratedResponse['content']);
@ -85,18 +84,17 @@ class InvoiceController extends Controller
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
*/ */
public function sendInvoicePdfViaMail($factureId, $email = '') public function sendInvoicePdfViaMail($factureId, $email = '')
{ {
$facture = $this->gestionRepository->getFactureByFactureId($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']); return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']);
} }
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->currentUserIdNextcloud); $factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId, $this->currentUserIdNextcloud);
if($factureGeneratedResponse == null){ if($factureGeneratedResponse == null) {
return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']); return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']);
} }
$factureContent = $factureGeneratedResponse["content"]; $factureContent = $factureGeneratedResponse["content"];
@ -109,10 +107,11 @@ class InvoiceController extends Controller
$message->attach($content); $message->attach($content);
$message->setSubject("Facture"); $message->setSubject("Facture");
$signature = $this->mailerService->getFooterContent(); $signature = $this->mailerService->getFooterContent($this->getUserNameForEmailSignature());
$message->setHtmlBody( $message->setHtmlBody(
"<p>Bonjour.</p>". "<p>Bonjour.</p>".
"<p> Vous trouverez en pièce jointe la facture des soins de " . $factureDate . ".</p>". "<p> Vous trouverez en pièce jointe la facture des soins de " . $factureDate . ".</p>".
$signature $signature
); );
@ -128,4 +127,11 @@ class InvoiceController extends Controller
} }
return new DataResponse("E-mail envoyé avec succès à ".$email.".", 200, ['Content-Type' => 'application/json']); return new DataResponse("E-mail envoyé avec succès à ".$email.".", 200, ['Content-Type' => 'application/json']);
} }
public function getUserNameForEmailSignature()
{
$configs = json_decode($this->gestionRepository->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD));
$currentConfig = $configs[0];
return $currentConfig->nom . " " . $currentConfig->prenom;
}
} }

View File

@ -3352,6 +3352,7 @@ class Bdd
if($factureData == null) { if($factureData == null) {
return null; return null;
} }
$products = $this->getDevisProduits($factureData["devis_id"]); $products = $this->getDevisProduits($factureData["devis_id"]);
$isDevisNegative = $this->isDevisNegative($factureData['devis_id'], $factureData['client_id']); $isDevisNegative = $this->isDevisNegative($factureData['devis_id'], $factureData['client_id']);
$factureData = $this->setDevisStartAndEndTime($factureData); $factureData = $this->setDevisStartAndEndTime($factureData);
@ -3359,6 +3360,11 @@ class Bdd
$factureData["products"] = $products; $factureData["products"] = $products;
$factureData["configuration"] = $configuration; $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; $isClientInsideGroup = $factureData["group_id"] != null;
if($isClientInsideGroup) { if($isClientInsideGroup) {
$factureData["client_real_adress"] = $factureData["group_address"]; $factureData["client_real_adress"] = $factureData["group_address"];
@ -3371,11 +3377,15 @@ class Bdd
$factureData["client_real_adress"] = $clientAdresses["address"]; $factureData["client_real_adress"] = $clientAdresses["address"];
$factureData["client_adress_city"] = $clientAdresses["city"]; $factureData["client_adress_city"] = $clientAdresses["city"];
} }
$factureData['is_negative'] = $isDevisNegative; $factureData['is_negative'] = $isDevisNegative;
$factureData["is_tva"] = $hasTva;
$factureData["client_tva_intracommu"] = $groupClient["tva_intracommu"];
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse); $configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
$factureData["configuration_adresse"] = $configurationAdresses["address"]; $factureData["configuration_adresse"] = $configurationAdresses["address"];
$factureData["configuration_adresse_city"] = $configurationAdresses["city"]; $factureData["configuration_adresse_city"] = $configurationAdresses["city"];
return $factureData; return $factureData;
} }

View File

@ -29,40 +29,44 @@ namespace OCA\Gestion\Service;
use OCA\Gestion\Constants\BddConstant; use OCA\Gestion\Constants\BddConstant;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
class MailerService { class MailerService
{
private $adminStorage; private $adminStorage;
public function __construct( public function __construct(
IRootFolder $rootFolder, IRootFolder $rootFolder,
){ ) {
$this->adminStorage = $rootFolder->getUserFolder(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD); $this->adminStorage = $rootFolder->getUserFolder(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
} }
public function getFooterContent ($userName = "Johann"){ public function getFooterContent($userName = "DEKINDT Vanessa")
$wish = "<p>Vous en souhaitant bonne réception. </p>"; {
$wish = "<p>Vous en souhaitant bonne réception. </p>";
$cordialement = "<p> Cordialement,</p>"; $cordialement = "<p> Cordialement,</p>";
$userName = "<p> {$userName} </p>" ; $userName = "<p> {$userName} </p>" ;
$signatureImage = $this->getSignatureHtmlEmailContent(); // $signatureImage = $this->getSignatureHtmlEmailContent();
return $wish . $cordialement .$userName . $signatureImage ; // return $wish . $cordialement .$userName . $signatureImage ;
} return $wish . $cordialement .$userName ;
}
private function getSignatureHtmlEmailContent (){ private function getSignatureHtmlEmailContent()
$signatureImage = $this->getSignatureContent(); {
if (!$signatureImage) { $signatureImage = $this->getSignatureContent();
return ""; if (!$signatureImage) {
} return "";
return "<img width='170' height='80' style= 'width: 170;height: 80px;display:block;' src='data:image/jpeg;base64,".base64_encode($signatureImage)."'>" ; }
} return "<img width='170' height='80' style= 'width: 170;height: 80px;display:block;' src='data:image/jpeg;base64,".base64_encode($signatureImage)."'>" ;
}
private function getSignatureContent(){ private function getSignatureContent()
try{ {
if(isset($this->adminStorage)){ try {
$file = $this->adminStorage->get('/.gestion/sign.jpg'); if(isset($this->adminStorage)) {
return $file->getContent(); $file = $this->adminStorage->get('/.gestion/sign.jpg');
} return $file->getContent();
} }
catch(\OCP\Files\NotFoundException $e) {} } catch(\OCP\Files\NotFoundException $e) {
}
return false; return false;
} }
} }