src-db/database/model/functions/C_GET_SERVICE_AMOUNT.xml
changeset 29855 956cd99a1937
parent 28634 b7ee95444dc0
child 29873 73a8cd831ca4
--- a/src-db/database/model/functions/C_GET_SERVICE_AMOUNT.xml	Fri Apr 08 14:51:17 2016 +0530
+++ b/src-db/database/model/functions/C_GET_SERVICE_AMOUNT.xml	Mon Apr 18 18:51:42 2016 +0200
@@ -33,64 +33,59 @@
   Cur_Rule RECORD;
   Cur_Range RECORD;
   BEGIN
-  
-    
-  
-		SELECT SUM(AMOUNT), SUM(QUANTITY), ISPRICERULEBASED, M_PRODUCT.M_PRODUCT_ID, C_ORDER.DATEORDERED, STDPRECISION, C_ORDER.M_PRICELIST_ID
-		INTO v_TotalAmount, v_TotalQantity, v_IsPriceRuleBased, v_M_Product_ID,  v_Dateordered, v_stdPrecision, 	v_OrderPricelist
-		FROM C_ORDERLINE_SERVICERELATION, C_ORDERLINE, M_PRODUCT, C_ORDER, C_CURRENCY
-		WHERE C_ORDERLINE_SERVICERELATION.C_ORDERLINE_ID = C_ORDERLINE.C_ORDERLINE_ID
-		AND C_ORDER.C_ORDER_ID = C_ORDERLINE.C_ORDER_ID
-		AND C_ORDER.C_CURRENCY_ID =  C_CURRENCY.C_CURRENCY_ID
-		AND C_ORDERLINE.M_PRODUCT_id =  M_PRODUCT.M_PRODUCT_ID
-		AND C_ORDERLINE.C_ORDERLINE_ID =  v_c_orderline_id
-		GROUP BY ISPRICERULEBASED, M_PRODUCT.M_PRODUCT_ID, C_ORDER.DATEORDERED, STDPRECISION, C_ORDER.M_PRICELIST_ID;
+    SELECT SUM(AMOUNT), SUM(QUANTITY), ISPRICERULEBASED, M_PRODUCT.M_PRODUCT_ID, C_ORDER.DATEORDERED, STDPRECISION, C_ORDER.M_PRICELIST_ID
+      INTO v_TotalAmount, v_TotalQantity, v_IsPriceRuleBased, v_M_Product_ID,  v_Dateordered, v_stdPrecision, v_OrderPricelist
+    FROM C_ORDERLINE_SERVICERELATION, C_ORDERLINE, M_PRODUCT, C_ORDER, C_CURRENCY
+    WHERE C_ORDERLINE_SERVICERELATION.C_ORDERLINE_ID = C_ORDERLINE.C_ORDERLINE_ID
+    AND C_ORDER.C_ORDER_ID = C_ORDERLINE.C_ORDER_ID
+    AND C_ORDER.C_CURRENCY_ID =  C_CURRENCY.C_CURRENCY_ID
+    AND C_ORDERLINE.M_PRODUCT_id =  M_PRODUCT.M_PRODUCT_ID
+    AND C_ORDERLINE.C_ORDERLINE_ID =  v_c_orderline_id
+    GROUP BY ISPRICERULEBASED, M_PRODUCT.M_PRODUCT_ID, C_ORDER.DATEORDERED, STDPRECISION, C_ORDER.M_PRICELIST_ID;
 		
     IF(v_IsPriceRuleBased = 'Y') THEN
