AccWindow.h: Add comment about who owns the GList *

gncInvoice.[ch]: add date-posted, paid-txn
	change date-closed->date-paid
        add gncInvoicePayToAccount()
dialog-date-close.[ch]: allow list of account-types
        provide a dialog with only 1 date and account (for invoice payment)
dialog-invoice.c: provide list of accounts to date-close dialog(s)
        change 'close' to 'pay'
        hide cancel button on posted/paid invoices
dialog-order.c: hide cancel button on closed orders
search-date.c: remove unused time_t
search-param.[ch]: provide a 'type' over-ride


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6707 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2002-02-11 01:59:54 +00:00
parent edbbab384a
commit ea0d741c3b
13 changed files with 393 additions and 114 deletions

View File

@ -41,6 +41,8 @@ AccountWindow * gnc_ui_new_account_window_with_default(AccountGroup *group,
AccountWindow * gnc_ui_edit_account_window (Account *account);
Account * gnc_ui_new_accounts_from_name_window (const char *name);
/* Note that the caller owns the valid_types list */
Account * gnc_ui_new_accounts_from_name_window_with_types (const char *name,
GList *valid_types);

View File

@ -35,11 +35,13 @@ struct _gncInvoice {
GList * entries;
GncOwner owner;
Timespec date_opened;
Timespec date_posted;
Timespec date_due;
Timespec date_closed;
Timespec date_paid;
Account * posted_acc;
Transaction * posted_txn;
Transaction * paid_txn;
gboolean active;
@ -134,6 +136,13 @@ void gncInvoiceSetDateOpened (GncInvoice *invoice, const Timespec *date)
invoice->dirty = TRUE;
}
void gncInvoiceSetDatePosted (GncInvoice *invoice, const Timespec *date)
{
if (!invoice || !date) return;
invoice->date_posted = *date;
invoice->dirty = TRUE;
}
void gncInvoiceSetDateDue (GncInvoice *invoice, const Timespec *date)
{
if (!invoice || !date) return;
@ -141,10 +150,10 @@ void gncInvoiceSetDateDue (GncInvoice *invoice, const Timespec *date)
invoice->dirty = TRUE;
}
void gncInvoiceSetDateClosed (GncInvoice *invoice, const Timespec *date)
void gncInvoiceSetDatePaid (GncInvoice *invoice, const Timespec *date)
{
if (!invoice || !date) return;
invoice->date_closed = *date;
invoice->date_paid = *date;
invoice->dirty = TRUE;
}
@ -183,6 +192,14 @@ void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn)
invoice->dirty = TRUE;
}
void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn)
{
if (!invoice) return;
invoice->paid_txn = txn;
invoice->dirty = TRUE;
}
void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc)
{
if (!invoice) return;
@ -248,6 +265,13 @@ Timespec gncInvoiceGetDateOpened (GncInvoice *invoice)
return invoice->date_opened;
}
Timespec gncInvoiceGetDatePosted (GncInvoice *invoice)
{
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
if (!invoice) return ts;
return invoice->date_posted;
}
Timespec gncInvoiceGetDateDue (GncInvoice *invoice)
{
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
@ -255,11 +279,11 @@ Timespec gncInvoiceGetDateDue (GncInvoice *invoice)
return invoice->date_due;
}
Timespec gncInvoiceGetDateClosed (GncInvoice *invoice)
Timespec gncInvoiceGetDatePaid (GncInvoice *invoice)
{
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
if (!invoice) return ts;
return invoice->date_closed;
return invoice->date_paid;
}
const char * gncInvoiceGetTerms (GncInvoice *invoice)
@ -280,6 +304,12 @@ Transaction * gncInvoiceGetPostedTxn (GncInvoice *invoice)
return invoice->posted_txn;
}
Transaction * gncInvoiceGetPaidTxn (GncInvoice *invoice)
{
if (!invoice) return NULL;
return invoice->posted_txn;
}
Account * gncInvoiceGetPostedAcc (GncInvoice *invoice)
{
if (!invoice) return NULL;
@ -304,7 +334,8 @@ gboolean gncInvoiceIsDirty (GncInvoice *invoice)
return invoice->dirty;
}
void gncInvoiceAttachInvoiceToTxn (GncInvoice *invoice, Transaction *txn)
static void
gncInvoiceAttachInvoiceToTxn (GncInvoice *invoice, Transaction *txn, char type)
{
kvp_frame *kvp;
kvp_value *value;
@ -319,10 +350,19 @@ void gncInvoiceAttachInvoiceToTxn (GncInvoice *invoice, Transaction *txn)
value = kvp_value_new_guid (gncInvoiceGetGUID (invoice));
kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
kvp_value_delete (value);
xaccTransSetTxnType (txn, TXN_TYPE_INVOICE);
xaccTransSetTxnType (txn, type);
xaccTransCommitEdit (txn);
gncInvoiceSetPostedTxn (invoice, txn);
switch (type) {
case TXN_TYPE_PAYMENT:
gncInvoiceSetPaidTxn (invoice, txn);
break;
case TXN_TYPE_INVOICE:
gncInvoiceSetPostedTxn (invoice, txn);
break;
default:
break;
}
}
#define GET_OR_ADD_ACCVAL(list,t_acc,res) { \
@ -357,11 +397,11 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
if (!invoice || !acc) return NULL;
/* XXX: Figure out the common currency */
txn = xaccMallocTransaction (invoice->book);
xaccTransBeginEdit (txn);
/* XXX: Figure out the common currency */
/* Set Transaction Description (customer), Num (invoice ID), Currency */
xaccTransSetDescription
(txn, gncOwnerGetName (gncInvoiceGetOwner (invoice)));
@ -373,6 +413,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
if (date) {
xaccTransSetDateEnteredTS (txn, date);
xaccTransSetDatePostedTS (txn, date);
gncInvoiceSetDatePosted (invoice, date);
}
/* Set the txn due date to be equal to the invoice */
@ -445,7 +486,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
}
/* Now attach this invoice to the txn and account */
gncInvoiceAttachInvoiceToTxn (invoice, txn);
gncInvoiceAttachInvoiceToTxn (invoice, txn, TXN_TYPE_INVOICE);
gncInvoiceSetPostedAcc (invoice, acc);
xaccTransCommitEdit (txn);
@ -453,6 +494,92 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
return txn;
}
Transaction *
gncInvoicePayToAccount (GncInvoice *invoice, Account *acc,
Timespec *paid_date)
{
Transaction *txn;
gnc_numeric total;
gnc_commodity *commonCommodity = NULL; /* XXX: FIXME */
Account *acct;
if (!invoice || !acc) return NULL;
/* Must have posted before you can pay */
g_return_val_if_fail (gncInvoiceGetPostedTxn(invoice), NULL);
acct = gncInvoiceGetPostedAcc (invoice);
g_return_val_if_fail (acct, NULL);
/* Determine the value for this payment.. Find the split into
* the posted account and pull the value out of that.
* XXX: Should the payment value be an argument here?
*/
{
GList *l = xaccTransGetSplitList (gncInvoiceGetPostedTxn (invoice));
for (; l; l=l->next) {
Split *s = l->data;
if (xaccSplitGetAccount (s) == acct) {
total = xaccSplitGetValue (s);
break;
}
}
/* Make sure we found the Split */
g_return_val_if_fail (l, NULL);
}
/* XXX: Figure out the common currency */
txn = xaccMallocTransaction (invoice->book);
xaccTransBeginEdit (txn);
/* Set Transaction Description (customer), Num (invoice ID), Currency */
xaccTransSetDescription
(txn, gncOwnerGetName (gncInvoiceGetOwner (invoice)));
xaccTransSetNum (txn, gncInvoiceGetID (invoice));
xaccTransSetCurrency (txn, commonCommodity);
/* Entered and Posted at date */
if (paid_date) {
xaccTransSetDateEnteredTS (txn, paid_date);
xaccTransSetDatePostedTS (txn, paid_date);
gncInvoiceSetDatePaid (invoice, paid_date);
}
/* create the split to the payment account */
{
Split *split = xaccMallocSplit (invoice->book);
/* Set action/memo */
xaccSplitSetBaseValue (split, total, commonCommodity);
xaccAccountBeginEdit (acc);
xaccAccountInsertSplit (acc, split);
xaccAccountCommitEdit (acc);
xaccTransAppendSplit (txn, split);
}
/* Now create the Payment split for the posted acc, reverse value */
{
Split *split = xaccMallocSplit (invoice->book);
/* Set action/memo */
xaccSplitSetBaseValue (split, gnc_numeric_neg (total), commonCommodity);
xaccAccountBeginEdit (acct);
xaccAccountInsertSplit (acct, split);
xaccAccountCommitEdit (acct);
xaccTransAppendSplit (txn, split);
}
/* Now attach this invoice to the txn and account */
gncInvoiceAttachInvoiceToTxn (invoice, txn, TXN_TYPE_PAYMENT);
xaccTransCommitEdit (txn);
return txn;
}
GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn)
{
kvp_frame *kvp;
@ -503,7 +630,10 @@ int gncInvoiceCompare (GncInvoice *a, GncInvoice *b)
compare = timespec_cmp (&(a->date_opened), &(b->date_opened));
if (!compare) return compare;
compare = timespec_cmp (&(a->date_closed), &(b->date_closed));
compare = timespec_cmp (&(a->date_posted), &(b->date_posted));
if (!compare) return compare;
compare = timespec_cmp (&(a->date_paid), &(b->date_paid));
if (!compare) return compare;
return guid_compare (&(a->guid), &(b->guid));
@ -577,11 +707,13 @@ gboolean gncInvoiceRegister (void)
{ INVOICE_ID, QUERYCORE_STRING, (QueryAccess)gncInvoiceGetID },
{ INVOICE_OWNER, GNC_OWNER_MODULE_NAME, (QueryAccess)gncInvoiceGetOwner },
{ INVOICE_OPENED, QUERYCORE_DATE, (QueryAccess)gncInvoiceGetDateOpened },
{ INVOICE_POSTED, QUERYCORE_DATE, (QueryAccess)gncInvoiceGetDatePosted },
{ INVOICE_DUE, QUERYCORE_DATE, (QueryAccess)gncInvoiceGetDateDue },
{ INVOICE_CLOSED, QUERYCORE_DATE, (QueryAccess)gncInvoiceGetDateClosed },
{ INVOICE_PAID, QUERYCORE_DATE, (QueryAccess)gncInvoiceGetDatePaid },
{ INVOICE_NOTES, QUERYCORE_STRING, (QueryAccess)gncInvoiceGetNotes },
{ INVOICE_ACC, GNC_ID_ACCOUNT, (QueryAccess)gncInvoiceGetPostedAcc },
{ INVOICE_TXN, GNC_ID_TRANS, (QueryAccess)gncInvoiceGetPostedTxn },
{ INVOICE_POST_TXN, GNC_ID_TRANS, (QueryAccess)gncInvoiceGetPostedTxn },
{ INVOICE_PD_TXN, GNC_ID_TRANS, (QueryAccess)gncInvoiceGetPaidTxn },
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncInvoiceGetBook },
{ NULL },
};

