2015年3月27日 星期五

iDempiere 複製 Oracle EBS 報表

CREATE OR REPLACE PROCEDURE IDEMPIERE.Printformat_Copy
(
    PInstance_ID            IN NUMBER
)
AS
/*
DECLARE
  PINSTANCE_ID NUMBER;

BEGIN
  PINSTANCE_ID := 0;
  IDEMPIERE.PRINTFORMAT_COPY ( PINSTANCE_ID );
  COMMIT;
END;
*/
    --    Logistics
    ResultStr                        VARCHAR2(2000);
    Message                            VARCHAR2(2000);
    Record_ID                        NUMBER;
    IsProcessing                    CHAR(1);
    IsProcessed                        CHAR(1);
    myResult                        NUMBER := 1;    --    Success
    --    Parameter
    CURSOR Cur_Parameter (PInstance NUMBER) IS
        SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
          FROM AD_PInstance i, AD_PInstance_Para p
         WHERE i.AD_PInstance_ID=PInstance
           AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
         ORDER BY p.SeqNo;
-- DESC AD_Printformat
-- DESC AD_PrintformatItem
  --SELECT Name,AD_Printformat_ID FROM AD_Printformat WHERE Name LIKE '%Order%';
  --Order Detail    1000031
  --Order Header    118
  --Order LineTax   119
  --Order Header1000088    1000088
  --Order LineTax1000089    1000089
  --Order Detail1000090    1000090
  -- SELECT Name,AD_Printformat_ID FROM AD_PrintformatItem WHERE AD_Printformat_ID  IN(1000088,1000089,1000090)
   
     CURSOR    Cur_Head   IS
        SELECT Name,AD_Printformat_ID
          FROM AD_Printformat
         WHERE Name IN ('Order Header','Order Detail','Order LineTax');
       
     CURSOR    Cur_AD_Printformat_Trl (x_AD_Printformat_ID NUMBER)    IS
        SELECT
          AD_PRINTFORMAT_ID      ,--NUMBER(10)             DEFAULT 0                     NOT NULL,
          AD_LANGUAGE            ,--VARCHAR2(6 BYTE)       NOT NULL,
          AD_CLIENT_ID           ,--NUMBER(10)             NOT NULL,
          AD_ORG_ID              ,--NUMBER(10)             NOT NULL,
          ISACTIVE               ,--CHAR(1 BYTE)           DEFAULT 'Y'                   NOT NULL,
          CREATED                ,--DATE                   DEFAULT SYSDATE               NOT NULL,
          CREATEDBY              ,--NUMBER(10)             NOT NULL,
          UPDATED                ,--DATE                   DEFAULT SYSDATE               NOT NULL,
          UPDATEDBY              ,--NUMBER(10)             NOT NULL,
          NAME                   ,--VARCHAR2(60 BYTE)      NOT NULL,
          DESCRIPTION            ,--VARCHAR2(255 BYTE)     DEFAULT NULL,
          ISTRANSLATED           ,--CHAR(1 BYTE)           NOT NULL,
          AD_PRINTFORMAT_TRL_UU   --VARCHAR2(36 BYTE)      DEFAULT NULL
     FROM AD_Printformat_Trl
    WHERE AD_Printformat_ID=x_AD_Printformat_ID;
   
     -- DESC AD_Printformat_Trl
     CURSOR    Cur_AD_Printformat (x_AD_Printformat_ID NUMBER)    IS
        SELECT
          AD_PRINTFORMAT_ID       ,--NUMBER(10)            NOT NULL,
          AD_CLIENT_ID            ,--NUMBER(10)            NOT NULL,
          AD_ORG_ID               ,--NUMBER(10)            NOT NULL,
          ISACTIVE                ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          CREATED                 ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          CREATEDBY               ,--NUMBER(10)            NOT NULL,
          UPDATED                 ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          UPDATEDBY               ,--NUMBER(10)            NOT NULL,
          NAME                    ,--NVARCHAR2(60)         NOT NULL,
          DESCRIPTION             ,--NVARCHAR2(255),
          ISTABLEBASED            ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          ISFORM                  ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          AD_TABLE_ID             ,--NUMBER(10)            NOT NULL,
          AD_PRINTPAPER_ID        ,--NUMBER(10)            NOT NULL,
          AD_PRINTCOLOR_ID        ,--NUMBER(10)            NOT NULL,
          AD_PRINTFONT_ID         ,--NUMBER(10)            NOT NULL,
          ISSTANDARDHEADERFOOTER  ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          HEADERMARGIN            ,--NUMBER(10)            NOT NULL,
          FOOTERMARGIN            ,--NUMBER(10)            NOT NULL,
          CREATECOPY              ,--CHAR(1 BYTE),
          AD_REPORTVIEW_ID        ,--NUMBER(10),
          AD_PRINTTABLEFORMAT_ID  ,--NUMBER(10),
          PRINTERNAME             ,--NVARCHAR2(40),
          ISDEFAULT               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          JASPERPROCESS_ID        ,--NUMBER(10),
          CLASSNAME               ,--VARCHAR2(240 BYTE),
          ARGS                    ,--VARCHAR2(480 BYTE),
          AD_PRINTFORMAT_UU       ,--NVARCHAR2(36)         DEFAULT NULL,
          AD_WINDOW_ID             --NUMBER(10)            DEFAULT NULL
     FROM AD_Printformat
    WHERE AD_Printformat_ID=x_AD_Printformat_ID;

--DESC AD_PrintformatItem_Trl
     CURSOR    Cur_AD_PrintformatItem (x_AD_Printformat_ID NUMBER)    IS
        SELECT
          AD_PRINTFORMATITEM_ID   ,--NUMBER(10)            NOT NULL,
          AD_CLIENT_ID            ,--NUMBER(10)            NOT NULL,
          AD_ORG_ID               ,--NUMBER(10)            NOT NULL,
          ISACTIVE                ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          CREATED                 ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          CREATEDBY               ,--NUMBER(10)            NOT NULL,
          UPDATED                 ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          UPDATEDBY               ,--NUMBER(10)            NOT NULL,
          AD_PRINTFORMAT_ID       ,--NUMBER(10)            NOT NULL,
          NAME                    ,--NVARCHAR2(60)         NOT NULL,
          PRINTNAME               ,--NVARCHAR2(2000),
          ISPRINTED               ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          PRINTAREATYPE           ,--CHAR(1 BYTE)          NOT NULL,
          SEQNO                   ,--NUMBER(10)            NOT NULL,
          PRINTFORMATTYPE         ,--CHAR(1 BYTE)          NOT NULL,
          AD_COLUMN_ID            ,--NUMBER(10),
          AD_PRINTFORMATCHILD_ID  ,--NUMBER(10),
          ISRELATIVEPOSITION      ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          ISNEXTLINE              ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          XSPACE                  ,--NUMBER(10)            NOT NULL,
          YSPACE                  ,--NUMBER(10)            NOT NULL,
          XPOSITION               ,--NUMBER(10)            NOT NULL,
          YPOSITION               ,--NUMBER(10)            NOT NULL,
          MAXWIDTH                ,--NUMBER(10)            NOT NULL,
          ISHEIGHTONELINE         ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          MAXHEIGHT               ,--NUMBER(10)            NOT NULL,
          FIELDALIGNMENTTYPE      ,--CHAR(1 BYTE)          NOT NULL,
          LINEALIGNMENTTYPE       ,--CHAR(1 BYTE)          NOT NULL,
          AD_PRINTCOLOR_ID        ,--NUMBER(10),
          AD_PRINTFONT_ID         ,--NUMBER(10),
          ISORDERBY               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          SORTNO                  ,--NUMBER(10)            NOT NULL,
          ISGROUPBY               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISPAGEBREAK             ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISSUMMARIZED            ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          IMAGEISATTACHED         ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          IMAGEURL                ,--NVARCHAR2(120),
          ISAVERAGED              ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISCOUNTED               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISSETNLPOSITION         ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISSUPPRESSNULL          ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          BELOWCOLUMN             ,--NUMBER(10),
          AD_PRINTGRAPH_ID        ,--NUMBER(10),
          ISFIXEDWIDTH            ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISNEXTPAGE              ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          PRINTNAMESUFFIX         ,--NVARCHAR2(60),
          ISMINCALC               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISMAXCALC               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISRUNNINGTOTAL          ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          RUNNINGTOTALLINES       ,--NUMBER(10),
          ISVARIANCECALC          ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISDEVIATIONCALC         ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISFILLEDRECTANGLE       ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          LINEWIDTH               ,--NUMBER(10),
          ARCDIAMETER             ,--NUMBER(10),
          SHAPETYPE               ,--CHAR(1 BYTE),
          ISCENTRALLYMAINTAINED   ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          ISIMAGEFIELD            ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          BARCODETYPE             ,--CHAR(3 BYTE),
          FORMATPATTERN           ,--NVARCHAR2(60)         DEFAULT NULL,
          ISSUPPRESSREPEATS       ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          AD_PRINTFORMATITEM_UU   ,--NVARCHAR2(36)         DEFAULT NULL,
          ISDESC                   --CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL
     FROM AD_PrintformatItem
    WHERE AD_Printformat_ID=x_AD_Printformat_ID;
   
   
     CURSOR    Cur_AD_PrintformatItem_Trl (x_AD_PrintformatItem_ID NUMBER)    IS
        SELECT
          AD_PRINTFORMATITEM_ID      ,--NUMBER(10)         NOT NULL,
          AD_LANGUAGE                ,--VARCHAR2(6 BYTE)   NOT NULL,
          AD_CLIENT_ID               ,--NUMBER(10)         NOT NULL,
          AD_ORG_ID                  ,--NUMBER(10)         NOT NULL,
          ISACTIVE                   ,--CHAR(1 BYTE)       DEFAULT 'Y'                   NOT NULL,
          CREATED                    ,--DATE               DEFAULT SYSDATE               NOT NULL,
          CREATEDBY                  ,--NUMBER(10)         NOT NULL,
          UPDATED                    ,--DATE               DEFAULT SYSDATE               NOT NULL,
          UPDATEDBY                  ,--NUMBER(10)         NOT NULL,
          PRINTNAME                  ,--NVARCHAR2(2000),
          ISTRANSLATED               ,--CHAR(1 BYTE)       DEFAULT 'N'                   NOT NULL,
          PRINTNAMESUFFIX            ,--NVARCHAR2(60),
          AD_PRINTFORMATITEM_TRL_UU  ,--NVARCHAR2(36)      DEFAULT NULL,
          NAME                        --NVARCHAR2(60)      DEFAULT NULL                  NOT NULL
     FROM AD_PrintformatItem_Trl
    WHERE AD_PrintformatItem_ID=x_AD_PrintformatItem_ID;
   
      --
    Updated                            NUMBER := 0;
    Created                            NUMBER := 0;
    Updated_Total                    NUMBER := 0;
    Created_Total                    NUMBER := 0;
    v_H_ID                          NUMBER(10,0) := 0;
    v_H_UU                          VARCHAR2(36) := NULL;
    v_HT_ID                         NUMBER(10,0) := 0;
    v_HT_UU                         VARCHAR2(36) := NULL;
    v_I_ID                          NUMBER(10,0) := 0;
    v_I_UU                          VARCHAR2(36) := NULL;
    v_IT_ID                         NUMBER(10,0) := 0;
    v_IT_UU                         VARCHAR2(36) := NULL;
    p_AD_Printformat_ID             NUMBER(10,0) := 0;
    P_Printformat_ID                NUMBER(10,0) := 0;