-          FOR Cur_Rule IN
-			      (
-						SELECT  RULETYPE, AFTERDISCOUNTS, PERCENTAGE, M_SERVICEPRICERULE.M_SERVICEPRICERULE_ID
-						FROM M_SERVICEPRICERULE_VERSION, M_SERVICEPRICERULE
-						WHERE M_SERVICEPRICERULE_VERSION.M_SERVICEPRICERULE_ID =  M_SERVICEPRICERULE.M_SERVICEPRICERULE_ID
-						AND M_PRODUCT_ID = v_M_Product_ID
-						AND VALIDFROM <=  v_Dateordered
-						ORDER BY VALIDFROM DESC
-			      )
-			    LOOP
-            IF(Cur_Rule.RULETYPE = 'P') THEN
-              RETURN  round(v_TotalAmount * Cur_Rule.percentage / 100, v_stdPrecision);
-            ELSE
-			          FOR Cur_Range IN
-						      (
-									SELECT  RULETYPE, AFTERDISCOUNTS, PERCENTAGE, M_PRICELIST_ID
-									FROM m_servicepricerule_range
-									WHERE m_servicepricerule_ID  = Cur_Rule.M_SERVICEPRICERULE_ID
-									AND coalesce(amountupto, v_TotalAmount)  >=  v_TotalAmount
-									ORDER BY amountupto
-						      )
-						    LOOP
-			            IF(Cur_Range.RULETYPE = 'P') THEN
-			              RETURN  ROUND(v_TotalAmount * Cur_Range.percentage / 100, v_stdPrecision);
-			            ELSE
-			              SELECT PRICELIST 
-			              INTO v_PriceList
-			              FROM M_PRODUCTPRICE
-			              WHERE M_PRICELIST_VERSION_ID = M_GET_PRICELIST_VERSION(Cur_Range.M_PRICELIST_ID, v_Dateordered)
-			              AND M_PRODUCT_ID = v_M_Product_ID;
-                    RETURN ROUND(v_PriceList * v_TotalQantity, v_stdPrecision);
-			            END IF;
-						    END LOOP;
-						    RAISE_APPLICATION_ERROR(-20000, '@NoMatchingRange@');
-            END IF;
-			    END LOOP;
-			    RAISE_APPLICATION_ERROR(-20000, '@NoMatchingPriceRule@');
-		ELSE
-			SELECT PRICELIST 
-			INTO v_PriceList
-			FROM M_PRODUCTPRICE
-			WHERE M_PRICELIST_VERSION_ID = M_GET_PRICELIST_VERSION(v_OrderPricelist, v_Dateordered)
-			AND M_PRODUCT_ID = v_M_Product_ID;
-			RETURN ROUND(v_PriceList * v_TotalQantity, v_stdPrecision);
+      FOR Cur_Rule IN
+	(SELECT  RULETYPE, AFTERDISCOUNTS, PERCENTAGE, M_SERVICEPRICERULE.M_SERVICEPRICERULE_ID
+	 FROM M_SERVICEPRICERULE_VERSION, M_SERVICEPRICERULE
+	 WHERE M_SERVICEPRICERULE_VERSION.M_SERVICEPRICERULE_ID =  M_SERVICEPRICERULE.M_SERVICEPRICERULE_ID
+	 AND M_PRODUCT_ID = v_M_Product_ID
+	 AND VALIDFROM <=  v_Dateordered
+	 ORDER BY VALIDFROM DESC
+	)
+      LOOP
+        IF(Cur_Rule.RULETYPE = 'P') THEN
+          RETURN  round(v_TotalAmount * Cur_Rule.percentage / 100, v_stdPrecision);
+        ELSE
+	  FOR Cur_Range IN
+            (SELECT  RULETYPE, AFTERDISCOUNTS, PERCENTAGE, M_PRICELIST_ID
+	     FROM m_servicepricerule_range
+	     WHERE m_servicepricerule_ID  = Cur_Rule.M_SERVICEPRICERULE_ID
+	     AND coalesce(amountupto, v_TotalAmount)  >=  v_TotalAmount
+	     ORDER BY amountupto
+	    )
+	  LOOP
+	    IF(Cur_Range.RULETYPE = 'P') THEN
+	      RETURN  ROUND(v_TotalAmount * Cur_Range.percentage / 100, v_stdPrecision);
+	    ELSE
+	      SELECT PRICELIST 
+		INTO v_PriceList
+	      FROM M_PRODUCTPRICE
+	      WHERE M_PRICELIST_VERSION_ID = M_GET_PRICELIST_VERSION(Cur_Range.M_PRICELIST_ID, v_Dateordered)
+	      AND M_PRODUCT_ID = v_M_Product_ID;
+              RETURN ROUND(v_PriceList * v_TotalQantity, v_stdPrecision);
+	    END IF;
+	  END LOOP;
+	  RAISE_APPLICATION_ERROR(-20000, '@NoMatchingRange@');
+        END IF;
+      END LOOP;
+      RAISE_APPLICATION_ERROR(-20000, '@NoMatchingPriceRule@');
+    ELSE
+      SELECT PRICELIST 
+        INTO v_PriceList
+      FROM M_PRODUCTPRICE
+      WHERE M_PRICELIST_VERSION_ID = M_GET_PRICELIST_VERSION(v_OrderPricelist, v_Dateordered)
+      AND M_PRODUCT_ID = v_M_Product_ID;
+      RETURN ROUND(v_PriceList * v_TotalQantity, v_stdPrecision);
     END IF;
 END C_GET_SERVICE_AMOUNT
 ]]></body>