From 77cdb2f409ccf8cfbd94fb26847b3ea205a3e22a Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 7 Sep 2018 02:24:41 -0700 Subject: [PATCH] Added console command to send inventory reports to users --- .../Commands/SendCurrentInventoryToUsers.php | 53 +++++++++++++++ app/Console/Kernel.php | 1 + app/Notifications/CurrentInventory.php | 66 +++++++++++++++++++ .../markdown/user-inventory.blade.php | 39 +++++++++++ 4 files changed, 159 insertions(+) create mode 100644 app/Console/Commands/SendCurrentInventoryToUsers.php create mode 100644 app/Notifications/CurrentInventory.php create mode 100644 resources/views/notifications/markdown/user-inventory.blade.php diff --git a/app/Console/Commands/SendCurrentInventoryToUsers.php b/app/Console/Commands/SendCurrentInventoryToUsers.php new file mode 100644 index 0000000000..2ea8ac3782 --- /dev/null +++ b/app/Console/Commands/SendCurrentInventoryToUsers.php @@ -0,0 +1,53 @@ +whereNotNull('email')->with('assets', 'accessories', 'consumables', 'licenses')->get(); + + foreach ($users as $user) { + $this->info($user->email); + $user->notify((new CurrentInventory($user))); + } + + + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index fed6c0398c..750369df55 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -31,6 +31,7 @@ class Kernel extends ConsoleKernel Commands\RegenerateAssetTags::class, Commands\SyncAssetCounters::class, Commands\RestoreDeletedUsers::class, + Commands\SendCurrentInventoryToUsers::class, ]; /** diff --git a/app/Notifications/CurrentInventory.php b/app/Notifications/CurrentInventory.php new file mode 100644 index 0000000000..b39c7245c6 --- /dev/null +++ b/app/Notifications/CurrentInventory.php @@ -0,0 +1,66 @@ +user = $user; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($notifiable) + { + $message = (new MailMessage)->markdown('notifications.markdown.user-inventory', + [ + 'assets' => $this->user->assets, + 'accessories' => $this->user->accessories, + 'licenses' => $this->user->licenses, + ]) + ->subject('Inventory Report'); + + return $message; + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/resources/views/notifications/markdown/user-inventory.blade.php b/resources/views/notifications/markdown/user-inventory.blade.php new file mode 100644 index 0000000000..4efe69e01f --- /dev/null +++ b/resources/views/notifications/markdown/user-inventory.blade.php @@ -0,0 +1,39 @@ +@component('mail::message') + +This is a reminder of the items currently checked out to you. If you feel this list is inaccurate (something is missing, or something appears here that you believe you never received), please email {{ config('mail.reply_to.name') }} at {{ config('mail.reply_to.address') }}. + + +@component('mail::table') + +@if ($assets->count() > 0) +## {{ $assets->count() }} Assets +|{{ trans('mail.name') }} |{{ trans('mail.asset_tag') }} | +|:------------- |:-------------|:---------| +@foreach($assets as $asset) +|{{ $asset->present()->name }} |{{ $asset->asset_tag }} | +@endforeach +@endif + +@if ($accessories->count() > 0) +## {{ $accessories->count() }} Accessories +|{{ trans('mail.name') }} | +| |:------------- | +@foreach($accessories as $accessory) +|{{ $accessory->name }} | +@endforeach +@endif + +@if ($licenses->count() > 0) +## {{ $licenses->count() }} Licenses + +| |:------------- | +@foreach($licenses as $license) +|{{ $asset->$license }} | +@endforeach +@endif + + +@endcomponent + + +@endcomponent