From 6f908934094aa586a7f961056e17f3b5b3ec480a Mon Sep 17 00:00:00 2001 From: Matthew Myers Date: Wed, 10 Jan 2024 11:54:46 -0500 Subject: [PATCH 1/8] Asset device age. --- .../src/Filament/Resources/AssetResource.php | 21 ++++++++++++++++--- .../AssetResource/Pages/CreateAsset.php | 19 ++++++++++++++++- .../AssetResource/Pages/ListAssets.php | 18 ++++++++++++++-- .../AssetResource/Pages/ViewAsset.php | 16 +++++++++++++- .../inventory-management/src/Models/Asset.php | 4 ++++ 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php index d5337bb3b3..83144850d2 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php @@ -36,7 +36,10 @@ namespace AdvisingApp\InventoryManagement\Filament\Resources; +use App\Models\User; use Filament\Forms\Form; +use Carbon\CarbonInterface; +use Illuminate\Support\Carbon; use Filament\Resources\Resource; use Filament\Resources\Pages\Page; use Filament\Forms\Components\Select; @@ -68,8 +71,6 @@ class AssetResource extends Resource protected static ?string $breadcrumb = 'Asset Management'; - protected static bool $shouldRegisterNavigation = false; - public function getTitle(): string | Htmlable { return 'Manage Assets'; @@ -112,7 +113,21 @@ public static function form(Form $form): Form ->required() ->exists((new AssetLocation())->getTable(), 'id'), DatePicker::make('purchase_date') - ->required(), + ->required() + ->live() + ->helperText(function (?string $state) { + if (blank($state)) { + return null; + } + + /** @var User $user */ + $user = auth()->user(); + + return str(Carbon::parse($state) + ->setTimezone($user->timezone) + ->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2)) + ->headline(); + }), ]); } diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php index d983e03637..7a8eebca87 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php @@ -36,7 +36,10 @@ namespace AdvisingApp\InventoryManagement\Filament\Resources\AssetResource\Pages; +use App\Models\User; use Filament\Forms\Form; +use Carbon\CarbonInterface; +use Illuminate\Support\Carbon; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; @@ -80,7 +83,21 @@ public function form(Form $form): Form ->required() ->exists((new AssetLocation())->getTable(), 'id'), DatePicker::make('purchase_date') - ->required(), + ->required() + ->live() + ->helperText(function (?string $state) { + if (blank($state)) { + return null; + } + + /** @var User $user */ + $user = auth()->user(); + + return str(Carbon::parse($state) + ->setTimezone($user->timezone) + ->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2)) + ->headline(); + }), ]); } } diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php index 21e20ad78e..427c790340 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php @@ -36,7 +36,10 @@ namespace AdvisingApp\InventoryManagement\Filament\Resources\AssetResource\Pages; +use App\Models\User; use Filament\Tables\Table; +use Carbon\CarbonInterface; +use Illuminate\Support\Carbon; use Filament\Actions\CreateAction; use Filament\Tables\Actions\EditAction; use Filament\Resources\Pages\ListRecords; @@ -45,6 +48,7 @@ use Filament\Tables\Actions\BulkActionGroup; use Filament\Tables\Actions\DeleteBulkAction; use App\Filament\Columns\OpenSearch\TextColumn; +use AdvisingApp\InventoryManagement\Models\Asset; use AdvisingApp\InventoryManagement\Filament\Resources\AssetResource; class ListAssets extends ListRecords @@ -65,8 +69,18 @@ public function table(Table $table): Table TextColumn::make('status.name'), TextColumn::make('location.name'), TextColumn::make('purchase_date') - ->searchable() - ->sortable(), + ->label('Device Age') + ->sortable() + ->formatStateUsing(function (string $state) { + /** @var User $user */ + $user = auth()->user(); + + return str(Carbon::parse($state) + ->setTimezone($user->timezone) + ->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2)) + ->headline(); + }) + ->tooltip(fn (Asset $record) => $record->purchase_date->format('M j, Y')), ]) ->filters([ SelectFilter::make('type') diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php index db278be7fb..045797eede 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php @@ -36,6 +36,9 @@ namespace AdvisingApp\InventoryManagement\Filament\Resources\AssetResource\Pages; +use App\Models\User; +use Carbon\CarbonInterface; +use Illuminate\Support\Carbon; use Filament\Actions\EditAction; use Filament\Infolists\Infolist; use Filament\Resources\Pages\ViewRecord; @@ -65,7 +68,18 @@ public function infolist(Infolist $infolist): Infolist ->label('Location'), TextEntry::make('status.name') ->label('Status'), - TextEntry::make('purchase_date'), + TextEntry::make('purchase_date') + ->label('Device Age') + ->formatStateUsing(function (string $state) { + /** @var User $user */ + $user = auth()->user(); + + return str(Carbon::parse($state) + ->setTimezone($user->timezone) + ->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2)) + ->headline(); + }) + ->helperText(fn (Asset $record) => $record->purchase_date->format('M j, Y')), ]), ]); } diff --git a/app-modules/inventory-management/src/Models/Asset.php b/app-modules/inventory-management/src/Models/Asset.php index d2723972ea..3eae5830f3 100644 --- a/app-modules/inventory-management/src/Models/Asset.php +++ b/app-modules/inventory-management/src/Models/Asset.php @@ -63,6 +63,10 @@ class Asset extends BaseModel implements Auditable 'type_id', ]; + protected $casts = [ + 'purchase_date' => 'datetime', + ]; + public function type(): BelongsTo { return $this->belongsTo(AssetType::class, 'type_id'); From f3ee3406783777edf55c33bb0044bf060da3fdb0 Mon Sep 17 00:00:00 2001 From: Matthew Myers Date: Wed, 10 Jan 2024 12:13:40 -0500 Subject: [PATCH 2/8] Switch to manual diffing. --- .../src/Filament/Resources/AssetResource.php | 16 ++++++++++++---- .../AssetResource/Pages/CreateAsset.php | 16 ++++++++++++---- .../Resources/AssetResource/Pages/ListAssets.php | 16 ++++++++++++---- .../Resources/AssetResource/Pages/ViewAsset.php | 16 ++++++++++++---- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php index 83144850d2..94fa7357b3 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php @@ -38,7 +38,6 @@ use App\Models\User; use Filament\Forms\Form; -use Carbon\CarbonInterface; use Illuminate\Support\Carbon; use Filament\Resources\Resource; use Filament\Resources\Pages\Page; @@ -120,13 +119,22 @@ public static function form(Form $form): Form return null; } + $date = Carbon::parse($state); + + if ($date->isFuture()) { + return '0 Years 0 Months'; + } + /** @var User $user */ $user = auth()->user(); - return str(Carbon::parse($state) + $diff = $date + ->roundMonth() ->setTimezone($user->timezone) - ->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2)) - ->headline(); + ->diff(); + + return $diff->y . ' ' . ($diff->y == 1 ? 'Year' : 'Years') . ' ' . + $diff->m . ' ' . ($diff->m == 1 ? 'Month' : 'Months'); }), ]); } diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php index 7a8eebca87..ce3726db39 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php @@ -38,7 +38,6 @@ use App\Models\User; use Filament\Forms\Form; -use Carbon\CarbonInterface; use Illuminate\Support\Carbon; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; @@ -90,13 +89,22 @@ public function form(Form $form): Form return null; } + $date = Carbon::parse($state); + + if ($date->isFuture()) { + return '0 Years 0 Months'; + } + /** @var User $user */ $user = auth()->user(); - return str(Carbon::parse($state) + $diff = $date + ->roundMonth() ->setTimezone($user->timezone) - ->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2)) - ->headline(); + ->diff(); + + return $diff->y . ' ' . ($diff->y == 1 ? 'Year' : 'Years') . ' ' . + $diff->m . ' ' . ($diff->m == 1 ? 'Month' : 'Months'); }), ]); } diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php index 427c790340..3607a05211 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php @@ -38,7 +38,6 @@ use App\Models\User; use Filament\Tables\Table; -use Carbon\CarbonInterface; use Illuminate\Support\Carbon; use Filament\Actions\CreateAction; use Filament\Tables\Actions\EditAction; @@ -72,13 +71,22 @@ public function table(Table $table): Table ->label('Device Age') ->sortable() ->formatStateUsing(function (string $state) { + $date = Carbon::parse($state); + + if ($date->isFuture()) { + return '0 Years 0 Months'; + } + /** @var User $user */ $user = auth()->user(); - return str(Carbon::parse($state) + $diff = $date + ->roundMonth() ->setTimezone($user->timezone) - ->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2)) - ->headline(); + ->diff(); + + return $diff->y . ' ' . ($diff->y == 1 ? 'Year' : 'Years') . ' ' . + $diff->m . ' ' . ($diff->m == 1 ? 'Month' : 'Months'); }) ->tooltip(fn (Asset $record) => $record->purchase_date->format('M j, Y')), ]) diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php index 045797eede..e48854505b 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php @@ -37,7 +37,6 @@ namespace AdvisingApp\InventoryManagement\Filament\Resources\AssetResource\Pages; use App\Models\User; -use Carbon\CarbonInterface; use Illuminate\Support\Carbon; use Filament\Actions\EditAction; use Filament\Infolists\Infolist; @@ -71,13 +70,22 @@ public function infolist(Infolist $infolist): Infolist TextEntry::make('purchase_date') ->label('Device Age') ->formatStateUsing(function (string $state) { + $date = Carbon::parse($state); + + if ($date->isFuture()) { + return '0 Years 0 Months'; + } + /** @var User $user */ $user = auth()->user(); - return str(Carbon::parse($state) + $diff = $date + ->roundMonth() ->setTimezone($user->timezone) - ->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, parts: 2)) - ->headline(); + ->diff(); + + return $diff->y . ' ' . ($diff->y == 1 ? 'Year' : 'Years') . ' ' . + $diff->m . ' ' . ($diff->m == 1 ? 'Month' : 'Months'); }) ->helperText(fn (Asset $record) => $record->purchase_date->format('M j, Y')), ]), From 4b8703d7d9df1d74d0e15a9d04eaa7e55d2488b6 Mon Sep 17 00:00:00 2001 From: Matthew Myers Date: Wed, 10 Jan 2024 12:16:39 -0500 Subject: [PATCH 3/8] Strict. --- .../src/Filament/Resources/AssetResource.php | 4 ++-- .../Filament/Resources/AssetResource/Pages/CreateAsset.php | 4 ++-- .../Filament/Resources/AssetResource/Pages/ListAssets.php | 4 ++-- .../Filament/Resources/AssetResource/Pages/ViewAsset.php | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php index 94fa7357b3..65b7570f22 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php @@ -133,8 +133,8 @@ public static function form(Form $form): Form ->setTimezone($user->timezone) ->diff(); - return $diff->y . ' ' . ($diff->y == 1 ? 'Year' : 'Years') . ' ' . - $diff->m . ' ' . ($diff->m == 1 ? 'Month' : 'Months'); + return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' . + $diff->m . ' ' . ($diff->m === 1 ? 'Month' : 'Months'); }), ]); } diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php index ce3726db39..bfa81f3f67 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php @@ -103,8 +103,8 @@ public function form(Form $form): Form ->setTimezone($user->timezone) ->diff(); - return $diff->y . ' ' . ($diff->y == 1 ? 'Year' : 'Years') . ' ' . - $diff->m . ' ' . ($diff->m == 1 ? 'Month' : 'Months'); + return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' . + $diff->m . ' ' . ($diff->m === 1 ? 'Month' : 'Months'); }), ]); } diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php index 3607a05211..ad1268fd18 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php @@ -85,8 +85,8 @@ public function table(Table $table): Table ->setTimezone($user->timezone) ->diff(); - return $diff->y . ' ' . ($diff->y == 1 ? 'Year' : 'Years') . ' ' . - $diff->m . ' ' . ($diff->m == 1 ? 'Month' : 'Months'); + return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' . + $diff->m . ' ' . ($diff->m === 1 ? 'Month' : 'Months'); }) ->tooltip(fn (Asset $record) => $record->purchase_date->format('M j, Y')), ]) diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php index e48854505b..e64d9fcaf4 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php @@ -67,7 +67,7 @@ public function infolist(Infolist $infolist): Infolist ->label('Location'), TextEntry::make('status.name') ->label('Status'), - TextEntry::make('purchase_date') + TextEntry::make('purchase_date') //Strict ->label('Device Age') ->formatStateUsing(function (string $state) { $date = Carbon::parse($state); @@ -84,8 +84,8 @@ public function infolist(Infolist $infolist): Infolist ->setTimezone($user->timezone) ->diff(); - return $diff->y . ' ' . ($diff->y == 1 ? 'Year' : 'Years') . ' ' . - $diff->m . ' ' . ($diff->m == 1 ? 'Month' : 'Months'); + return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' . + $diff->m . ' ' . ($diff->m === 1 ? 'Month' : 'Months'); }) ->helperText(fn (Asset $record) => $record->purchase_date->format('M j, Y')), ]), From 3a3afc49512a7bc07085558b2b5d488e17f97185 Mon Sep 17 00:00:00 2001 From: Matthew Myers Date: Thu, 11 Jan 2024 11:20:03 -0500 Subject: [PATCH 4/8] Feedback. --- .../src/Filament/Resources/AssetResource.php | 19 +++------------ .../AssetResource/Pages/CreateAsset.php | 23 ++++++------------ .../AssetResource/Pages/ListAssets.php | 22 ++--------------- .../AssetResource/Pages/ViewAsset.php | 20 +--------------- .../inventory-management/src/Models/Asset.php | 24 +++++++++++++++++++ 5 files changed, 37 insertions(+), 71 deletions(-) diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php index 1f5d78fb24..fc1590c2ab 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php @@ -120,22 +120,9 @@ public static function form(Form $form): Form return null; } - $date = Carbon::parse($state); - - if ($date->isFuture()) { - return '0 Years 0 Months'; - } - - /** @var User $user */ - $user = auth()->user(); - - $diff = $date - ->roundMonth() - ->setTimezone($user->timezone) - ->diff(); - - return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' . - $diff->m . ' ' . ($diff->m === 1 ? 'Month' : 'Months'); + return (new Asset([ + 'purchase_date' => Carbon::parse($state), + ]))->purchase_age; }), ]); } diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php index bfa81f3f67..5b897f25c6 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/CreateAsset.php @@ -36,7 +36,6 @@ namespace AdvisingApp\InventoryManagement\Filament\Resources\AssetResource\Pages; -use App\Models\User; use Filament\Forms\Form; use Illuminate\Support\Carbon; use Filament\Forms\Components\Select; @@ -44,6 +43,7 @@ use Filament\Forms\Components\TextInput; use Filament\Forms\Components\DatePicker; use Filament\Resources\Pages\CreateRecord; +use AdvisingApp\InventoryManagement\Models\Asset; use AdvisingApp\InventoryManagement\Models\AssetType; use AdvisingApp\InventoryManagement\Models\AssetStatus; use AdvisingApp\InventoryManagement\Models\AssetLocation; @@ -84,27 +84,18 @@ public function form(Form $form): Form DatePicker::make('purchase_date') ->required() ->live() - ->helperText(function (?string $state) { + ->helperText(function (?string $state, ?Asset $record) { if (blank($state)) { return null; } - $date = Carbon::parse($state); - - if ($date->isFuture()) { - return '0 Years 0 Months'; + if ($record) { + return $record->purchase_age; } - /** @var User $user */ - $user = auth()->user(); - - $diff = $date - ->roundMonth() - ->setTimezone($user->timezone) - ->diff(); - - return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' . - $diff->m . ' ' . ($diff->m === 1 ? 'Month' : 'Months'); + return (new Asset([ + 'purchase_date' => Carbon::parse($state), + ]))->purchase_age; }), ]); } diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php index ad1268fd18..832b799f36 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php @@ -67,27 +67,9 @@ public function table(Table $table): Table TextColumn::make('type.name'), TextColumn::make('status.name'), TextColumn::make('location.name'), - TextColumn::make('purchase_date') + TextColumn::make('purchase_age') ->label('Device Age') - ->sortable() - ->formatStateUsing(function (string $state) { - $date = Carbon::parse($state); - - if ($date->isFuture()) { - return '0 Years 0 Months'; - } - - /** @var User $user */ - $user = auth()->user(); - - $diff = $date - ->roundMonth() - ->setTimezone($user->timezone) - ->diff(); - - return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' . - $diff->m . ' ' . ($diff->m === 1 ? 'Month' : 'Months'); - }) + ->sortable(['purchase_date']) ->tooltip(fn (Asset $record) => $record->purchase_date->format('M j, Y')), ]) ->filters([ diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php index 1b5c8aa36f..b4874a38bc 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php @@ -67,26 +67,8 @@ public function infolist(Infolist $infolist): Infolist ->label('Location'), TextEntry::make('status.name') ->label('Status'), - TextEntry::make('purchase_date') //Strict + TextEntry::make('purchase_age') ->label('Device Age') - ->formatStateUsing(function (string $state) { - $date = Carbon::parse($state); - - if ($date->isFuture()) { - return '0 Years 0 Months'; - } - - /** @var User $user */ - $user = auth()->user(); - - $diff = $date - ->roundMonth() - ->setTimezone($user->timezone) - ->diff(); - - return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' . - $diff->m . ' ' . ($diff->m === 1 ? 'Month' : 'Months'); - }) ->helperText(fn (Asset $record) => $record->purchase_date->format('M j, Y')), ]), ]); diff --git a/app-modules/inventory-management/src/Models/Asset.php b/app-modules/inventory-management/src/Models/Asset.php index 05132d18b7..0788e418ef 100644 --- a/app-modules/inventory-management/src/Models/Asset.php +++ b/app-modules/inventory-management/src/Models/Asset.php @@ -37,6 +37,9 @@ namespace AdvisingApp\InventoryManagement\Models; use App\Models\BaseModel; +use App\Models\User; +use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Support\Carbon; use OwenIt\Auditing\Contracts\Auditable; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\HasOne; @@ -125,4 +128,25 @@ public function isCheckedOut(): bool return $this->status->classification === SystemAssetStatusClassification::CheckedOut && is_null($this->latestCheckOut?->asset_check_in_id); } + + protected function purchaseAge(): Attribute + { + return Attribute::get(function () { + if ($this->purchase_date->isFuture()) { + return '0 Years 0 Months'; + } + + /** @var User $user */ + $user = auth()->user(); + + $diff = $this + ->purchase_date + ->roundMonth() + ->setTimezone($user->timezone) + ->diff(); + + return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' . + $diff->m . ' ' . ($diff->m === 1 ? 'Month' : 'Months'); + }); + } } From 8554599fd123dedea553794e66413300fc0efcdf Mon Sep 17 00:00:00 2001 From: Matthew Myers Date: Thu, 11 Jan 2024 11:22:33 -0500 Subject: [PATCH 5/8] Format. --- .../src/Filament/Resources/AssetResource.php | 1 - .../Filament/Resources/AssetResource/Pages/ListAssets.php | 2 -- .../src/Filament/Resources/AssetResource/Pages/ViewAsset.php | 2 -- app-modules/inventory-management/src/Models/Asset.php | 5 ++--- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php index fc1590c2ab..4772859af4 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource.php @@ -36,7 +36,6 @@ namespace AdvisingApp\InventoryManagement\Filament\Resources; -use App\Models\User; use Filament\Forms\Form; use Illuminate\Support\Carbon; use Filament\Resources\Resource; diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php index 832b799f36..04328b49e7 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ListAssets.php @@ -36,9 +36,7 @@ namespace AdvisingApp\InventoryManagement\Filament\Resources\AssetResource\Pages; -use App\Models\User; use Filament\Tables\Table; -use Illuminate\Support\Carbon; use Filament\Actions\CreateAction; use Filament\Tables\Actions\EditAction; use Filament\Resources\Pages\ListRecords; diff --git a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php index b4874a38bc..f11b2d4b87 100644 --- a/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php +++ b/app-modules/inventory-management/src/Filament/Resources/AssetResource/Pages/ViewAsset.php @@ -36,8 +36,6 @@ namespace AdvisingApp\InventoryManagement\Filament\Resources\AssetResource\Pages; -use App\Models\User; -use Illuminate\Support\Carbon; use Filament\Actions\EditAction; use Filament\Infolists\Infolist; use Filament\Resources\Pages\ViewRecord; diff --git a/app-modules/inventory-management/src/Models/Asset.php b/app-modules/inventory-management/src/Models/Asset.php index 0788e418ef..72f54dc8c1 100644 --- a/app-modules/inventory-management/src/Models/Asset.php +++ b/app-modules/inventory-management/src/Models/Asset.php @@ -36,12 +36,11 @@ namespace AdvisingApp\InventoryManagement\Models; -use App\Models\BaseModel; use App\Models\User; -use Illuminate\Database\Eloquent\Casts\Attribute; -use Illuminate\Support\Carbon; +use App\Models\BaseModel; use OwenIt\Auditing\Contracts\Auditable; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; From 4a1913cc9a7172e5fca18576b259c4103bce3add Mon Sep 17 00:00:00 2001 From: Matthew Myers Date: Thu, 11 Jan 2024 11:29:26 -0500 Subject: [PATCH 6/8] Regen helpers. --- _ide_helper_models.php | 44 +++---------------- .../inventory-management/src/Models/Asset.php | 2 + 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/_ide_helper_models.php b/_ide_helper_models.php index 5f39c168fe..9e16f5ac61 100644 --- a/_ide_helper_models.php +++ b/_ide_helper_models.php @@ -1,39 +1,5 @@ - - Copyright © 2022-2023, Canyon GBS LLC. All rights reserved. - - Advising App™ is licensed under the Elastic License 2.0. For more details, - see https://github.com/canyongbs/advisingapp/blob/main/LICENSE. - - Notice: - - - You may not provide the software to third parties as a hosted or managed - service, where the service provides users with access to any substantial set of - the features or functionality of the software. - - You may not move, change, disable, or circumvent the license key functionality - in the software, and you may not remove or obscure any functionality in the - software that is protected by the license key. - - You may not alter, remove, or obscure any licensing, copyright, or other notices - of the licensor in the software. Any use of the licensor’s trademarks is subject - to applicable law. - - Canyon GBS LLC respects the intellectual property rights of others and expects the - same in return. Canyon GBS™ and Advising App™ are registered trademarks of - Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks - vigorously. - - The software solution, including services, infrastructure, and code, is offered as a - Software as a Service (SaaS) by Canyon GBS LLC. - - Use of this software implies agreement to the license terms and conditions as stated - in the Elastic License 2.0. - - For more information or inquiries please visit our website at - https://www.canyongbs.com or contact us via email at legal@canyongbs.com. - - -*/ - // @formatter:off /** * A helper file for your Eloquent Models @@ -2133,6 +2099,7 @@ class IdeHelperInteractionType {} /** * AdvisingApp\InventoryManagement\Models\Asset * + * @property string $purchase_age * @property string $id * @property string $serial_number * @property string $name @@ -2140,7 +2107,7 @@ class IdeHelperInteractionType {} * @property string $type_id * @property string $status_id * @property string $location_id - * @property string $purchase_date + * @property \Illuminate\Support\Carbon $purchase_date * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Support\Carbon|null $deleted_at @@ -2320,8 +2287,6 @@ class IdeHelperAssetLocation {} * @property-read int|null $assets_count * @property-read \Illuminate\Database\Eloquent\Collection $audits * @property-read int|null $audits_count - * @method static \Illuminate\Database\Eloquent\Builder|AssetStatus available() - * @method static \Illuminate\Database\Eloquent\Builder|AssetStatus checkedOut() * @method static \AdvisingApp\InventoryManagement\Database\Factories\AssetStatusFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|AssetStatus newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|AssetStatus newQuery() @@ -2710,6 +2675,7 @@ class IdeHelperEvent {} * @property-read int|null $students_count * @property-read \Illuminate\Database\Eloquent\Collection $submissions * @property-read int|null $submissions_count + * @method static \AdvisingApp\MeetingCenter\Database\Factories\EventAttendeeFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|EventAttendee newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|EventAttendee newQuery() * @method static \Illuminate\Database\Eloquent\Builder|EventAttendee query() @@ -2748,6 +2714,7 @@ class IdeHelperEventAttendee {} * @property-read int|null $steps_count * @property-read \Illuminate\Database\Eloquent\Collection $submissions * @property-read int|null $submissions_count + * @method static \AdvisingApp\MeetingCenter\Database\Factories\EventRegistrationFormFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationForm newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationForm newQuery() * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationForm onlyTrashed() @@ -2814,6 +2781,7 @@ class IdeHelperEventRegistrationFormAuthentication {} * @property \Illuminate\Support\Carbon|null $updated_at * @property-read \AdvisingApp\MeetingCenter\Models\EventRegistrationFormStep|null $step * @property-read \AdvisingApp\MeetingCenter\Models\EventRegistrationForm $submissible + * @method static \AdvisingApp\MeetingCenter\Database\Factories\EventRegistrationFormFieldFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationFormField newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationFormField newQuery() * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationFormField query() @@ -2846,6 +2814,7 @@ class IdeHelperEventRegistrationFormField {} * @property-read \Illuminate\Database\Eloquent\Collection $fields * @property-read int|null $fields_count * @property-read \AdvisingApp\MeetingCenter\Models\EventRegistrationForm $submissible + * @method static \AdvisingApp\MeetingCenter\Database\Factories\EventRegistrationFormStepFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationFormStep newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationFormStep newQuery() * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationFormStep query() @@ -2880,6 +2849,7 @@ class IdeHelperEventRegistrationFormStep {} * @property-read int|null $fields_count * @property-read \App\Models\User $requester * @property-read \AdvisingApp\MeetingCenter\Models\EventRegistrationForm $submissible + * @method static \AdvisingApp\MeetingCenter\Database\Factories\EventRegistrationFormSubmissionFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|Submission licensedToEducatable(string $relationship) * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationFormSubmission newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|EventRegistrationFormSubmission newQuery() diff --git a/app-modules/inventory-management/src/Models/Asset.php b/app-modules/inventory-management/src/Models/Asset.php index 72f54dc8c1..22a9ff35bb 100644 --- a/app-modules/inventory-management/src/Models/Asset.php +++ b/app-modules/inventory-management/src/Models/Asset.php @@ -48,6 +48,8 @@ use AdvisingApp\InventoryManagement\Enums\SystemAssetStatusClassification; /** + * @property string $purchase_age + * * @mixin IdeHelperAsset */ class Asset extends BaseModel implements Auditable From c82cbd1c9bbb52f573820d3042e1b7bf1b2b125c Mon Sep 17 00:00:00 2001 From: mxm1070 Date: Thu, 11 Jan 2024 16:31:02 +0000 Subject: [PATCH 7/8] chore: fix enforcement of copyright on all files --- _ide_helper_models.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/_ide_helper_models.php b/_ide_helper_models.php index 9e16f5ac61..0b9764e53a 100644 --- a/_ide_helper_models.php +++ b/_ide_helper_models.php @@ -1,5 +1,39 @@ + + Copyright © 2022-2023, Canyon GBS LLC. All rights reserved. + + Advising App™ is licensed under the Elastic License 2.0. For more details, + see https://github.com/canyongbs/advisingapp/blob/main/LICENSE. + + Notice: + + - You may not provide the software to third parties as a hosted or managed + service, where the service provides users with access to any substantial set of + the features or functionality of the software. + - You may not move, change, disable, or circumvent the license key functionality + in the software, and you may not remove or obscure any functionality in the + software that is protected by the license key. + - You may not alter, remove, or obscure any licensing, copyright, or other notices + of the licensor in the software. Any use of the licensor’s trademarks is subject + to applicable law. + - Canyon GBS LLC respects the intellectual property rights of others and expects the + same in return. Canyon GBS™ and Advising App™ are registered trademarks of + Canyon GBS LLC, and we are committed to enforcing and protecting our trademarks + vigorously. + - The software solution, including services, infrastructure, and code, is offered as a + Software as a Service (SaaS) by Canyon GBS LLC. + - Use of this software implies agreement to the license terms and conditions as stated + in the Elastic License 2.0. + + For more information or inquiries please visit our website at + https://www.canyongbs.com or contact us via email at legal@canyongbs.com. + + +*/ + // @formatter:off /** * A helper file for your Eloquent Models From 54d562a416cb1dc4249ff632f9a4627e635898c8 Mon Sep 17 00:00:00 2001 From: Matthew Myers Date: Thu, 11 Jan 2024 11:46:18 -0500 Subject: [PATCH 8/8] Fix timezone. --- app-modules/inventory-management/src/Models/Asset.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app-modules/inventory-management/src/Models/Asset.php b/app-modules/inventory-management/src/Models/Asset.php index 22a9ff35bb..293a51f129 100644 --- a/app-modules/inventory-management/src/Models/Asset.php +++ b/app-modules/inventory-management/src/Models/Asset.php @@ -48,7 +48,7 @@ use AdvisingApp\InventoryManagement\Enums\SystemAssetStatusClassification; /** - * @property string $purchase_age + * @property-read string $purchase_age * * @mixin IdeHelperAsset */ @@ -137,13 +137,13 @@ protected function purchaseAge(): Attribute return '0 Years 0 Months'; } - /** @var User $user */ + /** @var ?User $user */ $user = auth()->user(); $diff = $this ->purchase_date ->roundMonth() - ->setTimezone($user->timezone) + ->setTimezone($user?->timezone) ->diff(); return $diff->y . ' ' . ($diff->y === 1 ? 'Year' : 'Years') . ' ' .