* integrate the Billing Terms into the Core, GUI, and XML Backend

for the rest of the business objects that need billing terms.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6994 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2002-06-22 02:38:13 +00:00
parent 64555fa8c3
commit 00a335aca1
22 changed files with 316 additions and 107 deletions

View File

@ -1,5 +1,8 @@
2002-06-21 Derek Atkins <derek@ihtfp.com>
* integrate the Billing Terms into the Core, GUI, and XML Backend
for the rest of the business objects that need billing terms.
* .../business-core/gncBillTerm*.[ch]: Add Billing Term objects.
Currently there are "Days" and "Proximo" billing terms available.

View File

@ -41,6 +41,7 @@
#include "io-gncxml-gen.h"
#include "io-gncxml-v2.h"
#include "gncBillTermP.h"
#include "gncCustomerP.h"
#include "gnc-customer-xml-v2.h"
#include "gnc-address-xml-v2.h"
@ -81,6 +82,7 @@ customer_dom_tree_create (GncCustomer *cust)
{
xmlNodePtr ret;
gnc_numeric num;
GncBillTerm *term;
ret = xmlNewNode(NULL, gnc_customer_string);
xmlSetProp(ret, "version", customer_version_string);
@ -101,7 +103,11 @@ customer_dom_tree_create (GncCustomer *cust)
gncCustomerGetShipAddr (cust)));
maybe_add_string (ret, cust_notes_string, gncCustomerGetNotes (cust));
maybe_add_string (ret, cust_terms_string, gncCustomerGetTerms (cust));
term = gncCustomerGetTerms (cust);
if (term)
xmlAddChild(ret, guid_to_dom_tree(cust_terms_string,
gncBillTermGetGUID (term)));
xmlAddChild(ret, int_to_dom_tree(cust_taxincluded_string,
gncCustomerGetTaxIncluded (cust)));
@ -195,8 +201,22 @@ static gboolean
customer_terms_handler (xmlNodePtr node, gpointer cust_pdata)
{
struct customer_pdata *pdata = cust_pdata;
GUID *guid;
GncBillTerm *term;
return set_string(node, pdata->customer, gncCustomerSetTerms);
guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE);
term = gncBillTermLookup (pdata->book, guid);
if (!term) {
term = gncBillTermCreate (pdata->book);
gncBillTermSetGUID (term, guid);
} else
gncBillTermDecRef (term);
g_free (guid);
gncCustomerSetTerms (pdata->customer, term);
return TRUE;
}
static gboolean

View File

@ -41,6 +41,7 @@
#include "io-gncxml-gen.h"
#include "io-gncxml-v2.h"
#include "gncBillTermP.h"
#include "gncInvoiceP.h"
#include "gnc-invoice-xml-v2.h"
#include "gnc-owner-xml-v2.h"
@ -90,6 +91,7 @@ invoice_dom_tree_create (GncInvoice *invoice)
Timespec ts;
Transaction *txn;
Account *acc;
GncBillTerm *term;
ret = xmlNewNode(NULL, gnc_invoice_string);
xmlSetProp(ret, "version", invoice_version_string);
@ -109,7 +111,11 @@ invoice_dom_tree_create (GncInvoice *invoice)
maybe_add_timespec (ret, invoice_posted_string,
gncInvoiceGetDatePosted (invoice));
maybe_add_string (ret, invoice_terms_string, gncInvoiceGetTerms (invoice));
term = gncInvoiceGetTerms (invoice);
if (term)
xmlAddChild(ret, guid_to_dom_tree(invoice_terms_string,
gncBillTermGetGUID (term)));
maybe_add_string (ret, invoice_billing_id_string,
gncInvoiceGetBillingID (invoice));
maybe_add_string (ret, invoice_notes_string, gncInvoiceGetNotes (invoice));
@ -229,14 +235,6 @@ invoice_posted_handler (xmlNodePtr node, gpointer invoice_pdata)
return set_timespec (node, pdata->invoice, gncInvoiceSetDatePosted);
}
static gboolean
invoice_terms_handler (xmlNodePtr node, gpointer invoice_pdata)
{
struct invoice_pdata *pdata = invoice_pdata;
return set_string(node, pdata->invoice, gncInvoiceSetTerms);
}
static gboolean
invoice_billing_id_handler (xmlNodePtr node, gpointer invoice_pdata)
{
@ -267,6 +265,28 @@ invoice_active_handler (xmlNodePtr node, gpointer invoice_pdata)
return ret;
}
static gboolean
invoice_terms_handler (xmlNodePtr node, gpointer invoice_pdata)
{
struct invoice_pdata *pdata = invoice_pdata;
GUID *guid;
GncBillTerm *term;
guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE);
term = gncBillTermLookup (pdata->book, guid);
if (!term) {
term = gncBillTermCreate (pdata->book);
gncBillTermSetGUID (term, guid);
} else
gncBillTermDecRef (term);
g_free (guid);
gncInvoiceSetTerms (pdata->invoice, term);
return TRUE;
}
static gboolean
invoice_posttxn_handler (xmlNodePtr node, gpointer invoice_pdata)
{
@ -321,10 +341,10 @@ static struct dom_tree_handler invoice_handlers_v2[] = {
{ invoice_owner_string, invoice_owner_handler, 1, 0 },
{ invoice_opened_string, invoice_opened_handler, 1, 0 },
{ invoice_posted_string, invoice_posted_handler, 0, 0 },
{ invoice_terms_string, invoice_terms_handler, 0, 0 },
{ invoice_billing_id_string, invoice_billing_id_handler, 0, 0 },
{ invoice_notes_string, invoice_notes_handler, 0, 0 },
{ invoice_active_string, invoice_active_handler, 1, 0 },
{ invoice_terms_string, invoice_terms_handler, 0, 0 },
{ invoice_posttxn_string, invoice_posttxn_handler, 0, 0 },
{ invoice_postacc_string, invoice_postacc_handler, 0, 0 },
{ invoice_commodity_string, invoice_commodity_handler, 1, 0 },

View File

@ -41,6 +41,7 @@
#include "io-gncxml-gen.h"
#include "io-gncxml-v2.h"
#include "gncBillTermP.h"
#include "gncVendorP.h"
#include "gnc-vendor-xml-v2.h"
#include "gnc-address-xml-v2.h"
@ -77,6 +78,7 @@ static xmlNodePtr
vendor_dom_tree_create (GncVendor *vendor)
{
xmlNodePtr ret;
GncBillTerm *term;
ret = xmlNewNode(NULL, gnc_vendor_string);
xmlSetProp(ret, "version", vendor_version_string);
@ -94,7 +96,11 @@ vendor_dom_tree_create (GncVendor *vendor)
gncVendorGetAddr (vendor)));
maybe_add_string (ret, vendor_notes_string, gncVendorGetNotes (vendor));
maybe_add_string (ret, vendor_terms_string, gncVendorGetTerms (vendor));
term = gncVendorGetTerms (vendor);
if (term)
xmlAddChild(ret, guid_to_dom_tree(vendor_terms_string,
gncBillTermGetGUID (term)));
xmlAddChild(ret, int_to_dom_tree(vendor_taxincluded_string,
gncVendorGetTaxIncluded (vendor)));
@ -182,8 +188,22 @@ static gboolean
vendor_terms_handler (xmlNodePtr node, gpointer vendor_pdata)
{
struct vendor_pdata *pdata = vendor_pdata;
GUID *guid;
GncBillTerm *term;
return set_string(node, pdata->vendor, gncVendorSetTerms);
guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE);
term = gncBillTermLookup (pdata->book, guid);
if (!term) {
term = gncBillTermCreate (pdata->book);
gncBillTermSetGUID (term, guid);
} else
gncBillTermDecRef (term);
g_free (guid);
gncVendorSetTerms (pdata->vendor, term);
return TRUE;
}
static gboolean

