/*
CERSAO DO SCRIPT: 218
DATA: 22/02/2016
*/

SET QUOTED_IDENTIFIER OFF
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ABERTURA_ESTOQUE_ECF_FILIAL_D' AND type = 'TR')
  drop trigger ABERTURA_ESTOQUE_ECF_FILIAL_D
go
create trigger dbo.ABERTURA_ESTOQUE_ECF_FILIAL_D on dbo.ABERTURA_ESTOQUE_ECF_FILIAL for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ABERTURA_ESTOQUE_ECF_FILIAL WHERE 
OID = '+ RTRIM(LTRIM(CAST(OID as char(120)))) + ' ','ABERTURA_ESTOQUE_ECF_FILIAL' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ABERTURA_ESTOQUE_ECF_FILIAL_I' AND type = 'TR')
   drop trigger ABERTURA_ESTOQUE_ECF_FILIAL_I
go
create trigger dbo.ABERTURA_ESTOQUE_ECF_FILIAL_I on dbo.ABERTURA_ESTOQUE_ECF_FILIAL for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ABERTURA_ESTOQUE_ECF_FILIAL(
        FILIAL,    OIDSERIALECF,    SERIALECF,    DATA)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+'
     '+ ')', 'ABERTURA_ESTOQUE_ECF_FILIAL' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ABERTURA_ESTOQUE_ECF_FILIAL_U' AND type = 'TR')
   drop trigger ABERTURA_ESTOQUE_ECF_FILIAL_U
go
create trigger dbo.ABERTURA_ESTOQUE_ECF_FILIAL_U on dbo.ABERTURA_ESTOQUE_ECF_FILIAL for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ABERTURA_ESTOQUE_ECF_FILIAL SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDSERIALECF = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**],    SERIALECF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+  ' WHERE     OID = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'  , 'ABERTURA_ESTOQUE_ECF_FILIAL' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARGA_D' AND type = 'TR')
  drop trigger CARGA_D
go
create trigger dbo.CARGA_D on dbo.CARGA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CARGA WHERE 
NUMEROLISTA = '+ RTRIM(LTRIM(CAST(NUMEROLISTA as char(120)))) + ' ','CARGA' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARGA_I' AND type = 'TR')
   drop trigger CARGA_I
go
create trigger dbo.CARGA_I on dbo.CARGA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CARGA(
        CODTRAN,    NUMEROLISTA,    PLACA,    IMPRIMIUMAPACARGA)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(IMPRIMIUMAPACARGA AS CHAR(254)))),0) +'
     '+ ')', 'CARGA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARGA_U' AND type = 'TR')
   drop trigger CARGA_U
go
create trigger dbo.CARGA_U on dbo.CARGA for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CARGA SET     CODTRAN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PLACA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IMPRIMIUMAPACARGA = '+ ISNULL(LTRIM(RTRIM(CAST(IMPRIMIUMAPACARGA AS CHAR(254)))),0) +''+  ' WHERE NUMEROLISTA = '+ RTRIM(CAST(NUMEROLISTA as char(254))) +  ''   , 'CARGA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARVOLUFAT_D' AND type = 'TR')
  drop trigger CARVOLUFAT_D
go
create trigger dbo.CARVOLUFAT_D on dbo.CARVOLUFAT for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CARVOLUFAT WHERE 
ITEM = '+ RTRIM(LTRIM(CAST(ITEM as char(120)))) + ' ','CARVOLUFAT' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARVOLUFAT_INST_I' AND type = 'TR')
   drop trigger CARVOLUFAT_INST_I
go
create trigger dbo.CARVOLUFAT_INST_I on dbo.CARVOLUFAT INSTEAD OF insert as
begin
    SELECT * INTO #Inserted FROM Inserted
    UPDATE #Inserted SET item = (@@spid*-1)
    INSERT INTO CARVOLUFAT SELECT * FROM #Inserted
    Return
end
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARVOLUFAT_I' AND type = 'TR')
   drop trigger CARVOLUFAT_I
go
create trigger dbo.CARVOLUFAT_I on dbo.CARVOLUFAT for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CARVOLUFAT(
        NUMORD,    MARCA,    NUMERO,    QUANTID,    ESPECIE,    PESOBRUTO,    PESOLIQU,    NUMORDFIS,    IMPOGER,    ITEM)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MARCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMERO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTID AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESPECIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PESOBRUTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PESOLIQU AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +'
     '+ ')', 'CARVOLUFAT' FROM inserted
    declare @nContador integer
    exec GERASEMENTE_P 'TW_IDENTIFICADOR', 7, @nContador OUTPUT
    if @nContador > 0
      update CARVOLUFAT set ITEM = @nContador WHERE ITEM = (select ITEM from inserted WHERE ITEM=(@@spid*-1))
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARVOLUFAT_U' AND type = 'TR')
   drop trigger CARVOLUFAT_U
go
create trigger dbo.CARVOLUFAT_U on dbo.CARVOLUFAT for update as
begin
  if (select count(*) from deleted where item = @@spid*-1 ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CARVOLUFAT SET     NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    MARCA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MARCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMERO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMERO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTID = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTID AS CHAR(254)))),0) +',    ESPECIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESPECIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PESOBRUTO = '+ ISNULL(LTRIM(RTRIM(CAST(PESOBRUTO AS CHAR(254)))),0) +',    PESOLIQU = '+ ISNULL(LTRIM(RTRIM(CAST(PESOLIQU AS CHAR(254)))),0) +',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +''+  ' WHERE item = '+ ISNULL(LTRIM(RTRIM(CAST((@@spid*-1) AS CHAR(254)))),0) , 'CARVOLUFAT' FROM inserted
 else
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CARVOLUFAT SET     NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    MARCA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MARCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMERO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMERO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTID = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTID AS CHAR(254)))),0) +',    ESPECIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESPECIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PESOBRUTO = '+ ISNULL(LTRIM(RTRIM(CAST(PESOBRUTO AS CHAR(254)))),0) +',    PESOLIQU = '+ ISNULL(LTRIM(RTRIM(CAST(PESOLIQU AS CHAR(254)))),0) +',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +''+  ' WHERE ITEM = '+ RTRIM(CAST(ITEM as char(254))) +  ''   , 'CARVOLUFAT' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARVOLUPEDIDO_D' AND type = 'TR')
  drop trigger CARVOLUPEDIDO_D
go
create trigger dbo.CARVOLUPEDIDO_D on dbo.CARVOLUPEDIDO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CARVOLUPEDIDO WHERE 
NumPed = '+ RTRIM(LTRIM(CAST(NumPed as char(120)))) + '  and PaginaOrdemSeparacao = '+ RTRIM(LTRIM(CAST(PaginaOrdemSeparacao as char(120)))) + '  and SequenciaOrdemSeparacao = '''+ RTRIM(LTRIM(SequenciaOrdemSeparacao)) + '''  and numeroLista = '+ RTRIM(LTRIM(CAST(numeroLista as char(120)))) + ' ','CARVOLUPEDIDO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARVOLUPEDIDO_I' AND type = 'TR')
   drop trigger CARVOLUPEDIDO_I
go
create trigger dbo.CARVOLUPEDIDO_I on dbo.CARVOLUPEDIDO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CARVOLUPEDIDO(
        NUMPED,    PAGINAORDEMSEPARACAO,    SEQUENCIAORDEMSEPARACAO,    QTDEVOLUME,    IMPETIQUETA,    TIPOVOLUME,    NUMEROLISTA,    IDCLIENTECENTROCUSTO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PAGINAORDEMSEPARACAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SEQUENCIAORDEMSEPARACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QTDEVOLUME AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPETIQUETA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOVOLUME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IDCLIENTECENTROCUSTO AS CHAR(254)))),0) +'
     '+ ')', 'CARVOLUPEDIDO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CARVOLUPEDIDO_U' AND type = 'TR')
   drop trigger CARVOLUPEDIDO_U
go
create trigger dbo.CARVOLUPEDIDO_U on dbo.CARVOLUPEDIDO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CARVOLUPEDIDO SET     QTDEVOLUME = '+ ISNULL(LTRIM(RTRIM(CAST(QTDEVOLUME AS CHAR(254)))),0) +',    IMPETIQUETA = '+ ISNULL(LTRIM(RTRIM(CAST(IMPETIQUETA AS CHAR(254)))),0) +',    TIPOVOLUME = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOVOLUME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IDCLIENTECENTROCUSTO = '+ ISNULL(LTRIM(RTRIM(CAST(IDCLIENTECENTROCUSTO AS CHAR(254)))),0) +''+  ' WHERE NumPed = '+ RTRIM(CAST(NumPed as char(254))) +  ' and PaginaOrdemSeparacao = '+ RTRIM(CAST(PaginaOrdemSeparacao as char(254))) +  ' and SequenciaOrdemSeparacao = '''+ RTRIM(SequenciaOrdemSeparacao)  + ''' and numeroLista = '+ RTRIM(CAST(numeroLista as char(254))) +  ''   , 'CARVOLUPEDIDO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOENTRCAD_D' AND type = 'TR')
  drop trigger CFOENTRCAD_D
go
create trigger dbo.CFOENTRCAD_D on dbo.CFOENTRCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CFOENTRCAD WHERE 
numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + '  and cfo = '''+ RTRIM(LTRIM(cfo)) + ''' ','CFOENTRCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOENTRCAD_I' AND type = 'TR')
   drop trigger CFOENTRCAD_I
go
create trigger dbo.CFOENTRCAD_I on dbo.CFOENTRCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CFOENTRCAD(
        NUMNOTA,    SERIE,    CODFOR,    NUMORD,    CFO,    CODNATOP,    BASEICM,    BASEICM2,    BASEICM3,    BASEICM4,    BASEICM5,    ALQICM,    ALQICM2,    ALQICM3,    ALQICM4,    ALQICM5,    VALICM,    VALICM2,    VALICM3,    VALICM4,    VALICM5,    OUTRICM,    VALSEMICM,    BASEIPI,    ALIQIPI,    VALIPI,    OUTRIPI,    VALSEMIPI,    BASESTRIB,    VALSUBSTRI,    VRIPI,    OBSVALORIPI,    OBSBASESUBSTRI,    OBSVALSUBSTRI,    OBSBASESTANTECIPADA,    OBSVALSTANTECIPADA,    OBSVALICMSSTANTECIPADA,    BASEEXCEDENTE)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODFOR AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODNATOP AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(BASEICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEMICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEMIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VRIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALORIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESTANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSTANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALICMSSTANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEEXCEDENTE AS CHAR(254)))),0) +'
     '+ ')', 'CFOENTRCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOENTRCAD_U' AND type = 'TR')
   drop trigger CFOENTRCAD_U
go
create trigger dbo.CFOENTRCAD_U on dbo.CFOENTRCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CFOENTRCAD SET     NUMNOTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODFOR = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODFOR AS CHAR(254)))),0) +'**],    CODNATOP = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODNATOP AS CHAR(254)))),0) +'**],    BASEICM = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM AS CHAR(254)))),0) +',    BASEICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM2 AS CHAR(254)))),0) +',    BASEICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM3 AS CHAR(254)))),0) +',    BASEICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM4 AS CHAR(254)))),0) +',    BASEICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM5 AS CHAR(254)))),0) +',    ALQICM = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM AS CHAR(254)))),0) +',    ALQICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM2 AS CHAR(254)))),0) +',    ALQICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM3 AS CHAR(254)))),0) +',    ALQICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM4 AS CHAR(254)))),0) +',    ALQICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM5 AS CHAR(254)))),0) +',    VALICM = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM AS CHAR(254)))),0) +',    VALICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM2 AS CHAR(254)))),0) +',    VALICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM3 AS CHAR(254)))),0) +',    VALICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM4 AS CHAR(254)))),0) +',    VALICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM5 AS CHAR(254)))),0) +',    OUTRICM = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRICM AS CHAR(254)))),0) +',    VALSEMICM = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEMICM AS CHAR(254)))),0) +',    BASEIPI = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +',    ALIQIPI = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +',    VALIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +',    OUTRIPI = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRIPI AS CHAR(254)))),0) +',    VALSEMIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEMIPI AS CHAR(254)))),0) +',    BASESTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +',    VALSUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +',    VRIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VRIPI AS CHAR(254)))),0) +',    OBSVALORIPI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALORIPI AS CHAR(254)))),0) +',    OBSBASESUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESUBSTRI AS CHAR(254)))),0) +',    OBSVALSUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSUBSTRI AS CHAR(254)))),0) +',    OBSBASESTANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESTANTECIPADA AS CHAR(254)))),0) +',    OBSVALSTANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSTANTECIPADA AS CHAR(254)))),0) +',    OBSVALICMSSTANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALICMSSTANTECIPADA AS CHAR(254)))),0) +',    BASEEXCEDENTE = '+ ISNULL(LTRIM(RTRIM(CAST(BASEEXCEDENTE AS CHAR(254)))),0) +''+  ' WHERE numord = '+ RTRIM(CAST(numord as char(254))) +  ' and cfo = '''+ RTRIM(cfo)  + ''''   , 'CFOENTRCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOENTRCOMPLEMENTO_D' AND type = 'TR')
  drop trigger CFOENTRCOMPLEMENTO_D
go
create trigger dbo.CFOENTRCOMPLEMENTO_D on dbo.CFOENTRCOMPLEMENTO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CFOENTRCOMPLEMENTO WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and CFO = '''+ RTRIM(LTRIM(CFO)) + ''' ','CFOENTRCOMPLEMENTO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOENTRCOMPLEMENTO_I' AND type = 'TR')
   drop trigger CFOENTRCOMPLEMENTO_I
go
create trigger dbo.CFOENTRCOMPLEMENTO_I on dbo.CFOENTRCOMPLEMENTO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CFOENTRCOMPLEMENTO(
        NUMORD,    CFO,    ISENTOICMBASEREDUZIDA,    ISENTOICMNAOTRIBUTADA,    ISENTOICMOUTRAS,    OUTRASICMSUBSTRIB,    OUTRASICMSUSPENSO,    OUTRASICMDIFERIDO,    BASEOUTRASICM1,    BASEOUTRASICM2,    BASEOUTRASICM3,    BASEOUTRASICM4,    BASEOUTRASICM5,    ALIQOUTRASICM1,    ALIQOUTRASICM2,    ALIQOUTRASICM3,    ALIQOUTRASICM4,    ALIQOUTRASICM5,    BASEIPI1,    BASEIPI2,    BASEIPI3,    BASEIPI4,    BASEIPI5,    ALIQIPI1,    ALIQIPI2,    ALIQIPI3,    ALIQIPI4,    ALIQIPI5,    VALORIPI1,    VALORIPI2,    VALORIPI3,    VALORIPI4,    VALORIPI5,    BASEICMSSOBREIPI,    VALORICMSSOBREIPI,    ISENTOICMSSOBREIPI,    VALTRIBANTECIPADA,    BASETRIBANTECIPADA,    VALORCREDITOICMSST,    SITUACAOST,    PIS,    COFINS,    BASECAL_PIS,    BASECAL_COFINS,    VALOR_PIS,    VALOR_COFINS,    CST_PIS,    CST_COFINS)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMBASEREDUZIDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMNAOTRIBUTADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMOUTRAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMSUBSTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMSUSPENSO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMDIFERIDO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSSOBREIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSSOBREIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMSSOBREIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALTRIBANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASETRIBANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORCREDITOICMSST AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAOST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_PIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_COFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALOR_PIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALOR_COFINS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_PIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_COFINS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'CFOENTRCOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOENTRCOMPLEMENTO_U' AND type = 'TR')
   drop trigger CFOENTRCOMPLEMENTO_U
go
create trigger dbo.CFOENTRCOMPLEMENTO_U on dbo.CFOENTRCOMPLEMENTO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CFOENTRCOMPLEMENTO SET     ISENTOICMBASEREDUZIDA = '+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMBASEREDUZIDA AS CHAR(254)))),0) +',    ISENTOICMNAOTRIBUTADA = '+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMNAOTRIBUTADA AS CHAR(254)))),0) +',    ISENTOICMOUTRAS = '+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMOUTRAS AS CHAR(254)))),0) +',    OUTRASICMSUBSTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMSUBSTRIB AS CHAR(254)))),0) +',    OUTRASICMSUSPENSO = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMSUSPENSO AS CHAR(254)))),0) +',    OUTRASICMDIFERIDO = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMDIFERIDO AS CHAR(254)))),0) +',    BASEOUTRASICM1 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM1 AS CHAR(254)))),0) +',    BASEOUTRASICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM2 AS CHAR(254)))),0) +',    BASEOUTRASICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM3 AS CHAR(254)))),0) +',    BASEOUTRASICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM4 AS CHAR(254)))),0) +',    BASEOUTRASICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM5 AS CHAR(254)))),0) +',    ALIQOUTRASICM1 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM1 AS CHAR(254)))),0) +',    ALIQOUTRASICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM2 AS CHAR(254)))),0) +',    ALIQOUTRASICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM3 AS CHAR(254)))),0) +',    ALIQOUTRASICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM4 AS CHAR(254)))),0) +',    ALIQOUTRASICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM5 AS CHAR(254)))),0) +',    BASEIPI1 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI1 AS CHAR(254)))),0) +',    BASEIPI2 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI2 AS CHAR(254)))),0) +',    BASEIPI3 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI3 AS CHAR(254)))),0) +',    BASEIPI4 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI4 AS CHAR(254)))),0) +',    BASEIPI5 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI5 AS CHAR(254)))),0) +',    ALIQIPI1 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI1 AS CHAR(254)))),0) +',    ALIQIPI2 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI2 AS CHAR(254)))),0) +',    ALIQIPI3 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI3 AS CHAR(254)))),0) +',    ALIQIPI4 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI4 AS CHAR(254)))),0) +',    ALIQIPI5 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI5 AS CHAR(254)))),0) +',    VALORIPI1 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI1 AS CHAR(254)))),0) +',    VALORIPI2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI2 AS CHAR(254)))),0) +',    VALORIPI3 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI3 AS CHAR(254)))),0) +',    VALORIPI4 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI4 AS CHAR(254)))),0) +',    VALORIPI5 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI5 AS CHAR(254)))),0) +',    BASEICMSSOBREIPI = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSSOBREIPI AS CHAR(254)))),0) +',    VALORICMSSOBREIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSSOBREIPI AS CHAR(254)))),0) +',    ISENTOICMSSOBREIPI = '+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMSSOBREIPI AS CHAR(254)))),0) +',    VALTRIBANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(VALTRIBANTECIPADA AS CHAR(254)))),0) +',    BASETRIBANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(BASETRIBANTECIPADA AS CHAR(254)))),0) +',    VALORCREDITOICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(VALORCREDITOICMSST AS CHAR(254)))),0) +',    SITUACAOST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAOST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PIS = '+ ISNULL(LTRIM(RTRIM(CAST(PIS AS CHAR(254)))),0) +',    COFINS = '+ ISNULL(LTRIM(RTRIM(CAST(COFINS AS CHAR(254)))),0) +',    BASECAL_PIS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_PIS AS CHAR(254)))),0) +',    BASECAL_COFINS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_COFINS AS CHAR(254)))),0) +',    VALOR_PIS = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR_PIS AS CHAR(254)))),0) +',    VALOR_COFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR_COFINS AS CHAR(254)))),0) +',    CST_PIS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_PIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CST_COFINS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_COFINS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and CFO = '''+ RTRIM(CFO)  + ''''   , 'CFOENTRCOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOSAIDCAD_D' AND type = 'TR')
  drop trigger CFOSAIDCAD_D
go
create trigger dbo.CFOSAIDCAD_D on dbo.CFOSAIDCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CFOSAIDCAD WHERE 
numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + '  and cfo = '''+ RTRIM(LTRIM(cfo)) + ''' ','CFOSAIDCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOSAIDCAD_I' AND type = 'TR')
   drop trigger CFOSAIDCAD_I
go
create trigger dbo.CFOSAIDCAD_I on dbo.CFOSAIDCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CFOSAIDCAD(
        NUMNOTA,    SERIE,    CODCLIE,    NUMORD,    CFO,    CODNATOP,    BASEICM,    BASEICM2,    BASEICM3,    BASEICM4,    BASEICM5,    ALQICM,    ALQICM2,    ALQICM3,    ALQICM4,    ALQICM5,    VALICM,    VALICM2,    VALICM3,    VALICM4,    VALICM5,    OUTRICM,    VALSEMICM,    BASEIPI,    ALIQIPI,    VALIPI,    OUTRIPI,    VALSEMIPI,    VALSUBSTRI,    VALTRIBDIF,    PERCSUBST,    BASESTRIB,    OBSVALORIPI,    OBSBASESUBSTRI,    OBSVALSUBSTRI,    NOVOIPI,    BASEEXCEDENTE)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODNATOP AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(BASEICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEMICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEMIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALTRIBDIF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCSUBST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALORIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NOVOIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEEXCEDENTE AS CHAR(254)))),0) +'
     '+ ')', 'CFOSAIDCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOSAIDCAD_U' AND type = 'TR')
   drop trigger CFOSAIDCAD_U
go
create trigger dbo.CFOSAIDCAD_U on dbo.CFOSAIDCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CFOSAIDCAD SET     NUMNOTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODCLIE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],    CODNATOP = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODNATOP AS CHAR(254)))),0) +'**],    BASEICM = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM AS CHAR(254)))),0) +',    BASEICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM2 AS CHAR(254)))),0) +',    BASEICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM3 AS CHAR(254)))),0) +',    BASEICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM4 AS CHAR(254)))),0) +',    BASEICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM5 AS CHAR(254)))),0) +',    ALQICM = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM AS CHAR(254)))),0) +',    ALQICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM2 AS CHAR(254)))),0) +',    ALQICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM3 AS CHAR(254)))),0) +',    ALQICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM4 AS CHAR(254)))),0) +',    ALQICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM5 AS CHAR(254)))),0) +',    VALICM = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM AS CHAR(254)))),0) +',    VALICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM2 AS CHAR(254)))),0) +',    VALICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM3 AS CHAR(254)))),0) +',    VALICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM4 AS CHAR(254)))),0) +',    VALICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM5 AS CHAR(254)))),0) +',    OUTRICM = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRICM AS CHAR(254)))),0) +',    VALSEMICM = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEMICM AS CHAR(254)))),0) +',    BASEIPI = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +',    ALIQIPI = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +',    VALIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +',    OUTRIPI = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRIPI AS CHAR(254)))),0) +',    VALSEMIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEMIPI AS CHAR(254)))),0) +',    VALSUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +',    VALTRIBDIF = '+ ISNULL(LTRIM(RTRIM(CAST(VALTRIBDIF AS CHAR(254)))),0) +',    PERCSUBST = '+ ISNULL(LTRIM(RTRIM(CAST(PERCSUBST AS CHAR(254)))),0) +',    BASESTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +',    OBSVALORIPI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALORIPI AS CHAR(254)))),0) +',    OBSBASESUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESUBSTRI AS CHAR(254)))),0) +',    OBSVALSUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSUBSTRI AS CHAR(254)))),0) +',    NOVOIPI = '+ ISNULL(LTRIM(RTRIM(CAST(NOVOIPI AS CHAR(254)))),0) +',    BASEEXCEDENTE = '+ ISNULL(LTRIM(RTRIM(CAST(BASEEXCEDENTE AS CHAR(254)))),0) +''+  ' WHERE numord = '+ RTRIM(CAST(numord as char(254))) +  ' and cfo = '''+ RTRIM(cfo)  + ''''   , 'CFOSAIDCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOSAIDCOMPLEMENTO_D' AND type = 'TR')
  drop trigger CFOSAIDCOMPLEMENTO_D
go
create trigger dbo.CFOSAIDCOMPLEMENTO_D on dbo.CFOSAIDCOMPLEMENTO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CFOSAIDCOMPLEMENTO WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and CFO = '''+ RTRIM(LTRIM(CFO)) + ''' ','CFOSAIDCOMPLEMENTO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOSAIDCOMPLEMENTO_I' AND type = 'TR')
   drop trigger CFOSAIDCOMPLEMENTO_I
go
create trigger dbo.CFOSAIDCOMPLEMENTO_I on dbo.CFOSAIDCOMPLEMENTO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CFOSAIDCOMPLEMENTO(
        NUMORD,    CFO,    ISENTOICMBASEREDUZIDA,    ISENTOICMNAOTRIBUTADA,    ISENTOICMOUTRAS,    OUTRASICMSUBSTRIB,    OUTRASICMSUSPENSO,    OUTRASICMDIFERIDO,    BASEOUTRASICM1,    BASEOUTRASICM2,    BASEOUTRASICM3,    BASEOUTRASICM4,    BASEOUTRASICM5,    ALIQOUTRASICM1,    ALIQOUTRASICM2,    ALIQOUTRASICM3,    ALIQOUTRASICM4,    ALIQOUTRASICM5,    BASEIPI1,    BASEIPI2,    BASEIPI3,    BASEIPI4,    BASEIPI5,    ALIQIPI1,    ALIQIPI2,    ALIQIPI3,    ALIQIPI4,    ALIQIPI5,    VALORIPI1,    VALORIPI2,    VALORIPI3,    VALORIPI4,    VALORIPI5,    BASEICMSSOBREIPI,    VALORICMSSOBREIPI,    ISENTOICMSSOBREIPI)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMBASEREDUZIDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMNAOTRIBUTADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMOUTRAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMSUBSTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMSUSPENSO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMDIFERIDO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSSOBREIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSSOBREIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMSSOBREIPI AS CHAR(254)))),0) +'
     '+ ')', 'CFOSAIDCOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CFOSAIDCOMPLEMENTO_U' AND type = 'TR')
   drop trigger CFOSAIDCOMPLEMENTO_U
go
create trigger dbo.CFOSAIDCOMPLEMENTO_U on dbo.CFOSAIDCOMPLEMENTO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CFOSAIDCOMPLEMENTO SET     ISENTOICMBASEREDUZIDA = '+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMBASEREDUZIDA AS CHAR(254)))),0) +',    ISENTOICMNAOTRIBUTADA = '+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMNAOTRIBUTADA AS CHAR(254)))),0) +',    ISENTOICMOUTRAS = '+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMOUTRAS AS CHAR(254)))),0) +',    OUTRASICMSUBSTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMSUBSTRIB AS CHAR(254)))),0) +',    OUTRASICMSUSPENSO = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMSUSPENSO AS CHAR(254)))),0) +',    OUTRASICMDIFERIDO = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASICMDIFERIDO AS CHAR(254)))),0) +',    BASEOUTRASICM1 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM1 AS CHAR(254)))),0) +',    BASEOUTRASICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM2 AS CHAR(254)))),0) +',    BASEOUTRASICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM3 AS CHAR(254)))),0) +',    BASEOUTRASICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM4 AS CHAR(254)))),0) +',    BASEOUTRASICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEOUTRASICM5 AS CHAR(254)))),0) +',    ALIQOUTRASICM1 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM1 AS CHAR(254)))),0) +',    ALIQOUTRASICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM2 AS CHAR(254)))),0) +',    ALIQOUTRASICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM3 AS CHAR(254)))),0) +',    ALIQOUTRASICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM4 AS CHAR(254)))),0) +',    ALIQOUTRASICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQOUTRASICM5 AS CHAR(254)))),0) +',    BASEIPI1 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI1 AS CHAR(254)))),0) +',    BASEIPI2 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI2 AS CHAR(254)))),0) +',    BASEIPI3 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI3 AS CHAR(254)))),0) +',    BASEIPI4 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI4 AS CHAR(254)))),0) +',    BASEIPI5 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI5 AS CHAR(254)))),0) +',    ALIQIPI1 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI1 AS CHAR(254)))),0) +',    ALIQIPI2 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI2 AS CHAR(254)))),0) +',    ALIQIPI3 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI3 AS CHAR(254)))),0) +',    ALIQIPI4 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI4 AS CHAR(254)))),0) +',    ALIQIPI5 = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI5 AS CHAR(254)))),0) +',    VALORIPI1 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI1 AS CHAR(254)))),0) +',    VALORIPI2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI2 AS CHAR(254)))),0) +',    VALORIPI3 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI3 AS CHAR(254)))),0) +',    VALORIPI4 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI4 AS CHAR(254)))),0) +',    VALORIPI5 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI5 AS CHAR(254)))),0) +',    BASEICMSSOBREIPI = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSSOBREIPI AS CHAR(254)))),0) +',    VALORICMSSOBREIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSSOBREIPI AS CHAR(254)))),0) +',    ISENTOICMSSOBREIPI = '+ ISNULL(LTRIM(RTRIM(CAST(ISENTOICMSSOBREIPI AS CHAR(254)))),0) +''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and CFO = '''+ RTRIM(CFO)  + ''''   , 'CFOSAIDCOMPLEMENTO' FROM inserted
    return
end
go
--============================================================================================================== 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CHAVEUNICA_I' AND type = 'TR')
   drop trigger CHAVEUNICA_I
go
create trigger dbo.CHAVEUNICA_I on dbo.CHAVEUNICA for insert as
begin
  if not exists (select 1 from inserted where descricao like '%MONITOR%'or substring(descricao,3,10)='OIDHISTPED' or substring(descricao,3,7)='SANGRIA' or substring(descricao,3,2)='SL' or substring(inserted.descricao,3,6)='NUMDAV')
  BEGIN 
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CHAVEUNICA(
        OID,    DESCRICAO)
    VALUES (
      [**OID'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCRICAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'CHAVEUNICA' FROM inserted
  END 
    return
end
go
--================================================================================================================= 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CHEVISTCAD_D' AND type = 'TR')
  drop trigger CHEVISTCAD_D
go
create trigger dbo.CHEVISTCAD_D on dbo.CHEVISTCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CHEVISTCAD WHERE 
documen = '''+ RTRIM(LTRIM(documen)) + ''' ','CHEVISTCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CHEVISTCAD_I' AND type = 'TR')
   drop trigger CHEVISTCAD_I
go
create trigger dbo.CHEVISTCAD_I on dbo.CHEVISTCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CHEVISTCAD(
        DOCUMEN,    VALOR,    DATACHE,    HORA,    CGCCPF,    NUMCHEQ,    FILIAL,    EXPORTADO)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DOCUMEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATACHE,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CGCCPF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCHEQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'CHEVISTCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CHEVISTCAD_U' AND type = 'TR')
   drop trigger CHEVISTCAD_U
go
create trigger dbo.CHEVISTCAD_U on dbo.CHEVISTCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CHEVISTCAD SET     VALOR = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +',    DATACHE = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATACHE,20)))+''',120)','NULL')+',    HORA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CGCCPF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CGCCPF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMCHEQ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCHEQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    EXPORTADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE documen = '''+ RTRIM(documen)  + ''''   , 'CHEVISTCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CLIENTENOTA_D' AND type = 'TR')
  drop trigger CLIENTENOTA_D
