From 6d72b1b78904832c104b1220db20b6212881957c Mon Sep 17 00:00:00 2001 From: ivan-sim Date: Tue, 21 Nov 2023 12:07:51 +0700 Subject: [PATCH] Update notifikasi send email --- .../Http/Controllers/Api/ClaimController.php | 38 ++++- app/Helpers/Helper.php | 46 ++++- .../dashboard/header/NotificationsPopover.tsx | 23 +-- resources/views/email/notif_email.blade.php | 160 ++++++++++++++++++ 4 files changed, 252 insertions(+), 15 deletions(-) create mode 100644 resources/views/email/notif_email.blade.php diff --git a/Modules/Internal/Http/Controllers/Api/ClaimController.php b/Modules/Internal/Http/Controllers/Api/ClaimController.php index 341201a2..2d79fc2f 100644 --- a/Modules/Internal/Http/Controllers/Api/ClaimController.php +++ b/Modules/Internal/Http/Controllers/Api/ClaimController.php @@ -22,6 +22,7 @@ use Modules\Internal\Transformers\ClaimHistoryCareResource; use Box\Spout\Reader\Common\Creator\ReaderEntityFactory; use Box\Spout\Writer\Common\Creator\WriterEntityFactory; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\View; use PDF; @@ -928,16 +929,19 @@ class ClaimController extends Controller $note = $request->input('note'); $dataToInsert = []; + $description = ""; if ($condition) { $dataToInsert[] = [ 'claim_request_id' => $claim_id, 'date' => date('Y-m-d H:i:s'), 'type' => 'claim-kondisi', 'description' => $note, - 'created_by' =>auth()->user()->id, + 'created_by' => auth()->user()->id, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]; + $description = "Condition"; + $this->sendNotif($description); } if ($diagnosis) { $dataToInsert[] = [ @@ -949,6 +953,8 @@ class ClaimController extends Controller 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]; + $description = "Diagnosis"; + $this->sendNotif($description); } if ($result) { $dataToInsert[] = [ @@ -960,12 +966,42 @@ class ClaimController extends Controller 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]; + $description = "Result"; + $this->sendNotif($description); } DB::table('claim_request_files')->insert($dataToInsert); return Helper::responseJson([]); } + public function sendNotif($description) + { + // Insert data notifications + $dataNotif = [ + 'hospital_id' => 1, + 'title' => 'Request Document', + 'description' => 'Please enter the document '.$description, + 'type' => 1, + 'isUnRead' => true, + 'created_by' => auth()->user()->id, + 'created_at' => date('Y-m-d H:i:s'), + 'updated_at' => date('Y-m-d H:i:s'), + ]; + $sendNotif = Helper::insertNotification($dataNotif); + // Send Email after insert notifications + if($sendNotif) + { + //Beluma ada Data Users + $dataEmail = [ + 'email' => 'akun.kerja.ivan@gmail.com', + 'name' => 'Ivan Julian', + 'subject' => 'Enter Document '.$description, + 'body' => View::make('email/notif_email', ['name' => 'Ivan Julian', 'link' => 'https://linkmedis.com/chat'])->render(), + ]; + Helper::sendEmail($dataEmail); + } + } + //////////////////// History Care Hospital /////////////////////////// public function storeHistoryCare(Request $request, $id){ diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 3118be39..59629850 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -6,6 +6,8 @@ use Carbon\Carbon; use Carbon\CarbonPeriod; use Illuminate\Http\JsonResponse; use Symfony\Component\HttpFoundation\Response; +use PHPMailer\PHPMailer\PHPMailer; +use Illuminate\Support\Facades\DB; class Helper { @@ -244,14 +246,52 @@ class Helper return $convertedDate; } - public static function sendNotification() + public static function insertNotification($data = array()) { - + try { + DB::beginTransaction(); + DB::table('notifications')->insert($data); + DB::commit(); + return true; + } + catch (\Exception $e) { + DB::rollback(); + return $e->getMessage(); + } } - public static function sendEmail() + public static function sendEmail($data = array()) { + // Buat instance PHPMailer + $mail = new PHPMailer(true); + try { + // Server settings + $mail->isSMTP(); + $mail->Host = 'smtp.gmail.com'; + $mail->SMTPAuth = true; + $mail->Username = env('EMAIL'); + $mail->Password = env('PW_EMAIL'); + $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; + $mail->Port = 465; + $mail->SMTPSecure = "ssl"; + + // Penerima email + $mail->setFrom(env('EMAIL'), env('NAME_EMAIL')); + $mail->addAddress($data['email'], $data['name']); + + // Konten email + $mail->isHTML(true); + $mail->Subject = $data['subject']; + $mail->Body = $data['body']; + + // Kirim email + $mail->send(); + return true; + } catch (\Exception $e) { + //var_dump($mail->ErrorInfo);die(); + return false; + } } } diff --git a/frontend/hospital-portal/src/layouts/dashboard/header/NotificationsPopover.tsx b/frontend/hospital-portal/src/layouts/dashboard/header/NotificationsPopover.tsx index f0d92aae..be068570 100644 --- a/frontend/hospital-portal/src/layouts/dashboard/header/NotificationsPopover.tsx +++ b/frontend/hospital-portal/src/layouts/dashboard/header/NotificationsPopover.tsx @@ -14,6 +14,7 @@ import { ListSubheader, ListItemAvatar, ListItemButton, + Stack } from '@mui/material'; // utils import { fToNow } from '@/utils/formatTime'; @@ -93,13 +94,13 @@ export default function NotificationsPopover() { - {totalUnRead > 0 && ( + {/* {totalUnRead > 0 && ( - )} + )} */} @@ -116,7 +117,7 @@ export default function NotificationsPopover() { } > {notifications.slice(0, 2).map((notification) => ( - + ))} @@ -129,7 +130,7 @@ export default function NotificationsPopover() { } > {notifications.slice(2, 5).map((notification) => ( - + ))} @@ -161,7 +162,7 @@ type NotificationItemProps = { isUnRead: boolean; }; -function NotificationItem({ notification, onClick, getDataNotifications }: { notification: NotificationItemProps, onClick: (id: string) => void, getDataNotifications: () => void}) { +function NotificationItem({ notification, getDataNotifications }: { notification: NotificationItemProps, getDataNotifications: () => void}) { const { avatar, title } = renderContent(notification); const {enqueueSnackbar} = useSnackbar(); const handleClick = () => { @@ -223,12 +224,12 @@ function NotificationItem({ notification, onClick, getDataNotifications }: { not function renderContent(notification: NotificationItemProps) { const title = ( - - {notification.title} - -   {noCase(notification.description)} - - + + {notification.title} + + {notification.description} + + ); if (notification.type === 'order_placed') { diff --git a/resources/views/email/notif_email.blade.php b/resources/views/email/notif_email.blade.php new file mode 100644 index 00000000..db698f16 --- /dev/null +++ b/resources/views/email/notif_email.blade.php @@ -0,0 +1,160 @@ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + \ No newline at end of file