[invoice+easy-invoice] invoice.scm can generate easy-invoice

invoice.scm can now mimic easy-invoice.scm reports, including a
greater number of options.
This commit is contained in:
Christopher Lam 2018-06-09 00:46:38 +08:00
parent bfde5a17f7
commit 74ebac461b
2 changed files with 79 additions and 17 deletions

View File

@ -190,7 +190,7 @@
(loop (cdr list-of-substrings) (loop (cdr list-of-substrings)
(cons* (gnc:html-markup-br) (car list-of-substrings) result))))) (cons* (gnc:html-markup-br) (car list-of-substrings) result)))))
(define (options-generator) (define (options-generator css-default)
(define gnc:*report-options* (gnc:new-options)) (define gnc:*report-options* (gnc:new-options))
@ -207,6 +207,11 @@
"z" (N_ "A custom string to replace Invoice, Bill or Expense Voucher.") "z" (N_ "A custom string to replace Invoice, Bill or Expense Voucher.")
"")) ""))
(gnc:register-inv-option
(gnc:make-internal-option
"General" "CSS"
css-default))
(gnc:register-inv-option (gnc:register-inv-option
(gnc:make-simple-boolean-option (gnc:make-simple-boolean-option
(N_ "Display Columns") (N_ "Date") (N_ "Display Columns") (N_ "Date")
@ -252,6 +257,26 @@
(N_ "Display Columns") (N_ "Total") (N_ "Display Columns") (N_ "Total")
"n" (N_ "Display the entry's value?") #t)) "n" (N_ "Display the entry's value?") #t))
(gnc:register-inv-option
(gnc:make-simple-boolean-option
(N_ "Display") (N_ "My Company")
"a" (N_ "Display my company name and address?") #f))
(gnc:register-inv-option
(gnc:make-simple-boolean-option
(N_ "Display") (N_ "My Company ID")
"b" (N_ "Display my company ID?") #f))
(gnc:register-inv-option
(gnc:make-simple-boolean-option
(N_ "Display") (N_ "Due Date")
"c" (N_ "Display due date?") #t))
(gnc:register-inv-option
(gnc:make-simple-boolean-option
(N_ "Display") (N_ "Subtotal")
"d" (N_ "Display the subtotals?") #t))
(gnc:register-inv-option (gnc:register-inv-option
(gnc:make-simple-boolean-option (gnc:make-simple-boolean-option
(N_ "Display") (N_ "Individual Taxes") (N_ "Display") (N_ "Individual Taxes")
@ -310,6 +335,7 @@
(let ((show-payments (opt-val "Display" "Payments")) (let ((show-payments (opt-val "Display" "Payments"))
(display-all-taxes (opt-val "Display" "Individual Taxes")) (display-all-taxes (opt-val "Display" "Individual Taxes"))
(display-subtotal? (opt-val "Display" "Subtotal"))
(lot (gncInvoiceGetPostedLot invoice)) (lot (gncInvoiceGetPostedLot invoice))
(txn (gncInvoiceGetPostedTxn invoice)) (txn (gncInvoiceGetPostedTxn invoice))
(currency (gncInvoiceGetCurrency invoice)) (currency (gncInvoiceGetCurrency invoice))
@ -382,8 +408,9 @@
;; all entries done, add subtotals ;; all entries done, add subtotals
(let ((total-collector (gnc:make-commodity-collector))) (let ((total-collector (gnc:make-commodity-collector)))
(add-subtotal-row table used-columns (gncInvoiceGetTotalSubtotal invoice) (if display-subtotal?
"grand-total" (_ "Net Price")) (add-subtotal-row table used-columns (gncInvoiceGetTotalSubtotal invoice)
"grand-total" (_ "Net Price")))
(if display-all-taxes (if display-all-taxes
(for-each (for-each
@ -459,7 +486,7 @@
#t) #t)
table))) table)))
(define (make-invoice-details-table invoice options) (define (make-invoice-details-table invoice options display-due-date?)
;; dual-column. invoice date/due, billingID, terms, job name/number ;; dual-column. invoice date/due, billingID, terms, job name/number
(define (opt-val section name) (define (opt-val section name)
(gnc:option-value (gnc:option-value
@ -483,9 +510,10 @@
invoice-details-table invoice-details-table
(make-date-row (_ "Date") post-date date-format)) (make-date-row (_ "Date") post-date date-format))
(gnc:html-table-append-row! (if display-due-date?
invoice-details-table (gnc:html-table-append-row!
(make-date-row (_ "Due Date") due-date date-format))) invoice-details-table
(make-date-row (_ "Due Date") due-date date-format))))
(gnc:html-table-append-row! invoice-details-table (gnc:html-table-append-row! invoice-details-table
(gnc:make-html-table-cell/size (gnc:make-html-table-cell/size
@ -556,11 +584,12 @@
(strftime date-format (strftime date-format
(localtime date)))) (localtime date))))
(define (make-myname-table book date-format) (define (make-myname-table book date-format display-tax-id?)
;; single-column table. my name, address, and printdate ;; single-column table. my name, address, and printdate
(let* ((table (gnc:make-html-table)) (let* ((table (gnc:make-html-table))
(name (gnc:company-info book gnc:*company-name*)) (name (gnc:company-info book gnc:*company-name*))
(addy (gnc:company-info book gnc:*company-addy*))) (addy (gnc:company-info book gnc:*company-addy*))
(taxid (gnc:company-info book gnc:*company-id*)))
(gnc:html-table-set-style! table "table" (gnc:html-table-set-style! table "table"
'attribute (list "border" 0) 'attribute (list "border" 0)
@ -575,6 +604,9 @@
(if (and addy (not (string-null? addy))) (if (and addy (not (string-null? addy)))
(gnc:html-table-append-row! table (list (multiline-to-html-text addy)))) (gnc:html-table-append-row! table (list (multiline-to-html-text addy))))
(if (and display-tax-id? taxid (not (string-null? taxid)))
(gnc:html-table-append-row! table (list (multiline-to-html-text taxid))))
(gnc:html-table-append-row! table (list (qof-print-date (current-time)))) (gnc:html-table-append-row! table (list (qof-print-date (current-time))))
table)) table))
@ -586,6 +618,9 @@
(invoice (opt-val gnc:pagename-general gnc:optname-invoice-number)) (invoice (opt-val gnc:pagename-general gnc:optname-invoice-number))
(references? (opt-val "Display" "References")) (references? (opt-val "Display" "References"))
(custom-title (opt-val gnc:pagename-general "Custom Title")) (custom-title (opt-val gnc:pagename-general "Custom Title"))
(company-table? (opt-val "Display" "My Company"))
(display-tax-id? (opt-val "Display" "My Company ID"))
(display-due-date? (opt-val "Display" "Due Date"))
(title-string (lambda (title custom-title) (if (string-null? custom-title) title custom-title)))) (title-string (lambda (title custom-title) (if (string-null? custom-title) title custom-title))))
(if (null? invoice) (if (null? invoice)
@ -609,30 +644,36 @@
(else (else
(_ "Invoice")))) (_ "Invoice"))))
(title (title-string default-title custom-title)) (title (title-string default-title custom-title))
(invoice-title (format #f (_"~a #~a") title (gncInvoiceGetID invoice)))
(entry-table (make-entry-table invoice (entry-table (make-entry-table invoice
(gnc:report-options report-obj) (gnc:report-options report-obj)
cust-doc? credit-note?))) cust-doc? credit-note?)))
(gnc:html-document-set-title! document (format #f (_"~a #~a") title (gnc:html-document-set-title! document invoice-title)
(gncInvoiceGetID invoice)))
(gnc:html-document-set-style-text! document invoice-css) (gnc:html-document-set-style-text! document (opt-val "General" "CSS"))
(let ((main-table (gnc:make-html-table))) (let ((main-table (gnc:make-html-table)))
(gnc:html-table-append-row! main-table
(gnc:make-html-table-cell/size
1 2 (gnc:make-html-div/markup
"invoice-title" invoice-title)))
(gnc:html-table-append-row! main-table (gnc:html-table-append-row! main-table
(list #f (list #f
(gnc:make-html-div/markup (gnc:make-html-div/markup
"invoice-details-table" "invoice-details-table"
(make-invoice-details-table invoice options)))) (make-invoice-details-table invoice options display-due-date?))))
(gnc:html-table-append-row! main-table (gnc:html-table-append-row! main-table
(list (gnc:make-html-div/markup (list (gnc:make-html-div/markup
"client-table" "client-table"
(make-client-table owner orders)) (make-client-table owner orders))
(gnc:make-html-div/markup (and company-table?
"company-table" (make-myname-table book date-format)))) (gnc:make-html-div/markup
"company-table" (make-myname-table book date-format display-tax-id?)))))
(gnc:html-table-append-row! main-table (gnc:html-table-append-row! main-table
(gnc:make-html-table-cell/size (gnc:make-html-table-cell/size
@ -660,12 +701,32 @@
document)) document))
(define invoice-report-guid "5123a759ceb9483abf2182d01c140e8d") (define invoice-report-guid "5123a759ceb9483abf2182d01c140e8d")
(define easy-invoice-guid "67112f318bef4fc496bdc27d106bbda4")
(gnc:define-report (gnc:define-report
'version 1 'version 1
'name (N_ "Printable Invoice") 'name (N_ "Printable Invoice")
'report-guid invoice-report-guid 'report-guid invoice-report-guid
'menu-path (list gnc:menuname-business-reports) 'menu-path (list gnc:menuname-business-reports)
'options-generator options-generator 'options-generator (lambda () (options-generator easy-invoice-css))
'renderer reg-renderer 'renderer reg-renderer
'in-menu? #t) 'in-menu? #t)
#;
(gnc:define-report
'version 1
'name (N_ "Easy Invoice")
'report-guid easy-invoice-guid
'menu-path (list gnc:menuname-business-reports)
'options-generator (lambda () (options-generator easy-invoice-css))
'renderer reg-renderer
'in-menu? #t)
(define (gnc:easy-invoice-report-create-internal invoice)
(let* ((options (gnc:make-report-options easy-invoice-guid))
(invoice-op (gnc:lookup-option options gnc:pagename-general gnc:optname-invoice-number)))
(gnc:option-set-value invoice-op invoice)
(gnc:make-report easy-invoice-guid options)))
(export gnc:easy-invoice-report-create-internal)

View File

@ -202,7 +202,8 @@
(set-option! options "Display" disp-col-name setting)) (set-option! options "Display" disp-col-name setting))
(case variant (case variant
((invoice) ((invoice)
'("Individual Taxes" "Totals" "References" "Billing Terms" '("My Company" "My Company ID" "Due Date"
"Individual Taxes" "Totals" "Subtotal" "References" "Billing Terms"
"Billing ID" "Invoice Notes" "Payments" "Job Details")) "Billing ID" "Invoice Notes" "Payments" "Job Details"))
((fancy-invoice) ((fancy-invoice)
'("Individual Taxes" "Totals" "References" "Billing Terms" '("Individual Taxes" "Totals" "References" "Billing Terms"