GnuCash  4.11-11-ge9df8d41d2+
Files | Macros | Typedefs | Enumerations | Functions

Files

file  gncEntry.h
 Business Entry Interface.
 

Macros

#define GNC_ID_ENTRY   "gncEntry"
 
#define GNC_TYPE_ENTRY   (gnc_entry_get_type ())
 
#define GNC_ENTRY(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ENTRY, GncEntry))
 
#define GNC_ENTRY_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ENTRY, GncEntryClass))
 
#define GNC_IS_ENTRY(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ENTRY))
 
#define GNC_IS_ENTRY_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ENTRY))
 
#define GNC_ENTRY_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ENTRY, GncEntryClass))
 
#define ENTRY_DATE   "date"
 
#define ENTRY_DATE_ENTERED   "date-entered"
 
#define ENTRY_DESC   "desc"
 
#define ENTRY_ACTION   "action"
 
#define ENTRY_NOTES   "notes"
 
#define ENTRY_QTY   "qty"
 
#define ENTRY_IPRICE   "iprice"
 
#define ENTRY_IACCT   "invoice-account"
 
#define ENTRY_BACCT   "bill-account"
 
#define ENTRY_BPRICE   "bprice"
 
#define ENTRY_BILLABLE   "billable?"
 
#define ENTRY_BILLTO   "bill-to"
 
#define ENTRY_ORDER   "order"
 
#define ENTRY_INVOICE   "invoice"
 
#define ENTRY_BILL   "bill"
 
#define ENTRY_INV_DISC_TYPE   "discount-type"
 
#define ENTRY_INV_DISC_HOW   "discount-method"
 
#define ENTRY_INV_TAXABLE   "invoice-taxable"
 
#define ENTRY_BILL_TAXABLE   "bill-taxable"
 
#define ENTRY_INV_TAX_INC   "invoice-tax-included"
 
#define ENTRY_BILL_TAX_INC   "bill-tax-included"
 
#define ENTRY_INV_DISCOUNT   "invoice-discount"
 
#define ENTRY_BILL_PAY_TYPE   "bill-payment-type"
 
#define gncEntryGetGUID(x)   qof_instance_get_guid(QOF_INSTANCE(x))
 

Typedefs

typedef GList AccountValueList
 

Enumerations

enum  GncEntryPaymentType { GNC_PAYMENT_CASH = 1, GNC_PAYMENT_CARD }
 
enum  GncDiscountHow { GNC_DISC_PRETAX = 1, GNC_DISC_SAMETIME, GNC_DISC_POSTTAX }
 

Functions

GType gnc_entry_get_type (void)
 
const char * gncEntryDiscountHowToString (GncDiscountHow how)
 How to apply the discount and taxes. More...
 
gboolean gncEntryDiscountStringToHow (const char *str, GncDiscountHow *how)
 
const char * gncEntryPaymentTypeToString (GncEntryPaymentType type)
 
gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type)
 
void gncEntryCopy (const GncEntry *src, GncEntry *dest, gboolean add_entry)
 
GncOrder * gncEntryGetOrder (const GncEntry *entry)
 
GncInvoice * gncEntryGetInvoice (const GncEntry *entry)
 
GncInvoice * gncEntryGetBill (const GncEntry *entry)
 
gboolean gncEntryIsOpen (const GncEntry *entry)
 
void gncEntryBeginEdit (GncEntry *entry)
 
void gncEntryCommitEdit (GncEntry *entry)
 
int gncEntryCompare (const GncEntry *a, const GncEntry *b)
 

Create/Destroy Functions

GncEntry * gncEntryCreate (QofBook *book)
 
void gncEntryDestroy (GncEntry *entry)
 

Generic (shared) data

void gncEntrySetDateGDate (GncEntry *entry, const GDate *date)
 Set the date of this entry.
 
