mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
9daeeeb851
* Improved expiring licenses notification * Improved expiring assets notification * Nicee low inventory notification * Refactored stupid language strings * Oops * Use settings variable
73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Setting;
|
|
use DB;
|
|
use Mail;
|
|
use App\Helpers\Helper;
|
|
use App\Notifications\InventoryAlert;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
class SendInventoryAlerts extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'snipeit:inventory-alerts';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'This command checks for low inventory, and sends out an alert email.';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$settings = Setting::getSettings();
|
|
|
|
if (($settings->alert_email!='') && ($settings->alerts_enabled==1)) {
|
|
|
|
$items = Helper::checkLowInventory();
|
|
|
|
// Send a rollup to the admin, if settings dictate
|
|
$recipient = new \App\Models\Recipients\AlertRecipient();
|
|
|
|
if (($items) && (count($items) > 0) && ($settings->alert_email!='')) {
|
|
|
|
$this->info( trans_choice('mail.low_inventory_alert',count($items)) );
|
|
|
|
$recipient->notify(new InventoryAlert($items, $settings->alert_threshold));
|
|
}
|
|
|
|
} else {
|
|
if (Setting::getSettings()->alert_email=='') {
|
|
$this->error('Could not send email. No alert email configured in settings');
|
|
} elseif (Setting::getSettings()->alerts_enabled!=1) {
|
|
$this->info('Alerts are disabled in the settings. No mail will be sent');
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|