branch: elpa/csv2ledger
commit 6e9838193e8243a7502fd5c725acf5cbeba6ee9c
Author: Joost Kremers <joostkrem...@fastmail.fm>
Commit: Joost Kremers <joostkrem...@fastmail.fm>

    New function: `c2l-payee-or-sender`.
    
    Default value of `c2l-title-function`.
---
 csv2ledger.el | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/csv2ledger.el b/csv2ledger.el
index e01d8ecc1a..179933ad63 100644
--- a/csv2ledger.el
+++ b/csv2ledger.el
@@ -158,6 +158,20 @@ format, it just splits DATE on the separator, reverses the 
date
 parts and joins them again."
   (string-join (nreverse (split-string date "[./-]" t "[[:space:]]")) "-"))
 
+(defun c2l-payee-or-sender (entry)
+  "Return payee or sender based on `c2l-account-holder'.
+This function is for use as the value of `c2l-title-function'.
+ENTRY should be an alist containing field-value pairs for an
+entry and should contain values for `payee' and `sender'.  If the
+value of `c2l-account-holder' matches the payee, the sender is
+returned, otherwise the payee is returned."
+  (let ((payee (alist-get 'payee entry))
+        (sender (alist-get 'sender entry)))
+    (if (and (stringp c2l-account-holder)
+             (string-match-p c2l-account-holder payee))
+        sender
+      payee)))
+
   "Create a ledger entry.
 DATE, TITLE, AMOUNT are used to create the entry.  DESCRIPTION,
 if non-nil, is added as a comment, preceded by \"Desc:\".  FROM

Reply via email to