[Gnucash-changes] Daniel Lindenaar's patch for posting invoices.

Derek Atkins warlord at cvs.gnucash.org
Fri Oct 15 22:46:49 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.

Tags:
----
gnucash-1-8-branch

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.1461.2.358
retrieving revision 1.1461.2.359
diff -LChangeLog -LChangeLog -u -r1.1461.2.358 -r1.1461.2.359
--- 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: dialog-invoice.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-gnome/dialog-invoice.c,v
retrieving revision 1.81.2.9
retrieving revision 1.81.2.10
diff -Lsrc/business/business-gnome/dialog-invoice.c -Lsrc/business/business-gnome/dialog-invoice.c -u -r1.81.2.9 -r1.81.2.10
--- src/business/business-gnome/dialog-invoice.c
+++ src/business/business-gnome/dialog-invoice.c
@@ -535,10 +535,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))
@@ -563,6 +564,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));
@@ -572,10 +574,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... 
@@ -587,7 +592,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.5
retrieving revision 1.5.2.1
diff -Lsrc/business/business-gnome/dialog-date-close.h -Lsrc/business/business-gnome/dialog-date-close.h -u -r1.5 -r1.5.2.1
--- src/business/business-gnome/dialog-date-close.h
+++ src/business/business-gnome/dialog-date-close.h
@@ -27,16 +27,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.15
retrieving revision 1.15.2.1
diff -Lsrc/business/business-gnome/dialog-date-close.c -Lsrc/business/business-gnome/dialog-date-close.c -u -r1.15 -r1.15.2.1
--- src/business/business-gnome/dialog-date-close.c
+++ src/business/business-gnome/dialog-date-close.c
@@ -25,6 +25,7 @@
   GtkWidget *post_date;
   GtkWidget *acct_combo;
   GtkWidget *memo_entry;
+  GtkWidget *question_check;
   GncBillTerm *terms;
   Timespec *ts, *ts2;
   GList * acct_types;
@@ -32,6 +33,7 @@
   Account *acct;
   char **memo;
   gboolean retval;
+  gboolean answer;
 } DialogDateClose;
 
 static void
@@ -66,7 +68,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));
 }
@@ -209,16 +212,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;
@@ -231,6 +235,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;
@@ -257,6 +263,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));
 
@@ -270,6 +278,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);
 
@@ -302,6 +320,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.2.2.1
retrieving revision 1.2.2.2
diff -Lsrc/business/business-gnome/glade/date-close.glade -Lsrc/business/business-gnome/glade/date-close.glade -u -r1.2.2.1 -r1.2.2.2
--- 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: gncInvoice.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-core/gncInvoice.c,v
retrieving revision 1.56.2.10
retrieving revision 1.56.2.11
diff -Lsrc/business/business-core/gncInvoice.c -Lsrc/business/business-core/gncInvoice.c -u -r1.56.2.10 -r1.56.2.11
--- src/business/business-core/gncInvoice.c
+++ src/business/business-core/gncInvoice.c
@@ -552,6 +552,7 @@
   return invoice->active;
 }
 
+
 gnc_numeric gncInvoiceGetToChargeAmount (GncInvoice *invoice)
 {
   if (!invoice) return gnc_numeric_zero();
@@ -691,7 +692,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;
@@ -795,7 +796,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->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.29.2.4
retrieving revision 1.29.2.5
diff -Lsrc/business/business-core/gncInvoice.h -Lsrc/business/business-core/gncInvoice.h -u -r1.29.2.4 -r1.29.2.5
--- src/business/business-core/gncInvoice.h
+++ src/business/business-core/gncInvoice.h
@@ -81,7 +81,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
Index: business-prefs.scm
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-utils/business-prefs.scm,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -Lsrc/business/business-utils/business-prefs.scm -Lsrc/business/business-utils/business-prefs.scm -u -r1.2.2.2 -r1.2.2.3
--- 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