Provide option to print checks directly from the payment window

This commit is contained in:
Geert Janssens 2016-03-25 16:16:00 +01:00
parent d5d58dacba
commit 656a3a9b57
5 changed files with 57 additions and 10 deletions

View File

@ -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));

View File

@ -262,7 +262,7 @@
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">8</property>
<property name="n_rows">9</property>
<property name="n_columns">2</property>
<property name="column_spacing">3</property>
<property name="row_spacing">3</property>
@ -549,6 +549,24 @@ In case of an over-payment or if no invoice was selected, GnuCash will automatic
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkCheckButton" id="print_check">
<property name="label" translatable="yes">Print Check</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">8</property>
<property name="bottom_attach">9</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>

View File

@ -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 */

View File

@ -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)

View File

@ -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);