Merge branch 'h2f/features/add-to-cc-the-mailer' into releases/release-h2f
This commit is contained in:
commit
26d0ecaa70
@ -242,7 +242,7 @@ class OrderController extends Controller {
|
|||||||
public function exportOrderToPdf($orderId) {
|
public function exportOrderToPdf($orderId) {
|
||||||
try{
|
try{
|
||||||
$factureFilenames = $this->orderPdfService->generateOrderPdfByOrderId($orderId,$this->idNextcloud);
|
$factureFilenames = $this->orderPdfService->generateOrderPdfByOrderId($orderId,$this->idNextcloud);
|
||||||
return json_encode($factureFilenames);
|
return json_encode($factureFilenames["filenames"]);
|
||||||
}
|
}
|
||||||
catch(\OCP\Files\NotFoundException $e) { }
|
catch(\OCP\Files\NotFoundException $e) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -130,7 +130,10 @@ class DevisPdfService {
|
|||||||
$storage->newFile($ff_pdf);
|
$storage->newFile($ff_pdf);
|
||||||
$file_pdf = $storage->get($ff_pdf);
|
$file_pdf = $storage->get($ff_pdf);
|
||||||
$file_pdf->putContent($pdfContent);
|
$file_pdf->putContent($pdfContent);
|
||||||
$filenames[] = $ff_pdf;
|
$filenames[] = [
|
||||||
|
"name" => $pdfFilename.'.pdf',
|
||||||
|
"path" => $ff_pdf,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
return $filenames;
|
return $filenames;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -233,6 +233,8 @@ class GestionService {
|
|||||||
//Nothing to do manage fo a private calendar
|
//Nothing to do manage fo a private calendar
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$orderContent = [];
|
||||||
|
$attachmentsCalendar = [];
|
||||||
|
|
||||||
$thanato = $this->GetThanatoFromVCalendarString($vCalendarString);
|
$thanato = $this->GetThanatoFromVCalendarString($vCalendarString);
|
||||||
if($thanato != null){
|
if($thanato != null){
|
||||||
@ -269,33 +271,30 @@ class GestionService {
|
|||||||
$order = $this->orderBdd->getOrderByDevisId($devisId);
|
$order = $this->orderBdd->getOrderByDevisId($devisId);
|
||||||
$this->logger->debug(json_encode($order));
|
$this->logger->debug(json_encode($order));
|
||||||
if($order != null){
|
if($order != null){
|
||||||
$this->orderPdfService->generateOrderPdfByOrderId($order['id'],$this->userConnectedUuid);
|
$orderPdf = $this->orderPdfService->generateOrderPdfByOrderId($order['id'],$this->userConnectedUuid);
|
||||||
|
if (!empty($orderPdf['content'])) {
|
||||||
|
$orderContent[] = $orderPdf['content'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devisId,$userName);
|
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devisId,$userName);
|
||||||
$this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid);
|
$this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid);
|
||||||
$this->devisPdfService->generateDevisPdfByDevisId($devisId,$this->userConnectedUuid);
|
$this->devisPdfService->generateDevisPdfByDevisId($devisId,$this->userConnectedUuid);
|
||||||
|
$devis = $this->gestionBdd->getDevisByDevisId($devisId);
|
||||||
|
|
||||||
//Move calendar attachment file to defunt folder
|
//Move calendar attachment file to defunt folder
|
||||||
|
$devisExist = $devis != null && $devis["client_entreprise"] != null;
|
||||||
if (VCalendarHelpers::hasAttachment($vCalendarString)) {
|
if (VCalendarHelpers::hasAttachment($vCalendarString)) {
|
||||||
$devis = $this->gestionBdd->getDevisByDevisId($devisId);
|
if($devisExist){
|
||||||
if($devis != null && $devis["client_entreprise"] != null){
|
|
||||||
$destinationFolderAttachment = FolderHelpers::GetDefuntFolder($devis["client_entreprise"],$devis["defunt_nom"]);
|
$destinationFolderAttachment = FolderHelpers::GetDefuntFolder($devis["client_entreprise"],$devis["defunt_nom"]);
|
||||||
$attachments = VCalendarHelpers::extractAttachments($vCalendarString);
|
$attachmentsCalendar = VCalendarHelpers::extractAttachments($vCalendarString);
|
||||||
|
$this->moveCalendarAttachmentFile($attachmentsCalendar,$destinationFolderAttachment);
|
||||||
|
|
||||||
|
if (!$thanatoIsSubcontractor) {
|
||||||
|
|
||||||
$this->moveCalendarAttachmentFile($attachments,$destinationFolderAttachment);
|
|
||||||
if ($thanatoIsSubcontractor) {
|
|
||||||
$thanatoHasEmail = $thanato["thanato_email"] != null;
|
|
||||||
if($thanatoHasEmail){
|
|
||||||
$emailBody = $this->extractBodyOfEmailAttachment(VCalendarHelpers::getEmailIdInVCalendar($vCalendarString));
|
|
||||||
$this->sendEmailAndAttachment($thanato["thanato_email"] , $devis["defunt_nom"],$emailBody ,$attachments);
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
$roomToken = $this->talkService->getRoomTokenBeetwenTwoUser($this->userConnectedUuid, $userName);
|
$roomToken = $this->talkService->getRoomTokenBeetwenTwoUser($this->userConnectedUuid, $userName);
|
||||||
if($roomToken != null){
|
if($roomToken != null){
|
||||||
foreach ( $attachments as $attachment) {
|
foreach ( $attachmentsCalendar as $attachment) {
|
||||||
$this->userConnectedStorage->getFullPath("/");
|
$this->userConnectedStorage->getFullPath("/");
|
||||||
$path = Filesystem::getPath($attachment['file_id']);
|
$path = Filesystem::getPath($attachment['file_id']);
|
||||||
$destination = 'Talk/';
|
$destination = 'Talk/';
|
||||||
@ -304,10 +303,18 @@ class GestionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($thanatoIsSubcontractor && $devisExist) {
|
||||||
|
$thanatoHasEmail = $thanato["thanato_email"] != null;
|
||||||
|
if($thanatoHasEmail){
|
||||||
|
$emailBody = $this->extractBodyOfEmailAttachment(VCalendarHelpers::getEmailIdInVCalendar($vCalendarString));
|
||||||
|
$this->sendEmailAndAttachment($thanato["thanato_email"] , $devis["defunt_nom"],$emailBody ,$attachmentsCalendar ,$orderContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$userName);
|
$this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$userName);
|
||||||
}
|
}
|
||||||
catch(Exception $e){
|
catch(Exception $e){
|
||||||
@ -501,8 +508,10 @@ class GestionService {
|
|||||||
$this->logger->debug("error creating devis");
|
$this->logger->debug("error creating devis");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function extractBodyOfEmailAttachment($emailId){
|
private function extractBodyOfEmailAttachment($emailId){
|
||||||
|
if ( $emailId == null || $emailId == '') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
$messageId = (int) $emailId;
|
$messageId = (int) $emailId;
|
||||||
try {
|
try {
|
||||||
$message = $this->mailManager->getMessage($this->currentUserId, $messageId);
|
$message = $this->mailManager->getMessage($this->currentUserId, $messageId);
|
||||||
@ -510,8 +519,11 @@ class GestionService {
|
|||||||
$account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
|
$account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
|
||||||
|
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
if ($account == null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$client = $this->clientFactory->getClient($account);
|
$client = $this->clientFactory->getClient($account);
|
||||||
try {
|
try {
|
||||||
@ -529,10 +541,11 @@ class GestionService {
|
|||||||
return [
|
return [
|
||||||
"body" => $fullMessage["body"] ?? '',
|
"body" => $fullMessage["body"] ?? '',
|
||||||
"subject" => $fullMessage["subject"] ?? '',
|
"subject" => $fullMessage["subject"] ?? '',
|
||||||
|
'from' => $fullMessage["from"] ? $fullMessage["from"]['label'] : '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendEmailAndAttachment($to , $defunt_nom ,$emailBody = [] ,$attachments = []){
|
public function sendEmailAndAttachment($to , $defunt_nom ,$emailBody = [] ,$attachmentsCalendar = [] ,$attachmentOrderContent = []){
|
||||||
$this->userConnectedStorage->getFullPath("/");
|
$this->userConnectedStorage->getFullPath("/");
|
||||||
$subject = "Piece jointe";
|
$subject = "Piece jointe";
|
||||||
$body = "
|
$body = "
|
||||||
@ -540,6 +553,7 @@ class GestionService {
|
|||||||
<p>Vous trouverez ci-dessous l'email et le(s) pièce(s) jointe(s) de « $defunt_nom ».</p>
|
<p>Vous trouverez ci-dessous l'email et le(s) pièce(s) jointe(s) de « $defunt_nom ».</p>
|
||||||
<p>Vous en souhaitant bonne réception</p>
|
<p>Vous en souhaitant bonne réception</p>
|
||||||
|
|
||||||
|
<div>" . ($emailBody['from'] ?? '') . "</div>
|
||||||
<div>" . ($emailBody['subject'] ?? '') . "</div>
|
<div>" . ($emailBody['subject'] ?? '') . "</div>
|
||||||
<div>" . ($emailBody['body'] ?? '') . "</div>";
|
<div>" . ($emailBody['body'] ?? '') . "</div>";
|
||||||
|
|
||||||
@ -547,11 +561,22 @@ class GestionService {
|
|||||||
$message->setSubject($subject);
|
$message->setSubject($subject);
|
||||||
$message->setTo(recipients: [$to]);
|
$message->setTo(recipients: [$to]);
|
||||||
|
|
||||||
foreach ($attachments as $attachment) {
|
foreach ($attachmentsCalendar as $attachment) {
|
||||||
$path = Filesystem::getPath($attachment['file_id']);
|
$path = Filesystem::getPath($attachment['file_id']) ;
|
||||||
$content = $this->mailer->createAttachment( Filesystem::file_get_contents($path),$attachment['name'],$attachment['mime_type']);
|
$content = $this->mailer->createAttachment( Filesystem::file_get_contents($path), ($attachment['name'] ?? null),($attachment['mime_type']) ?? null);
|
||||||
$message->attach($content);
|
$message->attach($content);
|
||||||
}
|
}
|
||||||
|
foreach ($attachmentOrderContent as $orderContent) {
|
||||||
|
$content = $this->mailer->createAttachment( $orderContent ,"bdc.pdf", "application/pdf");
|
||||||
|
$message->attach($content);
|
||||||
|
}
|
||||||
|
|
||||||
|
$senderEmailAddress = $this->config->getSystemValue('mail_from_address') ?? null;
|
||||||
|
$senderEmailDomain = $this->config->getSystemValue('mail_domain') ?? null;
|
||||||
|
if($senderEmailAddress && $senderEmailDomain){
|
||||||
|
$senderEmail = $senderEmailAddress.'@'.$senderEmailDomain;
|
||||||
|
$message->setCc([$senderEmail]);
|
||||||
|
}
|
||||||
|
|
||||||
$message->setHtmlBody($body);
|
$message->setHtmlBody($body);
|
||||||
|
|
||||||
|
|||||||
@ -172,7 +172,10 @@ class OrderPdfService {
|
|||||||
$pdf->SetOrderContent();
|
$pdf->SetOrderContent();
|
||||||
$pdfContent = $pdf->Output('','S');
|
$pdfContent = $pdf->Output('','S');
|
||||||
$pdfFilename = $this->GetOrderFilename($orderPdfData);
|
$pdfFilename = $this->GetOrderFilename($orderPdfData);
|
||||||
$filenames = [];
|
$filenames = [
|
||||||
|
"content" => $pdfContent,
|
||||||
|
"filenames" => [],
|
||||||
|
];
|
||||||
foreach($orderFolders as $folder){
|
foreach($orderFolders as $folder){
|
||||||
try {
|
try {
|
||||||
$storage->newFolder($folder);
|
$storage->newFolder($folder);
|
||||||
@ -183,7 +186,7 @@ class OrderPdfService {
|
|||||||
$storage->newFile($ff_pdf);
|
$storage->newFile($ff_pdf);
|
||||||
$file_pdf = $storage->get($ff_pdf);
|
$file_pdf = $storage->get($ff_pdf);
|
||||||
$file_pdf->putContent($pdfContent);
|
$file_pdf->putContent($pdfContent);
|
||||||
$filenames[] = $ff_pdf;
|
$filenames["filenames"][] = $ff_pdf;
|
||||||
}
|
}
|
||||||
return $filenames;
|
return $filenames;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user