mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add TaxTable entries to Vendor Invoices (Bills); make sure it does
not bleed over into billback items. Fixes RFE #91415 (See ChangeLog for more details) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7208 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
33
ChangeLog
33
ChangeLog
@@ -1,3 +1,36 @@
|
||||
2002-09-14 Derek Atkins <derek@ihtfp.com>
|
||||
Add TaxTable entries to Vendor Invoices (Bills); make sure it does
|
||||
not bleed over into billback items. Fixes RFE #91415
|
||||
|
||||
* business-core/gncEntry.[ch] -- change the API to provide
|
||||
separate storage for Price, Taxtable information, etc. for
|
||||
Invoices and Bills, for chargeback features
|
||||
* business-core/file/gnc-entry-xml-v2.c -- change the XML to
|
||||
clearly separate the "bill" and "invoice" data.
|
||||
* business-core/gw-business-core-spec.scm -- change scheme API
|
||||
to match the new gncEntry API
|
||||
|
||||
* business-core/gncInvoice.c -- use new gncEntry API. If posting
|
||||
a bill, set the invoice-price on each "billable" item.
|
||||
|
||||
* business-gnome/business-prefs.scm -- duplicate the Taxincluded
|
||||
preference into Invoice Taxincluded and Bill Taxincluded.
|
||||
|
||||
* business-gnome/dialog-invoice.c -- use proper Price (Invoice
|
||||
Price or Bill Price) when sorting by price.
|
||||
|
||||
* business-ledger/gncEntryLedgerP.h -- add "is_invoice" flag
|
||||
* business-ledger/gncEntryLedger.c -- set is_invoice at creation
|
||||
* business-ledger/gncEntryLedgerLayout.c -- add TaxTable columns to Bills
|
||||
* business-ledger/gncEntryLedgerLoad.c -- initialize the entry properly
|
||||
based upon this being an invoice or a bill. Use different global
|
||||
pref's as well.
|
||||
* business-ledger/gncEntryLedgerModel.c -- Load/Save using the new API.
|
||||
Make price-cell immutable if the ledger is an invoice-ledger and the
|
||||
entry is attached to a bill.
|
||||
|
||||
* business-reports/invoice.scm -- use new API
|
||||
|
||||
2002-09-07 Christian Stimming <stimming@tuhh.de>
|
||||
|
||||
* src/import-export/gnc-generic-import.c, ...: Patch by Benoit
|
||||
|
||||
@@ -66,20 +66,30 @@ const gchar *entry_version_string = "2.0.0";
|
||||
#define entry_action_string "entry:action"
|
||||
#define entry_notes_string "entry:notes"
|
||||
#define entry_qty_string "entry:qty"
|
||||
#define entry_price_string "entry:price"
|
||||
#define entry_discount_string "entry:discount"
|
||||
#define entry_disctype_string "entry:disc-type"
|
||||
#define entry_dischow_string "entry:disc-how"
|
||||
|
||||
/* cust inv */
|
||||
#define entry_invacct_string "entry:i-acct"
|
||||
#define entry_iprice_string "entry:i-price"
|
||||
#define entry_idiscount_string "entry:i-discount"
|
||||
#define entry_idisctype_string "entry:i-disc-type"
|
||||
#define entry_idischow_string "entry:i-disc-how"
|
||||
#define entry_itaxable_string "entry:i-taxable"
|
||||
#define entry_itaxincluded_string "entry:i-taxincluded"
|
||||
#define entry_itaxtable_string "entry:i-taxtable"
|
||||
|
||||
/* vend bill */
|
||||
#define entry_billacct_string "entry:b-acct"
|
||||
#define entry_taxable_string "entry:taxable"
|
||||
#define entry_taxincluded_string "entry:taxincluded"
|
||||
#define entry_taxtable_string "entry:taxtable"
|
||||
#define entry_bprice_string "entry:b-price"
|
||||
#define entry_btaxable_string "entry:b-taxable"
|
||||
#define entry_btaxincluded_string "entry:b-taxincluded"
|
||||
#define entry_btaxtable_string "entry:b-taxtable"
|
||||
#define entry_billable_string "entry:billable"
|
||||
#define entry_billto_string "entry:billto"
|
||||
|
||||
/* other stuff */
|
||||
#define entry_order_string "entry:order"
|
||||
#define entry_invoice_string "entry:invoice"
|
||||
#define entry_bill_string "entry:bill"
|
||||
#define entry_billable_string "entry:billable"
|
||||
#define entry_billto_string "entry:billto"
|
||||
|
||||
static void
|
||||
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
|
||||
@@ -123,44 +133,49 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
maybe_add_string (ret, entry_notes_string, gncEntryGetNotes (entry));
|
||||
|
||||
maybe_add_numeric (ret, entry_qty_string, gncEntryGetQuantity (entry));
|
||||
maybe_add_numeric (ret, entry_price_string, gncEntryGetPrice (entry));
|
||||
|
||||
maybe_add_numeric (ret, entry_discount_string, gncEntryGetDiscount (entry));
|
||||
xmlAddChild(ret, text_to_dom_tree(entry_disctype_string,
|
||||
gncAmountTypeToString (
|
||||
gncEntryGetDiscountType (entry))));
|
||||
xmlAddChild(ret, text_to_dom_tree(entry_dischow_string,
|
||||
gncEntryDiscountHowToString (
|
||||
gncEntryGetDiscountHow (entry))));
|
||||
/* cust invoice */
|
||||
|
||||
acc = gncEntryGetInvAccount (entry);
|
||||
if (acc)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_invacct_string,
|
||||
xaccAccountGetGUID (acc)));
|
||||
|
||||
maybe_add_numeric (ret, entry_iprice_string, gncEntryGetInvPrice (entry));
|
||||
|
||||
maybe_add_numeric (ret, entry_idiscount_string, gncEntryGetInvDiscount (entry));
|
||||
|
||||
invoice = gncEntryGetInvoice (entry);
|
||||
if (invoice) {
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_invoice_string,
|
||||
gncInvoiceGetGUID (invoice)));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(entry_idisctype_string,
|
||||
gncAmountTypeToString (
|
||||
gncEntryGetInvDiscountType (entry))));
|
||||
xmlAddChild(ret, text_to_dom_tree(entry_idischow_string,
|
||||
gncEntryDiscountHowToString (
|
||||
gncEntryGetInvDiscountHow (entry))));
|
||||
|
||||
xmlAddChild(ret, int_to_dom_tree(entry_itaxable_string,
|
||||
gncEntryGetInvTaxable (entry)));
|
||||
xmlAddChild(ret, int_to_dom_tree(entry_itaxincluded_string,
|
||||
gncEntryGetInvTaxIncluded (entry)));
|
||||
}
|
||||
|
||||
taxtable = gncEntryGetInvTaxTable (entry);
|
||||
if (taxtable)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_itaxtable_string,
|
||||
gncTaxTableGetGUID (taxtable)));
|
||||
|
||||
/* vendor bills */
|
||||
|
||||
acc = gncEntryGetBillAccount (entry);
|
||||
if (acc)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_billacct_string,
|
||||
xaccAccountGetGUID (acc)));
|
||||
|
||||
xmlAddChild(ret, int_to_dom_tree(entry_taxable_string,
|
||||
gncEntryGetTaxable (entry)));
|
||||
xmlAddChild(ret, int_to_dom_tree(entry_taxincluded_string,
|
||||
gncEntryGetTaxIncluded (entry)));
|
||||
taxtable = gncEntryGetTaxTable (entry);
|
||||
if (taxtable)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_taxtable_string,
|
||||
gncTaxTableGetGUID (taxtable)));
|
||||
|
||||
order = gncEntryGetOrder (entry);
|
||||
if (order)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_order_string,
|
||||
gncOrderGetGUID (order)));
|
||||
|
||||
invoice = gncEntryGetInvoice (entry);
|
||||
if (invoice)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_invoice_string,
|
||||
gncInvoiceGetGUID (invoice)));
|
||||
maybe_add_numeric (ret, entry_bprice_string, gncEntryGetBillPrice (entry));
|
||||
|
||||
invoice = gncEntryGetBill (entry);
|
||||
if (invoice) {
|
||||
@@ -172,8 +187,25 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
owner = gncEntryGetBillTo (entry);
|
||||
if (owner && owner->owner.undefined != NULL)
|
||||
xmlAddChild (ret, gnc_owner_to_dom_tree (entry_billto_string, owner));
|
||||
|
||||
xmlAddChild(ret, int_to_dom_tree(entry_btaxable_string,
|
||||
gncEntryGetBillTaxable (entry)));
|
||||
xmlAddChild(ret, int_to_dom_tree(entry_btaxincluded_string,
|
||||
gncEntryGetBillTaxIncluded (entry)));
|
||||
}
|
||||
|
||||
taxtable = gncEntryGetBillTaxTable (entry);
|
||||
if (taxtable)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_btaxtable_string,
|
||||
gncTaxTableGetGUID (taxtable)));
|
||||
|
||||
/* Other stuff */
|
||||
|
||||
order = gncEntryGetOrder (entry);
|
||||
if (order)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_order_string,
|
||||
gncOrderGetGUID (order)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -254,6 +286,27 @@ set_account(xmlNodePtr node, struct entry_pdata *pdata,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
set_taxtable (xmlNodePtr node, struct entry_pdata *pdata,
|
||||
void (*func)(GncEntry *entry, GncTaxTable *taxtable))
|
||||
{
|
||||
GUID *guid;
|
||||
GncTaxTable *taxtable;
|
||||
|
||||
guid = dom_tree_to_guid (node);
|
||||
g_return_val_if_fail (guid, FALSE);
|
||||
taxtable = gncTaxTableLookup (pdata->book, guid);
|
||||
if (!taxtable) {
|
||||
taxtable = gncTaxTableCreate (pdata->book);
|
||||
gncTaxTableSetGUID (taxtable, guid);
|
||||
} else
|
||||
gncTaxTableDecRef (taxtable);
|
||||
|
||||
func (pdata->entry, taxtable);
|
||||
g_free(guid);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_guid_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
@@ -324,24 +377,33 @@ entry_qty_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
return set_numeric(node, pdata->entry, gncEntrySetQuantity);
|
||||
}
|
||||
|
||||
/* Cust invoice */
|
||||
|
||||
static gboolean
|
||||
entry_price_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_invacct_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
|
||||
return set_numeric(node, pdata->entry, gncEntrySetPrice);
|
||||
return set_account (node, pdata, gncEntrySetInvAccount);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_discount_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_iprice_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
|
||||
return set_numeric(node, pdata->entry, gncEntrySetDiscount);
|
||||
return set_numeric(node, pdata->entry, gncEntrySetInvPrice);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_disctype_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_idiscount_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
|
||||
return set_numeric(node, pdata->entry, gncEntrySetInvDiscount);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_idisctype_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
GncAmountType type;
|
||||
@@ -355,13 +417,13 @@ entry_disctype_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
g_free (str);
|
||||
|
||||
if (ret)
|
||||
gncEntrySetDiscountType(pdata->entry, type);
|
||||
gncEntrySetInvDiscountType(pdata->entry, type);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_dischow_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_idischow_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
GncDiscountHow how;
|
||||
@@ -375,29 +437,34 @@ entry_dischow_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
g_free (str);
|
||||
|
||||
if (ret)
|
||||
gncEntrySetDiscountHow(pdata->entry, how);
|
||||
gncEntrySetInvDiscountHow(pdata->entry, how);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_acct_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_itaxable_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
/* XXX: try to figure out if this is an 'invoice' or a 'bill' --
|
||||
* we have to wait until the end!
|
||||
*/
|
||||
|
||||
return set_account (node, pdata, NULL);
|
||||
return set_boolean (node, pdata->entry, gncEntrySetInvTaxable);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_invacct_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_itaxincluded_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
return set_account (node, pdata, gncEntrySetInvAccount);
|
||||
return set_boolean (node, pdata->entry, gncEntrySetInvTaxIncluded);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_itaxtable_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
return set_taxtable (node, pdata, gncEntrySetInvTaxTable);
|
||||
}
|
||||
|
||||
/* vendor bills */
|
||||
|
||||
static gboolean
|
||||
entry_billacct_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
@@ -406,40 +473,57 @@ entry_billacct_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_taxable_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_bprice_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
return set_boolean (node, pdata->entry, gncEntrySetTaxable);
|
||||
|
||||
return set_numeric(node, pdata->entry, gncEntrySetBillPrice);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_taxincluded_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_btaxable_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
return set_boolean (node, pdata->entry, gncEntrySetTaxIncluded);
|
||||
return set_boolean (node, pdata->entry, gncEntrySetBillTaxable);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_taxtable_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_btaxincluded_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
GUID *guid;
|
||||
GncTaxTable *taxtable;
|
||||
|
||||
guid = dom_tree_to_guid (node);
|
||||
g_return_val_if_fail (guid, FALSE);
|
||||
taxtable = gncTaxTableLookup (pdata->book, guid);
|
||||
if (!taxtable) {
|
||||
taxtable = gncTaxTableCreate (pdata->book);
|
||||
gncTaxTableSetGUID (taxtable, guid);
|
||||
} else
|
||||
gncTaxTableDecRef (taxtable);
|
||||
gncEntrySetTaxTable (pdata->entry, taxtable);
|
||||
|
||||
g_free(guid);
|
||||
return TRUE;
|
||||
return set_boolean (node, pdata->entry, gncEntrySetBillTaxIncluded);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_btaxtable_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
return set_taxtable (node, pdata, gncEntrySetBillTaxTable);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_billable_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
return set_boolean (node, pdata->entry, gncEntrySetBillable);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_billto_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
GncOwner billto;
|
||||
gboolean ret;
|
||||
|
||||
ret = gnc_dom_tree_to_owner (node, &billto, pdata->book);
|
||||
if (ret)
|
||||
gncEntrySetBillTo (pdata->entry, &billto);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* The rest of the stuff */
|
||||
|
||||
static gboolean
|
||||
entry_order_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
@@ -503,25 +587,30 @@ entry_bill_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Support for older XML versions */
|
||||
|
||||
static gboolean
|
||||
entry_billable_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_acct_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
return set_boolean (node, pdata->entry, gncEntrySetBillable);
|
||||
/* XXX: try to figure out if this is an 'invoice' or a 'bill' --
|
||||
* we have to wait until the end!
|
||||
*/
|
||||
|
||||
return set_account (node, pdata, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_billto_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
entry_price_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
{
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
GncOwner billto;
|
||||
gboolean ret;
|
||||
struct entry_pdata *pdata = entry_pdata;
|
||||
gboolean res;
|
||||
|
||||
ret = gnc_dom_tree_to_owner (node, &billto, pdata->book);
|
||||
if (ret)
|
||||
gncEntrySetBillTo (pdata->entry, &billto);
|
||||
|
||||
return ret;
|
||||
/* just set both.. Don't worry about extra data if it's wrong */
|
||||
res = set_numeric(node, pdata->entry, gncEntrySetInvPrice);
|
||||
if (res)
|
||||
gncEntrySetBillPrice (pdata->entry, gncEntryGetInvPrice (pdata->entry));
|
||||
return res;
|
||||
}
|
||||
|
||||
static struct dom_tree_handler entry_handlers_v2[] = {
|
||||
@@ -532,21 +621,40 @@ static struct dom_tree_handler entry_handlers_v2[] = {
|
||||
{ entry_action_string, entry_action_handler, 0, 0 },
|
||||
{ entry_notes_string, entry_notes_handler, 0, 0 },
|
||||
{ entry_qty_string, entry_qty_handler, 0, 0 },
|
||||
{ entry_price_string, entry_price_handler, 0, 0 },
|
||||
{ entry_discount_string, entry_discount_handler, 0, 0 },
|
||||
{ entry_disctype_string, entry_disctype_handler, 0, 0 },
|
||||
{ entry_dischow_string, entry_dischow_handler, 0, 0 },
|
||||
{ "entry:acct", entry_acct_handler, 0, 0 },
|
||||
|
||||
/* cust invoice */
|
||||
{ entry_invacct_string, entry_invacct_handler, 0, 0 },
|
||||
{ entry_iprice_string, entry_iprice_handler, 0, 0 },
|
||||
{ entry_idiscount_string, entry_idiscount_handler, 0, 0 },
|
||||
{ entry_idisctype_string, entry_idisctype_handler, 0, 0 },
|
||||
{ entry_idischow_string, entry_idischow_handler, 0, 0 },
|
||||
{ entry_itaxable_string, entry_itaxable_handler, 0, 0 },
|
||||
{ entry_itaxincluded_string, entry_itaxincluded_handler, 0, 0 },
|
||||
{ entry_itaxtable_string, entry_itaxtable_handler, 0, 0 },
|
||||
|
||||
/* vendor invoice */
|
||||
{ entry_billacct_string, entry_billacct_handler, 0, 0 },
|
||||
{ entry_taxable_string, entry_taxable_handler, 0, 0 },
|
||||
{ entry_taxincluded_string, entry_taxincluded_handler, 0, 0 },
|
||||
{ entry_taxtable_string, entry_taxtable_handler, 0, 0 },
|
||||
{ entry_bprice_string, entry_bprice_handler, 0, 0 },
|
||||
{ entry_btaxable_string, entry_btaxable_handler, 0, 0 },
|
||||
{ entry_btaxincluded_string, entry_btaxincluded_handler, 0, 0 },
|
||||
{ entry_btaxtable_string, entry_btaxtable_handler, 0, 0 },
|
||||
{ entry_billable_string, entry_billable_handler, 0, 0 },
|
||||
{ entry_billto_string, entry_billto_handler, 0, 0 },
|
||||
|
||||
/* Other stuff */
|
||||
{ entry_order_string, entry_order_handler, 0, 0 },
|
||||
{ entry_invoice_string, entry_invoice_handler, 0, 0 },
|
||||
{ entry_bill_string, entry_bill_handler, 0, 0 },
|
||||
{ entry_billable_string, entry_billable_handler, 0, 0 },
|
||||
{ entry_billto_string, entry_billto_handler, 0, 0 },
|
||||
|
||||
/* Old XML support */
|
||||
{ "entry:acct", entry_acct_handler, 0, 0 },
|
||||
{ "entry:price", entry_price_handler, 0, 0 },
|
||||
{ "entry:discount", entry_idiscount_handler, 0, 0 },
|
||||
{ "entry:disc-type", entry_idisctype_handler, 0, 0 },
|
||||
{ "entry:disc-how", entry_idischow_handler, 0, 0 },
|
||||
{ "entry:taxable", entry_itaxable_handler, 0, 0 },
|
||||
{ "entry:taxincluded", entry_itaxincluded_handler, 0, 0 },
|
||||
{ "entry:taxtable", entry_itaxtable_handler, 0, 0 },
|
||||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -32,17 +32,23 @@ struct _gncEntry {
|
||||
char * action;
|
||||
char * notes;
|
||||
gnc_numeric quantity;
|
||||
gnc_numeric price;
|
||||
gnc_numeric discount;
|
||||
GncAmountType disc_type;
|
||||
GncDiscountHow disc_how;
|
||||
Account * invaccount;
|
||||
Account * bilaccount;
|
||||
|
||||
gboolean taxable;
|
||||
gboolean taxincluded;
|
||||
GncTaxTable * tax_table;
|
||||
/* customer invoice data */
|
||||
Account * i_account;
|
||||
gnc_numeric i_price;
|
||||
gboolean i_taxable;
|
||||
gboolean i_taxincluded;
|
||||
GncTaxTable * i_tax_table;
|
||||
gnc_numeric i_discount;
|
||||
GncAmountType i_disc_type;
|
||||
GncDiscountHow i_disc_how;
|
||||
|
||||
/* vendor bill data */
|
||||
Account * b_account;
|
||||
gnc_numeric b_price;
|
||||
gboolean b_taxable;
|
||||
gboolean b_taxincluded;
|
||||
GncTaxTable * b_tax_table;
|
||||
gboolean billable;
|
||||
GncOwner billto;
|
||||
|
||||
@@ -50,17 +56,29 @@ struct _gncEntry {
|
||||
GncInvoice * invoice;
|
||||
GncInvoice * bill;
|
||||
|
||||
gnc_numeric value;
|
||||
gnc_numeric value_rounded;
|
||||
GList * tax_values;
|
||||
gnc_numeric tax_value;
|
||||
gnc_numeric tax_value_rounded;
|
||||
gnc_numeric disc_value;
|
||||
gnc_numeric disc_value_rounded;
|
||||
gboolean values_dirty;
|
||||
Timespec taxtable_modtime;
|
||||
|
||||
gboolean dirty;
|
||||
|
||||
/* CACHED VALUES */
|
||||
|
||||
gboolean values_dirty;
|
||||
|
||||
/* customer invoice */
|
||||
gnc_numeric i_value;
|
||||
gnc_numeric i_value_rounded;
|
||||
GList * i_tax_values;
|
||||
gnc_numeric i_tax_value;
|
||||
gnc_numeric i_tax_value_rounded;
|
||||
gnc_numeric i_disc_value;
|
||||
gnc_numeric i_disc_value_rounded;
|
||||
Timespec i_taxtable_modtime;
|
||||
|
||||
/* vendor bill */
|
||||
gnc_numeric b_value;
|
||||
gnc_numeric b_value_rounded;
|
||||
GList * b_tax_values;
|
||||
gnc_numeric b_tax_value;
|
||||
gnc_numeric b_tax_value_rounded;
|
||||
Timespec b_taxtable_modtime;
|
||||
};
|
||||
|
||||
/* You must edit the functions in this block in tandem. KEEP THEM IN
|
||||
@@ -127,6 +145,7 @@ mark_entry (GncEntry *entry)
|
||||
GncEntry *gncEntryCreate (GNCBook *book)
|
||||
{
|
||||
GncEntry *entry;
|
||||
gnc_numeric zero = gnc_numeric_zero ();
|
||||
|
||||
if (!book) return NULL;
|
||||
|
||||
@@ -136,20 +155,20 @@ GncEntry *gncEntryCreate (GNCBook *book)
|
||||
entry->desc = CACHE_INSERT ("");
|
||||
entry->action = CACHE_INSERT ("");
|
||||
entry->notes = CACHE_INSERT ("");
|
||||
entry->quantity = zero;
|
||||
|
||||
{
|
||||
gnc_numeric zero = gnc_numeric_zero ();
|
||||
entry->quantity = zero;
|
||||
entry->price = zero;
|
||||
entry->discount = zero;
|
||||
}
|
||||
entry->disc_type = GNC_AMT_TYPE_PERCENT;
|
||||
entry->disc_how = GNC_DISC_PRETAX;
|
||||
entry->taxable = TRUE;
|
||||
entry->dirty = FALSE;
|
||||
entry->values_dirty = TRUE;
|
||||
entry->i_price = zero;
|
||||
entry->i_taxable = TRUE;
|
||||
entry->i_discount = zero;
|
||||
entry->i_disc_type = GNC_AMT_TYPE_PERCENT;
|
||||
entry->i_disc_how = GNC_DISC_PRETAX;
|
||||
|
||||
entry->b_price = zero;
|
||||
entry->b_taxable = TRUE;
|
||||
entry->billto.type = GNC_OWNER_CUSTOMER;
|
||||
|
||||
entry->values_dirty = TRUE;
|
||||
|
||||
xaccGUIDNew (&entry->guid, book);
|
||||
addObj (entry);
|
||||
|
||||
@@ -167,8 +186,10 @@ void gncEntryDestroy (GncEntry *entry)
|
||||
CACHE_REMOVE (entry->desc);
|
||||
CACHE_REMOVE (entry->action);
|
||||
CACHE_REMOVE (entry->notes);
|
||||
if (entry->tax_values)
|
||||
gncAccountValueDestroy (entry->tax_values);
|
||||
if (entry->i_tax_values)
|
||||
gncAccountValueDestroy (entry->i_tax_values);
|
||||
if (entry->b_tax_values)
|
||||
gncAccountValueDestroy (entry->b_tax_values);
|
||||
remObj (entry);
|
||||
|
||||
g_free (entry);
|
||||
@@ -232,37 +253,150 @@ void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity)
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetPrice (GncEntry *entry, gnc_numeric price)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (gnc_numeric_eq (entry->price, price)) return;
|
||||
entry->price = price;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetDiscount (GncEntry *entry, gnc_numeric discount)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (gnc_numeric_eq (entry->discount, discount)) return;
|
||||
entry->discount = discount;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
/* Customer Invoices */
|
||||
|
||||
void gncEntrySetInvAccount (GncEntry *entry, Account *acc)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->invaccount == acc) return;
|
||||
entry->invaccount = acc;
|
||||
if (entry->i_account == acc) return;
|
||||
entry->i_account = acc;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetInvPrice (GncEntry *entry, gnc_numeric price)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (gnc_numeric_eq (entry->i_price, price)) return;
|
||||
entry->i_price = price;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetInvTaxable (GncEntry *entry, gboolean taxable)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->i_taxable == taxable) return;
|
||||
entry->i_taxable = taxable;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetInvTaxIncluded (GncEntry *entry, gboolean taxincluded)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->i_taxincluded == taxincluded) return;
|
||||
entry->i_taxincluded = taxincluded;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetInvTaxTable (GncEntry *entry, GncTaxTable *table)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->i_tax_table == table) return;
|
||||
if (entry->i_tax_table)
|
||||
gncTaxTableDecRef (entry->i_tax_table);
|
||||
if (table)
|
||||
gncTaxTableIncRef (table);
|
||||
entry->i_tax_table = table;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetInvDiscount (GncEntry *entry, gnc_numeric discount)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (gnc_numeric_eq (entry->i_discount, discount)) return;
|
||||
entry->i_discount = discount;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetInvDiscountType (GncEntry *entry, GncAmountType type)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->i_disc_type == type) return;
|
||||
|
||||
entry->i_disc_type = type;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetInvDiscountHow (GncEntry *entry, GncDiscountHow how)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->i_disc_how == how) return;
|
||||
|
||||
entry->i_disc_how = how;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
/* Vendor Bills */
|
||||
|
||||
void gncEntrySetBillAccount (GncEntry *entry, Account *acc)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->bilaccount == acc) return;
|
||||
entry->bilaccount = acc;
|
||||
if (entry->b_account == acc) return;
|
||||
entry->b_account = acc;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetBillPrice (GncEntry *entry, gnc_numeric price)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (gnc_numeric_eq (entry->b_price, price)) return;
|
||||
entry->b_price = price;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetBillTaxable (GncEntry *entry, gboolean taxable)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->b_taxable == taxable) return;
|
||||
entry->b_taxable = taxable;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetBillTaxIncluded (GncEntry *entry, gboolean taxincluded)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->b_taxincluded == taxincluded) return;
|
||||
entry->b_taxincluded = taxincluded;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetBillTaxTable (GncEntry *entry, GncTaxTable *table)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->b_tax_table == table) return;
|
||||
if (entry->b_tax_table)
|
||||
gncTaxTableDecRef (entry->b_tax_table);
|
||||
if (table)
|
||||
gncTaxTableIncRef (table);
|
||||
entry->b_tax_table = table;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetBillable (GncEntry *entry, gboolean billable)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->billable == billable) return;
|
||||
|
||||
entry->billable = billable;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetBillTo (GncEntry *entry, GncOwner *billto)
|
||||
{
|
||||
if (!entry || !billto) return;
|
||||
if (gncOwnerEqual (&entry->billto, billto)) return;
|
||||
|
||||
gncOwnerCopy (billto, &entry->billto);
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
@@ -297,75 +431,6 @@ void gncEntrySetBill (GncEntry *entry, GncInvoice *bill)
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetTaxable (GncEntry *entry, gboolean taxable)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->taxable == taxable) return;
|
||||
entry->taxable = taxable;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetTaxIncluded (GncEntry *entry, gboolean taxincluded)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->taxincluded == taxincluded) return;
|
||||
entry->taxincluded = taxincluded;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetTaxTable (GncEntry *entry, GncTaxTable *table)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->tax_table == table) return;
|
||||
if (entry->tax_table)
|
||||
gncTaxTableDecRef (entry->tax_table);
|
||||
if (table)
|
||||
gncTaxTableIncRef (table);
|
||||
entry->tax_table = table;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetDiscountType (GncEntry *entry, GncAmountType type)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->disc_type == type) return;
|
||||
|
||||
entry->disc_type = type;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetDiscountHow (GncEntry *entry, GncDiscountHow how)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->disc_how == how) return;
|
||||
|
||||
entry->disc_how = how;
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetBillable (GncEntry *entry, gboolean billable)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (entry->billable == billable) return;
|
||||
|
||||
entry->billable = billable;
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetBillTo (GncEntry *entry, GncOwner *billto)
|
||||
{
|
||||
if (!entry || !billto) return;
|
||||
if (gncOwnerEqual (&entry->billto, billto)) return;
|
||||
|
||||
gncOwnerCopy (billto, &entry->billto);
|
||||
mark_entry (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetDirty (GncEntry *entry, gboolean dirty)
|
||||
{
|
||||
if (!entry) return;
|
||||
@@ -382,18 +447,28 @@ void gncEntryCopy (const GncEntry *src, GncEntry *dest)
|
||||
gncEntrySetAction (dest, src->action);
|
||||
gncEntrySetNotes (dest, src->notes);
|
||||
dest->quantity = src->quantity;
|
||||
dest->price = src->price;
|
||||
dest->discount = src->discount;
|
||||
dest->disc_type = src->disc_type;
|
||||
dest->invaccount = src->invaccount;
|
||||
dest->bilaccount = src->bilaccount;
|
||||
dest->taxable = src->taxable;
|
||||
dest->taxincluded = src->taxincluded;
|
||||
|
||||
dest->i_account = src->i_account;
|
||||
dest->i_price = src->i_price;
|
||||
dest->i_taxable = src->i_taxable;
|
||||
dest->i_taxincluded = src->i_taxincluded;
|
||||
dest->i_discount = src->i_discount;
|
||||
dest->i_disc_type = src->i_disc_type;
|
||||
dest->i_disc_how = src->i_disc_how;
|
||||
|
||||
/* vendor bill data */
|
||||
dest->b_account = src->b_account;
|
||||
dest->b_price = src->b_price;
|
||||
dest->b_taxable = src->b_taxable;
|
||||
dest->b_taxincluded = src->b_taxincluded;
|
||||
dest->billable = src->billable;
|
||||
dest->billto = src->billto;
|
||||
|
||||
if (src->tax_table)
|
||||
gncEntrySetTaxTable (dest, src->tax_table);
|
||||
if (src->i_tax_table)
|
||||
gncEntrySetInvTaxTable (dest, src->i_tax_table);
|
||||
|
||||
if (src->b_tax_table)
|
||||
gncEntrySetBillTaxTable (dest, src->b_tax_table);
|
||||
|
||||
if (src->order)
|
||||
gncOrderAddEntry (src->order, dest);
|
||||
@@ -459,28 +534,98 @@ gnc_numeric gncEntryGetQuantity (GncEntry *entry)
|
||||
return entry->quantity;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetPrice (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->price;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetDiscount (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->discount;
|
||||
}
|
||||
/* Customer Invoice */
|
||||
|
||||
Account * gncEntryGetInvAccount (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->invaccount;
|
||||
return entry->i_account;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetInvPrice (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->i_price;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetInvDiscount (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->i_discount;
|
||||
}
|
||||
|
||||
GncAmountType gncEntryGetInvDiscountType (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return 0;
|
||||
return entry->i_disc_type;
|
||||
}
|
||||
|
||||
GncDiscountHow gncEntryGetInvDiscountHow (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return 0;
|
||||
return entry->i_disc_how;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetInvTaxable (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->i_taxable;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetInvTaxIncluded (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->i_taxincluded;
|
||||
}
|
||||
|
||||
GncTaxTable * gncEntryGetInvTaxTable (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->i_tax_table;
|
||||
}
|
||||
|
||||
/* vendor bills */
|
||||
|
||||
Account * gncEntryGetBillAccount (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->bilaccount;
|
||||
return entry->b_account;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetBillPrice (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->b_price;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetBillTaxable (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->b_taxable;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetBillTaxIncluded (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->b_taxincluded;
|
||||
}
|
||||
|
||||
GncTaxTable * gncEntryGetBillTaxTable (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->b_tax_table;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetBillable (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->billable;
|
||||
}
|
||||
|
||||
GncOwner * gncEntryGetBillTo (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return &entry->billto;
|
||||
}
|
||||
|
||||
GncInvoice * gncEntryGetInvoice (GncEntry *entry)
|
||||
@@ -501,48 +646,6 @@ GncOrder * gncEntryGetOrder (GncEntry *entry)
|
||||
return entry->order;
|
||||
}
|
||||
|
||||
GncAmountType gncEntryGetDiscountType (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return 0;
|
||||
return entry->disc_type;
|
||||
}
|
||||
|
||||
GncDiscountHow gncEntryGetDiscountHow (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return 0;
|
||||
return entry->disc_how;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetTaxable (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->taxable;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetTaxIncluded (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->taxincluded;
|
||||
}
|
||||
|
||||
GncTaxTable * gncEntryGetTaxTable (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->tax_table;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetBillable (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->billable;
|
||||
}
|
||||
|
||||
GncOwner * gncEntryGetBillTo (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return &entry->billto;
|
||||
}
|
||||
|
||||
GncEntry * gncEntryLookup (GNCBook *book, const GUID *guid)
|
||||
{
|
||||
if (!book || !guid) return NULL;
|
||||
@@ -775,84 +878,110 @@ gncEntryRecomputeValues (GncEntry *entry)
|
||||
{
|
||||
int denom;
|
||||
|
||||
/* See if the tax table changed since we last computed values */
|
||||
if (entry->tax_table) {
|
||||
Timespec modtime = gncTaxTableLastModified (entry->tax_table);
|
||||
if (timespec_cmp (&entry->taxtable_modtime, &modtime)) {
|
||||
/* See if either tax table changed since we last computed values */
|
||||
if (entry->i_tax_table) {
|
||||
Timespec modtime = gncTaxTableLastModified (entry->i_tax_table);
|
||||
if (timespec_cmp (&entry->i_taxtable_modtime, &modtime)) {
|
||||
entry->values_dirty = TRUE;
|
||||
entry->taxtable_modtime = modtime;
|
||||
entry->i_taxtable_modtime = modtime;
|
||||
}
|
||||
}
|
||||
if (entry->b_tax_table) {
|
||||
Timespec modtime = gncTaxTableLastModified (entry->b_tax_table);
|
||||
if (timespec_cmp (&entry->b_taxtable_modtime, &modtime)) {
|
||||
entry->values_dirty = TRUE;
|
||||
entry->b_taxtable_modtime = modtime;
|
||||
}
|
||||
}
|
||||
|
||||
if (!entry->values_dirty)
|
||||
return;
|
||||
|
||||
if (entry->tax_values) {
|
||||
gncAccountValueDestroy (entry->tax_values);
|
||||
entry->tax_values = NULL;
|
||||
/* Clear the last-computed tax values */
|
||||
if (entry->i_tax_values) {
|
||||
gncAccountValueDestroy (entry->i_tax_values);
|
||||
entry->i_tax_values = NULL;
|
||||
}
|
||||
if (entry->b_tax_values) {
|
||||
gncAccountValueDestroy (entry->b_tax_values);
|
||||
entry->b_tax_values = NULL;
|
||||
}
|
||||
|
||||
gncEntryComputeValue (entry->quantity, entry->price,
|
||||
(entry->taxable ? entry->tax_table : NULL),
|
||||
entry->taxincluded,
|
||||
entry->discount, entry->disc_type,
|
||||
entry->disc_how,
|
||||
&(entry->value), &(entry->disc_value),
|
||||
&(entry->tax_values));
|
||||
/* Compute the invoice values */
|
||||
gncEntryComputeValue (entry->quantity, entry->i_price,
|
||||
(entry->i_taxable ? entry->i_tax_table : NULL),
|
||||
entry->i_taxincluded,
|
||||
entry->i_discount, entry->i_disc_type,
|
||||
entry->i_disc_how,
|
||||
&(entry->i_value), &(entry->i_disc_value),
|
||||
&(entry->i_tax_values));
|
||||
|
||||
/* Compute the bill values */
|
||||
gncEntryComputeValue (entry->quantity, entry->b_price,
|
||||
(entry->b_taxable ? entry->b_tax_table : NULL),
|
||||
entry->b_taxincluded,
|
||||
gnc_numeric_zero(), GNC_AMT_TYPE_VALUE, GNC_DISC_PRETAX,
|
||||
&(entry->b_value), NULL, &(entry->b_tax_values));
|
||||
|
||||
denom = get_commodity_denom (entry);
|
||||
entry->value_rounded = gnc_numeric_convert (entry->value, denom,
|
||||
GNC_RND_ROUND);
|
||||
entry->disc_value_rounded = gnc_numeric_convert (entry->disc_value, denom,
|
||||
GNC_RND_ROUND);
|
||||
entry->tax_value = gncAccountValueTotal (entry->tax_values);
|
||||
entry->tax_value_rounded = gnc_numeric_convert (entry->tax_value, denom,
|
||||
GNC_RND_ROUND);
|
||||
entry->i_value_rounded = gnc_numeric_convert (entry->i_value, denom,
|
||||
GNC_RND_ROUND);
|
||||
entry->i_disc_value_rounded = gnc_numeric_convert (entry->i_disc_value, denom,
|
||||
GNC_RND_ROUND);
|
||||
entry->i_tax_value = gncAccountValueTotal (entry->i_tax_values);
|
||||
entry->i_tax_value_rounded = gnc_numeric_convert (entry->i_tax_value, denom,
|
||||
GNC_RND_ROUND);
|
||||
|
||||
entry->b_value_rounded = gnc_numeric_convert (entry->b_value, denom,
|
||||
GNC_RND_ROUND);
|
||||
entry->b_tax_value = gncAccountValueTotal (entry->b_tax_values);
|
||||
entry->b_tax_value_rounded = gnc_numeric_convert (entry->b_tax_value, denom,
|
||||
GNC_RND_ROUND);
|
||||
entry->values_dirty = FALSE;
|
||||
}
|
||||
|
||||
void gncEntryGetValue (GncEntry *entry, gnc_numeric *value,
|
||||
void gncEntryGetValue (GncEntry *entry, gboolean is_inv, gnc_numeric *value,
|
||||
gnc_numeric *discount_value, gnc_numeric *tax_value,
|
||||
GList **tax_values)
|
||||
{
|
||||
if (!entry) return;
|
||||
gncEntryRecomputeValues (entry);
|
||||
if (value)
|
||||
*value = entry->value;
|
||||
*value = (is_inv ? entry->i_value : entry->b_value);
|
||||
if (discount_value)
|
||||
*discount_value = entry->disc_value;
|
||||
*discount_value = (is_inv ? entry->i_disc_value : gnc_numeric_zero());
|
||||
if (tax_value)
|
||||
*tax_value = entry->tax_value;
|
||||
*tax_value = (is_inv ? entry->i_tax_value : entry->b_tax_value);
|
||||
if (tax_values)
|
||||
*tax_values = entry->tax_values;
|
||||
*tax_values = (is_inv ? entry->i_tax_values : entry->b_tax_values);
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryReturnValue (GncEntry *entry)
|
||||
gnc_numeric gncEntryReturnValue (GncEntry *entry, gboolean is_inv)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
gncEntryRecomputeValues (entry);
|
||||
return entry->value_rounded;
|
||||
return (is_inv ? entry->i_value_rounded : entry->b_value_rounded);
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryReturnTaxValue (GncEntry *entry)
|
||||
gnc_numeric gncEntryReturnTaxValue (GncEntry *entry, gboolean is_inv)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
gncEntryRecomputeValues (entry);
|
||||
return entry->tax_value_rounded;
|
||||
return (is_inv ? entry->i_tax_value_rounded : entry->b_tax_value_rounded);
|
||||
}
|
||||
|
||||
GList * gncEntryReturnTaxValues (GncEntry *entry)
|
||||
GList * gncEntryReturnTaxValues (GncEntry *entry, gboolean is_inv)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
gncEntryRecomputeValues (entry);
|
||||
return entry->tax_values;
|
||||
return (is_inv ? entry->i_tax_values : entry->b_tax_values);
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry)
|
||||
gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
gncEntryRecomputeValues (entry);
|
||||
return entry->disc_value_rounded;
|
||||
return (is_inv ? entry->i_disc_value_rounded : gnc_numeric_zero());
|
||||
}
|
||||
|
||||
void gncEntryCommitEdit (GncEntry *entry)
|
||||
@@ -946,7 +1075,8 @@ gboolean gncEntryRegister (void)
|
||||
{ ENTRY_ACTION, QUERYCORE_STRING, (QueryAccess)gncEntryGetAction },
|
||||
{ ENTRY_NOTES, QUERYCORE_STRING, (QueryAccess)gncEntryGetNotes },
|
||||
{ ENTRY_QTY, QUERYCORE_NUMERIC, (QueryAccess)gncEntryGetQuantity },
|
||||
{ ENTRY_PRICE, QUERYCORE_NUMERIC, (QueryAccess)gncEntryGetPrice },
|
||||
{ ENTRY_IPRICE, QUERYCORE_NUMERIC, (QueryAccess)gncEntryGetInvPrice },
|
||||
{ ENTRY_BPRICE, QUERYCORE_NUMERIC, (QueryAccess)gncEntryGetBillPrice },
|
||||
{ ENTRY_INVOICE, GNC_INVOICE_MODULE_NAME, (QueryAccess)gncEntryGetInvoice },
|
||||
{ ENTRY_BILL, GNC_INVOICE_MODULE_NAME, (QueryAccess)gncEntryGetBill },
|
||||
{ ENTRY_BILLABLE, QUERYCORE_BOOLEAN, (QueryAccess)gncEntryGetBillable },
|
||||
|
||||
@@ -40,29 +40,37 @@ gboolean gncEntryDiscountStringToHow (const char *str, GncDiscountHow *how);
|
||||
GncEntry *gncEntryCreate (GNCBook *book);
|
||||
void gncEntryDestroy (GncEntry *entry);
|
||||
|
||||
/* Set Functions */
|
||||
/* SET FUNCTIONS */
|
||||
|
||||
/* Generic (shared) data */
|
||||
void gncEntrySetDate (GncEntry *entry, Timespec date);
|
||||
void gncEntrySetDateEntered (GncEntry *entry, Timespec date);
|
||||
void gncEntrySetDescription (GncEntry *entry, const char *desc);
|
||||
void gncEntrySetAction (GncEntry *entry, const char *action);
|
||||
void gncEntrySetNotes (GncEntry *entry, const char *notes);
|
||||
void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity);
|
||||
void gncEntrySetPrice (GncEntry *entry, gnc_numeric price);
|
||||
void gncEntrySetDiscount (GncEntry *entry, gnc_numeric discount);
|
||||
void gncEntrySetDiscountType (GncEntry *entry, GncAmountType type);
|
||||
void gncEntrySetDiscountHow (GncEntry *entry, GncDiscountHow how);
|
||||
void gncEntrySetTaxable (GncEntry *entry, gboolean taxable);
|
||||
void gncEntrySetTaxIncluded (GncEntry *entry, gboolean tax_included);
|
||||
void gncEntrySetTaxTable (GncEntry *entry, GncTaxTable *table);
|
||||
|
||||
/* Customer Invoices */
|
||||
void gncEntrySetInvAccount (GncEntry *entry, Account *acc);
|
||||
void gncEntrySetInvPrice (GncEntry *entry, gnc_numeric price);
|
||||
void gncEntrySetInvTaxable (GncEntry *entry, gboolean taxable);
|
||||
void gncEntrySetInvTaxIncluded (GncEntry *entry, gboolean tax_included);
|
||||
void gncEntrySetInvTaxTable (GncEntry *entry, GncTaxTable *table);
|
||||
void gncEntrySetInvDiscount (GncEntry *entry, gnc_numeric discount);
|
||||
void gncEntrySetInvDiscountType (GncEntry *entry, GncAmountType type);
|
||||
void gncEntrySetInvDiscountHow (GncEntry *entry, GncDiscountHow how);
|
||||
|
||||
/* Vendor Bills (and Employee Expenses) */
|
||||
void gncEntrySetBillAccount (GncEntry *entry, Account *acc);
|
||||
void gncEntrySetBillPrice (GncEntry *entry, gnc_numeric price);
|
||||
void gncEntrySetBillTaxable (GncEntry *entry, gboolean taxable);
|
||||
void gncEntrySetBillTaxIncluded (GncEntry *entry, gboolean tax_included);
|
||||
void gncEntrySetBillTaxTable (GncEntry *entry, GncTaxTable *table);
|
||||
void gncEntrySetBillable (GncEntry *entry, gboolean billable);
|
||||
void gncEntrySetBillTo (GncEntry *entry, GncOwner *billto);
|
||||
|
||||
void gncEntrySetInvAccount (GncEntry *entry, Account *acc);
|
||||
void gncEntrySetBillAccount (GncEntry *entry, Account *acc);
|
||||
|
||||
/* Get Functions */
|
||||
|
||||
/* GET FUNCTIONS */
|
||||
/* Generic (shared) data */
|
||||
GNCBook * gncEntryGetBook (GncEntry *entry);
|
||||
const GUID * gncEntryGetGUID (GncEntry *entry);
|
||||
Timespec gncEntryGetDate (GncEntry *entry);
|
||||
@@ -71,26 +79,37 @@ const char * gncEntryGetDescription (GncEntry *entry);
|
||||
const char * gncEntryGetAction (GncEntry *entry);
|
||||
const char * gncEntryGetNotes (GncEntry *notes);
|
||||
gnc_numeric gncEntryGetQuantity (GncEntry *entry);
|
||||
gnc_numeric gncEntryGetPrice (GncEntry *entry);
|
||||
gnc_numeric gncEntryGetDiscount (GncEntry *entry);
|
||||
GncAmountType gncEntryGetDiscountType (GncEntry *entry);
|
||||
GncDiscountHow gncEntryGetDiscountHow (GncEntry *entry);
|
||||
gboolean gncEntryGetTaxable (GncEntry *entry);
|
||||
gboolean gncEntryGetTaxIncluded (GncEntry *entry);
|
||||
GncTaxTable * gncEntryGetTaxTable (GncEntry *entry);
|
||||
|
||||
/* Customer Invoices */
|
||||
Account * gncEntryGetInvAccount (GncEntry *entry);
|
||||
gnc_numeric gncEntryGetInvPrice (GncEntry *entry);
|
||||
gnc_numeric gncEntryGetInvDiscount (GncEntry *entry);
|
||||
GncAmountType gncEntryGetInvDiscountType (GncEntry *entry);
|
||||
GncDiscountHow gncEntryGetInvDiscountHow (GncEntry *entry);
|
||||
gboolean gncEntryGetInvTaxable (GncEntry *entry);
|
||||
gboolean gncEntryGetInvTaxIncluded (GncEntry *entry);
|
||||
GncTaxTable * gncEntryGetInvTaxTable (GncEntry *entry);
|
||||
|
||||
/* Vendor Bills (and Employee Expenses) */
|
||||
Account * gncEntryGetBillAccount (GncEntry *entry);
|
||||
gnc_numeric gncEntryGetBillPrice (GncEntry *entry);
|
||||
gboolean gncEntryGetBillTaxable (GncEntry *entry);
|
||||
gboolean gncEntryGetBillTaxIncluded (GncEntry *entry);
|
||||
GncTaxTable * gncEntryGetBillTaxTable (GncEntry *entry);
|
||||
gboolean gncEntryGetBillable (GncEntry *entry);
|
||||
GncOwner *gncEntryGetBillTo (GncEntry *entry);
|
||||
|
||||
|
||||
void gncEntryCopy (const GncEntry *src, GncEntry *dest);
|
||||
|
||||
/* The first three return the rounded values -- the last returns the
|
||||
* list of unrounded account-values. The list belongs to the entry
|
||||
* and will be destroyed, so use it quickly.
|
||||
*/
|
||||
gnc_numeric gncEntryReturnValue (GncEntry *entry);
|
||||
gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry);
|
||||
gnc_numeric gncEntryReturnTaxValue (GncEntry *entry);
|
||||
GList * gncEntryReturnTaxValues (GncEntry *entry);
|
||||
gnc_numeric gncEntryReturnValue (GncEntry *entry, gboolean is_inv);
|
||||
gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv);
|
||||
gnc_numeric gncEntryReturnTaxValue (GncEntry *entry, gboolean is_inv);
|
||||
GList * gncEntryReturnTaxValues (GncEntry *entry, gboolean is_inv);
|
||||
|
||||
/* Compute the Entry value, tax-value, and discount_value, based on
|
||||
* the quantity, price, discount, tax-table, and types. The value is
|
||||
@@ -101,9 +120,10 @@ GList * gncEntryReturnTaxValues (GncEntry *entry);
|
||||
* destroyed automatically, so use it quickly. Note that all return
|
||||
* values from these two functions are NOT rounded.
|
||||
*/
|
||||
void gncEntryGetValue (GncEntry *entry, gnc_numeric *value,
|
||||
void gncEntryGetValue (GncEntry *entry, gboolean is_inv, gnc_numeric *value,
|
||||
gnc_numeric *discount, gnc_numeric *tax_value,
|
||||
GList **tax_values);
|
||||
|
||||
void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
|
||||
GncTaxTable *tax_table, gboolean tax_included,
|
||||
gnc_numeric discount, GncAmountType discount_type,
|
||||
@@ -112,9 +132,6 @@ void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
|
||||
gnc_numeric *value, gnc_numeric *discount_value,
|
||||
GList **tax_values);
|
||||
|
||||
Account * gncEntryGetInvAccount (GncEntry *entry);
|
||||
Account * gncEntryGetBillAccount (GncEntry *entry);
|
||||
|
||||
GncOrder * gncEntryGetOrder (GncEntry *entry);
|
||||
GncInvoice * gncEntryGetInvoice (GncEntry *entry);
|
||||
GncInvoice * gncEntryGetBill (GncEntry *entry);
|
||||
@@ -130,7 +147,9 @@ int gncEntryCompare (GncEntry *a, GncEntry *b);
|
||||
#define ENTRY_ACTION "action"
|
||||
#define ENTRY_NOTES "notes"
|
||||
#define ENTRY_QTY "qty"
|
||||
#define ENTRY_PRICE "price"
|
||||
|
||||
#define ENTRY_IPRICE "iprice"
|
||||
#define ENTRY_BPRICE "bprice"
|
||||
#define ENTRY_BILLABLE "billable?"
|
||||
#define ENTRY_BILLTO "bill-to"
|
||||
|
||||
|
||||
@@ -626,12 +626,20 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
Account *this_acc;
|
||||
|
||||
/* Stabilize the TaxTable in this entry */
|
||||
gncEntrySetTaxTable (entry,
|
||||
gncTaxTableReturnChild (gncEntryGetTaxTable (entry),
|
||||
TRUE));
|
||||
if (reverse)
|
||||
gncEntrySetInvTaxTable
|
||||
(entry, gncTaxTableReturnChild (gncEntryGetInvTaxTable (entry), TRUE));
|
||||
else {
|
||||
gncEntrySetBillTaxTable
|
||||
(entry, gncTaxTableReturnChild (gncEntryGetBillTaxTable (entry), TRUE));
|
||||
|
||||
/* If this is a bill, and the entry is billable, copy the price */
|
||||
if (gncEntryGetBillable (entry))
|
||||
gncEntrySetInvPrice (entry, gncEntryGetBillPrice (entry));
|
||||
}
|
||||
|
||||
/* Obtain the Entry's Value and TaxValues */
|
||||
gncEntryGetValue (entry, &value, NULL, &tax, &taxes);
|
||||
gncEntryGetValue (entry, reverse, &value, NULL, &tax, &taxes);
|
||||
|
||||
/* add the value for the account split */
|
||||
this_acc = (reverse ? gncEntryGetInvAccount (entry) :
|
||||
|
||||
@@ -379,34 +379,42 @@
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:entry-get-price
|
||||
'gnc:entry-get-inv-price
|
||||
'<gnc:numeric>
|
||||
"gncEntryGetPrice"
|
||||
"gncEntryGetInvPrice"
|
||||
'((<gnc:GncEntry*> entry))
|
||||
"Return the Entry's Price")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:entry-get-discount
|
||||
'gnc:entry-get-inv-discount
|
||||
'<gnc:numeric>
|
||||
"gncEntryGetDiscount"
|
||||
"gncEntryGetInvDiscount"
|
||||
'((<gnc:GncEntry*> entry))
|
||||
"Return the Entry's Discount")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:entry-get-discount-type
|
||||
'gnc:entry-get-inv-discount-type
|
||||
'<gw:int>
|
||||
"gncEntryGetDiscountType"
|
||||
"gncEntryGetInvDiscountType"
|
||||
'((<gnc:GncEntry*> entry))
|
||||
"Return the Entry's discount type")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:entry-get-bill-price
|
||||
'<gnc:numeric>
|
||||
"gncEntryGetBillPrice"
|
||||
'((<gnc:GncEntry*> entry))
|
||||
"Return the Entry's Price")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:entry-get-value
|
||||
'<gnc:numeric>
|
||||
"gncEntryReturnValue"
|
||||
'((<gnc:GncEntry*> entry))
|
||||
'((<gnc:GncEntry*> entry) (<gw:bool> invoice?))
|
||||
"Return the Entry's computed Value (after discount)")
|
||||
|
||||
(gw:wrap-function
|
||||
@@ -414,7 +422,7 @@
|
||||
'gnc:entry-get-tax-value
|
||||
'<gnc:numeric>
|
||||
"gncEntryReturnTaxValue"
|
||||
'((<gnc:GncEntry*> entry))
|
||||
'((<gnc:GncEntry*> entry) (<gw:bool> invoice?))
|
||||
"Return the Entry's computed Tax Value")
|
||||
|
||||
(gw:wrap-function
|
||||
@@ -422,7 +430,7 @@
|
||||
'gnc:entry-get-discount-value
|
||||
'<gnc:numeric>
|
||||
"gncEntryReturnDiscountValue"
|
||||
'((<gnc:GncEntry*> entry))
|
||||
'((<gnc:GncEntry*> entry) (<gw:bool> invoice?))
|
||||
"Return the Entry's computed Discount Value")
|
||||
|
||||
(gw:wrap-function
|
||||
|
||||
@@ -40,9 +40,17 @@
|
||||
|
||||
(gnc:register-configuration-option
|
||||
(gnc:make-simple-boolean-option
|
||||
gnc:*business-label* (N_ "Tax Included?")
|
||||
"f" (N_ (string-append
|
||||
"Whether tax is included by default in entries. "
|
||||
gnc:*business-label* (N_ "Invoice Tax Included?")
|
||||
"f1" (N_ (string-append
|
||||
"Whether tax is included by default in entries on Invoices. "
|
||||
"This setting is inherited by new customers and vendors"))
|
||||
#f))
|
||||
|
||||
(gnc:register-configuration-option
|
||||
(gnc:make-simple-boolean-option
|
||||
gnc:*business-label* (N_ "Bill Tax Included?")
|
||||
"f2" (N_ (string-append
|
||||
"Whether tax is included by default in entries on Bills. "
|
||||
"This setting is inherited by new customers and vendors"))
|
||||
#f))
|
||||
|
||||
|
||||
@@ -699,7 +699,8 @@ gnc_invoice_window_sort (InvoiceWindow *iw, sort_type_t sort_code)
|
||||
p2 = standard;
|
||||
break;
|
||||
case BY_PRICE:
|
||||
p1 = g_slist_prepend (p1, ENTRY_PRICE);
|
||||
p1 = g_slist_prepend (p1, ((iw->owner.type == GNC_OWNER_CUSTOMER) ?
|
||||
ENTRY_IPRICE : ENTRY_BPRICE));
|
||||
p2 = standard;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -209,6 +209,21 @@ GncEntryLedger * gnc_entry_ledger_new (GNCBook *book, GncEntryLedgerType type)
|
||||
ledger->type = type;
|
||||
ledger->book = book;
|
||||
|
||||
/* Orders and Invoices are "invoices" for lookups */
|
||||
switch (type) {
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_ORDER_VIEWER:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
ledger->is_invoice = TRUE;
|
||||
break;
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_BILL_VIEWER:
|
||||
case GNCENTRY_NUM_REGISTER_TYPES:
|
||||
ledger->is_invoice = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
ledger->blank_entry_guid = *xaccGUIDNULL();
|
||||
ledger->blank_entry_edited = FALSE;
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ static void gnc_entry_ledger_layout_add_cursors (GncEntryLedger *ledger,
|
||||
break;
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_BILL_VIEWER:
|
||||
num_cols = 9;
|
||||
num_cols = 12;
|
||||
break;
|
||||
default:
|
||||
g_assert (FALSE);
|
||||
@@ -166,8 +166,11 @@ static void gnc_entry_ledger_set_cells (GncEntryLedger *ledger,
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BACCT_CELL, 0, 4);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 7);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 8);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXABLE_CELL, 0, 7);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXINCLUDED_CELL, 0, 8);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXTABLE_CELL, 0, 9);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 10);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 11);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
@@ -231,13 +231,20 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
break;
|
||||
case GNC_TAXINCLUDED_USEGLOBAL:
|
||||
taxincluded = gnc_lookup_boolean_option ("Business",
|
||||
"Tax Included?", FALSE);
|
||||
(ledger->is_invoice ?
|
||||
"Invoice Tax Included?" :
|
||||
"Bill Tax Included?"), FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
gncEntrySetTaxTable (blank_entry, table);
|
||||
gncEntrySetTaxIncluded (blank_entry, taxincluded);
|
||||
gncEntrySetDiscount (blank_entry, discount);
|
||||
if (ledger->is_invoice) {
|
||||
gncEntrySetInvTaxTable (blank_entry, table);
|
||||
gncEntrySetInvTaxIncluded (blank_entry, taxincluded);
|
||||
gncEntrySetInvDiscount (blank_entry, discount);
|
||||
} else {
|
||||
gncEntrySetBillTaxTable (blank_entry, table);
|
||||
gncEntrySetBillTaxIncluded (blank_entry, taxincluded);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -200,7 +200,7 @@ static const char * get_disc_entry (VirtualLocation virt_loc,
|
||||
gnc_numeric discount;
|
||||
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
discount = gncEntryGetDiscount (entry);
|
||||
discount = gncEntryGetInvDiscount (entry);
|
||||
if (gnc_numeric_zero_p (discount))
|
||||
return NULL;
|
||||
|
||||
@@ -217,7 +217,7 @@ static const char * get_distype_entry (VirtualLocation virt_loc,
|
||||
char type;
|
||||
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
type = gncEntryGetDiscountType (entry);
|
||||
type = gncEntryGetInvDiscountType (entry);
|
||||
|
||||
if (translate) {
|
||||
return gnc_entry_ledger_type_string_getter (type + '0');
|
||||
@@ -239,7 +239,7 @@ static const char * get_dishow_entry (VirtualLocation virt_loc,
|
||||
char type;
|
||||
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
type = gncEntryGetDiscountHow (entry);
|
||||
type = gncEntryGetInvDiscountHow (entry);
|
||||
|
||||
if (translate) {
|
||||
return gnc_entry_ledger_how_string_getter (type + '0');
|
||||
@@ -261,7 +261,10 @@ static const char * get_pric_entry (VirtualLocation virt_loc,
|
||||
gnc_numeric price;
|
||||
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
price = gncEntryGetPrice (entry);
|
||||
if (ledger->is_invoice)
|
||||
price = gncEntryGetInvPrice (entry);
|
||||
else
|
||||
price = gncEntryGetBillPrice (entry);
|
||||
|
||||
if (gnc_numeric_zero_p (price))
|
||||
return NULL;
|
||||
@@ -294,10 +297,16 @@ static const char * get_taxable_entry (VirtualLocation virt_loc,
|
||||
{
|
||||
GncEntryLedger *ledger = user_data;
|
||||
GncEntry *entry;
|
||||
gboolean taxable;
|
||||
static char s[2] = { ' ', '\0' };
|
||||
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
if (gncEntryGetTaxable (entry))
|
||||
if (ledger->is_invoice)
|
||||
taxable = gncEntryGetInvTaxable (entry);
|
||||
else
|
||||
taxable = gncEntryGetBillTaxable (entry);
|
||||
|
||||
if (taxable)
|
||||
s[0] = 'X';
|
||||
else
|
||||
s[0] = ' ';
|
||||
@@ -348,7 +357,10 @@ static const char * get_taxtable_entry (VirtualLocation virt_loc,
|
||||
}
|
||||
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
table = gncEntryGetTaxTable (entry);
|
||||
if (ledger->is_invoice)
|
||||
table = gncEntryGetInvTaxTable (entry);
|
||||
else
|
||||
table = gncEntryGetBillTaxTable (entry);
|
||||
|
||||
return gncTaxTableGetName (table);
|
||||
}
|
||||
@@ -361,7 +373,7 @@ static const char * get_taxincluded_entry (VirtualLocation virt_loc,
|
||||
GncEntryLedger *ledger = user_data;
|
||||
GncEntry *entry;
|
||||
static char s[2] = { ' ', '\0' };
|
||||
gboolean taxable;
|
||||
gboolean taxable, taxincluded;
|
||||
|
||||
/* load the cell properly; just shadow the value */
|
||||
if (!conditionally_changed) {
|
||||
@@ -373,7 +385,12 @@ static const char * get_taxincluded_entry (VirtualLocation virt_loc,
|
||||
}
|
||||
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
if (gncEntryGetTaxIncluded (entry))
|
||||
if (ledger->is_invoice)
|
||||
taxincluded = gncEntryGetInvTaxIncluded (entry);
|
||||
else
|
||||
taxincluded = gncEntryGetBillTaxIncluded (entry);
|
||||
|
||||
if (taxincluded)
|
||||
s[0] = 'X';
|
||||
else
|
||||
s[0] = ' ';
|
||||
@@ -423,7 +440,7 @@ static const char * get_value_entry (VirtualLocation virt_loc,
|
||||
if (entry == gnc_entry_ledger_get_blank_entry (ledger))
|
||||
return NULL;
|
||||
|
||||
value = gncEntryReturnValue (entry);
|
||||
value = gncEntryReturnValue (entry, ledger->is_invoice);
|
||||
}
|
||||
return xaccPrintAmount (value, gnc_default_print_info (TRUE));
|
||||
}
|
||||
@@ -446,7 +463,7 @@ static const char * get_taxval_entry (VirtualLocation virt_loc,
|
||||
if (entry == gnc_entry_ledger_get_blank_entry (ledger))
|
||||
return NULL;
|
||||
|
||||
value = gncEntryReturnTaxValue (entry);
|
||||
value = gncEntryReturnTaxValue (entry, ledger->is_invoice);
|
||||
}
|
||||
|
||||
return xaccPrintAmount (value, gnc_default_print_info (TRUE));
|
||||
@@ -790,6 +807,26 @@ static CellIOFlags get_taxincluded_io_flags (VirtualLocation virt_loc,
|
||||
return flags | XACC_CELL_ALLOW_EXACT_ONLY;
|
||||
}
|
||||
|
||||
static CellIOFlags get_qty_io_flags (VirtualLocation virt_loc, gpointer user_data)
|
||||
{
|
||||
GncEntryLedger *ledger = user_data;
|
||||
GncEntry *entry;
|
||||
CellIOFlags flags = get_standard_io_flags (virt_loc, user_data);
|
||||
|
||||
/* If this isn't an invoice, or the flags are already read-only ... */
|
||||
if (!ledger->is_invoice || flags == XACC_CELL_ALLOW_SHADOW)
|
||||
return flags;
|
||||
|
||||
/* ok, if this is an invoice ledger AND this entry is attached to a
|
||||
* bill (i.e. it's billable), freeze the quantity
|
||||
*/
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
if (gncEntryGetBillable (entry))
|
||||
return XACC_CELL_ALLOW_SHADOW;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
/* GET BG_COLORS */
|
||||
|
||||
static guint32
|
||||
@@ -900,7 +937,7 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
|
||||
gnc_numeric amount;
|
||||
|
||||
if (gnc_entry_ledger_get_numeric (ledger, ENTRY_DISC_CELL, &amount))
|
||||
gncEntrySetDiscount (entry, amount);
|
||||
gncEntrySetInvDiscount (entry, amount);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
@@ -910,7 +947,7 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
|
||||
type = gnc_entry_ledger_get_type (ledger, ENTRY_DISTYPE_CELL);
|
||||
|
||||
if (type != -1)
|
||||
gncEntrySetDiscountType (entry, type);
|
||||
gncEntrySetInvDiscountType (entry, type);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
@@ -920,15 +957,7 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
|
||||
type = gnc_entry_ledger_get_type (ledger, ENTRY_DISHOW_CELL);
|
||||
|
||||
if (type != -1)
|
||||
gncEntrySetDiscountHow (entry, type);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
ENTRY_PRIC_CELL, TRUE)) {
|
||||
gnc_numeric amount;
|
||||
|
||||
if (gnc_entry_ledger_get_numeric (ledger, ENTRY_PRIC_CELL, &amount))
|
||||
gncEntrySetPrice (entry, amount);
|
||||
gncEntrySetInvDiscountHow (entry, type);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
@@ -939,12 +968,35 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
|
||||
gncEntrySetQuantity (entry, amount);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
ENTRY_BILLABLE_CELL, TRUE)) {
|
||||
gboolean billable;
|
||||
|
||||
billable = gnc_entry_ledger_get_checkmark (ledger, ENTRY_BILLABLE_CELL);
|
||||
gncEntrySetBillable (entry, billable);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
ENTRY_PRIC_CELL, TRUE)) {
|
||||
gnc_numeric amount;
|
||||
|
||||
if (gnc_entry_ledger_get_numeric (ledger, ENTRY_PRIC_CELL, &amount)) {
|
||||
if (ledger->is_invoice)
|
||||
gncEntrySetInvPrice (entry, amount);
|
||||
else
|
||||
gncEntrySetBillPrice (entry, amount);
|
||||
}
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
ENTRY_TAXABLE_CELL, TRUE)) {
|
||||
gboolean taxable;
|
||||
|
||||
taxable = gnc_entry_ledger_get_checkmark (ledger, ENTRY_TAXABLE_CELL);
|
||||
gncEntrySetTaxable (entry, taxable);
|
||||
if (ledger->is_invoice)
|
||||
gncEntrySetInvTaxable (entry, taxable);
|
||||
else
|
||||
gncEntrySetBillTaxable (entry, taxable);
|
||||
}
|
||||
|
||||
/* XXX: Only (re-set) these if taxable is TRUE? */
|
||||
@@ -953,8 +1005,12 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
|
||||
GncTaxTable *table;
|
||||
|
||||
table = gnc_entry_ledger_get_taxtable (ledger, ENTRY_TAXTABLE_CELL);
|
||||
if (table)
|
||||
gncEntrySetTaxTable (entry, table);
|
||||
if (table) {
|
||||
if (ledger->is_invoice)
|
||||
gncEntrySetInvTaxTable (entry, table);
|
||||
else
|
||||
gncEntrySetBillTaxTable (entry, table);
|
||||
}
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
@@ -963,15 +1019,10 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
|
||||
|
||||
taxincluded = gnc_entry_ledger_get_checkmark (ledger,
|
||||
ENTRY_TAXINCLUDED_CELL);
|
||||
gncEntrySetTaxIncluded (entry, taxincluded);
|
||||
}
|
||||
|
||||
if (gnc_table_layout_get_cell_changed (ledger->table->layout,
|
||||
ENTRY_BILLABLE_CELL, TRUE)) {
|
||||
gboolean billable;
|
||||
|
||||
billable = gnc_entry_ledger_get_checkmark (ledger, ENTRY_BILLABLE_CELL);
|
||||
gncEntrySetBillable (entry, billable);
|
||||
if (ledger->is_invoice)
|
||||
gncEntrySetInvTaxIncluded (entry, taxincluded);
|
||||
else
|
||||
gncEntrySetBillTaxIncluded (entry, taxincluded);
|
||||
}
|
||||
|
||||
if (ledger->type == GNCENTRY_INVOICE_ENTRY) {
|
||||
@@ -1020,7 +1071,7 @@ static void gnc_entry_ledger_model_new_handlers (TableModel *model,
|
||||
{ ENTRY_DISTYPE_CELL, get_distype_entry, get_distype_label, get_distype_help, get_typecell_io_flags },
|
||||
{ ENTRY_DISHOW_CELL, get_dishow_entry, get_dishow_label, get_dishow_help, get_typecell_io_flags },
|
||||
{ ENTRY_PRIC_CELL, get_pric_entry, get_pric_label, get_pric_help, get_standard_io_flags },
|
||||
{ ENTRY_QTY_CELL, get_qty_entry, get_qty_label, get_qty_help, get_standard_io_flags },
|
||||
{ ENTRY_QTY_CELL, get_qty_entry, get_qty_label, get_qty_help, get_qty_io_flags },
|
||||
{ ENTRY_TAXABLE_CELL, get_taxable_entry, get_taxable_label, get_taxable_help, get_typecell_io_flags },
|
||||
{ ENTRY_TAXTABLE_CELL, get_taxtable_entry, get_taxtable_label, get_taxtable_help, get_tax_io_flags },
|
||||
{ ENTRY_TAXINCLUDED_CELL, get_taxincluded_entry, get_taxincluded_label, get_taxincluded_help, get_taxincluded_io_flags },
|
||||
|
||||
@@ -33,6 +33,8 @@ struct GncEntryLedger_s {
|
||||
QueryNew * query;
|
||||
|
||||
GncEntryLedgerType type;
|
||||
|
||||
gboolean is_invoice; /* is this an invoice (or a bill)? */
|
||||
};
|
||||
|
||||
GncEntry * gnc_entry_ledger_get_entry (GncEntryLedger *ledger,
|
||||
|
||||
@@ -123,15 +123,15 @@
|
||||
table)
|
||||
(gnc:make-gnc-monetary currency numeric)))
|
||||
|
||||
(define (add-entry-row table entry column-vector row-style)
|
||||
(define (add-entry-row table entry column-vector row-style invoice?)
|
||||
(let* ((row-contents '())
|
||||
(currency (gnc:default-currency)) ; XXX: FIXME
|
||||
(entry-value (gnc:make-gnc-monetary
|
||||
currency
|
||||
(gnc:entry-get-value entry)))
|
||||
(gnc:entry-get-value entry invoice?)))
|
||||
(entry-tax-value (gnc:make-gnc-monetary
|
||||
currency
|
||||
(gnc:entry-get-tax-value entry))))
|
||||
(gnc:entry-get-tax-value entry invoice?))))
|
||||
|
||||
(if (date-col column-vector)
|
||||
(addto! row-contents
|
||||
@@ -156,23 +156,32 @@
|
||||
(gnc:make-html-table-cell/markup
|
||||
"number-cell"
|
||||
(gnc:make-gnc-monetary
|
||||
currency (gnc:entry-get-price entry)))))
|
||||
currency (if invoice? (gnc:entry-get-inv-price entry)
|
||||
(gnc:entry-get-bill-price entry))))))
|
||||
|
||||
(if (discount-col column-vector)
|
||||
(addto! row-contents
|
||||
(gnc:make-html-table-cell/markup
|
||||
"number-cell"
|
||||
(monetary-or-percent (gnc:entry-get-discount entry)
|
||||
currency
|
||||
(gnc:entry-get-discount-type entry)))))
|
||||
(if invoice?
|
||||
(gnc:make-html-table-cell/markup
|
||||
"number-cell"
|
||||
(monetary-or-percent (gnc:entry-get-inv-discount entry)
|
||||
currency
|
||||
(gnc:entry-get-inv-discount-type entry)))
|
||||
"")))
|
||||
|
||||
(if (tax-col column-vector)
|
||||
(addto! row-contents
|
||||
(gnc:make-html-table-cell/markup
|
||||
"number-cell"
|
||||
(monetary-or-percent (gnc:entry-get-tax entry)
|
||||
currency
|
||||
(gnc:entry-get-tax-type entry)))))
|
||||
(if #t ""
|
||||
(if invoice?
|
||||
(monetary-or-percent (gnc:entry-get-inv-tax entry)
|
||||
currency
|
||||
(gnc:entry-get-inv-tax-type entry))
|
||||
(monetary-or-percent (gnc:entry-get-bill-tax entry)
|
||||
currency
|
||||
(gnc:entry-get-bill-tax-type entry))))))
|
||||
)
|
||||
|
||||
(if (taxvalue-col column-vector)
|
||||
(addto! row-contents
|
||||
@@ -293,7 +302,7 @@
|
||||
|
||||
gnc:*report-options*)
|
||||
|
||||
(define (make-entry-table invoice options add-order)
|
||||
(define (make-entry-table invoice options add-order invoice?)
|
||||
(let ((show-payments (gnc:option-value
|
||||
(gnc:lookup-option options (N_ "Display")
|
||||
(N_ "Payments"))))
|
||||
@@ -403,7 +412,8 @@
|
||||
(entry-values (add-entry-row table
|
||||
current
|
||||
used-columns
|
||||
current-row-style)))
|
||||
current-row-style
|
||||
invoice?)))
|
||||
|
||||
(value-collector 'add
|
||||
(gnc:gnc-monetary-commodity (car entry-values))
|
||||
@@ -558,7 +568,8 @@
|
||||
(invoice (opt-val invoice-page invoice-name))
|
||||
(owner #f)
|
||||
(references? (opt-val "Display" "References"))
|
||||
(title (_ "Invoice")))
|
||||
(title (_ "Invoice"))
|
||||
(invoice? #f))
|
||||
|
||||
(define (add-order o)
|
||||
(if (and references? (not (member o orders)))
|
||||
@@ -567,6 +578,14 @@
|
||||
(if invoice
|
||||
(begin
|
||||
(set! owner (gnc:invoice-get-owner invoice))
|
||||
(let ((type (gw:enum-<gnc:GncOwnerType>-val->sym
|
||||
(gnc:owner-get-type
|
||||
(gnc:owner-get-end-owner owner)) #f)))
|
||||
(case type
|
||||
((gnc-owner-customer)
|
||||
(set! invoice? #t))
|
||||
((gnc-owner-vendor)
|
||||
(set! title (_ "Bill")))))
|
||||
(set! title (string-append title " #"
|
||||
(gnc:invoice-get-id invoice)))))
|
||||
|
||||
@@ -576,7 +595,7 @@
|
||||
(let ((book (gnc:invoice-get-book invoice)))
|
||||
(set! table (make-entry-table invoice
|
||||
(gnc:report-options report-obj)
|
||||
add-order))
|
||||
add-order invoice?))
|
||||
|
||||
(gnc:html-table-set-style!
|
||||
table "table"
|
||||
|
||||
Reference in New Issue
Block a user