"Updated AdminController and orders.blade.php to display order items, added modal to view order details, and made minor changes to adminheader.blade.php"

This commit is contained in:
UronShrestha 2024-07-16 13:50:22 +05:45
parent 12aef87712
commit 7670867b62
4 changed files with 290 additions and 66 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use App\Models\User; use App\Models\User;
use App\Models\Order; use App\Models\Order;
use App\Models\OrderItem;
@ -194,19 +195,44 @@ class AdminController extends Controller
return redirect()->back(); return redirect()->back();
} }
//old orders
public function orders() public function orders()
{ {
if (session()->get('type') == 'Admin') { if (session()->get('type') == 'Admin') {
$orderItems = DB::table('order_items')
->join('products', 'order_items.productId', 'products.id')
->select('products.name', 'products.picture', 'order_items.*')
->get();
$orders = DB::table('users') $orders = DB::table('users')
->join('orders', 'orders.customerId', 'users.id') ->join('orders', 'orders.customerId', 'users.id')
->select('orders.*', 'users.name', 'users.email', 'users.status as userStatus') ->select('orders.*', 'users.name', 'users.email', 'users.status as userStatus')
->get(); ->get();
return view('Dashboard.orders', compact('orders')); return view('Dashboard.orders', compact('orders', 'orderItems'));
} }
return redirect()->back(); return redirect()->back();
} }
//new orders
// public function orders()
// {
// if (session()->get('type') == 'Admin') {
// $orderItems = DB::table('order_items')
// ->join('products', 'order_items.productId', 'products.id')
// ->select('products.name as productName', 'products.picture', 'order_items.*')
// ->get();
// $orders = DB::table('users')
// ->join('orders', 'orders.customerId', 'users.id')
// ->select('orders.*', 'users.name as userName', 'users.email', 'users.status as userStatus')
// ->get();
// return view('Dashboard.orders', compact('orders', 'orderItems'));
// }
// return redirect()->back();
// }
public function changeOrderStatus($status, $id) public function changeOrderStatus($status, $id)
{ {

View File

@ -1,5 +1,190 @@
{{-- new --}}
<x-adminheader /> <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">
<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>View</th>
<th>Order Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($orders as $order)
<tr>
<td>{{ $loop->iteration }}</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>
</td>
<td>
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-light" data-toggle="modal"
data-target="#orderModal{{ $order->id }}">
<i class="fas fa-eye"></i>
</button>
</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>
<!-- Modals -->
@foreach ($orders as $order)
<div class="modal fade" id="orderModal{{ $order->id }}" tabindex="-1" role="dialog"
aria-labelledby="orderModalLabel{{ $order->id }}" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Ordered Products</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<!-- Modal Body -->
<div class="modal-body">
<div style="overflow-x: auto;">
<table class="table table-striped table-bordered modal-table">
<thead>
<tr>
<th>Name</th>
<th>Picture</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
@foreach ($orderItems as $orderDetail)
@if ($order->id == $orderDetail->orderId)
<tr>
<td>{{ $orderDetail->name }}</td>
<td><img src="{{ asset('uploads/products/' . $orderDetail->picture) }}"
class="img-fluid rounded-circle"
alt="" width= "100px"
height="100px">
<td>{{ $orderDetail->quantity }}</td>
<td>{{ $orderDetail->price }}</td>
<td>{{ $orderDetail->quantity * $orderDetail->price }}
</td>
</tr>
@endif
@endforeach
</tbody>
<tfoot>
<tr>
<td colspan="4" style="text-align: center;">
<strong>Sub Total</strong>
</td>
<td><strong>{{ $order->bill }}</strong></td>
</tr>
</tfoot>
</table>
</div>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger"
data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
</div>
</div>
<!-- content-wrapper ends -->
<x-adminfooter />
{{-- <x-adminheader />
<!-- partial --> <!-- partial -->
<div class="main-panel"> <div class="main-panel">
<div class="content-wrapper"> <div class="content-wrapper">
@ -38,38 +223,7 @@
<div class="col-md-12 grid-margin stretch-card"> <div class="col-md-12 grid-margin stretch-card">
<div class="card"> <div class="card">
<div class="card-body"> <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> <p class="card-title mb-0">Our Orders</p>
<div class="table-responsive"> <div class="table-responsive">
@ -84,6 +238,7 @@
<th>Email</th> <th>Email</th>
<th>Bill</th> <th>Bill</th>
<th> Status</th> <th> Status</th>
<th>View</th>
<th>Order Date</th> <th>Order Date</th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
@ -119,24 +274,84 @@
<div class="badge badge-light d-flex justify-content-center"> <div class="badge badge-light d-flex justify-content-center">
{{ $order->status }} {{ $order->status }}
</div> </div>
<td>
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-light" data-toggle="modal"
data-target="#orderModal">
<i class="fas fa-eye"></i>
</button>
<!-- The Modal -->
@foreach ($orders as $order)
<div class="modal" id="orderModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Ordered Products</h4>
<button type="button" class="close"
data-dismiss="modal">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div style="overflow-x: auto;">
<table>
<thead>
<tr>
<th>Name</th>
<th>Picture</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
@foreach ($orderItems as $orderDetail)
@if ($orderDetail->orderId == $order->id)
<tr>
<td>{{ $orderDetail->name }}
</td>
<td><img src="{{ asset('uploads/products/' . $orderDetail->picture) }}"
class="img-fluid rounded-circle"
alt=""
width= "100px"
height="100px">
</td>
<td>{{ $orderDetail->quantity }}
</td>
<td>{{ $orderDetail->price }}
</td>
<td>{{ $orderDetail->quantity * $orderDetail->price }}
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger"
data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@endforeach
</td>
{{-- @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>{{ $order->created_at }}</td>
<td> <td>
@if ($order->status == 'Paid') @if ($order->status == 'Paid')
@ -170,4 +385,4 @@
</div> </div>
<!-- content-wrapper ends --> <!-- content-wrapper ends -->
<x-adminfooter /> <x-adminfooter /> --}}

View File

@ -11,6 +11,7 @@
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> --}} <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> --}}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<!-- Required meta tags --> <!-- Required meta tags -->
<meta charset="utf-8"> <meta charset="utf-8">

View File

@ -74,24 +74,6 @@
</thead> </thead>
{{-- old tbody --}}
{{-- <tbody>
@foreach ($items as $product)
@if ($product->order_id == $item->id)
<tr>
<td>{{ $product->name }}</td>
<td><img src="{{ asset('uploads/products/' . $product->picture) }}"
alt="" width= "100px"
height="100px"></td>
<td>{{ $product->quantity }}</td>
<td>{{ $product->price }}</td>
<td>{{ $product->price * $product->quantity }}
</td>
</tr>
@endif
@endforeach
</tbody> --}}
{{-- new tbody --}} {{-- new tbody --}}
<tbody> <tbody>
@foreach ($items as $product) @foreach ($items as $product)