order list added
This commit is contained in:
68
app/Http/Controllers/Admin/AdminOrderController.php
Normal file
68
app/Http/Controllers/Admin/AdminOrderController.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Order;
|
||||
use App\Models\MarkList; // ✅ Correct model
|
||||
|
||||
class AdminOrderController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$orders = Order::latest()->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'));
|
||||
}
|
||||
}
|
||||
24
app/Models/Order.php
Normal file
24
app/Models/Order.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\MarkList;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'order_id', 'mark_no', 'description', 'origin', 'destination',
|
||||
'ctn', 'qty', 'ttl_qty', 'unit', 'price', 'ttl_amount',
|
||||
'cbm', 'ttl_cbm', 'kg', 'ttl_kg', 'shop_no', 'status'
|
||||
];
|
||||
|
||||
// Relation using mark_no instead of id
|
||||
public function markList()
|
||||
{
|
||||
return $this->hasOne(MarkList::class, 'mark_no', 'mark_no');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('orders', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
@@ -1,12 +1,133 @@
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('page-title', 'Dashboard')
|
||||
@section('page-title', 'Orders')
|
||||
|
||||
@section('content')
|
||||
<div class="card shadow-sm">
|
||||
<div class="container-fluid py-4">
|
||||
|
||||
{{-- Header --}}
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h4 class="mb-0">Order Management</h4>
|
||||
<button class="btn btn-primary" data-bs-toggle="collapse" data-bs-target="#createOrderForm">
|
||||
<i class="bi bi-plus-circle"></i> Create Order
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{{-- Create Order Form --}}
|
||||
<div id="createOrderForm" class="collapse">
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-header bg-light">
|
||||
<strong>New Order Form</strong>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h4>Welcome to the Admin Dashboard</h4>
|
||||
<p>Here you can manage all system modules.</p>
|
||||
<form action="{{ route('admin.orders.store') }}" method="POST">
|
||||
@csrf
|
||||
<div class="row g-3">
|
||||
|
||||
{{-- Mark No --}}
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Mark No</label>
|
||||
<select class="form-select" id="markNoSelect" name="mark_no" required>
|
||||
<option value="">Select Mark No</option>
|
||||
@foreach($markList as $mark)
|
||||
<option value="{{ $mark->mark_no }}"
|
||||
data-origin="{{ $mark->origin }}"
|
||||
data-destination="{{ $mark->destination }}">
|
||||
{{ $mark->mark_no }} - {{ $mark->customer_name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Origin</label>
|
||||
<input type="text" class="form-control" name="origin" id="originField" readonly>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Destination</label>
|
||||
<input type="text" class="form-control" name="destination" id="destinationField" readonly>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Description</label>
|
||||
<input type="text" class="form-control" name="description" required>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2"><label class="form-label">CTN</label><input type="number" class="form-control" name="ctn"></div>
|
||||
<div class="col-md-2"><label class="form-label">QTY</label><input type="number" class="form-control" name="qty"></div>
|
||||
<div class="col-md-2"><label class="form-label">TTL/QTY</label><input type="number" class="form-control" name="ttl_qty"></div>
|
||||
<div class="col-md-2"><label class="form-label">Unit</label><input type="text" class="form-control" name="unit"></div>
|
||||
<div class="col-md-2"><label class="form-label">Price</label><input type="number" step="0.01" class="form-control" name="price"></div>
|
||||
<div class="col-md-2"><label class="form-label">TTL Amount</label><input type="number" step="0.01" class="form-control" name="ttl_amount"></div>
|
||||
<div class="col-md-2"><label class="form-label">CBM</label><input type="number" step="0.001" class="form-control" name="cbm"></div>
|
||||
<div class="col-md-2"><label class="form-label">TTL CBM</label><input type="number" step="0.001" class="form-control" name="ttl_cbm"></div>
|
||||
<div class="col-md-2"><label class="form-label">KG</label><input type="number" step="0.001" class="form-control" name="kg"></div>
|
||||
<div class="col-md-2"><label class="form-label">TTL KG</label><input type="number" step="0.001" class="form-control" name="ttl_kg"></div>
|
||||
<div class="col-md-3"><label class="form-label">Shop No</label><input type="text" class="form-control" name="shop_no"></div>
|
||||
|
||||
<div class="col-md-12 text-end">
|
||||
<button type="submit" class="btn btn-success mt-3">
|
||||
<i class="bi bi-save"></i> Submit Order
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Orders Table --}}
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header bg-light">
|
||||
<strong>Recent Orders</strong>
|
||||
</div>
|
||||
<div class="card-body table-responsive">
|
||||
<table class="table table-striped align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Order ID</th>
|
||||
<th>Mark No</th>
|
||||
<th>Description</th>
|
||||
<th>Origin</th>
|
||||
<th>Destination</th>
|
||||
<th>TTL Amount</th>
|
||||
<th>Status</th>
|
||||
<th>Date</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($orders as $index => $order)
|
||||
<tr>
|
||||
<td>{{ $index + 1 }}</td>
|
||||
<td><a href="{{ route('admin.orders.show', $order->id) }}">{{ $order->order_id }}</a></td>
|
||||
<td>{{ $order->mark_no }}</td>
|
||||
<td>{{ $order->description }}</td>
|
||||
<td>{{ $order->origin }}</td>
|
||||
<td>{{ $order->destination }}</td>
|
||||
<td>₹{{ number_format($order->ttl_amount, 2) }}</td>
|
||||
<td><span class="badge bg-info text-dark">{{ ucfirst($order->status) }}</span></td>
|
||||
<td>{{ $order->created_at->format('d-m-Y') }}</td>
|
||||
<td><a href="{{ route('admin.orders.show', $order->id) }}" class="btn btn-sm btn-outline-primary">View</a></td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="10" class="text-center">No orders found</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Autofill JS --}}
|
||||
<script>
|
||||
document.getElementById('markNoSelect').addEventListener('change', function() {
|
||||
const option = this.options[this.selectedIndex];
|
||||
document.getElementById('originField').value = option.dataset.origin || '';
|
||||
document.getElementById('destinationField').value = option.dataset.destination || '';
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
@@ -81,7 +81,10 @@
|
||||
<a href="{{ route('admin.customers') }}" class="{{ request()->routeIs('admin.customers') ? 'active' : '' }}"><i class="bi bi-people"></i> Customers</a>
|
||||
<a href="{{ route('admin.reports') }}" class="{{ request()->routeIs('admin.reports') ? 'active' : '' }}"><i class="bi bi-graph-up"></i> Reports</a>
|
||||
<a href="{{ route('admin.chat_support') }}" class="{{ request()->routeIs('admin.chat_support') ? 'active' : '' }}"><i class="bi bi-chat-dots"></i> Chat Support</a>
|
||||
<a href="{{ route('admin.orders') }}" class="{{ request()->routeIs('admin.orders') ? 'active' : '' }}"><i class="bi bi-bag"></i> Orders</a>
|
||||
<a href="{{ route('admin.orders.index') }}"
|
||||
class="{{ request()->routeIs('admin.orders.*') ? 'active' : '' }}">
|
||||
<i class="bi bi-bag"></i> Orders
|
||||
</a>
|
||||
<a href="{{ route('admin.requests') }}" class="{{ request()->routeIs('admin.requests') ? 'active' : '' }}"><i class="bi bi-envelope"></i> Requests</a>
|
||||
<a href="{{ route('admin.staff') }}" class="{{ request()->routeIs('admin.staff') ? 'active' : '' }}"><i class="bi bi-person-badge"></i> Staff</a>
|
||||
<a href="{{ route('admin.account') }}" class="{{ request()->routeIs('admin.account') ? 'active' : '' }}"><i class="bi bi-gear"></i> Account</a>
|
||||
|
||||
@@ -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');
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user