Add pricing entry flow and platform admin foundations
This commit is contained in:
@@ -16,14 +16,18 @@ class ClinicFinanceRepository {
|
||||
int limit = 30,
|
||||
}) async {
|
||||
final filterParts = ['tenant_id = "$tenantId"', 'type = "payable"'];
|
||||
if (status != null) filterParts.add('status = "$status"');
|
||||
if (status == FinanceStatus.pending.value) {
|
||||
filterParts.add('(status = "pending" || status = "reported")');
|
||||
} else if (status != null) {
|
||||
filterParts.add('status = "$status"');
|
||||
}
|
||||
|
||||
final result = await _pb.collection('finance_entries').getList(
|
||||
page: page,
|
||||
perPage: limit,
|
||||
filter: filterParts.join(' && '),
|
||||
expand: 'job_id',
|
||||
);
|
||||
page: page,
|
||||
perPage: limit,
|
||||
filter: filterParts.join(' && '),
|
||||
expand: 'job_id',
|
||||
);
|
||||
return (result.items.map((r) => FinanceEntry.fromJson(r.toJson())).toList()
|
||||
..sort((a, b) => (b.dateCreated ?? '').compareTo(a.dateCreated ?? '')));
|
||||
}
|
||||
@@ -32,7 +36,7 @@ class ClinicFinanceRepository {
|
||||
final all = await listEntries(tenantId, limit: 200);
|
||||
double pending = 0, paid = 0;
|
||||
for (final e in all) {
|
||||
if (e.status == FinanceStatus.pending) {
|
||||
if (e.status.isOpen) {
|
||||
pending += e.amount;
|
||||
} else {
|
||||
paid += e.amount;
|
||||
@@ -41,15 +45,17 @@ class ClinicFinanceRepository {
|
||||
return {'pending': pending, 'paid': paid};
|
||||
}
|
||||
|
||||
Future<List<CounterpartyFinanceSummary>> byCounterparty(String tenantId) async {
|
||||
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 key =
|
||||
entry.counterpartyTenantId ?? entry.counterpartyName ?? 'unknown';
|
||||
final current = map[key];
|
||||
final pending = (current?.pendingAmount ?? 0) +
|
||||
(entry.status == FinanceStatus.pending ? entry.amount : 0);
|
||||
(entry.status.isOpen ? entry.amount : 0);
|
||||
final paid = (current?.paidAmount ?? 0) +
|
||||
(entry.status == FinanceStatus.paid ? entry.amount : 0);
|
||||
map[key] = CounterpartyFinanceSummary(
|
||||
@@ -67,16 +73,16 @@ class ClinicFinanceRepository {
|
||||
return list;
|
||||
}
|
||||
|
||||
Future<void> markPaid(String entryId) async {
|
||||
Future<void> reportPayment(String entryId) async {
|
||||
final record = await _pb.collection('finance_entries').getOne(entryId);
|
||||
final jobId = record.data['job_id']?.toString();
|
||||
if (jobId == null || jobId.isEmpty) {
|
||||
await _pb.collection('finance_entries').update(entryId, body: {
|
||||
'status': 'paid',
|
||||
'paid_at': DateTime.now().toIso8601String(),
|
||||
'status': 'reported',
|
||||
'paid_at': null,
|
||||
});
|
||||
return;
|
||||
}
|
||||
await FinanceService.instance.markJobPaid(jobId);
|
||||
await FinanceService.instance.reportJobPayment(jobId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user