In addition to how much a customer owes me I also wanted to know how much I 
had earned from that customer over the last year.  It seemed that the customer 
report could provide me that information with a little tweaking of the report 
scheme.  The attached patch adds an extra line below the table, above the 
"Total Due" line with the total amount Invoiced for the selected period.  
Since the same file is used for Vendor and Employee the same data are 
presented, with appropriate changes to the label.

If you think this is useful to others please incorporate it into the code 
base, if not, well...

It could be an option with a little more work.

Mike Evans
-- 
GPG Key: 1024D/050895C2
Keyserver: http://pgp.mit.edu/          
Search String: 0x050895C2
Index: src/business/business-reports/owner-report.scm
===================================================================
--- src/business/business-reports/owner-report.scm	(revision 18947)
+++ src/business/business-reports/owner-report.scm	(working copy)
@@ -6,16 +6,16 @@
 ;; Created by:  Derek Atkins <[email protected]>
 ;; Copyright (c) 2002, 2003 Derek Atkins <[email protected]>
 ;;
-;; This program is free software; you can redistribute it and/or    
-;; modify it under the terms of the GNU General Public License as   
-;; published by the Free Software Foundation; either version 2 of   
-;; the License, or (at your option) any later version.              
-;;                                                                  
-;; This program is distributed in the hope that it will be useful,  
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of   
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    
-;; GNU General Public License for more details.                     
-;;                                                                  
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2 of
+;; the License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
 ;; You should have received a copy of the GNU General Public License
 ;; along with this program; if not, contact:
 ;;