View File

@ -25,8 +25,9 @@ void gncInvoiceDestroy (GncInvoice *invoice);
void gncInvoiceSetID (GncInvoice *invoice, const char *id);
void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner);
void gncInvoiceSetDateOpened (GncInvoice *invoice, const Timespec *date);
void gncInvoiceSetDatePosted (GncInvoice *invoice, const Timespec *date);
void gncInvoiceSetDateDue (GncInvoice *invoice, const Timespec *date);
void gncInvoiceSetDateClosed (GncInvoice *invoice, const Timespec *date);
void gncInvoiceSetDatePaid (GncInvoice *invoice, const Timespec *date);
void gncInvoiceSetTerms (GncInvoice *invoice, const char *terms);
void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes);
void gncInvoiceSetActive (GncInvoice *invoice, gboolean active);
@ -41,13 +42,15 @@ const GUID * gncInvoiceGetGUID (GncInvoice *invoice);
const char * gncInvoiceGetID (GncInvoice *invoice);
GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
Timespec gncInvoiceGetDateOpened (GncInvoice *invoice);
Timespec gncInvoiceGetDatePosted (GncInvoice *invoice);
Timespec gncInvoiceGetDateDue (GncInvoice *invoice);
Timespec gncInvoiceGetDateClosed (GncInvoice *invoice);
Timespec gncInvoiceGetDatePaid (GncInvoice *invoice);
const char * gncInvoiceGetTerms (GncInvoice *invoice);
const char * gncInvoiceGetNotes (GncInvoice *invoice);
gboolean gncInvoiceGetActive (GncInvoice *invoice);
Transaction * gncInvoiceGetPostedTxn (GncInvoice *invoice);
Transaction * gncInvoiceGetPaidTxn (GncInvoice *invoice);
Account * gncInvoiceGetPostedAcc (GncInvoice *invoice);
GList * gncInvoiceGetEntries (GncInvoice *invoice);
@ -62,6 +65,14 @@ Transaction *
gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
Timespec *posted_date, gboolean reverse);
/* Pay this invoice, by creating a split from the posted_acc to the
* supplied (bank) account, occuring at the specified paid_date.
*/
Transaction *
gncInvoicePayToAccount (GncInvoice *invoice, Account *acc,
Timespec *paid_date);
/* Given a transaction, find and return the Invoice */
GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn);
@ -75,10 +86,12 @@ int gncInvoiceCompare (GncInvoice *a, GncInvoice *b);
#define INVOICE_ID "id"
#define INVOICE_OWNER "owner"
#define INVOICE_OPENED "date_opened"
#define INVOICE_POSTED "date_posted"
#define INVOICE_DUE "date_due"
#define INVOICE_CLOSED "date_closed"
#define INVOICE_PAID "date_paid"
#define INVOICE_NOTES "notes"
#define INVOICE_ACC "account"
#define INVOICE_TXN "txn"
#define INVOICE_POST_TXN "posted_txn"
#define INVOICE_PD_TXN "paid_txn"
#endif /* GNC_INVOICE_H_ */