View File

@ -29,7 +29,7 @@ struct _gncCustomer {
char * id;
char * name;
char * notes;
char * terms;
GncBillTerm * terms;
GncAddress * addr;
GncAddress * shipaddr;
gnc_commodity * commodity;
@ -72,7 +72,6 @@ GncCustomer *gncCustomerCreate (GNCBook *book)
cust->id = CACHE_INSERT ("");
cust->name = CACHE_INSERT ("");
cust->notes = CACHE_INSERT ("");
cust->terms = CACHE_INSERT ("Net-30");
cust->addr = gncAddressCreate (book, &cust->guid);
cust->shipaddr = gncAddressCreate (book, &cust->guid);
cust->discount = gnc_numeric_zero();
@ -98,7 +97,6 @@ void gncCustomerDestroy (GncCustomer *cust)
CACHE_REMOVE (cust->id);
CACHE_REMOVE (cust->name);
CACHE_REMOVE (cust->notes);
CACHE_REMOVE (cust->terms);
gncAddressDestroy (cust->addr);
gncAddressDestroy (cust->shipaddr);
g_list_free (cust->jobs);
@ -153,10 +151,15 @@ void gncCustomerSetGUID (GncCustomer *cust, const GUID *guid)
addObj (cust);
}
void gncCustomerSetTerms (GncCustomer *cust, const char *terms)
void gncCustomerSetTerms (GncCustomer *cust, GncBillTerm *terms)
{
if (!cust || !terms) return;
SET_STR(cust->terms, terms);
if (!cust) return;
if (cust->terms == terms) return;
if (cust->terms)
gncBillTermDecRef (cust->terms);
cust->terms = terms;
if (cust->terms)
gncBillTermIncRef (cust->terms);
mark_customer (cust);
}
@ -286,7 +289,7 @@ const char * gncCustomerGetNotes (GncCustomer *cust)
return cust->notes;
}
const char * gncCustomerGetTerms (GncCustomer *cust)
GncBillTerm * gncCustomerGetTerms (GncCustomer *cust)
{
if (!cust) return NULL;
return cust->terms;

View File

@ -11,6 +11,7 @@ typedef struct _gncCustomer GncCustomer;
#include "gnc-book.h"
#include "gncAddress.h"
#include "gncBillTerm.h"
#include "gncJob.h"
#include "gnc-numeric.h"
@ -27,7 +28,7 @@ void gncCustomerDestroy (GncCustomer *customer);
void gncCustomerSetID (GncCustomer *customer, const char *id);
void gncCustomerSetName (GncCustomer *customer, const char *name);
void gncCustomerSetNotes (GncCustomer *customer, const char *notes);
void gncCustomerSetTerms (GncCustomer *customer, const char *terms);
void gncCustomerSetTerms (GncCustomer *customer, GncBillTerm *term);
void gncCustomerSetTaxIncluded (GncCustomer *customer, gboolean taxincl);
void gncCustomerSetActive (GncCustomer *customer, gboolean active);
void gncCustomerSetDiscount (GncCustomer *customer, gnc_numeric discount);
@ -48,7 +49,7 @@ const char * gncCustomerGetName (GncCustomer *customer);
GncAddress * gncCustomerGetAddr (GncCustomer *customer);
GncAddress * gncCustomerGetShipAddr (GncCustomer *customer);
const char * gncCustomerGetNotes (GncCustomer *customer);
const char * gncCustomerGetTerms (GncCustomer *customer);
GncBillTerm * gncCustomerGetTerms (GncCustomer *customer);
gboolean gncCustomerGetTaxIncluded (GncCustomer *customer);
gboolean gncCustomerGetActive (GncCustomer *customer);
gnc_numeric gncCustomerGetDiscount (GncCustomer *customer);

View File

@ -33,9 +33,9 @@ struct _gncInvoice {
GUID guid;
char * id;
char * notes;
char * terms;
char * billing_id;
char * printname;
GncBillTerm * terms;
GList * entries;
GncOwner owner;
GncJob * job;
@ -94,7 +94,6 @@ GncInvoice *gncInvoiceCreate (GNCBook *book)
invoice->id = CACHE_INSERT ("");
invoice->notes = CACHE_INSERT ("");
invoice->terms = CACHE_INSERT ("");
invoice->billing_id = CACHE_INSERT ("");
invoice->active = TRUE;
@ -115,7 +114,6 @@ void gncInvoiceDestroy (GncInvoice *invoice)
CACHE_REMOVE (invoice->id);
CACHE_REMOVE (invoice->notes);
CACHE_REMOVE (invoice->terms);
CACHE_REMOVE (invoice->billing_id);
g_list_free (invoice->entries);
remObj (invoice);
@ -168,10 +166,15 @@ void gncInvoiceSetDatePosted (GncInvoice *invoice, Timespec date)
mark_invoice (invoice);
}
void gncInvoiceSetTerms (GncInvoice *invoice, const char *terms)
void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms)
{
if (!invoice) return;
SET_STR (invoice->terms, terms);
if (invoice->terms == terms) return;
if (invoice->terms)
gncBillTermDecRef (invoice->terms);
invoice->terms = terms;
if (invoice->terms)
gncBillTermIncRef (invoice->terms);
mark_invoice (invoice);
}
@ -306,7 +309,7 @@ Timespec gncInvoiceGetDateDue (GncInvoice *invoice)
return xaccTransRetDateDueTS (txn);
}
const char * gncInvoiceGetTerms (GncInvoice *invoice)
GncBillTerm * gncInvoiceGetTerms (GncInvoice *invoice)
{
if (!invoice) return 0;
return invoice->terms;
@ -418,6 +421,12 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
if (!invoice || !acc) return NULL;
/* Stabilize the Billing Terms of this invoice */
if (invoice->terms)
gncInvoiceSetTerms (invoice,
gncBillTermReturnChild (invoice->terms, TRUE));
/* Figure out if we need to "reverse" the numbers. */
reverse = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
/* Create a new lot for this invoice */
@ -694,12 +703,12 @@ gboolean gncInvoiceRegister (void)
{ INVOICE_DUE, QUERYCORE_DATE, (QueryAccess)gncInvoiceGetDateDue },
{ INVOICE_POSTED, QUERYCORE_DATE, (QueryAccess)gncInvoiceGetDatePosted },
{ INVOICE_IS_POSTED, QUERYCORE_BOOLEAN, (QueryAccess)gncInvoiceIsPosted },
{ INVOICE_TERMS, QUERYCORE_STRING, (QueryAccess)gncInvoiceGetTerms },
{ INVOICE_BILLINGID, QUERYCORE_STRING, (QueryAccess)gncInvoiceGetBillingID },
{ INVOICE_NOTES, QUERYCORE_STRING, (QueryAccess)gncInvoiceGetNotes },
{ INVOICE_ACC, GNC_ID_ACCOUNT, (QueryAccess)gncInvoiceGetPostedAcc },
{ INVOICE_POST_TXN, GNC_ID_TRANS, (QueryAccess)gncInvoiceGetPostedTxn },
{ INVOICE_TYPE, QUERYCORE_STRING, (QueryAccess)gncInvoiceGetType },
{ INVOICE_TERMS, GNC_BILLTERM_MODULE_NAME, (QueryAccess)gncInvoiceGetTerms },
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncInvoiceGetBook },
{ QUERY_PARAM_GUID, QUERYCORE_GUID, (QueryAccess)gncInvoiceGetGUID },
{ NULL },

