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

This commit is contained in:
snipe 2025-01-13 22:23:30 +00:00 committed by GitHub
commit ca11efd3ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 22 deletions

View file

@ -11,6 +11,7 @@ use App\Models\AssetModel;
use App\Models\Category;
use App\Models\AssetMaintenance;
use App\Models\CheckoutAcceptance;
use App\Models\Company;
use App\Models\CustomField;
use App\Models\Depreciation;
use App\Models\License;
@ -18,6 +19,7 @@ use App\Models\ReportTemplate;
use App\Models\Setting;
use App\Notifications\CheckoutAssetNotification;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Mail;
@ -1109,28 +1111,31 @@ 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();
} else {
$acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->with(['assignedTo' => function ($query) {
$query = CheckoutAcceptance::pending()
->where('checkoutable_type', 'App\Models\Asset')
->with([
'checkoutable' => function (MorphTo $query) {
$query->morphWith([
AssetModel::class => ['model'],
Company::class => ['company'],
Asset::class => ['assignedTo'],
])->with('model.category');
},
'assignedTo' => function($query){
$query->withTrashed();
}
]);
if ($showDeleted) {
$query->withTrashed();
}, 'checkoutable.assignedTo', 'checkoutable.model'])->get();
}
$assetsForReport = $acceptances
->filter(function ($acceptance) {
$acceptance_checkoutable_flag = false;
if ($acceptance->checkoutable){
$acceptance_checkoutable_flag = $acceptance->checkoutable->checkedOutToUser();
}
return $acceptance->checkoutable_type == 'App\Models\Asset' && $acceptance_checkoutable_flag;
})
$assetsForReport = $query->get()
->map(function ($acceptance) {
return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance];
return [
'assetItem' => $acceptance->checkoutable,
'acceptance' => $acceptance,
];
});
return view('reports/unaccepted_assets', compact('assetsForReport','showDeleted' ));

View file

@ -35,7 +35,7 @@ class CheckoutAcceptance extends Model
/**
* The resource that was is out
*
* @return Illuminate\Database\Eloquent\Relations\MorphTo
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function checkoutable()
{

View file

@ -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...