GnuCash  4.12-74-g36b33262ad+
Files | Macros | Typedefs | Enumerations | Functions

An invoice holds a list of entries, a pointer to the customer, and the job, the dates entered and posted, as well as the account, transaction and lot for the posted invoice. More...

Files

file  gncInvoice.h
 Business Invoice Interface.
 

Macros

#define GNC_ID_INVOICE   "gncInvoice"
 
#define GNC_TYPE_INVOICE   (gnc_invoice_get_type ())
 
#define GNC_INVOICE(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_INVOICE, GncInvoice))
 
#define GNC_INVOICE_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_INVOICE, GncInvoiceClass))
 
#define GNC_IS_INVOICE(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_INVOICE))
 
#define GNC_IS_INVOICE_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_INVOICE))
 
#define GNC_INVOICE_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_INVOICE, GncInvoiceClass))
 
#define INVOICE_ID   "id"
 
#define INVOICE_OWNER   "owner"
 
#define INVOICE_OPENED   "date_opened"
 
#define INVOICE_POSTED   "date_posted"
 
#define INVOICE_DUE   "date_due"
 
#define INVOICE_IS_POSTED   "is_posted?"
 
#define INVOICE_IS_PAID   "is_paid?"
 
#define INVOICE_TERMS   "terms"
 
#define INVOICE_BILLINGID   "billing_id"
 
#define INVOICE_NOTES   "notes"
 
#define INVOICE_DOCLINK   "doclink"
 
#define INVOICE_ACC   "account"
 
#define INVOICE_POST_TXN   "posted_txn"
 
#define INVOICE_POST_LOT   "posted_lot"
 
#define INVOICE_IS_CN   "credit_note"
 
#define INVOICE_TYPE   "type"
 
#define INVOICE_TYPE_STRING   "type_string"
 
#define INVOICE_BILLTO   "bill-to"
 
#define INVOICE_ENTRIES   "list_of_entries"
 
#define INVOICE_JOB   "invoice_job"
 
#define INVOICE_FROM_LOT   "invoice-from-lot"
 
#define INVOICE_FROM_TXN   "invoice-from-txn"
 
#define gncInvoiceGetGUID(x)   qof_instance_get_guid (QOF_INSTANCE(x))
 deprecated functions
 
#define gncInvoiceRetGUID(x)   (x ? *(qof_instance_get_guid (QOF_INSTANCE(x))) : *(guid_null()))
 

Typedefs

typedef GList GncInvoiceList
 
typedef GList EntryList
 

Enumerations

enum  GncInvoiceType {
  GNC_INVOICE_UNDEFINED, GNC_INVOICE_CUST_INVOICE, GNC_INVOICE_VEND_INVOICE, GNC_INVOICE_EMPL_INVOICE,
  GNC_INVOICE_CUST_CREDIT_NOTE, GNC_INVOICE_VEND_CREDIT_NOTE, GNC_INVOICE_EMPL_CREDIT_NOTE, GNC_INVOICE_NUM_TYPES
}
 

Functions

GType gnc_invoice_get_type (void)
 
void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry)
 
void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry)
 
void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price)
 
void gncBillAddEntry (GncInvoice *bill, GncEntry *entry)
 Call this function when adding an entry to a bill instead of an invoice.
 
void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry)
 
void gncInvoiceSortEntries (GncInvoice *invoice)
 Call this function when an Entry is changed and you want to re-sort the list of entries.
 
void gncInvoiceRemoveEntries (GncInvoice *invoice)
 Remove all entries from an invoice. More...
 
gnc_numeric gncInvoiceGetTotal (GncInvoice *invoice)
 Return the "total" amount of the invoice as seen on the document (and shown to the user in the reports and invoice ledger). More...
 
gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type)
 
gnc_numeric gncInvoiceGetTotalSubtotal (GncInvoice *invoice)
 
gnc_numeric gncInvoiceGetTotalTax (GncInvoice *invoice)
 
AccountValueList * gncInvoiceGetTotalTaxList (GncInvoice *invoice)
 Return a list of tax totals accumulated per tax account.
 
EntryList * gncInvoiceGetEntries (GncInvoice *invoice)
 
GNCPrice * gncInvoiceGetPrice (GncInvoice *invoice, gnc_commodity *commodity)
 
gboolean gncInvoiceAmountPositive (const GncInvoice *invoice)
 Depending on the invoice type, invoices have a different effect on the balance. More...
 
GHashTable * gncInvoiceGetForeignCurrencies (const GncInvoice *invoice)
 Return an overview of amounts on this invoice that will be posted to accounts in currencies that are different from the invoice currency. More...
 
Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, time64 posted_date, time64 due_date, const char *memo, gboolean accumulatesplits, gboolean autopay)
 Post this invoice to an account. More...
 
gboolean gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables)
 Unpost this invoice. More...
 
void gncInvoiceAutoApplyPayments (GncInvoice *invoice)
 Attempt to pay the invoice using open payment lots and lots for documents of the opposite sign (credit notes versus invoices).
 
void gncInvoiceApplyPayment (const GncInvoice *invoice, Transaction *txn, Account *xfer_acc, gnc_numeric amount, gnc_numeric exch, time64 date, const char *memo, const char *num)
 A convenience function to apply a payment to an invoice. More...
 
GncInvoice * gncInvoiceGetInvoiceFromTxn (const Transaction *txn)
 Given a transaction, find and return the Invoice.
 
GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
 Given a LOT, find and return the Invoice attached to the lot.
 
void gncInvoiceBeginEdit (GncInvoice *invoice)
 
void gncInvoiceCommitEdit (GncInvoice *invoice)
 
int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b)
 
gboolean gncInvoiceIsPosted (const GncInvoice *invoice)
 
gboolean gncInvoiceIsPaid (const GncInvoice *invoice)
 
