GnuCash 2.3.0
Data Structures | Files | Defines | Typedefs | Enumerations | Functions
Owner
Business

Data Structures

struct  _gncOwner
struct  GncOwner

Files

file  gncOwner.h
 

Business Interface: Object OWNERs.


Defines

#define GNC_ID_OWNER   "gncOwner"
#define OWNER_TYPE   "type"
#define OWNER_TYPE_STRING   "type-string"
#define OWNER_CUSTOMER   "customer"
#define OWNER_JOB   "job"
#define OWNER_VENDOR   "vendor"
#define OWNER_EMPLOYEE   "employee"
#define OWNER_PARENT   "parent"
#define OWNER_PARENTG   "parent-guid"
#define OWNER_NAME   "name"
#define OWNER_FROM_LOT   "owner-from-lot"

Typedefs

typedef struct _gncOwner GncOwner

Enumerations

enum  GncOwnerType {
  GNC_OWNER_NONE, GNC_OWNER_UNDEFINED, GNC_OWNER_CUSTOMER, GNC_OWNER_JOB,
  GNC_OWNER_VENDOR, GNC_OWNER_EMPLOYEE
}

Functions

void gncOwnerCopy (const GncOwner *src, GncOwner *dest)
const GncGUIDgncOwnerGetGUID (const GncOwner *owner)
GncGUID gncOwnerRetGUID (GncOwner *owner)
const GncOwnergncOwnerGetEndOwner (const GncOwner *owner)
const GncGUIDgncOwnerGetEndGUID (const GncOwner *owner)
void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot)
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid)
KvpFramegncOwnerGetSlots (GncOwner *owner)
TransactiongncOwnerApplyPayment (const GncOwner *owner, GncInvoice *invoice, Account *posted_acc, Account *xfer_acc, gnc_numeric amount, gnc_numeric exch, Timespec date, const char *memo, const char *num)
gint gncOwnerAssignPaymentTxn (const GncOwner *owner, Transaction *txn, Account *posted_account, GncInvoice *invoice)
GList * gncOwnerGetAccountTypesList (const GncOwner *owner)
GList * gncOwnerGetCommoditiesList (const GncOwner *owner)
gnc_numeric gncOwnerGetBalanceInCurrency (const GncOwner *owner, const gnc_commodity *report_currency)
GncOwnergncOwnerNew (void)
void gncOwnerFree (GncOwner *owner)
void gncOwnerBeginEdit (GncOwner *owner)
void gncOwnerDestroy (GncOwner *owner)

QOF handling

Whilst GncOwner is not a formal QOF object, these functions are still expected to be useful in making GncOwner transparent to QOF as they can be used by objects like GncInvoice.

QofIdTypeConst qofOwnerGetType (const GncOwner *owner)
QofInstanceqofOwnerGetOwner (const GncOwner *owner)
void qofOwnerSetEntity (GncOwner *owner, QofInstance *ent)
gboolean GNC_IS_OWNER (QofInstance *ent)
QofIdTypeConst gncOwnerTypeToQofIdType (GncOwnerType t)
gboolean gncOwnerRegister (void)

Setup routines

void gncOwnerInitUndefined (GncOwner *owner, gpointer obj)
void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer)
void gncOwnerInitJob (GncOwner *owner, GncJob *job)
void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor)
void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee)

Get routines.

GncOwnerType gncOwnerGetType (const GncOwner *owner)
gboolean gncOwnerIsValid (const GncOwner *owner)
gpointer gncOwnerGetUndefined (const GncOwner *owner)
GncCustomergncOwnerGetCustomer (const GncOwner *owner)
GncJobgncOwnerGetJob (const GncOwner *owner)
GncVendorgncOwnerGetVendor (const GncOwner *owner)
GncEmployeegncOwnerGetEmployee (const GncOwner *owner)
const char * gncOwnerGetID (const GncOwner *owner)
const char * gncOwnerGetName (const GncOwner *owner)
GncAddressgncOwnerGetAddr (const GncOwner *owner)
gboolean gncOwnerGetActive (const GncOwner *owner)
gnc_commoditygncOwnerGetCurrency (const GncOwner *owner)