go
create trigger dbo.CLIENTENOTA_D on dbo.CLIENTENOTA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CLIENTENOTA WHERE 
NumPed = '+ RTRIM(LTRIM(CAST(NumPed as char(120)))) + ' ','CLIENTENOTA' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CLIENTENOTA_I' AND type = 'TR')
   drop trigger CLIENTENOTA_I
go
create trigger dbo.CLIENTENOTA_I on dbo.CLIENTENOTA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CLIENTENOTA(
        NUMPED,    NOME,    ENDERECO,    BAIRRO,    CIDADE,    UF,    CEP,    FONE,    CONTRIBUINTE,    INSCREST,    CNPJ,    CODCLIE)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FONE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CONTRIBUINTE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCREST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**]
     '+ ')', 'CLIENTENOTA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CLIENTENOTA_U' AND type = 'TR')
   drop trigger CLIENTENOTA_U
go
create trigger dbo.CLIENTENOTA_U on dbo.CLIENTENOTA for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CLIENTENOTA SET     NOME = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ENDERECO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BAIRRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CIDADE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FONE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FONE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONTRIBUINTE = '+ ISNULL(LTRIM(RTRIM(CAST(CONTRIBUINTE AS CHAR(254)))),0) +',    INSCREST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCREST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CNPJ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODCLIE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**]'+  ' WHERE NumPed = '+ RTRIM(CAST(NumPed as char(254))) +  ''   , 'CLIENTENOTA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLEMENTONFENTRA_D' AND type = 'TR')
  drop trigger COMPLEMENTONFENTRA_D
go
create trigger dbo.COMPLEMENTONFENTRA_D on dbo.COMPLEMENTONFENTRA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM COMPLEMENTONFENTRA WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + ' ','COMPLEMENTONFENTRA' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLEMENTONFENTRA_I' AND type = 'TR')
   drop trigger COMPLEMENTONFENTRA_I
go
create trigger dbo.COMPLEMENTONFENTRA_I on dbo.COMPLEMENTONFENTRA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO COMPLEMENTONFENTRA(
        NUMORD,    NUMORDNFVENDA,    OBSQUALIFICACAO,    DIFICMS,    CONSIGNADO,    NUMORDCONSIGNACAO,    VOLUMECONCRETODEVOLVIDO,    PERCENTUALPIS,    PERCENTUALCOFINS,    COMEMISSAO,    FLAGEMIT,    LIBERAPRECO,    NUMPEDPRODREL,    OBSERVACAO,    PRIORIDADE,    AIDF,    JUROS,    MULTA,    NUMORDTRANSFERENCIA,    FRETEPORPESO,    NUMEROLISTACONFERENCIA,    STATUSCONFERENCIA,    NUMORDSAIDACOMPONENTE,    SITUACAONFE,    NUMEROPROTOCOLO,    CODIGONFE,    RECIBONFE,    CHAVEDEACESSONFE,    SALDOINICIAL,    JUSTIFICATIVA,    LOTENFE,    LIBQTDEVALORCOMPRA,    LIBCONDPAGTOCOMPRA,    CREDITODEVOLUCAO,    OIDDOCDEORIGEMCOMISSAO,    AGUARDACONFIRMACAONFDEVOLUCAO,    PERCSTFRETE,    COMPOSICAOCALCULOST,    FLAGEMITCONTINGENCIA,    PENDENCIAINTEGRARLIVRO,    DI,    DATADI,    LOCALDESEMBARACO,    UFDESEMBARACO,    DTDESEMBARACOADUANEIRO,    VALSEGURO,    NUMORDTRANSF,    NUMORDCONTINGENCIA,    RECIBODPEC,    NUMEROPROTOCOLOCANCELAMENTO,    NUMEROPROTOCOLOINUTILIZACAO,    FINNFE,    NUMPEDAUTOMATICO,    ADE_ATODECLARATORIO,    ADE_MODELODOCUMENTO,    ADE_SERIEDOCUMENTO,    ADE_NUMERODOCUMENTO,    ADE_DATADOCUMENTO,    ADE_PARTICIPANTE,    USULIBCANCELAMENTONF,    FLAGPISCOFINS,    ATUALIZALOCALFISICO,    BASESTDADOSADICIONAIS,    VALORSTDADOSADICIONAIS,    DHPROTOCOLO,    DHRECIBODPEC,    DHCANCELAMENTO,    DHINUTILIZACAO,    VALORACRESCIMO,    VALSERVICO,    INTEGRASAGA,    FLAGRENTABI,    CODVENDEXT,    FLAGCRIACAO,    PERCICMSFRETE,    VALORICMSFRETE,    BASEICMSFRETE,    IMPOGER,    COD_INF_COMPL,    DES_INF_COMPL)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDNFVENDA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSQUALIFICACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(DIFICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CONSIGNADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDCONSIGNACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VOLUMECONCRETODEVOLVIDO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COMEMISSAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBERAPRECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDPRODREL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRIORIDADE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AIDF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(JUROS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MULTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDTRANSFERENCIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FRETEPORPESO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTACONFERENCIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(STATUSCONFERENCIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDSAIDACOMPONENTE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CODIGONFE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RECIBONFE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CHAVEDEACESSONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SALDOINICIAL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(JUSTIFICATIVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTENFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBQTDEVALORCOMPRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBCONDPAGTOCOMPRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CREDITODEVOLUCAO AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEMCOMISSAO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(AGUARDACONFIRMACAONFDEVOLUCAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCSTFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPOSICAOCALCULOST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMITCONTINGENCIA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PENDENCIAINTEGRARLIVRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATADI,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOCALDESEMBARACO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFDESEMBARACO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTDESEMBARACOADUANEIRO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VALSEGURO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDTRANSF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDCONTINGENCIA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RECIBODPEC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLOCANCELAMENTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLOINUTILIZACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FINNFE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAUTOMATICO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_ATODECLARATORIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_MODELODOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_SERIEDOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_NUMERODOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ADE_DATADOCUMENTO,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_PARTICIPANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(USULIBCANCELAMENTONF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGPISCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZALOCALFISICO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASESTDADOSADICIONAIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORSTDADOSADICIONAIS AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHPROTOCOLO,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHRECIBODPEC,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHCANCELAMENTO,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHINUTILIZACAO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VALORACRESCIMO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSERVICO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTEGRASAGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FLAGRENTABI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVENDEXT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FLAGCRIACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCICMSFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COD_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DES_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'COMPLEMENTONFENTRA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLEMENTONFENTRA_U' AND type = 'TR')
   drop trigger COMPLEMENTONFENTRA_U
go
create trigger dbo.COMPLEMENTONFENTRA_U on dbo.COMPLEMENTONFENTRA for update as
begin
   If (SELECT COUNT(1) FROM sys.dm_exec_sessions where session_id = @@spid and program_name not like 'MUImportarContingencia%' ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE COMPLEMENTONFENTRA SET     NUMORDNFVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDNFVENDA AS CHAR(254)))),0) +',    OBSQUALIFICACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSQUALIFICACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DIFICMS = '+ ISNULL(LTRIM(RTRIM(CAST(DIFICMS AS CHAR(254)))),0) +',    CONSIGNADO = '+ ISNULL(LTRIM(RTRIM(CAST(CONSIGNADO AS CHAR(254)))),0) +',    NUMORDCONSIGNACAO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDCONSIGNACAO AS CHAR(254)))),0) +',    VOLUMECONCRETODEVOLVIDO = '+ ISNULL(LTRIM(RTRIM(CAST(VOLUMECONCRETODEVOLVIDO AS CHAR(254)))),0) +',    PERCENTUALPIS = '+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALPIS AS CHAR(254)))),0) +',    PERCENTUALCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALCOFINS AS CHAR(254)))),0) +',    COMEMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(COMEMISSAO AS CHAR(254)))),0) +',    FLAGEMIT = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),0) +',    LIBERAPRECO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBERAPRECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDPRODREL = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDPRODREL AS CHAR(254)))),0) +',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PRIORIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(PRIORIDADE AS CHAR(254)))),0) +',    AIDF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AIDF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    JUROS = '+ ISNULL(LTRIM(RTRIM(CAST(JUROS AS CHAR(254)))),0) +',    MULTA = '+ ISNULL(LTRIM(RTRIM(CAST(MULTA AS CHAR(254)))),0) +',    NUMORDTRANSFERENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDTRANSFERENCIA AS CHAR(254)))),0) +',    FRETEPORPESO = '+ ISNULL(LTRIM(RTRIM(CAST(FRETEPORPESO AS CHAR(254)))),0) +',    NUMEROLISTACONFERENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTACONFERENCIA AS CHAR(254)))),0) +',    STATUSCONFERENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(STATUSCONFERENCIA AS CHAR(254)))),0) +',    NUMORDSAIDACOMPONENTE = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDSAIDACOMPONENTE AS CHAR(254)))),0) +',    SITUACAONFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROPROTOCOLO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLO AS CHAR(254)))),0) +',    CODIGONFE = '+ ISNULL(LTRIM(RTRIM(CAST(CODIGONFE AS CHAR(254)))),0) +',    RECIBONFE = '+ ISNULL(LTRIM(RTRIM(CAST(RECIBONFE AS CHAR(254)))),0) +',    CHAVEDEACESSONFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CHAVEDEACESSONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SALDOINICIAL = '+ ISNULL(LTRIM(RTRIM(CAST(SALDOINICIAL AS CHAR(254)))),0) +',    JUSTIFICATIVA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(JUSTIFICATIVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOTENFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTENFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBQTDEVALORCOMPRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBQTDEVALORCOMPRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBCONDPAGTOCOMPRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBCONDPAGTOCOMPRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CREDITODEVOLUCAO = '+ ISNULL(LTRIM(RTRIM(CAST(CREDITODEVOLUCAO AS CHAR(254)))),0) +',    OIDDOCDEORIGEMCOMISSAO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEMCOMISSAO AS CHAR(254)))),0) +'**],    AGUARDACONFIRMACAONFDEVOLUCAO = '+ ISNULL(LTRIM(RTRIM(CAST(AGUARDACONFIRMACAONFDEVOLUCAO AS CHAR(254)))),0) +',    PERCSTFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(PERCSTFRETE AS CHAR(254)))),0) +',    COMPOSICAOCALCULOST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPOSICAOCALCULOST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGEMITCONTINGENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMITCONTINGENCIA AS CHAR(254)))),0) +',    PENDENCIAINTEGRARLIVRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PENDENCIAINTEGRARLIVRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATADI = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATADI,20)))+''',120)','NULL')+',    LOCALDESEMBARACO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOCALDESEMBARACO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UFDESEMBARACO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFDESEMBARACO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTDESEMBARACOADUANEIRO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTDESEMBARACOADUANEIRO,20)))+''',120)','NULL')+',    VALSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEGURO AS CHAR(254)))),0) +',    NUMORDTRANSF = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDTRANSF AS CHAR(254)))),0) +',    NUMORDCONTINGENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDCONTINGENCIA AS CHAR(254)))),0) +',    RECIBODPEC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RECIBODPEC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROPROTOCOLOCANCELAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLOCANCELAMENTO AS CHAR(254)))),0) +',    NUMEROPROTOCOLOINUTILIZACAO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLOINUTILIZACAO AS CHAR(254)))),0) +',    FINNFE = '+ ISNULL(LTRIM(RTRIM(CAST(FINNFE AS CHAR(254)))),0) +',    NUMPEDAUTOMATICO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAUTOMATICO AS CHAR(254)))),0) +',    ADE_ATODECLARATORIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_ATODECLARATORIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ADE_MODELODOCUMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_MODELODOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ADE_SERIEDOCUMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_SERIEDOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ADE_NUMERODOCUMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_NUMERODOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ADE_DATADOCUMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ADE_DATADOCUMENTO,20)))+''',120)','NULL')+',    ADE_PARTICIPANTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_PARTICIPANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    USULIBCANCELAMENTONF = '+ ISNULL(LTRIM(RTRIM(CAST(USULIBCANCELAMENTONF AS CHAR(254)))),0) +',    FLAGPISCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGPISCOFINS AS CHAR(254)))),0) +',    ATUALIZALOCALFISICO = '+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZALOCALFISICO AS CHAR(254)))),0) +',    BASESTDADOSADICIONAIS = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTDADOSADICIONAIS AS CHAR(254)))),0) +',    VALORSTDADOSADICIONAIS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSTDADOSADICIONAIS AS CHAR(254)))),0) +',    DHPROTOCOLO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHPROTOCOLO,20)))+''',120)','NULL')+',    DHRECIBODPEC = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHRECIBODPEC,20)))+''',120)','NULL')+',    DHCANCELAMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHCANCELAMENTO,20)))+''',120)','NULL')+',    DHINUTILIZACAO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHINUTILIZACAO,20)))+''',120)','NULL')+',    VALORACRESCIMO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORACRESCIMO AS CHAR(254)))),0) +',    VALSERVICO = '+ ISNULL(LTRIM(RTRIM(CAST(VALSERVICO AS CHAR(254)))),0) +',    INTEGRASAGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTEGRASAGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGRENTABI = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGRENTABI AS CHAR(254)))),0) +',    CODVENDEXT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVENDEXT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGCRIACAO = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGCRIACAO AS CHAR(254)))),0) +',    PERCICMSFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(PERCICMSFRETE AS CHAR(254)))),0) +',    VALORICMSFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSFRETE AS CHAR(254)))),0) +',    BASEICMSFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSFRETE AS CHAR(254)))),0) +',    IMPOGER = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COD_INF_COMPL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COD_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DES_INF_COMPL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DES_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ''   , 'COMPLEMENTONFENTRA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLEMENTONFSAIDA_D' AND type = 'TR')
  drop trigger COMPLEMENTONFSAIDA_D
go
create trigger dbo.COMPLEMENTONFSAIDA_D on dbo.COMPLEMENTONFSAIDA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM COMPLEMENTONFSAIDA WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + ' ','COMPLEMENTONFSAIDA' from deleted
    End
go
--==================================================================================================== 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLEMENTONFSAIDA_I2' AND type = 'TR')
   drop trigger COMPLEMENTONFSAIDA_I2
go
create trigger dbo.COMPLEMENTONFSAIDA_I2 on dbo.COMPLEMENTONFSAIDA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO COMPLEMENTONFSAIDA(
        NUMORD,    NUMORDNFVENDA,    TIPOFRETE,    VALORFRETEDESTACADO,    BASEICMDESTACADO,    PERCICMDESTACADO,    VALORICMFRETE,    EXPEDIDOR,    MOTORISTA,    NUMPEDREGIONAL,    GERARNFSERVICO,    OIDCONTRATANTE,    PREVISAOENTREGA,    NUMORDPRODPROPRIO,    CONSULTASUFRAMA,    RESPONSAVELCONSULTA,    SITUACAOCADASTROSUFRAMA,    MOEDA,    COTACAOMOEDA,    FRETEPAGAR,    CODIGOREGIAO,    STATUSCONSIGNACAO,    PLACA,    KMATUAL,    KMMES,    PERCENTUALPIS,    PERCENTUALCOFINS,    MARKUPREALTOTAL,    ITINERARIO,    ORDEM,    CODVENDEXT,    NUMPEDPRODREL,    NUMEROEMPENHO,    UNIDADEEXECUTORA,    VALORICMSDISPENSADO,    MANUAL,    OBSERVACAO,    CLASSE,    VALCUSTOFRETE,    AIDF,    VALORICMFRETEO,    ISSCIDADE,    FLAGPESOALTERADO,    RATENDIMENTO,    DESCONTOSUFRAMA,    CODPROCONJ,    QUANTCONJ,    SITUACAONFE,    NUMEROPROTOCOLO,    CODIGONFE,    RECIBONFE,    CHAVEDEACESSONFE,    OIDDOCDEORIGEMFRETE,    JUSTIFICATIVA,    LOTENFE,    OIDDOCDEORIGEMCOMISSAO,    FLAGEMITCONTINGENCIA,    FILIALNFE,    FINNFE,    DTEMIS,    ETIQUETAEMITIDA,    DESCONTODEVOLUCAO,    PERCENTUALCOMISSAO,    NFEIMPORTADA,    VALORACRESCIMO,    NUMORDCONTINGENCIA,    RECIBODPEC,    NUMEROPROTOCOLOCANCELAMENTO,    NUMEROPROTOCOLOINUTILIZACAO,    NUMPEDAUTOMATICO,    ADE_ATODECLARATORIO,    ADE_MODELODOCUMENTO,    ADE_SERIEDOCUMENTO,    ADE_NUMERODOCUMENTO,    ADE_DATADOCUMENTO,    ADE_PARTICIPANTE,    USULIBCANCELAMENTONF,    RECEBIMENTOTEF,    REDZMANUAL,    FLAGPISCOFINS,    DHPROTOCOLO,    DHRECIBODPEC,    DHCANCELAMENTO,    DHINUTILIZACAO,    VALORDESCONTOPISCOFINS,    FLAGRENTABI,    TOTALTRIBUTO,    DHEMISSAO,    COD_INF_COMPL,    DES_INF_COMPL,    FLAGCRIACAO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDNFVENDA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETEDESTACADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMDESTACADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCICMDESTACADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EXPEDIDOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTORISTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDREGIONAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(GERARNFSERVICO AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCONTRATANTE AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,PREVISAOENTREGA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDPRODPROPRIO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,CONSULTASUFRAMA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESPONSAVELCONSULTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SITUACAOCADASTROSUFRAMA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MOEDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COTACAOMOEDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FRETEPAGAR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CODIGOREGIAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(STATUSCONSIGNACAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(KMATUAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(KMMES AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MARKUPREALTOTAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITINERARIO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ORDEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVENDEXT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDPRODREL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROEMPENHO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDADEEXECUTORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSDISPENSADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MANUAL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASSE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AIDF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMFRETEO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ISSCIDADE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGPESOALTERADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RATENDIMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOSUFRAMA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPROCONJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTCONJ AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CODIGONFE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RECIBONFE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CHAVEDEACESSONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEMFRETE AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(JUSTIFICATIVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTENFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEMCOMISSAO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMITCONTINGENCIA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALNFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FINNFE AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMIS,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(ETIQUETAEMITIDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTODEVOLUCAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALCOMISSAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFEIMPORTADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORACRESCIMO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDCONTINGENCIA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RECIBODPEC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLOCANCELAMENTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLOINUTILIZACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAUTOMATICO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_ATODECLARATORIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_MODELODOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_SERIEDOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_NUMERODOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ADE_DATADOCUMENTO,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_PARTICIPANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(USULIBCANCELAMENTONF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RECEBIMENTOTEF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(REDZMANUAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGPISCOFINS AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHPROTOCOLO,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHRECIBODPEC,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHCANCELAMENTO,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHINUTILIZACAO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTOPISCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGRENTABI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TOTALTRIBUTO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHEMISSAO,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COD_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DES_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FLAGCRIACAO AS CHAR(254)))),0) +'
     '+ ')', 'COMPLEMENTONFSAIDA' FROM inserted
    return
end
go
--======================================================================================================= 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLEMENTONFSAIDA_U' AND type = 'TR')
   drop trigger COMPLEMENTONFSAIDA_U
go
create trigger dbo.COMPLEMENTONFSAIDA_U on dbo.COMPLEMENTONFSAIDA for update as
begin
   If (SELECT COUNT(1) FROM sys.dm_exec_sessions where session_id = @@spid and program_name not like 'MUImportarContingencia%' ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE COMPLEMENTONFSAIDA SET     NUMORDNFVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDNFVENDA AS CHAR(254)))),0) +',    TIPOFRETE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORFRETEDESTACADO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETEDESTACADO AS CHAR(254)))),0) +',    BASEICMDESTACADO = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICMDESTACADO AS CHAR(254)))),0) +',    PERCICMDESTACADO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCICMDESTACADO AS CHAR(254)))),0) +',    VALORICMFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMFRETE AS CHAR(254)))),0) +',    EXPEDIDOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EXPEDIDOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MOTORISTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTORISTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDREGIONAL = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDREGIONAL AS CHAR(254)))),0) +',    GERARNFSERVICO = '+ ISNULL(LTRIM(RTRIM(CAST(GERARNFSERVICO AS CHAR(254)))),0) +',    OIDCONTRATANTE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCONTRATANTE AS CHAR(254)))),0) +'**],    PREVISAOENTREGA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,PREVISAOENTREGA,20)))+''',120)','NULL')+',    NUMORDPRODPROPRIO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDPRODPROPRIO AS CHAR(254)))),0) +',    CONSULTASUFRAMA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,CONSULTASUFRAMA,20)))+''',120)','NULL')+',    RESPONSAVELCONSULTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESPONSAVELCONSULTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITUACAOCADASTROSUFRAMA = '+ ISNULL(LTRIM(RTRIM(CAST(SITUACAOCADASTROSUFRAMA AS CHAR(254)))),0) +',    MOEDA = '+ ISNULL(LTRIM(RTRIM(CAST(MOEDA AS CHAR(254)))),0) +',    COTACAOMOEDA = '+ ISNULL(LTRIM(RTRIM(CAST(COTACAOMOEDA AS CHAR(254)))),0) +',    FRETEPAGAR = '+ ISNULL(LTRIM(RTRIM(CAST(FRETEPAGAR AS CHAR(254)))),0) +',    CODIGOREGIAO = '+ ISNULL(LTRIM(RTRIM(CAST(CODIGOREGIAO AS CHAR(254)))),0) +',    STATUSCONSIGNACAO = '+ ISNULL(LTRIM(RTRIM(CAST(STATUSCONSIGNACAO AS CHAR(254)))),0) +',    PLACA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    KMATUAL = '+ ISNULL(LTRIM(RTRIM(CAST(KMATUAL AS CHAR(254)))),0) +',    KMMES = '+ ISNULL(LTRIM(RTRIM(CAST(KMMES AS CHAR(254)))),0) +',    PERCENTUALPIS = '+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALPIS AS CHAR(254)))),0) +',    PERCENTUALCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALCOFINS AS CHAR(254)))),0) +',    MARKUPREALTOTAL = '+ ISNULL(LTRIM(RTRIM(CAST(MARKUPREALTOTAL AS CHAR(254)))),0) +',    ITINERARIO = '+ ISNULL(LTRIM(RTRIM(CAST(ITINERARIO AS CHAR(254)))),0) +',    ORDEM = '+ ISNULL(LTRIM(RTRIM(CAST(ORDEM AS CHAR(254)))),0) +',    CODVENDEXT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVENDEXT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDPRODREL = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDPRODREL AS CHAR(254)))),0) +',    NUMEROEMPENHO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROEMPENHO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UNIDADEEXECUTORA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDADEEXECUTORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORICMSDISPENSADO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSDISPENSADO AS CHAR(254)))),0) +',    MANUAL = '+ ISNULL(LTRIM(RTRIM(CAST(MANUAL AS CHAR(254)))),0) +',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CLASSE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASSE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALCUSTOFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOFRETE AS CHAR(254)))),0) +',    AIDF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AIDF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORICMFRETEO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMFRETEO AS CHAR(254)))),0) +',    ISSCIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(ISSCIDADE AS CHAR(254)))),0) +',    FLAGPESOALTERADO = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGPESOALTERADO AS CHAR(254)))),0) +',    RATENDIMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RATENDIMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCONTOSUFRAMA = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOSUFRAMA AS CHAR(254)))),0) +',    CODPROCONJ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPROCONJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTCONJ = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTCONJ AS CHAR(254)))),0) +',    SITUACAONFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROPROTOCOLO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLO AS CHAR(254)))),0) +',    CODIGONFE = '+ ISNULL(LTRIM(RTRIM(CAST(CODIGONFE AS CHAR(254)))),0) +',    RECIBONFE = '+ ISNULL(LTRIM(RTRIM(CAST(RECIBONFE AS CHAR(254)))),0) +',    CHAVEDEACESSONFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CHAVEDEACESSONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDDOCDEORIGEMFRETE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEMFRETE AS CHAR(254)))),0) +'**],    JUSTIFICATIVA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(JUSTIFICATIVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOTENFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTENFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDDOCDEORIGEMCOMISSAO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEMCOMISSAO AS CHAR(254)))),0) +'**],    FLAGEMITCONTINGENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMITCONTINGENCIA AS CHAR(254)))),0) +',    FILIALNFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALNFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FINNFE = '+ ISNULL(LTRIM(RTRIM(CAST(FINNFE AS CHAR(254)))),0) +',    DTEMIS = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMIS,20)))+''',120)','NULL')+',    ETIQUETAEMITIDA = '+ ISNULL(LTRIM(RTRIM(CAST(ETIQUETAEMITIDA AS CHAR(254)))),0) +',    DESCONTODEVOLUCAO = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTODEVOLUCAO AS CHAR(254)))),0) +',    PERCENTUALCOMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALCOMISSAO AS CHAR(254)))),0) +',    NFEIMPORTADA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFEIMPORTADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORACRESCIMO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORACRESCIMO AS CHAR(254)))),0) +',    NUMORDCONTINGENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDCONTINGENCIA AS CHAR(254)))),0) +',    RECIBODPEC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RECIBODPEC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROPROTOCOLOCANCELAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLOCANCELAMENTO AS CHAR(254)))),0) +',    NUMEROPROTOCOLOINUTILIZACAO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROPROTOCOLOINUTILIZACAO AS CHAR(254)))),0) +',    NUMPEDAUTOMATICO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAUTOMATICO AS CHAR(254)))),0) +',    ADE_ATODECLARATORIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_ATODECLARATORIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ADE_MODELODOCUMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_MODELODOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ADE_SERIEDOCUMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_SERIEDOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ADE_NUMERODOCUMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_NUMERODOCUMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ADE_DATADOCUMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ADE_DATADOCUMENTO,20)))+''',120)','NULL')+',    ADE_PARTICIPANTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ADE_PARTICIPANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    USULIBCANCELAMENTONF = '+ ISNULL(LTRIM(RTRIM(CAST(USULIBCANCELAMENTONF AS CHAR(254)))),0) +',    RECEBIMENTOTEF = '+ ISNULL(LTRIM(RTRIM(CAST(RECEBIMENTOTEF AS CHAR(254)))),0) +',    REDZMANUAL = '+ ISNULL(LTRIM(RTRIM(CAST(REDZMANUAL AS CHAR(254)))),0) +',    FLAGPISCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGPISCOFINS AS CHAR(254)))),0) +',    DHPROTOCOLO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHPROTOCOLO,20)))+''',120)','NULL')+',    DHRECIBODPEC = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHRECIBODPEC,20)))+''',120)','NULL')+',    DHCANCELAMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHCANCELAMENTO,20)))+''',120)','NULL')+',    DHINUTILIZACAO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHINUTILIZACAO,20)))+''',120)','NULL')+',    VALORDESCONTOPISCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTOPISCOFINS AS CHAR(254)))),0) +',    FLAGRENTABI = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGRENTABI AS CHAR(254)))),0) +',    TOTALTRIBUTO = '+ ISNULL(LTRIM(RTRIM(CAST(TOTALTRIBUTO AS CHAR(254)))),0) +',    DHEMISSAO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHEMISSAO,20)))+''',120)','NULL')+',    COD_INF_COMPL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COD_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DES_INF_COMPL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DES_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGCRIACAO = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGCRIACAO AS CHAR(254)))),0) +''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ''   , 'COMPLEMENTONFSAIDA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLNFFAT_D' AND type = 'TR')
  drop trigger COMPLNFFAT_D
go
create trigger dbo.COMPLNFFAT_D on dbo.COMPLNFFAT for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM COMPLNFFAT WHERE 
numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + ' ','COMPLNFFAT' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLNFFAT_I' AND type = 'TR')
   drop trigger COMPLNFFAT_I
go
create trigger dbo.COMPLNFFAT_I on dbo.COMPLNFFAT for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO COMPLNFFAT(
        NUMORD,    RAZSOC,    CGC,    INSCREST,    ENDERECO,    BAIRRO,    CIDADE,    ESTADO,    CEP,    ENDENTR,    BAIRENTR,    CIDENTR,    ESTENTR,    CEPENTR,    CODENDENT,    OBSERV,    PLACA,    FLAGMENS,    CODENDCOB,    FLAGCARVO,    FLAGTEXLI,    DTSAI,    CONTLINHA,    PERICMS,    VALICMS,    VALFRETAU,    UF_VEIC,    TIPOFRETE,    OBSPED,    PESSOA,    NUMEROSELO,    SERIESELO,    FONE,    NUMORDFIS,    IMPOGER,    IMPDTSAI,    CGC_CPFMOTORISTA,    LOGRADOURO,    NUMERO,    COMPLEMENTO,    COD_INF_COMPL,    DES_INF_COMPL)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RAZSOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CGC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCREST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODENDENT AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGMENS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODENDCOB AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGCARVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGTEXLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSAI,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(CONTLINHA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALFRETAU AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF_VEIC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PESSOA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROSELO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIESELO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FONE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IMPDTSAI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CGC_CPFMOTORISTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOGRADOURO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMERO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLEMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COD_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DES_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'COMPLNFFAT' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'COMPLNFFAT_U' AND type = 'TR')
   drop trigger COMPLNFFAT_U
