Sfoglia il codice sorgente

balance formatting

Innokentiy Enikeev 8 anni fa
parent
commit
c60197ffdb
1 ha cambiato i file con 10 aggiunte e 11 eliminazioni
  1. 10 11
      pta-ledger.lisp

+ 10 - 11
pta-ledger.lisp

@@ -95,19 +95,18 @@
                   (add-amounts! (gethash "TOTALS" balance) amounts))))))))
 
 (defun format-balance (balance)
-  (let* ((accounts (alexandria:hash-table-keys balance))
-         (max-account-length (if accounts (apply #'max (mapcar #'length accounts)) 20)))
+  (let* ((accounts (alexandria:hash-table-keys balance)))
     (with-output-to-string (s)
       (loop for account in (sort accounts #'string<)
-         for amounts = (gethash account balance)
-         when (find 0 amounts :test-not #'= :key #'amount-quantity)
-         do (format s "~vA  ~$ ~A~{~%~va  ~$ ~A~}~%" max-account-length account
-                    (amount-quantity (car amounts)) (amount-commodity (car amounts))
-                    (apply #'append (mapcar #'(lambda (a)
-                                                (list max-account-length ""
-                                                      (amount-quantity a)
-                                                      (amount-commodity a)))
-                                            (rest amounts))))))))
+         for amounts = (remove 0 (gethash account balance) :test #'equal :key #'amount-quantity)
+	 do (loop for amount in amounts
+	       for first = t then nil
+	       for amount-text = (render amount)
+	       do (format s "~vA ~A~%"
+			  (- *posting-length*
+			     (position #\Space amount-text))
+			  (if first account "")
+			  amount-text))))))
 
 (defun journal-balance (journal &optional query)
   (format-balance (balance (entries journal)