2026-03-15 17:08:23 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Modules\Business\App\Exports;
|
|
|
|
|
|
|
|
|
|
use App\Models\Product;
|
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
|
use Maatwebsite\Excel\Concerns\FromView;
|
|
|
|
|
|
|
|
|
|
class ExportCurrentStockReport implements FromView
|
|
|
|
|
{
|
|
|
|
|
public function view(): View
|
|
|
|
|
{
|
2026-05-14 11:55:22 +07:00
|
|
|
$productsQuery = Product::with(['stocks' => function ($q) {
|
|
|
|
|
$q->select('id', 'product_id', 'productStock', 'productPurchasePrice', 'productSalePrice');
|
|
|
|
|
}])
|
|
|
|
|
->where('business_id', auth()->user()->business_id)
|
|
|
|
|
->where('product_type', '!=', 'combo');
|
|
|
|
|
|
|
|
|
|
if (request('search')) {
|
|
|
|
|
$productsQuery->where(function ($q) {
|
|
|
|
|
$q->where('productName', 'like', '%' . request('search') . '%')
|
|
|
|
|
->orWhereHas('stocks', function ($stock) {
|
|
|
|
|
$stock->where('productSalePrice', 'like', '%' . request('search') . '%')
|
|
|
|
|
->orWhere('productPurchasePrice', 'like', '%' . request('search') . '%');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$stock_reports = $productsQuery
|
|
|
|
|
->latest()
|
|
|
|
|
->limit($request->per_page ?? 20)
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
return view('business::reports.stocks.excel-csv', compact('stock_reports'));
|
2026-03-15 17:08:23 +07:00
|
|
|
}
|
|
|
|
|
}
|