static QofInstance* qofJobGetOwner (GncJob *job) { if (!job) { return NULL; } return QOF_INSTANCE(qofOwnerGetOwner(&job->owner)); }
/* * Given an owner, extract the open balance from the owner and then * convert it to the desired currency. */ gnc_numeric gncOwnerGetBalanceInCurrency (const GncOwner *owner, const gnc_commodity *report_currency) { 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, gncOwnerLotMatchOwnerFunc, (gpointer)owner, NULL); /* 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); GncInvoice *invoice = gncInvoiceGetInvoiceFromLot(lot); if (invoice) 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; }
static void gnc_payment_dialog_owner_changed (PaymentWindow *pw) { Account *last_acct = NULL; GncGUID *guid = NULL; GncOwner *owner = &pw->owner; /* If the owner changed, the initial invoice is no longer valid */ pw->invoice = NULL; /* Now handle the account tree */ qof_instance_get (qofOwnerGetOwner (owner), "payment-last-account", &guid, NULL); /* refresh the post and acc available accounts, but cleanup first */ if (pw->acct_types) { g_list_free(pw->acct_types); pw->acct_types = NULL; } if (pw->acct_commodities) { g_list_free(pw->acct_commodities); pw->acct_commodities = NULL; } pw->acct_types = gncOwnerGetAccountTypesList(owner); if (gncOwnerIsValid(owner)) pw->acct_commodities = gncOwnerGetCommoditiesList (owner); pw->post_acct = gnc_account_select_combo_fill (pw->post_combo, pw->book, pw->acct_types, pw->acct_commodities); /* Update list of documents and pre-payments */ gnc_payment_window_fill_docs_list (pw); if (guid) { last_acct = xaccAccountLookup(guid, pw->book); } /* Set the last-used transfer account, but only if we didn't * create this dialog from a pre-existing transaction. */ if (last_acct && !gnc_payment_dialog_has_pre_existing_txn(pw)) { gnc_tree_view_account_set_selected_account(GNC_TREE_VIEW_ACCOUNT(pw->acct_tree), last_acct); } }
static void gnc_payment_dialog_remember_account (PaymentWindow *pw, Account *acc) { QofInstance *owner = qofOwnerGetOwner (&pw->owner); const GncGUID *guid; if (!acc) return; guid = xaccAccountGetGUID(acc); qof_begin_edit (owner); qof_instance_set (owner, "payment-last-account", guid, NULL); qof_commit_edit (owner); }