* gncInvoice*, gnc-invoice-xml-v2.c: add a "posted_lot" attribute

which points to the LOT created during the posting of the invoice.
  Also provide a function to grab the invoice from the lot (via KVP
  storage).


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7019 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2002-06-24 22:30:36 +00:00
parent e2299697df
commit 849f794800
4 changed files with 102 additions and 21 deletions

View File

@ -67,6 +67,7 @@ const gchar *invoice_version_string = "2.0.0";
#define invoice_notes_string "invoice:notes"
#define invoice_active_string "invoice:active"
#define invoice_posttxn_string "invoice:posttxn"
#define invoice_postlot_string "invoice:postlot"
#define invoice_postacc_string "invoice:postacc"
#define invoice_commodity_string "invoice:commodity"
@ -90,6 +91,7 @@ invoice_dom_tree_create (GncInvoice *invoice)
xmlNodePtr ret;
Timespec ts;
Transaction *txn;
GNCLot *lot;
Account *acc;
GncBillTerm *term;
@ -128,6 +130,11 @@ invoice_dom_tree_create (GncInvoice *invoice)
xmlAddChild (ret, guid_to_dom_tree (invoice_posttxn_string,
xaccTransGetGUID (txn)));
lot = gncInvoiceGetPostedlot (invoice);
if (lot)
xmlAddChild (ret, guid_to_dom_tree (invoice_postlot_string,
gnc_lot_get_guid (lot)));
acc = gncInvoiceGetPostedAcc (invoice);
if (acc)
xmlAddChild (ret, guid_to_dom_tree (invoice_postacc_string,
@ -304,6 +311,23 @@ invoice_posttxn_handler (xmlNodePtr node, gpointer invoice_pdata)
return TRUE;
}
static gboolean
invoice_postlot_handler (xmlNodePtr node, gpointer invoice_pdata)
{
struct invoice_pdata *pdata = invoice_pdata;
GUID *guid;
GNCLot *lot;
guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE);
lot = gnc_lot_lookup (guid, pdata->book);
g_free (guid);
g_return_val_if_fail (lot, FALSE);
gncInvoiceSetPostedLot (pdata->invoice, lot);
return TRUE;
}
static gboolean
invoice_postacc_handler (xmlNodePtr node, gpointer invoice_pdata)
{
@ -346,6 +370,7 @@ static struct dom_tree_handler invoice_handlers_v2[] = {
{ 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_postlot_string, invoice_postlot_handler, 0, 0 },
{ invoice_postacc_string, invoice_postacc_handler, 0, 0 },
{ invoice_commodity_string, invoice_commodity_handler, 1, 0 },
{ NULL, 0, 0, 0 }

View File

@ -46,6 +46,7 @@ struct _gncInvoice {
Account * posted_acc;
Transaction * posted_txn;
GNCLot * posted_lot;
gboolean active;
@ -225,6 +226,15 @@ void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn)
mark_invoice (invoice);
}
void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot)
{
if (!invoice) return;
g_return_if_fail (invoice->posted_lot == NULL);
invoice->posted_lot = lot;
mark_invoice (invoice);
}
void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc)
{
if (!invoice) return;
@ -386,6 +396,44 @@ gboolean gncInvoiceIsDirty (GncInvoice *invoice)
return invoice->dirty;
}
static void
gncInvoiceAttachInvoiceToLot (GncInvoice *invoice, GNCLot *lot)
{
kvp_frame *kvp;
kvp_value *value;
if (!invoice || !lot)
return;
if (invoice->posted_lot) return; /* Cannot reset invoice's lot */
kvp = gnc_lot_get_slots (lot);
value = kvp_value_new_guid (gncInvoiceGetGUID (invoice));
kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
kvp_value_delete (value);
gncInvoiceSetPostedLot (invoice, lot);
}
GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
{
kvp_frame *kvp;
kvp_value *value;
GUID *guid;
GNCBook *book;
if (!lot) return NULL;
book = gnc_lot_get_book (lot);
kvp = gnc_lot_get_slots (lot);
value = kvp_frame_get_slot_path (kvp, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
if (!value) return NULL;
guid = kvp_value_get_guid (value);
return xaccLookupEntity (gnc_book_get_entity_table (book),
guid, _GNC_MOD_NAME);
}
static void
gncInvoiceAttachInvoiceToTxn (GncInvoice *invoice, Transaction *txn)
{
@ -407,6 +455,26 @@ gncInvoiceAttachInvoiceToTxn (GncInvoice *invoice, Transaction *txn)
gncInvoiceSetPostedTxn (invoice, txn);
}
GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn)
{
kvp_frame *kvp;
kvp_value *value;
GUID *guid;
GNCBook *book;
if (!txn) return NULL;
book = xaccTransGetBook (txn);
kvp = xaccTransGetSlots (txn);
value = kvp_frame_get_slot_path (kvp, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
if (!value) return NULL;
guid = kvp_value_get_guid (value);
return xaccLookupEntity (gnc_book_get_entity_table (book),
guid, _GNC_MOD_NAME);
}
Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
Timespec *post_date, Timespec *due_date,
const char * memo)
@ -530,7 +598,8 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
xaccTransAppendSplit (txn, split);
}
/* Now attach this invoice to the txn and account */
/* Now attach this invoice to the txn, lot, and account */
gncInvoiceAttachInvoiceToLot (invoice, lot);
gncInvoiceAttachInvoiceToTxn (invoice, txn);
gncInvoiceSetPostedAcc (invoice, acc);
@ -541,26 +610,6 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
return txn;
}
GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn)
{
kvp_frame *kvp;
kvp_value *value;
GUID *guid;
GNCBook *book;
if (!txn) return NULL;
book = xaccTransGetBook (txn);
kvp = xaccTransGetSlots (txn);
value = kvp_frame_get_slot_path (kvp, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
if (!value) return NULL;
guid = kvp_value_get_guid (value);
return xaccLookupEntity (gnc_book_get_entity_table (book),
guid, _GNC_MOD_NAME);
}
static gboolean gncInvoiceDateExists (Timespec *date)
{
g_return_val_if_fail (date, FALSE);

View File

@ -13,6 +13,7 @@ typedef struct _gncInvoice GncInvoice;
#include "gncBillTerm.h"
#include "gncEntry.h"
#include "gncOwner.h"
#include "gnc-lot.h"
#define GNC_INVOICE_MODULE_NAME "gncInvoice"
@ -52,6 +53,7 @@ const char * gncInvoiceGetType (GncInvoice *invoice);
gnc_commodity * gncInvoiceGetCommonCommodity (GncInvoice *invoice);
gboolean gncInvoiceGetActive (GncInvoice *invoice);
GNCLot * gncInvoiceGetPostedLot (GncInvoice *invoice);
Transaction * gncInvoiceGetPostedTxn (GncInvoice *invoice);
Account * gncInvoiceGetPostedAcc (GncInvoice *invoice);
@ -71,6 +73,9 @@ gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
/* Given a transaction, find and return the Invoice */
GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn);
/* Given a LOT, find and return the Invoice attached to the lot */
GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot);
GUID gncInvoiceRetGUID (GncInvoice *invoice);
GncInvoice * gncInvoiceLookupDirect (GUID guid, GNCBook *book);

View File

@ -10,6 +10,7 @@
#include "gncInvoice.h"
#include "Account.h"
#include "Transaction.h"
#include "gnc-lot.h"
gboolean gncInvoiceRegister (void);
gint64 gncInvoiceNextID (GNCBook *book);
@ -17,6 +18,7 @@ void gncInvoiceSetGUID (GncInvoice *invoice, const GUID *guid);
void gncInvoiceSetDirty (GncInvoice *invoice, gboolean dirty);
void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc);
void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot);
void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn);
#endif /* GNC_INVOICEP_H_ */