diff --git a/calendar/lib/Controller/EmailBoxController.php b/calendar/lib/Controller/EmailBoxController.php index 440dfa9..0e2214d 100644 --- a/calendar/lib/Controller/EmailBoxController.php +++ b/calendar/lib/Controller/EmailBoxController.php @@ -22,7 +22,6 @@ use OCP\AppFramework\Db\DoesNotExistException; class EmailBoxController extends Controller { private ?string $currentUserId; - private IMailManager $mailManager; private IUserPreferences $preferences; @@ -71,7 +70,7 @@ class EmailBoxController extends Controller { */ public function loadEmailboxMessage(): JSONResponse { //TODO - $mailboxId = 1; + $mailboxId = 9; $lastMessageTimestamp = null; $init = false; @@ -99,7 +98,6 @@ class EmailBoxController extends Controller { return new JSONResponse([], Http::STATUS_FORBIDDEN); } - $order = $this->preferences->getPreference($this->currentUserId, 'sort-order', 'newest') === 'newest' ? 'DESC': 'ASC'; return new JSONResponse( $this->mailSearch->findMessages( diff --git a/calendar/src/components/Editor/Attachments/AttachmentsList.vue b/calendar/src/components/Editor/Attachments/AttachmentsList.vue index ad03817..c9f3c0f 100644 --- a/calendar/src/components/Editor/Attachments/AttachmentsList.vue +++ b/calendar/src/components/Editor/Attachments/AttachmentsList.vue @@ -100,11 +100,10 @@ Revenir dans la listes des emails
Pas d'Attachements
diff --git a/gestion/appinfo/routes.php b/gestion/appinfo/routes.php index 45ae3c4..f76e56a 100644 --- a/gestion/appinfo/routes.php +++ b/gestion/appinfo/routes.php @@ -203,8 +203,10 @@ return [ //user groups getUserConnectedGroups ['name' => 'page#getUserConnectedGroups', 'url' => '/getUserConnectedGroups', 'verb' => 'GET'], - - + + + ['name' => 'provider#moveAttachmentFile', 'url' => '/test-move', 'verb' => 'GET'], + ['name' => 'provider#sendEmailAttachment', 'url' => '/test-send-mail-attach', 'verb' => 'GET'], ] diff --git a/gestion/lib/Controller/ProviderController.php b/gestion/lib/Controller/ProviderController.php index 52b5eb6..8ac9079 100644 --- a/gestion/lib/Controller/ProviderController.php +++ b/gestion/lib/Controller/ProviderController.php @@ -1,29 +1,34 @@ navigationService = $navigationService; $this->configurationService = $configurationService; $this->logger = $logger; - $this->providerService = $providerService; + $this->providerService = $providerService; $this->providerStatisticService = $providerStatisticService; + $this->gestionService = $gestionService; - if ($userSession->isLoggedIn()) { - $this->user = $userSession->getUser(); - } + if ($userSession->isLoggedIn()) { + $this->user = $userSession->getUser(); + } - if ($this->user != null) { - $groups = $groupManager->getUserGroups($this->user); - $this->groups = []; - foreach ($groups as $group) { - $this->groups[] = $group->getGID(); - } - } + if ($this->user != null) { + $groups = $groupManager->getUserGroups($this->user); + $this->groups = []; + foreach ($groups as $group) { + $this->groups[] = $group->getGID(); + } + } - try{ + try { $this->storage = $rootFolder->getUserFolder($this->idNextcloud); - }catch(\OC\User\NoUserException $e){ - + } catch (\OC\User\NoUserException $e) { } } /** * @NoAdminRequired * @NoCSRFRequired - */ - public function provider() { + */ + public function provider() + { return new TemplateResponse('gestion', 'provider', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink())); } /** * @NoAdminRequired * @NoCSRFRequired - */ - public function getProviders() { + */ + public function getProviders() + { $providers = $this->providerService->getProvidersAsArray(); return json_encode($providers); } @@ -116,13 +128,13 @@ class ProviderController extends Controller { /** * @NoAdminRequired * @NoCSRFRequired - */ - public function createDefaultProvider() { - try{ + */ + public function createDefaultProvider() + { + try { $this->providerService->createDefaultProvider($this->idNextcloud); return true; - } - catch(Exception $e){ + } catch (Exception $e) { return null; } } @@ -130,14 +142,84 @@ class ProviderController extends Controller { /** * @NoAdminRequired * @NoCSRFRequired - */ - public function exportProvidersStatistic(array $providerIds,$year){ - try{ - $filenames = $this->providerStatisticService->exportProvidersStatisticByYear($providerIds,$year,$this->idNextcloud); + */ + public function exportProvidersStatistic(array $providerIds, $year) + { + try { + $filenames = $this->providerStatisticService->exportProvidersStatisticByYear($providerIds, $year, $this->idNextcloud); return $filenames; - } - catch(Exception $e){ + } catch (Exception $e) { return []; } } + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function moveAttachmentFile() + { + $tex = "BEGIN:VCALENDAR +PRODID:-//IDN nextcloud.com//Calendar app 4.7.16//EN +CALSCALE:GREGORIAN +VERSION:2.0 +BEGIN:VEVENT +CREATED:20250319T070401Z +DTSTAMP:20250319T070538Z +LAST-MODIFIED:20250319T070538Z +SEQUENCE:2 +UID:dc3ebd49-74c6-490a-afd2-2b61ef47c6f3 +DTSTART;TZID=Africa/Nairobi:20250319T110001 +DTEND;TZID=Africa/Nairobi:20250319T120001 +STATUS:CONFIRMED +SUMMARY:test 5 +LOCATION:2 +DESCRIPTION:SOINS +TRANSP:TRANSPARENT +ATTACH;FMTTYPE=image/png;FILENAME=/sign.png;X-NC-FILE-ID=1426;X-NC-HAS-PREV + IEW=true:/f/1426 +CLIENT:1 +EMBALMER: +END:VEVENT +BEGIN:VTIMEZONE +TZID:Africa/Nairobi +BEGIN:STANDARD +TZOFFSETFROM:+0300 +TZOFFSETTO:+0300 +TZNAME:EAT +DTSTART:19700101T000000 +END:STANDARD +END:VTIMEZONE +END:VCALENDAR"; + $this->gestionService->moveCalendarAttachmentFile($tex, '/f'); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + + public function sendEmailAttachment() + { + $this->storage->getFullPath("/"); + $attachments = [ + ['file_id' => 1518, 'name' => 'Capture.JPG'] + ]; + $to = "jonathan.goulet@nextcloud.com"; + $subject = "Piece jointe"; + $body = "Bonjour.
Vous trouverez en pièce jointe les fichiers votre défunt.
"; + + $message = $this->mailer->createMessage(); + $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'], 'image/png'); + $message->attach($content); + } + $message->setHtmlBody($body); + + $this->mailer->send($message); + return true; + } } diff --git a/gestion/lib/Helpers/FolderHelpers.php b/gestion/lib/Helpers/FolderHelpers.php new file mode 100644 index 0000000..b7804e1 --- /dev/null +++ b/gestion/lib/Helpers/FolderHelpers.php @@ -0,0 +1,12 @@ +$match[1], // Extrait 'image' de 'image/png' + 'name' => trim($match[2], '/'), + 'file_id' => (int) $match[3], + ]; + } + + return $attachments; + } } diff --git a/gestion/lib/Service/GestionService.php b/gestion/lib/Service/GestionService.php index dc0c306..8a7b413 100644 --- a/gestion/lib/Service/GestionService.php +++ b/gestion/lib/Service/GestionService.php @@ -26,18 +26,22 @@ declare(strict_types=1); namespace OCA\Gestion\Service; +use OCP\DB\Exception; +use OCP\IUserSession; +use OCP\Mail\IMailer; +use OCA\Gestion\Db\Bdd; +use OC\Files\Filesystem; +use OCP\Files\IRootFolder; +use OCA\Gestion\Db\OrderBdd; +use Psr\Log\LoggerInterface; use OCA\Gestion\Constants\BddConstant; -use OCA\Gestion\Constants\DevisMentionConstant; +use OCA\Gestion\Helpers\FolderHelpers; +use OCA\Gestion\Helpers\VCalendarHelpers; use OCA\Gestion\Constants\OrderStatusConstant; use OCA\Gestion\Constants\ThanatoTypeConstant; -use OCA\Gestion\Db\Bdd; -use OCA\Gestion\Db\OrderBdd; -use OCA\Gestion\Service\Devis\Pdf\DevisPdfService; use OCA\Gestion\Service\Order\OrderPdfService; -use OCP\DB\Exception; -use Psr\Log\LoggerInterface; -use OCA\Gestion\Helpers\VCalendarHelpers; -use OCP\IUserSession; +use OCA\Gestion\Constants\DevisMentionConstant; +use OCA\Gestion\Service\Devis\Pdf\DevisPdfService; class GestionService { /** @var Bdd */ @@ -58,6 +62,11 @@ class GestionService { private string $userConnectedUuid; + private $userConnectedStorage; + + private $mailer; + + public function __construct( Bdd $gestionBdd, OrderBdd $orderBdd, @@ -65,7 +74,10 @@ class GestionService { OrderPdfService $orderPdfService, DevisPdfService $devisPdfService, TalkService $talkService, - IUserSession $userSession + IUserSession $userSession, + IRootFolder $rootFolder, + IMailer $mailer, + ) { $this->orderBdd = $orderBdd; $this->logger = $logger; @@ -75,6 +87,9 @@ class GestionService { $this->talkService = $talkService; $this->userSession = $userSession; $this->userConnectedUuid = $userSession->getUser()?->getUID() ?? BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD; + $this->userConnectedStorage = $rootFolder->getUserFolder($this->userConnectedUuid); + $this->mailer = $mailer; + } private function GetCalendarSummaryFromVCalendarString(string $vCalendarString): string @@ -184,6 +199,8 @@ class GestionService { $calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString); $userName = $this->GetThanatoNameFromVCalendarString($vCalendarString); $devisAlreadyCreated = $this->IsDevisAlreadyCreated($clientId,$locationId,$thanatoId,$calendarSummary,$calendarUuid); + + if($devisAlreadyCreated){ return; } @@ -210,6 +227,20 @@ class GestionService { $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){ + $destinationFolderAttachment = FolderHelpers::GetDefuntFolder($devis["client_entreprise"],$devis["defunt_nom"]); + $attachments = VCalendarHelpers::extractAttachments($vCalendarString); + $this->moveCalendarAttachmentFile($attachments,$destinationFolderAttachment); + if ($thanatoIsSubcontractor) { + $this->sendEmailAttachment($devis["defunt_nom"],$attachments); + } + + } + } + $this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$userName); } catch(Exception $e){ @@ -217,6 +248,14 @@ class GestionService { } } + + public function moveCalendarAttachmentFile(array $attachments ,string $destinationFolder ){ + $this->userConnectedStorage->getFullPath("/"); + foreach ($attachments as $attachment) { + $path = Filesystem::getPath($attachment['file_id']); + Filesystem::copy($path, $destinationFolder . $attachment['name']); + } + } private function GetThanatoNameFromVCalendarString($vCalendarString){ $thanatoName = null; $thanatoNames = $this->GetAttendeesNameFromVCalendarString($vCalendarString); @@ -329,12 +368,50 @@ class GestionService { $userName = $this->GetThanatoNameFromVCalendarString($vCalendarString); $devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devis['id'],$userName); $this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid); + $this->devisPdfService->generateDevisPdfByDevisId($devis['id'],$this->userConnectedUuid); + + + if (VCalendarHelpers::hasAttachment($vCalendarString)) { + $thanato = $this->gestionBdd->getThanatoByThanatoId($devis['id_thanato']); + $thanatoIsSubcontractor = $thanato["fk_thanato_type_key"] === ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR; + + $devis = $this->gestionBdd->getDevisByDevisId($devis['id']); + if($devis != null && $devis["client_entreprise"] != null){ + $destinationFolderAttachment = FolderHelpers::GetDefuntFolder($devis["client_entreprise"],$devis["defunt_nom"]); + $attachments = VCalendarHelpers::extractAttachments($vCalendarString); + $this->moveCalendarAttachmentFile($attachments , $destinationFolderAttachment); + if ($thanatoIsSubcontractor) { + $this->sendEmailAttachment($devis["defunt_nom"],$attachments); + } + } + } } - $this->devisPdfService->generateDevisPdfByDevisId($devis['id'],$this->userConnectedUuid); return true; } catch(Exception $e){ $this->logger->debug("error creating devis"); } } + + public function sendEmailAttachment($defunt_nom ,$attachments = []){ + $this->userConnectedStorage->getFullPath("/"); + + $to = "jonathan.goulet@nextcloud.com"; + $subject = "Piece jointe"; + $body = "Bonjour.
Vous trouverez en pièce jointe les documents concernant de « $defunt_nom ».
"; + + $message = $this->mailer->createMessage(); + $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'],'image/png'); + $message->attach($content); + } + $message->setHtmlBody( $body); + + $this->mailer->send($message); + + } }