mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Added console command to send inventory reports to users
This commit is contained in:
parent
26fd7f7e79
commit
77cdb2f409
53
app/Console/Commands/SendCurrentInventoryToUsers.php
Normal file
53
app/Console/Commands/SendCurrentInventoryToUsers.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Asset;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CurrentInventory;
|
||||
|
||||
class SendCurrentInventoryToUsers extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'snipeit:user-inventory';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'This will send users a report of all of the items currently checked out to them.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$users = User::whereNull('deleted_at')->whereNotNull('email')->with('assets', 'accessories', 'consumables', 'licenses')->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
$this->info($user->email);
|
||||
$user->notify((new CurrentInventory($user)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ class Kernel extends ConsoleKernel
|
|||
Commands\RegenerateAssetTags::class,
|
||||
Commands\SyncAssetCounters::class,
|
||||
Commands\RestoreDeletedUsers::class,
|
||||
Commands\SendCurrentInventoryToUsers::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
66
app/Notifications/CurrentInventory.php
Normal file
66
app/Notifications/CurrentInventory.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class CurrentInventory extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($user)
|
||||
{
|
||||
$this->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 [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
|
@ -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
|
Loading…
Reference in a new issue