QofBook * gncInvoiceGetBook (GncInvoice *x)
 
gboolean gncInvoiceEqual (const GncInvoice *a, const GncInvoice *b)
 Test support function used by test-dbi-business-stuff.c.
 

Create/Destroy Functions

GncInvoice * gncInvoiceCreate (QofBook *book)
 
void gncInvoiceDestroy (GncInvoice *invoice)
 
GncInvoice * gncInvoiceCopy (const GncInvoice *other_invoice)
 Create a new GncInvoice object as a deep copy of the given other invoice. More...
 

Set Functions

void gncInvoiceSetID (GncInvoice *invoice, const char *id)
 
void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner)
 
void gncInvoiceSetDateOpenedGDate (GncInvoice *invoice, const GDate *date)
 Set the DateOpened using a GDate argument. More...
 
void gncInvoiceSetDateOpened (GncInvoice *invoice, time64 date)
 
void gncInvoiceSetDatePosted (GncInvoice *invoice, time64 date)
 
void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms)
 
void gncInvoiceSetBillingID (GncInvoice *invoice, const char *billing_id)
 
void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes)
 
void gncInvoiceSetDocLink (GncInvoice *invoice, const char *doclink)
 
void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency)
 
void gncInvoiceSetActive (GncInvoice *invoice, gboolean active)
 
void gncInvoiceSetIsCreditNote (GncInvoice *invoice, gboolean credit_note)
 
void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto)
 
void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount)
 

Get Functions

const char * gncInvoiceGetID (const GncInvoice *invoice)
 
const GncOwnergncInvoiceGetOwner (const GncInvoice *invoice)
 
time64 gncInvoiceGetDateOpened (const GncInvoice *invoice)
 
time64 gncInvoiceGetDatePosted (const GncInvoice *invoice)
 
time64 gncInvoiceGetDateDue (const GncInvoice *invoice)
 
GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice)
 
const char * gncInvoiceGetBillingID (const GncInvoice *invoice)
 
const char * gncInvoiceGetNotes (const GncInvoice *invoice)
 
const char * gncInvoiceGetDocLink (const GncInvoice *invoice)
 
GncOwnerType gncInvoiceGetOwnerType (const GncInvoice *invoice)
 
GList * gncInvoiceGetTypeListForOwnerType (const GncOwnerType type)
 
GncInvoiceType gncInvoiceGetType (const GncInvoice *invoice)
 
const char * gncInvoiceGetTypeString (const GncInvoice *invoice)
 
gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice)
 
GncOwnergncInvoiceGetBillTo (GncInvoice *invoice)
 
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice)
 
gboolean gncInvoiceGetActive (const GncInvoice *invoice)
 
gboolean gncInvoiceGetIsCreditNote (const GncInvoice *invoice)
 
GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice)
 
Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice)
 
AccountgncInvoiceGetPostedAcc (const GncInvoice *invoice)
 

Detailed Description

An invoice holds a list of entries, a pointer to the customer, and the job, the dates entered and posted, as well as the account, transaction and lot for the posted invoice.

Function Documentation

◆ gncInvoiceAmountPositive()

gboolean gncInvoiceAmountPositive ( const GncInvoice *  invoice)

Depending on the invoice type, invoices have a different effect on the balance.

Customer invoices increase the balance, while vendor bills decrease the balance. Credit notes have the opposite effect.

Returns TRUE if the invoice will increase the balance or FALSE otherwise.

Definition at line 1363 of file gncInvoice.c.

1364 {
1365  switch (gncInvoiceGetType (invoice))
1366  {
1367  case GNC_INVOICE_CUST_INVOICE:
1368  case GNC_INVOICE_VEND_CREDIT_NOTE:
1369  case GNC_INVOICE_EMPL_CREDIT_NOTE:
1370  return TRUE;
1371  case GNC_INVOICE_CUST_CREDIT_NOTE:
1372  case GNC_INVOICE_VEND_INVOICE:
1373  case GNC_INVOICE_EMPL_INVOICE:
1374  return FALSE;
1375  case GNC_INVOICE_UNDEFINED:
1376  default:
1377  /* Should never be reached.
1378  * If it is, perhaps a new value is added to GncInvoiceType ? */
1379  g_assert_not_reached ();
1380  return FALSE;
1381  }
1382 }

◆ gncInvoiceApplyPayment()

void gncInvoiceApplyPayment ( const GncInvoice *  invoice,
Transaction *  txn,
Account xfer_acc,
gnc_numeric  amount,
gnc_numeric  exch,
time64  date,
const char *  memo,
const char *  num 
)

A convenience function to apply a payment to an invoice.

It creates a lot for a payment optionally based on an existing transaction and then tries to balance it with the given invoice. Contrary to gncOwnerApplyPayment, no other open documents or payments for the owner will be considered to balance the payment.

This code is actually a convenience wrapper around gncOwnerCreatePaymentLotSecs and gncOwnerAutoApplyPaymentsWithLots. See their descriptions for more details on what happens exactly.

Definition at line 2027 of file gncInvoice.c.

