Skip to content

Commit 1e1782c

Browse files
committed
Merge remote-tracking branch 'origin/develop'
Signed-off-by: snipe <[email protected]> # Conflicts: # public/css/build/app.css # public/css/build/overrides.css # public/css/dist/all.css # public/mix-manifest.json
2 parents 56cb9a0 + dab5874 commit 1e1782c

30 files changed

+859
-222
lines changed

app/Console/Commands/SendExpectedCheckinAlerts.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use App\Notifications\ExpectedCheckinNotification;
1010
use Carbon\Carbon;
1111
use Illuminate\Console\Command;
12-
use Illuminate\Support\Facades\Log;
1312

1413
class SendExpectedCheckinAlerts extends Command
1514
{
@@ -43,25 +42,31 @@ public function __construct()
4342
public function handle()
4443
{
4544
$settings = Setting::getSettings();
46-
$whenNotify = Carbon::now();
47-
$assets = Asset::with('assignedTo')->whereNotNull('assigned_to')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get();
45+
$interval = $settings->audit_warning_days ?? 0;
46+
$today = Carbon::now();
47+
$interval_date = $today->copy()->addDays($interval);
48+
49+
$assets = Asset::whereNull('deleted_at')->DueOrOverdueForCheckin($settings)->orderBy('assets.expected_checkin', 'desc')->get();
50+
51+
$this->info($assets->count().' assets must be checked in on or before '.$interval_date.' is deadline');
4852

49-
$this->info($whenNotify.' is deadline');
50-
$this->info($assets->count().' assets');
5153

5254
foreach ($assets as $asset) {
53-
if ($asset->assigned && $asset->checkedOutToUser()) {
54-
Log::info('Sending ExpectedCheckinNotification to ' . $asset->assigned->email);
55-
$asset->assigned->notify((new ExpectedCheckinNotification($asset)));
55+
if ($asset->assignedTo && (isset($asset->assignedTo->email)) && ($asset->assignedTo->email!='') && $asset->checkedOutToUser()) {
56+
$this->info('Sending User ExpectedCheckinNotification to: '.$asset->assignedTo->email);
57+
$asset->assignedTo->notify((new ExpectedCheckinNotification($asset)));
5658
}
5759
}
5860

5961
if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) {
6062
// Send a rollup to the admin, if settings dictate
61-
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) {
63+
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item) {
6264
return new AlertRecipient($item);
6365
});
66+
67+
$this->info('Sending Admin ExpectedCheckinNotification to: '.$settings->alert_email);
6468
\Notification::send($recipients, new ExpectedCheckinAdminNotification($assets));
69+
6570
}
6671
}
6772
}

app/Console/Commands/SendUpcomingAuditReport.php

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace App\Console\Commands;
44

55
use App\Models\Asset;
6-
use App\Models\License;
7-
use App\Models\Recipients;
6+
use App\Models\Recipients\AlertRecipient;
87
use App\Models\Setting;
9-
use App\Notifications\ExpiringAssetsNotification;
108
use App\Notifications\SendUpcomingAuditNotification;
119
use Carbon\Carbon;
1210
use DB;
@@ -45,40 +43,26 @@ public function __construct()
4543
*/
4644
public function handle()
4745
{
46+
47+
$interval = $settings->audit_warning_days ?? 0;
48+
$today = Carbon::now();
49+
$interval_date = $today->copy()->addDays($interval);
50+
4851
$settings = Setting::getSettings();
52+
$assets = Asset::whereNull('deleted_at')->DueOrOverdueForAudit($settings)->orderBy('assets.next_audit_date', 'desc')->get();
53+
$this->info($assets->count().' assets must be audited in on or before '.$interval_date.' is deadline');
4954

50-
if (($settings->alert_email != '') && ($settings->audit_warning_days) && ($settings->alerts_enabled == 1)) {
5155

56+
if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) {
5257
// Send a rollup to the admin, if settings dictate
53-
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) {
54-
return new \App\Models\Recipients\AlertRecipient($item);
58+
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item) {
59+
return new AlertRecipient($item);
5560
});
5661

57-
// Assets due for auditing
62+
$this->info('Sending Admin SendUpcomingAuditNotification to: '.$settings->alert_email);
63+
\Notification::send($recipients, new SendUpcomingAuditNotification($assets, $settings->audit_warning_days));
5864

