Skip to content

Instantly share code, notes, and snippets.

@lucassmacedo
Created July 1, 2024 19:01
Show Gist options
  • Save lucassmacedo/156c8c8b5fe763b86897058fe502f3c8 to your computer and use it in GitHub Desktop.
Save lucassmacedo/156c8c8b5fe763b86897058fe502f3c8 to your computer and use it in GitHub Desktop.
V_INTEGRACAO_TITULOS
SELECT PCPREST.NUMTRANSVENDA || '/' || PCPREST.PREST AS codigo,
PCUSUARI.tipovend,
PCCLIENT.TIPOFJ AS tipoCliente,
REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') AS documentoCliente,
'DISDAL' AS nomeOrigem,
NULL AS token,
JSON_OBJECT(
'tipoRepresentante' VALUE PCUSUARI.TIPOVEND,
'documentoRepresentante' VALUE REGEXP_REPLACE(DECODE(PCUSUARI.tipovend,
'J', PCUSUARI.CGC,
'F', PCUSUARI.CPF,
'E', PCUSUARI.CODUSUR
), '[^0-9]', ''),
'documentoTitulo' VALUE TO_CHAR(PCPREST.DUPLIC),
'dataEmissao' VALUE PCPREST.DTEMISSAO,
'dataVencimentoProrrogado' VALUE PCPREST.DTVENCORIG,
'dataVencimento' VALUE PCPREST.DTVENC,
'motivoProrrogacao' VALUE NULL,
'parcela' VALUE TO_CHAR(PCPREST.PREST),
'valor' VALUE TO_NUMBER(PCPREST.VALOR),
'observacao' VALUE PCPREST.OBSTITULO,
'numeroBoleto' VALUE PCPREST.NOSSONUMBCO,
'observacao1' VALUE PCPREST.OBS,
'observacao2' VALUE PCPREST.OBS2,
'observacao3' VALUE NULL,
'tipoCedente' VALUE NULL,
'documentoCedente' VALUE NULL,
'codigoMoeda' VALUE 'BRL'
) AS titulo,
JSON_ARRAY(
JSON_OBJECT(
'desassociar' VALUE NULL,
'codigo' VALUE PCPREST.NUMPED
)
) AS pedidosRelacionados,
JSON_ARRAY(
JSON_OBJECT(
'desassociar' VALUE NULL,
'documento' VALUE NULL,
'origem' VALUE NULL,
'tipoCliente' VALUE NULL,
'tipoRelacao' VALUE NULL
)
) AS clientesRelacionados,
JSON_ARRAY(
JSON_OBJECT(
'desassociar' VALUE NULL,
'codigoSistemaGestao' VALUE NULL,
'valor' VALUE NULL
)
) AS divisorLimite,
JSON_ARRAY(
JSON_OBJECT(
'desassociar' VALUE NULL,
'codigoSistemaGestao' VALUE NULL,
'nomeCategoria' VALUE NULL
)
) AS parametrizacoesCategorias,
JSON_ARRAY(
JSON_OBJECT(
'desassociar' VALUE NULL,
'numero' VALUE NULL,
'valorUtilizado' VALUE NULL
)
) AS cheques,
JSON_ARRAY(
JSON_OBJECT(
'desassociar' VALUE NULL,
'codigo' VALUE NULL
)
) AS notas,
JSON_ARRAY(
JSON_OBJECT(
'desassociar' VALUE NULL,
'codigo' VALUE NULL
)
) AS notasComplementares,
JSON_ARRAY(
JSON_OBJECT(
'codigoTipoBaixa' VALUE NULL,
'nomeTipoBaixa' VALUE NULL,
'documento' VALUE PCPREST.NUMTRANSVENDA || '/' || PCPREST.PREST,
'dataBaixa' VALUE NVL(DTPAG, DTBAIXA),
'valor' VALUE NVL(PCPREST.VPAGO, 0)
)
) AS movimentosBaixas,
JSON_ARRAY(
JSON_OBJECT(
'codigoTipoMovimento' VALUE NULL,
'nomeTipoMovimento' VALUE NULL,
'documento' VALUE NULL,
'dataMovimento' VALUE NULL,
'valor' VALUE NULL
)
) AS movimentosGerais,
JSON_OBJECT(
'desassociar' VALUE NULL,
'codigoNegociacao' VALUE NULL,
'numeroParcela' VALUE NULL
) AS recuperacaoNegociacao
FROM PCPREST
JOIN PCCLIENT ON PCCLIENT.CODCLI = PCPREST.CODCLI
JOIN PCCOB ON PCCOB.CODCOB = PCCLIENT.CODCOB
JOIN PCUSUARI ON PCUSUARI.CODUSUR = PCCLIENT.CODUSUR1
WHERE PCPREST.VALOR > 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment