mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
srfi-19: Fix date->string to work with guile-1.4/slib-2d2
gncEntry: add date_entered for better sorting change SetDate methods from "Timespec*" to "Timespec" update entry ledger to use new function calls Fix a comparison bug in Entry/Invoice/Order. Compares now work correctly. Updated invoice report; use date->string to print today's date; flags to print notes. Added more flexibility in what gets printed. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6748 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
38f3120e14
commit
a2f360a38b
@ -26,6 +26,10 @@
|
||||
;; of the file, by rewriting the code with use of more Guile native
|
||||
;; functions that do more work in a "chunk".
|
||||
|
||||
;;; Modifications from the "official" implementation.
|
||||
;;;
|
||||
;;; Removed all non r5rs-isms that I detected (i.e :optional).
|
||||
|
||||
(define-module (srfi srfi-19)
|
||||
:use-module (srfi srfi-8)
|
||||
:use-module (srfi srfi-9))
|
||||
@ -1209,12 +1213,14 @@
|
||||
port))))))))))))
|
||||
|
||||
|
||||
(define (date->string date . format-string)
|
||||
(define (date->string date format-string)
|
||||
(call-with-output-string
|
||||
(lambda (str-port)
|
||||
(let ((fmt-str (:optional format-string "~c")))
|
||||
(let ((fmt-str format-string))
|
||||
(if (not (and format-string (> (string-length format-string) 0)))
|
||||
(set! fmt-str "~c"))
|
||||
(priv:date-printer date 0 fmt-str (string-length fmt-str) str-port)
|
||||
(get-output-string str-port)))))
|
||||
))))
|
||||
|
||||
(define (priv:char->int ch)
|
||||
(case ch
|
||||
|
@ -26,6 +26,7 @@ struct _gncEntry {
|
||||
|
||||
GUID guid;
|
||||
Timespec date;
|
||||
Timespec date_entered;
|
||||
char * desc;
|
||||
char * action;
|
||||
gnc_numeric quantity;
|
||||
@ -141,10 +142,17 @@ void gncEntrySetGUID (GncEntry *entry, const GUID *guid)
|
||||
addObj (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetDate (GncEntry *entry, Timespec *date)
|
||||
void gncEntrySetDate (GncEntry *entry, Timespec date)
|
||||
{
|
||||
if (!entry || !date) return;
|
||||
entry->date = *date;
|
||||
if (!entry) return;
|
||||
entry->date = date;
|
||||
entry->dirty = TRUE;
|
||||
}
|
||||
|
||||
void gncEntrySetDateEntered (GncEntry *entry, Timespec date)
|
||||
{
|
||||
if (!entry) return;
|
||||
entry->date_entered = date;
|
||||
entry->dirty = TRUE;
|
||||
}
|
||||
|
||||
@ -265,6 +273,13 @@ Timespec gncEntryGetDate (GncEntry *entry)
|
||||
return entry->date;
|
||||
}
|
||||
|
||||
Timespec gncEntryGetDateEntered (GncEntry *entry)
|
||||
{
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
if (!entry) return ts;
|
||||
return entry->date_entered;
|
||||
}
|
||||
|
||||
const char * gncEntryGetDescription (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
@ -428,13 +443,16 @@ int gncEntryCompare (GncEntry *a, GncEntry *b)
|
||||
if (a && !b) return 1;
|
||||
|
||||
compare = timespec_cmp (&(a->date), &(b->date));
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
compare = timespec_cmp (&(a->date_entered), &(b->date_entered));
|
||||
if (compare) return compare;
|
||||
|
||||
compare = safe_strcmp (a->desc, b->desc);
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
compare = safe_strcmp (a->action, b->action);
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
return guid_compare (&(a->guid), &(b->guid));
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ void gncEntryDestroy (GncEntry *entry);
|
||||
|
||||
/* Set Functions */
|
||||
|
||||
void gncEntrySetDate (GncEntry *entry, Timespec *date);
|
||||
void gncEntrySetDate (GncEntry *entry, Timespec date);
|
||||
void gncEntrySetDateEntered (GncEntry *entry, Timespec date);
|
||||
void gncEntrySetDescription (GncEntry *entry, const char *desc);
|
||||
void gncEntrySetAction (GncEntry *entry, const char *action);
|
||||
void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity);
|
||||
@ -52,6 +53,7 @@ void gncEntrySetTaxAccount (GncEntry *entry, Account *acc);
|
||||
GNCBook * gncEntryGetBook (GncEntry *entry);
|
||||
const GUID * gncEntryGetGUID (GncEntry *entry);
|
||||
Timespec gncEntryGetDate (GncEntry *entry);
|
||||
Timespec gncEntryGetDateEntered (GncEntry *entry);
|
||||
const char * gncEntryGetDescription (GncEntry *entry);
|
||||
const char * gncEntryGetAction (GncEntry *entry);
|
||||
gnc_numeric gncEntryGetQuantity (GncEntry *entry);
|
||||
|
@ -222,7 +222,8 @@ void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry)
|
||||
if (old) gncInvoiceRemoveEntry (old, entry);
|
||||
|
||||
gncEntrySetInvoice (entry, invoice);
|
||||
invoice->entries = g_list_append (invoice->entries, entry);
|
||||
invoice->entries = g_list_insert_sorted (invoice->entries, entry,
|
||||
(GCompareFunc)gncEntryCompare);
|
||||
invoice->dirty = TRUE;
|
||||
}
|
||||
|
||||
@ -647,16 +648,16 @@ int gncInvoiceCompare (GncInvoice *a, GncInvoice *b)
|
||||
if (a && !b) return 1;
|
||||
|
||||
compare = safe_strcmp (a->id, b->id);
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
compare = timespec_cmp (&(a->date_opened), &(b->date_opened));
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
compare = timespec_cmp (&(a->date_posted), &(b->date_posted));
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
compare = timespec_cmp (&(a->date_paid), &(b->date_paid));
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
return guid_compare (&(a->guid), &(b->guid));
|
||||
}
|
||||
|
@ -175,7 +175,8 @@ void gncOrderAddEntry (GncOrder *order, GncEntry *entry)
|
||||
if (old) gncOrderRemoveEntry (old, entry);
|
||||
|
||||
gncEntrySetOrder (entry, order);
|
||||
order->entries = g_list_append (order->entries, entry);
|
||||
order->entries = g_list_insert_sorted (order->entries, entry,
|
||||
(GCompareFunc)gncEntryCompare);
|
||||
order->dirty = TRUE;
|
||||
}
|
||||
|
||||
@ -292,13 +293,13 @@ int gncOrderCompare (GncOrder *a, GncOrder *b)
|
||||
if (a && !b) return 1;
|
||||
|
||||
compare = safe_strcmp (a->id, b->id);
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
compare = timespec_cmp (&(a->opened), &(b->opened));
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
compare = timespec_cmp (&(a->closed), &(b->closed));
|
||||
if (!compare) return compare;
|
||||
if (compare) return compare;
|
||||
|
||||
return guid_compare (&(a->guid), &(b->guid));
|
||||
}
|
||||
|
@ -56,7 +56,12 @@ gnc_entry_ledger_save (GncEntryLedger *ledger, gboolean do_commit)
|
||||
|
||||
gnc_suspend_gui_refresh ();
|
||||
|
||||
if (entry == blank_entry)
|
||||
if (entry == blank_entry) {
|
||||
Timespec ts;
|
||||
ts.tv_sec = time(NULL);
|
||||
ts.tv_nsec = 0;
|
||||
gncEntrySetDateEntered (blank_entry, ts);
|
||||
|
||||
switch (ledger->type) {
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
gncOrderAddEntry (ledger->order, blank_entry);
|
||||
@ -67,8 +72,10 @@ gnc_entry_ledger_save (GncEntryLedger *ledger, gboolean do_commit)
|
||||
break;
|
||||
default:
|
||||
/* Nothing to do for viewers */
|
||||
g_warning ("blank entry traversed in a viewer");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gnc_table_save_cells (ledger->table, entry);
|
||||
|
||||
|
@ -160,7 +160,7 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
blank_entry = gncEntryCreate (ledger->book);
|
||||
gncEntrySetDate (blank_entry, &ledger->last_date_entered);
|
||||
gncEntrySetDate (blank_entry, ledger->last_date_entered);
|
||||
ledger->blank_entry_guid = *gncEntryGetGUID (blank_entry);
|
||||
break;
|
||||
default:
|
||||
|
@ -704,7 +704,7 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
|
||||
gnc_date_cell_commit ((DateCell *) cell);
|
||||
|
||||
gnc_date_cell_get_date ((DateCell *) cell, &ts);
|
||||
gncEntrySetDate (entry, &ts);
|
||||
gncEntrySetDate (entry, ts);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
|
@ -69,15 +69,15 @@
|
||||
|
||||
(let* ((col-vector (make-vector columns-used-size #f))
|
||||
(set-col (make-set-col col-vector)))
|
||||
(set-col (opt-val "Display" "Date") 0)
|
||||
(set-col (opt-val "Display" "Description") 1)
|
||||
(set-col (opt-val "Display" "Action") 2)
|
||||
(set-col (opt-val "Display" "Quantity") 3)
|
||||
(set-col (opt-val "Display" "Price") 4)
|
||||
(set-col (opt-val "Display" "Discount") 5)
|
||||
(set-col (opt-val "Display" "Tax") 6)
|
||||
(set-col (opt-val "Display" "Tax Value") 7)
|
||||
(set-col (opt-val "Display" "Value") 8)
|
||||
(set-col (opt-val "Display Columns" "Date") 0)
|
||||
(set-col (opt-val "Display Columns" "Description") 1)
|
||||
(set-col (opt-val "Display Columns" "Action") 2)
|
||||
(set-col (opt-val "Display Columns" "Quantity") 3)
|
||||
(set-col (opt-val "Display Columns" "Price") 4)
|
||||
(set-col (opt-val "Display Columns" "Discount") 5)
|
||||
(set-col (opt-val "Display Columns" "Tax") 6)
|
||||
(set-col (opt-val "Display Columns" "Tax Value") 7)
|
||||
(set-col (opt-val "Display Columns" "Total") 8)
|
||||
col-vector))
|
||||
|
||||
(define (make-heading-list column-vector)
|
||||
@ -100,7 +100,7 @@
|
||||
(if (taxvalue-col column-vector)
|
||||
(addto! heading-list (_ "Tax Amount")))
|
||||
(if (value-col column-vector)
|
||||
(addto! heading-list (_ "Value")))
|
||||
(addto! heading-list (_ "Total")))
|
||||
(reverse heading-list)))
|
||||
|
||||
(define (monetary-or-percent numeric currency entry-type)
|
||||
@ -200,47 +200,47 @@
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Date")
|
||||
(N_ "Display Columns") (N_ "Date")
|
||||
"b" (N_ "Display the date?") #t))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Description")
|
||||
(N_ "Display Columns") (N_ "Description")
|
||||
"d" (N_ "Display the description?") #t))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Action")
|
||||
(N_ "Display Columns") (N_ "Action")
|
||||
"g" (N_ "Display the action?") #t))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Quantity")
|
||||
(N_ "Display Columns") (N_ "Quantity")
|
||||
"ha" (N_ "Display the quantity of items?") #t))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Price")
|
||||
(N_ "Display Columns") (N_ "Price")
|
||||
"hb" "Display the price per item?" #t))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Discount")
|
||||
(N_ "Display Columns") (N_ "Discount")
|
||||
"k" (N_ "Display the entry's discount") #t))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Tax")
|
||||
(N_ "Display Columns") (N_ "Tax")
|
||||
"l" (N_ "Display the entry's tax") #f))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Tax Value")
|
||||
(N_ "Display Columns") (N_ "Tax Value")
|
||||
"m" (N_ "Display the entry's monetary tax") #f))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Value")
|
||||
(N_ "Display Columns") (N_ "Total")
|
||||
"n" (N_ "Display the entry's value") #t))
|
||||
|
||||
(gnc:register-inv-option
|
||||
@ -255,9 +255,26 @@
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Terms")
|
||||
(N_ "Display") (N_ "Invoice Terms")
|
||||
"t" (N_ "Display the invoice terms?") #t))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-simple-boolean-option
|
||||
(N_ "Display") (N_ "Invoice Notes")
|
||||
"t" (N_ "Display the invoice notes?") #f))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-text-option
|
||||
(N_ "Display") (N_ "Extra Notes")
|
||||
"u" (N_ "Extra notes to put on the invoice")
|
||||
"Thank you for your patronage"))
|
||||
|
||||
(gnc:register-inv-option
|
||||
(gnc:make-string-option
|
||||
(N_ "Display") (N_ "Today Date Format")
|
||||
"v" (N_ "The format for the date->string conversion for today's date.")
|
||||
"~B ~e, ~Y"))
|
||||
|
||||
(gnc:options-set-default-section gnc:*report-options* "General")
|
||||
|
||||
gnc:*report-options*)
|
||||
@ -316,7 +333,7 @@
|
||||
"grand-total" (cdr this)))
|
||||
(list (cons value-collector (_ "Subtotal"))
|
||||
(cons tax-collector (_ "Tax"))
|
||||
(cons total-collector (_"Total"))))
|
||||
(cons total-collector (_"Amount Due"))))
|
||||
|
||||
(let* ((current (car entries))
|
||||
(current-row-style (if odd-row? "normal-row" "alternate-row"))
|
||||
@ -441,7 +458,7 @@
|
||||
'attribute (list "valign" "top"))
|
||||
table))
|
||||
|
||||
(define (make-myname-table)
|
||||
(define (make-myname-table date-format)
|
||||
(let ((table (gnc:make-html-table)))
|
||||
(gnc:html-table-set-style!
|
||||
table "table"
|
||||
@ -462,10 +479,7 @@
|
||||
(gnc:lookup-global-option "User Info" "User Address"))))
|
||||
(gnc:html-table-append-row!
|
||||
table
|
||||
(list
|
||||
"Day, Month day, year"
|
||||
;;(date->string (current-date) "~A, ~B ~e, ~Y")
|
||||
))
|
||||
(list (date->string (current-date) date-format)))
|
||||
table))
|
||||
|
||||
(define (make-break! document)
|
||||
@ -506,7 +520,7 @@
|
||||
|
||||
(gnc:html-document-add-object!
|
||||
document
|
||||
(make-myname-table))
|
||||
(make-myname-table (opt-val "Display" "Today Date Format")))
|
||||
|
||||
(let ((date-table (make-date-table)))
|
||||
(make-date-row!
|
||||
@ -529,7 +543,7 @@
|
||||
(make-break! document)
|
||||
(make-break! document)
|
||||
|
||||
(if (opt-val "Display" "Terms")
|
||||
(if (opt-val "Display" "Invoice Terms")
|
||||
(let ((terms (gnc:invoice-get-terms invoice)))
|
||||
(if (and terms (> (string-length terms) 0))
|
||||
(gnc:html-document-add-object!
|
||||
@ -543,6 +557,25 @@
|
||||
|
||||
(gnc:html-document-add-object! document table)
|
||||
|
||||
(make-break! document)
|
||||
(make-break! document)
|
||||
|
||||
(if (opt-val "Display" "Invoice Notes")
|
||||
(let ((notes (gnc:invoice-get-notes invoice)))
|
||||
(gnc:html-document-add-object!
|
||||
document
|
||||
(gnc:make-html-text
|
||||
(string-expand notes #\newline "<br>")))))
|
||||
|
||||
(make-break! document)
|
||||
|
||||
(gnc:html-document-add-object!
|
||||
document
|
||||
(gnc:make-html-text
|
||||
(gnc:html-markup-br)
|
||||
(string-expand (opt-val "Display" "Extra Notes") #\newline "<br>")
|
||||
(gnc:html-markup-br)))
|
||||
|
||||
document))
|
||||
|
||||
(gnc:define-report
|
||||
|
Loading…
Reference in New Issue
Block a user