r21550 - gnucash/trunk/src - Add invoice/credit note type field and selector to invoice dialog and

Geert Janssens gjanssens at code.gnucash.org
Thu Nov 10 10:05:06 EST 2011


Author: gjanssens
Date: 2011-11-10 10:05:05 -0500 (Thu, 10 Nov 2011)
New Revision: 21550
Trac: http://svn.gnucash.org/trac/changeset/21550

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/business/business-gnome/gtkbuilder/dialog-invoice.glade
   gnucash/trunk/src/engine/gncInvoice.c
   gnucash/trunk/src/engine/gncInvoice.h
Log:
Add invoice/credit note type field and selector to invoice dialog and
invoice page.

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-11-10 15:04:50 UTC (rev 21549)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-11-10 15:05:05 UTC (rev 21550)
@@ -90,6 +90,7 @@
 void gnc_invoice_window_ok_cb (GtkWidget *widget, gpointer data);
 void gnc_invoice_window_cancel_cb (GtkWidget *widget, gpointer data);
 void gnc_invoice_window_help_cb (GtkWidget *widget, gpointer data);
+void gnc_invoice_type_toggled_cb (GtkWidget *widget, gpointer data);
 void gnc_invoice_id_changed_cb (GtkWidget *widget, gpointer data);
 void gnc_invoice_terms_changed_cb (GtkWidget *widget, gpointer data);
 
@@ -135,6 +136,9 @@
     GtkWidget  * total_tax_label;
 
     /* Data Widgets */
+    GtkWidget  * type_label;
+    GtkWidget  * type_hbox;
+    GtkWidget  * type_choice;
     GtkWidget  * id_entry;
     GtkWidget  * notes_text;
     GtkWidget  * opened_date;
@@ -172,6 +176,7 @@
 
     InvoiceDialogType   dialog_type;
     GncGUID      invoice_guid;
+    gboolean     is_credit_note;
     gint         component_id;
     QofBook    * book;
     GncInvoice * created_invoice;
@@ -323,6 +328,10 @@
             gncInvoiceSetBillTo (invoice, &iw->proj_cust);
     }
 
+    /* Document type can only be modified for a new invoice/credit note */
+    if (iw->dialog_type == NEW_INVOICE)
+        gncInvoiceSetIsCreditNote (invoice, iw->is_credit_note);
+
     gncInvoiceCommitEdit (invoice);
     gnc_resume_gui_refresh ();
 }
@@ -1077,7 +1086,7 @@
 {
     GtkWidget *summarybar;
 
-    iw->total_label	    = NULL;
+    iw->total_label           = NULL;
     iw->total_cash_label      = NULL;
     iw->total_charge_label    = NULL;
     iw->total_subtotal_label  = NULL;
@@ -1085,7 +1094,7 @@
 
     summarybar = gtk_hbox_new (FALSE, 4);
 
-    iw->total_label	    = add_summary_label (summarybar, _("Total:"));
+    iw->total_label           = add_summary_label (summarybar, _("Total:"));
 
     switch (gncOwnerGetType (&iw->owner))
     {
@@ -1112,7 +1121,6 @@
 gnc_invoice_job_changed_cb (GtkWidget *widget, gpointer data)
 {
     InvoiceWindow *iw = data;
-    GncInvoice *invoice;
     char const *msg = "";
 
     if (!iw)
@@ -1122,7 +1130,6 @@
         return FALSE;
 
     gnc_owner_get_owner (iw->job_choice, &(iw->job));
-    invoice = iw_get_invoice (iw);
 
     if (iw->dialog_type == EDIT_INVOICE)
         return FALSE;
@@ -1164,7 +1171,6 @@
     if (iw->owner.owner.undefined == NULL)
     {
         iw->job_choice = NULL;
-
     }
     else
         switch (iw->dialog_type)
@@ -1568,6 +1574,9 @@
         break;
     }
 
+    /* Set the type label */
+    gtk_label_set_text (GTK_LABEL(iw->type_label), iw->is_credit_note ? _("Credit note") : _("Invoice"));
+
     if (iw->owner_choice)
         gtk_widget_show_all (iw->owner_choice);
     if (iw->proj_cust_choice)
@@ -1803,6 +1812,15 @@
 }
 
 void
+gnc_invoice_type_toggled_cb (GtkWidget *widget, gpointer data)
+{
+    InvoiceWindow *iw = data;
+
+    if (!iw) return;
+    iw->is_credit_note = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+}
+
+void
 gnc_invoice_id_changed_cb (GtkWidget *unused, gpointer data)
 {
     InvoiceWindow *iw = data;
@@ -1881,6 +1899,7 @@
     iw->book = bookp;
     iw->dialog_type = type;
     iw->invoice_guid = *gncInvoiceGetGUID (invoice);
+    iw->is_credit_note = gncInvoiceGetIsCreditNote (invoice);
     iw->width = -1;
 
     /* Save this for later */
@@ -2048,6 +2067,7 @@
     gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, iw);
 
     /* Grab the widgets */
+    iw->type_label = GTK_WIDGET (gtk_builder_get_object (builder, "page_type_label"));
     iw->id_entry = GTK_WIDGET (gtk_builder_get_object (builder, "page_id_entry"));
     iw->billing_id_entry = GTK_WIDGET (gtk_builder_get_object (builder, "page_billing_id_entry"));
     iw->terms_menu = GTK_WIDGET (gtk_builder_get_object (builder, "page_terms_menu"));
@@ -2285,6 +2305,22 @@
     g_object_set_data (G_OBJECT (iw->dialog), "dialog_info", iw);
 
     /* Grab the widgets */
+    iw->type_label = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_type_label"));
+    iw->type_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_type_choice_hbox"));
+    iw->type_choice = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_type_invoice"));
+    /* configure the type related widgets based on dialog type and invoice type */
+    if (iw->dialog_type == NEW_INVOICE)
+    {
+        gtk_widget_show_all (iw->type_hbox);
+        gtk_widget_hide (iw->type_label);
+    }
+    else
+    {
+        gtk_widget_hide_all (iw->type_hbox);
+        gtk_widget_show (iw->type_label);
+
+    }
+
     iw->id_entry = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_id_entry"));
     iw->billing_id_entry = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_billing_id_entry"));
     iw->terms_menu = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_terms_menu"));
@@ -2311,8 +2347,10 @@
     gtk_builder_connect_signals_full( builder,
                                        gnc_builder_connect_full_func,
                                        iw);
+
     /* Setup initial values */
     iw->invoice_guid = *gncInvoiceGetGUID (invoice);
+    iw->is_credit_note = gncInvoiceGetIsCreditNote (invoice);
 
     iw->component_id =
         gnc_register_gui_component (DIALOG_NEW_INVOICE_CM_CLASS,
@@ -2423,7 +2461,7 @@
     // And also open the "properties" pop-up... however, changing the
     // invoice ID won't be copied over to the tab title even though
     // it's correctly copied into the invoice.
-    iw = gnc_invoice_window_new_invoice (NULL, NULL, new_invoice);
+    iw = gnc_ui_invoice_modify (new_invoice);
 
     return iw;
 }

Modified: gnucash/trunk/src/business/business-gnome/gtkbuilder/dialog-invoice.glade
===================================================================
--- gnucash/trunk/src/business/business-gnome/gtkbuilder/dialog-invoice.glade	2011-11-10 15:04:50 UTC (rev 21549)
+++ gnucash/trunk/src/business/business-gnome/gtkbuilder/dialog-invoice.glade	2011-11-10 15:05:05 UTC (rev 21550)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk+" version="2.16"/>
+  <requires lib="gtk+" version="2.24"/>
   <object class="GtkWindow" id="Invoice Entry Window">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -30,6 +30,20 @@
                         <property name="can_focus">False</property>
                         <property name="homogeneous">True</property>
                         <child>
+                          <object class="GtkLabel" id="label9">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">1</property>
+                            <property name="label" translatable="yes">Type</property>
+                            <property name="justify">right</property>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
                           <object class="GtkLabel" id="label3">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
@@ -40,7 +54,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">0</property>
+                            <property name="position">1</property>
                           </packing>
                         </child>
                         <child>
@@ -54,7 +68,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">1</property>
+                            <property name="position">2</property>
                           </packing>
                         </child>
                         <child>
@@ -68,7 +82,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">2</property>
+                            <property name="position">3</property>
                           </packing>
                         </child>
                         <child>
@@ -82,7 +96,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">3</property>
+                            <property name="position">4</property>
                           </packing>
                         </child>
                         <child>
@@ -94,7 +108,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">4</property>
+                            <property name="position">5</property>
                           </packing>
                         </child>
                         <child>
@@ -106,7 +120,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">5</property>
+                            <property name="position">6</property>
                           </packing>
                         </child>
                       </object>
@@ -122,6 +136,19 @@
                         <property name="can_focus">False</property>
                         <property name="homogeneous">True</property>
                         <child>
+                          <object class="GtkLabel" id="page_type_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Invoice</property>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
                           <object class="GtkEntry" id="page_id_entry">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
@@ -130,7 +157,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">0</property>
+                            <property name="position">1</property>
                           </packing>
                         </child>
                         <child>
@@ -144,7 +171,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">1</property>
+                            <property name="position">2</property>
                           </packing>
                         </child>
                         <child>
@@ -158,7 +185,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">2</property>
+                            <property name="position">3</property>
                           </packing>
                         </child>
                         <child>
@@ -170,7 +197,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">3</property>
+                            <property name="position">4</property>
                           </packing>
                         </child>
                         <child>
@@ -187,7 +214,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">4</property>
+                            <property name="position">5</property>
                           </packing>
                         </child>
                         <child>
@@ -199,7 +226,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">5</property>
+                            <property name="position">6</property>
                           </packing>
                         </child>
                       </object>
@@ -722,6 +749,20 @@
                         <property name="border_width">3</property>
                         <property name="homogeneous">True</property>
                         <child>
+                          <object class="GtkLabel" id="label7">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">1</property>
+                            <property name="label" translatable="yes">Type</property>
+                            <property name="justify">right</property>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
                           <object class="GtkLabel" id="label14">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
@@ -732,7 +773,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">0</property>
+                            <property name="position">1</property>
                           </packing>
                         </child>
                         <child>
@@ -746,7 +787,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">1</property>
+                            <property name="position">2</property>
                           </packing>
                         </child>
                       </object>
@@ -763,6 +804,76 @@
                         <property name="border_width">3</property>
                         <property name="homogeneous">True</property>
                         <child>
+                          <object class="GtkHBox" id="dialog_type_hbox">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <child>
+                              <object class="GtkLabel" id="dialog_type_label">
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">Invoice</property>
+                              </object>
+                              <packing>
+                                <property name="expand">True</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkHBox" id="dialog_type_choice_hbox">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <child>
+                                  <object class="GtkRadioButton" id="dialog_invoice_type">
+                                    <property name="label" translatable="yes">Invoice</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="use_action_appearance">False</property>
+                                    <property name="xalign">0</property>
+                                    <property name="active">True</property>
+                                    <property name="draw_indicator">True</property>
+                                    <signal name="toggled" handler="gnc_invoice_type_toggled_cb" swapped="no"/>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkRadioButton" id="dialog_creditnote_type">
+                                    <property name="label" translatable="yes">Credit Note</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="use_action_appearance">False</property>
+                                    <property name="xalign">0</property>
+                                    <property name="active">True</property>
+                                    <property name="draw_indicator">True</property>
+                                    <property name="group">dialog_invoice_type</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
                           <object class="GtkEntry" id="dialog_id_entry">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
@@ -774,7 +885,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">0</property>
+                            <property name="position">1</property>
                           </packing>
                         </child>
                         <child>
@@ -788,7 +899,7 @@
                           <packing>
                             <property name="expand">False</property>
                             <property name="fill">False</property>
-                            <property name="position">1</property>
+                            <property name="position">2</property>
                           </packing>
                         </child>
                       </object>

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2011-11-10 15:04:50 UTC (rev 21549)
+++ gnucash/trunk/src/engine/gncInvoice.c	2011-11-10 15:05:05 UTC (rev 21550)
@@ -897,6 +897,8 @@
                       GNC_INVOICE_EMPL_CREDIT_NOTE :
                       GNC_INVOICE_EMPL_INVOICE);
     default:
+        PWARN ("No invoice types defined for owner %d",
+                gncInvoiceGetOwnerType (invoice));
         return GNC_INVOICE_UNDEFINED;
     }
 }
@@ -919,6 +921,7 @@
     case GNC_INVOICE_EMPL_CREDIT_NOTE:
         return _("Employee Credit Note");
     default:
+        PWARN("Unknown invoice type");
         return NULL;
     }
 }

Modified: gnucash/trunk/src/engine/gncInvoice.h
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.h	2011-11-10 15:04:50 UTC (rev 21549)
+++ gnucash/trunk/src/engine/gncInvoice.h	2011-11-10 15:05:05 UTC (rev 21550)
@@ -63,6 +63,7 @@
                                         not sure this makes sense,
                                         but all code is symmetrical
                                         so I've added it to prevent unexpected errors */
+    GNC_INVOICE_NUM_TYPES
 } GncInvoiceType;
 
 /* --- type macros --- */



More information about the gnucash-changes mailing list