diff --git a/ChangeLog b/ChangeLog index a0b1d37cd0..93b7766497 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-10-15 Derek Atkins + + * src/business/business-core/gncInvoice.[ch] + * src/business/business-gnome/dialog-date-close.[ch] + * src/business/business-gnome/dialog-invoice.c + * src/business/business-gnome/glade/date-close.glade + * src/business/business-utils/business-prefs.scm + Daniel Lindenaar's patch to implement a check-box in the Invoice Post + Dialog (with a default in the File Preferences) to choose to accumulate + splits when posting an invoice, or post a 1:1 mapping. + 2004-10-13 Derek Atkins * src/import-export/qif-import/qif-object.scm: diff --git a/src/business/business-core/gncInvoice.c b/src/business/business-core/gncInvoice.c index ee54e160a5..a5d3eaefe9 100644 --- a/src/business/business-core/gncInvoice.c +++ b/src/business/business-core/gncInvoice.c @@ -612,6 +612,7 @@ gboolean gncInvoiceGetActive (GncInvoice *invoice) return invoice->active; } + gnc_numeric gncInvoiceGetToChargeAmount (GncInvoice *invoice) { if (!invoice) return gnc_numeric_zero(); @@ -742,7 +743,7 @@ gnc_lot_match_owner_payment (GNCLot *lot, gpointer user_data) Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, Timespec *post_date, Timespec *due_date, - const char * memo) + const char * memo, gboolean accumulatesplits) { Transaction *txn; GNCLot *lot = NULL; @@ -853,7 +854,25 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, gncEntryGetBillAccount (entry)); if (this_acc) { if (gnc_numeric_check (value) == GNC_ERROR_OK) { - splitinfo = gncAccountValueAdd (splitinfo, this_acc, value); + if (accumulatesplits) { + gncAccountValueAdd (splitinfo, this_acc, value); + } else { + Split *split; + + split = xaccMallocSplit (invoice->inst.book); + /* set action and memo? */ + + xaccSplitSetMemo (split, gncEntryGetDescription (entry)); + xaccSplitSetAction (split, type); + + xaccSplitSetBaseValue (split, (reverse ? gnc_numeric_neg (value) + : value), + invoice->currency); + xaccAccountBeginEdit (this_acc); + xaccAccountInsertSplit (this_acc, split); + xaccAccountCommitEdit (this_acc); + xaccTransAppendSplit (txn, split); + } /* If there is a credit-card account, and this is a CCard * payment type, the don't add it to the total, and instead diff --git a/src/business/business-core/gncInvoice.h b/src/business/business-core/gncInvoice.h index f09b028ba1..7eba91883d 100644 --- a/src/business/business-core/gncInvoice.h +++ b/src/business/business-core/gncInvoice.h @@ -111,7 +111,7 @@ GList * gncInvoiceGetEntries (GncInvoice *invoice); Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, Timespec *posted_date, Timespec *due_date, - const char *memo); + const char *memo, gboolean accumulatesplits); /** * UNpost this invoice. This will destroy the posted transaction and diff --git a/src/business/business-gnome/dialog-date-close.c b/src/business/business-gnome/dialog-date-close.c index 3f528a0d61..ca05ca34cb 100644 --- a/src/business/business-gnome/dialog-date-close.c +++ b/src/business/business-gnome/dialog-date-close.c @@ -42,6 +42,7 @@ typedef struct _dialog_date_close_window { GtkWidget *post_date; GtkWidget *acct_combo; GtkWidget *memo_entry; + GtkWidget *question_check; GncBillTerm *terms; Timespec *ts, *ts2; GList * acct_types; @@ -49,6 +50,7 @@ typedef struct _dialog_date_close_window { Account *acct; char **memo; gboolean retval; + gboolean answer; } DialogDateClose; static void @@ -83,7 +85,8 @@ gnc_dialog_date_close_ok_cb (GtkWidget *widget, gpointer user_data) if (ddc->memo_entry && ddc->memo) *(ddc->memo) = gtk_editable_get_chars (GTK_EDITABLE (ddc->memo_entry), 0, -1); - + if (ddc->question_check) + ddc->answer = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ddc->question_check)); ddc->retval = TRUE; gnome_dialog_close (GNOME_DIALOG (ddc->dialog)); } @@ -226,16 +229,17 @@ post_date_changed_cb (GNCDateEdit *gde, gpointer d) } gboolean -gnc_dialog_dates_acct_parented (GtkWidget *parent, const char *message, +gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message, const char *ddue_label_message, const char *post_label_message, const char *acct_label_message, + const char *question_check_message, gboolean ok_is_default, GList * acct_types, GNCBook *book, GncBillTerm *terms, /* Returned Data... */ Timespec *ddue, Timespec *post, - char **memo, Account **acct) + char **memo, Account **acct, gboolean *answer) { DialogDateClose *ddc; GtkWidget *hbox; @@ -248,6 +252,8 @@ gnc_dialog_dates_acct_parented (GtkWidget *parent, const char *message, if (!message || !ddue_label_message || !post_label_message || !acct_label_message || !acct_types || !book || !ddue || !post || !acct) return FALSE; + if (question_check_message && !answer) + return FALSE; ddc = g_new0 (DialogDateClose, 1); ddc->ts = ddue; @@ -274,6 +280,8 @@ gnc_dialog_dates_acct_parented (GtkWidget *parent, const char *message, ddc->post_date = gnc_date_edit_new (time(NULL), FALSE, FALSE); gtk_box_pack_start (GTK_BOX(date_box), ddc->post_date, TRUE, TRUE, 0); + ddc->question_check = glade_xml_get_widget(xml, "question_check"); + if (parent) gnome_dialog_set_parent (GNOME_DIALOG(ddc->dialog), GTK_WINDOW(parent)); @@ -287,6 +295,16 @@ gnc_dialog_dates_acct_parented (GtkWidget *parent, const char *message, label = glade_xml_get_widget (xml, "acct_label"); gtk_label_set_text (GTK_LABEL (label), acct_label_message); + if (question_check_message) + { + gtk_label_set_text(GTK_LABEL(GTK_BIN(ddc->question_check)->child), question_check_message); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ddc->question_check), *answer); + } else { + gtk_widget_hide(ddc->question_check); + gtk_widget_hide(glade_xml_get_widget(xml, "hide1")); + } + + /* Set the post date widget */ gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->post_date), *post); @@ -319,6 +337,8 @@ gnc_dialog_dates_acct_parented (GtkWidget *parent, const char *message, retval = ddc->retval; *acct = ddc->acct; + if (question_check_message) + *answer = ddc->answer; g_free (ddc); return retval; diff --git a/src/business/business-gnome/dialog-date-close.h b/src/business/business-gnome/dialog-date-close.h index b9a77dbd27..25f37abeab 100644 --- a/src/business/business-gnome/dialog-date-close.h +++ b/src/business/business-gnome/dialog-date-close.h @@ -44,16 +44,40 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message, */ gboolean -gnc_dialog_dates_acct_parented (GtkWidget *parent, const char *message, +gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message, const char *ddue_label_message, const char *post_label_message, const char *acct_label_message, + const char *question_check_message, gboolean ok_is_default, GList * acct_types, GNCBook *book, GncBillTerm *terms, /* Returned Data... */ Timespec *ddue, Timespec *post, - char **memo, Account **acct); + char **memo, Account **acct, gboolean *answer); + +#define gnc_dialog_dates_acct_parented(parent, message, \ + ddue_label_message, \ + post_label_message, \ + acct_label_message, \ + ok_is_default, \ + acct_types, book, \ + terms, \ + /* Returned Data... */ \ + ddue, post, \ + memo, acct) \ + gnc_dialog_dates_acct_question_parented (parent, message, \ + ddue_label_message, \ + post_label_message, \ + acct_label_message, \ + NULL, \ + ok_is_default, \ + acct_types, book, \ + terms, \ + /* Returned Data... */ \ + ddue, post, \ + memo, acct, NULL) \ + gboolean gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message, diff --git a/src/business/business-gnome/dialog-invoice.c b/src/business/business-gnome/dialog-invoice.c index 20b027f760..eeab65ae5e 100644 --- a/src/business/business-gnome/dialog-invoice.c +++ b/src/business/business-gnome/dialog-invoice.c @@ -616,10 +616,11 @@ gnc_invoice_window_postCB (GtkWidget *widget, gpointer data) { InvoiceWindow *iw = data; GncInvoice *invoice; - char *message, *memo, *ddue_label, *post_label, *acct_label; + char *message, *memo, *ddue_label, *post_label, *acct_label, *question_label; Account *acc = NULL; GList * acct_types = NULL; Timespec ddue, postdate; + gboolean accumulate; /* Make sure the invoice is ok */ if (!gnc_invoice_window_verify_ok (iw)) @@ -644,6 +645,7 @@ gnc_invoice_window_postCB (GtkWidget *widget, gpointer data) ddue_label = _("Due Date"); post_label = _("Post Date"); acct_label = _("Post to Account"); + question_label = _("Accumulate Splits?"); /* Determine the type of account to post to */ acct_types = gnc_business_account_types (&(iw->owner)); @@ -653,10 +655,13 @@ gnc_invoice_window_postCB (GtkWidget *widget, gpointer data) ddue = postdate; memo = NULL; - if (!gnc_dialog_dates_acct_parented (iw->dialog, message, ddue_label, - post_label, acct_label, TRUE, + /* Get the default for the accumulate option */ + accumulate = gnc_lookup_boolean_option("Business", "Accumulate splits on Post?", TRUE); + + if (!gnc_dialog_dates_acct_question_parented (iw->dialog, message, ddue_label, + post_label, acct_label, question_label, TRUE, acct_types, iw->book, iw->terms, - &ddue, &postdate, &memo, &acc)) + &ddue, &postdate, &memo, &acc, &accumulate)) return; /* Yep, we're posting. So, save the invoice... @@ -668,7 +673,7 @@ gnc_invoice_window_postCB (GtkWidget *widget, gpointer data) gnc_invoice_window_ok_save (iw); /* ... post it; post date is set to now ... */ - gncInvoicePostToAccount (invoice, acc, &postdate, &ddue, memo); + gncInvoicePostToAccount (invoice, acc, &postdate, &ddue, memo, accumulate); gncInvoiceCommitEdit (invoice); gnc_resume_gui_refresh (); diff --git a/src/business/business-gnome/glade/date-close.glade b/src/business/business-gnome/glade/date-close.glade index 37a58045b3..592bb1c719 100644 --- a/src/business/business-gnome/glade/date-close.glade +++ b/src/business/business-gnome/glade/date-close.glade @@ -382,6 +382,23 @@ False + + + GtkLabel + hide1 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + @@ -457,6 +474,20 @@ Placeholder + + + GtkCheckButton + question_check + True + + False + True + + 0 + False + False + + diff --git a/src/business/business-utils/business-prefs.scm b/src/business/business-utils/business-prefs.scm index b12cb79fb2..fd2c4a9099 100644 --- a/src/business/business-utils/business-prefs.scm +++ b/src/business/business-utils/business-prefs.scm @@ -42,6 +42,15 @@ 1.0 ;; step size )) +(gnc:register-configuration-option + (gnc:make-simple-boolean-option + gnc:*business-label* (N_ "Accumulate splits on Post?") + "f0" (N_ (string-append + "Whether multiple entries in an invoice which transfer to " + "the same account should be accumulated into a single split by default." + "This setting can be changed in the Post dialog.")) + #t)) + (gnc:register-configuration-option (gnc:make-simple-boolean-option gnc:*business-label* (N_ "Invoice Tax Included?")