27 #include <glib/gi18n.h> 31 #include "gnc-component-manager.h" 34 #include "gnc-warnings.h" 37 #include "dialog-transfer.h" 38 #include "dialog-utils.h" 44 #include "engine-helpers.h" 48 static QofLogModule log_module = GNC_MOD_LEDGER;
52 gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans)
59 GList *radio_list = NULL;
60 const char *title = _(
"Rebalance Transaction");
61 const char *message = _(
"The current transaction is not balanced.");
64 gboolean two_accounts;
65 gboolean multi_currency;
73 MonetaryList *imbal_list;
74 gnc_monetary *imbal_mon;
82 multi_currency = TRUE;
85 imbal_mon =
static_cast<gnc_monetary*
>(imbal_list->data);
86 if (!imbal_list->next &&
89 multi_currency = FALSE;
91 multi_currency = TRUE;
99 multi_currency = FALSE;
104 if (other_split == NULL)
111 if (other_split == NULL || multi_currency)
113 two_accounts = FALSE;
114 other_account = NULL;
122 default_account = gnc_split_register_get_default_account (reg);
128 if (default_account == other_account)
135 if (default_account == other_account)
136 two_accounts = FALSE;
138 radio_list = g_list_append (radio_list,
139 _(
"Balance it _manually"));
140 radio_list = g_list_append (radio_list,
141 _(
"Let GnuCash _add an adjusting split"));
143 if (reg->type < NUM_SINGLE_REGISTER_TYPES && !multi_currency)
145 radio_list = g_list_append (radio_list,
146 _(
"Adjust current account _split total"));
151 radio_list = g_list_append (radio_list,
152 _(
"Adjust _other account split total"));
159 choice = gnc_choose_radio_option_dialog
160 (gnc_split_register_get_parent (reg),
167 g_list_free (radio_list);
193 gnc_split_register_old_split_empty_p (SplitRegister *reg, Split *split)
199 string = gnc_table_layout_get_cell_value (reg->table->layout, MEMO_CELL);
200 if ((
string != NULL) && (*
string !=
'\0'))
203 string = gnc_table_layout_get_cell_value (reg->table->layout, XFRM_CELL);
204 if ((
string != NULL) && (*
string !=
'\0'))
207 cell = gnc_table_layout_get_cell (reg->table->layout, CRED_CELL);
215 cell = gnc_table_layout_get_cell (reg->table->layout, DEBT_CELL);
230 gnc_split_register_check_debcred (SplitRegister *reg,
231 const char *cell_name)
233 if ((gnc_cell_name_equal (cell_name, DEBT_CELL) &&
234 gnc_table_layout_get_cell_changed (reg->table->layout,
235 DEBT_CELL, FALSE)) ||
236 (gnc_cell_name_equal (cell_name, CRED_CELL) &&
237 gnc_table_layout_get_cell_changed (reg->table->layout,
240 SRInfo *info = gnc_split_register_get_info (reg);
246 info->rate_reset = RATE_RESET_REQD;
247 if (info->auto_complete)
262 gnc_split_register_check_account (SplitRegister *reg,
263 const char *cell_name)
271 g_return_val_if_fail(reg, TRUE);
274 if (gnc_cell_name_equal (cell_name, XFRM_CELL))
276 if (gnc_table_layout_get_cell_changed (reg->table->layout,
278 cell = (
ComboCell *) gnc_table_layout_get_cell (reg->table->layout,
281 else if (gnc_cell_name_equal (cell_name, MXFRM_CELL))
283 if (gnc_table_layout_get_cell_changed (reg->table->layout,
285 cell = (
ComboCell *) gnc_table_layout_get_cell (reg->table->layout,
293 name = cell->cell.value;
294 DEBUG(
"Changed to %s", name ? name :
"NULL");
295 if (!name || *name ==
'\0' ||
296 g_strcmp0 (name, SPLIT_TRANS_STR) == 0 ||
297 g_strcmp0 (name, STOCK_SPLIT_STR) == 0)
301 info = gnc_split_register_get_info (reg);
302 new_acct = gnc_split_register_get_account_by_name (reg,
309 gnc_split_register_set_cell_fractions (reg, split);
323 DEBUG(
"Commodity is still %s. Leaving rate unchanged.",
329 DEBUG(
"Commodity now %s (originally %s). Clearing rate.",
334 info->rate_account = new_acct;
335 info->rate_reset = RATE_RESET_REQD;
347 DEBUG(
"Using original rate of %s.",
350 info->rate_account = new_acct;
351 info->rate_reset = RATE_RESET_NOT_REQD;
355 DEBUG(
"Can't get rate. Using zero.");
357 info->rate_account = new_acct;
358 info->rate_reset = RATE_RESET_REQD;
367 gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
370 VirtualLocation new_virt_loc = *p_new_virt_loc;
371 VirtualCellLocation old_trans_split_loc;
372 auto reg =
static_cast<SplitRegister*
>(user_data);
373 Transaction *pending_trans;
374 Transaction *new_trans;
375 Transaction *old_trans;
376 Split *old_trans_split;
377 Split *new_trans_split;
382 gboolean exact_traversal;
387 ENTER(
"reg=%p, p_new_virt_loc=%p (%d, %d)",
389 new_virt_loc.vcell_loc.virt_row,
390 new_virt_loc.vcell_loc.virt_col);
394 LEAVE(
"no register");
398 info = gnc_split_register_get_info (reg);
407 exact_traversal = info->exact_traversal;
409 if (info->traverse_to_new)
411 if (old_class == CURSOR_CLASS_SPLIT)
412 new_trans = old_trans;
417 new_trans_split = NULL;
418 new_class = CURSOR_CLASS_NONE;
420 else if (!info->hint_set_by_traverse)
423 new_trans = gnc_split_register_get_trans (reg, new_virt_loc.vcell_loc);
426 new_split = gnc_split_register_get_split (reg, new_virt_loc.vcell_loc);
429 new_trans_split = gnc_split_register_get_trans_split
430 (reg, new_virt_loc.vcell_loc, NULL);
433 new_virt_loc.vcell_loc);
437 new_trans = info->cursor_hint_trans;
438 new_split = info->cursor_hint_split;
439 new_trans_split = info->cursor_hint_trans_split;
440 new_class = info->cursor_hint_cursor_class;
443 info->hint_set_by_traverse = FALSE;
444 info->reg_loaded = FALSE;
446 gnc_suspend_gui_refresh ();
451 gnc_get_current_book ());
453 gnc_get_current_book ());
456 if ((old_class == CURSOR_CLASS_SPLIT) &&
458 (old_split != new_split) &&
459 gnc_split_register_old_split_empty_p(reg, old_split))
472 current_row = reg->table->current_cursor_loc.vcell_loc.virt_row;
473 if (new_virt_loc.vcell_loc.virt_row > current_row)
474 new_virt_loc.vcell_loc.virt_row--;
477 else if ((pending_trans != NULL) &&
478 (pending_trans == old_trans) &&
479 (pending_trans != blank_trans) &&
480 (old_trans != new_trans))
482 if (gnc_split_register_balance_trans (reg, pending_trans))
485 new_trans = old_trans;
486 new_split = old_split;
487 new_trans_split = old_trans_split;
488 new_class = old_class;
489 new_virt_loc = reg->table->current_cursor_loc;
494 info->pending_trans_guid = *
guid_null ();
497 else g_assert_not_reached();
499 pending_trans = NULL;
503 else if (old_trans &&
504 (old_trans != new_trans) &&
507 gnc_split_register_balance_trans (reg, old_trans))
510 new_trans = old_trans;
511 new_split = old_split;
512 new_trans_split = old_trans_split;
513 new_class = old_class;
514 new_virt_loc = reg->table->current_cursor_loc;
519 info->cursor_hint_trans = new_trans;
520 info->cursor_hint_split = new_split;
521 info->cursor_hint_trans_split = new_trans_split;
522 info->cursor_hint_cursor_class = new_class;
526 if (old_class != new_class)
527 info->change_confirmed = FALSE;
529 if (old_split != new_split)
531 info->change_confirmed = FALSE;
532 info->rate_account = NULL;
533 info->rate_reset = RATE_RESET_NOT_REQD;
536 gnc_resume_gui_refresh ();
541 VirtualCellLocation vcell_loc;
543 if (!info->reg_loaded)
548 if (gnc_split_register_find_split (reg, new_trans, new_trans_split,
549 new_split, new_class, &vcell_loc))
552 new_virt_loc.vcell_loc = vcell_loc;
555 new_virt_loc.vcell_loc = reg->table->current_cursor_loc.vcell_loc;
557 new_trans = gnc_split_register_get_trans (reg, new_virt_loc.vcell_loc);
558 new_split = gnc_split_register_get_split (reg, new_virt_loc.vcell_loc);
559 new_trans_split = gnc_split_register_get_trans_split(
560 reg, new_virt_loc.vcell_loc, NULL);
562 new_virt_loc.vcell_loc);
564 else if (info->traverse_to_new)
566 new_trans = info->cursor_hint_trans;
567 new_split = info->cursor_hint_split;
568 new_trans_split = info->cursor_hint_trans_split;
569 new_class = info->cursor_hint_cursor_class;
574 *p_new_virt_loc = new_virt_loc;
576 PINFO (
"after move %d %d\n",
577 new_virt_loc.vcell_loc.virt_row,
578 new_virt_loc.vcell_loc.virt_col);
584 gnc_split_register_set_cell_fractions (reg, new_split);
593 (old_trans_split != new_trans_split))
595 VirtualCellLocation vc_loc;
597 vc_loc = old_trans_split_loc;
599 reg->table, vc_loc, gnc_split_register_get_passive_cursor (reg));
601 reg->style == REG_STYLE_JOURNAL);
603 if ((REG_STYLE_AUTO_LEDGER == reg->style) ||
604 (REG_STYLE_JOURNAL == reg->style))
606 gnc_split_register_get_trans_split (reg, new_virt_loc.vcell_loc,
609 (reg->table, vc_loc, gnc_split_register_get_active_cursor (reg));
611 reg->style == REG_STYLE_JOURNAL);
614 info->trans_expanded = FALSE;
621 info->cursor_hint_trans = new_trans;
622 info->cursor_hint_split = new_split;
623 info->cursor_hint_trans_split = new_trans_split;
624 info->cursor_hint_cursor_class = new_class;
626 gnc_split_register_set_cell_fractions (reg, new_split);
633 VirtualCellLocation vc_loc;
636 gnc_table_leave_update (reg->table, reg->table->current_cursor_loc);
638 gnc_split_register_get_trans_split (reg, p_new_virt_loc->vcell_loc,
640 gnc_split_register_show_trans (reg, vc_loc);
647 gnc_find_split_in_trans_by_memo (Transaction *trans,
const char *memo,
652 auto split = GNC_SPLIT(n->data);
668 gnc_find_split_in_account_by_memo (
Account *account,
const char *memo,
671 if (account == NULL)
return NULL;
675 for (
auto slp = g_list_last (splits); !rv && slp; slp = slp->prev)
677 auto split = GNC_SPLIT(slp->data);
680 split = gnc_find_split_in_trans_by_memo (trans, memo, unit_price);
686 g_list_free (splits);
691 gnc_find_split_in_reg_by_memo (SplitRegister *reg,
const char *memo,
694 int virt_row, virt_col;
695 int num_rows, num_cols;
696 Transaction *last_trans;
698 if (!reg || !reg->table)
701 num_rows = reg->table->num_virt_rows;
702 num_cols = reg->table->num_virt_cols;
706 for (virt_row = num_rows - 1; virt_row >= 0; virt_row--)
707 for (virt_col = num_cols - 1; virt_col >= 0; virt_col--)
711 VirtualCellLocation vcell_loc = { virt_row, virt_col };
713 split = gnc_split_register_get_split (reg, vcell_loc);
716 if (trans == last_trans)
719 split = gnc_find_split_in_trans_by_memo (trans, memo, unit_price);
730 gnc_find_trans_in_reg_by_desc (SplitRegister *reg,
const char *description)
732 int virt_row, virt_col;
733 int num_rows, num_cols;
734 Transaction *last_trans;
736 if (!reg || !reg->table)
739 num_rows = reg->table->num_virt_rows;
740 num_cols = reg->table->num_virt_cols;
744 for (virt_row = num_rows - 1; virt_row >= 0; virt_row--)
745 for (virt_col = num_cols - 1; virt_col >= 0; virt_col--)
749 VirtualCellLocation vcell_loc = { virt_row, virt_col };
751 split = gnc_split_register_get_split (reg, vcell_loc);
754 if (trans == last_trans)
769 gnc_split_register_auto_completion (SplitRegister *reg,
770 gncTableTraversalDir dir,
771 VirtualLocation *p_new_virt_loc)
773 SRInfo *info = gnc_split_register_get_info (reg);
774 VirtualLocation new_virt_loc;
776 Transaction *pending_trans;
777 Transaction *blank_trans;
778 const char *cell_name;
785 if (!reg->do_auto_complete)
789 gnc_get_current_book ());
793 gnc_get_current_book ());
796 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
805 cell_name = gnc_table_get_current_cell_name (reg->table);
807 switch (cursor_class)
809 case CURSOR_CLASS_TRANS:
811 Transaction *auto_trans;
815 if (blank_trans == NULL)
819 if (trans != blank_trans)
823 if (!gnc_cell_name_equal (cell_name, DESC_CELL))
828 if (gnc_table_layout_get_cell_changed (reg->table->layout,
830 gnc_table_layout_get_cell_changed (reg->table->layout,
832 gnc_table_layout_get_cell_changed (reg->table->layout,
834 gnc_table_layout_get_cell_changed (reg->table->layout,
836 gnc_table_layout_get_cell_changed (reg->table->layout,
838 gnc_table_layout_get_cell_changed (reg->table->layout,
840 gnc_table_layout_get_cell_changed (reg->table->layout,
842 gnc_table_layout_get_cell_changed (reg->table->layout,
847 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
852 desc = gnc_table_layout_get_cell_value (reg->table->layout, DESC_CELL);
853 if ((desc == NULL) || (*desc ==
'\0'))
857 if (gnc_split_register_get_default_account (reg) != NULL)
859 Account *account = gnc_split_register_get_default_account (reg);
864 auto_trans = gnc_find_trans_in_reg_by_desc(reg, desc);
866 if (auto_trans == NULL)
869 gnc_suspend_gui_refresh ();
875 if (pending_trans != trans)
881 if (pending_trans != NULL)
885 else g_assert_not_reached();
890 gnc_get_current_book ());
891 g_assert(pending_trans == trans);
899 if (gnc_split_register_get_default_account (reg) != NULL)
902 gnc_split_register_get_default_account (reg);
911 auto s = GNC_SPLIT(n->data);
921 if (blank_split == NULL)
926 DEBUG(
"blank_split=%p", blank_split);
928 info->blank_split_edited = TRUE;
933 sd = gnc_split_register_save_data_new(
935 gnc_table_save_cells (reg->table, sd);
936 gnc_split_register_save_data_destroy (sd);
939 gnc_resume_gui_refresh ();
943 GNC_PREF_TAB_TRANS_MEMORISED) )
948 if (gnc_table_get_current_cell_location (reg->table, cell_name,
950 *p_new_virt_loc = new_virt_loc;
956 case CURSOR_CLASS_SPLIT:
968 if (!gnc_cell_name_equal (cell_name, MEMO_CELL))
973 if (gnc_table_layout_get_cell_changed (reg->table->layout,
975 gnc_table_layout_get_cell_changed (reg->table->layout,
977 gnc_table_layout_get_cell_changed (reg->table->layout,
979 gnc_table_layout_get_cell_changed (reg->table->layout,
981 gnc_table_layout_get_cell_changed (reg->table->layout,
986 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
991 memo = gnc_table_layout_get_cell_value (reg->table->layout, MEMO_CELL);
992 if ((memo == NULL) || (*memo ==
'\0'))
997 unit_price = !gnc_table_get_current_cell_location (reg->table,
1001 if (gnc_split_register_get_default_account (reg) != NULL)
1003 Account *account = gnc_split_register_get_default_account (reg);
1005 auto_split = gnc_find_split_in_account_by_memo (account, memo,
1009 auto_split = gnc_find_split_in_reg_by_memo (reg, memo, unit_price);
1011 if (auto_split == NULL)
1017 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1020 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1021 gnc_combo_cell_set_value ((
ComboCell *) cell,
1022 gnc_get_num_action (NULL, auto_split));
1026 cell = gnc_table_layout_get_cell (reg->table->layout, XFRM_CELL);
1029 reg->show_leaf_accounts);
1030 gnc_combo_cell_set_value ((
ComboCell *) cell, account_name);
1031 g_free(account_name);
1033 gnc_basic_cell_set_changed (cell, TRUE);
1035 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1037 !gnc_table_layout_get_cell_changed (reg->table->layout,
1040 BasicCell *debit_cell;
1041 BasicCell *credit_cell;
1045 debit_cell = gnc_table_layout_get_cell (reg->table->layout,
1047 credit_cell = gnc_table_layout_get_cell (reg->table->layout,
1054 gnc_basic_cell_set_changed (debit_cell, TRUE);
1055 gnc_basic_cell_set_changed (credit_cell, TRUE);
1065 if (gnc_table_get_current_cell_location (reg->table, cell_name,
1067 *p_new_virt_loc = new_virt_loc;
1080 gnc_split_register_check_stock_action (SplitRegister *reg,
1081 const char *cell_name)
1088 if (!gnc_cell_name_equal (cell_name, ACTN_CELL) ||
1089 !gnc_table_layout_get_cell_changed (reg->table->layout,
1093 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1097 if ((name == NULL) || (*name ==
'\0'))
1100 buy = g_strcmp0 (name, ACTION_BUY_STR) == 0;
1101 sell = g_strcmp0 (name, ACTION_SELL_STR) == 0;
1105 cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
1114 gnc_basic_cell_set_changed (cell, TRUE);
1119 gnc_split_register_check_stock_shares (SplitRegister *reg,
1120 const char *cell_name)
1127 if (!gnc_cell_name_equal (cell_name, SHRS_CELL) ||
1128 !gnc_table_layout_get_cell_changed (reg->table->layout,
1132 cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
1140 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1145 if (!g_strcmp0(name,
"") ||
1146 !g_strcmp0(name, buy ? ACTION_SELL_STR : ACTION_BUY_STR))
1148 gnc_combo_cell_set_value((
ComboCell *)cell,
1149 buy ? ACTION_BUY_STR : ACTION_SELL_STR);
1150 gnc_basic_cell_set_changed (cell, TRUE);
1160 gnc_split_register_check_cell (SplitRegister *reg,
const char *cell_name)
1162 ENTER(
"reg=%p, cell_name=%s", reg, cell_name ? cell_name :
"NULL");
1165 if (!gnc_split_register_check_account (reg, cell_name))
1167 LEAVE(
"account check failed");
1172 if (!gnc_split_register_check_debcred (reg, cell_name))
1174 LEAVE(
"debit/credit check failed");
1179 if ((reg->type == STOCK_REGISTER) ||
1180 (reg->type == PORTFOLIO_LEDGER) ||
1181 (reg->type == CURRENCY_REGISTER))
1183 gnc_split_register_check_stock_action (reg, cell_name);
1184 gnc_split_register_check_stock_shares (reg, cell_name);
1192 gnc_split_register_get_account_always (SplitRegister *reg,
1193 const char * cell_name)
1198 cell = gnc_table_layout_get_cell (reg->table->layout, cell_name);
1201 name = gnc_basic_cell_get_value (cell);
1205 if (!g_strcmp0 (name, SPLIT_TRANS_STR))
1210 return gnc_split_register_get_account_by_name (reg, cell, name);
1217 gnc_split_register_xfer_dialog(SplitRegister *reg, Transaction *txn,
1224 g_return_val_if_fail(reg, NULL);
1225 g_return_val_if_fail(reg->table, NULL);
1226 cur = reg->table->current_cursor;
1229 xfer = gnc_xfer_dialog(gnc_split_register_get_parent (reg), NULL);
1230 g_return_val_if_fail(xfer, NULL);
1235 gnc_xfer_dialog_set_description(xfer, gnc_basic_cell_get_value(cell));
1239 gnc_xfer_dialog_set_description(xfer, str ? str :
"");
1245 gnc_xfer_dialog_set_memo(xfer, gnc_basic_cell_get_value(cell));
1249 gnc_xfer_dialog_set_memo(xfer, str ? str :
"");
1255 gnc_xfer_dialog_set_num(xfer, gnc_basic_cell_get_value(cell));
1258 const char *str = gnc_get_num_action (txn, split);
1259 gnc_xfer_dialog_set_num(xfer, str ? str :
"");
1268 gnc_xfer_dialog_set_date(xfer, time);
1289 Split *split, *osplit;
1291 gnc_commodity *txn_cur, *xfer_com, *reg_com;
1292 gnc_numeric amount, exch_rate;
1294 gboolean expanded = FALSE;
1296 const char *message;
1299 ENTER(
"reg=%p, force_dialog=%s", reg, force_dialog ?
"TRUE" :
"FALSE" );
1302 if (reg->is_template)
1304 LEAVE(
"Template transaction, rate makes no sense.");
1313 message = _(
"This register does not support editing exchange rates.");
1314 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1316 LEAVE(
"no rate cell");
1320 rate_cell = (
PriceCell*) gnc_table_layout_get_cell(
1321 reg->table->layout, RATE_CELL);
1326 message = _(
"This register does not support editing exchange rates.");
1327 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1329 LEAVE(
"null rate cell");
1334 info = gnc_split_register_get_info (reg);
1337 info->rate_reset != RATE_RESET_REQD)
1339 LEAVE(
"rate already non-zero");
1348 if (expanded && cursor_class == CURSOR_CLASS_TRANS)
1352 message = _(
"You need to select a split in order to modify its exchange " 1354 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1356 LEAVE(
"expanded with transaction cursor; nothing to do");
1361 xfer_acc = gnc_split_register_get_account_always(
1362 reg, expanded ? XFRM_CELL : MXFRM_CELL);
1365 if (force_dialog && !expanded && !xfer_acc)
1367 message = _(
"You need to expand the transaction in order to modify its " 1369 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1370 LEAVE(
"%s", message);
1379 message = _(
"The entered account could not be found.");
1380 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1382 LEAVE(
"no xfer account");
1392 reg_acc = gnc_split_register_get_default_account (reg);
1407 LEAVE(
"txn and account currencies match, and not forcing");
1412 if (expanded || osplit == NULL)
1414 message = _(
"The two currencies involved equal each other.");
1415 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1416 LEAVE(
"register is expanded or osplit == NULL; not forcing dialog");
1427 message = _(
"The two currencies involved equal each other.");
1428 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1429 LEAVE(
"reg commodity == txn commodity; not forcing");
1438 if (!expanded && osplit &&
1439 gnc_split_register_split_needs_amount (reg, split) &&
1440 gnc_split_register_split_needs_amount (reg, osplit))
1442 message = _(
"You need to expand the transaction in order to modify its " 1446 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1448 LEAVE(
"%s", message);
1468 amount = gnc_split_register_debcred_cell_value (reg);
1478 message = _(
"The split's amount is zero, so no exchange rate is needed.");
1479 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1481 LEAVE(
"amount is zero; no exchange rate needed");
1490 info->rate_reset != RATE_RESET_REQD &&
1493 LEAVE(
"gain/loss split; no exchange rate needed");
1498 xfer = gnc_split_register_xfer_dialog(reg, txn, split);
1499 gnc_xfer_dialog_is_exchange_dialog(xfer, &exch_rate);
1500 if (gnc_xfer_dialog_run_exchange_dialog(
1501 xfer, &exch_rate, amount, reg_acc, txn, xfer_com, expanded))
1504 LEAVE(
"leaving rate unchanged");
1511 gnc_basic_cell_set_changed (&rate_cell->cell, TRUE);
1512 info->rate_account = xfer_acc;
1513 info->rate_reset = RATE_RESET_DONE;
1520 transaction_changed_confirm(VirtualLocation *p_new_virt_loc,
1521 VirtualLocation *virt_loc,
1522 SplitRegister *reg, Transaction *new_trans,
1523 gboolean exact_traversal)
1525 GtkWidget *dialog, *window;
1527 const char *title = _(
"Save the changed transaction?");
1528 const char *message =
1529 _(
"The current transaction has been changed. Would you like to " 1530 "record the changes before moving to a new transaction, discard the " 1531 "changes, or return to the changed transaction?");
1533 window = gnc_split_register_get_parent(reg);
1534 dialog = gtk_message_dialog_new(GTK_WINDOW(window),
1535 GTK_DIALOG_DESTROY_WITH_PARENT,
1536 GTK_MESSAGE_QUESTION,
1539 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
1541 gtk_dialog_add_buttons(GTK_DIALOG(dialog),
1542 _(
"_Discard Changes"), GTK_RESPONSE_REJECT,
1543 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
1544 _(
"_Record Changes"), GTK_RESPONSE_ACCEPT,
1546 response = gnc_dialog_run(GTK_DIALOG(dialog), GNC_PREF_WARN_REG_TRANS_MOD);
1547 gtk_widget_destroy(dialog);
1551 case GTK_RESPONSE_ACCEPT:
1554 case GTK_RESPONSE_REJECT:
1556 VirtualCellLocation vcell_loc;
1562 if (reg->unrecn_splits != NULL)
1564 g_list_free (reg->unrecn_splits);
1565 reg->unrecn_splits = NULL;
1568 new_split = gnc_split_register_get_split (reg, virt_loc->vcell_loc);
1569 trans_split = gnc_split_register_get_trans_split (reg,
1570 virt_loc->vcell_loc,
1573 virt_loc->vcell_loc);
1577 if (gnc_split_register_find_split (reg, new_trans, trans_split,
1578 new_split, new_class, &vcell_loc))
1579 virt_loc->vcell_loc = vcell_loc;
1584 *p_new_virt_loc = *virt_loc;
1588 case GTK_RESPONSE_CANCEL:
1609 gnc_split_register_traverse (VirtualLocation *p_new_virt_loc,
1610 gncTableTraversalDir dir,
1613 auto reg =
static_cast<SplitRegister*
>(user_data);
1614 Transaction *pending_trans;
1615 VirtualLocation virt_loc;
1616 Transaction *trans, *new_trans;
1620 const char *cell_name;
1622 g_return_val_if_fail(p_new_virt_loc, TRUE);
1624 ENTER(
"reg=%p, p_new_virt_loc=%p (%d,%d), dir=%d",
1625 reg, p_new_virt_loc, (*p_new_virt_loc).vcell_loc.virt_row,
1626 (*p_new_virt_loc).vcell_loc.virt_col, dir);
1630 LEAVE(
"no register");
1634 info = gnc_split_register_get_info (reg);
1636 if (info->first_pass)
1638 LEAVE(
"first pass");
1643 gnc_get_current_book ());
1644 virt_loc = *p_new_virt_loc;
1646 info->exact_traversal = (dir == GNC_TABLE_TRAVERSE_POINTER);
1652 LEAVE(
"no transaction");
1657 changed = gnc_table_current_cursor_changed (reg->table, FALSE);
1658 if (!changed && (pending_trans != trans))
1661 info->exact_traversal);
1663 *p_new_virt_loc = virt_loc;
1665 LEAVE(
"no changes");
1670 cell_name = gnc_table_get_current_cell_name (reg->table);
1671 if (!gnc_split_register_check_cell (reg, cell_name))
1673 LEAVE(
"check cell");
1680 VirtualLocation virt_loc;
1682 if (!changed && !info->blank_split_edited)
1685 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
1688 virt_loc = reg->table->current_cursor_loc;
1692 virt_loc = reg->table->current_cursor_loc;
1693 if (gnc_table_move_tab (reg->table, &virt_loc, TRUE))
1699 LEAVE(
"no exchange rate");
1703 *p_new_virt_loc = reg->table->current_cursor_loc;
1704 (p_new_virt_loc->vcell_loc.virt_row)++;
1705 p_new_virt_loc->phys_row_offset = 0;
1706 p_new_virt_loc->phys_col_offset = 0;
1708 info->traverse_to_new = TRUE;
1710 LEAVE(
"off end of last line");
1720 if (gnc_split_register_auto_completion (reg, dir, p_new_virt_loc))
1722 info->auto_complete = TRUE;
1723 LEAVE(
"auto-complete");
1731 VirtualLocation virt_loc;
1740 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
1743 virt_loc = reg->table->current_cursor_loc;
1744 old_virt_row = virt_loc.vcell_loc.virt_row;
1746 if (gnc_table_move_tab (reg->table, &virt_loc, TRUE) &&
1747 old_virt_row == virt_loc.vcell_loc.virt_row)
1760 LEAVE(
"no exchange rate");
1764 info->cursor_hint_trans = trans;
1765 info->cursor_hint_split = split;
1766 info->cursor_hint_trans_split =
1768 info->cursor_hint_cursor_class = CURSOR_CLASS_SPLIT;
1769 info->hint_set_by_traverse = TRUE;
1771 LEAVE(
"off end of blank split");
1778 int old_virt_row = reg->table->current_cursor_loc.vcell_loc.virt_row;
1782 info->exact_traversal);
1786 if (virt_loc.vcell_loc.virt_row != old_virt_row)
1790 LEAVE(
"no exchange rate");
1797 new_trans = gnc_split_register_get_trans (reg, virt_loc.vcell_loc);
1798 if (trans == new_trans)
1800 *p_new_virt_loc = virt_loc;
1802 LEAVE(
"staying within txn");
1809 LEAVE(
"txn change");
1810 return transaction_changed_confirm(p_new_virt_loc, &virt_loc, reg,
1811 new_trans, info->exact_traversal);
1819 control->move_cursor = gnc_split_register_move_cursor;
1820 control->traverse = gnc_split_register_traverse;
1826 gnc_split_register_recn_cell_confirm (
char old_flag, gpointer data)
1828 auto reg =
static_cast<SplitRegister*
>(data);
1829 GtkWidget *dialog, *window;
1831 const gchar *title = _(
"Mark split as unreconciled?");
1832 const gchar *message =
1833 _(
"You are about to mark a reconciled split as unreconciled. Doing " 1834 "so might make future reconciliation difficult! Continue " 1835 "with this change?");
1837 if (old_flag !=
YREC)
1841 window = gnc_split_register_get_parent(reg);
1843 gtk_message_dialog_new(GTK_WINDOW(window),
1844 GTK_DIALOG_DESTROY_WITH_PARENT,
1845 GTK_MESSAGE_WARNING,
1848 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
1850 gtk_dialog_add_button(GTK_DIALOG(dialog), _(
"_Unreconcile"),
1852 response = gnc_dialog_run(GTK_DIALOG(dialog), GNC_PREF_WARN_REG_RECD_SPLIT_UNREC);
1853 gtk_widget_destroy(dialog);
1854 return (response == GTK_RESPONSE_YES);
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...
void gnc_copy_trans_onto_trans(Transaction *from, Transaction *to, gboolean use_cut_semantics, gboolean do_commit)
Private function – outsiders must not use this.
gboolean xaccTransHasReconciledSplits(const Transaction *trans)
FIXME: document me.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency...
gchar * gnc_num_dbg_to_string(gnc_numeric n)
Convert to string.
Split * xaccTransGetSplit(const Transaction *trans, int i)
Return a pointer to the indexed split in this transaction's split list.
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
Determine whether this transaction should use commodity trading accounts.
SplitList * xaccAccountGetSplitList(const Account *acc)
The xaccAccountGetSplitList() routine returns a pointer to a GList of the splits in the account...
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
gboolean gnc_split_register_save(SplitRegister *reg, gboolean do_commit)
Copy the contents of the current cursor to a split.
gboolean xaccTransIsOpen(const Transaction *trans)
The xaccTransIsOpen() method returns TRUE if the transaction is open for editing. ...
#define PINFO(format, args...)
Print an informational note.
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.
Transaction * gnc_split_register_get_current_trans(SplitRegister *reg)
Gets the transaction at the current cursor location, which may be on the transaction itself or on any...
gboolean xaccSplitDestroy(Split *split)
Destructor.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
#define DEBUG(format, args...)
Print a debugging message.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
TableControl specialized for the SplitRegister.
gboolean gnc_table_find_close_valid_cell(Table *table, VirtualLocation *virt_loc, gboolean exact_pointer)
Find a close valid 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.
Save handlers for the SplitRegister Model and Template SplitRegister model.
gboolean gnc_split_reg_has_rate_cell(SplitRegisterType type)
Determine if we need to perform any conversion on the splits in this transaction, and if so...
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
gboolean xaccTransIsBalanced(const Transaction *trans)
Returns true if the transaction is balanced according to the rules currently in effect.
#define ENTER(format, args...)
Print a function entry debugging message.
gboolean gnc_split_register_current_trans_expanded(SplitRegister *reg)
Return TRUE if current trans is expanded and style is REG_STYLE_LEDGER.
const char * xaccTransGetDocLink(const Transaction *trans)
Gets the transaction Document Link.
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
Transaction * xaccTransLookup(const GncGUID *guid, QofBook *book)
The xaccTransLookup() subroutine will return the transaction associated with the given id...
convert single-entry accounts to clean double-entry
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.
void gnc_table_refresh_gui(Table *table, gboolean do_scroll)
Refresh the whole GUI from the table.
void gnc_split_register_redraw(SplitRegister *reg)
Causes a redraw of the register window associated with reg.
The ComboCell object implements a cell handler with a "combination-box" pull-down menu in it...
Reduce the result value by common factor elimination, using the smallest possible value for the denom...
Transaction * xaccAccountFindTransByDesc(const Account *acc, const char *description)
Returns a pointer to the transaction, not a copy.
CursorClass
Types of cursors.
#define YREC
The Split has been reconciled.
char * gnc_get_account_name_for_split_register(const Account *account, gboolean show_leaf_accounts)
Get either the full name of the account or the simple name, depending on the show_leaf_accounts.
The PriceCell object implements a cell handler that stores a single double-precision value...
Split * gnc_split_register_get_blank_split(SplitRegister *reg)
Gets the blank split for a register.
void gnc_monetary_list_free(MonetaryList *list)
Free a MonetaryList and all the monetaries it points to.
void gnc_date_cell_get_date(DateCell *cell, time64 *time, gboolean warn)
Set a time64 to the value in the DateCell.
void xaccTransScrubImbalance(Transaction *trans, Account *root, Account *account)
Correct transaction imbalances.
private declarations for SplitRegister
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
TableControl * gnc_split_register_control_new(void)
Create a new TableControl specialized for the SplitRegister.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
gnc_numeric gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Division.
#define xaccSplitGetGUID(X)
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
gnc_numeric xaccSplitGetSharePrice(const Split *split)
Returns the price of the split, that is, the value divided by the amount.
gboolean gnc_table_move_vertical_position(Table *table, VirtualLocation *virt_loc, int phys_row_offset)
Moves away from virtual location virt_loc by phys_row_offset physical rows.
API for checkbook register display area.
gboolean gnc_numeric_positive_p(gnc_numeric a)
Returns 1 if a > 0, otherwise returns 0.
#define xaccTransGetGUID(X)
Generic api to store and retrieve preferences.
void gnc_split_register_cancel_cursor_trans_changes(SplitRegister *reg)
Cancels any changes made to the current pending transaction, reloads the table from the engine...
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
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.
void gnc_table_set_virt_cell_cursor(Table *table, VirtualCellLocation vcell_loc, CellBlock *cursor)
Set the cellblock handler for a virtual cell.
MonetaryList * xaccTransGetImbalance(const Transaction *trans)
The xaccTransGetImbalance method returns a list giving the value of the transaction in each currency ...
gboolean gnc_table_virtual_cell_out_of_bounds(Table *table, VirtualCellLocation vcell_loc)
checks the given location and returns true if it is out of bounds of the table.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
void xaccTransSetDocLink(Transaction *trans, const char *doclink)
Sets the transaction Document Link.
Declarations for the Table object.
Split * xaccSplitGetOtherSplit(const Split *split)
The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits...
#define LEAVE(format, args...)
Print a function exit debugging message.
gboolean gnc_price_cell_set_value(PriceCell *cell, gnc_numeric amount)
updates amount, returns TRUE if string representation actually changed
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
The DateCell object implements a date handling cell.
gboolean gnc_split_register_handle_exchange(SplitRegister *reg, gboolean force_dialog)
If needed display the transfer dialog to get a price/exchange rate and adjust the price cell accordin...
Account * gnc_account_get_root(Account *acc)
This routine returns the root account of the account tree that the specified account belongs to...
void gnc_price_cell_set_debt_credit_value(PriceCell *debit, PriceCell *credit, gnc_numeric amount)
updates two cells; the deb cell if amt is negative, the credit cell if amount is positive, and makes the other cell blank.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
gnc_numeric gnc_price_cell_get_value(PriceCell *cell)
return the value of a price cell
Split * gnc_split_register_get_current_split(SplitRegister *reg)
Returns the split at which the cursor is currently located.
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
BasicCell * gnc_cellblock_get_cell_by_name(CellBlock *cellblock, const char *cell_name, int *row, int *col)
Searches by name for a particular cell in a CellBlock.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.