From 97aa3c68fe10543cf3c0682e4229db49a45b6786 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Tue, 21 Nov 2000 06:39:43 +0000 Subject: [PATCH] Display total share balance and value balance for transaction lines. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3185 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/SplitLedger.c | 108 +++++++++++++++++++++----- src/engine/Transaction.h | 9 +-- src/register/splitreg.c | 158 +++++++++++++++++++++------------------ src/register/splitreg.h | 8 +- 4 files changed, 186 insertions(+), 97 deletions(-) diff --git a/src/SplitLedger.c b/src/SplitLedger.c index a63327df81..5fe8796380 100644 --- a/src/SplitLedger.c +++ b/src/SplitLedger.c @@ -690,7 +690,7 @@ sr_set_cell_fractions (SplitRegister *reg, Split *split) } static CellBlock * -sr_get_lead_cursor (SplitRegister *reg) +sr_get_passive_cursor (SplitRegister *reg) { switch (reg->style) { @@ -709,6 +709,26 @@ sr_get_lead_cursor (SplitRegister *reg) return NULL; } +static CellBlock * +sr_get_active_cursor (SplitRegister *reg) +{ + switch (reg->style) + { + case REG_STYLE_LEDGER: + return reg->use_double_line ? + reg->cursor_ledger_double : reg->cursor_ledger_single; + + case REG_STYLE_AUTO_LEDGER: + case REG_STYLE_JOURNAL: + return reg->use_double_line ? + reg->cursor_journal_double : reg->cursor_journal_single; + } + + PWARN ("bad register style"); + + return NULL; +} + /* ======================================================== */ /* This callback gets called when the user clicks on the gui * in such a way as to leave the current virtual cursor, and @@ -844,15 +864,13 @@ LedgerMoveCursor (Table *table, VirtualLocation *p_new_virt_loc) vc_loc = old_trans_split_loc; gnc_table_set_virt_cell_cursor (table, vc_loc, - sr_get_lead_cursor (reg)); + sr_get_passive_cursor (reg)); xaccSRSetTransVisible (reg, vc_loc, FALSE, reg->style == REG_STYLE_JOURNAL); xaccSRGetTransSplit (reg, new_virt_loc.vcell_loc, &vc_loc); gnc_table_set_virt_cell_cursor (table, vc_loc, - reg->use_double_line ? - reg->cursor_journal_double : - reg->cursor_journal_single); + sr_get_active_cursor (reg)); xaccSRSetTransVisible (reg, vc_loc, TRUE, reg->style == REG_STYLE_JOURNAL); @@ -2925,7 +2943,7 @@ xaccSRSaveChangedCells (SplitRegister *reg, Transaction *trans, Split *split) /* ======================================================== */ static gnc_numeric -get_trans_total (SplitRegister *reg, Transaction *trans) +get_trans_total_value (SplitRegister *reg, Transaction *trans) { GList *node; Account *account; @@ -2953,6 +2971,59 @@ get_trans_total (SplitRegister *reg, Transaction *trans) return total; } +static Split * +get_trans_last_split (SplitRegister *reg, Transaction *trans) +{ + GList *node; + Account *account; + Split *last_split = NULL; + + SRInfo *info = xaccSRGetInfo(reg); + account = info->default_source_account; + + if (!account) + return last_split; + + for (node = xaccTransGetSplitList (trans); node; node = node->next) + { + Split *split = node->data; + + if (xaccSplitGetAccount (split) != account) + continue; + + if (!last_split) + { + last_split = split; + continue; + } + + if (xaccSplitDateOrder (last_split, split) < 0) + last_split = split; + } + + return last_split; +} + +static gnc_numeric +get_trans_total_share_balance (SplitRegister *reg, Transaction *trans) +{ + Split *last_split; + + last_split = get_trans_last_split (reg, trans); + + return xaccSplitGetShareBalance (last_split); +} + +static gnc_numeric +get_trans_total_balance (SplitRegister *reg, Transaction *trans) +{ + Split *last_split; + + last_split = get_trans_last_split (reg, trans); + + return xaccSplitGetBalance (last_split); +} + /* ======================================================== */ const char * @@ -3004,6 +3075,7 @@ xaccSRGetEntryHandler (gpointer vcell_data, short _cell_type, break; case SHRBALN_CELL: + case TSHRBALN_CELL: { SRInfo *info = xaccSRGetInfo(reg); Split *blank_split = xaccSplitLookup(&info->blank_split_guid); @@ -3012,7 +3084,10 @@ xaccSRGetEntryHandler (gpointer vcell_data, short _cell_type, if (split == blank_split) return ""; - balance = xaccSplitGetShareBalance (split); + if (cell_type == SHRBALN_CELL) + balance = xaccSplitGetShareBalance (split); + else + balance = get_trans_total_share_balance (reg, trans); return xaccPrintAmount (balance, gnc_split_quantity_print_info (split, FALSE)); @@ -3020,6 +3095,7 @@ xaccSRGetEntryHandler (gpointer vcell_data, short _cell_type, break; case BALN_CELL: + case TBALN_CELL: { SRInfo *info = xaccSRGetInfo(reg); Split *blank_split = xaccSplitLookup(&info->blank_split_guid); @@ -3030,7 +3106,11 @@ xaccSRGetEntryHandler (gpointer vcell_data, short _cell_type, /* If the reverse_balance callback is present use that. * Otherwise, reverse income and expense by default. */ - balance = xaccSplitGetBalance (split); + if (cell_type == BALN_CELL) + balance = xaccSplitGetBalance (split); + else + balance = get_trans_total_balance (reg, trans); + if (reverse_balance != NULL) { Account *account; @@ -3042,9 +3122,6 @@ xaccSRGetEntryHandler (gpointer vcell_data, short _cell_type, if (reverse_balance(account)) balance = gnc_numeric_neg (balance); } - else if ((INCOME_REGISTER == reg->type) || - (EXPENSE_REGISTER == reg->type)) - balance = gnc_numeric_neg (balance); return xaccPrintAmount (balance, gnc_split_value_print_info (split, FALSE)); @@ -3145,7 +3222,7 @@ xaccSRGetEntryHandler (gpointer vcell_data, short _cell_type, { gnc_numeric total; - total = get_trans_total (reg, trans); + total = get_trans_total_value (reg, trans); if (gnc_numeric_zero_p (total)) return ""; @@ -3242,9 +3319,6 @@ xaccSRGetFGColorHandler (VirtualLocation virt_loc, gpointer user_data) if (reverse_balance (account)) balance = gnc_numeric_neg (balance); } - else if ((INCOME_REGISTER == reg->type) || - (EXPENSE_REGISTER == reg->type)) - balance = gnc_numeric_neg (balance); if (gnc_numeric_negative_p (balance)) return red; @@ -3475,7 +3549,7 @@ xaccSRLoadRegister (SplitRegister *reg, Split **slist, multi_line = (reg->style == REG_STYLE_JOURNAL); dynamic = (reg->style == REG_STYLE_AUTO_LEDGER); - lead_cursor = sr_get_lead_cursor (reg); + lead_cursor = sr_get_passive_cursor (reg); /* figure out where we are going to. */ find_trans = info->cursor_hint_trans; @@ -3630,7 +3704,7 @@ xaccSRLoadRegister (SplitRegister *reg, Split **slist, if (dynamic || multi_line) { gnc_table_set_virt_cell_cursor (table, trans_split_loc.vcell_loc, - reg->cursor_journal_single); + sr_get_active_cursor (reg)); xaccSRSetTransVisible (reg, trans_split_loc.vcell_loc, TRUE, multi_line); } else diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index 6aa31512d1..6f8c073fd0 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -449,7 +449,8 @@ Account * xaccSplitGetAccount (Split *split); * Finally, it returns zero if all of the above match. * Note that it does *NOT* compare its member splits. * - * The xaccSplitOrder(sa,sb) method is useful for sorting. + * The xaccSplitDateOrder(sa,sb) method is useful for sorting. + * if sa and sb have different transactions, return their xaccTransOrder * return a negative value if split sa has a smaller currency-value than sb, * return a positive value if split sa has a larger currency-value than sb, * return a negative value if split sa has a smaller share-price than sb, @@ -458,12 +459,6 @@ Account * xaccSplitGetAccount (Split *split); * c-library routine, returning what strcmp would return. * Then it compares the reconciled flags, then the reconciled dates, * Finally, it returns zero if all of the above match. - * Note that it does *NOT* compare its parent transaction. - * - * The xaccSplitDateOrder(sa,sb) method is useful for sorting. - * It is just like the xaccSplitOrder() routine, except that it first - * calls xaccTransOrder(), and then does split comparisons only if - * xaccTransOrder returned zero (i.e. that everything matched). * */ diff --git a/src/register/splitreg.c b/src/register/splitreg.c index 04f328df82..0595d5f80e 100644 --- a/src/register/splitreg.c +++ b/src/register/splitreg.c @@ -100,6 +100,8 @@ static char *cell_sample_strings[] = N_("sample:Expenses:Automobile:Gasoline"+7), /* mxfrm cell */ N_("sample:999,999.000"+7), /* tcredit cell */ N_("sample:999,999.000"+7), /* tdebit cell */ + N_("sample:999,999.000"+7), /* tshrbaln cell */ + N_("sample:999,999.000"+7), /* tbalance cell */ }; static CellAlignment cell_alignments[] = @@ -121,6 +123,8 @@ static CellAlignment cell_alignments[] = CELL_ALIGN_RIGHT, /* mxfrm cell */ CELL_ALIGN_RIGHT, /* tcredit cell */ CELL_ALIGN_RIGHT, /* tdebit cell */ + CELL_ALIGN_RIGHT, /* tshrbaln cell */ + CELL_ALIGN_RIGHT, /* tbalance cell */ }; @@ -172,23 +176,25 @@ configLabels (SplitRegister *reg) type = reg->type; - LABEL (DATE, _("Date")); - LABEL (NUM, _("Num")); - LABEL (DESC, _("Description")); - LABEL (RECN, _("Reconciled:R"+11)); - LABEL (SHRBALN, _("Total Shares")); - LABEL (BALN, _("Balance")); - LABEL (ACTN, _("Action")); - LABEL (XFRM, _("Account")); - LABEL (XTO, _("Account")); - LABEL (MEMO, _("Memo")); - LABEL (CRED, _("Credit")); - LABEL (DEBT, _("Debit")); - LABEL (PRIC, _("Price")); - LABEL (SHRS, _("Shares")); - LABEL (MXFRM, _("Transfer")); - LABEL (TCRED, _("Total")); - LABEL (TDEBT, _("Total")); + LABEL (DATE, _("Date")); + LABEL (NUM, _("Num")); + LABEL (DESC, _("Description")); + LABEL (RECN, _("Reconciled:R"+11)); + LABEL (SHRBALN, _("Total Shares")); + LABEL (BALN, _("Balance")); + LABEL (ACTN, _("Action")); + LABEL (XFRM, _("Account")); + LABEL (XTO, _("Account")); + LABEL (MEMO, _("Memo")); + LABEL (CRED, _("Credit")); + LABEL (DEBT, _("Debit")); + LABEL (PRIC, _("Price")); + LABEL (SHRS, _("Shares")); + LABEL (MXFRM, _("Transfer")); + LABEL (TCRED, _("Total")); + LABEL (TDEBT, _("Total")); + LABEL (TSHRBALN, _("Total Shares")); + LABEL (TBALN, _("Balance")); if (debit_getter != NULL) { @@ -436,7 +442,7 @@ configLayout (SplitRegister *reg) set_cell (reg, curs, RECN_CELL, 0, 4); set_cell (reg, curs, TDEBT_CELL, 0, 5); set_cell (reg, curs, TCRED_CELL, 0, 6); - set_cell (reg, curs, BALN_CELL, 0, 7); + set_cell (reg, curs, TBALN_CELL, 0, 7); curs = reg->cursor_journal_double; copy_cursor_row (reg, curs, reg->cursor_journal_single, 0); @@ -522,16 +528,16 @@ configLayout (SplitRegister *reg) set_cell (reg, curs, MEMO_CELL, 1, 2); curs = reg->cursor_journal_single; - set_cell (reg, curs, DATE_CELL, 0, 0); - set_cell (reg, curs, NUM_CELL, 0, 1); - set_cell (reg, curs, DESC_CELL, 0, 2); - set_cell (reg, curs, RECN_CELL, 0, 4); - set_cell (reg, curs, SHRS_CELL, 0, 5); - set_cell (reg, curs, PRIC_CELL, 0, 6); - set_cell (reg, curs, TDEBT_CELL, 0, 7); - set_cell (reg, curs, TCRED_CELL, 0, 8); - set_cell (reg, curs, SHRBALN_CELL, 0, 9); - set_cell (reg, curs, BALN_CELL, 0, 10); + set_cell (reg, curs, DATE_CELL, 0, 0); + set_cell (reg, curs, NUM_CELL, 0, 1); + set_cell (reg, curs, DESC_CELL, 0, 2); + set_cell (reg, curs, RECN_CELL, 0, 4); + set_cell (reg, curs, SHRS_CELL, 0, 5); + set_cell (reg, curs, PRIC_CELL, 0, 6); + set_cell (reg, curs, TDEBT_CELL, 0, 7); + set_cell (reg, curs, TCRED_CELL, 0, 8); + set_cell (reg, curs, TSHRBALN_CELL, 0, 9); + set_cell (reg, curs, TBALN_CELL, 0, 10); curs = reg->cursor_journal_double; copy_cursor_row (reg, curs, reg->cursor_journal_single, 0); @@ -562,7 +568,6 @@ configLayout (SplitRegister *reg) set_cell (reg, curs, PRIC_CELL, 0, 7); set_cell (reg, curs, DEBT_CELL, 0, 8); set_cell (reg, curs, CRED_CELL, 0, 9); - set_cell (reg, curs, SHRBALN_CELL, 0, 10); curs = reg->cursor_ledger_double; copy_cursor_row (reg, curs, reg->cursor_ledger_single, 0); @@ -580,7 +585,6 @@ configLayout (SplitRegister *reg) set_cell (reg, curs, PRIC_CELL, 0, 7); set_cell (reg, curs, TDEBT_CELL, 0, 8); set_cell (reg, curs, TCRED_CELL, 0, 9); - set_cell (reg, curs, SHRBALN_CELL, 0, 10); curs = reg->cursor_journal_double; copy_cursor_row (reg, curs, reg->cursor_journal_single, 0); @@ -660,7 +664,7 @@ mallocCursors (SplitRegister *reg) break; case PORTFOLIO_LEDGER: - num_cols = 11; + num_cols = 10; break; default: @@ -757,23 +761,25 @@ xaccInitSplitRegister (SplitRegister *reg, reg->nullCell = xaccMallocBasicCell (); - NEW (DATE, date, Date); - NEW (NUM, num, Num); - NEW (DESC, desc, QuickFill); - NEW (RECN, recn, Recn); - NEW (SHRBALN, shrbaln, Price); - NEW (BALN, balance, Price); - NEW (XFRM, xfrm, Combo); - NEW (XTO, xto, Combo); - NEW (ACTN, action, Combo); - NEW (MEMO, memo, QuickFill); - NEW (CRED, credit, Price); - NEW (DEBT, debit, Price); - NEW (PRIC, price, Price); - NEW (SHRS, shares, Price); - NEW (MXFRM, mxfrm, Combo); - NEW (TCRED, tcredit, Price); - NEW (TDEBT, tdebit, Price); + NEW (DATE, date, Date); + NEW (NUM, num, Num); + NEW (DESC, desc, QuickFill); + NEW (RECN, recn, Recn); + NEW (SHRBALN, shrbaln, Price); + NEW (BALN, balance, Price); + NEW (XFRM, xfrm, Combo); + NEW (XTO, xto, Combo); + NEW (ACTN, action, Combo); + NEW (MEMO, memo, QuickFill); + NEW (CRED, credit, Price); + NEW (DEBT, debit, Price); + NEW (PRIC, price, Price); + NEW (SHRS, shares, Price); + NEW (MXFRM, mxfrm, Combo); + NEW (TCRED, tcredit, Price); + NEW (TDEBT, tdebit, Price); + NEW (TSHRBALN, tshrbaln, Price); + NEW (TBALN, tbalance, Price); /* --------------------------- */ @@ -830,10 +836,12 @@ xaccInitSplitRegister (SplitRegister *reg, _("Enter a description of the transaction")); /* The balance and total cells are just placeholders */ - reg->balanceCell->cell.input_output = XACC_CELL_ALLOW_NONE; - reg->shrbalnCell->cell.input_output = XACC_CELL_ALLOW_NONE; - reg->tcreditCell->cell.input_output = XACC_CELL_ALLOW_NONE; - reg->tdebitCell->cell.input_output = XACC_CELL_ALLOW_NONE; + reg->balanceCell->cell.input_output = XACC_CELL_ALLOW_NONE; + reg->shrbalnCell->cell.input_output = XACC_CELL_ALLOW_NONE; + reg->tcreditCell->cell.input_output = XACC_CELL_ALLOW_NONE; + reg->tdebitCell->cell.input_output = XACC_CELL_ALLOW_NONE; + reg->tbalanceCell->cell.input_output = XACC_CELL_ALLOW_NONE; + reg->tshrbalnCell->cell.input_output = XACC_CELL_ALLOW_NONE; /* by default, don't blank zeros on the price cells. */ xaccSetPriceCellBlankZero(reg->priceCell, FALSE); @@ -851,8 +859,12 @@ xaccInitSplitRegister (SplitRegister *reg, xaccSetPriceCellValue (reg->sharesCell, gnc_numeric_zero ()); /* Initialize shares and share balance cells */ - xaccSetPriceCellPrintInfo (reg->sharesCell, gnc_default_share_print_info ()); - xaccSetPriceCellPrintInfo (reg->shrbalnCell,gnc_default_share_print_info ()); + xaccSetPriceCellPrintInfo + (reg->sharesCell, gnc_default_share_print_info ()); + xaccSetPriceCellPrintInfo + (reg->shrbalnCell, gnc_default_share_print_info ()); + xaccSetPriceCellPrintInfo + (reg->tshrbalnCell, gnc_default_share_print_info ()); /* The action cell should accept strings not in the list */ xaccComboCellSetStrict (reg->actionCell, FALSE); @@ -987,24 +999,28 @@ xaccDestroySplitRegister (SplitRegister *reg) xaccDestroyComboCell (reg->mxfrmCell); xaccDestroyPriceCell (reg->tcreditCell); xaccDestroyPriceCell (reg->tdebitCell); + xaccDestroyPriceCell (reg->tshrbalnCell); + xaccDestroyPriceCell (reg->tbalanceCell); - reg->dateCell = NULL; - reg->numCell = NULL; - reg->descCell = NULL; - reg->recnCell = NULL; - reg->shrbalnCell = NULL; - reg->balanceCell = NULL; - reg->actionCell = NULL; - reg->xfrmCell = NULL; - reg->xtoCell = NULL; - reg->memoCell = NULL; - reg->creditCell = NULL; - reg->debitCell = NULL; - reg->priceCell = NULL; - reg->sharesCell = NULL; - reg->mxfrmCell = NULL; - reg->tcreditCell = NULL; - reg->tdebitCell = NULL; + reg->dateCell = NULL; + reg->numCell = NULL; + reg->descCell = NULL; + reg->recnCell = NULL; + reg->shrbalnCell = NULL; + reg->balanceCell = NULL; + reg->actionCell = NULL; + reg->xfrmCell = NULL; + reg->xtoCell = NULL; + reg->memoCell = NULL; + reg->creditCell = NULL; + reg->debitCell = NULL; + reg->priceCell = NULL; + reg->sharesCell = NULL; + reg->mxfrmCell = NULL; + reg->tcreditCell = NULL; + reg->tdebitCell = NULL; + reg->tshrbalnCell = NULL; + reg->tbalanceCell = NULL; for (i = 0; i < CELL_TYPE_COUNT; i++) { diff --git a/src/register/splitreg.h b/src/register/splitreg.h index 3ee205bf45..ec1da7c20e 100644 --- a/src/register/splitreg.h +++ b/src/register/splitreg.h @@ -93,9 +93,11 @@ typedef enum DEBT_CELL, PRIC_CELL, SHRS_CELL, - MXFRM_CELL, /* MXFRM is the "mirrored" transfer-from account */ - TCRED_CELL, + MXFRM_CELL, /* MXFRM is the "mirrored" transfer-from account */ + TCRED_CELL, /* T* cells are transaction summary cells */ TDEBT_CELL, + TSHRBALN_CELL, + TBALN_CELL, CELL_TYPE_COUNT } CellType; @@ -190,6 +192,8 @@ struct _SplitRegister ComboCell * mxfrmCell; PriceCell * tcreditCell; PriceCell * tdebitCell; + PriceCell * tshrbalnCell; + PriceCell * tbalanceCell; SplitRegisterType type; SplitRegisterStyle style;