[report-utilities] gnc:strify add invoice->str, refine owner->str

This commit is contained in:
Christopher Lam
2019-10-27 11:05:19 +08:00
parent 77855a7ed6
commit eb929fd6d3

View File

@@ -1138,16 +1138,25 @@ flawed. see report-utilities.scm. please update reports.")
(format #f "[~a]"
(gnc:monetary->string mon)))
(define (owner->str owner)
(define (fn s . rest) (format #f "[~a:~a]" s ((apply compose rest) owner)))
(let ((t (gncOwnerGetType owner)))
(cond
((eqv? t GNC-OWNER-NONE) "[None]")
((eqv? t GNC-OWNER-UNDEFINED) "[Undefined]")
((eqv? t GNC-OWNER-JOB) (fn "Job" owner->str gncOwnerGetEndOwner))
((eqv? t GNC-OWNER-CUSTOMER) (fn "Cust" gncCustomerGetName gncOwnerGetCustomer))
((eqv? t GNC-OWNER-VENDOR) (fn "Vend" gncVendorGetName gncOwnerGetVendor))
((eqv? t GNC-OWNER-EMPLOYEE) (fn "Emp" gncEmployeeGetName gncOwnerGetEmployee))
(else (format #f "[unknown:~a]" owner)))))
(define owner-alist
(list (cons GNC-OWNER-NONE "None")
(cons GNC-OWNER-UNDEFINED "Undefined")
(cons GNC-OWNER-JOB "Job")
(cons GNC-OWNER-CUSTOMER "Cust")
(cons GNC-OWNER-VENDOR "Vend")
(cons GNC-OWNER-EMPLOYEE "Emp")))
(format #f "[~a:~a]"
(or (assv-ref owner-alist (gncOwnerGetType owner)) "Owner")
(gncOwnerGetName owner))))
(define (invoice->str inv)
(format #f "~a<Post:~a,Owner:~a,Notes:~a,Total:~a>"
(gncInvoiceGetTypeString inv)
(qof-print-date (gncInvoiceGetDatePosted inv))
(gncOwnerGetName (gncInvoiceGetOwner inv))
(gncInvoiceGetNotes inv)
(monetary->string (gnc:make-gnc-monetary
(gncInvoiceGetCurrency inv)
(gncInvoiceGetTotal inv)))))
(define (try proc)
;; Try proc with d as a parameter, catching exceptions to return
;; #f to the (or) evaluator below.
@@ -1177,6 +1186,7 @@ flawed. see report-utilities.scm. please update reports.")
(try monetary->string)
(try gnc-budget-get-name)
(try owner->str)
(try invoice->str)
(object->string d)))
(define (pair->num pair)