예제 #1
0
파일: gncTaxTable.c 프로젝트: mlq/gnucash
/** Does this object refer to a specific object */
static gboolean
impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
{
    GncTaxTable* tt;

    g_return_val_if_fail(inst != NULL, FALSE);
    g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);

    tt = GNC_TAXTABLE(inst);

    if (GNC_IS_ACCOUNT(ref))
    {
        GList* node;

        for (node = tt->entries; node != NULL; node = node->next)
        {
            GncTaxTableEntry* tte = node->data;

            if (tte->account == GNC_ACCOUNT(ref))
            {
                return TRUE;
            }
        }
    }

    return FALSE;
}
예제 #2
0
파일: gncTaxTable.c 프로젝트: mlq/gnucash
static void
gnc_taxtable_set_property (GObject         *object,
                           guint            prop_id,
                           const GValue          *value,
                           GParamSpec      *pspec)
{
    GncTaxTable *tt;

    g_return_if_fail(GNC_IS_TAXTABLE(object));

    tt = GNC_TAXTABLE(object);
    switch (prop_id)
    {
    case PROP_NAME:
        gncTaxTableSetName(tt, g_value_get_string(value));
        break;
    case PROP_INVISIBLE:
        if (g_value_get_boolean(value))
        {
            gncTaxTableMakeInvisible(tt);
        }
        break;
    case PROP_REFCOUNT:
        gncTaxTableSetRefcount(tt, g_value_get_uint64(value));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
    }
}
예제 #3
0
/** Returns a list of my type of object which refers to an object.  For example, when called as
        qof_instance_get_typed_referring_object_list(taxtable, account);
    it will return the list of taxtables which refer to a specific account.  The result should be the
    same regardless of which taxtable object is used.  The list must be freed by the caller but the
    objects on the list must not.
 */
