Merge branch 'maint'

This commit is contained in:
Geert Janssens 2017-03-04 10:28:31 +01:00
commit be260a4305
3 changed files with 61 additions and 6 deletions

View File

@ -66,6 +66,7 @@ typedef int GNCOptionDBHandle;
void gnc_prefs_init();
QofBook * gnc_get_current_book (void);
QofSession * gnc_get_current_session (void);
const gchar * gnc_get_current_book_tax_name (void);
const gchar * gnc_get_current_book_tax_type (void);
Account * gnc_get_current_root_account (void);

View File

@ -1099,12 +1099,12 @@ GncOrder * gncEntryGetOrder (const GncEntry *entry)
* The discount return value is just for entertainment -- you may want
* to let a consumer know how much they saved.
*/
void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
static void gncEntryComputeValueInt (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_value)
GList **tax_value, gnc_numeric *net_price)
{
gnc_numeric aggregate;
gnc_numeric pretax;
@ -1113,6 +1113,7 @@ void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
gnc_numeric percent = gnc_numeric_create (100, 1);
gnc_numeric tpercent = gnc_numeric_zero ();
gnc_numeric tvalue = gnc_numeric_zero ();
gnc_numeric i_net_price = price;
GList * entries = gncTaxTableGetEntries (tax_table);
GList * node;
@ -1164,6 +1165,10 @@ void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
gnc_numeric_create (1, 1),
GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD),
GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
if (!gnc_numeric_zero_p(qty))
{
i_net_price = gnc_numeric_div (pretax, qty, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
}
}
else
{
@ -1288,9 +1293,26 @@ void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
*tax_value = taxes;
}
if (net_price != NULL)
{
if (SCU) i_net_price = gnc_numeric_convert(i_net_price, SCU, GNC_HOW_RND_ROUND_HALF_UP);
*net_price = i_net_price;
}
return;
}
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_value)
{
gncEntryComputeValueInt (qty, price, tax_table, tax_included, discount, discount_type,
discount_how, SCU, value, discount_value, tax_value, NULL);
}
static int
get_entry_commodity_denom (const GncEntry *entry)
{
@ -1429,6 +1451,37 @@ static gnc_numeric gncEntryGetIntDiscountValue (GncEntry *entry, gboolean round,
return (is_cust_doc ? entry->i_disc_value : gnc_numeric_zero());
}
gnc_numeric gncEntryGetPrice (const GncEntry *entry, gboolean cust_doc, gboolean net)
{
gnc_numeric result;
int denom;
if (!entry) return gnc_numeric_zero();
if (!net) return (cust_doc ? entry->i_price : entry->b_price);
/* Determine the commodity denominator */
denom = get_entry_commodity_denom (entry);
/* Compute the net price */
if (cust_doc)
gncEntryComputeValueInt (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,
denom,
NULL, NULL, NULL, &result);
else
gncEntryComputeValueInt (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,
denom,
NULL, NULL, NULL, &result);
return result;
}
gnc_numeric gncEntryGetDocValue (GncEntry *entry, gboolean round, gboolean is_cust_doc, gboolean is_cn)
{
gnc_numeric value = gncEntryGetIntValue (entry, round, is_cust_doc);

View File

@ -182,6 +182,7 @@ gnc_numeric gncEntryGetDocQuantity (const GncEntry *entry, gboolean is_cn);
@{ */
Account * gncEntryGetInvAccount (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);