go
create trigger dbo.COMPLNFFAT_U on dbo.COMPLNFFAT for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE COMPLNFFAT SET     RAZSOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RAZSOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CGC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CGC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INSCREST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCREST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ENDERECO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BAIRRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CIDADE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ENDENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BAIRENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CIDENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEPENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODENDENT = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODENDENT AS CHAR(254)))),0) +'**],    OBSERV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PLACA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGMENS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGMENS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODENDCOB = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODENDCOB AS CHAR(254)))),0) +'**],    FLAGCARVO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGCARVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGTEXLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGTEXLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTSAI = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSAI,20)))+''',120)','NULL')+',    CONTLINHA = '+ ISNULL(LTRIM(RTRIM(CAST(CONTLINHA AS CHAR(254)))),0) +',    PERICMS = '+ ISNULL(LTRIM(RTRIM(CAST(PERICMS AS CHAR(254)))),0) +',    VALICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VALICMS AS CHAR(254)))),0) +',    VALFRETAU = '+ ISNULL(LTRIM(RTRIM(CAST(VALFRETAU AS CHAR(254)))),0) +',    UF_VEIC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF_VEIC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOFRETE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBSPED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PESSOA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PESSOA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROSELO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROSELO AS CHAR(254)))),0) +',    SERIESELO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIESELO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FONE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FONE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    IMPDTSAI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IMPDTSAI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CGC_CPFMOTORISTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CGC_CPFMOTORISTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOGRADOURO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOGRADOURO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMERO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMERO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COMPLEMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLEMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COD_INF_COMPL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COD_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DES_INF_COMPL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DES_INF_COMPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE numord = '+ RTRIM(CAST(numord as char(254))) +  ''   , 'COMPLNFFAT' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREBARRA_D' AND type = 'TR')
  drop trigger CONFEREBARRA_D
go
create trigger dbo.CONFEREBARRA_D on dbo.CONFEREBARRA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CONFEREBARRA WHERE 
Filial = '''+ RTRIM(LTRIM(Filial)) + '''  and NumPed = '+ RTRIM(LTRIM(CAST(NumPed as char(120)))) + '  and CodPro = '''+ RTRIM(LTRIM(CodPro)) + ''' ','CONFEREBARRA' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREBARRA_I' AND type = 'TR')
   drop trigger CONFEREBARRA_I
go
create trigger dbo.CONFEREBARRA_I on dbo.CONFEREBARRA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CONFEREBARRA(
        FILIAL,    NUMPED,    CODPRO,    QTDCONFERIDO)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDO AS CHAR(254)))),0) +'
     '+ ')', 'CONFEREBARRA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREBARRA_U' AND type = 'TR')
   drop trigger CONFEREBARRA_U
go
create trigger dbo.CONFEREBARRA_U on dbo.CONFEREBARRA for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CONFEREBARRA SET     QTDCONFERIDO = '+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDO AS CHAR(254)))),0) +''+  ' WHERE Filial = '''+ RTRIM(Filial)  + ''' and NumPed = '+ RTRIM(CAST(NumPed as char(254))) +  ' and CodPro = '''+ RTRIM(CodPro)  + ''''   , 'CONFEREBARRA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFERENCIASAIDANF_D' AND type = 'TR')
  drop trigger CONFERENCIASAIDANF_D
go
create trigger dbo.CONFERENCIASAIDANF_D on dbo.CONFERENCIASAIDANF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CONFERENCIASAIDANF WHERE 
NUMEROLISTA = '+ RTRIM(LTRIM(CAST(NUMEROLISTA as char(120)))) + ' ','CONFERENCIASAIDANF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFERENCIASAIDANF_I' AND type = 'TR')
   drop trigger CONFERENCIASAIDANF_I
go
create trigger dbo.CONFERENCIASAIDANF_I on dbo.CONFERENCIASAIDANF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CONFERENCIASAIDANF(
        NUMEROLISTA,    ULTIMA_CONF,    USUARIO_CONF,    STATUS,    QUANT_CONF)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ULTIMA_CONF,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(USUARIO_CONF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(STATUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANT_CONF AS CHAR(254)))),0) +'
     '+ ')', 'CONFERENCIASAIDANF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFERENCIASAIDANF_U' AND type = 'TR')
   drop trigger CONFERENCIASAIDANF_U
go
create trigger dbo.CONFERENCIASAIDANF_U on dbo.CONFERENCIASAIDANF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CONFERENCIASAIDANF SET     ULTIMA_CONF = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ULTIMA_CONF,20)))+''',120)','NULL')+',    USUARIO_CONF = '+ ISNULL(LTRIM(RTRIM(CAST(USUARIO_CONF AS CHAR(254)))),0) +',    STATUS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(STATUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANT_CONF = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT_CONF AS CHAR(254)))),0) +''+  ' WHERE NUMEROLISTA = '+ RTRIM(CAST(NUMEROLISTA as char(254))) +  ''   , 'CONFERENCIASAIDANF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREPEDIDO_D' AND type = 'TR')
  drop trigger CONFEREPEDIDO_D
go
create trigger dbo.CONFEREPEDIDO_D on dbo.CONFEREPEDIDO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CONFEREPEDIDO WHERE 
NUMEROLISTA = '+ RTRIM(LTRIM(CAST(NUMEROLISTA as char(120)))) + ' ','CONFEREPEDIDO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREPEDIDO_I' AND type = 'TR')
   drop trigger CONFEREPEDIDO_I
go
create trigger dbo.CONFEREPEDIDO_I on dbo.CONFEREPEDIDO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CONFEREPEDIDO(
        NUMEROLISTA,    FILIAL,    DATA,    OBSERVACAO,    EMUSO,    SITUACAO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(EMUSO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),0) +'
     '+ ')', 'CONFEREPEDIDO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREPEDIDO_U' AND type = 'TR')
   drop trigger CONFEREPEDIDO_U
go
create trigger dbo.CONFEREPEDIDO_U on dbo.CONFEREPEDIDO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CONFEREPEDIDO SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    EMUSO = '+ ISNULL(LTRIM(RTRIM(CAST(EMUSO AS CHAR(254)))),0) +',    SITUACAO = '+ ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),0) +''+  ' WHERE NUMEROLISTA = '+ RTRIM(CAST(NUMEROLISTA as char(254))) +  ''   , 'CONFEREPEDIDO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREPEDIDOITEM_D' AND type = 'TR')
  drop trigger CONFEREPEDIDOITEM_D
go
create trigger dbo.CONFEREPEDIDOITEM_D on dbo.CONFEREPEDIDOITEM for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CONFEREPEDIDOITEM WHERE 
NUMEROLISTA = '+ RTRIM(LTRIM(CAST(NUMEROLISTA as char(120)))) + '  and CODPRO = '''+ RTRIM(LTRIM(CODPRO)) + '''  and NUMPED = '+ RTRIM(LTRIM(CAST(NUMPED as char(120)))) + '  and NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and ITEM = '''+ RTRIM(LTRIM(ITEM)) + ''' ','CONFEREPEDIDOITEM' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREPEDIDOITEM_I' AND type = 'TR')
   drop trigger CONFEREPEDIDOITEM_I
go
create trigger dbo.CONFEREPEDIDOITEM_I on dbo.CONFEREPEDIDOITEM for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CONFEREPEDIDOITEM(
        NUMEROLISTA,    CODPRO,    QUANTCONFERIDA,    NUMPED,    NUMORD,    RITEMVOLUME,    ITEM)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTCONFERIDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RITEMVOLUME AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'CONFEREPEDIDOITEM' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREPEDIDOITEM_U' AND type = 'TR')
   drop trigger CONFEREPEDIDOITEM_U
go
create trigger dbo.CONFEREPEDIDOITEM_U on dbo.CONFEREPEDIDOITEM for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CONFEREPEDIDOITEM SET     QUANTCONFERIDA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTCONFERIDA AS CHAR(254)))),0) +',    RITEMVOLUME = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMVOLUME AS CHAR(254)))),0) +''+  ' WHERE NUMEROLISTA = '+ RTRIM(CAST(NUMEROLISTA as char(254))) +  ' and CODPRO = '''+ RTRIM(CODPRO)  + ''' and NUMPED = '+ RTRIM(CAST(NUMPED as char(254))) +  ' and NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and ITEM = '''+ RTRIM(ITEM)  + ''''   , 'CONFEREPEDIDOITEM' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREPEDIDOITEMLOTE_D' AND type = 'TR')
  drop trigger CONFEREPEDIDOITEMLOTE_D
go
create trigger dbo.CONFEREPEDIDOITEMLOTE_D on dbo.CONFEREPEDIDOITEMLOTE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CONFEREPEDIDOITEMLOTE WHERE 
NUMEROLISTA = '+ RTRIM(LTRIM(CAST(NUMEROLISTA as char(120)))) + ' ','CONFEREPEDIDOITEMLOTE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREPEDIDOITEMLOTE_I' AND type = 'TR')
   drop trigger CONFEREPEDIDOITEMLOTE_I
go
create trigger dbo.CONFEREPEDIDOITEMLOTE_I on dbo.CONFEREPEDIDOITEMLOTE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CONFEREPEDIDOITEMLOTE(
        NUMEROLISTA,    CODPRO,    LOTE,    QUANTCONFERIDA,    NUMPED,    NUMORD)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTCONFERIDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +'
     '+ ')', 'CONFEREPEDIDOITEMLOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFEREPEDIDOITEMLOTE_U' AND type = 'TR')
   drop trigger CONFEREPEDIDOITEMLOTE_U
go
create trigger dbo.CONFEREPEDIDOITEMLOTE_U on dbo.CONFEREPEDIDOITEMLOTE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CONFEREPEDIDOITEMLOTE SET     CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTCONFERIDA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTCONFERIDA AS CHAR(254)))),0) +',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +''+  ' WHERE NUMEROLISTA = '+ RTRIM(CAST(NUMEROLISTA as char(254))) +  ''   , 'CONFEREPEDIDOITEMLOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFERESAIDACOMLOTE_D' AND type = 'TR')
  drop trigger CONFERESAIDACOMLOTE_D
go
create trigger dbo.CONFERESAIDACOMLOTE_D on dbo.CONFERESAIDACOMLOTE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CONFERESAIDACOMLOTE WHERE 
RITEM = '+ RTRIM(LTRIM(CAST(RITEM as char(120)))) + '  and LOTEINTERNO = '''+ RTRIM(LTRIM(LOTEINTERNO)) + ''' ','CONFERESAIDACOMLOTE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFERESAIDACOMLOTE_I' AND type = 'TR')
   drop trigger CONFERESAIDACOMLOTE_I
go
create trigger dbo.CONFERESAIDACOMLOTE_I on dbo.CONFERESAIDACOMLOTE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CONFERESAIDACOMLOTE(
        RITEM,    LOTEINTERNO,    CARGA,    QTDCONFERIDO,    SITUACAO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(RITEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTEINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CARGA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'CONFERESAIDACOMLOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFERESAIDACOMLOTE_U' AND type = 'TR')
   drop trigger CONFERESAIDACOMLOTE_U
go
create trigger dbo.CONFERESAIDACOMLOTE_U on dbo.CONFERESAIDACOMLOTE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CONFERESAIDACOMLOTE SET     CARGA = '+ ISNULL(LTRIM(RTRIM(CAST(CARGA AS CHAR(254)))),0) +',    QTDCONFERIDO = '+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDO AS CHAR(254)))),0) +',    SITUACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE RITEM = '+ RTRIM(CAST(RITEM as char(254))) +  ' and LOTEINTERNO = '''+ RTRIM(LOTEINTERNO)  + ''''   , 'CONFERESAIDACOMLOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFERESEMLOTE_D' AND type = 'TR')
  drop trigger CONFERESEMLOTE_D
go
create trigger dbo.CONFERESEMLOTE_D on dbo.CONFERESEMLOTE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CONFERESEMLOTE WHERE 
Filial = '''+ RTRIM(LTRIM(Filial)) + '''  and NumPed = '+ RTRIM(LTRIM(CAST(NumPed as char(120)))) + '  and CodPro = '''+ RTRIM(LTRIM(CodPro)) + '''  and RItem = '+ RTRIM(LTRIM(CAST(RItem as char(120)))) + '  and RITEMVOLUME = '+ RTRIM(LTRIM(CAST(RITEMVOLUME as char(120)))) + ' ','CONFERESEMLOTE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFERESEMLOTE_I' AND type = 'TR')
   drop trigger CONFERESEMLOTE_I
go
create trigger dbo.CONFERESEMLOTE_I on dbo.CONFERESEMLOTE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CONFERESEMLOTE(
        FILIAL,    NUMPED,    CODPRO,    RITEM,    QTDCONFERIDO,    QTDDANIFICADO,    CARGA,    SITUACAO,    RITEMVOLUME)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QTDDANIFICADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CARGA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RITEMVOLUME AS CHAR(254)))),0) +'
     '+ ')', 'CONFERESEMLOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONFERESEMLOTE_U' AND type = 'TR')
   drop trigger CONFERESEMLOTE_U
go
create trigger dbo.CONFERESEMLOTE_U on dbo.CONFERESEMLOTE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CONFERESEMLOTE SET     QTDCONFERIDO = '+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDO AS CHAR(254)))),0) +',    QTDDANIFICADO = '+ ISNULL(LTRIM(RTRIM(CAST(QTDDANIFICADO AS CHAR(254)))),0) +',    CARGA = '+ ISNULL(LTRIM(RTRIM(CAST(CARGA AS CHAR(254)))),0) +',    SITUACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE Filial = '''+ RTRIM(Filial)  + ''' and NumPed = '+ RTRIM(CAST(NumPed as char(254))) +  ' and CodPro = '''+ RTRIM(CodPro)  + ''' and RItem = '+ RTRIM(CAST(RItem as char(254))) +  ' and RITEMVOLUME = '+ RTRIM(CAST(RITEMVOLUME as char(254))) +  ''   , 'CONFERESEMLOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONTAARECEBERCHEQUE_D' AND type = 'TR')
  drop trigger CONTAARECEBERCHEQUE_D
go
create trigger dbo.CONTAARECEBERCHEQUE_D on dbo.CONTAARECEBERCHEQUE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CONTAARECEBERCHEQUE WHERE 
OID = '+ RTRIM(LTRIM(CAST(OID as char(120)))) + ' ','CONTAARECEBERCHEQUE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONTAARECEBERCHEQUE_I' AND type = 'TR')
   drop trigger CONTAARECEBERCHEQUE_I
go
create trigger dbo.CONTAARECEBERCHEQUE_I on dbo.CONTAARECEBERCHEQUE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CONTAARECEBERCHEQUE(
        RATOLIGACAOCONTAPAGAR,    RFONTEPAGADORACP,    NOMEEMITENTE,    CPFCNPJEMITENTE,    NUMEROCHEQUE,    NUMEROBANCO,    NUMEROAGENCIA,    NUMEROCONTA,    RITEMPREVCLI,    OID,    RCONTAARECEBER)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(RATOLIGACAOCONTAPAGAR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RFONTEPAGADORACP AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOMEEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CPFCNPJEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROBANCO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROAGENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCONTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RITEMPREVCLI AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(RCONTAARECEBER AS CHAR(254)))),0) +'
     '+ ')', 'CONTAARECEBERCHEQUE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONTAARECEBERCHEQUE_U' AND type = 'TR')
   drop trigger CONTAARECEBERCHEQUE_U
go
create trigger dbo.CONTAARECEBERCHEQUE_U on dbo.CONTAARECEBERCHEQUE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CONTAARECEBERCHEQUE SET     RATOLIGACAOCONTAPAGAR = '+ ISNULL(LTRIM(RTRIM(CAST(RATOLIGACAOCONTAPAGAR AS CHAR(254)))),0) +',    RFONTEPAGADORACP = '+ ISNULL(LTRIM(RTRIM(CAST(RFONTEPAGADORACP AS CHAR(254)))),0) +',    NOMEEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOMEEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CPFCNPJEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CPFCNPJEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROCHEQUE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROBANCO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROBANCO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROAGENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROAGENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROCONTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCONTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RITEMPREVCLI = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMPREVCLI AS CHAR(254)))),0) +',    RCONTAARECEBER = '+ ISNULL(LTRIM(RTRIM(CAST(RCONTAARECEBER AS CHAR(254)))),0) +''+  ' WHERE     OID = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'  , 'CONTAARECEBERCHEQUE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONTROLEUSOECF_D' AND type = 'TR')
  drop trigger CONTROLEUSOECF_D
go
create trigger dbo.CONTROLEUSOECF_D on dbo.CONTROLEUSOECF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CONTROLEUSOECF WHERE 
Oid = '+ RTRIM(LTRIM(CAST(Oid as char(120)))) + ' ','CONTROLEUSOECF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONTROLEUSOECF_I' AND type = 'TR')
   drop trigger CONTROLEUSOECF_I
go
create trigger dbo.CONTROLEUSOECF_I on dbo.CONTROLEUSOECF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CONTROLEUSOECF(
        FILIAL,    SERIALECF,    DATAABERTURA,    RUSUARIOABERTURA,    DATAFECHAMENTO,    RUSUARIOFECHAMENTO,    OIDSERIALECF,    NUMECF)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAABERTURA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(RUSUARIOABERTURA AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAFECHAMENTO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(RUSUARIOFECHAMENTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'CONTROLEUSOECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CONTROLEUSOECF_U' AND type = 'TR')
   drop trigger CONTROLEUSOECF_U
go
create trigger dbo.CONTROLEUSOECF_U on dbo.CONTROLEUSOECF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CONTROLEUSOECF SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIALECF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATAABERTURA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAABERTURA,20)))+''',120)','NULL')+',    RUSUARIOABERTURA = '+ ISNULL(LTRIM(RTRIM(CAST(RUSUARIOABERTURA AS CHAR(254)))),0) +',    DATAFECHAMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAFECHAMENTO,20)))+''',120)','NULL')+',    RUSUARIOFECHAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(RUSUARIOFECHAMENTO AS CHAR(254)))),0) +',    OIDSERIALECF = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**],    NUMECF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE     Oid = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(Oid AS CHAR(254)))),0) +'**]'  , 'CONTROLEUSOECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CREDITODUPLICATAS_D' AND type = 'TR')
  drop trigger CREDITODUPLICATAS_D
go
create trigger dbo.CREDITODUPLICATAS_D on dbo.CREDITODUPLICATAS for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM CREDITODUPLICATAS WHERE 
NUMORDDEV = '+ RTRIM(LTRIM(CAST(NUMORDDEV as char(120)))) + '  and OIDCTRECEBER = '+ RTRIM(LTRIM(CAST(OIDCTRECEBER as char(120)))) + ' ','CREDITODUPLICATAS' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CREDITODUPLICATAS_I' AND type = 'TR')
   drop trigger CREDITODUPLICATAS_I
go
create trigger dbo.CREDITODUPLICATAS_I on dbo.CREDITODUPLICATAS for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO CREDITODUPLICATAS(
        NUMORDDEV,    NUMDUPLICA,    OIDCTRECEBER,    VRCREDITO,    DATA,    USUARIO,    OBS)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDDEV AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDUPLICA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCTRECEBER AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(VRCREDITO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'CREDITODUPLICATAS' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'CREDITODUPLICATAS_U' AND type = 'TR')
   drop trigger CREDITODUPLICATAS_U
go
create trigger dbo.CREDITODUPLICATAS_U on dbo.CREDITODUPLICATAS for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE CREDITODUPLICATAS SET     NUMDUPLICA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDUPLICA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VRCREDITO = '+ ISNULL(LTRIM(RTRIM(CAST(VRCREDITO AS CHAR(254)))),0) +',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    USUARIO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],    OBS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE NUMORDDEV = '+ RTRIM(CAST(NUMORDDEV as char(254))) +  ' and     OIDCTRECEBER = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCTRECEBER AS CHAR(254)))),0) +'**]'  , 'CREDITODUPLICATAS' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSCOBRANCANFE_D' AND type = 'TR')
  drop trigger DADOSCOBRANCANFE_D
go
create trigger dbo.DADOSCOBRANCANFE_D on dbo.DADOSCOBRANCANFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DADOSCOBRANCANFE WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and NDUP = '''+ RTRIM(LTRIM(NDUP)) + ''' ','DADOSCOBRANCANFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSCOBRANCANFE_I' AND type = 'TR')
   drop trigger DADOSCOBRANCANFE_I
go
create trigger dbo.DADOSCOBRANCANFE_I on dbo.DADOSCOBRANCANFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DADOSCOBRANCANFE(
        NUMORD,    NDUP,    VORIG,    VDESC,    VLIQ,    DVENC,    NDUPDANFE)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NDUP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VORIG AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VLIQ AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DVENC,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NDUPDANFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'DADOSCOBRANCANFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSCOBRANCANFE_U' AND type = 'TR')
   drop trigger DADOSCOBRANCANFE_U
go
create trigger dbo.DADOSCOBRANCANFE_U on dbo.DADOSCOBRANCANFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DADOSCOBRANCANFE SET     VORIG = '+ ISNULL(LTRIM(RTRIM(CAST(VORIG AS CHAR(254)))),0) +',    VDESC = '+ ISNULL(LTRIM(RTRIM(CAST(VDESC AS CHAR(254)))),0) +',    VLIQ = '+ ISNULL(LTRIM(RTRIM(CAST(VLIQ AS CHAR(254)))),0) +',    DVENC = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DVENC,20)))+''',120)','NULL')+',    NDUPDANFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NDUPDANFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and NDUP = '''+ RTRIM(NDUP)  + ''''   , 'DADOSCOBRANCANFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSITEMNFE_D' AND type = 'TR')
  drop trigger DADOSITEMNFE_D
go
create trigger dbo.DADOSITEMNFE_D on dbo.DADOSITEMNFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DADOSITEMNFE WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and NITEM = '+ RTRIM(LTRIM(CAST(NITEM as char(120)))) + ' ','DADOSITEMNFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSITEMNFE_I' AND type = 'TR')
   drop trigger DADOSITEMNFE_I
go
create trigger dbo.DADOSITEMNFE_I on dbo.DADOSITEMNFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DADOSITEMNFE(
        NUMORD,    NITEM,    CPROD,    CEAN,    XPROD,    NCM,    CFOP,    UTRIB,    QTRIB,    VPROD,    VFRETE,    VSEG,    VDESC,    ORIG,    CST,    VBC,    PICMS,    VICMS,    PREDBC,    VBCST,    PICMSST,    VICMSST,    PREDBCST,    VBCIPI,    PIPI,    VIPI,    CSTIPI,    UCOM,    QCOM,    VUNCOM,    VUNTRIB,    MODBC,    MODBCST,    PMVAST,    VBCPIS,    PPIS,    VPIS,    VBCOFINS,    PCOFINS,    VCOFINS,    VOUTRO,    CSTPIS,    CSTCOFINS,    INFADPROD,    NDI,    DDI,    XLOCDESEMB,    UFDESEMB,    DDESEMB,    CEXPORTADOR,    NADICAO,    NSEQADIC,    CFABRICANTE,    VDESCDI,    VBCIMP,    VDESPADU,    VII,    VIOF,    PCREDSN,    VCREDICMSSN,    CSOSN,    INDTOT,    VBCSTRET,    VICMSSTRET,    XPED,    NITEMPED,    CEANTRIB,    MOTDESICMS,    CPRODANP,    UFCONS,    NFCI,    VICMSDESON,    CENQIPI,    CEST,    VBCUFDEST,    PFCPUFDEST,    PICMSUFDEST,    PICMSINTER,    PICMSINTERPART,    VFCPUFDEST,    VICMSUFDEST,    VICMSUFREMET)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NITEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NCM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CFOP AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UTRIB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VPROD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VSEG AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ORIG AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PREDBC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBCST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PICMSST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VICMSST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PREDBCST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBCIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VIPI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CSTIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UCOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QCOM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VUNCOM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VUNTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MODBC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MODBCST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PMVAST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBCPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VOUTRO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CSTPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CSTCOFINS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFADPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NDI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DDI,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLOCDESEMB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFDESEMB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DDESEMB,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEXPORTADOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NADICAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NSEQADIC AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFABRICANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VDESCDI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBCIMP AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VDESPADU AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VII AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VIOF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PCREDSN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VCREDICMSSN AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CSOSN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INDTOT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VBCSTRET AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VICMSSTRET AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NITEMPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEANTRIB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(MOTDESICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CPRODANP AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFCONS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFCI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VICMSDESON AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CENQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VBCUFDEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PFCPUFDEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PICMSUFDEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PICMSINTER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PICMSINTERPART AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VFCPUFDEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VICMSUFDEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VICMSUFREMET AS CHAR(254)))),0) +'
     '+ ')', 'DADOSITEMNFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSITEMNFE_U' AND type = 'TR')
   drop trigger DADOSITEMNFE_U
go
create trigger dbo.DADOSITEMNFE_U on dbo.DADOSITEMNFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DADOSITEMNFE SET     CPROD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEAN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XPROD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NCM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NCM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CFOP = '+ ISNULL(LTRIM(RTRIM(CAST(CFOP AS CHAR(254)))),0) +',    UTRIB = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UTRIB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(QTRIB AS CHAR(254)))),0) +',    VPROD = '+ ISNULL(LTRIM(RTRIM(CAST(VPROD AS CHAR(254)))),0) +',    VFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VFRETE AS CHAR(254)))),0) +',    VSEG = '+ ISNULL(LTRIM(RTRIM(CAST(VSEG AS CHAR(254)))),0) +',    VDESC = '+ ISNULL(LTRIM(RTRIM(CAST(VDESC AS CHAR(254)))),0) +',    ORIG = '+ ISNULL(LTRIM(RTRIM(CAST(ORIG AS CHAR(254)))),0) +',    CST = '+ ISNULL(LTRIM(RTRIM(CAST(CST AS CHAR(254)))),0) +',    VBC = '+ ISNULL(LTRIM(RTRIM(CAST(VBC AS CHAR(254)))),0) +',    PICMS = '+ ISNULL(LTRIM(RTRIM(CAST(PICMS AS CHAR(254)))),0) +',    VICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VICMS AS CHAR(254)))),0) +',    PREDBC = '+ ISNULL(LTRIM(RTRIM(CAST(PREDBC AS CHAR(254)))),0) +',    VBCST = '+ ISNULL(LTRIM(RTRIM(CAST(VBCST AS CHAR(254)))),0) +',    PICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(PICMSST AS CHAR(254)))),0) +',    VICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(VICMSST AS CHAR(254)))),0) +',    PREDBCST = '+ ISNULL(LTRIM(RTRIM(CAST(PREDBCST AS CHAR(254)))),0) +',    VBCIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VBCIPI AS CHAR(254)))),0) +',    PIPI = '+ ISNULL(LTRIM(RTRIM(CAST(PIPI AS CHAR(254)))),0) +',    VIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VIPI AS CHAR(254)))),0) +',    CSTIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CSTIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UCOM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UCOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QCOM = '+ ISNULL(LTRIM(RTRIM(CAST(QCOM AS CHAR(254)))),0) +',    VUNCOM = '+ ISNULL(LTRIM(RTRIM(CAST(VUNCOM AS CHAR(254)))),0) +',    VUNTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(VUNTRIB AS CHAR(254)))),0) +',    MODBC = '+ ISNULL(LTRIM(RTRIM(CAST(MODBC AS CHAR(254)))),0) +',    MODBCST = '+ ISNULL(LTRIM(RTRIM(CAST(MODBCST AS CHAR(254)))),0) +',    PMVAST = '+ ISNULL(LTRIM(RTRIM(CAST(PMVAST AS CHAR(254)))),0) +',    VBCPIS = '+ ISNULL(LTRIM(RTRIM(CAST(VBCPIS AS CHAR(254)))),0) +',    PPIS = '+ ISNULL(LTRIM(RTRIM(CAST(PPIS AS CHAR(254)))),0) +',    VPIS = '+ ISNULL(LTRIM(RTRIM(CAST(VPIS AS CHAR(254)))),0) +',    VBCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VBCOFINS AS CHAR(254)))),0) +',    PCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(PCOFINS AS CHAR(254)))),0) +',    VCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VCOFINS AS CHAR(254)))),0) +',    VOUTRO = '+ ISNULL(LTRIM(RTRIM(CAST(VOUTRO AS CHAR(254)))),0) +',    CSTPIS = '+ ISNULL(LTRIM(RTRIM(CAST(CSTPIS AS CHAR(254)))),0) +',    CSTCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(CSTCOFINS AS CHAR(254)))),0) +',    INFADPROD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFADPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NDI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NDI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DDI = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DDI,20)))+''',120)','NULL')+',    XLOCDESEMB = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLOCDESEMB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UFDESEMB = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFDESEMB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DDESEMB = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DDESEMB,20)))+''',120)','NULL')+',    CEXPORTADOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEXPORTADOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NADICAO = '+ ISNULL(LTRIM(RTRIM(CAST(NADICAO AS CHAR(254)))),0) +',    NSEQADIC = '+ ISNULL(LTRIM(RTRIM(CAST(NSEQADIC AS CHAR(254)))),0) +',    CFABRICANTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFABRICANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VDESCDI = '+ ISNULL(LTRIM(RTRIM(CAST(VDESCDI AS CHAR(254)))),0) +',    VBCIMP = '+ ISNULL(LTRIM(RTRIM(CAST(VBCIMP AS CHAR(254)))),0) +',    VDESPADU = '+ ISNULL(LTRIM(RTRIM(CAST(VDESPADU AS CHAR(254)))),0) +',    VII = '+ ISNULL(LTRIM(RTRIM(CAST(VII AS CHAR(254)))),0) +',    VIOF = '+ ISNULL(LTRIM(RTRIM(CAST(VIOF AS CHAR(254)))),0) +',    PCREDSN = '+ ISNULL(LTRIM(RTRIM(CAST(PCREDSN AS CHAR(254)))),0) +',    VCREDICMSSN = '+ ISNULL(LTRIM(RTRIM(CAST(VCREDICMSSN AS CHAR(254)))),0) +',    CSOSN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CSOSN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INDTOT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INDTOT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VBCSTRET = '+ ISNULL(LTRIM(RTRIM(CAST(VBCSTRET AS CHAR(254)))),0) +',    VICMSSTRET = '+ ISNULL(LTRIM(RTRIM(CAST(VICMSSTRET AS CHAR(254)))),0) +',    XPED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NITEMPED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NITEMPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEANTRIB = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEANTRIB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MOTDESICMS = '+ ISNULL(LTRIM(RTRIM(CAST(MOTDESICMS AS CHAR(254)))),0) +',    CPRODANP = '+ ISNULL(LTRIM(RTRIM(CAST(CPRODANP AS CHAR(254)))),0) +',    UFCONS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFCONS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NFCI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFCI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VICMSDESON = '+ ISNULL(LTRIM(RTRIM(CAST(VICMSDESON AS CHAR(254)))),0) +',    CENQIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CENQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VBCUFDEST = '+ ISNULL(LTRIM(RTRIM(CAST(VBCUFDEST AS CHAR(254)))),0) +',    PFCPUFDEST = '+ ISNULL(LTRIM(RTRIM(CAST(PFCPUFDEST AS CHAR(254)))),0) +',    PICMSUFDEST = '+ ISNULL(LTRIM(RTRIM(CAST(PICMSUFDEST AS CHAR(254)))),0) +',    PICMSINTER = '+ ISNULL(LTRIM(RTRIM(CAST(PICMSINTER AS CHAR(254)))),0) +',    PICMSINTERPART = '+ ISNULL(LTRIM(RTRIM(CAST(PICMSINTERPART AS CHAR(254)))),0) +',    VFCPUFDEST = '+ ISNULL(LTRIM(RTRIM(CAST(VFCPUFDEST AS CHAR(254)))),0) +',    VICMSUFDEST = '+ ISNULL(LTRIM(RTRIM(CAST(VICMSUFDEST AS CHAR(254)))),0) +',    VICMSUFREMET = '+ ISNULL(LTRIM(RTRIM(CAST(VICMSUFREMET AS CHAR(254)))),0) +''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and NITEM = '+ RTRIM(CAST(NITEM as char(254))) +  ''   , 'DADOSITEMNFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSLOCALNFE_D' AND type = 'TR')
  drop trigger DADOSLOCALNFE_D
go
create trigger dbo.DADOSLOCALNFE_D on dbo.DADOSLOCALNFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DADOSLOCALNFE WHERE 
Numord = '+ RTRIM(LTRIM(CAST(Numord as char(120)))) + '  and TipoLocal = '''+ RTRIM(LTRIM(TipoLocal)) + ''' ','DADOSLOCALNFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSLOCALNFE_I' AND type = 'TR')
   drop trigger DADOSLOCALNFE_I
go
create trigger dbo.DADOSLOCALNFE_I on dbo.DADOSLOCALNFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DADOSLOCALNFE(
        NUMORD,    TIPOLOCAL,    CNPJ,    XLGR,    NRO,    XCPL,    XBAIRRO,    CMUN,    XMUN,    UF)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOLOCAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLGR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XCPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XBAIRRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CMUN AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XMUN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'DADOSLOCALNFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSLOCALNFE_U' AND type = 'TR')
   drop trigger DADOSLOCALNFE_U
go
create trigger dbo.DADOSLOCALNFE_U on dbo.DADOSLOCALNFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DADOSLOCALNFE SET     CNPJ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XLGR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLGR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XCPL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XCPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XBAIRRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XBAIRRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CMUN = '+ ISNULL(LTRIM(RTRIM(CAST(CMUN AS CHAR(254)))),0) +',    XMUN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XMUN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE Numord = '+ RTRIM(CAST(Numord as char(254))) +  ' and TipoLocal = '''+ RTRIM(TipoLocal)  + ''''   , 'DADOSLOCALNFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSLOTENFE_D' AND type = 'TR')
  drop trigger DADOSLOTENFE_D
go
create trigger dbo.DADOSLOTENFE_D on dbo.DADOSLOTENFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DADOSLOTENFE WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and LOTEINTERNO = '''+ RTRIM(LTRIM(LOTEINTERNO)) + '''  and RITEM = '+ RTRIM(LTRIM(CAST(RITEM as char(120)))) + ' ','DADOSLOTENFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSLOTENFE_I' AND type = 'TR')
   drop trigger DADOSLOTENFE_I
go
create trigger dbo.DADOSLOTENFE_I on dbo.DADOSLOTENFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DADOSLOTENFE(
        NUMORD,    LOTEINTERNO,    RITEM,    NLOTE,    QLOTE,    DFAB,    DVAL,    VPMC)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTEINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RITEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NLOTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QLOTE AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DFAB,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DVAL,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VPMC AS CHAR(254)))),0) +'
     '+ ')', 'DADOSLOTENFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSLOTENFE_U' AND type = 'TR')
   drop trigger DADOSLOTENFE_U
go
create trigger dbo.DADOSLOTENFE_U on dbo.DADOSLOTENFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DADOSLOTENFE SET     NLOTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NLOTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QLOTE = '+ ISNULL(LTRIM(RTRIM(CAST(QLOTE AS CHAR(254)))),0) +',    DFAB = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DFAB,20)))+''',120)','NULL')+',    DVAL = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DVAL,20)))+''',120)','NULL')+',    VPMC = '+ ISNULL(LTRIM(RTRIM(CAST(VPMC AS CHAR(254)))),0) +''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and LOTEINTERNO = '''+ RTRIM(LOTEINTERNO)  + ''' and RITEM = '+ RTRIM(CAST(RITEM as char(254))) +  ''   , 'DADOSLOTENFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSMODOEMISSAONFE_D' AND type = 'TR')
  drop trigger DADOSMODOEMISSAONFE_D
go
create trigger dbo.DADOSMODOEMISSAONFE_D on dbo.DADOSMODOEMISSAONFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DADOSMODOEMISSAONFE WHERE 
Item = '+ RTRIM(LTRIM(CAST(Item as char(120)))) + ' ','DADOSMODOEMISSAONFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSMODOEMISSAONFE_I' AND type = 'TR')
   drop trigger DADOSMODOEMISSAONFE_I
go
create trigger dbo.DADOSMODOEMISSAONFE_I on dbo.DADOSMODOEMISSAONFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DADOSMODOEMISSAONFE(
        ITEM,    RFILIAL,    DHCONT,    XJUST,    RTIPOEMISSAO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RFILIAL AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHCONT,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XJUST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RTIPOEMISSAO AS CHAR(254)))),0) +'
     '+ ')', 'DADOSMODOEMISSAONFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSMODOEMISSAONFE_U' AND type = 'TR')
   drop trigger DADOSMODOEMISSAONFE_U
go
create trigger dbo.DADOSMODOEMISSAONFE_U on dbo.DADOSMODOEMISSAONFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DADOSMODOEMISSAONFE SET     RFILIAL = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RFILIAL AS CHAR(254)))),0) +'**],    DHCONT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHCONT,20)))+''',120)','NULL')+',    XJUST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XJUST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RTIPOEMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(RTIPOEMISSAO AS CHAR(254)))),0) +''+  ' WHERE Item = '+ RTRIM(CAST(Item as char(254))) +  ''   , 'DADOSMODOEMISSAONFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSNOTANFE_D' AND type = 'TR')
  drop trigger DADOSNOTANFE_D
