diff --git a/src/business/business-gnome/dialog-payment.c b/src/business/business-gnome/dialog-payment.c
index f2cfc8a50d..11b0c3ee9e 100644
--- a/src/business/business-gnome/dialog-payment.c
+++ b/src/business/business-gnome/dialog-payment.c
@@ -51,6 +51,7 @@
#include "business-gnome-utils.h"
#include "dialog-transfer.h"
+#include "dialog-print-check.h"
#include "gnome-search/gnc-general-search.h"
#define DIALOG_PAYMENT_CUSTOMER_CM_CLASS "customer-payment-dialog"
@@ -72,6 +73,7 @@ struct _payment_window
GtkWidget * acct_tree;
GtkWidget * docs_list_tree_view;
GtkWidget * commodity_label;
+ GtkWidget * print_check;
gint component_id;
QofBook * book;
@@ -84,6 +86,7 @@ struct _payment_window
GList * acct_commodities;
Transaction * pre_existing_txn;
+ gboolean print_check_state;
};
void gnc_ui_payment_window_set_num (PaymentWindow *pw, const char* num)
@@ -236,6 +239,16 @@ gnc_payment_window_check_payment (PaymentWindow *pw)
update_cleanup:
gtk_widget_set_sensitive (pw->acct_tree, enable_xfer_acct);
+ /* Disable "Print Check" widget if amount is zero but save current
+ state to restore when the widget is re-enabled */
+ if (gtk_widget_is_sensitive (pw->print_check))
+ pw->print_check_state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(pw->print_check));
+ if (!enable_xfer_acct)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pw->print_check), FALSE);
+ gtk_widget_set_sensitive (pw->print_check, enable_xfer_acct);
+ if (gtk_widget_is_sensitive (pw->print_check))
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(pw->print_check), pw->print_check_state);
+
/* Check if there are issues preventing a successful payment */
gtk_widget_set_tooltip_text (pw->payment_warning, conflict_msg);
if (conflict_msg)
@@ -736,15 +749,24 @@ gnc_payment_ok_cb (GtkWidget *widget, gpointer data)
else
auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY);
- gncOwnerApplyPayment (&pw->owner, pw->pre_existing_txn, selected_lots,
- pw->post_acct, pw->xfer_acct, pw->amount_tot,
- exch, date, memo, num, auto_pay);
+ gncOwnerApplyPayment (&pw->owner, &(pw->pre_existing_txn), selected_lots,
+ pw->post_acct, pw->xfer_acct, pw->amount_tot, exch,
+ date, memo, num, auto_pay);
}
gnc_resume_gui_refresh ();
/* Save the transfer account, xfer_acct */
gnc_payment_dialog_remember_account(pw, pw->xfer_acct);
+ if (gtk_widget_is_sensitive (pw->print_check) &&
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(pw->print_check)))
+ {
+ Split *split = xaccTransFindSplitByAccount (pw->pre_existing_txn, pw->xfer_acct);
+ GList *splits = NULL;
+ splits = g_list_append(splits, split);
+ gnc_ui_print_check_dialog_create(NULL, splits);
+ }
+
gnc_ui_payment_window_destroy (pw);
}
@@ -975,6 +997,7 @@ new_payment_window (GncOwner *owner, QofBook *book, GncInvoice *invoice)
box = GTK_WIDGET (gtk_builder_get_object (builder, "date_box"));
pw->date_edit = gnc_date_edit_new (time(NULL), FALSE, FALSE);
gtk_box_pack_start (GTK_BOX (box), pw->date_edit, TRUE, TRUE, 0);
+ pw->print_check = GTK_WIDGET (gtk_builder_get_object (builder, "print_check"));
pw->docs_list_tree_view = GTK_WIDGET (gtk_builder_get_object (builder, "docs_list_tree_view"));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(pw->docs_list_tree_view));
diff --git a/src/business/business-gnome/gtkbuilder/dialog-payment.glade b/src/business/business-gnome/gtkbuilder/dialog-payment.glade
index 4c61b3664d..83ae08c89f 100644
--- a/src/business/business-gnome/gtkbuilder/dialog-payment.glade
+++ b/src/business/business-gnome/gtkbuilder/dialog-payment.glade
@@ -262,7 +262,7 @@
False
diff --git a/src/engine/gncInvoice.c b/src/engine/gncInvoice.c
index 50f3373bfe..9b6c33f629 100644
--- a/src/engine/gncInvoice.c
+++ b/src/engine/gncInvoice.c
@@ -1854,7 +1854,7 @@ gncInvoiceApplyPayment (const GncInvoice *invoice, Transaction *txn,
g_return_if_fail (owner->owner.undefined);
/* Create a lot for this payment */
- payment_lot = gncOwnerCreatePaymentLot (owner, txn, invoice->posted_acc, xfer_acc,
+ payment_lot = gncOwnerCreatePaymentLot (owner, &txn, invoice->posted_acc, xfer_acc,
amount, exch, date, memo, num);
/* Select the invoice as only payment candidate */
diff --git a/src/engine/gncOwner.c b/src/engine/gncOwner.c
index b0e7ecaef1..0c0af8b02d 100644
--- a/src/engine/gncOwner.c
+++ b/src/engine/gncOwner.c
@@ -705,7 +705,7 @@ gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB)
}
GNCLot *
-gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction *txn,
+gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn,
Account *posted_acc, Account *xfer_acc,
gnc_numeric amount, gnc_numeric exch, Timespec date,
const char *memo, const char *num)
@@ -715,6 +715,7 @@ gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction *txn,
const char *name;
gnc_commodity *commodity;
Split *xfer_split = NULL;
+ Transaction *txn = NULL;
GNCLot *payment_lot;
/* Verify our arguments */
@@ -727,6 +728,9 @@ gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction *txn,
commodity = gncOwnerGetCurrency (owner);
// reverse = use_reversed_payment_amounts(owner);
+ if (preset_txn && *preset_txn)
+ txn = *preset_txn;
+
if (txn)
{
/* Pre-existing transaction was specified. We completely clear it,
@@ -845,6 +849,8 @@ gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction *txn,
/* Commit this new transaction */
xaccTransCommitEdit (txn);
+ if (preset_txn)
+ *preset_txn = txn;
return payment_lot;
}
@@ -1357,7 +1363,7 @@ void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots)
* then all open lots for the owner are considered.
*/
void
-gncOwnerApplyPayment (const GncOwner *owner, Transaction *txn, GList *lots,
+gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lots,
Account *posted_acc, Account *xfer_acc,
gnc_numeric amount, gnc_numeric exch, Timespec date,
const char *memo, const char *num, gboolean auto_pay)
@@ -1372,7 +1378,7 @@ gncOwnerApplyPayment (const GncOwner *owner, Transaction *txn, GList *lots,
/* If there's a real amount to transfer create a lot for this payment */
if (!gnc_numeric_zero_p (amount))
- payment_lot = gncOwnerCreatePaymentLot (owner, txn, posted_acc, xfer_acc,
+ payment_lot = gncOwnerCreatePaymentLot (owner, preset_txn, posted_acc, xfer_acc,
amount, exch, date, memo, num);
if (lots)
diff --git a/src/engine/gncOwner.h b/src/engine/gncOwner.h
index 416a89a0b0..b805ac6274 100644
--- a/src/engine/gncOwner.h
+++ b/src/engine/gncOwner.h
@@ -208,7 +208,7 @@ KvpFrame* gncOwnerGetSlots(GncOwner* owner);
* split in the transfer account).
*/
GNCLot *
-gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction *txn,
+gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn,
Account *posted_acc, Account *xfer_acc,
gnc_numeric amount, gnc_numeric exch, Timespec date,
const char *memo, const char *num);
@@ -261,7 +261,7 @@ void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots);
* details on what happens exactly.
*/
void
-gncOwnerApplyPayment (const GncOwner *owner, Transaction *txn, GList *lots,
+gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lots,
Account *posted_acc, Account *xfer_acc,
gnc_numeric amount, gnc_numeric exch, Timespec date,
const char *memo, const char *num, gboolean auto_pay);