void gncEntrySetDate (GncEntry *entry, time64 date)
 DEPRECATED - use gncEntrySetDateGDate() instead! (Because the time-of-day is a misleading extra information. More...
 
void gncEntrySetDateEntered (GncEntry *entry, time64 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)
 Set the internal quantity without any conversion. More...
 
void gncEntrySetDocQuantity (GncEntry *entry, gnc_numeric quantity, gboolean is_cn)
 Set the internal quantity converting from the quantity as visible on the physical document. More...
 
GDate gncEntryGetDateGDate (const GncEntry *entry)
 Returns the day of this entry.
 
time64 gncEntryGetDate (const GncEntry *entry)
 DEPRECATED - use gncEntryGetDateGDate() instead! (Because the time-of-day is a misleading extra information. More...
 
time64 gncEntryGetDateEntered (const GncEntry *entry)
 
const char * gncEntryGetDescription (const GncEntry *entry)
 
const char * gncEntryGetAction (const GncEntry *entry)
 
const char * gncEntryGetNotes (const GncEntry *notes)
 
gnc_numeric gncEntryGetQuantity (const GncEntry *entry)
 Get the quantity as stored internally. More...
 
gnc_numeric gncEntryGetDocQuantity (const GncEntry *entry, gboolean is_cn)
 Get the quantity as on the physical document. More...
 

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)
 
void qofEntrySetInvDiscType (GncEntry *entry, const char *type)
 
void qofEntrySetInvDiscHow (GncEntry *entry, const char *type)
 
AccountgncEntryGetInvAccount (const GncEntry *entry)
 
gnc_numeric gncEntryGetInvPrice (const GncEntry *entry)
 
gnc_numeric gncEntryGetPrice (const GncEntry *entry, const gboolean cust_doc, const gboolean net)
 
gnc_numeric gncEntryGetInvDiscount (const GncEntry *entry)
 
GncAmountType gncEntryGetInvDiscountType (const GncEntry *entry)
 
GncDiscountHow gncEntryGetInvDiscountHow (const GncEntry *entry)
 
char * qofEntryGetInvDiscType (const GncEntry *entry)
 
char * qofEntryGetInvDiscHow (const GncEntry *entry)
 
gboolean gncEntryGetInvTaxable (const GncEntry *entry)
 
gboolean gncEntryGetInvTaxIncluded (const GncEntry *entry)
 
GncTaxTablegncEntryGetInvTaxTable (const GncEntry *entry)
 

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)
 
AccountgncEntryGetBillAccount (const GncEntry *entry)
 
gnc_numeric gncEntryGetBillPrice (const GncEntry *entry)
 
gboolean gncEntryGetBillTaxable (const GncEntry *entry)
 
gboolean gncEntryGetBillTaxIncluded (const GncEntry *entry)
 
GncTaxTablegncEntryGetBillTaxTable (const GncEntry *entry)
 
gboolean gncEntryGetBillable (const GncEntry *entry)
 
GncOwnergncEntryGetBillTo (GncEntry *entry)
 
GncEntryPaymentType gncEntryGetBillPayment (const GncEntry *entry)
 

employee-stuff

void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type)
 

Getting Values

An entry has three important values:

  • entry value: the amount the merchant gets
  • tax value: the amount the government gets
  • discount value: the amount the customer saved

These values can be retrieved in several variants. Depending on how they will be used some sign reversals can be applied on the values:

  • Doc value: the value as listed on the document. This is usually a positive value, unless the document was a negative invoice/bill or negative credit note. Since credit note entry values are stored negatively internally, they will be sign-reversed before returning them.
  • Bal value: the value as it will impact the balance. Customer invoices and vendor credit notes have a positive influence on the balance, so these values will be positive. For vendor bills and customer credit notes, the values will be negative.

For tax there are TaxValue and TaxValues variants: the first one returns to total tax value for this entry, meaning the sum of all individual taxes. The second one returns a list of all the individual tax values for this entry. This list holds unrounded values only, there's no variant with rounded values.

Note that this list is not owned by the entry. When no longer needed, it should be freed with gncAccountValueDestroy.

Finally, there are rounded and unrounded variants of most of these functions.

gnc_numeric gncEntryGetDocValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn)
 
gnc_numeric gncEntryGetDocTaxValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn)
 
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.
 
gnc_numeric gncEntryGetDocDiscountValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn)
 
gnc_numeric gncEntryGetBalValue (GncEntry *entry, gboolean round, gboolean is_cust_doc)
 
gnc_numeric gncEntryGetBalTaxValue (GncEntry *entry, gboolean round, gboolean is_cust_doc)
 
AccountValueList * gncEntryGetBalTaxValues (GncEntry *entry, gboolean is_cust_doc)
 Careful: the returned list is NOT owned by the entry and should be freed by the caller.
 
gnc_numeric gncEntryGetBalDiscountValue (GncEntry *entry, gboolean round, gboolean is_cust_doc)
 
void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price, const GncTaxTable *tax_table, gboolean tax_included, gnc_numeric discount, GncAmountType discount_type, GncDiscountHow discount_how, int SCU, gnc_numeric *value, gnc_numeric *discount_value, GList **tax_values)
 Compute the Entry value, tax_value, and discount_value, based on the quantity, price, discount, tax_-table, and types. More...
 

Detailed Description

Function Documentation

◆ gncEntryComputeValue()

void gncEntryComputeValue ( gnc_numeric  qty,
gnc_numeric  price,
const GncTaxTable tax_table,
gboolean  tax_included,
gnc_numeric  discount,
GncAmountType  discount_type,
GncDiscountHow  discount_how,
int  SCU,
gnc_numeric *  value,
gnc_numeric *  discount_value,
GList **  tax_values 
)

Compute the Entry value, tax_value, and discount_value, based on the quantity, price, discount, tax_-table, and types.

The value is the amount the merchant gets, the taxes are what the gov't gets, and the discount is how much the customer saved. The SCU is the target denominator of the value and tax – it should be the account or commodity SCU of the target.

The return values are NOT rounded.

If the tax_values list is owned by the entry, it will be destroyed automatically. Otherwise use gncAccountValueDestroy to free it.