go
create trigger dbo.DADOSNOTANFE_D on dbo.DADOSNOTANFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DADOSNOTANFE WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + ' ','DADOSNOTANFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSNOTANFE_I' AND type = 'TR')
   drop trigger DADOSNOTANFE_I
go
create trigger dbo.DADOSNOTANFE_I on dbo.DADOSNOTANFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DADOSNOTANFE(
        NUMORD,    CUF,    CNF,    NATOP,    INDPAG,    MOD,    SERIE,    NNF,    DEMI,    TPNF,    CMUNFG,    CNPJ,    XNOME,    XFAN,    XLGR,    NRO,    XCPL,    XBAIRRO,    CMUN,    XMUN,    UF,    CEP,    CPAIS,    XPAIS,    FONE,    IE,    IM,    CNPJD,    XNOMED,    XLGRD,    NROD,    XCPLD,    XBAIRROD,    CMUND,    XMUND,    UFD,    CEPD,    CPAISD,    XPAISD,    FONED,    IED,    ISUF,    VBCPIS,    PPIS,    VPIS,    VBCOFINS,    PCOFINS,    VCOFINS,    VBCISS,    VISS,    VRETCSLL,    VNF,    TPEMIS,    FINNFE,    VERPROC,    JUSTIFICATIVAINUTILIZACAO,    IEST,    NNFFINAL,    CNAE,    VBC,    VICMS,    VBCST,    VST,    VPROD,    VFRETE,    VSEG,    VDESC,    VII,    VOUTRO,    VIPI,    DSAIENT,    UFEMBARQ,    XLOCEMBARQ,    FEMAIL,    INFCPL,    INFCANHOTO,    CRT,    HSAIENT,    EMAIL,    XJUST,    DHCONT,    IDDEST,    INDFINAL,    INDPRES,    IDESTRANGEIRO,    INDIEDEST,    VICMSDESON,    INFADFISCO,    VFCPUFDEST,    VICMSUFDEST,    VICMSUFREMET)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CNF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NATOP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(INDPAG AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NNF AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DEMI,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(TPNF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CMUNFG AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XNOME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XFAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLGR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XCPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XBAIRRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CMUN AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XMUN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CPAIS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XPAIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FONE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XNOMED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLGRD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XCPLD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XBAIRROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CMUND AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XMUND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CPAISD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XPAISD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FONED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ISUF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VBCPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBCISS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VISS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VRETCSLL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VNF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TPEMIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FINNFE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(VERPROC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(JUSTIFICATIVAINUTILIZACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NNFFINAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CNAE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBCST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VPROD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VSEG AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VII AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VOUTRO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VIPI AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DSAIENT,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFEMBARQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLOCEMBARQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FEMAIL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFCPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFCANHOTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CRT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,HSAIENT,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EMAIL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XJUST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHCONT,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IDDEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INDFINAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INDPRES AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IDESTRANGEIRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INDIEDEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VICMSDESON AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFADFISCO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VFCPUFDEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VICMSUFDEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VICMSUFREMET AS CHAR(254)))),0) +'
     '+ ')', 'DADOSNOTANFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSNOTANFE_U' AND type = 'TR')
   drop trigger DADOSNOTANFE_U
go
create trigger dbo.DADOSNOTANFE_U on dbo.DADOSNOTANFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DADOSNOTANFE SET     CUF = '+ ISNULL(LTRIM(RTRIM(CAST(CUF AS CHAR(254)))),0) +',    CNF = '+ ISNULL(LTRIM(RTRIM(CAST(CNF AS CHAR(254)))),0) +',    NATOP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NATOP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INDPAG = '+ ISNULL(LTRIM(RTRIM(CAST(INDPAG AS CHAR(254)))),0) +',    MOD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIE = '+ ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),0) +',    NNF = '+ ISNULL(LTRIM(RTRIM(CAST(NNF AS CHAR(254)))),0) +',    DEMI = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DEMI,20)))+''',120)','NULL')+',    TPNF = '+ ISNULL(LTRIM(RTRIM(CAST(TPNF AS CHAR(254)))),0) +',    CMUNFG = '+ ISNULL(LTRIM(RTRIM(CAST(CMUNFG AS CHAR(254)))),0) +',    CNPJ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XNOME = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XNOME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XFAN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XFAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XLGR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLGR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XCPL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XCPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XBAIRRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XBAIRRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CMUN = '+ ISNULL(LTRIM(RTRIM(CAST(CMUN AS CHAR(254)))),0) +',    XMUN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XMUN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CPAIS = '+ ISNULL(LTRIM(RTRIM(CAST(CPAIS AS CHAR(254)))),0) +',    XPAIS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XPAIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FONE = '+ ISNULL(LTRIM(RTRIM(CAST(FONE AS CHAR(254)))),0) +',    IE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CNPJD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XNOMED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XNOMED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XLGRD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLGRD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NROD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XCPLD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XCPLD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XBAIRROD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XBAIRROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CMUND = '+ ISNULL(LTRIM(RTRIM(CAST(CMUND AS CHAR(254)))),0) +',    XMUND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XMUND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UFD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEPD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CPAISD = '+ ISNULL(LTRIM(RTRIM(CAST(CPAISD AS CHAR(254)))),0) +',    XPAISD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XPAISD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FONED = '+ ISNULL(LTRIM(RTRIM(CAST(FONED AS CHAR(254)))),0) +',    IED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ISUF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ISUF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VBCPIS = '+ ISNULL(LTRIM(RTRIM(CAST(VBCPIS AS CHAR(254)))),0) +',    PPIS = '+ ISNULL(LTRIM(RTRIM(CAST(PPIS AS CHAR(254)))),0) +',    VPIS = '+ ISNULL(LTRIM(RTRIM(CAST(VPIS AS CHAR(254)))),0) +',    VBCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VBCOFINS AS CHAR(254)))),0) +',    PCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(PCOFINS AS CHAR(254)))),0) +',    VCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VCOFINS AS CHAR(254)))),0) +',    VBCISS = '+ ISNULL(LTRIM(RTRIM(CAST(VBCISS AS CHAR(254)))),0) +',    VISS = '+ ISNULL(LTRIM(RTRIM(CAST(VISS AS CHAR(254)))),0) +',    VRETCSLL = '+ ISNULL(LTRIM(RTRIM(CAST(VRETCSLL AS CHAR(254)))),0) +',    VNF = '+ ISNULL(LTRIM(RTRIM(CAST(VNF AS CHAR(254)))),0) +',    TPEMIS = '+ ISNULL(LTRIM(RTRIM(CAST(TPEMIS AS CHAR(254)))),0) +',    FINNFE = '+ ISNULL(LTRIM(RTRIM(CAST(FINNFE AS CHAR(254)))),0) +',    VERPROC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(VERPROC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    JUSTIFICATIVAINUTILIZACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(JUSTIFICATIVAINUTILIZACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IEST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NNFFINAL = '+ ISNULL(LTRIM(RTRIM(CAST(NNFFINAL AS CHAR(254)))),0) +',    CNAE = '+ ISNULL(LTRIM(RTRIM(CAST(CNAE AS CHAR(254)))),0) +',    VBC = '+ ISNULL(LTRIM(RTRIM(CAST(VBC AS CHAR(254)))),0) +',    VICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VICMS AS CHAR(254)))),0) +',    VBCST = '+ ISNULL(LTRIM(RTRIM(CAST(VBCST AS CHAR(254)))),0) +',    VST = '+ ISNULL(LTRIM(RTRIM(CAST(VST AS CHAR(254)))),0) +',    VPROD = '+ ISNULL(LTRIM(RTRIM(CAST(VPROD AS CHAR(254)))),0) +',    VFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VFRETE AS CHAR(254)))),0) +',    VSEG = '+ ISNULL(LTRIM(RTRIM(CAST(VSEG AS CHAR(254)))),0) +',    VDESC = '+ ISNULL(LTRIM(RTRIM(CAST(VDESC AS CHAR(254)))),0) +',    VII = '+ ISNULL(LTRIM(RTRIM(CAST(VII AS CHAR(254)))),0) +',    VOUTRO = '+ ISNULL(LTRIM(RTRIM(CAST(VOUTRO AS CHAR(254)))),0) +',    VIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VIPI AS CHAR(254)))),0) +',    DSAIENT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DSAIENT,20)))+''',120)','NULL')+',    UFEMBARQ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFEMBARQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XLOCEMBARQ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XLOCEMBARQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FEMAIL = '+ ISNULL(LTRIM(RTRIM(CAST(FEMAIL AS CHAR(254)))),0) +',    INFCPL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFCPL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INFCANHOTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFCANHOTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CRT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CRT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    HSAIENT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,HSAIENT,20)))+''',120)','NULL')+',    EMAIL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EMAIL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XJUST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XJUST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DHCONT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DHCONT,20)))+''',120)','NULL')+',    IDDEST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IDDEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INDFINAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INDFINAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INDPRES = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INDPRES AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IDESTRANGEIRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IDESTRANGEIRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INDIEDEST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INDIEDEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VICMSDESON = '+ ISNULL(LTRIM(RTRIM(CAST(VICMSDESON AS CHAR(254)))),0) +',    INFADFISCO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFADFISCO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VFCPUFDEST = '+ ISNULL(LTRIM(RTRIM(CAST(VFCPUFDEST AS CHAR(254)))),0) +',    VICMSUFDEST = '+ ISNULL(LTRIM(RTRIM(CAST(VICMSUFDEST AS CHAR(254)))),0) +',    VICMSUFREMET = '+ ISNULL(LTRIM(RTRIM(CAST(VICMSUFREMET AS CHAR(254)))),0) +''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ''   , 'DADOSNOTANFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSTRANSPORTENFE_D' AND type = 'TR')
  drop trigger DADOSTRANSPORTENFE_D
go
create trigger dbo.DADOSTRANSPORTENFE_D on dbo.DADOSTRANSPORTENFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DADOSTRANSPORTENFE WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + ' ','DADOSTRANSPORTENFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSTRANSPORTENFE_I' AND type = 'TR')
   drop trigger DADOSTRANSPORTENFE_I
go
create trigger dbo.DADOSTRANSPORTENFE_I on dbo.DADOSTRANSPORTENFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DADOSTRANSPORTENFE(
        NUMORD,    MODFRETE,    CNPJ,    CPF,    XNOME,    IE,    XENDER,    XMUN,    VSERV,    VBCRET,    PICMSRET,    VICMSRET,    CFOP,    CMUNFG,    PLACA,    UF,    RNTC,    QVOL,    ESP,    MARCA,    NVOL,    PESOL,    PESOB,    NLACRE,    UFPLACA,    CNPJCPF)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MODFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CPF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XNOME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XENDER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XMUN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VSERV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VBCRET AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PICMSRET AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VICMSRET AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFOP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CMUNFG AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RNTC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QVOL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MARCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NVOL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PESOL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PESOB AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NLACRE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFPLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJCPF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'DADOSTRANSPORTENFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DADOSTRANSPORTENFE_U' AND type = 'TR')
   drop trigger DADOSTRANSPORTENFE_U
go
create trigger dbo.DADOSTRANSPORTENFE_U on dbo.DADOSTRANSPORTENFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DADOSTRANSPORTENFE SET     MODFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(MODFRETE AS CHAR(254)))),0) +',    CNPJ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CPF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CPF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XNOME = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XNOME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XENDER = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XENDER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    XMUN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(XMUN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VSERV = '+ ISNULL(LTRIM(RTRIM(CAST(VSERV AS CHAR(254)))),0) +',    VBCRET = '+ ISNULL(LTRIM(RTRIM(CAST(VBCRET AS CHAR(254)))),0) +',    PICMSRET = '+ ISNULL(LTRIM(RTRIM(CAST(PICMSRET AS CHAR(254)))),0) +',    VICMSRET = '+ ISNULL(LTRIM(RTRIM(CAST(VICMSRET AS CHAR(254)))),0) +',    CFOP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFOP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CMUNFG = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CMUNFG AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PLACA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RNTC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RNTC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QVOL = '+ ISNULL(LTRIM(RTRIM(CAST(QVOL AS CHAR(254)))),0) +',    ESP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MARCA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MARCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NVOL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NVOL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PESOL = '+ ISNULL(LTRIM(RTRIM(CAST(PESOL AS CHAR(254)))),0) +',    PESOB = '+ ISNULL(LTRIM(RTRIM(CAST(PESOB AS CHAR(254)))),0) +',    NLACRE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NLACRE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UFPLACA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UFPLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CNPJCPF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJCPF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ''   , 'DADOSTRANSPORTENFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DETALHERZ_I' AND type = 'TR')
   drop trigger DETALHERZ_I
go
create trigger dbo.DETALHERZ_I on dbo.DETALHERZ for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DETALHERZ(
        NUMORD,    OIDSERIALECF,    SERIALECF,    CONTREDZ,    CODTOTALIZADOR,    VALOR)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTREDZ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTOTALIZADOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +')
     ', 'DETALHERZ' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DIVISAODAVENDA_D' AND type = 'TR')
  drop trigger DIVISAODAVENDA_D
go
create trigger dbo.DIVISAODAVENDA_D on dbo.DIVISAODAVENDA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DIVISAODAVENDA WHERE 
OID = '+ RTRIM(LTRIM(CAST(OID as char(120)))) + ' ','DIVISAODAVENDA' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DIVISAODAVENDA_I' AND type = 'TR')
   drop trigger DIVISAODAVENDA_I
go
create trigger dbo.DIVISAODAVENDA_I on dbo.DIVISAODAVENDA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DIVISAODAVENDA(
        RVENDEDOR,    RDOCDEORIGEM,    TIPODEVENDEDOR,    PERCENTUAL,    OID)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(RVENDEDOR AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCDEORIGEM AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(TIPODEVENDEDOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUAL AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]
     '+ ')', 'DIVISAODAVENDA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DIVISAODAVENDA_U' AND type = 'TR')
   drop trigger DIVISAODAVENDA_U
go
create trigger dbo.DIVISAODAVENDA_U on dbo.DIVISAODAVENDA for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DIVISAODAVENDA SET     RVENDEDOR = '+ ISNULL(LTRIM(RTRIM(CAST(RVENDEDOR AS CHAR(254)))),0) +',    RDOCDEORIGEM = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCDEORIGEM AS CHAR(254)))),0) +'**],    TIPODEVENDEDOR = '+ ISNULL(LTRIM(RTRIM(CAST(TIPODEVENDEDOR AS CHAR(254)))),0) +',    PERCENTUAL = '+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUAL AS CHAR(254)))),0) +''+  ' WHERE     OID = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'  , 'DIVISAODAVENDA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DOCDIVERSOSECF_D' AND type = 'TR')
  drop trigger DOCDIVERSOSECF_D
go
create trigger dbo.DOCDIVERSOSECF_D on dbo.DOCDIVERSOSECF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DOCDIVERSOSECF WHERE 
OID = '+ RTRIM(LTRIM(CAST(OID as char(120)))) + ' ','DOCDIVERSOSECF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DOCDIVERSOSECF_I' AND type = 'TR')
   drop trigger DOCDIVERSOSECF_I
go
create trigger dbo.DOCDIVERSOSECF_I on dbo.DOCDIVERSOSECF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DOCDIVERSOSECF(
        SERIALIMPRESSORA,    COO,    GNF,    TIPODOC,    CONTDOC,    DTOPER,    OIDSERIALECF,    FILIAL)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALIMPRESSORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GNF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPODOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTOPER,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''')
     ', 'DOCDIVERSOSECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DOCDIVERSOSECF_U' AND type = 'TR')
   drop trigger DOCDIVERSOSECF_U
go
create trigger dbo.DOCDIVERSOSECF_U on dbo.DOCDIVERSOSECF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DOCDIVERSOSECF SET     SERIALIMPRESSORA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALIMPRESSORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    GNF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GNF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPODOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPODOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONTDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTOPER = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTOPER,20)))+''',120)','NULL')+',    OIDSERIALECF = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**],    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE     OID = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'  , 'DOCDIVERSOSECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DOCFCXACAD_D' AND type = 'TR')
  drop trigger DOCFCXACAD_D
go
create trigger dbo.DOCFCXACAD_D on dbo.DOCFCXACAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM DOCFCXACAD WHERE 
caixa = '+ RTRIM(LTRIM(CAST(caixa as char(120)))) + '  and     DATAFCXA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAFCXA,20)))+''',120)','NULL') +' and filial = '''+ RTRIM(LTRIM(filial)) + ''' ','DOCFCXACAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DOCFCXACAD_I' AND type = 'TR')
   drop trigger DOCFCXACAD_I
go
create trigger dbo.DOCFCXACAD_I on dbo.DOCFCXACAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO DOCFCXACAD(
        CAIXA,    DATAFCXA,    DOCUMEN,    DESCR,    TIPOVALOR,    VALORFCXA,    VALORAPUR,    INTEGRADO,    FILIAL,    VALORSANG,    CTB,    VALORREC,    OBSERVACAO,    RAPURACAOCONTABILFCXA)
    VALUES (
      [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CAIXA AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAFCXA,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(DOCUMEN AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOVALOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORFCXA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORAPUR AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORSANG AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CTB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORREC AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RAPURACAOCONTABILFCXA AS CHAR(254)))),0) +'
     '+ ')', 'DOCFCXACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'DOCFCXACAD_U' AND type = 'TR')
   drop trigger DOCFCXACAD_U
go
create trigger dbo.DOCFCXACAD_U on dbo.DOCFCXACAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE DOCFCXACAD SET     DOCUMEN = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(DOCUMEN AS CHAR(254)))),0) +'**],    DESCR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOVALOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOVALOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORFCXA = '+ ISNULL(LTRIM(RTRIM(CAST(VALORFCXA AS CHAR(254)))),0) +',    VALORAPUR = '+ ISNULL(LTRIM(RTRIM(CAST(VALORAPUR AS CHAR(254)))),0) +',    INTEGRADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORSANG = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSANG AS CHAR(254)))),0) +',    CTB = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CTB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORREC = '+ ISNULL(LTRIM(RTRIM(CAST(VALORREC AS CHAR(254)))),0) +',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RAPURACAOCONTABILFCXA = '+ ISNULL(LTRIM(RTRIM(CAST(RAPURACAOCONTABILFCXA AS CHAR(254)))),0) +''+  ' WHERE     caixa = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(caixa AS CHAR(254)))),0) +'**] and     DATAFCXA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAFCXA,20)))+''',120)','NULL')+' and filial = '''+ RTRIM(filial)  + ''''   , 'DOCFCXACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ENTRCLICAD_D' AND type = 'TR')
  drop trigger ENTRCLICAD_D
go
create trigger dbo.ENTRCLICAD_D on dbo.ENTRCLICAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ENTRCLICAD WHERE 
item = '+ RTRIM(LTRIM(CAST(item as char(120)))) + ' ','ENTRCLICAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ENTRCLICAD_INST_I' AND type = 'TR')
   drop trigger ENTRCLICAD_INST_I
go
create trigger dbo.ENTRCLICAD_INST_I on dbo.ENTRCLICAD INSTEAD OF insert as
begin
    SELECT * INTO #Inserted FROM Inserted
    UPDATE #Inserted SET item = (@@spid*-1)
    INSERT INTO ENTRCLICAD SELECT * FROM #Inserted
    Return
end
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ENTRCLICAD_I' AND type = 'TR')
   drop trigger ENTRCLICAD_I
go
create trigger dbo.ENTRCLICAD_I on dbo.ENTRCLICAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ENTRCLICAD(
        FILIAL,    NUMPED,    ENDENTR,    BAIRENTR,    CIDENTR,    ESTENTR,    CEPENTR,    NUMENTR,    CNPJEND,    INSCREND,    COMPLENTR,    TIPOENDERECO,    SELECIONADO,    ITEM,    RBAIRRO,    REFERENCIAENDERECO)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCREND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SELECIONADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RBAIRRO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFERENCIAENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'ENTRCLICAD' FROM inserted
    declare @nContador integer
    exec GERASEMENTE_P 'TW_IDENTIFICADOR', 7, @nContador OUTPUT
    if @nContador > 0
      update ENTRCLICAD set ITEM = @nContador WHERE ITEM = (select ITEM from inserted WHERE ITEM=(@@spid*-1))
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ENTRCLICAD_U' AND type = 'TR')
   drop trigger ENTRCLICAD_U
go
create trigger dbo.ENTRCLICAD_U on dbo.ENTRCLICAD for update as
begin
  if (select count(*) from deleted where item = @@spid*-1 ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ENTRCLICAD SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    ENDENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BAIRENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CIDENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEPENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CNPJEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INSCREND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCREND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COMPLENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOENDERECO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SELECIONADO = '+ ISNULL(LTRIM(RTRIM(CAST(SELECIONADO AS CHAR(254)))),0) +',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +',    RBAIRRO = '+ ISNULL(LTRIM(RTRIM(CAST(RBAIRRO AS CHAR(254)))),0) +',    REFERENCIAENDERECO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFERENCIAENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE item = '+ ISNULL(LTRIM(RTRIM(CAST((@@spid*-1) AS CHAR(254)))),0) , 'ENTRCLICAD' FROM inserted
 else
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ENTRCLICAD SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    ENDENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BAIRENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CIDENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEPENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CNPJEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INSCREND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCREND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COMPLENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOENDERECO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SELECIONADO = '+ ISNULL(LTRIM(RTRIM(CAST(SELECIONADO AS CHAR(254)))),0) +',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +',    RBAIRRO = '+ ISNULL(LTRIM(RTRIM(CAST(RBAIRRO AS CHAR(254)))),0) +',    REFERENCIAENDERECO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFERENCIAENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE item = '+ RTRIM(CAST(item as char(254))) +  ''   , 'ENTRCLICAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'EXPEDICCAD_D' AND type = 'TR')
  drop trigger EXPEDICCAD_D
go
create trigger dbo.EXPEDICCAD_D on dbo.EXPEDICCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM EXPEDICCAD WHERE 
nordnota = '+ RTRIM(LTRIM(CAST(nordnota as char(120)))) + ' ','EXPEDICCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'EXPEDICCAD_I' AND type = 'TR')
   drop trigger EXPEDICCAD_I
