r21992 - gnucash/trunk/src - Make invoice totals always document values. These functions are only

Geert Janssens gjanssens at code.gnucash.org
Fri Feb 10 10:33:35 EST 2012


Author: gjanssens
Date: 2012-02-10 10:33:34 -0500 (Fri, 10 Feb 2012)
New Revision: 21992
Trac: http://svn.gnucash.org/trac/changeset/21992

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/engine/gncInvoice.c
   gnucash/trunk/src/engine/gncInvoice.h
Log:
Make invoice totals always document values. These functions are only
used for displaying.

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2012-02-10 15:33:25 UTC (rev 21991)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2012-02-10 15:33:34 UTC (rev 21992)
@@ -684,22 +684,6 @@
     is_cust_doc = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
     is_cn = gncInvoiceGetIsCreditNote (invoice);
 
-//    /* Make sure that the invoice/credit note has a positive balance */
-//    if (gnc_numeric_negative_p(gncInvoiceGetTotal(invoice)))
-//    {
-//        gnc_error_dialog(iw_get_window(iw), "%s",
-//                         _("You may not post an invoice with a negative total value."));
-//        return;
-//    }
-
-//    if (iw->total_cash_label &&
-//            gnc_numeric_negative_p(gncInvoiceGetTotalOf(invoice, GNC_PAYMENT_CASH)))
-//    {
-//        gnc_error_dialog(iw_get_window(iw), "%s",
-//                         _("You may not post an expense voucher with a negative total cash value."));
-//        return;
-//    }
-
     /* Ok, we can post this invoice.  Ask for verification, set the due date,
      * post date, and posted account
      */
@@ -1482,33 +1466,18 @@
     if (iw->total_label)
     {
         amount = gncInvoiceGetTotal (invoice);
-        /* Credit notes have their value signs reversed internally.
-         * So reverse here as well before displaying
-         */
-        if (iw->is_credit_note)
-            amount = gnc_numeric_neg (amount);
         gnc_invoice_reset_total_label (GTK_LABEL (iw->total_label), amount, currency);
     }
 
     if (iw->total_subtotal_label)
     {
         amount = gncInvoiceGetTotalSubtotal (invoice);
-        /* Credit notes have their value signs reversed internally.
-         * So reverse here as well before displaying
-         */
-        if (iw->is_credit_note)
-            amount = gnc_numeric_neg (amount);
         gnc_invoice_reset_total_label (GTK_LABEL (iw->total_subtotal_label), amount, currency);
     }
 
     if (iw->total_tax_label)
     {
         amount = gncInvoiceGetTotalTax (invoice);
-        /* Credit notes have their value signs reversed internally.
-         * So reverse here as well before displaying
-         */
-        if (iw->is_credit_note)
-            amount = gnc_numeric_neg (amount);
         gnc_invoice_reset_total_label (GTK_LABEL (iw->total_tax_label), amount, currency);
     }
 
@@ -1518,21 +1487,11 @@
     {
         gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (iw->to_charge_edit));
         to_charge_amt = gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(iw->to_charge_edit));
-        /* Credit notes have their value signs reversed internally.
-         * So reverse here as well before displaying
-         */
-        if (iw->is_credit_note)
-            to_charge_amt = gnc_numeric_neg (to_charge_amt);
     }
 
     if (iw->total_cash_label)
     {
         amount = gncInvoiceGetTotalOf (invoice, GNC_PAYMENT_CASH);
-        /* Credit notes have their value signs reversed internally.
-         * So reverse here as well before displaying
-         */
-        if (iw->is_credit_note)
-            amount = gnc_numeric_neg (amount);
         amount = gnc_numeric_sub (amount, to_charge_amt,
                                   gnc_commodity_get_fraction (currency), GNC_HOW_RND_ROUND_HALF_UP);
         gnc_invoice_reset_total_label (GTK_LABEL (iw->total_cash_label), amount, currency);
@@ -1541,11 +1500,6 @@
     if (iw->total_charge_label)
     {
         amount = gncInvoiceGetTotalOf (invoice, GNC_PAYMENT_CARD);
-        /* Credit notes have their value signs reversed internally.
-         * So reverse here as well before displaying
-         */
-        if (iw->is_credit_note)
-            amount = gnc_numeric_neg (amount);
         amount = gnc_numeric_add (amount, to_charge_amt,
                                   gnc_commodity_get_fraction (currency), GNC_HOW_RND_ROUND_HALF_UP);
         gnc_invoice_reset_total_label (GTK_LABEL (iw->total_charge_label), amount, currency);

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2012-02-10 15:33:25 UTC (rev 21991)
+++ gnucash/trunk/src/engine/gncInvoice.c	2012-02-10 15:33:34 UTC (rev 21992)
@@ -783,7 +783,7 @@
 {
     GList *node;
     gnc_numeric total = gnc_numeric_zero();
-    gboolean is_cust_doc;
+    gboolean is_cust_doc, is_cn;
 
     g_return_val_if_fail (invoice, total);
 
@@ -791,6 +791,7 @@
      * The GncEntry code needs to know to return the proper entry amounts
      */
     is_cust_doc = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
+    is_cn = gncInvoiceGetIsCreditNote (invoice);
 
     for (node = gncInvoiceGetEntries(invoice); node; node = node->next)
     {
@@ -800,7 +801,7 @@
         if (use_payment_type && gncEntryGetBillPayment (entry) != type)
             continue;
 
-        value = gncEntryGetIntValue (entry, FALSE, is_cust_doc);
+        value = gncEntryGetDocValue (entry, FALSE, is_cust_doc, is_cn);
         if (gnc_numeric_check (value) == GNC_ERROR_OK)
         {
             if (use_value)
@@ -811,7 +812,7 @@
 
         if (use_tax)
         {
-            tax = gncEntryGetIntTaxValue (entry, FALSE, is_cust_doc);
+            tax = gncEntryGetDocTaxValue (entry, FALSE, is_cust_doc, is_cn);
             if (gnc_numeric_check (tax) == GNC_ERROR_OK)
                 total = gnc_numeric_add (total, tax, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
             else

Modified: gnucash/trunk/src/engine/gncInvoice.h
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.h	2012-02-10 15:33:25 UTC (rev 21991)
+++ gnucash/trunk/src/engine/gncInvoice.h	2012-02-10 15:33:34 UTC (rev 21992)
@@ -152,7 +152,8 @@
 Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice);
 /** @} */
 
-/** return the "total" amount of the invoice */
+/** Return the "total" amount of the invoice as seen on the document
+ *  (and shown to the user in the reports and invoice ledger). */
 gnc_numeric gncInvoiceGetTotal (GncInvoice *invoice);
 gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type);
 gnc_numeric gncInvoiceGetTotalSubtotal (GncInvoice *invoice);



More information about the gnucash-changes mailing list