Use gross amount instead of price in callouts.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Tue, 19 Jun 2012 17:27:22 +0200
changeset 17354 3cae85e25c2d
parent 17353 0c7729c4873d
child 17355 f9147401cadf
Use gross amount instead of price in callouts.
src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Amt.java
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Amt.java	Tue Jun 19 17:23:43 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Invoice_Amt.java	Tue Jun 19 17:27:22 2012 +0200
@@ -175,8 +175,9 @@
     }
     // if taxRate field is changed
     if (strChanged.equals("inpcTaxId") && isPriceTaxInclusive(strInvoiceId)) {
-      // todo - Alternate Amount
-      BigDecimal netUnitPrice = calculateNetFromGross(strTaxId, strGrossUnitPrice, strPrecision,
+      BigDecimal grossUnitPrice = new BigDecimal(strGrossUnitPrice.trim());
+      BigDecimal grossAmount = grossUnitPrice.multiply(qtyInvoice);
+      BigDecimal netUnitPrice = calculateNetFromGross(strTaxId, grossAmount, strPrecision,
           taxBaseAmt).divide(qtyInvoice, PricePrecision, RoundingMode.HALF_UP);
       priceActual = netUnitPrice;
       priceStd = netUnitPrice;
@@ -190,8 +191,8 @@
     if (strChanged.equals("inpgrossUnitPrice")) {
       BigDecimal grossUnitPrice = new BigDecimal(strGrossUnitPrice.trim());
       BigDecimal grossAmount = grossUnitPrice.multiply(qtyInvoice);
-      final BigDecimal netUnitPrice = calculateNetFromGross(strTaxId, strGrossUnitPrice,
-          strPrecision, taxBaseAmt).divide(qtyInvoice, PricePrecision, RoundingMode.HALF_UP);
+      final BigDecimal netUnitPrice = calculateNetFromGross(strTaxId, grossAmount, strPrecision,
+          taxBaseAmt).divide(qtyInvoice, PricePrecision, RoundingMode.HALF_UP);
       priceActual = netUnitPrice;
       priceStd = netUnitPrice;
 
@@ -255,14 +256,13 @@
     out.close();
   }
 
-  private BigDecimal calculateNetFromGross(String strTaxId, String strGrossUnitPrice,
+  private BigDecimal calculateNetFromGross(String strTaxId, BigDecimal grossAmount,
       String strPrecision, BigDecimal alternateAmount) {
-    BigDecimal grossUnitPrice = new BigDecimal(strGrossUnitPrice.trim());
-    if (grossUnitPrice.compareTo(BigDecimal.ZERO) == 0)
+    if (grossAmount.compareTo(BigDecimal.ZERO) == 0)
       return BigDecimal.ZERO;
     final List<Object> parameters = new ArrayList<Object>();
     parameters.add(strTaxId);
-    parameters.add(grossUnitPrice);
+    parameters.add(grossAmount);
     // TODO: Alternate Base Amount
     parameters.add(alternateAmount);
     parameters.add(new BigDecimal(strPrecision));
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java	Tue Jun 19 17:23:43 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java	Tue Jun 19 17:27:22 2012 +0200
@@ -313,9 +313,11 @@
 
     // if taxRate field is changed
     if (strChanged.equals("inpcTaxId") && isPriceTaxInclusive(strCOrderId)) {
-      // todo - Alternate Amount
-      final BigDecimal netUnitPrice = calculateNetFromGross(strTaxId, strGrossUnitPrice,
-          strPrecision, taxBaseAmt).divide(qtyOrdered, PricePrecision, RoundingMode.HALF_UP);
+      BigDecimal grossUnitPrice = new BigDecimal(strGrossUnitPrice.trim());
+      BigDecimal grossAmount = grossUnitPrice.multiply(qtyOrdered).setScale(StdPrecision,
+          RoundingMode.HALF_UP);
+      final BigDecimal netUnitPrice = calculateNetFromGross(strTaxId, grossAmount, strPrecision,
+          taxBaseAmt).divide(qtyOrdered, PricePrecision, RoundingMode.HALF_UP);
       priceActual = netUnitPrice;
       priceStd = netUnitPrice;
       resultado.append("new Array(\"inppriceactual\",\"" + netUnitPrice + "\"),");
@@ -327,12 +329,12 @@
     // if taxinclusive field is changed then modify net unit price and gross price
     if (strChanged.equals("inpgrossUnitPrice")) {
       BigDecimal grossUnitPrice = new BigDecimal(strGrossUnitPrice.trim());
-
-      final BigDecimal netUnitPrice = calculateNetFromGross(strTaxId, strGrossUnitPrice,
-          strPrecision, taxBaseAmt).divide(qtyOrdered, PricePrecision, RoundingMode.HALF_UP);
-
       BigDecimal grossAmount = grossUnitPrice.multiply(qtyOrdered).setScale(StdPrecision,
           RoundingMode.HALF_UP);
+
+      final BigDecimal netUnitPrice = calculateNetFromGross(strTaxId, grossAmount, strPrecision,
+          taxBaseAmt).divide(qtyOrdered, PricePrecision, RoundingMode.HALF_UP);
+
       priceActual = netUnitPrice;
       priceStd = netUnitPrice;
 
@@ -378,14 +380,13 @@
     out.close();
   }
 
-  private BigDecimal calculateNetFromGross(String strTaxId, String strGrossUnitPrice,
+  private BigDecimal calculateNetFromGross(String strTaxId, BigDecimal grossAmount,
       String strPrecision, BigDecimal alternateAmount) {
-    BigDecimal grossUnitPrice = new BigDecimal(strGrossUnitPrice.trim());
-    if (grossUnitPrice.compareTo(BigDecimal.ZERO) == 0)
+    if (grossAmount.compareTo(BigDecimal.ZERO) == 0)
       return BigDecimal.ZERO;
     final List<Object> parameters = new ArrayList<Object>();
     parameters.add(strTaxId);
-    parameters.add(grossUnitPrice);
+    parameters.add(grossAmount);
     // TODO: Alternate Base Amount
     parameters.add(alternateAmount);
     parameters.add(new BigDecimal(strPrecision));