Skip to content

Commit a1e65cd

Browse files
committed
Merge branch 'develop' into replace-date-and-time-display-macros
# Conflicts: # resources/macros/macros.php
2 parents c8b7782 + 5d65f1f commit a1e65cd

File tree

903 files changed

+5619
-3595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

903 files changed

+5619
-3595
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\Actionlog;
6+
use Illuminate\Console\Command;
7+
8+
class RemoveInvalidUploadDeleteActionLogItems extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'snipeit:remove-invalid-upload-delete-action-log-items';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Permanently remove invalid "upload deleted" action log items that have a null filename. This command can potentially result in deleted files being "resurrected" in the UI.';
23+
24+
/**
25+
* Execute the console command.
26+
*/
27+
public function handle()
28+
{
29+
$invalidLogs = Actionlog::query()
30+
->where('action_type', 'upload deleted')
31+
->whereNull('filename')
32+
->withTrashed()
33+
->get();
34+
35+
$this->info("{$invalidLogs->count()} invalid log items found.");
36+
37+
if ($invalidLogs->count() === 0) {
38+
return 0;
39+
}
40+
41+
$this->table(['ID', 'Action Type', 'Item Type', 'Item ID', 'Created At', 'Deleted At'], $invalidLogs->map(fn($log) => [
42+
$log->id,
43+
$log->action_type,
44+
$log->item_type,
45+
$log->item_id,
46+
$log->created_at,
47+
$log->deleted_at,
48+
])->toArray());
49+
50+
if ($this->confirm("Do you wish to remove {$invalidLogs->count()} log items?")) {
51+
$invalidLogs->each(fn($log) => $log->forceDelete());
52+
}
53+
54+
return 0;
55+
}
56+
}

app/Console/Commands/SendExpirationAlerts.php

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,57 @@ public function handle()
6060
Mail::to($recipients)->send(new ExpiringAssetsMail($assets, $alert_interval));
6161

6262
$this->table(
63-
['ID', 'Tag', 'Model', 'Model Number', 'EOL', 'EOL Months', 'Warranty Expires', 'Warranty Months'],
64-
$assets->map(fn($item) => ['ID' => $item->id, 'Tag' => $item->asset_tag, 'Model' => $item->model->name, 'Model Number' => $item->model->model_number, 'EOL' => $item->asset_eol_date, 'EOL Months' => $item->model->eol, 'Warranty Expires' => $item->warranty_expires, 'Warranty Months' => $item->warranty_months])
65-
);
63+
[
64+
trans('general.id'),
65+
trans('admin/hardware/form.tag'),
66+
trans('admin/hardware/form.model'),
67+
trans('general.model_no'),
68+
trans('general.purchase_date'),
69+
trans('admin/hardware/form.eol_rate'),
70+
trans('admin/hardware/form.eol_date'),
71+
trans('admin/hardware/form.warranty_expires'),
72+
],
73+
$assets->map(fn($item) =>
74+
[
75+
trans('general.id') => $item->id,
76+
trans('admin/hardware/form.tag') => $item->asset_tag,
77+
trans('admin/hardware/form.model') => $item->model->name,
78+
trans('general.model_no') => $item->model->model_number,
79+
trans('general.purchase_date') => $item->purchase_date_formatted,
80+
trans('admin/hardware/form.eol_rate') => $item->model->eol,
81+
trans('admin/hardware/form.eol_date') => $item->eol_date ? $item->eol_formatted_date .' ('.$item->eol_diff_for_humans.')' : '',
82+
trans('admin/hardware/form.warranty_expires') => $item->warranty_expires ? $item->warranty_expires_formatted_date .' ('.$item->warranty_expires_diff_for_humans.')' : '',
83+
])
84+
);
6685
}
6786

6887
// Expiring licenses
69-
$licenses = License::getExpiringLicenses($alert_interval);
88+
$licenses = License::query()->ExpiringLicenses($alert_interval)
89+
->with('manufacturer','category')
90+
->orderBy('expiration_date', 'ASC')
91+
->orderBy('termination_date', 'ASC')
92+
->get();
7093
if ($licenses->count() > 0) {
7194
Mail::to($recipients)->send(new ExpiringLicenseMail($licenses, $alert_interval));
7295

7396
$this->table(
74-
['ID', 'Name', 'Expires', 'Termination Date'],
75-
$licenses->map(fn($item) => ['ID' => $item->id, 'Name' => $item->name, 'Expires' => $item->expiration_date, 'Termination Date' => $item->termination_date])
97+
[
98+
trans('general.id'),
99+
trans('general.name'),
100+
trans('general.purchase_date'),
101+
trans('admin/licenses/form.expiration'),
102+
trans('mail.expires'),
103+
trans('admin/licenses/form.termination_date'),
104+
trans('mail.terminates')],
105+
$licenses->map(fn($item) => [
106+
trans('general.id') => $item->id,
107+
trans('general.name') => $item->name,
108+
trans('general.purchase_date') => $item->purchase_date_formatted,
109+
trans('admin/licenses/form.expiration') => $item->expires_formatted_date,
110+
trans('mail.expires') => $item->expires_diff_for_humans,
111+
trans('admin/licenses/form.termination_date') => $item->terminates_formatted_date,
112+
trans('mail.terminates') => $item->terminates_diff_for_humans
113+
])
76114
);
77115
}
78116

