99use App \Notifications \ExpectedCheckinNotification ;
1010use Carbon \Carbon ;
1111use Illuminate \Console \Command ;
12+ use Illuminate \Support \Facades \Notification ;
13+ use App \Helpers \Helper ;
1214
1315class SendExpectedCheckinAlerts extends Command
1416{
@@ -17,7 +19,7 @@ class SendExpectedCheckinAlerts extends Command
1719 *
1820 * @var string
1921 */
20- protected $ name = 'snipeit:expected-checkin ' ;
22+ protected $ signature = 'snipeit:expected-checkin {--with-output : Display the results in a table in your console in addition to sending the email} ' ;
2123
2224 /**
2325 * The console command description.
@@ -42,19 +44,47 @@ public function __construct()
4244 public function handle ()
4345 {
4446 $ settings = Setting::getSettings ();
45- $ interval = $ settings ->audit_warning_days ?? 0 ;
47+ $ interval = $ settings ->due_checkin_days ?? 0 ;
4648 $ today = Carbon::now ();
4749 $ interval_date = $ today ->copy ()->addDays ($ interval );
48-
50+ $ count = 0 ;
51+
52+ if (!$ this ->option ('with-output ' )) {
53+ $ this ->info ('Run this command with the --with-output option to see the full list in the console. ' );
54+ }
55+
4956 $ assets = Asset::whereNull ('deleted_at ' )->DueOrOverdueForCheckin ($ settings )->orderBy ('assets.expected_checkin ' , 'desc ' )->get ();
5057
51- $ this ->info ($ assets ->count ().' assets must be checked in on or before ' .$ interval_date. ' is deadline ' );
58+ $ this ->info ($ assets ->count ().' assets must be checked on or before ' .Helper:: getFormattedDateObject ( $ interval_date, ' date ' , false ) );
5259
5360
5461 foreach ($ assets as $ asset ) {
5562 if ($ asset ->assignedTo && (isset ($ asset ->assignedTo ->email )) && ($ asset ->assignedTo ->email !='' ) && $ asset ->checkedOutToUser ()) {
56- $ this ->info ('Sending User ExpectedCheckinNotification to: ' .$ asset ->assignedTo ->email );
5763 $ asset ->assignedTo ->notify ((new ExpectedCheckinNotification ($ asset )));
64+ $ count ++;
65+ }
66+ }
67+
68+ if ($ this ->option ('with-output ' )) {
69+ if (($ assets ) && ($ assets ->count () > 0 ) && ($ settings ->alert_email != '' )) {
70+ $ this ->table (
71+ [
72+ trans ('general.id ' ),
73+ trans ('admin/hardware/form.tag ' ),
74+ trans ('admin/hardware/form.model ' ),
75+ trans ('general.model_no ' ),
76+ trans ('general.purchase_date ' ),
77+ trans ('admin/hardware/form.expected_checkin ' ),
78+ ],
79+ $ assets ->map (fn ($ assets ) => [
80+ trans ('general.id ' ) => $ assets ->id ,
81+ trans ('admin/hardware/form.tag ' ) => $ assets ->asset_tag ,
82+ trans ('admin/hardware/form.model ' ) => $ assets ->model ->name ,
83+ trans ('general.model_no ' ) => $ assets ->model ->model_number ,
84+ trans ('general.purchase_date ' ) => $ assets ->purchase_date_formatted ,
85+ trans ('admin/hardware/form.eol_date ' ) => $ assets ->expected_checkin_formattedDate ? $ assets ->expected_checkin_formattedDate . ' ( ' . $ assets ->expected_checkin_diff_for_humans . ') ' : '' ,
86+ ])
87+ );
5888 }
5989 }
6090
@@ -63,10 +93,11 @@ public function handle()
6393 $ recipients = collect (explode (', ' , $ settings ->alert_email ))->map (function ($ item ) {
6494 return new AlertRecipient ($ item );
6595 });
66-
67- $ this ->info ('Sending Admin ExpectedCheckinNotification to: ' .$ settings ->alert_email );
68- \Notification::send ($ recipients , new ExpectedCheckinAdminNotification ($ assets ));
96+ Notification::send ($ recipients , new ExpectedCheckinAdminNotification ($ assets ));
6997
7098 }
99+
100+ $ this ->info ('Sent checkin reminders to to ' .$ count .' users. ' );
101+
71102 }
72103}
0 commit comments