r21258 - gnucash/branches/2.4/src/business/business-gnome - [21257] Change default post date:
Geert Janssens
gjanssens at code.gnucash.org
Wed Sep 14 08:39:14 EDT 2011
Author: gjanssens
Date: 2011-09-14 08:39:13 -0400 (Wed, 14 Sep 2011)
New Revision: 21258
Trac: http://svn.gnucash.org/trac/changeset/21258
Modified:
gnucash/branches/2.4/src/business/business-gnome/dialog-invoice.c
Log:
[21257] Change default post date:
* customer invoices: post at the current date
* bills/vouchers: post at the last date on the bill/voucher
Modified: gnucash/branches/2.4/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/branches/2.4/src/business/business-gnome/dialog-invoice.c 2011-09-14 12:29:59 UTC (rev 21257)
+++ gnucash/branches/2.4/src/business/business-gnome/dialog-invoice.c 2011-09-14 12:39:13 UTC (rev 21258)
@@ -644,7 +644,7 @@
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 @@
/* 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 @@
/* 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));
More information about the gnucash-changes
mailing list