GncEmployee * gncCloneEmployee (GncEmployee *from, QofBook *book) { GncEmployee *employee; if (!book || !from) return NULL; employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL); qof_instance_init_data(&employee->inst, _GNC_MOD_NAME, book); qof_instance_gemini (&employee->inst, &from->inst); employee->id = CACHE_INSERT (from->id); employee->username = CACHE_INSERT (from->username); employee->language = CACHE_INSERT (from->language); employee->acl = CACHE_INSERT (from->acl); employee->addr = gncCloneAddress (from->addr, &employee->inst, book); employee->workday = from->workday; employee->rate = from->rate; employee->active = from->active; employee->currency = gnc_commodity_obtain_twin(from->currency, book); employee->ccard_acc = GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book)); qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL); return employee; }
bool GncSqlBackend::write_account_tree(Account* root) { GList* descendants; GList* node; bool is_ok = true; g_return_val_if_fail (root != nullptr, false); auto obe = m_backend_registry.get_object_backend(GNC_ID_ACCOUNT); is_ok = obe->commit (this, QOF_INSTANCE (root)); if (is_ok) { descendants = gnc_account_get_descendants (root); for (node = descendants; node != NULL && is_ok; node = g_list_next (node)) { is_ok = obe->commit(this, QOF_INSTANCE (GNC_ACCOUNT (node->data))); if (!is_ok) break; } g_list_free (descendants); } update_progress(); return is_ok; }
/** 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; }
static void set_account (gpointer pObj, gpointer val) { budget_amount_info_t* info = (budget_amount_info_t*)pObj; g_return_if_fail (pObj != NULL); g_return_if_fail (val != NULL); g_return_if_fail (GNC_IS_ACCOUNT (val)); info->account = GNC_ACCOUNT (val); }
static void set_lot_account (gpointer pObject, gpointer pValue) { GNCLot* lot; Account* pAccount; g_return_if_fail (pObject != NULL && GNC_IS_LOT (pObject)); g_return_if_fail (pValue == NULL || GNC_IS_ACCOUNT (pValue)); lot = GNC_LOT (pObject); pAccount = GNC_ACCOUNT (pValue); if (pAccount != NULL) { xaccAccountInsertLot (pAccount, lot); } }
/** Does this object refer to a specific object */ static gboolean impl_refers_to_object(const QofInstance* inst, const QofInstance* ref) { GncEmployee* emp; g_return_val_if_fail(inst != NULL, FALSE); g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE); emp = GNC_EMPLOYEE(inst); if (GNC_IS_COMMODITY(ref)) { return (emp->currency == GNC_COMMODITY(ref)); } else if (GNC_IS_ACCOUNT(ref)) { return (emp->ccard_acc == GNC_ACCOUNT(ref)); } return FALSE; }
static void set_parent (gpointer pObject, gpointer pValue) { Account* pAccount; QofBook* pBook; GncGUID* guid = (GncGUID*)pValue; Account* pParent; g_return_if_fail (pObject != NULL); g_return_if_fail (GNC_IS_ACCOUNT (pObject)); pAccount = GNC_ACCOUNT (pObject); pBook = qof_instance_get_book (QOF_INSTANCE (pAccount)); if (guid != NULL) { pParent = xaccAccountLookup (guid, pBook); if (pParent != NULL) { gnc_account_append_child (pParent, pAccount); } } }
/** * Saves the budget amounts for a budget. * * @param sql_be SQL backend * @param budget Budget */ static gboolean save_budget_amounts (GncSqlBackend* sql_be, GncBudget* budget) { GList* descendants; GList* node; budget_amount_info_t info; guint num_periods; gboolean is_ok = TRUE;; g_return_val_if_fail (sql_be != NULL, FALSE); g_return_val_if_fail (budget != NULL, FALSE); // Delete the amounts, then save delete_budget_amounts (sql_be, budget); info.budget = budget; num_periods = gnc_budget_get_num_periods (budget); descendants = gnc_account_get_descendants (gnc_book_get_root_account ( sql_be->book())); for (node = descendants; node != NULL && is_ok; node = g_list_next (node)) { guint i; info.account = GNC_ACCOUNT (node->data); for (i = 0; i < num_periods && is_ok; i++) { if (gnc_budget_is_account_period_value_set (budget, info.account, i)) { info.period_num = i; is_ok = sql_be->do_db_operation(OP_DB_INSERT, AMOUNTS_TABLE, "", &info, budget_amounts_col_table); } } } g_list_free (descendants); return is_ok; }
/** 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; }
static gpointer get_parent (gpointer pObject) { const Account* pAccount; const Account* pParent; const GncGUID* parent_guid; g_return_val_if_fail (pObject != NULL, NULL); g_return_val_if_fail (GNC_IS_ACCOUNT (pObject), NULL); pAccount = GNC_ACCOUNT (pObject); pParent = gnc_account_get_parent (pAccount); if (pParent == NULL) { parent_guid = NULL; } else { parent_guid = qof_instance_get_guid (QOF_INSTANCE (pParent)); } return (gpointer)parent_guid; }
/* ================================================================= */ bool GncSqlAccountBackend::commit (GncSqlBackend* sql_be, QofInstance* inst) { Account* pAcc = GNC_ACCOUNT (inst); const GncGUID* guid; gboolean is_infant; gboolean is_ok = FALSE; gnc_commodity* commodity; E_DB_OPERATION op; g_return_val_if_fail (sql_be != NULL, FALSE); g_return_val_if_fail (inst != NULL, FALSE); g_return_val_if_fail (GNC_IS_ACCOUNT (inst), FALSE); ENTER ("inst=%p", inst); is_infant = qof_instance_get_infant (inst); // If there is no commodity yet, this might be because a new account name // has been entered directly into the register and an account window will // be opened. The account info is not complete yet, but the name has been // set, triggering this commit commodity = xaccAccountGetCommodity (pAcc); is_ok = TRUE; 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; } // If not deleting the account, ensure the commodity is in the db if (op != OP_DB_DELETE && commodity != NULL) { is_ok = sql_be->save_commodity(commodity); } if (is_ok) { is_ok = sql_be->do_db_operation (op, TABLE_NAME, GNC_ID_ACCOUNT, pAcc, 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 (sql_be, guid, is_infant, inst); } else { is_ok = gnc_sql_slots_delete (sql_be, guid); } } LEAVE ("is_ok=%d", is_ok); return is_ok; }
static gboolean gnc_html_register_url_cb (const char *location, const char *label, gboolean new_window, GNCURLResult *result) { GncPluginPage *page = NULL; GNCSplitReg * gsr = NULL; Split * split = NULL; Account * account = NULL; Transaction * trans; GList * node; QofBook * book = gnc_get_current_book(); GncGUID guid; QofInstance * entity = NULL; g_return_val_if_fail (location != NULL, FALSE); g_return_val_if_fail (result != NULL, FALSE); result->load_to_stream = FALSE; /* href="gnc-register:account=My Bank Account" */ if (strncmp("account=", location, 8) == 0) { account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (), location + 8); } /* href="gnc-register:guid=12345678901234567890123456789012" */ else if (strncmp ("acct-guid=", location, strlen ("acct-guid=")) == 0) { if (!validate_type("acct-guid=", location, GNC_ID_ACCOUNT, result, &guid, &entity)) return FALSE; account = GNC_ACCOUNT(entity); } else if (strncmp ("trans-guid=", location, strlen ("trans-guid=")) == 0) { if (!validate_type("trans-guid=", location, GNC_ID_TRANS, result, &guid, &entity)) return FALSE; trans = (Transaction *) entity; for (node = xaccTransGetSplitList (trans); node; node = node->next) { split = node->data; account = xaccSplitGetAccount(split); if (account) break; } if (!account) { result->error_message = g_strdup_printf (_("Transaction with no Accounts: %s"), location); return FALSE; } } else if (strncmp ("split-guid=", location, strlen ("split-guid=")) == 0) { if (!validate_type("split-guid=", location, GNC_ID_SPLIT, result, &guid, &entity)) return FALSE; split = (Split *) entity; account = xaccSplitGetAccount(split); } else { result->error_message = g_strdup_printf (_("Unsupported entity type: %s"), location); return FALSE; } page = gnc_plugin_page_register_new (account, FALSE); gnc_main_window_open_page (NULL, page); if (split) { gsr = gnc_plugin_page_register_get_gsr(page); gnc_split_reg_jump_to_split( gsr, split ); } return TRUE; }