go
create trigger dbo.EXPEDICCAD_I on dbo.EXPEDICCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO EXPEDICCAD(
        FILIAL,    NUMNOTA,    SERIE,    TIPOENTR,    NORDNOTA,    NORDVEN,    DATAENTR,    NUMFRETE,    FLAGEMIT,    BAIENTR,    CIDENTR,    VALORFRETE,    TIPOHIST,    NUMCARGA,    CONFERIUSERIAL)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NORDNOTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NORDVEN AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAENTR,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOHIST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCARGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CONFERIUSERIAL AS CHAR(254)))),0) +'
     '+ ')', 'EXPEDICCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'EXPEDICCAD_U' AND type = 'TR')
   drop trigger EXPEDICCAD_U
go
create trigger dbo.EXPEDICCAD_U on dbo.EXPEDICCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE EXPEDICCAD SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMNOTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NORDVEN = '+ ISNULL(LTRIM(RTRIM(CAST(NORDVEN AS CHAR(254)))),0) +',    DATAENTR = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAENTR,20)))+''',120)','NULL')+',    NUMFRETE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGEMIT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BAIENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CIDENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +',    TIPOHIST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOHIST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMCARGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCARGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONFERIUSERIAL = '+ ISNULL(LTRIM(RTRIM(CAST(CONFERIUSERIAL AS CHAR(254)))),0) +''+  ' WHERE nordnota = '+ RTRIM(CAST(nordnota as char(254))) +  ''   , 'EXPEDICCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FILANFE_D' AND type = 'TR')
  drop trigger FILANFE_D
go
create trigger dbo.FILANFE_D on dbo.FILANFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM FILANFE WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + ' ','FILANFE' from deleted
    End
go
--===================================================================================================== 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FILANFE_I2' AND type = 'TR')
   drop trigger FILANFE_I2
go
create trigger dbo.FILANFE_I2 on dbo.FILANFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO FILANFE(
        NUMORD,    DATAPROCESSAMENTONFE,    SITUACAONFE,    TEMPOMEDIOESTIMADO,    TIPONFE,    FILIAL,    SITANTERIOR)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAPROCESSAMENTONFE,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TEMPOMEDIOESTIMADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITANTERIOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'FILANFE' FROM inserted
    return
end
go
--====================================================================================================== 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FILANFE_U' AND type = 'TR')
   drop trigger FILANFE_U
go
create trigger dbo.FILANFE_U on dbo.FILANFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE FILANFE SET     DATAPROCESSAMENTONFE = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAPROCESSAMENTONFE,20)))+''',120)','NULL')+',    SITUACAONFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TEMPOMEDIOESTIMADO = '+ ISNULL(LTRIM(RTRIM(CAST(TEMPOMEDIOESTIMADO AS CHAR(254)))),0) +',    TIPONFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITANTERIOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITANTERIOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ''   , 'FILANFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FILARETORNONFE_D' AND type = 'TR')
  drop trigger FILARETORNONFE_D
go
create trigger dbo.FILARETORNONFE_D on dbo.FILARETORNONFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM FILARETORNONFE WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + ' ','FILARETORNONFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FILARETORNONFE_I' AND type = 'TR')
   drop trigger FILARETORNONFE_I
go
create trigger dbo.FILARETORNONFE_I on dbo.FILARETORNONFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO FILARETORNONFE(
        NUMORD,    TIPOES,    SITUACAONFE,    ATUALIZADOEM,    GUID)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOES AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ATUALIZADOEM,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(GUID AS CHAR(254)))),0) +'
     '+ ')', 'FILARETORNONFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FILARETORNONFE_U' AND type = 'TR')
   drop trigger FILARETORNONFE_U
go
create trigger dbo.FILARETORNONFE_U on dbo.FILARETORNONFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE FILARETORNONFE SET     TIPOES = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOES AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITUACAONFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAONFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ATUALIZADOEM = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ATUALIZADOEM,20)))+''',120)','NULL')+',    GUID = '+ ISNULL(LTRIM(RTRIM(CAST(GUID AS CHAR(254)))),0) +''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ''   , 'FILARETORNONFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FORAESTFAT_D' AND type = 'TR')
  drop trigger FORAESTFAT_D
go
create trigger dbo.FORAESTFAT_D on dbo.FORAESTFAT for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM FORAESTFAT WHERE 
oid = '+ RTRIM(LTRIM(CAST(oid as char(120)))) + ' ','FORAESTFAT' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FORAESTFAT_INST_I' AND type = 'TR')
   drop trigger FORAESTFAT_INST_I
go
create trigger dbo.FORAESTFAT_INST_I on dbo.FORAESTFAT INSTEAD OF insert as
begin
    SELECT * INTO #Inserted FROM Inserted
    UPDATE #Inserted SET OID = (@@spid*-1)
    INSERT INTO FORAESTFAT SELECT * FROM #Inserted
    Return
end
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FORAESTFAT_I' AND type = 'TR')
   drop trigger FORAESTFAT_I
go
create trigger dbo.FORAESTFAT_I on dbo.FORAESTFAT for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO FORAESTFAT(
        NUMORD,    DESCR,    ITEM,    NUMORDFIS,    IMPOGER,    OID)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'
     '+ ')', 'FORAESTFAT' FROM inserted
    declare @nContador integer
    exec GERASEMENTE_P 'TW_IDENTIFICADOR', 7, @nContador OUTPUT
    if @nContador > 0
      update FORAESTFAT set OID = @nContador WHERE OID = (select OID from inserted WHERE OID=(@@spid*-1))
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FORAESTFAT_U' AND type = 'TR')
   drop trigger FORAESTFAT_U
go
create trigger dbo.FORAESTFAT_U on dbo.FORAESTFAT for update as
begin
  if (select count(*) from deleted where OID = @@spid*-1 ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE FORAESTFAT SET     NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    DESCR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ITEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    OID = '+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +''+  ' WHERE OID = '+ ISNULL(LTRIM(RTRIM(CAST((@@spid*-1) AS CHAR(254)))),0) , 'FORAESTFAT' FROM inserted
 else
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE FORAESTFAT SET     NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    DESCR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ITEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    OID = '+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +''+  ' WHERE oid = '+ RTRIM(CAST(oid as char(254))) +  ''   , 'FORAESTFAT' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FRETPEDCAD_D' AND type = 'TR')
  drop trigger FRETPEDCAD_D
go
create trigger dbo.FRETPEDCAD_D on dbo.FRETPEDCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM FRETPEDCAD WHERE 
filial = '''+ RTRIM(LTRIM(filial)) + '''  and numped = '+ RTRIM(LTRIM(CAST(numped as char(120)))) + '  and numcarga = '''+ RTRIM(LTRIM(numcarga)) + ''' ','FRETPEDCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FRETPEDCAD_I' AND type = 'TR')
   drop trigger FRETPEDCAD_I
go
create trigger dbo.FRETPEDCAD_I on dbo.FRETPEDCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO FRETPEDCAD(
        FILIAL,    NUMPED,    NUMCARGA,    DTPREVENT,    TICKET,    VALOR,    NUMORD)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCARGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVENT,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TICKET AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +'
     '+ ')', 'FRETPEDCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FRETPEDCAD_U' AND type = 'TR')
   drop trigger FRETPEDCAD_U
go
create trigger dbo.FRETPEDCAD_U on dbo.FRETPEDCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE FRETPEDCAD SET     DTPREVENT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVENT,20)))+''',120)','NULL')+',    TICKET = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TICKET AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALOR = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +''+  ' WHERE filial = '''+ RTRIM(filial)  + ''' and numped = '+ RTRIM(CAST(numped as char(254))) +  ' and numcarga = '''+ RTRIM(numcarga)  + ''''   , 'FRETPEDCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FRETVENCAD_D' AND type = 'TR')
  drop trigger FRETVENCAD_D
go
create trigger dbo.FRETVENCAD_D on dbo.FRETVENCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM FRETVENCAD WHERE 
filial = '''+ RTRIM(LTRIM(filial)) + '''  and codtran = '''+ RTRIM(LTRIM(codtran)) + '''  and     DTENTR = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTENTR,20)))+''',120)','NULL') +'','FRETVENCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FRETVENCAD_I' AND type = 'TR')
   drop trigger FRETVENCAD_I
go
create trigger dbo.FRETVENCAD_I on dbo.FRETVENCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO FRETVENCAD(
        FILIAL,    CODTRAN,    NUMORD,    VALORFRETE,    NUMFRETE,    DTENTR,    NUMORDVEN,    INTPAG)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTENTR,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDVEN AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTPAG AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'FRETVENCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'FRETVENCAD_U' AND type = 'TR')
   drop trigger FRETVENCAD_U
go
create trigger dbo.FRETVENCAD_U on dbo.FRETVENCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE FRETVENCAD SET     NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    VALORFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +',    NUMFRETE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORDVEN = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDVEN AS CHAR(254)))),0) +',    INTPAG = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTPAG AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE filial = '''+ RTRIM(filial)  + ''' and codtran = '''+ RTRIM(codtran)  + ''' and     DTENTR = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTENTR,20)))+''',120)','NULL') , 'FRETVENCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'GERANFECF_D' AND type = 'TR')
  drop trigger GERANFECF_D
go
create trigger dbo.GERANFECF_D on dbo.GERANFECF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM GERANFECF WHERE 
NUMPED = '+ RTRIM(LTRIM(CAST(NUMPED as char(120)))) + ' ','GERANFECF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'GERANFECF_I' AND type = 'TR')
   drop trigger GERANFECF_I
go
create trigger dbo.GERANFECF_I on dbo.GERANFECF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO GERANFECF(
        NUMPED,    NUMEROCUPOM,    NUMEROECF,    RCAIXA,    OPERACAO,    IMPREQ,    RSESSAODEUSO,    DTOPERA,    RUSUARIO,    DIFMERC)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCAIXA AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OPERACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IMPREQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RSESSAODEUSO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTOPERA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(RUSUARIO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DIFMERC AS CHAR(254)))),0) +'
     '+ ')', 'GERANFECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'GERANFECF_U' AND type = 'TR')
   drop trigger GERANFECF_U
go
create trigger dbo.GERANFECF_U on dbo.GERANFECF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE GERANFECF SET     NUMEROCUPOM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROECF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RCAIXA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCAIXA AS CHAR(254)))),0) +'**],    OPERACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OPERACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IMPREQ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(IMPREQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RSESSAODEUSO = '+ ISNULL(LTRIM(RTRIM(CAST(RSESSAODEUSO AS CHAR(254)))),0) +',    DTOPERA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTOPERA,20)))+''',120)','NULL')+',    RUSUARIO = '+ ISNULL(LTRIM(RTRIM(CAST(RUSUARIO AS CHAR(254)))),0) +',    DIFMERC = '+ ISNULL(LTRIM(RTRIM(CAST(DIFMERC AS CHAR(254)))),0) +''+  ' WHERE NUMPED = '+ RTRIM(CAST(NUMPED as char(254))) +  ''   , 'GERANFECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTATECAD_D' AND type = 'TR')
  drop trigger HISTATECAD_D
go
create trigger dbo.HISTATECAD_D on dbo.HISTATECAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM HISTATECAD WHERE 
    DTATIV = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTATIV,20)))+''',120)','NULL') +' and codvend = '''+ RTRIM(LTRIM(codvend)) + ''' ','HISTATECAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTATECAD_I' AND type = 'TR')
   drop trigger HISTATECAD_I
go
create trigger dbo.HISTATECAD_I on dbo.HISTATECAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO HISTATECAD(
        CODCLIE,    DTATIV,    CODATIV,    CODVEND,    MOTIVO,    DTCONTATO,    CONTATO,    TELEFONE,    TEXTO,    LIDO,    NUMPED)
    VALUES (
      [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTATIV,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODATIV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTCONTATO,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTATO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TELEFONE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TEXTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(LIDO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +'
     '+ ')', 'HISTATECAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTATECAD_U' AND type = 'TR')
   drop trigger HISTATECAD_U
go
create trigger dbo.HISTATECAD_U on dbo.HISTATECAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE HISTATECAD SET     CODCLIE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],    CODATIV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODATIV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MOTIVO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTCONTATO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTCONTATO,20)))+''',120)','NULL')+',    CONTATO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTATO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TELEFONE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TELEFONE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TEXTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TEXTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIDO = '+ ISNULL(LTRIM(RTRIM(CAST(LIDO AS CHAR(254)))),0) +',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +''+  ' WHERE     DTATIV = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTATIV,20)))+''',120)','NULL')+' and codvend = '''+ RTRIM(codvend)  + ''''   , 'HISTATECAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTENTCAD_D' AND type = 'TR')
  drop trigger HISTENTCAD_D
go
create trigger dbo.HISTENTCAD_D on dbo.HISTENTCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM HISTENTCAD WHERE 
numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + ' ','HISTENTCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTENTCAD_I' AND type = 'TR')
   drop trigger HISTENTCAD_I
go
create trigger dbo.HISTENTCAD_I on dbo.HISTENTCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO HISTENTCAD(
        NUMORD,    NUMNOTA,    SERIE,    FILIAL,    DTHIST,    USUARIO,    DTPREVENT,    CODTRAN,    TEXTO,    RESPENTR,    TIPOHIST,    ORDMONTAGEM,    OBSERVACAO,    RITEMCLI,    CODSEN,    CODPRO,    ITEMNF)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTHIST,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVENT,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TEXTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESPENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOHIST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ORDMONTAGEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMNF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'HISTENTCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTENTCAD_U' AND type = 'TR')
   drop trigger HISTENTCAD_U
go
create trigger dbo.HISTENTCAD_U on dbo.HISTENTCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE HISTENTCAD SET     NUMNOTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTHIST = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTHIST,20)))+''',120)','NULL')+',    USUARIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTPREVENT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVENT,20)))+''',120)','NULL')+',    CODTRAN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TEXTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TEXTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RESPENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESPENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOHIST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOHIST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ORDMONTAGEM = '+ ISNULL(LTRIM(RTRIM(CAST(ORDMONTAGEM AS CHAR(254)))),0) +',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RITEMCLI = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLI AS CHAR(254)))),0) +',    CODSEN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ITEMNF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMNF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE numord = '+ RTRIM(CAST(numord as char(254))) +  ''   , 'HISTENTCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTORICONFE_I' AND type = 'TR')
   drop trigger HISTORICONFE_I
go
create trigger dbo.HISTORICONFE_I on dbo.HISTORICONFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO HISTORICONFE(
        DATAPROCESSAMENTO,    NUMORD,    HISTORICO,    USUARIO)
    VALUES (
    '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAPROCESSAMENTO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HISTORICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**]
     '+ ')', 'HISTORICONFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTORICOPEDIDO_D' AND type = 'TR')
  drop trigger HISTORICOPEDIDO_D
go
create trigger dbo.HISTORICOPEDIDO_D on dbo.HISTORICOPEDIDO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM HISTORICOPEDIDO WHERE 
OID =  [**OID'+ RTRIM(CAST(OID AS CHAR(20))) +'**]','HISTORICOPEDIDO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTORICOPEDIDO_I' AND type = 'TR')
   drop trigger HISTORICOPEDIDO_I
go
create trigger dbo.HISTORICOPEDIDO_I on dbo.HISTORICOPEDIDO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO HISTORICOPEDIDO(
        OID,    DATA,    FILIAL,    NUMPED,    USUARIO,    CODSEN,    SITVEN,    SITCONF,    TIPOLIB,    HISTORICO,    CODVEND,    RESERVA)
    VALUES (
      [**OID'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SITCONF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOLIB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HISTORICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'HISTORICOPEDIDO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTORICOPEDIDO_U' AND type = 'TR')
   drop trigger HISTORICOPEDIDO_U
go
create trigger dbo.HISTORICOPEDIDO_U on dbo.HISTORICOPEDIDO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE HISTORICOPEDIDO SET     DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    USUARIO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],    CODSEN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITVEN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITCONF = '+ ISNULL(LTRIM(RTRIM(CAST(SITCONF AS CHAR(254)))),0) +',    TIPOLIB = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOLIB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    HISTORICO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HISTORICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RESERVA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE     OID = [**OID'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'  , 'HISTORICOPEDIDO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTPEDCAD_D' AND type = 'TR')
  drop trigger HISTPEDCAD_D
go
create trigger dbo.HISTPEDCAD_D on dbo.HISTPEDCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM HISTPEDCAD WHERE 
Filial = '''+ RTRIM(LTRIM(Filial)) + '''  and NumPed = '+ RTRIM(LTRIM(CAST(NumPed as char(120)))) + ' ','HISTPEDCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTPEDCAD_I' AND type = 'TR')
   drop trigger HISTPEDCAD_I
go
create trigger dbo.HISTPEDCAD_I on dbo.HISTPEDCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO HISTPEDCAD(
        FILIAL,    NUMPED,    SITUACAO,    HISTORICO,    USUARIO,    DATA)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HISTORICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+'
     '+ ')', 'HISTPEDCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'HISTPEDCAD_U' AND type = 'TR')
   drop trigger HISTPEDCAD_U
go
create trigger dbo.HISTPEDCAD_U on dbo.HISTPEDCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE HISTPEDCAD SET     SITUACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    HISTORICO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HISTORICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    USUARIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+  ' WHERE Filial = '''+ RTRIM(Filial)  + ''' and NumPed = '+ RTRIM(CAST(NumPed as char(254))) +  ''   , 'HISTPEDCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'INCONSISTENCIANFE_I' AND type = 'TR')
   drop trigger INCONSISTENCIANFE_I
go
create trigger dbo.INCONSISTENCIANFE_I on dbo.INCONSISTENCIANFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO INCONSISTENCIANFE(
        NUMORD,    CODMENSAGEM,    DESCRICAO,    DATAPROCESSAMENTO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMENSAGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCRICAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAPROCESSAMENTO,20 ))) +''',120)','NULL')+'
     '+ ')', 'INCONSISTENCIANFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITCONFSAIDANF_D' AND type = 'TR')
  drop trigger ITCONFSAIDANF_D
go
create trigger dbo.ITCONFSAIDANF_D on dbo.ITCONFSAIDANF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITCONFSAIDANF WHERE 
NUMEROLISTA = '+ RTRIM(LTRIM(CAST(NUMEROLISTA as char(120)))) + '  and CODPRO = '''+ RTRIM(LTRIM(CODPRO)) + '''  and VOLUME = '''+ RTRIM(LTRIM(VOLUME)) + ''' ','ITCONFSAIDANF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITCONFSAIDANF_I' AND type = 'TR')
   drop trigger ITCONFSAIDANF_I
go
create trigger dbo.ITCONFSAIDANF_I on dbo.ITCONFSAIDANF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITCONFSAIDANF(
        NUMEROLISTA,    CODPRO,    QTDCONFERIDA,    VOLUME)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(VOLUME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'ITCONFSAIDANF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITCONFSAIDANF_U' AND type = 'TR')
   drop trigger ITCONFSAIDANF_U
go
create trigger dbo.ITCONFSAIDANF_U on dbo.ITCONFSAIDANF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITCONFSAIDANF SET     QTDCONFERIDA = '+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDA AS CHAR(254)))),0) +''+  ' WHERE NUMEROLISTA = '+ RTRIM(CAST(NUMEROLISTA as char(254))) +  ' and CODPRO = '''+ RTRIM(CODPRO)  + ''' and VOLUME = '''+ RTRIM(VOLUME)  + ''''   , 'ITCONFSAIDANF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCANCELADO_D' AND type = 'TR')
  drop trigger ITEMCANCELADO_D
go
create trigger dbo.ITEMCANCELADO_D on dbo.ITEMCANCELADO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITEMCANCELADO WHERE 
IDENTIFICADOR = '+ RTRIM(LTRIM(CAST(IDENTIFICADOR as char(120)))) + ' ','ITEMCANCELADO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCANCELADO_INST_I' AND type = 'TR')
   drop trigger ITEMCANCELADO_INST_I
go
create trigger dbo.ITEMCANCELADO_INST_I on dbo.ITEMCANCELADO INSTEAD OF insert as
begin
    SELECT * INTO #Inserted FROM Inserted
    UPDATE #Inserted SET IDENTIFICADOR = (@@spid*-1)
    INSERT INTO ITEMCANCELADO SELECT * FROM #Inserted
    Return
end
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCANCELADO_I' AND type = 'TR')
   drop trigger ITEMCANCELADO_I
go
create trigger dbo.ITEMCANCELADO_I on dbo.ITEMCANCELADO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITEMCANCELADO(
        NUMPED,    FILIAL,    NUMPEDAVULSO,    RITEMCLI,    OBSERVACAO,    QUANTIDADE,    CODPRO,    PRECO,    IDENTIFICADOR,    RIDENTIFICADOR,    RECOLHER,    DATACANCELAMENTO,    ROIDNOTACREDITO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAVULSO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IDENTIFICADOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RIDENTIFICADOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RECOLHER AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATACANCELAMENTO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(ROIDNOTACREDITO AS CHAR(254)))),0) +'
     '+ ')', 'ITEMCANCELADO' FROM inserted
    declare @nContador integer
    exec GERASEMENTE_P 'TW_IDENTIFICADOR', 7, @nContador OUTPUT
    if @nContador > 0
      update ITEMCANCELADO set IDENTIFICADOR = @nContador WHERE IDENTIFICADOR = (select IDENTIFICADOR from inserted WHERE IDENTIFICADOR=(@@spid*-1))
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCANCELADO_U' AND type = 'TR')
   drop trigger ITEMCANCELADO_U
go
create trigger dbo.ITEMCANCELADO_U on dbo.ITEMCANCELADO for update as
begin
  if (select count(*) from deleted where IDENTIFICADOR = @@spid*-1 ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMCANCELADO SET     NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDAVULSO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAVULSO AS CHAR(254)))),0) +',    RITEMCLI = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLI AS CHAR(254)))),0) +',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +',    CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PRECO = '+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +',    IDENTIFICADOR = '+ ISNULL(LTRIM(RTRIM(CAST(IDENTIFICADOR AS CHAR(254)))),0) +',    RIDENTIFICADOR = '+ ISNULL(LTRIM(RTRIM(CAST(RIDENTIFICADOR AS CHAR(254)))),0) +',    RECOLHER = '+ ISNULL(LTRIM(RTRIM(CAST(RECOLHER AS CHAR(254)))),0) +',    DATACANCELAMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATACANCELAMENTO,20)))+''',120)','NULL')+',    ROIDNOTACREDITO = '+ ISNULL(LTRIM(RTRIM(CAST(ROIDNOTACREDITO AS CHAR(254)))),0) +''+  ' WHERE IDENTIFICADOR = '+ ISNULL(LTRIM(RTRIM(CAST((@@spid*-1) AS CHAR(254)))),0) , 'ITEMCANCELADO' FROM inserted
 else
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMCANCELADO SET     NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDAVULSO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAVULSO AS CHAR(254)))),0) +',    RITEMCLI = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLI AS CHAR(254)))),0) +',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +',    CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PRECO = '+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +',    IDENTIFICADOR = '+ ISNULL(LTRIM(RTRIM(CAST(IDENTIFICADOR AS CHAR(254)))),0) +',    RIDENTIFICADOR = '+ ISNULL(LTRIM(RTRIM(CAST(RIDENTIFICADOR AS CHAR(254)))),0) +',    RECOLHER = '+ ISNULL(LTRIM(RTRIM(CAST(RECOLHER AS CHAR(254)))),0) +',    DATACANCELAMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATACANCELAMENTO,20)))+''',120)','NULL')+',    ROIDNOTACREDITO = '+ ISNULL(LTRIM(RTRIM(CAST(ROIDNOTACREDITO AS CHAR(254)))),0) +''+  ' WHERE IDENTIFICADOR = '+ RTRIM(CAST(IDENTIFICADOR as char(254))) +  ''   , 'ITEMCANCELADO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCLICAD_D' AND type = 'TR')
  drop trigger ITEMCLICAD_D
go
create trigger dbo.ITEMCLICAD_D on dbo.ITEMCLICAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITEMCLICAD WHERE 
item = '+ RTRIM(LTRIM(CAST(item as char(120)))) + ' ','ITEMCLICAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCLICAD_INST_I' AND type = 'TR')
   drop trigger ITEMCLICAD_INST_I
go
create trigger dbo.ITEMCLICAD_INST_I on dbo.ITEMCLICAD INSTEAD OF insert as
begin
    SELECT * INTO #Inserted FROM Inserted
    UPDATE #Inserted SET item = (@@spid*-1)
    INSERT INTO ITEMCLICAD SELECT * FROM #Inserted
    Return
end
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCLICAD_I' AND type = 'TR')
   drop trigger ITEMCLICAD_I
go
create trigger dbo.ITEMCLICAD_I on dbo.ITEMCLICAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITEMCLICAD(
        NUMPED,    CODPRO,    DV,    QUANT,    UNID,    PRECO,    VALDESC,    QUANTENT,    DTPREVENT,    FILIAL,    NUMORD,    VALORIPI,    ALIQIPI,    ORDPROD,    DESCUNIT,    OBS,    NUMPEDFIL,    SITUACAO,    FILIALCLI,    TIPOENTR,    LIBQUANT,    RESERVA,    NUMCARGA,    PERDESC,    PENDEST,    LIBEST,    NOVQUANENT,    QTDDISPLIB,    PRECOSTX,    TPA_COD,    ITEM,    FACONV,    PRECONF,    PRECOCOMP,    QUANTDISP,    QUANTPED,    DESCRATE,    QUANTCAN,    PENDENTE,    ITEMRELACIONADO,    RCARENCIAPARCELA,    RDOCPLANO,    RDOCENTRADA,    FATOR1,    FATOR2,    ITEMSERVICO,    FILIALRETIRADA,    FILIALTRANSFERENCIA,    FATURAMENTODIRETO,    MOSTRUARIO,    PRECOCOMIS,    PLANOSEMJUROS,    CODVEND,    NUMPEDFILIAL,    VALENTRADA,    FATORAUX,    SITFAT,    NUMORDFAT,    NUMORDRET,    NUMORDTRANSF,    ITEMSELECIONADO,    LOTENF,    VALIDADENF,    FLAGEMIT,    GARANTIAVENDA,    CMIPI,    QUANTSOLICITADA,    PAGINAORDEMSEPARACAO,    SEQUENCIAORDEMSEPARACAO,    TEMSEGURO,    ENTREGAEXPED,    FLAGOFERTA,    ITEMFAT,    CUSTOREPOSICAO,    PRECOUNITORIG,    PRECOTX,    ID_CLIENTECENTROCUSTO,    PRECOCOMICMS,    VALORICMS,    RCADASTROFAIXADESCONTO,    PERCFAIXADESC,    PERCFAIXADESCONTO,    PERCCOM,    FLAGCOMFAIXA,    PRECOOFERTA)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNID AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTENT AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVENT,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ORDPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(DESCUNIT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDFIL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBQUANT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCARGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PERDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PENDEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(LIBEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NOVQUANENT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QTDDISPLIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOSTX AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPA_COD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FACONV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECONF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMP AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTDISP AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCRATE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTCAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PENDENTE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMRELACIONADO AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCARENCIAPARCELA AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCPLANO AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCENTRADA AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(FATOR1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FATOR2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMSERVICO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALRETIRADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALTRANSFERENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FATURAMENTODIRETO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MOSTRUARIO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PLANOSEMJUROS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDFILIAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALENTRADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FATORAUX AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SITFAT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFAT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDRET AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDTRANSF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMSELECIONADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTENF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,VALIDADENF,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(GARANTIAVENDA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CMIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTSOLICITADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PAGINAORDEMSEPARACAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SEQUENCIAORDEMSEPARACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TEMSEGURO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENTREGAEXPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FLAGOFERTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTOREPOSICAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOUNITORIG AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOTX AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ID_CLIENTECENTROCUSTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RCADASTROFAIXADESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCFAIXADESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCFAIXADESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCCOM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGCOMFAIXA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOOFERTA AS CHAR(254)))),0) +'
     '+ ')', 'ITEMCLICAD' FROM inserted
    declare @nContador integer
    exec GERASEMENTE_P 'TW_IDENTIFICADOR', 7, @nContador OUTPUT
    if @nContador > 0
      update ITEMCLICAD set ITEM = @nContador WHERE ITEM = (select ITEM from inserted WHERE ITEM=(@@spid*-1))
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCLICAD_U' AND type = 'TR')
   drop trigger ITEMCLICAD_U
