Compare commits
2 Commits
fix/add-me
...
claude/pra
| Author | SHA1 | Date | |
|---|---|---|---|
| b0282b7f8b | |||
| ac72905ecb |
@@ -13,6 +13,16 @@ export class JournalEntriesService {
|
||||
async findAll(filters: { from?: string; to?: string; accountId?: string; type?: string }) {
|
||||
let sql = `
|
||||
SELECT je.*,
|
||||
CASE
|
||||
WHEN SUM(CASE WHEN a.account_type IN ('income','expense') THEN 1 ELSE 0 END) > 0
|
||||
THEN COALESCE(SUM(CASE WHEN a.account_type IN ('income','expense') THEN jel.debit ELSE 0 END), 0)
|
||||
ELSE COALESCE(SUM(jel.debit), 0)
|
||||
END as total_debit,
|
||||
CASE
|
||||
WHEN SUM(CASE WHEN a.account_type IN ('income','expense') THEN 1 ELSE 0 END) > 0
|
||||
THEN COALESCE(SUM(CASE WHEN a.account_type IN ('income','expense') THEN jel.credit ELSE 0 END), 0)
|
||||
ELSE COALESCE(SUM(jel.credit), 0)
|
||||
END as total_credit,
|
||||
json_agg(json_build_object(
|
||||
'id', jel.id, 'account_id', jel.account_id,
|
||||
'debit', jel.debit, 'credit', jel.credit, 'memo', jel.memo,
|
||||
|
||||
Reference in New Issue
Block a user