r19611 - gnucash/trunk/src - Bug #554396: Implement a partial TXF output for capital gains

Christian Stimming cstim at code.gnucash.org
Fri Sep 24 15:48:02 EDT 2010


Author: cstim
Date: 2010-09-24 15:48:02 -0400 (Fri, 24 Sep 2010)
New Revision: 19611
Trac: http://svn.gnucash.org/trac/changeset/19611

Modified:
   gnucash/trunk/src/gnome/dialog-tax-info.c
   gnucash/trunk/src/report/locale-specific/us/taxtxf.scm
   gnucash/trunk/src/tax/us/txf-help.scm
   gnucash/trunk/src/tax/us/txf.scm
Log:
Bug #554396: Implement a partial TXF output for capital gains

Modified: gnucash/trunk/src/gnome/dialog-tax-info.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-tax-info.c	2010-09-24 19:38:46 UTC (rev 19610)
+++ gnucash/trunk/src/gnome/dialog-tax-info.c	2010-09-24 19:48:02 UTC (rev 19611)
@@ -279,6 +279,9 @@
         const gchar *str;
         const gchar *last_yr = _("Last Valid Year: ");
         const gchar *form_line = _("Form Line Data: ");
+        const gchar *code_line_word = _("Code");
+        const gchar *code_line_colon = ": ";
+        gchar *num_code = NULL;
         gchar *form_line_data = NULL;
         SCM scm;
         gint year;
@@ -304,6 +307,8 @@
 
         str = scm_is_symbol(code_scm) ? SCM_SYMBOL_CHARS(code_scm) : "";
         txf_info->code = g_strdup (str);
+        num_code = g_strdup (str);
+        num_code++; /* to lose the leading N */
 
         scm = scm_call_3 (getters.form, category, code_scm, tax_entity_type);
         str = scm_is_string(scm) ? scm_to_locale_string(scm) : "";
@@ -323,8 +328,6 @@
         {
             const gchar *until = _("now");
 
-            if (year != 0)
-                until = g_strdup_printf ("%d", year);
             form_line_data = g_strconcat ("\n", "\n", form_line, NULL);
             while (!scm_is_null (scm))
             {
@@ -355,17 +358,23 @@
         {
             if (form_line_data != NULL)
                 txf_info->help = g_strconcat (last_yr, g_strdup_printf ("%d", year),
-                                              "\n", "\n", str, form_line_data, NULL);
+                                              "\n", "\n", str, "\n", "\n",
+                                              code_line_word, code_line_colon, num_code,
+                                              form_line_data, NULL);
             else
                 txf_info->help = g_strconcat (last_yr, g_strdup_printf ("%d", year),
-                                              "\n", "\n", str, NULL);
+                                              "\n", "\n", str, "\n", "\n",
+                                              code_line_word, code_line_colon, num_code, NULL);
         }
         else
         {
             if (form_line_data != NULL)
-                txf_info->help = g_strconcat (str, form_line_data, NULL);
+                txf_info->help = g_strconcat (str, "\n", "\n",
+                                              code_line_word, code_line_colon, num_code,
+                                              form_line_data, NULL);
             else
-                txf_info->help = g_strdup (str);
+                txf_info->help = g_strconcat (str, "\n", "\n",
+                                              code_line_word, code_line_colon, num_code, NULL);
         }
 
         if (form_line_data != NULL)

Modified: gnucash/trunk/src/report/locale-specific/us/taxtxf.scm
===================================================================
--- gnucash/trunk/src/report/locale-specific/us/taxtxf.scm	2010-09-24 19:38:46 UTC (rev 19610)
+++ gnucash/trunk/src/report/locale-specific/us/taxtxf.scm	2010-09-24 19:48:02 UTC (rev 19611)
@@ -48,6 +48,10 @@
 ;; Update from "V037" to "V041"
 ;; Add support for taxpayer types other than F1040 
 ;;
+;; September, 2010 Update:
+;;
+;; Add support for code N673, Format 4
+;;
 ;; From prior version:
 ;; NOTE: setting of specific dates is squirly! and seems
 ;; to be current-date dependant!  Actually, time of day dependant!  Just
@@ -383,7 +387,7 @@
   )
 )
 
-(define (render-account-detail-header-row table suppress-action-memo? beg-bal?)
+(define (render-account-detail-header-row table suppress-action-memo? format4?)
   (gnc:html-table-append-row!
        table
        (append (list (gnc:make-html-table-header-cell/markup
@@ -398,7 +402,10 @@
                              "Notes"
                              "Notes/Action:Memo")))
                (list (gnc:make-html-table-header-cell/markup
-                          "column-heading-center" "Transfer To/From Account(s)"))
+                          "column-heading-center"
+                         (if format4?
+                             "Capital Gains Data"
+                             "Transfer To/From Account(s)")))
                (list (gnc:make-html-table-header-cell/markup
                               "column-heading-center" "Amount"))
        )
@@ -406,7 +413,8 @@
 )
 
 (define (render-total-row table total-amount total-line-text tax_code?
-                          transaction-details? end-bal-text total-amount-neg?)
+                          transaction-details? end-bal-text total-amount-neg?
+                          format4? cap-gain-sales-total cap-gain-basis-total)
   (let ((description (gnc:make-html-text))
         (total (gnc:make-html-text)))
        (if (or tax_code? transaction-details?)
@@ -428,12 +436,19 @@
                                        (gnc:make-html-table-cell/markup
                                             "column-heading-right" description)
                                    (gnc:make-html-table-cell description)))
