Created
October 18, 2017 17:09
-
-
Save primogf/fa5b215f16fc7d2b7a3b6a0870f4a3c6 to your computer and use it in GitHub Desktop.
procedure atualiza numero da nota no pedido
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE `ajuste_numero_nf_pedido` () | |
BEGIN | |
DECLARE fim INT DEFAULT false; | |
DECLARE var_id_documento int; | |
DECLARE var_id_registro int; | |
DECLARE var_numero_nfe int; | |
DECLARE var_id_lancamento_contabil int; | |
DECLARE var_id_conta_debito int; | |
DECLARE var_id_conta_credito int; | |
DECLARE var_valor_debito decimal(20,2); | |
DECLARE var_valor_credito decimal(20,2); | |
DECLARE var_stat tinyint; | |
-- criando o cursor | |
DECLARE curDocumentoNfe CURSOR FOR | |
select | |
id_documento, | |
id_registro | |
from | |
DocumentOrigin | |
where id_documento in ( | |
select | |
id_documento | |
from | |
DocumentOrigin | |
where id_registro in ( | |
select | |
o.id_documento | |
from | |
`Order` o | |
inner join ConsumerTransaction c on c.id_transacao_consumidor = o.id_transacao_consumidor | |
where | |
o.fe_stat <> 0 | |
) | |
) | |
and id_tabela_sistema = 1471; | |
DECLARE CONTINUE handler FOR NOT found SET fim = TRUE; | |
OPEN curDocumentoNfe; | |
-- loop no cursor | |
READ_LOOP:LOOP | |
FETCH curDocumentoNfe | |
INTO | |
var_id_documento, | |
var_id_registro; | |
-- buscando numero da nota | |
SELECT numero | |
INTO var_numero_nfe | |
FROM fis_nfe | |
WHERE id_nfe = var_id_registro; | |
-- atualizando pedido | |
update Document set no_documento = var_numero_nfe where id_documento = var_id_documento; | |
IF fim THEN | |
LEAVE read_loop; | |
end IF; | |
end LOOP; | |
close curDocumentoNfe; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment