diff --git a/gestion/lib/Constants/BddConstant.php b/gestion/lib/Constants/BddConstant.php index 02ac83c..82a3ab7 100644 --- a/gestion/lib/Constants/BddConstant.php +++ b/gestion/lib/Constants/BddConstant.php @@ -8,7 +8,7 @@ abstract class BddConstant const DEFAULT_TABLE_PREFIX = "*PREFIX*"; const DEFAULT_CLIENT_GROUP_NAME = "Nom du groupe"; const DEFAULT_ADMIN_ID_NEXTCLOUD = 'admin'; - const DEFAULT_ADMIN_APP_ID_NEXTCLOUD = "admin"; + const DEFAULT_ADMIN_APP_ID_NEXTCLOUD = "Johann"; const ISLEAVEPROPERTYONVCALENDAR = "ISLEAVE"; diff --git a/gestion/lib/Controller/InvoiceController.php b/gestion/lib/Controller/InvoiceController.php index 502a82f..3ec6a59 100644 --- a/gestion/lib/Controller/InvoiceController.php +++ b/gestion/lib/Controller/InvoiceController.php @@ -1,6 +1,7 @@ 'application/json']); } - $factureClientMail = $this->gestionRepository->getFactureClientMailByFactureId($factureId); - if($factureClientMail == null){ - return new DataResponse("Le mail de la facture n'existe pas", 404, ['Content-Type' => 'application/json']); - } $factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->currentUserIdNextcloud); if($factureGeneratedResponse == null){ return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']); @@ -119,9 +116,9 @@ class InvoiceController extends Controller "
Vous trouverez en pièce jointe la facture des soins de « " . $factureDate . " » .
". $signature ); - $authUserEmail = $this->user->getEMailAddress(); - if ($authUserEmail) { - $message->setCc([$authUserEmail]); + $appAdminEmail = $this->gestionRepository->getUserEmailByNextcloudId(BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD); + if ($appAdminEmail) { + $message->setCc([$appAdminEmail]); } $this->mailer->send($message); diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index 1c874d1..53e1986 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -1619,9 +1619,9 @@ class PageController extends Controller { $signature ); - $authUserEmail = $this->user->getEMailAddress(); - if ($authUserEmail) { - $message->setCc([$authUserEmail]); + $appAdminEmail = $this->myDb->getUserEmailByNextcloudId(BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD); + if ($appAdminEmail) { + $message->setCc([$appAdminEmail]); } $this->mailer->send($message); return new DataResponse("", 200, ['Content-Type' => 'application/json']); diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index 0f874cf..2c6ac9d 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -2,6 +2,7 @@ namespace OCA\Gestion\Db; use \Datetime; +use OCA\Gestion\Helpers\MailHelpers; use OCP\IL10N; use OCP\IDBConnection; use Psr\Log\LoggerInterface; @@ -5147,4 +5148,24 @@ COMMENTAIRES: ".$comment; return $mail; } + + private function getUserAccountDataByNextcloudId($nextcloudId) + { + $sql = "SELECT * FROM " . self::DEFAULT_TABLE_PREFIX . "accounts as user_account WHERE user_account.uid = ? LIMIT 1;"; + $result = $this->execSQLNoJsonReturn($sql, [$nextcloudId]); + if (!empty($result)) { + return $result[0]; + } + return null; + } + + public function getUserEmailByNextcloudId($nextcloudId) + { + $userAccount = $this->getUserAccountDataByNextcloudId($nextcloudId); + if ($userAccount != null) { + $userEmail = MailHelpers::getUserMailFromUserAccountData($userAccount['data']); + return $userEmail; + } + return null; + } } diff --git a/gestion/lib/Helpers/MailHelpers.php b/gestion/lib/Helpers/MailHelpers.php new file mode 100644 index 0000000..0bedc6b --- /dev/null +++ b/gestion/lib/Helpers/MailHelpers.php @@ -0,0 +1,18 @@ +