app/Console/Commands/SendUpcomingAuditReport.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function handle()
4747
$today = Carbon::now();
4848
$interval_date = $today->copy()->addDays($interval);
4949

50-
$assets = Asset::whereNull('deleted_at')->dueOrOverdueForAudit($settings)->orderBy('assets.next_audit_date', 'desc')->get();
50+
$assets = Asset::whereNull('deleted_at')->dueOrOverdueForAudit($settings)->orderBy('assets.next_audit_date', 'asc')->get();
5151
$this->info($assets->count() . ' assets must be audited in on or before ' . $interval_date . ' is deadline');
5252

5353

@@ -61,6 +61,28 @@ public function handle()
6161

6262
$this->info('Sending Admin SendUpcomingAuditNotification to: ' . $settings->alert_email);
6363
Mail::to($recipients)->send(new SendUpcomingAuditMail($assets, $settings->audit_warning_days));
64+
65+
$this->table(
66+
[
67+
trans('general.id'),
68+
trans('general.name'),
69+
trans('general.last_audit'),
70+
trans('general.next_audit_date'),
71+
trans('mail.Days'),
72+
trans('mail.supplier'),
73+
trans('mail.assigned_to'),
74+
75+
],
76+
$assets->map(fn($item) => [
77+
trans('general.id') => $item->id,
78+
trans('general.name') => $item->display_name,
79+
trans('general.last_audit') => $item->last_audit_formatted_date,
80+
trans('general.next_audit_date') => $item->next_audit_formatted_date,
81+
trans('mail.Days') => round($item->next_audit_diff_in_days),
82+
trans('mail.supplier') => $item->supplier ? $item->supplier->name : '',
83+
trans('mail.assigned_to') => $item->assignedTo ? $item->assignedTo->display_name : '',
84+
])
85+
);
6486
}
6587

6688
}

app/Http/Controllers/Account/AcceptanceController.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function store(Request $request, $id) : RedirectResponse
7777
$acceptance = CheckoutAcceptance::find($id);
7878
$assigned_user = User::find($acceptance->assigned_to_id);
7979
$settings = Setting::getSettings();
80-
$path_logo = '';
8180
$sig_filename='';
8281

8382

@@ -138,6 +137,13 @@ public function store(Request $request, $id) : RedirectResponse
138137
}
139138

140139

140+
// Convert PDF logo to base64 for TCPDF
141+
// This is needed for TCPDF to properly embed the image if it's a png and the cache isn't writable
142+
$encoded_logo = null;
143+
if ($settings->acceptance_pdf_logo) {
144+
$encoded_logo = base64_encode(file_get_contents(public_path() . '/uploads/' . $settings->acceptance_pdf_logo));
145+
}
146+
141147
// Get the data array ready for the notifications and PDF generation
142148
$data = [
143149
'item_tag' => $item->asset_tag,
@@ -153,8 +159,8 @@ public function store(Request $request, $id) : RedirectResponse
153159
'assigned_to' => $assigned_user->display_name,
154160
'site_name' => $settings->site_name,
155161
'company_name' => $item->company?->name?? $settings->site_name,
156-
'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null,
157-
'logo' => ($settings->acceptance_pdf_logo) ? public_path() . '/uploads/' . $settings->acceptance_pdf_logo : null,
162+
'signature' => (($sig_filename && array_key_exists('1', $encoded_image))) ? $encoded_image[1] : null,
163+
'logo' => ($encoded_logo) ?? null,
158164
'date_settings' => $settings->date_display_format,
159165
'admin' => auth()->user()->present()?->fullName,
160166
'qty' => $acceptance->qty ?? 1,

app/Http/Controllers/Api/AssetsController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ public function index(Request $request, $action = null, $upcoming_status = null)
116116
'asset_eol_date',
117117
'requestable',
118118
'jobtitle',
119+
// These are *relationships* so we wouldn't normally include them in this array,
120+
// since they would normally create a `column not found` error,
121+
// BUT we account for them in the ordering switch down at the end of this method
122+
// DO NOT ADD ANYTHING TO THIS LIST WITHOUT CHECKING THE ORDERING SWITCH BELOW!
123+
'company',
124+
'model',
125+
'location',
126+
'rtd_location',
127+
'category',
128+
'status_label',
129+
'manufacturer',
130+
'supplier',
131+
'jobtitle',
132+
'assigned_to',
133+
'created_by',
134+
119135
];
120136

