diff --git a/app/Filament/Resources/OrderResource.php b/app/Filament/Resources/OrderResource.php index af448ce..76cdf44 100644 --- a/app/Filament/Resources/OrderResource.php +++ b/app/Filament/Resources/OrderResource.php @@ -9,6 +9,8 @@ use App\Models\Contact; use App\Models\Customer; use App\Models\Order; +use App\Models\ProductService; +use App\Models\ServiceFile; use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\Grid; use Filament\Forms\Components\Repeater; @@ -25,6 +27,7 @@ use Filament\Tables\Table; use Guava\FilamentClusters\Forms\Cluster; use Icetalker\FilamentTableRepeater\Forms\Components\TableRepeater; +use Illuminate\Support\Facades\Log; class OrderResource extends Resource { @@ -137,18 +140,18 @@ public static function form(Form $form): Form ->columnSpan(2), TextInput::make('placement') ->columnSpan(3), - TextInput::make('service_file_name') + TextInput::make('serviceFileName') ->columnSpan(3) ->label('Logo Name'), - TextInput::make('service_file_setup_number') + TextInput::make('serviceFileSetupNumber') ->label('Setup') ->columnSpan(1), Cluster::make([ - TextInput::make('service_file_width') + TextInput::make('serviceFileWidth') ->prefix('w') ->placeholder('Width'), - TextInput::make('service_file_height') + TextInput::make('serviceFileHeight') ->prefix('h') ->placeholder('Height'), ]) @@ -170,7 +173,7 @@ public static function form(Form $form): Form Grid::make(9) ->schema([ - TextInput::make('service_file_code') + TextInput::make('serviceFileCode') ->label('Code') ->columnSpan(1) ->placeholder('A1234'), @@ -183,7 +186,51 @@ public static function form(Form $form): Form ->reorderable() ->cloneable() ->columns(4) - ->columnSpan(2), + ->columnSpan(2) + ->mutateRelationshipDataBeforeSaveUsing(function (array $data, ProductService $record): array { + dd('yep'); + + Log::debug($record->toJson()); + + if ($record->serviceFile !== null) { + $record->serviceFile->update([ + 'name' => $data['serviceFileName'], + 'width' => $data['serviceFileWidth'], + 'height' => $data['serviceFileHeight'], + 'code' => $data['serviceFileCode'], + 'setup_number' => $data['serviceFileSetupNumber'], + ]); + } + + return $data; + }) + ->mutateRelationshipDataBeforeFillUsing(function (array $data): array { + /** @var ProductService $productService */ + $productService = ProductService::findOrFail($data['id']); + + $serviceFile = ServiceFile::findOrFail($productService->service_file_id); + + if ($serviceFile !== null) { + $data['serviceFileName'] = $serviceFile->name; + $data['serviceFileWidth'] = $serviceFile->width; + $data['serviceFileHeight'] = $serviceFile->height; + $data['serviceFileCode'] = $serviceFile->code; + $data['serviceFileSetupNumber'] = $serviceFile->setup_number; + } + + return $data; + }), + // ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { + // $serviceFile = ServiceFile::create([ + // 'name' => $data['serviceFileName'], + // 'width' => $data['serviceFileWidth'], + // 'height' => $data['serviceFileHeight'], + // 'code' => $data['serviceFileCode'], + // 'setup_number' => $data['serviceFileSetupNumber'], + // ]); + // + // return $data; + // }), ]); } diff --git a/app/Models/ProductService.php b/app/Models/ProductService.php index a390292..e0762c6 100644 --- a/app/Models/ProductService.php +++ b/app/Models/ProductService.php @@ -18,49 +18,16 @@ class ProductService extends Model 'service_file_id', 'service_type', 'placement', + 'width', + 'height', + 'code', + 'setup_amount', + 'logo_name', 'amount', 'amount_price', 'notes', ]; - protected $appends = [ - 'service_file_name', - 'service_file_setup_number', - 'service_file_width', - 'service_file_height', - 'service_file_code', - ]; - - public function getServiceFileNameAttribute(): string - { - return $this->serviceFile->name ?? ''; - } - - public function getServiceFileSetupNumberAttribute(): string - { - return $this->serviceFile->setup_number ?? ''; - } - - public function getServiceFileWidthAttribute(): string - { - return $this->serviceFile->width ?? ''; - } - - public function getServiceFileHeightAttribute(): string - { - return $this->serviceFile->height ?? ''; - } - - public function getServiceFileCodeAttribute(): string - { - return $this->serviceFile->code ?? ''; - } - - public function setServiceFileName(string $name): void - { - $this->serviceFile->name = $name; - } - /** * @return BelongsTo */ diff --git a/database/factories/OrderProductFactory.php b/database/factories/OrderProductFactory.php index be6d525..2b6bf47 100644 --- a/database/factories/OrderProductFactory.php +++ b/database/factories/OrderProductFactory.php @@ -18,6 +18,14 @@ public function definition(): array 'sku' => $this->faker->randomElement([$this->faker->randomNumber(4, true), null]), 'product_name' => $this->faker->randomElement(['shirts', 'hats', 'jackets', 'pants', 'tote bags', 'backpacks']), 'color' => $this->faker->randomElement(['black', 'white', 'navy', 'red', 'gold', 'charcoal']), + 'xs' => $this->faker->numberBetween(0, 10), + 's' => $this->faker->numberBetween(0, 10), + 'm' => $this->faker->numberBetween(0, 10), + 'l' => $this->faker->numberBetween(0, 10), + 'xl' => $this->faker->numberBetween(0, 10), + '2xl' => $this->faker->numberBetween(0, 10), + '3xl' => $this->faker->numberBetween(0, 10), + 'osfa' => $this->faker->numberBetween(0, 10), ]; } } diff --git a/database/factories/ProductServiceFactory.php b/database/factories/ProductServiceFactory.php index b9b63f9..7ab1911 100644 --- a/database/factories/ProductServiceFactory.php +++ b/database/factories/ProductServiceFactory.php @@ -18,6 +18,10 @@ public function definition(): array 'service_type' => $this->faker->randomElement(['emb', 'scp', 'dtg', 'vinyl']), 'placement' => $this->faker->randomElement(['l/c', 'c/f', 'f/b', 'r/c']), 'amount' => $this->faker->randomNumber(1), + 'code' => $this->faker->randomElement(['A', 'B']).$this->faker->randomNumber(4, true), + 'logo_name' => $this->faker->word(), + 'width' => round($this->faker->randomFloat(2, 0, 10), 1), + 'height' => round($this->faker->randomFloat(2, 0, 10), 1), 'amount_price' => 0, 'notes' => $this->faker->randomElement(['1) 1149 2) grey 3) white', '1) white', '1) black 2) white']), ]; diff --git a/database/migrations/2024_09_10_224439_create_order_products_table.php b/database/migrations/2024_09_10_224439_create_order_products_table.php index 4e1ccd6..8221f5f 100644 --- a/database/migrations/2024_09_10_224439_create_order_products_table.php +++ b/database/migrations/2024_09_10_224439_create_order_products_table.php @@ -14,6 +14,16 @@ public function up(): void $table->string('sku')->nullable(); $table->string('product_name'); $table->string('color')->nullable(); + + $table->string('xs')->nullable(); + $table->string('s')->nullable(); + $table->string('m')->nullable(); + $table->string('l')->nullable(); + $table->string('xl')->nullable(); + $table->string('2xl')->nullable(); + $table->string('3xl')->nullable(); + $table->string('osfa')->nullable(); + $table->softDeletes(); $table->timestamps(); }); diff --git a/database/migrations/2024_09_10_224947_create_product_services_table.php b/database/migrations/2024_09_10_224947_create_product_services_table.php index d369349..b2230ab 100644 --- a/database/migrations/2024_09_10_224947_create_product_services_table.php +++ b/database/migrations/2024_09_10_224947_create_product_services_table.php @@ -14,6 +14,11 @@ public function up(): void $table->foreignId('service_file_id')->nullable(); $table->string('service_type'); $table->string('placement'); + $table->string('logo_name'); + $table->string('width'); + $table->string('height'); + $table->string('setup_amount')->nullable(); + $table->string('code'); $table->string('amount')->nullable(); $table->string('amount_price')->nullable(); $table->string('notes')->nullable(); diff --git a/database/seeders/CustomerSeeder.php b/database/seeders/CustomerSeeder.php index e6b7f82..cd82314 100644 --- a/database/seeders/CustomerSeeder.php +++ b/database/seeders/CustomerSeeder.php @@ -22,8 +22,7 @@ public function run(): void ->has(Contact::factory(rand(1, 5))) ->has(ShippingEntry::factory(rand(1, 3))) ->has(Order::factory(rand(5, 10)) - ->has(OrderProduct::factory(rand(1, 3)) - ->has(productSize::factory(rand(1, 3)))) + ->has(OrderProduct::factory(rand(1, 3))) ->has(ProductService::factory(rand(1, 5), [ 'service_file_id' => ServiceFile::factory(), ]))