database/model/functions/AD_SYNCHRONIZE.xml
author Carlos Romero <carlos.romero@openbravo.com>
Tue, 06 Nov 2007 08:33:31 +0000
changeset 0 0247c26f10c6
child 94 4e7ba7b8a4ad
permissions -rw-r--r--
Modified PostgreSQL post script in order to include C_DEBT_PAYMENT_GENERATE modification tules
carlos@0
     1
<?xml version="1.0"?>
carlos@0
     2
<database name="FUNCTION AD_SYNCHRONIZE">
carlos@0
     3
<function name="AD_SYNCHRONIZE">
carlos@0
     4
<parameter name="p_PInstance_ID" type="NUMERIC" mode="in"/>
carlos@0
     5
<body><![CDATA[
carlos@0
     6
  /*************************************************************************
carlos@0
     7
  * The contents of this file are subject to the Compiere License
carlos@0
     8
  * Version 2.5.0 ("License"); You may not use this file except in
carlos@0
     9
  * compliance with the License. You may obtain a copy of the License at
carlos@0
    10
  * http://www.compiere.org/license.html
carlos@0
    11
  * Software distributed under the License is distributed on an
carlos@0
    12
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
carlos@0
    13
  * implied. See the License for the specific language governing rights
carlos@0
    14
  * and limitations under the License.
carlos@0
    15
  * The Original Code is  Compiere  ERP &  Business Solution
carlos@0
    16
  * The Initial Developer of the Original Code is Jorg Janke  and ComPiere,
carlos@0
    17
  Inc.
carlos@0
    18
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
carlos@0
    19
  * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
carlos@0
    20
  * All Rights Reserved.
carlos@0
    21
  * Contributor(s): Openbravo SL
carlos@0
    22
  * Contributions are Copyright ? 1999-2005 Openbravo, S.L
carlos@0
    23
  *************************************************************************
carlos@0
    24
  * $Id: AD_Syncronize.sql,v 1.12 2003/07/26 04:29:44 jjanke Exp $
carlos@0
    25
  ***
carlos@0
    26
  * Title: Syncronize Application Dictionary
carlos@0
    27
  * Description:
carlos@0
    28
  *  Synchronize Elements
carlos@0
    29
  *  Update Column and Field with Names from Element and Process
carlos@0
    30
  *  Update Process Parameters from Elements
carlos@0
    31
  *  Update Workflow Notes from Windows
carlos@0
    32
  *  Update Menu from Window/Form/Process/Task
carlos@0
    33
  ************************************************************************/
carlos@0
    34
  -- Logistice
carlos@0
    35
  v_ResultStr VARCHAR2(2000):='';
carlos@0
    36
  v_Message VARCHAR2(2000):='';
carlos@0
    37
  v_Result NUMBER:=1; -- 0=failure
carlos@0
    38
  v_Record_ID NUMBER;
carlos@0
    39
  v_AD_User_ID NUMBER;
carlos@0
    40
  -- Parameter
carlos@0
    41
  TYPE RECORD IS REF CURSOR;
carlos@0
    42
    Cur_Parameter RECORD;
carlos@0
    43
    -- Parameter Variables
carlos@0
    44
    v_rowcount NUMBER;
carlos@0
    45
  BEGIN
carlos@0
    46
    IF(p_PInstance_ID IS NOT NULL) THEN
carlos@0
    47
      --  Update AD_PInstance
carlos@0
    48
      DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
carlos@0
    49
      v_ResultStr:='PInstanceNotFound';
carlos@0
    50
      Ad_Update_Pinstance(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    51
      -- Get Parameters
carlos@0
    52
      v_ResultStr:='ReadingParameters';
carlos@0
    53
      FOR Cur_Parameter IN
carlos@0
    54
        (SELECT i.Record_ID, i.AD_User_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
carlos@0
    55
        FROM AD_PINSTANCE i
carlos@0
    56
        LEFT JOIN AD_PINSTANCE_PARA p
carlos@0
    57
          ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    58
        WHERE i.AD_PInstance_ID=p_PInstance_ID
carlos@0
    59
        ORDER BY p.SeqNo
carlos@0
    60
        )
carlos@0
    61
      LOOP
carlos@0
    62
        v_Record_ID:=Cur_Parameter.Record_ID;
carlos@0
    63
        v_AD_User_ID:=Cur_Parameter.AD_User_ID;
carlos@0
    64
      END LOOP; -- Get Parameter
carlos@0
    65
      DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
carlos@0
    66
    END IF;
carlos@0
    67
  BEGIN --BODY
carlos@0
    68
    ---------------------------------------------------------------------------
carlos@0
    69
    DBMS_OUTPUT.PUT_LINE('Adding missing Elements') ;
carlos@0
    70
    DECLARE
carlos@0
    71
      NextNo NUMBER;
carlos@0
    72
      Cur_Column RECORD;
carlos@0
    73
      Cur_Process RECORD;
carlos@0
    74
    BEGIN
carlos@0
    75
      DBMS_OUTPUT.PUT_LINE('Column:') ;
carlos@0
    76
      FOR Cur_Column IN
carlos@0
    77
        (SELECT DISTINCT ColumnName, NAME, Description, Help
carlos@0
    78
        FROM AD_COLUMN c
carlos@0
    79
        WHERE AD_Element_ID IS NULL  AND NOT EXISTS
carlos@0
    80
          (SELECT * FROM AD_ELEMENT e  WHERE UPPER(c.ColumnName)=UPPER(e.ColumnName))
carlos@0
    81
        )
carlos@0
    82
      LOOP
carlos@0
    83
        Ad_Sequence_Next('AD_Element', 0, NextNo) ; -- get ID
carlos@0
    84
        INSERT
carlos@0
    85
        INTO AD_ELEMENT
carlos@0
    86
          (
carlos@0
    87
            AD_ELEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
carlos@0
    88
            CREATED, CREATEDBY, UPDATED, UPDATEDBY,
carlos@0
    89
            ColumnName, NAME, PrintName, Description,
carlos@0
    90
            Help
carlos@0
    91
          )
carlos@0
    92
          VALUES
carlos@0
    93
          (NextNo, 0, 0, 'Y',
carlos@0
    94
          Now(), 0, Now(), 0,
carlos@0
    95
          Cur_Column.ColumnName, Cur_Column.NAME, Cur_Column.NAME, Cur_Column.Description,
carlos@0
    96
          Cur_Column.Help) ;
carlos@0
    97
        DBMS_OUTPUT.PUT_LINE('  added ' || Cur_Column.ColumnName) ;
carlos@0
    98
        COMMIT;
carlos@0
    99
      END LOOP;
carlos@0
   100
      DBMS_OUTPUT.PUT_LINE('Parameter:') ;
carlos@0
   101
      FOR Cur_Process IN
carlos@0
   102
        (SELECT DISTINCT ColumnName, NAME, Description, Help
carlos@0
   103
      FROM AD_PROCESS_PARA p
carlos@0
   104
      WHERE AD_Element_ID IS NULL  AND NOT EXISTS
carlos@0
   105
        (SELECT * FROM AD_ELEMENT e  WHERE UPPER(p.ColumnName)=UPPER(e.ColumnName))
carlos@0
   106
        )
carlos@0
   107
      LOOP
carlos@0
   108
        Ad_Sequence_Next('AD_Element', 0, NextNo) ; -- get ID
carlos@0
   109
        INSERT
carlos@0
   110
        INTO AD_ELEMENT
carlos@0
   111
          (
carlos@0
   112
            AD_ELEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
carlos@0
   113
            CREATED, CREATEDBY, UPDATED, UPDATEDBY,
carlos@0
   114
            ColumnName, NAME, PrintName, Description,
carlos@0
   115
            Help
carlos@0
   116
          )
carlos@0
   117
          VALUES
carlos@0
   118
          (NextNo, 0, 0, 'Y',
carlos@0
   119
          Now(), 0, Now(), 0,
carlos@0
   120
          Cur_Process.ColumnName, Cur_Process.NAME, Cur_Process.NAME, Cur_Process.Description,
carlos@0
   121
          Cur_Process.Help) ;
carlos@0
   122
        DBMS_OUTPUT.PUT_LINE('  added ' || Cur_Process.ColumnName) ;
carlos@0
   123
        COMMIT;
carlos@0
   124
      END LOOP;
carlos@0
   125
    END;
carlos@0
   126
    DBMS_OUTPUT.PUT_LINE('Adding missing Element Translations') ;
carlos@0
   127
    INSERT
carlos@0
   128
    INTO AD_ELEMENT_TRL
carlos@0
   129
      (
carlos@0
   130
        AD_Element_ID, AD_LANGUAGE, AD_Client_ID, AD_Org_ID,
carlos@0
   131
        IsActive, Created, CreatedBy, Updated,
carlos@0
   132
        UpdatedBy, NAME, PrintName, Description,
carlos@0
   133
        Help, IsTranslated
carlos@0
   134
      )
carlos@0
   135
    SELECT m.AD_Element_ID, l.AD_LANGUAGE, m.AD_Client_ID, m.AD_Org_ID, m.IsActive, m.Created, m.CreatedBy, m.Updated, m.UpdatedBy, m.NAME, m.PrintName, m.Description, m.Help, 'N'
carlos@0
   136
    FROM AD_ELEMENT m, AD_LANGUAGE l
carlos@0
   137
    WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y'  AND AD_Element_ID || AD_LANGUAGE NOT IN
carlos@0
   138
      (SELECT AD_Element_ID || AD_LANGUAGE FROM AD_ELEMENT_TRL)
carlos@0
   139
      ;
carlos@0
   140
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   141
    DBMS_OUTPUT.PUT_LINE('  rows added: ' || v_rowcount) ;
carlos@0
   142
    DBMS_OUTPUT.PUT_LINE('Deleting unused Elements') ;
carlos@0
   143
    DELETE
carlos@0
   144
    FROM AD_ELEMENT_TRL
carlos@0
   145
    WHERE AD_Element_ID IN
carlos@0
   146
      (SELECT AD_Element_ID
carlos@0
   147
      FROM AD_ELEMENT e
carlos@0
   148
      WHERE NOT EXISTS
carlos@0
   149
        (SELECT *
carlos@0
   150
        FROM AD_COLUMN c
carlos@0
   151
        WHERE UPPER(e.ColumnName)=UPPER(c.ColumnName) OR e.AD_Element_ID=c.AD_Element_ID
carlos@0
   152
        )
carlos@0
   153
        AND NOT EXISTS
carlos@0
   154
        (SELECT *
carlos@0
   155
        FROM AD_PROCESS_PARA p
carlos@0
   156
        WHERE UPPER(e.ColumnName)=UPPER(p.ColumnName) OR e.AD_Element_ID=p.AD_Element_ID
carlos@0
   157
        )
carlos@0
   158
      )
carlos@0
   159
      ;
carlos@0
   160
    DELETE
carlos@0
   161
    FROM AD_ELEMENT
carlos@0
   162
    WHERE NOT EXISTS
carlos@0
   163
      (SELECT *
carlos@0
   164
      FROM AD_COLUMN c
carlos@0
   165
      WHERE UPPER(AD_ELEMENT.ColumnName)=UPPER(c.ColumnName) OR AD_ELEMENT.AD_Element_ID=c.AD_Element_ID
carlos@0
   166
      )
carlos@0
   167
      AND NOT EXISTS
carlos@0
   168
      (SELECT *
carlos@0
   169
      FROM AD_PROCESS_PARA p
carlos@0
   170
      WHERE UPPER(AD_ELEMENT.ColumnName)=UPPER(p.ColumnName) OR AD_ELEMENT.AD_Element_ID=p.AD_Element_ID
carlos@0
   171
      )
carlos@0
   172
      ;
carlos@0
   173
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   174
    DBMS_OUTPUT.PUT_LINE('  rows deleted: ' || v_rowcount) ;
carlos@0
   175
    DBMS_OUTPUT.PUT_LINE('Creating link from Element to Column') ;
carlos@0
   176
    UPDATE AD_COLUMN
carlos@0
   177
      SET AD_Element_id=
carlos@0
   178
      (SELECT MAX(AD_Element_ID)
carlos@0
   179
      FROM AD_ELEMENT e
carlos@0
   180
      WHERE UPPER(AD_COLUMN.ColumnName)=UPPER(e.ColumnName)
carlos@0
   181
      )
carlos@0
   182
    WHERE AD_Element_ID IS NULL;
carlos@0
   183
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   184
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   185
    DBMS_OUTPUT.PUT_LINE('Creating link from Element to Process Para') ;
carlos@0
   186
    UPDATE AD_PROCESS_PARA
carlos@0
   187
      SET AD_Element_id=
carlos@0
   188
      (SELECT MAX(AD_Element_ID)
carlos@0
   189
      FROM AD_ELEMENT e
carlos@0
   190
      WHERE UPPER(AD_PROCESS_PARA.ColumnName)=UPPER(e.ColumnName)
carlos@0
   191
      )
carlos@0
   192
    WHERE AD_Element_ID IS NULL;
carlos@0
   193
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   194
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   195
    COMMIT;
carlos@0
   196
    ---------------------------------------------------------------------------
carlos@0
   197
    -- Columns
carlos@0
   198
    DBMS_OUTPUT.PUT_LINE('Synchronize Column') ;
carlos@0
   199
    UPDATE AD_COLUMN
carlos@0
   200
      SET --ColumnName = (SELECT ColumnName FROM AD_Element e WHERE AD_Column.AD_Element_ID=e.AD_Element_ID),
carlos@0
   201
      NAME=
carlos@0
   202
      (SELECT NAME FROM AD_ELEMENT e WHERE AD_COLUMN.AD_Element_ID=e.AD_Element_ID)
carlos@0
   203
      , Description=
carlos@0
   204
      (SELECT Description
carlos@0
   205
      FROM AD_ELEMENT e
carlos@0
   206
      WHERE AD_COLUMN.AD_Element_ID=e.AD_Element_ID
carlos@0
   207
      )
carlos@0
   208
      , Help=
carlos@0
   209
      (SELECT Help FROM AD_ELEMENT e WHERE AD_COLUMN.AD_Element_ID=e.AD_Element_ID)
carlos@0
   210
      , Updated=Now()
carlos@0
   211
    WHERE EXISTS
carlos@0
   212
      (SELECT *
carlos@0
   213
      FROM AD_ELEMENT e
carlos@0
   214
      WHERE AD_COLUMN.AD_Element_ID=e.AD_Element_ID  AND(--AD_Column.ColumnName <> e.ColumnName OR
carlos@0
   215
        AD_COLUMN.NAME<>e.NAME  OR COALESCE(TO_CHAR(AD_COLUMN.Description), ' ')<>COALESCE(TO_CHAR(e.Description), ' ')
carlos@0
   216
        OR COALESCE(TO_CHAR(AD_COLUMN.Help), ' ')<>COALESCE(TO_CHAR(e.Help), ' '))
carlos@0
   217
      )
carlos@0
   218
      ;
carlos@0
   219
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   220
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   221
    -- Fields should now be syncronized
carlos@0
   222
    DBMS_OUTPUT.PUT_LINE('Synchronize Field') ;
carlos@0
   223
    UPDATE AD_FIELD
carlos@0
   224
      SET NAME=
carlos@0
   225
      (SELECT e.NAME
carlos@0
   226
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   227
      WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=AD_FIELD.AD_Column_ID
carlos@0
   228
      )
carlos@0
   229
      , Description=
carlos@0
   230
      (SELECT e.Description
carlos@0
   231
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   232
      WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=AD_FIELD.AD_Column_ID
carlos@0
   233
      )
carlos@0
   234
      , Help=
carlos@0
   235
      (SELECT e.Help
carlos@0
   236
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   237
      WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=AD_FIELD.AD_Column_ID
carlos@0
   238
      )
carlos@0
   239
      , Updated=Now()
carlos@0
   240
    WHERE AD_FIELD.IsCentrallyMaintained='Y' AND AD_FIELD.IsActive='Y'  AND EXISTS
carlos@0
   241
      (SELECT *
carlos@0
   242
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   243
      WHERE AD_FIELD.AD_Column_ID=c.AD_Column_ID  AND c.AD_Element_ID=e.AD_Element_ID
carlos@0
   244
      AND c.AD_Process_ID IS NULL  AND(AD_FIELD.NAME<>e.NAME OR COALESCE(TO_CHAR(AD_FIELD.Description), ' ')<>COALESCE(TO_CHAR(e.Description), ' ')
carlos@0
   245
      OR COALESCE(TO_CHAR(AD_FIELD.Help), ' ')<>COALESCE(TO_CHAR(e.Help), ' '))
carlos@0
   246
      )
carlos@0
   247
      ;
carlos@0
   248
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   249
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   250
    -- Field Translations
carlos@0
   251
    DBMS_OUTPUT.PUT_LINE('Synchronize Field Translations') ;
carlos@0
   252
    UPDATE AD_FIELD_TRL
carlos@0
   253
      SET NAME=
carlos@0
   254
      (SELECT e.NAME
carlos@0
   255
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f
carlos@0
   256
      WHERE e.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   257
      AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   258
      )
carlos@0
   259
      , Description=
carlos@0
   260
      (SELECT e.Description
carlos@0
   261
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f
carlos@0
   262
      WHERE e.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   263
      AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   264
      )
carlos@0
   265
      , Help=
carlos@0
   266
      (SELECT e.Help
carlos@0
   267
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f
carlos@0
   268
      WHERE e.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   269
      AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   270
      )
carlos@0
   271
      , IsTranslated=
carlos@0
   272
      (SELECT e.IsTranslated
carlos@0
   273
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f
carlos@0
   274
      WHERE e.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   275
      AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   276
      )
carlos@0
   277
      , Updated=Now()
carlos@0
   278
    WHERE EXISTS
carlos@0
   279
      (SELECT *
carlos@0
   280
      FROM AD_FIELD f, AD_ELEMENT_TRL e, AD_COLUMN c
carlos@0
   281
      WHERE AD_FIELD_TRL.AD_Field_ID=f.AD_Field_ID  AND f.AD_Column_ID=c.AD_Column_ID
carlos@0
   282
      AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL
carlos@0
   283
      AND AD_FIELD_TRL.AD_LANGUAGE=e.AD_LANGUAGE  AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
carlos@0
   284
      AND(AD_FIELD_TRL.NAME<>e.NAME OR COALESCE(TO_CHAR(AD_FIELD_TRL.Description), ' ')<>COALESCE(TO_CHAR(e.Description), ' ')
carlos@0
   285
      OR COALESCE(TO_CHAR(AD_FIELD_TRL.Help), ' ')<>COALESCE(TO_CHAR(e.Help), ' '))
carlos@0
   286
      );
carlos@0
   287
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   288
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   289
    -- Fields should now be syncronized
carlos@0
   290
    DBMS_OUTPUT.PUT_LINE('Synchronize PO Field') ;
carlos@0
   291
    UPDATE AD_FIELD
carlos@0
   292
      SET NAME=
carlos@0
   293
      (SELECT e.PO_Name
carlos@0
   294
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   295
      WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=AD_FIELD.AD_Column_ID
carlos@0
   296
      )
carlos@0
   297
      , Description=
carlos@0
   298
      (SELECT e.PO_Description
carlos@0
   299
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   300
      WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=AD_FIELD.AD_Column_ID
carlos@0
   301
      )
carlos@0
   302
      , Help=
carlos@0
   303
      (SELECT e.PO_Help
carlos@0
   304
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   305
      WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=AD_FIELD.AD_Column_ID
carlos@0
   306
      )
carlos@0
   307
      , Updated=Now()
carlos@0
   308
    WHERE AD_FIELD.IsCentrallyMaintained='Y' AND AD_FIELD.IsActive='Y'  AND EXISTS
carlos@0
   309
      (SELECT *
carlos@0
   310
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   311
      WHERE AD_FIELD.AD_Column_ID=c.AD_Column_ID  AND c.AD_Element_ID=e.AD_Element_ID
carlos@0
   312
      AND c.AD_Process_ID IS NULL  AND(AD_FIELD.NAME<>e.PO_Name OR COALESCE(TO_CHAR(AD_FIELD.Description), ' ')<>COALESCE(TO_CHAR(e.PO_Description), ' ')
carlos@0
   313
      OR COALESCE(TO_CHAR(AD_FIELD.Help), ' ')<>COALESCE(TO_CHAR(e.PO_Help), ' ')) AND e.PO_Name IS NOT NULL
carlos@0
   314
      )
carlos@0
   315
      AND EXISTS
carlos@0
   316
      (SELECT *
carlos@0
   317
      FROM AD_TAB t, AD_WINDOW w
carlos@0
   318
      WHERE AD_FIELD.AD_Tab_ID=t.AD_Tab_ID  AND t.AD_Window_ID=w.AD_Window_ID  AND w.IsSOTrx='N'
carlos@0
   319
      )
carlos@0
   320
      ;
carlos@0
   321
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   322
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   323
    -- Field Translations
carlos@0
   324
    DBMS_OUTPUT.PUT_LINE('Synchronize PO Field Translations') ;
carlos@0
   325
    UPDATE AD_FIELD_TRL
carlos@0
   326
      SET NAME=
carlos@0
   327
      (SELECT e.PO_Name
carlos@0
   328
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f
carlos@0
   329
      WHERE e.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   330
      AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   331
      )
carlos@0
   332
      , Description=
carlos@0
   333
      (SELECT e.PO_Description
carlos@0
   334
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f
carlos@0
   335
      WHERE e.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   336
      AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   337
      )
carlos@0
   338
      , Help=
carlos@0
   339
      (SELECT e.PO_Help
carlos@0
   340
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f
carlos@0
   341
      WHERE e.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   342
      AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   343
      )
carlos@0
   344
      , IsTranslated=
carlos@0
   345
      (SELECT e.IsTranslated
carlos@0
   346
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_FIELD f
carlos@0
   347
      WHERE e.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   348
      AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   349
      )
carlos@0
   350
      , Updated=Now()
carlos@0
   351
    WHERE EXISTS
carlos@0
   352
      (SELECT *
carlos@0
   353
      FROM AD_FIELD f, AD_ELEMENT_TRL e, AD_COLUMN c
carlos@0
   354
      WHERE AD_FIELD_TRL.AD_Field_ID=f.AD_Field_ID  AND f.AD_Column_ID=c.AD_Column_ID
carlos@0
   355
      AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL
carlos@0
   356
      AND AD_FIELD_TRL.AD_LANGUAGE=e.AD_LANGUAGE  AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
carlos@0
   357
      AND(AD_FIELD_TRL.NAME<>e.PO_Name OR COALESCE(TO_CHAR(AD_FIELD_TRL.Description), ' ')<>COALESCE(TO_CHAR(e.PO_Description), ' ')
carlos@0
   358
      OR COALESCE(TO_CHAR(AD_FIELD_TRL.Help), ' ')<>COALESCE(TO_CHAR(e.PO_Help), ' ')) AND e.PO_Name IS NOT NULL
carlos@0
   359
      )
carlos@0
   360
      AND EXISTS
carlos@0
   361
      (SELECT *
carlos@0
   362
      FROM AD_FIELD f, AD_TAB t, AD_WINDOW w
carlos@0
   363
      WHERE AD_FIELD_TRL.AD_Field_ID=f.AD_Field_ID  AND f.AD_Tab_ID=t.AD_Tab_ID
carlos@0
   364
      AND t.AD_Window_ID=w.AD_Window_ID  AND w.IsSOTrx='N'
carlos@0
   365
      )
carlos@0
   366
      ;
carlos@0
   367
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   368
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   369
    -- Fields from Process
carlos@0
   370
    DBMS_OUTPUT.PUT_LINE('Synchronize Field from Process') ;
carlos@0
   371
    UPDATE AD_FIELD
carlos@0
   372
      SET NAME=
carlos@0
   373
      (SELECT p.NAME
carlos@0
   374
      FROM AD_PROCESS p, AD_COLUMN c
carlos@0
   375
      WHERE p.AD_Process_ID=c.AD_Process_ID  AND c.AD_Column_ID=AD_FIELD.AD_Column_ID
carlos@0
   376
      )
carlos@0
   377
      , Description=
carlos@0
   378
      (SELECT p.Description
carlos@0
   379
      FROM AD_PROCESS p, AD_COLUMN c
carlos@0
   380
      WHERE p.AD_Process_ID=c.AD_Process_ID  AND c.AD_Column_ID=AD_FIELD.AD_Column_ID
carlos@0
   381
      )
carlos@0
   382
      , Help=
carlos@0
   383
      (SELECT p.Help
carlos@0
   384
      FROM AD_PROCESS p, AD_COLUMN c
carlos@0
   385
      WHERE p.AD_Process_ID=c.AD_Process_ID  AND c.AD_Column_ID=AD_FIELD.AD_Column_ID
carlos@0
   386
      )
carlos@0
   387
      , Updated=Now()
carlos@0
   388
    WHERE AD_FIELD.IsCentrallyMaintained='Y' AND AD_FIELD.IsActive='Y'  AND EXISTS
carlos@0
   389
      (SELECT *
carlos@0
   390
      FROM AD_PROCESS p, AD_COLUMN c
carlos@0
   391
      WHERE c.AD_Process_ID=p.AD_Process_ID AND AD_FIELD.AD_Column_ID=c.AD_Column_ID
carlos@0
   392
      AND(AD_FIELD.NAME<>p.NAME OR COALESCE(TO_CHAR(AD_FIELD.Description), ' ')<>COALESCE(TO_CHAR(p.Description), ' ')
carlos@0
   393
      OR COALESCE(TO_CHAR(AD_FIELD.Help), ' ')<>COALESCE(TO_CHAR(p.Help), ' '))
carlos@0
   394
      )
carlos@0
   395
      ;
carlos@0
   396
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   397
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   398
    -- Field Translations from Process
carlos@0
   399
    DBMS_OUTPUT.PUT_LINE('Synchronize Field Trl from Process Trl') ;
carlos@0
   400
    UPDATE AD_FIELD_TRL
carlos@0
   401
      SET NAME=
carlos@0
   402
      (SELECT p.NAME
carlos@0
   403
      FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f
carlos@0
   404
      WHERE p.AD_Process_ID=c.AD_Process_ID AND c.AD_Column_ID=f.AD_Column_ID  AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   405
      AND p.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE
carlos@0
   406
      )
carlos@0
   407
      , Description=
carlos@0
   408
      (SELECT p.Description
carlos@0
   409
      FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f
carlos@0
   410
      WHERE p.AD_Process_ID=c.AD_Process_ID AND c.AD_Column_ID=f.AD_Column_ID  AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   411
      AND p.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE
carlos@0
   412
      )
carlos@0
   413
      , Help=
carlos@0
   414
      (SELECT p.Help
carlos@0
   415
      FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f
carlos@0
   416
      WHERE p.AD_Process_ID=c.AD_Process_ID AND c.AD_Column_ID=f.AD_Column_ID  AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   417
      AND p.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE
carlos@0
   418
      )
carlos@0
   419
      , IsTranslated=
carlos@0
   420
      (SELECT p.IsTranslated
carlos@0
   421
      FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f
carlos@0
   422
      WHERE p.AD_Process_ID=c.AD_Process_ID AND c.AD_Column_ID=f.AD_Column_ID  AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   423
      AND p.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE
carlos@0
   424
      )
carlos@0
   425
      , Updated=Now()
carlos@0
   426
    WHERE EXISTS
carlos@0
   427
      (SELECT *
carlos@0
   428
      FROM AD_PROCESS_TRL p, AD_COLUMN c, AD_FIELD f
carlos@0
   429
      WHERE c.AD_Process_ID=p.AD_Process_ID AND f.AD_Column_ID=c.AD_Column_ID  AND f.AD_Field_ID=AD_FIELD_TRL.AD_Field_ID
carlos@0
   430
      AND p.AD_LANGUAGE=AD_FIELD_TRL.AD_LANGUAGE  AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'  AND(AD_FIELD_TRL.NAME<>p.NAME
carlos@0
   431
      OR COALESCE(TO_CHAR(AD_FIELD_TRL.Description), ' ')<>COALESCE(TO_CHAR(p.Description), ' ') OR COALESCE(TO_CHAR(AD_FIELD_TRL.Help), ' ')<>COALESCE(TO_CHAR(p.Help), ' '))
carlos@0
   432
      );
carlos@0
   433
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   434
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   435
    -- Sync Parameter ColumnName
carlos@0
   436
    /*UPDATE AD_Process_Para
carlos@0
   437
    SET ColumnName = (SELECT e.ColumnName FROM AD_Element e
carlos@0
   438
    WHERE UPPER(e.ColumnName)=UPPER(AD_Process_Para.ColumnName))
carlos@0
   439
    WHERE AD_Process_Para.IsCentrallyMaintained='Y' AND AD_Process_Para.IsActive='Y'
carlos@0
   440
    AND EXISTS (SELECT * FROM AD_Element e
carlos@0
   441
    WHERE e.AD_Element_ID=AD_Process_Para.AD_Element_ID
carlos@0
   442
    AND e.ColumnName<>AD_Process_Para.ColumnName);*/
carlos@0
   443
    -- Paramenter Fields
carlos@0
   444
    UPDATE AD_PROCESS_PARA
carlos@0
   445
      SET IsCentrallyMaintained='N'
carlos@0
   446
    WHERE IsCentrallyMaintained<>'N'  AND NOT EXISTS
carlos@0
   447
      (SELECT *
carlos@0
   448
      FROM AD_ELEMENT e
carlos@0
   449
      WHERE AD_PROCESS_PARA.AD_Element_ID=e.AD_Element_ID
carlos@0
   450
      )
carlos@0
   451
      ;
carlos@0
   452
    -- Parameter Fields
carlos@0
   453
    DBMS_OUTPUT.PUT_LINE('Synchronize Process Parameter') ;
carlos@0
   454
    UPDATE AD_PROCESS_PARA
carlos@0
   455
      SET NAME=
carlos@0
   456
      (SELECT e.NAME
carlos@0
   457
      FROM AD_ELEMENT e
carlos@0
   458
      WHERE e.AD_Element_ID=AD_PROCESS_PARA.AD_Element_ID
carlos@0
   459
      )
carlos@0
   460
      , Description=
carlos@0
   461
      (SELECT e.Description
carlos@0
   462
      FROM AD_ELEMENT e
carlos@0
   463
      WHERE e.AD_Element_ID=AD_PROCESS_PARA.AD_Element_ID
carlos@0
   464
      )
carlos@0
   465
      , Help=
carlos@0
   466
      (SELECT e.Help
carlos@0
   467
      FROM AD_ELEMENT e
carlos@0
   468
      WHERE e.AD_Element_ID=AD_PROCESS_PARA.AD_Element_ID
carlos@0
   469
      )
carlos@0
   470
      , Updated=Now()
carlos@0
   471
    WHERE AD_PROCESS_PARA.IsCentrallyMaintained='Y' AND AD_PROCESS_PARA.IsActive='Y'  AND EXISTS
carlos@0
   472
      (SELECT *
carlos@0
   473
      FROM AD_ELEMENT e
carlos@0
   474
      WHERE e.AD_Element_ID=AD_PROCESS_PARA.AD_Element_ID  AND(AD_PROCESS_PARA.NAME<>e.NAME
carlos@0
   475
      OR COALESCE(TO_CHAR(AD_PROCESS_PARA.Description), ' ')<>COALESCE(TO_CHAR(e.Description), ' ')
carlos@0
   476
      OR COALESCE(TO_CHAR(AD_PROCESS_PARA.Help), ' ')<>COALESCE(TO_CHAR(e.Help), ' '))
carlos@0
   477
      )
carlos@0
   478
      ;
carlos@0
   479
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   480
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   481
    -- Parameter Translations
carlos@0
   482
    DBMS_OUTPUT.PUT_LINE('Synchronize Process Parameter Trl') ;
carlos@0
   483
    UPDATE AD_PROCESS_PARA_TRL
carlos@0
   484
      SET NAME=
carlos@0
   485
      (SELECT et.NAME
carlos@0
   486
      FROM AD_ELEMENT_TRL et, AD_PROCESS_PARA f
carlos@0
   487
      WHERE et.AD_LANGUAGE=AD_PROCESS_PARA_TRL.AD_LANGUAGE AND f.AD_Element_ID=et.AD_Element_ID
carlos@0
   488
      AND f.AD_Process_Para_ID=AD_PROCESS_PARA_TRL.AD_Process_Para_ID
carlos@0
   489
      )
carlos@0
   490
      , Description=
carlos@0
   491
      (SELECT et.Description
carlos@0
   492
      FROM AD_ELEMENT_TRL et, AD_PROCESS_PARA f
carlos@0
   493
      WHERE et.AD_LANGUAGE=AD_PROCESS_PARA_TRL.AD_LANGUAGE AND f.AD_Element_ID=et.AD_Element_ID
carlos@0
   494
      AND f.AD_Process_Para_ID=AD_PROCESS_PARA_TRL.AD_Process_Para_ID
carlos@0
   495
      )
carlos@0
   496
      , Help=
carlos@0
   497
      (SELECT et.Help
carlos@0
   498
      FROM AD_ELEMENT_TRL et, AD_PROCESS_PARA f
carlos@0
   499
      WHERE et.AD_LANGUAGE=AD_PROCESS_PARA_TRL.AD_LANGUAGE AND f.AD_Element_ID=et.AD_Element_ID
carlos@0
   500
      AND f.AD_Process_Para_ID=AD_PROCESS_PARA_TRL.AD_Process_Para_ID
carlos@0
   501
      )
carlos@0
   502
      , IsTranslated=
carlos@0
   503
      (SELECT et.IsTranslated
carlos@0
   504
      FROM AD_ELEMENT_TRL et, AD_PROCESS_PARA f
carlos@0
   505
      WHERE et.AD_LANGUAGE=AD_PROCESS_PARA_TRL.AD_LANGUAGE AND f.AD_Element_ID=et.AD_Element_ID
carlos@0
   506
      AND f.AD_Process_Para_ID=AD_PROCESS_PARA_TRL.AD_Process_Para_ID
carlos@0
   507
      )
carlos@0
   508
      , Updated=Now()
carlos@0
   509
    WHERE EXISTS
carlos@0
   510
      (SELECT *
carlos@0
   511
      FROM AD_ELEMENT_TRL et, AD_PROCESS_PARA f
carlos@0
   512
      WHERE et.AD_LANGUAGE=AD_PROCESS_PARA_TRL.AD_LANGUAGE AND f.AD_Element_ID=et.AD_Element_ID
carlos@0
   513
      AND f.AD_Process_Para_ID=AD_PROCESS_PARA_TRL.AD_Process_Para_ID  AND f.IsCentrallyMaintained='Y'
carlos@0
   514
      AND f.IsActive='Y'  AND(AD_PROCESS_PARA_TRL.NAME<>et.NAME OR COALESCE(TO_CHAR(AD_PROCESS_PARA_TRL.Description), ' ')<>COALESCE(TO_CHAR(et.Description), ' ')
carlos@0
   515
      OR COALESCE(TO_CHAR(AD_PROCESS_PARA_TRL.Help), ' ')<>COALESCE(TO_CHAR(et.Help), ' '))
carlos@0
   516
      );
carlos@0
   517
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   518
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   519
    -- Workflow Node - Window
carlos@0
   520
    DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node from Window') ;
carlos@0
   521
    UPDATE AD_WF_NODE
carlos@0
   522
      SET NAME=
carlos@0
   523
      (SELECT w.NAME FROM AD_WINDOW w  WHERE w.AD_Window_ID=AD_WF_NODE.AD_Window_ID)
carlos@0
   524
      , Description=
carlos@0
   525
      (SELECT w.Description
carlos@0
   526
      FROM AD_WINDOW w
carlos@0
   527
      WHERE w.AD_Window_ID=AD_WF_NODE.AD_Window_ID
carlos@0
   528
      )
carlos@0
   529
      , Help=
carlos@0
   530
      (SELECT w.Help FROM AD_WINDOW w  WHERE w.AD_Window_ID=AD_WF_NODE.AD_Window_ID)
carlos@0
   531
    WHERE AD_WF_NODE.IsCentrallyMaintained='Y'  AND EXISTS
carlos@0
   532
      (SELECT *
carlos@0
   533
      FROM AD_WINDOW w
carlos@0
   534
      WHERE w.AD_Window_ID=AD_WF_NODE.AD_Window_ID  AND(w.NAME<>AD_WF_NODE.NAME OR COALESCE(TO_CHAR(w.Description), ' ')<>COALESCE(TO_CHAR(AD_WF_NODE.Description), ' ')
carlos@0
   535
      OR COALESCE(TO_CHAR(w.Help), ' ')<>COALESCE(TO_CHAR(AD_WF_NODE.Help), ' '))
carlos@0
   536
      )
carlos@0
   537
      ;
carlos@0
   538
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   539
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   540
    -- Workflow Translations - Window
carlos@0
   541
    DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node Trl from Window Trl') ;
carlos@0
   542
    UPDATE AD_WF_NODE_TRL
carlos@0
   543
      SET NAME=
carlos@0
   544
      (SELECT t.NAME
carlos@0
   545
      FROM AD_WINDOW_TRL t, AD_WF_NODE n
carlos@0
   546
      WHERE AD_WF_NODE_TRL.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Window_ID=t.AD_Window_ID
carlos@0
   547
      AND AD_WF_NODE_TRL.AD_LANGUAGE=t.AD_LANGUAGE
carlos@0
   548
      )
carlos@0
   549
      , Description=
carlos@0
   550
      (SELECT t.Description
carlos@0
   551
      FROM AD_WINDOW_TRL t, AD_WF_NODE n
carlos@0
   552
      WHERE AD_WF_NODE_TRL.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Window_ID=t.AD_Window_ID
carlos@0
   553
      AND AD_WF_NODE_TRL.AD_LANGUAGE=t.AD_LANGUAGE
carlos@0
   554
      )
carlos@0
   555
      , Help=
carlos@0
   556
      (SELECT t.Help
carlos@0
   557
      FROM AD_WINDOW_TRL t, AD_WF_NODE n
carlos@0
   558
      WHERE AD_WF_NODE_TRL.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Window_ID=t.AD_Window_ID
carlos@0
   559
      AND AD_WF_NODE_TRL.AD_LANGUAGE=t.AD_LANGUAGE
carlos@0
   560
      )
carlos@0
   561
    WHERE EXISTS
carlos@0
   562
      (SELECT *
carlos@0
   563
      FROM AD_WINDOW_TRL t, AD_WF_NODE n
carlos@0
   564
      WHERE AD_WF_NODE_TRL.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Window_ID=t.AD_Window_ID
carlos@0
   565
      AND AD_WF_NODE_TRL.AD_LANGUAGE=t.AD_LANGUAGE AND n.IsCentrallyMaintained='Y' AND n.IsActive='Y'
carlos@0
   566
      AND(AD_WF_NODE_TRL.NAME<>t.NAME OR COALESCE(TO_CHAR(AD_WF_NODE_TRL.Description), ' ')<>COALESCE(TO_CHAR(t.Description), ' ')
carlos@0
   567
      OR COALESCE(TO_CHAR(AD_WF_NODE_TRL.Help), ' ')<>COALESCE(TO_CHAR(t.Help), ' '))
carlos@0
   568
      )
carlos@0
   569
      ;
carlos@0
   570
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   571
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   572
    -- Workflow Node - Form
carlos@0
   573
    DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node from Form') ;
carlos@0
   574
    UPDATE AD_WF_NODE
carlos@0
   575
      SET NAME=
carlos@0
   576
      (SELECT f.NAME  FROM AD_FORM f  WHERE f.AD_Form_ID=AD_WF_NODE.AD_Form_ID)
carlos@0
   577
      , Description=
carlos@0
   578
      (SELECT f.Description
carlos@0
   579
      FROM AD_FORM f
carlos@0
   580
      WHERE f.AD_Form_ID=AD_WF_NODE.AD_Form_ID
carlos@0
   581
      )
carlos@0
   582
      , Help=
carlos@0
   583
      (SELECT f.Help  FROM AD_FORM f  WHERE f.AD_Form_ID=AD_WF_NODE.AD_Form_ID)
carlos@0
   584
    WHERE AD_WF_NODE.IsCentrallyMaintained='Y'  AND EXISTS
carlos@0
   585
      (SELECT *
carlos@0
   586
      FROM AD_FORM f
carlos@0
   587
      WHERE f.AD_Form_ID=AD_WF_NODE.AD_Form_ID  AND(f.NAME<>AD_WF_NODE.NAME OR COALESCE(TO_CHAR(f.Description), ' ')<>COALESCE(TO_CHAR(AD_WF_NODE.Description), ' ')
carlos@0
   588
      OR COALESCE(TO_CHAR(f.Help), ' ')<>COALESCE(TO_CHAR(AD_WF_NODE.Help), ' '))
carlos@0
   589
      )
carlos@0
   590
      ;
carlos@0
   591
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   592
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   593
    -- Workflow Translations - Form
carlos@0
   594
    DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node Trl from Form Trl') ;
carlos@0
   595
    UPDATE AD_WF_NODE_TRL
carlos@0
   596
      SET NAME=
carlos@0
   597
      (SELECT t.NAME
carlos@0
   598
      FROM AD_FORM_TRL t, AD_WF_NODE n
carlos@0
   599
      WHERE AD_WF_NODE_TRL.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Form_ID=t.AD_Form_ID
carlos@0
   600
      AND AD_WF_NODE_TRL.AD_LANGUAGE=t.AD_LANGUAGE
carlos@0
   601
      )
carlos@0
   602
      , Description=
carlos@0
   603
      (SELECT t.Description
carlos@0
   604
      FROM AD_FORM_TRL t, AD_WF_NODE n
carlos@0
   605
      WHERE AD_WF_NODE_TRL.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Form_ID=t.AD_Form_ID
carlos@0
   606
      AND AD_WF_NODE_TRL.AD_LANGUAGE=t.AD_LANGUAGE
carlos@0
   607
      )
carlos@0
   608
      , Help=
carlos@0
   609
      (SELECT t.Help
carlos@0
   610
      FROM AD_FORM_TRL t, AD_WF_NODE n
carlos@0
   611
      WHERE AD_WF_NODE_TRL.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Form_ID=t.AD_Form_ID
carlos@0
   612
      AND AD_WF_NODE_TRL.AD_LANGUAGE=t.AD_LANGUAGE
carlos@0
   613
      )
carlos@0
   614
    WHERE EXISTS
carlos@0
   615
      (SELECT *
carlos@0
   616
      FROM AD_FORM_TRL t, AD_WF_NODE n
carlos@0
   617
      WHERE AD_WF_NODE_TRL.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Form_ID=t.AD_Form_ID
carlos@0
   618
      AND AD_WF_NODE_TRL.AD_LANGUAGE=t.AD_LANGUAGE AND n.IsCentrallyMaintained='Y' AND n.IsActive='Y'
carlos@0
   619
      AND(AD_WF_NODE_TRL.NAME<>t.NAME OR COALESCE(TO_CHAR(AD_WF_NODE_TRL.Description), ' ')<>COALESCE(TO_CHAR(t.Description), ' ')
carlos@0
   620
      OR COALESCE(TO_CHAR(AD_WF_NODE_TRL.Help), ' ')<>COALESCE(TO_CHAR(t.Help), ' '))
carlos@0
   621
      )
carlos@0
   622
      ;
carlos@0
   623
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   624
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   625
    DBMS_OUTPUT.PUT_LINE('Synchronize PrintFormatItem Name from Element') ;
carlos@0
   626
    UPDATE AD_PRINTFORMATITEM
carlos@0
   627
      SET NAME=
carlos@0
   628
      (SELECT e.NAME
carlos@0
   629
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   630
      WHERE e.AD_Element_ID=c.AD_Element_ID  AND c.AD_Column_ID=AD_PRINTFORMATITEM.AD_Column_ID
carlos@0
   631
      )
carlos@0
   632
    WHERE EXISTS
carlos@0
   633
      (SELECT *
carlos@0
   634
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   635
      WHERE e.AD_Element_ID=c.AD_Element_ID  AND c.AD_Column_ID=AD_PRINTFORMATITEM.AD_Column_ID
carlos@0
   636
      AND e.NAME<>AD_PRINTFORMATITEM.NAME
carlos@0
   637
      )
carlos@0
   638
      AND EXISTS
carlos@0
   639
      (SELECT *
carlos@0
   640
      FROM AD_CLIENT
carlos@0
   641
      WHERE AD_Client_ID=AD_PRINTFORMATITEM.AD_Client_ID AND IsMultiLingualDocument='Y'
carlos@0
   642
      )
carlos@0
   643
      ;
carlos@0
   644
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   645
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   646
    DBMS_OUTPUT.PUT_LINE('Synchronize PrintFormatItem PrintName from Element') ;
carlos@0
   647
    UPDATE AD_PRINTFORMATITEM
carlos@0
   648
      SET PrintName=
carlos@0
   649
      (SELECT e.PrintName
carlos@0
   650
      FROM AD_ELEMENT e, AD_COLUMN c
carlos@0
   651
      WHERE e.AD_Element_ID=c.AD_Element_ID  AND c.AD_Column_ID=AD_PRINTFORMATITEM.AD_Column_ID
carlos@0
   652
      )
carlos@0
   653
    WHERE EXISTS
carlos@0
   654
      (SELECT *
carlos@0
   655
      FROM AD_ELEMENT e, AD_COLUMN c, AD_PRINTFORMAT pf
carlos@0
   656
      WHERE e.AD_Element_ID=c.AD_Element_ID  AND c.AD_Column_ID=AD_PRINTFORMATITEM.AD_Column_ID
carlos@0
   657
      AND LENGTH(AD_PRINTFORMATITEM.PrintName)>0  AND e.PrintName<>AD_PRINTFORMATITEM.PrintName
carlos@0
   658
      AND pf.AD_PrintFormat_ID=AD_PRINTFORMATITEM.AD_PrintFormat_ID  AND pf.IsForm='N' AND IsTableBased='Y'
carlos@0
   659
      )
carlos@0
   660
      AND EXISTS
carlos@0
   661
      (SELECT *
carlos@0
   662
      FROM AD_CLIENT
carlos@0
   663
      WHERE AD_Client_ID=AD_PRINTFORMATITEM.AD_Client_ID AND IsMultiLingualDocument='Y'
carlos@0
   664
      )
carlos@0
   665
      ;
carlos@0
   666
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   667
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   668
    DBMS_OUTPUT.PUT_LINE('Synchronize PrintFormatItem Trl from Element Trl (Multi-Lingual)') ;
carlos@0
   669
    UPDATE AD_PRINTFORMATITEM_TRL
carlos@0
   670
      SET PrintName=
carlos@0
   671
      (SELECT e.PrintName
carlos@0
   672
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_PRINTFORMATITEM pfi
carlos@0
   673
      WHERE e.AD_LANGUAGE=AD_PRINTFORMATITEM_TRL.AD_LANGUAGE  AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   674
      AND c.AD_Column_ID=pfi.AD_Column_ID  AND pfi.AD_PrintFormatItem_ID=AD_PRINTFORMATITEM_TRL.AD_PrintFormatItem_ID
carlos@0
   675
      )
carlos@0
   676
    WHERE EXISTS
carlos@0
   677
      (SELECT *
carlos@0
   678
      FROM AD_ELEMENT_TRL e, AD_COLUMN c, AD_PRINTFORMATITEM pfi, AD_PRINTFORMAT pf
carlos@0
   679
      WHERE e.AD_LANGUAGE=AD_PRINTFORMATITEM_TRL.AD_LANGUAGE  AND e.AD_Element_ID=c.AD_Element_ID
carlos@0
   680
      AND c.AD_Column_ID=pfi.AD_Column_ID  AND pfi.AD_PrintFormatItem_ID=AD_PRINTFORMATITEM_TRL.AD_PrintFormatItem_ID
carlos@0
   681
      AND LENGTH(pfi.PrintName)>0  AND(e.PrintName<>AD_PRINTFORMATITEM_TRL.PrintName OR AD_PRINTFORMATITEM_TRL.PrintName IS NULL)
carlos@0
   682
      AND pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID  AND pf.IsForm='N' AND IsTableBased='Y'
carlos@0
   683
      )
carlos@0
   684
      AND EXISTS
carlos@0
   685
      (SELECT *
carlos@0
   686
      FROM AD_CLIENT
carlos@0
   687
      WHERE AD_Client_ID=AD_PRINTFORMATITEM_TRL.AD_Client_ID AND IsMultiLingualDocument='Y'
carlos@0
   688
      )
carlos@0
   689
      ;
carlos@0
   690
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   691
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   692
    DBMS_OUTPUT.PUT_LINE('Synchronize PrintFormatItem Trl (Not Multi-Lingual)') ;
carlos@0
   693
    UPDATE AD_PRINTFORMATITEM_TRL
carlos@0
   694
      SET PrintName=
carlos@0
   695
      (SELECT pfi.PrintName
carlos@0
   696
      FROM AD_PRINTFORMATITEM pfi
carlos@0
   697
      WHERE pfi.AD_PrintFormatItem_ID=AD_PRINTFORMATITEM_TRL.AD_PrintFormatItem_ID
carlos@0
   698
      )
carlos@0
   699
    WHERE EXISTS
carlos@0
   700
      (SELECT *
carlos@0
   701
      FROM AD_PRINTFORMATITEM pfi, AD_PRINTFORMAT pf
carlos@0
   702
      WHERE pfi.AD_PrintFormatItem_ID=AD_PRINTFORMATITEM_TRL.AD_PrintFormatItem_ID
carlos@0
   703
      AND LENGTH(pfi.PrintName)>0  AND pfi.PrintName<>AD_PRINTFORMATITEM_TRL.PrintName
carlos@0
   704
      AND pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID  AND pf.IsForm='N' AND pf.IsTableBased='Y'
carlos@0
   705
      )
carlos@0
   706
      AND EXISTS
carlos@0
   707
      (SELECT *
carlos@0
   708
      FROM AD_CLIENT
carlos@0
   709
      WHERE AD_Client_ID=AD_PRINTFORMATITEM_TRL.AD_Client_ID AND IsMultiLingualDocument='N'
carlos@0
   710
      )
carlos@0
   711
      ;
carlos@0
   712
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   713
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   714
    DBMS_OUTPUT.PUT_LINE('Reset PrintFormatItem Trl where not used in base table') ;
carlos@0
   715
    UPDATE AD_PRINTFORMATITEM_TRL
carlos@0
   716
      SET PrintName=NULL
carlos@0
   717
    WHERE PrintName IS NOT NULL  AND EXISTS
carlos@0
   718
      (SELECT *
carlos@0
   719
      FROM AD_PRINTFORMATITEM pfi
carlos@0
   720
      WHERE pfi.AD_PrintFormatItem_ID=AD_PRINTFORMATITEM_TRL.AD_PrintFormatItem_ID
carlos@0
   721
      AND(LENGTH(pfi.PrintName)=0 OR pfi.PrintName IS NULL)
carlos@0
   722
      )
carlos@0
   723
      ;
carlos@0
   724
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   725
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   726
    /**
carlos@0
   727
    SELECT  e.PrintName "Element", pfi.PrintName "FormatItem", trl.AD_Language, trl.PrintName "Trl"
carlos@0
   728
    FROM  AD_Element e
carlos@0
   729
    INNER JOIN AD_Column c ON (e.AD_Element_ID=c.AD_Element_ID)
carlos@0
   730
    INNER JOIN AD_PrintFormatItem pfi ON (c.AD_Column_ID=pfi.AD_Column_ID)
carlos@0
   731
    INNER JOIN AD_PrintFormatItem_Trl trl ON (pfi.AD_PrintFormatItem_ID=trl.AD_PrintFormatItem_ID)
carlos@0
   732
    WHERE pfi.AD_PrintFormatItem_ID=?
carlos@0
   733
    **/
carlos@0
   734
    -- Sync Names - Window
carlos@0
   735
    DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Window') ;
carlos@0
   736
    UPDATE AD_MENU
carlos@0
   737
      SET NAME=
carlos@0
   738
      (SELECT NAME FROM AD_WINDOW w WHERE AD_MENU.AD_Window_ID=w.AD_Window_ID)
carlos@0
   739
      , Description=
carlos@0
   740
      (SELECT Description FROM AD_WINDOW w WHERE AD_MENU.AD_Window_ID=w.AD_Window_ID)
carlos@0
   741
    WHERE AD_Window_ID IS NOT NULL  AND Action='W';
carlos@0
   742
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   743
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   744
    UPDATE AD_MENU_TRL
carlos@0
   745
      SET NAME=
carlos@0
   746
      (SELECT wt.NAME
carlos@0
   747
      FROM AD_WINDOW_TRL wt, AD_MENU m
carlos@0
   748
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Window_ID=wt.AD_Window_ID
carlos@0
   749
      AND AD_MENU_TRL.AD_LANGUAGE=wt.AD_LANGUAGE
carlos@0
   750
      )
carlos@0
   751
      , Description=
carlos@0
   752
      (SELECT wt.Description
carlos@0
   753
      FROM AD_WINDOW_TRL wt, AD_MENU m
carlos@0
   754
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Window_ID=wt.AD_Window_ID
carlos@0
   755
      AND AD_MENU_TRL.AD_LANGUAGE=wt.AD_LANGUAGE
carlos@0
   756
      )
carlos@0
   757
      , IsTranslated=
carlos@0
   758
      (SELECT wt.IsTranslated
carlos@0
   759
      FROM AD_WINDOW_TRL wt, AD_MENU m
carlos@0
   760
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Window_ID=wt.AD_Window_ID
carlos@0
   761
      AND AD_MENU_TRL.AD_LANGUAGE=wt.AD_LANGUAGE
carlos@0
   762
      )
carlos@0
   763
    WHERE EXISTS
carlos@0
   764
      (SELECT *
carlos@0
   765
      FROM AD_WINDOW_TRL wt, AD_MENU m
carlos@0
   766
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Window_ID=wt.AD_Window_ID
carlos@0
   767
      AND AD_MENU_TRL.AD_LANGUAGE=wt.AD_LANGUAGE  AND m.AD_Window_ID IS NOT NULL  AND m.Action='W'
carlos@0
   768
      )
carlos@0
   769
      ;
carlos@0
   770
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   771
    DBMS_OUTPUT.PUT_LINE('  trl rows updated: ' || v_rowcount) ;
carlos@0
   772
    -- Sync Names - Process
carlos@0
   773
    DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Processes') ;
carlos@0
   774
    UPDATE AD_MENU
carlos@0
   775
      SET NAME=
carlos@0
   776
      (SELECT p.NAME FROM AD_PROCESS p WHERE AD_MENU.AD_Process_ID=p.AD_Process_ID)
carlos@0
   777
      , Description=
carlos@0
   778
      (SELECT p.Description
carlos@0
   779
      FROM AD_PROCESS p
carlos@0
   780
      WHERE AD_MENU.AD_Process_ID=p.AD_Process_ID
carlos@0
   781
      )
carlos@0
   782
    WHERE AD_MENU.AD_Process_ID IS NOT NULL  AND AD_MENU.Action IN('R', 'P') ;
carlos@0
   783
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   784
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   785
    UPDATE AD_MENU_TRL
carlos@0
   786
      SET NAME=
carlos@0
   787
      (SELECT pt.NAME
carlos@0
   788
      FROM AD_PROCESS_TRL pt, AD_MENU m
carlos@0
   789
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Process_ID=pt.AD_Process_ID
carlos@0
   790
      AND AD_MENU_TRL.AD_LANGUAGE=pt.AD_LANGUAGE
carlos@0
   791
      )
carlos@0
   792
      , Description=
carlos@0
   793
      (SELECT pt.Description
carlos@0
   794
      FROM AD_PROCESS_TRL pt, AD_MENU m
carlos@0
   795
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Process_ID=pt.AD_Process_ID
carlos@0
   796
      AND AD_MENU_TRL.AD_LANGUAGE=pt.AD_LANGUAGE
carlos@0
   797
      )
carlos@0
   798
      , IsTranslated=
carlos@0
   799
      (SELECT pt.IsTranslated
carlos@0
   800
      FROM AD_PROCESS_TRL pt, AD_MENU m
carlos@0
   801
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Process_ID=pt.AD_Process_ID
carlos@0
   802
      AND AD_MENU_TRL.AD_LANGUAGE=pt.AD_LANGUAGE
carlos@0
   803
      )
carlos@0
   804
    WHERE EXISTS
carlos@0
   805
      (SELECT *
carlos@0
   806
      FROM AD_PROCESS_TRL pt, AD_MENU m
carlos@0
   807
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Process_ID=pt.AD_Process_ID
carlos@0
   808
      AND AD_MENU_TRL.AD_LANGUAGE=pt.AD_LANGUAGE  AND m.AD_Process_ID IS NOT NULL  AND Action IN('R', 'P')
carlos@0
   809
      );
carlos@0
   810
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   811
    DBMS_OUTPUT.PUT_LINE('  trl rows updated: ' || v_rowcount) ;
carlos@0
   812
    -- Sync Names = Form
carlos@0
   813
    DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Forms') ;
carlos@0
   814
    UPDATE AD_MENU
carlos@0
   815
      SET NAME=
carlos@0
   816
      (SELECT NAME FROM AD_FORM f WHERE AD_MENU.AD_Form_ID=f.AD_Form_ID)
carlos@0
   817
      , Description=
carlos@0
   818
      (SELECT Description FROM AD_FORM f WHERE AD_MENU.AD_Form_ID=f.AD_Form_ID)
carlos@0
   819
    WHERE AD_Form_ID IS NOT NULL  AND Action='X';
carlos@0
   820
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   821
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   822
    UPDATE AD_MENU_TRL
carlos@0
   823
      SET NAME=
carlos@0
   824
      (SELECT ft.NAME
carlos@0
   825
      FROM AD_FORM_TRL ft, AD_MENU m
carlos@0
   826
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Form_ID=ft.AD_Form_ID
carlos@0
   827
      AND AD_MENU_TRL.AD_LANGUAGE=ft.AD_LANGUAGE
carlos@0
   828
      )
carlos@0
   829
      , Description=
carlos@0
   830
      (SELECT ft.Description
carlos@0
   831
      FROM AD_FORM_TRL ft, AD_MENU m
carlos@0
   832
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Form_ID=ft.AD_Form_ID
carlos@0
   833
      AND AD_MENU_TRL.AD_LANGUAGE=ft.AD_LANGUAGE
carlos@0
   834
      )
carlos@0
   835
      , IsTranslated=
carlos@0
   836
      (SELECT ft.IsTranslated
carlos@0
   837
      FROM AD_FORM_TRL ft, AD_MENU m
carlos@0
   838
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Form_ID=ft.AD_Form_ID
carlos@0
   839
      AND AD_MENU_TRL.AD_LANGUAGE=ft.AD_LANGUAGE
carlos@0
   840
      )
carlos@0
   841
    WHERE EXISTS
carlos@0
   842
      (SELECT *
carlos@0
   843
      FROM AD_FORM_TRL ft, AD_MENU m
carlos@0
   844
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Form_ID=ft.AD_Form_ID
carlos@0
   845
      AND AD_MENU_TRL.AD_LANGUAGE=ft.AD_LANGUAGE  AND m.AD_Form_ID IS NOT NULL  AND Action='X'
carlos@0
   846
      );
carlos@0
   847
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   848
    DBMS_OUTPUT.PUT_LINE('  trl rows updated: ' || v_rowcount) ;
carlos@0
   849
    -- Sync Names - Workflow
carlos@0
   850
    DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Workflows') ;
carlos@0
   851
    UPDATE AD_MENU
carlos@0
   852
      SET NAME=
carlos@0
   853
      (SELECT p.NAME
carlos@0
   854
      FROM AD_WORKFLOW p
carlos@0
   855
      WHERE AD_MENU.AD_Workflow_ID=p.AD_Workflow_ID
carlos@0
   856
      )
carlos@0
   857
      , Description=
carlos@0
   858
      (SELECT p.Description
carlos@0
   859
      FROM AD_WORKFLOW p
carlos@0
   860
      WHERE AD_MENU.AD_Workflow_ID=p.AD_Workflow_ID
carlos@0
   861
      )
carlos@0
   862
    WHERE AD_MENU.AD_Workflow_ID IS NOT NULL  AND AD_MENU.Action='F';
carlos@0
   863
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   864
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   865
    UPDATE AD_MENU_TRL
carlos@0
   866
      SET NAME=
carlos@0
   867
      (SELECT pt.NAME
carlos@0
   868
      FROM AD_WORKFLOW_TRL pt, AD_MENU m
carlos@0
   869
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Workflow_ID=pt.AD_Workflow_ID
carlos@0
   870
      AND AD_MENU_TRL.AD_LANGUAGE=pt.AD_LANGUAGE
carlos@0
   871
      )
carlos@0
   872
      , Description=
carlos@0
   873
      (SELECT pt.Description
carlos@0
   874
      FROM AD_WORKFLOW_TRL pt, AD_MENU m
carlos@0
   875
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Workflow_ID=pt.AD_Workflow_ID
carlos@0
   876
      AND AD_MENU_TRL.AD_LANGUAGE=pt.AD_LANGUAGE
carlos@0
   877
      )
carlos@0
   878
      , IsTranslated=
carlos@0
   879
      (SELECT pt.IsTranslated
carlos@0
   880
      FROM AD_WORKFLOW_TRL pt, AD_MENU m
carlos@0
   881
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Workflow_ID=pt.AD_Workflow_ID
carlos@0
   882
      AND AD_MENU_TRL.AD_LANGUAGE=pt.AD_LANGUAGE
carlos@0
   883
      )
carlos@0
   884
    WHERE EXISTS
carlos@0
   885
      (SELECT *
carlos@0
   886
      FROM AD_WORKFLOW_TRL pt, AD_MENU m
carlos@0
   887
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Workflow_ID=pt.AD_Workflow_ID
carlos@0
   888
      AND AD_MENU_TRL.AD_LANGUAGE=pt.AD_LANGUAGE  AND m.AD_Workflow_ID IS NOT NULL  AND Action='F'
carlos@0
   889
      )
carlos@0
   890
      ;
carlos@0
   891
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   892
    DBMS_OUTPUT.PUT_LINE('  trl rows updated: ' || v_rowcount) ;
carlos@0
   893
    -- Sync Names = Task
carlos@0
   894
    DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Tasks') ;
carlos@0
   895
    UPDATE AD_MENU
carlos@0
   896
      SET NAME=
carlos@0
   897
      (SELECT NAME FROM AD_TASK f WHERE AD_MENU.AD_Task_ID=f.AD_Task_ID)
carlos@0
   898
      , Description=
carlos@0
   899
      (SELECT Description FROM AD_TASK f WHERE AD_MENU.AD_Task_ID=f.AD_Task_ID)
carlos@0
   900
    WHERE AD_Task_ID IS NOT NULL  AND Action='T';
carlos@0
   901
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   902
    DBMS_OUTPUT.PUT_LINE('  rows updated: ' || v_rowcount) ;
carlos@0
   903
    UPDATE AD_MENU_TRL
carlos@0
   904
      SET NAME=
carlos@0
   905
      (SELECT ft.NAME
carlos@0
   906
      FROM AD_TASK_TRL ft, AD_MENU m
carlos@0
   907
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Task_ID=ft.AD_Task_ID
carlos@0
   908
      AND AD_MENU_TRL.AD_LANGUAGE=ft.AD_LANGUAGE
carlos@0
   909
      )
carlos@0
   910
      , Description=
carlos@0
   911
      (SELECT ft.Description
carlos@0
   912
      FROM AD_TASK_TRL ft, AD_MENU m
carlos@0
   913
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Task_ID=ft.AD_Task_ID
carlos@0
   914
      AND AD_MENU_TRL.AD_LANGUAGE=ft.AD_LANGUAGE
carlos@0
   915
      )
carlos@0
   916
      , IsTranslated=
carlos@0
   917
      (SELECT ft.IsTranslated
carlos@0
   918
      FROM AD_TASK_TRL ft, AD_MENU m
carlos@0
   919
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Task_ID=ft.AD_Task_ID
carlos@0
   920
      AND AD_MENU_TRL.AD_LANGUAGE=ft.AD_LANGUAGE
carlos@0
   921
      )
carlos@0
   922
    WHERE EXISTS
carlos@0
   923
      (SELECT *
carlos@0
   924
      FROM AD_TASK_TRL ft, AD_MENU m
carlos@0
   925
      WHERE AD_MENU_TRL.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Task_ID=ft.AD_Task_ID
carlos@0
   926
      AND AD_MENU_TRL.AD_LANGUAGE=ft.AD_LANGUAGE  AND m.AD_Task_ID IS NOT NULL  AND Action='T'
carlos@0
   927
      )
carlos@0
   928
      ;
carlos@0
   929
    v_rowcount:=SQL%ROWCOUNT;
carlos@0
   930
    DBMS_OUTPUT.PUT_LINE('  trl rows updated: ' || v_rowcount) ;
carlos@0
   931
    --<<FINISH_PROCESS>>
carlos@0
   932
    IF(p_PInstance_ID IS NOT NULL) THEN
carlos@0
   933
      --  Update AD_PInstance
carlos@0
   934
      DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
   935
      Ad_Update_Pinstance(p_PInstance_ID, NULL, 'N', v_Result, v_Message) ;
carlos@0
   936
    END IF;
carlos@0
   937
    RETURN;
carlos@0
   938
  END; --BODY
carlos@0
   939
EXCEPTION
carlos@0
   940
WHEN OTHERS THEN
carlos@0
   941
  v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
   942
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
   943
  ROLLBACK;
carlos@0
   944
  IF(p_PInstance_ID IS NOT NULL) THEN
carlos@0
   945
    Ad_Update_Pinstance(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
   946
  END IF;
carlos@0
   947
  RETURN;
carlos@0
   948
END Ad_Synchronize]]>
carlos@0
   949
</body>
carlos@0
   950
</function>
carlos@0
   951
</database>