diff --git a/gestion/lib/Controller/OrderController.php b/gestion/lib/Controller/OrderController.php index d7f4489..6735bed 100644 --- a/gestion/lib/Controller/OrderController.php +++ b/gestion/lib/Controller/OrderController.php @@ -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) { } } diff --git a/gestion/lib/Service/Devis/Pdf/DevisPdfService.php b/gestion/lib/Service/Devis/Pdf/DevisPdfService.php index 97e5498..7b81b8a 100644 --- a/gestion/lib/Service/Devis/Pdf/DevisPdfService.php +++ b/gestion/lib/Service/Devis/Pdf/DevisPdfService.php @@ -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; } diff --git a/gestion/lib/Service/GestionService.php b/gestion/lib/Service/GestionService.php index 9340132..395f16a 100644 --- a/gestion/lib/Service/GestionService.php +++ b/gestion/lib/Service/GestionService.php @@ -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); + $devis = $this->gestionBdd->getDevisByDevisId($devisId); + //Move calendar attachment file to defunt folder + $devisExist = $devis != null && $devis["client_entreprise"] != null; if (VCalendarHelpers::hasAttachment($vCalendarString)) { - $devis = $this->gestionBdd->getDevisByDevisId($devisId); - if($devis != null && $devis["client_entreprise"] != null){ + 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,8 +519,11 @@ class GestionService { $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId()); } catch (DoesNotExistException $e) { - - } + return []; + } + if ($account == null) { + return []; + } $client = $this->clientFactory->getClient($account); try { @@ -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 {
Vous trouverez ci-dessous l'email et le(s) pièce(s) jointe(s) de « $defunt_nom ».
Vous en souhaitant bonne réception
+