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 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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -11,6 +11,7 @@ return [
|
|||
'admin' => 'Admin',
|
||||
'administrator' => 'Administrator',
|
||||
'add_seats' => 'Added seats',
|
||||
'age' => "Age",
|
||||
'all_assets' => 'All Assets',
|
||||
'all' => 'All',
|
||||
'archived' => 'Archived',
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue