CREATE OR REPLACE PROCEDURE COPYPARAMS_GOP(P_CDFILDEST   IN LISTA.NRLISTA%TYPE,
                                           P_ITEMOPERA   IN VARCHAR2,
                                           P_CDOPERADOR  IN VARCHAR2,
                                           P_CDFILORIG   IN FILIAL.CDFILIAL%TYPE DEFAULT NULL)
AS
  V_VRJASOLICITADOAF   FLOAT;
  V_PERCITFILGOP       NUMBER;
  V_PERCITDETALFILGOP  NUMBER;
  V_PERCITEMDETALGOP   NUMBER;
BEGIN
   FOR C_ITEM IN (SELECT I.IDTIPOORCAOP, I.NRITEMOPERACIONAL, P.DSITEMORCAMENTO
                    FROM ITEMOPERACIONAL I, PERCITEMGOP P
                   WHERE INSTR(P_ITEMOPERA, '_' || TO_CHAR(I.NRITEMOPERACIONAL) || '_') > 0
                     AND I.NRITEMOPERACIONAL = P.NRPERCITEMGOP
                   ORDER BY I.NRITEMOPERACIONAL) LOOP   
      /* REMOVE FILIAIS DE DESTINO */
      DELETE FROM PERCDETPRODFILGOP
            WHERE NRPERCITDETALFILGOP IN (SELECT PD.NRPERCITDETALFILGOP
                                            FROM PERCITDETALFILGOP PD INNER JOIN PERCITFILGOP P ON P.NRPERCITFILGOP = PD.NRPERCITFILGOP
                                                                      INNER JOIN LISTA L ON L.CDLISTA = P.CDFILIAL
                                                                                        AND L.CDLISTA <> NVL(P_CDFILORIG,'T')
                                           WHERE P.NRSEQITEMORCA = C_ITEM.NRITEMOPERACIONAL
                                             AND L.NRLISTA = P_CDFILDEST);
      DELETE FROM PERCITDETALFILGOP
            WHERE NRPERCITFILGOP IN (SELECT P.NRPERCITFILGOP
                                       FROM PERCITFILGOP P INNER JOIN LISTA L ON L.CDLISTA = P.CDFILIAL
                                                                             AND L.CDLISTA <> NVL(P_CDFILORIG,'T')
                                      WHERE P.NRSEQITEMORCA = C_ITEM.NRITEMOPERACIONAL
                                        AND L.NRLISTA = P_CDFILDEST);
      DELETE FROM PERCITFILGOP
            WHERE NRSEQITEMORCA = C_ITEM.NRITEMOPERACIONAL
              AND CDFILIAL IN (SELECT L.CDLISTA
                                 FROM LISTA L
                                WHERE L.CDLISTA <> NVL(P_CDFILORIG,'T')
                                  AND L.NRLISTA = P_CDFILDEST);
      /* REMOVE FILIAL PADRAO CASO TENHA POSSIBILIDADE DE ESTAR NO DESTINO */
      DELETE FROM PERCDETALPRODGOP
            WHERE NRPERCITEMDETALGOP IN (SELECT PD.NRPERCITEMDETALGOP
                                           FROM PERCITEMDETALGOP PD INNER JOIN PERCITEMGOP P ON P.NRPERCITEMGOP = PD.NRPERCITEMGOP
                                                                    INNER JOIN LISTA L ON L.CDLISTA = 'P'
                                          WHERE P.NRSEQITEMORCA = C_ITEM.NRITEMOPERACIONAL
                                            AND L.NRLISTA = P_CDFILDEST);
      DELETE FROM PERCITEMDETALGOP
            WHERE NRPERCITEMGOP IN (SELECT P.NRPERCITEMGOP
                                      FROM PERCITEMGOP P INNER JOIN LISTA L ON L.CDLISTA = 'P'
                                     WHERE P.NRSEQITEMORCA = C_ITEM.NRITEMOPERACIONAL
                                       AND L.NRLISTA = P_CDFILDEST);
      IF P_CDFILORIG IS NULL THEN
         /* DRO */
         FOR C_LISTAFIL IN (SELECT L.CDLISTA, P.CDFILIAL CDFILIALP, P.IDSERVFATROP, P.IDCONSFATUDIV, P.CDGRUPPROD,
                                   P.IDDESPMOBROP, P.IDAPURDESPENTRMO, P.IDAPUMOCTPGROP, P.IDDESPMOBROPCTB, P.IDDESPDIVROP,
                                   P.IDAPUCTPGROP, P.IDDESPENTROP, P.IDDESPDIVCTBL, P.IDAPUINVFILROP, P.IDAPURAINVCTPAGROP,
                                   P.IDLANCIMPPAG
                              FROM LISTA L, PARFILIALROP P
                             WHERE L.NRLISTA = P_CDFILDEST
                               AND P.CDFILIAL = TIPOPARAM_DRO(L.CDLISTA)) LOOP
            IF C_LISTAFIL.CDLISTA = 'P' THEN
               UPDATE PERCITEMGOP
                  SET VRPERCITEMGOP = 0
                WHERE NRPERCITEMGOP = C_ITEM.NRITEMOPERACIONAL;
               IF C_ITEM.IDTIPOORCAOP = 'FATURAMENTO' THEN
                  IF C_LISTAFIL.IDCONSFATUDIV = 'S' THEN                         
                     FOR C_FAT IN (SELECT CDFATUDIVER
                                     FROM FATUDIVER) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDFATUDIVER, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_FAT.CDFATUDIVER, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
               ELSIF C_ITEM.IDTIPOORCAOP = 'IMPOSTO' THEN
                  FOR C_IMP IN (SELECT P.CDIMPOSTO
                                  FROM IMPOSTOROP P
                                 WHERE P.CDFILIAL = C_LISTAFIL.CDFILIALP
                                   AND P.IDTPIMPOSTOROP IN ('FS', 'FE', 'FN')
                                 GROUP BY P.CDIMPOSTO) LOOP
                     INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDIMPOSTO, VRPERCENTUAL, CDOPERINCLUSAO)
                          VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_IMP.CDIMPOSTO, 0, P_CDOPERADOR);
                  END LOOP;
                  IF C_LISTAFIL.IDLANCIMPPAG = 'S' THEN
                     FOR C_IMP IN (SELECT CDTPCTPAGAR
                                     FROM TIPOPAGIMPROP
                                    WHERE CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDTPCTPAGAR, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_IMP.CDTPCTPAGAR, 0, P_CDOPERADOR);        
                     END LOOP;
                  END IF;
               ELSIF C_ITEM.IDTIPOORCAOP = 'CONSUMO' THEN
                  FOR C_FAT IN (SELECT CDPRODUTO
                                  FROM PRODUTOROP
                                 WHERE IDTPPRODUTOROP = 'CO'
                                   AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                     INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDPRODUTO, VRPERCENTUAL, CDOPERINCLUSAO)
                          VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_FAT.CDPRODUTO, 0, P_CDOPERADOR);
                  END LOOP;
               ELSIF C_ITEM.IDTIPOORCAOP = 'MAOOBRA' THEN
                  IF C_LISTAFIL.IDDESPMOBROP = 'S' THEN
                     FOR C_MOO IN (SELECT CDFILIAL, CDORCAMENTOMO
                                     FROM ORCAMENTOMO
                                    WHERE CDFILIAL = 'T') LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDFILIALMO, CDORCAMENTOMO, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_MOO.CDFILIAL, C_MOO.CDORCAMENTOMO, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDDESPMOBROPCTB = 'S' THEN
                     FOR C_MOO IN (SELECT CDFILIAL, CDDESPADMFAT, CDCONTCTBL
                                     FROM DESPORCMOCCONT
                                    WHERE CDFILIAL = 'T') LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDFILIALMO, CDCONTCTBL, CDDESPADMFAT, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_MOO.CDFILIAL, C_MOO.CDCONTCTBL, C_MOO.CDDESPADMFAT, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDAPUMOCTPGROP = 'S' THEN
                     FOR C_MOO IN (SELECT CASE WHEN CDFILIAL = 'P' THEN 'T' ELSE CDFILIAL END CDFILIAL, CDTPCTPAGAR
                                     FROM TIPOCTPAGROP
                                    WHERE IDTPCTPAGROP = 'MAO'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDFILIALMO, CDTPCTPAGAR, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_MOO.CDFILIAL, C_MOO.CDTPCTPAGAR, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDAPURDESPENTRMO = 'S' THEN
                     FOR C_MOO IN (SELECT CASE WHEN CDFILIAL = 'P' THEN 'T' ELSE CDFILIAL END CDFILIAL, CDPRODUTO
                                     FROM PRODUTOROP
                                    WHERE IDTPPRODUTOROP = 'CO'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDFILIALMO, CDPRODUTO, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_MOO.CDFILIAL, C_MOO.CDPRODUTO, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
               ELSIF C_ITEM.IDTIPOORCAOP = 'DESPDIVERSA' THEN
                  IF C_LISTAFIL.IDDESPDIVROP = 'S' THEN
                     FOR C_DSP IN (SELECT CDDESPPREV
                                     FROM DESPPREV) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDDESPPREV, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_DSP.CDDESPPREV, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDAPUCTPGROP = 'S' THEN
                     FOR C_DSP IN (SELECT CDTPCTPAGAR
                                     FROM TIPOCTPAGROP
                                    WHERE IDTPCTPAGROP = 'DSP'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDTPCTPAGAR, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_DSP.CDTPCTPAGAR, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDDESPENTROP = 'S' THEN
                     FOR C_DSP IN (SELECT CDPRODUTO
                                     FROM PRODUTOROP
                                    WHERE IDTPPRODUTOROP = 'DE'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDPRODUTO, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_DSP.CDPRODUTO, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDDESPENTROP = 'N' AND C_LISTAFIL.IDAPUCTPGROP = 'N' AND C_LISTAFIL.IDAPUMOCTPGROP = 'N' AND C_LISTAFIL.IDDESPDIVCTBL = 'S' THEN
                     FOR C_DSP IN (SELECT CDCONTCTBL
                                     FROM CTBLDESPPREV
                                    WHERE NVL(IDATIVOCTBLDESP,'S') = 'S'
                                    GROUP BY CDCONTCTBL) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDCONTCTBL, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_DSP.CDCONTCTBL, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
               ELSIF C_ITEM.IDTIPOORCAOP = 'DESPENTRADA' THEN
                  IF C_LISTAFIL.IDDESPENTROP = 'S' THEN
                     FOR C_DSP IN (SELECT CDPRODUTO
                                     FROM PRODUTOROP
                                    WHERE IDTPPRODUTOROP = 'DE'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDPRODUTO, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_DSP.CDPRODUTO, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
               ELSIF C_ITEM.IDTIPOORCAOP = 'INVESTIMENTO' THEN
                  IF C_LISTAFIL.IDAPUINVFILROP = 'S' THEN
                     FOR C_INV IN (SELECT CDINVEST
                                     FROM INVESTIMENTOS) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDINVEST, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_INV.CDINVEST, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDAPURAINVCTPAGROP = 'S' THEN
                     FOR C_INV IN (SELECT CDTPCTPAGAR
                                     FROM TIPOCTPAGROP
                                    WHERE IDTPCTPAGROP = 'INV'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDTPCTPAGAR, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (C_ITEM.NRITEMOPERACIONAL, SEQ_PERCITEMDETALGOP.NEXTVAL, C_INV.CDTPCTPAGAR, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
               END IF;
            ELSE
               V_PERCITFILGOP := SEQ_PERCITFILGOP.NEXTVAL;
               INSERT INTO PERCITFILGOP (NRPERCITFILGOP, CDFILIAL, NRSEQITEMORCA, DSITEMORCAMENTO, VRPERCITEMGOP, CDOPERINCLUSAO)
                    VALUES (V_PERCITFILGOP, C_LISTAFIL.CDLISTA, C_ITEM.NRITEMOPERACIONAL, C_ITEM.DSITEMORCAMENTO, 0, P_CDOPERADOR);
               IF C_ITEM.IDTIPOORCAOP = 'FATURAMENTO' THEN
                  IF C_LISTAFIL.IDCONSFATUDIV = 'S' THEN                         
                     FOR C_FAT IN (SELECT CDFATUDIVER
                                     FROM FATUDIVER) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDFATUDIVER, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_FAT.CDFATUDIVER, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  FOR C_FAT IN (SELECT SC.CDSERVFILI
                                  FROM SERVICOROP SC, SERVICO S
                                 WHERE SC.CDFILIAL = C_LISTAFIL.CDFILIALP
                                   AND IDTPSERVICOROP = 'E'
                                   AND C_LISTAFIL.IDSERVFATROP <> 'S'
                                   AND SC.CDSERVFILI = S.CDSERVFILI
                                   AND S.CDFILIAL = C_LISTAFIL.CDLISTA
                                 UNION
                                SELECT S.CDSERVFILI
                                  FROM SERVICO S
                                 WHERE S.CDFILIAL = C_LISTAFIL.CDLISTA
                                   AND C_LISTAFIL.IDSERVFATROP = 'S'
                                   AND (QTCOMESTISEG IS NOT NULL OR
                                        QTCOMESTITER IS NOT NULL OR
                                        QTCOMESTIQUA IS NOT NULL OR
                                        QTCOMESTIQUI IS NOT NULL OR
                                        QTCOMESTISEX IS NOT NULL OR
                                        QTCOMESTISAB IS NOT NULL OR
                                        QTCOMESTIDOM IS NOT NULL OR
                                        QTCOMESTIFER IS NOT NULL)) LOOP
                     INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDSERVFILI, VRPERCENTUAL, CDOPERINCLUSAO)
                          VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_FAT.CDSERVFILI, 0, P_CDOPERADOR);
                  END LOOP;                                  
               ELSIF C_ITEM.IDTIPOORCAOP = 'IMPOSTO' THEN
                  FOR C_IMP IN (SELECT P.CDIMPOSTO
                                  FROM IMPOSTOROP P
                                 WHERE P.CDFILIAL = C_LISTAFIL.CDFILIALP
                                   AND P.IDTPIMPOSTOROP IN ('FS', 'FE', 'FN')
                                 GROUP BY P.CDIMPOSTO) LOOP
                     INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDIMPOSTO, VRPERCENTUAL, CDOPERINCLUSAO)
                          VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_IMP.CDIMPOSTO, 0, P_CDOPERADOR);
                  END LOOP;
                  IF C_LISTAFIL.IDLANCIMPPAG = 'S' THEN
                     FOR C_IMP IN (SELECT CDTPCTPAGAR
                                     FROM TIPOPAGIMPROP
                                    WHERE CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDTPCTPAGAR, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_IMP.CDTPCTPAGAR, 0, P_CDOPERADOR);        
                     END LOOP;
                  END IF;
               ELSIF C_ITEM.IDTIPOORCAOP = 'CONSUMO' THEN
                  FOR C_FAT IN (SELECT CDPRODUTO
                                  FROM PRODUTOROP
                                 WHERE IDTPPRODUTOROP = 'CO'
                                   AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                     INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDPRODUTO, VRPERCENTUAL, CDOPERINCLUSAO)
                          VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_FAT.CDPRODUTO, 0, P_CDOPERADOR);
                  END LOOP;
               ELSIF C_ITEM.IDTIPOORCAOP = 'MAOOBRA' THEN
                  IF C_LISTAFIL.IDDESPMOBROP = 'S' THEN
                     FOR C_MOO IN (SELECT CDFILIAL, CDORCAMENTOMO
                                     FROM ORCAMENTOMO
                                    WHERE CDFILIAL = 'T' OR CDFILIAL = C_LISTAFIL.CDLISTA) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDFILIALMO, CDORCAMENTOMO, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_MOO.CDFILIAL, C_MOO.CDORCAMENTOMO, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDDESPMOBROPCTB = 'S' THEN
                     FOR C_MOO IN (SELECT CDFILIAL, CDDESPADMFAT, CDCONTCTBL
                                     FROM DESPORCMOCCONT
                                    WHERE CDFILIAL = 'T') LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDFILIALMO, CDCONTCTBL, CDDESPADMFAT, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_MOO.CDFILIAL, C_MOO.CDCONTCTBL, C_MOO.CDDESPADMFAT, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDAPUMOCTPGROP = 'S' THEN
                     FOR C_MOO IN (SELECT CASE WHEN CDFILIAL = 'P' THEN 'T' ELSE CDFILIAL END CDFILIAL, CDTPCTPAGAR
                                     FROM TIPOCTPAGROP
                                    WHERE IDTPCTPAGROP = 'MAO'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDFILIALMO, CDTPCTPAGAR, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_MOO.CDFILIAL, C_MOO.CDTPCTPAGAR, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDAPURDESPENTRMO = 'S' THEN
                     FOR C_MOO IN (SELECT CASE WHEN CDFILIAL = 'P' THEN 'T' ELSE CDFILIAL END CDFILIAL, CDPRODUTO
                                     FROM PRODUTOROP
                                    WHERE IDTPPRODUTOROP = 'CO'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDFILIALMO, CDPRODUTO, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_MOO.CDFILIAL, C_MOO.CDPRODUTO, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
               ELSIF C_ITEM.IDTIPOORCAOP = 'DESPDIVERSA' THEN
                  IF C_LISTAFIL.IDDESPDIVROP = 'S' THEN
                     FOR C_DSP IN (SELECT CDDESPPREV
                                     FROM DESPPREV) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDDESPPREV, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_DSP.CDDESPPREV, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDAPUCTPGROP = 'S' THEN
                     FOR C_DSP IN (SELECT CDTPCTPAGAR
                                     FROM TIPOCTPAGROP
                                    WHERE IDTPCTPAGROP = 'DSP'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDTPCTPAGAR, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_DSP.CDTPCTPAGAR, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDDESPENTROP = 'S' THEN
                     FOR C_DSP IN (SELECT CDPRODUTO
                                     FROM PRODUTOROP
                                    WHERE IDTPPRODUTOROP = 'DE'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDPRODUTO, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_DSP.CDPRODUTO, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDDESPENTROP = 'N' AND C_LISTAFIL.IDAPUCTPGROP = 'N' AND C_LISTAFIL.IDAPUMOCTPGROP = 'N' AND C_LISTAFIL.IDDESPDIVCTBL = 'S' THEN
                     FOR C_DSP IN (SELECT CDCONTCTBL
                                     FROM CTBLDESPPREV
                                    WHERE NVL(IDATIVOCTBLDESP,'S') = 'S'
                                    GROUP BY CDCONTCTBL) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDCONTCTBL, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_DSP.CDCONTCTBL, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
               ELSIF C_ITEM.IDTIPOORCAOP = 'DESPENTRADA' THEN
                  IF C_LISTAFIL.IDDESPENTROP = 'S' THEN
                     FOR C_DSP IN (SELECT CDPRODUTO
                                     FROM PRODUTOROP
                                    WHERE IDTPPRODUTOROP = 'DE'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDPRODUTO, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_DSP.CDPRODUTO, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
               ELSIF C_ITEM.IDTIPOORCAOP = 'INVESTIMENTO' THEN
                  IF C_LISTAFIL.IDAPUINVFILROP = 'S' THEN
                     FOR C_INV IN (SELECT CDINVEST
                                     FROM INVESTIMENTOS) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDINVEST, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_INV.CDINVEST, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
                  IF C_LISTAFIL.IDAPURAINVCTPAGROP = 'S' THEN
                     FOR C_INV IN (SELECT CDTPCTPAGAR
                                     FROM TIPOCTPAGROP
                                    WHERE IDTPCTPAGROP = 'INV'
                                      AND CDFILIAL = C_LISTAFIL.CDFILIALP) LOOP
                        INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDTPCTPAGAR, VRPERCENTUAL, CDOPERINCLUSAO)
                             VALUES (V_PERCITFILGOP, SEQ_PERCITDETALFILGOP.NEXTVAL, C_LISTAFIL.CDLISTA, C_INV.CDTPCTPAGAR, 0, P_CDOPERADOR);
                     END LOOP;
                  END IF;
               END IF;
            END IF;
            COMMIT;
         END LOOP;
      ELSE
         /* REPLICACAO */         
         FOR C_LISTAFIL IN (SELECT L.CDLISTA
                              FROM LISTA L
                             WHERE L.NRLISTA = P_CDFILDEST
                               AND L.CDLISTA <> P_CDFILORIG) LOOP
            IF P_CDFILORIG = 'P' THEN
               /* ORIGEM PADRAO */
               FOR C_PERCITFILGOP IN (SELECT SEQ_PERCITFILGOP.NEXTVAL SEQ, P.NRSEQITEMORCA, P.DSITEMORCAMENTO, P.VRPERCITEMGOP, P_CDOPERADOR CDOPERADOR,
                                             P.NRPERCITEMGOP
                                        FROM PERCITEMGOP P
                                       WHERE P.NRPERCITEMGOP = C_ITEM.NRITEMOPERACIONAL) LOOP
                  INSERT INTO PERCITFILGOP (NRPERCITFILGOP, CDFILIAL, NRSEQITEMORCA, DSITEMORCAMENTO, VRPERCITEMGOP, CDOPERINCLUSAO)
                       VALUES (C_PERCITFILGOP.SEQ, C_LISTAFIL.CDLISTA, C_PERCITFILGOP.NRSEQITEMORCA, C_PERCITFILGOP.DSITEMORCAMENTO, C_PERCITFILGOP.VRPERCITEMGOP, C_PERCITFILGOP.CDOPERADOR);
                  FOR C_PERCITDETALFILGOP IN (SELECT SEQ_PERCITDETALFILGOP.NEXTVAL SEQ, PD.CDPRODUTO, PD.CDIMPOSTO, PD.CDTIPOOPER, PD.CDFILIALMO,
                                                     PD.IDENTRSAIDOP, PD.CDINVEST, PD.CDDESPADMFAT, PD.CDDESPPREV, PD.IDDESPPREV, PD.VRPERCENTUAL, 
                                                     PD.CDORCAMENTOMO, PD.CDFATUDIVER, PD.CDSERVFILI, PD.CDSUBGRPROD, PD.CDTPCTPAGAR, PD.CDCONTCTBL, PD.CDGRUPPROD, PD.DSEXPRESSAO,
                                                     P_CDOPERADOR CDOPERADOR, PD.NRPERCITEMDETALGOP
                                                FROM PERCITEMDETALGOP PD
                                               WHERE PD.NRPERCITEMGOP = C_PERCITFILGOP.NRPERCITEMGOP
                                                 AND PD.CDSERVFILI IS NULL) LOOP
                     INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDPRODUTO,
                                                    CDIMPOSTO, CDTIPOOPER, CDFILIALMO, IDENTRSAIDOP,
                                                    CDINVEST, CDDESPADMFAT, CDDESPPREV, IDDESPPREV,
                                                    VRPERCENTUAL, CDORCAMENTOMO, CDFATUDIVER, CDSERVFILI,
                                                    CDSUBGRPROD, CDTPCTPAGAR, CDCONTCTBL, CDGRUPPROD,
                                                    DSEXPRESSAO, CDOPERINCLUSAO)
                          VALUES (C_PERCITFILGOP.SEQ, C_PERCITDETALFILGOP.SEQ, C_LISTAFIL.CDLISTA, C_PERCITDETALFILGOP.CDPRODUTO,
                                  C_PERCITDETALFILGOP.CDIMPOSTO, C_PERCITDETALFILGOP.CDTIPOOPER, C_PERCITDETALFILGOP.CDFILIALMO, C_PERCITDETALFILGOP.IDENTRSAIDOP,
                                  C_PERCITDETALFILGOP.CDINVEST, C_PERCITDETALFILGOP.CDDESPADMFAT, C_PERCITDETALFILGOP.CDDESPPREV, C_PERCITDETALFILGOP.IDDESPPREV,
                                  C_PERCITDETALFILGOP.VRPERCENTUAL, C_PERCITDETALFILGOP.CDORCAMENTOMO, C_PERCITDETALFILGOP.CDFATUDIVER, C_PERCITDETALFILGOP.CDSERVFILI,
                                  C_PERCITDETALFILGOP.CDSUBGRPROD, C_PERCITDETALFILGOP.CDTPCTPAGAR, C_PERCITDETALFILGOP.CDCONTCTBL, C_PERCITDETALFILGOP.CDGRUPPROD,
                                  C_PERCITDETALFILGOP.DSEXPRESSAO, C_PERCITDETALFILGOP.CDOPERADOR);
                     FOR C_PERCDETPRODFILGOP IN (SELECT SEQ_PERCDETPRODFILGOP.NEXTVAL SEQ, PDP.CDPRODUTO,
                                                        PDP.CDORCAMENTOMO, PDP.CDDESPADMFAT, PDP.CDTIPOOPER,
                                                        PDP.CDFILIALMO, PDP.IDENTRSAIDOP, PDP.VRPERCENTUAL,
                                                        PDP.CDCONTCTBL, PDP.CDTPCTPAGAR, P_CDOPERADOR CDOPERADOR
                                                   FROM PERCDETALPRODGOP PDP
                                                  WHERE PDP.NRPERCITEMDETALGOP = C_PERCITDETALFILGOP.NRPERCITEMDETALGOP) LOOP
                        INSERT INTO PERCDETPRODFILGOP (NRPERCITDETALFILGOP, NRPERCDETPRODFILGOP, CDFILIAL, CDPRODUTO,
                                                       CDORCAMENTOMO, CDDESPADMFAT, CDTIPOOPER,
                                                       CDFILIALMO, IDENTRSAIDOP, VRPERCENTUAL,
                                                       CDCONTCTBL, CDTPCTPAGAR, CDOPERINCLUSAO)
                             VALUES (C_PERCITDETALFILGOP.SEQ, C_PERCDETPRODFILGOP.SEQ, C_LISTAFIL.CDLISTA, C_PERCDETPRODFILGOP.CDPRODUTO,
                                     C_PERCDETPRODFILGOP.CDORCAMENTOMO, C_PERCDETPRODFILGOP.CDDESPADMFAT, C_PERCDETPRODFILGOP.CDTIPOOPER,
                                     C_PERCDETPRODFILGOP.CDFILIALMO, C_PERCDETPRODFILGOP.IDENTRSAIDOP, C_PERCDETPRODFILGOP.VRPERCENTUAL,
                                     C_PERCDETPRODFILGOP.CDCONTCTBL, C_PERCDETPRODFILGOP.CDTPCTPAGAR, C_PERCDETPRODFILGOP.CDOPERADOR);
                     END LOOP;
                  END LOOP;
               END LOOP;
            ELSIF C_LISTAFIL.CDLISTA  = 'P' THEN
               /* DESTINO PADRAO */
               FOR C_PERCITEMGOP IN (SELECT P.CDFILIAL, P.NRSEQITEMORCA, P.DSITEMORCAMENTO, P.VRPERCITEMGOP, P_CDOPERADOR CDOPERADOR, P.NRPERCITFILGOP
                                       FROM PERCITFILGOP P
                                      WHERE P.NRSEQITEMORCA = C_ITEM.NRITEMOPERACIONAL
                                        AND P.CDFILIAL = P_CDFILORIG) LOOP
                  UPDATE PERCITEMGOP
                     SET VRPERCITEMGOP = C_PERCITEMGOP.VRPERCITEMGOP
                   WHERE NRPERCITEMGOP = C_ITEM.NRITEMOPERACIONAL;
                  FOR C_PERCITEMDETALGOP IN (SELECT SEQ_PERCITEMDETALGOP.NEXTVAL SEQ, PD.CDPRODUTO, PD.CDIMPOSTO, PD.CDTIPOOPER, PD.CDFILIALMO,
                                                    PD.IDENTRSAIDOP, PD.CDINVEST, PD.CDDESPADMFAT, PD.CDDESPPREV, PD.IDDESPPREV, PD.VRPERCENTUAL, 
                                                    PD.CDORCAMENTOMO, PD.CDFATUDIVER, PD.CDSERVFILI, PD.CDSUBGRPROD, PD.CDTPCTPAGAR, PD.CDCONTCTBL, PD.CDGRUPPROD, PD.DSEXPRESSAO,
                                                    P_CDOPERADOR CDOPERADOR, PD.NRPERCITDETALFILGOP
                                               FROM PERCITDETALFILGOP PD
                                              WHERE PD.NRPERCITFILGOP = C_PERCITEMGOP.NRPERCITFILGOP
                                                AND PD.CDSERVFILI IS NULL) LOOP
                     INSERT INTO PERCITEMDETALGOP (NRPERCITEMGOP, NRPERCITEMDETALGOP, CDPRODUTO,
                                                   CDIMPOSTO, CDTIPOOPER, CDFILIALMO, IDENTRSAIDOP,
                                                   CDINVEST, CDDESPADMFAT, CDDESPPREV, IDDESPPREV,
                                                   VRPERCENTUAL, CDORCAMENTOMO, CDFATUDIVER, CDSERVFILI,
                                                   CDSUBGRPROD, CDTPCTPAGAR, CDCONTCTBL, CDGRUPPROD,
                                                   DSEXPRESSAO, CDOPERINCLUSAO)
                          VALUES (C_ITEM.NRITEMOPERACIONAL, C_PERCITEMDETALGOP.SEQ, C_PERCITEMDETALGOP.CDPRODUTO,
                                  C_PERCITEMDETALGOP.CDIMPOSTO, C_PERCITEMDETALGOP.CDTIPOOPER, C_PERCITEMDETALGOP.CDFILIALMO, C_PERCITEMDETALGOP.IDENTRSAIDOP,
                                  C_PERCITEMDETALGOP.CDINVEST, C_PERCITEMDETALGOP.CDDESPADMFAT, C_PERCITEMDETALGOP.CDDESPPREV, C_PERCITEMDETALGOP.IDDESPPREV,
                                  C_PERCITEMDETALGOP.VRPERCENTUAL, C_PERCITEMDETALGOP.CDORCAMENTOMO, C_PERCITEMDETALGOP.CDFATUDIVER, C_PERCITEMDETALGOP.CDSERVFILI,
                                  C_PERCITEMDETALGOP.CDSUBGRPROD, C_PERCITEMDETALGOP.CDTPCTPAGAR, C_PERCITEMDETALGOP.CDCONTCTBL, C_PERCITEMDETALGOP.CDGRUPPROD,
                                  C_PERCITEMDETALGOP.DSEXPRESSAO, C_PERCITEMDETALGOP.CDOPERADOR);
                     FOR C_PERCDETALPRODGOP IN (SELECT SEQ_PERCDETALPRODGOP.NEXTVAL SEQ, PDP.CDPRODUTO,
                                                       PDP.CDORCAMENTOMO, PDP.CDDESPADMFAT, PDP.CDTIPOOPER,
                                                       PDP.CDFILIALMO, PDP.IDENTRSAIDOP, PDP.VRPERCENTUAL,
                                                       PDP.CDCONTCTBL, PDP.CDTPCTPAGAR, P_CDOPERADOR CDOPERADOR
                                                  FROM PERCDETPRODFILGOP PDP
                                                 WHERE PDP.NRPERCITDETALFILGOP = C_PERCITEMDETALGOP.NRPERCITDETALFILGOP) LOOP
                        INSERT INTO PERCDETALPRODGOP (NRPERCITEMDETALGOP, NRPERCDETALPRODGOP, CDPRODUTO,
                                                      CDORCAMENTOMO, CDDESPADMFAT, CDTIPOOPER,
                                                      CDFILIALMO, IDENTRSAIDOP, VRPERCENTUAL,
                                                      CDCONTCTBL, CDTPCTPAGAR, CDOPERINCLUSAO)
                             VALUES (C_PERCITEMDETALGOP.NRPERCITDETALFILGOP, C_PERCDETALPRODGOP.SEQ, C_PERCDETALPRODGOP.CDPRODUTO,
                                     C_PERCDETALPRODGOP.CDORCAMENTOMO, C_PERCDETALPRODGOP.CDDESPADMFAT, C_PERCDETALPRODGOP.CDTIPOOPER,
                                     C_PERCDETALPRODGOP.CDFILIALMO, C_PERCDETALPRODGOP.IDENTRSAIDOP, C_PERCDETALPRODGOP.VRPERCENTUAL,
                                     C_PERCDETALPRODGOP.CDCONTCTBL, C_PERCDETALPRODGOP.CDTPCTPAGAR, C_PERCDETALPRODGOP.CDOPERADOR);
                     END LOOP;
                  END LOOP;
               END LOOP;
            ELSE
               /* ORIGEM E DESTINO FILIAL */
               FOR C_PERCITFILGOP IN (SELECT SEQ_PERCITFILGOP.NEXTVAL SEQ, P.NRSEQITEMORCA, P.DSITEMORCAMENTO, P.VRPERCITEMGOP, P_CDOPERADOR CDOPERADOR, P.NRPERCITFILGOP
                                        FROM PERCITFILGOP P
                                       WHERE P.NRSEQITEMORCA = C_ITEM.NRITEMOPERACIONAL
                                         AND P.CDFILIAL = P_CDFILORIG) LOOP
                  INSERT INTO PERCITFILGOP (NRPERCITFILGOP, CDFILIAL, NRSEQITEMORCA, DSITEMORCAMENTO, VRPERCITEMGOP, CDOPERINCLUSAO)
                       VALUES (C_PERCITFILGOP.SEQ, C_LISTAFIL.CDLISTA, C_PERCITFILGOP.NRSEQITEMORCA, C_PERCITFILGOP.DSITEMORCAMENTO, C_PERCITFILGOP.VRPERCITEMGOP, C_PERCITFILGOP.CDOPERADOR);
                  FOR C_PERCITDETALFILGOP IN (SELECT SEQ_PERCITDETALFILGOP.NEXTVAL SEQ, PD.CDPRODUTO, PD.CDIMPOSTO, PD.CDTIPOOPER, PD.CDFILIALMO,
                                                     PD.IDENTRSAIDOP, PD.CDINVEST, PD.CDDESPADMFAT, PD.CDDESPPREV, PD.IDDESPPREV, PD.VRPERCENTUAL, 
                                                     PD.CDORCAMENTOMO, PD.CDFATUDIVER, PD.CDSERVFILI, PD.CDSUBGRPROD, PD.CDTPCTPAGAR, PD.CDCONTCTBL, PD.CDGRUPPROD, PD.DSEXPRESSAO,
                                                     P_CDOPERADOR CDOPERADOR, PD.NRPERCITDETALFILGOP
                                                FROM PERCITDETALFILGOP PD
                                               WHERE PD.NRPERCITFILGOP = C_PERCITFILGOP.NRPERCITFILGOP
                                                 AND PD.CDSERVFILI IS NULL) LOOP
                     INSERT INTO PERCITDETALFILGOP (NRPERCITFILGOP, NRPERCITDETALFILGOP, CDFILIAL, CDPRODUTO,
                                                    CDIMPOSTO, CDTIPOOPER, CDFILIALMO, IDENTRSAIDOP,
                                                    CDINVEST, CDDESPADMFAT, CDDESPPREV, IDDESPPREV,
                                                    VRPERCENTUAL, CDORCAMENTOMO, CDFATUDIVER, CDSERVFILI,
                                                    CDSUBGRPROD, CDTPCTPAGAR, CDCONTCTBL, CDGRUPPROD,
                                                    DSEXPRESSAO, CDOPERINCLUSAO)
                          VALUES (C_PERCITFILGOP.SEQ, C_PERCITDETALFILGOP.SEQ, C_LISTAFIL.CDLISTA, C_PERCITDETALFILGOP.CDPRODUTO,
                                  C_PERCITDETALFILGOP.CDIMPOSTO, C_PERCITDETALFILGOP.CDTIPOOPER, C_PERCITDETALFILGOP.CDFILIALMO, C_PERCITDETALFILGOP.IDENTRSAIDOP,
                                  C_PERCITDETALFILGOP.CDINVEST, C_PERCITDETALFILGOP.CDDESPADMFAT, C_PERCITDETALFILGOP.CDDESPPREV, C_PERCITDETALFILGOP.IDDESPPREV,
                                  C_PERCITDETALFILGOP.VRPERCENTUAL, C_PERCITDETALFILGOP.CDORCAMENTOMO, C_PERCITDETALFILGOP.CDFATUDIVER, C_PERCITDETALFILGOP.CDSERVFILI,
                                  C_PERCITDETALFILGOP.CDSUBGRPROD, C_PERCITDETALFILGOP.CDTPCTPAGAR, C_PERCITDETALFILGOP.CDCONTCTBL, C_PERCITDETALFILGOP.CDGRUPPROD,
                                  C_PERCITDETALFILGOP.DSEXPRESSAO, C_PERCITDETALFILGOP.CDOPERADOR);
                     FOR C_PERCDETPRODFILGOP IN (SELECT SEQ_PERCDETPRODFILGOP.NEXTVAL SEQ, PDP.CDPRODUTO,
                                                       PDP.CDORCAMENTOMO, PDP.CDDESPADMFAT, PDP.CDTIPOOPER,
                                                       PDP.CDFILIALMO, PDP.IDENTRSAIDOP, PDP.VRPERCENTUAL,
                                                       PDP.CDCONTCTBL, PDP.CDTPCTPAGAR, P_CDOPERADOR CDOPERADOR
                                                  FROM PERCDETPRODFILGOP PDP
                                                 WHERE PDP.NRPERCITDETALFILGOP = C_PERCITDETALFILGOP.NRPERCITDETALFILGOP) LOOP
                        INSERT INTO PERCDETPRODFILGOP (NRPERCITDETALFILGOP, NRPERCDETPRODFILGOP, CDFILIAL, CDPRODUTO,
                                                       CDORCAMENTOMO, CDDESPADMFAT, CDTIPOOPER,
                                                       CDFILIALMO, IDENTRSAIDOP, VRPERCENTUAL,
                                                       CDCONTCTBL, CDTPCTPAGAR, CDOPERINCLUSAO)
                             VALUES (C_PERCITDETALFILGOP.SEQ, C_PERCDETPRODFILGOP.SEQ, C_LISTAFIL.CDLISTA, C_PERCDETPRODFILGOP.CDPRODUTO,
                                     C_PERCDETPRODFILGOP.CDORCAMENTOMO, C_PERCDETPRODFILGOP.CDDESPADMFAT, C_PERCDETPRODFILGOP.CDTIPOOPER,
                                     C_PERCDETPRODFILGOP.CDFILIALMO, C_PERCDETPRODFILGOP.IDENTRSAIDOP, C_PERCDETPRODFILGOP.VRPERCENTUAL,
                                     C_PERCDETPRODFILGOP.CDCONTCTBL, C_PERCDETPRODFILGOP.CDTPCTPAGAR, C_PERCDETPRODFILGOP.CDOPERADOR);
                     END LOOP;
                  END LOOP;
               END LOOP;
            END IF;
            COMMIT;
         END LOOP;
      END IF;
   END LOOP;
   DELETE FROM LISTA WHERE NRLISTA = P_CDFILDEST;
END;