Set routines.

void gncOwnerSetActive (const GncOwner *owner, gboolean active)

Comparison routines.

gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b)
int gncOwnerGCompareFunc (const GncOwner *a, const GncOwner *b)
int gncOwnerCompare (const GncOwner *a, const GncOwner *b)

Define Documentation

#define OWNER_TYPE_STRING   "type-string"

Allows the type to be handled externally.

Definition at line 246 of file gncOwner.h.


Function Documentation

gboolean GNC_IS_OWNER ( QofInstance ent)

Check if entity is an owner kind. This function conveniently imitates the various GNC_IS_ checks on the other gnucash objects even though an owner is not really a true object.

Definition at line 297 of file gncOwner.c.

{
    if (!ent)
        return FALSE;

    return (GNC_IS_VENDOR(ent) ||
            GNC_IS_CUSTOMER(ent) ||
            GNC_IS_EMPLOYEE(ent) ||
            GNC_IS_JOB(ent));
}
Transaction* gncOwnerApplyPayment ( const GncOwner owner,
GncInvoice invoice,
Account posted_acc,
Account xfer_acc,
gnc_numeric  amount,
gnc_numeric  exch,
Timespec  date,
const char *  memo,
const char *  num 
)

Apply a payment of "amount" for the owner, between the xfer_account (bank or other asset) and the posted_account (A/R or A/P). If the caller supplies an (optional) invoice argument, then apply the payment to that invoice first before any other invoice.

Definition at line 903 of file gncOwner.c.

