"Added orders management functionality to AdminController, including orders listing and status update, and updated routes and admin header view accordingly."

This commit is contained in:
UronShrestha 2024-07-16 11:04:46 +05:45
parent 9c427917b8
commit 12aef87712
4 changed files with 204 additions and 3 deletions

View File

@ -2,8 +2,10 @@
namespace App\Http\Controllers;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\DB;
use App\Models\User;
use App\Models\Order;
use Illuminate\Http\Request;
@ -191,4 +193,29 @@ class AdminController extends Controller
}
return redirect()->back();
}
public function orders()
{
if (session()->get('type') == 'Admin') {
$orders = DB::table('users')
->join('orders', 'orders.customerId', 'users.id')
->select('orders.*', 'users.name', 'users.email', 'users.status as userStatus')
->get();
return view('Dashboard.orders', compact('orders'));
}
return redirect()->back();
}
public function changeOrderStatus($status, $id)
{
if (session()->get('type') == 'Admin') {
$order = Order::find($id);
$order->status = $status;
$order->save();
return redirect()->back()->with('success', 'Order Status Changed Successfully');
}
return redirect()->back();
}
}

View File

@ -0,0 +1,173 @@
<x-adminheader />
<!-- partial -->
<div class="main-panel">
<div class="content-wrapper">
<div class="row">
<div class="col-md-12 grid-margin">
<div class="row">
<div class="col-12 col-xl-8 mb-4 mb-xl-0">
<h3 class="font-weight-bold">Welcome Aamir</h3>
<h6 class="font-weight-normal mb-0">All systems are running smoothly!
</h6>
</div>
<div class="col-12 col-xl-4">
<div class="justify-content-end d-flex">
<div class="dropdown flex-md-grow-1 flex-xl-grow-0">
<button class="btn btn-sm btn-light bg-white dropdown-toggle" type="button"
id="dropdownMenuDate2" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="true">
<i class="mdi mdi-calendar"></i> Today (10 Jan 2021)
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuDate2">
<a class="dropdown-item" href="#">January - March</a>
<a class="dropdown-item" href="#">March - June</a>
<a class="dropdown-item" href="#">June - August</a>
<a class="dropdown-item" href="#">August - November</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<!-- Button to Open the Modal -->
{{-- <button type="button" class="btn btn-primary float-right" data-toggle="modal"
data-target="#myModal">
Add New
</button> --}}
<!-- The Modal -->
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title"> Add New Product</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger"
data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<p class="card-title mb-0">Our Orders</p>
<div class="table-responsive">
<table class="table table-striped table-bordered" id="product-table">
<thead>
<tr>
<th>ID</th>
<th>Customer Name</th>
<th> Customer Status</th>
<th>Phone</th>
<th>Address</th>
<th>Email</th>
<th>Bill</th>
<th> Status</th>
<th>Order Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@php
$i = 0;
@endphp
@foreach ($orders as $order)
@php
$i++;
@endphp
<tr>
<td>{{ $i }}</td>
<td>{{ $order->name }}</td>
<td>
@if ($order->userStatus == 'Active')
<span
class="badge badge-success d-flex justify-content-center">Active</span>
@else
<span
class="badge badge-danger d-flex justify-content-center">Blocked</span>
@endif
</td>
<td>{{ $order->phone }}</td>
<td>{{ $order->address }}</td>
<td>{{ $order->email }}</td>
<td>NRs {{ $order->bill }}</td>
<td>
<div class="badge badge-light d-flex justify-content-center">
{{ $order->status }}
</div>
{{-- @if ($order->status == 'Pending')
<span
class="badge badge-warning d-flex justify-content-center">Pending</span>
@elseif ($order->status == 'Paid')
<span
class="badge badge-info d-flex justify-content-center">Paid</span>
@elseif ($order->status == 'Delivered')
<span
class="badge badge-success d-flex justify-content-center">Delivered</span>
@elseif ($order->status == 'Rejected')
<span
class="badge badge-danger d-flex justify-content-center">Rejected</span>
@endif
</td> --}}
<td>{{ $order->created_at }}</td>
<td>
@if ($order->status == 'Paid')
<a href="{{ route('changeOrderStatus', ['status' => 'Accepted', 'id' => $order->id]) }}"
class="btn btn-info">Accept</a>
<a href="{{ route('changeOrderStatus', ['status' => 'Rejected', 'id' => $order->id]) }}"
class="btn btn-danger">Reject</a>
@elseif ($order->status == 'Accepted')
<a href="{{ route('changeOrderStatus', ['status' => 'Delivered', 'id' => $order->id]) }}"
class="btn btn-success">Completed</a>
@elseif ($order->status == 'Delivered')
Deliver Complete
@else
<a href="{{ route('changeOrderStatus', ['status' => 'Accepted', 'id' => $order->id]) }}"
class="btn btn-info">Accept</a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- content-wrapper ends -->
<x-adminfooter />

View File

@ -389,7 +389,7 @@
</a>
<div class="collapse" id="charts">
<ul class="nav flex-column sub-menu">
<li class="nav-item"> <a class="nav-link" href="#">View
<li class="nav-item"> <a class="nav-link" href="{{ route('ourOrders') }}">View
All</a></li>
</ul>
</div>

View File

@ -19,7 +19,8 @@ Route::get('/deleteProduct/{id}', [AdminController::class, 'deleteProduct'])->na
Route::get('/adminProfile', [AdminController::class, 'profile'])->name('adminProfile');
Route::get('/ourCustomers', [AdminController::class, 'customers'])->name('ourCustomers');
Route::get('/changeUserStatus/{status}/{id}', [AdminController::class, 'changeUserStatus'])->name('changeUserStatus');
Route::get('/changeOrderStatus/{status}/{id}', [AdminController::class, 'changeOrderStatus'])->name('changeOrderStatus');
Route::get('/ourOrders', [AdminController::class, 'orders'])->name('ourOrders');
//customer routes