r21706 - gnucash/trunk/src - Implement setting the date for duplicating multiple invoices.

Christian Stimming cstim at code.gnucash.org
Sat Dec 10 16:10:17 EST 2011


Author: cstim
Date: 2011-12-10 16:10:17 -0500 (Sat, 10 Dec 2011)
New Revision: 21706
Trac: http://svn.gnucash.org/trac/changeset/21706

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/business/business-gnome/dialog-invoice.h
   gnucash/trunk/src/gnome-utils/dialog-dup-trans.c
   gnucash/trunk/src/gnome-utils/dialog-dup-trans.h
Log:
Implement setting the date for duplicating multiple invoices.

Along the way, the "dialog date" dialog accepts a GDate argument instead of
a time_t because the user enters a date, not a date-and-time.

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-12-10 21:10:05 UTC (rev 21705)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-12-10 21:10:17 UTC (rev 21706)
@@ -62,6 +62,7 @@
 #include "dialog-billterms.h"
 #include "dialog-account.h"
 #include "guile-mappings.h"
+#include "dialog-dup-trans.h"
 
 #include "dialog-query-list.h"
 
@@ -476,7 +477,7 @@
     GncInvoice *invoice = iw_get_invoice (iw);
 
     if (invoice)
-        gnc_ui_invoice_duplicate (invoice, TRUE);
+        gnc_ui_invoice_duplicate (invoice, TRUE, NULL);
 }
 
 void gnc_invoice_window_entryUpCB (GtkWidget *widget, gpointer data)
@@ -2469,11 +2470,10 @@
 }
 
 
-InvoiceWindow * gnc_ui_invoice_duplicate (GncInvoice *old_invoice, gboolean open_properties)
+InvoiceWindow * gnc_ui_invoice_duplicate (GncInvoice *old_invoice, gboolean open_properties, const GDate *new_date)
 {
     InvoiceWindow *iw;
     GncInvoice *new_invoice = NULL;
-    Timespec new_date;
     gchar *new_id;
     GList *node;
     GDate new_date_gdate;
@@ -2503,9 +2503,17 @@
     g_free(new_id);
 
     // Modify the date to today
-    timespecFromTime_t(&new_date, gnc_timet_get_today_start());
-    new_date_gdate = timespec_to_gdate(new_date);
-    gncInvoiceSetDateOpened(new_invoice, new_date);
+    if (new_date)
+    {
+        new_date_gdate = *new_date;
+    }
+    else
+    {
+        GDate *tmp = gnc_g_date_new_today();
+        new_date_gdate = *tmp;
+        g_date_free(tmp);
+    }
+    gncInvoiceSetDateOpenedGDate(new_invoice, &new_date_gdate);
 
     // Also modify the date of all entries to today
     //g_warning("We have %d entries", g_list_length(gncInvoiceGetEntries(new_invoice)));
@@ -2585,27 +2593,35 @@
         return;
     pay_invoice_direct (*invoice_p, user_data);
 }
+struct multi_duplicate_invoice_data
+{
+    GDate date;
+};
 
 static void multi_duplicate_invoice_one(gpointer data, gpointer user_data)
 {
     GncInvoice *old_invoice = data;
+    struct multi_duplicate_invoice_data *dup_user_data = user_data;
+
+    g_assert(dup_user_data);
     if (old_invoice)
     {
         GncInvoice *new_invoice;
         // In this simplest form, we just use the existing duplication
         // algorithm, only without opening the "edit invoice" window for editing
         // the number etc. for each of the invoices.
-        InvoiceWindow *iw = gnc_ui_invoice_duplicate(old_invoice, FALSE);
+        InvoiceWindow *iw = gnc_ui_invoice_duplicate(old_invoice, FALSE, &dup_user_data->date);
         // FIXME: Now we could use this invoice and manipulate further data.
         g_assert(iw);
         new_invoice = iw->created_invoice;
-        //g_assert(new_invoice); // FIXME: This is NULL?!?
+        g_assert(new_invoice); // FIXME: This is NULL?!?
     }
 }
 
 static void
 multi_duplicate_invoice_cb (GList *invoice_list, gpointer user_data)
 {
+    struct _invoice_select_window *sw = user_data; // unused, though
     g_return_if_fail (invoice_list);
     switch (g_list_length(invoice_list))
     {
@@ -2615,15 +2631,28 @@
     {
         // Duplicate exactly one invoice
         GncInvoice *old_invoice = invoice_list->data;
-        gnc_ui_invoice_duplicate(old_invoice, TRUE);
+        gnc_ui_invoice_duplicate(old_invoice, TRUE, NULL);
         return;
     }
     default:
     {
+        // Duplicate multiple invoices. We ask for a date first.
+        struct multi_duplicate_invoice_data dup_user_data;
+        gboolean dialog_ok;
+
+        // Default date: Today
+        g_date_set_time_t(&dup_user_data.date, time(NULL));
+        dialog_ok = gnc_dup_date_dialog (NULL, _("Date of duplicated entries"), &dup_user_data.date);
+        if (!dialog_ok)
+        {
+            // User pressed cancel, so don't duplicate anything here.
+            return;
+        }
+
         // Note: If we want to have a more sophisticated duplication, we might want
         // to ask for particular data right here, then insert this data upon
         // duplication.
-        g_list_foreach(invoice_list, multi_duplicate_invoice_one, user_data);
+        g_list_foreach(invoice_list, multi_duplicate_invoice_one, &dup_user_data);
         return;
     }
     }

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.h	2011-12-10 21:10:05 UTC (rev 21705)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.h	2011-12-10 21:10:17 UTC (rev 21706)
@@ -54,8 +54,19 @@
 /* Create and edit an invoice */
 InvoiceWindow * gnc_ui_invoice_edit (GncInvoice *invoice);
 InvoiceWindow * gnc_ui_invoice_new (GncOwner *owner, QofBook *book);
-InvoiceWindow * gnc_ui_invoice_duplicate (GncInvoice *invoice, gboolean open_properties);
 
+/** Create a new invoice as a duplicate of the given existing invoice.
+ *
+ * \param invoice The invoice which is being duplicated
+ * \param open_properties If TRUE, open the "invoice properties" dialog window after creating the new invoice
+ * \param new_date If non-NULL, use this date as the date for the "opening date" and also as date for all invoice entries.
+ *
+ * \return The InvoiceWindow structure that contains a whole lot of things,
+ * among others the "created_invoice" as a GncInvoice* pointer on the newly
+ * created invoice.
+ */
+InvoiceWindow * gnc_ui_invoice_duplicate (GncInvoice *invoice, gboolean open_properties, const GDate *new_date);
+
 /* Search for invoices */
 GNCSearchWindow * gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book);
 

Modified: gnucash/trunk/src/gnome-utils/dialog-dup-trans.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-dup-trans.c	2011-12-10 21:10:05 UTC (rev 21705)
+++ gnucash/trunk/src/gnome-utils/dialog-dup-trans.c	2011-12-10 21:10:17 UTC (rev 21706)
@@ -152,7 +152,8 @@
 }
 
 static gboolean
-gnc_dup_trans_dialog_internal (GtkWidget * parent, const char* title, time_t *date_p,
+gnc_dup_trans_dialog_internal (GtkWidget * parent, const char* title,
+                               time_t *date_p, GDate *gdate_p,
                                const char *num, char **out_num)
 {
     DupTransDialog *dt_dialog;
@@ -175,7 +176,9 @@
 
     if (title)
     {
-        gtk_label_set_text(GTK_LABEL (dt_dialog->duplicate_title_label), title);
+        gchar *full_text = g_strdup_printf("<b>%s</b>", title);
+        gtk_label_set_markup(GTK_LABEL (dt_dialog->duplicate_title_label), full_text);
+        g_free(full_text);
     }
 
     if (!out_num)
@@ -189,7 +192,10 @@
 
     if (result == GTK_RESPONSE_OK)
     {
-        *date_p = gnc_date_edit_get_date (GNC_DATE_EDIT (dt_dialog->date_edit));
+        if (date_p)
+            *date_p = gnc_date_edit_get_date (GNC_DATE_EDIT (dt_dialog->date_edit));
+        if (gdate_p)
+            gnc_date_edit_get_gdate(GNC_DATE_EDIT (dt_dialog->date_edit), gdate_p);
         if (out_num)
             *out_num = g_strdup (gtk_entry_get_text (GTK_ENTRY (dt_dialog->num_edit)));
         ok = TRUE;
@@ -207,11 +213,26 @@
 gnc_dup_trans_dialog (GtkWidget * parent, time_t *date_p,
                       const char *num, char **out_num)
 {
-    return gnc_dup_trans_dialog_internal(parent, NULL, date_p, num, out_num);
+    return gnc_dup_trans_dialog_internal(parent, NULL, date_p, NULL, num, out_num);
 }
 
 gboolean
-gnc_dup_date_dialog (GtkWidget * parent, const char* title, time_t *date_p)
+gnc_dup_trans_dialog_gdate (GtkWidget * parent, GDate *gdate_p,
+                            const char *num, char **out_num)
 {
-    return gnc_dup_trans_dialog_internal(parent, title, date_p, NULL, NULL);
+    time_t tmp_time;
+    g_assert(gdate_p);
+
+    tmp_time = timespecToTime_t(gdate_to_timespec(*gdate_p));
+    return gnc_dup_trans_dialog_internal(parent, NULL, &tmp_time, gdate_p, num, out_num);
 }
+
+gboolean
+gnc_dup_date_dialog (GtkWidget * parent, const char* title, GDate *gdate_p)
+{
+    time_t tmp_time;
+    g_assert(gdate_p);
+
+    tmp_time = timespecToTime_t(gdate_to_timespec(*gdate_p));
+    return gnc_dup_trans_dialog_internal(parent, title, &tmp_time, gdate_p, NULL, NULL);
+}

Modified: gnucash/trunk/src/gnome-utils/dialog-dup-trans.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-dup-trans.h	2011-12-10 21:10:05 UTC (rev 21705)
+++ gnucash/trunk/src/gnome-utils/dialog-dup-trans.h	2011-12-10 21:10:17 UTC (rev 21706)
@@ -45,18 +45,22 @@
 gnc_dup_trans_dialog (GtkWidget * parent, time_t *date_p,
                       const char *num, char **out_num);
 
+gboolean
+gnc_dup_trans_dialog_gdate (GtkWidget * parent, GDate *gdate_p,
+                            const char *num, char **out_num);
 
+
 /**
  * Opens up a window to ask for a date for the duplicated element
  *
  * \param parent The parent of the window to be created
  * \param title The text of the title label
  * \param date  The initial date to use, and the output
- *                   parameter for the new date
+ *                   parameter for the new date. Must not be NULL.
  *
  * \return TRUE if user closes dialog with 'OK', otherwise FALSE
  */
 gboolean
-gnc_dup_date_dialog (GtkWidget * parent, const char* title, time_t *date_p);
+gnc_dup_date_dialog (GtkWidget * parent, const char* title, GDate *date);
 
 #endif // DIALOGDUPTRANS_H



More information about the gnucash-changes mailing list