From 8d8985a6be00e2a8da2c73cadf2abd37ff78111e Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 21 Oct 2024 14:23:03 +0700 Subject: [PATCH] update send mail warning checkin late --- .../app/Http/Controllers/TicketController.php | 8 +- .../Http/Controllers/TrackingController.php | 63 +++++++- BACKEND/app/Mail/CheckinLateMail.php | 58 +++++++ .../email/checkin_late_notification.blade.php | 153 ++++++++++++++++++ FRONTEND/src/components/Navbar/Navbar.tsx | 4 +- 5 files changed, 272 insertions(+), 14 deletions(-) create mode 100644 BACKEND/app/Mail/CheckinLateMail.php create mode 100644 BACKEND/resources/views/email/checkin_late_notification.blade.php diff --git a/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php b/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php index 70283ff..1e3e27b 100644 --- a/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php +++ b/BACKEND/Modules/Admin/app/Http/Controllers/TicketController.php @@ -344,13 +344,13 @@ class TicketController extends Controller $date = Carbon::create($year, $month, $day)->setTimezone(env('TIME_ZONE')); //Default: ALL - $start = $date->copy()->setTime(7, 31, 11); - $end = $date->copy()->setTime(17, 1, 11); + $start = $date->copy()->setTime(7, 30, 0); + $end = $date->copy()->setTime(17, 0, 0); if ($type == 'S') { - $end = $date->copy()->setTime(11, 31, 11); + $end = $date->copy()->setTime(11, 30, 0); } else if ($type == 'C') { - $start = $date->copy()->setTime(11, 31, 11); + $start = $date->copy()->setTime(11, 30, 0); } Tracking::insert([ diff --git a/BACKEND/Modules/Admin/app/Http/Controllers/TrackingController.php b/BACKEND/Modules/Admin/app/Http/Controllers/TrackingController.php index 5bf2ed9..205ee95 100755 --- a/BACKEND/Modules/Admin/app/Http/Controllers/TrackingController.php +++ b/BACKEND/Modules/Admin/app/Http/Controllers/TrackingController.php @@ -2,8 +2,9 @@ namespace Modules\Admin\app\Http\Controllers; -use App\Helper\Cache\CurrentMonthTimekeeping; +use App\Events\WarningChekinLate; use App\Http\Controllers\Controller; +use App\Mail\CheckinLateMail; use App\Traits\AnalyzeData; use App\Traits\HasFilterRequest; use App\Traits\HasOrderByRequest; @@ -11,6 +12,7 @@ use App\Traits\HasSearchRequest; use Carbon\Carbon; use DateTime; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; use Modules\Admin\app\Models\Admin; use Modules\Admin\app\Models\MonthlyTimekeeping; @@ -163,14 +165,9 @@ class TrackingController extends Controller $id = $request->get('id'); $tracking = Tracking::find($id); - // $id = $request->get('id'); - // $tracking = Tracking::find($id); - // $payload = $request->all(); - - // if ($tracking) { - // $tracking->update($payload); - // } + $user = Admin::find($tracking->user_id); + $this->sendCheckinLateMail($user, $tracking->created_at, $tracking->status); if ($request->hasFile('image')) { $file = $request->file('image'); $filename = $request->file_name; @@ -203,4 +200,54 @@ class TrackingController extends Controller 'status' => true ]); } + + // public function sendCheckinLateMail() + private function sendCheckinLateMail($user, $time, $status) + { + // $status = $this->CHECK_IN; + // $time =Tracking::find(1)->created_at; + // $user = Admin::where('name', 'LE TAN LUAN')->first(); + if($status === $this->CHECK_IN){ + $morning_time = Carbon::createFromTimeString('07:30AM')->setTimezone(env('TIME_ZONE')); + $morning_condition_time = Carbon::createFromTimeString('07:40AM')->setTimezone(env('TIME_ZONE')); + $afternoon_time = Carbon::createFromTimeString('01:00PM')->setTimezone(env('TIME_ZONE')); + $afternoon_condition_time = Carbon::createFromTimeString('01:10PM')->setTimezone(env('TIME_ZONE')); + $admin_mails = Admin::where('permission', 'like', '%admin%')->pluck('email'); + + if ($time->greaterThan($morning_condition_time) && $time->lessThan($afternoon_time)) + { + $period = 'morning'; + $minutes_late = $morning_time->diffInMinutes($time); + $data = array( + "email_template" => "email.checkin_late_notification", + "email" => $user->email, + "name" => $user->name, + "admin_mails" => $admin_mails, + "message1" => "Your ". $period ." starts ". $minutes_late ." minutes late", + "message2" => "You checked in at [" . $time ."]", + "url" => env('ADMIN_URL')."/tracking?search=&per_page=10&page=1&timezone=Asia%2FSaigon&name=".$user->name."&time_string=".$time->format("Y-m-d H:i")."&status=check+in", + "subject" => "[Management System] Late warning" + ); + Mail::to($user->email)->cc($admin_mails)->send(new CheckinLateMail($data)); + } + + // if ($time->greaterThan($afternoon_condition_time)) + // { + // $period = 'afternoon'; + // $minutes_late = $afternoon_time->diffInMinutes($time); + // $data = array( + // "email_template" => "email.checkin_late_notification", + // "email" => $user->email, + // "name" => $user->name, + // "message1" => "Your ". $period ." starts ". $minutes_late ." minutes late", + // "message2" => "You checked in at [" . $time ."]", + // "url" => env('ADMIN_URL')."/tracking?search=&per_page=10&page=1&timezone=Asia%2FSaigon&name=".$user->name."&time_string=".$time->format("Y-m-d H:i")."&status=check+in", + // "subject" => "[Management System] Late warning" + // ); + // Mail::to($user->email)->cc($admin_mails)->send(new CheckinLateMail($data)); + // } + + + } + } } diff --git a/BACKEND/app/Mail/CheckinLateMail.php b/BACKEND/app/Mail/CheckinLateMail.php new file mode 100644 index 0000000..2d95ac2 --- /dev/null +++ b/BACKEND/app/Mail/CheckinLateMail.php @@ -0,0 +1,58 @@ +data = $data; + } + + /** + * Get the message envelope. + */ + public function envelope(): Envelope + { + return new Envelope( + // replyTo: [ + // new Address($this->data["email"], $this->data["name"]), + // ], + subject: $this->data["subject"], + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + view: ($this->data["email_template"]) + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return []; + } +} diff --git a/BACKEND/resources/views/email/checkin_late_notification.blade.php b/BACKEND/resources/views/email/checkin_late_notification.blade.php new file mode 100644 index 0000000..1a01dc5 --- /dev/null +++ b/BACKEND/resources/views/email/checkin_late_notification.blade.php @@ -0,0 +1,153 @@ + + + + + + + + + + {{ $data['subject'] }} + + + + + + + + + + + + + + + +
+ + + + +
+ + Logo + +
+
+ + + + + + + + + + + + + + + + + +
+

+ Hi {{ $data['name'] }}, +

+
+

+ {{ $data['message1'] }} +

+
+

+ {{ $data['message2'] }} +

+
+

+ + Check now +

+
+
+ + + + +
+
+

© 2024 APAC Tech.

+
+
+
+ + + + diff --git a/FRONTEND/src/components/Navbar/Navbar.tsx b/FRONTEND/src/components/Navbar/Navbar.tsx index faf3354..866ab8a 100755 --- a/FRONTEND/src/components/Navbar/Navbar.tsx +++ b/FRONTEND/src/components/Navbar/Navbar.tsx @@ -61,8 +61,8 @@ const data = [ link: '/tracking', label: 'Check in/out', icon: IconScan, - permissions: 'hr,admin', - group: 'other', + permissions: 'staff,hr,admin', + group: 'staff', }, { link: '/worklogs',