r21681 - gnucash/trunk/src/report - Prepare the "Print Invoice" scheme function to be given a report name.

Christian Stimming cstim at code.gnucash.org
Mon Dec 5 16:24:51 EST 2011


Author: cstim
Date: 2011-12-05 16:24:50 -0500 (Mon, 05 Dec 2011)
New Revision: 21681
Trac: http://svn.gnucash.org/trac/changeset/21681

Modified:
   gnucash/trunk/src/report/business-reports/business-reports.scm
   gnucash/trunk/src/report/business-reports/invoice.scm
   gnucash/trunk/src/report/report-system/report-system.scm
Log:
Prepare the "Print Invoice" scheme function to be given a report name.

Modified: gnucash/trunk/src/report/business-reports/business-reports.scm
===================================================================
--- gnucash/trunk/src/report/business-reports/business-reports.scm	2011-12-05 06:06:03 UTC (rev 21680)
+++ gnucash/trunk/src/report/business-reports/business-reports.scm	2011-12-05 21:24:50 UTC (rev 21681)
@@ -32,6 +32,7 @@
 (gnc:module-load "gnucash/html" 0)
 
 (define gnc:menuname-business-reports (N_ "_Business"))
+(define gnc:optname-invoice-number (N_ "Invoice Number"))
 
 (define (guid-ref idstr type guid)
   (gnc-build-url type (string-append idstr guid) ""))
@@ -95,8 +96,31 @@
 	  (gnc-build-url URL-TYPE-OWNERREPORT ref ""))
 	ref)))
 
-(export gnc:menuname-business-reports)
+;; Creates a new report instance for the given invoice. The given
+;; report name must be the name of one existing report template, which
+;; is then used to instantiate the new report instance.
+(define (gnc:invoice-report-create-withname invoice report-name)
+  ;; Look up the internal template-id that belongs to the given report
+  ;; name
+  (let ((report-template-id
+         (gnc:report-template-name-to-id report-name)))
 
+    (if report-template-id
+        ;; We found the report template id, so instantiate a report
+        ;; and set the invoice option accordingly.
+        (let* ((options (gnc:make-report-options report-template-id))
+               (invoice-op (gnc:lookup-option options gnc:pagename-general gnc:optname-invoice-number)))
+
+          (gnc:option-set-value invoice-op invoice)
+          (gnc:make-report report-template-id options))
+        ;; No report template id was found (probably the name has a
+        ;; typo), so let's return zero as an invalid report id.
+        0
+        )))
+
+(export gnc:invoice-report-create-withname)
+(export gnc:menuname-business-reports gnc:optname-invoice-number)
+
 (use-modules (gnucash report fancy-invoice))
 (use-modules (gnucash report invoice))
 (use-modules (gnucash report easy-invoice))
@@ -108,8 +132,17 @@
 (use-modules (gnucash report customer-summary))
 (use-modules (gnucash report balsheet-eg))
 
-(define gnc:invoice-report-create gnc:invoice-report-create-internal)
+(define (gnc:invoice-report-create invoice)
+  (gnc:invoice-report-create-withname
+   invoice
+   ;; Feel free to insert a different invoice report name below, such
+   ;; as "Tax Invoice"
+   "Printable Invoice"))
 
+;; Alternatively, if your preferred report has a "create-internal"
+;; function, uncomment the line below and delete the ones above
+;;(define gnc:invoice-report-create gnc:invoice-report-create-internal)
+
 (define (gnc:payables-report-create account title show-zeros?)
   (payables-report-create-internal account title show-zeros?))
 

Modified: gnucash/trunk/src/report/business-reports/invoice.scm
===================================================================
--- gnucash/trunk/src/report/business-reports/invoice.scm	2011-12-05 06:06:03 UTC (rev 21680)
+++ gnucash/trunk/src/report/business-reports/invoice.scm	2011-12-05 21:24:50 UTC (rev 21681)
@@ -34,9 +34,6 @@
 (use-modules (gnucash report standard-reports))
 (use-modules (gnucash report business-reports))
 
-(define invoice-page gnc:pagename-general)
-(define invoice-name (N_ "Invoice Number"))
-
 (define-macro (addto! alist element)
   `(set! ,alist (cons ,element ,alist)))
 
@@ -244,12 +241,12 @@
     (gnc:register-option gnc:*report-options* new-option))
 
   (gnc:register-inv-option
-   (gnc:make-invoice-option invoice-page invoice-name "x" ""
+   (gnc:make-invoice-option gnc:pagename-general gnc:optname-invoice-number "x" ""
 			    (lambda () '()) #f))
 
   (gnc:register-inv-option
    (gnc:make-string-option
-    invoice-page (N_ "Custom Title")
+    gnc:pagename-general (N_ "Custom Title")
     "z" (N_ "A custom string to replace Invoice, Bill or Expense Voucher")
     ""))
 
@@ -399,7 +396,7 @@
     (define (add-payment-row table used-columns split total-collector reverse-payments?)
       (let* ((t (xaccSplitGetParent split))
 	     (currency (xaccTransGetCurrency t))
-	     (invoice (opt-val invoice-page invoice-name))
+	     (invoice (opt-val gnc:pagename-general gnc:optname-invoice-number))
 	     (owner '())
 	     ;; Depending on the document type, the payments may need to be sign-reversed
 	     (amt (gnc:make-gnc-monetary currency
@@ -656,11 +653,11 @@
   (let* ((document (gnc:make-html-document))
 	 (table '())
 	 (orders '())
-	 (invoice (opt-val invoice-page invoice-name))
+	 (invoice (opt-val gnc:pagename-general gnc:optname-invoice-number))
 	 (owner '())
 	 (references? (opt-val "Display" "References"))
 	 (default-title (_ "Invoice"))
-	 (custom-title (opt-val invoice-page "Custom Title"))
+	 (custom-title (opt-val gnc:pagename-general "Custom Title"))
 	 (title "")
 	 (cust-doc? #f)
 	 (credit-note? #f))
@@ -803,12 +800,3 @@
  'options-generator options-generator
  'renderer reg-renderer
  'in-menu? #t)
-
-(define (gnc:invoice-report-create-internal invoice)
-  (let* ((options (gnc:make-report-options invoice-report-guid))
-         (invoice-op (gnc:lookup-option options invoice-page invoice-name)))
-
-    (gnc:option-set-value invoice-op invoice)
-    (gnc:make-report invoice-report-guid options)))
-
-(export gnc:invoice-report-create-internal)

Modified: gnucash/trunk/src/report/report-system/report-system.scm
===================================================================
--- gnucash/trunk/src/report/report-system/report-system.scm	2011-12-05 06:06:03 UTC (rev 21680)
+++ gnucash/trunk/src/report/report-system/report-system.scm	2011-12-05 21:24:50 UTC (rev 21681)
@@ -171,6 +171,7 @@
 (export gnc:report-run)
 (export gnc:report-templates-for-each)
 (export gnc:report-embedded-list)
+(export gnc:report-template-name-to-id)
 
 ;; html-barchart.scm
 



More information about the gnucash-changes mailing list