{
    QofBook *book;
    Transaction *txn;
    Split *split;
    const char *name;
    gnc_commodity *commodity;
    gboolean reverse;
    gnc_numeric payment_value = amount;

    /* Verify our arguments */
    if (!owner || !posted_acc || !xfer_acc) return NULL;
    g_return_val_if_fail (owner->owner.undefined != NULL, NULL);

    /* Compute the ancillary data */
    book = gnc_account_get_book (posted_acc);
    name = gncOwnerGetName (gncOwnerGetEndOwner ((GncOwner*)owner));
    commodity = gncOwnerGetCurrency (owner);
    reverse = use_reversed_payment_amounts(owner);

    txn = xaccMallocTransaction (book);
    xaccTransBeginEdit (txn);

    /* Set up the transaction */
    xaccTransSetDescription (txn, name ? name : "");
    xaccTransSetNum (txn, num);
    xaccTransSetCurrency (txn, commodity);
    xaccTransSetDateEnteredSecs (txn, time(NULL));
    xaccTransSetDatePostedTS (txn, &date);
    xaccTransSetTxnType (txn, TXN_TYPE_PAYMENT);


    /* The split for the transfer account */
    split = xaccMallocSplit (book);
    xaccSplitSetMemo (split, memo);
    xaccSplitSetAction (split, _("Payment"));
    xaccAccountBeginEdit (xfer_acc);
    xaccAccountInsertSplit (xfer_acc, split);
    xaccAccountCommitEdit (xfer_acc);
    xaccTransAppendSplit (txn, split);

    if (gnc_commodity_equal(xaccAccountGetCommodity(xfer_acc), commodity))
    {
        xaccSplitSetBaseValue (split, reverse ? amount :
                               gnc_numeric_neg (amount), commodity);
    }
    else
    {
        /* Need to value the payment in terms of the owner commodity */
        xaccSplitSetAmount(split, reverse ? amount : gnc_numeric_neg (amount));
        payment_value = gnc_numeric_mul(amount, exch, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
        xaccSplitSetValue(split, reverse ? payment_value : gnc_numeric_neg(payment_value));
    }

    gncOwnerAssignPaymentTxn(owner, txn, posted_acc, invoice);

    /* Commit this new transaction */
    xaccTransCommitEdit (txn);

    return txn;
}
gint gncOwnerAssignPaymentTxn ( const GncOwner owner,
Transaction txn,
Account posted_account,
GncInvoice invoice 
)

Fill in a half-finished payment transaction for the owner. The transaction txn must already contain one split that belongs to a bank or other asset account. This function will add the other split (or splits) that go to the posted_account (A/R or A/P), including the linking to the lots so that the payment is recorded in the correct lot(s).

If the caller supplies an (optional) invoice argument, then apply the payment to that invoice first before any other invoice.

Preconditions: The arguments owner, txn, and posted_account must not be NULL. The txn must be open (by xaccTransBeginEdit()); it must contain exactly one split; its commodity (by xaccTransGetCurrency()) must be equal to the owner's commodity (by gncOwnerGetCurrency()).

Returns:
The number of splits that have been assigned as owner payments. On success, this is always positive (1 or larger). In case of failure (due to unfulfilled conditions on the input values), null is returned.

Definition at line 706 of file gncOwner.c.

{
    Account *inv_posted_acc;
    GList *lot_iter, *open_lot_fifo;
    GNCLot *inv_posted_lot = NULL, *prepay_lot = NULL;
    gnc_numeric split_amt;
    gboolean inv_passed = TRUE;
    Split *split;
    QofBook *book = gnc_account_get_book(posted_account);
    gnc_commodity *txn_commodity = xaccTransGetCurrency(txn);
    gint result = 0;
    gnc_numeric payment_value;
    const char *memo;

    g_assert(owner);
    g_assert(txn);
    g_assert(xaccTransIsOpen(txn));
    g_assert(posted_account);

    if (txn_commodity != gncOwnerGetCurrency (owner))
    {
        // Uh oh
        return result;
    }
    // We require exactly one split in the transaction
    if (xaccTransCountSplits(txn) != 1)
    {
        // Uh oh
        return result;
    }

    {
        // Retrieve the payment value from the existing first split.
        Split *asset_split = xaccTransGetSplit(txn, 0);
        g_assert(asset_split);

        /* Note: to balance the transaction the payment to assign
         * must have the opposite sign of the existing first split */
        payment_value = gnc_numeric_neg(xaccSplitGetValue(asset_split));
        memo = xaccSplitGetMemo(asset_split);
    }

    /* Now, find all "open" lots in the posting account for this
     * company and apply the payment on a FIFO basis.  Create
     * a new split for each open lot until the payment is gone.
     */

    open_lot_fifo = xaccAccountFindOpenLots (posted_account, gnc_lot_match_invoice_owner,
                    (gpointer)owner,
                    (GCompareFunc)gnc_lot_sort_func);

    /* Check if an invoice was passed in. */
    if (invoice)
    {
        /* If so, does it match the account, and is it an open lot?
         * If so, put it at the beginning of the lot list fifo so we
         * post to this invoice's lot first.
         */
        inv_posted_acc = gncInvoiceGetPostedAcc(invoice);
        inv_posted_lot = gncInvoiceGetPostedLot(invoice);
        if (inv_posted_acc && inv_posted_lot &&
                guid_equal(xaccAccountGetGUID(inv_posted_acc),
                           xaccAccountGetGUID(posted_account)) &&
                !gnc_lot_is_closed(inv_posted_lot))
        {
            /* Put this invoice at the beginning of the FIFO */
            open_lot_fifo = g_list_prepend (open_lot_fifo, inv_posted_lot);
            inv_passed = FALSE;
        }
    }

    xaccAccountBeginEdit (posted_account);

    /* Now iterate over the fifo until the payment is fully applied
     * (or all the lots are paid)
     */
    for (lot_iter = open_lot_fifo; lot_iter; lot_iter = lot_iter->next)
    {
        gnc_numeric balance;

        GNCLot *lot = lot_iter->data;

        /* Skip this lot if it matches the invoice that was passed in and
         * we've seen it already.  This way we post to it the first time
         * (from the beginning of the lot-list) but not when we reach it
         * the second time.
         */
        if (inv_posted_lot &&
                guid_equal(qof_instance_get_guid(QOF_INSTANCE(lot)),
                           qof_instance_get_guid(QOF_INSTANCE(inv_posted_lot))))
        {
            if (inv_passed)
                continue;
            else
                inv_passed = TRUE;
        }

        balance = gnc_lot_get_balance (lot);

        /* The balance can be positive or negative. But in order to assign a payment to it,
         * it has to have the opposite sign of the payment_value we have left.
         * If they are of the same sign, we may reserve it as the pre-payment lot for later
         */
        if ( (gnc_numeric_negative_p (balance) && gnc_numeric_negative_p (payment_value)) ||
                (gnc_numeric_positive_p (balance) && gnc_numeric_positive_p (payment_value)) )
        {
            if (prepay_lot)
            {
                g_warning ("Multiple pre-payment lots are found.  Skipping.");
            }
            else
            {
                /* A lot can only be used as a pre-payment lot if it has no document (invoice/credit note) attached */
                if (!gncInvoiceGetInvoiceFromLot(lot))
                    prepay_lot = lot;
            }
            continue;
        }

        /*
         * If there is less to pay than there's open in the lot; we're done -- apply the payment_value.
         * Note that payment_value and balance are opposite in sign, so we have to compare absolute values here
         *
         * Otherwise, apply the balance, subtract that from the payment_value,
         * and move on to the next one.
         */
        if (gnc_numeric_compare (gnc_numeric_abs (payment_value), gnc_numeric_abs (balance)) <= 0)
        {
            /* abs(payment_value) <= abs(balance) */
            split_amt = payment_value;
        }
        else
        {
            /* abs(payment_value) > abs(balance)
             * Remember payment_value and balance are opposite in sign,
             * and we want a payment to neutralize the current balance
             * so we need to negate here */
            split_amt = gnc_numeric_neg (balance);
        }

        /* reduce the payment_value by split_amt */
        payment_value = gnc_numeric_sub (payment_value, split_amt, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);

        /* Create the split for this lot in the post account */
        ++result;
        split = xaccMallocSplit (book);
        xaccSplitSetMemo (split, memo);
        xaccSplitSetAction (split, _("Payment"));
        xaccAccountInsertSplit (posted_account, split);
        xaccTransAppendSplit (txn, split);
        xaccSplitSetBaseValue (split, split_amt, txn_commodity);
        gnc_lot_add_split (lot, split);

        /* If the lot was linked to a document (invoice/credit note),
         * send an event for it so it gets updated as paid */
        {
            GncInvoice *this_invoice = gncInvoiceGetInvoiceFromLot(lot);
            if (this_invoice)
                qof_event_gen (QOF_INSTANCE(this_invoice), QOF_EVENT_MODIFY, NULL);
        }

        if (gnc_numeric_zero_p (payment_value))
            break;
    }

    g_list_free (open_lot_fifo);

    /* If there is still money left here, then create a pre-payment lot */
    if (!gnc_numeric_zero_p (payment_value))
    {
        if (prepay_lot == NULL)
        {
            prepay_lot = gnc_lot_new (book);
            gncOwnerAttachToLot (owner, prepay_lot);
        }

        split = xaccMallocSplit (book);
        xaccSplitSetMemo (split, memo);
        xaccSplitSetAction (split, _("Pre-Payment"));
        xaccAccountInsertSplit (posted_account, split);
        xaccTransAppendSplit (txn, split);
        xaccSplitSetBaseValue (split, payment_value, txn_commodity);
        gnc_lot_add_split (prepay_lot, split);
    }

    xaccAccountCommitEdit (posted_account);

    return result;
}
void gncOwnerAttachToLot ( const GncOwner owner,
GNCLot lot 
)

attach an owner to a lot

Definition at line 567 of file gncOwner.c.

{
    KvpFrame *kvp;
    KvpValue *value;

    if (!owner || !lot)
        return;

    kvp = gnc_lot_get_slots (lot);
    gnc_lot_begin_edit (lot);

    value = kvp_value_new_gint64 (gncOwnerGetType (owner));
    kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
    kvp_value_delete (value);

    value = kvp_value_new_guid (gncOwnerGetGUID (owner));
    kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
    qof_instance_set_dirty (QOF_INSTANCE (lot));
    gnc_lot_commit_edit (lot);
    kvp_value_delete (value);

}
void gncOwnerBeginEdit ( GncOwner owner)

These are convenience wrappers around gnc{Vender,Customer,Job,Employee}* functions. This allows you to begin edit, destroy commit edit an owner without knowing its type.

Definition at line 70 of file gncOwner.c.

{
    if (!owner) return;
    switch (owner->type)
    {
    case GNC_OWNER_NONE :
    case GNC_OWNER_UNDEFINED :
        break;
    case GNC_OWNER_CUSTOMER :
    {
        gncCustomerBeginEdit(owner->owner.customer);
        break;
    }
    case GNC_OWNER_JOB :
    {
        gncJobBeginEdit(owner->owner.job);
        break;
    }
    case GNC_OWNER_VENDOR :
    {
        gncVendorBeginEdit(owner->owner.vendor);
        break;
    }
    case GNC_OWNER_EMPLOYEE :
    {
        gncEmployeeBeginEdit(owner->owner.employee);
        break;
    }
    }
}
int gncOwnerCompare ( const GncOwner a,
const GncOwner b 
)

Sort on name

Definition at line 535 of file gncOwner.c.

{
    if (!a && !b) return 0;
    if (!a && b) return 1;
    if (a && !b) return -1;

    if (a->type != b->type)
        return (a->type - b->type);

    switch (a->type)
    {
    case GNC_OWNER_NONE:
    case GNC_OWNER_UNDEFINED:
    default:
        return 0;
    case GNC_OWNER_CUSTOMER:
        return gncCustomerCompare (a->owner.customer, b->owner.customer);
    case GNC_OWNER_VENDOR:
        return gncVendorCompare (a->owner.vendor, b->owner.vendor);
    case GNC_OWNER_EMPLOYEE:
        return gncEmployeeCompare (a->owner.employee, b->owner.employee);
    case GNC_OWNER_JOB:
        return gncJobCompare (a->owner.job, b->owner.job);
    }
}
gboolean gncOwnerEqual ( const GncOwner a,
const GncOwner b 
)

Assess equality by checking

  • if both owner objects refer to the same owner type
  • and if the owner reference points to the same {vendor/customer/employee} in memory

Definition at line 349 of file gncOwner.c.

{
    if (!a || !b) return FALSE;
    if (gncOwnerGetType (a) != gncOwnerGetType (b)) return FALSE;
    return (a->owner.undefined == b->owner.undefined);
}
int gncOwnerGCompareFunc ( const GncOwner a,
const GncOwner b 
)

Same as gncOwnerEqual, but returns 0 if equal to be used as a GList custom compare function

Definition at line 356 of file gncOwner.c.

{
    if (gncOwnerEqual (a, b))
        return 0;
    else
        return 1;
}
GList* gncOwnerGetAccountTypesList ( const GncOwner owner)

Returns a GList of account-types based on the owner type

Definition at line 969 of file gncOwner.c.

{
    g_return_val_if_fail (owner, NULL);

    switch (gncOwnerGetType (owner))
    {
    case GNC_OWNER_CUSTOMER:
        return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_RECEIVABLE));
    case GNC_OWNER_VENDOR:
    case GNC_OWNER_EMPLOYEE:
        return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_PAYABLE));
        break;
    default:
        return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_NONE));
    }
}
gnc_numeric gncOwnerGetBalanceInCurrency ( const GncOwner owner,
const gnc_commodity report_currency 
)

Given an owner, extract the open balance from the owner and then convert it to the desired currency.

Definition at line 1003 of file gncOwner.c.

{
    gnc_numeric balance = gnc_numeric_zero ();
    GList *acct_list, *acct_node, *acct_types, *lot_list = NULL, *lot_node;
    QofBook *book;
    gnc_commodity *owner_currency;
    GNCPriceDB *pdb;

    g_return_val_if_fail (owner, gnc_numeric_zero ());

    /* Get account list */
    book       = qof_instance_get_book (qofOwnerGetOwner (owner));
    acct_list  = gnc_account_get_descendants (gnc_book_get_root_account (book));
    acct_types = gncOwnerGetAccountTypesList (owner);
    owner_currency = gncOwnerGetCurrency (owner);

    /* For each account */
    for (acct_node = acct_list; acct_node; acct_node = acct_node->next)
    {
        Account *account = acct_node->data;

        /* Check if this account can have lots for the owner, otherwise skip to next */
        if (g_list_index (acct_types, (gpointer)xaccAccountGetType (account))
                == -1)
            continue;


        if (!gnc_commodity_equal (owner_currency, xaccAccountGetCommodity (account)))
            continue;

        /* Get a list of open lots for this owner and account */
        lot_list = xaccAccountFindOpenLots (account, gnc_lot_match_invoice_owner,
                                            (gpointer)owner,
                                            (GCompareFunc)gnc_lot_sort_func);
        /* For each lot */
        for (lot_node = lot_list; lot_node; lot_node = lot_node->next)
        {
            GNCLot *lot = lot_node->data;
            gnc_numeric lot_balance = gnc_lot_get_balance (lot);
            balance = gnc_numeric_add (balance, lot_balance,
                                       gnc_commodity_get_fraction (owner_currency), GNC_HOW_RND_ROUND_HALF_UP);
        }
    }

    pdb = gnc_pricedb_get_db (book);

    if (report_currency)
        balance = gnc_pricedb_convert_balance_latest_price (
                      pdb, balance, owner_currency, report_currency);

    return balance;
}
GList* gncOwnerGetCommoditiesList ( const GncOwner owner)

