2003-10-17 00:15:56 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* gncEntry.c -- the Core Business Entry Interface *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2003-10-17 00:15:56 -05:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
/*
|
2002-01-20 20:27:02 -06:00
|
|
|
* Copyright (C) 2001,2002 Derek Atkins
|
2001-11-21 19:23:07 -06:00
|
|
|
* Author: Derek Atkins <warlord@MIT.EDU>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2003-06-11 11:22:26 -05:00
|
|
|
#include "gnc-commodity.h"
|
2005-11-01 21:32:36 -06:00
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
#include "gncEntry.h"
|
|
|
|
#include "gncEntryP.h"
|
|
|
|
#include "gncInvoice.h"
|
|
|
|
#include "gncOrder.h"
|
|
|
|
|
2003-10-14 16:20:55 -05:00
|
|
|
struct _gncEntry
|
|
|
|
{
|
|
|
|
QofInstance inst;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
Timespec date;
|
2002-02-27 23:10:07 -06:00
|
|
|
Timespec date_entered;
|
2001-11-21 19:23:07 -06:00
|
|
|
char * desc;
|
|
|
|
char * action;
|
2002-06-16 23:04:05 -05:00
|
|
|
char * notes;
|
2001-11-21 19:23:07 -06:00
|
|
|
gnc_numeric quantity;
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* customer invoice data */
|
|
|
|
Account * i_account;
|
|
|
|
gnc_numeric i_price;
|
|
|
|
gboolean i_taxable;
|
|
|
|
gboolean i_taxincluded;
|
|
|
|
GncTaxTable * i_tax_table;
|
|
|
|
gnc_numeric i_discount;
|
|
|
|
GncAmountType i_disc_type;
|
|
|
|
GncDiscountHow i_disc_how;
|
|
|
|
|
|
|
|
/* vendor bill data */
|
|
|
|
Account * b_account;
|
|
|
|
gnc_numeric b_price;
|
|
|
|
gboolean b_taxable;
|
|
|
|
gboolean b_taxincluded;
|
|
|
|
GncTaxTable * b_tax_table;
|
2002-07-10 12:32:59 -05:00
|
|
|
gboolean billable;
|
|
|
|
GncOwner billto;
|
|
|
|
|
2003-03-02 22:58:55 -06:00
|
|
|
/* employee bill data */
|
|
|
|
GncEntryPaymentType b_payment;
|
|
|
|
|
|
|
|
/* my parent(s) */
|
2001-11-21 19:23:07 -06:00
|
|
|
GncOrder * order;
|
|
|
|
GncInvoice * invoice;
|
2002-07-09 23:12:19 -05:00
|
|
|
GncInvoice * bill;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* CACHED VALUES */
|
2002-05-27 13:17:31 -05:00
|
|
|
gboolean values_dirty;
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* customer invoice */
|
|
|
|
gnc_numeric i_value;
|
|
|
|
gnc_numeric i_value_rounded;
|
|
|
|
GList * i_tax_values;
|
|
|
|
gnc_numeric i_tax_value;
|
|
|
|
gnc_numeric i_tax_value_rounded;
|
|
|
|
gnc_numeric i_disc_value;
|
|
|
|
gnc_numeric i_disc_value_rounded;
|
|
|
|
Timespec i_taxtable_modtime;
|
|
|
|
|
|
|
|
/* vendor bill */
|
|
|
|
gnc_numeric b_value;
|
|
|
|
gnc_numeric b_value_rounded;
|
|
|
|
GList * b_tax_values;
|
|
|
|
gnc_numeric b_tax_value;
|
|
|
|
gnc_numeric b_tax_value_rounded;
|
|
|
|
Timespec b_taxtable_modtime;
|
2001-11-21 19:23:07 -06:00
|
|
|
};
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
static QofLogModule log_module = GNC_MOD_BUSINESS;
|
2002-11-03 14:21:42 -06:00
|
|
|
|
2002-07-01 13:31:48 -05:00
|
|
|
/* You must edit the functions in this block in tandem. KEEP THEM IN
|
|
|
|
SYNC! */
|
|
|
|
|
|
|
|
#define GNC_RETURN_ENUM_AS_STRING(x,s) case (x): return (s);
|
|
|
|
const char *
|
|
|
|
gncEntryDiscountHowToString (GncDiscountHow how)
|
|
|
|
{
|
|
|
|
switch(how)
|
|
|
|
{
|
|
|
|
GNC_RETURN_ENUM_AS_STRING(GNC_DISC_PRETAX, "PRETAX");
|
|
|
|
GNC_RETURN_ENUM_AS_STRING(GNC_DISC_SAMETIME, "SAMETIME");
|
|
|
|
GNC_RETURN_ENUM_AS_STRING(GNC_DISC_POSTTAX, "POSTTAX");
|
|
|
|
default:
|
|
|
|
g_warning ("asked to translate unknown discount-how %d.\n", how);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(NULL);
|
|
|
|
}
|
2003-03-02 22:58:55 -06:00
|
|
|
|
|
|
|
const char * gncEntryPaymentTypeToString (GncEntryPaymentType type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
GNC_RETURN_ENUM_AS_STRING(GNC_PAYMENT_CASH, "CASH");
|
|
|
|
GNC_RETURN_ENUM_AS_STRING(GNC_PAYMENT_CARD, "CARD");
|
|
|
|
default:
|
|
|
|
g_warning ("asked to translate unknown payment type %d.\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(NULL);
|
|
|
|
}
|
2002-07-01 13:31:48 -05:00
|
|
|
#undef GNC_RETURN_ENUM_AS_STRING
|
2003-03-02 22:58:55 -06:00
|
|
|
#define GNC_RETURN_ON_MATCH(s,x,r) \
|
|
|
|
if(safe_strcmp((s), (str)) == 0) { *(r) = x; return(TRUE); }
|
2002-07-01 13:31:48 -05:00
|
|
|
gboolean gncEntryDiscountStringToHow (const char *str, GncDiscountHow *how)
|
|
|
|
{
|
2003-03-02 22:58:55 -06:00
|
|
|
GNC_RETURN_ON_MATCH ("PRETAX", GNC_DISC_PRETAX, how);
|
|
|
|
GNC_RETURN_ON_MATCH ("SAMETIME", GNC_DISC_SAMETIME, how);
|
|
|
|
GNC_RETURN_ON_MATCH ("POSTTAX", GNC_DISC_POSTTAX, how);
|
|
|
|
g_warning ("asked to translate unknown discount-how string %s.\n",
|
|
|
|
str ? str : "(null)");
|
|
|
|
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type)
|
|
|
|
{
|
|
|
|
GNC_RETURN_ON_MATCH ("CASH", GNC_PAYMENT_CASH, type);
|
|
|
|
GNC_RETURN_ON_MATCH ("CARD", GNC_PAYMENT_CARD, type);
|
2002-07-01 13:31:48 -05:00
|
|
|
g_warning ("asked to translate unknown discount-how string %s.\n",
|
|
|
|
str ? str : "(null)");
|
|
|
|
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
#undef GNC_RETURN_ON_MATCH
|
|
|
|
|
2003-10-19 00:13:59 -05:00
|
|
|
#define _GNC_MOD_NAME GNC_ID_ENTRY
|
2001-11-24 23:34:34 -06:00
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
#define SET_STR(obj, member, str) { \
|
2001-11-21 19:23:07 -06:00
|
|
|
char * tmp; \
|
|
|
|
\
|
|
|
|
if (!safe_strcmp (member, str)) return; \
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (obj); \
|
2001-11-21 19:23:07 -06:00
|
|
|
tmp = CACHE_INSERT (str); \
|
|
|
|
CACHE_REMOVE (member); \
|
|
|
|
member = tmp; \
|
|
|
|
}
|
|
|
|
|
2002-02-28 22:15:01 -06:00
|
|
|
G_INLINE_FUNC void mark_entry (GncEntry *entry);
|
2005-11-01 21:32:36 -06:00
|
|
|
void mark_entry (GncEntry *entry)
|
2002-02-28 22:15:01 -06:00
|
|
|
{
|
2006-05-02 21:28:18 -05:00
|
|
|
qof_instance_set_dirty(&entry->inst);
|
2006-03-08 21:48:49 -06:00
|
|
|
qof_event_gen (&entry->inst.entity, QOF_EVENT_MODIFY, NULL);
|
2002-02-28 22:15:01 -06:00
|
|
|
}
|
|
|
|
|
2003-10-21 08:53:55 -05:00
|
|
|
/* ================================================================ */
|
2001-11-21 19:23:07 -06:00
|
|
|
/* Create/Destroy Functions */
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
GncEntry *gncEntryCreate (QofBook *book)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
GncEntry *entry;
|
2002-09-14 00:32:37 -05:00
|
|
|
gnc_numeric zero = gnc_numeric_zero ();
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
if (!book) return NULL;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
entry = g_new0 (GncEntry, 1);
|
2003-10-14 16:20:55 -05:00
|
|
|
qof_instance_init (&entry->inst, _GNC_MOD_NAME, book);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
entry->desc = CACHE_INSERT ("");
|
|
|
|
entry->action = CACHE_INSERT ("");
|
2002-06-16 23:04:05 -05:00
|
|
|
entry->notes = CACHE_INSERT ("");
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->quantity = zero;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_price = zero;
|
|
|
|
entry->i_taxable = TRUE;
|
|
|
|
entry->i_discount = zero;
|
|
|
|
entry->i_disc_type = GNC_AMT_TYPE_PERCENT;
|
|
|
|
entry->i_disc_how = GNC_DISC_PRETAX;
|
|
|
|
|
|
|
|
entry->b_price = zero;
|
|
|
|
entry->b_taxable = TRUE;
|
2002-07-11 00:20:52 -05:00
|
|
|
entry->billto.type = GNC_OWNER_CUSTOMER;
|
2003-03-02 22:58:55 -06:00
|
|
|
entry->b_payment = GNC_PAYMENT_CASH;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->values_dirty = TRUE;
|
|
|
|
|
2006-03-08 21:48:49 -06:00
|
|
|
qof_event_gen (&entry->inst.entity, QOF_EVENT_CREATE, NULL);
|
2002-02-28 22:15:01 -06:00
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntryDestroy (GncEntry *entry)
|
2002-11-03 14:21:42 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2003-10-14 16:20:55 -05:00
|
|
|
entry->inst.do_free = TRUE;
|
2002-11-03 14:21:42 -06:00
|
|
|
gncEntryCommitEdit(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gncEntryFree (GncEntry *entry)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
|
2006-03-08 21:48:49 -06:00
|
|
|
qof_event_gen (&entry->inst.entity, QOF_EVENT_DESTROY, NULL);
|
2002-02-28 22:15:01 -06:00
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
CACHE_REMOVE (entry->desc);
|
|
|
|
CACHE_REMOVE (entry->action);
|
2002-06-16 23:04:05 -05:00
|
|
|
CACHE_REMOVE (entry->notes);
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->i_tax_values)
|
|
|
|
gncAccountValueDestroy (entry->i_tax_values);
|
|
|
|
if (entry->b_tax_values)
|
|
|
|
gncAccountValueDestroy (entry->b_tax_values);
|
2003-06-13 23:31:03 -05:00
|
|
|
if (entry->i_tax_table)
|
|
|
|
gncTaxTableDecRef (entry->i_tax_table);
|
|
|
|
if (entry->b_tax_table)
|
|
|
|
gncTaxTableDecRef (entry->b_tax_table);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2003-10-14 16:20:55 -05:00
|
|
|
qof_instance_release (&entry->inst);
|
2001-11-21 19:23:07 -06:00
|
|
|
g_free (entry);
|
|
|
|
}
|
|
|
|
|
2003-10-21 08:53:55 -05:00
|
|
|
GncEntry *
|
|
|
|
gncCloneEntry (GncEntry *from, QofBook *book)
|
|
|
|
{
|
|
|
|
/* XXX unfinished */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GncEntry *
|
|
|
|
gncEntryObtainTwin (GncEntry *from, QofBook *book)
|
|
|
|
{
|
|
|
|
GncEntry *entry;
|
|
|
|
if (!book) return NULL;
|
|
|
|
|
|
|
|
entry = (GncEntry *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
|
|
|
if (!entry)
|
|
|
|
{
|
|
|
|
entry = gncCloneEntry (from, book);
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ================================================================ */
|
2001-11-21 19:23:07 -06:00
|
|
|
/* Set Functions */
|
|
|
|
|
2002-02-27 23:10:07 -06:00
|
|
|
void gncEntrySetDate (GncEntry *entry, Timespec date)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2006-02-01 15:49:06 -06:00
|
|
|
gboolean first_date = FALSE;
|
|
|
|
Timespec zero_time = { 0, 0 };
|
|
|
|
|
2002-02-27 23:10:07 -06:00
|
|
|
if (!entry) return;
|
2002-06-21 14:00:34 -05:00
|
|
|
if (timespec_equal (&entry->date, &date)) return;
|
2006-02-01 15:49:06 -06:00
|
|
|
if (timespec_equal (&entry->date, &zero_time))
|
|
|
|
first_date = TRUE;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-02-27 23:10:07 -06:00
|
|
|
entry->date = date;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2006-02-01 15:49:06 -06:00
|
|
|
|
|
|
|
/* Don't re-sort the first time we set the date on this entry */
|
|
|
|
if (!first_date) {
|
|
|
|
if (entry->invoice)
|
|
|
|
gncInvoiceSortEntries(entry->invoice);
|
|
|
|
if (entry->bill)
|
|
|
|
gncInvoiceSortEntries(entry->bill);
|
|
|
|
}
|
2002-02-27 23:10:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetDateEntered (GncEntry *entry, Timespec date)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-06-21 14:00:34 -05:00
|
|
|
if (timespec_equal (&entry->date_entered, &date)) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-02-27 23:10:07 -06:00
|
|
|
entry->date_entered = date;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetDescription (GncEntry *entry, const char *desc)
|
|
|
|
{
|
|
|
|
if (!entry || !desc) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
SET_STR (entry, entry->desc, desc);
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetAction (GncEntry *entry, const char *action)
|
|
|
|
{
|
|
|
|
if (!entry || !action) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
SET_STR (entry,entry->action, action);
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-06-16 23:04:05 -05:00
|
|
|
void gncEntrySetNotes (GncEntry *entry, const char *notes)
|
|
|
|
{
|
|
|
|
if (!entry || !notes) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
SET_STR (entry, entry->notes, notes);
|
2002-06-16 23:04:05 -05:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-06-16 23:04:05 -05:00
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-06-21 14:00:34 -05:00
|
|
|
if (gnc_numeric_eq (entry->quantity, quantity)) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
entry->quantity = quantity;
|
2002-05-27 13:17:31 -05:00
|
|
|
entry->values_dirty = TRUE;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* Customer Invoices */
|
|
|
|
|
|
|
|
void gncEntrySetInvAccount (GncEntry *entry, Account *acc)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->i_account == acc) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_account = acc;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetInvPrice (GncEntry *entry, gnc_numeric price)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (gnc_numeric_eq (entry->i_price, price)) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_price = price;
|
2002-05-27 13:17:31 -05:00
|
|
|
entry->values_dirty = TRUE;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetInvTaxable (GncEntry *entry, gboolean taxable)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->i_taxable == taxable) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_taxable = taxable;
|
|
|
|
entry->values_dirty = TRUE;
|
2002-07-11 10:11:33 -05:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-07-11 10:11:33 -05:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetInvTaxIncluded (GncEntry *entry, gboolean taxincluded)
|
2002-07-11 10:11:33 -05:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->i_taxincluded == taxincluded) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_taxincluded = taxincluded;
|
|
|
|
entry->values_dirty = TRUE;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetInvTaxTable (GncEntry *entry, GncTaxTable *table)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->i_tax_table == table) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->i_tax_table)
|
|
|
|
gncTaxTableDecRef (entry->i_tax_table);
|
|
|
|
if (table)
|
|
|
|
gncTaxTableIncRef (table);
|
|
|
|
entry->i_tax_table = table;
|
|
|
|
entry->values_dirty = TRUE;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetInvDiscount (GncEntry *entry, gnc_numeric discount)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (gnc_numeric_eq (entry->i_discount, discount)) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_discount = discount;
|
|
|
|
entry->values_dirty = TRUE;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetInvDiscountType (GncEntry *entry, GncAmountType type)
|
2002-07-09 23:12:19 -05:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->i_disc_type == type) return;
|
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_disc_type = type;
|
|
|
|
entry->values_dirty = TRUE;
|
2002-07-09 23:12:19 -05:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-07-09 23:12:19 -05:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetInvDiscountHow (GncEntry *entry, GncDiscountHow how)
|
2002-06-16 00:11:33 -05:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->i_disc_how == how) return;
|
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_disc_how = how;
|
2002-06-16 00:11:33 -05:00
|
|
|
entry->values_dirty = TRUE;
|
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
void qofEntrySetInvDiscType (GncEntry *entry, const char *type_string)
|
|
|
|
{
|
|
|
|
GncAmountType type;
|
|
|
|
|
|
|
|
if (!entry) return;
|
|
|
|
gncAmountStringToType(type_string, &type);
|
|
|
|
if (entry->i_disc_type == type) return;
|
|
|
|
gncEntryBeginEdit (entry);
|
|
|
|
entry->i_disc_type = type;
|
|
|
|
entry->values_dirty = TRUE;
|
|
|
|
mark_entry (entry);
|
|
|
|
gncEntryCommitEdit (entry);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void qofEntrySetInvDiscHow (GncEntry *entry, const char *type)
|
|
|
|
{
|
|
|
|
GncDiscountHow how;
|
|
|
|
|
|
|
|
if (!entry) return;
|
|
|
|
gncEntryBeginEdit (entry);
|
|
|
|
gncEntryDiscountStringToHow(type, &how);
|
|
|
|
if (entry->i_disc_how == how) return;
|
|
|
|
entry->i_disc_how = how;
|
|
|
|
entry->values_dirty = TRUE;
|
|
|
|
mark_entry (entry);
|
|
|
|
gncEntryCommitEdit (entry);
|
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* Vendor Bills */
|
|
|
|
|
|
|
|
void gncEntrySetBillAccount (GncEntry *entry, Account *acc)
|
2001-11-23 23:35:08 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->b_account == acc) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->b_account = acc;
|
2002-06-16 00:11:33 -05:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetBillPrice (GncEntry *entry, gnc_numeric price)
|
2002-06-16 00:11:33 -05:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (gnc_numeric_eq (entry->b_price, price)) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->b_price = price;
|
2002-05-27 13:17:31 -05:00
|
|
|
entry->values_dirty = TRUE;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetBillTaxable (GncEntry *entry, gboolean taxable)
|
2001-11-23 23:35:08 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->b_taxable == taxable) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->b_taxable = taxable;
|
2002-05-27 13:17:31 -05:00
|
|
|
entry->values_dirty = TRUE;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetBillTaxIncluded (GncEntry *entry, gboolean taxincluded)
|
2002-06-16 00:11:33 -05:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->b_taxincluded == taxincluded) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->b_taxincluded = taxincluded;
|
|
|
|
entry->values_dirty = TRUE;
|
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
}
|
2002-06-16 00:11:33 -05:00
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntrySetBillTaxTable (GncEntry *entry, GncTaxTable *table)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
if (entry->b_tax_table == table) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
if (entry->b_tax_table)
|
|
|
|
gncTaxTableDecRef (entry->b_tax_table);
|
|
|
|
if (table)
|
|
|
|
gncTaxTableIncRef (table);
|
|
|
|
entry->b_tax_table = table;
|
2002-06-16 00:11:33 -05:00
|
|
|
entry->values_dirty = TRUE;
|
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
|
|
|
|
2002-07-10 12:32:59 -05:00
|
|
|
void gncEntrySetBillable (GncEntry *entry, gboolean billable)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
if (entry->billable == billable) return;
|
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-07-10 12:32:59 -05:00
|
|
|
entry->billable = billable;
|
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-07-10 12:32:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetBillTo (GncEntry *entry, GncOwner *billto)
|
|
|
|
{
|
|
|
|
if (!entry || !billto) return;
|
|
|
|
if (gncOwnerEqual (&entry->billto, billto)) return;
|
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-07-10 12:32:59 -05:00
|
|
|
gncOwnerCopy (billto, &entry->billto);
|
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-07-10 12:32:59 -05:00
|
|
|
}
|
|
|
|
|
2003-03-02 22:58:55 -06:00
|
|
|
void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
if (entry->b_payment == type) return;
|
|
|
|
gncEntryBeginEdit (entry);
|
|
|
|
entry->b_payment = type;
|
|
|
|
mark_entry (entry);
|
|
|
|
gncEntryCommitEdit (entry);
|
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* Called from gncOrder when we're added to the Order */
|
|
|
|
void gncEntrySetOrder (GncEntry *entry, GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
if (entry->order == order) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->order = order;
|
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
|
|
|
|
/* Generate an event modifying the Order's end-owner */
|
2003-06-27 00:51:05 -05:00
|
|
|
#if 0
|
2006-03-08 21:48:49 -06:00
|
|
|
qof_event_gen (gncOwnerGetEndGUID (gncOrderGetOwner (order)),
|
|
|
|
QOF_EVENT_MODIFY, NULL);
|
2003-06-27 00:51:05 -05:00
|
|
|
#endif
|
2002-09-14 00:32:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called from gncInvoice when we're added to the Invoice */
|
|
|
|
void gncEntrySetInvoice (GncEntry *entry, GncInvoice *invoice)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
if (entry->invoice == invoice) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->invoice = invoice;
|
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called from gncInvoice when we're added to the Invoice/Bill */
|
|
|
|
void gncEntrySetBill (GncEntry *entry, GncInvoice *bill)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
if (entry->bill == bill) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->bill = bill;
|
|
|
|
mark_entry (entry);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
}
|
|
|
|
|
2002-05-18 15:10:27 -05:00
|
|
|
void gncEntryCopy (const GncEntry *src, GncEntry *dest)
|
|
|
|
{
|
|
|
|
if (!src || !dest) return;
|
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryBeginEdit (dest);
|
2002-05-18 15:10:27 -05:00
|
|
|
dest->date = src->date;
|
|
|
|
dest->date_entered = src->date_entered; /* ??? */
|
|
|
|
gncEntrySetDescription (dest, src->desc);
|
|
|
|
gncEntrySetAction (dest, src->action);
|
2002-06-16 23:04:05 -05:00
|
|
|
gncEntrySetNotes (dest, src->notes);
|
2002-05-18 15:10:27 -05:00
|
|
|
dest->quantity = src->quantity;
|
2002-09-14 00:32:37 -05:00
|
|
|
|
|
|
|
dest->i_account = src->i_account;
|
|
|
|
dest->i_price = src->i_price;
|
|
|
|
dest->i_taxable = src->i_taxable;
|
|
|
|
dest->i_taxincluded = src->i_taxincluded;
|
|
|
|
dest->i_discount = src->i_discount;
|
|
|
|
dest->i_disc_type = src->i_disc_type;
|
|
|
|
dest->i_disc_how = src->i_disc_how;
|
|
|
|
|
|
|
|
/* vendor bill data */
|
|
|
|
dest->b_account = src->b_account;
|
|
|
|
dest->b_price = src->b_price;
|
|
|
|
dest->b_taxable = src->b_taxable;
|
|
|
|
dest->b_taxincluded = src->b_taxincluded;
|
2002-07-10 12:32:59 -05:00
|
|
|
dest->billable = src->billable;
|
|
|
|
dest->billto = src->billto;
|
2002-06-16 00:11:33 -05:00
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
if (src->i_tax_table)
|
|
|
|
gncEntrySetInvTaxTable (dest, src->i_tax_table);
|
|
|
|
|
|
|
|
if (src->b_tax_table)
|
|
|
|
gncEntrySetBillTaxTable (dest, src->b_tax_table);
|
2002-05-18 15:10:27 -05:00
|
|
|
|
|
|
|
if (src->order)
|
|
|
|
gncOrderAddEntry (src->order, dest);
|
|
|
|
|
|
|
|
if (src->invoice)
|
|
|
|
gncInvoiceAddEntry (src->invoice, dest);
|
2002-05-27 13:17:31 -05:00
|
|
|
|
2002-07-09 23:12:19 -05:00
|
|
|
if (src->bill)
|
|
|
|
gncBillAddEntry (src->bill, dest);
|
|
|
|
|
2002-05-27 13:17:31 -05:00
|
|
|
dest->values_dirty = TRUE;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncEntryCommitEdit (dest);
|
2002-05-18 15:10:27 -05:00
|
|
|
}
|
|
|
|
|
2003-10-21 08:53:55 -05:00
|
|
|
/* ================================================================ */
|
2001-11-21 19:23:07 -06:00
|
|
|
/* Get Functions */
|
|
|
|
|
|
|
|
Timespec gncEntryGetDate (GncEntry *entry)
|
|
|
|
{
|
|
|
|
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
|
|
|
if (!entry) return ts;
|
|
|
|
return entry->date;
|
|
|
|
}
|
|
|
|
|
2002-02-27 23:10:07 -06:00
|
|
|
Timespec gncEntryGetDateEntered (GncEntry *entry)
|
|
|
|
{
|
|
|
|
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
|
|
|
if (!entry) return ts;
|
|
|
|
return entry->date_entered;
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
const char * gncEntryGetDescription (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * gncEntryGetAction (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->action;
|
|
|
|
}
|
|
|
|
|
2002-06-16 23:04:05 -05:00
|
|
|
const char * gncEntryGetNotes (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->notes;
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
gnc_numeric gncEntryGetQuantity (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return gnc_numeric_zero();
|
|
|
|
return entry->quantity;
|
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* Customer Invoice */
|
|
|
|
|
|
|
|
Account * gncEntryGetInvAccount (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->i_account;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnc_numeric gncEntryGetInvPrice (GncEntry *entry)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return gnc_numeric_zero();
|
2002-09-14 00:32:37 -05:00
|
|
|
return entry->i_price;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
gnc_numeric gncEntryGetInvDiscount (GncEntry *entry)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return gnc_numeric_zero();
|
2002-09-14 00:32:37 -05:00
|
|
|
return entry->i_discount;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
GncAmountType gncEntryGetInvDiscountType (GncEntry *entry)
|
2002-07-11 10:11:33 -05:00
|
|
|
{
|
2002-09-14 00:32:37 -05:00
|
|
|
if (!entry) return 0;
|
|
|
|
return entry->i_disc_type;
|
2002-07-11 10:11:33 -05:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
GncDiscountHow gncEntryGetInvDiscountHow (GncEntry *entry)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2002-09-14 00:32:37 -05:00
|
|
|
if (!entry) return 0;
|
|
|
|
return entry->i_disc_how;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
char* qofEntryGetInvDiscType (GncEntry *entry)
|
|
|
|
{
|
|
|
|
char *type_string;
|
|
|
|
|
|
|
|
if (!entry) return 0;
|
|
|
|
type_string = g_strdup(gncAmountTypeToString(entry->i_disc_type));
|
|
|
|
return type_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* qofEntryGetInvDiscHow (GncEntry *entry)
|
|
|
|
{
|
|
|
|
char *type_string;
|
|
|
|
|
|
|
|
if (!entry) return 0;
|
|
|
|
type_string = g_strdup(gncEntryDiscountHowToString(entry->i_disc_how));
|
|
|
|
return type_string;
|
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
gboolean gncEntryGetInvTaxable (GncEntry *entry)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2002-09-14 00:32:37 -05:00
|
|
|
if (!entry) return FALSE;
|
|
|
|
return entry->i_taxable;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
gboolean gncEntryGetInvTaxIncluded (GncEntry *entry)
|
2002-07-09 23:12:19 -05:00
|
|
|
{
|
2002-09-14 00:32:37 -05:00
|
|
|
if (!entry) return FALSE;
|
|
|
|
return entry->i_taxincluded;
|
2002-07-09 23:12:19 -05:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
GncTaxTable * gncEntryGetInvTaxTable (GncEntry *entry)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
2002-09-14 00:32:37 -05:00
|
|
|
return entry->i_tax_table;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* vendor bills */
|
|
|
|
|
|
|
|
Account * gncEntryGetBillAccount (GncEntry *entry)
|
2001-11-23 23:35:08 -06:00
|
|
|
{
|
2002-09-14 00:32:37 -05:00
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->b_account;
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
gnc_numeric gncEntryGetBillPrice (GncEntry *entry)
|
2001-11-23 23:35:08 -06:00
|
|
|
{
|
2002-09-14 00:32:37 -05:00
|
|
|
if (!entry) return gnc_numeric_zero();
|
|
|
|
return entry->b_price;
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
gboolean gncEntryGetBillTaxable (GncEntry *entry)
|
2002-06-16 00:11:33 -05:00
|
|
|
{
|
|
|
|
if (!entry) return FALSE;
|
2002-09-14 00:32:37 -05:00
|
|
|
return entry->b_taxable;
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
gboolean gncEntryGetBillTaxIncluded (GncEntry *entry)
|
2002-06-16 00:11:33 -05:00
|
|
|
{
|
|
|
|
if (!entry) return FALSE;
|
2002-09-14 00:32:37 -05:00
|
|
|
return entry->b_taxincluded;
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
GncTaxTable * gncEntryGetBillTaxTable (GncEntry *entry)
|
2002-06-16 00:11:33 -05:00
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
2002-09-14 00:32:37 -05:00
|
|
|
return entry->b_tax_table;
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2002-07-10 12:32:59 -05:00
|
|
|
gboolean gncEntryGetBillable (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return FALSE;
|
|
|
|
return entry->billable;
|
|
|
|
}
|
|
|
|
|
|
|
|
GncOwner * gncEntryGetBillTo (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return &entry->billto;
|
|
|
|
}
|
|
|
|
|
2003-03-02 22:58:55 -06:00
|
|
|
GncEntryPaymentType gncEntryGetBillPayment (GncEntry* entry)
|
|
|
|
{
|
|
|
|
if (!entry) return 0;
|
|
|
|
return entry->b_payment;
|
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
GncInvoice * gncEntryGetInvoice (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->invoice;
|
|
|
|
}
|
|
|
|
|
|
|
|
GncInvoice * gncEntryGetBill (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->bill;
|
|
|
|
}
|
|
|
|
|
|
|
|
GncOrder * gncEntryGetOrder (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->order;
|
|
|
|
}
|
|
|
|
|
2003-10-21 08:53:55 -05:00
|
|
|
/* ================================================================ */
|
2002-06-16 00:11:33 -05:00
|
|
|
/*
|
|
|
|
* This is the logic of computing the total for an Entry, so you know
|
|
|
|
* what values to put into various Splits or to display in the ledger.
|
|
|
|
* In other words, we combine the quantity, unit-price, discount and
|
|
|
|
* taxes together, depending on various flags.
|
|
|
|
*
|
|
|
|
* There are four potental ways to combine these numbers:
|
|
|
|
* Discount: Pre-Tax Post-Tax
|
|
|
|
* Tax : Included Not-Included
|
|
|
|
*
|
|
|
|
* The process is relatively simple:
|
|
|
|
*
|
|
|
|
* 1) compute the agregate price (price*qty)
|
|
|
|
* 2) if taxincluded, then back-compute the agregate pre-tax price
|
|
|
|
* 3) apply discount and taxes in the appropriate order
|
|
|
|
* 4) return the requested results.
|
|
|
|
*
|
|
|
|
* step 2 can be done with agregate taxes; no need to compute them all
|
|
|
|
* unless the caller asked for the tax_value.
|
|
|
|
*
|
|
|
|
* Note that the returned "value" is such that value + tax == "total
|
|
|
|
* to pay," which means in the case of tax-included that the returned
|
|
|
|
* "value" may be less than the agregate price, even without a
|
|
|
|
* discount. If you want to display the tax-included value, you need
|
|
|
|
* to add the value and taxes together. In other words, the value is
|
|
|
|
* the amount the merchant gets; the taxes are the amount the gov't
|
|
|
|
* gets, and the customer pays the sum or value + taxes.
|
|
|
|
*
|
2006-07-16 21:04:59 -05:00
|
|
|
* The SCU is the denominator to convert the value.
|
|
|
|
*
|
2002-06-16 00:11:33 -05:00
|
|
|
* The discount return value is just for entertainment -- you may way
|
|
|
|
* to let a consumer know how much they saved.
|
|
|
|
*/
|
2002-01-20 20:27:02 -06:00
|
|
|
void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
|
2002-06-16 00:11:33 -05:00
|
|
|
GncTaxTable *tax_table, gboolean tax_included,
|
|
|
|
gnc_numeric discount, GncAmountType discount_type,
|
2006-07-16 21:04:59 -05:00
|
|
|
GncDiscountHow discount_how, int SCU,
|
2002-06-16 00:11:33 -05:00
|
|
|
gnc_numeric *value, gnc_numeric *discount_value,
|
|
|
|
GList **tax_value)
|
|
|
|
{
|
|
|
|
gnc_numeric aggregate;
|
|
|
|
gnc_numeric pretax;
|
|
|
|
gnc_numeric result;
|
|
|
|
gnc_numeric tax;
|
2002-01-21 16:59:44 -06:00
|
|
|
gnc_numeric percent = gnc_numeric_create (100, 1);
|
2002-06-16 00:11:33 -05:00
|
|
|
gnc_numeric tpercent = gnc_numeric_zero ();
|
|
|
|
gnc_numeric tvalue = gnc_numeric_zero ();
|
2002-01-12 22:25:55 -06:00
|
|
|
|
2002-06-16 00:11:33 -05:00
|
|
|
GList * entries = gncTaxTableGetEntries (tax_table);
|
|
|
|
GList * node;
|
2002-01-12 22:25:55 -06:00
|
|
|
|
2002-06-16 00:11:33 -05:00
|
|
|
/* Step 1: compute the aggregate price */
|
2002-01-12 22:25:55 -06:00
|
|
|
|
2002-06-16 00:11:33 -05:00
|
|
|
aggregate = gnc_numeric_mul (qty, price, GNC_DENOM_AUTO, GNC_DENOM_LCD);
|
|
|
|
|
|
|
|
/* Step 2: compute the pre-tax aggregate */
|
|
|
|
|
|
|
|
/* First, compute the aggregate tpercent and tvalue numbers */
|
|
|
|
for (node = entries; node; node = node->next) {
|
|
|
|
GncTaxTableEntry *entry = node->data;
|
|
|
|
gnc_numeric amount = gncTaxTableEntryGetAmount (entry);
|
|
|
|
|
|
|
|
switch (gncTaxTableEntryGetType (entry)) {
|
|
|
|
case GNC_AMT_TYPE_VALUE:
|
|
|
|
tvalue = gnc_numeric_add (tvalue, amount, GNC_DENOM_AUTO,
|
2002-05-27 13:17:31 -05:00
|
|
|
GNC_DENOM_LCD);
|
2002-06-16 00:11:33 -05:00
|
|
|
break;
|
|
|
|
case GNC_AMT_TYPE_PERCENT:
|
|
|
|
tpercent = gnc_numeric_add (tpercent, amount, GNC_DENOM_AUTO,
|
|
|
|
GNC_DENOM_LCD);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning ("Unknown tax type: %d", gncTaxTableEntryGetType (entry));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* now we need to convert from 5% -> .05 */
|
|
|
|
tpercent = gnc_numeric_div (tpercent, percent, GNC_DENOM_AUTO,
|
|
|
|
GNC_DENOM_LCD);
|
|
|
|
|
|
|
|
/* Next, actually compute the pre-tax aggregate value based on the
|
|
|
|
* taxincluded flag.
|
|
|
|
*/
|
|
|
|
if (tax_table && tax_included) {
|
|
|
|
/* Back-compute the pre-tax aggregate value.
|
|
|
|
* We know that aggregate = pretax + pretax*tpercent + tvalue, so
|
|
|
|
* pretax = (aggregate-tvalue)/(1+tpercent)
|
|
|
|
*/
|
|
|
|
pretax = gnc_numeric_sub (aggregate, tvalue, GNC_DENOM_AUTO,
|
|
|
|
GNC_DENOM_LCD);
|
|
|
|
pretax = gnc_numeric_div (pretax,
|
|
|
|
gnc_numeric_add (tpercent,
|
|
|
|
gnc_numeric_create (1, 1),
|
|
|
|
GNC_DENOM_AUTO, GNC_DENOM_LCD),
|
|
|
|
GNC_DENOM_AUTO, GNC_DENOM_LCD);
|
|
|
|
} else {
|
|
|
|
pretax = aggregate;
|
2002-01-21 16:59:44 -06:00
|
|
|
}
|
2002-01-12 22:25:55 -06:00
|
|
|
|
2002-06-16 00:11:33 -05:00
|
|
|
/* Step 3: apply discount and taxes in the appropriate order */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are two ways to apply discounts and taxes. In one way, you
|
|
|
|
* always compute the discount off the pretax number, and compute
|
|
|
|
* the taxes off of either the pretax value or "pretax-discount"
|
|
|
|
* value. In the other way, you always compute the tax on "pretax",
|
|
|
|
* and compute the discount on either "pretax" or "pretax+taxes".
|
|
|
|
*
|
|
|
|
* I don't know which is the "correct" way.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Type: discount tax
|
|
|
|
* PRETAX pretax pretax-discount
|
|
|
|
* SAMETIME pretax pretax
|
|
|
|
* POSTTAX pretax+tax pretax
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (discount_how) {
|
|
|
|
case GNC_DISC_PRETAX:
|
|
|
|
case GNC_DISC_SAMETIME:
|
|
|
|
/* compute the discount from pretax */
|
|
|
|
|
|
|
|
if (discount_type == GNC_AMT_TYPE_PERCENT) {
|
|
|
|
discount = gnc_numeric_div (discount, percent, GNC_DENOM_AUTO,
|
|
|
|
GNC_DENOM_LCD);
|
|
|
|
discount = gnc_numeric_mul (pretax, discount, GNC_DENOM_AUTO,
|
|
|
|
GNC_DENOM_LCD);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = gnc_numeric_sub (pretax, discount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
|
2002-01-12 22:25:55 -06:00
|
|
|
|
2002-06-16 00:11:33 -05:00
|
|
|
/* Figure out when to apply the tax, pretax or pretax-discount */
|
|
|
|
if (discount_how == GNC_DISC_PRETAX)
|
|
|
|
pretax = result;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GNC_DISC_POSTTAX:
|
|
|
|
/* compute discount on pretax+taxes */
|
|
|
|
|
|
|
|
if (discount_type == GNC_AMT_TYPE_PERCENT) {
|
|
|
|
gnc_numeric after_tax;
|
|
|
|
|
|
|
|
tax = gnc_numeric_mul (pretax, tpercent, GNC_DENOM_AUTO, GNC_DENOM_LCD);
|
|
|
|
after_tax = gnc_numeric_add (pretax, tax, GNC_DENOM_AUTO, GNC_DENOM_LCD);
|
|
|
|
after_tax = gnc_numeric_add (after_tax, tvalue, GNC_DENOM_AUTO,
|
|
|
|
GNC_DENOM_LCD);
|
|
|
|
discount = gnc_numeric_div (discount, percent, GNC_DENOM_AUTO,
|
|
|
|
GNC_DENOM_LCD);
|
|
|
|
discount = gnc_numeric_mul (after_tax, discount, GNC_DENOM_AUTO,
|
|
|
|
GNC_DENOM_LCD);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = gnc_numeric_sub (pretax, discount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_warning ("unknown DiscountHow value: %d", discount_how);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Step 4: return the requested results. */
|
|
|
|
|
|
|
|
/* result == amount merchant gets
|
|
|
|
* discount == amount of discount
|
|
|
|
* need to compute taxes (based on 'pretax') if the caller wants it.
|
|
|
|
*/
|
2002-05-24 16:19:45 -05:00
|
|
|
|
2006-07-16 21:04:59 -05:00
|
|
|
if (discount_value != NULL) {
|
|
|
|
if (SCU) discount = gnc_numeric_convert(discount, SCU, GNC_RND_ROUND);
|
2002-05-24 16:19:45 -05:00
|
|
|
*discount_value = discount;
|
2006-07-16 21:04:59 -05:00
|
|
|
}
|
2002-05-24 16:19:45 -05:00
|
|
|
|
2006-07-16 21:04:59 -05:00
|
|
|
if (value != NULL) {
|
|
|
|
if (SCU) result = gnc_numeric_convert(result, SCU, GNC_RND_ROUND);
|
2002-06-16 00:11:33 -05:00
|
|
|
*value = result;
|
2006-07-16 21:04:59 -05:00
|
|
|
}
|
2002-01-12 22:25:55 -06:00
|
|
|
|
2002-06-16 00:11:33 -05:00
|
|
|
/* Now... Compute the list of tax values (if the caller wants it) */
|
2002-01-12 22:25:55 -06:00
|
|
|
|
|
|
|
if (tax_value != NULL) {
|
2002-06-16 00:11:33 -05:00
|
|
|
GList * taxes = NULL;
|
|
|
|
|
|
|
|
for (node = entries; node; node = node->next) {
|
|
|
|
GncTaxTableEntry *entry = node->data;
|
|
|
|
Account *acc = gncTaxTableEntryGetAccount (entry);
|
|
|
|
gnc_numeric amount = gncTaxTableEntryGetAmount (entry);
|
|
|
|
|
|
|
|
g_return_if_fail (acc);
|
|
|
|
|
|
|
|
switch (gncTaxTableEntryGetType (entry)) {
|
|
|
|
case GNC_AMT_TYPE_VALUE:
|
2006-07-16 21:04:59 -05:00
|
|
|
if (SCU) amount = gnc_numeric_convert(amount, SCU, GNC_RND_ROUND);
|
2002-06-16 00:11:33 -05:00
|
|
|
taxes = gncAccountValueAdd (taxes, acc, amount);
|
|
|
|
break;
|
|
|
|
case GNC_AMT_TYPE_PERCENT:
|
|
|
|
amount = gnc_numeric_div (amount, percent, GNC_DENOM_AUTO,
|
|
|
|
GNC_DENOM_LCD);
|
|
|
|
tax = gnc_numeric_mul (pretax, amount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
|
2006-07-16 21:04:59 -05:00
|
|
|
if (SCU) tax = gnc_numeric_convert(tax, SCU, GNC_RND_ROUND);
|
2002-06-16 00:11:33 -05:00
|
|
|
taxes = gncAccountValueAdd (taxes, acc, tax);
|
|
|
|
break;
|
|
|
|
default:
|
2002-11-17 23:05:48 -06:00
|
|
|
break;
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
2002-01-21 16:59:44 -06:00
|
|
|
}
|
2002-06-16 00:11:33 -05:00
|
|
|
*tax_value = taxes;
|
2002-01-12 22:25:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-05-27 13:17:31 -05:00
|
|
|
static int
|
2006-01-03 11:13:10 -06:00
|
|
|
get_entry_commodity_denom (GncEntry *entry)
|
2002-05-27 13:17:31 -05:00
|
|
|
{
|
2002-07-09 23:12:19 -05:00
|
|
|
gnc_commodity *c;
|
2002-05-27 13:17:31 -05:00
|
|
|
if (!entry)
|
|
|
|
return 0;
|
|
|
|
if (entry->invoice) {
|
2003-01-12 16:07:33 -06:00
|
|
|
c = gncInvoiceGetCurrency (entry->invoice);
|
2002-07-09 23:12:19 -05:00
|
|
|
if (c)
|
|
|
|
return (gnc_commodity_get_fraction (c));
|
|
|
|
}
|
|
|
|
if (entry->bill) {
|
2003-01-12 16:07:33 -06:00
|
|
|
c = gncInvoiceGetCurrency (entry->bill);
|
2002-05-27 13:17:31 -05:00
|
|
|
if (c)
|
|
|
|
return (gnc_commodity_get_fraction (c));
|
|
|
|
}
|
|
|
|
return 100000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gncEntryRecomputeValues (GncEntry *entry)
|
|
|
|
{
|
|
|
|
int denom;
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* See if either tax table changed since we last computed values */
|
|
|
|
if (entry->i_tax_table) {
|
|
|
|
Timespec modtime = gncTaxTableLastModified (entry->i_tax_table);
|
|
|
|
if (timespec_cmp (&entry->i_taxtable_modtime, &modtime)) {
|
2002-06-16 00:11:33 -05:00
|
|
|
entry->values_dirty = TRUE;
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_taxtable_modtime = modtime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (entry->b_tax_table) {
|
|
|
|
Timespec modtime = gncTaxTableLastModified (entry->b_tax_table);
|
|
|
|
if (timespec_cmp (&entry->b_taxtable_modtime, &modtime)) {
|
|
|
|
entry->values_dirty = TRUE;
|
|
|
|
entry->b_taxtable_modtime = modtime;
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-27 13:17:31 -05:00
|
|
|
if (!entry->values_dirty)
|
|
|
|
return;
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* Clear the last-computed tax values */
|
|
|
|
if (entry->i_tax_values) {
|
|
|
|
gncAccountValueDestroy (entry->i_tax_values);
|
|
|
|
entry->i_tax_values = NULL;
|
|
|
|
}
|
|
|
|
if (entry->b_tax_values) {
|
|
|
|
gncAccountValueDestroy (entry->b_tax_values);
|
|
|
|
entry->b_tax_values = NULL;
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
|
|
|
|
2006-07-16 21:04:59 -05:00
|
|
|
/* Determine the commodity denominator */
|
|
|
|
denom = get_entry_commodity_denom (entry);
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
/* Compute the invoice values */
|
|
|
|
gncEntryComputeValue (entry->quantity, entry->i_price,
|
|
|
|
(entry->i_taxable ? entry->i_tax_table : NULL),
|
|
|
|
entry->i_taxincluded,
|
|
|
|
entry->i_discount, entry->i_disc_type,
|
|
|
|
entry->i_disc_how,
|
2006-07-16 21:04:59 -05:00
|
|
|
denom,
|
2002-09-14 00:32:37 -05:00
|
|
|
&(entry->i_value), &(entry->i_disc_value),
|
|
|
|
&(entry->i_tax_values));
|
|
|
|
|
|
|
|
/* Compute the bill values */
|
|
|
|
gncEntryComputeValue (entry->quantity, entry->b_price,
|
|
|
|
(entry->b_taxable ? entry->b_tax_table : NULL),
|
|
|
|
entry->b_taxincluded,
|
|
|
|
gnc_numeric_zero(), GNC_AMT_TYPE_VALUE, GNC_DISC_PRETAX,
|
2006-07-16 21:04:59 -05:00
|
|
|
denom,
|
2002-09-14 00:32:37 -05:00
|
|
|
&(entry->b_value), NULL, &(entry->b_tax_values));
|
2002-05-27 13:17:31 -05:00
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
entry->i_value_rounded = gnc_numeric_convert (entry->i_value, denom,
|
|
|
|
GNC_RND_ROUND);
|
|
|
|
entry->i_disc_value_rounded = gnc_numeric_convert (entry->i_disc_value, denom,
|
|
|
|
GNC_RND_ROUND);
|
|
|
|
entry->i_tax_value = gncAccountValueTotal (entry->i_tax_values);
|
|
|
|
entry->i_tax_value_rounded = gnc_numeric_convert (entry->i_tax_value, denom,
|
|
|
|
GNC_RND_ROUND);
|
|
|
|
|
|
|
|
entry->b_value_rounded = gnc_numeric_convert (entry->b_value, denom,
|
|
|
|
GNC_RND_ROUND);
|
|
|
|
entry->b_tax_value = gncAccountValueTotal (entry->b_tax_values);
|
|
|
|
entry->b_tax_value_rounded = gnc_numeric_convert (entry->b_tax_value, denom,
|
|
|
|
GNC_RND_ROUND);
|
2002-05-27 13:17:31 -05:00
|
|
|
entry->values_dirty = FALSE;
|
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
void gncEntryGetValue (GncEntry *entry, gboolean is_inv, gnc_numeric *value,
|
2002-06-16 00:11:33 -05:00
|
|
|
gnc_numeric *discount_value, gnc_numeric *tax_value,
|
|
|
|
GList **tax_values)
|
2002-01-20 20:27:02 -06:00
|
|
|
{
|
|
|
|
if (!entry) return;
|
2002-05-27 13:17:31 -05:00
|
|
|
gncEntryRecomputeValues (entry);
|
|
|
|
if (value)
|
2002-09-14 00:32:37 -05:00
|
|
|
*value = (is_inv ? entry->i_value : entry->b_value);
|
2002-05-27 13:17:31 -05:00
|
|
|
if (discount_value)
|
2002-09-14 00:32:37 -05:00
|
|
|
*discount_value = (is_inv ? entry->i_disc_value : gnc_numeric_zero());
|
2002-06-16 00:11:33 -05:00
|
|
|
if (tax_value)
|
2002-09-14 00:32:37 -05:00
|
|
|
*tax_value = (is_inv ? entry->i_tax_value : entry->b_tax_value);
|
2002-06-16 00:11:33 -05:00
|
|
|
if (tax_values)
|
2002-09-14 00:32:37 -05:00
|
|
|
*tax_values = (is_inv ? entry->i_tax_values : entry->b_tax_values);
|
2002-01-20 20:27:02 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
gnc_numeric gncEntryReturnValue (GncEntry *entry, gboolean is_inv)
|
2002-02-24 23:02:21 -06:00
|
|
|
{
|
2002-05-27 13:17:31 -05:00
|
|
|
if (!entry) return gnc_numeric_zero();
|
|
|
|
gncEntryRecomputeValues (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
return (is_inv ? entry->i_value_rounded : entry->b_value_rounded);
|
2002-02-24 23:02:21 -06:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
gnc_numeric gncEntryReturnTaxValue (GncEntry *entry, gboolean is_inv)
|
2002-02-24 23:02:21 -06:00
|
|
|
{
|
2002-05-27 13:17:31 -05:00
|
|
|
if (!entry) return gnc_numeric_zero();
|
|
|
|
gncEntryRecomputeValues (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
return (is_inv ? entry->i_tax_value_rounded : entry->b_tax_value_rounded);
|
2002-05-24 16:19:45 -05:00
|
|
|
}
|
|
|
|
|
2006-10-15 14:02:05 -05:00
|
|
|
AccountValueList * gncEntryReturnTaxValues (GncEntry *entry, gboolean is_inv)
|
2002-06-16 00:11:33 -05:00
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
gncEntryRecomputeValues (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
return (is_inv ? entry->i_tax_values : entry->b_tax_values);
|
2002-06-16 00:11:33 -05:00
|
|
|
}
|
|
|
|
|
2002-09-14 00:32:37 -05:00
|
|
|
gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv)
|
2002-05-24 16:19:45 -05:00
|
|
|
{
|
2002-05-27 13:17:31 -05:00
|
|
|
if (!entry) return gnc_numeric_zero();
|
|
|
|
gncEntryRecomputeValues (entry);
|
2002-09-14 00:32:37 -05:00
|
|
|
return (is_inv ? entry->i_disc_value_rounded : gnc_numeric_zero());
|
2002-02-24 23:02:21 -06:00
|
|
|
}
|
|
|
|
|
2003-10-14 16:20:55 -05:00
|
|
|
/* XXXX this exsitnace of this routine is just wrong */
|
2002-11-03 14:21:42 -06:00
|
|
|
gboolean gncEntryIsOpen (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return FALSE;
|
2003-10-14 16:20:55 -05:00
|
|
|
return (entry->inst.editlevel > 0);
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
|
|
|
|
2003-10-21 08:53:55 -05:00
|
|
|
/* ================================================================ */
|
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
void gncEntryBeginEdit (GncEntry *entry)
|
|
|
|
{
|
2004-06-13 11:48:32 -05:00
|
|
|
QOF_BEGIN_EDIT (&entry->inst);
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
|
|
|
|
2003-10-14 16:20:55 -05:00
|
|
|
static inline void gncEntryOnError (QofInstance *entry, QofBackendError errcode)
|
2002-11-03 14:21:42 -06:00
|
|
|
{
|
2003-06-26 22:36:02 -05:00
|
|
|
PERR("Entry QofBackend Failure: %d", errcode);
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
|
|
|
|
2003-10-16 23:32:04 -05:00
|
|
|
static inline void gncEntryOnDone (QofInstance *inst) {}
|
|
|
|
|
2003-10-14 16:20:55 -05:00
|
|
|
static inline void entry_free (QofInstance *inst)
|
|
|
|
{
|
|
|
|
GncEntry *entry = (GncEntry *)inst;
|
|
|
|
gncEntryFree (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
void gncEntryCommitEdit (GncEntry *entry)
|
|
|
|
{
|
2006-04-21 23:42:29 -05:00
|
|
|
if (!qof_commit_edit (QOF_INSTANCE(entry))) return;
|
2006-02-26 12:36:05 -06:00
|
|
|
qof_commit_edit_part2 (&entry->inst, gncEntryOnError,
|
2003-10-14 16:20:55 -05:00
|
|
|
gncEntryOnDone, entry_free);
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
|
|
|
|
2002-02-03 14:01:08 -06:00
|
|
|
int gncEntryCompare (GncEntry *a, GncEntry *b)
|
|
|
|
{
|
|
|
|
int compare;
|
|
|
|
|
|
|
|
if (a == b) return 0;
|
|
|
|
if (!a && b) return -1;
|
|
|
|
if (a && !b) return 1;
|
|
|
|
|
|
|
|
compare = timespec_cmp (&(a->date), &(b->date));
|
2002-02-27 23:10:07 -06:00
|
|
|
if (compare) return compare;
|
|
|
|
|
|
|
|
compare = timespec_cmp (&(a->date_entered), &(b->date_entered));
|
|
|
|
if (compare) return compare;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
|
|
|
compare = safe_strcmp (a->desc, b->desc);
|
2002-02-27 23:10:07 -06:00
|
|
|
if (compare) return compare;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
|
|
|
compare = safe_strcmp (a->action, b->action);
|
2002-02-27 23:10:07 -06:00
|
|
|
if (compare) return compare;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
2003-10-14 16:20:55 -05:00
|
|
|
return guid_compare (&(a->inst.entity.guid), &(b->inst.entity.guid));
|
2002-02-03 14:01:08 -06:00
|
|
|
}
|
|
|
|
|
2003-10-19 00:13:59 -05:00
|
|
|
/* ============================================================= */
|
|
|
|
/* Object declaration */
|
2001-11-24 23:34:34 -06:00
|
|
|
|
2003-10-19 00:13:59 -05:00
|
|
|
static QofObject gncEntryDesc =
|
2002-02-24 16:12:24 -06:00
|
|
|
{
|
2003-10-19 00:13:59 -05:00
|
|
|
interface_version: QOF_OBJECT_VERSION,
|
|
|
|
e_type: _GNC_MOD_NAME,
|
|
|
|
type_label: "Order/Invoice/Bill Entry",
|
2004-08-19 14:47:34 -05:00
|
|
|
create: (gpointer)gncEntryCreate,
|
2003-10-19 00:13:59 -05:00
|
|
|
book_begin: NULL,
|
|
|
|
book_end: NULL,
|
|
|
|
is_dirty: qof_collection_is_dirty,
|
|
|
|
mark_clean: qof_collection_mark_clean,
|
|
|
|
foreach: qof_collection_foreach,
|
|
|
|
printable: NULL,
|
2004-06-12 15:27:08 -05:00
|
|
|
version_cmp: (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
|
2001-11-21 19:23:07 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
gboolean gncEntryRegister (void)
|
|
|
|
{
|
2003-09-27 05:21:27 -05:00
|
|
|
static QofParam params[] = {
|
2004-07-26 07:41:43 -05:00
|
|
|
{ ENTRY_DATE, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDate, (QofSetterFunc)gncEntrySetDate },
|
|
|
|
{ ENTRY_DATE_ENTERED, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDateEntered, (QofSetterFunc)gncEntrySetDateEntered },
|
|
|
|
{ ENTRY_DESC, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetDescription, (QofSetterFunc)gncEntrySetDescription },
|
|
|
|
{ ENTRY_ACTION, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetAction, (QofSetterFunc)gncEntrySetAction },
|
|
|
|
{ ENTRY_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetNotes, (QofSetterFunc)gncEntrySetNotes },
|
|
|
|
{ ENTRY_QTY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetQuantity, (QofSetterFunc)gncEntrySetQuantity },
|
|
|
|
{ ENTRY_IPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetInvPrice, (QofSetterFunc)gncEntrySetInvPrice },
|
|
|
|
{ ENTRY_BPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetBillPrice, (QofSetterFunc)gncEntrySetBillPrice },
|
2003-10-19 00:13:59 -05:00
|
|
|
{ ENTRY_INVOICE, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetInvoice, NULL },
|
2005-11-01 21:32:36 -06:00
|
|
|
{ ENTRY_IACCT, GNC_ID_ACCOUNT, (QofAccessFunc)gncEntryGetInvAccount, (QofSetterFunc)gncEntrySetInvAccount },
|
|
|
|
{ ENTRY_BACCT, GNC_ID_ACCOUNT, (QofAccessFunc)gncEntryGetBillAccount, (QofSetterFunc)gncEntrySetBillAccount },
|
2003-10-19 00:13:59 -05:00
|
|
|
{ ENTRY_BILL, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetBill, NULL },
|
2005-11-01 21:32:36 -06:00
|
|
|
{ ENTRY_INV_DISC_TYPE, QOF_TYPE_STRING, (QofAccessFunc)qofEntryGetInvDiscType,
|
|
|
|
(QofSetterFunc)qofEntrySetInvDiscType },
|
|
|
|
{ ENTRY_INV_DISC_HOW, QOF_TYPE_STRING, (QofAccessFunc)qofEntryGetInvDiscHow,
|
|
|
|
(QofSetterFunc)qofEntrySetInvDiscHow },
|
|
|
|
{ ENTRY_INV_TAXABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxable,
|
|
|
|
(QofSetterFunc)gncEntrySetInvTaxable },
|
|
|
|
{ ENTRY_INV_TAX_INC, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxIncluded,
|
|
|
|
(QofSetterFunc)gncEntrySetInvTaxIncluded },
|
|
|
|
{ ENTRY_BILL_TAXABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxable,
|
|
|
|
(QofSetterFunc)gncEntrySetInvTaxable },
|
|
|
|
{ ENTRY_BILL_TAX_INC, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillTaxIncluded,
|
|
|
|
(QofSetterFunc)gncEntrySetBillTaxIncluded },
|
2004-07-26 07:41:43 -05:00
|
|
|
{ ENTRY_BILLABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillable, (QofSetterFunc)gncEntrySetBillable },
|
|
|
|
{ ENTRY_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncEntryGetBillTo, (QofSetterFunc)gncEntrySetBillTo },
|
2003-10-19 00:13:59 -05:00
|
|
|
{ ENTRY_ORDER, GNC_ID_ORDER, (QofAccessFunc)gncEntryGetOrder, NULL },
|
2004-05-23 12:31:40 -05:00
|
|
|
{ QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
|
|
|
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
2002-02-03 14:01:08 -06:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2003-09-27 11:33:06 -05:00
|
|
|
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEntryCompare, params);
|
2002-02-03 14:01:08 -06:00
|
|
|
|
2003-06-26 22:09:39 -05:00
|
|
|
return qof_object_register (&gncEntryDesc);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|