Always sort credit before payment before fee.

This commit is contained in:
Dominik Pantůček 2023-06-24 21:44:29 +02:00
parent b8f95657da
commit f297e876cc

View file

@ -283,6 +283,20 @@
"Credit"))
crs))
;; Sorting order number
(define (balance-type->number t)
(if (equal? t "Credit")
0
(if (equal? t "Payment")
1
2)))
;; Sorting on the same day
(define (balance-type<? a b)
(let ((an (balance-type->number a))
(bn (balance-type->number b)))
(< an bn)))
;; Returns a single credit/debit list of payments and fees
;; calendar. The result is a list of lists:
;; (list balance day amount currency message/comment czk-amount type-string)
@ -293,7 +307,10 @@
(all-unsorted (append mcal pmts crs))
(all (sort all-unsorted
(lambda (a b)
(cal-day<? (car a) (car b))))))
(if (cal-day=? (car a) (car b))
(balance-type<? (list-ref a 5)
(list-ref b 5))
(cal-day<? (car a) (car b)))))))
(let loop ((trs all)
(rbls '())
(bal 0))