Returns a GList of currencies associated with the owner

Definition at line 987 of file gncOwner.c.

{
    g_return_val_if_fail (owner, NULL);
    g_return_val_if_fail (gncOwnerGetCurrency(owner), NULL);

    return (g_list_prepend (NULL, gncOwnerGetCurrency(owner)));
}
GncCustomer* gncOwnerGetCustomer ( const GncOwner owner)

If the given owner is of type GNC_OWNER_CUSTOMER, returns the pointer to the customer object. Otherwise returns NULL.

Definition at line 314 of file gncOwner.c.

{
    if (!owner) return NULL;
    if (owner->type != GNC_OWNER_CUSTOMER) return NULL;
    return owner->owner.customer;
}
GncEmployee* gncOwnerGetEmployee ( const GncOwner owner)

If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer to the employee object. Otherwise returns NULL.

Definition at line 335 of file gncOwner.c.

{
    if (!owner) return NULL;
    if (owner->type != GNC_OWNER_EMPLOYEE) return NULL;
    return owner->owner.employee;
}
const GncOwner* gncOwnerGetEndOwner ( const GncOwner owner)

Get the "parent" Owner or GncGUID thereof. The "parent" owner is the Customer or Vendor, or the Owner of a Job

Definition at line 517 of file gncOwner.c.

