27 lines
758 B
PHP
27 lines
758 B
PHP
<?php
|
|
|
|
namespace Modules\Business\App\Exports;
|
|
|
|
use App\Models\Party;
|
|
use Illuminate\Contracts\View\View;
|
|
use Maatwebsite\Excel\Concerns\FromView;
|
|
|
|
class ExportTopSupplier implements FromView
|
|
{
|
|
public function view(): View
|
|
{
|
|
$suppliers = Party::with('purchases')
|
|
->where('business_id', auth()->user()->business_id)
|
|
->where('type', '=', 'Supplier')
|
|
->whereHas('purchases')
|
|
->withCount('purchases')
|
|
->withSum('purchases', 'totalAmount')
|
|
->orderByDesc('purchases_count')
|
|
->orderByDesc('purchases_sum_total_amount')
|
|
->take(5)
|
|
->get();
|
|
|
|
return view('business::party-reports.top-suppliers.excel-csv', compact('suppliers'));
|
|
}
|
|
}
|