2031 {
2032  GNCLot *payment_lot;
2033  GList *selected_lots = NULL;
2034  const GncOwner *owner;
2035 
2036  /* Verify our arguments */
2037  if (!invoice || !gncInvoiceIsPosted (invoice) || !xfer_acc) return;
2038 
2039  owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
2040  g_return_if_fail (owner->owner.undefined);
2041 
2042  /* Create a lot for this payment */
2043  payment_lot = gncOwnerCreatePaymentLotSecs (owner, &txn,
2044  invoice->posted_acc,
2045  xfer_acc, amount, exch,
2046  date, memo, num);
2047 
2048  /* Select the invoice as only payment candidate */
2049  selected_lots = g_list_prepend (selected_lots, invoice->posted_lot);
2050 
2051  /* And link the invoice lot and the payment lot together as well as possible. */
2052  if (payment_lot)
2053  selected_lots = g_list_prepend (selected_lots, payment_lot);
2054  gncOwnerAutoApplyPaymentsWithLots (owner, selected_lots);
2055 }
void gncOwnerAutoApplyPaymentsWithLots(const GncOwner *owner, GList *lots)
Given a list of lots, try to balance as many of them as possible by creating balancing transactions b...
Definition: gncOwner.c:1259
GNCLot * gncOwnerCreatePaymentLotSecs(const GncOwner *owner, Transaction **preset_txn, Account *posted_acc, Account *xfer_acc, gnc_numeric amount, gnc_numeric exch, time64 date, const char *memo, const char *num)
Create a lot for a payment to the owner using the other parameters passed in.
Definition: gncOwner.c:751
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
Get the "parent" Owner or GncGUID thereof.
Definition: gncOwner.c:573

◆ gncInvoiceCopy()

