From c1a2ba708ec9ee0c06fea23ff865c52c3d991743 Mon Sep 17 00:00:00 2001 From: Narindra ezway Date: Fri, 25 Apr 2025 16:55:01 +0300 Subject: [PATCH] [Invoice] add authenticated user's email address in cc --- gestion/lib/Controller/InvoiceController.php | 22 ++++++++++++-------- gestion/lib/Controller/PageController.php | 13 ++++++++---- gestion/templates/content/defuntshow.php | 4 ++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/gestion/lib/Controller/InvoiceController.php b/gestion/lib/Controller/InvoiceController.php index 6c22a80..502a82f 100644 --- a/gestion/lib/Controller/InvoiceController.php +++ b/gestion/lib/Controller/InvoiceController.php @@ -12,6 +12,8 @@ use OCA\Gestion\Helpers\DateHelpers; use OCA\Gestion\Service\MailerService; use OCP\AppFramework\Http\DataResponse; use OCA\Gestion\Service\InvoicePdfService; +use OCP\IUserSession; + date_default_timezone_set('Europe/Paris'); class InvoiceController extends Controller { @@ -25,6 +27,9 @@ class InvoiceController extends Controller private $config; + private $user; + + public function __construct( $UserId, @@ -35,7 +40,8 @@ class InvoiceController extends Controller InvoicePdfService $invoicePdfService, IRootFolder $rootFolder, IMailer $mailer, - MailerService $mailerService + MailerService $mailerService, + IUserSession $userSession ) { @@ -46,6 +52,7 @@ class InvoiceController extends Controller $this->gestionRepository = $bdd; $this->mailerService = $mailerService; $this->config = $config; + $this->user = $userSession->getUser(); try{ $this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud); @@ -98,12 +105,7 @@ class InvoiceController extends Controller $factureContent = $factureGeneratedResponse["content"]; $factureDate = DateHelpers::convertInvoiceDateToMonthAndYearOnly($facture['date_paiement']); try { - $senderEmailAddress = $this->config->getSystemValue('mail_from_address') ?? null; - $senderEmailDomain = $this->config->getSystemValue('mail_domain') ?? null; - $senderEmail = null; - if($senderEmailAddress && $senderEmailDomain){ - $senderEmail = $senderEmailAddress.'@'.$senderEmailDomain; - } + $message = $this->mailer->createMessage(); $message->setTo(recipients: [$email => "Facture"]); $content = $this->mailer->createAttachment($factureContent, "Facture.pdf", "application/pdf"); @@ -117,9 +119,11 @@ class InvoiceController extends Controller "

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

". $signature ); - if($senderEmail != null){ - $message->setCc([$senderEmail]); + $authUserEmail = $this->user->getEMailAddress(); + if ($authUserEmail) { + $message->setCc([$authUserEmail]); } + $this->mailer->send($message); $this->gestionRepository->setFactureSentDate($factureId); } catch (Exception $e) { diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index 6c67ea4..1c874d1 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -80,6 +80,9 @@ class PageController extends Controller { private $rootFolder; private $mailerService; + + + /** * Constructor */ @@ -99,7 +102,8 @@ class PageController extends Controller { CertificateService $certificateService, TalkService $talkService, DevisPdfService $devisPdfService, - MailerService $mailerService + MailerService $mailerService, + ) { parent::__construct($AppName, $request); @@ -1614,9 +1618,10 @@ class PageController extends Controller { "

$body_text

". $signature ); - - if($senderEmail != null){ - $message->setCc([$senderEmail]); + + $authUserEmail = $this->user->getEMailAddress(); + if ($authUserEmail) { + $message->setCc([$authUserEmail]); } $this->mailer->send($message); return new DataResponse("", 200, ['Content-Type' => 'application/json']); diff --git a/gestion/templates/content/defuntshow.php b/gestion/templates/content/defuntshow.php index e7e2f6d..573bbf9 100644 --- a/gestion/templates/content/defuntshow.php +++ b/gestion/templates/content/defuntshow.php @@ -540,10 +540,10 @@ $coverProducts = $_['coverProducts']; class="form-control rounded-sm" placeholder="adresse email" type="text" - value="client_group_mail ?? $_['defunt'][0]->client_mail; ?>" + value="client_mail ?? '' ?>" style="cursor:pointer;margin-right:8px;" id="valueSendEmailModal" - data-init-value="client_group_mail ?? $_['defunt'][0]->client_mail; ?>" + data-init-value="client_mail ?? ''; ?>" >