diff --git a/src/gnome/dialog-print-check.c b/src/gnome/dialog-print-check.c index b58ae8f6bc..0afe53ed79 100644 --- a/src/gnome/dialog-print-check.c +++ b/src/gnome/dialog-print-check.c @@ -381,31 +381,29 @@ gchar * get_check_splits_amount(PrintCheckDialog *pcd) { gchar* amount = NULL; - gchar* amt_temp; - int cnt; - const gchar* split_amount; - int nSplits; Transaction *trans; - Split *split; GList *node; SplitList* s_list; trans = xaccSplitGetParent(pcd->split); - nSplits = xaccTransCountSplits(trans); s_list = xaccTransGetSplitList(trans); if ( !s_list ) return NULL; amount = g_strconcat("", NULL); node = s_list; - cnt = 1; - while ( cnt < nSplits ) + while ( node ) { - cnt++; - split = node->data; - split_amount = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE)); - amt_temp = amount; - amount = g_strconcat(amt_temp, "\n", split_amount, NULL); - g_free(amt_temp); + Split *split = node->data; + /* Include all splits except the main split for the check */ + if (split != pcd->split) + { + const gchar* split_amount; + gchar* amt_temp; + split_amount = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE)); + amt_temp = amount; + amount = g_strconcat(amt_temp, "\n", split_amount, NULL); + g_free(amt_temp); + } node = node->next; } return amount; @@ -418,31 +416,29 @@ gchar * get_check_splits_memo(PrintCheckDialog *pcd) { gchar* memo = NULL; - gchar* memo_temp; - int cnt; const gchar* split_memo; - int nSplits; Transaction *trans; - Split *split; GList *node; SplitList* s_list; trans = xaccSplitGetParent(pcd->split); - nSplits = xaccTransCountSplits(trans); s_list = xaccTransGetSplitList(trans); if ( !s_list ) return NULL; memo = g_strconcat("", NULL); node = s_list; - cnt = 1; - while ( cnt < nSplits ) + while ( node ) { - cnt++; - split = node->data; - split_memo = xaccSplitGetMemo(split); - memo_temp = memo; - memo = g_strconcat(memo_temp, "\n", split_memo, NULL); - g_free(memo_temp); + Split *split = node->data; + /* Include all splits except the main split for the check */ + if (split != pcd->split) + { + gchar* memo_temp; + split_memo = xaccSplitGetMemo(split); + memo_temp = memo; + memo = g_strconcat(memo_temp, "\n", split_memo, NULL); + g_free(memo_temp); + } node = node->next; } return memo; @@ -455,33 +451,31 @@ gchar * get_check_splits_account(PrintCheckDialog *pcd) { gchar* account = NULL; - gchar* account_temp; - int cnt; - const gchar* aName = NULL; - int nSplits; - Account *pAccount; Transaction *trans; - Split *split; GList *node; SplitList* s_list; trans = xaccSplitGetParent(pcd->split); - nSplits = xaccTransCountSplits(trans); s_list = xaccTransGetSplitList(trans); if ( !s_list ) return NULL; account = g_strconcat("", NULL); node = s_list; - cnt = 1; - while ( cnt < nSplits ) + while ( node ) { - cnt++; - split = node->data; - pAccount = xaccSplitGetAccount(split); - aName = gnc_get_account_name_for_register(pAccount); - account_temp = account; - account = g_strconcat(account_temp, "\n", aName, NULL); - g_free(account_temp); + Split *split = node->data; + /* Include all splits except the main split for the check */ + if (split != pcd->split) + { + gchar* account_temp; + const gchar* aName = NULL; + Account *pAccount; + pAccount = xaccSplitGetAccount(split); + aName = gnc_get_account_name_for_register(pAccount); + account_temp = account; + account = g_strconcat(account_temp, "\n", aName, NULL); + g_free(account_temp); + } node = node->next; } return account; diff --git a/src/gnome/dialog-print-check2.c b/src/gnome/dialog-print-check2.c index f39a5bd730..812e2efb6e 100644 --- a/src/gnome/dialog-print-check2.c +++ b/src/gnome/dialog-print-check2.c @@ -381,31 +381,29 @@ gchar * get_check_splits_amount2(PrintCheckDialog *pcd) { gchar* amount = NULL; - gchar* amt_temp; - int cnt; - const gchar* split_amount; - int nSplits; Transaction *trans; - Split *split; GList *node; SplitList* s_list; trans = xaccSplitGetParent(pcd->split); - nSplits = xaccTransCountSplits(trans); s_list = xaccTransGetSplitList(trans); if ( !s_list ) return NULL; amount = g_strconcat("", NULL); node = s_list; - cnt = 1; - while ( cnt < nSplits ) + while ( node ) { - cnt++; - split = node->data; - split_amount = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE)); - amt_temp = amount; - amount = g_strconcat(amt_temp, "\n", split_amount, NULL); - g_free(amt_temp); + Split *split = node->data; + /* Include all splits except the main split for the check */ + if (split != pcd->split) + { + const gchar* split_amount; + gchar* amt_temp; + split_amount = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE)); + amt_temp = amount; + amount = g_strconcat(amt_temp, "\n", split_amount, NULL); + g_free(amt_temp); + } node = node->next; } return amount; @@ -418,31 +416,29 @@ gchar * get_check_splits_memo2(PrintCheckDialog *pcd) { gchar* memo = NULL; - gchar* memo_temp; - int cnt; const gchar* split_memo; - int nSplits; Transaction *trans; - Split *split; GList *node; SplitList* s_list; trans = xaccSplitGetParent(pcd->split); - nSplits = xaccTransCountSplits(trans); s_list = xaccTransGetSplitList(trans); if ( !s_list ) return NULL; memo = g_strconcat("", NULL); node = s_list; - cnt = 1; - while ( cnt < nSplits ) + while ( node ) { - cnt++; - split = node->data; - split_memo = xaccSplitGetMemo(split); - memo_temp = memo; - memo = g_strconcat(memo_temp, "\n", split_memo, NULL); - g_free(memo_temp); + Split *split = node->data; + /* Include all splits except the main split for the check */ + if (split != pcd->split) + { + gchar* memo_temp; + split_memo = xaccSplitGetMemo(split); + memo_temp = memo; + memo = g_strconcat(memo_temp, "\n", split_memo, NULL); + g_free(memo_temp); + } node = node->next; } return memo; @@ -455,33 +451,31 @@ gchar * get_check_splits_account2(PrintCheckDialog *pcd) { gchar* account = NULL; - gchar* account_temp; - int cnt; - const gchar* aName = NULL; - int nSplits; - Account *pAccount; Transaction *trans; - Split *split; GList *node; SplitList* s_list; trans = xaccSplitGetParent(pcd->split); - nSplits = xaccTransCountSplits(trans); s_list = xaccTransGetSplitList(trans); if ( !s_list ) return NULL; account = g_strconcat("", NULL); node = s_list; - cnt = 1; - while ( cnt < nSplits ) + while ( node ) { - cnt++; - split = node->data; - pAccount = xaccSplitGetAccount(split); - aName = gnc_get_account_name_for_register(pAccount); - account_temp = account; - account = g_strconcat(account_temp, "\n", aName, NULL); - g_free(account_temp); + Split *split = node->data; + /* Include all splits except the main split for the check */ + if (split != pcd->split) + { + gchar* account_temp; + const gchar* aName = NULL; + Account *pAccount; + pAccount = xaccSplitGetAccount(split); + aName = gnc_get_account_name_for_register(pAccount); + account_temp = account; + account = g_strconcat(account_temp, "\n", aName, NULL); + g_free(account_temp); + } node = node->next; } return account; diff --git a/src/gnome/gnc-plugin-page-register.c b/src/gnome/gnc-plugin-page-register.c index 180fc588b4..c7f7bee293 100644 --- a/src/gnome/gnc-plugin-page-register.c +++ b/src/gnome/gnc-plugin-page-register.c @@ -2696,6 +2696,7 @@ gnc_plugin_page_register_cmd_print_check (GtkAction *action, Transaction * trans; GList * splits = NULL, *item; GNCLedgerDisplayType ledger_type; + Account * account; ENTER("(action %p, plugin_page %p)", action, plugin_page); @@ -2706,14 +2707,30 @@ gnc_plugin_page_register_cmd_print_check (GtkAction *action, ledger_type = gnc_ledger_display_type(priv->ledger); if (ledger_type == LD_SINGLE || ledger_type == LD_SUBACCOUNT) { + account = gnc_plugin_page_register_get_account (plugin_page); split = gnc_split_register_get_current_split(reg); trans = xaccSplitGetParent(split); if (split && trans) { - splits = g_list_append(splits, split); - gnc_ui_print_check_dialog_create(plugin_page, splits); - g_list_free(splits); + if (xaccSplitGetAccount(split) == account) + { + splits = g_list_append(splits, split); + gnc_ui_print_check_dialog_create(plugin_page, splits); + g_list_free(splits); + } + else + { + /* This split is not for the account shown in this register. Get the + split that anchors the transaction to the registor */ + split = gnc_split_register_get_current_trans_split(reg, NULL); + if (split) + { + splits = g_list_append(splits, split); + gnc_ui_print_check_dialog_create(plugin_page, splits); + g_list_free(splits); + } + } } } else if (ledger_type == LD_GL && reg->type == SEARCH_LEDGER) diff --git a/src/gnome/gnc-plugin-page-register2.c b/src/gnome/gnc-plugin-page-register2.c index 3eef99208b..3cc5f95d5e 100644 --- a/src/gnome/gnc-plugin-page-register2.c +++ b/src/gnome/gnc-plugin-page-register2.c @@ -2543,6 +2543,7 @@ gnc_plugin_page_register2_cmd_print_check (GtkAction *action, Transaction * trans; GList * splits = NULL, *item; GNCLedgerDisplay2Type ledger_type; + Account * account; ENTER("(action %p, plugin_page %p)", action, plugin_page); @@ -2555,6 +2556,7 @@ gnc_plugin_page_register2_cmd_print_check (GtkAction *action, if (ledger_type == LD2_SINGLE || ledger_type == LD2_SUBACCOUNT) { + account = gnc_plugin_page_register2_get_account (plugin_page); split = gnc_tree_view_split_reg_get_current_split (view); trans = xaccSplitGetParent (split); @@ -2587,9 +2589,24 @@ gnc_plugin_page_register2_cmd_print_check (GtkAction *action, if (split && trans) { - splits = g_list_append (splits, split); - gnc_ui_print_check_dialog_create2 (plugin_page, splits); - g_list_free (splits); + if (xaccSplitGetAccount(split) == account) + { + splits = g_list_append(splits, split); + gnc_ui_print_check_dialog_create2 (plugin_page, splits); + g_list_free(splits); + } + else + { + /* This split is not for the account shown in this register. Get the + split for that account and use it. */ + split = gnc_tree_model_split_reg_trans_get_split_equal_to_ancestor(trans, account); + if (split) + { + splits = g_list_append(splits, split); + gnc_ui_print_check_dialog_create2 (plugin_page, splits); + g_list_free(splits); + } + } } } else if (ledger_type == LD2_GL && model->type == SEARCH_LEDGER2)