snipe-it/app/Console/Commands/SendInventoryAlerts.php

70 lines
1.8 KiB
PHP
Raw Normal View History

2016-03-25 01:18:05 -07:00
<?php
namespace App\Console\Commands;
use App\Models\Setting;
use DB;
use Mail;
use App\Helpers\Helper;
use Illuminate\Console\Command;
class SendInventoryAlerts extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'snipeit:inventory-alerts';
2016-03-25 01:18:05 -07:00
/**
* 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()
{
if ((Setting::getSettings()->alert_email!='') && (Setting::getSettings()->alerts_enabled==1)) {
$data['data'] = Helper::checkLowInventory();
$data['count'] = count($data['data']);
if (count($data['data']) > 0) {
2016-06-22 12:27:41 -07:00
\Mail::send('emails.low-inventory', $data, function ($m) {
$m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name);
2016-09-20 07:20:10 -07:00
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
$m->subject(trans('mail.Low_Inventory_Report'));
2016-06-22 12:27:41 -07:00
});
2016-03-25 01:18:05 -07:00
2016-06-22 12:27:41 -07:00
}
2016-03-25 01:18:05 -07:00
} else {
if (Setting::getSettings()->alert_email=='') {
2016-06-22 12:27:41 -07:00
echo "Could not send email. No alert email configured in settings. \n";
} elseif (Setting::getSettings()->alerts_enabled!=1) {
echo "Alerts are disabled in the settings. No mail will be sent. \n";
}
2016-03-25 01:18:05 -07:00
}
}
}