-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Filament\Resources\ItemResource; | ||
use App\Filament\Resources\LocationResource; | ||
use App\Models\Item; | ||
use App\Models\Location; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\Layout\Stack; | ||
use Filament\Tables\Table; | ||
use Filament\Widgets\TableWidget as BaseWidget; | ||
|
||
class Locations extends BaseWidget | ||
{ | ||
protected int|string|array $columnSpan = 'full'; | ||
|
||
protected static ?int $sort = 3; | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->query(LocationResource::getEloquentQuery()->where('parent_id', null)) | ||
->defaultPaginationPageOption(15) | ||
->defaultSort('created_at', 'desc') | ||
->columns([ | ||
Stack::make([ | ||
Tables\Columns\TextColumn::make('name') | ||
->searchable()->sortable(), | ||
]) | ||
]) | ||
->contentGrid([ | ||
'md' => 2, | ||
'xl' => 3, | ||
]) | ||
->actions([ | ||
Tables\Actions\Action::make('open') | ||
->url(fn (Location $record): string => LocationResource::getUrl('edit', ['record' => $record])), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Filament\Resources\ItemResource; | ||
use App\Models\Item; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\CheckboxColumn; | ||
use Filament\Tables\Table; | ||
use Filament\Widgets\TableWidget as BaseWidget; | ||
|
||
class RecentlyAdded extends BaseWidget | ||
{ | ||
protected int|string|array $columnSpan = 'full'; | ||
|
||
protected static ?int $sort = 2; | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->query(ItemResource::getEloquentQuery()) | ||
->defaultPaginationPageOption(5) | ||
->defaultSort('created_at', 'desc') | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name') | ||
->searchable()->sortable(), | ||
Tables\Columns\TextColumn::make('quantity') | ||
->searchable() | ||
->sortable(), | ||
Tables\Columns\TextColumn::make('location.name') | ||
->searchable() | ||
->sortable(), | ||
Tables\Columns\TextColumn::make('purchase_price') | ||
->searchable() | ||
->sortable(), | ||
Tables\Columns\CheckboxColumn::make('insured'), | ||
]) | ||
->actions([ | ||
Tables\Actions\Action::make('open') | ||
->url(fn (Item $record): string => ItemResource::getUrl('edit', ['record' => $record])), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Models\Item; | ||
use App\Models\Location; | ||
use Carbon\Carbon; | ||
use Filament\Widgets\Concerns\InteractsWithPageFilters; | ||
use Filament\Widgets\StatsOverviewWidget as BaseWidget; | ||
use Filament\Widgets\StatsOverviewWidget\Stat; | ||
use Illuminate\Support\Number; | ||
|
||
class StatsOverviewWidget extends BaseWidget | ||
{ | ||
use InteractsWithPageFilters; | ||
|
||
protected static ?int $sort = 0; | ||
|
||
protected function getStats(): array | ||
{ | ||
|
||
$startDate = ! is_null($this->filters['startDate'] ?? null) ? | ||
Carbon::parse($this->filters['startDate']) : | ||
null; | ||
|
||
$endDate = ! is_null($this->filters['endDate'] ?? null) ? | ||
Carbon::parse($this->filters['endDate']) : | ||
now(); | ||
|
||
$isBusinessCustomersOnly = $this->filters['businessCustomersOnly'] ?? null; | ||
$businessCustomerMultiplier = match (true) { | ||
boolval($isBusinessCustomersOnly) => 2 / 3, | ||
blank($isBusinessCustomersOnly) => 1, | ||
default => 1 / 3, | ||
}; | ||
|
||
$diffInDays = $startDate ? $startDate->diffInDays($endDate) : 0; | ||
|
||
$revenue = (int) (($startDate ? ($diffInDays * 137) : 192100) * $businessCustomerMultiplier); | ||
$newCustomers = (int) (($startDate ? ($diffInDays * 7) : 1340) * $businessCustomerMultiplier); | ||
$newOrders = (int) (($startDate ? ($diffInDays * 13) : 3543) * $businessCustomerMultiplier); | ||
|
||
$formatNumber = function (int $number): string { | ||
if ($number < 1000) { | ||
return (string) Number::format($number, 0); | ||
} | ||
|
||
if ($number < 1000000) { | ||
return Number::format($number / 1000, 2).'k'; | ||
} | ||
|
||
return Number::format($number / 1000000, 2).'m'; | ||
}; | ||
|
||
$totalValue = Item::sum('purchase_price'); | ||
|
||
return [ | ||
Stat::make('Total Value', '$'.$formatNumber($totalValue)), | ||
Stat::make('Total Items', Item::count()) | ||
->description('10% increase') | ||
->descriptionIcon('heroicon-m-arrow-trending-up') | ||
->chart([7, 2, 10, 3, 15, 4, 17]) | ||
->color('success'), | ||
Stat::make('Total Locations', Location::count()) | ||
->description('3% decrease') | ||
->descriptionIcon('heroicon-m-arrow-trending-down') | ||
->chart([17, 16, 14, 15, 14, 13, 12]) | ||
->color('danger'), | ||
Stat::make('Total Labels', 5) | ||
->description('7% increase') | ||
->descriptionIcon('heroicon-m-arrow-trending-up') | ||
->chart([15, 4, 10, 2, 12, 4, 12]) | ||
->color('success'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters