diff --git a/app/Http/Controllers/Admin/AdminOrderController.php b/app/Http/Controllers/Admin/AdminOrderController.php new file mode 100644 index 0000000..d467825 --- /dev/null +++ b/app/Http/Controllers/Admin/AdminOrderController.php @@ -0,0 +1,68 @@ +get(); + $markList = MarkList::where('status', 'active')->get(); // ✅ Correct usage + + return view('admin.dashboard', compact('orders', 'markList')); + } + + public function store(Request $request) +{ + $request->validate([ + 'mark_no' => 'required', + 'description' => 'required', + ]); + + // ✅ Generate custom order_id like KNT-25-00000001 + $year = date('y'); + $prefix = "KNT-$year-"; + + // Get the last order to increment number + $lastOrder = Order::latest('id')->first(); + $nextNumber = $lastOrder ? intval(substr($lastOrder->order_id, -8)) + 1 : 1; + + // Format number with leading zeros (8 digits) + $newOrderId = $prefix . str_pad($nextNumber, 8, '0', STR_PAD_LEFT); + + // ✅ Create order + $order = new Order(); + $order->order_id = $newOrderId; // ✅ set this field + $order->mark_no = $request->mark_no; + $order->origin = $request->origin; + $order->destination = $request->destination; + $order->description = $request->description; + $order->ctn = $request->ctn; + $order->qty = $request->qty; + $order->ttl_qty = $request->ttl_qty; + $order->unit = $request->unit; + $order->price = $request->price; + $order->ttl_amount = $request->ttl_amount; + $order->cbm = $request->cbm; + $order->ttl_cbm = $request->ttl_cbm; + $order->kg = $request->kg; + $order->ttl_kg = $request->ttl_kg; + $order->shop_no = $request->shop_no; + $order->status = 'pending'; + $order->save(); + + return redirect()->back()->with('success', 'Order created successfully with ID: ' . $newOrderId); +} + + + public function show($id) + { + $order = Order::findOrFail($id); + return view('admin.orders_show', compact('order')); + } +} diff --git a/app/Models/Order.php b/app/Models/Order.php new file mode 100644 index 0000000..c387c31 --- /dev/null +++ b/app/Models/Order.php @@ -0,0 +1,24 @@ +hasOne(MarkList::class, 'mark_no', 'mark_no'); + } +} diff --git a/database/migrations/2025_11_07_171303_create_orders_table.php b/database/migrations/2025_11_07_171303_create_orders_table.php new file mode 100644 index 0000000..f8cec8b --- /dev/null +++ b/database/migrations/2025_11_07_171303_create_orders_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('order_id')->unique(); // Example: KNT-25-00000001 + $table->string('mark_no'); // linked to mark_lists.mark_no + $table->string('description')->nullable(); + $table->string('origin')->nullable(); + $table->string('destination')->nullable(); + $table->integer('ctn')->nullable(); + $table->integer('qty')->nullable(); + $table->integer('ttl_qty')->nullable(); + $table->string('unit')->nullable(); + $table->decimal('price', 10, 2)->nullable(); + $table->decimal('ttl_amount', 10, 2)->nullable(); + $table->decimal('cbm', 10, 3)->nullable(); + $table->decimal('ttl_cbm', 10, 3)->nullable(); + $table->decimal('kg', 10, 3)->nullable(); + $table->decimal('ttl_kg', 10, 3)->nullable(); + $table->string('shop_no')->nullable(); + $table->string('status')->default('in_transit'); // in_transit, dispatched, delivered + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('orders'); + } +}; diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index 89f399d..0359d50 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -1,12 +1,133 @@ @extends('admin.layouts.app') -@section('page-title', 'Dashboard') +@section('page-title', 'Orders') @section('content') -
Here you can manage all system modules.
+| # | +Order ID | +Mark No | +Description | +Origin | +Destination | +TTL Amount | +Status | +Date | +Action | +
|---|---|---|---|---|---|---|---|---|---|
| {{ $index + 1 }} | +{{ $order->order_id }} | +{{ $order->mark_no }} | +{{ $order->description }} | +{{ $order->origin }} | +{{ $order->destination }} | +₹{{ number_format($order->ttl_amount, 2) }} | +{{ ucfirst($order->status) }} | +{{ $order->created_at->format('d-m-Y') }} | +View | +
| No orders found | |||||||||