feat: Remove Chicken model, related resources, and associated functionality
This commit is contained in:
parent
1e59711070
commit
97ba4f1de5
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enum\WithComment;
|
||||
use App\Traits\Enum\WithValue;
|
||||
use Filament\Support\Contracts\HasColor;
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
|
||||
enum ChickenStatus: int implements HasColor, HasLabel
|
||||
{
|
||||
use WithComment, WithValue;
|
||||
|
||||
case ACTIVE = 1;
|
||||
case DEAD = 2;
|
||||
case CULLED = 3;
|
||||
case SOLD = 4;
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return match ($this) {
|
||||
self::ACTIVE => 'Aktif',
|
||||
self::DEAD => 'Mati',
|
||||
self::CULLED => 'Dimusnahkan',
|
||||
self::SOLD => 'Dijual',
|
||||
};
|
||||
}
|
||||
|
||||
public function getColor(): string|array|null
|
||||
{
|
||||
return match ($this) {
|
||||
self::ACTIVE => 'success',
|
||||
self::DEAD => 'danger',
|
||||
self::CULLED => 'warning',
|
||||
self::SOLD => 'primary',
|
||||
};
|
||||
}
|
||||
|
||||
public static function options(): array
|
||||
{
|
||||
return collect(self::cases())
|
||||
->mapWithKeys(fn ($case) => [$case->value => $case->getLabel()])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@ -1,166 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Master\Chickens;
|
||||
|
||||
use App\Enums\ChickenStatus;
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Actions\Cheerful\DeleteAction;
|
||||
use App\Filament\Actions\Cheerful\EditAction;
|
||||
use App\Filament\Actions\Cheerful\ForceDeleteAction;
|
||||
use App\Filament\Actions\Cheerful\RestoreAction;
|
||||
use App\Filament\Actions\DefaultBulkActions;
|
||||
use App\Filament\Columns\TimestampColumns;
|
||||
use App\Filament\Resources\Master\Chickens\Pages\ManageChickens;
|
||||
use App\Models\Chicken;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use UnitEnum;
|
||||
|
||||
class ChickenResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Chicken::class;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Master';
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::RectangleGroup;
|
||||
|
||||
protected static ?string $navigationLabel = 'Ayam';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'tag_code';
|
||||
|
||||
protected static ?string $slug = 'master/chickens';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('tag_code')
|
||||
->label('Kode Tag')
|
||||
->placeholder('...')
|
||||
->autocomplete(false)
|
||||
->autofocus()
|
||||
->required()
|
||||
->maxLength(20)
|
||||
->unique(ignoreRecord: true),
|
||||
|
||||
DatePicker::make('hatch_date')
|
||||
->label('Tanggal Menetas')
|
||||
->placeholder('Pilih Tanggal')
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y'),
|
||||
|
||||
DatePicker::make('arrival_date')
|
||||
->label('Tanggal Tiba')
|
||||
->placeholder('Pilih Tanggal')
|
||||
->required()
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y'),
|
||||
|
||||
DatePicker::make('exit_date')
|
||||
->label('Tanggal Keluar/Afkir')
|
||||
->placeholder('Pilih Tanggal')
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y'),
|
||||
|
||||
Select::make('status')
|
||||
->label('Status')
|
||||
->options(ChickenStatus::class)
|
||||
->required()
|
||||
->native(false)
|
||||
->default(ChickenStatus::ACTIVE),
|
||||
])
|
||||
->columns(1);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('tag_code')
|
||||
->label('Kode Tag')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('hatch_date')
|
||||
->label('Tanggal Menetas')
|
||||
->date('l, d F Y')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('arrival_date')
|
||||
->label('Tanggal Tiba')
|
||||
->date('l, d F Y')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('exit_date')
|
||||
->label('Tanggal Keluar')
|
||||
->date('l, d F Y')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->sortable(),
|
||||
|
||||
...TimestampColumns::make(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
->label('Status')
|
||||
->options(ChickenStatus::class)
|
||||
->native(false),
|
||||
|
||||
TrashedFilter::make()
|
||||
->native(false)
|
||||
->visible(fn (): bool => auth()->user()->hasRole(RoleEnum::DEVELOPER)),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()
|
||||
->modalWidth(Width::Large),
|
||||
|
||||
DeleteAction::make(),
|
||||
|
||||
ForceDeleteAction::make(),
|
||||
|
||||
RestoreAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
...DefaultBulkActions::make('Ayam'),
|
||||
]),
|
||||
])
|
||||
->emptyStateIcon(Heroicon::RectangleGroup)
|
||||
->emptyStateDescription('Setelah Anda membuat data pertama, maka akan muncul disini.')
|
||||
->defaultSort('created_at', 'desc')
|
||||
->deferFilters(false);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ManageChickens::route('/'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getRecordRouteBindingEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Master\Chickens\Pages;
|
||||
|
||||
use App\Filament\Actions\Cheerful\CreateAction;
|
||||
use App\Filament\Resources\Master\Chickens\ChickenResource;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class ManageChickens extends ManageRecords
|
||||
{
|
||||
protected static string $resource = ChickenResource::class;
|
||||
|
||||
protected static ?string $title = 'Ayam';
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->label('Tambah')
|
||||
->modalHeading('Tambah Ayam')
|
||||
->modalSubmitActionLabel('Simpan')
|
||||
->modalCancelActionLabel('Batal')
|
||||
->extraModalFooterActions(fn (CreateAction $action): array => [
|
||||
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
|
||||
->label('Simpan dan Tambah Lagi'),
|
||||
])
|
||||
->modalWidth(Width::Large),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Enums\ChickenStatus;
|
||||
use App\Models\Chicken;
|
||||
use App\Models\Customer;
|
||||
use App\Models\DelayedGood;
|
||||
use App\Models\EggCollection;
|
||||
@ -23,11 +21,6 @@ class StatsOverview extends BaseWidget
|
||||
protected function getStats(): array
|
||||
{
|
||||
return [
|
||||
Stat::make('Total Ayam', Chicken::where('status', ChickenStatus::ACTIVE)->count())
|
||||
->description('Jumlah ayam dengan status aktif saat ini.')
|
||||
->descriptionIcon('heroicon-m-heart')
|
||||
->color('success'),
|
||||
|
||||
Stat::make('Produksi Telur', number_format(EggCollection::sum('total_eggs'), 0, ',', '.').' Butir')
|
||||
->description('Total telur yang terkumpul.')
|
||||
->descriptionIcon('heroicon-m-circle-stack')
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ChickenStatus;
|
||||
use App\Observers\ChickenObserver;
|
||||
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
#[ObservedBy([ChickenObserver::class])]
|
||||
class Chicken extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'hatch_date' => 'date',
|
||||
'arrival_date' => 'date',
|
||||
'exit_date' => 'date',
|
||||
'status' => ChickenStatus::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Chicken;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ChickenObserver
|
||||
{
|
||||
/**
|
||||
* Handle events after any change that should invalidate chicken cache.
|
||||
*/
|
||||
protected function clearChickenCache(): void
|
||||
{
|
||||
Cache::store('redis')->forget('active_chickens_for_egg_collection_form');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Chicken "created" event.
|
||||
*/
|
||||
public function created(Chicken $chicken): void
|
||||
{
|
||||
$this->clearChickenCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Chicken "updated" event.
|
||||
*/
|
||||
public function updated(Chicken $chicken): void
|
||||
{
|
||||
$this->clearChickenCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Chicken "deleted" event.
|
||||
*/
|
||||
public function deleted(Chicken $chicken): void
|
||||
{
|
||||
$this->clearChickenCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Chicken "restored" event.
|
||||
*/
|
||||
public function restored(Chicken $chicken): void
|
||||
{
|
||||
$this->clearChickenCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Chicken "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(Chicken $chicken): void
|
||||
{
|
||||
$this->clearChickenCache();
|
||||
}
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Chicken;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Foundation\Auth\User as AuthUser;
|
||||
|
||||
class ChickenPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function viewAny(AuthUser $authUser): bool
|
||||
{
|
||||
return $authUser->can('ViewAny:Chicken');
|
||||
}
|
||||
|
||||
public function view(AuthUser $authUser, Chicken $chicken): bool
|
||||
{
|
||||
return $authUser->can('View:Chicken');
|
||||
}
|
||||
|
||||
public function create(AuthUser $authUser): bool
|
||||
{
|
||||
return $authUser->can('Create:Chicken');
|
||||
}
|
||||
|
||||
public function update(AuthUser $authUser, Chicken $chicken): bool
|
||||
{
|
||||
return $authUser->can('Update:Chicken');
|
||||
}
|
||||
|
||||
public function delete(AuthUser $authUser, Chicken $chicken): bool
|
||||
{
|
||||
return $authUser->can('Delete:Chicken');
|
||||
}
|
||||
|
||||
public function restore(AuthUser $authUser, Chicken $chicken): bool
|
||||
{
|
||||
return $authUser->can('Restore:Chicken');
|
||||
}
|
||||
|
||||
public function forceDelete(AuthUser $authUser, Chicken $chicken): bool
|
||||
{
|
||||
return $authUser->can('ForceDelete:Chicken');
|
||||
}
|
||||
|
||||
public function forceDeleteAny(AuthUser $authUser): bool
|
||||
{
|
||||
return $authUser->can('ForceDeleteAny:Chicken');
|
||||
}
|
||||
|
||||
public function restoreAny(AuthUser $authUser): bool
|
||||
{
|
||||
return $authUser->can('RestoreAny:Chicken');
|
||||
}
|
||||
|
||||
public function replicate(AuthUser $authUser, Chicken $chicken): bool
|
||||
{
|
||||
return $authUser->can('Replicate:Chicken');
|
||||
}
|
||||
|
||||
public function reorder(AuthUser $authUser): bool
|
||||
{
|
||||
return $authUser->can('Reorder:Chicken');
|
||||
}
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\ChickenStatus;
|
||||
use App\Models\Chicken;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories.Factory<\App\Models\Chicken>
|
||||
*/
|
||||
class ChickenFactory extends Factory
|
||||
{
|
||||
protected $model = Chicken::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$arrivalDate = $this->faker->dateTimeBetween('-6 months', 'now');
|
||||
$hatchDate = $this->faker->boolean(70)
|
||||
? $this->faker->dateTimeBetween(
|
||||
(clone $arrivalDate)->modify('-2 months'),
|
||||
$arrivalDate
|
||||
)
|
||||
: null;
|
||||
|
||||
$status = $this->faker->randomElement(ChickenStatus::cases());
|
||||
$exitDate = $status === ChickenStatus::DEAD
|
||||
? $this->faker->dateTimeBetween($arrivalDate, 'now')
|
||||
: null;
|
||||
|
||||
return [
|
||||
'tag_code' => strtoupper($this->faker->bothify('CHK-###??')),
|
||||
'hatch_date' => $hatchDate,
|
||||
'arrival_date' => $arrivalDate,
|
||||
'exit_date' => $exitDate,
|
||||
'status' => $status,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\ChickenStatus;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('chickens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('tag_code', 20);
|
||||
$table->date('hatch_date')->nullable();
|
||||
$table->date('arrival_date');
|
||||
$table->date('exit_date')->nullable();
|
||||
$table->enum('status', ChickenStatus::cases())->default(ChickenStatus::ACTIVE->value)->comment(ChickenStatus::comment());
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('chickens');
|
||||
}
|
||||
};
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Chicken;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ChickenSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Chicken::factory()->count(50)->create();
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,6 @@ public function run(): void
|
||||
ShieldSeeder::class,
|
||||
UserSeeder::class,
|
||||
UnitSeeder::class,
|
||||
ChickenSeeder::class,
|
||||
FeedSeeder::class,
|
||||
FeedPurchaseSeeder::class,
|
||||
EggCollectionSeeder::class,
|
||||
|
||||
@ -27,18 +27,6 @@ public function run(): void
|
||||
"View:OrderTrendChart",
|
||||
"View:RevenueExpenseChart",
|
||||
"View:TopCustomersChart",
|
||||
|
||||
"ViewAny:Chicken",
|
||||
"View:Chicken",
|
||||
"Create:Chicken",
|
||||
"Update:Chicken",
|
||||
"Delete:Chicken",
|
||||
"Restore:Chicken",
|
||||
"ForceDelete:Chicken",
|
||||
"ForceDeleteAny:Chicken",
|
||||
"RestoreAny:Chicken",
|
||||
"Replicate:Chicken",
|
||||
"Reorder:Chicken",
|
||||
|
||||
"ViewAny:Customer",
|
||||
"View:Customer",
|
||||
@ -76,18 +64,6 @@ public function run(): void
|
||||
"Replicate:EggCollection",
|
||||
"Reorder:EggCollection",
|
||||
|
||||
"ViewAny:EggPrice",
|
||||
"View:EggPrice",
|
||||
"Create:EggPrice",
|
||||
"Update:EggPrice",
|
||||
"Delete:EggPrice",
|
||||
"Restore:EggPrice",
|
||||
"ForceDelete:EggPrice",
|
||||
"ForceDeleteAny:EggPrice",
|
||||
"RestoreAny:EggPrice",
|
||||
"Replicate:EggPrice",
|
||||
"Reorder:EggPrice",
|
||||
|
||||
"ViewAny:Expense",
|
||||
"View:Expense",
|
||||
"Create:Expense",
|
||||
@ -135,7 +111,7 @@ public function run(): void
|
||||
"RestoreAny:Order",
|
||||
"Replicate:Order",
|
||||
"Reorder:Order",
|
||||
|
||||
|
||||
"ViewAny:Unit",
|
||||
"View:Unit",
|
||||
"Create:Unit",
|
||||
@ -147,7 +123,7 @@ public function run(): void
|
||||
"RestoreAny:Unit",
|
||||
"Replicate:Unit",
|
||||
"Reorder:Unit",
|
||||
|
||||
|
||||
"ViewAny:User",
|
||||
"View:User",
|
||||
"Create:User",
|
||||
@ -182,14 +158,6 @@ public function run(): void
|
||||
"View:OrderTrendChart",
|
||||
"View:RevenueExpenseChart",
|
||||
"View:TopCustomersChart",
|
||||
|
||||
"ViewAny:Chicken",
|
||||
"View:Chicken",
|
||||
"Create:Chicken",
|
||||
"Update:Chicken",
|
||||
"Delete:Chicken",
|
||||
"Replicate:Chicken",
|
||||
"Reorder:Chicken",
|
||||
|
||||
"ViewAny:Customer",
|
||||
"View:Customer",
|
||||
@ -215,14 +183,6 @@ public function run(): void
|
||||
"Replicate:EggCollection",
|
||||
"Reorder:EggCollection",
|
||||
|
||||
"ViewAny:EggPrice",
|
||||
"View:EggPrice",
|
||||
"Create:EggPrice",
|
||||
"Update:EggPrice",
|
||||
"Delete:EggPrice",
|
||||
"Replicate:EggPrice",
|
||||
"Reorder:EggPrice",
|
||||
|
||||
"ViewAny:Expense",
|
||||
"View:Expense",
|
||||
"Create:Expense",
|
||||
@ -254,7 +214,7 @@ public function run(): void
|
||||
"Delete:Order",
|
||||
"Replicate:Order",
|
||||
"Reorder:Order",
|
||||
|
||||
|
||||
"ViewAny:Unit",
|
||||
"View:Unit",
|
||||
"Create:Unit",
|
||||
@ -262,7 +222,7 @@ public function run(): void
|
||||
"Delete:Unit",
|
||||
"Replicate:Unit",
|
||||
"Reorder:Unit",
|
||||
|
||||
|
||||
"ViewAny:User",
|
||||
"View:User",
|
||||
"Create:User",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user