|
|
@@ -7,9 +7,19 @@
|
|
|
|
|
|
class FinancialPlanAccountService
|
|
|
{
|
|
|
- public function getAll(): Collection
|
|
|
+ /**
|
|
|
+ * Plano de contas por escopo: franqueador (matriz) usa unit_id null;
|
|
|
+ * franchisee usa o unit_id da unidade. Ordenado por código (1.1, 1.1.1, ...).
|
|
|
+ */
|
|
|
+ public function getAll(?int $unitId = null): Collection
|
|
|
{
|
|
|
- return FinancialPlanAccount::orderBy('created_at', 'desc')
|
|
|
+ return FinancialPlanAccount::query()
|
|
|
+ ->when(
|
|
|
+ $unitId !== null,
|
|
|
+ fn ($query) => $query->where('unit_id', $unitId),
|
|
|
+ fn ($query) => $query->whereNull('unit_id'),
|
|
|
+ )
|
|
|
+ ->orderBy('code')
|
|
|
->get();
|
|
|
}
|
|
|
|
|
|
@@ -20,6 +30,9 @@ public function findById(int $id): ?FinancialPlanAccount
|
|
|
|
|
|
public function create(array $data): FinancialPlanAccount
|
|
|
{
|
|
|
+ $data['unit_id'] = $data['unit_id'] ?? null;
|
|
|
+ $data['order'] = $data['order'] ?? $data['code'];
|
|
|
+
|
|
|
return FinancialPlanAccount::create($data);
|
|
|
}
|
|
|
|