removes undeployables from asset_id array
This commit is contained in:
@@ -53,9 +53,13 @@ class BulkAssetsController extends Controller
|
||||
|
||||
$asset_ids = $request->input('ids');
|
||||
if ($request->input('bulk_actions') === 'checkout') {
|
||||
$status_check =$this->hasUndeployableStatus($asset_ids);
|
||||
if($status_check && $status_check['status'] === true){
|
||||
|
||||
if($this->hasUndeployableStatus($asset_ids)){
|
||||
return redirect()->back()->with('error', trans('admin/hardware/message.undeployable'));
|
||||
$asset_tags = implode(', ', array_column($status_check['tags'], 'asset_tag'));
|
||||
$asset_ids = $status_check['asset_ids'];
|
||||
|
||||
session()->flash('error', trans('admin/hardware/message.undeployable', ['asset_tags' => $asset_tags]));
|
||||
}
|
||||
|
||||
$request->session()->flashInput(['selected_assets' => $asset_ids]);
|
||||
@@ -665,14 +669,24 @@ class BulkAssetsController extends Controller
|
||||
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.restore.success'));
|
||||
}
|
||||
}
|
||||
public function hasUndeployableStatus (array $asset_ids) : bool
|
||||
public function hasUndeployableStatus (array $asset_ids)
|
||||
{
|
||||
$undeployable = Asset::whereIn('id', $asset_ids)
|
||||
->undeployable()
|
||||
->first();
|
||||
->get();
|
||||
|
||||
if($undeployable) {
|
||||
return true;
|
||||
$undeployableTags = $undeployable->map(function ($asset) {
|
||||
return [
|
||||
'id' => $asset->id,
|
||||
'asset_tag' => $asset->asset_tag,
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
$undeployableIds = array_column($undeployableTags, 'id');
|
||||
$filtered_ids = array_diff($asset_ids, $undeployableIds);
|
||||
|
||||
if($undeployable->isNotEmpty()) {
|
||||
return ['status' => true, 'tags' => $undeployableTags, 'asset_ids' => $filtered_ids];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
return [
|
||||
|
||||
'undeployable' => 'An asset in your selection for checkout has been marked as currently undeployable. If this status has changed, please update the asset status before checking it out.',
|
||||
'undeployable' => 'The following assets cannot be deployed and have been removed from checkout: :asset_tags',
|
||||
'does_not_exist' => 'Asset does not exist.',
|
||||
'does_not_exist_var' => 'Asset with tag :asset_tag not found.',
|
||||
'no_tag' => 'No asset tag provided.',
|
||||
|
||||
Reference in New Issue
Block a user