src-db/database/model/functions/C_GET_SERVICE_AMOUNT.xml
changeset 29855 956cd99a1937
parent 28634 b7ee95444dc0
child 29873 73a8cd831ca4
equal deleted inserted replaced
29854:af0d6a9e780b 29855:956cd99a1937
    31   -- Parameter
    31   -- Parameter
    32   TYPE RECORD IS REF CURSOR;
    32   TYPE RECORD IS REF CURSOR;
    33   Cur_Rule RECORD;
    33   Cur_Rule RECORD;
    34   Cur_Range RECORD;
    34   Cur_Range RECORD;
    35   BEGIN
    35   BEGIN
    36   
    36     SELECT SUM(AMOUNT), SUM(QUANTITY), ISPRICERULEBASED, M_PRODUCT.M_PRODUCT_ID, C_ORDER.DATEORDERED, STDPRECISION, C_ORDER.M_PRICELIST_ID
    37     
    37       INTO v_TotalAmount, v_TotalQantity, v_IsPriceRuleBased, v_M_Product_ID,  v_Dateordered, v_stdPrecision, v_OrderPricelist
    38   
    38     FROM C_ORDERLINE_SERVICERELATION, C_ORDERLINE, M_PRODUCT, C_ORDER, C_CURRENCY
    39 		SELECT SUM(AMOUNT), SUM(QUANTITY), ISPRICERULEBASED, M_PRODUCT.M_PRODUCT_ID, C_ORDER.DATEORDERED, STDPRECISION, C_ORDER.M_PRICELIST_ID
    39     WHERE C_ORDERLINE_SERVICERELATION.C_ORDERLINE_ID = C_ORDERLINE.C_ORDERLINE_ID
    40 		INTO v_TotalAmount, v_TotalQantity, v_IsPriceRuleBased, v_M_Product_ID,  v_Dateordered, v_stdPrecision, 	v_OrderPricelist
    40     AND C_ORDER.C_ORDER_ID = C_ORDERLINE.C_ORDER_ID
    41 		FROM C_ORDERLINE_SERVICERELATION, C_ORDERLINE, M_PRODUCT, C_ORDER, C_CURRENCY
    41     AND C_ORDER.C_CURRENCY_ID =  C_CURRENCY.C_CURRENCY_ID
    42 		WHERE C_ORDERLINE_SERVICERELATION.C_ORDERLINE_ID = C_ORDERLINE.C_ORDERLINE_ID
    42     AND C_ORDERLINE.M_PRODUCT_id =  M_PRODUCT.M_PRODUCT_ID
    43 		AND C_ORDER.C_ORDER_ID = C_ORDERLINE.C_ORDER_ID
    43     AND C_ORDERLINE.C_ORDERLINE_ID =  v_c_orderline_id
    44 		AND C_ORDER.C_CURRENCY_ID =  C_CURRENCY.C_CURRENCY_ID
    44     GROUP BY ISPRICERULEBASED, M_PRODUCT.M_PRODUCT_ID, C_ORDER.DATEORDERED, STDPRECISION, C_ORDER.M_PRICELIST_ID;
    45 		AND C_ORDERLINE.M_PRODUCT_id =  M_PRODUCT.M_PRODUCT_ID
       
    46 		AND C_ORDERLINE.C_ORDERLINE_ID =  v_c_orderline_id
       
    47 		GROUP BY ISPRICERULEBASED, M_PRODUCT.M_PRODUCT_ID, C_ORDER.DATEORDERED, STDPRECISION, C_ORDER.M_PRICELIST_ID;
       
    48 		
    45 		
    49     IF(v_IsPriceRuleBased = 'Y') THEN
    46     IF(v_IsPriceRuleBased = 'Y') THEN
    50           FOR Cur_Rule IN
    47       FOR Cur_Rule IN
    51 			      (
    48 	(SELECT  RULETYPE, AFTERDISCOUNTS, PERCENTAGE, M_SERVICEPRICERULE.M_SERVICEPRICERULE_ID
    52 						SELECT  RULETYPE, AFTERDISCOUNTS, PERCENTAGE, M_SERVICEPRICERULE.M_SERVICEPRICERULE_ID
    49 	 FROM M_SERVICEPRICERULE_VERSION, M_SERVICEPRICERULE
    53 						FROM M_SERVICEPRICERULE_VERSION, M_SERVICEPRICERULE
    50 	 WHERE M_SERVICEPRICERULE_VERSION.M_SERVICEPRICERULE_ID =  M_SERVICEPRICERULE.M_SERVICEPRICERULE_ID
    54 						WHERE M_SERVICEPRICERULE_VERSION.M_SERVICEPRICERULE_ID =  M_SERVICEPRICERULE.M_SERVICEPRICERULE_ID
    51 	 AND M_PRODUCT_ID = v_M_Product_ID
    55 						AND M_PRODUCT_ID = v_M_Product_ID
    52 	 AND VALIDFROM <=  v_Dateordered
    56 						AND VALIDFROM <=  v_Dateordered
    53 	 ORDER BY VALIDFROM DESC
    57 						ORDER BY VALIDFROM DESC
    54 	)
    58 			      )
    55       LOOP
    59 			    LOOP
    56         IF(Cur_Rule.RULETYPE = 'P') THEN
    60             IF(Cur_Rule.RULETYPE = 'P') THEN
    57           RETURN  round(v_TotalAmount * Cur_Rule.percentage / 100, v_stdPrecision);
    61               RETURN  round(v_TotalAmount * Cur_Rule.percentage / 100, v_stdPrecision);
    58         ELSE
    62             ELSE
    59 	  FOR Cur_Range IN
    63 			          FOR Cur_Range IN
    60             (SELECT  RULETYPE, AFTERDISCOUNTS, PERCENTAGE, M_PRICELIST_ID
    64 						      (
    61 	     FROM m_servicepricerule_range
    65 									SELECT  RULETYPE, AFTERDISCOUNTS, PERCENTAGE, M_PRICELIST_ID
    62 	     WHERE m_servicepricerule_ID  = Cur_Rule.M_SERVICEPRICERULE_ID
    66 									FROM m_servicepricerule_range
    63 	     AND coalesce(amountupto, v_TotalAmount)  >=  v_TotalAmount
    67 									WHERE m_servicepricerule_ID  = Cur_Rule.M_SERVICEPRICERULE_ID
    64 	     ORDER BY amountupto
    68 									AND coalesce(amountupto, v_TotalAmount)  >=  v_TotalAmount
    65 	    )
    69 									ORDER BY amountupto
    66 	  LOOP
    70 						      )
    67 	    IF(Cur_Range.RULETYPE = 'P') THEN
    71 						    LOOP
    68 	      RETURN  ROUND(v_TotalAmount * Cur_Range.percentage / 100, v_stdPrecision);
    72 			            IF(Cur_Range.RULETYPE = 'P') THEN
    69 	    ELSE
    73 			              RETURN  ROUND(v_TotalAmount * Cur_Range.percentage / 100, v_stdPrecision);
    70 	      SELECT PRICELIST 
    74 			            ELSE
    71 		INTO v_PriceList
    75 			              SELECT PRICELIST 
    72 	      FROM M_PRODUCTPRICE
    76 			              INTO v_PriceList
    73 	      WHERE M_PRICELIST_VERSION_ID = M_GET_PRICELIST_VERSION(Cur_Range.M_PRICELIST_ID, v_Dateordered)
    77 			              FROM M_PRODUCTPRICE
    74 	      AND M_PRODUCT_ID = v_M_Product_ID;
    78 			              WHERE M_PRICELIST_VERSION_ID = M_GET_PRICELIST_VERSION(Cur_Range.M_PRICELIST_ID, v_Dateordered)
    75               RETURN ROUND(v_PriceList * v_TotalQantity, v_stdPrecision);
    79 			              AND M_PRODUCT_ID = v_M_Product_ID;
    76 	    END IF;
    80                     RETURN ROUND(v_PriceList * v_TotalQantity, v_stdPrecision);
    77 	  END LOOP;
    81 			            END IF;
    78 	  RAISE_APPLICATION_ERROR(-20000, '@NoMatchingRange@');
    82 						    END LOOP;
    79         END IF;
    83 						    RAISE_APPLICATION_ERROR(-20000, '@NoMatchingRange@');
    80       END LOOP;
    84             END IF;
    81       RAISE_APPLICATION_ERROR(-20000, '@NoMatchingPriceRule@');
    85 			    END LOOP;
    82     ELSE
    86 			    RAISE_APPLICATION_ERROR(-20000, '@NoMatchingPriceRule@');
    83       SELECT PRICELIST 
    87 		ELSE
    84         INTO v_PriceList
    88 			SELECT PRICELIST 
    85       FROM M_PRODUCTPRICE
    89 			INTO v_PriceList
    86       WHERE M_PRICELIST_VERSION_ID = M_GET_PRICELIST_VERSION(v_OrderPricelist, v_Dateordered)
    90 			FROM M_PRODUCTPRICE
    87       AND M_PRODUCT_ID = v_M_Product_ID;
    91 			WHERE M_PRICELIST_VERSION_ID = M_GET_PRICELIST_VERSION(v_OrderPricelist, v_Dateordered)
    88       RETURN ROUND(v_PriceList * v_TotalQantity, v_stdPrecision);
    92 			AND M_PRODUCT_ID = v_M_Product_ID;
       
    93 			RETURN ROUND(v_PriceList * v_TotalQantity, v_stdPrecision);
       
    94     END IF;
    89     END IF;
    95 END C_GET_SERVICE_AMOUNT
    90 END C_GET_SERVICE_AMOUNT
    96 ]]></body>
    91 ]]></body>
    97     </function>
    92     </function>
    98   </database>
    93   </database>