From 78c5203d8c683adfddf7212b7f3b676b644efc6b Mon Sep 17 00:00:00 2001 From: hcrohland Date: Fri, 3 Feb 2017 08:44:08 +0100 Subject: [PATCH] Enable taxinvoice to show net price Add gncEntryGetNetPrice Create an option in taxinvoice to either use gncEntryGetNetPrice or gncEntryGetPrice So far taxinvoice would show net or gross prices dependent on the internal flag tax_included. This is inconsistent for the reader of the invoice since there is no notion of that flag. This patch adds the option to always show net prices. It does not change the default behaviour even if I would consider it broken. --- src/engine/gncEntry.c | 56 +++++++++++++++++-- src/engine/gncEntry.h | 1 + .../business-reports/taxinvoice.eguile.scm | 2 +- src/report/business-reports/taxinvoice.scm | 3 + 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/engine/gncEntry.c b/src/engine/gncEntry.c index 72458290ed..5539aaab8d 100644 --- a/src/engine/gncEntry.c +++ b/src/engine/gncEntry.c @@ -1071,12 +1071,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, - 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) +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, gnc_numeric *net_price) { gnc_numeric aggregate; gnc_numeric pretax; @@ -1085,6 +1085,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; @@ -1136,6 +1137,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 { @@ -1260,9 +1265,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) { @@ -1401,6 +1423,28 @@ 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 result = gnc_numeric_zero(); + if (entry) + { + int denom; + + /* 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); + } + 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); diff --git a/src/engine/gncEntry.h b/src/engine/gncEntry.h index d0d121e921..1be0d64669 100644 --- a/src/engine/gncEntry.h +++ b/src/engine/gncEntry.h @@ -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 gncEntryGetInvNetPrice (const GncEntry *entry); 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 74aa6843d6..8a985cf1fe 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 (gncEntryGetInvPrice entry)) + (each (if opt-netprice (gncEntryGetInvNetPrice entry) (gncEntryGetInvPrice entry))) (action (gncEntryGetAction entry)) (rval (gncEntryGetDocValue entry #t #t credit-note?)) (rdiscval (gncEntryGetDocDiscountValue entry #t #t credit-note?)) diff --git a/src/report/business-reports/taxinvoice.scm b/src/report/business-reports/taxinvoice.scm index 16a925ef7b..59e6cb74f4 100644 --- a/src/report/business-reports/taxinvoice.scm +++ b/src/report/business-reports/taxinvoice.scm @@ -108,6 +108,7 @@ (define optname-jobnumber-text (N_ "Job Number text")) (define optname-jobname-show (N_ "Show Job name")) (define optname-jobnumber-show (N_ "Show Job number")) +(define optname-netprice (N_ "Show net price")) (define optname-invnum-next-to-title (N_ "Invoice number next to title")) (define optname-border-collapse (N_ "table-border-collapse")) (define optname-border-color-th (N_ "table-header-border-color")) @@ -176,6 +177,7 @@ (add-option (gnc:make-simple-boolean-option elementspage optname-invnum-next-to-title "h" (N_ "Invoice Number next to title?") #f)) (add-option (gnc:make-simple-boolean-option elementspage optname-jobname-show "i" (N_ "Display Job name?") #t)) (add-option (gnc:make-simple-boolean-option elementspage optname-jobnumber-show "j" (N_ "Invoice Job number?") #f)) +(add-option (gnc:make-simple-boolean-option elementspage optname-netprice "k" (N_ "Show net price?") #f)) ;; Display options (add-option (gnc:make-string-option displaypage optname-template-file "a" @@ -288,6 +290,7 @@ (opt-invnum-next-to-title (opt-value elementspage optname-invnum-next-to-title)) (opt-jobname-show (opt-value elementspage optname-jobname-show)) (opt-jobnumber-show (opt-value elementspage optname-jobnumber-show)) + (opt-netprice (opt-value elementspage optname-netprice)) (opt-report-currency (opt-value gnc:pagename-general optname-report-currency)) (opt-css-border-collapse (if (opt-value displaypage optname-border-collapse) "border-collapse:collapse;")) (opt-css-border-color-th (opt-value displaypage optname-border-color-th))