feat: improve patient flow and pricing workflow
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
import '../../../core/api/pocketbase_client.dart';
|
||||
import '../../../core/services/finance_service.dart';
|
||||
import '../../../models/finance_entry.dart';
|
||||
|
||||
class ClinicFinanceRepository {
|
||||
@@ -40,10 +41,42 @@ class ClinicFinanceRepository {
|
||||
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;
|
||||
}
|
||||
|
||||
Future<void> markPaid(String entryId) async {
|
||||
await _pb.collection('finance_entries').update(entryId, body: {
|
||||
'status': 'paid',
|
||||
'paid_at': DateTime.now().toIso8601String(),
|
||||
});
|
||||
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(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
await FinanceService.instance.markJobPaid(jobId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user