View File

@ -10,6 +10,7 @@
struct _gncInvoice;
typedef struct _gncInvoice GncInvoice;
#include "gncBillTerm.h"
#include "gncEntry.h"
#include "gncOwner.h"
@ -26,7 +27,7 @@ void gncInvoiceSetID (GncInvoice *invoice, const char *id);
void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner);
void gncInvoiceSetDateOpened (GncInvoice *invoice, Timespec date);
void gncInvoiceSetDatePosted (GncInvoice *invoice, Timespec date);
void gncInvoiceSetTerms (GncInvoice *invoice, const char *terms);
void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms);
void gncInvoiceSetBillingID (GncInvoice *invoice, const char *billing_id);
void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes);
void gncInvoiceSetCommonCommodity (GncInvoice *invoice, gnc_commodity *com);
@ -44,7 +45,7 @@ GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
Timespec gncInvoiceGetDateOpened (GncInvoice *invoice);
Timespec gncInvoiceGetDatePosted (GncInvoice *invoice);
Timespec gncInvoiceGetDateDue (GncInvoice *invoice);
const char * gncInvoiceGetTerms (GncInvoice *invoice);
GncBillTerm * gncInvoiceGetTerms (GncInvoice *invoice);
const char * gncInvoiceGetBillingID (GncInvoice *invoice);
const char * gncInvoiceGetNotes (GncInvoice *invoice);
const char * gncInvoiceGetType (GncInvoice *invoice);

