mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
fix deprecation on asset obs get unaccept report to populate
This commit is contained in:
parent
331fbb66bd
commit
bb03e00279
|
@ -9,6 +9,7 @@ use App\Models\Setting;
|
|||
use App\Notifications\ExpiringAssetsNotification;
|
||||
use App\Notifications\ExpiringLicenseNotification;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
class SendExpirationAlerts extends Command
|
||||
{
|
||||
|
@ -45,7 +46,7 @@ class SendExpirationAlerts extends Command
|
|||
$threshold = $settings->alert_interval;
|
||||
|
||||
if (($settings->alert_email != '') && ($settings->alerts_enabled == 1)) {
|
||||
|
||||
$this->info('alerts');
|
||||
// Send a rollup to the admin, if settings dictate
|
||||
$recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) {
|
||||
return new AlertRecipient($item);
|
||||
|
@ -54,15 +55,17 @@ class SendExpirationAlerts extends Command
|
|||
// Expiring Assets
|
||||
$assets = Asset::getExpiringWarrantee($threshold);
|
||||
if ($assets->count() > 0) {
|
||||
$this->info('expiring warrantees');
|
||||
$this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), ['count' => $assets->count(), 'threshold' => $threshold]));
|
||||
\Notification::send($recipients, new ExpiringAssetsNotification($assets, $threshold));
|
||||
Notification::send($recipients, new ExpiringAssetsNotification($assets, $threshold));
|
||||
}
|
||||
|
||||
// Expiring licenses
|
||||
$licenses = License::getExpiringLicenses($threshold);
|
||||
if ($licenses->count() > 0) {
|
||||
$this->info('expiring licenses');
|
||||
$this->info(trans_choice('mail.license_expiring_alert', $licenses->count(), ['count' => $licenses->count(), 'threshold' => $threshold]));
|
||||
\Notification::send($recipients, new ExpiringLicenseNotification($licenses, $threshold));
|
||||
Notification::send($recipients, new ExpiringLicenseNotification($licenses, $threshold));
|
||||
}
|
||||
} else {
|
||||
if ($settings->alert_email == '') {
|
||||
|
@ -71,5 +74,6 @@ class SendExpirationAlerts extends Command
|
|||
$this->info('Alerts are disabled in the settings. No mail will be sent');
|
||||
}
|
||||
}
|
||||
$this->info('nothing here.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1093,30 +1093,43 @@ class ReportsController extends Controller
|
|||
$this->authorize('reports.view');
|
||||
$showDeleted = $deleted == 'deleted';
|
||||
|
||||
/**
|
||||
* Get all assets with pending checkout acceptances
|
||||
*/
|
||||
if($showDeleted) {
|
||||
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->withTrashed()->with(['assignedTo' , 'checkoutable.assignedTo', 'checkoutable.model'])->get();
|
||||
$assetsForReport = collect();
|
||||
|
||||
$query = CheckoutAcceptance::pending()
|
||||
->where('checkoutable_type', 'App\Models\Asset')
|
||||
->with(['checkoutable.assignedTo', 'checkoutable.model']); // Eager load common relationships
|
||||
|
||||
if ($showDeleted) {
|
||||
$query->withTrashed()->with(['assignedTo']);
|
||||
} else {
|
||||
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->with(['assignedTo' => function ($query) {
|
||||
$query->with(['assignedTo' => function ($query) {
|
||||
$query->withTrashed();
|
||||
}, 'checkoutable.assignedTo', 'checkoutable.model'])->get();
|
||||
}]);
|
||||
}
|
||||
|
||||
$assetsForReport = $acceptances
|
||||
->filter(function ($acceptance) {
|
||||
// Process records in chunks
|
||||
$query->chunk(100, function ($chunk) use (&$assetsForReport) {
|
||||
|
||||
$filtered = $chunk->filter(function ($acceptance) {
|
||||
$acceptance_checkoutable_flag = false;
|
||||
if ($acceptance->checkoutable){
|
||||
$acceptance_checkoutable_flag = $acceptance->checkoutable->checkedOutToUser();
|
||||
|
||||
if($acceptance->checkoutable) {
|
||||
$acceptance_checkoutable_flag = $acceptance->assignedTo;
|
||||
}
|
||||
|
||||
return $acceptance->checkoutable_type == 'App\Models\Asset' && $acceptance_checkoutable_flag;
|
||||
})
|
||||
->map(function($acceptance) {
|
||||
return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance];
|
||||
// Return true if criteria match
|
||||
return $acceptance->checkoutable_type === 'App\Models\Asset' && $acceptance_checkoutable_flag;
|
||||
})->map(function ($acceptance) {
|
||||
|
||||
return [
|
||||
'assetItem' => $acceptance->checkoutable,
|
||||
'acceptance' => $acceptance,
|
||||
];
|
||||
});
|
||||
|
||||
// Merge results into the main collection
|
||||
$assetsForReport = $assetsForReport->merge($filtered);
|
||||
});
|
||||
|
||||
return view('reports/unaccepted_assets', compact('assetsForReport','showDeleted' ));
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ class AssetObserver
|
|||
{
|
||||
if ($settings = Setting::getSettings()) {
|
||||
$tag = $asset->asset_tag;
|
||||
$prefix = $settings->auto_increment_prefix;
|
||||
$prefix = (string)($settings->auto_increment_prefix ?? '');
|
||||
$number = substr($tag, strlen($prefix));
|
||||
// IF - auto_increment_assets is on, AND (there is no prefix OR the prefix matches the start of the tag)
|
||||
// AND the rest of the string after the prefix is all digits, THEN...
|
||||
|
|
Loading…
Reference in a new issue