31 lines
827 B
PHP
31 lines
827 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Modules\Business\App\Exports;
|
||
|
|
|
||
|
|
use App\Models\Product;
|
||
|
|
use Illuminate\Contracts\View\View;
|
||
|
|
use Maatwebsite\Excel\Concerns\FromView;
|
||
|
|
|
||
|
|
class ExportCurrentStock implements FromView
|
||
|
|
{
|
||
|
|
public function view(): View
|
||
|
|
{
|
||
|
|
$query = Product::with('stocks')
|
||
|
|
->where('product_type', '!=', 'combo')
|
||
|
|
->where('business_id', auth()->user()->business_id);
|
||
|
|
|
||
|
|
if (request('alert_qty')) {
|
||
|
|
$products = $query->get()->filter(function ($product) {
|
||
|
|
$totalStock = $product->stocks->sum('productStock');
|
||
|
|
return $totalStock <= $product->alert_qty;
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$products = $query->latest()->get();
|
||
|
|
}
|
||
|
|
|
||
|
|
return view('business::stocks.excel-csv', [
|
||
|
|
'products' => $products
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|