From ece859705de339ab483b23895b8f4d76ba0cef2b Mon Sep 17 00:00:00 2001 From: sdementen Date: Sat, 18 Feb 2017 16:38:46 +0100 Subject: [PATCH 1/4] add gnc_get_current_session to swig interface --- src/app-utils/app-utils.i | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app-utils/app-utils.i b/src/app-utils/app-utils.i index a27c15f974..434b8305f9 100644 --- a/src/app-utils/app-utils.i +++ b/src/app-utils/app-utils.i @@ -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); From 78c5203d8c683adfddf7212b7f3b676b644efc6b Mon Sep 17 00:00:00 2001 From: hcrohland Date: Fri, 3 Feb 2017 08:44:08 +0100 Subject: [PATCH 2/4] 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)) From 3445ef8845315dbe06b4f9a9296fd0b7181bd4f9 Mon Sep 17 00:00:00 2001 From: hcrohland Date: Wed, 1 Mar 2017 18:22:02 +0100 Subject: [PATCH 3/4] 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?)) From de360cabb33395c2dd668b08b7b8c12dd6e33b80 Mon Sep 17 00:00:00 2001 From: hcrohland Date: Thu, 2 Mar 2017 20:53:40 +0100 Subject: [PATCH 4/4] Revert the taxinvoice.scm changes Since they touch strings and user behavior they cannot go into maint. The pull request now only includes the backend change. By that you can easily tweak the invoice reports to show the net price. --- src/report/business-reports/taxinvoice.eguile.scm | 2 +- src/report/business-reports/taxinvoice.scm | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/report/business-reports/taxinvoice.eguile.scm b/src/report/business-reports/taxinvoice.eguile.scm index e5fa8eadb4..74aa6843d6 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 (gncEntryGetPrice entry #t opt-netprice)) + (each (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 59e6cb74f4..16a925ef7b 100644 --- a/src/report/business-reports/taxinvoice.scm +++ b/src/report/business-reports/taxinvoice.scm @@ -108,7 +108,6 @@ (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")) @@ -177,7 +176,6 @@ (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" @@ -290,7 +288,6 @@ (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))