gnucash master: New business report for printing receipts

Geert Janssens gjanssens at code.gnucash.org
Mon Dec 22 10:02:07 EST 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/0820090e (commit)
	from  https://github.com/Gnucash/gnucash/commit/7d5f0a66 (commit)



commit 0820090e753049120913b95c85dce3276c2eb695
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Mon Dec 22 15:48:27 2014 +0100

    New business report for printing receipts
    
    This report was originally developped by Manfred Usselman
    Some small tweaks were needed to make it work on current master.
    
    It is designed for and tested with a StarMedia TSP100
    receipt printer using a 72mm  wide print roll.
    However using a different css file the same report
    can be adapted to any printer that can be directly
    used via your OS' print system

diff --git a/src/report/business-reports/Makefile.am b/src/report/business-reports/Makefile.am
index 8ea9dfe..526c121 100644
--- a/src/report/business-reports/Makefile.am
+++ b/src/report/business-reports/Makefile.am
@@ -5,6 +5,7 @@ gncscmmod_DATA = \
    easy-invoice.scm \
    fancy-invoice.scm \
    taxinvoice.scm \
+   receipt.scm \
    invoice.scm \
    job-report.scm \
    owner-report.scm \
@@ -20,6 +21,8 @@ gncscmtpldir = ${GNC_SCM_INSTALL_DIR}/gnucash/report
 gncscmtpl_DATA = \
    taxinvoice.eguile.scm \
    taxinvoice.css \
+   receipt.eguile.scm \
+   receipt.css \
    balsheet-eg.css \
    balsheet-eg.eguile.scm
 
diff --git a/src/report/business-reports/business-reports.scm b/src/report/business-reports/business-reports.scm
index 7b2bcf2..48e8d02 100644
--- a/src/report/business-reports/business-reports.scm
+++ b/src/report/business-reports/business-reports.scm
@@ -114,6 +114,7 @@
 (use-modules (gnucash report invoice))
 (use-modules (gnucash report easy-invoice))
 (use-modules (gnucash report taxinvoice))
+(use-modules (gnucash report receipt))
 (use-modules (gnucash report owner-report))
 (use-modules (gnucash report job-report))
 (use-modules (gnucash report payables))
