update marketing
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 5m14s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 17s
Build, Push and Deploy / deploy-staging (push) Successful in 41s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-05-14 11:55:22 +07:00
parent f80fcc4c1b
commit 05fd3230b8
448 changed files with 17545 additions and 5128 deletions

View File

@@ -10,21 +10,58 @@ class ExportCurrentStock implements FromView
{
public function view(): View
{
$query = Product::with('stocks')
->where('product_type', '!=', 'combo')
->where('business_id', auth()->user()->business_id);
$businessId = auth()->user()->business_id;
$alert_qty_filter = request('alert_qty');
$search_term = request('search');
$per_page = request('per_page', 20);
if (request('alert_qty')) {
$products = $query->get()->filter(function ($product) {
$totalStock = $product->stocks->sum('productStock');
return $totalStock <= $product->alert_qty;
// Base query
$query = Product::with('stocks', 'category:id,categoryName')
->where('product_type', '!=', 'combo')
->where('business_id', $businessId);
if ($search_term) {
$query->where(function ($q) use ($search_term) {
$q->where('productName', 'like', '%' . $search_term . '%')
->orWhere('productCode', 'like', '%' . $search_term . '%')
->orWhere('hsn_code', 'like', '%' . $search_term . '%')
->orWhereHas('category', function ($q) use ($search_term) {
$q->where('categoryName', 'like', '%' . $search_term . '%');
});
});
} else {
$products = $query->latest()->get();
}
return view('business::stocks.excel-csv', [
'products' => $products
]);
if ($alert_qty_filter) {
$products = $query
->withSum('stocks as total_stock', 'productStock')
->havingRaw('total_stock <= alert_qty')
->latest()
->limit($per_page)
->get();
$total_stock_qty = $products->sum('total_stock');
$total_stock_value = $products->sum(function ($product) {
return $product->stocks->sum(function ($stock) {
return $stock->productStock * $stock->productPurchasePrice;
});
});
} else {
$products = $query
->withSum('stocks as total_stock', 'productStock')
->latest()
->limit($per_page)
->get();
$total_stock_qty = $products->sum('total_stock');
$total_stock_value = $products->sum(function ($product) {
return $product->stocks->sum(function ($stock) {
return $stock->productStock * $stock->productPurchasePrice;
});
});
}
return view('business::stocks.excel-csv', compact('products', 'total_stock_qty', 'total_stock_value'));
}
}