static const char* equals_node_val_vs_splits (xmlNodePtr node, const Transaction* trn) { xmlNodePtr spl_node; Split* spl_mark; int i; g_return_val_if_fail (node, FALSE); g_return_val_if_fail (node->xmlChildrenNode, FALSE); for (i = 0, spl_mark = xaccTransGetSplit ((Transaction*)trn, i); spl_mark; i++, spl_mark = xaccTransGetSplit ((Transaction*)trn, i)) { spl_node = find_appropriate_node (node, spl_mark); if (!spl_node) { gchar guidstr[GUID_ENCODING_LENGTH + 1]; guid_to_string_buff (xaccSplitGetGUID (spl_mark), guidstr); g_print ("Split GUID %s", guidstr); return "no matching split found"; } const char* msg = equals_node_val_vs_split_internal (spl_node, spl_mark); if (msg != NULL) { return msg; } } return NULL; }
static void add_quickfill_completions(TableLayout *layout, Transaction *trans, Split *split, gboolean has_last_num) { Split *s; int i = 0; gnc_quickfill_cell_add_completion( (QuickFillCell *) gnc_table_layout_get_cell(layout, DESC_CELL), xaccTransGetDescription(trans)); gnc_quickfill_cell_add_completion( (QuickFillCell *) gnc_table_layout_get_cell(layout, NOTES_CELL), xaccTransGetNotes(trans)); if (!has_last_num) gnc_num_cell_set_last_num( (NumCell *) gnc_table_layout_get_cell(layout, NUM_CELL), gnc_get_num_action(trans, split)); while ((s = xaccTransGetSplit(trans, i)) != NULL) { gnc_quickfill_cell_add_completion( (QuickFillCell *) gnc_table_layout_get_cell(layout, MEMO_CELL), xaccSplitGetMemo(s)); i++; } }
/* Is this split part of a multi split transaction */ gboolean gnc_tree_util_split_reg_is_multi (Split *split) { gboolean multi = FALSE; Split *osplit; if (!split) return FALSE; osplit = xaccSplitGetOtherSplit (split); if (osplit) multi = FALSE; else { /* For multi-split transactions and stock splits, * use a special value. */ osplit = xaccTransGetSplit (xaccSplitGetParent (split), 1); if (osplit) multi = TRUE; else if (g_strcmp0 ("stock-split", xaccSplitGetType (split)) == 0) multi = TRUE; else multi = FALSE; } return multi; }
static void gnc_split_register_save_mxfrm_cell (BasicCell * cell, gpointer save_data, gpointer user_data) { SRSaveData *sd = save_data; SplitRegister *reg = user_data; Split * other_split; g_return_if_fail (gnc_basic_cell_has_name (cell, MXFRM_CELL)); other_split = xaccSplitGetOtherSplit (sd->split); /* other_split may be null for two very different reasons: * (1) the parent transaction has three or more splits in it, * and so the "other" split is ambiguous, and thus null. * (2) the parent transaction has only this one split as a child. * and "other" is null because there is no other. * * In the case (2), we want to create the other split, so that * the user's request to transfer actually works out. */ if (!other_split) { other_split = xaccTransGetSplit (sd->trans, 1); if (!other_split) { other_split = xaccMallocSplit (gnc_get_current_book ()); xaccTransAppendSplit (sd->trans, other_split); } } if (other_split) { Account *old_acc; Account *new_acc; /* Do some reparenting. Insertion into new account * will automatically delete from the old account. */ old_acc = xaccSplitGetAccount (other_split); new_acc = gnc_split_register_get_account (reg, MXFRM_CELL); if ((new_acc != NULL) && (old_acc != new_acc)) xaccAccountInsertSplit (new_acc, other_split); } }
/* Return the string entry for transfer column and if multi */ const char * gnc_tree_util_split_reg_get_transfer_entry (Split *split, gboolean *is_multi) { static char *name = NULL; gboolean multi = FALSE; Split *osplit; if (is_multi) *is_multi = multi; if (!split) return NULL; osplit = xaccSplitGetOtherSplit (split); g_free (name); if (osplit) name = gnc_get_account_name_for_register (xaccSplitGetAccount (osplit)); else { /* For multi-split transactions and stock splits, * use a special value. */ osplit = xaccTransGetSplit (xaccSplitGetParent (split), 1); if (osplit) { name = g_strdup (SPLIT_TRANS_STR); multi = TRUE; } else if (g_strcmp0 ("stock-split", xaccSplitGetType (split)) == 0) { name = g_strdup (STOCK_SPLIT_STR); multi = TRUE; } else name = g_strdup (""); } if (is_multi) *is_multi = multi; return name; }
static gboolean save_transaction( GncSqlBackend* be, Transaction* pTx, gboolean do_save_splits ) { const GncGUID* guid; gint op; gboolean is_infant; QofInstance* inst; gboolean is_ok = TRUE; gchar* err = NULL; g_return_val_if_fail( be != NULL, FALSE ); g_return_val_if_fail( pTx != NULL, FALSE ); inst = QOF_INSTANCE(pTx); is_infant = qof_instance_get_infant( inst ); if ( qof_instance_get_destroying( inst ) ) { op = OP_DB_DELETE; } else if ( be->is_pristine_db || is_infant ) { op = OP_DB_INSERT; } else { op = OP_DB_UPDATE; } if ( op != OP_DB_DELETE ) { gnc_commodity *commodity = xaccTransGetCurrency( pTx ); // Ensure the commodity is in the db is_ok = gnc_sql_save_commodity( be, commodity ); if ( ! is_ok ) { err = "Commodity save failed: Probably an invalid or missing currency"; qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT); } } if ( is_ok ) { is_ok = gnc_sql_do_db_operation( be, op, TRANSACTION_TABLE, GNC_ID_TRANS, pTx, tx_col_table ); if ( ! is_ok ) { err = "Transaction header save failed. Check trace log for SQL errors"; } } if ( is_ok ) { // Commit slots and splits guid = qof_instance_get_guid( inst ); if ( !qof_instance_get_destroying(inst) ) { is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); if ( ! is_ok ) { err = "Slots save failed. Check trace log for SQL errors"; } if ( is_ok && do_save_splits ) { is_ok = save_splits( be, guid, xaccTransGetSplitList( pTx ) ); if ( ! is_ok ) { err = "Split save failed. Check trace log for SQL errors"; } } } else { is_ok = gnc_sql_slots_delete( be, guid ); if ( ! is_ok ) { err = "Slots delete failed. Check trace log for SQL errors"; } if ( is_ok ) { is_ok = delete_splits( be, pTx ); if ( ! is_ok ) { err = "Split delete failed. Check trace log for SQL errors"; } } } } if (! is_ok ) { G_GNUC_UNUSED gchar *message1 = "Transaction %s dated %s in account %s not saved due to %s.%s"; G_GNUC_UNUSED gchar *message2 = "\nDatabase may be corrupted, check your data carefully."; Split* split = xaccTransGetSplit( pTx, 0); Account *acc = xaccSplitGetAccount( split ); /* FIXME: This needs to be implemented qof_error_format_secondary_text( GTK_MESSAGE_DIALOG( msg ), message1, xaccTransGetDescription( pTx ), qof_print_date( xaccTransGetDate( pTx ) ), xaccAccountGetName( acc ), err, message2 ); */ PERR( "Transaction %s dated %s in account %s not saved due to %s.\n", xaccTransGetDescription( pTx ), qof_print_date( xaccTransGetDate( pTx ) ), xaccAccountGetName( acc ), err ); } return is_ok; }
GNCLot * gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction *txn, Account *posted_acc, Account *xfer_acc, gnc_numeric amount, gnc_numeric exch, Timespec date, const char *memo, const char *num) { QofBook *book; Split *split; const char *name; gnc_commodity *commodity; Split *xfer_split = NULL; GNCLot *payment_lot; /* 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); if (txn) { /* Pre-existing transaction was specified. We completely clear it, * except for the split in the transfer account, unless the * transaction can't be reused (wrong currency, wrong transfer account). * In that case, the transaction is simply removed and an new * one created. */ xfer_split = xaccTransFindSplitByAccount(txn, xfer_acc); if (xaccTransGetCurrency(txn) != gncOwnerGetCurrency (owner)) { g_message("Uh oh, mismatching currency/commodity between selected transaction and owner. We fall back to manual creation of a new transaction."); xfer_split = NULL; } if (!xfer_split) { g_message("Huh? Asset account not found anymore. Fully deleting old txn and now creating a new one."); xaccTransBeginEdit (txn); xaccTransDestroy (txn); xaccTransCommitEdit (txn); txn = NULL; } else { int i = 0; xaccTransBeginEdit (txn); while (i < xaccTransCountSplits(txn)) { Split *split = xaccTransGetSplit (txn, i); if (split == xfer_split) { gnc_set_num_action (NULL, split, num, _("Payment")); ++i; } else { xaccSplitDestroy(split); } } /* Note: don't commit transaction now - that would insert an imbalance split.*/ } } /* Create the transaction if we don't have one yet */ if (!txn) { txn = xaccMallocTransaction (book); xaccTransBeginEdit (txn); } /* Insert a split for the transfer account if we don't have one yet */ if (!xfer_split) { /* Set up the transaction */ xaccTransSetDescription (txn, name ? name : ""); /* set per book option */ xaccTransSetCurrency (txn, commodity); xaccTransSetDateEnteredSecs (txn, gnc_time (NULL)); xaccTransSetDatePostedTS (txn, &date); /* The split for the transfer account */ split = xaccMallocSplit (book); xaccSplitSetMemo (split, memo); /* set per book option */ gnc_set_num_action (NULL, split, num, _("Payment")); xaccAccountBeginEdit (xfer_acc); xaccAccountInsertSplit (xfer_acc, split); xaccAccountCommitEdit (xfer_acc); xaccTransAppendSplit (txn, split); if (gnc_commodity_equal(xaccAccountGetCommodity(xfer_acc), commodity)) { xaccSplitSetBaseValue (split, amount, commodity); } else { /* Need to value the payment in terms of the owner commodity */ gnc_numeric payment_value = gnc_numeric_mul(amount, exch, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetAmount(split, amount); xaccSplitSetValue(split, payment_value); } } /* Add a split in the post account */ split = xaccMallocSplit (book); xaccSplitSetMemo (split, memo); /* set per book option */ gnc_set_num_action (NULL, split, num, _("Payment")); xaccAccountBeginEdit (posted_acc); xaccAccountInsertSplit (posted_acc, split); xaccAccountCommitEdit (posted_acc); xaccTransAppendSplit (txn, split); xaccSplitSetBaseValue (split, gnc_numeric_neg (amount), commodity); /* Create a new lot for the payment */ payment_lot = gnc_lot_new (book); gncOwnerAttachToLot (owner, payment_lot); gnc_lot_add_split (payment_lot, split); /* Mark the transaction as a payment */ gnc_set_num_action (txn, NULL, num, _("Payment")); xaccTransSetTxnType (txn, TXN_TYPE_PAYMENT); /* Commit this new transaction */ xaccTransCommitEdit (txn); return payment_lot; }