From b706fc43ea8a73bd8262e5aef0aa50d8b0e86ce4 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Wed, 14 Sep 2011 12:39:13 +0000 Subject: [PATCH] [21257] Change default post date: * customer invoices: post at the current date * bills/vouchers: post at the last date on the bill/voucher git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/2.4@21258 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/business/business-gnome/dialog-invoice.c | 31 +++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/business/business-gnome/dialog-invoice.c b/src/business/business-gnome/dialog-invoice.c index 0fe7a59af6..121cdea35d 100644 --- a/src/business/business-gnome/dialog-invoice.c +++ b/src/business/business-gnome/dialog-invoice.c @@ -644,7 +644,7 @@ gnc_invoice_window_postCB (GtkWidget *widget, gpointer data) KvpFrame *kvpf; KvpValue *kvp_val; const char *text; - EntryList *entries; + EntryList *entries, *entries_iter; GncEntry* entry; gboolean reverse; gboolean show_dialog = TRUE; @@ -698,8 +698,31 @@ gnc_invoice_window_postCB (GtkWidget *widget, gpointer data) /* Determine which commodity we're working with */ acct_commodities = gnc_business_commodities(&(iw->owner)); + /* Get the invoice entries */ + entries = gncInvoiceGetEntries (invoice); + + /* Find the most suitable post date. + * For Customer Invoices that would be today. + * For Vendor Bills and Employee Vouchers + * that would be the date of the most recent invoice entry. + * Failing that, today is used as a fallback */ + postdate = timespec_now(); + + if (entries && ((gncInvoiceGetOwnerType (invoice) == GNC_OWNER_VENDOR) || + (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_EMPLOYEE))) + { + postdate = gncEntryGetDate ((GncEntry*)entries->data); + for (entries_iter = entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter)) + { + Timespec entrydate; + + entrydate = gncEntryGetDate ((GncEntry*)entries_iter->data); + if (timespec_cmp(&entrydate, &postdate) > 0) + postdate = entrydate; + } + } + /* Get the due date and posted account */ - postdate = gncInvoiceGetDateOpened (invoice); ddue = postdate; memo = NULL; @@ -728,11 +751,11 @@ gnc_invoice_window_postCB (GtkWidget *widget, gpointer data) /* Fill in the conversion prices with feedback from the user */ text = _("One or more of the entries are for accounts different from the invoice/bill currency. You will be asked a conversion rate for each."); - for (entries = gncInvoiceGetEntries(invoice); entries != NULL; entries = g_list_next(entries)) + for (entries_iter = entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter)) { Account *this_acc; - entry = (GncEntry*)entries->data; + entry = (GncEntry*)entries_iter->data; this_acc = (reverse ? gncEntryGetInvAccount (entry) : gncEntryGetBillAccount (entry));