Ejemplo n.º 1
0
/* ================================================================= */
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;
}
Ejemplo n.º 2
0
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 );
    }
}
Ejemplo n.º 3
0
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);
    }
}