dialog-payment.c (gnucash-5.0.tar.bz2) | : | dialog-payment.c (gnucash-5.1.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 1591 | skipping to change at line 1591 | |||
return split_str; | return split_str; | |||
} | } | |||
static Split *select_payment_split (GtkWindow *parent, Transaction *txn) | static Split *select_payment_split (GtkWindow *parent, Transaction *txn) | |||
{ | { | |||
/* We require the txn to have one split in an Asset account. | /* We require the txn to have one split in an Asset account. | |||
* The only exception would be a lot link transaction | * The only exception would be a lot link transaction | |||
*/ | */ | |||
GList *payment_splits = xaccTransGetPaymentAcctSplitList (txn); | GList *payment_splits = xaccTransGetPaymentAcctSplitList (txn); | |||
Split *selected_split = NULL; | ||||
if (!payment_splits) | if (!payment_splits) | |||
{ | { | |||
GtkWidget *dialog; | GtkWidget *dialog; | |||
if (xaccTransGetTxnType(txn) == TXN_TYPE_LINK) | if (xaccTransGetTxnType(txn) == TXN_TYPE_LINK) | |||
return NULL; | return NULL; | |||
dialog = gtk_message_dialog_new (parent, | dialog = gtk_message_dialog_new (parent, | |||
GTK_DIALOG_DESTROY_WITH_PARENT, | GTK_DIALOG_DESTROY_WITH_PARENT, | |||
GTK_MESSAGE_INFO, | GTK_MESSAGE_INFO, | |||
skipping to change at line 1613 | skipping to change at line 1614 | |||
_("The selected transaction doesn't hav e splits that can be assigned as a payment")); | _("The selected transaction doesn't hav e splits that can be assigned as a payment")); | |||
gtk_dialog_run (GTK_DIALOG(dialog)); | gtk_dialog_run (GTK_DIALOG(dialog)); | |||
gtk_widget_destroy (dialog); | gtk_widget_destroy (dialog); | |||
PINFO("No asset splits in txn \"%s\"; cannot use this for assigning a pa yment.", | PINFO("No asset splits in txn \"%s\"; cannot use this for assigning a pa yment.", | |||
xaccTransGetDescription(txn)); | xaccTransGetDescription(txn)); | |||
return NULL; | return NULL; | |||
} | } | |||
if (g_list_length(payment_splits) > 1) | if (g_list_length(payment_splits) > 1) | |||
{ | { | |||
Split *selected_split = NULL; | ||||
GList *node; | ||||
GtkWidget *first_rb = NULL; | GtkWidget *first_rb = NULL; | |||
int answer = GTK_BUTTONS_OK; | int answer = GTK_BUTTONS_OK; | |||
const char *message = _("While this transaction has multiple splits that can be considered\n" | const char *message = _("While this transaction has multiple splits that can be considered\n" | |||
"as 'the payment split', GnuCash only knows how to handle one.\n" | "as 'the payment split', GnuCash only knows how to handle one.\n" | |||
"Please select one, the others will be discarded .\n\n"); | "Please select one, the others will be discarded .\n\n"); | |||
GtkDialog *dialog = GTK_DIALOG( | GtkDialog *dialog = GTK_DIALOG( | |||
gtk_dialog_new_with_buttons (_("Warning"), | gtk_dialog_new_with_buttons (_("Warning"), | |||
parent, | parent, | |||
GTK_DIALOG_DESTROY_WITH _PARENT, | GTK_DIALOG_DESTROY_WITH _PARENT, | |||
_("Continue"), GTK_BUTT ONS_OK, | _("Continue"), GTK_BUTT ONS_OK, | |||
_("Cancel"), GTK_BUTTON S_CANCEL, | _("Cancel"), GTK_BUTTON S_CANCEL, | |||
NULL)); | NULL)); | |||
GtkWidget *content = gtk_dialog_get_content_area(dialog); | GtkWidget *content = gtk_dialog_get_content_area(dialog); | |||
GtkWidget *label = gtk_label_new (message); | GtkWidget *label = gtk_label_new (message); | |||
gtk_box_pack_start (GTK_BOX(content), label, FALSE, TRUE, 0); | gtk_box_pack_start (GTK_BOX(content), label, FALSE, TRUE, 0); | |||
/* Add splits as selectable options to the dialog */ | /* Add splits as selectable options to the dialog */ | |||
for (node = payment_splits; node; node = node->next) | for (GList *node = payment_splits; node; node = node->next) | |||
{ | { | |||
GtkWidget *rbutton; | GtkWidget *rbutton; | |||
Split *split = node->data; | Split *split = node->data; | |||
char *split_str = gen_split_desc (txn, split); | char *split_str = gen_split_desc (txn, split); | |||
if (node == payment_splits) | if (node == payment_splits) | |||
{ | { | |||
first_rb = gtk_radio_button_new_with_label (NULL, split_str); | first_rb = gtk_radio_button_new_with_label (NULL, split_str); | |||
rbutton = first_rb; | rbutton = first_rb; | |||
} | } | |||
skipping to change at line 1672 | skipping to change at line 1671 | |||
GtkWidget *rbutton = rbnode->data; | GtkWidget *rbutton = rbnode->data; | |||
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(rbutton))) | if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(rbutton))) | |||
{ | { | |||
selected_split = g_object_get_data(G_OBJECT(rbutton), "split "); | selected_split = g_object_get_data(G_OBJECT(rbutton), "split "); | |||
break; | break; | |||
} | } | |||
} | } | |||
} | } | |||
gtk_widget_destroy (GTK_WIDGET(dialog)); | gtk_widget_destroy (GTK_WIDGET(dialog)); | |||
return selected_split; | ||||
} | } | |||
else | else | |||
return payment_splits->data; | selected_split = payment_splits->data; | |||
g_list_free (payment_splits); | ||||
return selected_split; | ||||
} | } | |||
static GList *select_txn_lots (GtkWindow *parent, Transaction *txn, Account **po st_acct, gboolean *abort) | static GList *select_txn_lots (GtkWindow *parent, Transaction *txn, Account **po st_acct, gboolean *abort) | |||
{ | { | |||
SplitList *apar_splits = NULL; /* all spits in txn that are APAR type */ | SplitList *apar_splits = NULL; /* all spits in txn that are APAR type */ | |||
SplitList *apar_splits_no_lot = NULL; /* all splits in txn that are APAR typ e, but not tied to a lot */ | SplitList *apar_splits_no_lot = NULL; /* all splits in txn that are APAR typ e, but not tied to a lot */ | |||
SplitList *iter; | SplitList *iter; | |||
GList *txn_lots = NULL; | GList *txn_lots = NULL; | |||
GList *unique_apar_accts = NULL; | GList *unique_apar_accts = NULL; | |||
skipping to change at line 1719 | skipping to change at line 1720 | |||
{ | { | |||
PreExistLotInfo *lot_info = g_new0 (PreExistLotInfo, 1); | PreExistLotInfo *lot_info = g_new0 (PreExistLotInfo, 1); | |||
lot_info->lot = postlot; | lot_info->lot = postlot; | |||
lot_info->amount = xaccSplitGetValue (post_split); | lot_info->amount = xaccSplitGetValue (post_split); | |||
txn_lots = g_list_prepend (txn_lots, lot_info); | txn_lots = g_list_prepend (txn_lots, lot_info); | |||
*post_acct = apar_acct; | *post_acct = apar_acct; | |||
} | } | |||
else | else | |||
apar_splits_no_lot = g_list_prepend (apar_splits_no_lot, post_split) ; | apar_splits_no_lot = g_list_prepend (apar_splits_no_lot, post_split) ; | |||
} | } | |||
g_list_free (apar_splits); | ||||
/* If no post_acct was selected from the postlots, fall back to the first ap ar split's | /* If no post_acct was selected from the postlots, fall back to the first ap ar split's | |||
* account if there is one. */ | * account if there is one. */ | |||
if (!*post_acct && apar_splits_no_lot) | if (!*post_acct && apar_splits_no_lot) | |||
*post_acct = xaccSplitGetAccount (apar_splits_no_lot->data); | *post_acct = xaccSplitGetAccount (apar_splits_no_lot->data); | |||
g_list_free (apar_splits_no_lot); | ||||
/* Abort if the txn has splits in more than one APAR account | /* Abort if the txn has splits in more than one APAR account | |||
* GnuCash can only handle one post account per payment transaction. | * GnuCash can only handle one post account per payment transaction. | |||
*/ | */ | |||
if (g_list_length (unique_apar_accts) > 1) | if (g_list_length (unique_apar_accts) > 1) | |||
{ | { | |||
GtkWidget *dialog; | GtkWidget *dialog; | |||
char *split_str = g_strdup (""); | char *split_str = g_strdup (""); | |||
for (iter = unique_apar_accts; iter; iter = iter->next) | for (iter = unique_apar_accts; iter; iter = iter->next) | |||
skipping to change at line 1764 | skipping to change at line 1763 | |||
gtk_widget_destroy (dialog); | gtk_widget_destroy (dialog); | |||
PINFO("Multiple asset accounts in splits of txn \"%s\"; cannot use this for assigning a payment.", | PINFO("Multiple asset accounts in splits of txn \"%s\"; cannot use this for assigning a payment.", | |||
xaccTransGetDescription(txn)); | xaccTransGetDescription(txn)); | |||
g_free (split_str); | g_free (split_str); | |||
*abort = TRUE; | *abort = TRUE; | |||
g_list_free_full (txn_lots, g_free); | g_list_free_full (txn_lots, g_free); | |||
txn_lots = NULL; | txn_lots = NULL; | |||
} | } | |||
g_list_free (apar_splits); | ||||
g_list_free (apar_splits_no_lot); | ||||
g_list_free (unique_apar_accts); | ||||
return txn_lots; | return txn_lots; | |||
} | } | |||
PaymentWindow * gnc_ui_payment_new_with_txn (GtkWindow* parent, GncOwner *owner, Transaction *txn) | PaymentWindow * gnc_ui_payment_new_with_txn (GtkWindow* parent, GncOwner *owner, Transaction *txn) | |||
{ | { | |||
Split *payment_split = NULL; | Split *payment_split = NULL; | |||
Account *post_acct = NULL; | Account *post_acct = NULL; | |||
InitialPaymentInfo *tx_info = NULL; | InitialPaymentInfo *tx_info = NULL; | |||
GList *txn_lots = NULL; | GList *txn_lots = NULL; | |||
gboolean abort = FALSE; | gboolean abort = FALSE; | |||
skipping to change at line 1812 | skipping to change at line 1814 | |||
qof_instance_get_book(QOF_INSTANCE(txn)), | qof_instance_get_book(QOF_INSTANCE(txn)), | |||
tx_info); | tx_info); | |||
gnc_ui_payment_window_set_num(pw, gnc_get_num_action (txn, payment_split)); | gnc_ui_payment_window_set_num(pw, gnc_get_num_action (txn, payment_split)); | |||
gnc_ui_payment_window_set_memo(pw, xaccTransGetDescription(txn)); | gnc_ui_payment_window_set_memo(pw, xaccTransGetDescription(txn)); | |||
{ | { | |||
GDate txn_date = xaccTransGetDatePostedGDate (txn); | GDate txn_date = xaccTransGetDatePostedGDate (txn); | |||
gnc_ui_payment_window_set_date(pw, &txn_date); | gnc_ui_payment_window_set_date(pw, &txn_date); | |||
} | } | |||
gnc_ui_payment_window_set_amount(pw, xaccSplitConvertAmount (payment_split, | gnc_numeric amount = xaccSplitGetAmount (payment_split); | |||
post_acct)); | /* Note: at this point post account selected in newly created payment dialog | |||
* may differ from what we got from select_txn_lots above. | ||||
* Use the dialog's post account commodity to optionally convert the amount | ||||
* to to display to the user */ | ||||
if (pw->post_acct) | ||||
amount = xaccSplitConvertAmount (payment_split, pw->post_acct); | ||||
gnc_ui_payment_window_set_amount(pw, amount); | ||||
if (payment_split) | if (payment_split) | |||
gnc_ui_payment_window_set_xferaccount(pw, xaccSplitGetAccount(payment_sp lit)); | gnc_ui_payment_window_set_xferaccount(pw, xaccSplitGetAccount(payment_sp lit)); | |||
return pw; | return pw; | |||
} | } | |||
End of changes. 9 change blocks. | ||||
9 lines changed or deleted | 17 lines changed or added |