/* for each invoice, check the bill terms. If the bill terms are * grandchildren, then fix them to point to the most senior child */ static void billterm_scrub_invoices (QofInstance * invoice_p, gpointer ht_p) { GHashTable *ht = ht_p; GncInvoice *invoice = GNC_INVOICE(invoice_p); GncBillTerm *term, *new_bt; gint32 count; term = gncInvoiceGetTerms(invoice); if (term) { if (billterm_is_grandchild(term)) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(invoice)),guidstr); PWARN("Fixing i-billterm on invoice %s\n", guidstr); new_bt = billterm_find_senior(term); gncInvoiceBeginEdit(invoice); gncInvoiceSetTerms(invoice, new_bt); gncInvoiceCommitEdit(invoice); term = new_bt; } if (term) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); count++; g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); } } }
/* ================================================================= */ bool GncSqlInvoiceBackend::commit (GncSqlBackend* be, QofInstance* inst) { const GncGUID* guid; GncInvoice* invoice; E_DB_OPERATION op; gboolean is_infant; gboolean is_ok = TRUE; g_return_val_if_fail (inst != NULL, FALSE); g_return_val_if_fail (GNC_IS_INVOICE (inst), FALSE); g_return_val_if_fail (be != NULL, FALSE); invoice = GNC_INVOICE (inst); is_infant = qof_instance_get_infant (inst); if (qof_instance_get_destroying (inst)) { op = OP_DB_DELETE; } else if (be->pristine() || is_infant) { op = OP_DB_INSERT; } else { op = OP_DB_UPDATE; } if (op != OP_DB_DELETE) { // Ensure the commodity is in the db is_ok = gnc_sql_save_commodity (be, gncInvoiceGetCurrency (invoice)); } if (is_ok) { is_ok = gnc_sql_do_db_operation (be, op, TABLE_NAME, GNC_ID_INVOICE, inst, col_table); } if (is_ok) { // Now, commit or delete any slots guid = qof_instance_get_guid (inst); if (!qof_instance_get_destroying (inst)) { is_ok = gnc_sql_slots_save (be, guid, is_infant, inst); } else { is_ok = gnc_sql_slots_delete (be, guid); } } return is_ok; }
static void compare_single_invoice( QofInstance* inst, gpointer user_data ) { CompareInfoStruct* info = (CompareInfoStruct*)user_data; GncInvoice* inv_1 = GNC_INVOICE(inst); GncInvoice* inv_2 = gncInvoiceLookup( info->book_2, qof_instance_get_guid(inst) ); if (!gncInvoiceEqual( inv_1, inv_2 )) { info->result = FALSE; } }
static void write_single_invoice( QofInstance *term_p, gpointer data_p ) { write_objects_t* s = (write_objects_t*)data_p; g_return_if_fail( term_p != NULL ); g_return_if_fail( GNC_IS_INVOICE(term_p) ); g_return_if_fail( data_p != NULL ); if ( s->is_ok && invoice_should_be_saved( GNC_INVOICE(term_p) ) ) { s->is_ok = save_invoice( s->be, term_p ); } }
static void write_single_invoice (QofInstance* term_p, gpointer data_p) { auto s = reinterpret_cast<write_objects_t*>(data_p); g_return_if_fail (term_p != NULL); g_return_if_fail (GNC_IS_INVOICE (term_p)); g_return_if_fail (data_p != NULL); if (s->is_ok && invoice_should_be_saved (GNC_INVOICE (term_p))) { s->commit (term_p); } }