Merge pull request #12181 from Godmartinz/gh12163_asset_age

Adds asset age to asset index and asset view pages
This commit is contained in:
snipe 2022-12-13 10:28:17 -08:00 committed by GitHub
commit c432fb9d70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 0 deletions

View file

@ -12,6 +12,7 @@ use App\Models\Statuslabel;
use Crypt;
use Illuminate\Contracts\Encryption\DecryptException;
use Image;
use Carbon\Carbon;
class Helper
{
@ -1125,5 +1126,25 @@ class Helper
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;
}
}

View file

@ -8,6 +8,7 @@ use App\Models\Setting;
use Gate;
use Illuminate\Database\Eloquent\Collection;
class AssetsTransformer
{
public function transformAssets(Collection $assets, $total)
@ -80,6 +81,7 @@ class AssetsTransformer
'next_audit_date' => Helper::getFormattedDateObject($asset->next_audit_date, 'date'),
'deleted_at' => Helper::getFormattedDateObject($asset->deleted_at, 'datetime'),
'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'),
'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'),
'purchase_cost' => Helper::formatCurrencyOutput($asset->purchase_cost),

View file

@ -140,6 +140,12 @@ class AssetPresenter extends Presenter
'visible' => false,
'title' => trans('general.purchase_date'),
'formatter' => 'dateDisplayFormatter',
], [
'field' => 'age',
'searchable' => true,
'sortable' => true,
'visible' => false,
'title' => trans('general.age'),
], [
'field' => 'purchase_cost',
'searchable' => true,

View file

@ -11,6 +11,7 @@ return [
'admin' => 'Admin',
'administrator' => 'Administrator',
'add_seats' => 'Added seats',
'age' => "Age",
'all_assets' => 'All Assets',
'all' => 'All',
'archived' => 'Archived',

View file

@ -495,6 +495,9 @@
</div>
<div class="col-md-6">
{{ 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>
@endif