App\Console\Commands\SendExpirationAlerts Class Reference
Inheritance diagram for App\Console\Commands\SendExpirationAlerts:

Public Member Functions

 __construct ()
 Create a new command instance. More...
 
 fire ()
 Execute the console command. More...
 

Protected Attributes

 $name = 'alerts:expiring'
 
 $description = 'Check for expiring warrantees and service agreements, and sends out an alert email.'
 

Detailed Description

Definition at line 11 of file SendExpirationAlerts.php.

Constructor & Destructor Documentation

App\Console\Commands\SendExpirationAlerts::__construct ( )

Create a new command instance.

Returns
void

Definition at line 32 of file SendExpirationAlerts.php.

33  {
34  parent::__construct();
35  }

Member Function Documentation

App\Console\Commands\SendExpirationAlerts::fire ( )

Execute the console command.

Returns
mixed

Definition at line 42 of file SendExpirationAlerts.php.

43  {
44 
45  // Expiring Assets
46  $expiring_assets = Asset::getExpiringWarrantee(60);
47  $this->info(count($expiring_assets).' expiring assets');
48 
49  $asset_data['count'] = count($expiring_assets);
50  $asset_data['email_content'] ='';
51  $now = date("Y-m-d");
52 
53 
54  foreach ($expiring_assets as $asset) {
55 
56  $expires = $asset->warrantee_expires();
57  $difference = round(abs(strtotime($expires) - strtotime($now))/86400);
58 
59  if ($difference > 30) {
60  $asset_data['email_content'] .= '<tr style="background-color: #fcffa3;">';
61  } else {
62  $asset_data['email_content'] .= '<tr style="background-color:#d9534f;">';
63  }
64  $asset_data['email_content'] .= '<td><a href="'.config('app.url').'/hardware/'.$asset->id.'/view">';
65  $asset_data['email_content'] .= $asset->showAssetName().'</a></td><td>'.$asset->asset_tag.'</td>';
66  $asset_data['email_content'] .= '<td>'.$asset->warrantee_expires().'</td>';
67  $asset_data['email_content'] .= '<td>'.$difference.' days</td>';
68  $asset_data['email_content'] .= '</tr>';
69  }
70 
71  // Expiring licenses
72  $expiring_licenses = License::getExpiringLicenses(60);
73  $this->info(count($expiring_licenses).' expiring licenses');
74 
75 
76  $license_data['count'] = count($expiring_licenses);
77  $license_data['email_content'] = '';
78 
79  foreach ($expiring_licenses as $license) {
80  $expires = $license->expiration_date;
81  $difference = round(abs(strtotime($expires) - strtotime($now))/86400);
82 
83  if ($difference > 30) {
84  $license_data['email_content'] .= '<tr style="background-color: #fcffa3;">';
85  } else {
86  $license_data['email_content'] .= '<tr style="background-color:#d9534f;">';
87  }
88  $license_data['email_content'] .= '<td><a href="'.config('app.url').'/admin/licenses/'.$license->id.'/view">';
89  $license_data['email_content'] .= $license->name.'</a></td>';
90  $license_data['email_content'] .= '<td>'.$license->expiration_date.'</td>';
91  $license_data['email_content'] .= '<td>'.$difference.' days</td>';
92  $license_data['email_content'] .= '</tr>';
93  }
94 
95  if ((Setting::getSettings()->alert_email!='') && (Setting::getSettings()->alerts_enabled==1)) {
96 
97 
98  if (count($expiring_assets) > 0) {
99  Mail::send('emails.expiring-assets-report', $asset_data, function ($m) {
100  $m->to(explode(',',Setting::getSettings()->alert_email), Setting::getSettings()->site_name);
101  $m->subject('Expiring Assets Report');
102  });
103 
104  }
105 
106  if (count($expiring_licenses) > 0) {
107  Mail::send('emails.expiring-licenses-report', $license_data, function ($m) {
108  $m->to(explode(',',Setting::getSettings()->alert_email), Setting::getSettings()->site_name);
109  $m->subject('Expiring Licenses Report');
110  });
111 
112  }
113 
114 
115  } else {
116 
117  if (Setting::getSettings()->alert_email=='') {
118  echo "Could not send email. No alert email configured in settings. \n";
119  } elseif (Setting::getSettings()->alerts_enabled!=1) {
120  echo "Alerts are disabled in the settings. No mail will be sent. \n";
121  }
122 
123  }
124 
125 
126 
127 
128  }
static getExpiringWarrantee($days=30)
Definition: Asset.php:360
static getSettings()
Definition: Setting.php:33
static getExpiringLicenses($days=60)
Definition: License.php:182

Member Data Documentation

App\Console\Commands\SendExpirationAlerts::$description = 'Check for expiring warrantees and service agreements, and sends out an alert email.'
protected

Definition at line 25 of file SendExpirationAlerts.php.

App\Console\Commands\SendExpirationAlerts::$name = 'alerts:expiring'
protected

Definition at line 18 of file SendExpirationAlerts.php.


The documentation for this class was generated from the following file: