Skip to content

Commit

Permalink
🚩applied sales report
Browse files Browse the repository at this point in the history
  • Loading branch information
remonhasanapu committed Nov 14, 2023
1 parent 6e7f411 commit 53d6ee8
Show file tree
Hide file tree
Showing 19 changed files with 572 additions and 122 deletions.
7 changes: 4 additions & 3 deletions app/Http/Controllers/Admin/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public function store(Request $request)
DB::beginTransaction();

Category::insert([
'name' => $request->name,
'slug' => strtolower(str_replace(' ', '-', $request->name)),
'status' => $request->status
'name' => $request->name,
'slug' => strtolower(str_replace(' ', '-', $request->name)),
'status' => $request->status,
'created_at' => now()
]);

DB::commit();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function pendingOrder()
{

// $pendingOrders = $this->orderModel->getPendingOrder();
$pendingOrders = Order::where('status', 'pending')->get();
$pendingOrders = Order::where('status', 'pending')->paginate(5);
$orderId = $pendingOrders[0]['id'];
$pendingOrderProducts = OrderProduct::where('order_id', $orderId)->get();
$pendingOrderAddress = OrderProduct::where('order_id', $orderId)->first();
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public function store(Request $request)
'subcategory_id' => $subcategoryId,
'image' => $imageUrl,
'slug' => strtolower(str_replace(' ', '-', $request->name)),
'status' => $request->status
'status' => $request->status,
'created_at' => now()
]);

Category::where('id', $categoryId)->increment('product_count', 1);
Expand Down
20 changes: 20 additions & 0 deletions app/Http/Controllers/Admin/ReportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Order;
use Illuminate\Http\Request;

class ReportController extends Controller
{
public function totalSaleReport()
{
$orderModel = new Order();
$orders = Order::latest()->paginate(5);
$orderId = $orders[0]['id'];
$totalSales = $orderModel->getTotalSaleReportByOrderId($orderId);

return view('admin.report.totalSale', compact('orders', 'totalSales'));
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/SubCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function store(Request $request)
'name' => $request->name,
'category_id' => $categoryId,
'slug' => strtolower(str_replace(' ', '-', $request->name)),
'status' => $request->status
'status' => $request->status,
'created_at' => now()
]);

Category::where('id', $categoryId)->increment('subcategory_count', 1);
Expand Down
32 changes: 20 additions & 12 deletions app/Http/Controllers/Frontend/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ public function placeOrder(Request $request)
$shippingAddress = Shipping::where('user_id', $userId)->first();
$checkTotalQuantity = $request->total_quantity;
$checkTotalPrice = $request->total_price;

$result = Order::insert([
'user_id' => $userId,
'quantity' => $request->total_quantity,
'total_price' => $request->total_price
'total_price' => $request->total_price,
'created_at' => now()
]);

if ($result) {
Expand All @@ -136,27 +137,34 @@ public function placeOrder(Request $request)
'address' => $shippingAddress->address,
'postal_code' => $shippingAddress->postal_code,
'quantity' => $cartItem->quantity,
'price' => $cartItem->price
'price' => $cartItem->price,
'created_at' => now()
]);

// Delete form cart after place order
$cartId = $cartItem->id;
Cart::findOrFail($cartId)->delete();
}
}
}

//Delete shipping address after place order
Shipping::where('user_id', $userId)->first()->delete();

// Get date after order placed
$placeOrders = $this->orderModel->getPlacedOrders($userId,$checkTotalQuantity,$checkTotalPrice);

$placeOrderId = $placeOrders->id;
$placeOrder = (object) ($placeOrders);
if (!empty($checkTotalQuantity)) {

// Get date after order placed
$placeOrders = $this->orderModel->getPlacedOrders($userId, $checkTotalQuantity, $checkTotalPrice);

$placeOrderId = $placeOrders->id;
$placeOrder = (object) ($placeOrders);

$placeOrderDetails = OrderProduct::where('order_id', $placeOrderId)->get();

return view('frontend.user.checkout', compact('checkTotalQuantity', 'checkTotalPrice'));
$placeOrderDetails = OrderProduct::where('order_id', $placeOrderId)->get();

return view('frontend.user.checkout', compact('checkTotalQuantity', 'checkTotalPrice'));

} else {
return redirect()->back();
}
}

public function userProfile()
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Category extends Model
protected $fillable = [
'name',
'slug',
'status'
'status',
'created_at'
];
}
20 changes: 19 additions & 1 deletion app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Order extends Model
'user_id',
'quantity',
'total_price',
'status'
'status',
'created_at'
];

public function getPendingOrder()
Expand Down Expand Up @@ -99,4 +100,21 @@ public function getPlacedOrders($userId, $totalQuantity, $totalPrice)
->where('orders.status', 'pending')
->first();
}

public function getTotalSaleReportByOrderId($orderId)
{
return DB::table('orders')
->leftjoin('users', 'orders.user_id', '=', 'users.id')
->leftjoin('order_products', 'orders.id', '=', 'order_products.order_id')
->leftjoin('products', 'order_products.product_id', '=', 'products.id')
->select(
'orders.*',
'users.name as user_name',
'products.name as product_name',
'orders.quantity as order_quantity',
'orders.total_price as order_total_price'
)
->where('order_products.order_id', $orderId)
->get();
}
}
3 changes: 2 additions & 1 deletion app/Models/OrderProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class OrderProduct extends Model
'city',
'postal_code',
'quantity',
'price'
'price',
'created_at'
];


Expand Down
3 changes: 2 additions & 1 deletion app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Product extends Model
'subcategory_id',
'image',
'slug',
'status'
'status',
'created_at'
];

public function geProductList()
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Subcategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Subcategory extends Model
'name',
'category_id',
'slug',
'status'
'status',
'created_at'
];

public function geSubcategoryList()
Expand Down
139 changes: 98 additions & 41 deletions resources/views/admin/category/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,69 @@
</div>
@endif

<div class="table-responsive text-nowrap">
<table class="table">

<thead class="table-light">
<tr>
<th>Id</th>
<th>Name</th>
<th>Total Subcategory</th>
<th>Slug</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>

<tbody class="table-border-bottom-0">
@foreach ($categories as $category)
<div class="container">
<div class="row mb-4">

<div class="col-md-6">
<label for="customerFilter">Filter by Name:</label>
<input type="text" id="customerFilter" class="form-control" oninput="filterTable()">
</div>
<div class="col-md-6">
<label for="statusFilter">Filter by Status:</label>
<select id="statusFilter" class="form-control" onchange="filterTable()">
<option value="">All</option>
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
</div>
</div>


<div class="table-responsive text-nowrap">
<table class="table" id="salesTable">

<thead class="table-primary">
<tr>
<td>{{ $category->id }}</td>
<td>{{ $category->name }}</td>
<td>{{ $category->subcategory_count }}</td>
<td>{{ $category->slug }}</td>
<td>
@if ($category->status == 1)
<span class="badge bg-label-success">Active</span>
@else
<span class="badge bg-label-danger">Inactive</span>
@endif
</td>
<td>
<a href="{{ route('edit.category', $category->id) }}" class="btn btn-info mr-3">
<i class="fa-solid fa-eye"></i>
</a>
<a href="{{ route('edit.category', $category->id) }}" class="btn btn-primary mr-3">
<i class="fa-solid fa-file-pen"></i>
</a>
<a href="{{ route('delete.category', $category->id) }}" class="btn btn-danger">
<i class="fa-solid fa-trash"></i>
</a>
</td>
<th>Id</th>
<th>Name</th>
<th>Total Subcategory</th>
<th>Slug</th>
<th>Status</th>
<th>Actions</th>
</tr>
@endforeach
</tbody>
</thead>

<tbody class="table-border-bottom-0">
@foreach ($categories as $category)
<tr>
<td>{{ $category->id }}</td>
<td>{{ $category->name }}</td>
<td>{{ $category->subcategory_count }}</td>
<td>{{ $category->slug }}</td>
<td>
@if ($category->status == 1)
<span class="badge bg-label-success">Active</span>
@else
<span class="badge bg-label-danger">Inactive</span>
@endif
</td>
<td>
<a href="{{ route('edit.category', $category->id) }}" class="btn btn-info mr-3">
<i class="fa-solid fa-eye"></i>
</a>
<a href="{{ route('edit.category', $category->id) }}" class="btn btn-primary mr-3">
<i class="fa-solid fa-file-pen"></i>
</a>
<a href="{{ route('delete.category', $category->id) }}" class="btn btn-danger">
<i class="fa-solid fa-trash"></i>
</a>
</td>
</tr>
@endforeach
</tbody>

</table>
</table>
</div>
</div>

</div>
Expand All @@ -78,3 +97,41 @@
</div>
</div>
@endsection

@push('script')
<script>
function filterTable() {
var inputCustomer, inputStatus, filterCustomer, filterStatus, table, tr, tdCustomer, tdStatus, i,
txtValueCustomer, txtValueStatus;
inputCustomer = document.getElementById("customerFilter");
inputStatus = document.getElementById("statusFilter");
filterCustomer = inputCustomer.value.toUpperCase();
filterStatus = inputStatus.value.toUpperCase(); // Ensure comparison in uppercase
table = document.getElementById("salesTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
tdCustomer = tr[i].getElementsByTagName("td")[1]; // Column index for Customer Name
tdStatus = tr[i].getElementsByTagName("td")[4]; // Column index for Status
if (tdCustomer && tdStatus) {
txtValueCustomer = tdCustomer.textContent || tdCustomer.innerText;
txtValueStatus = tdStatus.textContent || tdStatus.innerText;
var customerMatch = txtValueCustomer.toUpperCase().indexOf(filterCustomer) > -1;
var statusMatch = (filterStatus === "ALL" || (filterStatus === "ACTIVE" && txtValueStatus.trim() ===
"Active") || (filterStatus === "INACTIVE" && txtValueStatus.trim() === "Inactive"));
if (customerMatch && statusMatch) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
@endpush
2 changes: 2 additions & 0 deletions resources/views/admin/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@
<div class="card mt-3">
<h5 class="card-header">Recent Orders</h5>
<table class="table">
<thead class="table-primary">
<tr>
<th>Customer Name & Invoice</th>
<th>Product & Quantity</th>
<th>Total Price</th>
<th>Status</th>
</tr>
</thead>
<tbody class="table-border-bottom-0">
<tr>
<td>
Expand Down
Loading

0 comments on commit 53d6ee8

Please sign in to comment.