diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php index 2aebeba..3a1aa0e 100644 --- a/app/Http/Controllers/OrderController.php +++ b/app/Http/Controllers/OrderController.php @@ -11,8 +11,11 @@ use App\Models\ProductService; use App\Models\ProductSize; use App\Models\ServiceFile; +use Illuminate\Contracts\View\Factory; +use Illuminate\Foundation\Application; use Illuminate\Http\Request; use Illuminate\Support\Carbon; +use Illuminate\View\View; class OrderController extends Controller { @@ -103,7 +106,7 @@ public function store(OrderRequest $request) return redirect()->route('order-products.create', ['order' => $order->id]); } - public function show($id) + public function show(int $id): Factory|\Illuminate\Contracts\View\View|Application|View { return view('orders.show', [ 'order' => Order::find($id), @@ -111,7 +114,7 @@ public function show($id) ]); } - public function edit($id) {} + public function edit(int $id) {} public function update(Request $request, $id) {} diff --git a/app/Http/Requests/OrderRequest.php b/app/Http/Requests/OrderRequest.php index 8236ac5..247d439 100644 --- a/app/Http/Requests/OrderRequest.php +++ b/app/Http/Requests/OrderRequest.php @@ -12,6 +12,7 @@ class OrderRequest extends FormRequest public function rules(): array { return [ + // Order 'customer_id' => ['required', 'exists:customers,id'], 'contact_id' => ['nullable', 'exists:contacts,id'], 'customer_po' => ['required', 'string'], @@ -26,6 +27,14 @@ public function rules(): array 'purchased_garments' => ['nullable'], 'customer_supplied_file' => ['nullable'], 'notes' => ['nullable'], + + // Order Products + + // Product Sizes + + // Product Services + + // Service Files ]; } diff --git a/app/Models/Order.php b/app/Models/Order.php index a7f49b3..abf1d28 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -57,6 +57,28 @@ public function generateInternalPo(int $id): string return 'TN'.$year.'-'.$po; } + public function totalProductQuantity(): int + { + $total = 0; + + foreach ($this->orderProducts as $product) { + $total += $product->totalQuantity(); + } + + return $total; + } + + public function totalServicePrice(): float + { + $total = 0; + + foreach ($this->productServices as $service) { + $total += $service->amount * $service->amount_price; + } + + return number_format($total, 2); + } + public function active(): bool { if ($this->status == OrderStatus::APPROVED @@ -113,6 +135,14 @@ public function customer(): BelongsTo return $this->belongsTo(Customer::class); } + /** + * @return BelongsTo + */ + public function contact(): BelongsTo + { + return $this->belongsTo(Contact::class); + } + /** * @return HasMany */ diff --git a/app/Models/OrderProduct.php b/app/Models/OrderProduct.php index c5be45c..75ce673 100644 --- a/app/Models/OrderProduct.php +++ b/app/Models/OrderProduct.php @@ -22,6 +22,11 @@ class OrderProduct extends Model 'color', ]; + public function totalQuantity(): int + { + return array_sum($this->productSizes()->pluck('amount')->toArray()); + } + /** * @return BelongsTo */ @@ -41,7 +46,7 @@ public function serviceFile(): HasOne /** * @return HasMany */ - public function productSize(): HasMany + public function productSizes(): HasMany { return $this->hasMany(ProductSize::class); } diff --git a/app/Models/ServiceFile.php b/app/Models/ServiceFile.php index 597f361..dd30e2c 100644 --- a/app/Models/ServiceFile.php +++ b/app/Models/ServiceFile.php @@ -19,7 +19,6 @@ class ServiceFile extends Model 'name', 'width', 'height', - 'unit', 'setup_number', ]; diff --git a/database/factories/ProductServiceFactory.php b/database/factories/ProductServiceFactory.php index 68538b7..277576e 100644 --- a/database/factories/ProductServiceFactory.php +++ b/database/factories/ProductServiceFactory.php @@ -15,9 +15,8 @@ public function definition(): array return [ 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), - 'service_type' => $this->faker->randomElement(['embroidery', 'screen printing', 'dtg', 'vinyl']), + 'service_type' => $this->faker->randomElement(['emb', 'scp', 'dtg', 'vinyl']), 'placement' => $this->faker->randomElement(['l/c', 'c/f', 'f/b', 'r/c']), - 'setup_amount' => 0, 'amount' => $this->faker->randomNumber(1), 'amount_price' => 0, ]; diff --git a/database/factories/ServiceFileFactory.php b/database/factories/ServiceFileFactory.php index 6a2dc22..36ebf03 100644 --- a/database/factories/ServiceFileFactory.php +++ b/database/factories/ServiceFileFactory.php @@ -20,6 +20,7 @@ public function definition(): array 'width' => round($this->faker->randomFloat(2, 0, 10), 1), 'height' => round($this->faker->randomFloat(2, 0, 10), 1), 'unit' => 'inch', + 'notes' => $this->faker->randomElement(['1) 1149 2) grey 3) white', '1) white', '1) black 2) white']), ]; } } 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 b176300..5cd7819 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 @@ -13,7 +13,6 @@ public function up(): void $table->foreignId('order_id'); $table->string('service_type'); $table->string('placement'); - $table->string('setup_amount'); $table->string('amount')->nullable(); $table->string('amount_price')->nullable(); $table->softDeletes(); diff --git a/database/migrations/2024_09_10_225029_create_service_files_table.php b/database/migrations/2024_09_10_225029_create_service_files_table.php index 91c3bca..36a1474 100644 --- a/database/migrations/2024_09_10_225029_create_service_files_table.php +++ b/database/migrations/2024_09_10_225029_create_service_files_table.php @@ -13,11 +13,11 @@ public function up(): void $table->foreignId('product_service_id')->constrained(); $table->string('code'); $table->string('name'); - $table->string('placement'); $table->decimal('width')->nullable(); $table->decimal('height')->nullable(); $table->string('unit')->default('inch'); $table->integer('setup_number')->nullable(); + $table->string('notes'); $table->softDeletes(); $table->timestamps(); }); diff --git a/database/seeders/CustomerSeeder.php b/database/seeders/CustomerSeeder.php index 55f3048..881783f 100644 --- a/database/seeders/CustomerSeeder.php +++ b/database/seeders/CustomerSeeder.php @@ -9,6 +9,7 @@ use App\Models\PackingSlip; use App\Models\ProductService; use App\Models\ProductSize; +use App\Models\ServiceFile; use App\Models\ShippingEntry; use Illuminate\Database\Seeder; @@ -16,16 +17,18 @@ class CustomerSeeder extends Seeder { public function run(): void { - Customer::factory(3) - ->has(Contact::factory(5)) - ->has(PackingSlip::factory(30)) - ->has(ShippingEntry::factory(2)) - ->has(Order::factory(10) - ->has(OrderProduct::factory(2) - ->has(ProductSize::factory(3))) - ->has(ProductService::factory(3))) -// ->has(ServiceFile::factory(1)))) - ->create(); + for ($i = 0; $i < 10; $i++) { + Customer::factory() + ->has(Contact::factory(rand(1, 5))) + ->has(PackingSlip::factory(rand(1, 10))) + ->has(ShippingEntry::factory(rand(1, 3))) + ->has(Order::factory(rand(2, 10)) + ->has(OrderProduct::factory(rand(1, 10)) + ->has(productSize::factory(rand(1, 8)))) + ->has(ProductService::factory(rand(1, 10)) + ->has(ServiceFile::factory()))) + ->create(); + } Customer::factory([ 'company_name' => 'Genumark', diff --git a/resources/views/livewire/order-products-create.blade.php b/resources/views/livewire/order-products-create.blade.php index bcc1a9d..b14e54f 100644 --- a/resources/views/livewire/order-products-create.blade.php +++ b/resources/views/livewire/order-products-create.blade.php @@ -157,135 +157,138 @@ class="form-control form-control-sm @error('product_total') is-invalid @enderror - -
-
-
#
-
Service
-
Placement
-
Logo Name
+
-
-
-
Setup
-
Width
-
Height
-
Unit
-
Price
-
Total
-
+ +
+
+
#
+
Service
+
Placement
+
Logo Name
+ +
+
+
Setup
+
Width
+
Height
+
Unit
+
Price
+
Total
+
+
-
- + - @foreach($serviceInputs as $key => $value) -
+ @foreach($serviceInputs as $key => $value) +
- + -
-
-
-
{{$loop->index+1}}
-
- -
-
- -
-
- -
-
+
+
+
+
{{$loop->index+1}}
+
+ +
+
+ +
+
+ +
+
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- @if($key > 0) - - @endif +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ @if($key > 0) + + @endif +
-
-
-
-
- -
+
+
+
+ +
-
+
+
-
- @endforeach + @endforeach +
{{--
--}}
diff --git a/resources/views/orders/create.blade.php b/resources/views/orders/create.blade.php index 49ec647..08d4728 100644 --- a/resources/views/orders/create.blade.php +++ b/resources/views/orders/create.blade.php @@ -59,8 +59,7 @@
- +
+
-
- +
+ +
+ @if(isset($order->contact)) + + @else + + @endif +
-
- +
+ +
+ +
+ +
-
- +
+ +
+ +
+
+ +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+ @if($order->new_art) +
+ + +
+ @endif + @if($order->rush) +
+ + +
+ @endif + @if($order->digitizing) +
+ + +
+ @endif + + @if($order->customer_supplied_file) +
+ + +
+ @endif + + @if($order->repeat) +
+ + +
+ @endif + + @if($order->event) +
+ + +
+ @endif + @if($order->purchased_garments) +
+ + +
+ @endif +
+
+ +
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ + +
+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + @foreach($order->orderProducts as $key => $product) + + + + + + + + + + + + + + + + + + @endforeach + + +
#SKUProduct NameColorXSSMLXL2XL3XLOSFATotal
{{$loop->index+1}} + + {{$product->sku}} + + + {{$product->product_name}} + + + {{$product->color}} + + + {{$product->productSizes()->get()->where('size', 'xs')->first()->amount ?? ''}} + + + {{$product->productSizes()->get()->where('size', 'xs')->first()->amount ?? ''}} + + + + {{$product->productSizes()->get()->where('size', 'm')->first()->amount ?? ''}} + + + {{$product->productSizes()->get()->where('size', 'l')->first()->amount ?? ''}} + + + + {{$product->productSizes()->get()->where('size', 'xl')->first()->amount ?? ''}} + + + {{$product->productSizes()->get()->where('size', '2xl')->first()->amount ?? ''}} + + + {{$product->productSizes()->get()->where('size', '3xl')->first()->amount ?? ''}} + + + {{$product->productSizes()->get()->where('size', 'osfa')->first()->amount ?? ''}} + + {{$product->totalQuantity()}} + + +
+ +
+ + + +
+ + +
+ + +
+
+
#
+
Service
+
Placement
+
Logo Name
+ +
+
+
Setup
+
Width
+
Height
+
Unit
+
Price
+
Total
+
+
+
+
+ + + + @foreach($order->productServices as $key => $service) +
+ +
+
+
+
{{$loop->index+1}}
+
+ + {{$service->service_type}} +
+
+ {{$service->placement}} +
+
+ {{$service->serviceFile->name }} +
+
+
+
+ {{$service->serviceFile->setup_number}} +
+
+ {{$service->serviceFile->width}} +
+
+ {{$service->serviceFile->height}} +
+
+ {{$service->amount}} +
+
+ {{$service->amount_price != 0 ? $service->amount_price : ''}} +
+
+ {{$service->amount_price != 0 ? '$' . number_format($service->amount_price*$service->amount, 2) : ''}} +
+
+
+
+
+
+
+ + {{$service->serviceFile->code}} + +
+ +
+ {{$service->serviceFile->notes}} +
+
+
+
+
+ @endforeach +
+ +
+ +