go
create trigger dbo.ITEMCLICAD_U on dbo.ITEMCLICAD for update as
begin
  if (select count(*) from deleted where item = @@spid*-1 ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMCLICAD SET     NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +',    UNID = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNID AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PRECO = '+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +',    VALDESC = '+ ISNULL(LTRIM(RTRIM(CAST(VALDESC AS CHAR(254)))),0) +',    QUANTENT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTENT AS CHAR(254)))),0) +',    DTPREVENT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVENT,20)))+''',120)','NULL')+',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    VALORIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI AS CHAR(254)))),0) +',    ALIQIPI = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +',    ORDPROD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ORDPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCUNIT = '+ ISNULL(LTRIM(RTRIM(CAST(DESCUNIT AS CHAR(254)))),0) +',    OBS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDFIL = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDFIL AS CHAR(254)))),0) +',    SITUACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIALCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBQUANT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBQUANT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RESERVA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMCARGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCARGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PERDESC = '+ ISNULL(LTRIM(RTRIM(CAST(PERDESC AS CHAR(254)))),0) +',    PENDEST = '+ ISNULL(LTRIM(RTRIM(CAST(PENDEST AS CHAR(254)))),0) +',    LIBEST = '+ ISNULL(LTRIM(RTRIM(CAST(LIBEST AS CHAR(254)))),0) +',    NOVQUANENT = '+ ISNULL(LTRIM(RTRIM(CAST(NOVQUANENT AS CHAR(254)))),0) +',    QTDDISPLIB = '+ ISNULL(LTRIM(RTRIM(CAST(QTDDISPLIB AS CHAR(254)))),0) +',    PRECOSTX = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOSTX AS CHAR(254)))),0) +',    TPA_COD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPA_COD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +',    FACONV = '+ ISNULL(LTRIM(RTRIM(CAST(FACONV AS CHAR(254)))),0) +',    PRECONF = '+ ISNULL(LTRIM(RTRIM(CAST(PRECONF AS CHAR(254)))),0) +',    PRECOCOMP = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMP AS CHAR(254)))),0) +',    QUANTDISP = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTDISP AS CHAR(254)))),0) +',    QUANTPED = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTPED AS CHAR(254)))),0) +',    DESCRATE = '+ ISNULL(LTRIM(RTRIM(CAST(DESCRATE AS CHAR(254)))),0) +',    QUANTCAN = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTCAN AS CHAR(254)))),0) +',    PENDENTE = '+ ISNULL(LTRIM(RTRIM(CAST(PENDENTE AS CHAR(254)))),0) +',    ITEMRELACIONADO = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMRELACIONADO AS CHAR(254)))),0) +',    RCARENCIAPARCELA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCARENCIAPARCELA AS CHAR(254)))),0) +'**],    RDOCPLANO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCPLANO AS CHAR(254)))),0) +'**],    RDOCENTRADA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCENTRADA AS CHAR(254)))),0) +'**],    FATOR1 = '+ ISNULL(LTRIM(RTRIM(CAST(FATOR1 AS CHAR(254)))),0) +',    FATOR2 = '+ ISNULL(LTRIM(RTRIM(CAST(FATOR2 AS CHAR(254)))),0) +',    ITEMSERVICO = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMSERVICO AS CHAR(254)))),0) +',    FILIALRETIRADA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALRETIRADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIALTRANSFERENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALTRANSFERENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FATURAMENTODIRETO = '+ ISNULL(LTRIM(RTRIM(CAST(FATURAMENTODIRETO AS CHAR(254)))),0) +',    MOSTRUARIO = '+ ISNULL(LTRIM(RTRIM(CAST(MOSTRUARIO AS CHAR(254)))),0) +',    PRECOCOMIS = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMIS AS CHAR(254)))),0) +',    PLANOSEMJUROS = '+ ISNULL(LTRIM(RTRIM(CAST(PLANOSEMJUROS AS CHAR(254)))),0) +',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDFILIAL = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDFILIAL AS CHAR(254)))),0) +',    VALENTRADA = '+ ISNULL(LTRIM(RTRIM(CAST(VALENTRADA AS CHAR(254)))),0) +',    FATORAUX = '+ ISNULL(LTRIM(RTRIM(CAST(FATORAUX AS CHAR(254)))),0) +',    SITFAT = '+ ISNULL(LTRIM(RTRIM(CAST(SITFAT AS CHAR(254)))),0) +',    NUMORDFAT = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFAT AS CHAR(254)))),0) +',    NUMORDRET = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDRET AS CHAR(254)))),0) +',    NUMORDTRANSF = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDTRANSF AS CHAR(254)))),0) +',    ITEMSELECIONADO = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMSELECIONADO AS CHAR(254)))),0) +',    LOTENF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTENF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALIDADENF = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,VALIDADENF,20)))+''',120)','NULL')+',    FLAGEMIT = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),0) +',    GARANTIAVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(GARANTIAVENDA AS CHAR(254)))),0) +',    CMIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CMIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTSOLICITADA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTSOLICITADA AS CHAR(254)))),0) +',    PAGINAORDEMSEPARACAO = '+ ISNULL(LTRIM(RTRIM(CAST(PAGINAORDEMSEPARACAO AS CHAR(254)))),0) +',    SEQUENCIAORDEMSEPARACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SEQUENCIAORDEMSEPARACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TEMSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(TEMSEGURO AS CHAR(254)))),0) +',    ENTREGAEXPED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENTREGAEXPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGOFERTA AS CHAR(254)))),0) +',    ITEMFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CUSTOREPOSICAO = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTOREPOSICAO AS CHAR(254)))),0) +',    PRECOUNITORIG = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOUNITORIG AS CHAR(254)))),0) +',    PRECOTX = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOTX AS CHAR(254)))),0) +',    ID_CLIENTECENTROCUSTO = '+ ISNULL(LTRIM(RTRIM(CAST(ID_CLIENTECENTROCUSTO AS CHAR(254)))),0) +',    PRECOCOMICMS = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMICMS AS CHAR(254)))),0) +',    VALORICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +',    RCADASTROFAIXADESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(RCADASTROFAIXADESCONTO AS CHAR(254)))),0) +',    PERCFAIXADESC = '+ ISNULL(LTRIM(RTRIM(CAST(PERCFAIXADESC AS CHAR(254)))),0) +',    PERCFAIXADESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCFAIXADESCONTO AS CHAR(254)))),0) +',    PERCCOM = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCOM AS CHAR(254)))),0) +',    FLAGCOMFAIXA = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGCOMFAIXA AS CHAR(254)))),0) +',    PRECOOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOOFERTA AS CHAR(254)))),0) +''+  ' WHERE item = '+ ISNULL(LTRIM(RTRIM(CAST((@@spid*-1) AS CHAR(254)))),0) , 'ITEMCLICAD' FROM inserted
 else
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMCLICAD SET     NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +',    UNID = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNID AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PRECO = '+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +',    VALDESC = '+ ISNULL(LTRIM(RTRIM(CAST(VALDESC AS CHAR(254)))),0) +',    QUANTENT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTENT AS CHAR(254)))),0) +',    DTPREVENT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVENT,20)))+''',120)','NULL')+',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    VALORIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI AS CHAR(254)))),0) +',    ALIQIPI = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +',    ORDPROD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ORDPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCUNIT = '+ ISNULL(LTRIM(RTRIM(CAST(DESCUNIT AS CHAR(254)))),0) +',    OBS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDFIL = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDFIL AS CHAR(254)))),0) +',    SITUACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIALCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBQUANT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBQUANT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RESERVA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMCARGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCARGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PERDESC = '+ ISNULL(LTRIM(RTRIM(CAST(PERDESC AS CHAR(254)))),0) +',    PENDEST = '+ ISNULL(LTRIM(RTRIM(CAST(PENDEST AS CHAR(254)))),0) +',    LIBEST = '+ ISNULL(LTRIM(RTRIM(CAST(LIBEST AS CHAR(254)))),0) +',    NOVQUANENT = '+ ISNULL(LTRIM(RTRIM(CAST(NOVQUANENT AS CHAR(254)))),0) +',    QTDDISPLIB = '+ ISNULL(LTRIM(RTRIM(CAST(QTDDISPLIB AS CHAR(254)))),0) +',    PRECOSTX = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOSTX AS CHAR(254)))),0) +',    TPA_COD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPA_COD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +',    FACONV = '+ ISNULL(LTRIM(RTRIM(CAST(FACONV AS CHAR(254)))),0) +',    PRECONF = '+ ISNULL(LTRIM(RTRIM(CAST(PRECONF AS CHAR(254)))),0) +',    PRECOCOMP = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMP AS CHAR(254)))),0) +',    QUANTDISP = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTDISP AS CHAR(254)))),0) +',    QUANTPED = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTPED AS CHAR(254)))),0) +',    DESCRATE = '+ ISNULL(LTRIM(RTRIM(CAST(DESCRATE AS CHAR(254)))),0) +',    QUANTCAN = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTCAN AS CHAR(254)))),0) +',    PENDENTE = '+ ISNULL(LTRIM(RTRIM(CAST(PENDENTE AS CHAR(254)))),0) +',    ITEMRELACIONADO = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMRELACIONADO AS CHAR(254)))),0) +',    RCARENCIAPARCELA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCARENCIAPARCELA AS CHAR(254)))),0) +'**],    RDOCPLANO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCPLANO AS CHAR(254)))),0) +'**],    RDOCENTRADA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCENTRADA AS CHAR(254)))),0) +'**],    FATOR1 = '+ ISNULL(LTRIM(RTRIM(CAST(FATOR1 AS CHAR(254)))),0) +',    FATOR2 = '+ ISNULL(LTRIM(RTRIM(CAST(FATOR2 AS CHAR(254)))),0) +',    ITEMSERVICO = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMSERVICO AS CHAR(254)))),0) +',    FILIALRETIRADA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALRETIRADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIALTRANSFERENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALTRANSFERENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FATURAMENTODIRETO = '+ ISNULL(LTRIM(RTRIM(CAST(FATURAMENTODIRETO AS CHAR(254)))),0) +',    MOSTRUARIO = '+ ISNULL(LTRIM(RTRIM(CAST(MOSTRUARIO AS CHAR(254)))),0) +',    PRECOCOMIS = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMIS AS CHAR(254)))),0) +',    PLANOSEMJUROS = '+ ISNULL(LTRIM(RTRIM(CAST(PLANOSEMJUROS AS CHAR(254)))),0) +',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDFILIAL = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDFILIAL AS CHAR(254)))),0) +',    VALENTRADA = '+ ISNULL(LTRIM(RTRIM(CAST(VALENTRADA AS CHAR(254)))),0) +',    FATORAUX = '+ ISNULL(LTRIM(RTRIM(CAST(FATORAUX AS CHAR(254)))),0) +',    SITFAT = '+ ISNULL(LTRIM(RTRIM(CAST(SITFAT AS CHAR(254)))),0) +',    NUMORDFAT = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFAT AS CHAR(254)))),0) +',    NUMORDRET = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDRET AS CHAR(254)))),0) +',    NUMORDTRANSF = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDTRANSF AS CHAR(254)))),0) +',    ITEMSELECIONADO = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMSELECIONADO AS CHAR(254)))),0) +',    LOTENF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTENF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALIDADENF = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,VALIDADENF,20)))+''',120)','NULL')+',    FLAGEMIT = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),0) +',    GARANTIAVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(GARANTIAVENDA AS CHAR(254)))),0) +',    CMIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CMIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTSOLICITADA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTSOLICITADA AS CHAR(254)))),0) +',    PAGINAORDEMSEPARACAO = '+ ISNULL(LTRIM(RTRIM(CAST(PAGINAORDEMSEPARACAO AS CHAR(254)))),0) +',    SEQUENCIAORDEMSEPARACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SEQUENCIAORDEMSEPARACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TEMSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(TEMSEGURO AS CHAR(254)))),0) +',    ENTREGAEXPED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENTREGAEXPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGOFERTA AS CHAR(254)))),0) +',    ITEMFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CUSTOREPOSICAO = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTOREPOSICAO AS CHAR(254)))),0) +',    PRECOUNITORIG = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOUNITORIG AS CHAR(254)))),0) +',    PRECOTX = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOTX AS CHAR(254)))),0) +',    ID_CLIENTECENTROCUSTO = '+ ISNULL(LTRIM(RTRIM(CAST(ID_CLIENTECENTROCUSTO AS CHAR(254)))),0) +',    PRECOCOMICMS = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMICMS AS CHAR(254)))),0) +',    VALORICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +',    RCADASTROFAIXADESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(RCADASTROFAIXADESCONTO AS CHAR(254)))),0) +',    PERCFAIXADESC = '+ ISNULL(LTRIM(RTRIM(CAST(PERCFAIXADESC AS CHAR(254)))),0) +',    PERCFAIXADESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCFAIXADESCONTO AS CHAR(254)))),0) +',    PERCCOM = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCOM AS CHAR(254)))),0) +',    FLAGCOMFAIXA = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGCOMFAIXA AS CHAR(254)))),0) +',    PRECOOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOOFERTA AS CHAR(254)))),0) +''+  ' WHERE item = '+ RTRIM(CAST(item as char(254))) +  ''   , 'ITEMCLICAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCLICOMPLEMENTO_D' AND type = 'TR')
  drop trigger ITEMCLICOMPLEMENTO_D
go
create trigger dbo.ITEMCLICOMPLEMENTO_D on dbo.ITEMCLICOMPLEMENTO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITEMCLICOMPLEMENTO WHERE 
RITEM = '+ RTRIM(LTRIM(CAST(RITEM as char(120)))) + ' ','ITEMCLICOMPLEMENTO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCLICOMPLEMENTO_I' AND type = 'TR')
   drop trigger ITEMCLICOMPLEMENTO_I
go
create trigger dbo.ITEMCLICOMPLEMENTO_I on dbo.ITEMCLICOMPLEMENTO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITEMCLICOMPLEMENTO(
        RITEM,    PESOINICIAL,    PESOFINAL,    ITEMOFERTA,    NUMPED,    SITCONF,    TPASEMDESCONTO,    PRECOMOEDA2,    DESCRATEMOEDA2,    VALORIPIMOEDA2,    COTACAOMOEDA,    PERCCOMISSAO,    OIDFUNCIONARIO,    PRECOBASE,    NUMORDAVULSO,    NUMNOTAAVULSO,    SERIEAVULSO,    DTEMISAVULSO,    VALORNFAVULSO,    RCONCORRENTE,    MONTAGEM,    PERCCOMISVENDEXTORIGINAL,    PERCCOMISVENDEXTORCAMENTO,    RSEGURO,    VALORSEGURO,    PRODUTOEMOFERTA,    MARKUPREAL,    VALCUSTOREAL,    VALCUSTOFRETE,    PERCCUSTOFINANCEIRO,    OIDPESQUISADEPRECO,    PERCBONIFICACAO,    PRECOVENDAMINIMO,    COMPRARTOTAL,    ENCOMENDA,    ITEMORIGINAL,    PRECOTABELA,    PERCDESCTOUNITARIO,    LIBBONIFICACAO,    RATEIOOUTRASDESPESAS,    PRECOUNITARIOCOMERCIAL,    ENTREGAPOSTERIOR,    DATAMARCADA,    TURNO,    RCODLISTA,    VENDADESEGURO,    VENDADESERVICO,    VALORSUBSTRIBUTARIA,    ITEMNF,    QUANTSAGA,    PRECOCUSTOUNITAREAVENDA,    ICMSCOMPRA,    QUANT1TEORICO,    QUANT1REAL,    QUANT1LIBERADA,    PESAGEM,    IMPRIME2UNIDADE,    UNIDPEDIDA,    TABELAUTILIZADA,    PRECONFTX,    DESCRPRODUTONF,    NUMEROCUPOM,    ETIQUETAPESAGEM,    CONJUNTORELACIONADO,    CODIGODEPOSITOORIGEM,    CODIGODEPOSITODESTINO,    PRECOVENDAMK,    CUSTOMEDIOGERENCIAL,    STATUSCONFERENCIAWMS,    OBSERVACAO,    ITEMDESMEMBRADO,    AMBIENTE,    CONTRATO,    QUANTATENDIDACONTRATO,    RESERVASIMPLIFICADA,    PEDIDOCOMPRA,    VALORDESCONTOMAXIMO,    REENVIO,    PROFINTERNO,    PROFEXTERNO,    TROCOUFILIALRETIRADA,    CODVEND,    RITEMCLASSE,    PERCDESCTOADICIONALOFERTA,    CUSTOVENDA,    CUSTTRAN,    ICMTRAN,    C2MOETRAN,    QUANTPENDENTE,    DESDOBRAR,    PRECODESDOBRAMENTO,    SITMANUT,    QUANTFATURADAANTERIOR,    INCLUIDOECF,    LIBDTMAXENTREGA,    CODCOR,    IDTINTA,    CODPROTINTA,    VALORSUBSTRIBUTARIATX,    CODTRAN,    CODTRAN2,    VALORIPITX,    VALORSUBSTRIBUTARIAUNT,    NUMORDSAIDACOLIGADA,    NUMORDENTRACOLIGADA,    USULIBALTPRECOMARGEM,    SIMPLESREMESSA,    DESCRICAOTEMPORARIA,    CF,    CM,    USOMENS,    TIPOMENS,    BASEICMS,    ALIQICMS,    VALORICMS,    PRECOCOMDESCONTODEICMS,    ALIQPIS,    VALORPIS,    ALIQCOFINS,    VALORCOFINS,    DATACANCELAMENTO,    COMISOFERTA,    PERCOMISSAOINDICADOR,    PERCPRECOVENDAMADEIRA,    RCODPRO,    LINHAORDCOMPRA,    PERCMVA,    SITMON,    PERDESCUNITDESTACADO,    IMPRIMIUCOMPROVANTEENTREGA,    DESCICMSSUFRAMA,    NFCI,    FCI_NUMORDORIGEM,    FCI_RITEMORIGEM,    PERCFRETE,    DESCONTOENTREGA)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(RITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PESOINICIAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PESOFINAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMOFERTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITCONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPASEMDESCONTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECOMOEDA2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCRATEMOEDA2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPIMOEDA2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COTACAOMOEDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISSAO AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDFUNCIONARIO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(PRECOBASE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDAVULSO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTAAVULSO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIEAVULSO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMISAVULSO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VALORNFAVULSO AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCONCORRENTE AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(MONTAGEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDEXTORIGINAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDEXTORCAMENTO AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RSEGURO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(VALORSEGURO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRODUTOEMOFERTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MARKUPREAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOREAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCCUSTOFINANCEIRO AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDPESQUISADEPRECO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(PERCBONIFICACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOVENDAMINIMO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COMPRARTOTAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ENCOMENDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMORIGINAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOTABELA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCTOUNITARIO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBBONIFICACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RATEIOOUTRASDESPESAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOUNITARIOCOMERCIAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ENTREGAPOSTERIOR AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAMARCADA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TURNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RCODLISTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VENDADESEGURO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VENDADESERVICO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMNF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTSAGA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOCUSTOUNITAREAVENDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMSCOMPRA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANT1TEORICO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANT1REAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANT1LIBERADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PESAGEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPRIME2UNIDADE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDPEDIDA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TABELAUTILIZADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECONFTX AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCRPRODUTONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ETIQUETAPESAGEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONJUNTORELACIONADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGODEPOSITOORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGODEPOSITODESTINO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECOVENDAMK AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTOMEDIOGERENCIAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(STATUSCONFERENCIAWMS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ITEMDESMEMBRADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AMBIENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CONTRATO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTATENDIDACONTRATO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RESERVASIMPLIFICADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PEDIDOCOMPRA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTOMAXIMO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REENVIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PROFINTERNO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PROFEXTERNO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TROCOUFILIALRETIRADA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLASSE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCTOADICIONALOFERTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTOVENDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTTRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMTRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(C2MOETRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTPENDENTE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESDOBRAR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECODESDOBRAMENTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SITMANUT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTFATURADAANTERIOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(INCLUIDOECF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBDTMAXENTREGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CODCOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IDTINTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPROTINTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIATX AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPITX AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIAUNT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDSAIDACOLIGADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDENTRACOLIGADA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USULIBALTPRECOMARGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SIMPLESREMESSA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCRICAOTEMPORARIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USOMENS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOMENS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMDESCONTODEICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORCOFINS AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATACANCELAMENTO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(COMISOFERTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCOMISSAOINDICADOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCPRECOVENDAMADEIRA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RCODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(LINHAORDCOMPRA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCMVA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMON AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PERDESCUNITDESTACADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPRIMIUCOMPROVANTEENTREGA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCICMSSUFRAMA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFCI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FCI_NUMORDORIGEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FCI_RITEMORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PERCFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOENTREGA AS CHAR(254)))),0) +'
     '+ ')', 'ITEMCLICOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMCLICOMPLEMENTO_U' AND type = 'TR')
   drop trigger ITEMCLICOMPLEMENTO_U
go
create trigger dbo.ITEMCLICOMPLEMENTO_U on dbo.ITEMCLICOMPLEMENTO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMCLICOMPLEMENTO SET     PESOINICIAL = '+ ISNULL(LTRIM(RTRIM(CAST(PESOINICIAL AS CHAR(254)))),0) +',    PESOFINAL = '+ ISNULL(LTRIM(RTRIM(CAST(PESOFINAL AS CHAR(254)))),0) +',    ITEMOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMOFERTA AS CHAR(254)))),0) +',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    SITCONF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITCONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TPASEMDESCONTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPASEMDESCONTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PRECOMOEDA2 = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOMOEDA2 AS CHAR(254)))),0) +',    DESCRATEMOEDA2 = '+ ISNULL(LTRIM(RTRIM(CAST(DESCRATEMOEDA2 AS CHAR(254)))),0) +',    VALORIPIMOEDA2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPIMOEDA2 AS CHAR(254)))),0) +',    COTACAOMOEDA = '+ ISNULL(LTRIM(RTRIM(CAST(COTACAOMOEDA AS CHAR(254)))),0) +',    PERCCOMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISSAO AS CHAR(254)))),0) +',    OIDFUNCIONARIO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDFUNCIONARIO AS CHAR(254)))),0) +'**],    PRECOBASE = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOBASE AS CHAR(254)))),0) +',    NUMORDAVULSO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDAVULSO AS CHAR(254)))),0) +',    NUMNOTAAVULSO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTAAVULSO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIEAVULSO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIEAVULSO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTEMISAVULSO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMISAVULSO,20)))+''',120)','NULL')+',    VALORNFAVULSO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORNFAVULSO AS CHAR(254)))),0) +',    RCONCORRENTE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCONCORRENTE AS CHAR(254)))),0) +'**],    MONTAGEM = '+ ISNULL(LTRIM(RTRIM(CAST(MONTAGEM AS CHAR(254)))),0) +',    PERCCOMISVENDEXTORIGINAL = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDEXTORIGINAL AS CHAR(254)))),0) +',    PERCCOMISVENDEXTORCAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDEXTORCAMENTO AS CHAR(254)))),0) +',    RSEGURO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RSEGURO AS CHAR(254)))),0) +'**],    VALORSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSEGURO AS CHAR(254)))),0) +',    PRODUTOEMOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(PRODUTOEMOFERTA AS CHAR(254)))),0) +',    MARKUPREAL = '+ ISNULL(LTRIM(RTRIM(CAST(MARKUPREAL AS CHAR(254)))),0) +',    VALCUSTOREAL = '+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOREAL AS CHAR(254)))),0) +',    VALCUSTOFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOFRETE AS CHAR(254)))),0) +',    PERCCUSTOFINANCEIRO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCUSTOFINANCEIRO AS CHAR(254)))),0) +',    OIDPESQUISADEPRECO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDPESQUISADEPRECO AS CHAR(254)))),0) +'**],    PERCBONIFICACAO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCBONIFICACAO AS CHAR(254)))),0) +',    PRECOVENDAMINIMO = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOVENDAMINIMO AS CHAR(254)))),0) +',    COMPRARTOTAL = '+ ISNULL(LTRIM(RTRIM(CAST(COMPRARTOTAL AS CHAR(254)))),0) +',    ENCOMENDA = '+ ISNULL(LTRIM(RTRIM(CAST(ENCOMENDA AS CHAR(254)))),0) +',    ITEMORIGINAL = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMORIGINAL AS CHAR(254)))),0) +',    PRECOTABELA = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOTABELA AS CHAR(254)))),0) +',    PERCDESCTOUNITARIO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCTOUNITARIO AS CHAR(254)))),0) +',    LIBBONIFICACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBBONIFICACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RATEIOOUTRASDESPESAS = '+ ISNULL(LTRIM(RTRIM(CAST(RATEIOOUTRASDESPESAS AS CHAR(254)))),0) +',    PRECOUNITARIOCOMERCIAL = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOUNITARIOCOMERCIAL AS CHAR(254)))),0) +',    ENTREGAPOSTERIOR = '+ ISNULL(LTRIM(RTRIM(CAST(ENTREGAPOSTERIOR AS CHAR(254)))),0) +',    DATAMARCADA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAMARCADA,20)))+''',120)','NULL')+',    TURNO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TURNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RCODLISTA = '+ ISNULL(LTRIM(RTRIM(CAST(RCODLISTA AS CHAR(254)))),0) +',    VENDADESEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(VENDADESEGURO AS CHAR(254)))),0) +',    VENDADESERVICO = '+ ISNULL(LTRIM(RTRIM(CAST(VENDADESERVICO AS CHAR(254)))),0) +',    VALORSUBSTRIBUTARIA = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIA AS CHAR(254)))),0) +',    ITEMNF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMNF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTSAGA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTSAGA AS CHAR(254)))),0) +',    PRECOCUSTOUNITAREAVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOCUSTOUNITAREAVENDA AS CHAR(254)))),0) +',    ICMSCOMPRA = '+ ISNULL(LTRIM(RTRIM(CAST(ICMSCOMPRA AS CHAR(254)))),0) +',    QUANT1TEORICO = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT1TEORICO AS CHAR(254)))),0) +',    QUANT1REAL = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT1REAL AS CHAR(254)))),0) +',    QUANT1LIBERADA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT1LIBERADA AS CHAR(254)))),0) +',    PESAGEM = '+ ISNULL(LTRIM(RTRIM(CAST(PESAGEM AS CHAR(254)))),0) +',    IMPRIME2UNIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(IMPRIME2UNIDADE AS CHAR(254)))),0) +',    UNIDPEDIDA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDPEDIDA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TABELAUTILIZADA = '+ ISNULL(LTRIM(RTRIM(CAST(TABELAUTILIZADA AS CHAR(254)))),0) +',    PRECONFTX = '+ ISNULL(LTRIM(RTRIM(CAST(PRECONFTX AS CHAR(254)))),0) +',    DESCRPRODUTONF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCRPRODUTONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROCUPOM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ETIQUETAPESAGEM = '+ ISNULL(LTRIM(RTRIM(CAST(ETIQUETAPESAGEM AS CHAR(254)))),0) +',    CONJUNTORELACIONADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONJUNTORELACIONADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODIGODEPOSITOORIGEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGODEPOSITOORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODIGODEPOSITODESTINO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGODEPOSITODESTINO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PRECOVENDAMK = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOVENDAMK AS CHAR(254)))),0) +',    CUSTOMEDIOGERENCIAL = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTOMEDIOGERENCIAL AS CHAR(254)))),0) +',    STATUSCONFERENCIAWMS = '+ ISNULL(LTRIM(RTRIM(CAST(STATUSCONFERENCIAWMS AS CHAR(254)))),0) +',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ITEMDESMEMBRADO = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMDESMEMBRADO AS CHAR(254)))),0) +',    AMBIENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AMBIENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONTRATO = '+ ISNULL(LTRIM(RTRIM(CAST(CONTRATO AS CHAR(254)))),0) +',    QUANTATENDIDACONTRATO = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTATENDIDACONTRATO AS CHAR(254)))),0) +',    RESERVASIMPLIFICADA = '+ ISNULL(LTRIM(RTRIM(CAST(RESERVASIMPLIFICADA AS CHAR(254)))),0) +',    PEDIDOCOMPRA = '+ ISNULL(LTRIM(RTRIM(CAST(PEDIDOCOMPRA AS CHAR(254)))),0) +',    VALORDESCONTOMAXIMO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTOMAXIMO AS CHAR(254)))),0) +',    REENVIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REENVIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PROFINTERNO = '+ ISNULL(LTRIM(RTRIM(CAST(PROFINTERNO AS CHAR(254)))),0) +',    PROFEXTERNO = '+ ISNULL(LTRIM(RTRIM(CAST(PROFEXTERNO AS CHAR(254)))),0) +',    TROCOUFILIALRETIRADA = '+ ISNULL(LTRIM(RTRIM(CAST(TROCOUFILIALRETIRADA AS CHAR(254)))),0) +',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RITEMCLASSE = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLASSE AS CHAR(254)))),0) +',    PERCDESCTOADICIONALOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCTOADICIONALOFERTA AS CHAR(254)))),0) +',    CUSTOVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTOVENDA AS CHAR(254)))),0) +',    CUSTTRAN = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTTRAN AS CHAR(254)))),0) +',    ICMTRAN = '+ ISNULL(LTRIM(RTRIM(CAST(ICMTRAN AS CHAR(254)))),0) +',    C2MOETRAN = '+ ISNULL(LTRIM(RTRIM(CAST(C2MOETRAN AS CHAR(254)))),0) +',    QUANTPENDENTE = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTPENDENTE AS CHAR(254)))),0) +',    DESDOBRAR = '+ ISNULL(LTRIM(RTRIM(CAST(DESDOBRAR AS CHAR(254)))),0) +',    PRECODESDOBRAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(PRECODESDOBRAMENTO AS CHAR(254)))),0) +',    SITMANUT = '+ ISNULL(LTRIM(RTRIM(CAST(SITMANUT AS CHAR(254)))),0) +',    QUANTFATURADAANTERIOR = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTFATURADAANTERIOR AS CHAR(254)))),0) +',    INCLUIDOECF = '+ ISNULL(LTRIM(RTRIM(CAST(INCLUIDOECF AS CHAR(254)))),0) +',    LIBDTMAXENTREGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBDTMAXENTREGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODCOR = '+ ISNULL(LTRIM(RTRIM(CAST(CODCOR AS CHAR(254)))),0) +',    IDTINTA = '+ ISNULL(LTRIM(RTRIM(CAST(IDTINTA AS CHAR(254)))),0) +',    CODPROTINTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPROTINTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORSUBSTRIBUTARIATX = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIATX AS CHAR(254)))),0) +',    CODTRAN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODTRAN2 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORIPITX = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPITX AS CHAR(254)))),0) +',    VALORSUBSTRIBUTARIAUNT = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIAUNT AS CHAR(254)))),0) +',    NUMORDSAIDACOLIGADA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDSAIDACOLIGADA AS CHAR(254)))),0) +',    NUMORDENTRACOLIGADA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDENTRACOLIGADA AS CHAR(254)))),0) +',    USULIBALTPRECOMARGEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USULIBALTPRECOMARGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SIMPLESREMESSA = '+ ISNULL(LTRIM(RTRIM(CAST(SIMPLESREMESSA AS CHAR(254)))),0) +',    DESCRICAOTEMPORARIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCRICAOTEMPORARIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    USOMENS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USOMENS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOMENS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOMENS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BASEICMS = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICMS AS CHAR(254)))),0) +',    ALIQICMS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMS AS CHAR(254)))),0) +',    VALORICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +',    PRECOCOMDESCONTODEICMS = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOCOMDESCONTODEICMS AS CHAR(254)))),0) +',    ALIQPIS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQPIS AS CHAR(254)))),0) +',    VALORPIS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORPIS AS CHAR(254)))),0) +',    ALIQCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINS AS CHAR(254)))),0) +',    VALORCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORCOFINS AS CHAR(254)))),0) +',    DATACANCELAMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATACANCELAMENTO,20)))+''',120)','NULL')+',    COMISOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(COMISOFERTA AS CHAR(254)))),0) +',    PERCOMISSAOINDICADOR = '+ ISNULL(LTRIM(RTRIM(CAST(PERCOMISSAOINDICADOR AS CHAR(254)))),0) +',    PERCPRECOVENDAMADEIRA = '+ ISNULL(LTRIM(RTRIM(CAST(PERCPRECOVENDAMADEIRA AS CHAR(254)))),0) +',    RCODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RCODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LINHAORDCOMPRA = '+ ISNULL(LTRIM(RTRIM(CAST(LINHAORDCOMPRA AS CHAR(254)))),0) +',    PERCMVA = '+ ISNULL(LTRIM(RTRIM(CAST(PERCMVA AS CHAR(254)))),0) +',    SITMON = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMON AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PERDESCUNITDESTACADO = '+ ISNULL(LTRIM(RTRIM(CAST(PERDESCUNITDESTACADO AS CHAR(254)))),0) +',    IMPRIMIUCOMPROVANTEENTREGA = '+ ISNULL(LTRIM(RTRIM(CAST(IMPRIMIUCOMPROVANTEENTREGA AS CHAR(254)))),0) +',    DESCICMSSUFRAMA = '+ ISNULL(LTRIM(RTRIM(CAST(DESCICMSSUFRAMA AS CHAR(254)))),0) +',    NFCI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFCI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FCI_NUMORDORIGEM = '+ ISNULL(LTRIM(RTRIM(CAST(FCI_NUMORDORIGEM AS CHAR(254)))),0) +',    FCI_RITEMORIGEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FCI_RITEMORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PERCFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(PERCFRETE AS CHAR(254)))),0) +',    DESCONTOENTREGA = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOENTREGA AS CHAR(254)))),0) +''+  ' WHERE RITEM = '+ RTRIM(CAST(RITEM as char(254))) +  ''   , 'ITEMCLICOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMDAV_D' AND type = 'TR')
  drop trigger ITEMDAV_D