BEGIN
    --  Update AD_PInstance
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || PInstance_ID);
    ResultStr := 'PInstanceNotFound';
    UPDATE AD_PInstance
       SET Created = SysDate,
           IsProcessing = 'Y'
     WHERE AD_PInstance_ID=PInstance_ID;
    COMMIT;

    DBMS_OUTPUT.PUT_LINE('ReadingParameters');
    ResultStr := 'ReadingParameters';
    FOR p IN Cur_Parameter (PInstance_ID) LOOP
        Record_ID := p.Record_ID;
    /* IF (p.ParameterName = 'C_BP_Group_ID') THEN
             C_BP_Group_ID := p.P_Number;
            DBMS_OUTPUT.PUT_LINE('  C_BP_Group_ID=' || C_BP_Group_ID);
        ELSE
            DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || p.ParameterName);
         END IF;
   */
    END LOOP;    --    Get Parameter
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || Record_ID);

  --SELECT Name,AD_Printformat_ID FROM AD_Printformat WHERE Name LIKE '%Order%';
  --Order Detail    1000031
  --Order Header    118
  --Order LineTax   119
 
    p_AD_Printformat_ID := 0;
    /**
     *    For all Accounting Schema of the Group
     */
    DBMS_OUTPUT.PUT_LINE('Cur_Head');
    FOR p IN Cur_Head LOOP

    DBMS_OUTPUT.PUT_LINE('Cur_AD_Printformat');
    FOR a IN Cur_AD_Printformat (p.AD_Printformat_ID) LOOP
         
        --  SELECT * FROM AD_Sequence WHERE NAME='AD_PrintFormat'        --579
        --  SELECT * FROM AD_Sequence WHERE NAME='AD_PrintFormat_Trl'    --200177
        --  SELECT * FROM AD_Sequence WHERE NAME='AD_PrintFormatItem'    --575
        --  SELECT * FROM AD_Sequence WHERE NAME='AD_PrintFormatItem_Trl'--618
       
          SELECT generate_uuid                           INTO v_H_UU FROM DUAL;
          SELECT NEXTIDFUNCBYNAME('AD_PrintFormat', 'N') INTO v_H_ID FROM DUAL;
         
          DBMS_OUTPUT.PUT_LINE('Cur_AD_Printformat v_H_ID='||v_H_ID||' ,v_H_UU='||v_H_UU);
         
          INSERT INTO AD_Printformat(
          AD_PRINTFORMAT_ID       ,--NUMBER(10)            NOT NULL,
          AD_CLIENT_ID            ,--NUMBER(10)            NOT NULL,
          AD_ORG_ID               ,--NUMBER(10)            NOT NULL,
          ISACTIVE                ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          CREATED                 ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          CREATEDBY               ,--NUMBER(10)            NOT NULL,
          UPDATED                 ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          UPDATEDBY               ,--NUMBER(10)            NOT NULL,
          NAME                    ,--NVARCHAR2(60)         NOT NULL,
          DESCRIPTION             ,--NVARCHAR2(255),
          ISTABLEBASED            ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          ISFORM                  ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          AD_TABLE_ID             ,--NUMBER(10)            NOT NULL,
          AD_PRINTPAPER_ID        ,--NUMBER(10)            NOT NULL,
          AD_PRINTCOLOR_ID        ,--NUMBER(10)            NOT NULL,
          AD_PRINTFONT_ID         ,--NUMBER(10)            NOT NULL,
          ISSTANDARDHEADERFOOTER  ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          HEADERMARGIN            ,--NUMBER(10)            NOT NULL,
          FOOTERMARGIN            ,--NUMBER(10)            NOT NULL,
          CREATECOPY              ,--CHAR(1 BYTE),
          AD_REPORTVIEW_ID        ,--NUMBER(10),
          AD_PRINTTABLEFORMAT_ID  ,--NUMBER(10),
          PRINTERNAME             ,--NVARCHAR2(40),
          ISDEFAULT               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          JASPERPROCESS_ID        ,--NUMBER(10),
          CLASSNAME               ,--VARCHAR2(240 BYTE),
          ARGS                    ,--VARCHAR2(480 BYTE),
          AD_PRINTFORMAT_UU       ,--NVARCHAR2(36)         DEFAULT NULL,
          AD_WINDOW_ID             --NUMBER(10)            DEFAULT NULL
          )VALUES(
          v_H_ID,--a.AD_PRINTFORMAT_ID       ,--NUMBER(10)            NOT NULL,
          a.AD_CLIENT_ID            ,--NUMBER(10)            NOT NULL,
          a.AD_ORG_ID               ,--NUMBER(10)            NOT NULL,
          a.ISACTIVE                ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          SYSDATE,--a.CREATED       ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          a.CREATEDBY               ,--NUMBER(10)            NOT NULL,
          SYSDATE,--a.UPDATED       ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          a.UPDATEDBY               ,--NUMBER(10)            NOT NULL,
          a.NAME||v_H_ID            ,--NVARCHAR2(60)         NOT NULL,
          a.DESCRIPTION             ,--NVARCHAR2(255),
          a.ISTABLEBASED            ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          a.ISFORM                  ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          a.AD_TABLE_ID             ,--NUMBER(10)            NOT NULL,
          a.AD_PRINTPAPER_ID        ,--NUMBER(10)            NOT NULL,
          a.AD_PRINTCOLOR_ID        ,--NUMBER(10)            NOT NULL,
          a.AD_PRINTFONT_ID         ,--NUMBER(10)            NOT NULL,
          a.ISSTANDARDHEADERFOOTER  ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          a.HEADERMARGIN            ,--NUMBER(10)            NOT NULL,
          a.FOOTERMARGIN            ,--NUMBER(10)            NOT NULL,
          a.CREATECOPY              ,--CHAR(1 BYTE),
          a.AD_REPORTVIEW_ID        ,--NUMBER(10),
          a.AD_PRINTTABLEFORMAT_ID  ,--NUMBER(10),
          a.PRINTERNAME             ,--NVARCHAR2(40),
          a.ISDEFAULT               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          a.JASPERPROCESS_ID        ,--NUMBER(10),
          a.CLASSNAME               ,--VARCHAR2(240 BYTE),
          a.ARGS                    ,--VARCHAR2(480 BYTE),
          v_H_UU,--a.AD_PRINTFORMAT_UU       ,--NVARCHAR2(36)         DEFAULT NULL,
          a.AD_WINDOW_ID             --NUMBER(10)            DEFAULT NULL
          );
         
       DBMS_OUTPUT.PUT_LINE('Cur_AD_Printformat_Trl');
       FOR b IN Cur_AD_Printformat_Trl (a.AD_Printformat_ID) LOOP
      
          SELECT generate_uuid                               INTO v_HT_UU FROM DUAL;
          SELECT NEXTIDFUNCBYNAME('AD_PrintFormat_Trl', 'N') INTO v_HT_ID FROM DUAL;
         
          --ALTER TABLE AD_Printformat_Trl ADD AD_PRINTFORMAT_TRL_ID NUMBER(10);
         
          INSERT INTO AD_Printformat_Trl(
          AD_PRINTFORMAT_TRL_ID  ,--NUMBER(10)
          AD_PRINTFORMAT_ID      ,--NUMBER(10)             DEFAULT 0                     NOT NULL,
          AD_LANGUAGE            ,--VARCHAR2(6 BYTE)       NOT NULL,
          AD_CLIENT_ID           ,--NUMBER(10)             NOT NULL,
          AD_ORG_ID              ,--NUMBER(10)             NOT NULL,
          ISACTIVE               ,--CHAR(1 BYTE)           DEFAULT 'Y'                   NOT NULL,
          CREATED                ,--DATE                   DEFAULT SYSDATE               NOT NULL,
          CREATEDBY              ,--NUMBER(10)             NOT NULL,
          UPDATED                ,--DATE                   DEFAULT SYSDATE               NOT NULL,
          UPDATEDBY              ,--NUMBER(10)             NOT NULL,
          NAME                   ,--VARCHAR2(60 BYTE)      NOT NULL,
          DESCRIPTION            ,--VARCHAR2(255 BYTE)     DEFAULT NULL,
          ISTRANSLATED           ,--CHAR(1 BYTE)           NOT NULL,
          AD_PRINTFORMAT_TRL_UU   --VARCHAR
          )VALUES(
          v_HT_ID, --b.AD_PRINTFORMAT_TRL_ID      ,--NUMBER(10
          v_H_ID,  --b.AD_PRINTFORMAT_ID          ,--NUMBER(10)             DEFAULT 0                     NOT NULL,
          b.AD_LANGUAGE            ,--VARCHAR2(6 BYTE)       NOT NULL,
          b.AD_CLIENT_ID           ,--NUMBER(10)             NOT NULL,
          b.AD_ORG_ID              ,--NUMBER(10)             NOT NULL,
          b.ISACTIVE               ,--CHAR(1 BYTE)           DEFAULT 'Y'                   NOT NULL,
          SYSDATE,--b.CREATED                ,--DATE                   DEFAULT SYSDATE               NOT NULL,
          b.CREATEDBY              ,--NUMBER(10)             NOT NULL,
          SYSDATE,--b.UPDATED                ,--DATE                   DEFAULT SYSDATE               NOT NULL,
          b.UPDATEDBY              ,--NUMBER(10)             NOT NULL,
          b.NAME                   ,--VARCHAR2(60 BYTE)      NOT NULL,
          b.DESCRIPTION            ,--VARCHAR2(255 BYTE)     DEFAULT NULL,
          b.ISTRANSLATED           ,--CHAR(1 BYTE)           NOT NULL,
          v_HT_UU --b.AD_PRINTFORMAT_TRL_UU   --VARCHAR
          );
       END LOOP;
      
       DBMS_OUTPUT.PUT_LINE('Cur_AD_PrintformatItem');
       FOR c IN Cur_AD_PrintformatItem (a.AD_Printformat_ID) LOOP

          SELECT generate_uuid                               INTO v_I_UU FROM DUAL;
          SELECT NEXTIDFUNCBYNAME('AD_PrintFormatItem', 'N') INTO v_I_ID FROM DUAL;
         
          INSERT INTO AD_PrintformatItem(
          AD_PRINTFORMATITEM_ID   ,--NUMBER(10)            NOT NULL,
          AD_CLIENT_ID            ,--NUMBER(10)            NOT NULL,
          AD_ORG_ID               ,--NUMBER(10)            NOT NULL,
          ISACTIVE                ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          CREATED                 ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          CREATEDBY               ,--NUMBER(10)            NOT NULL,
          UPDATED                 ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          UPDATEDBY               ,--NUMBER(10)            NOT NULL,
          AD_PRINTFORMAT_ID       ,--NUMBER(10)            NOT NULL,
          NAME                    ,--NVARCHAR2(60)         NOT NULL,
          PRINTNAME               ,--NVARCHAR2(2000),
          ISPRINTED               ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          PRINTAREATYPE           ,--CHAR(1 BYTE)          NOT NULL,
          SEQNO                   ,--NUMBER(10)            NOT NULL,
          PRINTFORMATTYPE         ,--CHAR(1 BYTE)          NOT NULL,
          AD_COLUMN_ID            ,--NUMBER(10),
          AD_PRINTFORMATCHILD_ID  ,--NUMBER(10),
          ISRELATIVEPOSITION      ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          ISNEXTLINE              ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          XSPACE                  ,--NUMBER(10)            NOT NULL,
          YSPACE                  ,--NUMBER(10)            NOT NULL,
          XPOSITION               ,--NUMBER(10)            NOT NULL,
          YPOSITION               ,--NUMBER(10)            NOT NULL,
          MAXWIDTH                ,--NUMBER(10)            NOT NULL,
          ISHEIGHTONELINE         ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          MAXHEIGHT               ,--NUMBER(10)            NOT NULL,
          FIELDALIGNMENTTYPE      ,--CHAR(1 BYTE)          NOT NULL,
          LINEALIGNMENTTYPE       ,--CHAR(1 BYTE)          NOT NULL,
          AD_PRINTCOLOR_ID        ,--NUMBER(10),
          AD_PRINTFONT_ID         ,--NUMBER(10),
          ISORDERBY               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          SORTNO                  ,--NUMBER(10)            NOT NULL,
          ISGROUPBY               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISPAGEBREAK             ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISSUMMARIZED            ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          IMAGEISATTACHED         ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          IMAGEURL                ,--NVARCHAR2(120),
          ISAVERAGED              ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISCOUNTED               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISSETNLPOSITION         ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISSUPPRESSNULL          ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          BELOWCOLUMN             ,--NUMBER(10),
          AD_PRINTGRAPH_ID        ,--NUMBER(10),
          ISFIXEDWIDTH            ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISNEXTPAGE              ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          PRINTNAMESUFFIX         ,--NVARCHAR2(60),
          ISMINCALC               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISMAXCALC               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISRUNNINGTOTAL          ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          RUNNINGTOTALLINES       ,--NUMBER(10),
          ISVARIANCECALC          ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISDEVIATIONCALC         ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          ISFILLEDRECTANGLE       ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          LINEWIDTH               ,--NUMBER(10),
          ARCDIAMETER             ,--NUMBER(10),
          SHAPETYPE               ,--CHAR(1 BYTE),
          ISCENTRALLYMAINTAINED   ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          ISIMAGEFIELD            ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          BARCODETYPE             ,--CHAR(3 BYTE),
          FORMATPATTERN           ,--NVARCHAR2(60)         DEFAULT NULL,
          ISSUPPRESSREPEATS       ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          AD_PRINTFORMATITEM_UU   ,--NVARCHAR2(36)         DEFAULT NULL,
          ISDESC                   --CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL
          )VALUES(
          v_I_ID, --c.AD_PRINTFORMATITEM_ID   ,--NUMBER(10)            NOT NULL,
          c.AD_CLIENT_ID            ,--NUMBER(10)            NOT NULL,
          c.AD_ORG_ID               ,--NUMBER(10)            NOT NULL,
          c.ISACTIVE                ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          SYSDATE, --c.CREATED      ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          c.CREATEDBY               ,--NUMBER(10)            NOT NULL,
          SYSDATE, --c.UPDATED      ,--DATE                  DEFAULT SYSDATE               NOT NULL,
          c.UPDATEDBY               ,--NUMBER(10)            NOT NULL,
          v_H_ID, --c.AD_PRINTFORMAT_ID       ,--NUMBER(10)            NOT NULL,
          c.NAME                    ,--NVARCHAR2(60)         NOT NULL,
          c.PRINTNAME               ,--NVARCHAR2(2000),
          c.ISPRINTED               ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          c.PRINTAREATYPE           ,--CHAR(1 BYTE)          NOT NULL,
          c.SEQNO                   ,--NUMBER(10)            NOT NULL,
          c.PRINTFORMATTYPE         ,--CHAR(1 BYTE)          NOT NULL,
          c.AD_COLUMN_ID            ,--NUMBER(10),
          c.AD_PRINTFORMATCHILD_ID  ,--NUMBER(10),
          c.ISRELATIVEPOSITION      ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          c.ISNEXTLINE              ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          c.XSPACE                  ,--NUMBER(10)            NOT NULL,
          c.YSPACE                  ,--NUMBER(10)            NOT NULL,
          c.XPOSITION               ,--NUMBER(10)            NOT NULL,
          c.YPOSITION               ,--NUMBER(10)            NOT NULL,
          c.MAXWIDTH                ,--NUMBER(10)            NOT NULL,
          c.ISHEIGHTONELINE         ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          c.MAXHEIGHT               ,--NUMBER(10)            NOT NULL,
          c.FIELDALIGNMENTTYPE      ,--CHAR(1 BYTE)          NOT NULL,
          c.LINEALIGNMENTTYPE       ,--CHAR(1 BYTE)          NOT NULL,
          c.AD_PRINTCOLOR_ID        ,--NUMBER(10),
          c.AD_PRINTFONT_ID         ,--NUMBER(10),
          c.ISORDERBY               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.SORTNO                  ,--NUMBER(10)            NOT NULL,
          c.ISGROUPBY               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISPAGEBREAK             ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISSUMMARIZED            ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.IMAGEISATTACHED         ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.IMAGEURL                ,--NVARCHAR2(120),
          c.ISAVERAGED              ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISCOUNTED               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISSETNLPOSITION         ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISSUPPRESSNULL          ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.BELOWCOLUMN             ,--NUMBER(10),
          c.AD_PRINTGRAPH_ID        ,--NUMBER(10),
          c.ISFIXEDWIDTH            ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISNEXTPAGE              ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.PRINTNAMESUFFIX         ,--NVARCHAR2(60),
          c.ISMINCALC               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISMAXCALC               ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISRUNNINGTOTAL          ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.RUNNINGTOTALLINES       ,--NUMBER(10),
          c.ISVARIANCECALC          ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISDEVIATIONCALC         ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.ISFILLEDRECTANGLE       ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.LINEWIDTH               ,--NUMBER(10),
          c.ARCDIAMETER             ,--NUMBER(10),
          c.SHAPETYPE               ,--CHAR(1 BYTE),
          c.ISCENTRALLYMAINTAINED   ,--CHAR(1 BYTE)          DEFAULT 'Y'                   NOT NULL,
          c.ISIMAGEFIELD            ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          c.BARCODETYPE             ,--CHAR(3 BYTE),
          c.FORMATPATTERN           ,--NVARCHAR2(60)         DEFAULT NULL,
          c.ISSUPPRESSREPEATS       ,--CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL,
          v_I_UU, --c.AD_PRINTFORMATITEM_UU   ,--NVARCHAR2(36)         DEFAULT NULL,
          c.ISDESC                   --CHAR(1 BYTE)          DEFAULT 'N'                   NOT NULL
          );

          DBMS_OUTPUT.PUT_LINE('Cur_AD_PrintformatItem_Trl');
          FOR d IN Cur_AD_PrintformatItem_Trl (c.AD_PrintformatItem_ID) LOOP
         
          SELECT generate_uuid                                   INTO v_IT_UU FROM DUAL;
          SELECT NEXTIDFUNCBYNAME('AD_PrintFormatItem_Trl', 'N') INTO v_IT_ID FROM DUAL;
         
          --ALTER TABLE AD_PrintformatItem_Trl ADD AD_PRINTFORMATITEM_TRL_ID   NUMBER(10)
          INSERT INTO AD_PrintformatItem_Trl(
          AD_PRINTFORMATITEM_TRL_ID  ,--NUMBER(10),
          AD_PRINTFORMATITEM_ID      ,--NUMBER(10)         NOT NULL,
          AD_LANGUAGE                ,--VARCHAR2(6 BYTE)   NOT NULL,
          AD_CLIENT_ID               ,--NUMBER(10)         NOT NULL,
          AD_ORG_ID                  ,--NUMBER(10)         NOT NULL,
          ISACTIVE                   ,--CHAR(1 BYTE)       DEFAULT 'Y'                   NOT NULL,
          CREATED                    ,--DATE               DEFAULT SYSDATE               NOT NULL,
          CREATEDBY                  ,--NUMBER(10)         NOT NULL,
          UPDATED                    ,--DATE               DEFAULT SYSDATE               NOT NULL,
          UPDATEDBY                  ,--NUMBER(10)         NOT NULL,
          PRINTNAME                  ,--NVARCHAR2(2000),
          ISTRANSLATED               ,--CHAR(1 BYTE)       DEFAULT 'N'                   NOT NULL,
          PRINTNAMESUFFIX            ,--NVARCHAR2(60),
          AD_PRINTFORMATITEM_TRL_UU  ,--NVARCHAR2(36)      DEFAULT NULL,
          NAME                        --NVARCHAR2(60)      DEFAULT NULL                  NOT NULL
          )VALUES(
          v_IT_ID, --d.AD_PRINTFORMATITEM_TRL_ID      ,--NUMBER(10)         NOT NULL,
          v_I_ID,  --d.AD_PRINTFORMATITEM_ID          ,--NUMBER(10)         NOT NULL,
          d.AD_LANGUAGE                ,--VARCHAR2(6 BYTE)   NOT NULL,
          d.AD_CLIENT_ID               ,--NUMBER(10)         NOT NULL,
          d.AD_ORG_ID                  ,--NUMBER(10)         NOT NULL,
          d.ISACTIVE                   ,--CHAR(1 BYTE)       DEFAULT 'Y'                   NOT NULL,
          SYSDATE, --d.CREATED         ,--DATE               DEFAULT SYSDATE               NOT NULL,
          d.CREATEDBY                  ,--NUMBER(10)         NOT NULL,
          SYSDATE, --d.UPDATED         ,--DATE               DEFAULT SYSDATE               NOT NULL,
          d.UPDATEDBY                  ,--NUMBER(10)         NOT NULL,
          d.PRINTNAME                  ,--NVARCHAR2(2000),
          d.ISTRANSLATED               ,--CHAR(1 BYTE)       DEFAULT 'N'                   NOT NULL,
          d.PRINTNAMESUFFIX            ,--NVARCHAR2(60),
          v_IT_UU, --d.AD_PRINTFORMATITEM_TRL_UU  ,--NVARCHAR2(36)      DEFAULT NULL,
          d.NAME                        --NVARCHAR2(60)      DEFAULT NULL                  NOT NULL
          );
          END LOOP;
       END LOOP;
   
    END LOOP; --PrintFormat
    END LOOP; --Parameter
       
    --    Created := SQL%ROWCOUNT;
    --    DBMS_OUTPUT.PUT_LINE('Customers = ' || Updated || ' / ' || Created);
    Message := '@Created@=' || Created_Total || ':2, @Updated@=' || Updated_Total || ':2';


<<FINISH_PROCESS>>
    --  Update AD_PInstance
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished - ' || Message);
    UPDATE  AD_PInstance
    SET Updated = SysDate,
        IsProcessing = 'N',
        Result = myResult,                 -- 1=Success
        ErrorMsg = Message
    WHERE   AD_PInstance_ID=PInstance_ID;
    COMMIT;
    RETURN;

EXCEPTION
    WHEN  OTHERS THEN
        ResultStr := ResultStr || ': ' || SQLERRM || ' - ' || Message;
        DBMS_OUTPUT.PUT_LINE(ResultStr);
        UPDATE  AD_PInstance
        SET Updated = SysDate,
            IsProcessing = 'N',
            Result = 0,             -- failure
            ErrorMsg = ResultStr
        WHERE   AD_PInstance_ID=PInstance_ID;
        COMMIT;
        RETURN;

END Printformat_Copy;
/