27 #include <glib/gi18n.h> 32 #include "gnc-component-manager.h" 35 #include "gnc-warnings.h" 38 #include "dialog-transfer.h" 39 #include "dialog-utils.h" 45 #include "engine-helpers.h" 49 static QofLogModule log_module = GNC_MOD_LEDGER;
53 gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans)
60 GList *radio_list = NULL;
61 const char *title = _(
"Rebalance Transaction");
62 const char *message = _(
"The current transaction is not balanced.");
65 gboolean two_accounts;
66 gboolean multi_currency;
74 MonetaryList *imbal_list;
75 gnc_monetary *imbal_mon;
83 multi_currency = TRUE;
86 imbal_mon =
static_cast<gnc_monetary*
>(imbal_list->data);
87 if (!imbal_list->next &&
90 multi_currency = FALSE;
92 multi_currency = TRUE;
100 multi_currency = FALSE;
105 if (other_split == NULL)
112 if (other_split == NULL || multi_currency)
114 two_accounts = FALSE;
115 other_account = NULL;
123 default_account = gnc_split_register_get_default_account (reg);
129 if (default_account == other_account)
136 if (default_account == other_account)
137 two_accounts = FALSE;
139 radio_list = g_list_append (radio_list,
140 _(
"Balance it _manually"));
141 radio_list = g_list_append (radio_list,
142 _(
"Let GnuCash _add an adjusting split"));
144 if (reg->type < NUM_SINGLE_REGISTER_TYPES && !multi_currency)
146 radio_list = g_list_append (radio_list,
147 _(
"Adjust current account _split total"));
152 radio_list = g_list_append (radio_list,
153 _(
"Adjust _other account split total"));
160 choice = gnc_choose_radio_option_dialog
161 (gnc_split_register_get_parent (reg),
168 g_list_free (radio_list);
194 gnc_split_register_old_split_empty_p (SplitRegister *reg, Split *split)
200 string = gnc_table_layout_get_cell_value (reg->table->layout, MEMO_CELL);
201 if ((
string != NULL) && (*
string !=
'\0'))
204 string = gnc_table_layout_get_cell_value (reg->table->layout, XFRM_CELL);
205 if ((
string != NULL) && (*
string !=
'\0'))
208 cell = gnc_table_layout_get_cell (reg->table->layout, CRED_CELL);
216 cell = gnc_table_layout_get_cell (reg->table->layout, DEBT_CELL);
231 gnc_split_register_check_debcred (SplitRegister *reg,
232 const char *cell_name)
234 if ((gnc_cell_name_equal (cell_name, DEBT_CELL) &&
235 gnc_table_layout_get_cell_changed (reg->table->layout,
236 DEBT_CELL, FALSE)) ||
237 (gnc_cell_name_equal (cell_name, CRED_CELL) &&
238 gnc_table_layout_get_cell_changed (reg->table->layout,
241 SRInfo *info = gnc_split_register_get_info (reg);
247 info->rate_reset = RATE_RESET_REQD;
248 if (info->auto_complete)
263 gnc_split_register_check_account (SplitRegister *reg,
264 const char *cell_name)
272 g_return_val_if_fail(reg, TRUE);
275 if (gnc_cell_name_equal (cell_name, XFRM_CELL))
277 if (gnc_table_layout_get_cell_changed (reg->table->layout,
279 cell = (
ComboCell *) gnc_table_layout_get_cell (reg->table->layout,
282 else if (gnc_cell_name_equal (cell_name, MXFRM_CELL))
284 if (gnc_table_layout_get_cell_changed (reg->table->layout,
286 cell = (
ComboCell *) gnc_table_layout_get_cell (reg->table->layout,
294 name = cell->cell.value;
295 DEBUG(
"Changed to %s", name ? name :
"NULL");
296 if (!name || *name ==
'\0' ||
297 g_strcmp0 (name, SPLIT_TRANS_STR) == 0 ||
298 g_strcmp0 (name, STOCK_SPLIT_STR) == 0)
302 info = gnc_split_register_get_info (reg);
303 new_acct = gnc_split_register_get_account_by_name (reg,
310 gnc_split_register_set_cell_fractions (reg, split);
324 DEBUG(
"Commodity is still %s. Leaving rate unchanged.",
330 DEBUG(
"Commodity now %s (originally %s). Clearing rate.",
335 info->rate_account = new_acct;
336 info->rate_reset = RATE_RESET_REQD;
348 DEBUG(
"Using original rate of %s.",
351 info->rate_account = new_acct;
352 info->rate_reset = RATE_RESET_NOT_REQD;
356 DEBUG(
"Can't get rate. Using zero.");
358 info->rate_account = new_acct;
359 info->rate_reset = RATE_RESET_REQD;
368 gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
371 VirtualLocation new_virt_loc = *p_new_virt_loc;
372 VirtualCellLocation old_trans_split_loc;
373 auto reg =
static_cast<SplitRegister*
>(user_data);
374 Transaction *pending_trans;
375 Transaction *new_trans;
376 Transaction *old_trans;
377 Split *old_trans_split;
378 Split *new_trans_split;
383 gboolean exact_traversal;
388 ENTER(
"reg=%p, p_new_virt_loc=%p (%d, %d)",
390 new_virt_loc.vcell_loc.virt_row,
391 new_virt_loc.vcell_loc.virt_col);
395 LEAVE(
"no register");
399 info = gnc_split_register_get_info (reg);
408 exact_traversal = info->exact_traversal;
410 if (info->traverse_to_new)
412 if (old_class == CURSOR_CLASS_SPLIT)
413 new_trans = old_trans;
418 new_trans_split = NULL;
419 new_class = CURSOR_CLASS_NONE;
421 else if (!info->hint_set_by_traverse)
424 new_trans = gnc_split_register_get_trans (reg, new_virt_loc.vcell_loc);
427 new_split = gnc_split_register_get_split (reg, new_virt_loc.vcell_loc);
430 new_trans_split = gnc_split_register_get_trans_split
431 (reg, new_virt_loc.vcell_loc, NULL);
434 new_virt_loc.vcell_loc);
438 new_trans = info->cursor_hint_trans;
439 new_split = info->cursor_hint_split;
440 new_trans_split = info->cursor_hint_trans_split;
441 new_class = info->cursor_hint_cursor_class;
444 info->hint_set_by_traverse = FALSE;
445 info->reg_loaded = FALSE;
447 gnc_suspend_gui_refresh ();
452 gnc_get_current_book ());
454 gnc_get_current_book ());
457 if ((old_class == CURSOR_CLASS_SPLIT) &&
459 (old_split != new_split) &&
460 gnc_split_register_old_split_empty_p(reg, old_split))
473 current_row = reg->table->current_cursor_loc.vcell_loc.virt_row;
474 if (new_virt_loc.vcell_loc.virt_row > current_row)
475 new_virt_loc.vcell_loc.virt_row--;
478 else if ((pending_trans != NULL) &&
479 (pending_trans == old_trans) &&
480 (pending_trans != blank_trans) &&
481 (old_trans != new_trans))
483 if (gnc_split_register_balance_trans (reg, pending_trans))
486 new_trans = old_trans;
487 new_split = old_split;
488 new_trans_split = old_trans_split;
489 new_class = old_class;
490 new_virt_loc = reg->table->current_cursor_loc;
495 info->pending_trans_guid = *
guid_null ();
498 else g_assert_not_reached();
500 pending_trans = NULL;
504 else if (old_trans &&
505 (old_trans != new_trans) &&
508 gnc_split_register_balance_trans (reg, old_trans))
511 new_trans = old_trans;
512 new_split = old_split;
513 new_trans_split = old_trans_split;
514 new_class = old_class;
515 new_virt_loc = reg->table->current_cursor_loc;
520 info->cursor_hint_trans = new_trans;
521 info->cursor_hint_split = new_split;
522 info->cursor_hint_trans_split = new_trans_split;
523 info->cursor_hint_cursor_class = new_class;
527 if (old_class != new_class)
528 info->change_confirmed = FALSE;
530 if (old_split != new_split)
532 info->change_confirmed = FALSE;
533 info->rate_account = NULL;
534 info->rate_reset = RATE_RESET_NOT_REQD;
537 gnc_resume_gui_refresh ();
542 VirtualCellLocation vcell_loc;
544 if (!info->reg_loaded)
549 if (gnc_split_register_find_split (reg, new_trans, new_trans_split,
550 new_split, new_class, &vcell_loc))
553 new_virt_loc.vcell_loc = vcell_loc;
556 new_virt_loc.vcell_loc = reg->table->current_cursor_loc.vcell_loc;
558 new_trans = gnc_split_register_get_trans (reg, new_virt_loc.vcell_loc);
559 new_split = gnc_split_register_get_split (reg, new_virt_loc.vcell_loc);
560 new_trans_split = gnc_split_register_get_trans_split(
561 reg, new_virt_loc.vcell_loc, NULL);
563 new_virt_loc.vcell_loc);
565 else if (info->traverse_to_new)
567 new_trans = info->cursor_hint_trans;
568 new_split = info->cursor_hint_split;
569 new_trans_split = info->cursor_hint_trans_split;
570 new_class = info->cursor_hint_cursor_class;
575 *p_new_virt_loc = new_virt_loc;
577 PINFO (
"after move %d %d\n",
578 new_virt_loc.vcell_loc.virt_row,
579 new_virt_loc.vcell_loc.virt_col);
585 gnc_split_register_set_cell_fractions (reg, new_split);
594 (old_trans_split != new_trans_split))
596 VirtualCellLocation vc_loc;
598 vc_loc = old_trans_split_loc;
600 reg->table, vc_loc, gnc_split_register_get_passive_cursor (reg));
602 reg->style == REG_STYLE_JOURNAL);
604 if ((REG_STYLE_AUTO_LEDGER == reg->style) ||
605 (REG_STYLE_JOURNAL == reg->style))
607 gnc_split_register_get_trans_split (reg, new_virt_loc.vcell_loc,
610 (reg->table, vc_loc, gnc_split_register_get_active_cursor (reg));
612 reg->style == REG_STYLE_JOURNAL);
615 info->trans_expanded = FALSE;
622 info->cursor_hint_trans = new_trans;
623 info->cursor_hint_split = new_split;
624 info->cursor_hint_trans_split = new_trans_split;
625 info->cursor_hint_cursor_class = new_class;
627 gnc_split_register_set_cell_fractions (reg, new_split);
634 VirtualCellLocation vc_loc;
637 gnc_table_leave_update (reg->table, reg->table->current_cursor_loc);
639 gnc_split_register_get_trans_split (reg, p_new_virt_loc->vcell_loc,
641 gnc_split_register_show_trans (reg, vc_loc);
648 gnc_find_split_in_trans_by_memo (Transaction *trans,
const char *memo,
653 auto split = GNC_SPLIT(n->data);
669 gnc_find_split_in_account_by_memo (
Account *account,
const char *memo,
672 if (account ==
nullptr)
return nullptr;
674 const auto& splits = xaccAccountGetSplits (account);
675 for (
auto it = splits.rbegin(); it != splits.rend(); it++)
676 if (
auto split = gnc_find_split_in_trans_by_memo (
xaccSplitGetParent (*it), memo, unit_price))
683 gnc_find_split_in_reg_by_memo (SplitRegister *reg,
const char *memo,
686 int virt_row, virt_col;
687 int num_rows, num_cols;
688 Transaction *last_trans;
690 if (!reg || !reg->table)
693 num_rows = reg->table->num_virt_rows;
694 num_cols = reg->table->num_virt_cols;
698 for (virt_row = num_rows - 1; virt_row >= 0; virt_row--)
699 for (virt_col = num_cols - 1; virt_col >= 0; virt_col--)
703 VirtualCellLocation vcell_loc = { virt_row, virt_col };
705 split = gnc_split_register_get_split (reg, vcell_loc);
708 if (trans == last_trans)
711 split = gnc_find_split_in_trans_by_memo (trans, memo, unit_price);
722 gnc_find_trans_in_reg_by_desc (SplitRegister *reg,
const char *description)
724 int virt_row, virt_col;
725 int num_rows, num_cols;
726 Transaction *last_trans;
728 if (!reg || !reg->table)
731 num_rows = reg->table->num_virt_rows;
732 num_cols = reg->table->num_virt_cols;
736 for (virt_row = num_rows - 1; virt_row >= 0; virt_row--)
737 for (virt_col = num_cols - 1; virt_col >= 0; virt_col--)
741 VirtualCellLocation vcell_loc = { virt_row, virt_col };
743 split = gnc_split_register_get_split (reg, vcell_loc);
746 if (trans == last_trans)
761 gnc_split_register_auto_completion (SplitRegister *reg,
762 gncTableTraversalDir dir,
763 VirtualLocation *p_new_virt_loc)
765 SRInfo *info = gnc_split_register_get_info (reg);
766 VirtualLocation new_virt_loc;
768 Transaction *pending_trans;
769 Transaction *blank_trans;
770 const char *cell_name;
777 if (!reg->do_auto_complete)
781 gnc_get_current_book ());
785 gnc_get_current_book ());
788 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
797 cell_name = gnc_table_get_current_cell_name (reg->table);
799 switch (cursor_class)
801 case CURSOR_CLASS_TRANS:
803 Transaction *auto_trans;
807 if (blank_trans == NULL)
811 if (trans != blank_trans)
815 if (!gnc_cell_name_equal (cell_name, DESC_CELL))
820 if (gnc_table_layout_get_cell_changed (reg->table->layout,
822 gnc_table_layout_get_cell_changed (reg->table->layout,
824 gnc_table_layout_get_cell_changed (reg->table->layout,
826 gnc_table_layout_get_cell_changed (reg->table->layout,
828 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,
839 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
844 desc = gnc_table_layout_get_cell_value (reg->table->layout, DESC_CELL);
845 if ((desc == NULL) || (*desc ==
'\0'))
849 if (gnc_split_register_get_default_account (reg) != NULL)
851 Account *account = gnc_split_register_get_default_account (reg);
856 auto_trans = gnc_find_trans_in_reg_by_desc(reg, desc);
858 if (auto_trans == NULL)
861 gnc_suspend_gui_refresh ();
867 if (pending_trans != trans)
873 if (pending_trans != NULL)
877 else g_assert_not_reached();
882 gnc_get_current_book ());
883 g_assert(pending_trans == trans);
891 if (gnc_split_register_get_default_account (reg) != NULL)
894 gnc_split_register_get_default_account (reg);
903 auto s = GNC_SPLIT(n->data);
913 if (blank_split == NULL)
918 DEBUG(
"blank_split=%p", blank_split);
920 info->blank_split_edited = TRUE;
925 sd = gnc_split_register_save_data_new(
927 gnc_table_save_cells (reg->table, sd);
928 gnc_split_register_save_data_destroy (sd);
931 gnc_resume_gui_refresh ();
935 GNC_PREF_TAB_TRANS_MEMORISED) )
940 if (gnc_table_get_current_cell_location (reg->table, cell_name,
942 *p_new_virt_loc = new_virt_loc;
948 case CURSOR_CLASS_SPLIT:
960 if (!gnc_cell_name_equal (cell_name, MEMO_CELL))
965 if (gnc_table_layout_get_cell_changed (reg->table->layout,
967 gnc_table_layout_get_cell_changed (reg->table->layout,
969 gnc_table_layout_get_cell_changed (reg->table->layout,
971 gnc_table_layout_get_cell_changed (reg->table->layout,
973 gnc_table_layout_get_cell_changed (reg->table->layout,
978 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
983 memo = gnc_table_layout_get_cell_value (reg->table->layout, MEMO_CELL);
984 if ((memo == NULL) || (*memo ==
'\0'))
989 unit_price = !gnc_table_get_current_cell_location (reg->table,
993 if (gnc_split_register_get_default_account (reg) != NULL)
995 Account *account = gnc_split_register_get_default_account (reg);
997 auto_split = gnc_find_split_in_account_by_memo (account, memo,
1001 auto_split = gnc_find_split_in_reg_by_memo (reg, memo, unit_price);
1003 if (auto_split == NULL)
1009 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1012 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1013 gnc_combo_cell_set_value ((
ComboCell *) cell,
1014 gnc_get_num_action (NULL, auto_split));
1018 cell = gnc_table_layout_get_cell (reg->table->layout, XFRM_CELL);
1021 reg->show_leaf_accounts);
1022 gnc_combo_cell_set_value ((
ComboCell *) cell, account_name);
1023 g_free(account_name);
1025 gnc_basic_cell_set_changed (cell, TRUE);
1027 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1029 !gnc_table_layout_get_cell_changed (reg->table->layout,
1032 BasicCell *debit_cell;
1033 BasicCell *credit_cell;
1037 debit_cell = gnc_table_layout_get_cell (reg->table->layout,
1039 credit_cell = gnc_table_layout_get_cell (reg->table->layout,
1046 gnc_basic_cell_set_changed (debit_cell, TRUE);
1047 gnc_basic_cell_set_changed (credit_cell, TRUE);
1057 if (gnc_table_get_current_cell_location (reg->table, cell_name,
1059 *p_new_virt_loc = new_virt_loc;
1072 gnc_split_register_check_stock_action (SplitRegister *reg,
1073 const char *cell_name)
1080 if (!gnc_cell_name_equal (cell_name, ACTN_CELL) ||
1081 !gnc_table_layout_get_cell_changed (reg->table->layout,
1085 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1089 if ((name == NULL) || (*name ==
'\0'))
1092 buy = g_strcmp0 (name, ACTION_BUY_STR) == 0;
1093 sell = g_strcmp0 (name, ACTION_SELL_STR) == 0;
1097 cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
1106 gnc_basic_cell_set_changed (cell, TRUE);
1111 gnc_split_register_check_stock_shares (SplitRegister *reg,
1112 const char *cell_name)
1119 if (!gnc_cell_name_equal (cell_name, SHRS_CELL) ||
1120 !gnc_table_layout_get_cell_changed (reg->table->layout,
1124 cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
1132 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1137 if (!g_strcmp0(name,
"") ||
1138 !g_strcmp0(name, buy ? ACTION_SELL_STR : ACTION_BUY_STR))
1140 gnc_combo_cell_set_value((
ComboCell *)cell,
1141 buy ? ACTION_BUY_STR : ACTION_SELL_STR);
1142 gnc_basic_cell_set_changed (cell, TRUE);
1152 gnc_split_register_check_cell (SplitRegister *reg,
const char *cell_name)
1154 ENTER(
"reg=%p, cell_name=%s", reg, cell_name ? cell_name :
"NULL");
1157 if (!gnc_split_register_check_account (reg, cell_name))
1159 LEAVE(
"account check failed");
1164 if (!gnc_split_register_check_debcred (reg, cell_name))
1166 LEAVE(
"debit/credit check failed");
1171 if ((reg->type == STOCK_REGISTER) ||
1172 (reg->type == PORTFOLIO_LEDGER) ||
1173 (reg->type == CURRENCY_REGISTER))
1175 gnc_split_register_check_stock_action (reg, cell_name);
1176 gnc_split_register_check_stock_shares (reg, cell_name);
1184 gnc_split_register_get_account_always (SplitRegister *reg,
1185 const char * cell_name)
1190 cell = gnc_table_layout_get_cell (reg->table->layout, cell_name);
1193 name = gnc_basic_cell_get_value (cell);
1197 if (!g_strcmp0 (name, SPLIT_TRANS_STR))
1202 return gnc_split_register_get_account_by_name (reg, cell, name);
1209 gnc_split_register_xfer_dialog(SplitRegister *reg, Transaction *txn,
1216 g_return_val_if_fail(reg, NULL);
1217 g_return_val_if_fail(reg->table, NULL);
1218 cur = reg->table->current_cursor;
1221 xfer = gnc_xfer_dialog(gnc_split_register_get_parent (reg), NULL);
1222 g_return_val_if_fail(xfer, NULL);
1227 gnc_xfer_dialog_set_description(xfer, gnc_basic_cell_get_value(cell));
1231 gnc_xfer_dialog_set_description(xfer, str ? str :
"");
1237 gnc_xfer_dialog_set_memo(xfer, gnc_basic_cell_get_value(cell));
1241 gnc_xfer_dialog_set_memo(xfer, str ? str :
"");
1247 gnc_xfer_dialog_set_num(xfer, gnc_basic_cell_get_value(cell));
1250 const char *str = gnc_get_num_action (txn, split);
1251 gnc_xfer_dialog_set_num(xfer, str ? str :
"");
1260 gnc_xfer_dialog_set_date(xfer, time);
1281 Split *split, *osplit;
1283 gnc_commodity *txn_cur, *xfer_com, *reg_com;
1284 gnc_numeric amount, exch_rate;
1286 gboolean expanded = FALSE;
1288 const char *message;
1291 ENTER(
"reg=%p, force_dialog=%s", reg, force_dialog ?
"TRUE" :
"FALSE" );
1294 if (reg->is_template)
1296 LEAVE(
"Template transaction, rate makes no sense.");
1305 message = _(
"This register does not support editing exchange rates.");
1306 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1308 LEAVE(
"no rate cell");
1312 rate_cell = (
PriceCell*) gnc_table_layout_get_cell(
1313 reg->table->layout, RATE_CELL);
1318 message = _(
"This register does not support editing exchange rates.");
1319 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1321 LEAVE(
"null rate cell");
1326 info = gnc_split_register_get_info (reg);
1329 info->rate_reset != RATE_RESET_REQD)
1331 LEAVE(
"rate already non-zero");
1340 if (expanded && cursor_class == CURSOR_CLASS_TRANS)
1344 message = _(
"You need to select a split in order to modify its exchange " 1346 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1348 LEAVE(
"expanded with transaction cursor; nothing to do");
1353 xfer_acc = gnc_split_register_get_account_always(
1354 reg, expanded ? XFRM_CELL : MXFRM_CELL);
1357 if (force_dialog && !expanded && !xfer_acc)
1359 message = _(
"You need to expand the transaction in order to modify its " 1361 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1362 LEAVE(
"%s", message);
1371 message = _(
"The entered account could not be found.");
1372 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1374 LEAVE(
"no xfer account");
1384 reg_acc = gnc_split_register_get_default_account (reg);
1399 LEAVE(
"txn and account currencies match, and not forcing");
1404 if (expanded || osplit == NULL)
1406 message = _(
"The two currencies involved equal each other.");
1407 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1408 LEAVE(
"register is expanded or osplit == NULL; not forcing dialog");
1419 message = _(
"The two currencies involved equal each other.");
1420 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1421 LEAVE(
"reg commodity == txn commodity; not forcing");
1430 if (!expanded && osplit &&
1431 gnc_split_register_split_needs_amount (reg, split) &&
1432 gnc_split_register_split_needs_amount (reg, osplit))
1434 message = _(
"You need to expand the transaction in order to modify its " 1438 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1440 LEAVE(
"%s", message);
1460 amount = gnc_split_register_debcred_cell_value (reg);
1470 message = _(
"The split's amount is zero, so no exchange rate is needed.");
1471 gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)),
"%s", message);
1473 LEAVE(
"amount is zero; no exchange rate needed");
1482 info->rate_reset != RATE_RESET_REQD &&
1485 LEAVE(
"gain/loss split; no exchange rate needed");
1490 xfer = gnc_split_register_xfer_dialog(reg, txn, split);
1491 gnc_xfer_dialog_is_exchange_dialog(xfer, &exch_rate);
1492 if (gnc_xfer_dialog_run_exchange_dialog(
1493 xfer, &exch_rate, amount, reg_acc, txn, xfer_com, expanded))
1496 LEAVE(
"leaving rate unchanged");
1503 gnc_basic_cell_set_changed (&rate_cell->cell, TRUE);
1504 info->rate_account = xfer_acc;
1505 info->rate_reset = RATE_RESET_DONE;
1512 transaction_changed_confirm(VirtualLocation *p_new_virt_loc,
1513 VirtualLocation *virt_loc,
1514 SplitRegister *reg, Transaction *new_trans,
1515 gboolean exact_traversal)
1517 GtkWidget *dialog, *window;
1519 const char *title = _(
"Save the changed transaction?");
1520 const char *message =
1521 _(
"The current transaction has been changed. Would you like to " 1522 "record the changes before moving to a new transaction, discard the " 1523 "changes, or return to the changed transaction?");
1525 window = gnc_split_register_get_parent(reg);
1526 dialog = gtk_message_dialog_new(GTK_WINDOW(window),
1527 GTK_DIALOG_DESTROY_WITH_PARENT,
1528 GTK_MESSAGE_QUESTION,
1531 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
1533 gtk_dialog_add_buttons(GTK_DIALOG(dialog),
1534 _(
"_Discard Changes"), GTK_RESPONSE_REJECT,
1535 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
1536 _(
"_Record Changes"), GTK_RESPONSE_ACCEPT,
1538 response = gnc_dialog_run(GTK_DIALOG(dialog), GNC_PREF_WARN_REG_TRANS_MOD);
1539 gtk_widget_destroy(dialog);
1543 case GTK_RESPONSE_ACCEPT:
1546 case GTK_RESPONSE_REJECT:
1548 VirtualCellLocation vcell_loc;
1554 if (reg->unrecn_splits != NULL)
1556 g_list_free (reg->unrecn_splits);
1557 reg->unrecn_splits = NULL;
1560 new_split = gnc_split_register_get_split (reg, virt_loc->vcell_loc);
1561 trans_split = gnc_split_register_get_trans_split (reg,
1562 virt_loc->vcell_loc,
1565 virt_loc->vcell_loc);
1569 if (gnc_split_register_find_split (reg, new_trans, trans_split,
1570 new_split, new_class, &vcell_loc))
1571 virt_loc->vcell_loc = vcell_loc;
1576 *p_new_virt_loc = *virt_loc;
1580 case GTK_RESPONSE_CANCEL:
1601 gnc_split_register_traverse (VirtualLocation *p_new_virt_loc,
1602 gncTableTraversalDir dir,
1605 auto reg =
static_cast<SplitRegister*
>(user_data);
1606 Transaction *pending_trans;
1607 VirtualLocation virt_loc;
1608 Transaction *trans, *new_trans;
1612 const char *cell_name;
1614 g_return_val_if_fail(p_new_virt_loc, TRUE);
1616 ENTER(
"reg=%p, p_new_virt_loc=%p (%d,%d), dir=%d",
1617 reg, p_new_virt_loc, (*p_new_virt_loc).vcell_loc.virt_row,
1618 (*p_new_virt_loc).vcell_loc.virt_col, dir);
1622 LEAVE(
"no register");
1626 info = gnc_split_register_get_info (reg);
1628 if (info->first_pass)
1630 LEAVE(
"first pass");
1635 gnc_get_current_book ());
1636 virt_loc = *p_new_virt_loc;
1638 info->exact_traversal = (dir == GNC_TABLE_TRAVERSE_POINTER);
1644 LEAVE(
"no transaction");
1649 changed = gnc_table_current_cursor_changed (reg->table, FALSE);
1650 if (!changed && (pending_trans != trans))
1653 info->exact_traversal);
1655 *p_new_virt_loc = virt_loc;
1657 LEAVE(
"no changes");
1662 cell_name = gnc_table_get_current_cell_name (reg->table);
1663 if (!gnc_split_register_check_cell (reg, cell_name))
1665 LEAVE(
"check cell");
1672 VirtualLocation virt_loc;
1674 if (!changed && !info->blank_split_edited)
1677 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
1680 virt_loc = reg->table->current_cursor_loc;
1684 virt_loc = reg->table->current_cursor_loc;
1685 if (gnc_table_move_tab (reg->table, &virt_loc, TRUE))
1691 LEAVE(
"no exchange rate");
1695 *p_new_virt_loc = reg->table->current_cursor_loc;
1696 (p_new_virt_loc->vcell_loc.virt_row)++;
1697 p_new_virt_loc->phys_row_offset = 0;
1698 p_new_virt_loc->phys_col_offset = 0;
1700 info->traverse_to_new = TRUE;
1702 LEAVE(
"off end of last line");
1712 if (gnc_split_register_auto_completion (reg, dir, p_new_virt_loc))
1714 info->auto_complete = TRUE;
1715 LEAVE(
"auto-complete");
1723 VirtualLocation virt_loc;
1732 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
1735 virt_loc = reg->table->current_cursor_loc;
1736 old_virt_row = virt_loc.vcell_loc.virt_row;
1738 if (gnc_table_move_tab (reg->table, &virt_loc, TRUE) &&
1739 old_virt_row == virt_loc.vcell_loc.virt_row)
1752 LEAVE(
"no exchange rate");
1756 info->cursor_hint_trans = trans;
1757 info->cursor_hint_split = split;
1758 info->cursor_hint_trans_split =
1760 info->cursor_hint_cursor_class = CURSOR_CLASS_SPLIT;
1761 info->hint_set_by_traverse = TRUE;
1763 LEAVE(
"off end of blank split");
1770 int old_virt_row = reg->table->current_cursor_loc.vcell_loc.virt_row;
1774 info->exact_traversal);
1778 if (virt_loc.vcell_loc.virt_row != old_virt_row)
1782 LEAVE(
"no exchange rate");
1789 new_trans = gnc_split_register_get_trans (reg, virt_loc.vcell_loc);
1790 if (trans == new_trans)
1792 *p_new_virt_loc = virt_loc;
1794 LEAVE(
"staying within txn");
1801 LEAVE(
"txn change");
1802 return transaction_changed_confirm(p_new_virt_loc, &virt_loc, reg,
1803 new_trans, info->exact_traversal);
1811 control->move_cursor = gnc_split_register_move_cursor;
1812 control->traverse = gnc_split_register_traverse;
1818 gnc_split_register_recn_cell_confirm (
char old_flag, gpointer data)
1820 auto reg =
static_cast<SplitRegister*
>(data);
1821 GtkWidget *dialog, *window;
1823 const gchar *title = _(
"Mark split as unreconciled?");
1824 const gchar *message =
1825 _(
"You are about to mark a reconciled split as unreconciled. Doing " 1826 "so might make future reconciliation difficult! Continue " 1827 "with this change?");
1829 if (old_flag !=
YREC)
1833 window = gnc_split_register_get_parent(reg);
1835 gtk_message_dialog_new(GTK_WINDOW(window),
1836 GTK_DIALOG_DESTROY_WITH_PARENT,
1837 GTK_MESSAGE_WARNING,
1840 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
1842 gtk_dialog_add_button(GTK_DIALOG(dialog), _(
"_Unreconcile"),
1844 response = gnc_dialog_run(GTK_DIALOG(dialog), GNC_PREF_WARN_REG_RECD_SPLIT_UNREC);
1845 gtk_widget_destroy(dialog);
1846 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.
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.
Account public routines (C++ api)
#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.