diff --git a/src/report/business-reports/receipt.css b/src/report/business-reports/receipt.css
new file mode 100644
index 0000000..7d6763f
--- /dev/null
+++ b/src/report/business-reports/receipt.css
@@ -0,0 +1,114 @@
+/* Stylesheet for receipt.scm -- eguile-based Gnucash invoice report */
+/* Version 0.03 */
+
+/**
+;; 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, write to the Free Software
+;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+;; 02111-1307 USA
+**/
+
+/* Note that body and table font family and size will be overridden */
+/* by separate report options.                                      */
+  table { /* table does not inherit font sizes for some reason */
+      width: 72mm;
+      table-layout: auto;
+  }
+  table.entries {
+    border: 0;
+    border-spacing: 0.1em;
+    empty-cells: show;
+  }
+  table.entries th {
+    font-weight: bold;
+    padding: 0.2em 0.4em;
+    font-size: 0.9em;
+    border-top: 1px dashed black;
+    border-bottom: 1px dashed black;
+  }
+  table.entries td {
+    padding: 0.2em 0.4em;
+  }
+  td.invnum {
+    font-size: 120%;
+    font-weight: bold;
+  }
+  td.subtotal {
+    font-weight: bold;
+  }
+
+  td.total_first {
+    border-top: 1px dashed black;
+  }
+  td.total {
+    font-size: 1.1em;
+    /* font-weight: bold; */
+  }
+  td.total_last {
+    border-bottom: 1px dashed black;
+  }
+
+
+  table.coytable td, table.coytable tr {
+    vertical-align: top;
+  }
+  h1.coyname {
+    margin-top: 0em;
+    padding-top: 0em;
+    text-align: left;
+  }
+  h2.invoice {
+    padding-top: 0em;
+    margin-top: 0em;
+  }
+/* new entries below */
+
+body {
+  color: black; background-color: white;
+  font-size: 100.01%;
+  font-family: Helvetica,Arial,sans-serif;
+  text-align: center;
+  margin: 11mm 4mm 0mm 4mm;  /* padding: 1em; */
+  width:  72mm;
+}
+
+img.logo {
+  margin: 0;
+}
+
+div#content {
+  min-width: 16em;
+}
+div#content h1 {
+  font-size: 1.2em;
+  margin: 0.5em 0 0.5em 0;
+}
+div#content h2 {
+  font-size: 1.1em;
+  margin: 0.5em 0 0.5em 0;
+}
+div#content p {
+  font-size:1em;
+  margin: 0;
+}
+div#products {
+  margin: 0;
+  text-align: left;
+}
+div#totals {
+  margin: 0;
+  text-align: left;
+  border-top: 1px dashed black;
+  border-bottom: 1px dashed black;
+}
+
diff --git a/src/report/business-reports/receipt.eguile.scm b/src/report/business-reports/receipt.eguile.scm
new file mode 100644
index 0000000..36009e1
--- /dev/null
+++ b/src/report/business-reports/receipt.eguile.scm
@@ -0,0 +1,315 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+   "http://www.w3.org/TR/html4/loose.dtd">
+<?scm
+(let ((x 42)) ; only here to allow (define)s
+              ; i.e. to avoid "Bad define placement" error
+
+;; receipt.eguile.scm
+;; GnuCash report template
+;;
+;; This file is a mixture of HTML and Guile --
+;; see eguile-gnc.scm for 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, write to the Free Software
+;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+;; 02111-1307 USA
+
+  (define (display-report opt-invoice owner endowner ownertype)
+    ;; Main function that creates the receipt invoice report
+    (let* (; invoice and company details
+           (invoiceid  (gncInvoiceGetID         opt-invoice))
+           (book       (gncInvoiceGetBook       opt-invoice))
+           (postdate   (gncInvoiceGetDatePosted opt-invoice))
+           (duedate    (gncInvoiceGetDateDue    opt-invoice))
+           (billingid  (gncInvoiceGetBillingID  opt-invoice))
+           (notes      (gncInvoiceGetNotes      opt-invoice))
+           (terms      (gncInvoiceGetTerms      opt-invoice))
+           (termsdesc  (gncBillTermGetDescription terms))
+           (lot        (gncInvoiceGetPostedLot  opt-invoice))
+           (txn        (gncInvoiceGetPostedTxn  opt-invoice))
+           (currency   (gncInvoiceGetCurrency   opt-invoice))
+           (entries    (gncInvoiceGetEntries    opt-invoice))
+           (splits     '())
+           (slots      (qof-book-get-slots book))
+           (coyname    (coy-info slots gnc:*company-name*))
+           (coycontact (coy-info slots gnc:*company-contact*))
+           (coyaddr    (coy-info slots gnc:*company-addy*))
+           (coyid      (coy-info slots gnc:*company-id*))
+           (coyphone   (coy-info slots gnc:*company-phone*))
+           (coyfax     (coy-info slots gnc:*company-fax*))
+           (coyurl     (coy-info slots gnc:*company-url*))
+           (coyemail   (coy-info slots gnc:*company-email*))
+           (owneraddr  (gnc:owner-get-name-and-address-dep owner))
+           (billcontact (gncAddressGetName (gnc:owner-get-address owner)))
+           ; flags and counters
+           (discount?  #f) ; any discounts on this invoice?
+           (tax?       #f) ; any taxable entries on this invoice?
+           (taxtables? #t) ; are tax tables available in this version?
+           (payments?  #f) ; have any payments been made on this invoice?
+           (units?     #f) ; does any row specify units?
+           (qty?       #f) ; does any row have qty <> 1?
+           (maxcols    5)  ; cols of product line
+           (no-of-items 0)) ; number of items
+
+      ; load splits, if any
+      (if (not (null? lot))
+        (set! splits
+          (sort-list (gnc-lot-get-split-list lot) ; sort by date
+                     (lambda (s1 s2)
+                       (let ((t1 (xaccSplitGetParent s1))
+                             (t2 (xaccSplitGetParent s2)))
+                         (< (car (gnc-transaction-get-date-posted t1))
+                            (car (gnc-transaction-get-date-posted t2))))))))
+
+      ; pre-scan invoice entries to look for discounts and taxes
+      (for entry in entries do
+          (let ((action    (gncEntryGetAction entry))
+                (qty       (gncEntryGetQuantity entry))
+                (discount  (gncEntryGetInvDiscount entry))
+                (taxtable  (gncEntryGetInvTaxTable entry)))
+            (set! no-of-items (+ no-of-items 1))
+            (if (not (string=? action ""))
+              (set! units? #t))
+            (if (not (= (gnc-numeric-to-double qty) 1.0))
+              (set! qty? #t))
+            (if (not (gnc-numeric-zero-p discount)) (set! discount? #t))
+            ;(if taxable - no, this flag is redundant
+            (if (not (eq? taxtable '()))
+              (begin ; presence of a tax table means it's taxed
+                (set! tax? #t)
+                (let ((ttentries (gncTaxTableGetEntries taxtable)))
+                  (if (string-prefix? "#<swig-pointer PriceList" (object->string ttentries))
+                    ; error in SWIG binding -- disable display of tax details
+                    ; (see http://bugzilla.gnome.org/show_bug.cgi?id=573645)
+                    (set! taxtables? #f))))))) ; hack required until Swig is fixed
+
+      ; pre-scan invoice splits to see if any payments have been made
+      (for split in splits do
+          (let* ((t (xaccSplitGetParent split)))
+            (if (not (equal? t txn))
+              (set! payments? #t))))
+
+?>
+
+<!-- ====================================================================== -->
+<!-- The HTML for the invoice starts here -->
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
+<title><?scm:d (_ "Invoice") ?> <?scm:d invoiceid ?></title>
+
+<?scm (if css? (begin ?>
+<link rel="stylesheet" href="<?scm:d opt-css-file ?>" type="text/css">
+<!-- Note that the external stylesheet file is overridden by this following: -->
+<style type="text/css">
+  body {
+    <?scm:d opt-text-font ?>
+  }
+  table { /* table does not inherit font */
+    <?scm:d opt-text-font ?>
+  }
+  div#content h1  {
+    <?scm:d opt-heading-font ?>
+  }
+</style>
+<?scm )) ?>
+
+</head>
+<body>
+
+<div id="content">
+  <!-- footer logo -->
+  <p>
+    <?scm (if (access? opt-logofile-header R_OK) (begin ?>
+      <img align="left" src="<?scm:d opt-logofile-header ?>" alt="logo" class="logo"
+        <?scm (if opt-logo-width-header (begin ?>
+          style="width: <?scm:d opt-logo-width-header ?>"
+        <?scm )) ?>
+      >
+    <?scm )) ?>
+  </p>
+
+  <!-- header texts -->
+
+  <h1><?scm:d (nbsp (_ "Invoice No.")) ?> <?scm:d invoiceid ?></h1>
+  <h2><?scm:d (strftime	opt-date-format (localtime (car (gnc:get-today)))) ?></h2>
+  <p> </p>
+  <?scm (if (not (string=? billcontact "")) (begin ?>
+    <p>Attn: <?scm:d billcontact ?></p><br>
+  <?scm )) ?>
+  <?scm (if (not (string=? owneraddr "")) (begin ?>
+    <p><?scm:d (nl->br owneraddr) ?></p>
+  <?scm )) ?>
+
+  <!-- products -->
+
+  <div id="products">
+
+    <!-- invoice lines table -->
+    <p>
+    <table border="0" width="100%" class="entries">
+      <thead>
+        <tr>
+          <th align="left" ><?scm:d (_ "Date") ?></th>
+          <th align="left" ><?scm:d (_ "Descr.") ?></th>
+          <th align="right"><?scm:d opt-qty-heading ?></th>
+          <th align="right"><?scm:d opt-unit-price-heading ?></th>
+          <th align="right"><?scm:d opt-net-price-heading ?></th>
+        </tr>
+      </thead>
+
+      <tbody> <!-- display invoice entry lines, keeping running totals -->
+        <?scm
+          (let ((tax-total (gnc:make-commodity-collector))
+                (sub-total (gnc:make-commodity-collector))
+                (dsc-total (gnc:make-commodity-collector))
+                (inv-total (gnc:make-commodity-collector)))
+            (for entry in entries do
+                (let ((qty       (gncEntryGetQuantity entry))
+                      (each      (gncEntryGetInvPrice entry))
+                      (action    (gncEntryGetAction entry))
+                      (rval      (gncEntryGetDocValue entry #t #t #f))
+                      (rdiscval  (gncEntryGetDocDiscountValue entry #t #t #f))
+                      (rtaxval   (gncEntryGetDocTaxValue entry #t #t #f))
+                      (disc      (gncEntryGetInvDiscount entry))
+                      (disctype  (gncEntryGetInvDiscountType entry))
+                      (acc       (gncEntryGetInvAccount entry))
+                      (taxable   (gncEntryGetInvTaxable entry))
+                      (taxtable  (gncEntryGetInvTaxTable entry)))
+                  (inv-total 'add currency rval)
+                  (inv-total 'add currency rtaxval)
+                  (tax-total 'add currency rtaxval)
+                  (sub-total 'add currency rval)
+                  (dsc-total 'add currency rdiscval)
+        ?>
+        <tr valign="top">
+          <td align="left"><?scm:d (gnc-print-date (gncEntryGetDate entry)) ?></td>
+          <td align="left" ><?scm:d (gncEntryGetDescription entry) ?></td>
+          <td align="right"><?scm:d (fmtnumeric qty) ?></td>
+          <td align="right"><?scm:d (format #f "~4,2,,,'0f" (gnc-numeric-to-double each)) ?></td>
+          <td align="right" nowrap><?scm:d (format #f "~4,2,,,'0f" (gnc-numeric-to-double rval)) ?>
+          <!-- <td align="right" nowrap><?scm:d (fmtnumeric rval) ?> -->
+              <?scm (if (and tax? taxtables?) (begin ?>
+                 T
+              <?scm ) (begin ?>
+                  
+              <?scm )) ?>
+          </td>
+        </tr>
+
+        <?scm (if (not(equal? 0 (string-length (gncEntryGetNotes entry)))) (begin ?>
+          <tr>
+            <td align="left"> </td>
+            <td align="left" colspan="<?scm:d (- maxcols 1) ?>"><?scm:d (gncEntryGetNotes entry) ?></td>
+          </tr>
+        <?scm )) ?>
+
+        <?scm )) ?>
+
+        <!-- display subtotals row -->
+        <tr valign="top">
+          <td align="center" class="total total_first" colspan="<?scm:d maxcols ?>">
+              <?scm:d "Total No. Items:" ?> 
+              <?scm:d no-of-items ?>
+          </td>
+        </tr>
+
+        <?scm (if tax? (begin ?>
+          <tr valign="top">
+            <td align="left"  class="subtotal" colspan="<?scm:d (- maxcols 2) ?>"><strong><?scm:d opt-net-price-heading ?></strong></td>
+            <td align="right" class="subtotal" colspan="2>"><strong><?scm (display-comm-coll-total sub-total #f) ?></strong></td>
+          </tr>
+          <tr valign="top">
+            <td align="left"  class="subtotal" colspan="<?scm:d (- maxcols 2) ?>"><strong><?scm:d opt-tax-amount-heading ?></strong></td>
+            <td align="right" class="subtotal" colspan="2>"><strong><?scm (display-comm-coll-total tax-total #f) ?></strong></td>
+          </tr>
+        <?scm )) ?>
+
+        <!-- payments -->
+
+        <?scm (if payments? (begin ?>
+          <tr valign="top">
+            <td align="left"  class="subtotal" colspan="<?scm:d (- maxcols 2) ?>"><strong><?scm:d opt-total-price-heading ?></strong></td>
+            <td align="right" class="subtotal" colspan="2>"><strong><?scm (display-comm-coll-total inv-total #f) ?></strong></td>
+          </tr>
+        <?scm )) ?>
+
+        <?scm
+          (if payments?
+            (for split in splits do
+                (let ((t (xaccSplitGetParent split)))
+                  (if (not (equal? t txn)) ; don't process the entry itself as a split
+                    (let ((c (xaccTransGetCurrency t))
+                          (a (xaccSplitGetValue    split)))
+                      (inv-total 'add c a)
+        ?>
+        <tr valign="top">
+          <td align="center"><?scm:d (gnc-print-date (gnc-transaction-get-date-posted t)) ?></td>
+          <td align="left" colspan="<?scm:d (- maxcols 3) ?>"><?scm:d opt-payment-recd-heading ?></td>
+          <td align="right" colspan="2"><?scm:d (fmtmoney c a) ?></td>
+        </tr>
+        <?scm ))))) ?>
+
+        <!-- total row -->
+        <tr valign="top">
+          <td align="left"  class="total total_last" colspan="<?scm:d (- maxcols 2) ?>"><strong><?scm:d opt-amount-due-heading ?></strong></td>
+          <td align="right" class="total total_last" colspan="2>"><strong><?scm (display-comm-coll-total inv-total #f) ?></strong></td>
+        </tr>
+
+      </tbody>
+      <?scm ) ?> <!-- end of (let) surrounding table body -->
+    </table>
+
+  </div>
+
+  <p><?scm:d (nl->br notes) ?>
+  <p><?scm:d (nl->br opt-extra-notes) ?>
+
+  <!-- footer logo -->
+  <p>
+    <?scm (if (access? opt-logofile-footer R_OK) (begin ?>
+      <img align="left" src="<?scm:d opt-logofile-footer ?>" alt="logo" class="logo"
+        <?scm (if opt-logo-width-footer (begin ?>
+          style="width: <?scm:d opt-logo-width-footer ?>"
+        <?scm )) ?>
+      >
+    <?scm )) ?>
+  </p>
+
+</div>
+
+
+<?scm )) ; end of display-report function
+
+  ; 'mainline' code: check for a valid invoice, then display the report
+  (if (null? opt-invoice)
+    (begin
+      (display (string-append "<h2>" (_ "Receipt") "</h2>"))
+      (display (string-append "<p>" (_ "No invoice has been selected -- please use the Options menu to select one.") "</p>")))
+    (let* ((owner     (gncInvoiceGetOwner  opt-invoice))
+           (endowner  (gncOwnerGetEndOwner owner))
+           (ownertype (gncOwnerGetType     endowner)))
+      (if (not (eqv? ownertype GNC-OWNER-CUSTOMER))
+        (begin
+          (display (string-append "<h2>" (_ "Receipt") "</h2>"))
+          (display (string-append "<p>" (_ "This report is designed for customer (sales) invoices only. Please use the Options menu to select an <em>Invoice</em>, not a Bill or Expense Voucher.") "</p>")))
+        (display-report opt-invoice owner endowner ownertype))))
+
+?>
+</div>
+</body>
+</html>
+<?scm
+) ; end of enclosing let
+?>
diff --git a/src/report/business-reports/receipt.scm b/src/report/business-reports/receipt.scm
new file mode 100644
index 0000000..c405215
--- /dev/null
+++ b/src/report/business-reports/receipt.scm
@@ -0,0 +1,282 @@
+
+;; 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, write to the Free Software
+;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+;; 02111-1307 USA
+
+(define-module (gnucash report receipt))
+
+(cond-expand
+  (guile-2
+      (use-modules (ice-9 local-eval)))  ; for the-environment
+  (else ))
+(use-modules (gnucash main))
+(use-modules (gnucash gnc-module))
+(use-modules (gnucash gettext))
+(gnc:module-load "gnucash/report/report-system" 0)
+(gnc:module-load "gnucash/html" 0)
+(gnc:module-load "gnucash/engine" 0)
+
+(use-modules (gnucash report standard-reports))
+(use-modules (gnucash report business-reports))
+
+(use-modules (gnucash report eguile-utilities))
+(use-modules (gnucash report eguile-html-utilities))
+(use-modules (gnucash report eguile-gnc))
+
+(use-modules (srfi srfi-13)) ; for extra string functions
+(use-modules (ice-9 format)) ; for number formatting
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Report-specific routines
+
+(define (taxrate taxable taxtable curr)
+  ;; Display the tax rate applicable to an invoice line.
+  ;; This may be e.g. "15%" or "£5.00" or "15% + £5.00" or "n/a"
+  ;; depending on how complicated the tax table is.
+  ;; (When called from within the eguile template, anything
+  ;; (display)ed becomes part of the HTML string.)
+  (if (or (not taxable) (eq? taxtable '()))
+    (display " ")
+    (let* ((amttot  (gnc:make-commodity-collector))
+           (pctot   (gnc:make-numeric-collector))
+           (entries (gncTaxTableGetEntries taxtable))
+           (amt?    #f)  ; becomes #t if any entries are amounts
+           (pc?     #f)) ; becomes #t if any entries are percentages
+      (for entry in entries do
+          (let ((tttype (gncTaxTableEntryGetType   entry))
+                (ttamt  (gncTaxTableEntryGetAmount entry)))
+            (if (equal? tttype GNC-AMT-TYPE-VALUE)
+              (begin
+                (set! amt? #t)
+                (amttot 'add curr ttamt))
+              (begin
+                (set! pc? #t)
+                (pctot 'add ttamt)))))
+      (if pc? (begin (display (fmtnumeric (pctot 'total #f))) (display "%")))
+      (if (and amt? pc?) (display " + "))        ; both - this seems unlikely in practice
+      (if amt?
+        (display-comm-coll-total amttot #f))
+      (if (and (not amt?) (not pc?)) (display (_ "n/a"))))))        ; neither
+
+(define (coy-info slots key)
+  ;; Extract a value from the company info key-value pairs
+  (kvp-frame-get-slot-path-gslist
+    slots
+    (append gnc:*kvp-option-path* (list gnc:*business-label* key))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Define all the options
+
+; option pages
+(define headingpage  (N_ "Headings 1"))
+(define headingpage2 (N_ "Headings 2"))
+(define notespage    (N_ "Notes"))
+;(define filespage    (N_ "Files"))
+(define displaypage  (N_ "Display"))
+(define generalpage  gnc:pagename-general)
+; option names
+(define optname-report-title   (N_ "Report title"))
+(define optname-invoice-number (N_ "Invoice number"))
+(define optname-template-file  (N_ "Template file"))
+(define optname-css-file       (N_ "CSS stylesheet file"))
+(define optname-heading-font   (N_ "Heading font"))
+(define optname-text-font      (N_ "Text font"))
+(define optname-logofile-header  (N_ "Header logo filename"))
+(define optname-logo-width-header     (N_ "Header logo width"))
+(define optname-logofile-footer  (N_ "Footer logo filename"))
+(define optname-logo-width-footer     (N_ "Footer logo width"))
+(define optname-units          (N_ "Units"))
+(define optname-qty            (N_ "Qty"))
+(define optname-unit-price     (N_ "Unit Price"))
+(define optname-disc-rate      (N_ "Discount Rate"))
+(define optname-disc-amount    (N_ "Discount Amount"))
+(define optname-net-price      (N_ "Net Price"))
+(define optname-tax-rate       (N_ "Tax Rate"))
+(define optname-tax-amount     (N_ "Tax Amount"))
+(define optname-total-price    (N_ "Total Price"))
+(define optname-subtotal       (N_ "Sub-total"))
+(define optname-amount-due     (N_ "Amount Due"))
+(define optname-payment-recd   (N_ "Payment received text"))
+(define optname-extra-notes    (N_ "Extra notes"))
+(define optname-date-format    (N_ "Today date format"))
+
+; Choose only customer invoices
+; (This doesn't work very nicely -- all invoices and bills
+;  are offered for selection, but if a non-customer invoice
+;  is selected, the user is dumped back to viewing the
+;  previous invoice (or none) with no error message)
+(define (customers-only invoice)
+  (let* ((owner     (gncInvoiceGetOwner  invoice))
+         (endowner  (gncOwnerGetEndOwner owner))
+         (ownertype (gncOwnerGetType     endowner)))
+    ;(gnc:debug "ownertype is ")(gnc:debug ownertype)
+    (if (eqv? ownertype GNC-OWNER-CUSTOMER)
+      (list #t invoice)
+      (list #f invoice))))
+
+(define (options-generator)
+  ;; Options
+  (define report-options (gnc:new-options))
+  (define (add-option new-option)
+    (gnc:register-option report-options new-option))
+
+  (add-option
+    (gnc:make-invoice-option ; defined in gnucash/scm/business-options.scm
+      generalpage optname-invoice-number
+      "a" "" (lambda () '())
+      #f))        ;customers-only)) ;-- see above
+
+  ;; Display options
+  (add-option (gnc:make-string-option displaypage optname-template-file "a"
+    (N_ "The file name of the eguile template part of this report.  This file should either be in your .gnucash directory, or else in its proper place within the GnuCash installation directories.")
+    "receipt.eguile.scm"))
+  (add-option (gnc:make-string-option displaypage optname-css-file "b"
+    (N_ "The file name of the CSS stylesheet to use with this report.  This file should either be in your .gnucash directory, or else in its proper place within the GnuCash installation directories.")
+    "receipt.css"))
+  (add-option (gnc:make-font-option
+                displaypage optname-heading-font "c"
+                (N_ "Font to use for the main heading") "Sans Bold 14"))
+  (add-option (gnc:make-font-option
+                displaypage optname-text-font "d"
+                (N_ "Font to use for everything else") "Sans 10"))
+  (add-option (gnc:make-pixmap-option
+                displaypage optname-logofile-header "e"
+                (N_ "Name of a file containing a logo to be used on the header of the report")
+                "Receipt_header.jpg"))
+  (add-option (gnc:make-string-option
+                displaypage optname-logo-width-header "f" (N_ "Width of the header logo in CSS format, e.g. 10% or 32px.  Leave blank to display the logo at its natural width.  The height of the logo will be scaled accordingly.") "72mm"))
+  (add-option (gnc:make-pixmap-option
+                displaypage optname-logofile-footer "g"
+                (N_ "Name of a file containing a logo to be used on the footer of the report")
+                "Receipt_footer.jpg"))
+  (add-option (gnc:make-string-option
+                displaypage optname-logo-width-footer "h" (N_ "Width of the footer logo in CSS format, e.g. 10% or 32px.  Leave blank to display the logo at its natural width.  The height of the logo will be scaled accordingly.") "72mm"))
+
+  (add-option (gnc:make-string-option
+                displaypage  optname-date-format "i" (N_ "The format for the date->string conversion for today's date.") "%A, %b %e, %Y at %l:%M %P"))
+
+  ;; Heading options
+  (add-option (gnc:make-string-option
+                ; page / name / orderkey / tooltip / default
+                headingpage optname-report-title "a" "" (N_ "Invoice")))
+  (add-option (gnc:make-string-option
+                headingpage optname-units "b" "" (N_ "Units")))
+  (add-option (gnc:make-string-option
+                headingpage optname-qty "c" "" (N_ "Qty")))
+  (add-option (gnc:make-string-option
+                headingpage optname-unit-price "d" "" (N_ "Unit Price")))
+  (add-option (gnc:make-string-option
+                headingpage optname-disc-rate "e" "" (N_ "Discount Rate")))
+  (add-option (gnc:make-string-option
+                headingpage optname-disc-amount "f" "" (N_ "Discount Amount")))
+  (add-option (gnc:make-string-option
+                headingpage optname-net-price "g" "" (N_ "Net Price")))
+  (add-option (gnc:make-string-option
+                headingpage optname-tax-rate "h" "" (N_ "Tax Rate")))
+  (add-option (gnc:make-string-option
+                headingpage optname-tax-amount "i" "" (N_ "Tax Amount")))
+  (add-option (gnc:make-string-option
+                headingpage optname-total-price "j" "" (N_ "Total Price")))
+  (add-option (gnc:make-string-option
+                headingpage2 optname-subtotal "a" "" (N_ "Sub-total")))
+  (add-option (gnc:make-string-option
+                headingpage2 optname-amount-due "b" "" (N_ "Amount Due")))
+  (add-option (gnc:make-string-option
+                headingpage2 optname-payment-recd "c" ""
+                (N_ "Payment received, thank you")))
+
+  (add-option (gnc:make-text-option
+                notespage optname-extra-notes "a"
+                (N_ "Notes added at end of invoice -- may contain HTML markup")
+                ""))
+                ;(N_ "(Development version -- don't rely on the numbers on this report without double-checking them.<br>Change the 'Extra Notes' option to get rid of this message)")))
+
+  (gnc:options-set-default-section
+    report-options generalpage)
+
+  report-options)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Create the report
+
+(define (report-renderer report-obj)
+  ;; Create and return the report as either an HTML string
+  ;; or an <html-document>
+  (define (opt-value section name)
+    ; wrapper for option routines
+    (define (get-opt section name)
+      (gnc:lookup-option (gnc:report-options report-obj) section name))
+    (gnc:option-value (get-opt section name)))
+
+  ; Get all the options
+  (let* ((document                  (gnc:make-html-document))
+         (opt-invoice               (opt-value generalpage  optname-invoice-number))
+         (opt-template-file         (find-file
+                                      (opt-value displaypage optname-template-file)))
+         (opt-css-file              (find-file
+                                      (opt-value displaypage optname-css-file)))
+         (opt-heading-font          (font-name-to-style-info
+                                      (opt-value displaypage optname-heading-font)))
+         (opt-text-font             (font-name-to-style-info
+                                      (opt-value displaypage optname-text-font)))
+         (opt-logofile-header       (opt-value displaypage  optname-logofile-header))
+         (opt-logo-width-header     (opt-value displaypage  optname-logo-width-header))
+         (opt-logofile-footer       (opt-value displaypage  optname-logofile-footer))
+         (opt-logo-width-footer     (opt-value displaypage  optname-logo-width-footer))
+         (opt-date-format           (opt-value displaypage  optname-date-format))
+         (opt-report-title          (opt-value headingpage  optname-report-title))
+         (opt-units-heading         (opt-value headingpage  optname-units))
+         (opt-qty-heading           (opt-value headingpage  optname-qty))
+         (opt-unit-price-heading    (opt-value headingpage  optname-unit-price))
+         (opt-disc-rate-heading     (opt-value headingpage  optname-disc-rate))
+         (opt-disc-amount-heading   (opt-value headingpage  optname-disc-amount))
+         (opt-net-price-heading     (opt-value headingpage  optname-net-price))
+         (opt-tax-rate-heading      (opt-value headingpage  optname-tax-rate))
+         (opt-tax-amount-heading    (opt-value headingpage  optname-tax-amount))
+         (opt-total-price-heading   (opt-value headingpage  optname-total-price))
+         (opt-subtotal-heading      (opt-value headingpage2 optname-subtotal))
+         (opt-amount-due-heading    (opt-value headingpage2 optname-amount-due))
+         (opt-payment-recd-heading  (opt-value headingpage2 optname-payment-recd))
+         (opt-extra-notes           (opt-value notespage    optname-extra-notes))
+         (css? #t) ;(and (defined? 'gnc-html-engine-supports-css) (gnc-html-engine-supports-css)))
+         (html #f))
+
+    (set! html (eguile-file-to-string
+                 opt-template-file
+                 (the-environment)))
+
+    (gnc:debug "receipt.scm: css? is " css?)
+    (gnc:debug "receipt.scm: defined is " (defined? 'gnc-html-engine-supports-css))
+    (gnc:debug "receipt.scm - generated html:") (gnc:debug html)
+
+    (if css? ; return report as document or html, depending on version
+      html
+      (let ((document (gnc:make-html-document)))
+        (gnc:html-document-add-object! document html)
+        document))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Define the report
+
+(gnc:define-report
+  'version 1
+  'name (N_ "Receipt")
+  'report-guid "7eb3df21073d4c33920a0257da15fba5"
+  'menu-name (N_ "Receipt")
+  'menu-tip (N_ "Display a customer invoice as receipt, cash vousher")
+  'menu-path (list gnc:menuname-business-reports)
+  'options-generator options-generator
+  'renderer report-renderer)
+
+



Summary of changes:
 src/report/business-reports/Makefile.am            |   3 +
 src/report/business-reports/business-reports.scm   |   1 +
 .../{taxinvoice.css => receipt.css}                |  75 +++--
 src/report/business-reports/receipt.eguile.scm     | 315 +++++++++++++++++++++
 src/report/business-reports/receipt.scm            | 282 ++++++++++++++++++
 5 files changed, 660 insertions(+), 16 deletions(-)
 copy src/report/business-reports/{taxinvoice.css => receipt.css} (58%)
 create mode 100644 src/report/business-reports/receipt.eguile.scm
 create mode 100644 src/report/business-reports/receipt.scm



More information about the gnucash-changes mailing list