@@ -61,8 +61,8 @@
   `(set! ,alist (cons ,element ,alist)))
 
 (define (set-last-row-style! table tag . rest)
-  (let ((arg-list 
-         (cons table 
+  (let ((arg-list
+         (cons table
                (cons (- (gnc:html-table-num-rows table) 1)
                      (cons tag rest)))))
     (apply gnc:html-table-set-row-style! arg-list)))
@@ -82,9 +82,9 @@
 
 (define columns-used-size 6)
 
-(define (build-column-used options)   
+(define (build-column-used options)
   (define (opt-val section name)
-    (gnc:option-value 
+    (gnc:option-value
      (gnc:lookup-option options section name)))
   (define (make-set-col col-vector)
     (let ((col 0))
@@ -94,7 +94,7 @@
               (vector-set! col-vector index col)
               (set! col (+ col 1)))
             (vector-set! col-vector index #f)))))
-  
+
   (let* ((col-vector (make-vector columns-used-size #f))
          (set-col (make-set-col col-vector)))
     (set-col (opt-val "Display Columns" date-header) 0)
@@ -192,7 +192,7 @@
 		   (vector->list buckets))))
 
     table))
-		 
+
 ;;
 ;; Make a row list based on the visible columns
 ;;
@@ -201,7 +201,7 @@
     (if (date-col column-vector)
 	(addto! row-contents (gnc-print-date date)))
     (if (date-due-col column-vector)
-	(addto! row-contents 
+	(addto! row-contents
 		(if (and due-date
 			 (not (equal? due-date (cons 0 0))))
 		    (gnc-print-date due-date)
@@ -221,7 +221,7 @@
 ;; Adds the 'Balance' row to the table if it has not been printed and
 ;; total is not zero
 ;;
-;; Returns printed? 
+;; Returns printed?
 ;;
 (define (add-balance-row table column-vector txn odd-row? printed? start-date total)
   (if (not printed?)
@@ -270,10 +270,10 @@
 
     (if (gnc:timepair-later start-date date)
 	(begin
-	  
+
 	  ; Adds 'balance' row if needed
 	  (set! printed? (add-balance-row table column-vector txn odd-row? printed? start-date total))
-	  
+
 	  ; Now print out the invoice row
 	  (if (not (null? invoice))
 	      (set! due-date (gncInvoiceGetDateDue invoice)))
@@ -288,7 +288,7 @@
 
 	  (set! odd-row? (not odd-row?))
 	  ))
-
+;; Return a list of (printed? value odd-row?)
     (list printed? value odd-row?)
     ))
 
@@ -297,8 +297,11 @@
   (let ((txns (xaccQueryGetTransactions query QUERY-TXN-MATCH-ANY))
 	(used-columns (build-column-used options))
 	(total (gnc-numeric-zero))
+	(invoiced (gnc-numeric-zero))
 	(currency (gnc-default-currency)) ;XXX
 	(table (gnc:make-html-table))
+	(ownertype (gnc:option-value (gnc:lookup-option options "__reg" "owner-type")))
+	(type-str "")
 	(inv-str (gnc:option-value (gnc:lookup-option options "__reg"
 						      "inv-str")))
 	(reverse? (gnc:option-value (gnc:lookup-option options "__reg"
@@ -311,31 +314,71 @@
     ; Order the transactions properly
     (set! txns (sort txns (lambda (a b) (> 0 (xaccTransOrder a b)))))
 
+; Mike E wanted a "Total Invoiced|Billed|Paid" for period in the report.
+; edits below here to 381 do just that.  [email protected]
     (let ((printed? #f)
 	  (odd-row? #t))
       (for-each
        (lambda (txn)
-	 (let ((type (xaccTransGetTxnType txn)))
-	   (if
-	    (or (equal? type TXN-TYPE-INVOICE)
-		(equal? type TXN-TYPE-PAYMENT))
+	 (let ((type (xaccTransGetTxnType txn))
+	 (date (gnc-transaction-get-date-posted txn)))
+	   (if (equal? type TXN-TYPE-INVOICE)
+
 	    (let ((result (add-txn-row table txn acc used-columns odd-row? printed?
 				       inv-str reverse? start-date total)))
 
 	      (set! printed? (car result))
+	      ;(if(equal? ownertype GNC-OWNER-CUSTOMER) ; Not sure if all reports need totals, so optional?
+	      (if(gnc:timepair-le start-date date)
+		(set! invoiced (gnc-numeric-add-fixed invoiced (cadr result)))
+	      )
+	      ;)
 	      (set! total (gnc-numeric-add-fixed total (cadr result)))
 	      (set! odd-row? (caddr result))
-	      ))))
+	      ))
+
+	  (if (equal? type TXN-TYPE-PAYMENT)
+	    (let ((result (add-txn-row table txn acc used-columns odd-row? printed?
+				      inv-str reverse? start-date total)))
+
+	      (set! printed? (car result))
+	      (set! total (gnc-numeric-add-fixed total (cadr result)))
+	      (set! odd-row? (caddr result))
+	      ))
+
+	      ))
        txns)
 	  ;Balance row may not have been added if all transactions were before
 	  ;start-date (and no other rows would be added either) so add it now
       (if (not (null? txns))
-	  (add-balance-row table used-columns (car txns) odd-row? printed? start-date total)
-		))
+	  (add-balance-row table used-columns (car txns) odd-row? printed? start-date total))
 
-    (gnc:html-table-append-row/markup! 
+		)
+
+
+    (cond
+      ((eqv? ownertype GNC-OWNER-CUSTOMER)
+       (set! type-str (N_ "Total Invoiced")))
+      ((eqv? ownertype GNC-OWNER-VENDOR)
+       (set! type-str (N_ "Total Billed")))
+      ((eqv? ownertype GNC-OWNER-EMPLOYEE)
+       (set! type-str (N_ "Total Paid"))))
+
+ (gnc:html-table-append-row/markup!
      table
      "grand-total"
+ (append (cons (gnc:make-html-table-cell/markup
+		    "total-label-cell"
+		    (_ type-str))
+		   '())
+	     (list (gnc:make-html-table-cell/size/markup
+		    1 (value-col used-columns)
+		    "total-number-cell"
+		    (gnc:make-gnc-monetary currency invoiced)))))
+
+    (gnc:html-table-append-row/markup!
+     table
+     "grand-total"
      (append (cons (gnc:make-html-table-cell/markup
 		    "total-label-cell"
 		    (if (gnc-numeric-negative-p total)
@@ -347,6 +390,7 @@
 		    "total-number-cell"
 		    (gnc:make-gnc-monetary currency total)))))
 
+
     (let* ((interval-vec (list->vector (make-interval-list end-date))))
       (gnc:html-table-append-row/markup!
        table
@@ -432,7 +476,7 @@
   (gnc:options-set-default-section gnc:*report-options* "General")
 
   gnc:*report-options*)
-	     
+
 (define (customer-options-generator)
   (options-generator (list ACCT-TYPE-RECEIVABLE) GNC-OWNER-CUSTOMER
                      (_ "Invoice") #f))
@@ -467,7 +511,7 @@
   (let* ((guid (gncOwnerReturnGUID (gncOwnerGetEndOwner owner))))
 
     (qof-query-add-guid-match
-     q 
+     q
      (list SPLIT-TRANS INVOICE-FROM-TXN INVOICE-OWNER
 	   OWNER-PARENTG)
      guid QOF-QUERY-OR)
@@ -568,10 +612,10 @@
 	 (query (qof-query-create-for-splits))
 	 (account (opt-val owner-page acct-string))
 	 (owner (opt-val owner-page owner-string))
-	 (start-date (gnc:timepair-start-day-time 
+	 (start-date (gnc:timepair-start-day-time
 		       (gnc:date-option-absolute-time
 			(opt-val gnc:pagename-general optname-from-date))))
-	 (end-date (gnc:timepair-end-day-time 
+	 (end-date (gnc:timepair-end-day-time
 		       (gnc:date-option-absolute-time
 			(opt-val gnc:pagename-general optname-to-date))))
 	 (book (gnc-get-current-book)) ;XXX Grab this from elsewhere
@@ -599,13 +643,13 @@
 
            (gnc:html-document-set-headline!
             document (gnc:html-markup
-                      "!" 
+                      "!"
                       (_ type-str )
                       " " (_ "Report:") " "
                       (gnc:html-markup-anchor
                        (gnc:owner-anchor-text owner)
                        (gncOwnerGetName owner))))
-	  
+
 	  (if (not (null? account))
 	      (begin
 		(set! table (make-txn-table (gnc:report-options report-obj)
@@ -649,7 +693,7 @@
 	(gnc:html-document-add-object!
 	 document
 	 (gnc:make-html-text
-	  (sprintf #f 
+	  (sprintf #f
 		   (_ "No valid %s selected.  Click on the Options button to select a company.")
 		   (_ type-str))))) ;; FIXME because of translations: Please change this string into full sentences instead of sprintf, because in non-english languages the "no valid" has different forms depending on the grammatical gender of the "%s".
 
@@ -711,7 +755,7 @@
 (gnc:define-report
  'version 1
  'name (N_ "Employee Report")
- 'report-guid employee-report-guid 
+ 'report-guid employee-report-guid
  'menu-path (list gnc:menuname-business-reports)
  'options-generator employee-options-generator
  'renderer reg-renderer
_______________________________________________
gnucash-devel mailing list
[email protected]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to