32 static QofLogModule log_module = GNC_MOD_LEDGER;
41 gnc_split_register_init_info (SplitRegister *reg)
48 info = g_new0 (SRInfo, 1);
57 info->first_pass = TRUE;
58 info->full_refresh = TRUE;
59 info->separator_changed = TRUE;
65 gnc_split_register_get_info (SplitRegister *reg)
70 if (reg->sr_info == NULL)
71 gnc_split_register_init_info (reg);
77 gnc_split_register_get_parent (SplitRegister *reg)
79 SRInfo *info = gnc_split_register_get_info (reg);
84 if (info->get_parent == NULL)
87 return info->get_parent (info->user_data);
91 gnc_split_register_get_split (SplitRegister *reg,
92 VirtualCellLocation vcell_loc)
107 gnc_split_register_get_default_account (SplitRegister *reg)
109 SRInfo *info = gnc_split_register_get_info (reg);
112 gnc_get_current_book ());
119 SRInfo *info = gnc_split_register_get_info (reg);
121 g_return_if_fail (reg != NULL);
127 gnc_split_register_get_trans (SplitRegister *reg,
128 VirtualCellLocation vcell_loc)
132 if (!reg || !reg->table)
135 split = gnc_split_register_get_split (reg, vcell_loc);
142 vcell_loc.virt_row--;
144 split = gnc_split_register_get_split (reg, vcell_loc);
154 gnc_split_register_get_trans_split (SplitRegister *reg,
155 VirtualCellLocation vcell_loc,
156 VirtualCellLocation *trans_split_loc)
165 if ((0 > vcell_loc.virt_row) || (0 > vcell_loc.virt_col))
173 if (cursor_class == CURSOR_CLASS_TRANS)
176 *trans_split_loc = vcell_loc;
178 return gnc_split_register_get_split (reg, vcell_loc);
181 vcell_loc.virt_row--;
187 SplitRegister *reg, VirtualCellLocation *trans_split_loc)
189 VirtualCellLocation vcell_loc;
194 vcell_loc = reg->table->current_cursor_loc.vcell_loc;
196 return gnc_split_register_get_trans_split (reg, vcell_loc, trans_split_loc);
200 gnc_split_register_find_split (SplitRegister *reg,
201 Transaction *trans, Split *trans_split,
203 VirtualCellLocation *vcell_loc)
205 Table *
table = reg->table;
206 gboolean found_trans = FALSE;
207 gboolean found_trans_split = FALSE;
208 gboolean found_something = FALSE;
214 for (v_row = 1; v_row <
table->num_virt_rows; v_row++)
215 for (v_col = 0; v_col <
table->num_virt_cols; v_col++)
217 VirtualCellLocation vc_loc = { v_row, v_col };
219 s = gnc_split_register_get_split (reg, vc_loc);
229 if (cursor_class == CURSOR_CLASS_TRANS)
232 if (s == trans_split)
234 found_trans_split = TRUE;
236 found_trans_split = FALSE;
238 if (find_class == CURSOR_CLASS_TRANS &&
239 (s == split || reg->style == REG_STYLE_JOURNAL))
244 if (vcell_loc != NULL)
255 found_trans_split = FALSE;
258 if (found_trans && (s == split) && s)
262 if (vcell_loc != NULL)
265 found_something = TRUE;
268 if (found_trans_split && (s == split))
273 if (vcell_loc != NULL)
276 if (cursor_class == find_class)
281 return found_something;
285 gnc_split_register_show_trans (SplitRegister *reg,
286 VirtualCellLocation start_loc)
288 VirtualCellLocation end_loc;
293 for (v_row = end_loc.virt_row + 1;
294 v_row < reg->
table->num_virt_rows; v_row++)
296 VirtualCellLocation vc_loc = { v_row, 0 };
300 if (cursor_class == CURSOR_CLASS_TRANS)
303 if (cursor_class != CURSOR_CLASS_SPLIT)
310 end_loc.virt_row = MIN (v_row, reg->table->num_virt_rows - 1);
317 VirtualCellLocation vcell_loc,
319 gboolean only_blank_split)
325 vcell_loc.virt_row++;
328 if (cursor_class != CURSOR_CLASS_SPLIT)
331 if (only_blank_split && gnc_split_register_get_split (reg, vcell_loc))
339 gnc_split_register_set_cell_fractions (SplitRegister *reg, Split *split)
344 gnc_commodity *trans_currency;
347 gboolean trading_accts;
348 gnc_commodity *commodity;
356 split_account = gnc_split_register_get_account (reg, XFRM_CELL);
360 reg_account = gnc_split_register_get_default_account (reg);
379 if (reg->type == STOCK_REGISTER ||
380 reg->type == CURRENCY_REGISTER ||
381 reg->type == PORTFOLIO_LEDGER)
385 commodity = trans_currency;
386 else if (trading_accts &&
388 commodity = trans_currency;
390 commodity = trans_currency;
402 if (reg->type == STOCK_REGISTER ||
403 reg->type == CURRENCY_REGISTER ||
404 reg->type == PORTFOLIO_LEDGER)
405 commodity = trans_currency;
414 cell = (
PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
418 cell = (
PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
422 cell = (
PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
433 gnc_split_register_get_passive_cursor (SplitRegister *reg)
435 const char *cursor_name = NULL;
439 case REG_STYLE_LEDGER:
440 case REG_STYLE_AUTO_LEDGER:
441 cursor_name = reg->use_double_line ?
442 (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_LEDGER
443 : CURSOR_DOUBLE_LEDGER_NUM_ACTN)
444 : CURSOR_SINGLE_LEDGER;
447 case REG_STYLE_JOURNAL:
448 cursor_name = reg->use_double_line ?
449 (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_JOURNAL
450 : CURSOR_DOUBLE_JOURNAL_NUM_ACTN)
451 : CURSOR_SINGLE_JOURNAL;
457 PWARN (
"bad register style");
461 return gnc_table_layout_get_cursor (reg->table->layout, cursor_name);
465 gnc_split_register_get_active_cursor (SplitRegister *reg)
467 SRInfo *info = gnc_split_register_get_info (reg);
468 const char *cursor_name = NULL;
472 case REG_STYLE_LEDGER:
473 if (!info->trans_expanded)
475 cursor_name = reg->use_double_line ?
476 (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_LEDGER
477 : CURSOR_DOUBLE_LEDGER_NUM_ACTN)
478 : CURSOR_SINGLE_LEDGER;
483 case REG_STYLE_AUTO_LEDGER:
484 case REG_STYLE_JOURNAL:
485 cursor_name = reg->use_double_line ?
486 (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_JOURNAL
487 : CURSOR_DOUBLE_JOURNAL_NUM_ACTN)
488 : CURSOR_SINGLE_JOURNAL;
494 PWARN (
"bad register style");
498 return gnc_table_layout_get_cursor (reg->table->layout, cursor_name);
502 gnc_split_register_set_last_num (SplitRegister *reg,
const char *num)
506 account = gnc_split_register_get_default_account (reg);
514 gnc_split_register_cursor_class (SplitRegister *reg,
518 return CURSOR_CLASS_NONE;
520 return gnc_split_register_cursor_name_to_class (cursor->cursor_name);
525 VirtualCellLocation vcell_loc)
531 return CURSOR_CLASS_NONE;
535 return CURSOR_CLASS_NONE;
539 return CURSOR_CLASS_NONE;
541 return gnc_split_register_cursor_class (reg, vcell->cellblock);
550 return CURSOR_CLASS_NONE;
554 return CURSOR_CLASS_NONE;
556 return gnc_split_register_cursor_class (reg,
table->current_cursor);
560 gnc_split_register_cursor_name_to_class (
const char *cursor_name)
562 if (cursor_name == NULL)
563 return CURSOR_CLASS_NONE;
565 if (strcmp (cursor_name, CURSOR_SINGLE_LEDGER) == 0 ||
566 strcmp (cursor_name, CURSOR_DOUBLE_LEDGER) == 0 ||
567 strcmp (cursor_name, CURSOR_DOUBLE_LEDGER_NUM_ACTN) == 0 ||
568 strcmp (cursor_name, CURSOR_SINGLE_JOURNAL) == 0 ||
569 strcmp (cursor_name, CURSOR_DOUBLE_JOURNAL) == 0 ||
570 strcmp (cursor_name, CURSOR_DOUBLE_JOURNAL_NUM_ACTN) == 0)
571 return CURSOR_CLASS_TRANS;
573 if (strcmp (cursor_name, CURSOR_SPLIT) == 0)
574 return CURSOR_CLASS_SPLIT;
576 return CURSOR_CLASS_NONE;
CursorClass gnc_split_register_get_current_cursor_class(SplitRegister *reg)
Returns the class of a register's current cursor.
Split * gnc_split_register_get_current_trans_split(SplitRegister *reg, VirtualCellLocation *trans_split_loc)
Gets the anchoring split of the transaction at the current cursor location, which may be on the trans...
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
Determine whether this transaction should use commodity trading accounts.
Date and Time handling routines.
#define GNC_COMMODITY_MAX_FRACTION
Max fraction is 10^9 because 10^10 would require changing it to an int64_t.
gboolean xaccAccountIsPriced(const Account *acc)
Returns true if the account is a stock, mutual fund or currency, otherwise false. ...
void gnc_split_register_set_trans_visible(SplitRegister *reg, VirtualCellLocation vcell_loc, gboolean visible, gboolean only_blank_split)
Set the visibility of the split rows belonging to a transaction located at vcell_loc.
gpointer gnc_table_get_vcell_data(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell data associated with a cursor located at the given virtual coords...
void gnc_table_set_virt_cell_visible(Table *table, VirtualCellLocation vcell_loc, gboolean visible)
Set the visibility flag for a particular location.
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
holds information about each virtual cell.
CursorClass gnc_split_register_get_cursor_class(SplitRegister *reg, VirtualCellLocation vcell_loc)
Returns the class of the cursor at the given virtual cell location.
void gnc_split_register_set_template_account(SplitRegister *reg, Account *template_account)
Set the template account for use in a template register.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
#define PERR(format, args...)
Log a serious error.
void xaccAccountSetLastNum(Account *acc, const char *num)
Set the last num field of an Account.
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
#define PWARN(format, args...)
Log a warning.
#define xaccAccountGetGUID(X)
Split * xaccSplitLookup(const GncGUID *guid, QofBook *book)
The xaccSplitLookup() subroutine will return the split associated with the given id, or NULL if there is no such split.
CursorClass
Types of cursors.
The PriceCell object implements a cell handler that stores a single double-precision value...
void gnc_table_show_range(Table *table, VirtualCellLocation start_loc, VirtualCellLocation end_loc)
Try to show the whole range in the register.
VirtualCell * gnc_table_get_virtual_cell(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell associated with a particular virtual location.
private declarations for SplitRegister
time64 gnc_time64_get_today_start(void)
The gnc_time64_get_today_start() routine returns a time64 value corresponding to the first second of ...
void gnc_price_cell_set_fraction(PriceCell *cell, int fraction)
Sets the fraction used for rounding.
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
The type used to store guids in C.
gboolean qof_book_use_trading_accounts(const QofBook *book)
Returns flag indicating whether this book uses trading accounts.
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id...