go
create trigger dbo.ITEMDAV_D on dbo.ITEMDAV for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITEMDAV WHERE 
OID = '+ RTRIM(LTRIM(CAST(OID as char(120)))) + ' ','ITEMDAV' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMDAV_I' AND type = 'TR')
   drop trigger ITEMDAV_I
go
create trigger dbo.ITEMDAV_I on dbo.ITEMDAV for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITEMDAV(
        RITEMCLI,    NUMDAV,    DATAINCLUSAO,    NUMEROITEM,    CODPRO,    QUANTIDADE,    UNIDADE,    VALORUNIT,    DESCONTO,    ACRESCIMO,    VALORTOTAL,    SITUACAOTRIB,    ALIQUOTA,    CANCELADO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAINCLUSAO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROITEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORUNIT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ACRESCIMO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORTOTAL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAOTRIB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ALIQUOTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CANCELADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'ITEMDAV' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMDAV_U' AND type = 'TR')
   drop trigger ITEMDAV_U
go
create trigger dbo.ITEMDAV_U on dbo.ITEMDAV for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMDAV SET     RITEMCLI = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLI AS CHAR(254)))),0) +',    NUMDAV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATAINCLUSAO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAINCLUSAO,20)))+''',120)','NULL')+',    NUMEROITEM = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROITEM AS CHAR(254)))),0) +',    CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +',    UNIDADE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORUNIT = '+ ISNULL(LTRIM(RTRIM(CAST(VALORUNIT AS CHAR(254)))),0) +',    DESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +',    ACRESCIMO = '+ ISNULL(LTRIM(RTRIM(CAST(ACRESCIMO AS CHAR(254)))),0) +',    VALORTOTAL = '+ ISNULL(LTRIM(RTRIM(CAST(VALORTOTAL AS CHAR(254)))),0) +',    SITUACAOTRIB = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAOTRIB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ALIQUOTA = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQUOTA AS CHAR(254)))),0) +',    CANCELADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CANCELADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE     OID = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'  , 'ITEMDAV' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMDEPEST_D' AND type = 'TR')
  drop trigger ITEMDEPEST_D
go
create trigger dbo.ITEMDEPEST_D on dbo.ITEMDEPEST for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITEMDEPEST WHERE 
deposito = '''+ RTRIM(LTRIM(deposito)) + '''  and filial = '''+ RTRIM(LTRIM(filial)) + '''  and codpro = '''+ RTRIM(LTRIM(codpro)) + ''' ','ITEMDEPEST' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMDEPEST_I' AND type = 'TR')
   drop trigger ITEMDEPEST_I
go
create trigger dbo.ITEMDEPEST_I on dbo.ITEMDEPEST for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITEMDEPEST(
        DEPOSITO,    FILIAL,    CODPRO,    QUANT,    PRECOENTR,    ESTESTRATE,    SALDOCUST,    SALDOINIC)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPOSITO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOENTR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ESTESTRATE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SALDOCUST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SALDOINIC AS CHAR(254)))),0) +'
     '+ ')', 'ITEMDEPEST' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMDEPEST_U' AND type = 'TR')
   drop trigger ITEMDEPEST_U
go
create trigger dbo.ITEMDEPEST_U on dbo.ITEMDEPEST for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMDEPEST SET     QUANT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +',    PRECOENTR = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOENTR AS CHAR(254)))),0) +',    ESTESTRATE = '+ ISNULL(LTRIM(RTRIM(CAST(ESTESTRATE AS CHAR(254)))),0) +',    SALDOCUST = '+ ISNULL(LTRIM(RTRIM(CAST(SALDOCUST AS CHAR(254)))),0) +',    SALDOINIC = '+ ISNULL(LTRIM(RTRIM(CAST(SALDOINIC AS CHAR(254)))),0) +''+  ' WHERE deposito = '''+ RTRIM(deposito)  + ''' and filial = '''+ RTRIM(filial)  + ''' and codpro = '''+ RTRIM(codpro)  + ''''   , 'ITEMDEPEST' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMDETROCA_D' AND type = 'TR')
  drop trigger ITEMDETROCA_D
go
create trigger dbo.ITEMDETROCA_D on dbo.ITEMDETROCA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITEMDETROCA WHERE 
NUMPED = '+ RTRIM(LTRIM(CAST(NUMPED as char(120)))) + '  and RITEMCLI = '+ RTRIM(LTRIM(CAST(RITEMCLI as char(120)))) + ' ','ITEMDETROCA' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMDETROCA_I' AND type = 'TR')
   drop trigger ITEMDETROCA_I
go
create trigger dbo.ITEMDETROCA_I on dbo.ITEMDETROCA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITEMDETROCA(
        NUMPED,    RITEMCLI,    QUANTIDADE,    PRECO,    MOTIVO,    OBSERVACAO,    FILIAL,    NUMPEDAVULSO,    DATA,    CODVEND,    CODPRO,    RECOLHER,    TIPODEPRECO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RITEMCLI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAVULSO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RECOLHER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TIPODEPRECO AS CHAR(254)))),0) +'
     '+ ')', 'ITEMDETROCA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMDETROCA_U' AND type = 'TR')
   drop trigger ITEMDETROCA_U
go
create trigger dbo.ITEMDETROCA_U on dbo.ITEMDETROCA for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMDETROCA SET     QUANTIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +',    PRECO = '+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +',    MOTIVO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDAVULSO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAVULSO AS CHAR(254)))),0) +',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RECOLHER = '+ ISNULL(LTRIM(RTRIM(CAST(RECOLHER AS CHAR(254)))),0) +',    TIPODEPRECO = '+ ISNULL(LTRIM(RTRIM(CAST(TIPODEPRECO AS CHAR(254)))),0) +''+  ' WHERE NUMPED = '+ RTRIM(CAST(NUMPED as char(254))) +  ' and RITEMCLI = '+ RTRIM(CAST(RITEMCLI as char(254))) +  ''   , 'ITEMDETROCA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMFATURADO_D' AND type = 'TR')
  drop trigger ITEMFATURADO_D
go
create trigger dbo.ITEMFATURADO_D on dbo.ITEMFATURADO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITEMFATURADO WHERE 
Item = '+ RTRIM(LTRIM(CAST(Item as char(120)))) + '  and     RESERVADO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,RESERVADO,20)))+''',120)','NULL') +'','ITEMFATURADO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMFATURADO_I' AND type = 'TR')
   drop trigger ITEMFATURADO_I
go
create trigger dbo.ITEMFATURADO_I on dbo.ITEMFATURADO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITEMFATURADO(
        USUARIO,    ESTACAO,    FILIAL,    PEDIDO,    CODPRO,    ITEM,    QUANT,    RESERVADO,    FATURADO,    CANCELADO,    NUMEROLISTA,    ORDEMENTREGA,    SITMANUT,    VIAORDEMSEPARACAO,    NUMPEDTRANSFERENCIA,    DATAMONTAGEM,    NUMORD,    DATAORDEMSEPARACAO,    NUMORDTRANSF)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PEDIDO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,RESERVADO,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,FATURADO,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,CANCELADO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ORDEMENTREGA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMANUT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VIAORDEMSEPARACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDTRANSFERENCIA AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAMONTAGEM,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAORDEMSEPARACAO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDTRANSF AS CHAR(254)))),0) +'
     '+ ')', 'ITEMFATURADO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMFATURADO_U' AND type = 'TR')
   drop trigger ITEMFATURADO_U
go
create trigger dbo.ITEMFATURADO_U on dbo.ITEMFATURADO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMFATURADO SET     USUARIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PEDIDO = '+ ISNULL(LTRIM(RTRIM(CAST(PEDIDO AS CHAR(254)))),0) +',    CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +',    FATURADO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,FATURADO,20)))+''',120)','NULL')+',    CANCELADO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,CANCELADO,20)))+''',120)','NULL')+',    NUMEROLISTA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +',    ORDEMENTREGA = '+ ISNULL(LTRIM(RTRIM(CAST(ORDEMENTREGA AS CHAR(254)))),0) +',    SITMANUT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMANUT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VIAORDEMSEPARACAO = '+ ISNULL(LTRIM(RTRIM(CAST(VIAORDEMSEPARACAO AS CHAR(254)))),0) +',    NUMPEDTRANSFERENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDTRANSFERENCIA AS CHAR(254)))),0) +',    DATAMONTAGEM = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAMONTAGEM,20)))+''',120)','NULL')+',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    DATAORDEMSEPARACAO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAORDEMSEPARACAO,20)))+''',120)','NULL')+',    NUMORDTRANSF = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDTRANSF AS CHAR(254)))),0) +''+  ' WHERE Item = '+ RTRIM(CAST(Item as char(254))) +  ' and     RESERVADO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,RESERVADO,20)))+''',120)','NULL') , 'ITEMFATURADO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMFILEST_I' AND type = 'TR')
   drop trigger ITEMFILEST_I
go
create trigger dbo.ITEMFILEST_I on dbo.ITEMFILEST for insert as
begin
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMFILEST_U' AND type = 'TR')
   drop trigger ITEMFILEST_U
go
create trigger dbo.ITEMFILEST_U on ITEMFILEST for update as 
begin
 Declare @script varchar(1000), @coluna varchar(1000)
 declare @codpro varchar(5), @filial varchar(2)
 declare C_INSERTED_CONTROLE cursor local for select codpro, filial from inserted
 open C_INSERTED_CONTROLE
 fetch C_INSERTED_CONTROLE into @codpro , @filial
 while @@fetch_status <> -1
 begin
 set @coluna = ''
 IF update(quant)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QUANT = QUANT + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QUANT-DE.QUANT) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(ESTESTRATE)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' ESTESTRATE = ESTESTRATE + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.ESTESTRATE-DE.ESTESTRATE) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTDERESERV)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTDERESERV = QTDERESERV + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTDERESERV-DE.QTDERESERV) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTVENDMES)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTVENDMES = QTVENDMES + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTVENDMES-DE.QTVENDMES) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(VALVENMES)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' VALVENMES = VALVENMES + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.VALVENMES-DE.VALVENMES) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(ENTREXP)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' ENTREXP = ENTREXP + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.ENTREXP-DE.ENTREXP) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(ENTRFUT)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' ENTRFUT = ENTRFUT + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.ENTRFUT-DE.ENTRFUT) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTDEREQUI)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTDEREQUI = QTDEREQUI + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTDEREQUI-DE.QTDEREQUI) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTDEPED)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTDEPED = QTDEPED + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTDEPED-DE.QTDEPED) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTVEDIMES)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTVEDIMES = QTVEDIMES + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTVEDIMES-DE.QTVEDIMES) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(VALVEDIMES)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' VALVEDIMES = VALVEDIMES + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.VALVEDIMES-DE.VALVEDIMES) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTDEAFATURAR)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTDEAFATURAR = QTDEAFATURAR + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTDEAFATURAR-DE.QTDEAFATURAR) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTDEMONTAG)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTDEMONTAG = QTDEMONTAG + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTDEMONTAG-DE.QTDEMONTAG) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTDAMONTAR)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTDAMONTAR = QTDAMONTAR + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTDAMONTAR-DE.QTDAMONTAR) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTDETRANSITO)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTDETRANSITO = QTDETRANSITO + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTDETRANSITO-DE.QTDETRANSITO) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QTDETRANSF)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QTDETRANSF = QTDETRANSF + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QTDETRANSF-DE.QTDETRANSF) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QUANTMOSTRUARIO)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QUANTMOSTRUARIO = QUANTMOSTRUARIO + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QUANTMOSTRUARIO-DE.QUANTMOSTRUARIO) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(RESERVMOSTRUARIO)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' RESERVMOSTRUARIO = RESERVMOSTRUARIO + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.RESERVMOSTRUARIO-DE.RESERVMOSTRUARIO) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(QUANTRMA)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' QUANTRMA = QUANTRMA + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.QUANTRMA-DE.QUANTRMA) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(SALDOESTOQUE)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' SALDOESTOQUE = SALDOESTOQUE + ('+ ISNULL(LTRIM(RTRIM(CAST((INS.SALDOESTOQUE-DE.SALDOESTOQUE) AS CHAR(254)))),0)+')' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(DATAULTIMAVENDA)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' DATAULTIMAVENDA = '+ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,INS.DATAULTIMAVENDA,20)))+''',120)','NULL') FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF update(DTULTVEN)
   begin
    IF @coluna <> ''
      begin
       SET @coluna = @coluna + ', '
      end
    SELECT @coluna = @coluna + ' DTULTVEN = '+ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,INS.DTULTVEN,20)))+''',120)','NULL') FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
   end
 IF @coluna <> ''
    begin
     SELECT @COLUNA = 'UPDATE ITEMFILEST SET ' +@coluna+ ' WHERE CODPRO = '''+INS.CODPRO+''' AND FILIAL = '''+INS.FILIAL+'''' FROM INSERTED INS, DELETED DE WHERE INS.CODPRO = DE.CODPRO AND INS.FILIAL = DE.FILIAL and INS.CODPRO = @codpro AND INS.FILIAL = @filial
     INSERT INTO REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , TABELA, COMANDO )  SELECT getdate(), null, 'ITEMFILEST',@coluna FROM INSERTED
    end
 fetch C_INSERTED_CONTROLE into @codpro, @filial
 End
 Close C_INSERTED_CONTROLE
 deallocate C_INSERTED_CONTROLE          
 return
end

go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMPIGMENTADO_D' AND type = 'TR')
  drop trigger ITEMPIGMENTADO_D
go
create trigger dbo.ITEMPIGMENTADO_D on dbo.ITEMPIGMENTADO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITEMPIGMENTADO WHERE 
ITEM = '+ RTRIM(LTRIM(CAST(ITEM as char(120)))) + '  and     SELECIONADO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,SELECIONADO,20)))+''',120)','NULL') +'','ITEMPIGMENTADO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMPIGMENTADO_I' AND type = 'TR')
   drop trigger ITEMPIGMENTADO_I
go
create trigger dbo.ITEMPIGMENTADO_I on dbo.ITEMPIGMENTADO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITEMPIGMENTADO(
        CODPRO,    ITEM,    FILIAL,    NUMPED,    QUANT,    CANCELADO,    CONFIRMADO,    SELECIONADO,    USUARIO,    ESTACAO,    SITMANUT)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,CANCELADO,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,CONFIRMADO,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,SELECIONADO,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMANUT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'ITEMPIGMENTADO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITEMPIGMENTADO_U' AND type = 'TR')
   drop trigger ITEMPIGMENTADO_U
go
create trigger dbo.ITEMPIGMENTADO_U on dbo.ITEMPIGMENTADO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITEMPIGMENTADO SET     CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    QUANT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +',    CANCELADO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,CANCELADO,20)))+''',120)','NULL')+',    CONFIRMADO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,CONFIRMADO,20)))+''',120)','NULL')+',    USUARIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITMANUT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMANUT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE ITEM = '+ RTRIM(CAST(ITEM as char(254))) +  ' and     SELECIONADO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,SELECIONADO,20)))+''',120)','NULL') , 'ITEMPIGMENTADO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFENTCAD_D' AND type = 'TR')
  drop trigger ITNFENTCAD_D
