The document declares variables to count documents, get the status and number of the most recent document. It then checks if the last document status is open and returns document numbers for new purchase orders or sales orders to invoice if the last document is open.
The document declares variables to count documents, get the status and number of the most recent document. It then checks if the last document status is open and returns document numbers for new purchase orders or sales orders to invoice if the last document is open.
The document declares variables to count documents, get the status and number of the most recent document. It then checks if the last document status is open and returns document numbers for new purchase orders or sales orders to invoice if the last document is open.
The document declares variables to count documents, get the status and number of the most recent document. It then checks if the last document status is open and returns document numbers for new purchase orders or sales orders to invoice if the last document is open.
DECLARE @STAT AS NVARCHAR(2) -- ESTATUS DE DOCUMENTO ABIERTO O CERRADO
DECLARE @ULTDOC AS INT ---NUMERO ULTIMO DOCUMENTO SET @CONT = (SELECT COUNT(T4.[DocNum]) FROM OPRQ T4) SET @ULTDOC = (SELECT MAX(T4.[DocNum]) FROM OPRQ T4) SET @STAT = (SELECT T4.DocStatus FROM OPRQ T4 WHERE T4.[DocNum] = @ULTDOC)
SELECT @CONT, @ULTDOC, @STAT
IF @STAT = 'O' BEGIN
SELECT DISTINCT T0.[DocEntry] as 'N° de Nueva Solicitud de compra' FROM OPRQ T0 WHERE @CONT > '0' AND T0.[DocStatus] = 'O' AND T0.DocDate = CONVERT(date,GETDATE(),182) END
*********************************
DECLARE @CONT AS INT ---CONTADOR
DECLARE @STAT AS NVARCHAR(2) --- ESTATUS DE DOCUMENTO ABIERTO O CERRADO DECLARE @ULTDOC AS INT ---NUMERO ULTIMO DOCUMENTO SET @CONT = (SELECT COUNT(T4.[DocNum]) FROM ORDR T4) SET @ULTDOC = (SELECT MAX(T4.[DocNum]) FROM ORDR T4) SET @STAT = (SELECT T4.DocStatus FROM ORDR T4 WHERE T4.[DocNum] = @ULTDOC) IF @STAT = 'O' BEGIN SELECT DISTINCT T4.[DocNum] as 'N° Orden de Venta a Facturar' FROM [dbo].[OPDN] T0 INNER JOIN PDN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OPOR T2 ON T1.BaseRef = T2.DocEntry INNER JOIN POR1 T3 ON T2.DocEntry = T3.DocEntry INNER JOIN ORDR T4 ON T3.BaseRef = T4.DocEntry WHERE @CONT > '0' AND T4.[DocStatus] = 'O' END