Here you go. Seems to be a nice css template. You should submit for inclusion ^_^
On Fri, 3 Jul 2020 at 11:24, <lo...@clickworkorange.com> wrote: > Still locked in battle with my invoice template. While testing a few > changes I noticed they weren't being picked up - because I was editing > the wrong file. A search revealed no less than five(!) different > locations where I had copies of the template files: > > ~/.local/share/gnucash/ > ~/.config/gnucash/ > ~/.gnucash > /usr/share/gnucash/scm/gnucash/report/ > /usr/share/gnucash/scm/gnucash/reports/ > > I guess at least some of these are left-overs from earlier versions. > Perhaps I should apt-get purge and start over. Having perused the wiki > it is my understanding that custom template files should (now) go in > ~/.config/gnucash/, but if I put everything in there and dump the other > duplicates I get an error "Template file "cwo-invoice.eguile.scm" can > not be read". My template consists of the following files: > > cwo-invoice.eguile.scm > cwo-invoice.scm > cwo-invoice.css > > I also have a config-user.scm in ~/.config/gnucash/ which contains > (load "~/.config/gnucash/cwo-invoice.scm"). Where do I put cwo- > invoice.eguile.scm so that GnuCash finds it? > > > > _______________________________________________ > gnucash-user mailing list > gnucash-user@gnucash.org > To update your subscription preferences or to unsubscribe: > https://lists.gnucash.org/mailman/listinfo/gnucash-user > If you are using Nabble or Gmane, please see > https://wiki.gnucash.org/wiki/Mailing_Lists for more information. > ----- > Please remember to CC this list on all your replies. > You can do this by using Reply-To-List or Reply-All. >
=cwo= Invoice 000001 Customer-GBP B1 B2 B3 b4 b5 Invoice Date: 04/11/19 Due Date: 04/11/19 myname myaddress1 myaddress2 myaddress3 Date Description Net Price Tax Rate Tax Amount Total Price 02/11/19 Income Standard £100.00 20% £20.00 £120.00 02/11/19 Income Reduced £100.00 5% £5.00 £105.00 Sub-total £200.00 £25.00 £225.00 11/11/19 Payment received, thank you -£225.00 Amount Due £0.00 Inv-GBP Accumulatew Thank you for your patronage! myname myaddress1 myaddress2 myaddress3 myphone Company registered in the UK #
diff --git a/gnucash/report/reports/standard/cwo-invoice.scm b/gnucash/report/reports/standard/cwo-invoice.scm index 693831897..0f14f835b 100644 --- a/gnucash/report/reports/standard/cwo-invoice.scm +++ b/gnucash/report/reports/standard/cwo-invoice.scm @@ -22,25 +22,22 @@ ; - specify a different module name below (eg mycwo-invoice) ; - refer to it from .gnucash/config.user ; (see http://wiki.gnucash.org/wiki/Custom_Reports ) -(define-module (gnucash report cwo-invoice)) +(define-module (gnucash reports standard cwo-invoice)) (cond-expand (guile-2 (use-modules (ice-9 local-eval))) ; for the-environment (else )) (use-modules (gnucash gnc-module)) -(use-modules (gnucash gettext)) +(use-modules (gnucash core-utils)) (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 reports)) -(use-modules (gnucash report eguile-utilities)) -(use-modules (gnucash report eguile-html-utilities)) -(use-modules (gnucash report eguile-gnc)) +(use-modules (gnucash eguile)) (use-modules (srfi srfi-13)) ; for extra string functions @@ -53,34 +50,33 @@ ;; 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 " ") + (cond + ((or (not taxable) (eq? taxtable '())) + (display " ")) + (else (let* ((amttot (gnc:make-commodity-collector)) - (pctot (gnc:make-numeric-collector)) + (pctot (gnc:make-value-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 + (for-each + (lambda (entry) + (cond + ((eqv? (gncTaxTableEntryGetType entry) GNC-AMT-TYPE-VALUE) + (set! amt? #t) + (amttot 'add curr (gncTaxTableEntryGetAmount entry))) + (else + (set! pc? #t) + (pctot 'add (gncTaxTableEntryGetAmount entry))))) + entries) + (if pc? (format #t "~a%" (pctot 'total #f))) + (if (and amt? pc?) (display " + ")) + (if amt? (display-comm-coll-total amttot #f)) + (if (equal? amt? pc? #f) (display (_ "n/a"))))))) ; neither -(define (coy-info slots key) +(define (coy-info book 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)))) + (or (gnc:company-info book key) "")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Define all the options diff --git a/gnucash/report/reports/support/cwo-invoice.eguile.scm b/gnucash/report/reports/support/cwo-invoice.eguile.scm index 5c87aa2ad..b4a509539 100644 --- a/gnucash/report/reports/support/cwo-invoice.eguile.scm +++ b/gnucash/report/reports/support/cwo-invoice.eguile.scm @@ -21,15 +21,14 @@ (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*)) + (coyname (coy-info book gnc:*company-name*)) + (coycontact (coy-info book gnc:*company-contact*)) + (coyaddr (coy-info book gnc:*company-addy*)) + (coyid (coy-info book gnc:*company-id*)) + (coyphone (coy-info book gnc:*company-phone*)) + (coyfax (coy-info book gnc:*company-fax*)) + (coyurl (coy-info book gnc:*company-url*)) + (coyemail (coy-info book gnc:*company-email*)) (owneraddr (gnc:owner-get-address-dep owner)) (ownername (gnc:owner-get-name-dep owner)) (jobnumber (gncJobGetID (gncOwnerGetJob (gncInvoiceGetOwner opt-invoice)))) @@ -51,8 +50,8 @@ (lambda (s1 s2) (let ((t1 (xaccSplitGetParent s1)) (t2 (xaccSplitGetParent s2))) - (< (car (gnc-transaction-get-date-posted t1)) - (car (gnc-transaction-get-date-posted t2)))))))) + (< (xaccTransGetDate t1) + (xaccTransGetDate t2))))))) ; pre-scan invoice entries to look for discounts and taxes (for entry in entries do @@ -103,7 +102,7 @@ <td align="right"> <h2 class="invoice"> - <small><?scm:d opt-report-title ?> <?scm:d (sprintf #f (_ "%.0f") invoiceid) ?></small> + <small><?scm:d opt-report-title ?> <?scm:d invoiceid ?></small> </h2> </td> </tr> @@ -120,11 +119,11 @@ </tr> <tr> <td align="right"><?scm:d (nbsp (_ "Invoice Date")) ?>: </td> - <td align="left"><?scm:d (gnc-print-date postdate) ?></td> + <td align="left"><?scm:d (qof-print-date postdate) ?></td> </tr> <tr> <td align="right"><?scm:d (nbsp (_ "Due Date")) ?>: </td> - <td align="left"><?scm:d (gnc-print-date duedate) ?></td> + <td align="left"><?scm:d (qof-print-date duedate) ?></td> </tr> <?scm (if (not (string=? billingid "")) (begin ?> <tr> @@ -213,7 +212,7 @@ ?> <tr valign="top"> <?scm (if opt-col-date (begin ?> - <td align="center" ><nobr><?scm:d (nbsp (gnc-print-date (gncEntryGetDate entry))) ?></nobr></td> + <td align="center" ><nobr><?scm:d (nbsp (qof-print-date (gncEntryGetDate entry))) ?></nobr></td> <?scm )) ?> <td align="left"><?scm:d (gncEntryGetDescription entry) ?></td> <!-- td align="left">< ?scm:d (gncEntryGetNotes entry) ?></td --> @@ -282,7 +281,7 @@ ?> <tr valign="top"> <?scm (if opt-col-date (begin ?> - <td align="center"><?scm:d (gnc-print-date (gnc-transaction-get-date-posted t)) ?></td> + <td align="center"><?scm:d (qof-print-date (xaccTransGetDate t)) ?></td> <?scm )) ?> <td align="left" colspan="<?scm:d (+ tbl_cols (if opt-col-date 0 1)) ?>"><?scm:d opt-payment-recd-heading ?></td> <td align="right"><?scm:d (fmtmoney c a) ?></td>
diff --git a/gnucash/report/reports/CMakeLists.txt b/gnucash/report/reports/CMakeLists.txt index dd69a8e3d..6e0d2a5c2 100644 --- a/gnucash/report/reports/CMakeLists.txt +++ b/gnucash/report/reports/CMakeLists.txt @@ -53,6 +53,7 @@ set (reports_standard_SCHEME standard/invoice.scm standard/job-report.scm standard/balsheet-eg.scm + standard/cwo-invoice.scm ) # Reports depending on one of the generator functions from diff --git a/gnucash/report/reports/standard/cwo-invoice.scm b/gnucash/report/reports/standard/cwo-invoice.scm new file mode 100644 index 000000000..693831897 --- /dev/null +++ b/gnucash/report/reports/standard/cwo-invoice.scm @@ -0,0 +1,337 @@ + +;; $Author: chris $ $Date: 2009/07/29 09:31:44 $ $Revision: 1.33 $ +;; Modified by Dmitry Smirnov <only...@member.fsf.org> 16 Feb 2012 +;; +;; 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 + +; If you want to adapt this report privately: +; - copy the report to your .gnucash directory +; - specify a different module name below (eg mycwo-invoice) +; - refer to it from .gnucash/config.user +; (see http://wiki.gnucash.org/wiki/Custom_Reports ) +(define-module (gnucash report cwo-invoice)) + +(cond-expand + (guile-2 + (use-modules (ice-9 local-eval))) ; for the-environment + (else )) +(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 + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; 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 elementspage (N_ "Elements")) +; option names +(define optname-col-date (N_ "column: Date")) +(define optname-col-taxrate (N_ "column: Tax Rate")) +(define optname-col-units (N_ "column: Units")) +(define optname-row-address (N_ "row: Address")) +(define optname-row-contact (N_ "row: Contact")) +(define optname-row-invoice-number (N_ "row: Invoice Number")) +(define optname-row-company-name (N_ "row: Company Name")) +(define optname-report-currency (N_ "Report Currency")) +(define optname-invoice-number-text (N_ "Invoice number text")) +(define optname-to-text (N_ "To text")) +(define optname-ref-text (N_ "Ref text")) +(define optname-jobname-text (N_ "Job Name text")) +(define optname-jobnumber-text (N_ "Job Number text")) +(define optname-jobname-show (N_ "Show Job name")) +(define optname-jobnumber-show (N_ "Show Job number")) +(define optname-invnum-next-to-title (N_ "Invoice number next to title")) +(define optname-border-collapse (N_ "table-border-collapse")) +(define optname-border-color-th (N_ "table-header-border-color")) +(define optname-border-color-td (N_ "table-cell-border-color")) +(define optname-extra-css (N_ "Embedded CSS")) +(define optname-report-title (N_ "Report title")) +(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 (N_ "Logo filename")) +(define optname-logo-width (N_ "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")) + +; 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 + gnc:pagename-general gnc:optname-invoice-number + "a" "" (lambda () '()) + #f)) ;customers-only)) ;-- see above + +(add-option (gnc:make-currency-option gnc:pagename-general optname-report-currency "b" "" "")) + + ;; Elements page options +(add-option (gnc:make-simple-boolean-option elementspage optname-col-date "a" (N_ "Display the date?") #t)) +(add-option (gnc:make-simple-boolean-option elementspage optname-col-taxrate "b" (N_ "Display the Tax Rate?") #t)) +(add-option (gnc:make-simple-boolean-option elementspage optname-col-units "c" (N_ "Display the Units?") #t)) +(add-option (gnc:make-simple-boolean-option elementspage optname-row-contact "d" (N_ "Display the contact?") #t)) +(add-option (gnc:make-simple-boolean-option elementspage optname-row-address "e" (N_ "Display the address?") #t)) +(add-option (gnc:make-simple-boolean-option elementspage optname-row-invoice-number "f" (N_ "Display the Invoice Number?") #t)) +(add-option (gnc:make-simple-boolean-option elementspage optname-row-company-name "g" (N_ "Display the Company Name?") #t)) +(add-option (gnc:make-simple-boolean-option elementspage optname-invnum-next-to-title "h" (N_ "Invoice Number next to title?") #f)) +(add-option (gnc:make-simple-boolean-option elementspage optname-jobname-show "i" (N_ "Display Job name?") #t)) +(add-option (gnc:make-simple-boolean-option elementspage optname-jobnumber-show "j" (N_ "Invoice Job number?") #f)) + + ;; 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.") + "cwo-invoice.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.") + "cwo-invoice.css")) +; (add-option (gnc:make-font-option +; displaypage optname-heading-font "c" +; (N_ "Font to use for the main heading.") "Sans Bold 18")) +; (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 "e" +; (N_ "Name of a file containing a logo to be used on the report.") +; "")) +; (add-option (gnc:make-string-option +; displaypage optname-logo-width "f" (N_ "Width of the 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.") "")) +; (add-option (gnc:make-simple-boolean-option displaypage optname-border-collapse "g" (N_ "Border-collapse?") #f)) +; (add-option (gnc:make-string-option displaypage optname-border-color-th "h" (N_ "CSS color.") "black")) +; (add-option (gnc:make-string-option displaypage optname-border-color-td "i" (N_ "CSS color.") "black")) + + ;; Heading options + (add-option (gnc:make-string-option + ; page / name / orderkey / tooltip / default + headingpage optname-report-title "a" "" (_ "Invoice"))) + (add-option (gnc:make-string-option + headingpage optname-units "b" "" (_ "Units"))) + (add-option (gnc:make-string-option + headingpage optname-qty "c" "" (_ "Qty"))) + (add-option (gnc:make-string-option + headingpage optname-unit-price "d" "" (_ "Unit Price"))) + (add-option (gnc:make-string-option + headingpage optname-disc-rate "e" "" (_ "Discount Rate"))) + (add-option (gnc:make-string-option + headingpage optname-disc-amount "f" "" (_ "Discount Amount"))) + (add-option (gnc:make-string-option + headingpage optname-net-price "g" "" (_ "Net Price"))) + (add-option (gnc:make-string-option + headingpage optname-tax-rate "h" "" (_ "Tax Rate"))) + (add-option (gnc:make-string-option + headingpage optname-tax-amount "i" "" (_ "Tax Amount"))) + (add-option (gnc:make-string-option + headingpage optname-total-price "j" "" (_ "Total Price"))) + (add-option (gnc:make-string-option + headingpage2 optname-subtotal "a" "" (_ "Sub-total"))) + (add-option (gnc:make-string-option + headingpage2 optname-amount-due "b" "" (_ "Amount Due"))) + (add-option (gnc:make-string-option + headingpage2 optname-payment-recd "c" "" + (_ "Payment received, thank you"))) + (add-option (gnc:make-string-option headingpage2 optname-invoice-number-text + "d" "" (N_ "Invoice number: "))) + (add-option (gnc:make-string-option headingpage2 optname-to-text + "e" "" (N_ "To: "))) + (add-option (gnc:make-string-option headingpage2 optname-ref-text + "f" "" (N_ "Your ref: "))) + (add-option (gnc:make-string-option headingpage2 optname-jobnumber-text + "g" "" (N_ "Job number: "))) + (add-option (gnc:make-string-option headingpage2 optname-jobname-text + "h" "" (N_ "Job name: "))) + + (add-option (gnc:make-text-option + notespage optname-extra-notes "a" + (_ "Notes added at end of invoice -- may contain HTML markup.") + (_ "Thank you for your patronage!"))) + ;(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)"))) + + (add-option (gnc:make-text-option notespage optname-extra-css "b" + (N_ "Embedded CSS.") "h1.coyname { text-align: left; }")) + (gnc:options-set-default-section + report-options gnc:pagename-general) + + 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 gnc:pagename-general gnc: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 (opt-value displaypage optname-logofile)) + ; (opt-logo-width (opt-value displaypage optname-logo-width)) + (opt-col-date (opt-value elementspage optname-col-date)) + (opt-col-taxrate (opt-value elementspage optname-col-taxrate)) + (opt-col-units (opt-value elementspage optname-col-units)) + (opt-row-contact (opt-value elementspage optname-row-contact)) + (opt-row-address (opt-value elementspage optname-row-address)) + (opt-row-invoice-number (opt-value elementspage optname-row-invoice-number)) + (opt-row-company-name (opt-value elementspage optname-row-company-name)) + (opt-invnum-next-to-title (opt-value elementspage optname-invnum-next-to-title)) + (opt-jobname-show (opt-value elementspage optname-jobname-show)) + (opt-jobnumber-show (opt-value elementspage optname-jobnumber-show)) + (opt-report-currency (opt-value gnc:pagename-general optname-report-currency)) + ; (opt-css-border-collapse (if (opt-value displaypage optname-border-collapse) "border-collapse:collapse;")) + ; (opt-css-border-color-th (opt-value displaypage optname-border-color-th)) + ; (opt-css-border-color-td (opt-value displaypage optname-border-color-td)) + (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-invoice-number-text (opt-value headingpage2 optname-invoice-number-text)) + (opt-to-text (opt-value headingpage2 optname-to-text)) + (opt-ref-text (opt-value headingpage2 optname-ref-text)) + (opt-jobnumber-text (opt-value headingpage2 optname-jobnumber-text)) + (opt-jobname-text (opt-value headingpage2 optname-jobname-text)) + (opt-extra-css (opt-value notespage optname-extra-css)) + (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))) + + (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_ "CWO Invoice") + 'report-guid "6e28a7d672124a8a854a668434f02c7" + 'menu-name (N_ "CWO Invoice") + 'menu-tip (N_ "Display a customer invoice in cwo style") + 'menu-path (list gnc:menuname-business-reports) + 'options-generator options-generator + 'renderer report-renderer) + diff --git a/gnucash/report/reports/support/CMakeLists.txt b/gnucash/report/reports/support/CMakeLists.txt index 23a3d93e6..66aa37325 100644 --- a/gnucash/report/reports/support/CMakeLists.txt +++ b/gnucash/report/reports/support/CMakeLists.txt @@ -2,6 +2,7 @@ set(stylesheets_DATA taxinvoice.css receipt.css balsheet-eg.css + cwo-invoice.css ) install(FILES ${stylesheets_DATA} @@ -11,6 +12,7 @@ set(templates_DATA taxinvoice.eguile.scm receipt.eguile.scm balsheet-eg.eguile.scm + cwo-invoice.eguile.scm ) install(FILES ${templates_DATA} diff --git a/gnucash/report/reports/support/cwo-invoice.css b/gnucash/report/reports/support/cwo-invoice.css new file mode 100644 index 000000000..b4b67538d --- /dev/null +++ b/gnucash/report/reports/support/cwo-invoice.css @@ -0,0 +1,89 @@ +/* Stylesheet for cwo-invoice.scm -- eguile-based Gnucash invoice report */ +/* Version 0.03 */ + +@font-face { + font-family: "DejaVuSansMono"; + src: url("DejaVuSansMono.ttf") format("truetype"); + font-weight: normal; + font-style: normal; +} + +body { +font-family: DejaVuSansMono; +font-size: 80%; +} + +div.main { +position: relative; +margin: 2em; +max-width: 18cm; +min-height: 22cm; +padding: 2em; +border: 1px solid #000; +} + +h1.coyname { +margin: 0em; +padding: 0em; +text-align: left; +font-size: 1.8em; +} +h2.invoice { +padding: 0em; +margin: 0em; +font-size: 1.8em; +} + h2.invoice small { + font-weight: normal; + } + +table { +font-family: DejaVuSansMono; +} +td.subjectname { +} +td.subjectaddr { +padding-bottom: 1em; +} + +table.coytable { +margin-bottom: 1em; +} + +table.entries { +border: none; +border-collapse: collapse; +border-spacing: 0; +empty-cells: show; +} +table.entries th { +background: #ddd; +font-weight: bold; +padding: 0.2em 0.4em; +} +table.entries td { +padding: 0.2em 0.4em; +} +td.invnum { +font-weight: bold; +} +td.subtotal { +font-weight: bold; +} +td.total { +font-weight: bold; +} +table.coytable td, table.coytable tr { +vertical-align: top; +} + +div#footer { +position: absolute; +bottom: 0; +left: 0; +right: 0; +padding: 1em 0; +border-top: 1px solid #000; +font-size: 0.9em; +text-align: center; +} \ No newline at end of file diff --git a/gnucash/report/reports/support/cwo-invoice.eguile.scm b/gnucash/report/reports/support/cwo-invoice.eguile.scm new file mode 100644 index 000000000..5c87aa2ad --- /dev/null +++ b/gnucash/report/reports/support/cwo-invoice.eguile.scm @@ -0,0 +1,340 @@ +<!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 + + (define (display-report opt-invoice owner endowner ownertype) + ;; Main function that creates the CWO Invoice report + (let* (; invoice and company details + (invoiceid (gncInvoiceGetID opt-invoice)) + (credit-note? (gncInvoiceGetIsCreditNote 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-address-dep owner)) + (ownername (gnc:owner-get-name-dep owner)) + (jobnumber (gncJobGetID (gncOwnerGetJob (gncInvoiceGetOwner opt-invoice)))) + (jobname (gncJobGetName (gncOwnerGetJob (gncInvoiceGetOwner opt-invoice)))) + (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? + (tbl_cols 0)) ; number of columns for 'colspan' attributes + + ; 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 (gncEntryGetDocQuantity entry credit-note?)) + (discount (gncEntryGetInvDiscount entry)) + (taxable? (gncEntryGetInvTaxable entry)) + (taxtable (gncEntryGetInvTaxTable entry))) + (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 taxable? ; Also check if the taxable flag is set + (if (not (eq? taxtable '())) + (begin ; presence of a tax table AND taxable flag means it's taxed + (set! tax? #t)))))) + + ; 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 (make-file-url opt-css-file) ?>" type="text/css"> +<?scm )) ?> + +</head> +<body> + +<div class="main"> +<!-- company info --> +<table class="coytable" border="0" width="100%"> +<tr valign="top"> + <td align="left"> + <h1 class="coyname">=cwo=</h1> + </td> + <td align="right"> + <h2 class="invoice"> + + <small><?scm:d opt-report-title ?> <?scm:d (sprintf #f (_ "%.0f") invoiceid) ?></small> + </h2> + </td> +</tr> +</table> +<table border="0" width="100%"> +<tr valign="top"> + <td align="left"> + <table> + <tr> + <td colspan=2 class="subjectname"><strong><?scm:d ownername ?></strong></td> + </tr> + <tr> + <td colspan=2 class="subjectaddr"><?scm:d (nl->br owneraddr) ?></td> + </tr> + <tr> + <td align="right"><?scm:d (nbsp (_ "Invoice Date")) ?>: </td> + <td align="left"><?scm:d (gnc-print-date postdate) ?></td> + </tr> + <tr> + <td align="right"><?scm:d (nbsp (_ "Due Date")) ?>: </td> + <td align="left"><?scm:d (gnc-print-date duedate) ?></td> + </tr> + <?scm (if (not (string=? billingid "")) (begin ?> + <tr> + <td align="right"><?scm:d (nbsp (_ opt-ref-text)) ?></td> + <td align="left"><?scm:d billingid ?></td> + </tr> + <?scm )) ?> + <?scm (if (and opt-jobname-show (not (string=? jobname ""))) (begin ?> + <tr> + <td align="right"><?scm:d (nbsp (_ opt-jobname-text)) ?></td> + <td align="left"><?scm:d jobname ?></td> + </tr> + <?scm )) ?> + </table> + </td> + <td align="right"> + <table> + <tr> + <td align="right"><strong><?scm:d (nl->br coyname) ?></strong></td> + </tr> + <tr> + <td align="right"><?scm:d (nl->br coyaddr) ?></td> + </tr> + </table> + </td> +</tr> +</table> + +<!-- invoice lines table --> +<p> +<table border="1" width="100%" cellpadding="4" cellspacing="0" class="entries"> + <thead> + <tr bgcolor="#ccc" valign="bottom"> + <?scm (if opt-col-date (begin ?> + <th align="center" ><?scm:d (_ "Date") ?></th> + <?scm (set! tbl_cols (+ tbl_cols 1)) )) ?> + <th align="left" width="80%"><?scm:d (_ "Description") ?></th> + <?scm (if (and units? opt-col-units) (begin ?> + <th align="left"><?scm:d opt-units-heading ?></th> + <?scm (set! tbl_cols (+ tbl_cols 1)) )) ?> + <?scm (if (or units? qty?) (begin ?> + <th align="right"><?scm:d opt-qty-heading ?></th> + <?scm (set! tbl_cols (+ tbl_cols 1)) )) ?> + <?scm (if (or units? qty? discount?) (begin ?> + <th align="right"><?scm:d opt-unit-price-heading ?></th> + <?scm (set! tbl_cols (+ tbl_cols 1)) )) ?> + <?scm (if discount? (begin ?> + <th align="right"><?scm:d opt-disc-rate-heading ?></th> + <th align="right"><?scm:d opt-disc-amount-heading ?></th> + <?scm (set! tbl_cols (+ tbl_cols 2)) )) ?> + <?scm (if (and tax? taxtables?) (begin ?> + <th align="right"><?scm:d opt-net-price-heading ?></th> + <?scm (set! tbl_cols (+ tbl_cols 1)) ?> + <?scm (if opt-col-taxrate (begin ?> + <th align="right"><?scm:d opt-tax-rate-heading ?></th> + <?scm (set! tbl_cols (+ tbl_cols 1)) )) ?> + <th align="right"><?scm:d opt-tax-amount-heading ?></th> + <?scm (set! tbl_cols (+ tbl_cols 1)) )) ?> + <th align="right"><?scm:d opt-total-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 (gncEntryGetDocQuantity entry credit-note?)) + (each (gncEntryGetInvPrice entry)) + (action (gncEntryGetAction entry)) + (rval (gncEntryGetDocValue entry #t #t credit-note?)) + (rdiscval (gncEntryGetDocDiscountValue entry #t #t credit-note?)) + (rtaxval (gncEntryGetDocTaxValue entry #t #t credit-note?)) + (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"> + <?scm (if opt-col-date (begin ?> + <td align="center" ><nobr><?scm:d (nbsp (gnc-print-date (gncEntryGetDate entry))) ?></nobr></td> + <?scm )) ?> + <td align="left"><?scm:d (gncEntryGetDescription entry) ?></td> + <!-- td align="left">< ?scm:d (gncEntryGetNotes entry) ?></td --> + <?scm (if opt-col-units (begin ?> + <?scm (if units? (begin ?> + <td align="left"><?scm:d action ?></td> + <?scm )) ?> + <?scm )) ?> + <?scm (if (or units? qty?) (begin ?> + <td align="right"><?scm:d (fmtnumeric qty) ?></td> + <?scm )) ?> + <?scm (if (or units? qty? discount?) (begin ?> + <td align="right"><?scm:d (fmtmoney currency each) ?></td> + <?scm )) ?> + <?scm (if discount? (begin ?> + <?scm (if (equal? disctype GNC-AMT-TYPE-VALUE) (begin ?> + <td align="right"><?scm:d (gnc:monetary->string (gnc:make-gnc-monetary currency disc)) ?></td> + <?scm ) (begin ?> + <td align="right"><?scm:d (fmtnumeric disc) ?>%</td> + <?scm )) ?> + <td align="right"><?scm:d (fmtmoney currency rdiscval) ?></td> + <?scm )) ?> + <?scm (if (and tax? taxtables?) (begin ?> + <td align="right"><?scm:d (fmtmoney currency rval) ?></td> + <?scm (if opt-col-taxrate (begin ?> + <td align="right"><?scm (taxrate taxable taxtable currency) ?></td> + <?scm )) ?> + <td align="right"><?scm:d (fmtmoney currency rtaxval) ?></td> + <?scm )) ?> + <!-- TO DO: need an option about whether to display the tax-inclusive total? --> + <td align="right"><?scm:d (fmtmoney currency (gnc-numeric-add rval rtaxval GNC-DENOM-AUTO GNC-RND-ROUND)) ?></td> + </tr> + <?scm )) ?> + + <!-- subtotals row --> + <?scm (if (or tax? discount? payments?) (begin ?> + <tr valign="top"> + <td align="left" class="subtotal" colspan="<?scm:d + (- tbl_cols (if (and tax? taxtables? opt-col-taxrate) 1 0) + (if (and tax? taxtables?) 1 -1) + (if (and discount?) 1 0) + ) ?>"><strong><?scm:d opt-subtotal-heading ?></strong></td> + <?scm (if discount? (begin ?> + <td align="right" class="subtotal"><strong><?scm (display-comm-coll-total dsc-total #f) ?></strong></td> + <?scm )) ?> + <?scm (if (and tax? taxtables?) (begin ?> + <td align="right" class="subtotal"><strong><?scm (display-comm-coll-total sub-total #f) ?></strong></td> + <?scm (if opt-col-taxrate (begin ?> + <td> </td> + <?scm )) ?> + <td align="right" class="subtotal"><strong><?scm (display-comm-coll-total tax-total #f) ?></strong></td> + <?scm )) ?> + <td align="right" class="subtotal"><strong><?scm (display-comm-coll-total inv-total #f) ?></strong></td> + </tr> + <?scm )) ?> + + <!-- payments row --> + <?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"> + <?scm (if opt-col-date (begin ?> + <td align="center"><?scm:d (gnc-print-date (gnc-transaction-get-date-posted t)) ?></td> + <?scm )) ?> + <td align="left" colspan="<?scm:d (+ tbl_cols (if opt-col-date 0 1)) ?>"><?scm:d opt-payment-recd-heading ?></td> + <td align="right"><?scm:d (fmtmoney c a) ?></td> + </tr> + <?scm ))))) ?> + + <!-- total row --> + <tr valign="top"> + <td align="left" class="total" colspan="<?scm:d (+ tbl_cols 1) ?>"><strong> + <?scm:d opt-amount-due-heading ?><?scm (if (not (string=? (gnc-commodity-get-mnemonic opt-report-currency) "")) (begin ?>, + <?scm:d (gnc-commodity-get-mnemonic opt-report-currency) ?><?scm )) ?></strong></td> + <td align="right" class="total"><strong><?scm (display-comm-coll-total inv-total #f) ?></strong></td> + </tr> + + </tbody> + <?scm ) ?> <!-- end of (let) surrounding table body --> +</table> + +<p><?scm:d termsdesc ?> + +<p><?scm:d (nl->br notes) ?> +<p><?scm:d (nl->br opt-extra-notes) ?> + +<div id="footer"> + <strong><?scm:d coyname ?></strong><br /> + <?scm:d (nl->br coyaddr) ?><br /> + <?scm:d coyphone ?><br /> + <?scm:d coyemail ?><br /> + <?scm:d coyurl ?><br /><br /> + Company registered in the UK #<?scm:d coyid ?> +</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>" (_ "CWO Invoice") "</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>" (_ "CWO Invoice") "</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 +?>
_______________________________________________ gnucash-user mailing list gnucash-user@gnucash.org To update your subscription preferences or to unsubscribe: https://lists.gnucash.org/mailman/listinfo/gnucash-user If you are using Nabble or Gmane, please see https://wiki.gnucash.org/wiki/Mailing_Lists for more information. ----- Please remember to CC this list on all your replies. You can do this by using Reply-To-List or Reply-All.