Skip to content

Commit

Permalink
staple in the invoice clone routines
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9618 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
linas committed Oct 22, 2003
1 parent 08b12ed commit 1be1eae
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 8 deletions.
91 changes: 83 additions & 8 deletions src/business/business-core/gncInvoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@

/*
* Copyright (C) 2001,2002 Derek Atkins
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
* Author: Derek Atkins <warlord@MIT.EDU>
*/

#include "config.h"

#include <glib.h>

#include "Transaction.h"
#include "Account.h"
#include "messages.h"
#include "gnc-numeric.h"
#include "kvp_frame.h"
#include "gnc-engine-util.h"

#include "qofbook.h"
#include "qofclass.h"
#include "qofid.h"
Expand All @@ -46,16 +40,25 @@
#include "qofquerycore.h"
#include "qofquery.h"

#include "Transaction.h"
#include "Account.h"
#include "messages.h"
#include "gnc-numeric.h"
#include "kvp_frame.h"
#include "gnc-engine-util.h"

#include "gnc-event-p.h"
#include "gnc-lot.h"
#include "gnc-be-utils.h"

#include "gncBusiness.h"
#include "gncBillTermP.h"
#include "gncEntry.h"
#include "gncEntryP.h"
#include "gncJobP.h"
#include "gncInvoice.h"
#include "gncInvoiceP.h"
#include "gncOwner.h"
#include "gncOwnerP.h"

struct _gncInvoice
{
Expand Down Expand Up @@ -113,6 +116,7 @@ mark_invoice (GncInvoice *invoice)
gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_MODIFY);
}

/* ================================================================== */
/* Create/Destroy Functions */

GncInvoice *gncInvoiceCreate (QofBook *book)
Expand Down Expand Up @@ -165,6 +169,74 @@ static void gncInvoiceFree (GncInvoice *invoice)
g_free (invoice);
}

GncInvoice *
gncCloneInvoice (GncInvoice *from, QofBook *book)
{
GList *node;
GncInvoice *invoice;

if (!book) return NULL;

invoice = g_new0 (GncInvoice, 1);
qof_instance_init (&invoice->inst, _GNC_MOD_NAME, book);

invoice->id = CACHE_INSERT (from->id);
invoice->notes = CACHE_INSERT (from->notes);
invoice->billing_id = CACHE_INSERT (from->billing_id);
invoice->active = from->active;

invoice->billto = gncCloneOwner (&from->billto, book);
invoice->owner = gncCloneOwner (&from->owner, book);
invoice->job = gncJobObtainTwin (from->job, book);
invoice->terms = gncBillTermObtainTwin (from->terms, book);
gncBillTermIncRef (invoice->terms);


invoice->to_charge_amount = from->to_charge_amount;
invoice->printname = NULL; /* that's right, NULL. See below. */
invoice->date_opened = from->date_opened;
invoice->date_posted = from->date_posted;

invoice->currency = gnc_commodity_obtain_twin (from->currency, book);

invoice->entries = NULL;
for (node = g_list_last(from->entries); node; node=node->next)
{
GncEntry *entry = node->data;
entry = gncEntryObtainTwin (entry, book);
invoice->entries = g_list_prepend (invoice->entries, entry);
}

/* XXX should probably be obtain-twin not lookup-twin */
invoice->posted_acc =
GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->posted_acc), book));
#if 0
XXX not done */
Transaction * posted_txn;
GNCLot * posted_lot;
#endif

gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_CREATE);

return invoice;
}

GncInvoice *
gncInvoiceObtainTwin (GncInvoice *from, QofBook *book)
{
GncInvoice *invoice;
if (!book) return NULL;

invoice = (GncInvoice *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
if (!invoice)
{
invoice = gncCloneInvoice (from, book);
}

return invoice;
}

/* ================================================================== */
/* Set Functions */

void gncInvoiceSetID (GncInvoice *invoice, const char *id)
Expand Down Expand Up @@ -361,6 +433,7 @@ void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry)
mark_invoice (bill);
}

/* ================================================================== */
/* Get Functions */

const char * gncInvoiceGetID (GncInvoice *invoice)
Expand Down Expand Up @@ -1211,6 +1284,8 @@ gboolean gncInvoiceIsPaid (GncInvoice *invoice)
return gnc_lot_is_closed(invoice->posted_lot);
}

/* ================================================================== */

void gncInvoiceBeginEdit (GncInvoice *invoice)
{
GNC_BEGIN_EDIT (&invoice->inst);
Expand Down
23 changes: 23 additions & 0 deletions src/business/business-core/gncInvoiceP.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,28 @@ void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot);
void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn);


/** The gncCloneInvoice() routine makes a copy of the indicated
* invoice, placing it in the indicated book. It copies
* the name, description, type, due-days, discount, etc.
* It also copies (as needed) both parents and children, so that
* the parent-child relationship is correctly mirrored in the
* clone.
* It then adds a pair of 'gemini' kvp pointers so that each copy
* can be found from the other.
*/

GncInvoice * gncCloneInvoice (GncInvoice *from, QofBook *);

/** The gncInvoiceObtainTwin() will find the 'twin' of the
* indicated invoice in the indicated book. If the twin doesn't
* yet exist in the book, it will be created (by calling
* gncCloneInvoice()) and placed into the book.
*
* We called this routine 'Obtain' instead of "Get" to distinguish
* it from the other Get routines, which work in fundamentally
* different ways.
*/
GncInvoice * gncInvoiceObtainTwin (GncInvoice *from, QofBook *book);
#define gncInvoiceSetGUID(I,G) qof_entity_set_guid(QOF_ENTITY(I),(G))
#endif /* GNC_INVOICEP_H_ */

0 comments on commit 1be1eae

Please sign in to comment.