Move shares & price to split row in journal mode.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3218 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2000-12-01 07:16:51 +00:00
parent 9415ee13b5
commit 88bdc41cd8
3 changed files with 91 additions and 25 deletions

View File

@ -3103,6 +3103,35 @@ get_trans_total_value (SplitRegister *reg, Transaction *trans)
return total;
}
static gnc_numeric
get_trans_total_shares (SplitRegister *reg, Transaction *trans)
{
GList *node;
Account *account;
gnc_numeric total = gnc_numeric_zero ();
SRInfo *info = xaccSRGetInfo(reg);
account = info->default_source_account;
if (!account)
return total;
total = gnc_numeric_convert (total, xaccAccountGetSecuritySCU (account),
GNC_RND_ROUND);
for (node = xaccTransGetSplitList (trans); node; node = node->next)
{
Split *split = node->data;
if (xaccSplitGetAccount (split) != account)
continue;
total = gnc_numeric_add_fixed (total, xaccSplitGetShareAmount (split));
}
return total;
}
static Split *
get_trans_last_split (SplitRegister *reg, Transaction *trans)
{
@ -3408,6 +3437,16 @@ xaccSRGetEntryHandler (VirtualLocation virt_loc, short _cell_type,
gnc_split_value_print_info (split, FALSE));
}
case TSHRS_CELL:
{
gnc_numeric total;
total = get_trans_total_shares (reg, trans);
return xaccPrintAmount (total,
gnc_split_quantity_print_info (split, FALSE));
}
default:
return "";
break;
@ -3420,6 +3459,7 @@ xaccSRGetFGColorHandler (VirtualLocation virt_loc, gpointer user_data)
SplitRegister *reg = user_data;
const guint32 black = 0x000000;
const guint32 red = 0xff0000;
Transaction *trans;
VirtualCell *vcell;
gboolean is_current;
CellType cell_type;
@ -3436,6 +3476,8 @@ xaccSRGetFGColorHandler (VirtualLocation virt_loc, gpointer user_data)
if (split == NULL)
return black;
trans = xaccSplitGetParent (split);
cell_type = xaccSplitRegisterGetCellType (reg, virt_loc);
is_current = virt_cell_loc_equal (reg->table->current_cursor_loc.vcell_loc,
@ -3444,10 +3486,13 @@ xaccSRGetFGColorHandler (VirtualLocation virt_loc, gpointer user_data)
switch (cell_type)
{
case SHRS_CELL:
case TSHRS_CELL:
{
gnc_numeric shares;
if (is_current)
if (cell_type == TSHRS_CELL)
shares = get_trans_total_shares (reg, trans);
else if (is_current)
shares = xaccGetPriceCellValue (reg->sharesCell);
else
shares = xaccSplitGetShareAmount (split);
@ -3460,10 +3505,14 @@ xaccSRGetFGColorHandler (VirtualLocation virt_loc, gpointer user_data)
break;
case SHRBALN_CELL:
case TSHRBALN_CELL:
{
gnc_numeric balance;
balance = xaccSplitGetShareBalance (split);
if (cell_type == SHRBALN_CELL)
balance = xaccSplitGetShareBalance (split);
else
balance = get_trans_total_share_balance (reg, trans);
if (gnc_numeric_negative_p (balance))
return red;
@ -3473,12 +3522,16 @@ xaccSRGetFGColorHandler (VirtualLocation virt_loc, gpointer user_data)
break;
case BALN_CELL:
case TBALN_CELL:
{
gnc_numeric balance;
/* 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)
{

View File

@ -102,6 +102,7 @@ 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), /* tshares cell */
N_("sample:999,999.000"+7), /* tshrbaln cell */
N_("sample:999,999.000"+7), /* tbalance cell */
N_("sample:Notes field sample text string"+7), /* notes cell */
@ -126,6 +127,7 @@ static CellAlignment cell_alignments[] =
CELL_ALIGN_RIGHT, /* mxfrm cell */
CELL_ALIGN_RIGHT, /* tcredit cell */
CELL_ALIGN_RIGHT, /* tdebit cell */
CELL_ALIGN_RIGHT, /* tshares cell */
CELL_ALIGN_RIGHT, /* tshrbaln cell */
CELL_ALIGN_RIGHT, /* tbalance cell */
CELL_ALIGN_LEFT, /* notes cell */
@ -197,6 +199,7 @@ configLabels (SplitRegister *reg)
LABEL (MXFRM, _("Transfer"));
LABEL (TCRED, _("Total"));
LABEL (TDEBT, _("Total"));
LABEL (TSHRS, _("Total"));
LABEL (TSHRBALN, _("Total Shares"));
LABEL (TBALN, _("Balance"));
LABEL (NOTES, _("Notes"));
@ -537,8 +540,7 @@ configLayout (SplitRegister *reg)
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, TSHRS_CELL, 0, 5);
set_cell (reg, curs, TDEBT_CELL, 0, 7);
set_cell (reg, curs, TCRED_CELL, 0, 8);
set_cell (reg, curs, TSHRBALN_CELL, 0, 9);
@ -553,6 +555,8 @@ configLayout (SplitRegister *reg)
set_cell (reg, curs, ACTN_CELL, 0, 1);
set_cell (reg, curs, MEMO_CELL, 0, 2);
set_cell (reg, curs, XFRM_CELL, 0, 3);
set_cell (reg, curs, SHRS_CELL, 0, 5);
set_cell (reg, curs, PRIC_CELL, 0, 6);
set_cell (reg, curs, DEBT_CELL, 0, 7);
set_cell (reg, curs, CRED_CELL, 0, 8);
@ -563,16 +567,16 @@ configLayout (SplitRegister *reg)
case PORTFOLIO_LEDGER:
{
curs = reg->cursor_ledger_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, XTO_CELL, 0, 3);
set_cell (reg, curs, MXFRM_CELL, 0, 4);
set_cell (reg, curs, RECN_CELL, 0, 5);
set_cell (reg, curs, SHRS_CELL, 0, 6);
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, DATE_CELL, 0, 0);
set_cell (reg, curs, NUM_CELL, 0, 1);
set_cell (reg, curs, DESC_CELL, 0, 2);
set_cell (reg, curs, XTO_CELL, 0, 3);
set_cell (reg, curs, MXFRM_CELL, 0, 4);
set_cell (reg, curs, RECN_CELL, 0, 5);
set_cell (reg, curs, SHRS_CELL, 0, 6);
set_cell (reg, curs, PRIC_CELL, 0, 7);
set_cell (reg, curs, DEBT_CELL, 0, 8);
set_cell (reg, curs, CRED_CELL, 0, 9);
curs = reg->cursor_ledger_double;
copy_cursor_row (reg, curs, reg->cursor_ledger_single, 0);
@ -581,15 +585,14 @@ configLayout (SplitRegister *reg)
set_cell (reg, curs, NOTES_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, XTO_CELL, 0, 3);
set_cell (reg, curs, RECN_CELL, 0, 5);
set_cell (reg, curs, SHRS_CELL, 0, 6);
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, DATE_CELL, 0, 0);
set_cell (reg, curs, NUM_CELL, 0, 1);
set_cell (reg, curs, DESC_CELL, 0, 2);
set_cell (reg, curs, XTO_CELL, 0, 3);
set_cell (reg, curs, RECN_CELL, 0, 5);
set_cell (reg, curs, TSHRS_CELL, 0, 6);
set_cell (reg, curs, TDEBT_CELL, 0, 8);
set_cell (reg, curs, TCRED_CELL, 0, 9);
curs = reg->cursor_journal_double;
copy_cursor_row (reg, curs, reg->cursor_journal_single, 0);
@ -600,6 +603,8 @@ configLayout (SplitRegister *reg)
set_cell (reg, curs, ACTN_CELL, 0, 1);
set_cell (reg, curs, MEMO_CELL, 0, 2);
set_cell (reg, curs, XFRM_CELL, 0, 4);
set_cell (reg, curs, SHRS_CELL, 0, 6);
set_cell (reg, curs, PRIC_CELL, 0, 7);
set_cell (reg, curs, DEBT_CELL, 0, 8);
set_cell (reg, curs, CRED_CELL, 0, 9);
@ -628,7 +633,7 @@ xaccMallocSplitRegister (SplitRegisterType type,
{
SplitRegister * reg;
reg = g_new0(SplitRegister, 1);
reg = g_new0 (SplitRegister, 1);
xaccInitSplitRegister (reg, type, style, use_double_line,
entry_handler, fg_color_handler, bg_color_handler,
@ -792,6 +797,7 @@ xaccInitSplitRegister (SplitRegister *reg,
NEW (MXFRM, mxfrm, Combo);
NEW (TCRED, tcredit, Price);
NEW (TDEBT, tdebit, Price);
NEW (TSHRS, tshares, Price);
NEW (TSHRBALN, tshrbaln, Price);
NEW (TBALN, tbalance, Price);
NEW (NOTES, notes, QuickFill);
@ -859,6 +865,7 @@ xaccInitSplitRegister (SplitRegister *reg,
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->tsharesCell->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;
@ -880,6 +887,8 @@ xaccInitSplitRegister (SplitRegister *reg,
/* Initialize shares and share balance cells */
xaccSetPriceCellPrintInfo
(reg->sharesCell, gnc_default_share_print_info ());
xaccSetPriceCellPrintInfo
(reg->tsharesCell, gnc_default_share_print_info ());
xaccSetPriceCellPrintInfo
(reg->shrbalnCell, gnc_default_share_print_info ());
xaccSetPriceCellPrintInfo
@ -1018,6 +1027,7 @@ xaccDestroySplitRegister (SplitRegister *reg)
xaccDestroyComboCell (reg->mxfrmCell);
xaccDestroyPriceCell (reg->tcreditCell);
xaccDestroyPriceCell (reg->tdebitCell);
xaccDestroyPriceCell (reg->tsharesCell);
xaccDestroyPriceCell (reg->tshrbalnCell);
xaccDestroyPriceCell (reg->tbalanceCell);
xaccDestroyQuickFillCell (reg->notesCell);
@ -1039,6 +1049,7 @@ xaccDestroySplitRegister (SplitRegister *reg)
reg->mxfrmCell = NULL;
reg->tcreditCell = NULL;
reg->tdebitCell = NULL;
reg->tsharesCell = NULL;
reg->tshrbalnCell = NULL;
reg->tbalanceCell = NULL;
reg->notesCell = NULL;

View File

@ -96,6 +96,7 @@ typedef enum
MXFRM_CELL, /* MXFRM is the "mirrored" transfer-from account */
TCRED_CELL, /* T* cells are transaction summary cells */
TDEBT_CELL,
TSHRS_CELL,
TSHRBALN_CELL,
TBALN_CELL,
NOTES_CELL,
@ -197,6 +198,7 @@ struct _SplitRegister
ComboCell * mxfrmCell;
PriceCell * tcreditCell;
PriceCell * tdebitCell;
PriceCell * tsharesCell;
PriceCell * tshrbalnCell;
PriceCell * tbalanceCell;
QuickFillCell * notesCell;