Bug fixed 0005028: Purchase Order: Discount amount does not appear on copied lines
authorDavid Abragimov <david.abragimov@opensuite.com>
Fri, 21 Nov 2008 14:55:12 +0000
changeset 2066 f7b3a8f2f667
parent 2065 39f93a38e9c6
child 2067 c73cf7263093
Bug fixed 0005028: Purchase Order: Discount amount does not appear on copied lines
src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java
src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java	Fri Nov 21 13:51:37 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder.java	Fri Nov 21 14:55:12 2008 +0000
@@ -107,11 +107,28 @@
             orderlineprice = CopyFromOrderData.set();
             orderlineprice[0].pricelist ="0";
             orderlineprice[0].pricelimit = "0";
+            orderlineprice[0].stdprecision = "0";
           }
+
+          String strPrecision = orderlineprice[0].stdprecision.equals("")?"0":orderlineprice[0].stdprecision;
+          
+          BigDecimal discount, priceActual, priceList;          
+          int StdPrecision = Integer.valueOf(strPrecision).intValue();
+          priceList = (orderlineprice[0].pricelist.equals("")?ZERO:new BigDecimal(orderlineprice[0].pricelist));
+          priceActual = (strLastpriceso.equals("")?ZERO:new BigDecimal(strLastpriceso));
+          
+          if (priceList.doubleValue() == 0.0) discount = ZERO;
+          else {
+            if (log4j.isDebugEnabled()) log4j.debug("pricelist:" + Double.toString(priceList.doubleValue()));
+            if (log4j.isDebugEnabled()) log4j.debug("priceActual:" + Double.toString(priceActual.doubleValue()));
+            discount = new BigDecimal ((priceList.doubleValue() - priceActual.doubleValue()) / priceList.doubleValue() * 100.0);
+          }
+          if (log4j.isDebugEnabled()) log4j.debug("Discount: " + discount.toString());
+          if (discount.scale() > StdPrecision) discount = discount.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
           try {
             CopyFromOrderData.insertCOrderline(conn, this, strCOrderlineID, order[0].adClientId, order[0].adOrgId, vars.getUser(),
             strKey, order[0].cBpartnerId, order[0].cBpartnerLocationId, order[0].dateordered, order[0].dateordered, 
-            strmProductId, order[0].mWarehouseId.equals("")?vars.getWarehouse():order[0].mWarehouseId, strcUOMId, strQty, order[0].cCurrencyId, orderlineprice[0].pricelist, strLastpriceso, orderlineprice[0].pricelimit, strcTaxId, strmAttributesetinstanceId);
+            strmProductId, order[0].mWarehouseId.equals("")?vars.getWarehouse():order[0].mWarehouseId, strcUOMId, strQty, order[0].cCurrencyId, orderlineprice[0].pricelist, strLastpriceso, orderlineprice[0].pricelimit, discount.toString(), strcTaxId, strmAttributesetinstanceId);
           } catch(ServletException ex) {
             myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
             releaseRollbackConnection(conn);
--- a/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql	Fri Nov 21 13:51:37 2008 +0000
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql	Fri Nov 21 14:55:12 2008 +0000
@@ -12,7 +12,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SL 
- * All portions are Copyright (C) 2001-2006 Openbravo SL 
+ * All portions are Copyright (C) 2001-2008 Openbravo SL 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -28,7 +28,7 @@
     <Sql>
       <![CDATA[
         SELECT M_PRODUCT_ID, PRODUCTNAME, M_ATTRIBUTESETINSTANCE_ID, DESCRIPTION, CLASS_OFFER,
-        OFFER_NAME, PRICESTD, LASTPRICESO, C_TAX_ID, NAMETAX, C_UOM_ID, UOMSYMBOL, '0' AS QTY, '' AS PRICELIMIT, '' AS PRICELIST FROM (
+        OFFER_NAME, PRICESTD, LASTPRICESO, C_TAX_ID, NAMETAX, C_UOM_ID, UOMSYMBOL, '0' AS QTY, '' AS PRICELIMIT, '' AS PRICELIST, '' AS STDPRECISION FROM (
         SELECT CL.M_PRODUCT_ID AS M_PRODUCT_ID, M.NAME AS PRODUCTNAME,
         MA.M_ATTRIBUTESETINSTANCE_ID AS M_ATTRIBUTESETINSTANCE_ID, MA.DESCRIPTION AS DESCRIPTION,
         (CASE coalesce(M_GET_OFFER(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID),'-1') WHEN '-1' THEN '' ELSE '' END) AS CLASS_OFFER,
@@ -96,11 +96,12 @@
     <Sql>
       <![CDATA[
         SELECT M_BOM_PRICELIST(P.M_PRODUCT_ID,PV.M_PRICELIST_VERSION_ID) AS PRICELIST,
-        M_BOM_PRICELIMIT(P.M_PRODUCT_ID,PV.M_PRICELIST_VERSION_ID) AS PRICELIMIT
-        FROM M_PRODUCT P, M_PRODUCTPRICE PP, M_PRICELIST PL, M_PRICELIST_VERSION PV 
+        M_BOM_PRICELIMIT(P.M_PRODUCT_ID,PV.M_PRICELIST_VERSION_ID) AS PRICELIMIT, CUR.STDPRECISION AS STDPRECISION
+        FROM M_PRODUCT P, M_PRODUCTPRICE PP, M_PRICELIST PL, M_PRICELIST_VERSION PV, C_CURRENCY CUR  
         WHERE P.M_PRODUCT_ID=PP.M_PRODUCT_ID
         AND PP.M_PRICELIST_VERSION_ID=PV.M_PRICELIST_VERSION_ID
         AND PV.M_PRICELIST_ID=PL.M_PRICELIST_ID
+        AND PL.C_CURRENCY_ID = CUR.C_CURRENCY_ID
         AND PV.ISACTIVE='Y'
         AND PV.VALIDFROM <= TO_DATE(?)
         AND P.M_PRODUCT_ID = ?
@@ -118,10 +119,10 @@
       <![CDATA[
         INSERT INTO C_ORDERLINE (C_ORDERLINE_ID, AD_CLIENT_ID, AD_ORG_ID, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
         C_ORDER_ID, LINE, C_BPARTNER_ID, C_BPARTNER_LOCATION_ID, DATEORDERED, DATEPROMISED, M_PRODUCT_ID, M_WAREHOUSE_ID, C_UOM_ID,
-        QTYORDERED, C_CURRENCY_ID, PRICELIST, PRICEACTUAL, PRICELIMIT, C_TAX_ID, M_ATTRIBUTESETINSTANCE_ID) 
+        QTYORDERED, C_CURRENCY_ID, PRICELIST, PRICEACTUAL, PRICELIMIT, DISCOUNT, C_TAX_ID, M_ATTRIBUTESETINSTANCE_ID) 
         VALUES (?,?,?,NOW(),?,NOW(),?,
                 ?,(SELECT (coalesce(Max(Line),0))+10 FROM C_OrderLine WHERE C_Order_id = ?),?,?,TO_DATE(?),TO_DATE(?),?,?,?,
-                TO_NUMBER(?),?,TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?),?, ?)
+                TO_NUMBER(?),?,TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?), TO_NUMBER(?), ?, ?)
       ]]>
     </Sql>
     <Parameter name="cOrderlineId"/>
@@ -143,6 +144,7 @@
     <Parameter name="pricelist"/>
     <Parameter name="priceactual"/>
     <Parameter name="pricelimit"/>
+    <Parameter name="discount"/>
     <Parameter name="cTaxId"/>
     <Parameter name="mAttributesetinstanceId"/>
   </SqlMethod>