feat(payments): add customer ledgers and allocations (#744)

This commit is contained in:
Darko Gjorgjijoski
2026-08-05 03:28:35 +02:00
committed by GitHub
parent 8ae82ae91e
commit f322c2b74d
74 changed files with 5693 additions and 693 deletions
@@ -8,13 +8,16 @@ use App\Http\Requests\DeleteCustomersRequest;
use App\Http\Resources\CustomerResource;
use App\Models\Customer;
use App\Services\CustomerService;
use App\Services\CustomerStatementService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
class CustomersController extends Controller
{
public function __construct(
private readonly CustomerService $customerService,
private readonly CustomerStatementService $customerStatementService,
) {}
/**
@@ -31,10 +34,12 @@ class CustomersController extends Controller
$customers = Customer::with('creator')
->whereCompany()
->applyFilters($request->all())
->withSum('invoices as base_due_amount', 'base_due_amount')
->withSum('invoices as due_amount', 'due_amount')
->paginateData($limit);
$this->customerStatementService->hydrateAccountSummaries(
$customers instanceof LengthAwarePaginator ? $customers->getCollection() : $customers
);
return CustomerResource::collection($customers)
->additional(['meta' => [
'customer_total_count' => Customer::whereCompany()->count(),
@@ -52,6 +57,7 @@ class CustomersController extends Controller
$this->authorize('create', Customer::class);
$customer = $this->customerService->create($request);
$this->customerStatementService->hydrateAccountSummaries([$customer]);
return new CustomerResource($customer);
}
@@ -65,6 +71,8 @@ class CustomersController extends Controller
{
$this->authorize('view', $customer);
$this->customerStatementService->hydrateAccountSummaries([$customer]);
return new CustomerResource($customer);
}
@@ -79,6 +87,7 @@ class CustomersController extends Controller
$this->authorize('update', $customer);
$customer = $this->customerService->update($request, $customer);
$this->customerStatementService->hydrateAccountSummaries([$customer]);
return new CustomerResource($customer);
}