View File

@ -17,6 +17,6 @@ void gncInvoiceSetGUID (GncInvoice *invoice, const GUID *guid);
void gncInvoiceSetDirty (GncInvoice *invoice, gboolean dirty);
void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc);
void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
void gncInvoiceAttachInvoiceToTxn (GncInvoice *invoice, Transaction *txn);
void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn);
#endif /* GNC_INVOICEP_H_ */

View File

@ -24,7 +24,7 @@ typedef struct _dialog_date_close_window {
GtkWidget *post_date;
GtkWidget *acct_combo;
Timespec *ts, *ts2;
GNCAccountType acct_type;
GList * acct_types;
GNCBook *book;
Account *acct;
gboolean retval;
@ -49,8 +49,8 @@ ask_make_acct (DialogDateClose *ddc, const char *name, gboolean new_acc)
return NULL;
}
types = g_list_append (types, (gpointer)(ddc->acct_type));
acc = gnc_ui_new_accounts_from_name_window_with_types (name, types);
acc = gnc_ui_new_accounts_from_name_window_with_types (name,
ddc->acct_types);
g_list_free (types);
return acc;
}
@ -83,13 +83,12 @@ gnc_dialog_date_close_ok_cb (GtkWidget *widget, gpointer user_data)
return;
}
if (xaccAccountGetType (acc) != ddc->acct_type) {
if (g_list_index (ddc->acct_types, (gpointer)xaccAccountGetType (acc))
== -1) {
char *message =
g_strdup_printf (_("Invalid Account Type, %s.\n"
"You need an account of type %s."
"Please try again..."),
xaccAccountGetTypeStr (xaccAccountGetType (acc)),
xaccAccountGetTypeStr (ddc->acct_type));
xaccAccountGetTypeStr (xaccAccountGetType (acc)));
gnc_error_dialog_parented (GTK_WINDOW (ddc->dialog), message);
g_free (name);
name = xaccAccountGetFullName (acc, gnc_get_account_separator ());
@ -144,7 +143,8 @@ fill_in_acct_info (DialogDateClose *ddc)
char *name;
/* Only present accounts of the appropriate type */
if (xaccAccountGetType (account) != ddc->acct_type)
if (g_list_index (ddc->acct_types,
(gpointer)xaccAccountGetType (account)) == -1)
continue;
name = xaccAccountGetFullName (account, gnc_get_account_separator ());
@ -252,20 +252,21 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
gtk_main ();
retval = ddc->retval;
g_list_free (ddc->acct_types);
g_free (ddc);
return retval;
}
gboolean
gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
const char *ddue_label_message,
const char *post_label_message,
const char *acct_label_message,
gboolean ok_is_default,
GNCAccountType acct_type, GNCBook *book,
/* Returned Data... */
Timespec *ddue, Timespec *post, Account **acct)
gnc_dialog_dates_acct_parented (GtkWidget *parent, const char *message,
const char *ddue_label_message,
const char *post_label_message,
const char *acct_label_message,
gboolean ok_is_default,
GList * acct_types, GNCBook *book,
/* Returned Data... */
Timespec *ddue, Timespec *post, Account **acct)
{
DialogDateClose *ddc;
GtkWidget *hbox;
@ -274,14 +275,14 @@ gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
gboolean retval;
if (!message || !ddue_label_message || !post_label_message ||
!acct_label_message || !book || !ddue || !post || !acct)
!acct_label_message || !acct_types || !book || !ddue || !post || !acct)
return FALSE;
ddc = g_new0 (DialogDateClose, 1);
ddc->ts = ddue;
ddc->ts2 = post;
ddc->book = book;
ddc->acct_type = acct_type;
ddc->acct_types = acct_types;
xml = gnc_glade_xml_new ("date-close.glade", "Date Account Dialog");
ddc->dialog = glade_xml_get_widget (xml, "Date Account Dialog");
@ -332,3 +333,75 @@ gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
return retval;
}
gboolean
gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
const char *date_label_message,
const char *acct_label_message,
gboolean ok_is_default,
GList * acct_types, GNCBook *book,
/* Returned Data... */
Timespec *date, Account **acct)
{
DialogDateClose *ddc;
GtkWidget *hbox;
GtkWidget *label;
GladeXML *xml;
gboolean retval;
if (!message || !date_label_message || !acct_label_message ||
!acct_types || !book || !date || !acct)
return FALSE;
ddc = g_new0 (DialogDateClose, 1);
ddc->ts = date;
ddc->book = book;
ddc->acct_types = acct_types;
xml = gnc_glade_xml_new ("date-close.glade", "Date Account Dialog");
ddc->dialog = glade_xml_get_widget (xml, "Date Account Dialog");
ddc->date = glade_xml_get_widget (xml, "date");
ddc->acct_combo = glade_xml_get_widget (xml, "acct_combo");
hbox = glade_xml_get_widget (xml, "the_hbox");
if (parent)
gnome_dialog_set_parent (GNOME_DIALOG(ddc->dialog), GTK_WINDOW(parent));
build_date_close_window (hbox, message);
/* Set the labels */
label = glade_xml_get_widget (xml, "date_label");
gtk_label_set_text (GTK_LABEL (label), date_label_message);
label = glade_xml_get_widget (xml, "acct_label");
gtk_label_set_text (GTK_LABEL (label), acct_label_message);
/* Set the date widget */
gnome_date_edit_set_time (GNOME_DATE_EDIT (ddc->date), date->tv_sec);
/* Setup the account widget */
fill_in_acct_info (ddc);
/* Connect the buttons */
gnome_dialog_button_connect
(GNOME_DIALOG(ddc->dialog), 0,
GTK_SIGNAL_FUNC(gnc_dialog_date_close_ok_cb), ddc);
gnome_dialog_button_connect
(GNOME_DIALOG(ddc->dialog), 1,
GTK_SIGNAL_FUNC(gnc_dialog_date_close_cancel_cb), ddc);
gtk_signal_connect (GTK_OBJECT(ddc->dialog), "close",
GTK_SIGNAL_FUNC(gnc_dialog_date_close_cb), ddc);
gtk_window_set_modal (GTK_WINDOW (ddc->dialog), TRUE);
gtk_widget_show (ddc->dialog);
gtk_widget_hide_all (glade_xml_get_widget (xml, "postdate_label"));
gtk_widget_hide_all (glade_xml_get_widget (xml, "post_date"));
gtk_main ();
retval = ddc->retval;
*acct = ddc->acct;
g_free (ddc);
return retval;
}

