feat: improve patient flow and pricing workflow
This commit is contained in:
@@ -39,4 +39,30 @@ class LabFinanceRepository {
|
||||
}
|
||||
return {'pending': pending, 'paid': paid};
|
||||
}
|
||||
|
||||
Future<List<CounterpartyFinanceSummary>> byCounterparty(String tenantId) async {
|
||||
final entries = await listEntries(tenantId, limit: 300);
|
||||
final map = <String, CounterpartyFinanceSummary>{};
|
||||
|
||||
for (final entry in entries) {
|
||||
final key = entry.counterpartyTenantId ?? entry.counterpartyName ?? 'unknown';
|
||||
final current = map[key];
|
||||
final pending = (current?.pendingAmount ?? 0) +
|
||||
(entry.status == FinanceStatus.pending ? entry.amount : 0);
|
||||
final paid = (current?.paidAmount ?? 0) +
|
||||
(entry.status == FinanceStatus.paid ? entry.amount : 0);
|
||||
map[key] = CounterpartyFinanceSummary(
|
||||
counterpartyTenantId: entry.counterpartyTenantId,
|
||||
counterpartyName: entry.counterpartyName ?? 'Karşı Taraf',
|
||||
currency: entry.currency,
|
||||
pendingAmount: pending,
|
||||
paidAmount: paid,
|
||||
entryCount: (current?.entryCount ?? 0) + 1,
|
||||
);
|
||||
}
|
||||
|
||||
final list = map.values.toList();
|
||||
list.sort((a, b) => b.pendingAmount.compareTo(a.pendingAmount));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user