View File

@ -28,7 +28,7 @@ struct _gncVendor {
char * id;
char * name;
char * notes;
char * terms;
GncBillTerm * terms;
GncAddress * addr;
gnc_commodity * commodity;
gboolean taxincluded;
@ -68,7 +68,6 @@ GncVendor *gncVendorCreate (GNCBook *book)
vendor->id = CACHE_INSERT ("");
vendor->name = CACHE_INSERT ("");
vendor->notes = CACHE_INSERT ("");
vendor->terms = CACHE_INSERT ("");
vendor->addr = gncAddressCreate (book, &vendor->guid);
vendor->taxincluded = FALSE;
vendor->active = TRUE;
@ -90,7 +89,6 @@ void gncVendorDestroy (GncVendor *vendor)
CACHE_REMOVE (vendor->id);
CACHE_REMOVE (vendor->name);
CACHE_REMOVE (vendor->notes);
CACHE_REMOVE (vendor->terms);
gncAddressDestroy (vendor->addr);
g_list_free (vendor->jobs);
@ -144,10 +142,15 @@ void gncVendorSetGUID (GncVendor *vendor, const GUID *guid)
addObj (vendor);
}
void gncVendorSetTerms (GncVendor *vendor, const char *terms)
void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms)
{
if (!vendor || !terms) return;
SET_STR(vendor->terms, terms);
if (!vendor) return;
if (vendor->terms == terms) return;
if (vendor->terms)
gncBillTermDecRef (vendor->terms);
vendor->terms = terms;
if (vendor->terms)
gncBillTermDecRef (vendor->terms);
mark_vendor (vendor);
}
@ -215,7 +218,7 @@ const char * gncVendorGetNotes (GncVendor *vendor)
return vendor->notes;
}
const char * gncVendorGetTerms (GncVendor *vendor)
GncBillTerm * gncVendorGetTerms (GncVendor *vendor)
{
if (!vendor) return 0;
return vendor->terms;

View File

@ -11,6 +11,7 @@ typedef struct _gncVendor GncVendor;
#include "gnc-book.h"
#include "gncAddress.h"
#include "gncBillTerm.h"
#include "gncJob.h"
#define GNC_VENDOR_MODULE_NAME "gncVendor"
@ -25,7 +26,7 @@ void gncVendorDestroy (GncVendor *vendor);
void gncVendorSetID (GncVendor *vendor, const char *id);
void gncVendorSetName (GncVendor *vendor, const char *name);
void gncVendorSetNotes (GncVendor *vendor, const char *notes);
void gncVendorSetTerms (GncVendor *vendor, const char *terms);
void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms);
void gncVendorSetTaxIncluded (GncVendor *vendor, gboolean taxincl);
void gncVendorSetCommodity (GncVendor *vendor, gnc_commodity *com);
void gncVendorSetActive (GncVendor *vendor, gboolean active);
@ -43,7 +44,7 @@ const char * gncVendorGetID (GncVendor *vendor);
const char * gncVendorGetName (GncVendor *vendor);
GncAddress * gncVendorGetAddr (GncVendor *vendor);
const char * gncVendorGetNotes (GncVendor *vendor);
const char * gncVendorGetTerms (GncVendor *vendor);
GncBillTerm * gncVendorGetTerms (GncVendor *vendor);
gboolean gncVendorGetTaxIncluded (GncVendor *vendor);
gnc_commodity * gncVendorGetCommodity (GncVendor *vendor);
gboolean gncVendorGetActive (GncVendor *vendor);

View File