GncInvoice* gncInvoiceCopy ( const GncInvoice *  other_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.

Definition at line 343 of file gncInvoice.c.

344 {
345  GncInvoice *invoice;
346  QofBook* book;
347  GList *node;
348  GValue v = G_VALUE_INIT;
349 
350  g_assert (from);
351  book = qof_instance_get_book (from);
352  g_assert (book);
353 
354  invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
355  qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
356 
357  gncInvoiceBeginEdit (invoice);
358 
359  invoice->id = CACHE_INSERT (from->id);
360  invoice->notes = CACHE_INSERT (from->notes);
361  invoice->billing_id = CACHE_INSERT (from->billing_id);
362  invoice->active = from->active;
363 
364  qof_instance_get_kvp (QOF_INSTANCE (from), &v, 1, GNC_INVOICE_IS_CN);
365  if (G_VALUE_HOLDS_INT64 (&v))
366  qof_instance_set_kvp (QOF_INSTANCE (invoice), &v, 1, GNC_INVOICE_IS_CN);
367  g_value_unset (&v);
368 
369  invoice->terms = from->terms;
370  gncBillTermIncRef (invoice->terms);
371 
372  gncOwnerCopy (&from->billto, &invoice->billto);
373  gncOwnerCopy (&from->owner, &invoice->owner);
374  invoice->job = from->job; // FIXME: Need IncRef or similar here?!?
375 
376  invoice->to_charge_amount = from->to_charge_amount;
377  invoice->date_opened = from->date_opened;
378 
379  // Oops. Do not forget to copy the pointer to the correct currency here.
380  invoice->currency = from->currency;
381 
382  if (from->doclink == is_unset)
383  invoice->doclink = (char*)is_unset;
384  else
385  gncInvoiceSetDocLink (invoice, from->doclink);
386 
387  // Copy all invoice->entries
388  for (node = from->entries; node; node = node->next)
389  {
390  GncEntry *from_entry = node->data;
391  GncEntry *to_entry = gncEntryCreate (book);
392  gncEntryCopy (from_entry, to_entry, FALSE);
393 
394  switch (gncInvoiceGetOwnerType (invoice))
395  {
396  case GNC_OWNER_VENDOR:
397  case GNC_OWNER_EMPLOYEE:
398  // this is a vendor bill, or an expense voucher
399  gncBillAddEntry (invoice, to_entry);
400  break;
401  case GNC_OWNER_CUSTOMER:
402  default:
403  // this is an invoice
404  gncInvoiceAddEntry (invoice, to_entry);
405  break;
406  }
407  }
408 
409  // FIXME: The prices are not (yet) copied; is this a problem?
410 
411  // Posted-date and the posted Txn is intentionally not copied; the
412  // copy isn't "posted" but needs to be posted by the user.
413  mark_invoice (invoice);
414  gncInvoiceCommitEdit (invoice);
415 
416  return invoice;
417 }
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
void gncBillAddEntry(GncInvoice *bill, GncEntry *entry)
Call this function when adding an entry to a bill instead of an invoice.
Definition: gncInvoice.c:738

◆ gncInvoiceGetForeignCurrencies()

GHashTable* gncInvoiceGetForeignCurrencies ( const GncInvoice *  invoice)

Return an overview of amounts on this invoice that will be posted to accounts in currencies that are different from the invoice currency.

These accounts can be the accounts referred to in invoice entries or tax tables. This information is returned in the from of a hash table. The keys in the hash table are the foreign currencies, the values are the accumulated amounts in that currency. Drop the reference to the hash table with g_hash_table_unref when no longer needed.

Definition at line 1384 of file gncInvoice.c.

1385 {
1386  EntryList *entries_iter;
1387  gboolean is_cust_doc = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
1388  gboolean is_cn = gncInvoiceGetIsCreditNote (invoice);
1389  GHashTable *amt_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal,
1390  NULL, g_free);
1391  ENTER ("");
1392 
1393  for (entries_iter = invoice->entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter))
1394  {
1395  GncEntry *entry = (GncEntry*)entries_iter->data;
1396  Account *this_acc;
1397  gnc_commodity *account_currency;
1398  AccountValueList *tt_amts = NULL, *tt_iter;
1399 
1400  /* Check entry's account currency */
1401  this_acc = (is_cust_doc ? gncEntryGetInvAccount (entry) :
1402  gncEntryGetBillAccount (entry));
1403  account_currency = xaccAccountGetCommodity (this_acc);
1404 
1405  if (this_acc &&
1406  !gnc_commodity_equal (gncInvoiceGetCurrency (invoice), account_currency))
1407  {
1408  gnc_numeric *curr_amt = (gnc_numeric*) g_hash_table_lookup (amt_hash, account_currency);
1409  gnc_numeric *entry_amt = (gnc_numeric*) g_new0 (gnc_numeric, 1);
1410  *entry_amt = gncEntryGetDocValue (entry, FALSE, is_cust_doc, is_cn);
1411  if (curr_amt)
1412  *entry_amt = gnc_numeric_add (*entry_amt, *curr_amt, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
1413  g_hash_table_insert (amt_hash, account_currency, entry_amt);
1414  }
1415 
1416  /* Check currencies of each account in the tax table linked
1417  * to the current entry */
1418  tt_amts = gncEntryGetDocTaxValues (entry, is_cust_doc, is_cn);
1419 
1420  if (!tt_amts)
1421  continue;
1422 
1423  for (tt_iter = tt_amts; tt_iter != NULL; tt_iter = g_list_next(tt_iter))
1424  {
1425  GncAccountValue *tt_amt_val = (GncAccountValue*)tt_iter->data;
1426  Account *tt_acc = tt_amt_val->account;
1427  gnc_commodity *tt_acc_currency = xaccAccountGetCommodity (tt_acc);
1428 
1429  if (tt_acc &&
1430  !gnc_commodity_equal (gncInvoiceGetCurrency (invoice), tt_acc_currency))
1431  {
1432  gnc_numeric *curr_amt = (gnc_numeric*) g_hash_table_lookup (amt_hash, tt_acc_currency);
1433  gnc_numeric *tt_acc_amt = (gnc_numeric*) g_new0 (gnc_numeric, 1);
1434  *tt_acc_amt = tt_amt_val->value;
1435  if (curr_amt)
1436  *tt_acc_amt = gnc_numeric_add (*tt_acc_amt, *curr_amt, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
1437  g_hash_table_insert (amt_hash, tt_acc_currency, tt_acc_amt);
1438  }
1439  }
1440  gncAccountValueDestroy (tt_amts);
1441  }
1442 
1443  LEAVE ("");
1444  return amt_hash;
1445 }
AccountValueList * gncEntryGetDocTaxValues(GncEntry *entry, gboolean is_cust_doc, gboolean is_cn)
Careful: the returned list is NOT owned by the entry and should be freed by the caller.
Definition: gncEntry.c:1544
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
Definition: gnc-numeric.h:166
void gncAccountValueDestroy(GList *list)
Destroy a list of accountvalues.
Definition: gncTaxTable.c:997
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
Definition: Account.cpp:3448
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
Definition: gnc-numeric.h:246

◆ gncInvoiceGetTotal()

gnc_numeric gncInvoiceGetTotal ( GncInvoice *  invoice)

Return the "total" amount of the invoice as seen on the document (and shown to the user in the reports and invoice ledger).

Definition at line 1029 of file gncInvoice.c.

1030 {
1031  if (!invoice) return gnc_numeric_zero ();
1032  return gncInvoiceGetTotalInternal (invoice, TRUE, TRUE, FALSE, 0);
1033 }

◆ gncInvoicePostToAccount()

Transaction* gncInvoicePostToAccount ( GncInvoice *  invoice,
Account acc,
time64  posted_date,
time64  due_date,
const char *  memo,
gboolean  accumulatesplits,
gboolean  autopay 
)

Post this invoice to an account.

Returns the new Transaction that is tied to this invoice. The transaction is set with the supplied posted date, due date, and memo. The Transaction description is set to the name of the company.

If accumulate splits is TRUE, entries in the same account will be merged into one single split in that account. Otherwise each entry will be posted as a separate split, possibly resulting in multiple splits in one account.

If autopay is TRUE, the code will try to find pre-payments, invoices or credit notes that can reduce the amount due for this invoice, marking the invoice as fully or partially paid, depending on the amounts on all documents involved. If autopay is FALSE, it's the user's responsibility to explicitly pay the invoice.

Definition at line 1518 of file gncInvoice.c.

1522 {
1523  Transaction *txn;
1524  QofBook *book;
1525  GNCLot *lot = NULL;
1526  GList *iter;
1527  GList *splitinfo = NULL;
1528  gnc_numeric total;
1529  gboolean is_cust_doc;
1530  gboolean is_cn;
1531  const char *name, *type;
1532  char *lot_title;
1533  Account *ccard_acct = NULL;
1534  const GncOwner *owner;
1535  int denom = xaccAccountGetCommoditySCU (acc);
1536  AccountValueList *taxes;
1537 
1538  if (!invoice || !acc) return NULL;
1539  if (gncInvoiceIsPosted (invoice)) return NULL;
1540 
1541  ENTER ("");
1542  gncInvoiceBeginEdit (invoice);
1543  book = qof_instance_get_book (invoice);
1544 
1545  /* Stabilize the Billing Terms of this invoice */
1546  if (invoice->terms)
1547  gncInvoiceSetTerms (invoice,
1548  gncBillTermReturnChild (invoice->terms, TRUE));
1549 
1550  /* GncEntry functions need to know if the invoice/credit note is for a customer or a vendor/employee. */
1551  is_cust_doc = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
1552  is_cn = gncInvoiceGetIsCreditNote (invoice);
1553 
1554  /* Figure out if we need to separate out "credit-card" items */
1555  owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
1556  if (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_EMPLOYEE)
1557  ccard_acct = gncEmployeeGetCCard (gncOwnerGetEmployee (owner));
1558 
1559  /* Create a new lot for this invoice */
1560  lot = gnc_lot_new (book);
1561  gncInvoiceAttachToLot (invoice, lot);
1562  gnc_lot_begin_edit (lot);
1563 
1564  type = gncInvoiceGetTypeString (invoice);
1565 
1566  /* Set the lot title */
1567  lot_title = g_strdup_printf ("%s %s", type, gncInvoiceGetID (invoice));
1568  gnc_lot_set_title (lot, lot_title);
1569  g_free (lot_title);
1570 
1571  /* Create a new transaction */
1572  txn = xaccMallocTransaction (book);
1573  xaccTransBeginEdit (txn);
1574 
1575  name = gncOwnerGetName (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)));
1576 
1577  /* Set Transaction Description (Owner Name) , Num (invoice ID or type, based
1578  * on book option), Currency */
1579  xaccTransSetDescription (txn, name ? name : "");
1580  gnc_set_num_action (txn, NULL, gncInvoiceGetID (invoice), type);
1581  xaccTransSetCurrency (txn, invoice->currency);
1582 
1583  /* Entered and Posted at date */
1584  xaccTransSetDateEnteredSecs (txn, gnc_time (NULL));
1585  xaccTransSetDatePostedSecsNormalized (txn, post_date);
1586  gncInvoiceSetDatePosted (invoice, xaccTransRetDatePosted(txn));
1587 
1588  xaccTransSetDateDue (txn, due_date);
1589 
1590  /* Get invoice total and taxes. */
1591  total = gncInvoiceGetTotal (invoice);
1592  taxes = gncInvoiceGetTotalTaxList (invoice);
1593  /* The two functions above return signs relative to the document
1594  * We need to convert them to balance values before we can use them here
1595  * Note the odd construct comparing two booleans is to xor them
1596  * that is, only evaluate true if both are different.
1597  */
1598  if (is_cust_doc != is_cn)
1599  {
1600  GList *node;
1601  total = gnc_numeric_neg (total);
1602  for (node = taxes; node; node = node->next)
1603  {
1604  GncAccountValue *acc_val = node->data;
1605  acc_val->value = gnc_numeric_neg (acc_val->value);
1606  }
1607  }
1608 
1609  /* Iterate through the entries; sum up everything for each account.
1610  * then create the appropriate splits in this txn.
1611  */
1612 
1613  for (iter = gncInvoiceGetEntries (invoice); iter; iter = iter->next)
1614  {
1615  gnc_numeric value, tax;
1616  GncEntry * entry = iter->data;
1617  Account *this_acc;
1618 
1619  /* Stabilize the TaxTable in this entry */
1620  gncEntryBeginEdit (entry);
1621  if (is_cust_doc)
1622  gncEntrySetInvTaxTable
1623  (entry, gncTaxTableReturnChild (gncEntryGetInvTaxTable (entry), TRUE));
1624  else
1625  {
1626  gncEntrySetBillTaxTable
1627  (entry, gncTaxTableReturnChild (gncEntryGetBillTaxTable (entry), TRUE));
1628 
1629  /* If this is a bill, and the entry came from an invoice originally, copy the price */
1630  if (gncEntryGetBillable (entry))
1631  {
1632  /* We need to set the net price since it may be another tax rate for invoices than bills */
1633  gncEntrySetInvPrice (entry, gncEntryGetPrice (entry, FALSE, TRUE));
1634  gncEntrySetInvTaxIncluded (entry, FALSE);
1635  }
1636  }
1637  gncEntryCommitEdit (entry);
1638 
1639  /* Obtain the Entry's Value and TaxValues
1640  Note we use rounded values here and below to prevent creating an imbalanced transaction */
1641  value = gncEntryGetBalValue (entry, TRUE, is_cust_doc);
1642  tax = gncEntryGetBalTaxValue (entry, TRUE, is_cust_doc);
1643 
1644  DEBUG ("Tax %" PRId64 "/%" PRId64 " on entry value %" PRId64 "/%" PRId64,
1645  tax.num, tax.denom, value.num, value.denom);
1646  /* add the value for the account split */
1647  this_acc = (is_cust_doc ? gncEntryGetInvAccount (entry) :
1648  gncEntryGetBillAccount (entry));
1649  if (this_acc)
1650  {
1651  if (gnc_numeric_check (value) == GNC_ERROR_OK)
1652  {
1653  if (accumulatesplits)
1654  splitinfo = gncAccountValueAdd (splitinfo, this_acc, value);
1655  /* Adding to total in case of accumulatesplits will be deferred to later when each split is effectively added */
1656  else if (!gncInvoicePostAddSplit (book, this_acc, txn, value,
1657  gncEntryGetDescription (entry),
1658  type, invoice))
1659  {
1660  /*This is an error, which shouldn't even be able to happen.
1661  We can't really do anything sensible about it, and this is
1662  a user-interface free zone so we can't try asking the user
1663  again either, have to return NULL*/
1664  PERR("Failed to add split %s", gncEntryGetDescription (entry));
1665  LEAVE ("NULL");
1666  return NULL;
1667  }
1668 
1669  /* If there is a credit-card account, and this is a CCard
1670  * payment type, subtract it from the total, and instead
1671  * create a split to the CC Acct with a memo of the entry
1672  * description instead of the provided memo. Note that the
1673  * value reversal is the same as the post account.
1674  *
1675  * Note: we don't have to worry about the tax values --
1676  * expense vouchers don't have them.
1677  */
1678  if (ccard_acct && gncEntryGetBillPayment (entry) == GNC_PAYMENT_CARD)
1679  {
1680  Split *split;
1681 
1682  total = gnc_numeric_sub (total, value, denom,
1684 
1685  split = xaccMallocSplit (book);
1686  xaccSplitSetMemo (split, gncEntryGetDescription (entry));
1687  /* set action based on book option */
1688  gnc_set_num_action (NULL, split, gncInvoiceGetID (invoice), type);
1689  xaccAccountBeginEdit (ccard_acct);
1690  xaccAccountInsertSplit (ccard_acct, split);
1691  xaccAccountCommitEdit (ccard_acct);
1692  xaccTransAppendSplit (txn, split);
1693  xaccSplitSetBaseValue (split, gnc_numeric_neg (value),
1694  invoice->currency);
1695 
1696  }
1697 
1698  }
1699  else
1700  PWARN ("bad value in our entry");
1701  }
1702 
1703  /* check the taxes */
1704  if (gnc_numeric_check (tax) != GNC_ERROR_OK)
1705  PWARN ("bad tax in our entry");
1706 
1707  } /* for */
1708 
1709 
1710  /* now merge in the TaxValues */
1711  splitinfo = gncAccountValueAddList (splitinfo, taxes);
1712  gncAccountValueDestroy (taxes);
1713 
1714  /* Iterate through the splitinfo list and generate the splits */
1715  if (splitinfo)
1716  PINFO ("Processing Split List");
1717  for (iter = splitinfo; iter; iter = iter->next)
1718  {
1719  GncAccountValue *acc_val = iter->data;
1720 
1721  //gnc_numeric amt_rounded = gnc_numeric_convert(acc_val->value,
1722  // denom, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
1723  if (!gncInvoicePostAddSplit (book, acc_val->account, txn, acc_val->value,
1724  memo, type, invoice))
1725  {
1726  /*This is an error, which shouldn't even be able to happen.
1727  We can't really do anything sensible about it, and this is
1728  a user-interface free zone so we can't try asking the user
1729  again either, have to return NULL*/
1730  PERR("Failed to add split %s, aborting accumulated splits.", memo);
1731  return NULL;
1732  }
1733  }
1734 
1735  /* If there is a ccard account, we may have an additional "to_card" payment.
1736  * we should make that now.
1737  */
1738  if (ccard_acct && !gnc_numeric_zero_p (invoice->to_charge_amount))
1739  {
1740  Split *split = xaccMallocSplit (book);
1741 
1742  /* To charge amount is stored in document value. We need balance value here
1743  * so convert if necessary. */
1744  gnc_numeric to_charge_bal_amount = (is_cn ? gnc_numeric_neg (invoice->to_charge_amount)
1745  : invoice->to_charge_amount);
1746 
1747  PINFO ("Process to_card payment split");
1748  /* Set memo. */
1749  xaccSplitSetMemo (split, _("Extra to Charge Card"));
1750  /* Set action based on book option */
1751  gnc_set_num_action (NULL, split, gncInvoiceGetID (invoice), type);
1752 
1753  xaccAccountBeginEdit (ccard_acct);
1754  xaccAccountInsertSplit (ccard_acct, split);
1755  xaccAccountCommitEdit (ccard_acct);
1756  xaccTransAppendSplit (txn, split);
1757  xaccSplitSetBaseValue (split, gnc_numeric_neg (to_charge_bal_amount),
1758  invoice->currency);
1759 
1760  total = gnc_numeric_sub (total, to_charge_bal_amount, denom,
1762  }
1763 
1764  /* Now create the Posted split (which is the opposite sign of the above splits) */
1765  {
1766  Split *split = xaccMallocSplit (book);
1767 
1768  PINFO ("Process to_card balancing split");
1769  /* Set memo */
1770  xaccSplitSetMemo (split, memo);
1771  /* Set action based on book option */
1772  gnc_set_num_action (NULL, split, gncInvoiceGetID (invoice), type);
1773 
1774  xaccAccountBeginEdit (acc);
1775  xaccAccountInsertSplit (acc, split);
1776  xaccAccountCommitEdit (acc);
1777  xaccTransAppendSplit (txn, split);
1778  xaccSplitSetBaseValue (split, gnc_numeric_neg (total),
1779  invoice->currency);
1780 
1781  /* add this split to the lot */
1782  gnc_lot_add_split (lot, split);
1783  }
1784 
1785  /* Now attach this invoice to the txn and account */
1786  gncInvoiceAttachToTxn (invoice, txn);
1787  gncInvoiceSetPostedAcc (invoice, acc);
1788 
1789  xaccTransSetReadOnly (txn, _("Generated from an invoice. Try unposting the invoice."));
1790  xaccTransCommitEdit (txn);
1791 
1792  gncAccountValueDestroy (splitinfo);
1793 
1794  gnc_lot_commit_edit (lot);
1795  /* Not strictly necessary, since it was done by the Set calls
1796  * above, but good insurance. */
1797  DEBUG("Committing Invoice %s", invoice->id);
1798  mark_invoice (invoice);
1799  gncInvoiceCommitEdit (invoice);
1800 
1801  /* If requested, attempt to automatically apply open payments
1802  * and reverse documents to this lot to close it (or at least
1803  * reduce its balance) */
1804  if (autopay)
1805  gncInvoiceAutoApplyPayments (invoice);
1806 
1807  LEAVE ("");
1808  return txn;
1809 }
#define xaccTransAppendSplit(t, s)
Add a split to the transaction.
Definition: Transaction.h:370
Transaction * xaccMallocTransaction(QofBook *book)
The xaccMallocTransaction() will malloc memory and initialize it.
Definition: Transaction.c:511
void xaccSplitSetBaseValue(Split *s, gnc_numeric value, const gnc_commodity *base_currency)
Depending on the base_currency, set either the value or the amount of this split or both: If the base...
Definition: Split.c:1315
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
This function sets the posted date of the transaction, specified by a time64 (see ctime(3))...
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
Definition: Account.cpp:2701
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
void gnc_lot_add_split(GNCLot *lot, Split *split)
The gnc_lot_add_split() routine adds a split to this lot.
Definition: gnc-lot.c:626
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
Use any denominator which gives an exactly correct ratio of numerator to denominator.
Definition: gnc-numeric.h:189
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
Definition: gnc-numeric.h:166
gnc_numeric gncInvoiceGetTotal(GncInvoice *invoice)
Return the "total" amount of the invoice as seen on the document (and shown to the user in the report...
Definition: gncInvoice.c:1029
void gncInvoiceAutoApplyPayments(GncInvoice *invoice)
Attempt to pay the invoice using open payment lots and lots for documents of the opposite sign (credi...
Definition: gncInvoice.c:1983
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
Definition: Transaction.c:1426
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
void xaccTransSetReadOnly(Transaction *trans, const char *reason)
Set the transaction to be ReadOnly by setting a non-NULL value as "reason".
Definition: Transaction.c:2147
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
Definition: Split.c:1724
time64 xaccTransRetDatePosted(const Transaction *trans)
Retrieve the posted date of the transaction.
Definition: Transaction.c:2492
void xaccTransSetDateDue(Transaction *trans, time64 time)
Dates and txn-type for A/R and A/P "invoice" postings.
Definition: Transaction.c:2097
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
void gncAccountValueDestroy(GList *list)
Destroy a list of accountvalues.
Definition: gncTaxTable.c:997
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
Split * xaccMallocSplit(QofBook *book)
Constructor.
Definition: gmock-Split.cpp:37
gnc_numeric gnc_numeric_sub(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a-b.
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
Get the "parent" Owner or GncGUID thereof.
Definition: gncOwner.c:573
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition: Account.cpp:1449
#define xaccAccountInsertSplit(acc, s)
The xaccAccountInsertSplit() method will insert the indicated split into the indicated account...
Definition: Account.h:1038
GList * gncAccountValueAddList(GList *l1, GList *l2)
Merge l2 into l1.
Definition: gncTaxTable.c:970
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
time64 gnc_time(time64 *tbuf)
get the current local time
Definition: gnc-date.cpp:273
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.
GList * gncAccountValueAdd(GList *list, Account *acc, gnc_numeric value)
This will add value to the account-value for acc, creating a new list object if necessary.
Definition: gncTaxTable.c:942
void xaccTransSetDateEnteredSecs(Transaction *trans, time64 secs)
Modify the date of when the transaction was entered.
Definition: Transaction.c:2054
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer to the employee object...
Definition: gncOwner.c:391
No error.
Definition: gnc-numeric.h:224
AccountValueList * gncInvoiceGetTotalTaxList(GncInvoice *invoice)
Return a list of tax totals accumulated per tax account.
Definition: gncInvoice.c:1053
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition: Account.cpp:1490

◆ gncInvoiceRemoveEntries()

void gncInvoiceRemoveEntries ( GncInvoice *  invoice)

Remove all entries from an invoice.

To be called before destroying an invoice.

Definition at line 779 of file gncInvoice.c.

780 {
781  GList *node;
782 
783  if (!invoice) return;
784 
785  for (node = invoice->entries; node; node = node->next)
786  {
787  GncEntry *entry = node->data;
788 
789  switch (gncInvoiceGetOwnerType (invoice))
790  {
791  case GNC_OWNER_VENDOR:
792  case GNC_OWNER_EMPLOYEE:
793  // this is a vendor bill, or an expense voucher
794  gncBillRemoveEntry (invoice, entry);
795  break;
796  case GNC_OWNER_CUSTOMER:
797  default:
798  // this is an invoice
799  gncInvoiceRemoveEntry (invoice, entry);
800  break;
801  }
802 
803  /* If the entry is no longer referenced by any document,
804  * remove it.
805  */
806  if (!(gncEntryGetInvoice (entry) ||
807  gncEntryGetBill (entry) ||
808  gncEntryGetOrder (entry)))
809  {
810  gncEntryBeginEdit (entry);
811  gncEntryDestroy (entry);
812  }
813  }
814 }

◆ gncInvoiceSetDateOpenedGDate()

void gncInvoiceSetDateOpenedGDate ( GncInvoice *  invoice,
const GDate *  date 
)

Set the DateOpened using a GDate argument.

(Note: Internally this stores the date in a time64 as created through time64CanonicalDayTime()).

Definition at line 497 of file gncInvoice.c.

498 {
499  g_assert (date);
500  gncInvoiceSetDateOpened(invoice, time64CanonicalDayTime (gdate_to_time64 (*date)));
501 }
time64 gdate_to_time64(GDate d)
Turns a GDate into a time64, returning the first second of the day.
Definition: gnc-date.cpp:1256
time64 time64CanonicalDayTime(time64 t)
convert a time64 on a certain day (localtime) to the time64 representing midday on that day...
Definition: gnc-date.cpp:413

◆ gncInvoiceUnpost()

gboolean gncInvoiceUnpost ( GncInvoice *  invoice,
gboolean  reset_tax_tables 
)

Unpost this invoice.

This will destroy the posted transaction and return the invoice to its unposted state. It may leave empty lots out there. If reset_tax_tables is TRUE, then it will also revert all the Tax Tables to the parent, which will potentially change the total value of the invoice. It may also leave some orphaned Tax Table children.

Returns TRUE if successful, FALSE if there is a problem.

Definition at line 1812 of file gncInvoice.c.

1813 {
1814  Transaction *txn;
1815  GNCLot *lot;
1816  GList *lot_split_list, *lot_split_iter;
1817 
1818  if (!invoice) return FALSE;
1819  if (!gncInvoiceIsPosted (invoice)) return FALSE;
1820 
1821  txn = gncInvoiceGetPostedTxn (invoice);
1822  g_return_val_if_fail (txn, FALSE);
1823 
1824  lot = gncInvoiceGetPostedLot (invoice);
1825  g_return_val_if_fail (lot, FALSE);
1826 
1827  ENTER ("");
1828  /* Destroy the Posted Transaction */
1829  xaccTransClearReadOnly (txn);
1830  xaccTransBeginEdit (txn);
1831  xaccTransDestroy (txn);
1832  xaccTransCommitEdit (txn);
1833 
1834  /* Disconnect the lot from the invoice; re-attach to the invoice owner */
1835  gncInvoiceDetachFromLot (lot);
1836  gncOwnerAttachToLot (&invoice->owner, lot);
1837 
1838  /* Check if this invoice was linked to other lots (payments/inverse signed
1839  * invoices).
1840  * If this is the case, recreate the link transaction between all the remaining lots.
1841  *
1842  * Note that before GnuCash 2.6 payments were not stored in separate lots, but
1843  * always ended up in invoice lots when matched to an invoice. Over-payments
1844  * were copied to a new lot, to which later an invoice was added again and so on.
1845  * These over-payments were handled with automatic payment forward transactions.
1846  * You could consider these transactions to be links between lots as well, but
1847  * to avoid some unexpected behavior, these will not be altered here.
1848  */
1849 
1850  // Note: make a copy of the lot list here, when splits are deleted from the lot,
1851  // the original list may be destroyed by the lot code.
1852  lot_split_list = g_list_copy (gnc_lot_get_split_list (lot));
1853  if (lot_split_list)
1854  PINFO ("Recreating link transactions for remaining lots");
1855  for (lot_split_iter = lot_split_list; lot_split_iter; lot_split_iter = lot_split_iter->next)
1856  {
1857  Split *split = lot_split_iter->data;
1858  GList *other_split_list, *list_iter;
1859  Transaction *other_txn = xaccSplitGetParent (split);
1860  GList *lot_list = NULL;
1861 
1862  /* Only work with transactions that link invoices and payments.
1863  * Note: this check also catches the possible case of NULL splits. */
1864  if (xaccTransGetTxnType (other_txn) != TXN_TYPE_LINK)
1865  continue;
1866 
1867  /* Save a list of lots this linking transaction linked to */
1868  other_split_list = xaccTransGetSplitList (other_txn);
1869  for (list_iter = other_split_list; list_iter; list_iter = list_iter->next)
1870  {
1871  Split *other_split = list_iter->data;
1872  GNCLot *other_lot = xaccSplitGetLot (other_split);
1873 
1874  /* Omit the lot we are about to delete */
1875  if (other_lot == lot)
1876  continue;
1877 
1878  lot_list = g_list_prepend (lot_list, other_lot);
1879  }
1880  /* Maintain original split order */
1881  lot_list = g_list_reverse (lot_list);
1882 
1883  /* Now remove this link transaction. */
1884  xaccTransClearReadOnly (other_txn);
1885  xaccTransBeginEdit (other_txn);
1886  xaccTransDestroy (other_txn);
1887  xaccTransCommitEdit (other_txn);
1888 
1889  /* Re-balance the saved lots as well as is possible */
1890  gncOwnerAutoApplyPaymentsWithLots (&invoice->owner, lot_list);
1891 
1892  /* If any of the saved lots has no more splits, then destroy it.
1893  * Otherwise if any has an invoice associated with it,
1894  * send it a modified event to reset its paid status */
1895  for (list_iter = lot_list; list_iter; list_iter = list_iter->next)
1896  {
1897  GNCLot *other_lot = list_iter->data;
1898  GncInvoice *other_invoice = gncInvoiceGetInvoiceFromLot (other_lot);
1899 
1900  if (!gnc_lot_count_splits (other_lot))
1901  gnc_lot_destroy (other_lot);
1902  else if (other_invoice)
1903  qof_event_gen (QOF_INSTANCE(other_invoice), QOF_EVENT_MODIFY, NULL);
1904  }
1905  g_list_free (lot_list);
1906  }
1907  g_list_free (lot_split_list);
1908 
1909  /* If the lot has no splits, then destroy it */
1910  if (!gnc_lot_count_splits (lot))
1911  gnc_lot_destroy (lot);
1912 
1913  /* Clear out the invoice posted information */
1914  gncInvoiceBeginEdit (invoice);
1915 
1916  invoice->posted_acc = NULL;
1917  invoice->posted_txn = NULL;
1918  invoice->posted_lot = NULL;
1919  invoice->date_posted = INT64_MAX;
1920 
1921  /* if we've been asked to reset the tax tables, then do so */
1922  if (reset_tax_tables)
1923  {
1924  gboolean is_cust_doc = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
1925  GList *iter;
1926 
1927  for (iter = gncInvoiceGetEntries (invoice); iter; iter = iter->next)
1928  {
1929  GncEntry *entry = iter->data;
1930 
1931  gncEntryBeginEdit (entry);
1932  if (is_cust_doc)
1933  gncEntrySetInvTaxTable (entry,
1934  gncTaxTableGetParent (gncEntryGetInvTaxTable( entry)));
1935  else
1936  gncEntrySetBillTaxTable (entry,
1937  gncTaxTableGetParent (gncEntryGetBillTaxTable (entry)));
1938  gncEntryCommitEdit (entry);
1939  }
1940  }
1941 
1942  mark_invoice (invoice);
1943  gncInvoiceCommitEdit (invoice);
1944 
1945  LEAVE ("TRUE");
1946 
1947  return TRUE;
1948 }
char xaccTransGetTxnType(Transaction *trans)
Returns the Transaction Type: note this type will be derived from the transaction splits...
Definition: Transaction.c:2556
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
void gncOwnerAutoApplyPaymentsWithLots(const GncOwner *owner, GList *lots)
Given a list of lots, try to balance as many of them as possible by creating balancing transactions b...
Definition: gncOwner.c:1259
void xaccTransDestroy(Transaction *trans)
Destroys a transaction.
SplitList * gnc_lot_get_split_list(const GNCLot *lot)
The gnc_lot_get_split_list() routine returns a GList of all the splits in this lot.
Definition: gnc-lot.c:440
void gncOwnerAttachToLot(const GncOwner *owner, GNCLot *lot)
Attach an owner to a lot.
Definition: gncOwner.c:623
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
#define TXN_TYPE_LINK
Transaction is a link between (invoice and payment) lots.
Definition: Transaction.h:128
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
Definition: gncInvoice.c:1310
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:231
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
GNCLot * xaccSplitGetLot(const Split *split)
Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn't be...
Definition: Split.c:1877