Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE [dbo].SP_Corrige_Parcelas @idPagamentoVenda INT,
- @qtParcelas INT,
- @prTaxaAdministracao NUMERIC(9, 2)
- AS
- IF(
- (
- SELECT COUNT(*) AS 'Linhas'
- FROM card.tbParcela
- WHERE idPagamentoVenda = @idPagamentoVenda
- ) <> @qtParcelas)
- BEGIN
- DECLARE @iterator INT= 0;
- DECLARE @cntCorrente INT=
- (
- SELECT TOP 1 *
- FROM card.tbParcela
- WHERE idPagamentoVenda = @idPagamentoVenda
- );
- DELETE FROM card.tbParcela
- WHERE idPagamentoVenda = @idPagamentoVenda;
- WHILE @qtParcelas > @iterator
- BEGIN
- INSERT INTO card.tbParcela
- (idPagamentoVenda,
- nrParcela,
- idEmpresa,
- dtEmissao,
- dtVencimento,
- vlParcela,
- vlTaxaAdministracao,
- idContaCorrente,
- dtPagamento,
- vlPago,
- idStatusParcela,
- idMovimentoBanco
- )
- VALUES
- (
- (
- SELECT t1.idPagamentoVenda,
- @iterator + 1,
- t1.idEmpresa,
- t1.dtEmissao,
- CONVERT(VARCHAR, DATEADD(DAY, 30, CONVERT(DATE, t1.dtEmissao, 103)), 23),
- t1.vlPagamento / @qtParcelas,
- @prTaxaAdministracao,
- @cntCorrente,
- NULL,
- NULL,
- 1,
- NULL
- FROM card.tbPagamentoVenda t1
- INNER JOIN card.tbContaCorrente t2 ON t1.idEmpresa = t2.idEmpresa
- WHERE t1.idPagamentoVenda = @idPagamentoVenda
- )
- );
- END;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement