r16698 - gnucash/branches/gda-dev/src/business/business-core/gda - Implement billing table gda backend
Phil Longstaff
plongstaff at cvs.gnucash.org
Sat Dec 22 20:33:35 EST 2007
Author: plongstaff
Date: 2007-12-22 20:33:35 -0500 (Sat, 22 Dec 2007)
New Revision: 16698
Trac: http://svn.gnucash.org/trac/changeset/16698
Added:
gnucash/branches/gda-dev/src/business/business-core/gda/gnc-bill-term-gda.c
gnucash/branches/gda-dev/src/business/business-core/gda/gnc-bill-term-gda.h
Modified:
gnucash/branches/gda-dev/src/business/business-core/gda/Makefile.am
gnucash/branches/gda-dev/src/business/business-core/gda/gncmod-business-backend-gda.c
Log:
Implement billing table gda backend
Modified: gnucash/branches/gda-dev/src/business/business-core/gda/Makefile.am
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/Makefile.am 2007-12-22 20:24:43 UTC (rev 16697)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/Makefile.am 2007-12-23 01:33:35 UTC (rev 16698)
@@ -16,6 +16,7 @@
libgncmod_business_backend_gda_la_SOURCES = \
gncmod-business-backend-gda.c \
gnc-address-gda.c \
+ gnc-bill-term-gda.c \
gnc-customer-gda.c \
gnc-employee-gda.c \
gnc-invoice-gda.c \
@@ -24,7 +25,6 @@
gnc-vendor-gda.c
#libgncmod_business_backend_gda_la_SOURCES = \
-# gnc-bill-term-gda.c \
# gnc-entry-gda.c \
# gnc-owner-gda.c \
# gnc-tax-table-gda.c
Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-bill-term-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-bill-term-gda.c (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-bill-term-gda.c 2007-12-23 01:33:35 UTC (rev 16698)
@@ -0,0 +1,205 @@
+/********************************************************************\
+ * gnc-bill-term-gda.c -- billing term gda backend *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+ * *
+\********************************************************************/
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libgda/libgda.h>
+
+#include "gnc-backend-util-gda.h"
+
+#include "gncBillTermP.h"
+#include "gncInvoice.h"
+#include "gnc-bill-term-gda.h"
+#include "qof.h"
+
+#define _GNC_MOD_NAME GNC_ID_BILLTERM
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+#define MAX_NAME_LEN 50
+#define MAX_DESCRIPTION_LEN 50
+#define MAX_TYPE_LEN 50
+
+static void set_invisible( gpointer data, gpointer value );
+
+#define TABLE_NAME "billterms"
+
+static col_cvt_t col_table[] =
+{
+ { "guid", CT_GUID, 0, COL_NNUL, "guid" },
+ { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, NULL, GNC_BILLTERM_NAME },
+ { "description", CT_STRING, MAX_DESCRIPTION_LEN, COL_NNUL, NULL, GNC_BILLTERM_DESC },
+ { "refcount", CT_INT, 0, COL_NNUL, NULL, GNC_BILLTERM_REFCOUNT },
+ { "invisible", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncBillTermGetInvisible, (QofSetterFunc)set_invisible },
+ { "parent", CT_BILLTERMREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncBillTermGetParent, (QofSetterFunc)gncBillTermSetParent },
+ { "child", CT_BILLTERMREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncBillTermReturnChild, (QofSetterFunc)gncBillTermSetChild },
+ { "type", CT_STRING, MAX_TYPE_LEN, COL_NNUL, NULL, GNC_BILLTERM_TYPE },
+ { "duedays", CT_INT, 0, 0, 0, GNC_BILLTERM_DUEDAYS },
+ { "discountdays", CT_INT, 0, 0, 0, GNC_BILLTERM_DISCDAYS },
+ { "discount", CT_NUMERIC, 0, 0, 0, GNC_BILLTERM_DISCOUNT },
+ { "cutoff", CT_INT, 0, 0, 0, GNC_BILLTERM_CUTOFF },
+ { NULL }
+};
+
+static void
+set_invisible( gpointer data, gpointer value )
+{
+ GncBillTerm* term = GNC_BILLTERM(data);
+ gboolean b = GPOINTER_TO_INT(value);
+
+ if( b ) {
+ gncBillTermMakeInvisible( term );
+ }
+}
+
+static GncBillTerm*
+load_single_billterm( GncGdaBackend* be, GdaDataModel* pModel, int row )
+{
+ const GUID* guid;
+ GUID v_guid;
+ GncBillTerm* pBillTerm;
+
+ guid = gnc_gda_load_guid( be, pModel, row );
+ v_guid = *guid;
+
+ pBillTerm = gncBillTermLookup( be->primary_book, &v_guid );
+ if( pBillTerm == NULL ) {
+ pBillTerm = gncBillTermCreate( be->primary_book );
+ }
+ gnc_gda_load_object( be, pModel, row, GNC_ID_BILLTERM, pBillTerm, col_table );
+ gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE( pBillTerm )),
+ qof_instance_get_slots( QOF_INSTANCE(pBillTerm) ) );
+
+ qof_instance_mark_clean( QOF_INSTANCE(pBillTerm) );
+
+ return pBillTerm;
+}
+
+static void
+load_all_billterms( GncGdaBackend* be )
+{
+ static GdaQuery* query = NULL;
+ GdaObject* ret;
+ QofBook* pBook = be->primary_book;
+
+ /* First time, create the query */
+ if( query == NULL ) {
+ query = gnc_gda_create_select_query( be, TABLE_NAME );
+ }
+
+ ret = gnc_gda_execute_query( be, query );
+ if( GDA_IS_DATA_MODEL( ret ) ) {
+ GdaDataModel* pModel = GDA_DATA_MODEL(ret);
+ int numRows = gda_data_model_get_n_rows( pModel );
+ int r;
+
+ for( r = 0; r < numRows; r++ ) {
+ (void)load_single_billterm( be, pModel, r );
+ }
+ }
+}
+
+/* ================================================================= */
+static void
+create_billterm_tables( GncGdaBackend* be )
+{
+ gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+}
+
+/* ================================================================= */
+void
+gnc_gda_save_billterm( GncGdaBackend* be, QofInstance* inst )
+{
+ GncBillTerm* v = GNC_BILLTERM(inst);
+ const GUID* guid;
+
+ (void)gnc_gda_do_db_operation( be,
+ (qof_instance_get_destroying(inst) ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+ TABLE_NAME,
+ GNC_ID_BILLTERM, v,
+ col_table );
+
+ // Now, commit or delete any slots
+ guid = qof_instance_get_guid( inst );
+ if( !qof_instance_get_destroying(inst) ) {
+ gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+ } else {
+ gnc_gda_slots_delete( be, guid );
+ }
+}
+
+/* ================================================================= */
+static void
+load_billterm_guid( const GncGdaBackend* be, GdaDataModel* pModel, gint row,
+ QofSetterFunc setter, gpointer pObject,
+ const col_cvt_t* table )
+{
+ const GValue* val;
+ GUID guid;
+ const GUID* pGuid;
+ GncBillTerm* term = NULL;
+
+ val = gda_data_model_get_value_at_col_name( pModel, table->col_name, row );
+ if( gda_value_is_null( val ) ) {
+ pGuid = NULL;
+ } else {
+ string_to_guid( g_value_get_string( val ), &guid );
+ pGuid = &guid;
+ }
+ if( pGuid != NULL ) {
+ term = gncBillTermLookup( be->primary_book, pGuid );
+ }
+ if( table->gobj_param_name != NULL ) {
+ g_object_set( pObject, table->gobj_param_name, term, NULL );
+ } else {
+ (*setter)( pObject, (const gpointer)term );
+ }
+}
+
+static col_type_handler_t billterm_guid_handler =
+ { load_billterm_guid, gnc_gda_create_objectref_guid_col,
+ gnc_gda_get_gvalue_objectref_guid_for_query, gnc_gda_get_gvalue_objectref_guid_cond };
+/* ================================================================= */
+void
+gnc_billterm_gda_initialize( void )
+{
+ static GncGdaDataType_t be_data =
+ {
+ GNC_GDA_BACKEND_VERSION,
+ GNC_ID_BILLTERM,
+ gnc_gda_save_billterm, /* commit */
+ load_all_billterms, /* initial_load */
+ create_billterm_tables /* create_tables */
+ };
+
+ qof_object_register_backend( GNC_ID_BILLTERM, GNC_GDA_BACKEND, &be_data );
+
+ gnc_gda_register_col_type_handler( CT_BILLTERMREF, &billterm_guid_handler );
+}
+/* ========================== END OF FILE ===================== */
Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-bill-term-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-bill-term-gda.h (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-bill-term-gda.h 2007-12-23 01:33:35 UTC (rev 16698)
@@ -0,0 +1,39 @@
+/*
+ * gnc-bill-term-gda.h -- billing term gda backend
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+/** @file gnc-bill-term-gda.h
+ * @brief load and save accounts data to SQL via libgda
+ * @author Copyright (c) 2006 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_BILLTERM_GDA_H
+#define GNC_BILLTERM_GDA_H
+
+#include "gncBillTerm.h"
+
+#define CT_BILLTERMREF "billterm"
+
+void gnc_billterm_gda_initialize( void );
+
+#endif /* GNC_BILLTERM_GDA_H */
Modified: gnucash/branches/gda-dev/src/business/business-core/gda/gncmod-business-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gncmod-business-backend-gda.c 2007-12-22 20:24:43 UTC (rev 16697)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gncmod-business-backend-gda.c 2007-12-23 01:33:35 UTC (rev 16698)
@@ -58,52 +58,53 @@
gchar *
libgncmod_business_backend_gda_gnc_module_path(void)
{
- return g_strdup("gnucash/business-core-gda");
+ return g_strdup( "gnucash/business-core-gda" );
}
gchar *
libgncmod_business_backend_gda_gnc_module_description(void)
{
- return g_strdup("The GDA backend for GnuCash business objects");
+ return g_strdup( "The GDA backend for GnuCash business objects" );
}
int
libgncmod_business_backend_gda_gnc_module_init(int refcount)
{
- if(!gnc_engine_is_initialized()) { return FALSE; }
+ if(!gnc_engine_is_initialized()) { return FALSE; }
- bus_core = gnc_module_load("gnucash/business-core", 0);
- if(!bus_core) return FALSE;
+ bus_core = gnc_module_load( "gnucash/business-core", 0 );
+ if( !bus_core ) return FALSE;
- if (refcount == 0) {
- /* Initialize our pointers into the backend subsystem */
- gnc_address_gda_initialize ();
-// gnc_billterm_gda_initialize ();
- gnc_customer_gda_initialize ();
- gnc_employee_gda_initialize ();
-// gnc_entry_gda_initialize ();
- gnc_invoice_gda_initialize ();
- gnc_job_gda_initialize ();
- gnc_order_gda_initialize ();
-// gnc_owner_gda_initialize ();
-// gnc_taxtable_gda_initialize ();
- gnc_vendor_gda_initialize ();
- }
+ if( refcount == 0 ) {
+ /* Initialize our pointers into the backend subsystem */
+ gnc_address_gda_initialize();
+ gnc_billterm_gda_initialize();
+ gnc_customer_gda_initialize();
+ gnc_employee_gda_initialize();
+// gnc_entry_gda_initialize();
+ gnc_invoice_gda_initialize();
+ gnc_job_gda_initialize();
+ gnc_order_gda_initialize();
+// gnc_owner_gda_initialize();
+// gnc_taxtable_gda_initialize();
+ gnc_vendor_gda_initialize();
+ }
- return TRUE;
+ return TRUE;
}
int
libgncmod_business_backend_gda_gnc_module_end(int refcount)
{
- int unload = TRUE;
+ int unload = TRUE;
- if (bus_core)
- unload = gnc_module_unload(bus_core);
+ if( bus_core ) {
+ unload = gnc_module_unload( bus_core );
+ }
- if (refcount == 0) {
- bus_core = NULL;
- }
+ if( refcount == 0 ) {
+ bus_core = NULL;
+ }
- return unload;
+ return unload;
}
More information about the gnucash-changes
mailing list