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" 46 #include <gnc-gui-query.h> 50 static QofLogModule log_module = GNC_MOD_LEDGER;
53 check_imbalance_fraction (
const SplitRegister *reg,
54 const gnc_monetary *imbal_mon,
55 const Transaction *trans)
58 auto denom_diff = imbal_mon->value.denom > commodity_fraction;
61 const auto imbal_comm = imbal_mon->commodity;
63 node = g_list_next (node))
79 _(
"This transaction cannot be balanced: The imbalance is a fraction smaller than the commodity allows."));
85 gnc_split_register_balance_trans (SplitRegister *reg, Transaction *trans)
92 GList *radio_list = NULL;
93 const char *title = _(
"Rebalance Transaction");
94 const char *message = _(
"The current transaction is not balanced.");
97 gboolean two_accounts;
98 gboolean multi_currency;
105 MonetaryList *imbal_list;
106 gnc_monetary *imbal_mon;
114 multi_currency = TRUE;
117 imbal_mon =
static_cast<gnc_monetary*
>(imbal_list->data);
118 if (!imbal_list->next &&
121 multi_currency = FALSE;
123 multi_currency = TRUE;
125 if (multi_currency && check_imbalance_fraction (reg, imbal_mon, trans))
134 multi_currency = FALSE;
139 if (other_split == NULL)
148 if (other_split == NULL || multi_currency)
150 two_accounts = FALSE;
151 other_account = NULL;
159 default_account = gnc_split_register_get_default_account (reg);
165 if (default_account == other_account)
172 if (default_account == other_account)
173 two_accounts = FALSE;
175 radio_list = g_list_append (radio_list,
176 _(
"Balance it _manually"));
177 radio_list = g_list_append (radio_list,
178 _(
"Let GnuCash _add an adjusting split"));
180 if (reg->type < NUM_SINGLE_REGISTER_TYPES && !multi_currency)
182 radio_list = g_list_append (radio_list,
183 _(
"Adjust current account _split total"));
188 radio_list = g_list_append (radio_list,
189 _(
"Adjust _other account split total"));
196 choice = gnc_choose_radio_option_dialog (gnc_split_register_get_parent (reg),
203 g_list_free (radio_list);
229 gnc_split_register_old_split_empty_p (SplitRegister *reg, Split *split)
235 string = gnc_table_layout_get_cell_value (reg->table->layout, MEMO_CELL);
236 if ((
string != NULL) && (*
string !=
'\0'))
239 string = gnc_table_layout_get_cell_value (reg->table->layout, XFRM_CELL);
240 if ((
string != NULL) && (*
string !=
'\0'))
243 cell = gnc_table_layout_get_cell (reg->table->layout, CRED_CELL);
251 cell = gnc_table_layout_get_cell (reg->table->layout, DEBT_CELL);
266 gnc_split_register_check_debcred (SplitRegister *reg,
267 const char *cell_name)
269 if ((gnc_cell_name_equal (cell_name, DEBT_CELL) &&
270 gnc_table_layout_get_cell_changed (reg->table->layout, DEBT_CELL, FALSE)) ||
271 (gnc_cell_name_equal (cell_name, CRED_CELL) &&
272 gnc_table_layout_get_cell_changed (reg->table->layout, CRED_CELL, FALSE)))
274 SRInfo *info = gnc_split_register_get_info (reg);
280 info->rate_reset = RATE_RESET_REQD;
281 if (info->auto_complete)
296 gnc_split_register_check_account (SplitRegister *reg,
297 const char *cell_name)
305 g_return_val_if_fail (reg, TRUE);
308 if (gnc_cell_name_equal (cell_name, XFRM_CELL))
310 if (gnc_table_layout_get_cell_changed (reg->table->layout,
312 cell = (
ComboCell *) gnc_table_layout_get_cell (reg->table->layout,
315 else if (gnc_cell_name_equal (cell_name, MXFRM_CELL))
317 if (gnc_table_layout_get_cell_changed (reg->table->layout,
319 cell = (
ComboCell *) gnc_table_layout_get_cell (reg->table->layout,
327 name = cell->cell.value;
328 DEBUG(
"Changed to %s", name ? name :
"NULL");
329 if (!name || *name ==
'\0' ||
330 g_strcmp0 (name, SPLIT_TRANS_STR) == 0 ||
331 g_strcmp0 (name, STOCK_SPLIT_STR) == 0)
335 info = gnc_split_register_get_info (reg);
336 new_acct = gnc_split_register_get_account_by_name (reg,
343 gnc_split_register_set_cell_fractions (reg, split);
357 DEBUG(
"Commodity is still %s. Leaving rate unchanged.",
363 DEBUG(
"Commodity now %s (originally %s). Clearing rate.",
368 info->rate_account = new_acct;
369 info->rate_reset = RATE_RESET_REQD;
383 info->rate_account = new_acct;
384 info->rate_reset = RATE_RESET_NOT_REQD;
388 DEBUG(
"Can't get rate. Using zero.");
390 info->rate_account = new_acct;
391 info->rate_reset = RATE_RESET_REQD;
400 is_trading_split (Split *split)
407 gnc_split_register_move_cursor (VirtualLocation *p_new_virt_loc,
410 VirtualLocation new_virt_loc = *p_new_virt_loc;
411 VirtualCellLocation old_trans_split_loc;
412 auto reg =
static_cast<SplitRegister*
>(user_data);
413 Transaction *pending_trans;
414 Transaction *new_trans;
415 Transaction *old_trans;
416 Split *old_trans_split{
nullptr};
417 Split *new_trans_split;
419 Split *old_split{
nullptr};
422 gboolean exact_traversal;
427 ENTER(
"reg=%p, p_new_virt_loc=%p (%d, %d)",
429 new_virt_loc.vcell_loc.virt_row,
430 new_virt_loc.vcell_loc.virt_col);
434 LEAVE(
"no register");
438 info = gnc_split_register_get_info (reg);
445 !is_trading_split (s))
450 exact_traversal = info->exact_traversal;
452 if (info->traverse_to_new)
454 if (old_class == CURSOR_CLASS_SPLIT)
455 new_trans = old_trans;
460 new_trans_split = NULL;
461 new_class = CURSOR_CLASS_NONE;
463 else if (!info->hint_set_by_traverse)
466 new_trans = gnc_split_register_get_trans (reg, new_virt_loc.vcell_loc);
469 new_split = gnc_split_register_get_split (reg, new_virt_loc.vcell_loc);
472 new_trans_split = gnc_split_register_get_trans_split (reg,
473 new_virt_loc.vcell_loc,
477 new_virt_loc.vcell_loc);
481 new_trans = info->cursor_hint_trans;
482 new_split = info->cursor_hint_split;
483 new_trans_split = info->cursor_hint_trans_split;
484 new_class = info->cursor_hint_cursor_class;
487 info->hint_set_by_traverse = FALSE;
488 info->reg_loaded = FALSE;
490 gnc_suspend_gui_refresh ();
495 gnc_get_current_book ());
497 gnc_get_current_book ());
500 if ((old_class == CURSOR_CLASS_SPLIT) &&
502 (old_split != new_split) &&
503 gnc_split_register_old_split_empty_p (reg, old_split))
516 current_row = reg->table->current_cursor_loc.vcell_loc.virt_row;
517 if (new_virt_loc.vcell_loc.virt_row > current_row)
518 new_virt_loc.vcell_loc.virt_row--;
521 else if ((pending_trans != NULL) &&
522 (pending_trans == old_trans) &&
523 (pending_trans != blank_trans) &&
524 (old_trans != new_trans))
526 if (gnc_split_register_balance_trans (reg, pending_trans))
529 new_trans = old_trans;
530 new_split = old_split;
531 new_trans_split = old_trans_split;
532 new_class = old_class;
533 new_virt_loc = reg->table->current_cursor_loc;
538 info->pending_trans_guid = *
guid_null ();
541 else g_assert_not_reached ();
543 pending_trans = NULL;
547 else if (old_trans &&
548 (old_trans != new_trans) &&
551 gnc_split_register_balance_trans (reg, old_trans))
554 new_trans = old_trans;
555 new_split = old_split;
556 new_trans_split = old_trans_split;
557 new_class = old_class;
558 new_virt_loc = reg->table->current_cursor_loc;
563 info->cursor_hint_trans = new_trans;
564 info->cursor_hint_split = new_split;
565 info->cursor_hint_trans_split = new_trans_split;
566 info->cursor_hint_cursor_class = new_class;
570 if (old_class != new_class)
571 info->change_confirmed = FALSE;
573 if (old_split != new_split)
575 info->change_confirmed = FALSE;
576 info->rate_account = NULL;
577 info->rate_reset = RATE_RESET_NOT_REQD;
580 gnc_resume_gui_refresh ();
585 VirtualCellLocation vcell_loc;
587 if (!info->reg_loaded)
592 if (gnc_split_register_find_split (reg, new_trans, new_trans_split,
593 new_split, new_class, &vcell_loc))
595 new_virt_loc.vcell_loc = vcell_loc;
598 new_virt_loc.vcell_loc = reg->table->current_cursor_loc.vcell_loc;
600 new_trans = gnc_split_register_get_trans (reg, new_virt_loc.vcell_loc);
601 new_split = gnc_split_register_get_split (reg, new_virt_loc.vcell_loc);
602 new_trans_split = gnc_split_register_get_trans_split (reg,
603 new_virt_loc.vcell_loc,
606 new_virt_loc.vcell_loc);
608 else if (info->traverse_to_new)
610 new_trans = info->cursor_hint_trans;
611 new_split = info->cursor_hint_split;
612 new_trans_split = info->cursor_hint_trans_split;
613 new_class = info->cursor_hint_cursor_class;
618 *p_new_virt_loc = new_virt_loc;
620 PINFO(
"after move %d %d",
621 new_virt_loc.vcell_loc.virt_row,
622 new_virt_loc.vcell_loc.virt_col);
628 gnc_split_register_set_cell_fractions (reg, new_split);
637 (old_trans_split != new_trans_split))
639 VirtualCellLocation vc_loc;
641 vc_loc = old_trans_split_loc;
643 gnc_split_register_get_passive_cursor (reg));
645 reg->style == REG_STYLE_JOURNAL);
647 if ((REG_STYLE_AUTO_LEDGER == reg->style) ||
648 (REG_STYLE_JOURNAL == reg->style))
650 gnc_split_register_get_trans_split (reg, new_virt_loc.vcell_loc,
653 gnc_split_register_get_active_cursor (reg));
655 reg->style == REG_STYLE_JOURNAL);
658 info->trans_expanded = FALSE;
665 info->cursor_hint_trans = new_trans;
666 info->cursor_hint_split = new_split;
667 info->cursor_hint_trans_split = new_trans_split;
668 info->cursor_hint_cursor_class = new_class;
670 gnc_split_register_set_cell_fractions (reg, new_split);
677 VirtualCellLocation vc_loc;
680 gnc_table_leave_update (reg->table, reg->table->current_cursor_loc);
682 gnc_split_register_get_trans_split (reg, p_new_virt_loc->vcell_loc,
684 gnc_split_register_show_trans (reg, vc_loc);
691 gnc_find_split_in_trans_by_memo (Transaction *trans,
const char *memo,
696 auto split = GNC_SPLIT(n->data);
713 gnc_find_split_in_account_by_memo (
Account *account,
const char *memo,
716 if (account ==
nullptr)
return nullptr;
718 const auto& splits = xaccAccountGetSplits (account);
719 for (
auto it = splits.rbegin(); it != splits.rend(); it++)
728 gnc_find_split_in_reg_by_memo (SplitRegister *reg,
const char *memo,
731 int virt_row, virt_col;
732 int num_rows, num_cols;
733 Transaction *last_trans;
735 if (!reg || !reg->table)
738 num_rows = reg->table->num_virt_rows;
739 num_cols = reg->table->num_virt_cols;
743 for (virt_row = num_rows - 1; virt_row >= 0; virt_row--)
744 for (virt_col = num_cols - 1; virt_col >= 0; virt_col--)
748 VirtualCellLocation vcell_loc = { virt_row, virt_col };
750 split = gnc_split_register_get_split (reg, vcell_loc);
753 if (trans == last_trans)
756 split = gnc_find_split_in_trans_by_memo (trans, memo, unit_price);
767 gnc_find_trans_in_reg_by_desc (SplitRegister *reg,
const char *description)
769 int virt_row, virt_col;
770 int num_rows, num_cols;
771 Transaction *last_trans;
773 if (!reg || !reg->table)
776 num_rows = reg->table->num_virt_rows;
777 num_cols = reg->table->num_virt_cols;
781 for (virt_row = num_rows - 1; virt_row >= 0; virt_row--)
782 for (virt_col = num_cols - 1; virt_col >= 0; virt_col--)
786 VirtualCellLocation vcell_loc = { virt_row, virt_col };
788 split = gnc_split_register_get_split (reg, vcell_loc);
791 if (trans == last_trans)
806 gnc_split_register_auto_completion (SplitRegister *reg,
807 gncTableTraversalDir dir,
808 VirtualLocation *p_new_virt_loc)
810 SRInfo *info = gnc_split_register_get_info (reg);
811 VirtualLocation new_virt_loc;
813 Transaction *pending_trans;
814 Transaction *blank_trans;
815 const char *cell_name;
822 if (!reg->do_auto_complete)
826 gnc_get_current_book ());
830 gnc_get_current_book ());
833 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
842 cell_name = gnc_table_get_current_cell_name (reg->table);
844 switch (cursor_class)
846 case CURSOR_CLASS_TRANS:
848 Transaction *auto_trans;
852 if (blank_trans == NULL)
856 if (trans != blank_trans)
860 if (!gnc_cell_name_equal (cell_name, DESC_CELL))
865 if (gnc_table_layout_get_cell_changed (reg->table->layout,
867 gnc_table_layout_get_cell_changed (reg->table->layout,
869 gnc_table_layout_get_cell_changed (reg->table->layout,
871 gnc_table_layout_get_cell_changed (reg->table->layout,
873 gnc_table_layout_get_cell_changed (reg->table->layout,
875 gnc_table_layout_get_cell_changed (reg->table->layout,
877 gnc_table_layout_get_cell_changed (reg->table->layout,
879 gnc_table_layout_get_cell_changed (reg->table->layout,
884 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
889 desc = gnc_table_layout_get_cell_value (reg->table->layout, DESC_CELL);
890 if ((desc == NULL) || (*desc ==
'\0'))
894 if (gnc_split_register_get_default_account (reg) != NULL)
896 Account *account = gnc_split_register_get_default_account (reg);
901 auto_trans = gnc_find_trans_in_reg_by_desc (reg, desc);
903 if (auto_trans == NULL)
906 gnc_suspend_gui_refresh ();
912 if (pending_trans != trans)
918 if (pending_trans != NULL)
922 else g_assert_not_reached ();
927 gnc_get_current_book ());
928 g_assert (pending_trans == trans);
936 if (gnc_split_register_get_default_account (reg) != NULL)
938 Account *default_account = gnc_split_register_get_default_account (reg);
947 auto s = GNC_SPLIT(n->data);
957 if (blank_split == NULL)
962 DEBUG(
"blank_split=%p", blank_split);
964 info->blank_split_edited = TRUE;
969 sd = gnc_split_register_save_data_new (trans, blank_split,
971 gnc_table_save_cells (reg->table, sd);
972 gnc_split_register_save_data_destroy (sd);
975 gnc_resume_gui_refresh ();
979 GNC_PREF_TAB_TRANS_MEMORISED))
984 if (gnc_table_get_current_cell_location (reg->table, cell_name, &new_virt_loc))
985 *p_new_virt_loc = new_virt_loc;
991 case CURSOR_CLASS_SPLIT:
1003 if (!gnc_cell_name_equal (cell_name, MEMO_CELL))
1008 if (gnc_table_layout_get_cell_changed (reg->table->layout,
1010 gnc_table_layout_get_cell_changed (reg->table->layout,
1011 MXFRM_CELL, TRUE) ||
1012 gnc_table_layout_get_cell_changed (reg->table->layout,
1014 gnc_table_layout_get_cell_changed (reg->table->layout,
1016 gnc_table_layout_get_cell_changed (reg->table->layout,
1021 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1026 memo = gnc_table_layout_get_cell_value (reg->table->layout, MEMO_CELL);
1027 if ((memo == NULL) || (*memo ==
'\0'))
1032 unit_price = !gnc_table_get_current_cell_location (reg->table,
1036 if (gnc_split_register_get_default_account (reg) != NULL)
1038 Account *account = gnc_split_register_get_default_account (reg);
1040 auto_split = gnc_find_split_in_account_by_memo (account, memo,
1044 auto_split = gnc_find_split_in_reg_by_memo (reg, memo, unit_price);
1046 if (auto_split == NULL)
1052 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1055 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1056 gnc_combo_cell_set_value ((
ComboCell *) cell,
1057 gnc_get_num_action (NULL, auto_split));
1061 cell = gnc_table_layout_get_cell (reg->table->layout, XFRM_CELL);
1064 reg->show_leaf_accounts);
1065 gnc_combo_cell_set_value ((
ComboCell *) cell, account_name);
1066 g_free (account_name);
1068 gnc_basic_cell_set_changed (cell, TRUE);
1070 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1072 !gnc_table_layout_get_cell_changed (reg->table->layout,
1075 BasicCell *debit_cell;
1076 BasicCell *credit_cell;
1080 debit_cell = gnc_table_layout_get_cell (reg->table->layout,
1082 credit_cell = gnc_table_layout_get_cell (reg->table->layout,
1089 gnc_basic_cell_set_changed (debit_cell, TRUE);
1090 gnc_basic_cell_set_changed (credit_cell, TRUE);
1100 if (gnc_table_get_current_cell_location (reg->table, cell_name,
1102 *p_new_virt_loc = new_virt_loc;
1115 gnc_split_register_check_stock_action (SplitRegister *reg,
1116 const char *cell_name)
1123 if (!gnc_cell_name_equal (cell_name, ACTN_CELL) ||
1124 !gnc_table_layout_get_cell_changed (reg->table->layout,
1128 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1132 if ((name == NULL) || (*name ==
'\0'))
1135 buy = g_strcmp0 (name, ACTION_BUY_STR) == 0;
1136 sell = g_strcmp0 (name, ACTION_SELL_STR) == 0;
1140 cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
1149 gnc_basic_cell_set_changed (cell, TRUE);
1154 gnc_split_register_check_stock_shares (SplitRegister *reg,
1155 const char *cell_name)
1162 if (!gnc_cell_name_equal (cell_name, SHRS_CELL) ||
1163 !gnc_table_layout_get_cell_changed (reg->table->layout,
1167 cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
1175 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1180 if (!g_strcmp0 (name,
"") ||
1181 !g_strcmp0 (name, buy ? ACTION_SELL_STR : ACTION_BUY_STR))
1183 gnc_combo_cell_set_value ((
ComboCell *)cell,
1184 buy ? ACTION_BUY_STR : ACTION_SELL_STR);
1185 gnc_basic_cell_set_changed (cell, TRUE);
1195 gnc_split_register_check_cell (SplitRegister *reg,
const char *cell_name)
1197 ENTER(
"reg=%p, cell_name=%s", reg, cell_name ? cell_name :
"NULL");
1200 if (!gnc_split_register_check_account (reg, cell_name))
1202 LEAVE(
"account check failed");
1207 if (!gnc_split_register_check_debcred (reg, cell_name))
1209 LEAVE(
"debit/credit check failed");
1214 if ((reg->type == STOCK_REGISTER) ||
1215 (reg->type == PORTFOLIO_LEDGER) ||
1216 (reg->type == CURRENCY_REGISTER))
1218 gnc_split_register_check_stock_action (reg, cell_name);
1219 gnc_split_register_check_stock_shares (reg, cell_name);
1227 gnc_split_register_get_account_always (SplitRegister *reg,
1228 const char *cell_name)
1233 cell = gnc_table_layout_get_cell (reg->table->layout, cell_name);
1236 name = gnc_basic_cell_get_value (cell);
1240 if (!g_strcmp0 (name, SPLIT_TRANS_STR))
1243 return gnc_split_register_get_account_by_name (reg, cell, name);
1250 gnc_split_register_xfer_dialog (SplitRegister *reg, Transaction *txn,
1257 g_return_val_if_fail (reg, NULL);
1258 g_return_val_if_fail (reg->table, NULL);
1260 cur = reg->table->current_cursor;
1263 xfer = gnc_xfer_dialog (gnc_split_register_get_parent (reg), NULL);
1264 g_return_val_if_fail (xfer, NULL);
1269 gnc_xfer_dialog_set_description (xfer, gnc_basic_cell_get_value (cell));
1273 gnc_xfer_dialog_set_description (xfer, str ? str :
"");
1279 gnc_xfer_dialog_set_memo (xfer, gnc_basic_cell_get_value (cell));
1283 gnc_xfer_dialog_set_memo (xfer, str ? str :
"");
1289 gnc_xfer_dialog_set_num (xfer, gnc_basic_cell_get_value (cell));
1292 const char *str = gnc_get_num_action (txn, split);
1293 gnc_xfer_dialog_set_num (xfer, str ? str :
"");
1302 gnc_xfer_dialog_set_date (xfer, time);
1323 Split *split, *osplit;
1325 gnc_commodity *txn_cur, *xfer_com, *reg_com;
1326 gnc_numeric amount, exch_rate;
1328 gboolean expanded = FALSE;
1330 const char *message;
1333 ENTER(
"reg=%p, force_dialog=%s", reg, force_dialog ?
"TRUE" :
"FALSE" );
1336 if (reg->is_template)
1338 LEAVE(
"Template transaction, rate makes no sense.");
1347 message = _(
"This register does not support editing exchange rates.");
1348 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1350 LEAVE(
"no rate cell");
1354 rate_cell = (
PriceCell*) gnc_table_layout_get_cell (reg->table->layout, RATE_CELL);
1360 message = _(
"This register does not support editing exchange rates.");
1361 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1363 LEAVE(
"null rate cell");
1368 info = gnc_split_register_get_info (reg);
1371 info->rate_reset != RATE_RESET_REQD)
1373 LEAVE(
"rate already non-zero");
1382 if (expanded && cursor_class == CURSOR_CLASS_TRANS)
1386 message = _(
"You need to select a split in order to modify its exchange " 1388 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1390 LEAVE(
"expanded with transaction cursor; nothing to do");
1395 xfer_acc = gnc_split_register_get_account_always (reg,
1396 expanded ? XFRM_CELL : MXFRM_CELL);
1399 if (force_dialog && !expanded && !xfer_acc)
1401 message = _(
"You need to expand the transaction in order to modify its " 1403 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1404 LEAVE(
"%s", message);
1413 message = _(
"The entered account could not be found.");
1414 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1416 LEAVE(
"no xfer account");
1426 reg_acc = gnc_split_register_get_default_account (reg);
1441 LEAVE(
"txn and account currencies match, and not forcing");
1446 if (expanded || osplit == NULL)
1448 message = _(
"The two currencies involved equal each other.");
1449 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1450 LEAVE(
"register is expanded or osplit == NULL; not forcing dialog");
1461 message = _(
"The two currencies involved equal each other.");
1462 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1463 LEAVE(
"reg commodity == txn commodity; not forcing");
1472 if (!expanded && osplit &&
1473 gnc_split_register_split_needs_amount (reg, split) &&
1474 gnc_split_register_split_needs_amount (reg, osplit))
1476 message = _(
"You need to expand the transaction in order to modify its " 1480 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1482 LEAVE(
"%s", message);
1493 if (!expanded && osplit &&
1503 amount = gnc_split_register_debcred_cell_value (reg);
1513 message = _(
"The split's amount is zero, so no exchange rate is needed.");
1514 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1516 LEAVE(
"amount is zero; no exchange rate needed");
1525 info->rate_reset != RATE_RESET_REQD &&
1528 LEAVE(
"gain/loss split; no exchange rate needed");
1533 xfer = gnc_split_register_xfer_dialog (reg, txn, split);
1534 gnc_xfer_dialog_is_exchange_dialog (xfer, &exch_rate);
1535 if (gnc_xfer_dialog_run_exchange_dialog (xfer, &exch_rate, amount,
1536 reg_acc, txn, xfer_com, expanded))
1539 LEAVE(
"leaving rate unchanged");
1546 gnc_basic_cell_set_changed (&rate_cell->cell, TRUE);
1547 info->rate_account = xfer_acc;
1548 info->rate_reset = RATE_RESET_DONE;
1555 transaction_changed_confirm (VirtualLocation *p_new_virt_loc,
1556 VirtualLocation *virt_loc,
1557 SplitRegister *reg, Transaction *new_trans,
1558 gboolean exact_traversal)
1560 GtkWidget *dialog, *window;
1562 const char *title = _(
"Save the changed transaction?");
1563 const char *message =
1564 _(
"The current transaction has been changed. Would you like to " 1565 "record the changes before moving to a new transaction, discard the " 1566 "changes, or return to the changed transaction?");
1568 window = gnc_split_register_get_parent (reg);
1569 dialog = gtk_message_dialog_new (GTK_WINDOW(window),
1570 GTK_DIALOG_DESTROY_WITH_PARENT,
1571 GTK_MESSAGE_QUESTION,
1574 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
1576 gtk_dialog_add_buttons (GTK_DIALOG(dialog),
1577 _(
"_Discard Changes"), GTK_RESPONSE_REJECT,
1578 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
1579 _(
"_Record Changes"), GTK_RESPONSE_ACCEPT,
1581 response = gnc_dialog_run (GTK_DIALOG(dialog), GNC_PREF_WARN_REG_TRANS_MOD);
1582 gtk_widget_destroy (dialog);
1586 case GTK_RESPONSE_ACCEPT:
1589 case GTK_RESPONSE_REJECT:
1591 VirtualCellLocation vcell_loc;
1597 if (reg->unrecn_splits != NULL)
1599 g_list_free (reg->unrecn_splits);
1600 reg->unrecn_splits = NULL;
1603 new_split = gnc_split_register_get_split (reg, virt_loc->vcell_loc);
1604 trans_split = gnc_split_register_get_trans_split (reg,
1605 virt_loc->vcell_loc,
1608 virt_loc->vcell_loc);
1612 if (gnc_split_register_find_split (reg, new_trans, trans_split,
1613 new_split, new_class, &vcell_loc))
1614 virt_loc->vcell_loc = vcell_loc;
1619 *p_new_virt_loc = *virt_loc;
1623 case GTK_RESPONSE_CANCEL:
1644 gnc_split_register_traverse (VirtualLocation *p_new_virt_loc,
1645 gncTableTraversalDir dir,
1648 auto reg =
static_cast<SplitRegister*
>(user_data);
1649 Transaction *pending_trans;
1650 VirtualLocation virt_loc;
1651 Transaction *trans, *new_trans;
1655 const char *cell_name;
1657 g_return_val_if_fail (p_new_virt_loc, TRUE);
1659 ENTER(
"reg=%p, p_new_virt_loc=%p (%d,%d), dir=%d",
1660 reg, p_new_virt_loc,
1661 (*p_new_virt_loc).vcell_loc.virt_row,
1662 (*p_new_virt_loc).vcell_loc.virt_col, dir);
1666 LEAVE(
"no register");
1670 info = gnc_split_register_get_info (reg);
1672 if (info->first_pass)
1674 LEAVE(
"first pass");
1679 gnc_get_current_book ());
1680 virt_loc = *p_new_virt_loc;
1682 info->exact_traversal = (dir == GNC_TABLE_TRAVERSE_POINTER);
1688 LEAVE(
"no transaction");
1693 changed = gnc_table_current_cursor_changed (reg->table, FALSE);
1694 if (!changed && (pending_trans != trans))
1697 info->exact_traversal);
1699 *p_new_virt_loc = virt_loc;
1701 LEAVE(
"no changes");
1706 cell_name = gnc_table_get_current_cell_name (reg->table);
1707 if (!gnc_split_register_check_cell (reg, cell_name))
1709 LEAVE(
"check cell");
1716 VirtualLocation virt_loc;
1718 if (!changed && !info->blank_split_edited)
1721 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
1724 virt_loc = reg->table->current_cursor_loc;
1728 virt_loc = reg->table->current_cursor_loc;
1729 if (gnc_table_move_tab (reg->table, &virt_loc, TRUE))
1735 LEAVE(
"no exchange rate");
1739 *p_new_virt_loc = reg->table->current_cursor_loc;
1740 (p_new_virt_loc->vcell_loc.virt_row)++;
1741 p_new_virt_loc->phys_row_offset = 0;
1742 p_new_virt_loc->phys_col_offset = 0;
1744 info->traverse_to_new = TRUE;
1746 LEAVE(
"off end of last line");
1756 if (gnc_split_register_auto_completion (reg, dir, p_new_virt_loc))
1758 info->auto_complete = TRUE;
1759 LEAVE(
"auto-complete");
1767 VirtualLocation virt_loc;
1776 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
1779 virt_loc = reg->table->current_cursor_loc;
1780 old_virt_row = virt_loc.vcell_loc.virt_row;
1782 if (gnc_table_move_tab (reg->table, &virt_loc, TRUE) &&
1783 old_virt_row == virt_loc.vcell_loc.virt_row)
1796 LEAVE(
"no exchange rate");
1800 info->cursor_hint_trans = trans;
1801 info->cursor_hint_split = split;
1802 info->cursor_hint_trans_split =
1804 info->cursor_hint_cursor_class = CURSOR_CLASS_SPLIT;
1805 info->hint_set_by_traverse = TRUE;
1807 LEAVE(
"off end of blank split");
1814 int old_virt_row = reg->table->current_cursor_loc.vcell_loc.virt_row;
1818 info->exact_traversal);
1822 if (virt_loc.vcell_loc.virt_row != old_virt_row)
1826 LEAVE(
"no exchange rate");
1833 new_trans = gnc_split_register_get_trans (reg, virt_loc.vcell_loc);
1834 if (trans == new_trans)
1836 *p_new_virt_loc = virt_loc;
1838 LEAVE(
"staying within txn");
1845 LEAVE(
"txn change");
1846 return transaction_changed_confirm (p_new_virt_loc, &virt_loc, reg,
1847 new_trans, info->exact_traversal);
1855 control->move_cursor = gnc_split_register_move_cursor;
1856 control->traverse = gnc_split_register_traverse;
1862 gnc_split_register_recn_cell_confirm (
char old_flag, gpointer data)
1864 auto reg =
static_cast<SplitRegister*
>(data);
1865 GtkWidget *dialog, *window;
1867 const gchar *title = _(
"Mark split as unreconciled?");
1868 const gchar *message =
1869 _(
"You are about to mark a reconciled split as unreconciled. Doing " 1870 "so might make future reconciliation difficult! Continue " 1871 "with this change?");
1873 if (old_flag !=
YREC)
1877 window = gnc_split_register_get_parent (reg);
1878 dialog = gtk_message_dialog_new (GTK_WINDOW(window),
1879 GTK_DIALOG_DESTROY_WITH_PARENT,
1880 GTK_MESSAGE_WARNING,
1883 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
1885 gtk_dialog_add_button (GTK_DIALOG(dialog),
1888 response = gnc_dialog_run (GTK_DIALOG(dialog), GNC_PREF_WARN_REG_RECD_SPLIT_UNREC);
1889 gtk_widget_destroy (dialog);
1890 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.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
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.
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.
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.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
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.
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
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.
Account used to record multiple commodity transactions.
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.