mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add function for creating a new copy of an existing GncInvoice.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20081 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -314,6 +314,61 @@ GncInvoice *gncInvoiceCreate (QofBook *book)
|
||||
return invoice;
|
||||
}
|
||||
|
||||
GncInvoice *gncInvoiceCopy (const GncInvoice *from)
|
||||
{
|
||||
GncInvoice *invoice;
|
||||
QofBook* book;
|
||||
GList *node;
|
||||
|
||||
g_assert(from);
|
||||
book = qof_instance_get_book(from);
|
||||
g_assert(book);
|
||||
|
||||
invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
|
||||
qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
|
||||
|
||||
gncInvoiceBeginEdit(invoice);
|
||||
|
||||
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->terms = from->terms;
|
||||
gncBillTermIncRef (invoice->terms);
|
||||
|
||||
gncOwnerCopy(&from->billto, &invoice->billto);
|
||||
gncOwnerCopy(&from->owner, &invoice->owner);
|
||||
invoice->job = from->job; // FIXME: Need IncRef or similar here?!?
|
||||
|
||||
invoice->to_charge_amount = from->to_charge_amount;
|
||||
invoice->date_opened = from->date_opened;
|
||||
invoice->date_posted = from->date_posted;
|
||||
|
||||
// Copy all invoice->entries
|
||||
for (node = from->entries; node; node = node->next)
|
||||
{
|
||||
GncEntry *from_entry = node->data;
|
||||
GncEntry *to_entry = gncEntryCreate(book);
|
||||
gncEntryCopy(from_entry, to_entry);
|
||||
|
||||
if (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_VENDOR)
|
||||
{
|
||||
// this is a vendor bill
|
||||
gncBillAddEntry(invoice, to_entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is an invoice
|
||||
gncInvoiceAddEntry(invoice, to_entry);
|
||||
}
|
||||
}
|
||||
|
||||
gncInvoiceCommitEdit(invoice);
|
||||
|
||||
return invoice;
|
||||
}
|
||||
|
||||
void gncInvoiceDestroy (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return;
|
||||
@@ -594,6 +649,8 @@ void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry)
|
||||
{
|
||||
GncInvoice *old;
|
||||
|
||||
g_assert(invoice);
|
||||
g_assert(entry);
|
||||
if (!invoice || !entry) return;
|
||||
|
||||
old = gncEntryGetInvoice (entry);
|
||||
@@ -635,6 +692,8 @@ void gncBillAddEntry (GncInvoice *bill, GncEntry *entry)
|
||||
{
|
||||
GncInvoice *old;
|
||||
|
||||
g_assert(bill);
|
||||
g_assert(entry);
|
||||
if (!bill || !entry) return;
|
||||
|
||||
old = gncEntryGetBill (entry);
|
||||
|
||||
@@ -68,7 +68,16 @@ GType gnc_invoice_get_type(void);
|
||||
/** @name Create/Destroy Functions
|
||||
@{ */
|
||||
GncInvoice *gncInvoiceCreate (QofBook *book);
|
||||
|
||||
void gncInvoiceDestroy (GncInvoice *invoice);
|
||||
|
||||
/** Create a new GncInvoice object as a deep copy of the given other
|
||||
* invoice.
|
||||
*
|
||||
* The returned new invoice has everything copied from the other
|
||||
* invoice, including the ID string field. All GncEntries are newly
|
||||
* allocated copies of the original invoice's entries. */
|
||||
GncInvoice *gncInvoiceCopy (const GncInvoice *other_invoice);
|
||||
/** @} */
|
||||
|
||||
/** @name Set Functions
|
||||
|
||||
Reference in New Issue
Block a user