121137
$all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
@@ -132,6 +148,7 @@ public function index(Request $request, $action = null, $upcoming_status = null)
132148
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
133149
return in_array($key, $allowed_columns);
134150
}, ARRAY_FILTER_USE_KEY);
151+
135152
}
136153

137154
$assets = Asset::select('assets.*')

app/Http/Controllers/Api/LicensesController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Http\Transformers\LicensesTransformer;
88
use App\Http\Transformers\SelectlistTransformer;
99
use App\Models\License;
10+
use App\Models\Setting;
1011
use Illuminate\Http\Request;
1112
use Illuminate\Support\Facades\DB;
1213
use Illuminate\Http\JsonResponse;
@@ -25,9 +26,12 @@ public function index(Request $request) : JsonResponse | array
2526
$this->authorize('view', License::class);
2627

2728
$licenses = License::with('company', 'manufacturer', 'supplier','category', 'adminuser')->withCount('freeSeats as free_seats_count');
29+
$settings = Setting::getSettings();
2830

2931
if ($request->input('status')=='inactive') {
3032
$licenses->ExpiredLicenses();
33+
} elseif ($request->input('status')=='expiring') {
34+
$licenses->ExpiringLicenses($settings->alert_interval);
3135
} else {
3236
$licenses->ActiveLicenses();
3337
}

app/Http/Controllers/Api/MaintenancesController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function index(Request $request) : JsonResponse | array
5252
$maintenances->where('maintenances.created_by', '=', $request->input('created_by'));
5353
}
5454

55+
if ($request->filled('url')) {
56+
$maintenances->where('maintenances.url', '=', $request->input('url'));
57+
}
58+
5559
if ($request->filled('asset_maintenance_type')) {
5660
$maintenances->where('asset_maintenance_type', '=', $request->input('asset_maintenance_type'));
5761
}

app/Http/Controllers/Api/UploadedFilesController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,12 @@ public function destroy($object_type, $id, $file_id) : JsonResponse
193193

194194

195195
// Check for the file
196-
$log = Actionlog::find($file_id)->where('item_type', self::$map_object_type[$object_type])
197-
->where('item_id', $object->id)->first();
196+
$log = Actionlog::query()
197+
->where('id', $file_id)
198+
->where('action_type', 'uploaded')
199+
->where('item_type', self::$map_object_type[$object_type])
200+
->where('item_id', $object->id)
201+
->first();
198202

199203
if ($log) {
200204
// Check the file actually exists, and delete it
@@ -213,4 +217,4 @@ public function destroy($object_type, $id, $file_id) : JsonResponse
213217
return response()->json(Helper::formatStandardApiResponse('error', null, trans_choice('general.file_upload_status.delete.error', 1)), 500);
214218

215219
}
216-
}
220+
}

app/Http/Controllers/Assets/AssetsController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ public function update(ImageUploadRequest $request, Asset $asset) : RedirectResp
398398
$asset->assigned_to = null;
399399
$asset->assigned_type = null;
400400
$asset->accepted = null;
401+
$asset->last_checkin = now();
401402
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), 'Checkin on asset update with '.$status->getStatuslabelType().' status', date('Y-m-d H:i:s'), $originalValues));
402403
}
403404

app/Http/Controllers/MaintenancesController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function store(ImageUploadRequest $request) : RedirectResponse
7878
$maintenance->is_warranty = $request->input('is_warranty');
7979
$maintenance->cost = $request->input('cost');
8080
$maintenance->notes = $request->input('notes');
81+
$maintenance->url = $request->input('url');
8182

8283
// Save the asset maintenance data
8384
$maintenance->asset_id = $asset->id;
@@ -152,6 +153,7 @@ public function update(ImageUploadRequest $request, Maintenance $maintenance) :
152153
$maintenance->name = $request->input('name');
153154
$maintenance->start_date = $request->input('start_date');
154155
$maintenance->completion_date = $request->input('completion_date');
156+
$maintenance->url = $request->input('url');
155157

156158

157159
// Todo - put this in a getter/setter?

0 commit comments

Comments
 (0)