From 3445ef8845315dbe06b4f9a9296fd0b7181bd4f9 Mon Sep 17 00:00:00 2001 From: hcrohland Date: Wed, 1 Mar 2017 18:22:02 +0100 Subject: [PATCH] Make the net price option better compatible with master Create one gncEntryGetPrice function which can create given price or net price for both invoices and bills based on option parameters. The master version of taxinvoice.eguile.scm needs this for bills too. --- src/engine/gncEntry.c | 41 +++++++++++-------- src/engine/gncEntry.h | 2 +- .../business-reports/taxinvoice.eguile.scm | 2 +- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/engine/gncEntry.c b/src/engine/gncEntry.c index 5539aaab8d..f63fd3418a 100644 --- a/src/engine/gncEntry.c +++ b/src/engine/gncEntry.c @@ -1423,25 +1423,34 @@ static gnc_numeric gncEntryGetIntDiscountValue (GncEntry *entry, gboolean round, return (is_cust_doc ? entry->i_disc_value : gnc_numeric_zero()); } -gnc_numeric gncEntryGetInvNetPrice (const GncEntry *entry) +gnc_numeric gncEntryGetPrice (const GncEntry *entry, gboolean cust_doc, gboolean net) { - gnc_numeric result = gnc_numeric_zero(); - if (entry) - { - int denom; + 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); + /* Determine the commodity denominator */ + denom = get_entry_commodity_denom (entry); - /* Compute the invoice values */ - 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); - } + /* 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; } diff --git a/src/engine/gncEntry.h b/src/engine/gncEntry.h index 1be0d64669..8440396732 100644 --- a/src/engine/gncEntry.h +++ b/src/engine/gncEntry.h @@ -182,7 +182,7 @@ gnc_numeric gncEntryGetDocQuantity (const GncEntry *entry, gboolean is_cn); @{ */ Account * gncEntryGetInvAccount (const GncEntry *entry); gnc_numeric gncEntryGetInvPrice (const GncEntry *entry); -gnc_numeric gncEntryGetInvNetPrice (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); diff --git a/src/report/business-reports/taxinvoice.eguile.scm b/src/report/business-reports/taxinvoice.eguile.scm index 8a985cf1fe..e5fa8eadb4 100644 --- a/src/report/business-reports/taxinvoice.eguile.scm +++ b/src/report/business-reports/taxinvoice.eguile.scm @@ -311,7 +311,7 @@ (inv-total (gnc:make-commodity-collector))) (for entry in entries do (let ((qty (gncEntryGetDocQuantity entry credit-note?)) - (each (if opt-netprice (gncEntryGetInvNetPrice entry) (gncEntryGetInvPrice entry))) + (each (gncEntryGetPrice entry #t opt-netprice)) (action (gncEntryGetAction entry)) (rval (gncEntryGetDocValue entry #t #t credit-note?)) (rdiscval (gncEntryGetDocDiscountValue entry #t #t credit-note?))