mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
fixed some things, made bulk progress, tests pass
This commit is contained in:
parent
7ab0b98ff2
commit
dd8fb6ef4a
|
@ -22,7 +22,7 @@ class StoreAssetAction
|
||||||
* @throws CheckoutNotAllowed
|
* @throws CheckoutNotAllowed
|
||||||
*/
|
*/
|
||||||
public static function run(
|
public static function run(
|
||||||
$model_id,//gonna make these two optional for now... we can either make them required here or use the spread operator when calling...
|
$model_id,
|
||||||
$status_id,//
|
$status_id,//
|
||||||
ImageUploadRequest $request, //temp for handleImages - i'd like to see that moved to a helper or something - or maybe just invoked at the extended request level so that it doesn't need to be done in the action?
|
ImageUploadRequest $request, //temp for handleImages - i'd like to see that moved to a helper or something - or maybe just invoked at the extended request level so that it doesn't need to be done in the action?
|
||||||
$name = null,
|
$name = null,
|
||||||
|
|
|
@ -7,7 +7,9 @@ use App\Http\Requests\ImageUploadRequest;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\Location;
|
||||||
use App\Models\Statuslabel;
|
use App\Models\Statuslabel;
|
||||||
|
use App\Models\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
@ -17,17 +19,22 @@ class UpdateAssetAction
|
||||||
{
|
{
|
||||||
public static function run(
|
public static function run(
|
||||||
Asset $asset,
|
Asset $asset,
|
||||||
ImageUploadRequest $request,
|
ImageUploadRequest $request, //very much would like this to go away
|
||||||
$status_id = null,
|
$status_id = null,
|
||||||
$warranty_months = null,
|
$warranty_months = null,
|
||||||
$purchase_cost = null,
|
$purchase_cost = null,
|
||||||
$purchase_date = null,
|
$purchase_date = null,
|
||||||
|
$last_audit_date = null,
|
||||||
$next_audit_date = null,
|
$next_audit_date = null,
|
||||||
$asset_eol_date = null,
|
$asset_eol_date = null,
|
||||||
$supplier_id = null,
|
$supplier_id = null,
|
||||||
$expected_checkin = null,
|
$expected_checkin = null,
|
||||||
$requestable = false,
|
$requestable = false,
|
||||||
|
$location_id = null,
|
||||||
$rtd_location_id = null,
|
$rtd_location_id = null,
|
||||||
|
$assigned_location = null, // derp, make these work
|
||||||
|
$assigned_asset = null,
|
||||||
|
$assigned_user = null,
|
||||||
$byod = false,
|
$byod = false,
|
||||||
$image_delete = false,
|
$image_delete = false,
|
||||||
$serial = null,
|
$serial = null,
|
||||||
|
@ -37,16 +44,17 @@ class UpdateAssetAction
|
||||||
$order_number = null,
|
$order_number = null,
|
||||||
$asset_tag = null,
|
$asset_tag = null,
|
||||||
$notes = null,
|
$notes = null,
|
||||||
|
$isBulk = false,
|
||||||
): \App\Models\SnipeModel {
|
): \App\Models\SnipeModel {
|
||||||
|
|
||||||
dump($purchase_date);
|
$asset->status_id = $status_id ?? $asset->status_id;
|
||||||
$asset->status_id = $status_id;
|
$asset->warranty_months = $warranty_months ?? $asset->warranty_months;
|
||||||
$asset->warranty_months = $warranty_months;
|
$asset->purchase_cost = $purchase_cost ?? $asset->purchase_cost;
|
||||||
$asset->purchase_cost = $purchase_cost;
|
$asset->purchase_date = $purchase_date ?? $asset->purchase_date?->format('Y-m-d');
|
||||||
$asset->purchase_date = $purchase_date;
|
$asset->next_audit_date = $next_audit_date ?? $asset->next_audit_date;
|
||||||
$asset->next_audit_date = $next_audit_date;
|
$asset->last_audit_date = $last_audit_date ?? $asset->last_audit_date;
|
||||||
if ($purchase_date && !$asset_eol_date && ($asset->model->eol > 0)) {
|
if ($purchase_date && !$asset_eol_date && ($asset->model->eol > 0)) {
|
||||||
$asset->purchase_date = $purchase_date;
|
$asset->purchase_date = $purchase_date ?? $asset->purchase_date?->format('Y-m-d');
|
||||||
$asset->asset_eol_date = Carbon::parse($purchase_date)->addMonths($asset->model->eol)->format('Y-m-d');
|
$asset->asset_eol_date = Carbon::parse($purchase_date)->addMonths($asset->model->eol)->format('Y-m-d');
|
||||||
$asset->eol_explicit = false;
|
$asset->eol_explicit = false;
|
||||||
} elseif ($asset_eol_date) {
|
} elseif ($asset_eol_date) {
|
||||||
|
@ -68,7 +76,10 @@ class UpdateAssetAction
|
||||||
$asset->supplier_id = $supplier_id;
|
$asset->supplier_id = $supplier_id;
|
||||||
$asset->expected_checkin = $expected_checkin;
|
$asset->expected_checkin = $expected_checkin;
|
||||||
$asset->requestable = $requestable;
|
$asset->requestable = $requestable;
|
||||||
$asset->rtd_location_id = $rtd_location_id;
|
|
||||||
|
$asset->location_id = $location_id;
|
||||||
|
|
||||||
|
!$isBulk ?? $asset->rtd_location_id = $rtd_location_id;
|
||||||
$asset->byod = $byod;
|
$asset->byod = $byod;
|
||||||
|
|
||||||
$status = Statuslabel::find($status_id);
|
$status = Statuslabel::find($status_id);
|
||||||
|
@ -102,20 +113,20 @@ class UpdateAssetAction
|
||||||
|
|
||||||
$asset->name = $name;
|
$asset->name = $name;
|
||||||
$asset->company_id = Company::getIdForCurrentUser($company_id);
|
$asset->company_id = Company::getIdForCurrentUser($company_id);
|
||||||
$asset->model_id = $model_id;
|
$asset->model_id = $model_id ?? $asset->model_id;
|
||||||
$asset->order_number = $order_number;
|
$asset->order_number = $order_number ?? $asset->order_number;
|
||||||
|
|
||||||
$asset->asset_tag = $asset_tag;
|
$asset->asset_tag = $asset_tag ?? $asset->asset_tag;
|
||||||
|
|
||||||
$asset->notes = $notes;
|
$asset->notes = $notes;
|
||||||
|
|
||||||
// andddddddd the handleImages issue reappears - i guess we'll be passing the request through here as well
|
|
||||||
$asset = $request->handleImages($asset);
|
$asset = $request->handleImages($asset);
|
||||||
|
|
||||||
// Update custom fields in the database.
|
// Update custom fields in the database.
|
||||||
// Validation for these fields is handlded through the AssetRequest form request
|
// Validation for these fields is handlded through the AssetRequest form request
|
||||||
// FIXME: No idea why this is returning a Builder error on db_column_name.
|
// FIXME: No idea why this is returning a Builder error on db_column_name.
|
||||||
// Need to investigate and fix. Using static method for now.
|
// Need to investigate and fix. Using static method for now.
|
||||||
|
|
||||||
$model = AssetModel::find($request->get('model_id'));
|
$model = AssetModel::find($request->get('model_id'));
|
||||||
if (($model) && ($model->fieldset)) {
|
if (($model) && ($model->fieldset)) {
|
||||||
foreach ($model->fieldset->fields as $field) {
|
foreach ($model->fieldset->fields as $field) {
|
||||||
|
@ -140,8 +151,48 @@ class UpdateAssetAction
|
||||||
|
|
||||||
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
||||||
|
|
||||||
$asset->save();
|
if ($isBulk) {
|
||||||
|
self::bulkUpdate($asset, $request);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($asset->save()) {
|
||||||
|
// check out stuff
|
||||||
|
if (!is_null($assigned_user) && ($target = User::find($assigned_user))) {
|
||||||
|
$location = $target->location_id;
|
||||||
|
} elseif (!is_null($assigned_asset) && ($target = Asset::find($assigned_asset))) {
|
||||||
|
$location = $target->location_id;
|
||||||
|
|
||||||
|
Asset::where('assigned_type', \App\Models\Asset::class)->where('assigned_to', $asset->id)
|
||||||
|
->update(['location_id' => $target->location_id]);
|
||||||
|
} elseif (!is_null($assigned_location) && ($target = Location::find($assigned_location))) {
|
||||||
|
$location = $target->id;
|
||||||
|
}
|
||||||
|
if (isset($target)) {
|
||||||
|
$asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), '', 'Checked out on asset update', e($request->get('name')), $location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $asset;
|
return $asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function bulkUpdate($asset, $request): void
|
||||||
|
{
|
||||||
|
if ($request->filled('rtd_location_id')) {
|
||||||
|
|
||||||
|
if (($request->filled('update_real_loc')) && (($request->input('update_real_loc')) == '0')) {
|
||||||
|
$asset->rtd_location_id = $request->input('rtd_location_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($request->filled('update_real_loc')) && (($request->input('update_real_loc')) == '1')) {
|
||||||
|
$asset->location_id = $request->input('rtd_location_id');
|
||||||
|
$asset->rtd_location_id = $request->input('rtd_location_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($request->filled('update_real_loc')) && (($request->input('update_real_loc')) == '2')) {
|
||||||
|
$asset->location_id = $request->input('rtd_location_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -30,13 +30,11 @@ use App\Models\License;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Watson\Validating\ValidationException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -655,6 +653,10 @@ class AssetsController extends Controller
|
||||||
UpdateAssetAction::run($asset, $request, ...$request->validated());
|
UpdateAssetAction::run($asset, $request, ...$request->validated());
|
||||||
} catch (CheckoutNotAllowed $e) {
|
} catch (CheckoutNotAllowed $e) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $e->getMessage()), 200);
|
return response()->json(Helper::formatStandardApiResponse('error', null, $e->getMessage()), 200);
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $e->getErrors()), 200);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset->fill($request->validated());
|
$asset->fill($request->validated());
|
||||||
|
@ -708,20 +710,20 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
if (($request->filled('assigned_user')) && ($target = User::find($request->get('assigned_user')))) {
|
//if (($request->filled('assigned_user')) && ($target = User::find($request->get('assigned_user')))) {
|
||||||
$location = $target->location_id;
|
// $location = $target->location_id;
|
||||||
} elseif (($request->filled('assigned_asset')) && ($target = Asset::find($request->get('assigned_asset')))) {
|
//} elseif (($request->filled('assigned_asset')) && ($target = Asset::find($request->get('assigned_asset')))) {
|
||||||
$location = $target->location_id;
|
// $location = $target->location_id;
|
||||||
|
//
|
||||||
Asset::where('assigned_type', \App\Models\Asset::class)->where('assigned_to', $asset->id)
|
// Asset::where('assigned_type', \App\Models\Asset::class)->where('assigned_to', $asset->id)
|
||||||
->update(['location_id' => $target->location_id]);
|
// ->update(['location_id' => $target->location_id]);
|
||||||
} elseif (($request->filled('assigned_location')) && ($target = Location::find($request->get('assigned_location')))) {
|
//} elseif (($request->filled('assigned_location')) && ($target = Location::find($request->get('assigned_location')))) {
|
||||||
$location = $target->id;
|
// $location = $target->id;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
if (isset($target)) {
|
//if (isset($target)) {
|
||||||
$asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), '', 'Checked out on asset update', e($request->get('name')), $location);
|
// $asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), '', 'Checked out on asset update', e($request->get('name')), $location);
|
||||||
}
|
//}
|
||||||
|
|
||||||
if ($asset->image) {
|
if ($asset->image) {
|
||||||
$asset->image = $asset->getImageUrl();
|
$asset->image = $asset->getImageUrl();
|
||||||
|
|
|
@ -38,6 +38,7 @@ use Illuminate\Http\Response;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
|
use Watson\Validating\ValidationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class controls all actions related to assets for
|
* This class controls all actions related to assets for
|
||||||
|
@ -267,57 +268,12 @@ class AssetsController extends Controller
|
||||||
);
|
);
|
||||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
||||||
->with('success', trans('admin/hardware/message.update.success'));
|
->with('success', trans('admin/hardware/message.update.success'));
|
||||||
} catch (\Watson\Validating\ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
$errors = $e->getErrors();
|
return redirect()->back()->withInput()->withErrors($e->getErrors());
|
||||||
return redirect()->back()->withInput()->withErrors($errors);
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return redirect()->back()->with('error', trans('admin/hardware/message.update.error'), $asset);
|
return redirect()->back()->with('error', trans('admin/hardware/message.update.error'), $asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// serials????
|
|
||||||
//$asset->name = $request->input('name');
|
|
||||||
//$asset->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
|
||||||
//$asset->model_id = $request->input('model_id');
|
|
||||||
//$asset->order_number = $request->input('order_number');
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//$asset->notes = $request->input('notes');
|
|
||||||
//
|
|
||||||
//$asset = $request->handleImages($asset);
|
|
||||||
//
|
|
||||||
//// Update custom fields in the database.
|
|
||||||
//$model = AssetModel::find($request->get('model_id'));
|
|
||||||
//if (($model) && ($model->fieldset)) {
|
|
||||||
// foreach ($model->fieldset->fields as $field) {
|
|
||||||
//
|
|
||||||
// if ($field->field_encrypted == '1') {
|
|
||||||
// if (Gate::allows('assets.view.encrypted_custom_fields')) {
|
|
||||||
// if (is_array($request->input($field->db_column))) {
|
|
||||||
// $asset->{$field->db_column} = Crypt::encrypt(implode(', ', $request->input($field->db_column)));
|
|
||||||
// } else {
|
|
||||||
// $asset->{$field->db_column} = Crypt::encrypt($request->input($field->db_column));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if (is_array($request->input($field->db_column))) {
|
|
||||||
// $asset->{$field->db_column} = implode(', ', $request->input($field->db_column));
|
|
||||||
// } else {
|
|
||||||
// $asset->{$field->db_column} = $request->input($field->db_column);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
|
||||||
//
|
|
||||||
//if ($asset->save()) {
|
|
||||||
// return redirect()->to(Helper::getRedirectOption($request, $assetId, 'Assets'))
|
|
||||||
// ->with('success', trans('admin/hardware/message.update.success'));
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//return redirect()->back()->withInput()->withErrors($asset->getErrors());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Assets;
|
namespace App\Http\Controllers\Assets;
|
||||||
|
|
||||||
|
use App\Actions\Assets\UpdateAssetAction;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use App\Http\Controllers\CheckInOutRequest;
|
use App\Http\Controllers\CheckInOutRequest;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
use App\Models\Statuslabel;
|
use App\Models\Statuslabel;
|
||||||
|
@ -21,6 +23,7 @@ use App\Models\CustomField;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
|
use Watson\Validating\ValidationException;
|
||||||
|
|
||||||
class BulkAssetsController extends Controller
|
class BulkAssetsController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -199,25 +202,65 @@ class BulkAssetsController extends Controller
|
||||||
* @internal param array $assets
|
* @internal param array $assets
|
||||||
* @since [v2.0]
|
* @since [v2.0]
|
||||||
*/
|
*/
|
||||||
public function update(Request $request) : RedirectResponse
|
public function update(ImageUploadRequest $request): RedirectResponse
|
||||||
{
|
{
|
||||||
|
// this should be in request, but request weird, need to think it through a little
|
||||||
$this->authorize('update', Asset::class);
|
$this->authorize('update', Asset::class);
|
||||||
|
// Get the back url from the session and then destroy the session
|
||||||
|
$bulk_back_url = route('hardware.index');
|
||||||
|
// is this necessary?
|
||||||
|
if (!$request->filled('ids') || count($request->input('ids')) == 0) {
|
||||||
|
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
||||||
|
}
|
||||||
|
if ($request->session()->has('bulk_back_url')) {
|
||||||
|
$bulk_back_url = $request->session()->pull('bulk_back_url');
|
||||||
|
}
|
||||||
|
// find and update assets
|
||||||
|
$assets = Asset::whereIn('id', $request->input('ids'))->get();
|
||||||
|
$errors = [];
|
||||||
|
foreach ($assets as $key => $asset) {
|
||||||
|
try {
|
||||||
|
$updatedAsset = UpdateAssetAction::run(
|
||||||
|
asset: $asset,
|
||||||
|
request: $request,
|
||||||
|
status_id: $request->input('status_id'),
|
||||||
|
warranty_months: $request->input('warranty_months'),
|
||||||
|
purchase_cost: $request->input('purchase_cost'),
|
||||||
|
purchase_date: $request->filled('null_purchase_date') ? null : $request->input('purchase_date'),
|
||||||
|
next_audit_date: $request->filled('null_next_audit_date') ? null : $request->input('next_audit_date'),
|
||||||
|
supplier_id: $request->input('supplier_id'),
|
||||||
|
expected_checkin: $request->filled('null_expected_checkin_date') ? null : $request->input('expected_checkin'),
|
||||||
|
requestable: $request->input('requestable'),
|
||||||
|
rtd_location_id: $request->input('rtd_location_id'),
|
||||||
|
name: $request->filled('null_name') ? null : $request->input('name'),
|
||||||
|
company_id: $request->input('company_id'),
|
||||||
|
model_id: $request->input('model_id'),
|
||||||
|
order_number: $request->input('order_number'),
|
||||||
|
isBulk: true,
|
||||||
|
);
|
||||||
|
// catch exceptions
|
||||||
|
} catch (ValidationException $e) {
|
||||||
|
$errors[$key] = $e->getMessage();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
report($e);
|
||||||
|
$errors[$key] = trans('general.something_went_wrong');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($errors)) {
|
||||||
|
return redirect($bulk_back_url)->with('bulk_asset_errors', $errors);
|
||||||
|
}
|
||||||
|
return redirect()->to('index')->with('success', trans('admin/hardware/message.update.assets_do_not_exist'));
|
||||||
|
|
||||||
|
|
||||||
$has_errors = 0;
|
$has_errors = 0;
|
||||||
$error_array = array();
|
$error_array = array();
|
||||||
|
|
||||||
// Get the back url from the session and then destroy the session
|
// Get the back url from the session and then destroy the session
|
||||||
$bulk_back_url = route('hardware.index');
|
|
||||||
|
|
||||||
if ($request->session()->has('bulk_back_url')) {
|
|
||||||
$bulk_back_url = $request->session()->pull('bulk_back_url');
|
|
||||||
}
|
|
||||||
|
|
||||||
$custom_field_columns = CustomField::all()->pluck('db_column')->toArray();
|
$custom_field_columns = CustomField::all()->pluck('db_column')->toArray();
|
||||||
|
|
||||||
|
|
||||||
if (! $request->filled('ids') || count($request->input('ids')) == 0) {
|
|
||||||
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$assets = Asset::whereIn('id', $request->input('ids'))->get();
|
$assets = Asset::whereIn('id', $request->input('ids'))->get();
|
||||||
|
@ -232,24 +275,8 @@ class BulkAssetsController extends Controller
|
||||||
* its checkout status.
|
* its checkout status.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (($request->filled('name'))
|
if (
|
||||||
|| ($request->filled('purchase_date'))
|
($request->anyFilled($custom_field_columns))
|
||||||
|| ($request->filled('expected_checkin'))
|
|
||||||
|| ($request->filled('purchase_cost'))
|
|
||||||
|| ($request->filled('supplier_id'))
|
|
||||||
|| ($request->filled('order_number'))
|
|
||||||
|| ($request->filled('warranty_months'))
|
|
||||||
|| ($request->filled('rtd_location_id'))
|
|
||||||
|| ($request->filled('requestable'))
|
|
||||||
|| ($request->filled('company_id'))
|
|
||||||
|| ($request->filled('status_id'))
|
|
||||||
|| ($request->filled('model_id'))
|
|
||||||
|| ($request->filled('next_audit_date'))
|
|
||||||
|| ($request->filled('null_name'))
|
|
||||||
|| ($request->filled('null_purchase_date'))
|
|
||||||
|| ($request->filled('null_expected_checkin_date'))
|
|
||||||
|| ($request->filled('null_next_audit_date'))
|
|
||||||
|| ($request->anyFilled($custom_field_columns))
|
|
||||||
|
|
||||||
) {
|
) {
|
||||||
// Let's loop through those assets and build an update array
|
// Let's loop through those assets and build an update array
|
||||||
|
@ -264,14 +291,14 @@ class BulkAssetsController extends Controller
|
||||||
* It's tempting to make these match the request check above, but some of these values require
|
* It's tempting to make these match the request check above, but some of these values require
|
||||||
* extra work to make sure the data makes sense.
|
* extra work to make sure the data makes sense.
|
||||||
*/
|
*/
|
||||||
$this->conditionallyAddItem('name')
|
//$this->conditionallyAddItem('name')
|
||||||
->conditionallyAddItem('purchase_date')
|
// ->conditionallyAddItem('purchase_date')
|
||||||
->conditionallyAddItem('expected_checkin')
|
// ->conditionallyAddItem('expected_checkin')
|
||||||
->conditionallyAddItem('order_number')
|
// ->conditionallyAddItem('order_number')
|
||||||
->conditionallyAddItem('requestable')
|
// ->conditionallyAddItem('requestable')
|
||||||
->conditionallyAddItem('supplier_id')
|
// ->conditionallyAddItem('supplier_id')
|
||||||
->conditionallyAddItem('warranty_months')
|
// ->conditionallyAddItem('warranty_months')
|
||||||
->conditionallyAddItem('next_audit_date');
|
// ->conditionallyAddItem('next_audit_date');
|
||||||
foreach ($custom_field_columns as $key => $custom_field_column) {
|
foreach ($custom_field_columns as $key => $custom_field_column) {
|
||||||
$this->conditionallyAddItem($custom_field_column);
|
$this->conditionallyAddItem($custom_field_column);
|
||||||
}
|
}
|
||||||
|
@ -296,10 +323,6 @@ class BulkAssetsController extends Controller
|
||||||
/**
|
/**
|
||||||
* Blank out fields that were requested to be blanked out via checkbox
|
* Blank out fields that were requested to be blanked out via checkbox
|
||||||
*/
|
*/
|
||||||
if ($request->input('null_name')=='1') {
|
|
||||||
|
|
||||||
$this->update_array['name'] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->input('null_purchase_date')=='1') {
|
if ($request->input('null_purchase_date')=='1') {
|
||||||
$this->update_array['purchase_date'] = null;
|
$this->update_array['purchase_date'] = null;
|
||||||
|
@ -308,18 +331,10 @@ class BulkAssetsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->input('null_expected_checkin_date')=='1') {
|
|
||||||
$this->update_array['expected_checkin'] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->input('null_next_audit_date')=='1') {
|
if ($request->input('null_next_audit_date')=='1') {
|
||||||
$this->update_array['next_audit_date'] = null;
|
$this->update_array['next_audit_date'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('purchase_cost')) {
|
|
||||||
$this->update_array['purchase_cost'] = $request->input('purchase_cost');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->filled('company_id')) {
|
if ($request->filled('company_id')) {
|
||||||
$this->update_array['company_id'] = $request->input('company_id');
|
$this->update_array['company_id'] = $request->input('company_id');
|
||||||
if ($request->input('company_id') == 'clear') {
|
if ($request->input('company_id') == 'clear') {
|
||||||
|
@ -393,6 +408,7 @@ class BulkAssetsController extends Controller
|
||||||
* WILL NOT BE logged in the edit log_meta data
|
* WILL NOT BE logged in the edit log_meta data
|
||||||
* ------------------------------------------------------------------------------
|
* ------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
// it looks like this doesn't do anything anymore 🤔
|
||||||
$changed = [];
|
$changed = [];
|
||||||
|
|
||||||
foreach ($this->update_array as $key => $value) {
|
foreach ($this->update_array as $key => $value) {
|
||||||
|
|
Loading…
Reference in a new issue