{
    if (!owner) return NULL;
    switch (owner->type)
    {
    case GNC_OWNER_NONE:
    case GNC_OWNER_UNDEFINED:
    default:
        return NULL;
    case GNC_OWNER_CUSTOMER:
    case GNC_OWNER_VENDOR:
    case GNC_OWNER_EMPLOYEE:
        return owner;
    case GNC_OWNER_JOB:
        return gncJobGetOwner (owner->owner.job);
    }
}
const GncGUID* gncOwnerGetGUID ( const GncOwner owner)

Get the GncGUID of the immediate owner

Definition at line 463 of file gncOwner.c.

{
    if (!owner) return NULL;

    switch (owner->type)
    {
    case GNC_OWNER_NONE:
    case GNC_OWNER_UNDEFINED:
    default:
        return NULL;
    case GNC_OWNER_CUSTOMER:
        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.customer));
    case GNC_OWNER_JOB:
        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.job));
    case GNC_OWNER_VENDOR:
        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.vendor));
    case GNC_OWNER_EMPLOYEE:
        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.employee));
    }
}
GncJob* gncOwnerGetJob ( const GncOwner owner)

If the given owner is of type GNC_OWNER_JOB, returns the pointer to the job object. Otherwise returns NULL.

Definition at line 321 of file gncOwner.c.

