mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Rework of Titi Ala'ilima's patch to apply payments directly to invoices. (#121420)
Apply a re-work of Titi Ala'ilima's patch to apply payments directly to invoices. This fixes bug #121420. * src/business/business-core/gncInvoice.[ch]: Add argument to the ProcessPayment API to allow the caller to specify an invoice to post to first. * src/business/business-gnome/business-gnome-utils.[ch]: Create an invoice-select API that lets you select an invoice based on an owner (or not). I.e., you can limit the invoice search based on a selected owner. If you change the owner it invalidates the invoice search. * src/business/business-gnome/dialog-payment.[ch]: Change the API from ..new_with_value() to ..new_with_invoice(). Pull the default amount from the invoice (if one exists). Allow the user to select an invoice and apply payments there. If the user changes the owner, invalidate the invoice. * src/business/business-gnome/business-options-gnome.c: use the new invoice-select API instead of calling general_search API directly. * src/business/business-gnome/dialog-invoice.c: call the new dialog-payment API. No need to compute the initial value here; the payment dialog will compute it from the invoice (instead of computing it from the invoice here). * src/business/business-gnome/glade/payment.glade: Add invoice-selector label and box. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13411 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
30f415ecc0
commit
ac4ae4e58e
27
ChangeLog
27
ChangeLog
@ -1,3 +1,30 @@
|
||||
2006-02-26 Derek Atkins <derek@ihtfp.com>
|
||||
|
||||
Apply a re-work of Titi Ala'ilima's patch to apply payments
|
||||
directly to invoices. This fixes bug #121420.
|
||||
* src/business/business-core/gncInvoice.[ch]:
|
||||
Add argument to the ProcessPayment API to allow the caller
|
||||
to specify an invoice to post to first.
|
||||
* src/business/business-gnome/business-gnome-utils.[ch]:
|
||||
Create an invoice-select API that lets you select an invoice
|
||||
based on an owner (or not). I.e., you can limit the invoice
|
||||
search based on a selected owner. If you change the owner
|
||||
it invalidates the invoice search.
|
||||
* src/business/business-gnome/dialog-payment.[ch]:
|
||||
Change the API from ..new_with_value() to ..new_with_invoice().
|
||||
Pull the default amount from the invoice (if one exists).
|
||||
Allow the user to select an invoice and apply payments there.
|
||||
If the user changes the owner, invalidate the invoice.
|
||||
* src/business/business-gnome/business-options-gnome.c:
|
||||
use the new invoice-select API instead of calling general_search
|
||||
API directly.
|
||||
* src/business/business-gnome/dialog-invoice.c:
|
||||
call the new dialog-payment API. No need to compute the initial
|
||||
value here; the payment dialog will compute it from the invoice
|
||||
(instead of computing it from the invoice here).
|
||||
* src/business/business-gnome/glade/payment.glade:
|
||||
Add invoice-selector label and box.
|
||||
|
||||
2006-02-26 David Hampton <hampton@employees.org>
|
||||
|
||||
* packaging: Create a consolidated directory for distribution
|
||||
|
@ -21,7 +21,7 @@
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001,2002 Derek Atkins
|
||||
* Copyright (C) 2001,2002,2006 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
@ -1236,20 +1236,22 @@ gnc_lot_sort_func (GNCLot *a, GNCLot *b)
|
||||
* in gncInvoice...
|
||||
*/
|
||||
Transaction *
|
||||
gncOwnerApplyPayment (GncOwner *owner, Account *posted_acc, Account *xfer_acc,
|
||||
gncOwnerApplyPayment (GncOwner *owner, GncInvoice* invoice,
|
||||
Account *posted_acc, Account *xfer_acc,
|
||||
gnc_numeric amount, Timespec date,
|
||||
const char *memo, const char *num)
|
||||
{
|
||||
QofBook *book;
|
||||
Account *inv_posted_acc;
|
||||
Transaction *txn;
|
||||
Split *split;
|
||||
GList *lot_list, *fifo = NULL;
|
||||
GNCLot *lot, *prepay_lot = NULL;
|
||||
GncInvoice *invoice;
|
||||
GNCLot *lot, *inv_posted_lot = NULL, *prepay_lot = NULL;
|
||||
GncInvoice *this_invoice;
|
||||
const char *name;
|
||||
gnc_commodity *commodity;
|
||||
gnc_numeric split_amt;
|
||||
gboolean reverse;
|
||||
gboolean reverse, inv_passed = TRUE;
|
||||
|
||||
/* Verify our arguments */
|
||||
if (!owner || !posted_acc || !xfer_acc) return NULL;
|
||||
@ -1292,6 +1294,23 @@ gncOwnerApplyPayment (GncOwner *owner, Account *posted_acc, Account *xfer_acc,
|
||||
owner,
|
||||
(GCompareFunc)gnc_lot_sort_func);
|
||||
|
||||
/* Check if an invoice was passed in, and if so, does it match the
|
||||
* account, and is it an open lot? If so, put it at the beginning
|
||||
* of the lot list fifo so we post to this invoice's lot first.
|
||||
*/
|
||||
if (invoice) {
|
||||
inv_posted_acc = gncInvoiceGetPostedAcc(invoice);
|
||||
inv_posted_lot = gncInvoiceGetPostedLot(invoice);
|
||||
if (inv_posted_acc && inv_posted_lot &&
|
||||
guid_equal(xaccAccountGetGUID(inv_posted_acc),
|
||||
xaccAccountGetGUID(posted_acc)) &&
|
||||
!gnc_lot_is_closed(inv_posted_lot)) {
|
||||
/* Put this invoice at the beginning of the FIFO */
|
||||
fifo = g_list_prepend (fifo, inv_posted_lot);
|
||||
inv_passed = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
xaccAccountBeginEdit (posted_acc);
|
||||
|
||||
/* Now iterate over the fifo until the payment is fully applied
|
||||
@ -1301,6 +1320,21 @@ gncOwnerApplyPayment (GncOwner *owner, Account *posted_acc, Account *xfer_acc,
|
||||
gnc_numeric balance;
|
||||
|
||||
lot = lot_list->data;
|
||||
|
||||
/* Skip this lot if it matches the invoice that was passed in and
|
||||
* we've seen it already. This way we post to it the first time
|
||||
* (from the beginning of the lot-list) but not when we reach it
|
||||
* the second time.
|
||||
*/
|
||||
if (inv_posted_lot &&
|
||||
guid_equal(qof_instance_get_guid(QOF_INSTANCE(lot)),
|
||||
qof_instance_get_guid(QOF_INSTANCE(inv_posted_lot)))) {
|
||||
if (inv_passed)
|
||||
continue;
|
||||
else
|
||||
inv_passed = TRUE;
|
||||
}
|
||||
|
||||
balance = gnc_lot_get_balance (lot);
|
||||
|
||||
if (!reverse)
|
||||
@ -1345,9 +1379,9 @@ gncOwnerApplyPayment (GncOwner *owner, Account *posted_acc, Account *xfer_acc,
|
||||
gnc_lot_add_split (lot, split);
|
||||
|
||||
/* Now send an event for the invoice so it gets updated as paid */
|
||||
invoice = gncInvoiceGetInvoiceFromLot(lot);
|
||||
if (invoice)
|
||||
gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_MODIFY);
|
||||
this_invoice = gncInvoiceGetInvoiceFromLot(lot);
|
||||
if (this_invoice)
|
||||
gnc_engine_gen_event (&this_invoice->inst.entity, GNC_EVENT_MODIFY);
|
||||
|
||||
if (gnc_numeric_zero_p (amount))
|
||||
break;
|
||||
|
@ -29,7 +29,7 @@ transaction and lot for the posted invoice.
|
||||
@{ */
|
||||
/** @file gncInvoice.h
|
||||
@brief Business Invoice Interface
|
||||
@author Copyright (C) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
@author Copyright (C) 2001,2006 Derek Atkins <warlord@MIT.EDU>
|
||||
@author Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
||||
*/
|
||||
|
||||
@ -135,13 +135,16 @@ gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables);
|
||||
|
||||
/**
|
||||
* Apply a payment of "amount" for the owner, between the xfer_account
|
||||
* (bank or other asset) and the posted_account (A/R or A/P).
|
||||
* (bank or other asset) and the posted_account (A/R or A/P). If the
|
||||
* caller supplies an (optional) invoice argument, then apply the
|
||||
* payment to that invoice first before any other invoice.
|
||||
*
|
||||
* XXX: yes, this should be in gncOwner, but all the other logic is
|
||||
* in gncInvoice...
|
||||
*/
|
||||
Transaction *
|
||||
gncOwnerApplyPayment (GncOwner *owner, Account *posted_acc, Account *xfer_acc,
|
||||
gncOwnerApplyPayment (GncOwner *owner, GncInvoice *invoice,
|
||||
Account *posted_acc, Account *xfer_acc,
|
||||
gnc_numeric amount, Timespec date,
|
||||
const char *memo, const char *num);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* business-gnome-utils.c -- General GUI Utilities for GNC Business Objects
|
||||
*
|
||||
* Written By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (C) 2001, 2002 Derek Atkins
|
||||
* Copyright (C) 2001,2002,2006 Derek Atkins
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
@ -37,6 +37,7 @@
|
||||
#include "gncJob.h"
|
||||
#include "gncVendor.h"
|
||||
#include "gncOwner.h"
|
||||
#include "gncInvoice.h"
|
||||
|
||||
#include "gnc-general-search.h"
|
||||
#include "gncObject.h"
|
||||
@ -45,6 +46,7 @@
|
||||
#include "dialog-job.h"
|
||||
#include "dialog-vendor.h"
|
||||
#include "dialog-employee.h"
|
||||
#include "dialog-invoice.h"
|
||||
|
||||
typedef enum {
|
||||
GNCSEARCH_TYPE_SELECT,
|
||||
@ -168,6 +170,135 @@ void gnc_owner_set_owner (GtkWidget *widget, GncOwner *owner)
|
||||
owner->owner.undefined);
|
||||
}
|
||||
|
||||
typedef struct _invoice_select_info {
|
||||
GtkWidget *label;
|
||||
GNCBook *book;
|
||||
GncOwner owner;
|
||||
gboolean have_owner;
|
||||
} GncISI;
|
||||
|
||||
static GNCSearchWindow *
|
||||
gnc_invoice_select_search_cb (gpointer start, gpointer isip)
|
||||
{
|
||||
GncISI *isi = isip;
|
||||
|
||||
if (!isi) return NULL;
|
||||
g_assert(isi->book);
|
||||
|
||||
return gnc_invoice_search (start,
|
||||
isi->have_owner ? &isi->owner : NULL,
|
||||
isi->book);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_invoice_select_search_set_label(GncISI* isi)
|
||||
{
|
||||
GncOwnerType owner_type;
|
||||
GncOwner *tmp;
|
||||
char *label;
|
||||
|
||||
g_assert(isi);
|
||||
if (!isi->label) return;
|
||||
|
||||
tmp = &isi->owner;
|
||||
owner_type = gncOwnerGetType(tmp);
|
||||
while (owner_type == GNC_OWNER_JOB) {
|
||||
tmp = gncOwnerGetEndOwner(tmp);
|
||||
owner_type = gncOwnerGetType(tmp);
|
||||
}
|
||||
|
||||
/* Translators: See comments in dialog-invoice.c:gnc_invoice_search() */
|
||||
switch (owner_type) {
|
||||
case GNC_OWNER_VENDOR:
|
||||
label = _("Bill");
|
||||
break;
|
||||
case GNC_OWNER_EMPLOYEE:
|
||||
label = _("Voucher");
|
||||
break;
|
||||
default:
|
||||
label = _("Invoice");
|
||||
}
|
||||
|
||||
gtk_label_set_text(GTK_LABEL(isi->label), label);
|
||||
}
|
||||
|
||||
GtkWidget * gnc_invoice_select_create (GtkWidget *hbox, GNCBook *book,
|
||||
const GncOwner *owner,
|
||||
GncInvoice *invoice,
|
||||
GtkWidget *label)
|
||||
{
|
||||
GtkWidget *edit;
|
||||
GncISI *isi;
|
||||
|
||||
g_return_val_if_fail (hbox != NULL, NULL);
|
||||
g_return_val_if_fail (book != NULL, NULL);
|
||||
/* Note: it is legal to have no owner or invoice */
|
||||
|
||||
isi = g_new0(GncISI, 1);
|
||||
if (!isi)
|
||||
return NULL;
|
||||
|
||||
if (owner) {
|
||||
gncOwnerCopy(owner, &isi->owner);
|
||||
isi->have_owner = TRUE;
|
||||
} else {
|
||||
gncOwnerInitCustomer(&isi->owner, NULL);
|
||||
}
|
||||
isi->book = book;
|
||||
isi->label = label;
|
||||
|
||||
edit = gnc_general_search_new (GNC_INVOICE_MODULE_NAME, _("Select..."),
|
||||
gnc_invoice_select_search_cb, isi);
|
||||
if (!edit) {
|
||||
g_free(isi);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gnc_general_search_set_selected (GNC_GENERAL_SEARCH (edit), invoice);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), edit, FALSE, FALSE, 0);
|
||||
g_object_set_data_full(G_OBJECT(edit), "isi-state", isi, g_free);
|
||||
|
||||
/* Set the label */
|
||||
gnc_invoice_select_search_set_label(isi);
|
||||
|
||||
return edit;
|
||||
}
|
||||
|
||||
GncInvoice * gnc_invoice_get_invoice (GtkWidget *widget)
|
||||
{
|
||||
g_return_val_if_fail (widget != NULL, NULL);
|
||||
|
||||
return gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
|
||||
}
|
||||
|
||||
void gnc_invoice_set_invoice (GtkWidget *widget, GncInvoice *invoice)
|
||||
{
|
||||
g_return_if_fail (widget != NULL);
|
||||
g_return_if_fail (invoice != NULL);
|
||||
|
||||
gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget), invoice);
|
||||
}
|
||||
|
||||
void gnc_invoice_set_owner (GtkWidget *widget, GncOwner *owner)
|
||||
{
|
||||
GncISI *isi;
|
||||
|
||||
g_return_if_fail (widget != NULL);
|
||||
g_return_if_fail (owner != NULL);
|
||||
|
||||
isi = g_object_get_data(G_OBJECT(widget), "isi-state");
|
||||
g_assert(isi);
|
||||
|
||||
if (isi->owner.owner.undefined == owner->owner.undefined)
|
||||
return;
|
||||
|
||||
gncOwnerCopy(owner, &isi->owner);
|
||||
isi->have_owner = TRUE;
|
||||
gnc_general_search_set_selected(GNC_GENERAL_SEARCH(widget), NULL);
|
||||
|
||||
/* Reset the label */
|
||||
gnc_invoice_select_search_set_label(isi);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_fill_account_select_combo (GtkWidget *combo, GNCBook *book,
|
||||
|
@ -2,7 +2,7 @@
|
||||
* business-gnome-utils.h -- General GUI Utilities for GNC Business Objects
|
||||
*
|
||||
* Written By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Copyright (C) 2001,2006 Derek Atkins
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
@ -29,6 +29,7 @@
|
||||
#include "gncOwner.h"
|
||||
#include "gncBillTerm.h"
|
||||
#include "gncTaxTable.h"
|
||||
#include "gncInvoice.h"
|
||||
|
||||
#define GCONF_SECTION_ORDER "dialogs/business/order"
|
||||
#define GCONF_SECTION_JOB "dialogs/business/job"
|
||||
@ -46,6 +47,18 @@ void gnc_owner_get_owner (GtkWidget *widget, GncOwner *owner);
|
||||
void gnc_owner_set_owner (GtkWidget *widget, GncOwner *owner);
|
||||
|
||||
|
||||
/* An invoice select widget..
|
||||
* the owner, invoice, and label parameters are optional
|
||||
*/
|
||||
GtkWidget * gnc_invoice_select_create (GtkWidget *hbox, GNCBook *book,
|
||||
const GncOwner *owner,
|
||||
GncInvoice *invoice,
|
||||
GtkWidget *label);
|
||||
|
||||
GncInvoice * gnc_invoice_get_invoice (GtkWidget *widget);
|
||||
void gnc_invoice_set_invoice (GtkWidget *widget, GncInvoice *invoice);
|
||||
void gnc_invoice_set_owner (GtkWidget *widget, GncOwner *owner);
|
||||
|
||||
/* Return a list of account-types based on the owner type */
|
||||
GList * gnc_business_account_types (GncOwner *owner);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* business-options.c -- Initialize Business Options
|
||||
*
|
||||
* Written By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (C) 2002 Derek Atkins
|
||||
* Copyright (C) 2002,2006 Derek Atkins
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
@ -355,12 +355,10 @@ create_invoice_widget (GNCOption *option, GtkWidget *hbox)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
widget = gnc_general_search_new (GNC_INVOICE_MODULE_NAME,
|
||||
_("Select..."),
|
||||
gnc_invoice_search_select,
|
||||
gnc_get_current_book ());
|
||||
/* No owner or starting invoice here, but that's okay. */
|
||||
widget = gnc_invoice_select_create (hbox, gnc_get_current_book(),
|
||||
NULL, NULL, NULL);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
|
||||
gnc_option_set_widget (option, widget);
|
||||
g_signal_connect (G_OBJECT (widget), "changed",
|
||||
G_CALLBACK (gnc_option_changed_option_cb), option);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* dialog-invoice.c -- Dialog for Invoice entry
|
||||
* Copyright (C) 2001,2002 Derek Atkins
|
||||
* Copyright (C) 2001,2002,2006 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* Copyright (c) 2005,2006 David Hampton <hampton@employees.org>
|
||||
@ -783,13 +783,11 @@ void gnc_invoice_window_payment_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
InvoiceWindow *iw = data;
|
||||
GncInvoice *invoice = iw_get_invoice(iw);
|
||||
GNCLot *lot = gncInvoiceGetPostedLot (invoice);
|
||||
gnc_numeric val = gnc_numeric_abs (gnc_lot_get_balance (lot));
|
||||
|
||||
if (gncOwnerGetJob (&iw->job))
|
||||
gnc_ui_payment_new_with_value (&iw->job, iw->book, val);
|
||||
gnc_ui_payment_new_with_invoice (&iw->job, iw->book, invoice);
|
||||
else
|
||||
gnc_ui_payment_new_with_value (&iw->owner, iw->book, val);
|
||||
gnc_ui_payment_new_with_invoice (&iw->owner, iw->book, invoice);
|
||||
}
|
||||
|
||||
/* Sorting callbacks */
|
||||
@ -2150,15 +2148,10 @@ static void
|
||||
pay_invoice_direct (gpointer inv, gpointer user_data)
|
||||
{
|
||||
GncInvoice *invoice = inv;
|
||||
GNCLot *lot;
|
||||
gnc_numeric val;
|
||||
|
||||
g_return_if_fail (invoice);
|
||||
|
||||
lot = gncInvoiceGetPostedLot (invoice);
|
||||
val = gnc_numeric_abs (gnc_lot_get_balance (lot));
|
||||
gnc_ui_payment_new_with_value (gncInvoiceGetOwner (invoice),
|
||||
gncInvoiceGetBook (invoice), val);
|
||||
gnc_ui_payment_new_with_invoice (gncInvoiceGetOwner (invoice),
|
||||
gncInvoiceGetBook (invoice), invoice);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* dialog-payment.c -- Dialog for payment entry
|
||||
* Copyright (C) 2002 Derek Atkins
|
||||
* Copyright (C) 2002,2006 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@ -53,6 +53,7 @@ struct _payment_window {
|
||||
GtkWidget * memo_entry;
|
||||
GtkWidget * post_combo;
|
||||
GtkWidget * owner_choice;
|
||||
GtkWidget * invoice_choice;
|
||||
GtkWidget * amount_edit;
|
||||
GtkWidget * date_edit;
|
||||
GtkWidget * acct_tree;
|
||||
@ -60,6 +61,7 @@ struct _payment_window {
|
||||
gint component_id;
|
||||
GNCBook * book;
|
||||
GncOwner owner;
|
||||
GncInvoice * invoice;
|
||||
GList * acct_types;
|
||||
};
|
||||
|
||||
@ -86,14 +88,45 @@ gnc_payment_window_close_handler (gpointer data)
|
||||
gtk_widget_destroy (pw->dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_payment_dialog_invoice_changed(PaymentWindow *pw)
|
||||
{
|
||||
GNCLot *lot;
|
||||
gnc_numeric val;
|
||||
|
||||
/* Set the payment amount in the dialog */
|
||||
if (pw->invoice) {
|
||||
lot = gncInvoiceGetPostedLot (pw->invoice);
|
||||
val = gnc_numeric_abs (gnc_lot_get_balance (lot));
|
||||
} else {
|
||||
val = gnc_numeric_zero();
|
||||
}
|
||||
|
||||
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(pw->amount_edit), val);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_payment_dialog_owner_changed(PaymentWindow *pw)
|
||||
{
|
||||
Account *last_acct;
|
||||
GUID *guid;
|
||||
KvpValue* value;
|
||||
KvpFrame* slots = gncOwnerGetSlots(&pw->owner);
|
||||
KvpFrame* slots;
|
||||
|
||||
/* If the owner changed, the invoice selection is invalid */
|
||||
pw->invoice = NULL;
|
||||
gnc_invoice_set_owner(pw->invoice_choice, &pw->owner);
|
||||
/* note that set_owner implies ...set_invoice(...,NULL); */
|
||||
|
||||
/* in case we don't get the callback */
|
||||
gnc_payment_dialog_invoice_changed(pw);
|
||||
|
||||
/* XXX: We should set the sensitive flag on the invoice_choice
|
||||
* based on whether 'owner' is NULL or not...
|
||||
*/
|
||||
|
||||
/* Now handle the account tree */
|
||||
slots = gncOwnerGetSlots(&pw->owner);
|
||||
if (!slots) return;
|
||||
|
||||
value = kvp_frame_get_slot_path(slots, "payment", "last_acct", NULL);
|
||||
@ -157,6 +190,25 @@ gnc_payment_dialog_owner_changed_cb (GtkWidget *widget, gpointer data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
gnc_payment_dialog_invoice_changed_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
PaymentWindow *pw = data;
|
||||
GncInvoice *invoice;
|
||||
|
||||
if (!pw) return FALSE;
|
||||
|
||||
invoice = gnc_invoice_get_invoice (pw->invoice_choice);
|
||||
|
||||
/* If this invoice really changed, then reset ourselves */
|
||||
if (invoice != pw->invoice) {
|
||||
pw->invoice = invoice;
|
||||
gnc_payment_dialog_invoice_changed(pw);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_payment_ok_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
@ -225,7 +277,8 @@ gnc_payment_ok_cb (GtkWidget *widget, gpointer data)
|
||||
date = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (pw->date_edit));
|
||||
|
||||
/* Now apply the payment */
|
||||
gncOwnerApplyPayment (&pw->owner, post, acc, amount, date, memo, num);
|
||||
gncOwnerApplyPayment (&pw->owner, pw->invoice,
|
||||
post, acc, amount, date, memo, num);
|
||||
}
|
||||
gnc_resume_gui_refresh ();
|
||||
|
||||
@ -290,7 +343,7 @@ find_handler (gpointer find_data, gpointer user_data)
|
||||
}
|
||||
|
||||
static PaymentWindow *
|
||||
new_payment_window (GncOwner *owner, GNCBook *book, gnc_numeric initial_payment)
|
||||
new_payment_window (GncOwner *owner, GNCBook *book, GncInvoice *invoice)
|
||||
{
|
||||
PaymentWindow *pw;
|
||||
GladeXML *xml;
|
||||
@ -336,12 +389,16 @@ new_payment_window (GncOwner *owner, GNCBook *book, gnc_numeric initial_payment)
|
||||
box = glade_xml_get_widget (xml, "owner_box");
|
||||
pw->owner_choice = gnc_owner_select_create (label, box, book, owner);
|
||||
|
||||
label = glade_xml_get_widget (xml, "invoice_label");
|
||||
box = glade_xml_get_widget (xml, "invoice_box");
|
||||
pw->invoice_choice = gnc_invoice_select_create (box, book, owner, invoice, label);
|
||||
|
||||
box = glade_xml_get_widget (xml, "amount_box");
|
||||
pw->amount_edit = gnc_amount_edit_new ();
|
||||
gtk_box_pack_start (GTK_BOX (box), pw->amount_edit, TRUE, TRUE, 0);
|
||||
gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (pw->amount_edit),
|
||||
TRUE);
|
||||
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pw->amount_edit), initial_payment);
|
||||
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pw->amount_edit), gnc_numeric_zero());
|
||||
|
||||
box = glade_xml_get_widget (xml, "date_box");
|
||||
pw->date_edit = gnc_date_edit_new (time(NULL), FALSE, FALSE);
|
||||
@ -356,6 +413,10 @@ new_payment_window (GncOwner *owner, GNCBook *book, gnc_numeric initial_payment)
|
||||
/* Set the dialog for the 'new' owner */
|
||||
gnc_payment_dialog_owner_changed(pw);
|
||||
|
||||
/* Set the dialog for the 'new' invoice */
|
||||
pw->invoice = invoice;
|
||||
gnc_payment_dialog_invoice_changed(pw);
|
||||
|
||||
/* Setup signals */
|
||||
glade_xml_signal_autoconnect_full( xml,
|
||||
gnc_glade_autoconnect_full_func,
|
||||
@ -364,6 +425,9 @@ new_payment_window (GncOwner *owner, GNCBook *book, gnc_numeric initial_payment)
|
||||
g_signal_connect (G_OBJECT (pw->owner_choice), "changed",
|
||||
G_CALLBACK (gnc_payment_dialog_owner_changed_cb), pw);
|
||||
|
||||
g_signal_connect (G_OBJECT (pw->invoice_choice), "changed",
|
||||
G_CALLBACK (gnc_payment_dialog_invoice_changed_cb), pw);
|
||||
|
||||
/* Register with the component manager */
|
||||
pw->component_id =
|
||||
gnc_register_gui_component (cm_class,
|
||||
@ -415,8 +479,8 @@ gnc_ui_payment_window_destroy (PaymentWindow *pw)
|
||||
}
|
||||
|
||||
PaymentWindow *
|
||||
gnc_ui_payment_new_with_value (GncOwner *owner, GNCBook *book,
|
||||
gnc_numeric initial_payment)
|
||||
gnc_ui_payment_new_with_invoice (GncOwner *owner, GNCBook *book,
|
||||
GncInvoice *invoice)
|
||||
{
|
||||
GncOwner owner_def;
|
||||
|
||||
@ -429,12 +493,12 @@ gnc_ui_payment_new_with_value (GncOwner *owner, GNCBook *book,
|
||||
owner = &owner_def;
|
||||
}
|
||||
|
||||
return new_payment_window (owner, book, initial_payment);
|
||||
return new_payment_window (owner, book, invoice);
|
||||
}
|
||||
|
||||
PaymentWindow *
|
||||
gnc_ui_payment_new (GncOwner *owner, GNCBook *book)
|
||||
{
|
||||
return gnc_ui_payment_new_with_value (owner, book, gnc_numeric_zero());
|
||||
return gnc_ui_payment_new_with_invoice (owner, book, NULL);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* dialog-payment.h -- Dialog to enter payments
|
||||
* Copyright (C) 2002 Derek Atkins
|
||||
* Copyright (C) 2002,2006 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@ -28,11 +28,13 @@ typedef struct _payment_window PaymentWindow;
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "gncOwner.h"
|
||||
#include "gncInvoice.h"
|
||||
|
||||
/* Create a payment window */
|
||||
PaymentWindow * gnc_ui_payment_new (GncOwner *owner, GNCBook *book);
|
||||
PaymentWindow * gnc_ui_payment_new_with_value (GncOwner *owner, GNCBook *book,
|
||||
gnc_numeric initial_payment);
|
||||
PaymentWindow * gnc_ui_payment_new_with_invoice (GncOwner *owner,
|
||||
GNCBook *book,
|
||||
GncInvoice *invoice);
|
||||
|
||||
/* Destroy a payment window */
|
||||
void gnc_ui_payment_window_destroy (PaymentWindow *pw);
|
||||
|
@ -113,6 +113,27 @@
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="invoice_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">(invoice)</property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label3">
|
||||
<property name="visible">True</property>
|
||||
@ -228,6 +249,23 @@
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHBox" id="invoice_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHBox" id="date_box">
|
||||
<property name="visible">True</property>
|
||||
|
Loading…
Reference in New Issue
Block a user