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);
712 gnc_find_split_in_account_by_memo (
Account *account,
const char *memo,
715 if (account ==
nullptr)
return nullptr;
717 const auto& splits = xaccAccountGetSplits (account);
718 for (
auto it = splits.rbegin(); it != splits.rend(); it++)
727 gnc_find_split_in_reg_by_memo (SplitRegister *reg,
const char *memo,
730 int virt_row, virt_col;
731 int num_rows, num_cols;
732 Transaction *last_trans;
734 if (!reg || !reg->table)
737 num_rows = reg->table->num_virt_rows;
738 num_cols = reg->table->num_virt_cols;
742 for (virt_row = num_rows - 1; virt_row >= 0; virt_row--)
743 for (virt_col = num_cols - 1; virt_col >= 0; virt_col--)
747 VirtualCellLocation vcell_loc = { virt_row, virt_col };
749 split = gnc_split_register_get_split (reg, vcell_loc);
752 if (trans == last_trans)
755 split = gnc_find_split_in_trans_by_memo (trans, memo, unit_price);
766 gnc_find_trans_in_reg_by_desc (SplitRegister *reg,
const char *description)
768 int virt_row, virt_col;
769 int num_rows, num_cols;
770 Transaction *last_trans;
772 if (!reg || !reg->table)
775 num_rows = reg->table->num_virt_rows;
776 num_cols = reg->table->num_virt_cols;
780 for (virt_row = num_rows - 1; virt_row >= 0; virt_row--)
781 for (virt_col = num_cols - 1; virt_col >= 0; virt_col--)
785 VirtualCellLocation vcell_loc = { virt_row, virt_col };
787 split = gnc_split_register_get_split (reg, vcell_loc);
790 if (trans == last_trans)
805 gnc_split_register_auto_completion (SplitRegister *reg,
806 gncTableTraversalDir dir,
807 VirtualLocation *p_new_virt_loc)
809 SRInfo *info = gnc_split_register_get_info (reg);
810 VirtualLocation new_virt_loc;
812 Transaction *pending_trans;
813 Transaction *blank_trans;
814 const char *cell_name;
821 if (!reg->do_auto_complete)
825 gnc_get_current_book ());
829 gnc_get_current_book ());
832 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
841 cell_name = gnc_table_get_current_cell_name (reg->table);
843 switch (cursor_class)
845 case CURSOR_CLASS_TRANS:
847 Transaction *auto_trans;
851 if (blank_trans == NULL)
855 if (trans != blank_trans)
859 if (!gnc_cell_name_equal (cell_name, DESC_CELL))
864 if (gnc_table_layout_get_cell_changed (reg->table->layout,
866 gnc_table_layout_get_cell_changed (reg->table->layout,
868 gnc_table_layout_get_cell_changed (reg->table->layout,
870 gnc_table_layout_get_cell_changed (reg->table->layout,
872 gnc_table_layout_get_cell_changed (reg->table->layout,
874 gnc_table_layout_get_cell_changed (reg->table->layout,
876 gnc_table_layout_get_cell_changed (reg->table->layout,
878 gnc_table_layout_get_cell_changed (reg->table->layout,
883 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
888 desc = gnc_table_layout_get_cell_value (reg->table->layout, DESC_CELL);
889 if ((desc == NULL) || (*desc ==
'\0'))
893 if (gnc_split_register_get_default_account (reg) != NULL)
895 Account *account = gnc_split_register_get_default_account (reg);
900 auto_trans = gnc_find_trans_in_reg_by_desc (reg, desc);
902 if (auto_trans == NULL)
905 gnc_suspend_gui_refresh ();
911 if (pending_trans != trans)
917 if (pending_trans != NULL)
921 else g_assert_not_reached ();
926 gnc_get_current_book ());
927 g_assert (pending_trans == trans);
935 if (gnc_split_register_get_default_account (reg) != NULL)
937 Account *default_account = gnc_split_register_get_default_account (reg);
946 auto s = GNC_SPLIT(n->data);
956 if (blank_split == NULL)
961 DEBUG(
"blank_split=%p", blank_split);
963 info->blank_split_edited = TRUE;
968 sd = gnc_split_register_save_data_new (trans, blank_split,
970 gnc_table_save_cells (reg->table, sd);
971 gnc_split_register_save_data_destroy (sd);
974 gnc_resume_gui_refresh ();
978 GNC_PREF_TAB_TRANS_MEMORISED))
983 if (gnc_table_get_current_cell_location (reg->table, cell_name, &new_virt_loc))
984 *p_new_virt_loc = new_virt_loc;
990 case CURSOR_CLASS_SPLIT:
1002 if (!gnc_cell_name_equal (cell_name, MEMO_CELL))
1007 if (gnc_table_layout_get_cell_changed (reg->table->layout,
1009 gnc_table_layout_get_cell_changed (reg->table->layout,
1010 MXFRM_CELL, TRUE) ||
1011 gnc_table_layout_get_cell_changed (reg->table->layout,
1013 gnc_table_layout_get_cell_changed (reg->table->layout,
1015 gnc_table_layout_get_cell_changed (reg->table->layout,
1020 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1025 memo = gnc_table_layout_get_cell_value (reg->table->layout, MEMO_CELL);
1026 if ((memo == NULL) || (*memo ==
'\0'))
1031 unit_price = !gnc_table_get_current_cell_location (reg->table,
1035 if (gnc_split_register_get_default_account (reg) != NULL)
1037 Account *account = gnc_split_register_get_default_account (reg);
1039 auto_split = gnc_find_split_in_account_by_memo (account, memo,
1043 auto_split = gnc_find_split_in_reg_by_memo (reg, memo, unit_price);
1045 if (auto_split == NULL)
1051 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1054 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1055 gnc_combo_cell_set_value ((
ComboCell *) cell,
1056 gnc_get_num_action (NULL, auto_split));
1060 cell = gnc_table_layout_get_cell (reg->table->layout, XFRM_CELL);
1063 reg->show_leaf_accounts);
1064 gnc_combo_cell_set_value ((
ComboCell *) cell, account_name);
1065 g_free (account_name);
1067 gnc_basic_cell_set_changed (cell, TRUE);
1069 if (!gnc_table_layout_get_cell_changed (reg->table->layout,
1071 !gnc_table_layout_get_cell_changed (reg->table->layout,
1074 BasicCell *debit_cell;
1075 BasicCell *credit_cell;
1079 debit_cell = gnc_table_layout_get_cell (reg->table->layout,
1081 credit_cell = gnc_table_layout_get_cell (reg->table->layout,
1088 gnc_basic_cell_set_changed (debit_cell, TRUE);
1089 gnc_basic_cell_set_changed (credit_cell, TRUE);
1099 if (gnc_table_get_current_cell_location (reg->table, cell_name,
1101 *p_new_virt_loc = new_virt_loc;
1114 gnc_split_register_check_stock_action (SplitRegister *reg,
1115 const char *cell_name)
1122 if (!gnc_cell_name_equal (cell_name, ACTN_CELL) ||
1123 !gnc_table_layout_get_cell_changed (reg->table->layout,
1127 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1131 if ((name == NULL) || (*name ==
'\0'))
1134 buy = g_strcmp0 (name, ACTION_BUY_STR) == 0;
1135 sell = g_strcmp0 (name, ACTION_SELL_STR) == 0;
1139 cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
1148 gnc_basic_cell_set_changed (cell, TRUE);
1153 gnc_split_register_check_stock_shares (SplitRegister *reg,
1154 const char *cell_name)
1161 if (!gnc_cell_name_equal (cell_name, SHRS_CELL) ||
1162 !gnc_table_layout_get_cell_changed (reg->table->layout,
1166 cell = gnc_table_layout_get_cell (reg->table->layout, SHRS_CELL);
1174 cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
1179 if (!g_strcmp0 (name,
"") ||
1180 !g_strcmp0 (name, buy ? ACTION_SELL_STR : ACTION_BUY_STR))
1182 gnc_combo_cell_set_value ((
ComboCell *)cell,
1183 buy ? ACTION_BUY_STR : ACTION_SELL_STR);
1184 gnc_basic_cell_set_changed (cell, TRUE);
1194 gnc_split_register_check_cell (SplitRegister *reg,
const char *cell_name)
1196 ENTER(
"reg=%p, cell_name=%s", reg, cell_name ? cell_name :
"NULL");
1199 if (!gnc_split_register_check_account (reg, cell_name))
1201 LEAVE(
"account check failed");
1206 if (!gnc_split_register_check_debcred (reg, cell_name))
1208 LEAVE(
"debit/credit check failed");
1213 if ((reg->type == STOCK_REGISTER) ||
1214 (reg->type == PORTFOLIO_LEDGER) ||
1215 (reg->type == CURRENCY_REGISTER))
1217 gnc_split_register_check_stock_action (reg, cell_name);
1218 gnc_split_register_check_stock_shares (reg, cell_name);
1226 gnc_split_register_get_account_always (SplitRegister *reg,
1227 const char *cell_name)
1232 cell = gnc_table_layout_get_cell (reg->table->layout, cell_name);
1235 name = gnc_basic_cell_get_value (cell);
1239 if (!g_strcmp0 (name, SPLIT_TRANS_STR))
1242 return gnc_split_register_get_account_by_name (reg, cell, name);
1249 gnc_split_register_xfer_dialog (SplitRegister *reg, Transaction *txn,
1256 g_return_val_if_fail (reg, NULL);
1257 g_return_val_if_fail (reg->table, NULL);
1259 cur = reg->table->current_cursor;
1262 xfer = gnc_xfer_dialog (gnc_split_register_get_parent (reg), NULL);
1263 g_return_val_if_fail (xfer, NULL);
1268 gnc_xfer_dialog_set_description (xfer, gnc_basic_cell_get_value (cell));
1272 gnc_xfer_dialog_set_description (xfer, str ? str :
"");
1278 gnc_xfer_dialog_set_memo (xfer, gnc_basic_cell_get_value (cell));
1282 gnc_xfer_dialog_set_memo (xfer, str ? str :
"");
1288 gnc_xfer_dialog_set_num (xfer, gnc_basic_cell_get_value (cell));
1291 const char *str = gnc_get_num_action (txn, split);
1292 gnc_xfer_dialog_set_num (xfer, str ? str :
"");
1301 gnc_xfer_dialog_set_date (xfer, time);
1322 Split *split, *osplit;
1324 gnc_commodity *txn_cur, *xfer_com, *reg_com;
1325 gnc_numeric amount, exch_rate;
1327 gboolean expanded = FALSE;
1329 const char *message;
1332 ENTER(
"reg=%p, force_dialog=%s", reg, force_dialog ?
"TRUE" :
"FALSE" );
1335 if (reg->is_template)
1337 LEAVE(
"Template transaction, rate makes no sense.");
1346 message = _(
"This register does not support editing exchange rates.");
1347 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1349 LEAVE(
"no rate cell");
1353 rate_cell = (
PriceCell*) gnc_table_layout_get_cell (reg->table->layout, RATE_CELL);
1359 message = _(
"This register does not support editing exchange rates.");
1360 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1362 LEAVE(
"null rate cell");
1367 info = gnc_split_register_get_info (reg);
1370 info->rate_reset != RATE_RESET_REQD)
1372 LEAVE(
"rate already non-zero");
1381 if (expanded && cursor_class == CURSOR_CLASS_TRANS)
1385 message = _(
"You need to select a split in order to modify its exchange " 1387 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1389 LEAVE(
"expanded with transaction cursor; nothing to do");
1394 xfer_acc = gnc_split_register_get_account_always (reg,
1395 expanded ? XFRM_CELL : MXFRM_CELL);
1398 if (force_dialog && !expanded && !xfer_acc)
1400 message = _(
"You need to expand the transaction in order to modify its " 1402 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1403 LEAVE(
"%s", message);
1412 message = _(
"The entered account could not be found.");
1413 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1415 LEAVE(
"no xfer account");
1425 reg_acc = gnc_split_register_get_default_account (reg);
1440 LEAVE(
"txn and account currencies match, and not forcing");
1445 if (expanded || osplit == NULL)
1447 message = _(
"The two currencies involved equal each other.");
1448 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1449 LEAVE(
"register is expanded or osplit == NULL; not forcing dialog");
1460 message = _(
"The two currencies involved equal each other.");
1461 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1462 LEAVE(
"reg commodity == txn commodity; not forcing");
1471 if (!expanded && osplit &&
1472 gnc_split_register_split_needs_amount (reg, split) &&
1473 gnc_split_register_split_needs_amount (reg, osplit))
1475 message = _(
"You need to expand the transaction in order to modify its " 1479 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1481 LEAVE(
"%s", message);
1492 if (!expanded && osplit &&
1502 amount = gnc_split_register_debcred_cell_value (reg);
1512 message = _(
"The split's amount is zero, so no exchange rate is needed.");
1513 gnc_error_dialog (GTK_WINDOW(gnc_split_register_get_parent (reg)),
"%s", message);
1515 LEAVE(
"amount is zero; no exchange rate needed");
1524 info->rate_reset != RATE_RESET_REQD &&
1527 LEAVE(
"gain/loss split; no exchange rate needed");
1532 xfer = gnc_split_register_xfer_dialog (reg, txn, split);
1533 gnc_xfer_dialog_is_exchange_dialog (xfer, &exch_rate);
1534 if (gnc_xfer_dialog_run_exchange_dialog (xfer, &exch_rate, amount,
1535 reg_acc, txn, xfer_com, expanded))
1538 LEAVE(
"leaving rate unchanged");
1545 gnc_basic_cell_set_changed (&rate_cell->cell, TRUE);
1546 info->rate_account = xfer_acc;
1547 info->rate_reset = RATE_RESET_DONE;
1554 transaction_changed_confirm (VirtualLocation *p_new_virt_loc,
1555 VirtualLocation *virt_loc,
1556 SplitRegister *reg, Transaction *new_trans,
1557 gboolean exact_traversal)
1559 GtkWidget *dialog, *window;
1561 const char *title = _(
"Save the changed transaction?");
1562 const char *message =
1563 _(
"The current transaction has been changed. Would you like to " 1564 "record the changes before moving to a new transaction, discard the " 1565 "changes, or return to the changed transaction?");
1567 window = gnc_split_register_get_parent (reg);
1568 dialog = gtk_message_dialog_new (GTK_WINDOW(window),
1569 GTK_DIALOG_DESTROY_WITH_PARENT,
1570 GTK_MESSAGE_QUESTION,
1573 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
1575 gtk_dialog_add_buttons (GTK_DIALOG(dialog),
1576 _(
"_Discard Changes"), GTK_RESPONSE_REJECT,
1577 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
1578 _(
"_Record Changes"), GTK_RESPONSE_ACCEPT,
1580 response = gnc_dialog_run (GTK_DIALOG(dialog), GNC_PREF_WARN_REG_TRANS_MOD);
1581 gtk_widget_destroy (dialog);
1585 case GTK_RESPONSE_ACCEPT:
1588 case GTK_RESPONSE_REJECT:
1590 VirtualCellLocation vcell_loc;
1596 if (reg->unrecn_splits != NULL)
1598 g_list_free (reg->unrecn_splits);
1599 reg->unrecn_splits = NULL;
1602 new_split = gnc_split_register_get_split (reg, virt_loc->vcell_loc);
1603 trans_split = gnc_split_register_get_trans_split (reg,
1604 virt_loc->vcell_loc,
1607 virt_loc->vcell_loc);
1611 if (gnc_split_register_find_split (reg, new_trans, trans_split,
1612 new_split, new_class, &vcell_loc))
1613 virt_loc->vcell_loc = vcell_loc;
1618 *p_new_virt_loc = *virt_loc;
1622 case GTK_RESPONSE_CANCEL:
1643 gnc_split_register_traverse (VirtualLocation *p_new_virt_loc,
1644 gncTableTraversalDir dir,
1647 auto reg =
static_cast<SplitRegister*
>(user_data);
1648 Transaction *pending_trans;
1649 VirtualLocation virt_loc;
1650 Transaction *trans, *new_trans;
1654 const char *cell_name;
1656 g_return_val_if_fail (p_new_virt_loc, TRUE);
1658 ENTER(
"reg=%p, p_new_virt_loc=%p (%d,%d), dir=%d",
1659 reg, p_new_virt_loc,
1660 (*p_new_virt_loc).vcell_loc.virt_row,
1661 (*p_new_virt_loc).vcell_loc.virt_col, dir);
1665 LEAVE(
"no register");
1669 info = gnc_split_register_get_info (reg);
1671 if (info->first_pass)
1673 LEAVE(
"first pass");
1678 gnc_get_current_book ());
1679 virt_loc = *p_new_virt_loc;
1681 info->exact_traversal = (dir == GNC_TABLE_TRAVERSE_POINTER);
1687 LEAVE(
"no transaction");
1692 changed = gnc_table_current_cursor_changed (reg->table, FALSE);
1693 if (!changed && (pending_trans != trans))
1696 info->exact_traversal);
1698 *p_new_virt_loc = virt_loc;
1700 LEAVE(
"no changes");
1705 cell_name = gnc_table_get_current_cell_name (reg->table);
1706 if (!gnc_split_register_check_cell (reg, cell_name))
1708 LEAVE(
"check cell");
1715 VirtualLocation virt_loc;
1717 if (!changed && !info->blank_split_edited)
1720 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
1723 virt_loc = reg->table->current_cursor_loc;
1727 virt_loc = reg->table->current_cursor_loc;
1728 if (gnc_table_move_tab (reg->table, &virt_loc, TRUE))
1734 LEAVE(
"no exchange rate");
1738 *p_new_virt_loc = reg->table->current_cursor_loc;
1739 (p_new_virt_loc->vcell_loc.virt_row)++;
1740 p_new_virt_loc->phys_row_offset = 0;
1741 p_new_virt_loc->phys_col_offset = 0;
1743 info->traverse_to_new = TRUE;
1745 LEAVE(
"off end of last line");
1755 if (gnc_split_register_auto_completion (reg, dir, p_new_virt_loc))
1757 info->auto_complete = TRUE;
1758 LEAVE(
"auto-complete");
1766 VirtualLocation virt_loc;
1775 if (dir != GNC_TABLE_TRAVERSE_RIGHT)
1778 virt_loc = reg->table->current_cursor_loc;
1779 old_virt_row = virt_loc.vcell_loc.virt_row;
1781 if (gnc_table_move_tab (reg->table, &virt_loc, TRUE) &&
1782 old_virt_row == virt_loc.vcell_loc.virt_row)
1795 LEAVE(
"no exchange rate");
1799 info->cursor_hint_trans = trans;
1800 info->cursor_hint_split = split;
1801 info->cursor_hint_trans_split =
1803 info->cursor_hint_cursor_class = CURSOR_CLASS_SPLIT;
1804 info->hint_set_by_traverse = TRUE;
1806 LEAVE(
"off end of blank split");
1813 int old_virt_row = reg->table->current_cursor_loc.vcell_loc.virt_row;
1817 info->exact_traversal);
1821 if (virt_loc.vcell_loc.virt_row != old_virt_row)
1825 LEAVE(
"no exchange rate");
1832 new_trans = gnc_split_register_get_trans (reg, virt_loc.vcell_loc);
1833 if (trans == new_trans)
1835 *p_new_virt_loc = virt_loc;
1837 LEAVE(
"staying within txn");
1844 LEAVE(
"txn change");
1845 return transaction_changed_confirm (p_new_virt_loc, &virt_loc, reg,
1846 new_trans, info->exact_traversal);
1854 control->move_cursor = gnc_split_register_move_cursor;
1855 control->traverse = gnc_split_register_traverse;
1861 gnc_split_register_recn_cell_confirm (
char old_flag, gpointer data)
1863 auto reg =
static_cast<SplitRegister*
>(data);
1864 GtkWidget *dialog, *window;
1866 const gchar *title = _(
"Mark split as unreconciled?");
1867 const gchar *message =
1868 _(
"You are about to mark a reconciled split as unreconciled. Doing " 1869 "so might make future reconciliation difficult! Continue " 1870 "with this change?");
1872 if (old_flag !=
YREC)
1876 window = gnc_split_register_get_parent (reg);
1877 dialog = gtk_message_dialog_new (GTK_WINDOW(window),
1878 GTK_DIALOG_DESTROY_WITH_PARENT,
1879 GTK_MESSAGE_WARNING,
1882 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
1884 gtk_dialog_add_button (GTK_DIALOG(dialog),
1887 response = gnc_dialog_run (GTK_DIALOG(dialog), GNC_PREF_WARN_REG_RECD_SPLIT_UNREC);
1888 gtk_widget_destroy (dialog);
1889 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_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.