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->quickfill_setup = FALSE;
59 info->full_refresh = TRUE;
60 info->separator_changed = TRUE;
66 gnc_split_register_get_info (SplitRegister *reg)
71 if (reg->sr_info == NULL)
72 gnc_split_register_init_info (reg);
78 gnc_split_register_get_parent (SplitRegister *reg)
80 SRInfo *info = gnc_split_register_get_info (reg);
85 if (info->get_parent == NULL)
88 return info->get_parent (info->user_data);
92 gnc_split_register_get_split (SplitRegister *reg,
93 VirtualCellLocation vcell_loc)
108 gnc_split_register_get_default_account (SplitRegister *reg)
110 SRInfo *info = gnc_split_register_get_info (reg);
113 gnc_get_current_book ());
120 SRInfo *info = gnc_split_register_get_info (reg);
122 g_return_if_fail (reg != NULL);
128 gnc_split_register_get_trans (SplitRegister *reg,
129 VirtualCellLocation vcell_loc)
133 if (!reg || !reg->table)
136 split = gnc_split_register_get_split (reg, vcell_loc);
143 vcell_loc.virt_row--;
145 split = gnc_split_register_get_split (reg, vcell_loc);
155 gnc_split_register_get_trans_split (SplitRegister *reg,
156 VirtualCellLocation vcell_loc,
157 VirtualCellLocation *trans_split_loc)
166 if ((0 > vcell_loc.virt_row) || (0 > vcell_loc.virt_col))
174 if (cursor_class == CURSOR_CLASS_TRANS)
177 *trans_split_loc = vcell_loc;
179 return gnc_split_register_get_split (reg, vcell_loc);
182 vcell_loc.virt_row--;
188 SplitRegister *reg, VirtualCellLocation *trans_split_loc)
190 VirtualCellLocation vcell_loc;
195 vcell_loc = reg->table->current_cursor_loc.vcell_loc;
197 return gnc_split_register_get_trans_split (reg, vcell_loc, trans_split_loc);
201 gnc_split_register_find_split (SplitRegister *reg,
202 Transaction *trans, Split *trans_split,
204 VirtualCellLocation *vcell_loc)
206 Table *
table = reg->table;
207 gboolean found_trans = FALSE;
208 gboolean found_trans_split = FALSE;
209 gboolean found_something = FALSE;
215 for (v_row = 1; v_row <
table->num_virt_rows; v_row++)
216 for (v_col = 0; v_col <
table->num_virt_cols; v_col++)
218 VirtualCellLocation vc_loc = { v_row, v_col };
220 s = gnc_split_register_get_split (reg, vc_loc);
230 if (cursor_class == CURSOR_CLASS_TRANS)
233 if (s == trans_split)
235 found_trans_split = TRUE;
237 found_trans_split = FALSE;
239 if (find_class == CURSOR_CLASS_TRANS &&
240 (s == split || reg->style == REG_STYLE_JOURNAL))
245 if (vcell_loc != NULL)
256 found_trans_split = FALSE;
259 if (found_trans && (s == split) && s)
263 if (vcell_loc != NULL)
266 found_something = TRUE;
269 if (found_trans_split && (s == split))
274 if (vcell_loc != NULL)
277 if (cursor_class == find_class)
282 return found_something;
286 gnc_split_register_show_trans (SplitRegister *reg,
287 VirtualCellLocation start_loc)
289 VirtualCellLocation end_loc;
294 for (v_row = end_loc.virt_row + 1;
295 v_row < reg->
table->num_virt_rows; v_row++)
297 VirtualCellLocation vc_loc = { v_row, 0 };
301 if (cursor_class == CURSOR_CLASS_TRANS)
304 if (cursor_class != CURSOR_CLASS_SPLIT)
311 end_loc.virt_row = MIN (v_row, reg->table->num_virt_rows - 1);
318 VirtualCellLocation vcell_loc,
320 gboolean only_blank_split)
326 vcell_loc.virt_row++;
329 if (cursor_class != CURSOR_CLASS_SPLIT)
332 if (only_blank_split && gnc_split_register_get_split (reg, vcell_loc))
340 gnc_split_register_set_cell_fractions (SplitRegister *reg, Split *split)
345 gnc_commodity *trans_currency;
348 gboolean trading_accts;
349 gnc_commodity *commodity;
357 split_account = gnc_split_register_get_account (reg, XFRM_CELL);
361 reg_account = gnc_split_register_get_default_account (reg);
380 if (reg->type == STOCK_REGISTER ||
381 reg->type == CURRENCY_REGISTER ||
382 reg->type == PORTFOLIO_LEDGER)
386 commodity = trans_currency;
387 else if (trading_accts &&
389 commodity = trans_currency;
391 commodity = trans_currency;
403 if (reg->type == STOCK_REGISTER ||
404 reg->type == CURRENCY_REGISTER ||
405 reg->type == PORTFOLIO_LEDGER)
406 commodity = trans_currency;
415 cell = (
PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
419 cell = (
PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
423 cell = (
PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
434 gnc_split_register_get_passive_cursor (SplitRegister *reg)
436 const char *cursor_name = NULL;
440 case REG_STYLE_LEDGER:
441 case REG_STYLE_AUTO_LEDGER:
442 cursor_name = reg->use_double_line ?
443 (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_LEDGER
444 : CURSOR_DOUBLE_LEDGER_NUM_ACTN)
445 : CURSOR_SINGLE_LEDGER;
448 case REG_STYLE_JOURNAL:
449 cursor_name = reg->use_double_line ?
450 (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_JOURNAL
451 : CURSOR_DOUBLE_JOURNAL_NUM_ACTN)
452 : CURSOR_SINGLE_JOURNAL;
458 PWARN (
"bad register style");
462 return gnc_table_layout_get_cursor (reg->table->layout, cursor_name);
466 gnc_split_register_get_active_cursor (SplitRegister *reg)
468 SRInfo *info = gnc_split_register_get_info (reg);
469 const char *cursor_name = NULL;
473 case REG_STYLE_LEDGER:
474 if (!info->trans_expanded)
476 cursor_name = reg->use_double_line ?
477 (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_LEDGER
478 : CURSOR_DOUBLE_LEDGER_NUM_ACTN)
479 : CURSOR_SINGLE_LEDGER;
484 case REG_STYLE_AUTO_LEDGER:
485 case REG_STYLE_JOURNAL:
486 cursor_name = reg->use_double_line ?
487 (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_JOURNAL
488 : CURSOR_DOUBLE_JOURNAL_NUM_ACTN)
489 : CURSOR_SINGLE_JOURNAL;
495 PWARN (
"bad register style");
499 return gnc_table_layout_get_cursor (reg->table->layout, cursor_name);
503 gnc_split_register_set_last_num (SplitRegister *reg,
const char *num)
507 account = gnc_split_register_get_default_account (reg);
515 gnc_split_register_cursor_class (SplitRegister *reg,
519 return CURSOR_CLASS_NONE;
521 return gnc_split_register_cursor_name_to_class (cursor->cursor_name);
526 VirtualCellLocation vcell_loc)
532 return CURSOR_CLASS_NONE;
536 return CURSOR_CLASS_NONE;
540 return CURSOR_CLASS_NONE;
542 return gnc_split_register_cursor_class (reg, vcell->cellblock);
551 return CURSOR_CLASS_NONE;
555 return CURSOR_CLASS_NONE;
557 return gnc_split_register_cursor_class (reg,
table->current_cursor);
561 gnc_split_register_cursor_name_to_class (
const char *cursor_name)
563 if (cursor_name == NULL)
564 return CURSOR_CLASS_NONE;
566 if (strcmp (cursor_name, CURSOR_SINGLE_LEDGER) == 0 ||
567 strcmp (cursor_name, CURSOR_DOUBLE_LEDGER) == 0 ||
568 strcmp (cursor_name, CURSOR_DOUBLE_LEDGER_NUM_ACTN) == 0 ||
569 strcmp (cursor_name, CURSOR_SINGLE_JOURNAL) == 0 ||
570 strcmp (cursor_name, CURSOR_DOUBLE_JOURNAL) == 0 ||
571 strcmp (cursor_name, CURSOR_DOUBLE_JOURNAL_NUM_ACTN) == 0)
572 return CURSOR_CLASS_TRANS;
574 if (strcmp (cursor_name, CURSOR_SPLIT) == 0)
575 return CURSOR_CLASS_SPLIT;
577 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...