59-
$assets = Asset::whereNotNull('next_audit_date')
60-
->DueOrOverdueForAudit($settings)
61-
->orderBy('last_audit_date', 'asc')->get();
62-
63-
if ($assets->count() > 0) {
64-
$this->info(trans_choice('mail.upcoming-audits', $assets->count(),
65-
['count' => $assets->count(), 'threshold' => $settings->audit_warning_days]));
66-
\Notification::send($recipients, new SendUpcomingAuditNotification($assets, $settings->audit_warning_days));
67-
$this->info('Audit report sent to '.$settings->alert_email);
68-
} else {
69-
$this->info('No assets to be audited. No report sent.');
70-
}
71-
} elseif ($settings->alert_email == '') {
72-
$this->error('Could not send email. No alert email configured in settings');
73-
} elseif (! $settings->audit_warning_days) {
74-
$this->error('No audit warning days set in Admin Notifications. No mail will be sent.');
75-
} elseif ($settings->alerts_enabled != 1) {
76-
$this->info('Alerts are disabled in the settings. No mail will be sent');
77-
} else {
78-
$this->error('Something went wrong. :( ');
79-
$this->error('Admin Notifications Email Setting: '.$settings->alert_email);
80-
$this->error('Admin Audit Warning Setting: '.$settings->audit_warning_days);
81-
$this->error('Admin Alerts Emnabled: '.$settings->alerts_enabled);
8265
}
66+
8367
}
8468
}

app/Http/Controllers/Api/AssetsController.php

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class AssetsController extends Controller
5959
* @since [v4.0]
6060
* @return \Illuminate\Http\JsonResponse
6161
*/
62-
public function index(Request $request, $audit = null)
62+
public function index(Request $request, $action = null, $upcoming_status = null)
6363
{
6464

6565
$filter_non_deprecable_assets = false;
@@ -155,17 +155,44 @@ public function index(Request $request, $audit = null)
155155
$assets->TextSearch($request->input('search'));
156156
}
157157

158-
// This is used by the audit reporting routes
159-
if (Gate::allows('audit', Asset::class)) {
160-
switch ($audit) {
161-
case 'due':
162-
$assets->DueOrOverdueForAudit($settings);
163-
break;
164-
case 'overdue':
165-
$assets->overdueForAudit($settings);
166-
break;
158+
159+
/**
160+
* Handle due and overdue audits and checkin dates
161+
*/
162+
switch ($action) {
163+
case 'audits':
164+
165+
switch ($upcoming_status) {
166+
case 'due':
167+
$assets->DueForAudit($settings);
168+
break;
169+
case 'overdue':
170+
$assets->OverdueForAudit();
171+
break;
172+
case 'due-or-overdue':
173+
$assets->DueOrOverdueForAudit($settings);
174+
break;
175+
}
176+
break;
177+
178+
case 'checkins':
179+
switch ($upcoming_status) {
180+
case 'due':
181+
$assets->DueForCheckin($settings);
182+
break;
183+
case 'overdue':
184+
$assets->OverdueForCheckin();
185+
break;
186+
case 'due-or-overdue':
187+
$assets->DueOrOverdueForCheckin($settings);
188+
break;
189+
}
190+
break;
167191
}
168-
}
192+
193+
/**
194+
* End handling due and overdue audits and checkin dates
195+
*/
169196

170197

171198
// This is used by the sidenav, mostly

app/Http/Controllers/Assets/AssetsController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,11 +854,11 @@ public function dueForAudit()
854854
return view('hardware/audit-due');
855855
}
856856

857-
public function overdueForAudit()
857+
public function dueForCheckin()
858858
{
859-
$this->authorize('audit', Asset::class);
859+
$this->authorize('checkin', Asset::class);
860860

861-
return view('hardware/audit-overdue');
861+
return view('hardware/checkin-due');
862862
}
863863

864864

app/Http/Controllers/LabelsController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
use App\Models\Supplier;
1515
use App\Models\User;
1616
use App\View\Label as LabelView;
17+
use Illuminate\Support\Facades\DB;
1718
use Illuminate\Support\Facades\Storage;
1819

