Skip to content

Commit

Permalink
Merge pull request #16036 from Godmartinz/unaccepted_assets_reports_m…
Browse files Browse the repository at this point in the history
…emory_fix
  • Loading branch information
snipe authored Jan 13, 2025
2 parents 4a6a94a + 9276289 commit ca11efd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
45 changes: 25 additions & 20 deletions app/Http/Controllers/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
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;
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;
Expand Down Expand Up @@ -1109,28 +1111,31 @@ public function getAssetAcceptanceReport($deleted = false) : View
$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->withTrashed();
}, 'checkoutable.assignedTo', 'checkoutable.model'])->get();
$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();
}

$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;
})
->map(function($acceptance) {
return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance];
$assetsForReport = $query->get()
->map(function ($acceptance) {
return [
'assetItem' => $acceptance->checkoutable,
'acceptance' => $acceptance,
];
});

return view('reports/unaccepted_assets', compact('assetsForReport','showDeleted' ));
Expand Down
2 changes: 1 addition & 1 deletion app/Models/CheckoutAcceptance.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function routeNotificationForMail()
/**
* The resource that was is out
*
* @return Illuminate\Database\Eloquent\Relations\MorphTo
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function checkoutable()
{
Expand Down
2 changes: 1 addition & 1 deletion app/Observers/AssetObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function created(Asset $asset)
{
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...
Expand Down

0 comments on commit ca11efd

Please sign in to comment.