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) {
|
||||
try{
|
||||
$factureFilenames = $this->orderPdfService->generateOrderPdfByOrderId($orderId,$this->idNextcloud);
|
||||
return json_encode($factureFilenames);
|
||||
return json_encode($factureFilenames["filenames"]);
|
||||
}
|
||||
catch(\OCP\Files\NotFoundException $e) { }
|
||||
}
|
||||
|
||||
@ -130,7 +130,10 @@ class DevisPdfService {
|
||||
$storage->newFile($ff_pdf);
|
||||
$file_pdf = $storage->get($ff_pdf);
|
||||
$file_pdf->putContent($pdfContent);
|
||||
$filenames[] = $ff_pdf;
|
||||
$filenames[] = [
|
||||
"name" => $pdfFilename.'.pdf',
|
||||
"path" => $ff_pdf,
|
||||
];
|
||||
}
|
||||
return $filenames;
|
||||
}
|
||||
|
||||
@ -233,6 +233,8 @@ class GestionService {
|
||||
//Nothing to do manage fo a private calendar
|
||||
return;
|
||||
}
|
||||
$orderContent = [];
|
||||
$attachmentsCalendar = [];
|
||||
|
||||
$thanato = $this->GetThanatoFromVCalendarString($vCalendarString);
|
||||
if($thanato != null){
|
||||
@ -269,33 +271,30 @@ class GestionService {
|
||||
$order = $this->orderBdd->getOrderByDevisId($devisId);
|
||||
$this->logger->debug(json_encode($order));
|
||||
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);
|
||||
$this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid);
|
||||
$this->devisPdfService->generateDevisPdfByDevisId($devisId,$this->userConnectedUuid);
|
||||
//Move calendar attachment file to defunt folder
|
||||
if (VCalendarHelpers::hasAttachment($vCalendarString)) {
|
||||
$devis = $this->gestionBdd->getDevisByDevisId($devisId);
|
||||
if($devis != null && $devis["client_entreprise"] != null){
|
||||
|
||||
//Move calendar attachment file to defunt folder
|
||||
$devisExist = $devis != null && $devis["client_entreprise"] != null;
|
||||
if (VCalendarHelpers::hasAttachment($vCalendarString)) {
|
||||
if($devisExist){
|
||||
$destinationFolderAttachment = FolderHelpers::GetDefuntFolder($devis["client_entreprise"],$devis["defunt_nom"]);
|
||||
$attachments = VCalendarHelpers::extractAttachments($vCalendarString);
|
||||
$attachmentsCalendar = VCalendarHelpers::extractAttachments($vCalendarString);
|
||||
$this->moveCalendarAttachmentFile($attachmentsCalendar,$destinationFolderAttachment);
|
||||
|
||||
|
||||
|
||||
$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 {
|
||||
if (!$thanatoIsSubcontractor) {
|
||||
$roomToken = $this->talkService->getRoomTokenBeetwenTwoUser($this->userConnectedUuid, $userName);
|
||||
if($roomToken != null){
|
||||
foreach ( $attachments as $attachment) {
|
||||
foreach ( $attachmentsCalendar as $attachment) {
|
||||
$this->userConnectedStorage->getFullPath("/");
|
||||
$path = Filesystem::getPath($attachment['file_id']);
|
||||
$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);
|
||||
}
|
||||
catch(Exception $e){
|
||||
@ -501,8 +508,10 @@ class GestionService {
|
||||
$this->logger->debug("error creating devis");
|
||||
}
|
||||
}
|
||||
|
||||
private function extractBodyOfEmailAttachment($emailId){
|
||||
if ( $emailId == null || $emailId == '') {
|
||||
return [];
|
||||
}
|
||||
$messageId = (int) $emailId;
|
||||
try {
|
||||
$message = $this->mailManager->getMessage($this->currentUserId, $messageId);
|
||||
@ -510,7 +519,10 @@ class GestionService {
|
||||
$account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
|
||||
|
||||
} catch (DoesNotExistException $e) {
|
||||
|
||||
return [];
|
||||
}
|
||||
if ($account == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$client = $this->clientFactory->getClient($account);
|
||||
@ -529,10 +541,11 @@ class GestionService {
|
||||
return [
|
||||
"body" => $fullMessage["body"] ?? '',
|
||||
"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("/");
|
||||
$subject = "Piece jointe";
|
||||
$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 en souhaitant bonne réception</p>
|
||||
|
||||
<div>" . ($emailBody['from'] ?? '') . "</div>
|
||||
<div>" . ($emailBody['subject'] ?? '') . "</div>
|
||||
<div>" . ($emailBody['body'] ?? '') . "</div>";
|
||||
|
||||
@ -547,11 +561,22 @@ class GestionService {
|
||||
$message->setSubject($subject);
|
||||
$message->setTo(recipients: [$to]);
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
$path = Filesystem::getPath($attachment['file_id']);
|
||||
$content = $this->mailer->createAttachment( Filesystem::file_get_contents($path),$attachment['name'],$attachment['mime_type']);
|
||||
foreach ($attachmentsCalendar as $attachment) {
|
||||
$path = Filesystem::getPath($attachment['file_id']) ;
|
||||
$content = $this->mailer->createAttachment( Filesystem::file_get_contents($path), ($attachment['name'] ?? null),($attachment['mime_type']) ?? null);
|
||||
$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);
|
||||
|
||||
|
||||
@ -172,7 +172,10 @@ class OrderPdfService {
|
||||
$pdf->SetOrderContent();
|
||||
$pdfContent = $pdf->Output('','S');
|
||||
$pdfFilename = $this->GetOrderFilename($orderPdfData);
|
||||
$filenames = [];
|
||||
$filenames = [
|
||||
"content" => $pdfContent,
|
||||
"filenames" => [],
|
||||
];
|
||||
foreach($orderFolders as $folder){
|
||||
try {
|
||||
$storage->newFolder($folder);
|
||||
@ -183,7 +186,7 @@ class OrderPdfService {
|
||||
$storage->newFile($ff_pdf);
|
||||
$file_pdf = $storage->get($ff_pdf);
|
||||
$file_pdf->putContent($pdfContent);
|
||||
$filenames[] = $ff_pdf;
|
||||
$filenames["filenames"][] = $ff_pdf;
|
||||
}
|
||||
return $filenames;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user