diff --git a/app/Filament/Resources/OrderResource/Pages/EditOrder.php b/app/Filament/Resources/OrderResource/Pages/EditOrder.php index 8757381..6eb29a5 100644 --- a/app/Filament/Resources/OrderResource/Pages/EditOrder.php +++ b/app/Filament/Resources/OrderResource/Pages/EditOrder.php @@ -2,6 +2,7 @@ namespace App\Filament\Resources\OrderResource\Pages; +use App\Enums\OrderAttributes; use App\Filament\Resources\OrderResource; use Filament\Actions; use Filament\Resources\Pages\EditRecord; @@ -10,6 +11,34 @@ class EditOrder extends EditRecord { protected static string $resource = OrderResource::class; + protected function mutateFormDataBeforeFill(array $data): array + { + foreach (OrderAttributes::cases() as $case) { + if ($data[$case->name]) { + $data['order_attributes'][] = $case->value ?? null; + } + } + + return $data; + } + + protected function mutateFormDataBeforeSave(array $data): array + { + foreach (OrderAttributes::cases() as $case) { + $data[$case->name] = false; + } + + $data['order_attributes'] = array_filter($data['order_attributes']); + + foreach ($data['order_attributes'] as $attribute) { + $data[OrderAttributes::from($attribute)->name] = true; + } + + unset($data['order_attributes']); + + return $data; + } + protected function getHeaderActions(): array { return [ diff --git a/app/Filament/Widgets/ActiveOrdersTable.php b/app/Filament/Widgets/ActiveOrdersTable.php new file mode 100644 index 0000000..bfa45db --- /dev/null +++ b/app/Filament/Widgets/ActiveOrdersTable.php @@ -0,0 +1,34 @@ +query( + Order::query() + ->where('status', '!=', OrderStatus::SHIPPED) + ->where('status', '!=', OrderStatus::INVOICED) + ) + ->columns([ + TextColumn::make('customer.company_name'), + TextColumn::make('customer_po') + ->color('code') + ->weight('bold'), + TextColumn::make('status') +// ->color(OrderStatus::class) + ->badge(), + ]) + ->defaultPaginationPageOption(5); + } +} diff --git a/app/Filament/Widgets/LatestActiveOrders.php b/app/Filament/Widgets/RushOrdersTable.php similarity index 90% rename from app/Filament/Widgets/LatestActiveOrders.php rename to app/Filament/Widgets/RushOrdersTable.php index b2e3eb3..fc114a6 100644 --- a/app/Filament/Widgets/LatestActiveOrders.php +++ b/app/Filament/Widgets/RushOrdersTable.php @@ -8,10 +8,8 @@ use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; use Filament\Widgets\TableWidget as BaseWidget; -class LatestActiveOrders extends BaseWidget +class RushOrdersTable extends BaseWidget { - protected static ?int $sort = 2; - public function table(Table $table): Table { return $table diff --git a/app/Models/Order.php b/app/Models/Order.php index 53c899a..46fbcaf 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -28,12 +28,18 @@ class Order extends Model 'status', 'due_date', 'notes', - 'order_attributes', + 'rush', + 'repeat', + 'new_art', + 'event', + 'digitizing', + 'garments', + 'supplied_file', ]; protected $casts = [ - 'status' => OrderStatus::class, - 'order_attributes' => 'array', + 'status' => OrderStatus::class, + // 'order_attributes' => 'array', ]; public static function boot(): void diff --git a/composer.lock b/composer.lock index 62f6bed..ccdb662 100644 --- a/composer.lock +++ b/composer.lock @@ -10338,12 +10338,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { "php": "^8.2" }, - "platform-dev": [], + "platform-dev": {}, "plugin-api-version": "2.6.0" } diff --git a/database/factories/OrderFactory.php b/database/factories/OrderFactory.php index 491044f..0e94284 100644 --- a/database/factories/OrderFactory.php +++ b/database/factories/OrderFactory.php @@ -18,15 +18,24 @@ class OrderFactory extends Factory $due_date = $order_date->copy()->addDays(rand(9, 15)); return [ - 'created_at' => $order_date, - 'updated_at' => Carbon::now(), - 'customer_po' => $this->faker->randomNumber(6, true), - 'order_type' => $this->faker->randomElement(OrderType::cases())->value, - 'order_date' => $order_date, - 'due_date' => $due_date, - 'status' => $this->faker->randomElement(OrderStatus::cases())->value, - 'notes' => $this->faker->words(10, true), - 'order_attributes' => ['New Art', 'Garments', 'Rush'], + 'created_at' => $order_date, + 'updated_at' => Carbon::now(), + 'customer_po' => $this->faker->randomNumber(6, true), + 'order_type' => $this->faker->randomElement(OrderType::cases())->value, + 'order_date' => $order_date, + 'due_date' => $due_date, + 'status' => $this->faker->randomElement(OrderStatus::cases())->value, + 'notes' => $this->faker->words(10, true), + + 'rush' => $this->faker->boolean(20), + 'repeat' => $this->faker->boolean(), + 'new_art' => $this->faker->boolean(), + 'event' => $this->faker->boolean(), + 'digitizing' => $this->faker->boolean(), + 'garments' => $this->faker->boolean(), + 'supplied_file' => $this->faker->boolean(), + + // 'order_attributes' => ['New Art', 'Garments', 'Rush'], ]; } } diff --git a/database/migrations/2024_09_09_194631_create_orders_table.php b/database/migrations/2024_09_09_194631_create_orders_table.php index 89e0741..6e1193e 100644 --- a/database/migrations/2024_09_09_194631_create_orders_table.php +++ b/database/migrations/2024_09_09_194631_create_orders_table.php @@ -19,7 +19,15 @@ return new class extends Migration $table->date('due_date'); $table->string('status'); $table->longText('notes')->nullable(); - $table->json('order_attributes'); + + $table->boolean('rush')->default(0); + $table->boolean('repeat')->default(0); + $table->boolean('new_art')->default(0); + $table->boolean('event')->default(0); + $table->boolean('digitizing')->default(0); + $table->boolean('garments')->default(0); + $table->boolean('supplied_file')->default(0); + $table->softDeletes(); $table->timestamps(); });