go
create trigger dbo.ITNFENTCAD_D on dbo.ITNFENTCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITNFENTCAD WHERE 
codpro = '''+ RTRIM(LTRIM(codpro)) + '''  and numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + '  and item = '''+ RTRIM(LTRIM(item)) + ''' ','ITNFENTCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFENTCAD_I' AND type = 'TR')
   drop trigger ITNFENTCAD_I
go
create trigger dbo.ITNFENTCAD_I on dbo.ITNFENTCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITNFENTCAD(
        NUMNOTA,    SERIE,    CODPRO,    DV,    QUANT,    UNIDADE,    PRECO,    PRECOTOTAL,    NUMORD,    FLAGMOV,    EMISETIQ,    DTCHEG,    FILIAL,    VALORIPI,    ALIQICMS,    BASEICMS,    CFO,    CCUSTO,    ATUAITEM,    ATUCUSTO,    CODINTERNO,    PARTNUM,    CUSTTRAN,    ICMTRAN,    C2MOETRAN,    CODNBM,    TIPOIPI,    NUMORDDEV,    CM,    CT,    CF,    NUMPED,    CMCONTAB,    SERIEPRO,    VALCHE,    CUSTGERAL,    NUMORDFIS,    IMPOGER,    CODVEND,    CUSTVEN,    VALSUBSTRI,    FACONV,    PERCOM,    ITEM,    VALDESC,    PERDESC,    CODGER,    ITEMDEV,    NUMOS,    NUMORDSAIDA,    ITEMSAIDA,    ICMULTCOMP,    QTDEETIQIMPRESSA,    QTDCONFERIDO,    CUSTOMARGEM0,    GARANTIAFABRICANTE,    GARANTIAVENDA,    IDTINTA,    CODPROTINTA)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOTOTAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGMOV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(EMISETIQ AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTCHEG,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCUSTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ATUAITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ATUCUSTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PARTNUM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTTRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMTRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(C2MOETRAN AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODNBM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDDEV AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CMCONTAB AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIEPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALCHE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTGERAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTVEN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FACONV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCOM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERDESC AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODGER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMDEV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMOS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDSAIDA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMSAIDA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ICMULTCOMP AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QTDEETIQIMPRESSA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTOMARGEM0 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(GARANTIAFABRICANTE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(GARANTIAVENDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IDTINTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPROTINTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'ITNFENTCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFENTCAD_U' AND type = 'TR')
   drop trigger ITNFENTCAD_U
go
create trigger dbo.ITNFENTCAD_U on dbo.ITNFENTCAD for update as
begin
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFENTCOMPLEMENTO_D' AND type = 'TR')
  drop trigger ITNFENTCOMPLEMENTO_D
go
create trigger dbo.ITNFENTCOMPLEMENTO_D on dbo.ITNFENTCOMPLEMENTO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITNFENTCOMPLEMENTO WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and item = '''+ RTRIM(LTRIM(item)) + ''' ','ITNFENTCOMPLEMENTO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFENTCOMPLEMENTO_I' AND type = 'TR')
   drop trigger ITNFENTCOMPLEMENTO_I
go
create trigger dbo.ITNFENTCOMPLEMENTO_I on dbo.ITNFENTCOMPLEMENTO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITNFENTCOMPLEMENTO(
        NUMORD,    ITEM,    CODMENSAGEMIPI,    CREDITODEIPI,    QUANTDEVCONSIGNADO,    PRODUTOEMOFERTA,    APURADIFERENCAICMS,    VALTRIBANTECIPADA,    BASESTRIB,    BASETRIBANTECIPADA,    VALORCREDITOICMSST,    ITEMPEDDEV,    CUSTOATU,    ICMATU,    C2MOEATU,    QUANTIDADEUTILIZADA,    CODIGODEPOSITO,    OBSERVACAO,    NUMNOTAFABRICANTE,    DTEMISNOTAFABRICANTE,    VALSTREEMBOLSAVEL,    CUSTOFINANCEIRO,    BASEST,    CONTRATO,    COTACAOMOEDA,    STMEDIA,    PISMEDIO,    COFINSMEDIO,    USUALTCUSTOFINANC,    PERCDESCCUSTO,    PERCACRESCCUSTO,    BASESTFRETENAOINCLUSO,    VALORSTFRETENAOINCLUSO,    DEPOSITOTRANSFERENCIA,    CUSTOFINANCEIROANTERIOR,    SALDOANTERIOR,    DATAATUALIZACAOCUSTO,    NADICAO,    NSEQADIC,    CFABRICANTE,    VDESCDI,    VALORPIS,    VALORCOFINS,    VALORDESPINCL,    VALORFRETE,    VALORIPIFRETE,    VALORSEGURO,    VALORIMPORTACAO,    VALORICMS,    ALIQPIS,    ALIQCOFINS,    ALIQIPI,    BASEPIS,    BASECOFINS,    BASEIPI,    BASECALCULOICMS,    BASEIMPOSTOIMPORTACAO,    VALORDESPADUANEIRAS,    VALORIOF,    PERCSUBSTRIB,    NUMPEDAUTOMATICO,    OBSBASESTANTECIPADA,    OBSVALSTANTECIPADA,    OBSVALICMSSTANTECIPADA,    PERCENTUALSUBSTITUICAO,    PIS,    COFINS,    BASECAL_PIS,    BASECAL_COFINS,    VALOR_PIS,    VALOR_COFINS,    CST_PIS,    CST_COFINS,    VALORDESCONTO,    BASESTDADOSADICIONAIS,    VALORSTDADOSADICIONAIS,    CSOSN,    ICMSOPDADOSADICIONAIS,    ICMSOPTRAN,    STMEDIATRAN,    QUANTSAGA,    CST_IPI,    PERCCOMISVENDEXT,    PERCCOMISVENDINT,    BASEPISABATERITEMDEV,    BASECOFINSABATERITEMDEV,    ALIQICMSST,    BASEICMSST,    GERARCONTAAPAGAR,    OBSVALORIPI,    OBSBASESUBSTRI,    OBSVALSUBSTRI,    BASEST_DESPNINCL,    VALORST_DESPNINCL,    ALIQCOFINSIMPORTACAO,    VALCOFINSIMPORTACAO,    CODIGOPRODUTODANFE,    ALIQUOTAII,    VALORPISCOFINSDESPNINCL,    STPAGAPELOFORNECEDOR,    PATRIMONIO,    NFCI,    SALDOFCI,    CENQIPI)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMENSAGEMIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CREDITODEIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTDEVCONSIGNADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRODUTOEMOFERTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(APURADIFERENCAICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALTRIBANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASETRIBANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORCREDITOICMSST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMPEDDEV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTOATU AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMATU AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(C2MOEATU AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADEUTILIZADA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGODEPOSITO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTAFABRICANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMISNOTAFABRICANTE,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VALSTREEMBOLSAVEL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTOFINANCEIRO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CONTRATO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COTACAOMOEDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(STMEDIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PISMEDIO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COFINSMEDIO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(USUALTCUSTOFINANC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCCUSTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCACRESCCUSTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASESTFRETENAOINCLUSO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORSTFRETENAOINCLUSO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPOSITOTRANSFERENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTOFINANCEIROANTERIOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SALDOANTERIOR AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAATUALIZACAOCUSTO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NADICAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NSEQADIC AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFABRICANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VDESCDI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORDESPINCL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPIFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORSEGURO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIMPORTACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECALCULOICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIMPOSTOIMPORTACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORDESPADUANEIRAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIOF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCSUBSTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAUTOMATICO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESTANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSTANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALICMSSTANTECIPADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALSUBSTITUICAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_PIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_COFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALOR_PIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALOR_COFINS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_PIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_COFINS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASESTDADOSADICIONAIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORSTDADOSADICIONAIS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CSOSN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ICMSOPDADOSADICIONAIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMSOPTRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(STMEDIATRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTSAGA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_IPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDEXT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDINT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEPISABATERITEMDEV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECOFINSABATERITEMDEV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(GERARCONTAAPAGAR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALORIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEST_DESPNINCL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORST_DESPNINCL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINSIMPORTACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALCOFINSIMPORTACAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGOPRODUTODANFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ALIQUOTAII AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORPISCOFINSDESPNINCL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(STPAGAPELOFORNECEDOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PATRIMONIO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFCI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SALDOFCI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CENQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'ITNFENTCOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFENTCOMPLEMENTO_U' AND type = 'TR')
   drop trigger ITNFENTCOMPLEMENTO_U
go
create trigger dbo.ITNFENTCOMPLEMENTO_U on dbo.ITNFENTCOMPLEMENTO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITNFENTCOMPLEMENTO SET     CODMENSAGEMIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMENSAGEMIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CREDITODEIPI = '+ ISNULL(LTRIM(RTRIM(CAST(CREDITODEIPI AS CHAR(254)))),0) +',    QUANTDEVCONSIGNADO = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTDEVCONSIGNADO AS CHAR(254)))),0) +',    PRODUTOEMOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(PRODUTOEMOFERTA AS CHAR(254)))),0) +',    APURADIFERENCAICMS = '+ ISNULL(LTRIM(RTRIM(CAST(APURADIFERENCAICMS AS CHAR(254)))),0) +',    VALTRIBANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(VALTRIBANTECIPADA AS CHAR(254)))),0) +',    BASESTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +',    BASETRIBANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(BASETRIBANTECIPADA AS CHAR(254)))),0) +',    VALORCREDITOICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(VALORCREDITOICMSST AS CHAR(254)))),0) +',    ITEMPEDDEV = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMPEDDEV AS CHAR(254)))),0) +',    CUSTOATU = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTOATU AS CHAR(254)))),0) +',    ICMATU = '+ ISNULL(LTRIM(RTRIM(CAST(ICMATU AS CHAR(254)))),0) +',    C2MOEATU = '+ ISNULL(LTRIM(RTRIM(CAST(C2MOEATU AS CHAR(254)))),0) +',    QUANTIDADEUTILIZADA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADEUTILIZADA AS CHAR(254)))),0) +',    CODIGODEPOSITO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGODEPOSITO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMNOTAFABRICANTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTAFABRICANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTEMISNOTAFABRICANTE = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMISNOTAFABRICANTE,20)))+''',120)','NULL')+',    VALSTREEMBOLSAVEL = '+ ISNULL(LTRIM(RTRIM(CAST(VALSTREEMBOLSAVEL AS CHAR(254)))),0) +',    CUSTOFINANCEIRO = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTOFINANCEIRO AS CHAR(254)))),0) +',    BASEST = '+ ISNULL(LTRIM(RTRIM(CAST(BASEST AS CHAR(254)))),0) +',    CONTRATO = '+ ISNULL(LTRIM(RTRIM(CAST(CONTRATO AS CHAR(254)))),0) +',    COTACAOMOEDA = '+ ISNULL(LTRIM(RTRIM(CAST(COTACAOMOEDA AS CHAR(254)))),0) +',    STMEDIA = '+ ISNULL(LTRIM(RTRIM(CAST(STMEDIA AS CHAR(254)))),0) +',    PISMEDIO = '+ ISNULL(LTRIM(RTRIM(CAST(PISMEDIO AS CHAR(254)))),0) +',    COFINSMEDIO = '+ ISNULL(LTRIM(RTRIM(CAST(COFINSMEDIO AS CHAR(254)))),0) +',    USUALTCUSTOFINANC = '+ ISNULL(LTRIM(RTRIM(CAST(USUALTCUSTOFINANC AS CHAR(254)))),0) +',    PERCDESCCUSTO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCCUSTO AS CHAR(254)))),0) +',    PERCACRESCCUSTO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCACRESCCUSTO AS CHAR(254)))),0) +',    BASESTFRETENAOINCLUSO = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTFRETENAOINCLUSO AS CHAR(254)))),0) +',    VALORSTFRETENAOINCLUSO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSTFRETENAOINCLUSO AS CHAR(254)))),0) +',    DEPOSITOTRANSFERENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPOSITOTRANSFERENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CUSTOFINANCEIROANTERIOR = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTOFINANCEIROANTERIOR AS CHAR(254)))),0) +',    SALDOANTERIOR = '+ ISNULL(LTRIM(RTRIM(CAST(SALDOANTERIOR AS CHAR(254)))),0) +',    DATAATUALIZACAOCUSTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAATUALIZACAOCUSTO,20)))+''',120)','NULL')+',    NADICAO = '+ ISNULL(LTRIM(RTRIM(CAST(NADICAO AS CHAR(254)))),0) +',    NSEQADIC = '+ ISNULL(LTRIM(RTRIM(CAST(NSEQADIC AS CHAR(254)))),0) +',    CFABRICANTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFABRICANTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VDESCDI = '+ ISNULL(LTRIM(RTRIM(CAST(VDESCDI AS CHAR(254)))),0) +',    VALORPIS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORPIS AS CHAR(254)))),0) +',    VALORCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORCOFINS AS CHAR(254)))),0) +',    VALORDESPINCL = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDESPINCL AS CHAR(254)))),0) +',    VALORFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +',    VALORIPIFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPIFRETE AS CHAR(254)))),0) +',    VALORSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSEGURO AS CHAR(254)))),0) +',    VALORIMPORTACAO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIMPORTACAO AS CHAR(254)))),0) +',    VALORICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +',    ALIQPIS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQPIS AS CHAR(254)))),0) +',    ALIQCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINS AS CHAR(254)))),0) +',    ALIQIPI = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +',    BASEPIS = '+ ISNULL(LTRIM(RTRIM(CAST(BASEPIS AS CHAR(254)))),0) +',    BASECOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECOFINS AS CHAR(254)))),0) +',    BASEIPI = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +',    BASECALCULOICMS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECALCULOICMS AS CHAR(254)))),0) +',    BASEIMPOSTOIMPORTACAO = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIMPOSTOIMPORTACAO AS CHAR(254)))),0) +',    VALORDESPADUANEIRAS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDESPADUANEIRAS AS CHAR(254)))),0) +',    VALORIOF = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIOF AS CHAR(254)))),0) +',    PERCSUBSTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(PERCSUBSTRIB AS CHAR(254)))),0) +',    NUMPEDAUTOMATICO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAUTOMATICO AS CHAR(254)))),0) +',    OBSBASESTANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESTANTECIPADA AS CHAR(254)))),0) +',    OBSVALSTANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSTANTECIPADA AS CHAR(254)))),0) +',    OBSVALICMSSTANTECIPADA = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALICMSSTANTECIPADA AS CHAR(254)))),0) +',    PERCENTUALSUBSTITUICAO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALSUBSTITUICAO AS CHAR(254)))),0) +',    PIS = '+ ISNULL(LTRIM(RTRIM(CAST(PIS AS CHAR(254)))),0) +',    COFINS = '+ ISNULL(LTRIM(RTRIM(CAST(COFINS AS CHAR(254)))),0) +',    BASECAL_PIS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_PIS AS CHAR(254)))),0) +',    BASECAL_COFINS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_COFINS AS CHAR(254)))),0) +',    VALOR_PIS = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR_PIS AS CHAR(254)))),0) +',    VALOR_COFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR_COFINS AS CHAR(254)))),0) +',    CST_PIS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_PIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CST_COFINS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_COFINS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORDESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTO AS CHAR(254)))),0) +',    BASESTDADOSADICIONAIS = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTDADOSADICIONAIS AS CHAR(254)))),0) +',    VALORSTDADOSADICIONAIS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSTDADOSADICIONAIS AS CHAR(254)))),0) +',    CSOSN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CSOSN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ICMSOPDADOSADICIONAIS = '+ ISNULL(LTRIM(RTRIM(CAST(ICMSOPDADOSADICIONAIS AS CHAR(254)))),0) +',    ICMSOPTRAN = '+ ISNULL(LTRIM(RTRIM(CAST(ICMSOPTRAN AS CHAR(254)))),0) +',    STMEDIATRAN = '+ ISNULL(LTRIM(RTRIM(CAST(STMEDIATRAN AS CHAR(254)))),0) +',    QUANTSAGA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTSAGA AS CHAR(254)))),0) +',    CST_IPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_IPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PERCCOMISVENDEXT = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDEXT AS CHAR(254)))),0) +',    PERCCOMISVENDINT = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDINT AS CHAR(254)))),0) +',    BASEPISABATERITEMDEV = '+ ISNULL(LTRIM(RTRIM(CAST(BASEPISABATERITEMDEV AS CHAR(254)))),0) +',    BASECOFINSABATERITEMDEV = '+ ISNULL(LTRIM(RTRIM(CAST(BASECOFINSABATERITEMDEV AS CHAR(254)))),0) +',    ALIQICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSST AS CHAR(254)))),0) +',    BASEICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSST AS CHAR(254)))),0) +',    GERARCONTAAPAGAR = '+ ISNULL(LTRIM(RTRIM(CAST(GERARCONTAAPAGAR AS CHAR(254)))),0) +',    OBSVALORIPI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALORIPI AS CHAR(254)))),0) +',    OBSBASESUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESUBSTRI AS CHAR(254)))),0) +',    OBSVALSUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSUBSTRI AS CHAR(254)))),0) +',    BASEST_DESPNINCL = '+ ISNULL(LTRIM(RTRIM(CAST(BASEST_DESPNINCL AS CHAR(254)))),0) +',    VALORST_DESPNINCL = '+ ISNULL(LTRIM(RTRIM(CAST(VALORST_DESPNINCL AS CHAR(254)))),0) +',    ALIQCOFINSIMPORTACAO = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINSIMPORTACAO AS CHAR(254)))),0) +',    VALCOFINSIMPORTACAO = '+ ISNULL(LTRIM(RTRIM(CAST(VALCOFINSIMPORTACAO AS CHAR(254)))),0) +',    CODIGOPRODUTODANFE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGOPRODUTODANFE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ALIQUOTAII = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQUOTAII AS CHAR(254)))),0) +',    VALORPISCOFINSDESPNINCL = '+ ISNULL(LTRIM(RTRIM(CAST(VALORPISCOFINSDESPNINCL AS CHAR(254)))),0) +',    STPAGAPELOFORNECEDOR = '+ ISNULL(LTRIM(RTRIM(CAST(STPAGAPELOFORNECEDOR AS CHAR(254)))),0) +',    PATRIMONIO = '+ ISNULL(LTRIM(RTRIM(CAST(PATRIMONIO AS CHAR(254)))),0) +',    NFCI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFCI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SALDOFCI = '+ ISNULL(LTRIM(RTRIM(CAST(SALDOFCI AS CHAR(254)))),0) +',    CENQIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CENQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and item = '''+ RTRIM(item)  + ''''   , 'ITNFENTCOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFENTNFE_D' AND type = 'TR')
  drop trigger ITNFENTNFE_D
go
create trigger dbo.ITNFENTNFE_D on dbo.ITNFENTNFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITNFENTNFE WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and ITEM = '''+ RTRIM(LTRIM(ITEM)) + ''' ','ITNFENTNFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFENTNFE_I' AND type = 'TR')
   drop trigger ITNFENTNFE_I
go
create trigger dbo.ITNFENTNFE_I on dbo.ITNFENTNFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITNFENTNFE(
        NUMORD,    ITEM,    FRETE,    DESCONTO,    CT,    BASEICMS,    VALORICMS,    PERCREDUCAOBASE,    BASESUBSTRIBUTARIA,    ALIQICMS,    VALORSUBSTRIBUTARIA,    PERCREDUCAOBASEST,    BASEIPI,    ALIQIPI,    VALORIPI,    CTIPI,    SEGURO,    VALUNITTRIBUTADO,    BASEPIS,    ALIQPIS,    VALORPIS,    BASECOFINS,    ALIQCOFINS,    VALORCOFINS,    CTPIS,    CTCOFINS,    PERCENTUALST,    OUTRASDESPESASINCLUSAS,    VALORRETIDOCSLL,    ALIQICMSST)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCREDUCAOBASE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASESUBSTRIBUTARIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCREDUCAOBASEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CTIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SEGURO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALUNITTRIBUTADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CTPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CTCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORRETIDOCSLL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSST AS CHAR(254)))),0) +'
     '+ ')', 'ITNFENTNFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFENTNFE_U' AND type = 'TR')
   drop trigger ITNFENTNFE_U
go
create trigger dbo.ITNFENTNFE_U on dbo.ITNFENTNFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITNFENTNFE SET     FRETE = '+ ISNULL(LTRIM(RTRIM(CAST(FRETE AS CHAR(254)))),0) +',    DESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +',    CT = '+ ISNULL(LTRIM(RTRIM(CAST(CT AS CHAR(254)))),0) +',    BASEICMS = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICMS AS CHAR(254)))),0) +',    VALORICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +',    PERCREDUCAOBASE = '+ ISNULL(LTRIM(RTRIM(CAST(PERCREDUCAOBASE AS CHAR(254)))),0) +',    BASESUBSTRIBUTARIA = '+ ISNULL(LTRIM(RTRIM(CAST(BASESUBSTRIBUTARIA AS CHAR(254)))),0) +',    ALIQICMS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMS AS CHAR(254)))),0) +',    VALORSUBSTRIBUTARIA = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIA AS CHAR(254)))),0) +',    PERCREDUCAOBASEST = '+ ISNULL(LTRIM(RTRIM(CAST(PERCREDUCAOBASEST AS CHAR(254)))),0) +',    BASEIPI = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +',    ALIQIPI = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +',    VALORIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI AS CHAR(254)))),0) +',    CTIPI = '+ ISNULL(LTRIM(RTRIM(CAST(CTIPI AS CHAR(254)))),0) +',    SEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(SEGURO AS CHAR(254)))),0) +',    VALUNITTRIBUTADO = '+ ISNULL(LTRIM(RTRIM(CAST(VALUNITTRIBUTADO AS CHAR(254)))),0) +',    BASEPIS = '+ ISNULL(LTRIM(RTRIM(CAST(BASEPIS AS CHAR(254)))),0) +',    ALIQPIS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQPIS AS CHAR(254)))),0) +',    VALORPIS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORPIS AS CHAR(254)))),0) +',    BASECOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECOFINS AS CHAR(254)))),0) +',    ALIQCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINS AS CHAR(254)))),0) +',    VALORCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORCOFINS AS CHAR(254)))),0) +',    CTPIS = '+ ISNULL(LTRIM(RTRIM(CAST(CTPIS AS CHAR(254)))),0) +',    CTCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(CTCOFINS AS CHAR(254)))),0) +',    PERCENTUALST = '+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALST AS CHAR(254)))),0) +',    OUTRASDESPESASINCLUSAS = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +',    VALORRETIDOCSLL = '+ ISNULL(LTRIM(RTRIM(CAST(VALORRETIDOCSLL AS CHAR(254)))),0) +',    ALIQICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSST AS CHAR(254)))),0) +''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and ITEM = '''+ RTRIM(ITEM)  + ''''   , 'ITNFENTNFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFSAICAD_D' AND type = 'TR')
  drop trigger ITNFSAICAD_D
go
create trigger dbo.ITNFSAICAD_D on dbo.ITNFSAICAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITNFSAICAD WHERE 
numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + '  and ITEM = '''+ RTRIM(LTRIM(ITEM)) + ''' ','ITNFSAICAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFSAICAD_I' AND type = 'TR')
   drop trigger ITNFSAICAD_I
go
create trigger dbo.ITNFSAICAD_I on dbo.ITNFSAICAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITNFSAICAD(
        NUMNOTA,    SERIE,    CODPRO,    DV,    QUANT,    UNIDADE,    PRECO,    PRECOTAB,    QUANTDEV,    NUMORD,    DTEMIS,    FILIAL,    VALDESC,    ALIQIPI,    ALIQICMS,    BASEICMS,    CT,    CM,    CF,    CCUSTO,    CODVEND,    ATUAITEM,    ATUCUSTO,    CODINTERNO,    PARTNUM,    CUSTTRAN,    ICMTRAN,    C2MOETRAN,    DESCUNIT,    CMCONTAB,    GRUPO,    SERIEPRO,    NUMORDDEV,    CUSTGERAL,    VALCHE,    PERDESC,    NUMORDFIS,    IMPOGER,    QUANPED,    CFO,    PRECOSTX,    FACONV,    ITEM,    CUSTVEN,    PERCOM,    VALSUBSTRI,    SUBSTRIB,    NUMOS,    NUMORDENTRADA,    ITEMENTRADA,    RATENDEREQUISICAOVALOR,    ITEMPEDIDO,    ITEMDEV,    VALIPI)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOTAB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTDEV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMIS,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCUSTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ATUAITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ATUCUSTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PARTNUM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTTRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMTRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(C2MOETRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCUNIT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CMCONTAB AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GRUPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIEPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDDEV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTGERAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALCHE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECOSTX AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FACONV AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTVEN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCOM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SUBSTRIB AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMOS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDENTRADA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMENTRADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RATENDEREQUISICAOVALOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMPEDIDO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMDEV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +'
     '+ ')', 'ITNFSAICAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFSAICAD_U' AND type = 'TR')
   drop trigger ITNFSAICAD_U
go
create trigger dbo.ITNFSAICAD_U on ITNFSAICAD for update as 
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITNFSAICAD WHERE codpro = 
'''+ RTRIM(LTRIM(codpro)) + '''  and numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + '  and item = '''+ RTRIM(LTRIM(item)) + '''
','ITNFSAICAD' from deleted
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITNFSAICAD(
        NUMNOTA,    SERIE,    CODPRO,    DV,    QUANT,    UNIDADE,    PRECO,    PRECOTAB,    QUANTDEV,    NUMORD,    DTEMIS,    FILIAL,    VALDESC,    ALIQIPI,    ALIQICMS,    BASEICMS,    CT,    CM,    CF,    CCUSTO,    CODVEND,    ATUAITEM,    ATUCUSTO,    CODINTERNO,    PARTNUM,    CUSTTRAN,    ICMTRAN,    C2MOETRAN,    DESCUNIT,    CMCONTAB,    GRUPO,    SERIEPRO,    NUMORDDEV,    CUSTGERAL,    VALCHE,    PERDESC,    NUMORDFIS,    IMPOGER,    QUANPED,    CFO,    PRECOSTX,    FACONV,    ITEM,    CUSTVEN,    PERCOM,    VALSUBSTRI,    SUBSTRIB,    NUMOS,    NUMORDENTRADA,    ITEMENTRADA,    RATENDEREQUISICAOVALOR,    ITEMPEDIDO,    ITEMDEV,    VALIPI)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOTAB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANTDEV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMIS,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCUSTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ATUAITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ATUCUSTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PARTNUM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTTRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMTRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(C2MOETRAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCUNIT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CMCONTAB AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GRUPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIEPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDDEV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTGERAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALCHE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERDESC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QUANPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECOSTX AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FACONV AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTVEN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCOM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SUBSTRIB AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMOS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDENTRADA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMENTRADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RATENDEREQUISICAOVALOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMPEDIDO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMDEV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +'
     '+ ')', 'ITNFSAICAD' FROM inserted
 return
end
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFSAICOMPLEMENTO_D' AND type = 'TR')
  drop trigger ITNFSAICOMPLEMENTO_D
go
create trigger dbo.ITNFSAICOMPLEMENTO_D on dbo.ITNFSAICOMPLEMENTO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITNFSAICOMPLEMENTO WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and item = '''+ RTRIM(LTRIM(item)) + ''' ','ITNFSAICOMPLEMENTO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFSAICOMPLEMENTO_I' AND type = 'TR')
   drop trigger ITNFSAICOMPLEMENTO_I
go
create trigger dbo.ITNFSAICOMPLEMENTO_I on dbo.ITNFSAICOMPLEMENTO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITNFSAICOMPLEMENTO(
        NUMORD,    PESOINICIAL,    PESOFINAL,    ITEMOFERTA,    ITEM,    CODMENSAGEMIPI,    OIDFUNCIONARIO,    COMISSAOFUNCIONARIO,    PERCCOMISVENDEXT,    PERCCOMISVENDINT,    PRODUTOEMOFERTA,    MARKUPREALVENDA,    VALCUSTOREAL,    VALCUSTOFRETE,    PERCCUSTOFINANCEIRO,    OIDPESQUISADEPRECO,    PERCBONIFICACAO,    CREDICMSRESSARC,    SALDOST,    STRESSARC,    ID_CLIENTECENTROCUSTO,    CODIGODEPOSITO,    NUMORDNFGERADA,    ITEMNFGERADA,    CUSTOVENDA,    STMEDIA,    PISMEDIO,    COFINSMEDIO,    DEPOSITOTRANSFERENCIA,    CODVEND,    CUSTOREAL,    JUROS,    NUMPEDAUTOMATICO,    PIS,    COFINS,    PIS_COFINS_REDUCAO,    BASECAL_PIS,    BASECAL_COFINS,    VALOR_PIS,    VALOR_COFINS,    CST_PIS,    CST_COFINS,    BASESTRIB,    ALIQICMSSN,    VALORICMSSN,    CSOSN,    BASESTULTIMAENTRADA,    VALORSTULTIMAENTRADA,    PRECOVENDAORIG,    DEPOUTRAFILIAL,    VALORACRESCIMO,    VALORDESCONTO,    BASECALCULOICMS,    VALORICMS,    OBSVALORIPI,    OBSBASESUBSTRI,    OBSVALSUBSTRI,    CARGATRIBUTARIAMEDIA,    ALIQICMSST,    BASEICMSST,    INFOSUPORTE,    COMISOFERTA,    VLRUNITIPISEMDES,    ALIQIPISEMDES,    VALORFRETE,    VALORDESPINCL,    DESCICMSSUFRAMA,    NFCI,    FCI_NUMORDORIGEM,    FCI_RITEMORIGEM,    VALORSEGURO,    CENQIPI)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PESOINICIAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PESOFINAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMOFERTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMENSAGEMIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDFUNCIONARIO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(COMISSAOFUNCIONARIO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDEXT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDINT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRODUTOEMOFERTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MARKUPREALVENDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOREAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCCUSTOFINANCEIRO AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDPESQUISADEPRECO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(PERCBONIFICACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CREDICMSRESSARC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SALDOST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(STRESSARC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ID_CLIENTECENTROCUSTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGODEPOSITO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDNFGERADA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMNFGERADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTOVENDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(STMEDIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PISMEDIO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COFINSMEDIO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPOSITOTRANSFERENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CUSTOREAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(JUROS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAUTOMATICO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COFINS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PIS_COFINS_REDUCAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_PIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_COFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALOR_PIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALOR_COFINS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_PIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_COFINS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSSN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSSN AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CSOSN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(BASESTULTIMAENTRADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORSTULTIMAENTRADA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOVENDAORIG AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPOUTRAFILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORACRESCIMO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECALCULOICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALORIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSUBSTRI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CARGATRIBUTARIAMEDIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSST AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFOSUPORTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(COMISOFERTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VLRUNITIPISEMDES AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPISEMDES AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORDESPINCL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCICMSSUFRAMA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFCI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FCI_NUMORDORIGEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FCI_RITEMORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORSEGURO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CENQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'ITNFSAICOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFSAICOMPLEMENTO_U' AND type = 'TR')
   drop trigger ITNFSAICOMPLEMENTO_U
go
create trigger dbo.ITNFSAICOMPLEMENTO_U on dbo.ITNFSAICOMPLEMENTO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITNFSAICOMPLEMENTO SET     PESOINICIAL = '+ ISNULL(LTRIM(RTRIM(CAST(PESOINICIAL AS CHAR(254)))),0) +',    PESOFINAL = '+ ISNULL(LTRIM(RTRIM(CAST(PESOFINAL AS CHAR(254)))),0) +',    ITEMOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMOFERTA AS CHAR(254)))),0) +',    CODMENSAGEMIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMENSAGEMIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDFUNCIONARIO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDFUNCIONARIO AS CHAR(254)))),0) +'**],    COMISSAOFUNCIONARIO = '+ ISNULL(LTRIM(RTRIM(CAST(COMISSAOFUNCIONARIO AS CHAR(254)))),0) +',    PERCCOMISVENDEXT = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDEXT AS CHAR(254)))),0) +',    PERCCOMISVENDINT = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCOMISVENDINT AS CHAR(254)))),0) +',    PRODUTOEMOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(PRODUTOEMOFERTA AS CHAR(254)))),0) +',    MARKUPREALVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(MARKUPREALVENDA AS CHAR(254)))),0) +',    VALCUSTOREAL = '+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOREAL AS CHAR(254)))),0) +',    VALCUSTOFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOFRETE AS CHAR(254)))),0) +',    PERCCUSTOFINANCEIRO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCCUSTOFINANCEIRO AS CHAR(254)))),0) +',    OIDPESQUISADEPRECO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDPESQUISADEPRECO AS CHAR(254)))),0) +'**],    PERCBONIFICACAO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCBONIFICACAO AS CHAR(254)))),0) +',    CREDICMSRESSARC = '+ ISNULL(LTRIM(RTRIM(CAST(CREDICMSRESSARC AS CHAR(254)))),0) +',    SALDOST = '+ ISNULL(LTRIM(RTRIM(CAST(SALDOST AS CHAR(254)))),0) +',    STRESSARC = '+ ISNULL(LTRIM(RTRIM(CAST(STRESSARC AS CHAR(254)))),0) +',    ID_CLIENTECENTROCUSTO = '+ ISNULL(LTRIM(RTRIM(CAST(ID_CLIENTECENTROCUSTO AS CHAR(254)))),0) +',    CODIGODEPOSITO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGODEPOSITO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORDNFGERADA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDNFGERADA AS CHAR(254)))),0) +',    ITEMNFGERADA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEMNFGERADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CUSTOVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTOVENDA AS CHAR(254)))),0) +',    STMEDIA = '+ ISNULL(LTRIM(RTRIM(CAST(STMEDIA AS CHAR(254)))),0) +',    PISMEDIO = '+ ISNULL(LTRIM(RTRIM(CAST(PISMEDIO AS CHAR(254)))),0) +',    COFINSMEDIO = '+ ISNULL(LTRIM(RTRIM(CAST(COFINSMEDIO AS CHAR(254)))),0) +',    DEPOSITOTRANSFERENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPOSITOTRANSFERENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CUSTOREAL = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTOREAL AS CHAR(254)))),0) +',    JUROS = '+ ISNULL(LTRIM(RTRIM(CAST(JUROS AS CHAR(254)))),0) +',    NUMPEDAUTOMATICO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAUTOMATICO AS CHAR(254)))),0) +',    PIS = '+ ISNULL(LTRIM(RTRIM(CAST(PIS AS CHAR(254)))),0) +',    COFINS = '+ ISNULL(LTRIM(RTRIM(CAST(COFINS AS CHAR(254)))),0) +',    PIS_COFINS_REDUCAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PIS_COFINS_REDUCAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BASECAL_PIS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_PIS AS CHAR(254)))),0) +',    BASECAL_COFINS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECAL_COFINS AS CHAR(254)))),0) +',    VALOR_PIS = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR_PIS AS CHAR(254)))),0) +',    VALOR_COFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR_COFINS AS CHAR(254)))),0) +',    CST_PIS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_PIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CST_COFINS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CST_COFINS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BASESTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +',    ALIQICMSSN = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSSN AS CHAR(254)))),0) +',    VALORICMSSN = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSSN AS CHAR(254)))),0) +',    CSOSN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CSOSN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BASESTULTIMAENTRADA = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTULTIMAENTRADA AS CHAR(254)))),0) +',    VALORSTULTIMAENTRADA = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSTULTIMAENTRADA AS CHAR(254)))),0) +',    PRECOVENDAORIG = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOVENDAORIG AS CHAR(254)))),0) +',    DEPOUTRAFILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPOUTRAFILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORACRESCIMO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORACRESCIMO AS CHAR(254)))),0) +',    VALORDESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTO AS CHAR(254)))),0) +',    BASECALCULOICMS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECALCULOICMS AS CHAR(254)))),0) +',    VALORICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +',    OBSVALORIPI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALORIPI AS CHAR(254)))),0) +',    OBSBASESUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSBASESUBSTRI AS CHAR(254)))),0) +',    OBSVALSUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(OBSVALSUBSTRI AS CHAR(254)))),0) +',    CARGATRIBUTARIAMEDIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CARGATRIBUTARIAMEDIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ALIQICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSST AS CHAR(254)))),0) +',    BASEICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICMSST AS CHAR(254)))),0) +',    INFOSUPORTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFOSUPORTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COMISOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(COMISOFERTA AS CHAR(254)))),0) +',    VLRUNITIPISEMDES = '+ ISNULL(LTRIM(RTRIM(CAST(VLRUNITIPISEMDES AS CHAR(254)))),0) +',    ALIQIPISEMDES = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPISEMDES AS CHAR(254)))),0) +',    VALORFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +',    VALORDESPINCL = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDESPINCL AS CHAR(254)))),0) +',    DESCICMSSUFRAMA = '+ ISNULL(LTRIM(RTRIM(CAST(DESCICMSSUFRAMA AS CHAR(254)))),0) +',    NFCI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFCI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FCI_NUMORDORIGEM = '+ ISNULL(LTRIM(RTRIM(CAST(FCI_NUMORDORIGEM AS CHAR(254)))),0) +',    FCI_RITEMORIGEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FCI_RITEMORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSEGURO AS CHAR(254)))),0) +',    CENQIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CENQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and item = '''+ RTRIM(item)  + ''''   , 'ITNFSAICOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFSAINFE_D' AND type = 'TR')
  drop trigger ITNFSAINFE_D
go
create trigger dbo.ITNFSAINFE_D on dbo.ITNFSAINFE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ITNFSAINFE WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + '  and ITEM = '''+ RTRIM(LTRIM(ITEM)) + ''' ','ITNFSAINFE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFSAINFE_I' AND type = 'TR')
   drop trigger ITNFSAINFE_I
go
create trigger dbo.ITNFSAINFE_I on dbo.ITNFSAINFE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ITNFSAINFE(
        NUMORD,    ITEM,    FRETE,    DESCONTO,    CT,    BASEICMS,    VALORICMS,    PERCREDUCAOBASE,    BASESUBSTRIBUTARIA,    ALIQICMS,    VALORSUBSTRIBUTARIA,    PERCREDUCAOBASEST,    BASEIPI,    ALIQIPI,    VALORIPI,    CTIPI,    SEGURO,    VALUNITTRIBUTADO,    BASEPIS,    ALIQPIS,    VALORPIS,    BASECOFINS,    ALIQCOFINS,    VALORCOFINS,    CTPIS,    CTCOFINS,    PERCENTUALST,    OUTRASDESPESASINCLUSAS,    VALORRETIDOCSLL,    ALIQICMSST)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCREDUCAOBASE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASESUBSTRIBUTARIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCREDUCAOBASEST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CTIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SEGURO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALUNITTRIBUTADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASECOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CTPIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CTCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORRETIDOCSLL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSST AS CHAR(254)))),0) +'
     '+ ')', 'ITNFSAINFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ITNFSAINFE_U' AND type = 'TR')
   drop trigger ITNFSAINFE_U
go
create trigger dbo.ITNFSAINFE_U on dbo.ITNFSAINFE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ITNFSAINFE SET     FRETE = '+ ISNULL(LTRIM(RTRIM(CAST(FRETE AS CHAR(254)))),0) +',    DESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +',    CT = '+ ISNULL(LTRIM(RTRIM(CAST(CT AS CHAR(254)))),0) +',    BASEICMS = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICMS AS CHAR(254)))),0) +',    VALORICMS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMS AS CHAR(254)))),0) +',    PERCREDUCAOBASE = '+ ISNULL(LTRIM(RTRIM(CAST(PERCREDUCAOBASE AS CHAR(254)))),0) +',    BASESUBSTRIBUTARIA = '+ ISNULL(LTRIM(RTRIM(CAST(BASESUBSTRIBUTARIA AS CHAR(254)))),0) +',    ALIQICMS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMS AS CHAR(254)))),0) +',    VALORSUBSTRIBUTARIA = '+ ISNULL(LTRIM(RTRIM(CAST(VALORSUBSTRIBUTARIA AS CHAR(254)))),0) +',    PERCREDUCAOBASEST = '+ ISNULL(LTRIM(RTRIM(CAST(PERCREDUCAOBASEST AS CHAR(254)))),0) +',    BASEIPI = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +',    ALIQIPI = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIPI AS CHAR(254)))),0) +',    VALORIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALORIPI AS CHAR(254)))),0) +',    CTIPI = '+ ISNULL(LTRIM(RTRIM(CAST(CTIPI AS CHAR(254)))),0) +',    SEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(SEGURO AS CHAR(254)))),0) +',    VALUNITTRIBUTADO = '+ ISNULL(LTRIM(RTRIM(CAST(VALUNITTRIBUTADO AS CHAR(254)))),0) +',    BASEPIS = '+ ISNULL(LTRIM(RTRIM(CAST(BASEPIS AS CHAR(254)))),0) +',    ALIQPIS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQPIS AS CHAR(254)))),0) +',    VALORPIS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORPIS AS CHAR(254)))),0) +',    BASECOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(BASECOFINS AS CHAR(254)))),0) +',    ALIQCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQCOFINS AS CHAR(254)))),0) +',    VALORCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORCOFINS AS CHAR(254)))),0) +',    CTPIS = '+ ISNULL(LTRIM(RTRIM(CAST(CTPIS AS CHAR(254)))),0) +',    CTCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(CTCOFINS AS CHAR(254)))),0) +',    PERCENTUALST = '+ ISNULL(LTRIM(RTRIM(CAST(PERCENTUALST AS CHAR(254)))),0) +',    OUTRASDESPESASINCLUSAS = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +',    VALORRETIDOCSLL = '+ ISNULL(LTRIM(RTRIM(CAST(VALORRETIDOCSLL AS CHAR(254)))),0) +',    ALIQICMSST = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQICMSST AS CHAR(254)))),0) +''+  ' WHERE NUMORD = '+ RTRIM(CAST(NUMORD as char(254))) +  ' and ITEM = '''+ RTRIM(ITEM)  + ''''   , 'ITNFSAINFE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LANCHECCXA_D' AND type = 'TR')
