mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 22:19:41 -08:00
Merge pull request #13776 from Robert-Azelis/Robert-Azelis-EOL_fix_improvements
[FIX and improvements] EOL rate and EOL date
This commit is contained in:
commit
b4d3f51414
|
@ -179,9 +179,14 @@ class AssetModelsController extends Controller
|
|||
|
||||
if ($model->save()) {
|
||||
if ($model->wasChanged('eol')) {
|
||||
$newEol = $model->eol;
|
||||
$model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false)
|
||||
->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL ' . $newEol . ' MONTH)')]);
|
||||
if ($model->eol > 0) {
|
||||
$newEol = $model->eol;
|
||||
$model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false)
|
||||
->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL ' . $newEol . ' MONTH)')]);
|
||||
} elseif ($model->eol == 0) {
|
||||
$model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false)
|
||||
->update(['asset_eol_date' => DB::raw('null')]);
|
||||
}
|
||||
}
|
||||
return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success'));
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ class AssetsController extends Controller
|
|||
$asset->warranty_months = request('warranty_months', null);
|
||||
$asset->purchase_cost = request('purchase_cost');
|
||||
$asset->purchase_date = request('purchase_date', null);
|
||||
$asset->asset_eol_date = request('asset_eol_date', $asset->present()->eol_date());
|
||||
$asset->asset_eol_date = request('asset_eol_date', null);
|
||||
$asset->assigned_to = request('assigned_to', null);
|
||||
$asset->supplier_id = request('supplier_id', null);
|
||||
$asset->requestable = request('requestable', 0);
|
||||
|
@ -309,14 +309,15 @@ class AssetsController extends Controller
|
|||
$asset->warranty_months = $request->input('warranty_months', null);
|
||||
$asset->purchase_cost = $request->input('purchase_cost', null);
|
||||
$asset->purchase_date = $request->input('purchase_date', null);
|
||||
if ($request->filled('purchase_date') && !$request->filled('asset_eol_date') && $asset->model->eol) {
|
||||
if ($request->filled('purchase_date') && !$request->filled('asset_eol_date') && ($asset->model->eol > 0)) {
|
||||
$asset->purchase_date = $request->input('purchase_date', null);
|
||||
$asset->asset_eol_date = Carbon::parse($request->input('purchase_date'))->addMonths($asset->model->eol)->format('Y-m-d');
|
||||
$asset->eol_explicit = false;
|
||||
} elseif ($request->filled('asset_eol_date')) {
|
||||
$asset->asset_eol_date = $request->input('asset_eol_date', null);
|
||||
$months = Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date);
|
||||
if($asset->model->eol) {
|
||||
if($months != $asset->model->eol) {
|
||||
if($months != $asset->model->eol > 0) {
|
||||
$asset->eol_explicit = true;
|
||||
} else {
|
||||
$asset->eol_explicit = false;
|
||||
|
@ -324,6 +325,9 @@ class AssetsController extends Controller
|
|||
} else {
|
||||
$asset->eol_explicit = true;
|
||||
}
|
||||
} elseif (!$request->filled('asset_eol_date') && (($asset->model->eol) == 0)) {
|
||||
$asset->asset_eol_date = null;
|
||||
$asset->eol_explicit = false;
|
||||
}
|
||||
$asset->supplier_id = $request->input('supplier_id', null);
|
||||
$asset->expected_checkin = $request->input('expected_checkin', null);
|
||||
|
|
|
@ -7,6 +7,7 @@ use App\Models\Asset;
|
|||
use App\Models\Setting;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Carbon\Carbon;
|
||||
use Auth;
|
||||
|
||||
class AssetsTransformer
|
||||
|
@ -38,7 +39,7 @@ class AssetsTransformer
|
|||
'byod' => ($asset->byod ? true : false),
|
||||
|
||||
'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null,
|
||||
'eol' => (($asset->model) && ($asset->model->eol != '')) ? $asset->model->eol : null,
|
||||
'eol' => (($asset->asset_eol_date != '') && ($asset->purchase_date != '')) ? Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date).' months' : null,
|
||||
'asset_eol_date' => ($asset->asset_eol_date != '') ? Helper::getFormattedDateObject($asset->asset_eol_date, 'date') : null,
|
||||
'status_label' => ($asset->assetstatus) ? [
|
||||
'id' => (int) $asset->assetstatus->id,
|
||||
|
|
|
@ -137,14 +137,14 @@ class AssetObserver
|
|||
public function saving(Asset $asset)
|
||||
{
|
||||
// determine if calculated eol and then calculate it - this should only happen on a new asset
|
||||
if (is_null($asset->asset_eol_date) && !is_null($asset->purchase_date) && !is_null($asset->model->eol)){
|
||||
if (is_null($asset->asset_eol_date) && !is_null($asset->purchase_date) && ($asset->model->eol > 0)){
|
||||
$asset->asset_eol_date = $asset->purchase_date->addMonths($asset->model->eol)->format('Y-m-d');
|
||||
$asset->eol_explicit = false;
|
||||
}
|
||||
|
||||
// determine if explicit and set eol_explicit to true
|
||||
if (!is_null($asset->asset_eol_date) && !is_null($asset->purchase_date)) {
|
||||
if($asset->model->eol) {
|
||||
if($asset->model->eol > 0) {
|
||||
$months = Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date);
|
||||
if($months != $asset->model->eol) {
|
||||
$asset->eol_explicit = true;
|
||||
|
@ -153,7 +153,7 @@ class AssetObserver
|
|||
} elseif (!is_null($asset->asset_eol_date) && is_null($asset->purchase_date)) {
|
||||
$asset->eol_explicit = true;
|
||||
}
|
||||
if ((!is_null($asset->asset_eol_date)) && (!is_null($asset->purchase_date)) && (is_null($asset->model->eol))) {
|
||||
if ((!is_null($asset->asset_eol_date)) && (!is_null($asset->purchase_date)) && (is_null($asset->model->eol) || ($asset->model->eol == 0))) {
|
||||
$asset->eol_explicit = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ class AssetModelPresenter extends Presenter
|
|||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'switchable' => true,
|
||||
'title' => trans('general.eol'),
|
||||
'title' => trans('admin/hardware/form.eol_rate'),
|
||||
'visible' => true,
|
||||
],
|
||||
[
|
||||
|
|
|
@ -173,7 +173,7 @@ class AssetPresenter extends Presenter
|
|||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'visible' => false,
|
||||
'title' => trans('general.eol'),
|
||||
'title' => trans('admin/hardware/form.eol_rate'),
|
||||
],
|
||||
[
|
||||
'field' => 'asset_eol_date',
|
||||
|
|
|
@ -631,7 +631,7 @@
|
|||
</div>
|
||||
@endif
|
||||
|
||||
@if (($asset->model) && ($asset->model->eol))
|
||||
@if (($asset->asset_eol_date) && ($asset->purchase_date))
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<strong>
|
||||
|
@ -639,7 +639,7 @@
|
|||
</strong>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
{{ $asset->model->eol }}
|
||||
{{ Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date) }}
|
||||
{{ trans('admin/hardware/form.months') }}
|
||||
|
||||
</div>
|
||||
|
@ -650,6 +650,9 @@
|
|||
<div class="col-md-2">
|
||||
<strong>
|
||||
{{ trans('admin/hardware/form.eol_date') }}
|
||||
@if ($asset->purchase_date)
|
||||
{!! $asset->asset_eol_date < date("Y-m-d") ? '<i class="fas fa-exclamation-triangle text-orange" aria-hidden="true"></i>' : '' !!}
|
||||
@endif
|
||||
</strong>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<!-- Purchase Date -->
|
||||
<!-- EOL Date -->
|
||||
<div class="form-group {{ $errors->has('asset_eol_date') ? ' has-error' : '' }}">
|
||||
<label for="asset_eol_date" class="col-md-3 control-label">{{ trans('admin/hardware/form.eol_date') }}</label>
|
||||
<div class="input-group col-md-4">
|
||||
<div class="input-group date" data-provide="datepicker" data-date-clear-btn="true" data-date-format="yyyy-mm-dd" data-autoclose="true">
|
||||
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="asset_eol_date" id="asset_eol_date" readonly value="{{ old('asset_eol_date', optional($item->asset_eol_date)->format('Y-m-d') ?? $item->present()->eol_date() ?? '') }}" style="background-color:inherit">
|
||||
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="asset_eol_date" id="asset_eol_date" readonly value="{{ old('asset_eol_date', optional($item->asset_eol_date)->format('Y-m-d') ?? $item->asset_eol_date ?? '') }}" style="background-color:inherit" />
|
||||
<span class="input-group-addon"><i class="fas fa-calendar" aria-hidden="true"></i></span>
|
||||
</div>
|
||||
{!! $errors->first('asset_eol_date', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||
|
|
Loading…
Reference in a new issue