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.
140 lines
4.4 KiB
PHP
140 lines
4.4 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\Contracts\View\Factory;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\View\View;
|
|
use Spatie\Browsershot\Browsershot;
|
|
use Spatie\LaravelPdf\Facades\Pdf;
|
|
|
|
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++) {
|
|
$serviceFile = ServiceFile::create([
|
|
'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],
|
|
'setup_number' => $request->get('setup_amount')[$i],
|
|
]);
|
|
ProductService::create([
|
|
'order_id' => $order->id,
|
|
'service_file_id' => $serviceFile->id,
|
|
'service_type' => $request->get('service_type')[$i],
|
|
'placement' => $request->get('placement')[$i],
|
|
'amount' => $request->get('amount')[$i],
|
|
'amount_price' => $request->get('amount_price')[$i],
|
|
'notes' => $request->get('service_notes')[$i],
|
|
]);
|
|
|
|
}
|
|
|
|
return redirect()->route('orders.show', $order);
|
|
}
|
|
|
|
public function show(int $id): Factory|\Illuminate\Contracts\View\View|Application|View
|
|
{
|
|
return view('orders.show', [
|
|
'order' => Order::find($id),
|
|
'tab' => 'details',
|
|
]);
|
|
}
|
|
|
|
public function edit(int $id) {}
|
|
|
|
public function update(Request $request, $id) {}
|
|
|
|
public function destroy(int $id): void {}
|
|
|
|
public function pdf(int $id)
|
|
{
|
|
$order = Order::find($id);
|
|
$url = strtolower('order-'.$order->internal_po.'.pdf');
|
|
|
|
Pdf::view('pdf.order', ['order' => $order])
|
|
->withBrowsershot(function (Browsershot $browsershot) {
|
|
$browsershot->noSandbox();
|
|
})
|
|
->margins(8, 8, 15, 8)
|
|
->footerView('pdf.order-footer', ['order' => $order])
|
|
->save($url);
|
|
|
|
return redirect($url);
|
|
}
|
|
}
|