--- usr/local/share/gnucash/guile-modules/gnucash/report/standard-reports.scm.orig	2004-06-13 00:47:34.000000000 -0400
+++ usr/local/share/gnucash/guile-modules/gnucash/report/standard-reports.scm	2004-06-12 23:09:52.000000000 -0400
@@ -70,7 +70,7 @@
 (use-modules (gnucash report account-summary))
 (use-modules (gnucash report advanced-portfolio))
 (use-modules (gnucash report average-balance))
-(use-modules (gnucash report balance-sheet))
+(use-modules (gnucash report report-form-balance-sheet))
 (use-modules (gnucash report cash-flow))
 (use-modules (gnucash report category-barchart))
 (use-modules (gnucash report daily-reports))
--- usr/local/share/gnucash/guile-modules/gnucash/report/balance-sheet.scm	2004-06-07 12:03:49.000000000 -0400
+++ usr/local/share/gnucash/guile-modules/gnucash/report/report-form-balance-sheet.scm	2004-06-13 00:43:22.000000000 -0400
@@ -1,8 +1,15 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; balance-sheet.scm: balance sheet 
+;; report-form-balance-sheet.scm: balance sheet 
 ;; 
 ;; By Robert Merkel <rgmerk@mira.net>
 ;;
+;; 2004.06.12: Modified by David Montenegro <sunrise2000@comcast.net>
+;;  * Renamed to "Report form Balance Sheet".
+;;    (to distinguish it from "Account form Balance Sheet", forthcoming)
+;;  * Removed from-date & Net Profit from the report.
+;;  * BUGS: Line & column alignments still do not conform with
+;;    textbook accounting practice (they're close though!).
+;; 
 ;; Largely borrowed from pnl.scm by:
 ;; Christian Stimming <stimming@tu-harburg.de>
 ;;
@@ -25,7 +32,7 @@
 ;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(define-module (gnucash report balance-sheet))
+(define-module (gnucash report report-form-balance-sheet))
 (use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing.
 (use-modules (ice-9 slib))
 (use-modules (gnucash gnc-module))
@@ -34,19 +41,21 @@
 
 (gnc:module-load "gnucash/report/report-system" 0)
 
-(define reportname (N_ "Balance Sheet"))
+(define reportname (N_ "Report form Balance Sheet"))
 
 ;; define all option's names so that they are properly defined
 ;; in *one* place.
-(define optname-from-date (N_ "From"))
-(define optname-to-date (N_ "To"))
+(define optname-date (N_ "Balance Sheet Date"))
 
-(define optname-display-depth (N_ "Account Display Depth"))
+(define optname-party-name (N_ "Company name"))
+(define optname-report-title (N_ "Balance Sheet"))
+(define optname-depth-limit (N_ "Levels of Subaccounts"))
 (define optname-show-subaccounts (N_ "Always show sub-accounts"))
-(define optname-accounts (N_ "Account"))
+;; !!!          ^^^ WTF does this mean...?
+(define optname-accounts (N_ "Accounts to include"))
 
-(define optname-show-parent-balance (N_ "Show balances for parent accounts"))
-(define optname-show-parent-total (N_ "Show subtotals"))
+(define optname-show-parent-balance (N_ "Show any balance in parent accounts"))
+(define optname-show-parent-total (N_ "Show parent account subtotals"))
 
 (define optname-report-currency (N_ "Report's currency"))
 (define optname-price-source (N_ "Price Source"))
@@ -65,23 +74,25 @@
      t1 (+ (gnc:html-table-num-rows t1)
            (gnc:html-table-num-rows t2)))))
 