-             (amount-table (gnc:make-html-table))) ;; to line up totals to details
+             (amount-table (gnc:make-html-table)) ;; to line up totals to details
+             (cap-gains-detail-table (gnc:make-html-table))
+            )
             (gnc:html-table-set-style! amount-table "table" 
                                           'attribute (list "border" "0")
                                           'attribute (list "cellspacing" "0")
                                           'attribute (list "cellpadding" "0")
                                           'attribute (list "width" "100%"))
+            (gnc:html-table-set-style! cap-gains-detail-table "table" 
+                                          'attribute (list "border" "0")
+                                          'attribute (list "cellspacing" "0")
+                                          'attribute (list "cellpadding" "0")
+                                          'attribute (list "width" "100%"))
             (let ((total-amnt (if total-amount-neg?
                                   (gnc:make-html-table-cell/markup
                                              "number-cell-bot-neg" total)
@@ -442,18 +457,45 @@
                  )
                  (gnc:html-table-append-row! amount-table total-amnt)
             )
-            (gnc:html-table-cell-set-colspan! description-cell 5)
-            (gnc:html-table-append-row!
-                 table
-                 (append (list description-cell)
-                         (list (gnc:make-html-table-cell/markup
-                                           "number-cell-bot" amount-table))))
+            (if format4?
+                (let* ((total-cell (gnc:make-html-table-cell/markup
+                                    "column-heading-right"
+                                    "Capital Gains Totals: Sales Amount: "))
+                       (combined-cell (gnc:make-html-table-cell))
+                      )
+                      (gnc:html-table-cell-append-objects!
+                         total-cell
+                         cap-gain-sales-total
+                         " Cost/Basis: Not Available"
+                      )
+                      (gnc:html-table-append-row! cap-gains-detail-table
+                            (append (list total-cell)))
+                      (gnc:html-table-append-row! cap-gains-detail-table
+                            (append (list description-cell)))
+                      (gnc:html-table-cell-append-objects!
+                         combined-cell
+                         cap-gains-detail-table
+                      )
+                      (gnc:html-table-cell-set-colspan! combined-cell 5)
+                      (gnc:html-table-append-row! table
+                            (append (list combined-cell)
+                                    (list (gnc:make-html-table-cell/markup
+                                              "number-cell-bot" amount-table))))
+                )
+                (begin
+                   (gnc:html-table-cell-set-colspan! description-cell 5)
+                   (gnc:html-table-append-row! table
+                            (append (list description-cell)
+                                    (list (gnc:make-html-table-cell/markup
+                                              "number-cell-bot" amount-table))))
+                )
+            ) ;; end of if
        ) ;; end of let
   ) ;; end of let
 )
 
 (define (render-txf-account account account-value d? date x? x-date
-                            type code copy tax-entity-type)
+                            type code copy tax-entity-type sold-desc)
   (let* ((print-info (gnc-account-print-info account #f))
          (value (xaccPrintAmount account-value print-info))
          (txf? (gnc:account-get-txf account)))
@@ -465,7 +507,7 @@
                (x-date-str (if x-date
                                (strftime "%m/%d/%Y" (localtime (car x-date)))
                                #f))
-               ;; Only formats 1,3,6 implemented now! Others are treated as 1.
+               ;; Only formats 1,3,4,6 implemented now! Others are treated as 1.
                (format (get-acct-txf-info 'format type code))
                (action (if (eq? type ACCT-TYPE-INCOME)
                            (case code
@@ -520,14 +562,15 @@
           ;; 2      S    T, N, C, L, P                Spec unclear, unverified
           ;; 3      D    T, N, C, L, $, X             Spec clear & verified Q98
           ;; 3      S    T, N, C, L, $, P             Spec clear & verified Q98
-          ;; 4      D    T, N, C, L, P, D, D, $, $    Spec clear, unverified
+          ;; 4      D    T, N, C, L, P, D, D, $, $, X Spec clear, unverified
           ;; 4      S    T, N, C, L, $, $             Spec unclear, unverified
           ;; 5      D    T, N, C, L, P, D, D, $, $, $ Spec unclear, unverified
           ;; 5      S    T, N, C, L, $, $, $          Spec unclear, unverified
           ;; 6      D    T, N, C, L, D, $, P, X       Spec unclear, verified Q98
           ;; 6      S    T, N, C, L, $                Spec unclear, verified Q98
           ;;
-          ;; For F1040, support only formats 1, 3 and 6 (based on Q98)
+          ;; For F1040, support only formats 1, 3 and 6 (based on Q98) and
+          ;;    for 4 (guessed at) for code 673 only (no date acquired or basis)
           ;; For F1065, F1120 and F1120S, support only format 1
           ;;
           (list (if x? "TD" "TS") crlf
@@ -540,12 +583,18 @@
                 ;; these apply if pns is either 'current or 'parent', but not
                 ;; otherwise
                 "L" (number->string txf-l-count) crlf 
+                (if (= format 4)
+                    (if x?
+                        (list "P" sold-desc crlf "D" crlf "D" date-str crlf
+                                                                       "$" crlf)
+                        (list "$" crlf))
+                    '())
                 (if (and d? (= format 6) x?)
                     (list "D" date-str crlf)
                     '())
                 (case format
-                  ((1 3 6) (list value crlf))
-                  ((0 2 4 5) '()))
+                  ((1 3 4 6) (list value crlf))
+                  ((0 2 5) '()))
                 (case format
                   ((3) (if (not x?) (list "P" txf-account-name crlf) '()))
                   ((6) (if x?
@@ -733,11 +782,59 @@
 
 (define (process-transaction-multi-transfer-detail split parent
             USD-currency full-names? trans-date trans-currency acct-type
-            currency-conversion-date to-date transfer-table print-amnt)
+            currency-conversion-date to-date transfer-table print-amnt format
+            split-details? tax-mode? account account-type tax-code copy
+            tax-entity-type)
   (let* ((all-tran-splits (xaccTransGetSplitList parent))
          (tran-splits-to-render (- (length all-tran-splits) 1))
+         (acct-print-info (gnc-account-print-info account #f))
+         (output '())
          (trans-rpt-currency-total (gnc-numeric-zero)) ;;for USD-currency
+         (cap-gains-detail-table (gnc:make-html-table))
+         (trans-sub-heading-table (gnc:make-html-table))
+         (trans-sub-table (gnc:make-html-table))
+         (trans-cap-gain-sales-USD-total (gnc-numeric-zero))
+         (trans-cap-gain-basis-USD-total (gnc-numeric-zero))
         )
+        (if (= 4 format)
+            (begin
+               (gnc:html-table-set-style! cap-gains-detail-table "table" 
+                                          'attribute (list "border" "0")
+                                          'attribute (list "cellspacing" "0")
+                                          'attribute (list "cellpadding" "3")
+                                          'attribute (list "width" "100%"))
+               (gnc:html-table-set-style! trans-sub-heading-table "table" 
+                                          'attribute (list "cellspacing" "0")
+                                          'attribute (list "cellpadding" "0")
+                                          'attribute (list "width" "100%"))
+               (gnc:html-table-set-style! trans-sub-table "table" 
+                                          'attribute (list "border" "0")
+                                          'attribute (list "cellspacing" "0")
+                                          'attribute (list "cellpadding" "0")
+                                          'attribute (list "width" "100%"))
+               (gnc:html-table-append-row! cap-gains-detail-table
+                      (append (list (gnc:make-html-table-cell/markup
+                                           "column-heading-center" "Item"))
+                              (list (gnc:make-html-table-cell/markup
+                                           "column-heading-center"
+                                           "Date Acquired"))
+                              (list (gnc:make-html-table-cell/markup
+                                           "column-heading-center"
+                                           "Date Sold"))
+                              (list (gnc:make-html-table-cell/markup
+                                           "column-heading-center"
+                                           "Sales Amount"))
+                              (list (gnc:make-html-table-cell/markup
+                                           "column-heading-center"
+                                           "Cost/Basis"))
+                      )
+               )
+               (gnc:html-table-append-row! trans-sub-heading-table
+                      (append (list (gnc:make-html-table-header-cell/markup
+                                          "column-heading-center"
+                                          "Transfer To/From Account(s)"))))
+            )
+        )
         (map (lambda (tran-split)
              (if (not (xaccSplitEqual split tran-split #t #f #f))
                  (let* ((split-acct (xaccSplitGetAccount tran-split))
@@ -747,6 +844,7 @@
                         (splt-amnt (if (eq? acct-type ACCT-TYPE-INCOME)
                                             splt-amnt
                                             (gnc-numeric-neg splt-amnt)))
+                        (print-info (gnc-account-print-info split-acct #f))
                         (splt-curr-conv-note "")
                         (splt-curr-conv-data (list splt-amnt
                                                    splt-curr-conv-note #f ""))
@@ -768,8 +866,7 @@
                                                          to-date)
                                                      trans-currency
                                                      splt-amnt
-                                                     (gnc-account-print-info
-                                                                 split-acct #f)
+                                                     print-info
                                                      (if (eq? acct-type
                                                                ACCT-TYPE-INCOME)
                                                           #f
@@ -801,6 +898,82 @@
                            )
                            #f
                        )
+                       (if (and (= 4 format) (gnc-numeric-negative-p
+                                               (xaccSplitGetAmount tran-split)))
+                           (begin
+                              (if tax-mode? 
+                                (gnc:html-table-append-row!
+                                     cap-gains-detail-table
+                                     (append (list (gnc:make-html-table-cell
+                                                    (string-append 
+                                                      (xaccPrintAmount
+                                                       (gnc-numeric-neg 
+                                                        (xaccSplitGetAmount
+                                                                 tran-split))
+                                                                     print-info)
+                                                      " "
+                                                      (gnc-commodity-get-mnemonic 
+                                                        split-acct-commodity))))
+                                             (list (gnc:make-html-table-cell/markup
+                                                    "text-cell-center"
+                                                    "Not Available"))
+                                             (list (gnc:make-html-table-cell/markup
+                                                    "text-cell-center"
+                                                  (strftime "%Y-%b-%d" (localtime
+                                                            (car trans-date)))))
+                                             (list (gnc:make-html-table-cell/markup
+                                                    "number-cell-bot"
+                                                    (xaccPrintAmount
+                                                       (gnc-numeric-neg
+                                                              splt-print-amnt)
+                                                              acct-print-info)))
+                                             (list (gnc:make-html-table-cell/markup
+                                                    "number-cell-bot"
+                                                    "Not Available"))
+                                     )
+                                )
+                                (let ((cap-gain-output
+                                       (list (render-txf-account
+                                               account
+                                               splt-print-amnt
+                                               #f
+                                               trans-date
+                                               #t
+                                               trans-date
+                                               account-type
+                                               tax-code
+                                               copy
+                                               tax-entity-type
+                                               (string-append 
+                                                (xaccPrintAmount
+                                                 (gnc-numeric-neg 
+                                                  (xaccSplitGetAmount
+                                                        tran-split)) print-info)
+                                               " "
+                                               (gnc-commodity-get-mnemonic 
+                                                          split-acct-commodity))
+                                             )))
+                                     )
+                                     (set! output
+                                          (if (null? output)
+                                              (if (null? cap-gain-output)
+                                                  '()
+                                                  (list cap-gain-output))
+                                              (if (null? cap-gain-output)
+                                                  (list output)
+                                                  (list output
+                                                        cap-gain-output)))
+                                     )
+                                )
+                              )
+                              (set! trans-cap-gain-sales-USD-total
+                                          (gnc-numeric-add-fixed
+                                              trans-cap-gain-sales-USD-total
+                                              (gnc-numeric-neg splt-print-amnt))
+                              )
+;                              (set! trans-cap-gain-basis-USD-total #f)
+                           )
+                       )
                        (let* ((splt-amnt-anchor (gnc:html-split-anchor
                                                             tran-split
                                                             splt-print-amnt))
@@ -811,11 +984,18 @@
                                      (gnc:make-html-table-cell/markup
                                          "number-cell-bot" splt-amnt-anchor)))
                              )
-                             (gnc:html-table-append-row!
-                                  transfer-table
-                                  (append (list cell)
-                                          (list splt-amnt-anchor
-                                          )))
+                             (if (= 4 format)
+                                 (gnc:html-table-append-row!
+                                      trans-sub-table
+                                      (append (list cell)
+                                              (list splt-amnt-anchor
+                                              )))
+                                 (gnc:html-table-append-row!
+                                      transfer-table
+                                      (append (list cell)
+                                              (list splt-amnt-anchor
+                                              )))
+                             )
                        )
                        (set! trans-rpt-currency-total (gnc-numeric-add-fixed
                                 trans-rpt-currency-total
@@ -842,13 +1022,52 @@
                                         (gnc:make-html-table-cell/markup
                                             "number-cell-bot" plug-amnt)))
                         )
-                        (gnc:html-table-append-row! transfer-table
-                                                    (append
-                                                      (list conversion-cell)
-                                                      (list  plug-amnt)))
+                        (if (= 4 format)
+                            (gnc:html-table-append-row! trans-sub-table
+                                      (append (list conversion-cell)
+                                              (list plug-amnt)))
+                            (gnc:html-table-append-row! transfer-table
+                                      (append (list conversion-cell)
+                                              (list plug-amnt)))
+                        )
                   )
             )
         ) ;; end of if
+        (if (= 4 format)
+            (let* ((total-cell (gnc:make-html-table-cell/markup
+                                    "column-heading-right" "Totals: "))
+                  )
+                  (gnc:html-table-cell-set-colspan! total-cell 3)
+                  (gnc:html-table-append-row! cap-gains-detail-table
+                        (append (list total-cell)
+                                (list (gnc:make-html-table-cell/markup
+                                                  "number-cell-bot"
+                                                  (xaccPrintAmount
+                                                   trans-cap-gain-sales-USD-total
+                                                          acct-print-info)))
+                                (list (gnc:make-html-table-cell/markup
+                                                  "number-cell-bot"
+                                                  "Not Available"))
+                        )
+                  )
+                  (gnc:html-table-append-row! transfer-table
+                        (append (list (gnc:make-html-table-cell
+                                           cap-gains-detail-table))))
+                  (if split-details?
+                      (begin
+                      (gnc:html-table-append-row! transfer-table
+                            (append (list (gnc:make-html-table-cell
+                                               trans-sub-heading-table))))
+                      (gnc:html-table-append-row! transfer-table
+                            (append (list (gnc:make-html-table-cell
+                                               trans-sub-table))))
+                      )
+                  )
+            )
+        )
+        (list trans-cap-gain-sales-USD-total
+              trans-cap-gain-basis-USD-total
+              output)
   ) ;; end of let*
 )
 
@@ -871,6 +1090,8 @@
      (account-commodity-total (gnc-numeric-zero))
      (account-commodity-total-as-dr (gnc-numeric-zero))
      (account-USD-total (gnc-numeric-zero))
+     (account-cap-gain-sales-USD-total (gnc-numeric-zero))
+     (account-cap-gain-basis-USD-total (gnc-numeric-zero))
      (account-desc (string-append
                       acct-full-name
                       (if (gnc-commodity-equiv account-commodity USD-currency)
@@ -919,7 +1140,8 @@
         (begin ;; print account header for all accts
           (render-header-row table (string-append
                                     "       " account-desc))
-          (render-account-detail-header-row table suppress-action-memo? #f)
+          (render-account-detail-header-row table suppress-action-memo?
+                                                        (if (= format 4) #t #f))
         ))
     (if (not (or (eq? account-type ACCT-TYPE-INCOME)
                  (eq? account-type ACCT-TYPE-EXPENSE)))
@@ -1142,6 +1364,7 @@
                                                                   other-account)
                                               (xaccAccountGetName other-account)
                                           )))
+                  (cap-gain-txf-output '())
                   ;; use tables within cells for all items so that row lines up
                   ;; properly
                   (date-table (gnc:make-html-table))
@@ -1162,11 +1385,19 @@
                  (acct-collector-as-dr 'add account-commodity splt-amount)
                  (set! account-USD-total (gnc-numeric-add-fixed
                                               account-USD-total print-amnt))
-                 (if (and transaction-details? tax-mode?)
-                     (begin
-                       (if (and (null? other-account) split-details?)
-                           (process-transaction-multi-transfer-detail
-                                             split parent
+                 ;; for capital gains format 4, we need to go get data from the
+                 ;; transaction-multi-transfer-detail routine for TXF output and
+                 ;; to accumulate capital gains totals for account-, tax-code-,
+                 ;; and form-level totals even when not printing transaction
+                 ;; details and/or Transfer To/From Accounts 
+                 (if (or (and transaction-details? tax-mode?
+                                        (null? other-account) split-details?)
+                         (= 4 format)
+                     )
+                     (let ((cap-gain-data 
+                                      (process-transaction-multi-transfer-detail
+                                             split
+                                             parent
                                              USD-currency
                                              full-names?
                                              trans-date
@@ -1174,7 +1405,31 @@
                                              account-type
                                              currency-conversion-date
                                              to-value
-                                             transfer-table print-amnt))
+                                             transfer-table
+                                             print-amnt
+                                             format
+                                             split-details?
+                                             tax-mode?
+                                             account
+                                             account-type
+                                             tax-code
+                                             copy
+                                             tax-entity-type))
+                          )
+                          (set! account-cap-gain-sales-USD-total
+                                          (gnc-numeric-add-fixed
+                                              account-cap-gain-sales-USD-total
+                                              (car cap-gain-data))
+                          )
+                          (set! account-cap-gain-basis-USD-total
+                                          (gnc-numeric-add-fixed
+                                              account-cap-gain-basis-USD-total
+                                              (cadr cap-gain-data))
+                          )
+                          (set! cap-gain-txf-output (caddr cap-gain-data))
+                     ))
+                 (if (and transaction-details? tax-mode?)
+                     (begin
                        (gnc:html-table-set-style! date-table "table" 
                                           'attribute (list "border" "0")
                                           'attribute (list "cellspacing" "0")
@@ -1309,7 +1564,9 @@
                  ;; for quarterly estimated tax payments, we need to go
                  ;; get data from splits for TXF output
                  (if (and (txf-special-split? tax-code) (not tax-mode?))
-                     (render-txf-account account
+                     (list cap-gain-txf-output
+                           (render-txf-account
+                                       account
                                        (if (or (and print-amnt-is-dr?
                                                     splt-amount-is-dr?)
                                                (and (not print-amnt-is-dr?)
@@ -1319,7 +1576,9 @@
                                            (gnc-numeric-neg print-amnt))
                                        #t fudge-date  #t trans-date
                                        account-type tax-code copy
-                                       tax-entity-type)
+                                       tax-entity-type #f)
+                     )
+                     cap-gain-txf-output
                  )
            ) ;;end of let*
            ) ;;end of lambda
@@ -1337,6 +1596,14 @@
                                                 print-info))
                (account-total-amount (xaccPrintAmount account-USD-total
                                                 print-info))
+               (account-cap-gain-sales-total-amount
+                                     (xaccPrintAmount
+                                                account-cap-gain-sales-USD-total
+                                                print-info))
+               (account-cap-gain-basis-total-amount
+                                     (xaccPrintAmount
+                                                account-cap-gain-basis-USD-total
+                                                print-info))
                (account-total-line-text
                   (string-append (if transaction-details?
                                      "Account: "
@@ -1377,6 +1644,11 @@
                                 (if (gnc-numeric-negative-p account-USD-total)
                                     #t
                                     #f)
+                                (if (= format 4)
+                                    #t
+                                    #f)
+                                account-cap-gain-sales-total-amount
+                                account-cap-gain-basis-total-amount
               )
         ) ;; end of let*
     ) ;; end of if
@@ -1387,7 +1659,10 @@
                   (and (gnc-numeric-negative-p account-USD-total)
                        (gnc-numeric-negative-p account-commodity-total-as-dr)))
               account-USD-total
-              (gnc-numeric-neg account-USD-total)))
+              (gnc-numeric-neg account-USD-total))
+          account-cap-gain-sales-USD-total
+          account-cap-gain-basis-USD-total
+    )
   ) ;;end of let*
 )
 
@@ -1518,7 +1793,7 @@
                         (set! txf-invalid-alist (assoc-set!
                                  txf-invalid-alist
                                  tax-code
-                                 (list (_"Set as tax-related, but assigned tax code no longer valid for tax year")
+                                 (list "Set as tax-related, but assigned tax code no longer valid for tax year"
                                        account-name form account)))
                         selected-accounts-sorted-by-form-line-acct)
                      );; end if
@@ -1526,7 +1801,7 @@
                          (set! txf-invalid-alist (assoc-set!
                                  txf-invalid-alist
                                  tax-code
-                                 (list (_"Set as tax-related, tax code assigned for different tax entity type")
+                                 (list "Set as tax-related, tax code assigned for different tax entity type"
                                        account-name form account)))
                         selected-accounts-sorted-by-form-line-acct)
                     )
@@ -1541,7 +1816,7 @@
                           (set! txf-invalid-alist (assoc-set!
                                    txf-invalid-alist
                                    tax-code
-                                   (list (_"Set as not tax-related, tax code assigned for different tax entity type")
+                                   (list "Set as not tax-related, tax code assigned for different tax entity type"
                                          account-name form account)))
                       )
                     selected-accounts-sorted-by-form-line-acct)
@@ -1903,6 +2178,8 @@
                                      to-value)))
               (split-list (make-split-list account split-filter-pred))
               (account-USD-total (gnc-numeric-zero))
+              (account-cap-gain-sales-USD-total (gnc-numeric-zero))
+              (account-cap-gain-basis-USD-total (gnc-numeric-zero))
               (form-line-acct-text (string-append
                                          "Form or Schedule / Line (TXF Code"
                                          (if show-TXF-data?
@@ -1993,18 +2270,28 @@
                            (account-USD-total-as-dr (caddr tran-output))
                           )
                           (set! account-USD-total (car tran-output))
+                          (set! account-cap-gain-sales-USD-total
+                                                    (cadddr tran-output))
+                          (set! account-cap-gain-basis-USD-total
+                                                    (car (cddddr tran-output)))
                           (list
                             account-USD-total
-                            (if (not (txf-special-split? tax-code))
+                            (if (or (txf-special-split? tax-code)
+                                    (= 4 (get-acct-txf-info
+                                                   'format
+                                                   (xaccAccountGetType account)
+                                                   tax-code)))
+                                tran-txf
                                 (if (not tax-mode?)
                                     (render-txf-account account
                                             account-USD-total-as-dr
                                                   #f #f #t from-value
                                                   account-type tax-code copy
-                                                  tax-entity-type)
-                                    '())
-                                tran-txf)
+                                                  tax-entity-type #f)
+                                    '()))
                             account-USD-total-as-dr
+                            account-cap-gain-sales-USD-total
+                            account-cap-gain-basis-USD-total
                           )
                     )
                  )
@@ -2013,6 +2300,8 @@
                         (list account-USD-total
                               '()
                               account-USD-total
+                              account-cap-gain-sales-USD-total
+                              account-cap-gain-basis-USD-total
                         )
                         (begin
                            (if need-form-line-acct-header?
@@ -2030,7 +2319,10 @@
                            )
                            (list account-USD-total
                                  '()
-                                 account-USD-total)
+                                 account-USD-total
+                                 account-cap-gain-sales-USD-total
+                                 account-cap-gain-basis-USD-total
+                           )
                         )
                     )
                  )
@@ -2053,9 +2345,13 @@
           (prior-account #f)
           (prior-account-copy #f)
           (form-sched-line-USD-total (gnc-numeric-zero))
+          (form-sched-line-cap-gain-sales-USD-total (gnc-numeric-zero))
+          (form-sched-line-cap-gain-basis-USD-total (gnc-numeric-zero))
           (tax-code-sub-item-USD-total (gnc-numeric-zero))
           (tax-code-sub-item-USD-total-as-dr (gnc-numeric-zero))
           (tax-code-USD-total (gnc-numeric-zero))
+          (tax-code-cap-gain-sales-USD-total (gnc-numeric-zero))
+          (tax-code-cap-gain-basis-USD-total (gnc-numeric-zero))
           (tax-code-USD-total-as-dr (gnc-numeric-zero))
           (saved-tax-code-text "")
           (need-form-line-acct-header? #f)
@@ -2162,6 +2458,9 @@
                                                     tax-code-sub-item-USD-total)
                                                  #t
                                                  #f)
+                                              #f ;; format = 3, not 4
+                                              #f ;; not applicable
+                                              #f ;; not applicable
                                           )
                                     )
                                 )
@@ -2178,7 +2477,7 @@
                                               (xaccAccountGetType prior-account)
                                               (string->symbol prior-tax-code)
                                               prior-account-copy
-                                              tax-entity-type)))
+                                              tax-entity-type #f)))
                                       (set! tax-code-USD-total (gnc-numeric-zero))
                                       (set! tax-code-USD-total-as-dr
                                                              (gnc-numeric-zero))
@@ -2220,6 +2519,14 @@
                                                (xaccPrintAmount
                                                      tax-code-USD-total
                                                      print-info))
+                                        (tax-code-cap-gain-sales-total-amount
+                                               (xaccPrintAmount
+                                                     tax-code-cap-gain-sales-USD-total
+                                                     print-info))
+                                        (tax-code-cap-gain-basis-total-amount
+                                               (xaccPrintAmount
+                                                     tax-code-cap-gain-basis-USD-total
+                                                     print-info))
                                        ) 
                                        ;; print prior tax-code total and
                                        ;; reset accum
@@ -2240,9 +2547,24 @@
                                                              tax-code-USD-total)
                                                      #t
                                                      #f)
+                                                 (if (= 4 (get-acct-txf-info
+                                                             'format
+                                                             (xaccAccountGetType
+                                                                prior-account)
+                                                             (string->symbol
+                                                                prior-tax-code))
+                                                     )
+                                                     #t
+                                                     #f)
+                                                 tax-code-cap-gain-sales-total-amount
+                                                 tax-code-cap-gain-basis-total-amount
                                        )
                                        (set! tax-code-USD-total
                                                              (gnc-numeric-zero))
+                                       (set! tax-code-cap-gain-sales-USD-total
+                                                             (gnc-numeric-zero))
+                                       (set! tax-code-cap-gain-basis-USD-total
+                                                             (gnc-numeric-zero))
                                        (set! tax-code-USD-total-as-dr
                                                              (gnc-numeric-zero))
                                        (set! tax-code-sub-item-USD-total
@@ -2288,13 +2610,25 @@
                                     (set! output
                                           (list (render-txf-account
                                               prior-account
-                                              tax-code-USD-total-as-dr
+                                              (if (= 4 (get-acct-txf-info
+                                                          'format
+                                                          (xaccAccountGetType
+                                                                  prior-account)
+                                                          (string->symbol
+                                                               prior-tax-code)))
+                                                  (gnc-numeric-neg
+                                                   tax-code-cap-gain-sales-USD-total)
+                                                  tax-code-USD-total-as-dr)
                                               #f #f #f #f
                                               (xaccAccountGetType prior-account)
                                               (string->symbol prior-tax-code)
                                               prior-account-copy
-                                              tax-entity-type)))
+                                              tax-entity-type #f)))
                                     (set! tax-code-USD-total (gnc-numeric-zero))
+                                    (set! tax-code-cap-gain-sales-USD-total
+                                                             (gnc-numeric-zero))
+                                    (set! tax-code-cap-gain-basis-USD-total
+                                                             (gnc-numeric-zero))
                                     (set! tax-code-USD-total-as-dr
                                                              (gnc-numeric-zero))
                                     (set! tax-code-sub-item-USD-total
@@ -2330,30 +2664,53 @@
                                  (let* ((print-info (gnc-account-print-info
                                                               prior-account #f))
                                         (form-sched-line-total-amount
-                                               (xaccPrintAmount
-                                                     form-sched-line-USD-total
-                                                     print-info))
+                                          (xaccPrintAmount
+                                             form-sched-line-USD-total
+                                             print-info))
+                                        (form-sched-line-cap-gain-sales-total-amount
+                                          (xaccPrintAmount
+                                             form-sched-line-cap-gain-sales-USD-total
+                                             print-info))
+                                        (form-sched-line-cap-gain-basis-total-amount
+                                          (xaccPrintAmount
+                                             form-sched-line-cap-gain-sales-USD-total
+                                             print-info))
                                        ) 
                                        ;; print prior form-schedule-line total
                                        ;; and reset accum
                                        (render-total-row
-                                                 table
-                                                 form-sched-line-total-amount
-                                                 (string-append
-                                                     prior-form-schedule
-                                                     " Line "
-                                                     prior-form-sched-line
-                                                 )
-                                                 #t
-                                                 transaction-details?
-                                                 #f
-                                                 (if (gnc-numeric-negative-p
-                                                      form-sched-line-USD-total)
-                                                     #t
-                                                     #f)
+                                            table
+                                            form-sched-line-total-amount
+                                            (string-append
+                                                prior-form-schedule
+                                                " Line "
+                                                prior-form-sched-line
+                                            )
+                                            #t
+                                            transaction-details?
+                                            #f
+                                            (if (gnc-numeric-negative-p
+                                                 form-sched-line-USD-total)
+                                                #t
+                                                #f)
+                                            (if (= 4 (get-acct-txf-info
+                                                             'format
+                                                             (xaccAccountGetType
+                                                                prior-account)
+                                                             (string->symbol
+                                                                prior-tax-code))
+                                                )
+                                                #t
+                                                #f)
+                                            form-sched-line-cap-gain-sales-total-amount
+                                            form-sched-line-cap-gain-basis-total-amount
                                        )
                                        (set! form-sched-line-USD-total
                                                              (gnc-numeric-zero))
+                                       (set! form-sched-line-cap-gain-sales-USD-total
+                                                             (gnc-numeric-zero))
+                                       (set! form-sched-line-cap-gain-basis-USD-total
+                                                             (gnc-numeric-zero))
                                        (set! txf-l-count 0)
                                  )
                              )
@@ -2405,14 +2762,19 @@
                                           ""
                                           (string-append "Line "
                                                   current-form-sched-line ": "))
-                                      description " (" current-tax-code ")"))
+                                      description " ("
+                                      (substring current-tax-code 1
+                                           (string-length current-tax-code))
+                                      ")"))
                               (set! tax-code-heading-text
                                     (string-append
                                       (if (string=? current-form-sched-line "")
                                           ""
                                           (string-append "Line "
                                                   current-form-sched-line ": "))
-                                      description " (" current-tax-code
+                                      description " (" 
+                                      (substring current-tax-code 1
+                                           (string-length current-tax-code))
                                       (if show-TXF-data?
                                           (string-append
                                             ": Payer Name Option "
@@ -2497,6 +2859,14 @@
                         (set! tax-code-USD-total (gnc-numeric-add-fixed
                                                           tax-code-USD-total
                                                           (car account-output)))
+                        (set! tax-code-cap-gain-sales-USD-total
+                              (gnc-numeric-add-fixed
+                                       tax-code-cap-gain-sales-USD-total
+                                       (cadddr account-output)))
+                        (set! tax-code-cap-gain-basis-USD-total
+                              (gnc-numeric-add-fixed
+                                       tax-code-cap-gain-basis-USD-total
+                                       (car (cddddr account-output))))
                         (set! tax-code-USD-total-as-dr (gnc-numeric-add-fixed
                                                        tax-code-USD-total-as-dr
                                                        account-USD-total-as-dr))
@@ -2510,6 +2880,14 @@
                         (set! form-sched-line-USD-total (gnc-numeric-add-fixed
                                                        form-sched-line-USD-total
                                                           (car account-output)))
+                        (set! form-sched-line-cap-gain-sales-USD-total
+                              (gnc-numeric-add-fixed
+                                       form-sched-line-cap-gain-sales-USD-total
+                                       (cadddr account-output)))
+                        (set! form-sched-line-cap-gain-basis-USD-total
+                              (gnc-numeric-add-fixed
+                                       form-sched-line-cap-gain-basis-USD-total
+                                       (car (cddddr account-output))))
                         (set! need-form-line-acct-header? #f)
                         (set! need-form-schedule-header? #f)
                         (set! need-tax-code-header? #f)
@@ -2581,14 +2959,23 @@
                                              (gnc-numeric-zero-p tax-code-USD-total)
                                              (not prior-account))
                                           '()
-                                          (render-txf-account prior-account
-                                              tax-code-USD-total-as-dr
+                                          (render-txf-account
+                                              prior-account
+                                              (if (= 4 (get-acct-txf-info
+                                                          'format
+                                                          (xaccAccountGetType
+                                                                  prior-account)
+                                                          (gnc:account-get-txf-code
+                                                                prior-account)))
+                                                  (gnc-numeric-neg
+                                                   tax-code-cap-gain-sales-USD-total)
+                                                  tax-code-USD-total-as-dr)
                                               #f #f #f #f
                                               (xaccAccountGetType prior-account)
                                               (gnc:account-get-txf-code
                                                                 prior-account)
                                               prior-account-copy
-                                              tax-entity-type))
+                                              tax-entity-type #f))
                                     ))
                                  )
                                  ;; prior-account can be #f if selected accounts are
@@ -2599,7 +2986,7 @@
                                  ;; no user warning other than message on report.
                                  (if prior-account
                                      (gnc:display-report-list-item output-txf port
-                                                           "taxschedule.scm - ")
+                                                           "taxtxf.scm - ")
                                      #f) 
                                  (close-output-port port)
                                  #t
@@ -2639,6 +3026,12 @@
                    'attribute (list "valign" "top"))
 
                   (gnc:html-document-set-style!
+                   doc "text-cell-center"
+                   'tag "td"
+                   'attribute (list "class" "text-cell")
+                   'attribute (list "align" "center"))
+
+                  (gnc:html-document-set-style!
                    doc "number-cell-bot"
                    'tag "td"
                    'attribute (list "class" "number-cell")
@@ -2686,6 +3079,11 @@
                    'attribute (list "align" "right"))
 
                   (gnc:html-document-set-style!
+                   doc "text-cell-center"
+                   'tag "td"
+                   'attribute (list "align" "center"))
+
+                  (gnc:html-document-set-style!
                    doc "number-cell-bot"
                    'tag "td"
                    'attribute (list "align" "right")
@@ -2761,6 +3159,15 @@
                     (map (lambda (error)
                           (let* ((form (car (cdddr error)))
                                  (acct (cadr (cdddr error)))
+                                 (num-code (if (string=? (car error) "")
+                                               ""
+                                               (if (string=? (car error) "None")
+                                                   "None"
+                                                   (substring (car error) 1
+                                                    (string-length (car error)))
+                                               )
+                                           )
+                                 )
                                  (form-desc (if form
                                                 (let* ((tax-code
                                                  (xaccAccountGetTaxUSCode acct))
@@ -2782,7 +3189,7 @@
                                        (list (gnc:make-html-table-cell
                                               (cadr error)))
                                        (list (gnc:make-html-table-cell
-                                              (car error)))
+                                              num-code))
                                        (list (gnc:make-html-table-cell
                                               form))
                                        (list (gnc:make-html-table-cell
@@ -2860,6 +3267,9 @@
                                                     tax-code-sub-item-USD-total)
                                                #t
                                                #f)
+                                           #f ;; format = 3, not 4
+                                           #f ;; not applicable
+                                           #f ;; not applicable
                                )
                                (set! tax-code-sub-item-USD-total
                                                              (gnc-numeric-zero))
@@ -2879,6 +3289,14 @@
                         (tax-code-total-amount (xaccPrintAmount
                                                            tax-code-USD-total
                                                            print-info))
+                        (tax-code-cap-gain-sales-total-amount
+                                   (xaccPrintAmount
+                                            tax-code-cap-gain-sales-USD-total
+                                                           print-info))
+                        (tax-code-cap-gain-basis-total-amount
+                                   (xaccPrintAmount
+                                            tax-code-cap-gain-basis-USD-total
+                                                           print-info))
                        ) 
                        (render-total-row table tax-code-total-amount
                                               (string-append "Line (Code): "
@@ -2890,6 +3308,16 @@
                                                              tax-code-USD-total)
                                                   #t
                                                   #f)
+                                              (if (= 4 (get-acct-txf-info
+                                                          'format
+                                                          (xaccAccountGetType
+                                                                  prior-account)
+                                                          (string->symbol
+                                                               prior-tax-code)))
+                                                  #t
+                                                  #f)
+                                              tax-code-cap-gain-sales-total-amount
+                                              tax-code-cap-gain-basis-total-amount
                        )
                  )
              )
@@ -2906,6 +3334,14 @@
                             (form-sched-line-total-amount
                                       (xaccPrintAmount
                                           form-sched-line-USD-total print-info))
+                            (form-sched-line-cap-gain-sales-total-amount
+                                      (xaccPrintAmount
+                                        form-sched-line-cap-gain-sales-USD-total
+                                                                    print-info))
+                            (form-sched-line-cap-gain-basis-total-amount
+                                      (xaccPrintAmount
+                                        form-sched-line-cap-gain-basis-USD-total
+                                                                    print-info))
                            ) 
                            ;; print prior form-schedule-line total; reset accum
                            (render-total-row
@@ -2920,6 +3356,16 @@
                                                       form-sched-line-USD-total)
                                     #t
                                     #f)
+                                (if (= 4 (get-acct-txf-info
+                                                          'format
+                                                          (xaccAccountGetType
+                                                                  prior-account)
+                                                          (string->symbol
+                                                               prior-tax-code)))
+                                    #t
+                                    #f)
+                                form-sched-line-cap-gain-sales-total-amount
+                                form-sched-line-cap-gain-basis-total-amount
                            )
                            (set! form-sched-line-USD-total (gnc-numeric-zero))
                      )

Modified: gnucash/trunk/src/tax/us/txf-help.scm
===================================================================
--- gnucash/trunk/src/tax/us/txf-help.scm	2010-09-24 19:38:46 UTC (rev 19610)
+++ gnucash/trunk/src/tax/us/txf-help.scm	2010-09-24 19:48:02 UTC (rev 19611)
@@ -104,7 +104,7 @@
     (H320 . "Schedule D is used to report gains and losses from the sale of capital assets.")
     (N321 . "Short term gain or loss from the sale of a security.")
     (N323 . "Long term gain or loss from the sale of a security.")
-    (N810 . "Short term or long term gain or loss from the sale of capital assets other than securities.")
+    (N673 . "Short term or long term gain or loss from the sale of a security; for use when only the date sold and net sales amount are available and the date acquired and cost basis information is not available and will be separately added in the tax software.")
     (H325 . "Schedule E is used to report income or loss from rental real estate, royalties, and residual interest in REMIC's. Use a different copy for each rental or royalty. Use the Schedule K-1 categories for partnership rental income and loss amounts.")
     (N326 . "The amounts received as rental income from real estate (including personal property leased with real estate) but you were not in the real estate business. (If you are in the buisness of renting personal property, use Schedule C.)")
     (N327 . "Royalties recieved from oil, gas, or mineral properties (not including operating interests); copyrights; and patents.")

Modified: gnucash/trunk/src/tax/us/txf.scm
===================================================================
--- gnucash/trunk/src/tax/us/txf.scm	2010-09-24 19:38:46 UTC (rev 19610)
+++ gnucash/trunk/src/tax/us/txf.scm	2010-09-24 19:48:02 UTC (rev 19611)
@@ -140,7 +140,7 @@
     (cons 'N322 #(not-impl "Sched D" "ST gain/loss - other" 4 #f "" ((1991 "1d") (1989 "2d") (1986 "2c")) 1992))
     (cons 'N323 #(not-impl "Sched D" "Long Term gain/loss - security" 4 #f "" ((1997 "8") (1993 "9") (1992 "9a") (1991 "8a") (1986 "9a") (1983 "9") (1980 "8"))))
     (cons 'N324 #(not-impl "Sched D" "LT gain/loss - other" 4 #f "" ((1992 "9d") (1991 "8d") (1989 "9d") (1986 "9c")) 1992))
-    (cons 'N673 #(not-impl "Sched D" "Short/Long gain or loss" 4 #f "" ((1999 "1 or 8"))))
+    (cons 'N673 #(current "Sched D" "Short/Long gain or loss" 4 #f "" ((1999 "1 or 8"))))
     (cons 'N682 #(not-impl "Sched D" "Wash Sale - security" 4 #f "" ((2003 "1 or 8"))))
     (cons 'N488 #(parent "Sched D" "Dividend, cap gain distrib." 3 #f "_LT CapGnDst" ((1997 "13") (1992 "14") (1991 "12") (1986 "13") (1983 "15") (1980 "13"))))
     (cons 'N684 #(none "Sched D" "Div inc., PostMay5 cap gain" 3 #f "" ((2004 "NA - Expired") (2003 "13g")) 2003))



More information about the gnucash-changes mailing list