BUEN DIA estimados
tengo este TN para bloquear los documentos que no cumplan con ventas en meso de 6 meses pero me esta bloqueando todos los borradores por que tengo 112 y debo amarra este a que sea solo la orden de venta (17) pero no se que en lugar debe ir, agradezco si me pueden ayudar
saludos
IF :object_type='112' AND (:transaction_type='A' or :transaction_type='U') THEN
DECLARE cont INT;
DECLARE maxrownumber INT;
DECLARE rownumber INT;
DECLARE linenumber INT;
DECLARE invoicelines INT;
DECLARE itemcode NVARCHAR (50);
DECLARE cardcode NVARCHAR (15);
DECLARE docdate DATE;
DECLARE backdate DATE;
/Verificar si el campo U_AUTOR_VENTA tiene valor SI/NO en la orden de venta/
SELECT CASE WHEN IFNULL(H0."U_AUTOR_VENTA",'')='S' THEN 1 ELSE 0 END INTO cont FROM ODRF H0 WHERE H0."DocEntry"= :list_of_cols_val_tab_del;
IF cont = 0 THEN
rownumber:= 0;
SELECT COUNT(*) INTO maxrownumber FROM DRF1 WHERE "DocEntry" = :list_of_cols_val_tab_del;
WHILE (:rownumber < :maxrownumber) DO
SELECT "VisOrder" INTO linenumber FROM DRF1 WHERE "DocEntry" = :list_of_cols_val_tab_del AND "VisOrder" = :rownumber;
SELECT "ItemCode" INTO itemcode FROM DRF1 WHERE "DocEntry" = :list_of_cols_val_tab_del AND "LineNum" = :linenumber;
SELECT "BaseCard" INTO cardcode FROM DRF1 WHERE "DocEntry" = :list_of_cols_val_tab_del AND "LineNum" = :linenumber;
SELECT "DocDate" INTO docdate FROM DRF1 WHERE "DocEntry" = :list_of_cols_val_tab_del AND "LineNum" = :linenumber;
SELECT ADD_MONTHS(:docdate, -6) INTO backdate FROM DUMMY;
SELECT COUNT (*) INTO invoicelines FROM INV1 T0 WHERE T0."ItemCode"=:itemcode AND T0."DocDate" BETWEEN :backdate AND :docdate AND T0."BaseCard"= :cardcode;
IF (:invoicelines <= 0) THEN
error:= 1;
error_message:= 'SP-xx: Articulo en linea ('||:linenumber+1||') sin ventas en los ultimos meses, necesita autorizacion';
END IF;
rownumber:= :rownumber + 1;
END WHILE;
END IF;
END IF;