1920
class LabelsController extends Controller
2021
{
2122
/**
2223
* Returns the Label view with test data
2324
*
24-
* @author Grant Le Roux <[email protected]>
25-
* @param string $labelName
25+
* @param string $labelName
2626
* @return \Illuminate\Contracts\View\View
27+
* @author Grant Le Roux <[email protected]>
2728
*/
2829
public function show(string $labelName)
2930
{
@@ -66,7 +67,7 @@ public function show(string $labelName)
6667
$exampleAsset->model->category->id = 999999;
6768
$exampleAsset->model->category->name = trans('admin/labels/table.example_category');
6869

69-
$customFieldColumns = CustomField::all()->pluck('db_column');
70+
$customFieldColumns = CustomField::where('field_encrypted', '=', 0)->pluck('db_column');
7071

7172
collect(explode(';', Setting::getSettings()->label2_fields))
7273
->filter()

app/Http/Controllers/Licenses/LicensesController.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Http\Request;
1212
use Illuminate\Support\Facades\Auth;
1313
use Illuminate\Support\Facades\DB;
14+
use Symfony\Component\HttpFoundation\StreamedResponse;
1415

1516
/**
1617
* This controller handles all actions related to Licenses for
@@ -289,4 +290,106 @@ public function getClone($licenseId = null)
289290
->with('item', $license)
290291
->with('maintained_list', $maintained_list);
291292
}
293+
294+
/**
295+
* Exports Licenses to CSV
296+
*
297+
* @author [G. Martinez]
298+
* @since [v6.3]
299+
* @return StreamedResponse
300+
* @throws \Illuminate\Auth\Access\AuthorizationException
301+
*/
302+
public function getExportLicensesCsv()
303+
{
304+
$this->authorize('view', License::class);
305+
\Debugbar::disable();
306+
307+
$response = new StreamedResponse(function () {
308+
// Open output stream
309+
$handle = fopen('php://output', 'w');
310+
$licenses= License::with('company',
311+
'manufacturer',
312+
'category',
313+
'supplier',
314+
'adminuser',
315+
'assignedusers')
316+
->orderBy('created_at', 'DESC');
317+
Company::scopeCompanyables($licenses)
318+
->chunk(500, function ($licenses) use ($handle) {
319+
$headers = [
320+
// strtolower to prevent Excel from trying to open it as a SYLK file
321+
strtolower(trans('general.id')),
322+
trans('general.company'),
323+
trans('general.name'),
324+
trans('general.serial_number'),
325+
trans('general.purchase_date'),
326+
trans('general.purchase_cost'),
327+
trans('general.order_number'),
328+
trans('general.licenses_available'),
329+
trans('admin/licenses/table.seats'),
330+
trans('general.created_by'),
331+
trans('general.depreciation'),
332+
trans('general.updated_at'),
333+
trans('admin/licenses/table.deleted_at'),
334+
trans('general.email'),
335+
trans('admin/hardware/form.fully_depreciated'),
336+
trans('general.supplier'),
337+
trans('admin/licenses/form.expiration'),
338+
trans('admin/licenses/form.purchase_order'),
339+
trans('admin/licenses/form.termination_date'),
340+
trans('admin/licenses/form.maintained'),
341+
trans('general.manufacturer'),
342+
trans('general.category'),
343+
trans('general.min_amt'),
344+
trans('admin/licenses/form.reassignable'),
345+
trans('general.notes'),
346+
trans('general.created_at'),
347+
];
348+
349+
fputcsv($handle, $headers);
350+
351+
foreach ($licenses as $license) {
352+
// Add a new row with data
353+
$values = [
354+
$license->id,
355+
$license->company ? $license->company->name: '',
356+
$license->name,
357+
$license->serial,
358+
$license->purchase_date,
359+
$license->purchase_cost,
360+
$license->order_number,
361+
$license->free_seat_count,
362+
$license->seats,
363+
$license->adminuser->present()->fullName(),
364+
$license->depreciation ? $license->depreciation->name: '',
365+
$license->updated_at,
366+
$license->deleted_at,
367+
$license->email,
368+
( $license->depreciate == '1') ? trans('general.yes') : trans('general.no'),
369+
($license->supplier) ? $license->supplier->name: '',
370+
$license->expiration_date,
371+
$license->purchase_order,
372+
$license->termination_date,
373+
( $license->maintained == '1') ? trans('general.yes') : trans('general.no'),
374+
$license->manufacturer ? $license->manufacturer->name: '',
375+
$license->category ? $license->category->name: '',
376+
$license->min_amt,
377+
( $license->reassignable == '1') ? trans('general.yes') : trans('general.no'),
378+
$license->notes,
379+
$license->created_at,
380+
];
381+
382+
fputcsv($handle, $values);
383+
}
384+
});
385+
386+
// Close the output stream
387+
fclose($handle);
388+
}, 200, [
389+
'Content-Type' => 'text/csv; charset=UTF-8',
390+
'Content-Disposition' => 'attachment; filename="licenses-'.date('Y-m-d-his').'.csv"',
391+
]);
392+
393+
return $response;
394+
}
292395
}

app/Http/Controllers/SettingsController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,9 @@ public function getPhpInfo()
804804
*/
805805
public function getLabels()
806806
{
807-
return view('settings.labels', [
808-
'setting' => Setting::getSettings(),
809-
'customFields' => CustomField::all(),
810-
]);
807+
return view('settings.labels')
808+
->with('setting', Setting::getSettings())
809+
->with('customFields', CustomField::where('field_encrypted', '=', 0)->get());
811810
}
812811

813812
/**

0 commit comments

Comments
 (0)