EXEMPLO_1212310
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
XDATABAIXAPARCELAPAGAMENTO
Parameters
Name
Type
Mode
@CODCOLIGADA
smallint
IN
@IDLAN
int
IN
@STATUSLAN
int
IN
Definition
CREATE FUNCTION XDATABAIXAPARCELAPAGAMENTO(@CODCOLIGADA SMALLINT, @IDLAN INT, @STATUSLAN INT) RETURNS DATETIME AS BEGIN DECLARE @DATALIQUIDACAO DATETIME, @VRPARCELA NUMERIC(15,4), @VRPARCELABX NUMERIC(15,4) SELECT @VRPARCELA = XVENDAPARCELAEXT.VALORPARCELA, @VRPARCELABX = XVENDAPARCELAEXT.VALORPARCELABX FROM XVENDAPARCELA JOIN (SELECT XVPT.NUMVENDA, XVPT.CODGRUPO, XVPT.NUMPARC, XVPT.CODTIPOPARC, CAST(DBO.XSUMVRPARCELACOMPONENTEPORTIPO(XVPT.NUMVENDA, XVPT.CODGRUPO, XVPT.NUMPARC, XVPT.CODTIPOPARC, '0') AS NUMERIC(15,4)) AS VALORPARCELA, CAST(DBO.XSUMBXPARCELACOMPONENTEPORTIPO(XVPT.NUMVENDA, XVPT.CODGRUPO, XVPT.NUMPARC, XVPT.CODTIPOPARC, '0') AS NUMERIC(15,4)) AS VALORPARCELABX FROM XVENDAPARCELA XVPT) XVENDAPARCELAEXT ON XVENDAPARCELAEXT.NUMVENDA = XVENDAPARCELA.NUMVENDA AND XVENDAPARCELAEXT.CODGRUPO = XVENDAPARCELA.CODGRUPO AND XVENDAPARCELAEXT.CODTIPOPARC = XVENDAPARCELA.CODTIPOPARC AND XVENDAPARCELAEXT.NUMPARC = XVENDAPARCELA.NUMPARC WHERE XVENDAPARCELA.CODCOLIGADA = @CODCOLIGADA AND XVENDAPARCELA.IDLAN = @IDLAN IF ((@STATUSLAN = 0 OR @STATUSLAN = 4) AND (DBO.XSTATUSPARCELAPAGAMENTO(@STATUSLAN, @VRPARCELA, @VRPARCELABX) = 2)) BEGIN SELECT @DATALIQUIDACAO = (CASE WHEN FB1.DATACHEQUE IS NOT NULL THEN FB1.DATACHEQUE ELSE FB1.DATABAIXA END) FROM FLANBAIXA FB1 WHERE FB1.CODCOLIGADA = @CODCOLIGADA AND FB1.IDLAN = @IDLAN AND FB1.STATUS IN(0,4) AND FB1.IDBAIXA IN (SELECT MAX(FB2.IDBAIXA) FROM FLANBAIXA FB2 WHERE FB2.CODCOLIGADA = FB1.CODCOLIGADA AND FB2.IDLAN = FB1.IDLAN AND FB2.STATUS IN (0,4)) END ELSE IF (@STATUSLAN = 1 OR @STATUSLAN = 3 OR @STATUSLAN = 5) BEGIN SELECT @DATALIQUIDACAO = FLAN.DATABAIXA FROM FLAN WHERE FLAN.CODCOLIGADA = @CODCOLIGADA AND FLAN.IDLAN = @IDLAN END ELSE BEGIN SET @DATALIQUIDACAO = NULL; END RETURN @DATALIQUIDACAO END