[Gnucash-changes] Daniel Lindenaar's patch for posting invoices.
Derek Atkins
warlord at cvs.gnucash.org
Fri Oct 15 22:49:31 EDT 2004
Log Message:
-----------
Daniel Lindenaar's patch for posting invoices.
* 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.
Modified Files:
--------------
gnucash:
ChangeLog
gnucash/src/business/business-core:
gncInvoice.c
gncInvoice.h
gnucash/src/business/business-gnome:
dialog-date-close.c
dialog-date-close.h
dialog-invoice.c
gnucash/src/business/business-gnome/glade:
date-close.glade
gnucash/src/business/business-utils:
business-prefs.scm
Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1846
retrieving revision 1.1847
diff -LChangeLog -LChangeLog -u -r1.1846 -r1.1847
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,14 @@
+2004-10-15 Derek Atkins <derek at ihtfp.com>
+
+ * 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 <derek at ihtfp.com>
* src/import-export/qif-import/qif-object.scm:
Index: gncInvoice.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-core/gncInvoice.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -Lsrc/business/business-core/gncInvoice.c -Lsrc/business/business-core/gncInvoice.c -u -r1.92 -r1.93
--- src/business/business-core/gncInvoice.c
+++ src/business/business-core/gncInvoice.c
@@ -612,6 +612,7 @@
return invoice->active;
}
+
gnc_numeric gncInvoiceGetToChargeAmount (GncInvoice *invoice)
{
if (!invoice) return gnc_numeric_zero();
@@ -742,7 +743,7 @@
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 @@
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
Index: gncInvoice.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-core/gncInvoice.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -Lsrc/business/business-core/gncInvoice.h -Lsrc/business/business-core/gncInvoice.h -u -r1.41 -r1.42
--- src/business/business-core/gncInvoice.h
+++ src/business/business-core/gncInvoice.h
@@ -111,7 +111,7 @@
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
Index: dialog-invoice.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-gnome/dialog-invoice.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -Lsrc/business/business-gnome/dialog-invoice.c -Lsrc/business/business-gnome/dialog-invoice.c -u -r1.100 -r1.101
--- src/business/business-gnome/dialog-invoice.c
+++ src/business/business-gnome/dialog-invoice.c
@@ -616,10 +616,11 @@
{
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 @@
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 @@
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_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 ();
Index: dialog-date-close.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-gnome/dialog-date-close.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -Lsrc/business/business-gnome/dialog-date-close.h -Lsrc/business/business-gnome/dialog-date-close.h -u -r1.7 -r1.8
--- src/business/business-gnome/dialog-date-close.h
+++ src/business/business-gnome/dialog-date-close.h
@@ -44,16 +44,40 @@
*/
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,
Index: dialog-date-close.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-gnome/dialog-date-close.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lsrc/business/business-gnome/dialog-date-close.c -Lsrc/business/business-gnome/dialog-date-close.c -u -r1.17 -r1.18
--- src/business/business-gnome/dialog-date-close.c
+++ src/business/business-gnome/dialog-date-close.c
@@ -42,6 +42,7 @@
GtkWidget *post_date;
GtkWidget *acct_combo;
GtkWidget *memo_entry;
+ GtkWidget *question_check;
GncBillTerm *terms;
Timespec *ts, *ts2;
GList * acct_types;
@@ -49,6 +50,7 @@
Account *acct;
char **memo;
gboolean retval;
+ gboolean answer;
} DialogDateClose;
static void
@@ -83,7 +85,8 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
retval = ddc->retval;
*acct = ddc->acct;
+ if (question_check_message)
+ *answer = ddc->answer;
g_free (ddc);
return retval;
Index: date-close.glade
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-gnome/glade/date-close.glade,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lsrc/business/business-gnome/glade/date-close.glade -Lsrc/business/business-gnome/glade/date-close.glade -u -r1.3 -r1.4
--- src/business/business-gnome/glade/date-close.glade
+++ src/business/business-gnome/glade/date-close.glade
@@ -382,6 +382,23 @@
<fill>False</fill>
</child>
</widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <name>hide1</name>
+ <label></label>
+ <justify>GTK_JUSTIFY_RIGHT</justify>
+ <wrap>False</wrap>
+ <xalign>1</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ <child>
+ <padding>0</padding>
+ <expand>False</expand>
+ <fill>False</fill>
+ </child>
+ </widget>
</widget>
<widget>
@@ -457,6 +474,20 @@
<class>Placeholder</class>
</widget>
</widget>
+
+ <widget>
+ <class>GtkCheckButton</class>
+ <name>question_check</name>
+ <can_focus>True</can_focus>
+ <label>question</label>
+ <active>False</active>
+ <draw_indicator>True</draw_indicator>
+ <child>
+ <padding>0</padding>
+ <expand>False</expand>
+ <fill>False</fill>
+ </child>
+ </widget>
</widget>
<widget>
Index: business-prefs.scm
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-utils/business-prefs.scm,v
retrieving revision 1.7
retrieving revision 1.8
diff -Lsrc/business/business-utils/business-prefs.scm -Lsrc/business/business-utils/business-prefs.scm -u -r1.7 -r1.8
--- src/business/business-utils/business-prefs.scm
+++ src/business/business-utils/business-prefs.scm
@@ -44,6 +44,15 @@
(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?")
"f1" (N_ (string-append
"Whether tax is included by default in entries on Invoices. "
More information about the gnucash-changes
mailing list