@MickD
See example below:
DECLARE margin_ DECIMAL;
PRAGMA AUTONOMOUS_TRANSACTION;
CURSOR c_get_margin_ IS
SELECT CASE WHEN
SUM(Order_Quotation_Line_API.Get_Base_Sale_Price_Total(QUOTATION_NO, LINE_NO, REL_NO, LINE_ITEM_NO)) <> 0
THEN ROUND(100/SUM(Order_Quotation_Line_API.Get_Base_Sale_Price_Total(QUOTATION_NO, LINE_NO, REL_NO, LINE_ITEM_NO)) * SUM(Order_Quotation_Line_API.Get_Quot_Line_Contribution(QUOTATION_NO, LINE_NO, REL_NO, LINE_ITEM_NO)),2) ELSE 0 END FROM ORDER_QUOTATION_LINE_TAB WHERE QUOTATION_NO = '&NEW:QUOTATION_NO';
BEGIN
OPEN c_get_margin_ ;
FETCH c_get_margin_ INTO margin_ ;
CLOSE c_get_margin_;
IF margin_ < 40 THEN
Error_SYS.Record_General('OrderQuotation', 'CHECKMARGIN: The Sales Quotation Margin % is less than 40%. Quotation Lines where the "Contribution Margin Rate" is below 40% will need to be Approved.' );
END IF;
END;
Best Regards
John