diff --git a/app/Notifications/CurrentInventory.php b/app/Notifications/CurrentInventory.php index 170f183d946b..19e9686cd061 100644 --- a/app/Notifications/CurrentInventory.php +++ b/app/Notifications/CurrentInventory.php @@ -40,12 +40,35 @@ public function via() */ public function toMail() { + //assigned to user + $userAssets = $this->user->assets; + $userAccessories = $this->user->accessories; + $userLicenses = $this->user->licenses; + + //assigned through assets to user + $assetsAssets = $userAssets->flatMap(fn ($asset) => $asset->assignedAssets); + $assetsAccessories = $userAssets->flatMap(fn ($asset) => $asset->assignedAccessories->map(fn ($checkout) => $checkout->accessory)->filter()); + $assetsLicenses = $userAssets->flatMap(fn ($asset) => $asset->licenses); + $assetsComponents = $userAssets->flatMap(fn ($asset) => $asset->components); + + $allAssets = $userAssets + ->concat($assetsAssets) + ->unique() + ->values(); + $allLicenses = $userLicenses + ->concat($assetsLicenses) + ->values(); + $allAccessories = $userAccessories + ->concat($assetsAccessories) + ->values(); + $message = (new MailMessage)->markdown('notifications.markdown.user-inventory', [ - 'assets' => $this->user->assets, - 'accessories' => $this->user->accessories, - 'licenses' => $this->user->licenses, + 'assets' => $allAssets, + 'accessories' => $allAccessories, + 'licenses' => $allLicenses, 'consumables' => $this->user->consumables, + 'components' => $assetsComponents, ]) ->subject(trans('mail.inventory_report')) ->withSymfonyMessage(function (Email $message) { diff --git a/resources/views/notifications/markdown/user-inventory.blade.php b/resources/views/notifications/markdown/user-inventory.blade.php index ec476cf0394a..915027085add 100644 --- a/resources/views/notifications/markdown/user-inventory.blade.php +++ b/resources/views/notifications/markdown/user-inventory.blade.php @@ -73,6 +73,18 @@ @endif +@if ($components->count() > 0) +## {{ $components->count() }} {{ trans('general.components') }} +
| {{ trans('mail.name') }} | |
|---|---|
| {{ $component->name }} | +