From 101f8402555154951a1ab59905458891892e0473 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 10 May 2019 19:31:52 +0800 Subject: [PATCH] [taxtxf] compact get-acct-tax-info --- gnucash/report/locale-specific/us/taxtxf.scm | 116 +++++-------------- 1 file changed, 28 insertions(+), 88 deletions(-) diff --git a/gnucash/report/locale-specific/us/taxtxf.scm b/gnucash/report/locale-specific/us/taxtxf.scm index 89ec7569f4..2a61b242b7 100644 --- a/gnucash/report/locale-specific/us/taxtxf.scm +++ b/gnucash/report/locale-specific/us/taxtxf.scm @@ -298,94 +298,34 @@ (string->symbol (if (string-null? code) "N000" code)))) (define (get-acct-txf-info info-type acct-type code) - (let ((tax-entity-type (gnc-get-current-book-tax-type))) - (cond - ((= acct-type ACCT-TYPE-INCOME) - (cond - ((eqv? info-type 'form) - (gnc:txf-get-form txf-income-categories code tax-entity-type)) - ((eqv? info-type 'desc) - (gnc:txf-get-description txf-income-categories code tax-entity-type)) - ((eqv? info-type 'pns) - (gnc:txf-get-payer-name-source txf-income-categories code - tax-entity-type)) - ((eqv? info-type 'format) - (gnc:txf-get-format txf-income-categories code tax-entity-type)) - ((eqv? info-type 'multiple) - (gnc:txf-get-multiple txf-income-categories code tax-entity-type)) - ((eqv? info-type 'cat-key) - (gnc:txf-get-category-key txf-income-categories code tax-entity-type)) - ((eqv? info-type 'line) - (gnc:txf-get-line-data txf-income-categories code tax-entity-type)) - ((eqv? info-type 'last-yr) - (gnc:txf-get-last-year txf-income-categories code tax-entity-type)) - (else #f))) - ((= acct-type ACCT-TYPE-EXPENSE) - (cond - ((eqv? info-type 'form) - (gnc:txf-get-form txf-expense-categories code tax-entity-type)) - ((eqv? info-type 'desc) - (gnc:txf-get-description txf-expense-categories code tax-entity-type)) - ((eqv? info-type 'pns) - (gnc:txf-get-payer-name-source txf-expense-categories code - tax-entity-type)) - ((eqv? info-type 'format) - (gnc:txf-get-format txf-expense-categories code tax-entity-type)) - ((eqv? info-type 'multiple) - (gnc:txf-get-multiple txf-expense-categories code tax-entity-type)) - ((eqv? info-type 'cat-key) - (gnc:txf-get-category-key txf-expense-categories code tax-entity-type)) - ((eqv? info-type 'line) - (gnc:txf-get-line-data txf-expense-categories code tax-entity-type)) - ((eqv? info-type 'last-yr) - (gnc:txf-get-last-year txf-expense-categories code tax-entity-type)) - (else #f))) - ((or (= acct-type ACCT-TYPE-BANK) (= acct-type ACCT-TYPE-CASH) - (= acct-type ACCT-TYPE-ASSET) (= acct-type ACCT-TYPE-STOCK) - (= acct-type ACCT-TYPE-MUTUAL) (= acct-type ACCT-TYPE-RECEIVABLE)) - (cond - ((eqv? info-type 'form) - (gnc:txf-get-form txf-asset-categories code tax-entity-type)) - ((eqv? info-type 'desc) - (gnc:txf-get-description txf-asset-categories code tax-entity-type)) - ((eqv? info-type 'pns) - (gnc:txf-get-payer-name-source txf-asset-categories code - tax-entity-type)) - ((eqv? info-type 'format) - (gnc:txf-get-format txf-asset-categories code tax-entity-type)) - ((eqv? info-type 'multiple) - (gnc:txf-get-multiple txf-asset-categories code tax-entity-type)) - ((eqv? info-type 'cat-key) - (gnc:txf-get-category-key txf-asset-categories code tax-entity-type)) - ((eqv? info-type 'line) - (gnc:txf-get-line-data txf-asset-categories code tax-entity-type)) - ((eqv? info-type 'last-yr) - (gnc:txf-get-last-year txf-asset-categories code tax-entity-type)) - (else #f))) - ((or (= acct-type ACCT-TYPE-CREDIT) (= acct-type ACCT-TYPE-LIABILITY) - (= acct-type ACCT-TYPE-EQUITY) (= acct-type ACCT-TYPE-PAYABLE)) - (cond - ((eqv? info-type 'form) - (gnc:txf-get-form txf-liab-eq-categories code tax-entity-type)) - ((eqv? info-type 'desc) - (gnc:txf-get-description txf-liab-eq-categories code tax-entity-type)) - ((eqv? info-type 'pns) - (gnc:txf-get-payer-name-source txf-liab-eq-categories code - tax-entity-type)) - ((eqv? info-type 'format) - (gnc:txf-get-format txf-liab-eq-categories code tax-entity-type)) - ((eqv? info-type 'multiple) - (gnc:txf-get-multiple txf-liab-eq-categories code tax-entity-type)) - ((eqv? info-type 'cat-key) - (gnc:txf-get-category-key txf-liab-eq-categories code tax-entity-type)) - ((eqv? info-type 'line) - (gnc:txf-get-line-data txf-liab-eq-categories code tax-entity-type)) - ((eqv? info-type 'last-yr) - (gnc:txf-get-last-year txf-liab-eq-categories code tax-entity-type)) - (else #f))) - (else #f)) - ) -) + (let ((categories (assv-ref + (list (cons ACCT-TYPE-INCOME txf-income-categories) + (cons ACCT-TYPE-EXPENSE txf-expense-categories) + (cons ACCT-TYPE-BANK txf-asset-categories) + (cons ACCT-TYPE-CASH txf-asset-categories) + (cons ACCT-TYPE-ASSET txf-asset-categories) + (cons ACCT-TYPE-STOCK txf-asset-categories) + (cons ACCT-TYPE-MUTUAL txf-asset-categories) + (cons ACCT-TYPE-RECEIVABLE txf-asset-categories) + (cons ACCT-TYPE-CREDIT txf-liab-eq-categories) + (cons ACCT-TYPE-LIABILITY txf-liab-eq-categories) + (cons ACCT-TYPE-EQUITY txf-liab-eq-categories) + (cons ACCT-TYPE-PAYABLE txf-liab-eq-categories)) + acct-type)) + (get-info-fn + (case info-type + ((form) gnc:txf-get-form) + ((desc) gnc:txf-get-description) + ((pns) gnc:txf-get-payer-name-sourcecategories) + ((format) gnc:txf-get-formatcategories) + ((multiple) gnc:txf-get-multiplecategories) + ((cat-key) gnc:txf-get-category-keycategories) + ((line) gnc:txf-get-line-datacategories) + ((last-yr) gnc:txf-get-last-yearcategories) + (else #f)))) + (and categories + get-info-fn + (get-info-fn categories code (gnc-get-current-book-tax-type))))) (define (gnc:account-get-txf-payer-source account) (let ((pns (xaccAccountGetTaxUSPayerNameSource account)))