{
    if (!owner) return NULL;
    if (owner->type != GNC_OWNER_JOB) return NULL;
    return owner->owner.job;
}
gboolean gncOwnerGetOwnerFromLot ( GNCLot lot,
GncOwner owner 
)

Get the owner from the lot. If an owner is found in the lot, fill in "owner" and return TRUE. Otherwise return FALSE.

Definition at line 590 of file gncOwner.c.

{
    KvpFrame *kvp;
    KvpValue *value;
    GncGUID *guid;
    QofBook *book;
    GncOwnerType type;

    if (!lot || !owner) return FALSE;

    book = gnc_lot_get_book (lot);
    kvp = gnc_lot_get_slots (lot);

    value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
    if (!value) return FALSE;

    type = kvp_value_get_gint64 (value);

    value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
    if (!value) return FALSE;

    guid = kvp_value_get_guid (value);
    if (!guid)
        return FALSE;

    switch (type)
    {
    case GNC_OWNER_CUSTOMER:
        gncOwnerInitCustomer (owner, gncCustomerLookup (book, guid));
        break;
    case GNC_OWNER_VENDOR:
        gncOwnerInitVendor (owner, gncVendorLookup (book, guid));
        break;
    case GNC_OWNER_EMPLOYEE:
        gncOwnerInitEmployee (owner, gncEmployeeLookup (book, guid));
        break;
    case GNC_OWNER_JOB:
        gncOwnerInitJob (owner, gncJobLookup (book, guid));
        break;
    default:
        return FALSE;
    }

    return (owner->owner.undefined != NULL);
}
KvpFrame* gncOwnerGetSlots ( GncOwner owner)

Get the kvp-frame from the underlying owner object

Definition at line 642 of file gncOwner.c.

{
    if (!owner) return NULL;

    switch (gncOwnerGetType(owner))
    {
    case GNC_OWNER_CUSTOMER:
    case GNC_OWNER_VENDOR:
    case GNC_OWNER_EMPLOYEE:
        return qof_instance_get_slots(QOF_INSTANCE(owner->owner.undefined));
    case GNC_OWNER_JOB:
        return gncOwnerGetSlots(gncJobGetOwner(gncOwnerGetJob(owner)));
    default:
        return NULL;
    }
}
GncOwnerType gncOwnerGetType ( const GncOwner owner)

Returns the GncOwnerType of this owner. (Not to be confused with qofOwnerGetType().)

Definition at line 168 of file gncOwner.c.

{
    if (!owner) return GNC_OWNER_NONE;
    return owner->type;
}
gpointer gncOwnerGetUndefined ( const GncOwner owner)

If the given owner is of type GNC_OWNER_UNDEFINED, returns the undefined pointer, which is usually NULL. Otherwise returns NULL.

Definition at line 307 of file gncOwner.c.

{
    if (!owner) return NULL;
    if (owner->type != GNC_OWNER_UNDEFINED) return NULL;
    return owner->owner.undefined;
}
GncVendor* gncOwnerGetVendor ( const GncOwner owner)

If the given owner is of type GNC_OWNER_VENDOR, returns the pointer to the vendor object. Otherwise returns NULL.

Definition at line 328 of file gncOwner.c.

{
    if (!owner) return NULL;
    if (owner->type != GNC_OWNER_VENDOR) return NULL;
    return owner->owner.vendor;
}
gboolean gncOwnerIsValid ( const GncOwner owner)

Returns TRUE if the given owner is one of the valid objects. Returns FALSE if the owner is (still) undefined, or if it is NULL.

