ALTERAR O STATUS DE UMA NF-e PARA REJEITADA

Post date: May 13, 2015 6:34:06 PM

SQL para marcar uma NF-e com status de rejeitada.

Esse procedimento somente deve ser utilizado quando o status da NF-e no AutoSystem estiver como "Aguardando envio" e ao consultar a chave da NF-e na SEFAZ o mesmo retornar como "NF-e Inesistente".

/*COMANDO #1*/

select grid from nfe where nota_fiscal in (select grid from nota_fiscal where numero_nota='NUMERO_NOTA');

/*COMANDO #2*/

select * from nfe where grid='RESULTADO_COMANDO_1';

/*COMANDO #3*/

update nfe set retorno='INFORMAR_CODIGO_DA_TABELA_NFE_MENSAGEM_RETORNO' where grid='RESULTADO_COMANDO_1';

/*A TABELA NFE_MENSAGEM_RETORNO CONSTA TODOS OS CODIGOS DE RETORNO, VERIFICAR QUAL CÓDIGO MELHOR SE ENQUADRA NA SITUAÇÃO*/

/*COMANDO #4*/

select grid from nota_fiscal where numero_nota='NUMERO_NOTA';

/*COMANDO #5*/

select * from nota_fiscal_situacao where nota_fiscal='RESULTADO_COMANDO_4';

/*COMANDO #6*/

update nota_fiscal_situacao set situacao='320' where nota_fiscal='RESULTADO_COMANDO_4';

/*A SITUAÇÃO 320 MARCA A NFE COMO REJEITADA*/