40 #include "gncBillTermP.h"
41 #include "gncCustomerP.h"
42 #include "gncTaxTableP.h"
48 #define _GNC_MOD_NAME GNC_ID_CUSTOMER
52 #define TABLE_NAME "customers"
53 #define TABLE_VERSION 2
55 #define MAX_NAME_LEN 2048
56 #define MAX_ID_LEN 2048
57 #define MAX_NOTES_LEN 2048
62 {
"name", CT_STRING, MAX_NAME_LEN,
COL_NNUL,
"name" },
63 {
"id", CT_STRING, MAX_ID_LEN,
COL_NNUL, NULL, CUSTOMER_ID },
64 {
"notes", CT_STRING, MAX_NOTES_LEN,
COL_NNUL, NULL, CUSTOMER_NOTES },
65 {
"active", CT_BOOLEAN, 0,
COL_NNUL, NULL, QOF_PARAM_ACTIVE },
66 {
"discount", CT_NUMERIC, 0,
COL_NNUL, NULL, CUSTOMER_DISCOUNT },
67 {
"credit", CT_NUMERIC, 0,
COL_NNUL, NULL, CUSTOMER_CREDIT },
69 "currency", CT_COMMODITYREF, 0,
COL_NNUL, NULL, NULL,
72 {
"tax_override", CT_BOOLEAN, 0,
COL_NNUL, NULL, CUSTOMER_TT_OVER },
73 {
"addr", CT_ADDRESS, 0, 0, NULL, CUSTOMER_ADDR },
74 {
"shipaddr", CT_ADDRESS, 0, 0, NULL, CUSTOMER_SHIPADDR },
75 {
"terms", CT_BILLTERMREF, 0, 0, NULL, CUSTOMER_TERMS },
77 "tax_included", CT_INT, 0, 0, NULL, NULL,
81 "taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
93 g_return_val_if_fail( be != NULL, NULL );
94 g_return_val_if_fail( row != NULL, NULL );
97 pCustomer = gncCustomerLookup( be->
book, guid );
98 if ( pCustomer == NULL )
100 pCustomer = gncCustomerCreate( be->
book );
103 qof_instance_mark_clean( QOF_INSTANCE(pCustomer) );
114 g_return_if_fail( be != NULL );
119 gnc_sql_statement_dispose( stmt );
120 if ( result != NULL )
125 row = gnc_sql_result_get_first_row( result );
126 while ( row != NULL )
128 GncCustomer* pCustomer = load_single_customer( be, row );
129 if ( pCustomer != NULL )
131 list = g_list_append( list, pCustomer );
133 row = gnc_sql_result_get_next_row( result );
135 gnc_sql_result_dispose( result );
151 g_return_if_fail( be != NULL );
158 else if ( version == 1 )
164 PINFO(
"Customers table upgraded from version 1 to version %d\n", TABLE_VERSION);
172 g_return_val_if_fail( inst != NULL, FALSE );
173 g_return_val_if_fail( GNC_CUSTOMER(inst), FALSE );
174 g_return_val_if_fail( be != NULL, FALSE );
191 g_return_val_if_fail( customer != NULL, FALSE );
194 id = gncCustomerGetID( customer );
195 if (
id == NULL || *
id ==
'\0' )
204 write_single_customer(
QofInstance *term_p, gpointer data_p )
208 g_return_if_fail( term_p != NULL );
209 g_return_if_fail( GNC_IS_CUSTOMER(term_p) );
210 g_return_if_fail( data_p != NULL );
212 if ( customer_should_be_saved( GNC_CUSTOMER(term_p) ) && data->is_ok )
214 data->is_ok = save_customer( data->be, term_p );
223 g_return_val_if_fail( be != NULL, FALSE );
233 gnc_customer_sql_initialize(
void )
237 GNC_SQL_BACKEND_VERSION,
241 create_customer_tables,
gboolean qof_object_register_backend(QofIdTypeConst type_name, const char *backend_name, gpointer be_data)
gint gnc_sql_get_table_version(const GncSqlBackend *be, const gchar *table_name)
void gnc_sql_upgrade_table(GncSqlBackend *be, const gchar *table_name, const GncSqlColumnTableEntry *col_table)
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
#define PINFO(format, args...)
load and save accounts data to SQL
GncSqlStatement * gnc_sql_create_select_statement(GncSqlBackend *be, const gchar *table_name)
gboolean gnc_sql_create_table(GncSqlBackend *be, const gchar *table_name, gint table_version, const GncSqlColumnTableEntry *col_table)
load and save data to SQL
load and save customer data to SQL
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
load and save accounts data to SQL
const GncGUID * gnc_sql_load_guid(const GncSqlBackend *be, GncSqlRow *row)
gboolean gnc_sql_set_table_version(GncSqlBackend *be, const gchar *table_name, gint version)
void gnc_sql_slots_load_for_list(GncSqlBackend *be, GList *list)
void qof_object_foreach(QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
GncSqlResult * gnc_sql_execute_select_statement(GncSqlBackend *be, GncSqlStatement *stmt)
void gnc_sql_load_object(const GncSqlBackend *be, GncSqlRow *row, QofIdTypeConst obj_name, gpointer pObject, const GncSqlColumnTableEntry *table)
load and save address data to SQL
gboolean gnc_sql_commit_standard_item(GncSqlBackend *be, QofInstance *inst, const gchar *tableName, QofIdTypeConst obj_name, const GncSqlColumnTableEntry *col_table)
void(* QofSetterFunc)(gpointer, gpointer)
const gchar * QofLogModule
load and save tax table data to SQL