add cc on send email (facture,attestation)

This commit is contained in:
Tiavina 2025-04-02 12:59:40 +03:00
parent 748d7e7fbf
commit 8a7f3758ce
2 changed files with 24 additions and 0 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
namespace OCA\Gestion\Controller; namespace OCA\Gestion\Controller;
use OCP\IConfig;
use OCP\IRequest; use OCP\IRequest;
use OCP\DB\Exception; use OCP\DB\Exception;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
@ -22,11 +23,14 @@ class InvoiceController extends Controller
private $storage; private $storage;
private $mailerService; private $mailerService;
private $config;
public function __construct( public function __construct(
$UserId, $UserId,
$AppName, $AppName,
IRequest $request, IRequest $request,
IConfig $config,
Bdd $bdd, Bdd $bdd,
InvoicePdfService $invoicePdfService, InvoicePdfService $invoicePdfService,
IRootFolder $rootFolder, IRootFolder $rootFolder,
@ -41,6 +45,7 @@ class InvoiceController extends Controller
$this->mailer = $mailer; $this->mailer = $mailer;
$this->gestionRepository = $bdd; $this->gestionRepository = $bdd;
$this->mailerService = $mailerService; $this->mailerService = $mailerService;
$this->config = $config;
try{ try{
$this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud); $this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud);
@ -93,6 +98,12 @@ class InvoiceController extends Controller
$factureContent = $factureGeneratedResponse["content"]; $factureContent = $factureGeneratedResponse["content"];
$factureDate = DateHelpers::convertInvoiceDateToMonthAndYearOnly($facture['date_paiement']); $factureDate = DateHelpers::convertInvoiceDateToMonthAndYearOnly($facture['date_paiement']);
try { 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 = $this->mailer->createMessage();
$message->setTo(recipients: [$email => "Facture"]); $message->setTo(recipients: [$email => "Facture"]);
$content = $this->mailer->createAttachment($factureContent, "Facture.pdf", "application/pdf"); $content = $this->mailer->createAttachment($factureContent, "Facture.pdf", "application/pdf");
@ -106,6 +117,9 @@ class InvoiceController extends Controller
"<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
); );
if($senderEmail != null){
$message->setCc([$senderEmail]);
}
$this->mailer->send($message); $this->mailer->send($message);
$this->gestionRepository->setFactureSentDate($factureId); $this->gestionRepository->setFactureSentDate($factureId);
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -1590,6 +1590,12 @@ class PageController extends Controller {
$devis = $this->myDb->getDevisOfDefunt($defuntId); $devis = $this->myDb->getDevisOfDefunt($defuntId);
if($devis != null){ if($devis != null){
// try { // try {
$senderEmailAddress = $this->config->getSystemValue('mail_from_address') ?? null;
$senderEmailDomain = $this->config->getSystemValue('mail_domain') ?? null;
$senderEmail = null;
if($senderEmailAddress && $senderEmailDomain){
$senderEmail = $senderEmailAddress.'@'.$senderEmailDomain;
}
$client_email = $to; $client_email = $to;
$client_nom = $devis['client_nom']; $client_nom = $devis['client_nom'];
$data = $this->storage->get($ff_pdf)->getContent(); $data = $this->storage->get($ff_pdf)->getContent();
@ -1608,6 +1614,10 @@ class PageController extends Controller {
"<p>$body_text</p>". "<p>$body_text</p>".
$signature $signature
); );
if($senderEmail != null){
$message->setCc([$senderEmail]);
}
$this->mailer->send($message); $this->mailer->send($message);
return new DataResponse("", 200, ['Content-Type' => 'application/json']); return new DataResponse("", 200, ['Content-Type' => 'application/json']);
// } catch (Exception $e) { // } catch (Exception $e) {