Skip to Content
avatar image
Former Member

Trava de NF com mesmo número / mesmo Fornecedor

     Amigos,

Como insiro uma trava no sistema que impeça que o usuário entre com uma NF com o mesmo número (do mesmo Fornecedor) ???

Para fornecedores diferentes, o SAP mostra um aviso e pra mim já é o suficiente, porém para mesmo Fornecedor, ele mostra o mesmo aviso, porém permite o lançamento da NF.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Aug 03, 2014 at 10:05 PM

    Boa noite,

    tive o mesmo problema aqui na empresa, como ninguém lê as mensagens do sistema, tive que travar.

    Ele testa o número nos 4 locais onde possamos lançar nota de entrada, mas deixa passar sem modelo, já que não consigo cancelar notas "só imposto", eu no teste ignorei o modelo, testei somente PN, série e número, até o momento (3 anos), não peguei nenhum PN que tenha modelos diferentes, com série e números iguais.

    IF (@error = 0) AND (@sObjTyp IN ('14','16','18','20')) AND (@sTraTyp IN ('A')) AND (@SeqCode = -2)
    BEGIN
          IF @sObjTyp = 18 BEGIN SELECT @NFENUMERO = T0.Serial, @NFESERIE = ISNULL(T0.SeriesStr,''), @CodCliente = T0.CardCode FROM [dbo].[OPCH] T0 WHERE T0.DocEntry = @sKeyVal END
          IF @sObjTyp = 20 BEGIN SELECT @NFENUMERO = T0.Serial, @NFESERIE = ISNULL(T0.SeriesStr,''), @CodCliente = T0.CardCode FROM [dbo].[OPDN] T0 WHERE T0.DocEntry = @sKeyVal END
          IF @sObjTyp = 14 BEGIN SELECT @NFENUMERO = T0.Serial, @NFESERIE = ISNULL(T0.SeriesStr,''), @CodCliente = T0.CardCode FROM [dbo].[ORIN] T0 WHERE T0.DocEntry = @sKeyVal END
          IF @sObjTyp = 16 BEGIN SELECT @NFENUMERO = T0.Serial, @NFESERIE = ISNULL(T0.SeriesStr,''), @CodCliente = T0.CardCode FROM [dbo].[ORDN] T0 WHERE T0.DocEntry = @sKeyVal END
      
          set @sTmp = ''
          set @iTmp = 0
          
          -- Deixa passar modelo vazio, SAP não tem cancelamento de nota somente imposto.
          -- Nota de Entrada.
          SELECT @iTmp = MAX(T0.DocEntry) FROM [dbo].[OPCH] T0 
                 WHERE T0.DocEntry <> @sKeyVal and 
                       T0.CardCode = @CodCliente and ISNULL(T0.SeriesStr,'') = @NFESERIE and T0.Serial = @NFENUMERO and 
                       ISNULL(t0.model,'0') <> '0' and
                       T0.CANCELED = 'N' and 
                       T0.SeqCode = -2 and
                       T0.DocEntry NOT IN 
                         (SELECT T4.BaseEntry FROM ORPC T3 INNER JOIN RPC1 T4 ON T3.DocEntry = T4.DocEntry WHERE T4.BaseEntry IS NOT NULL and  T4.BaseType = T0.ObjType and T3.SeqCode = 1) -- NAO ENTRA CANCELADA
          if ISNULL(@iTmp,0) <> 0 
          BEGIN
             set @sTmp = 'Nota Fiscal Entrada'
          END
          
          -- Recebimento de Mercadorias
          if ISNULL(@iTmp,0) = 0 
          BEGIN                 
             SELECT @iTmp = MAX(T0.DocEntry) FROM [dbo].[OPDN] T0 
                    WHERE T0.DocEntry <> @sKeyVal and 
                          T0.CardCode = @CodCliente and ISNULL(T0.SeriesStr,'') = @NFESERIE and T0.Serial = @NFENUMERO and 
                          ISNULL(t0.model,'0') <> '0' and
                          T0.CANCELED = 'N' and 
                          T0.SeqCode = -2 and
                          T0.DocEntry NOT IN 
                            (SELECT T4.BaseEntry FROM ORPD T3 INNER JOIN RPD1 T4 ON T3.DocEntry = T4.DocEntry WHERE T4.BaseEntry IS NOT NULL and  T4.BaseType = T0.ObjType and T3.SeqCode = 1) -- NAO ENTRA CANCELADA
              if ISNULL(@iTmp,0) <> 0 
              BEGIN
                 set @sTmp = 'Recebimento de Mercadorias'
              END
          END
    
          -- Devolução Nota Fiscal Saida
          if ISNULL(@iTmp,0) = 0 
          BEGIN                 
             SELECT @iTmp = MAX(T0.DocEntry) FROM [dbo].[ORIN] T0 
                    WHERE T0.DocEntry <> @sKeyVal and 
                          T0.CardCode = @CodCliente and ISNULL(T0.SeriesStr,'') = @NFESERIE and T0.Serial = @NFENUMERO and 
                          ISNULL(t0.model,'0') <> '0' and
                          T0.CANCELED = 'N' and 
                          T0.SeqCode = -2 
              if ISNULL(@iTmp,0) <> 0 
              BEGIN
                 set @sTmp = 'Dev. Nota Fiscal Saida'
              END
          END
    
          -- Devolução Entrega
          if ISNULL(@iTmp,0) = 0 
          BEGIN                 
             SELECT @iTmp = MAX(T0.DocEntry) FROM [dbo].[ORDN] T0 
                    WHERE T0.DocEntry <> @sKeyVal and 
                          T0.CardCode = @CodCliente and ISNULL(T0.SeriesStr,'') = @NFESERIE and T0.Serial = @NFENUMERO and 
                          ISNULL(t0.model,'0') <> '0' and
                          T0.CANCELED = 'N' and 
                          T0.SeqCode = -2 
              if ISNULL(@iTmp,0) <> 0 
              BEGIN
                 SET @sTmp = 'Devolução Entrega'
              END
          END              
          
          IF ISNULL(@sTmp,'') <> '' 
          BEGIN                    
                SET @error=1
                SET @error_message = 'TI: Documento de entrada já lançado, verifique em "' + @sTmp + '", primário = ' + LTRIM(STR(@iTmp))                    
          END              
    END
    

    Espero ter ajudado

    Abraço

    Fabio

    SAP 8.82 PL16 / SAP 9.0 PL11

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Ah sim...

      Pois tenho uma pesquisa formatada tb, porém a minha só puxa o código... Acredito que com sua pesquisa vá funcionar...

      Vou fazer o teste e caso ok valido sua ajuda, ok??

      Obrigado!!

  • avatar image
    Former Member
    Aug 02, 2014 at 05:06 PM

    Buenas, Veja se isto lhe ajuda: IF(@object_type = '18') BEGIN            DECLARE @CardCode          VARCHAR(60)              DECLARE @Chave  VARCHAR(120)            DECLARE @NFE              INT            DECLARE @MODEL            INT                  Select @CardCode = isnull(OPCH.CardCode,''),             @NFE = isnull(OPCH.Serial,0),           @MODEL = ISNULL(OPCH.model,0),           @Chave = ISNULL(OPCH.U_MMQCHAVENFE,'')           from OPCH  where OPCH.DocEntry = @list_of_cols_val_tab_del                          -- VERIFICA SE JA TEM NOTA FISCAL COM O MESMO NUMERO PARA O MESMO FORNECEDOR              IF (@transaction_type = 'A' or @transaction_type = 'U')    BEGIN               IF EXISTS(SELECT 0 FROM OPCH WHERE OPCH.DocEntry <> @list_of_cols_val_tab_del                   and OPCH.CardCode = @CardCode and OPCH.Serial = @NFE and OPCH.Model = @model and OPCH.invntsttus <> 'C') BEGIN                              SET @error = 0001;                   SET @error_message = 'SAP - Esta nota fiscal ja esta lançada no sistema.'               END           END end;

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 11, 2014 at 05:07 PM

    Ok. Obrigado.

    Add comment
    10|10000 characters needed characters exceeded