update marketing
All checks were successful
All checks were successful
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user