From 4cbf48e56ebf69993deb451dda8704b8cfb84ba5 Mon Sep 17 00:00:00 2001 From: Amir Date: Sun, 18 Jun 2023 10:43:00 +0800 Subject: [PATCH] Add feature notify admin when download pdf --- .env.example | 2 + app/Http/Controllers/NotisController.php | 12 ++- app/Jobs/NotifyJanaNotis.php | 61 ++++++++++++++ app/Mail/NotifyAdmin.php | 37 +++++++++ config/app.php | 2 + .../views/template/notifyadmin.blade.php | 79 +++++++++++++++++++ 6 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 app/Jobs/NotifyJanaNotis.php create mode 100644 app/Mail/NotifyAdmin.php create mode 100644 resources/views/template/notifyadmin.blade.php diff --git a/.env.example b/.env.example index ff8bf90d..dbd14f5d 100644 --- a/.env.example +++ b/.env.example @@ -313,3 +313,5 @@ WABOT_TOKEN_KEYS_SECOND=cbee7e95cf3ffbfa0531d5fddfd44f87 # for config STORAGE_DIRECTORY, set value without slash at the end # STORAGE_DIRECTORY=/Users/UTM/Sites/lelong/storage + +ADMIN_EMAIL="admin_1@example.com,admin_2@example.com" \ No newline at end of file diff --git a/app/Http/Controllers/NotisController.php b/app/Http/Controllers/NotisController.php index 1a2b2e47..ff4ca809 100644 --- a/app/Http/Controllers/NotisController.php +++ b/app/Http/Controllers/NotisController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Jobs\NotifyJanaNotis; use Illuminate\Http\Request; use Spatie\Permission\Models\Role; use Spatie\Permission\Models\Permission; @@ -40,8 +41,6 @@ use App\Models\WtdDraft; use App\Jobs\WhatsappNotisLelongFasa1; use App\Jobs\WhatsappNotisLelongFasa2; - - class NotisController extends Controller { /** @@ -280,6 +279,11 @@ class NotisController extends Controller $currentdate = Carbon::now(); $tarikh_cetak = $currentdate->toDateString(); + $current_date_time = $currentdate->toDateTimeString(); + + Log::info("Jana notis fasa 1: " . $user->kodcaw . ", " . $user->name); + NotifyJanaNotis::dispatch($user->id, $user->kodcaw, $user->name, 'Jana Notis Fasa 1', $current_date_time); + $lelongid = Lelong::find($lelong_id); $arraynorujukan = LelongBid::where('lelong_id', $lelong_id)->where('kodcaw', $caw->caw_code)->pluck('norujukan'); @@ -591,6 +595,10 @@ class NotisController extends Controller // dd($marhuns); $arraysag = []; + $current_date_time = $current->toDateTimeString(); + + Log::info("Jana notis fasa 2: " . $user->kodcaw . ", " . $user->name); + NotifyJanaNotis::dispatch($user->id, $user->kodcaw, $user->name, 'Jana Notis Fasa 2', $current_date_time); foreach($marhuns as $index1=>$cal){ $customer = Customer::where('kpbaru','=',$cal['nokp']) diff --git a/app/Jobs/NotifyJanaNotis.php b/app/Jobs/NotifyJanaNotis.php new file mode 100644 index 00000000..6ba701ea --- /dev/null +++ b/app/Jobs/NotifyJanaNotis.php @@ -0,0 +1,61 @@ +user_id = $user_id; + $this->user_kodcaw = $user_kodcaw; + $this->user_name = $user_name; + $this->description = $description; + $this->date_time = $date_time; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $content_collection = collect(); + $content_collection['user_id'] = $this->user_id; + $content_collection['user_kodcaw'] = $this->user_kodcaw; + $content_collection['user_name'] = $this->user_name; + $content_collection['description'] = $this->description; + $content_collection['download_time'] = $this->date_time; + + $admin_emails = explode(',', config('app.admin_email')); + + foreach($admin_emails as $email) { + Mail::to($email)->send(new NotifyAdmin($content_collection)); + } + + } +} diff --git a/app/Mail/NotifyAdmin.php b/app/Mail/NotifyAdmin.php new file mode 100644 index 00000000..2db902ae --- /dev/null +++ b/app/Mail/NotifyAdmin.php @@ -0,0 +1,37 @@ +content_collection = $content_collection; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this->from("masterlelongpkb@gmail.com", "Admin ArrahnBid") + ->subject('ArrahnBid - ' . $this->content_collection['description']) + ->view('template.notifyadmin', ['content_collection' => $this->content_collection]); + } +} diff --git a/config/app.php b/config/app.php index dad3596f..d1b2ef31 100644 --- a/config/app.php +++ b/config/app.php @@ -254,4 +254,6 @@ return [ 'storage_directory' => env('STORAGE_DIRECTORY', storage_path()), 'taxation' => env('TAX_AROS',true), + + 'admin_email' => env('ADMIN_EMAIL', 'admin@example.com') ]; diff --git a/resources/views/template/notifyadmin.blade.php b/resources/views/template/notifyadmin.blade.php new file mode 100644 index 00000000..51bde7ab --- /dev/null +++ b/resources/views/template/notifyadmin.blade.php @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ ArrahnBid +
+ + + + +
+

+ Greetings, +

+ @foreach($content_collection as $index => $value) + {{ $index }} + : + {{ $value }} +
+ @endforeach +

+ +

+ Thank you,

+

+ ArrahnBid

+
+
+
+ + + \ No newline at end of file