2018-09-07 02:24:41 -07:00
|
|
|
<?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()
|
|
|
|
{
|
|
|
|
|
2018-09-07 03:08:32 -07:00
|
|
|
$users = User::whereNull('deleted_at')->whereNotNull('email')->with('assets', 'accessories', 'licenses')->get();
|
2018-09-07 02:24:41 -07:00
|
|
|
|
2018-09-07 03:08:32 -07:00
|
|
|
$count = 0;
|
2018-09-07 02:24:41 -07:00
|
|
|
foreach ($users as $user) {
|
2018-09-07 03:08:32 -07:00
|
|
|
|
|
|
|
if (($user->assets->count() > 0) || ($user->accessories->count() > 0) || ($user->licenses->count() > 0))
|
|
|
|
{
|
|
|
|
$count++;
|
|
|
|
$user->notify((new CurrentInventory($user)));
|
|
|
|
}
|
|
|
|
|
2018-09-07 02:24:41 -07:00
|
|
|
}
|
|
|
|
|
2018-09-07 03:08:32 -07:00
|
|
|
$this->info($count.' users notified.');
|
|
|
|
|
2018-09-07 02:24:41 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|