View File

@ -19,15 +19,29 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
Timespec *date);
/*
* Note that the dialog will "own" (and free) the acct_types list.
* it should be a list of GNCAccountTypes
*/
gboolean
gnc_dialog_dates_acct_parented (GtkWidget *parent, const char *message,
const char *ddue_label_message,
const char *post_label_message,
const char *acct_label_message,
gboolean ok_is_default,
GList * acct_types, GNCBook *book,
/* Returned Data... */
Timespec *ddue, Timespec *post,
Account **acct);
gboolean
gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
const char *ddue_label_message,
const char *post_label_message,
const char *date_label_message,
const char *acct_label_message,
gboolean ok_is_default,
GNCAccountType acct_type, GNCBook *book,
/* Returned Data... */
Timespec *ddue, Timespec *post, Account **acct);
GList * acct_types, GNCBook *book,
/* Returned Data... */
Timespec *date, Account **acct);
#endif /* _DIALOG_DATE_CLOSE_H */

View File

@ -206,7 +206,7 @@ gnc_invoice_window_post_invoice_cb (GtkWidget *widget, gpointer data)
GncInvoice *invoice;
char *message, *ddue_label, *post_label, *acct_label;
Account *acc = NULL;
GNCAccountType acct_type;
GList * acct_types = NULL;
Timespec ddue, postdate;
gboolean reverse = FALSE;
@ -218,8 +218,8 @@ gnc_invoice_window_post_invoice_cb (GtkWidget *widget, gpointer data)
if (!invoice)
return;
/* Ok, we can close this. Ask for verification, set the closed date,
* due date, and posted account
/* Ok, we can post this invoice. Ask for verification, set the due date,
* post date, and posted account
*/
message = _("Do you really want to post the invoice?");
ddue_label = _("Due Date");
@ -229,22 +229,22 @@ gnc_invoice_window_post_invoice_cb (GtkWidget *widget, gpointer data)
/* Determine the type of account to post to */
switch (gncOwnerGetType (&(iw->owner))) {
case GNC_OWNER_CUSTOMER:
acct_type = RECEIVABLE;
acct_types = g_list_prepend (NULL, (gpointer)RECEIVABLE);
reverse = TRUE;
break;
case GNC_OWNER_VENDOR:
acct_type = PAYABLE;
acct_types = g_list_prepend (NULL, (gpointer)PAYABLE);
break;
default:
acct_type = NO_TYPE;
acct_types = g_list_prepend (NULL, (gpointer)NO_TYPE);
}
/* Get the due date and posted account */
timespecFromTime_t (&postdate, time(NULL));
ddue = postdate;
ddue.tv_sec += 3600*24*30; /* XXX: due in 30 days */
if (!gnc_dialog_date_acct_parented (iw->dialog, message, ddue_label,
post_label, acct_label, TRUE, acct_type,
if (!gnc_dialog_dates_acct_parented (iw->dialog, message, ddue_label,
post_label, acct_label, TRUE, acct_types,
iw->book, &ddue, &postdate, &acc))
return;
@ -269,30 +269,45 @@ gnc_invoice_window_post_invoice_cb (GtkWidget *widget, gpointer data)
}
static void
gnc_invoice_window_close_invoice_cb (GtkWidget *widget, gpointer data)
gnc_invoice_window_pay_invoice_cb (GtkWidget *widget, gpointer data)
{
InvoiceWindow *iw = data;
GncInvoice *invoice;
char *message, *label;
Timespec ts;
char *message, *date_label, *acct_label;
GList *acct_types;
Timespec paid_date;
Account *acc = NULL;
/* Note that this assumes we're already posted! Should we check? */
/* Note that this assumes we're already posted! Should we check?
* There shuldn't be any way to get to this callback unless we're
* already posted.
*/
invoice = iw_get_invoice (iw);
if (!invoice)
return;
message = _("Do you really want to close the invoice?");
label = _("Closed Date");
message = _("Do you really want to pay the invoice?");
date_label = _("Date Paid");
acct_label = _("Pay to Account");
timespecFromTime_t (&ts, time(NULL));
if (!gnc_dialog_date_close_parented (iw->dialog, message, label, TRUE, &ts))
/* Add "appropriate" accounts */
acct_types = g_list_prepend (NULL, BANK);
acct_types = g_list_prepend (acct_types, CASH);
acct_types = g_list_prepend (acct_types, ASSET);
acct_types = g_list_prepend (acct_types, LIABILITY);
timespecFromTime_t (&paid_date, time(NULL));
if (!gnc_dialog_date_acct_parented (iw->dialog, message, date_label,
acct_label, TRUE, acct_types,
iw->book, &paid_date, &acc))
return;
gncInvoiceSetDateClosed (invoice, &ts);
/* Pay to the account now */
gncInvoicePayToAccount (invoice, acc, &paid_date);
/* And close the invoice */
return gnc_invoice_window_ok_cb (widget, data);
/* ... and redisplay here. */
gnc_invoice_update_window (iw);
}
static void
@ -415,18 +430,19 @@ gnc_configure_register_colors (void)
static void
gnc_invoice_update_window (InvoiceWindow *iw)
{
GtkWidget *closed_date, *due_date, *acct_entry;
GtkWidget *paid_date, *posted_date, *due_date, *acct_entry;
GncInvoice *invoice;
GncOwner *owner;
gboolean is_posted = FALSE;
gboolean is_closed = FALSE;
gboolean is_paid = FALSE;
invoice = iw_get_invoice (iw);
owner = gncInvoiceGetOwner (invoice);
gtk_widget_show_all (iw->dialog);
closed_date = glade_xml_get_widget (iw->xml, "closed_date");
paid_date = glade_xml_get_widget (iw->xml, "paid_date");
posted_date = glade_xml_get_widget (iw->xml, "posted_date");
due_date = glade_xml_get_widget (iw->xml, "due_date");
acct_entry = glade_xml_get_widget (iw->xml, "acct_entry");
@ -473,50 +489,57 @@ gnc_invoice_update_window (InvoiceWindow *iw)
ts = gncInvoiceGetDateDue (invoice);
gnome_date_edit_set_time (GNOME_DATE_EDIT (due_date), ts.tv_sec);
ts = gncInvoiceGetDatePosted (invoice);
gnome_date_edit_set_time (GNOME_DATE_EDIT (posted_date), ts.tv_sec);
string = xaccAccountGetFullName (acct, gnc_get_account_separator ());
gtk_entry_set_text (GTK_ENTRY (acct_entry), string);
/*
* Check if we're closed. By closed, we'll have an actual
* closed-date as well as everything else. Note that you can be
* posted without being closed, but not the reverse. Perhaps
* "closed" should be renamed to "paid"?
* Check if we're paid. By paid, we'll have an actual
* paid-date as well as everything else. Note that you can be
* posted without being paid, but not the reverse.
*/
ts = gncInvoiceGetDateClosed (invoice);
ts = gncInvoiceGetDatePaid (invoice);
if (timespec_equal (&ts, &ts_zero))
break;
is_closed = TRUE;
gnome_date_edit_set_time (GNOME_DATE_EDIT (closed_date), ts.tv_sec);
is_paid = TRUE;
gnome_date_edit_set_time (GNOME_DATE_EDIT (paid_date), ts.tv_sec);
} while (FALSE);
/* Hide/show the appropriate widgets based on our posted/closed state */
/* Hide/show the appropriate widgets based on our posted/paid state */
if (is_closed == FALSE) {
if (is_paid == FALSE) {
GtkWidget *hide;
hide = glade_xml_get_widget (iw->xml, "cd_label");
hide = glade_xml_get_widget (iw->xml, "paid_label");
gtk_widget_hide_all (hide);
gtk_widget_hide_all (closed_date);
gtk_widget_hide_all (paid_date);
hide = glade_xml_get_widget (iw->xml, "hide1");
gtk_widget_hide_all (hide);
hide = glade_xml_get_widget (iw->xml, "hide2");
gtk_widget_hide_all (hide);
if (is_posted == TRUE) {
hide = glade_xml_get_widget (iw->xml, "hide1");
gtk_widget_hide_all (hide);
hide = glade_xml_get_widget (iw->xml, "hide2");
gtk_widget_hide_all (hide);
if (is_posted == FALSE) {
hide = glade_xml_get_widget (iw->xml, "dd_label");
} else { /* ! posted */
hide = glade_xml_get_widget (iw->xml, "due_label");
gtk_widget_hide_all (hide);
gtk_widget_hide_all (due_date);
hide = glade_xml_get_widget (iw->xml, "posted_label");
gtk_widget_hide_all (hide);
gtk_widget_hide_all (posted_date);
hide = glade_xml_get_widget (iw->xml, "acct_label");
gtk_widget_hide_all (hide);
gtk_widget_hide_all (acct_entry);
/* hide the close invoice button -- it needs to be posted first! */
hide = glade_xml_get_widget (iw->xml, "close_invoice_button");
hide = glade_xml_get_widget (iw->xml, "pay_invoice_button");
gtk_widget_hide_all (hide);
/* Also hide the print invoice button, for the same reason */
@ -534,12 +557,16 @@ gnc_invoice_update_window (InvoiceWindow *iw)
gtk_widget_set_sensitive (iw->opened_date, FALSE);
gtk_widget_set_sensitive (iw->notes_text, FALSE); /* XXX: should notes remain writable? */
/* Hide the 'post invoice' button: "VIEW" implies is_posted */
/* Hide the 'post invoice' button */
hide = glade_xml_get_widget (iw->xml, "post_invoice_button");
gtk_widget_hide_all (hide);
if (is_closed) {
hide = glade_xml_get_widget (iw->xml, "close_invoice_button");
/* Hide the 'cancel' button */
hide = glade_xml_get_widget (iw->xml, "cancel_button");
gtk_widget_hide_all (hide);
if (is_paid) {
hide = glade_xml_get_widget (iw->xml, "pay_invoice_button");
gtk_widget_hide_all (hide);
}
}
@ -647,7 +674,7 @@ gnc_invoice_new_window (GtkWidget *parent, GNCBook *bookp,
(iwd, 4, GTK_SIGNAL_FUNC(gnc_invoice_window_post_invoice_cb), iw);
gnome_dialog_button_connect
(iwd, 5, GTK_SIGNAL_FUNC(gnc_invoice_window_close_invoice_cb), iw);
(iwd, 5, GTK_SIGNAL_FUNC(gnc_invoice_window_pay_invoice_cb), iw);
/* Setup initial values */
iw->invoice_guid = *gncInvoiceGetGUID (invoice);

View File

@ -589,6 +589,8 @@ gnc_order_new_window (GtkWidget *parent, GNCBook *bookp,
/* Hide the 'close order' button */
hide = glade_xml_get_widget (xml, "close_order_button");
gtk_widget_hide_all (hide);
hide = glade_xml_get_widget (xml, "cancel_button");
gtk_widget_hide_all (hide);
hide = glade_xml_get_widget (xml, "new_invoice_button");
gtk_widget_hide_all (hide);
}

View File

@ -69,7 +69,7 @@
<widget>
<class>GtkButton</class>
<name>button2</name>
<name>cancel_button</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button>
@ -101,10 +101,10 @@
<widget>
<class>GtkButton</class>
<name>close_invoice_button</name>
<name>pay_invoice_button</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<label>Close Invoice</label>
<label>Pay Invoice</label>
</widget>
</widget>
@ -195,8 +195,8 @@
<widget>
<class>GtkLabel</class>
<name>dd_label</name>
<label>Date Due</label>
<name>posted_label</name>
<label>Date Posted</label>
<justify>GTK_JUSTIFY_RIGHT</justify>
<wrap>False</wrap>
<xalign>1</xalign>
@ -212,8 +212,8 @@
<widget>
<class>GtkLabel</class>
<name>cd_label</name>
<label>Date Closed</label>
<name>paid_label</name>
<label>Date Paid</label>
<justify>GTK_JUSTIFY_RIGHT</justify>
<wrap>False</wrap>
<xalign>1</xalign>
@ -288,7 +288,7 @@
<widget>
<class>GnomeDateEdit</class>
<name>due_date</name>
<name>posted_date</name>
<sensitive>False</sensitive>
<show_time>False</show_time>
<use_24_format>False</use_24_format>
@ -304,7 +304,7 @@
<widget>
<class>GnomeDateEdit</class>
<name>closed_date</name>
<name>paid_date</name>
<sensitive>False</sensitive>
<show_time>False</show_time>
<use_24_format>False</use_24_format>
@ -417,11 +417,11 @@
<widget>
<class>GtkLabel</class>
<name>hide1</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<name>due_label</name>
<label>Date Due</label>
<justify>GTK_JUSTIFY_RIGHT</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<xalign>1</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
@ -434,7 +434,7 @@
<widget>
<class>GtkLabel</class>
<name>label11</name>
<name>hide1</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
@ -508,15 +508,14 @@
</widget>
<widget>
<class>GtkLabel</class>
<name>hide2</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<class>GnomeDateEdit</class>
<name>due_date</name>
<sensitive>False</sensitive>
<show_time>False</show_time>
<use_24_format>False</use_24_format>
<week_start_monday>False</week_start_monday>
<lower_hour>7</lower_hour>
<upper_hour>19</upper_hour>
<child>
<padding>0</padding>
<expand>False</expand>
@ -526,7 +525,7 @@
<widget>
<class>GtkLabel</class>
<name>label12</name>
<name>hide2</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>

View File

@ -69,7 +69,7 @@
<widget>
<class>GtkButton</class>
<name>button2</name>
<name>cancel_button</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button>

View File

@ -172,8 +172,6 @@ option_changed (GtkWidget *widget, GNCSearchDate *fe)
static void
date_changed (GNCDateEdit *date_edit, GNCSearchDate *fe)
{
time_t tt;
fe->ts = gnc_date_edit_get_date_ts (date_edit);
}

View File

@ -148,6 +148,15 @@ gnc_search_param_set_param_path (GNCSearchParam *param,
param->priv->type = type;
}
void
gnc_search_param_override_param_type (GNCSearchParam *param,
GNCIdTypeConst *param_type)
{
g_assert (IS_GNCSEARCH_PARAM (param));
g_assert (param_type != NULL && *param_type != '\0');
param->priv->type = param_type;
}
GSList *
gnc_search_param_get_param_path (GNCSearchParam *param)
{

View File

@ -47,4 +47,14 @@ void gnc_search_param_set_title (GNCSearchParam *param,
gboolean gnc_search_param_type_match (GNCSearchParam *a,
GNCSearchParam *b);
/* This will override the automatic param_type logic from "set_param_path()"
* so that the programmer can force a particular UI to appear for a given
* parameter path. This should be used with care -- if used improperly
* it could result in an invalid Query Term, where the path and the predicate
* don't match types properly.
*/
void gnc_search_param_override_param_type (GNCSearchParam *param,
GNCIdTypeConst *param_type);
#endif /* _GNCSEARCH_PARAM_H */