static GList*
impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
{
    if (!GNC_IS_ACCOUNT(ref) && !GNC_IS_TAXTABLE(ref))
    {
        return NULL;
    }

    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
}
예제 #4
0
static gpointer
get_child( gpointer pObject, const QofParam* param )
{
    GncTaxTable* tt = GNC_TAXTABLE(pObject);

    g_return_val_if_fail( pObject != NULL, NULL );
    g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );

    return gncTaxTableGetChild( tt );
}
예제 #5
0
bool
GncSqlTaxTableBackend::commit (GncSqlBackend* sql_be, QofInstance* inst)
{
    GncTaxTable* tt;
    const GncGUID* guid;
    E_DB_OPERATION op;
    gboolean is_infant;
    gboolean is_ok;

    g_return_val_if_fail (inst != NULL, FALSE);
    g_return_val_if_fail (GNC_IS_TAXTABLE (inst), FALSE);
    g_return_val_if_fail (sql_be != NULL, FALSE);

    tt = GNC_TAXTABLE (inst);

    is_infant = qof_instance_get_infant (inst);
    if (qof_instance_get_destroying (inst))
    {
        op = OP_DB_DELETE;
    }
    else if (sql_be->pristine() || is_infant)
    {
        op = OP_DB_INSERT;
    }
    else
    {
        op = OP_DB_UPDATE;
    }
    is_ok = sql_be->do_db_operation(op, TT_TABLE_NAME, GNC_ID_TAXTABLE, tt,
                                    tt_col_table);

    if (is_ok)
    {
        // Now, commit or delete any slots and tax table entries
        guid = qof_instance_get_guid (inst);
        if (!qof_instance_get_destroying (inst))
        {
            is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
            if (is_ok)
            {
                is_ok = save_tt_entries (sql_be, guid, gncTaxTableGetEntries (tt));
            }
        }
        else
        {
            is_ok = gnc_sql_slots_delete (sql_be, guid);
            if (is_ok)
            {
                is_ok = delete_all_tt_entries (sql_be, guid);
            }
        }
    }

    return is_ok;
}
예제 #6
0
파일: gncTaxTable.c 프로젝트: mlq/gnucash
/** Return displayable name */
static gchar*
impl_get_display_name(const QofInstance* inst)
{
    GncTaxTable* tt;

    g_return_val_if_fail(inst != NULL, FALSE);
    g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);

    tt = GNC_TAXTABLE(inst);
    return g_strdup_printf("Tax table %s", tt->name);
}
예제 #7
0
static void
set_invisible( gpointer data, gboolean value )
{
    GncTaxTable* tt = GNC_TAXTABLE(data);

    g_return_if_fail( data != NULL );
    g_return_if_fail( GNC_IS_TAXTABLE(data) );

    if ( value )
    {
        gncTaxTableMakeInvisible( tt );
    }
}
예제 #8
0
파일: gncCustomer.c 프로젝트: 573/gnucash
/** Does this object refer to a specific object */
static gboolean
impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
{
    GncCustomer* cust;

    g_return_val_if_fail(inst != NULL, FALSE);
    g_return_val_if_fail(GNC_IS_CUSTOMER(inst), FALSE);

    cust = GNC_CUSTOMER(inst);

    if (GNC_IS_BILLTERM(ref))
    {
        return (cust->terms == GNC_BILLTERM(ref));
    }
    else if (GNC_IS_TAXTABLE(ref))
    {
        return (cust->taxtable == GNC_TAXTABLE(ref));
    }

    return FALSE;
}
예제 #9
0
/** Does this object refer to a specific object */
static gboolean
impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
{
    GncEntry* entry;

    g_return_val_if_fail(inst != NULL, FALSE);
    g_return_val_if_fail(GNC_IS_ENTRY(inst), FALSE);

    entry = GNC_ENTRY(inst);

    if (GNC_IS_ACCOUNT(ref))
    {
        Account* acc = GNC_ACCOUNT(ref);
        return (entry->i_account == acc || entry->b_account == acc);
    }
    else if (GNC_IS_TAXTABLE(ref))
    {
        GncTaxTable* tt = GNC_TAXTABLE(ref);
        return (entry->i_tax_table == tt || entry->b_tax_table == tt);
    }

    return FALSE;
}
예제 #10
0
static void
tt_set_parent( gpointer data, gpointer value )
{
    GncTaxTable* tt;
    GncTaxTable* parent;
    QofBook* pBook;
    GncGUID* guid = (GncGUID*)value;

    g_return_if_fail( data != NULL );
    g_return_if_fail( GNC_IS_TAXTABLE(data) );

    tt = GNC_TAXTABLE(data);
    pBook = qof_instance_get_book( QOF_INSTANCE(tt) );
    if ( guid != NULL )
    {
        parent = gncTaxTableLookup( pBook, guid );
        if ( parent != NULL )
        {
            gncTaxTableSetParent( tt, parent );
            gncTaxTableSetChild( parent, tt );
        }
    }
}
예제 #11
0
static /*@ null @*//*@ dependent @*/ gpointer
bt_get_parent( gpointer pObject )
{
    const GncTaxTable* tt;
    const GncTaxTable* pParent;
    const GncGUID* parent_guid;

    g_return_val_if_fail( pObject != NULL, NULL );
    g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );

    tt = GNC_TAXTABLE(pObject);
    pParent = gncTaxTableGetParent( tt );
    if ( pParent == NULL )
    {
        parent_guid = NULL;
    }
    else
    {
        parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
    }

    return (gpointer)parent_guid;
}
예제 #12
0
파일: gncTaxTable.c 프로젝트: mlq/gnucash
gboolean gncTaxTableEqual(const GncTaxTable *a, const GncTaxTable *b)
{
    if (a == NULL && b == NULL) return TRUE;
    if (a == NULL || b == NULL) return FALSE;

    g_return_val_if_fail(GNC_IS_TAXTABLE(a), FALSE);
    g_return_val_if_fail(GNC_IS_TAXTABLE(b), FALSE);

    if (g_strcmp0(a->name, b->name) != 0)
    {
        PWARN("Names differ: %s vs %s", a->name, b->name);
        return FALSE;
    }

    if (a->invisible != b->invisible)
    {
        PWARN("invisible flags differ");
        return FALSE;
    }

    if ((a->entries != NULL) != (b->entries != NULL))
    {
        PWARN("only one has entries");
        return FALSE;
    }

    if (a->entries != NULL && b->entries != NULL)
    {
        GncTaxTableEntryList* a_node;
        GncTaxTableEntryList* b_node;

        for (a_node = a->entries, b_node = b->entries;
                a_node != NULL && b_node != NULL;
                a_node = a_node->next, b_node = b_node->next)
        {
            if (!gncTaxTableEntryEqual((GncTaxTableEntry*)a_node->data,
                                       (GncTaxTableEntry*)b_node->data))
            {
                PWARN("entries differ");
                return FALSE;
            }
        }

        if (a_node != NULL || b_node != NULL)
        {
            PWARN("Unequal number of entries");
            return FALSE;
        }
    }

#if 0
    /* See src/doc/business.txt for an explanation of the following */
    /* Code that handles this is *identical* to that in gncBillTerm */
    gint64          refcount;
    GncTaxTable *   parent;       /* if non-null, we are an immutable child */
    GncTaxTable *   child;        /* if non-null, we have not changed */
    GList *         children;     /* list of children for disconnection */
#endif

    return TRUE;
}