Definition at line 636 of file gncOwner.c.

{
    if (!owner) return FALSE;
    return (owner->owner.undefined != NULL);
}
GncOwner* gncOwnerNew ( void  )

These two functions are mainly for the convenience of scheme code. Normal C code has no need to ever use these two functions, and rather can just use a GncOwner directly and just pass around a pointer to it.

Definition at line 55 of file gncOwner.c.

{
    GncOwner *o;

    o = g_new0 (GncOwner, 1);
    o->type = GNC_OWNER_NONE;
    return o;
}
QofIdTypeConst gncOwnerTypeToQofIdType ( GncOwnerType  t)

Returns the QofIdType of the given GncOwnerType, or NULL if no suitable one exists.

Definition at line 180 of file gncOwner.c.

{
    QofIdTypeConst type = NULL;
    switch (t)
    {
    case GNC_OWNER_NONE :
    {
        type = NULL;
        break;
    }
    case GNC_OWNER_UNDEFINED :
    {
        type = NULL;
        break;
    }
    case GNC_OWNER_CUSTOMER :
    {
        type = GNC_ID_CUSTOMER;
        break;
    }
    case GNC_OWNER_JOB :
    {
        type = GNC_ID_JOB;
        break;
    }
    case GNC_OWNER_VENDOR :
    {
        type = GNC_ID_VENDOR;
        break;
    }
    case GNC_OWNER_EMPLOYEE :
    {
        type = GNC_ID_EMPLOYEE;
        break;
    }
    }
    return type;
}
QofInstance* qofOwnerGetOwner ( const GncOwner owner)

return the owner itself as an entity.

Definition at line 220 of file gncOwner.c.

{
    QofInstance *ent;

    if (!owner)
    {
        return NULL;
    }
    ent = NULL;
    switch (owner->type)
    {
    case GNC_OWNER_NONE :
    {
        break;
    }
    case GNC_OWNER_UNDEFINED :
    {
        break;
    }
    case GNC_OWNER_CUSTOMER :
    {
        ent = QOF_INSTANCE(owner->owner.customer);
        break;
    }
    case GNC_OWNER_JOB :
    {
        ent = QOF_INSTANCE(owner->owner.job);
        break;
    }
    case GNC_OWNER_VENDOR :
    {
        ent = QOF_INSTANCE(owner->owner.vendor);
        break;
    }
    case GNC_OWNER_EMPLOYEE :
    {
        ent = QOF_INSTANCE(owner->owner.employee);
        break;
    }
    }
    return ent;
}
QofIdTypeConst qofOwnerGetType ( const GncOwner owner)

return the type for the collection.

Definition at line 175 of file gncOwner.c.

{
    return gncOwnerTypeToQofIdType(owner->type);
}
void qofOwnerSetEntity ( GncOwner owner,
QofInstance ent 
)

set the owner from the entity.

Definition at line 264 of file gncOwner.c.

{
    if (!owner || !ent)
    {
        return;
    }
    if (0 == safe_strcmp(ent->e_type, GNC_ID_CUSTOMER))
    {
        owner->type = GNC_OWNER_CUSTOMER;
        gncOwnerInitCustomer(owner, (GncCustomer*)ent);
    }
    else if (0 == safe_strcmp(ent->e_type, GNC_ID_JOB))
    {
        owner->type = GNC_OWNER_JOB;
        gncOwnerInitJob(owner, (GncJob*)ent);
    }
    else if (0 == safe_strcmp(ent->e_type, GNC_ID_VENDOR))
    {
        owner->type = GNC_OWNER_VENDOR;
        gncOwnerInitVendor(owner, (GncVendor*)ent);
    }
    else if (0 == safe_strcmp(ent->e_type, GNC_ID_EMPLOYEE))
    {
        owner->type = GNC_OWNER_EMPLOYEE;
        gncOwnerInitEmployee(owner, (GncEmployee*)ent);
    }
    else
    {
        owner->type = GNC_OWNER_NONE;
        owner->owner.undefined = NULL;
    }
}
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines