From 6a4f1dd4e935f2e88c2aef06d1499eded82608d338fa9296519212a8e4ce7bd0 Mon Sep 17 00:00:00 2001 From: Abhishek Mali Date: Wed, 12 Nov 2025 11:56:43 +0530 Subject: [PATCH] order list added --- .../Admin/AdminOrderController.php | 68 +++++++++ app/Models/Order.php | 24 ++++ .../2025_11_07_171303_create_orders_table.php | 36 +++++ resources/views/admin/dashboard.blade.php | 131 +++++++++++++++++- resources/views/admin/layouts/app.blade.php | 5 +- routes/web.php | 10 +- 6 files changed, 267 insertions(+), 7 deletions(-) create mode 100644 app/Http/Controllers/Admin/AdminOrderController.php create mode 100644 app/Models/Order.php create mode 100644 database/migrations/2025_11_07_171303_create_orders_table.php 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') -
-
-

Welcome to the Admin Dashboard

-

Here you can manage all system modules.

+
+ + {{-- Header --}} +
+

Order Management

+ +
+ + {{-- Create Order Form --}} +
+
+
+ New Order Form +
+
+
+ @csrf +
+ + {{-- Mark No --}} +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+ +
+
+
+
+
+ + {{-- Orders Table --}} +
+
+ Recent Orders +
+
+ + + + + + + + + + + + + + + + + @forelse($orders as $index => $order) + + + + + + + + + + + + + @empty + + @endforelse + +
#Order IDMark NoDescriptionOriginDestinationTTL AmountStatusDateAction
{{ $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
+
+ +{{-- Autofill JS --}} + @endsection diff --git a/resources/views/admin/layouts/app.blade.php b/resources/views/admin/layouts/app.blade.php index d0c437c..4b7506e 100644 --- a/resources/views/admin/layouts/app.blade.php +++ b/resources/views/admin/layouts/app.blade.php @@ -81,7 +81,10 @@ Customers Reports Chat Support - Orders + + Orders + Requests Staff Account diff --git a/routes/web.php b/routes/web.php index 5e7ad98..6e0f860 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\Admin\AdminAuthController; use App\Http\Controllers\Admin\UserRequestController; use App\Http\Controllers\Admin\AdminMarkListController; +use App\Http\Controllers\Admin\AdminOrderController; // ------------------------- // Default Front Page @@ -26,7 +27,8 @@ Route::prefix('admin')->group(function () { // ------------------------- Route::prefix('admin')->middleware('auth:admin')->group(function () { // Dashboard Pages - Route::get('/dashboard', fn() => view('admin.dashboard'))->name('admin.dashboard'); + // Route::get('/dashboard', fn() => view('admin.dashboard'))->name('admin.dashboard'); + Route::get('/dashboard', [AdminOrderController::class, 'index'])->name('admin.dashboard'); Route::get('/shipments', fn() => view('admin.shipments'))->name('admin.shipments'); Route::get('/invoice', fn() => view('admin.invoice'))->name('admin.invoice'); Route::get('/customers', fn() => view('admin.customers'))->name('admin.customers'); @@ -45,4 +47,10 @@ Route::prefix('admin')->middleware('auth:admin')->group(function () { //mark list show Route::get('/mark-list', [AdminMarkListController::class, 'index'])->name('admin.marklist.index'); Route::get('/mark-list/status/{id}', [AdminMarkListController::class, 'toggleStatus'])->name('admin.marklist.toggle'); + + // Orders Controller Routes + Route::get('/orders', [AdminOrderController::class, 'index'])->name('admin.orders.index'); + Route::post('/orders/store', [AdminOrderController::class, 'store'])->name('admin.orders.store'); + Route::get('/orders/{id}', [AdminOrderController::class, 'show'])->name('admin.orders.show'); + });