mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge pull request #12181 from Godmartinz/gh12163_asset_age
Adds asset age to asset index and asset view pages
This commit is contained in:
commit
c432fb9d70
|
@ -12,6 +12,7 @@ use App\Models\Statuslabel;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Image;
|
use Image;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class Helper
|
class Helper
|
||||||
{
|
{
|
||||||
|
@ -1125,5 +1126,25 @@ class Helper
|
||||||
|
|
||||||
return $settings;
|
return $settings;
|
||||||
}
|
}
|
||||||
|
public static function AgeFormat($date) {
|
||||||
|
$year = Carbon::parse($date)
|
||||||
|
->diff(now())->y;
|
||||||
|
$month = Carbon::parse($date)
|
||||||
|
->diff(now())->m;
|
||||||
|
$days = Carbon::parse($date)
|
||||||
|
->diff(now())->d;
|
||||||
|
$age='';
|
||||||
|
if ($year) {
|
||||||
|
$age .= $year.'y ';
|
||||||
|
}
|
||||||
|
if ($month) {
|
||||||
|
$age .= $month.'m ';
|
||||||
|
}
|
||||||
|
if ($days) {
|
||||||
|
$age .= $days.'d';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $age;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ use App\Models\Setting;
|
||||||
use Gate;
|
use Gate;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
||||||
|
|
||||||
class AssetsTransformer
|
class AssetsTransformer
|
||||||
{
|
{
|
||||||
public function transformAssets(Collection $assets, $total)
|
public function transformAssets(Collection $assets, $total)
|
||||||
|
@ -80,6 +81,7 @@ class AssetsTransformer
|
||||||
'next_audit_date' => Helper::getFormattedDateObject($asset->next_audit_date, 'date'),
|
'next_audit_date' => Helper::getFormattedDateObject($asset->next_audit_date, 'date'),
|
||||||
'deleted_at' => Helper::getFormattedDateObject($asset->deleted_at, 'datetime'),
|
'deleted_at' => Helper::getFormattedDateObject($asset->deleted_at, 'datetime'),
|
||||||
'purchase_date' => Helper::getFormattedDateObject($asset->purchase_date, 'date'),
|
'purchase_date' => Helper::getFormattedDateObject($asset->purchase_date, 'date'),
|
||||||
|
'age' => $asset->purchase_date ? Helper::AgeFormat($asset->purchase_date) : '',
|
||||||
'last_checkout' => Helper::getFormattedDateObject($asset->last_checkout, 'datetime'),
|
'last_checkout' => Helper::getFormattedDateObject($asset->last_checkout, 'datetime'),
|
||||||
'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'),
|
'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'),
|
||||||
'purchase_cost' => Helper::formatCurrencyOutput($asset->purchase_cost),
|
'purchase_cost' => Helper::formatCurrencyOutput($asset->purchase_cost),
|
||||||
|
|
|
@ -140,6 +140,12 @@ class AssetPresenter extends Presenter
|
||||||
'visible' => false,
|
'visible' => false,
|
||||||
'title' => trans('general.purchase_date'),
|
'title' => trans('general.purchase_date'),
|
||||||
'formatter' => 'dateDisplayFormatter',
|
'formatter' => 'dateDisplayFormatter',
|
||||||
|
], [
|
||||||
|
'field' => 'age',
|
||||||
|
'searchable' => true,
|
||||||
|
'sortable' => true,
|
||||||
|
'visible' => false,
|
||||||
|
'title' => trans('general.age'),
|
||||||
], [
|
], [
|
||||||
'field' => 'purchase_cost',
|
'field' => 'purchase_cost',
|
||||||
'searchable' => true,
|
'searchable' => true,
|
||||||
|
|
|
@ -11,6 +11,7 @@ return [
|
||||||
'admin' => 'Admin',
|
'admin' => 'Admin',
|
||||||
'administrator' => 'Administrator',
|
'administrator' => 'Administrator',
|
||||||
'add_seats' => 'Added seats',
|
'add_seats' => 'Added seats',
|
||||||
|
'age' => "Age",
|
||||||
'all_assets' => 'All Assets',
|
'all_assets' => 'All Assets',
|
||||||
'all' => 'All',
|
'all' => 'All',
|
||||||
'archived' => 'Archived',
|
'archived' => 'Archived',
|
||||||
|
|
|
@ -495,6 +495,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
{{ Helper::getFormattedDateObject($asset->purchase_date, 'date', false) }}
|
{{ Helper::getFormattedDateObject($asset->purchase_date, 'date', false) }}
|
||||||
|
-
|
||||||
|
{{ Carbon::parse($asset->purchase_date)->diff(Carbon::now())->format('%y years, %m months and %d days')}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
Loading…
Reference in a new issue