You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
topnotch_website/app/Http/Controllers/OrderController.php

120 lines
3.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Enums\OrderStatus;
use App\Enums\OrderType;
use App\Http\Requests\OrderRequest;
use App\Models\Customer;
use App\Models\Order;
use App\Models\OrderProduct;
use App\Models\ProductService;
use App\Models\ProductSize;
use App\Models\ServiceFile;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
class OrderController extends Controller
{
public function index(Request $request)
{
if (! $request->get('tab')) {
return redirect()->route('orders.index', ['tab' => 'all']);
}
return view('orders.index', [
'tab' => $request->get('tab'),
]);
}
public function create()
{
return view('orders.create', [
'order_types' => OrderType::cases(),
'order_status' => OrderStatus::cases(),
'customers' => Customer::all(),
'today' => Carbon::today()->format('Y-m-d'),
'due_default' => Carbon::today()->addDay(10)->format('Y-m-d'),
]);
}
public function store(OrderRequest $request)
{
// Create order
$order = Order::create($request->safe()->only([
'customer_id',
'contact_id',
'order_type',
'status',
'customer_po',
'order_date',
'due_date',
'rush',
'new_art',
'digitizing',
'repeat',
'purchased_garments',
'customer_supplied_file',
'notes',
]));
// Create orderProducts
for ($i = 0; $i < count($request->get('productInputCount')) - 1; $i++) {
$orderProduct = OrderProduct::create([
'order_id' => $order->id,
'sku' => $request->get('sku')[$i],
'product_name' => $request->get('product_name')[$i],
'color' => $request->get('product_color')[$i],
]);
// Create productSizes
foreach (['xs', 's', 'm', 'l', 'xl', '2xl', '3xl', 'osfa'] as $size) {
ProductSize::create([
'order_product_id' => $orderProduct->id,
'amount' => $request->get('size_'.$size)[$i],
'size' => $size,
]);
}
}
// Create productServices
for ($i = 0; $i < count($request->get('serviceInputCount')) - 1; $i++) {
$productService = ProductService::create([
'order_id' => $order->id,
'service_type' => $request->get('service_type')[$i],
'placement' => $request->get('placement')[$i],
'setup_amount' => $request->get('setup_amount')[$i],
'amount' => $request->get('amount')[$i],
'amount_price' => $request->get('amount_price')[$i],
]);
ServiceFile::create([
'product_service_id' => $productService,
'code' => $request->get('service_file_name')[$i],
'name' => $request->get('logo_name')[$i],
'width' => $request->get('service_width')[$i],
'height' => $request->get('service_height')[$i],
'unit' => $request->get('service_setup_unit')[$i],
'setup_number' => $request->get('setup_number')[$i],
]);
}
return redirect()->route('order-products.create', ['order' => $order->id]);
}
public function show($id)
{
return view('orders.show', [
'order' => Order::find($id),
'tab' => 'details',
]);
}
public function edit($id) {}
public function update(Request $request, $id) {}
public function destroy($id) {}
}