◆ gncEntryDiscountHowToString()

const char* gncEntryDiscountHowToString ( GncDiscountHow  how)

How to apply the discount and taxes.

There are three distinct ways to apply them:

Type: discount tax PRETAX pretax pretax-discount SAMETIME pretax pretax POSTTAX pretax+tax pretax

Definition at line 113 of file gncEntry.c.

114 {
115  switch (how)
116  {
117  case (GNC_DISC_PRETAX):
118  return "PRETAX";
119  case (GNC_DISC_SAMETIME):
120  return "SAMETIME";
121  case (GNC_DISC_POSTTAX):
122  return "POSTTAX";
123  default:
124  PWARN ("asked to translate unknown discount-how %d.\n", how);
125  break;
126  }
127  return NULL;
128 }
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250

◆ gncEntryGetDate()

time64 gncEntryGetDate ( const GncEntry *  entry)

DEPRECATED - use gncEntryGetDateGDate() instead! (Because the time-of-day is a misleading extra information.

We are only dealing with the day information!

Definition at line 909 of file gncEntry.c.

910 {
911  return entry ? entry->date : 0;
912 }

◆ gncEntryGetDocQuantity()

gnc_numeric gncEntryGetDocQuantity ( const GncEntry *  entry,
gboolean  is_cn 
)

Get the quantity as on the physical document.

This distinction is made because credit notes store their quantity sign-reversed compared to how the quantity is written on the actual credit note (and hence how the ledger and reports show it to the user).

Definition at line 948 of file gncEntry.c.

949 {
950  gnc_numeric value = gncEntryGetQuantity (entry);
951  return (is_cn ? gnc_numeric_neg (value) : value);
952 }
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
gnc_numeric gncEntryGetQuantity(const GncEntry *entry)
Get the quantity as stored internally.
Definition: gncEntry.c:942

◆ gncEntryGetQuantity()

gnc_numeric gncEntryGetQuantity ( const GncEntry *  entry)

Get the quantity as stored internally.

This distinction is made because credit notes store their quantity sign-reversed compared to how the quantity is written on the actual credit note (and hence how the ledger and reports show it to the user).

Definition at line 942 of file gncEntry.c.

943 {
944  if (!entry) return gnc_numeric_zero();
945  return entry->quantity;
946 }

◆ gncEntrySetDate()

void gncEntrySetDate ( GncEntry *  entry,
time64  date 
)

DEPRECATED - use gncEntrySetDateGDate() instead! (Because the time-of-day is a misleading extra information.

We are only dealing with the day information!

Definition at line 478 of file gncEntry.c.

479 {
480  gboolean first_date = FALSE;
481  if (!entry) return;
482  if (entry->date == date) return;
483  if (!entry->date)
484  first_date = TRUE;
485  gncEntryBeginEdit (entry);
486  entry->date = date;
487  mark_entry (entry);
488  gncEntryCommitEdit (entry);
489 
490  /* Don't re-sort the first time we set the date on this entry */
491  if (!first_date)
492  {
493  if (entry->invoice)
494  gncInvoiceSortEntries(entry->invoice);
495  if (entry->bill)
496  gncInvoiceSortEntries(entry->bill);
497  }
498 }
void gncInvoiceSortEntries(GncInvoice *invoice)
Call this function when an Entry is changed and you want to re-sort the list of entries.
Definition: gncInvoice.c:766

◆ gncEntrySetDocQuantity()

void gncEntrySetDocQuantity ( GncEntry *  entry,
gnc_numeric  quantity,
gboolean  is_cn 
)

Set the internal quantity converting from the quantity as visible on the physical document.

This distinction is made because credit notes store their quantity sign-reversed compared to how the quantity is written on the actual credit note (and hence how the ledger and reports show it to the user).

Definition at line 558 of file gncEntry.c.

559 {
560  if (!entry) return;
561  if (gnc_numeric_eq (entry->quantity, (is_cn ? gnc_numeric_neg (quantity) : quantity))) return;
562  gncEntryBeginEdit (entry);
563  entry->quantity = (is_cn ? gnc_numeric_neg (quantity) : quantity);
564  entry->values_dirty = TRUE;
565  mark_entry (entry);
566  gncEntryCommitEdit (entry);
567 }
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b are exactly the same (have the same numerator and ...

◆ gncEntrySetQuantity()

void gncEntrySetQuantity ( GncEntry *  entry,
gnc_numeric  quantity 
)

Set the internal quantity without any conversion.

This distinction is made because credit notes store their quantity sign-reversed compared to how the quantity is written on the actual credit note (and hence how the ledger and reports show it to the user).

Definition at line 547 of file gncEntry.c.

548 {
549  if (!entry) return;
550  if (gnc_numeric_eq (entry->quantity, quantity)) return;
551  gncEntryBeginEdit (entry);
552  entry->quantity = quantity;
553  entry->values_dirty = TRUE;
554  mark_entry (entry);
555  gncEntryCommitEdit (entry);
556 }
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b are exactly the same (have the same numerator and ...