Files
kulakpos_web/Modules/Business/App/Exports/ExportCustomerLedger.php
eko54r 05fd3230b8
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
update marketing
2026-05-14 11:55:22 +07:00

46 lines
1.5 KiB
PHP

<?php
namespace Modules\Business\App\Exports;
use App\Models\Party;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportCustomerLedger implements FromView
{
public function view(): View
{
$customers = Party::with('sales')
->where('business_id', auth()->user()->business_id)
->where('type', '!=', 'Supplier')
->when(request('search'), function ($q) {
$q->where(function ($q) {
$q->where('name', 'like', '%' . request('search') . '%')
->orWhere('phone', 'like', '%' . request('search') . '%')
->orWhere('type', 'like', '%' . request('search') . '%');
});
})
->when(request('type'), function ($q) {
$q->where(function ($q) {
$q->where('type', request('type'));
});
})
->latest()
->limit(request('per_page') ?? 20)->get();
$totalAmount = $customers->sum(function ($customer) {
return $customer->sales?->sum('totalAmount') ?? 0;
});
$totalPaid = $customers->sum(function ($customer) {
return $customer->sales?->sum('paidAmount') ?? 0;
});
$totalDue = $customers->sum(function ($customer) {
return $customer->sales?->sum('dueAmount') ?? 0;
});
return view('business::party-reports.customer-ledger.excel-csv', compact('customers', 'totalAmount', 'totalPaid', 'totalDue'));
}
}