|
|
@@ -7,9 +7,20 @@
|
|
|
|
|
|
class TreasuryAccountService
|
|
|
{
|
|
|
- public function getAll(): Collection
|
|
|
+ /**
|
|
|
+ * Lista as contas de tesouraria por escopo:
|
|
|
+ * - franqueador (rede/conta-mãe): sem unit_id => contas com unit_id null;
|
|
|
+ * - franchisee: unit_id da unidade ativa => contas daquela unidade.
|
|
|
+ */
|
|
|
+ public function getAll(?int $unitId = null): Collection
|
|
|
{
|
|
|
- return TreasuryAccount::orderBy('created_at', 'desc')
|
|
|
+ return TreasuryAccount::query()
|
|
|
+ ->when(
|
|
|
+ $unitId !== null,
|
|
|
+ fn ($query) => $query->where('unit_id', $unitId),
|
|
|
+ fn ($query) => $query->whereNull('unit_id'),
|
|
|
+ )
|
|
|
+ ->orderBy('created_at', 'desc')
|
|
|
->get();
|
|
|
}
|
|
|
|
|
|
@@ -20,6 +31,9 @@ public function findById(int $id): ?TreasuryAccount
|
|
|
|
|
|
public function create(array $data): TreasuryAccount
|
|
|
{
|
|
|
+ // Sem unit_id => conta da rede (franqueador). Com unit_id => conta da unidade (franchisee).
|
|
|
+ $data['unit_id'] = $data['unit_id'] ?? null;
|
|
|
+
|
|
|
return TreasuryAccount::create($data);
|
|
|
}
|
|
|
|