-(define (accountlist-get-comm-balance-at-date accountlist from date)
+;; This calculates the increase in the balance of <accountlist>
+;; over the period from <from-date> to <to-date>.  Returns a collector.
+(define (accountlist-get-comm-balance-at-date accountlist from-date to-date)
 ;;  (for-each (lambda (x) (display x))
-;;	    (list "computing from: " (gnc:print-date from) " to "
-;;		  (gnc:print-date date) "\n"))
+;;	    (list "computing from: " (gnc:print-date from-date) " to "
+;;		  (gnc:print-date to-date) "\n"))
   (let ((collector (gnc:make-commodity-collector)))
     (for-each (lambda (account)
                 (let* (
 		       (start-balance
 			(gnc:account-get-comm-balance-at-date
-			 account from #f))
+			 account from-date #f))
 		       (sb (cadr (start-balance
 				  'getpair
 				  (gnc:account-get-commodity account)
 				  #f)))
 		       (end-balance
 			(gnc:account-get-comm-balance-at-date 
-			 account date #f))
+			 account to-date #f))
 		       (eb (cadr (end-balance
 				  'getpair
 				  (gnc:account-get-commodity account)
@@ -98,27 +109,44 @@
     collector))
 
 ;; options generator
-(define (balance-sheet-options-generator)
-  (let ((options (gnc:new-options)))
-
+(define (report-form-balance-sheet-options-generator)
+  (let* ((options (gnc:new-options))
+         (add-option 
+          (lambda (new-option)
+            (gnc:register-option options new-option))))
+
+
+    (add-option
+      (gnc:make-string-option
+      (N_ "General") optname-report-title
+      "a" (N_ "Title for this report") (N_ "Balance Sheet")))
+    (add-option
+      (gnc:make-string-option
+      (N_ "General") optname-party-name
+      "b" (N_ "Name of company/individual") (N_ "")))
+    ;; !!! this should default to the workbook company name !!!
+    
     ;; date at which to report balance
-    (gnc:options-add-date-interval!
-     options gnc:pagename-general 
-     optname-from-date optname-to-date "a")
+   (add-option
+     (gnc:make-date-option
+      (N_ "General") optname-date
+      "c" (N_ "Balance sheet as-of date")
+      (lambda () (cons 'absolute (cons (current-time) 0)))
+      #f 'both '(start-cal-year start-prev-year end-prev-year) ))
 
     ;; all about currencies
     (gnc:options-add-currency!
      options gnc:pagename-general
-     optname-report-currency "b")
+     optname-report-currency "c")
 
     (gnc:options-add-price-source! 
      options gnc:pagename-general
-     optname-price-source "c" 'weighted-average)
+     optname-price-source "d" 'weighted-average)
 
     ;; accounts to work on
     (gnc:options-add-account-selection! 
      options gnc:pagename-accounts
-     optname-display-depth optname-show-subaccounts
+     optname-depth-limit optname-show-subaccounts
      optname-accounts "a" 2
      (lambda ()
        (gnc:filter-accountlist-type 
@@ -132,20 +160,20 @@
      options
      (gnc:make-simple-boolean-option
       gnc:pagename-display optname-show-parent-balance 
-      "c" (N_ "Show balances for parent accounts") #t))
+      "c" (N_ "Show any balance in parent accounts") #t))
 
     ;; have a subtotal for each parent account?
     (gnc:register-option 
      options
      (gnc:make-simple-boolean-option
       gnc:pagename-display optname-show-parent-total
-      "d" (N_ "Show subtotals for parent accounts") #f))
+      "d" (N_ "Show parent account subtotals") #f))
 
     (gnc:register-option 
      options
      (gnc:make-simple-boolean-option
       gnc:pagename-display optname-show-foreign 
-      "e" (N_ "Display the account's foreign currency amount?") #f))
+      "e" (N_ "Display the account's foreign currency amount") #f))
 
     (gnc:register-option 
      options
@@ -159,11 +187,11 @@
     options))
 
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; balance-sheet-renderer
+;; report-form-balance-sheet-renderer
 ;; set up the document and add the table
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(define (balance-sheet-renderer report-obj)
+(define (report-form-balance-sheet-renderer report-obj)
   (define (get-option pagename optname)
     (gnc:option-value
      (gnc:lookup-option 
@@ -172,8 +200,8 @@
   (gnc:report-starting reportname)
 
   ;; get all option's values
-  (let* ((display-depth (get-option gnc:pagename-accounts 
-                                    optname-display-depth))
+  (let* ((depth-limit (get-option gnc:pagename-accounts 
+                                    optname-depth-limit))
          (show-subaccts? (get-option gnc:pagename-accounts
                                      optname-show-subaccounts))
          (accounts (get-option gnc:pagename-accounts
@@ -190,15 +218,11 @@
                                    optname-price-source))
          (show-rates? (get-option gnc:pagename-display 
                                   optname-show-rates))
-	 (from-date-printable (gnc:date-option-absolute-time
-			       (get-option gnc:pagename-general
-					   optname-from-date)))
-	 (from-date-tp (gnc:timepair-end-day-time
-	 		(gnc:timepair-previous-day from-date-printable)))
-         (to-date-tp (gnc:timepair-end-day-time 
+         (date-tp (gnc:timepair-end-day-time 
                       (gnc:date-option-absolute-time
                        (get-option gnc:pagename-general
-                                   optname-to-date))))
+                                   optname-date))))
+	 (forever-ago (cons 0 0))
 
          ;; decompose the account list
          (split-up-accounts (gnc:decompose-accountlist accounts))
@@ -214,9 +238,9 @@
 
          (doc (gnc:make-html-document))
          (txt (gnc:make-html-text))
-         (tree-depth (if (equal? display-depth 'all)
+         (tree-depth (if (equal? depth-limit 'all)
                          (gnc:get-current-group-depth) 
-                         display-depth))
+                         depth-limit))
          ;; calculate the exchange rates  
          (exchange-fn #f)
          (totals-get-balance #f))
@@ -235,25 +259,36 @@
 	    balance report-currency exchange-fn)
 	   #f "primary-subheading" #t #f)))
     
+    (define (get-option pagename optname)
+      (gnc:option-value
+       (gnc:lookup-option 
+	(gnc:report-options report-obj) pagename optname)))
+    
     ;;(gnc:warn "account names" liability-account-names)
     (gnc:html-document-set-title! 
-     doc (sprintf #f "%s %s - %s"
-		  (get-option gnc:pagename-general gnc:optname-reportname)
-		  (gnc:print-date from-date-printable)
-                  (gnc:print-date to-date-tp)))
+     doc (sprintf #f "%s\n%s\n%s"
+		  (get-option gnc:pagename-general optname-report-title)
+		  (get-option gnc:pagename-general optname-party-name)
+                  (gnc:print-date date-tp)))
+
+    (if (null? accounts)
+
+        ;; error condition: no accounts specified
+        (gnc:html-document-add-object! 
+         doc 
+         (gnc:html-make-no-account-warning 
+	  (_ "Balance Sheet") (gnc:report-id report-obj)))
 
-    (if (not (null? accounts))
         ;; Get all the balances for each account group.
         (let* ((asset-balance #f)
+               (neg-liability-balance #f) ;; norm credit balances are < 0
                (liability-balance #f)
+               (neg-equity-balance #f)
                (equity-balance #f)
-               (sign-reversed-liability-balance #f)
-               (neg-net-profit-balance #f)
-               (net-profit-balance #f)
-	       (neg-retained-earnings-balance #f)
-	       (retained-earnings-balance #f)
+	       (neg-retained-earnings #f) ;; credit, income - expenses, < 0
+	       (retained-earnings #f)     ;; retained earnings + net profit
                (total-equity-balance #f)
-               (equity-plus-liability #f)
+               (liability-plus-equity #f)
                (unrealized-gain-collector #f)
 
                ;; Create the account tables below where their
@@ -262,46 +297,69 @@
                (liability-table #f)
                (equity-table #f))
 
+	  ;; If you ask me, retained earnings and net profit
+	  ;; should be added directly into equity, since the
+	  ;; balance sheet does not have a period over which
+	  ;; to report earnings....
 	  (gnc:report-percent-done 2)
 	  (set! totals-get-balance (lambda (account)
                                (gnc:account-get-comm-balance-at-date 
-                                account to-date-tp #f)))
+                                account date-tp #f)))
 	  (gnc:report-percent-done 4)
+	  ;; sum assets
 	  (set! asset-balance 
                 (gnc:accounts-get-comm-total-assets 
                  asset-accounts totals-get-balance))
 	  (gnc:report-percent-done 6)
-	  (set! liability-balance
+	  ;; sum liabilities
+	  (set! neg-liability-balance
                 (gnc:accounts-get-comm-total-assets 
                  liability-accounts totals-get-balance))
+	  (set! liability-balance
+                (gnc:make-commodity-collector))
+          (liability-balance 'minusmerge
+			     neg-liability-balance
+			     #f)
 	  (gnc:report-percent-done 8)
-	  (set! equity-balance
+	  ;; sum equities
+	  (set! neg-equity-balance
                 (gnc:accounts-get-comm-total-assets 
                  equity-accounts totals-get-balance))
-	  (gnc:report-percent-done 10)
-	  (set! sign-reversed-liability-balance
-                (gnc:make-commodity-collector))
+	  (set! equity-balance (gnc:make-commodity-collector))
+	  (equity-balance 'minusmerge
+			  neg-equity-balance
+			  #f)
 	  (gnc:report-percent-done 12)
-	  (set! neg-net-profit-balance 
-                (accountlist-get-comm-balance-at-date
-                 income-expense-accounts
-                 from-date-tp to-date-tp))
-	  (set! neg-retained-earnings-balance
+	  ;; sum any retained earnings
+	  (set! neg-retained-earnings
 		(accountlist-get-comm-balance-at-date
 		 income-expense-accounts
-		 (cons 0 0) from-date-tp))
+		 forever-ago date-tp))
+	  (set! retained-earnings (gnc:make-commodity-collector))
+	  (retained-earnings 'minusmerge
+			  neg-retained-earnings
+			  #f)
 	  (gnc:report-percent-done 14)
-	  (set! net-profit-balance (gnc:make-commodity-collector))
-	  (set! retained-earnings-balance (gnc:make-commodity-collector))
-	  (gnc:report-percent-done 16)
+	  ;; calculate equity and liability+equity totals
 	  (set! total-equity-balance (gnc:make-commodity-collector))
+	  (total-equity-balance 'merge
+			  equity-balance
+			  #f)
+	  (total-equity-balance 'merge
+			  retained-earnings
+			  #f)
 	  (gnc:report-percent-done 18)
-	  (set! equity-plus-liability (gnc:make-commodity-collector))
-	  (set! unrealized-gain-collector (gnc:make-commodity-collector))
+	  (set! liability-plus-equity (gnc:make-commodity-collector))
+	  (liability-plus-equity 'merge
+			  liability-balance
+			  #f)
+	  (liability-plus-equity 'merge
+			  total-equity-balance
+			  #f)
 
 	  (gnc:report-percent-done 20)
 	  (set! exchange-fn (gnc:case-exchange-fn 
-			     price-source report-currency to-date-tp))
+			     price-source report-currency date-tp))
 	  (gnc:report-percent-done 30)
 
 	  ;;; Arbitrarily declare that the building of these tables
@@ -309,7 +367,7 @@
 	  ;;; this report. (from 30%-80%)
 	  (set! asset-table 
                 (gnc:html-build-acct-table 
-                 #f to-date-tp 
+                 #f date-tp 
                  tree-depth show-subaccts? 
                  asset-accounts
 		 30 20
@@ -318,7 +376,7 @@
                  show-fcur? report-currency exchange-fn #t))
 	  (set! liability-table 
                 (gnc:html-build-acct-table
-                 #f to-date-tp
+                 #f date-tp
                  tree-depth show-subaccts?
                  liability-accounts
 		 50 20
@@ -327,7 +385,7 @@
                  show-fcur? report-currency exchange-fn #t))
 	  (set! equity-table
                 (gnc:html-build-acct-table
-                 #f to-date-tp
+                 #f date-tp
                  tree-depth show-subaccts?
                  equity-accounts
 		 70 10
@@ -335,29 +393,6 @@
                  show-parent-balance? show-parent-total?
                  show-fcur? report-currency exchange-fn #t))
 
-          (net-profit-balance 'minusmerge
-                                   neg-net-profit-balance
-                                   #f)
-          (retained-earnings-balance 'minusmerge
-                                   neg-retained-earnings-balance
-                                   #f)
-          (total-equity-balance 'minusmerge equity-balance #f)
-          (total-equity-balance 'merge
-                                net-profit-balance
-                                #f)	    
-          (total-equity-balance 'merge
-                                retained-earnings-balance
-                                #f)	    
-          (sign-reversed-liability-balance 'minusmerge
-                                           liability-balance
-                                           #f)
-          (equity-plus-liability 'merge
-                                 sign-reversed-liability-balance
-                                 #f)
-          (equity-plus-liability 'merge
-                                 total-equity-balance
-                                 #f)
-
           ;; Now concatenate the tables. This first prepend-row has
           ;; to be written out by hand -- we can't use the function
           ;; append-something because we have to prepend.
@@ -378,20 +413,23 @@
           (add-subtotal-line 
            asset-table (_ "Assets") asset-balance)	    
           
-          ;; add a horizontal ruler
+          ;; add a horizontal rule
           (gnc:html-table-append-ruler! 
            asset-table (* (if show-fcur? 3 2) tree-depth))
+	  ;; !!! Rules really should go beneath added columns... !!!
           
 	  (gnc:report-percent-done 85)
           (add-subtotal-line 
            asset-table (_ "Liabilities") #f)
           (html-table-merge asset-table liability-table)
           (add-subtotal-line
-           asset-table (_ "Liabilities") sign-reversed-liability-balance)
+           asset-table (_ "Liabilities") liability-balance)
 
+	  ;; Hm... unrealized gains??
+          (set! unrealized-gain-collector (gnc:make-commodity-collector))
           (let* ((weighted-fn
                   (gnc:case-exchange-fn 'weighted-average
-                                        report-currency to-date-tp))
+                                        report-currency date-tp))
 
                  (value
                   (gnc:gnc-monetary-amount
@@ -408,10 +446,10 @@
                  (unrealized-gain (gnc:numeric-sub-fixed value cost)))
 
             (unrealized-gain-collector 'add report-currency unrealized-gain)
-            (equity-plus-liability 'add report-currency unrealized-gain)
+            (liability-plus-equity 'add report-currency unrealized-gain)
 
             (add-subtotal-line
-             asset-table (_ "Unrealized Gains(Losses)")
+             asset-table (_ "Unrealized Gains (Losses)")
              unrealized-gain-collector))
 
           (gnc:html-table-append-ruler! 
@@ -422,16 +460,14 @@
            asset-table (_ "Equity") #f)
           (html-table-merge asset-table equity-table)
 	  (add-subtotal-line
-	   asset-table (_ "Retained Earnings") retained-earnings-balance)
-          (add-subtotal-line
-           asset-table (_ "Net Profit") net-profit-balance)
+	   asset-table (_ "Retained Earnings") retained-earnings)
           (add-subtotal-line
            asset-table (_ "Total Equity") total-equity-balance)
 
           (gnc:html-table-append-ruler! 
            asset-table (* (if show-fcur? 3 2) tree-depth))
           (add-subtotal-line
-           asset-table (_ "Liabilities & Equity") equity-plus-liability)
+           asset-table (_ "Liabilities & Equity") liability-plus-equity)
           (gnc:html-document-add-object! doc asset-table)
           
           ;; add currency information
@@ -443,13 +479,7 @@
                 report-currency exchange-fn accounts)))
 	  (gnc:report-percent-done 100))
         
-        
-        ;; error condition: no accounts specified
-        
-        (gnc:html-document-add-object! 
-         doc 
-         (gnc:html-make-no-account-warning 
-	  (_ "Balance Sheet") (gnc:report-id report-obj))))
+        )
     (gnc:report-finished)
     doc))
 
@@ -457,5 +487,5 @@
  'version 1
  'name reportname
  'menu-path (list gnc:menuname-asset-liability)
- 'options-generator balance-sheet-options-generator
- 'renderer balance-sheet-renderer)
+ 'options-generator report-form-balance-sheet-options-generator
+ 'renderer report-form-balance-sheet-renderer)