@ -34,6 +34,7 @@
(lambda (wrapset client-wrapset)
(list
"#include <gncAddress.h>\n"
"#include <gncBillTerm.h>\n"
"#include <gncCustomer.h>\n"
"#include <gncEmployee.h>\n"
"#include <gncEntry.h>\n"
@ -41,6 +42,7 @@
"#include <gncJob.h>\n"
"#include <gncOrder.h>\n"
"#include <gncOwner.h>\n"
"#include <gncTaxTable.h>\n"
"#include <gncVendor.h>\n")))
(gw:wrapset-add-cs-initializers!
@ -54,6 +56,7 @@
;; XXX: Need to add lists of all of these!
(gw:wrap-as-wct ws '<gnc:GncAddress*> "GncAddress*" "const GncAddress*")
(gw:wrap-as-wct ws '<gnc:GncBillTerm*> "GncBillTerm*" "const GncBillTerm*")
(gw:wrap-as-wct ws '<gnc:GncCustomer*> "GncCustomer*" "const GncCustomer*")
(gw:wrap-as-wct ws '<gnc:GncEmployee*> "GncEmployee*" "const GncEmployee*")
(gw:wrap-as-wct ws '<gnc:GncEntry*> "GncEntry*" "const GncEntry*")
@ -61,6 +64,7 @@
(gw:wrap-as-wct ws '<gnc:GncJob*> "GncJob*" "const GncJob*")
(gw:wrap-as-wct ws '<gnc:GncOrder*> "GncOrder*" "const GncOrder*")
(gw:wrap-as-wct ws '<gnc:GncOwner*> "GncOwner*" "const GncOwner*")
(gw:wrap-as-wct ws '<gnc:GncTaxTable*> "GncTaxTable*" "const GncTaxTable*")
(gw:wrap-as-wct ws '<gnc:GncVendor*> "GncVendor*" "const GncVendor*")
(let ((wt (gw:wrap-enumeration ws '<gnc:GncOwnerType> "GncOwnerType")))
@ -183,6 +187,26 @@
'((<gnc:GncAddress*> address))
"Return the Address's Email Entry")
;;
;; gncBillTerm.h
;;
(gw:wrap-function
ws
'gnc:bill-term-get-name
'(<gw:mchars> callee-owned const)
"gncBillTermGetName"
'((<gnc:GncBillTerm*> term))
"Return the Bill-term name")
(gw:wrap-function
ws
'gnc:bill-term-get-description
'(<gw:mchars> callee-owned const)
"gncBillTermGetDescription"
'((<gnc:GncBillTerm*> term))
"Return the printable Bill-term description")
;;
;; gncCustomer.h
;;
@ -450,7 +474,7 @@
'gnc:invoice-set-terms
'<gw:void>
"gncInvoiceSetTerms"
'((<gnc:GncInvoice*> invoice) ((<gw:mchars> callee-owned const) id))
'((<gnc:GncInvoice*> invoice) (<gnc:GncBillTerm*> term))
"Set the Invoice Terms")
(gw:wrap-function
@ -514,7 +538,7 @@
(gw:wrap-function
ws
'gnc:invoice-get-terms
'(<gw:mchars> callee-owned const)
'(<gnc:GncBillTerm*>)
"gncInvoiceGetTerms"
'((<gnc:GncInvoice*> invoice))
"Return the invoice's Terms")

View File

@ -60,7 +60,7 @@ test_customer (void)
test_string_fcn (book, "Name", gncCustomerSetName, gncCustomerGetName);
test_string_fcn (book, "Notes", gncCustomerSetNotes, gncCustomerGetNotes);
test_string_fcn (book, "Terms", gncCustomerSetTerms, gncCustomerGetTerms);
//test_string_fcn (book, "Terms", gncCustomerSetTerms, gncCustomerGetTerms);
test_numeric_fcn (book, "Discount", gncCustomerSetDiscount, gncCustomerGetDiscount);
test_numeric_fcn (book, "Credit", gncCustomerSetCredit, gncCustomerGetCredit);

View File

@ -62,7 +62,7 @@ test_vendor (void)
test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName);
test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes);
test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms);
//test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms);
test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded);
test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive);

View File

@ -214,3 +214,87 @@ gnc_business_account_types (GncOwner *owner)
return (g_list_prepend (NULL, (gpointer)NO_TYPE));
}
}
static void
business_option_changed (GtkWidget *widget, gpointer *result)
{
*result =
gtk_object_get_data (GTK_OBJECT (widget), "this_item");
}
static void
add_menu_item (GtkWidget *menu, const char *label, gpointer *result,
gpointer this_item)
{
GtkWidget *item = gtk_menu_item_new_with_label (label);
gtk_object_set_data (GTK_OBJECT (item), "this_item", this_item);
gtk_signal_connect (GTK_OBJECT (item), "activate",
business_option_changed, result);
gtk_menu_append (GTK_MENU (menu), item);
gtk_widget_show (item);
}
#define DO_ADD_ITEM(s,o) { \
add_menu_item (menu, (s), result, (o)); \
if (*result == (o)) current = index; \
index++; \
}
typedef const char * (*GenericLookup_t)(gpointer);
static void
make_generic_optionmenu (GList *items, GtkWidget *omenu, GNCBook *book,
gboolean none_ok, GenericLookup_t func,
gpointer *result)
{
GtkWidget *menu;
int current = 0, index = 0;
menu = gtk_menu_new ();
if (none_ok || items == NULL)
DO_ADD_ITEM (_("None"), NULL);
for ( ; items; items = items->next)
DO_ADD_ITEM (func (items->data), items->data);
gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), current);
gtk_widget_show (menu);
}
/* Create an optionmenu of available billing terms and attach it to
* the menu passed in. If none_ok is true, then add "none" as a
* choice (with data set to NULL). Any time the menu changes,
* 'choice' will be set to the chosen option. If *choice is non-NULL,
* then that will be the default option setting when the menu is
* created.
*/
void
gnc_ui_billterms_optionmenu (GtkWidget *omenu, GNCBook *book,
gboolean none_ok, GncBillTerm **choice)
{
GList *terms;
if (!omenu || !choice || !book) return;
terms = gncBillTermGetTerms (book);
make_generic_optionmenu (terms, omenu, book, none_ok,
(GenericLookup_t)gncBillTermGetName,
(gpointer *)choice);
}
void
gnc_ui_taxtables_optionmenu (GtkWidget *omenu, GNCBook *book,
gboolean none_ok, GncTaxTable **choice)
{
GList *tables;
if (!omenu || !choice || !book) return;
tables = gncTaxTableGetTables (book);
make_generic_optionmenu (tables, omenu, book, none_ok,
(GenericLookup_t)gncTaxTableGetName,
(gpointer *)choice);
}

View File

@ -10,6 +10,8 @@
#include "gnc-book.h"
#include "gncOwner.h"
#include "gncBillTerm.h"
#include "gncTaxTable.h"
GtkWidget * gnc_owner_select_create (GtkWidget *label, GtkWidget *hbox,
GNCBook *book, GncOwner *owner);
@ -28,4 +30,20 @@ GList * gnc_business_account_types (GncOwner *owner);
void gnc_fill_account_select_combo (GtkWidget *combo, GNCBook *book,
GList *acct_types);
/* Create an optionmenu of available billing terms and attach it to
* the menu passed in. If none_ok is true, then add "none" as a
* choice (with data set to NULL). Any time the menu changes,
* 'choice' will be set to the chosen option. If *choice is non-NULL,
* then that will be the default option setting when the menu is
* created.
*/
void gnc_ui_billterms_optionmenu (GtkWidget *omenu, GNCBook *book,
gboolean none_ok, GncBillTerm **choice);
/* Same thing except for the tax tables */
void
gnc_ui_taxtables_optionmenu (GtkWidget *omenu, GNCBook *book,
gboolean none_ok, GncTaxTable **choice);
#endif /* GNC_BUSINESS_UTILS_H_ */

View File

@ -25,6 +25,7 @@
#include "gncCustomer.h"
#include "gncCustomerP.h"
#include "business-utils.h"
#include "dialog-customer.h"
#include "dialog-job.h"
#include "dialog-order.h"
@ -69,7 +70,7 @@ struct _customer_window {
GtkWidget * shipfax_entry;
GtkWidget * shipemail_entry;
GtkWidget * terms_entry;
GtkWidget * terms_menu;
GtkWidget * discount_amount;
GtkWidget * credit_amount;
@ -77,6 +78,7 @@ struct _customer_window {
GtkWidget * taxincluded_check;
GtkWidget * notes_text;
GncBillTerm * terms;
CustomerDialogType dialog_type;
GUID customer_guid;
gint component_id;
@ -150,8 +152,7 @@ static void gnc_ui_to_customer (CustomerWindow *cw, GncCustomer *cust)
(GTK_EDITABLE (cw->notes_text), 0, -1));
/* Parse and set the terms, discount, and credit amounts */
gncCustomerSetTerms (cust, gtk_editable_get_chars
(GTK_EDITABLE (cw->terms_entry), 0, -1));
gncCustomerSetTerms (cust, cw->terms);
gncCustomerSetDiscount (cust, gnc_amount_edit_get_amount
(GNC_AMOUNT_EDIT (cw->discount_amount)));
gncCustomerSetCredit (cust, gnc_amount_edit_get_amount
@ -219,10 +220,6 @@ gnc_customer_window_ok_cb (GtkWidget *widget, gpointer data)
/* Verify terms, discount, and credit are valid (or empty) */
min = gnc_numeric_zero ();
max = gnc_numeric_create (100, 1);
// if (check_edit_amount (cw->dialog, cw->terms_amount, &min, NULL,
// _("Terms must be a positive integer or "
// "you must leave it blank.")))
// return;
if (check_edit_amount (cw->dialog, cw->discount_amount, &min, &max,
_("Discount percentage must be between 0-100 "
@ -426,7 +423,7 @@ gnc_customer_new_window (GNCBook *bookp, GncCustomer *cust)
cw->taxincluded_check = glade_xml_get_widget (xml, "tax_included_check");
cw->notes_text = glade_xml_get_widget (xml, "notes_text");
cw->terms_entry = glade_xml_get_widget (xml, "terms_entry");
cw->terms_menu = glade_xml_get_widget (xml, "terms_menu");
/* DISCOUNT: Percentage Value */
edit = gnc_amount_edit_new();
@ -554,6 +551,8 @@ gnc_customer_new_window (GNCBook *bookp, GncCustomer *cust)
gnc_customer_window_refresh_handler,
gnc_customer_window_close_handler,
cw);
cw->terms = gncCustomerGetTerms (cust);
} else {
cust = gncCustomerCreate (bookp);
gncCustomerSetCommodity (cust, commodity);
@ -565,12 +564,15 @@ gnc_customer_new_window (GNCBook *bookp, GncCustomer *cust)
gnc_customer_window_refresh_handler,
gnc_customer_window_close_handler,
cw);
/* XXX: get the global-default terms */
cw->terms = NULL;
}
/* I know that cust exists here -- either passed in or just created */
gtk_entry_set_text (GTK_ENTRY (cw->terms_entry),
gncCustomerGetTerms (cust));
gnc_ui_billterms_optionmenu (cw->terms_menu, bookp, TRUE, &cw->terms);
/* Set the Discount, and Credit amounts */
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->discount_amount),

View File

@ -82,10 +82,11 @@ struct _invoice_window {
GtkWidget * job_box;
GtkWidget * job_choice;
GtkWidget * billing_id_entry;
GtkWidget * terms_entry;
GtkWidget * terms_menu;
gint width;
GncBillTerm * terms;
GnucashRegister * reg;
GncEntryLedger * ledger;
@ -136,8 +137,7 @@ static void gnc_ui_to_invoice (InvoiceWindow *iw, GncInvoice *invoice)
(GTK_EDITABLE (iw->id_entry), 0, -1));
gncInvoiceSetBillingID (invoice, gtk_editable_get_chars
(GTK_EDITABLE (iw->billing_id_entry), 0, -1));
gncInvoiceSetTerms (invoice, gtk_editable_get_chars
(GTK_EDITABLE (iw->terms_entry), 0, -1));
gncInvoiceSetTerms (invoice, iw->terms);
ts = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (iw->opened_date));
gncInvoiceSetDateOpened (invoice, ts);
@ -764,7 +764,7 @@ static int
gnc_invoice_owner_changed_cb (GtkWidget *widget, gpointer data)
{
InvoiceWindow *iw = data;
char const *msg = "";
GncBillTerm *term = NULL;
GncOwner owner;
if (!iw)
@ -791,17 +791,19 @@ gnc_invoice_owner_changed_cb (GtkWidget *widget, gpointer data)
switch (gncOwnerGetType (&(iw->owner))) {
case GNC_OWNER_CUSTOMER:
msg = gncCustomerGetTerms (gncOwnerGetCustomer (&(iw->owner)));
term = gncCustomerGetTerms (gncOwnerGetCustomer (&(iw->owner)));
break;
case GNC_OWNER_VENDOR:
msg = gncVendorGetTerms (gncOwnerGetVendor (&(iw->owner)));
term = gncVendorGetTerms (gncOwnerGetVendor (&(iw->owner)));
break;
default:
g_warning ("Unknown owner type: %d\n", gncOwnerGetType (&(iw->owner)));
break;
}
gtk_entry_set_text (GTK_ENTRY (iw->terms_entry), msg ? msg : "");
/* XXX: I'm not sure -- should we change the terms if this happens? */
iw->terms = term;
gnc_ui_billterms_optionmenu (iw->terms_menu, iw->book, TRUE, &iw->terms);
gnc_invoice_update_job_choice (iw);
@ -991,9 +993,6 @@ gnc_invoice_update_window (InvoiceWindow *iw)
gtk_entry_set_text (GTK_ENTRY (iw->billing_id_entry),
gncInvoiceGetBillingID (invoice));
gtk_entry_set_text (GTK_ENTRY (iw->terms_entry),
gncInvoiceGetTerms (invoice));
string = gncInvoiceGetNotes (invoice);
gtk_editable_delete_text (GTK_EDITABLE (iw->notes_text), 0, -1);
gtk_editable_insert_text (GTK_EDITABLE (iw->notes_text), string,
@ -1010,6 +1009,10 @@ gnc_invoice_update_window (InvoiceWindow *iw)
gnc_date_edit_set_time_ts (GNC_DATE_EDIT (iw->opened_date), ts);
}
/* fill in the terms menu */
iw->terms = gncInvoiceGetTerms (invoice);
gnc_ui_billterms_optionmenu (iw->terms_menu, iw->book, TRUE, &iw->terms);
/*
* Next, figure out if we've been posted, and if so set the
* appropriate bits of information.. Then work on hiding or
@ -1029,7 +1032,6 @@ gnc_invoice_update_window (InvoiceWindow *iw)
string = xaccAccountGetFullName (acct, gnc_get_account_separator ());
gtk_entry_set_text (GTK_ENTRY (acct_entry), string);
} while (FALSE);
if (iw->dialog_type == NEW_INVOICE || iw->dialog_type == MOD_INVOICE)
@ -1075,7 +1077,7 @@ gnc_invoice_update_window (InvoiceWindow *iw)
/* Setup viewer for read-only access */
/*
gtk_widget_set_sensitive (iw->id_entry, FALSE);
gtk_widget_set_sensitive (iw->terms_entry, FALSE);
gtk_widget_set_sensitive (iw->terms_menu, FALSE);
gtk_widget_set_sensitive (iw->opened_date, FALSE);
gtk_widget_set_sensitive (iw->notes_text, FALSE); *//* XXX: should notes remain writable? */
@ -1141,7 +1143,7 @@ gnc_invoice_new_window (GNCBook *bookp, InvoiceDialogType type,
/* Grab the widgets */
iw->id_entry = glade_xml_get_widget (xml, "id_entry");
iw->billing_id_entry = glade_xml_get_widget (xml, "billing_id_entry");
iw->terms_entry = glade_xml_get_widget (xml, "terms_entry");
iw->terms_menu = glade_xml_get_widget (xml, "terms_menu");
iw->notes_text = glade_xml_get_widget (xml, "notes_text");
iw->active_check = glade_xml_get_widget (xml, "active_check");
iw->owner_box = glade_xml_get_widget (xml, "owner_hbox");
@ -1318,7 +1320,7 @@ gnc_invoice_window_new_invoice (GNCBook *bookp, GncOwner *owner,
/* Grab the widgets */
iw->id_entry = glade_xml_get_widget (xml, "id_entry");
iw->billing_id_entry = glade_xml_get_widget (xml, "billing_id_entry");
iw->terms_entry = glade_xml_get_widget (xml, "terms_entry");
iw->terms_menu = glade_xml_get_widget (xml, "terms_menu");
iw->notes_text = glade_xml_get_widget (xml, "notes_text");
iw->owner_box = glade_xml_get_widget (xml, "owner_hbox");
iw->owner_label = glade_xml_get_widget (xml, "owner_label");

View File

@ -24,6 +24,7 @@
#include "gncVendor.h"
#include "gncVendorP.h"
#include "business-utils.h"
#include "dialog-vendor.h"
#include "dialog-job.h"
#include "dialog-order.h"
@ -58,12 +59,13 @@ struct _vendor_window {
GtkWidget * phone_entry;
GtkWidget * fax_entry;
GtkWidget * email_entry;
GtkWidget * terms_entry;
GtkWidget * terms_menu;
GtkWidget * active_check;
GtkWidget * taxincluded_check;
GtkWidget * notes_text;
GncBillTerm * terms;
VendorDialogType dialog_type;
GUID vendor_guid;
gint component_id;
@ -117,8 +119,7 @@ static void gnc_ui_to_vendor (VendorWindow *vw, GncVendor *vendor)
(GTK_TOGGLE_BUTTON (vw->taxincluded_check)));
gncVendorSetNotes (vendor, gtk_editable_get_chars
(GTK_EDITABLE (vw->notes_text), 0, -1));
gncVendorSetTerms (vendor, gtk_editable_get_chars
(GTK_EDITABLE (vw->terms_entry), 0, -1));
gncVendorSetTerms (vendor, vw->terms);
gncVendorCommitEdit (vendor);
gnc_resume_gui_refresh ();
@ -156,13 +157,6 @@ gnc_vendor_window_ok_cb (GtkWidget *widget, gpointer data)
return;
}
// /* Verify terms are valid (or empty) */
// min = gnc_numeric_zero ();
// if (check_edit_amount (vw->dialog, vw->terms_amount, &min, NULL,
// _("Terms must be a positive integer or "
// "you must leave it blank.")))
// return;
/* Check for valid id and set one if necessary */
if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (vw->id_entry)), "") == 0)
gtk_entry_set_text (GTK_ENTRY (vw->id_entry),
@ -341,7 +335,7 @@ gnc_vendor_new_window (GNCBook *bookp, GncVendor *vendor)
vw->active_check = glade_xml_get_widget (xml, "active_check");
vw->taxincluded_check = glade_xml_get_widget (xml, "tax_included_check");
vw->notes_text = glade_xml_get_widget (xml, "notes_text");
vw->terms_entry = glade_xml_get_widget (xml, "terms_entry");
vw->terms_menu = glade_xml_get_widget (xml, "terms_menu");
/* Setup Dialog for Editing */
gnome_dialog_set_default (vwd, 0);
@ -422,6 +416,9 @@ gnc_vendor_new_window (GNCBook *bookp, GncVendor *vendor)
gnc_vendor_window_refresh_handler,
gnc_vendor_window_close_handler,
vw);
vw->terms = gncVendorGetTerms (vendor);
} else {
vendor = gncVendorCreate (bookp);
gncVendorSetCommodity (vendor, gnc_default_currency ());
@ -433,12 +430,15 @@ gnc_vendor_new_window (GNCBook *bookp, GncVendor *vendor)
gnc_vendor_window_refresh_handler,
gnc_vendor_window_close_handler,
vw);
/* XXX: Get the default Billing Terms */
vw->terms = NULL;
}
/* I know that vendor exists here -- either passed in or just created */
/* Set the Terms amounts */
gtk_entry_set_text (GTK_ENTRY (vw->terms_entry), gncVendorGetTerms (vendor));
gnc_ui_billterms_optionmenu (vw->terms_menu, bookp, TRUE, &vw->terms);
gnc_gui_component_watch_entity_type (vw->component_id,
GNC_VENDOR_MODULE_NAME,

View File

@ -716,13 +716,12 @@
</child>
<widget>
<class>GtkEntry</class>
<name>terms_entry</name>
<class>GtkOptionMenu</class>
<name>terms_menu</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<items>(terms)
</items>
<initial_choice>0</initial_choice>
<child>
<padding>0</padding>
<expand>False</expand>

View File

@ -366,13 +366,12 @@
</widget>
<widget>
<class>GtkEntry</class>
<name>terms_entry</name>
<class>GtkOptionMenu</class>
<name>terms_menu</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<items>(terms)
</items>
<initial_choice>0</initial_choice>
<child>
<padding>0</padding>
<expand>False</expand>
@ -912,13 +911,13 @@
</widget>
<widget>
<class>GtkEntry</class>
<name>terms_entry</name>
<class>GtkOptionMenu</class>
<name>terms_menu</name>
<sensitive>False</sensitive>
<can_focus>True</can_focus>
<editable>False</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<items>(terms)
</items>
<initial_choice>0</initial_choice>
<child>
<padding>0</padding>
<expand>False</expand>

View File

@ -683,13 +683,12 @@
</child>
<widget>
<class>GtkEntry</class>
<name>terms_entry</name>
<class>GtkOptionMenu</class>
<name>terms_menu</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<items>(terms)
</items>
<initial_choice>0</initial_choice>
<child>
<padding>0</padding>
<expand>False</expand>

View File

@ -564,7 +564,8 @@
(make-break! document)))))
(if (opt-val "Display" "Invoice Terms")
(let ((terms (gnc:invoice-get-terms invoice)))
(let* ((term (gnc:invoice-get-terms invoice))
(terms (gnc:bill-term-get-description term)))
(if (and terms (> (string-length terms) 0))
(gnc:html-document-add-object!
document