SendInventoryAlerts.php
Go to the documentation of this file.
1 <?php
2 
3 namespace App\Console\Commands;
4 
6 use DB;
7 use Mail;
9 
11 
12 class SendInventoryAlerts extends Command
13 {
19  protected $signature = 'alerts:inventory';
20 
26  protected $description = 'This command checks for low inventory, and sends out an alert email.';
27 
33  public function __construct()
34  {
35  parent::__construct();
36  }
37 
43  public function handle()
44  {
45  if ((Setting::getSettings()->alert_email!='') && (Setting::getSettings()->alerts_enabled==1)) {
46 
47  $data['data'] = Helper::checkLowInventory();
48  $data['count'] = count($data['data']);
49 
50  if (count($data['data']) > 0) {
51  Mail::send('emails.low-inventory', $data, function ($m) {
52  $m->to(explode(',',Setting::getSettings()->alert_email), Setting::getSettings()->site_name);
53  $m->subject('Low Inventory Report');
54  });
55 
56  }
57 
58  } else {
59  if (Setting::getSettings()->alert_email=='') {
60  echo "Could not send email. No alert email configured in settings. \n";
61  } elseif (Setting::getSettings()->alerts_enabled!=1) {
62  echo "Alerts are disabled in the settings. No mail will be sent. \n";
63  }
64  }
65 
66 
67  }
68 
69 }
handle()
Execute the console command.
static checkLowInventory()
This nasty little method gets the low inventory info for the alert dropdown.
Definition: Helper.php:201
static getSettings()
Definition: Setting.php:33
__construct()
Create a new command instance.