create or replace PROCEDURE ARQUIVO_DIGITAL( 
   P_CDIMPOSTO    IN IMPOSTO.CDIMPOSTO%TYPE, 
   P_CDEMPRESA    IN EMPRESA.CDEMPRESA%TYPE, 
   P_CDINSCESTA   IN EMPRESA.CDINSCESTA%TYPE, 
   P_DTINICIAL    IN NOTAFISCAL.DTENTRSAID%TYPE, 
   P_DTFINAL      IN NOTAFISCAL.DTENTRSAID%TYPE, 
   P_TIPO         IN NOTAFISCAL.IDSTATUS%TYPE, 
   P_FINALIDADE   IN NOTAFISCAL.CDTIPOOPER%TYPE, 
   P_INDESCRITU   IN NOTAFISCAL.IDSTATUS%TYPE, 
   P_IDCENTRAL    IN NOTAFISCAL.IDSTATUS%TYPE, 
   P_REGISTRO     IN VARCHAR2, 
   P_CDINSCMUNIC  IN EMPRESA.CDINSCESTA%TYPE, 
   P_NRSEQARQMAG  IN VARCHAR2, 
   P_CDLIVROMAG   IN LIVROMAGNETICO.CDLIVROMAG%TYPE,
   P_VALORSTENTR  IN NUMBER)
AS
   V_CONTGERA     NUMBER;
   V_CONTREGA     NUMBER;
   V_REGAAAAA     NUMBER;
   V_CONTREGB     NUMBER;
   V_CONTREGC     NUMBER;
   V_CONTREGD     NUMBER;
   V_CONTREGE     NUMBER;
   V_CONTREGH     NUMBER;
   V_CONTREG8     NUMBER;
   V_CONTREG9     NUMBER;
   V_SEQUENCIAL   VARCHAR2(20);
BEGIN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
   V_CONTREGA := 0;
   V_CONTREGA := ARQDIGITAL_INICIO(P_CDIMPOSTO,P_CDEMPRESA,P_CDINSCESTA,P_DTINICIAL,P_DTFINAL,P_TIPO,P_FINALIDADE,P_INDESCRITU,P_NRSEQARQMAG,P_IDCENTRAL, P_CDLIVROMAG);
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
   V_REGAAAAA := 0;
   V_REGAAAAA := ARQDIGITAL_BLCA(P_CDEMPRESA, P_CDINSCMUNIC, P_DTINICIAL, P_DTFINAL, P_NRSEQARQMAG);
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
   V_CONTREGB := 0;
   V_CONTREGB := ARQDIGITAL_BLOCOB(P_CDIMPOSTO, P_CDEMPRESA, P_CDINSCMUNIC, P_DTINICIAL, P_DTFINAL, P_NRSEQARQMAG);
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
   V_CONTREGC := 0;
   V_CONTREGC := ARQDIGITAL_BLOCOC(P_CDIMPOSTO, P_CDEMPRESA, P_CDINSCESTA, P_DTINICIAL, P_DTFINAL, P_NRSEQARQMAG);
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
   V_CONTREGD := 0;
   V_CONTREGD := ARQDIGITAL_BLOCOD(P_CDIMPOSTO, P_CDEMPRESA, P_CDINSCESTA, P_DTINICIAL, P_DTFINAL, P_NRSEQARQMAG);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   V_CONTREGE := 0;
   V_CONTREGE := ARQDIGITAL_BLOCOE(P_CDIMPOSTO, P_CDEMPRESA, P_CDINSCESTA, P_DTINICIAL, P_DTFINAL, P_NRSEQARQMAG, P_VALORSTENTR);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   V_CONTREGH := 0;
   V_CONTREGH := ARQDIGITAL_BLOCOH(P_CDIMPOSTO, P_CDEMPRESA, P_CDINSCESTA, P_DTINICIAL, P_DTFINAL, P_NRSEQARQMAG, P_CDLIVROMAG);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   /* 5811 */
   V_CONTREG8 := 0;
   V_CONTREG8 := ARQDIGITAL_BLOCO8(P_CDEMPRESA,P_NRSEQARQMAG);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   /* 5807 */
   V_CONTREG9 := 0;
   V_CONTREG9 := ARQDIGITAL_BLOCO9(V_CONTREGA, V_CONTREGB, V_CONTREGC, V_CONTREGD, V_CONTREGE, V_CONTREGH, P_NRSEQARQMAG, P_CDLIVROMAG);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   V_CONTGERA := NVL(V_CONTREGA,0) + NVL(V_REGAAAAA,0) + NVL(V_CONTREGB,0) + NVL(V_CONTREGC,0) + NVL(V_CONTREGD,0) + NVL(V_CONTREGE,0) + NVL(V_CONTREGH,0) + NVL(V_CONTREG8,0) + NVL(V_CONTREG9,0);
   V_CONTGERA := 0;
   SELECT COUNT(*)+1
     INTO V_CONTGERA
     FROM ARQMAGNETICO
    WHERE NRSEQARQMAG = P_NRSEQARQMAG;
   INSERT INTO ARQMAGNETICO
     (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG)
   VALUES
     ('70'||LPAD(RTRIM(V_CONTREG9), 8, '0'), '|9999'|| '|' ||RTRIM(V_CONTGERA)|| '|',  P_NRSEQARQMAG);
END;
/
-- VERSAO --
BEGIN ATUVEROBJ('ARQUIVO_DIGITAL','6.39.005'); END;
/

