mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge pull request #16036 from Godmartinz/unaccepted_assets_reports_memory_fix
Some checks failed
Crowdin Action / upload-sources-to-crowdin (push) Waiting to run
CodeQL Security Scan / CodeQL Security Scan (javascript) (push) Has been cancelled
Codacy Security Scan / Codacy Security Scan (push) Has been cancelled
Docker images (Alpine) / docker (push) Has been cancelled
Docker images / docker (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Has been cancelled
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Has been cancelled
Some checks failed
Crowdin Action / upload-sources-to-crowdin (push) Waiting to run
CodeQL Security Scan / CodeQL Security Scan (javascript) (push) Has been cancelled
Codacy Security Scan / Codacy Security Scan (push) Has been cancelled
Docker images (Alpine) / docker (push) Has been cancelled
Docker images / docker (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Has been cancelled
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Has been cancelled
This commit is contained in:
commit
ca11efd3ee
|
@ -11,6 +11,7 @@ use App\Models\AssetModel;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
use App\Models\AssetMaintenance;
|
use App\Models\AssetMaintenance;
|
||||||
use App\Models\CheckoutAcceptance;
|
use App\Models\CheckoutAcceptance;
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\CustomField;
|
use App\Models\CustomField;
|
||||||
use App\Models\Depreciation;
|
use App\Models\Depreciation;
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
|
@ -18,6 +19,7 @@ use App\Models\ReportTemplate;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Notifications\CheckoutAssetNotification;
|
use App\Notifications\CheckoutAssetNotification;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
@ -1109,28 +1111,31 @@ class ReportsController extends Controller
|
||||||
$this->authorize('reports.view');
|
$this->authorize('reports.view');
|
||||||
$showDeleted = $deleted == 'deleted';
|
$showDeleted = $deleted == 'deleted';
|
||||||
|
|
||||||
/**
|
$query = CheckoutAcceptance::pending()
|
||||||
* Get all assets with pending checkout acceptances
|
->where('checkoutable_type', 'App\Models\Asset')
|
||||||
*/
|
->with([
|
||||||
if($showDeleted) {
|
'checkoutable' => function (MorphTo $query) {
|
||||||
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->withTrashed()->with(['assignedTo' , 'checkoutable.assignedTo', 'checkoutable.model'])->get();
|
$query->morphWith([
|
||||||
} else {
|
AssetModel::class => ['model'],
|
||||||
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->with(['assignedTo' => function ($query) {
|
Company::class => ['company'],
|
||||||
$query->withTrashed();
|
Asset::class => ['assignedTo'],
|
||||||
}, 'checkoutable.assignedTo', 'checkoutable.model'])->get();
|
])->with('model.category');
|
||||||
|
},
|
||||||
|
'assignedTo' => function($query){
|
||||||
|
$query->withTrashed();
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($showDeleted) {
|
||||||
|
$query->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
$assetsForReport = $acceptances
|
$assetsForReport = $query->get()
|
||||||
->filter(function ($acceptance) {
|
->map(function ($acceptance) {
|
||||||
$acceptance_checkoutable_flag = false;
|
return [
|
||||||
if ($acceptance->checkoutable){
|
'assetItem' => $acceptance->checkoutable,
|
||||||
$acceptance_checkoutable_flag = $acceptance->checkoutable->checkedOutToUser();
|
'acceptance' => $acceptance,
|
||||||
}
|
];
|
||||||
|
|
||||||
return $acceptance->checkoutable_type == 'App\Models\Asset' && $acceptance_checkoutable_flag;
|
|
||||||
})
|
|
||||||
->map(function($acceptance) {
|
|
||||||
return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return view('reports/unaccepted_assets', compact('assetsForReport','showDeleted' ));
|
return view('reports/unaccepted_assets', compact('assetsForReport','showDeleted' ));
|
||||||
|
|
|
@ -35,7 +35,7 @@ class CheckoutAcceptance extends Model
|
||||||
/**
|
/**
|
||||||
* The resource that was is out
|
* The resource that was is out
|
||||||
*
|
*
|
||||||
* @return Illuminate\Database\Eloquent\Relations\MorphTo
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
||||||
*/
|
*/
|
||||||
public function checkoutable()
|
public function checkoutable()
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,7 +80,7 @@ class AssetObserver
|
||||||
{
|
{
|
||||||
if ($settings = Setting::getSettings()) {
|
if ($settings = Setting::getSettings()) {
|
||||||
$tag = $asset->asset_tag;
|
$tag = $asset->asset_tag;
|
||||||
$prefix = $settings->auto_increment_prefix;
|
$prefix = (string)($settings->auto_increment_prefix ?? '');
|
||||||
$number = substr($tag, strlen($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)
|
// 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...
|
// AND the rest of the string after the prefix is all digits, THEN...
|
||||||
|
|
Loading…
Reference in a new issue