database/model/functions/C_ACCTSCHEMA_DEFAULT_COPY.xml
author Antonio Moreno <antonio.moreno@openbravo.com>
Tue, 22 Apr 2008 13:22:11 +0000
changeset 735 daced7e311c9
parent 636 2e910559bbda
permissions -rw-r--r--
Structure after exporting from PostgreSQL with new dbsourcemanager
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION C_ACCTSCHEMA_DEFAULT_COPY">
adrian@94
     3
    <function name="C_ACCTSCHEMA_DEFAULT_COPY" type="NULL">
antonio@735
     4
      <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
antonio@735
     7
      <parameter name="p_client_id" type="NUMERIC" mode="in">
antonio@735
     8
        <default><![CDATA[NULL]]></default>
antonio@735
     9
      </parameter>
gorkaion@239
    10
      <body><![CDATA[/*************************************************************************
carlos@0
    11
  * The contents of this file are subject to the Compiere License
carlos@0
    12
  * Version 2.5.0 ("License"); You may not use this file except in
carlos@0
    13
  * compliance with the License. You may obtain a copy of the License at
carlos@0
    14
  * http://www.compiere.org/license.html
carlos@0
    15
  * Software distributed under the License is distributed on an
carlos@0
    16
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
carlos@0
    17
  * implied. See the License for the specific language governing rights
carlos@0
    18
  * and limitations under the License.
gorkaion@239
    19
  * The Original Code is  Compiere  ERP &  Business Solution
carlos@0
    20
  * The Initial Developer of the Original Code is Jorg Janke  and ComPiere,
carlos@0
    21
  Inc.
carlos@0
    22
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
carlos@0
    23
  * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
carlos@0
    24
  * All Rights Reserved.
carlos@0
    25
  * Contributor(s): Openbravo SL
carlos@0
    26
  * Contributions are Copyright (C) 1999-2005 Openbravo, S.L
carlos@0
    27
  *************************************************************************
carlos@0
    28
  * $Id: C_AcctSchema_Default_Copy.sql,v 1.2 2001/11/26 05:25:18 jjanke Exp $
carlos@0
    29
  ***
carlos@0
    30
  * Title: Copy Accounting Schema information to elements
carlos@0
    31
  * Description:
carlos@0
    32
  *   Existing entities are overwritten) cascade all!
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_Record_ID NUMBER;
carlos@0
    38
  -- Parameter
carlos@0
    39
  TYPE RECORD IS REF CURSOR;
carlos@0
    40
    Cur_Parameter RECORD;
carlos@0
    41
    --
carlos@0
    42
    v_AD_Client_ID NUMBER;
carlos@0
    43
    --
carlos@0
    44
    Cur_Acct RECORD;
carlos@0
    45
    --
carlos@0
    46
    v_Updated NUMBER:=0;
carlos@0
    47
    v_Created NUMBER:=0;
carlos@0
    48
    v_Updated_Total NUMBER:=0;
carlos@0
    49
    v_Created_Total NUMBER:=0;
carlos@0
    50
    v_rowcount NUMBER;
carlos@0
    51
  BEGIN
carlos@0
    52
    --  Update AD_PInstance
carlos@0
    53
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
carlos@0
    54
    v_ResultStr:='PInstanceNotFound';
carlos@0
    55
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    56
  BEGIN --BODY
carlos@0
    57
    -- Get Parameters
carlos@0
    58
    v_ResultStr:='ReadingParameters';
carlos@0
    59
    FOR Cur_Parameter IN
carlos@0
    60
      (SELECT i.Record_ID,
carlos@0
    61
        p.ParameterName,
carlos@0
    62
        p.P_String,
carlos@0
    63
        p.P_Number,
carlos@0
    64
        p.P_Date
carlos@0
    65
      FROM AD_PInstance i
carlos@0
    66
      LEFT JOIN AD_PInstance_Para p
carlos@0
    67
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    68
      WHERE i.AD_PInstance_ID=p_PInstance_ID
carlos@0
    69
      ORDER BY p.SeqNo
carlos@0
    70
      )
carlos@0
    71
    LOOP
carlos@0
    72
      v_Record_ID:=Cur_Parameter.Record_ID;
carlos@0
    73
      IF(Cur_Parameter.ParameterName='AD_Client_ID') THEN
carlos@0
    74
        v_AD_Client_ID:=Cur_Parameter.P_Number;
carlos@0
    75
        DBMS_OUTPUT.PUT_LINE('  AD_Client_ID=' || v_AD_Client_ID) ;
carlos@0
    76
      ELSE
carlos@0
    77
        DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ;
carlos@0
    78
      END IF;
carlos@0
    79
    END LOOP; -- Get Parameter
carlos@0
    80
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
carlos@0
    81
    -- Direct Calls
carlos@0
    82
    IF(p_Client_ID IS NOT NULL) THEN
carlos@0
    83
      v_AD_Client_ID:=p_Client_ID;
carlos@0
    84
      DBMS_OUTPUT.PUT_LINE('  AD_Client_ID=' || v_AD_Client_ID) ;
carlos@0
    85
    END IF;
carlos@0
    86
    /**
carlos@0
    87
    * For all Accounting Schema
carlos@0
    88
    */
carlos@0
    89
    FOR Cur_Acct IN
carlos@0
    90
      (SELECT * FROM C_AcctSchema_Default WHERE AD_Client_ID=v_AD_Client_ID)
carlos@0
    91
    LOOP
carlos@0
    92
      -- Update existing Product Category
carlos@0
    93
      UPDATE M_Product_Category_Acct
carlos@0
    94
        SET P_Revenue_Acct=Cur_Acct.P_Revenue_Acct,
carlos@0
    95
        P_Expense_Acct=Cur_Acct.P_Expense_Acct,
carlos@0
    96
        P_Asset_Acct=Cur_Acct.P_Asset_Acct,
carlos@0
    97
        P_CoGs_Acct=Cur_Acct.P_CoGs_Acct,
carlos@0
    98
        P_PurchasePriceVariance_Acct=Cur_Acct.P_PurchasePriceVariance_Acct,
carlos@0
    99
        P_InvoicePriceVariance_Acct=Cur_Acct.P_InvoicePriceVariance_Acct,
carlos@0
   100
        P_TradeDiscountRec_Acct=Cur_Acct.P_TradeDiscountRec_Acct,
carlos@0
   101
        P_TradeDiscountGrant_Acct=Cur_Acct.P_TradeDiscountGrant_Acct,
antonio@735
   102
        Updated=now(),
carlos@0
   103
        UpdatedBy=0
carlos@0
   104
      WHERE M_Product_Category_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   105
        AND EXISTS
carlos@0
   106
        (SELECT *
carlos@0
   107
        FROM M_Product_Category p
carlos@0
   108
        WHERE p.M_Product_Category_ID=M_Product_Category_Acct.M_Product_Category_ID
carlos@0
   109
        )
carlos@0
   110
        ;
carlos@0
   111
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   112
      v_Updated:=v_rowcount;
carlos@0
   113
      -- Insert new Product Category
carlos@0
   114
      INSERT
carlos@0
   115
      INTO M_Product_Category_Acct
carlos@0
   116
        (
carlos@0
   117
          M_Product_Category_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   118
          IsActive, Created, CreatedBy, Updated,
carlos@0
   119
          UpdatedBy, P_Revenue_Acct, P_Expense_Acct, P_Asset_Acct,
carlos@0
   120
          P_CoGs_Acct, P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct,
carlos@0
   121
          P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct
carlos@0
   122
        )
carlos@0
   123
      SELECT p.M_Product_Category_ID, Cur_Acct.C_AcctSchema_ID, p.AD_Client_ID, p.AD_Org_ID,
carlos@0
   124
        'Y', now(), 0, now(),
carlos@0
   125
        0, Cur_Acct.P_Revenue_Acct, Cur_Acct.P_Expense_Acct,
carlos@0
   126
        Cur_Acct.P_Asset_Acct, Cur_Acct.P_CoGs_Acct, Cur_Acct.P_PurchasePriceVariance_Acct,
carlos@0
   127
        Cur_Acct.P_InvoicePriceVariance_Acct, Cur_Acct.P_TradeDiscountRec_Acct, Cur_Acct.P_TradeDiscountGrant_Acct
carlos@0
   128
      FROM M_Product_Category p
carlos@0
   129
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   130
        AND NOT EXISTS
carlos@0
   131
        (SELECT *
carlos@0
   132
        FROM M_Product_Category_Acct pa
carlos@0
   133
        WHERE pa.M_Product_Category_ID=p.M_Product_Category_ID
carlos@0
   134
          AND pa.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   135
        )
carlos@0
   136
        ;
carlos@0
   137
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   138
      v_Created:=v_rowcount;
carlos@0
   139
      DBMS_OUTPUT.PUT_LINE('Product Category = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   140
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   141
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   142
      -- Business Partner Group
carlos@0
   143
      UPDATE C_BP_Group_Acct
carlos@0
   144
        SET C_Receivable_Acct=Cur_Acct.C_Receivable_Acct,
carlos@0
   145
        C_PrePayment_Acct=Cur_Acct.C_PrePayment_Acct,
carlos@0
   146
        V_Liability_Acct=Cur_Acct.V_Liability_Acct,
carlos@0
   147
        V_Liability_Services_Acct=Cur_Acct.V_Liability_Services_Acct,
carlos@0
   148
        V_PrePayment_Acct=Cur_Acct.V_PrePayment_Acct,
carlos@0
   149
        PayDiscount_Exp_Acct=Cur_Acct.PayDiscount_Exp_Acct,
carlos@0
   150
        PayDiscount_Rev_Acct=Cur_Acct.PayDiscount_Rev_Acct,
carlos@0
   151
        WriteOff_Acct=Cur_Acct.WriteOff_Acct,
carlos@0
   152
        UnRealizedGain_Acct=Cur_Acct.UnRealizedGain_Acct,
carlos@0
   153
        UnRealizedLoss_Acct=Cur_Acct.UnRealizedLoss_Acct,
carlos@0
   154
        RealizedGain_Acct=Cur_Acct.RealizedGain_Acct,
carlos@0
   155
        RealizedLoss_Acct=Cur_Acct.RealizedLoss_Acct,
carlos@0
   156
        NotInvoicedReceipts_Acct=Cur_Acct.NotInvoicedReceipts_Acct,
carlos@0
   157
        UnEarnedRevenue_Acct=Cur_Acct.UnEarnedRevenue_Acct,
carlos@0
   158
        NotInvoicedRevenue_Acct=Cur_Acct.NotInvoicedRevenue_Acct,
carlos@0
   159
        NotInvoicedReceivables_Acct=Cur_Acct.NotInvoicedReceivables_Acct,
antonio@735
   160
        Updated=now(),
carlos@0
   161
        UpdatedBy=0,
carlos@0
   162
        Status=Cur_Acct.Status
carlos@0
   163
      WHERE C_BP_Group_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   164
        AND EXISTS
carlos@0
   165
        (SELECT *
carlos@0
   166
        FROM C_BP_Group_Acct x
carlos@0
   167
        WHERE x.C_BP_Group_ID=C_BP_Group_Acct.C_BP_Group_ID
carlos@0
   168
        )
carlos@0
   169
        ;
carlos@0
   170
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   171
      v_Updated:=v_rowcount;
carlos@0
   172
      -- Insert new
carlos@0
   173
      INSERT
carlos@0
   174
      INTO C_BP_Group_Acct
carlos@0
   175
        (
eduardo@636
   176
          C_BP_Group_Acct_ID, C_BP_Group_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   177
          IsActive, Created, CreatedBy, Updated,
carlos@0
   178
          UpdatedBy, C_Receivable_Acct, C_PrePayment_Acct, V_Liability_Acct,
carlos@0
   179
          V_Liability_Services_Acct, V_PrePayment_Acct, PayDiscount_Exp_Acct, PayDiscount_Rev_Acct,
carlos@0
   180
          WriteOff_Acct, UnRealizedGain_Acct, UnRealizedLoss_Acct, RealizedGain_Acct,
carlos@0
   181
          RealizedLoss_Acct, NotInvoicedReceipts_Acct, UnEarnedRevenue_Acct, NotInvoicedRevenue_Acct,
carlos@0
   182
          NotInvoicedReceivables_Acct, Status
carlos@0
   183
        )
eduardo@636
   184
      SELECT AD_SEQUENCE_NEXTNO('C_BP_Group_Acct'), x.C_BP_Group_ID,
carlos@0
   185
        Cur_Acct.C_AcctSchema_ID, x.AD_Client_ID, x.AD_Org_ID, 'Y',
carlos@0
   186
        now(), 0, now(), 0,
carlos@0
   187
        Cur_Acct.C_Receivable_Acct, Cur_Acct.C_PrePayment_Acct, Cur_Acct.V_Liability_Acct, Cur_Acct.V_Liability_Services_Acct,
carlos@0
   188
        Cur_Acct.V_PrePayment_Acct, Cur_Acct.PayDiscount_Exp_Acct, Cur_Acct.PayDiscount_Rev_Acct, Cur_Acct.WriteOff_Acct,
carlos@0
   189
        Cur_Acct.UnRealizedGain_Acct, Cur_Acct.UnRealizedLoss_Acct, Cur_Acct.RealizedGain_Acct, Cur_Acct.RealizedLoss_Acct,
carlos@0
   190
        Cur_Acct.NotInvoicedReceipts_Acct, Cur_Acct.UnEarnedRevenue_Acct, Cur_Acct.NotInvoicedRevenue_Acct, Cur_Acct.NotInvoicedReceivables_Acct,
carlos@0
   191
        Cur_Acct.Status
carlos@0
   192
      FROM C_BP_Group x
carlos@0
   193
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   194
        AND NOT EXISTS
carlos@0
   195
        (SELECT *
carlos@0
   196
        FROM C_BP_Group_Acct a
carlos@0
   197
        WHERE a.C_BP_Group_ID=x.C_BP_Group_ID
carlos@0
   198
          AND a.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   199
        )
carlos@0
   200
        ;
carlos@0
   201
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   202
      v_Created:=v_rowcount;
carlos@0
   203
      DBMS_OUTPUT.PUT_LINE('Business Group = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   204
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   205
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   206
      -- Business Partner - Employee
carlos@0
   207
      UPDATE C_BP_Employee_Acct
carlos@0
   208
        SET E_Expense_Acct=Cur_Acct.E_Expense_Acct,
carlos@0
   209
        E_PrePayment_Acct=Cur_Acct.E_PrePayment_Acct,
antonio@735
   210
        Updated=now(),
carlos@0
   211
        UpdatedBy=0
carlos@0
   212
      WHERE C_BP_Employee_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   213
        AND EXISTS
carlos@0
   214
        (SELECT *
carlos@0
   215
        FROM C_BP_Employee_Acct x
carlos@0
   216
        WHERE x.C_BPartner_ID=C_BP_Employee_Acct.C_BPartner_ID
carlos@0
   217
        )
carlos@0
   218
        ;
carlos@0
   219
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   220
      v_Updated:=v_rowcount;
carlos@0
   221
      -- Insert new
carlos@0
   222
      INSERT
carlos@0
   223
      INTO C_BP_Employee_Acct
carlos@0
   224
        (
carlos@0
   225
          C_BPartner_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   226
          IsActive, Created, CreatedBy, Updated,
carlos@0
   227
          UpdatedBy, E_Expense_Acct, E_PrePayment_Acct
carlos@0
   228
        )
carlos@0
   229
      SELECT x.C_BPartner_ID,
carlos@0
   230
        Cur_Acct.C_AcctSchema_ID, x.AD_Client_ID, x.AD_Org_ID, 'Y',
carlos@0
   231
        now(), 0, now(), 0,
carlos@0
   232
        Cur_Acct.E_Expense_Acct, Cur_Acct.E_PrePayment_Acct
carlos@0
   233
      FROM C_BPartner x
carlos@0
   234
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   235
        AND NOT EXISTS
carlos@0
   236
        (SELECT *
carlos@0
   237
        FROM C_BP_Employee_Acct a
carlos@0
   238
        WHERE a.C_BPartner_ID=x.C_BPartner_ID
carlos@0
   239
          AND a.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   240
        )
carlos@0
   241
        ;
carlos@0
   242
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   243
      v_Created:=v_rowcount;
carlos@0
   244
      DBMS_OUTPUT.PUT_LINE('Employees = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   245
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   246
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   247
      -- Warehouse
carlos@0
   248
      UPDATE M_Warehouse_Acct
carlos@0
   249
        SET W_Inventory_Acct=Cur_Acct.W_Inventory_Acct,
carlos@0
   250
        W_Differences_Acct=Cur_Acct.W_Differences_Acct,
carlos@0
   251
        W_Revaluation_Acct=Cur_Acct.W_Revaluation_Acct,
carlos@0
   252
        W_InvActualAdjust_Acct=Cur_Acct.W_InvActualAdjust_Acct,
antonio@735
   253
        Updated=now(),
carlos@0
   254
        UpdatedBy=0
carlos@0
   255
      WHERE M_Warehouse_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   256
        AND EXISTS
carlos@0
   257
        (SELECT *
carlos@0
   258
        FROM M_Warehouse_Acct x
carlos@0
   259
        WHERE x.M_Warehouse_ID=M_Warehouse_Acct.M_Warehouse_ID
carlos@0
   260
        )
carlos@0
   261
        ;
carlos@0
   262
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   263
      v_Updated:=v_rowcount;
carlos@0
   264
      -- Insert new
carlos@0
   265
      INSERT
carlos@0
   266
      INTO M_Warehouse_Acct
carlos@0
   267
        (
carlos@0
   268
          M_Warehouse_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   269
          IsActive, Created, CreatedBy, Updated,
carlos@0
   270
          UpdatedBy, W_Inventory_Acct, W_Differences_Acct, W_Revaluation_Acct,
carlos@0
   271
          W_InvActualAdjust_Acct
carlos@0
   272
        )
carlos@0
   273
      SELECT x.M_Warehouse_ID,
carlos@0
   274
        Cur_Acct.C_AcctSchema_ID, x.AD_Client_ID, x.AD_Org_ID, 'Y',
carlos@0
   275
        now(), 0, now(), 0,
carlos@0
   276
        Cur_Acct.W_Inventory_Acct, Cur_Acct.W_Differences_Acct, Cur_Acct.W_Revaluation_Acct, Cur_Acct.W_InvActualAdjust_Acct
carlos@0
   277
      FROM M_Warehouse x
carlos@0
   278
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   279
        AND NOT EXISTS
carlos@0
   280
        (SELECT *
carlos@0
   281
        FROM M_Warehouse_Acct a
carlos@0
   282
        WHERE a.M_Warehouse_ID=x.M_Warehouse_ID
carlos@0
   283
          AND a.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   284
        )
carlos@0
   285
        ;
carlos@0
   286
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   287
      v_Created:=v_rowcount;
carlos@0
   288
      DBMS_OUTPUT.PUT_LINE('Warehouse = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   289
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   290
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   291
      -- Project
carlos@0
   292
      UPDATE C_Project_Acct
carlos@0
   293
        SET PJ_Asset_Acct=Cur_Acct.PJ_Asset_Acct,
carlos@0
   294
        PJ_WIP_Acct=Cur_Acct.PJ_Asset_Acct,
antonio@735
   295
        Updated=now(),
carlos@0
   296
        UpdatedBy=0
carlos@0
   297
      WHERE C_Project_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   298
        AND EXISTS
carlos@0
   299
        (SELECT *
carlos@0
   300
        FROM C_Project_Acct x
carlos@0
   301
        WHERE x.C_Project_ID=C_Project_Acct.C_Project_ID
carlos@0
   302
        )
carlos@0
   303
        ;
carlos@0
   304
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   305
      v_Updated:=v_rowcount;
carlos@0
   306
      -- Insert new
carlos@0
   307
      INSERT
carlos@0
   308
      INTO C_Project_Acct
carlos@0
   309
        (
carlos@0
   310
          C_Project_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   311
          IsActive, Created, CreatedBy, Updated,
carlos@0
   312
          UpdatedBy, PJ_Asset_Acct, PJ_WIP_Acct
carlos@0
   313
        )
carlos@0
   314
      SELECT x.C_Project_ID,
carlos@0
   315
        Cur_Acct.C_AcctSchema_ID, x.AD_Client_ID, x.AD_Org_ID, 'Y',
carlos@0
   316
        now(), 0, now(), 0,
carlos@0
   317
        Cur_Acct.PJ_Asset_Acct, Cur_Acct.PJ_WIP_Acct
carlos@0
   318
      FROM C_Project x
carlos@0
   319
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   320
        AND NOT EXISTS
carlos@0
   321
        (SELECT *
carlos@0
   322
        FROM C_Project_Acct a
carlos@0
   323
        WHERE a.C_Project_ID=x.C_Project_ID
carlos@0
   324
          AND a.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   325
        )
carlos@0
   326
        ;
carlos@0
   327
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   328
      v_Created:=v_rowcount;
carlos@0
   329
      DBMS_OUTPUT.PUT_LINE('Project = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   330
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   331
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   332
      -- Tax
carlos@0
   333
      UPDATE C_Tax_Acct
carlos@0
   334
        SET T_Due_Acct=Cur_Acct.T_Due_Acct,
carlos@0
   335
        T_Liability_Acct=Cur_Acct.T_Liability_Acct,
carlos@0
   336
        T_Credit_Acct=Cur_Acct.T_Credit_Acct,
carlos@0
   337
        T_Receivables_Acct=Cur_Acct.T_Receivables_Acct,
carlos@0
   338
        T_Expense_Acct=Cur_Acct.T_Expense_Acct,
antonio@735
   339
        Updated=now(),
carlos@0
   340
        UpdatedBy=0
carlos@0
   341
      WHERE C_Tax_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   342
        AND EXISTS
carlos@0
   343
        (SELECT * FROM C_Tax_Acct x WHERE x.C_Tax_ID=C_Tax_Acct.C_Tax_ID)
carlos@0
   344
        ;
carlos@0
   345
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   346
      v_Updated:=v_rowcount;
carlos@0
   347
      -- Insert new
carlos@0
   348
      INSERT
carlos@0
   349
      INTO C_Tax_Acct
carlos@0
   350
        (
carlos@0
   351
          C_Tax_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   352
          IsActive, Created, CreatedBy, Updated,
carlos@0
   353
          UpdatedBy, T_Due_Acct, T_Liability_Acct, T_Credit_Acct,
carlos@0
   354
          T_Receivables_Acct, T_Expense_Acct
carlos@0
   355
        )
carlos@0
   356
      SELECT x.C_Tax_ID, Cur_Acct.C_AcctSchema_ID, x.AD_Client_ID, x.AD_Org_ID,
carlos@0
   357
        'Y', now(), 0, now(), 0,
carlos@0
   358
        Cur_Acct.T_Due_Acct, Cur_Acct.T_Liability_Acct, Cur_Acct.T_Credit_Acct, Cur_Acct.T_Receivables_Acct,
carlos@0
   359
        Cur_Acct.T_Expense_Acct
carlos@0
   360
      FROM C_Tax x
carlos@0
   361
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   362
        AND NOT EXISTS
carlos@0
   363
        (SELECT *
carlos@0
   364
        FROM C_Tax_Acct a
carlos@0
   365
        WHERE a.C_Tax_ID=x.C_Tax_ID
carlos@0
   366
          AND a.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   367
        )
carlos@0
   368
        ;
carlos@0
   369
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   370
      v_Created:=v_rowcount;
carlos@0
   371
      DBMS_OUTPUT.PUT_LINE('Tax = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   372
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   373
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   374
      -- BankAccount
carlos@0
   375
      UPDATE C_BankAccount_Acct
carlos@0
   376
        SET B_InTransit_Acct=Cur_Acct.B_InTransit_Acct,
carlos@0
   377
        B_Asset_Acct=Cur_Acct.B_Asset_Acct,
carlos@0
   378
        B_Expense_Acct=Cur_Acct.B_Expense_Acct,
carlos@0
   379
        B_InterestRev_Acct=Cur_Acct.B_InterestRev_Acct,
carlos@0
   380
        B_InterestExp_Acct=Cur_Acct.B_InterestExp_Acct,
carlos@0
   381
        B_UnIdentified_Acct=Cur_Acct.B_UnIdentified_Acct,
carlos@0
   382
        B_UnAllocatedCash_Acct=Cur_Acct.B_UnAllocatedCash_Acct,
carlos@0
   383
        B_PaymentSelect_Acct=Cur_Acct.B_PaymentSelect_Acct,
carlos@0
   384
        B_SettlementGain_Acct=Cur_Acct.B_SettlementGain_Acct,
carlos@0
   385
        B_SettlementLoss_Acct=Cur_Acct.B_SettlementLoss_Acct,
carlos@0
   386
        B_RevaluationGain_Acct=Cur_Acct.B_RevaluationGain_Acct,
carlos@0
   387
        B_RevaluationLoss_Acct=Cur_Acct.B_RevaluationLoss_Acct,
antonio@735
   388
        Updated=now(),
carlos@0
   389
        UpdatedBy=0
carlos@0
   390
      WHERE C_BankAccount_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   391
        AND EXISTS
carlos@0
   392
        (SELECT *
carlos@0
   393
        FROM C_BankAccount_Acct x
carlos@0
   394
        WHERE x.C_BankAccount_ID=C_BankAccount_Acct.C_BankAccount_ID
carlos@0
   395
        )
carlos@0
   396
        ;
carlos@0
   397
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   398
      v_Updated:=v_rowcount;
carlos@0
   399
      -- Insert new
carlos@0
   400
      INSERT
carlos@0
   401
      INTO C_BankAccount_Acct
carlos@0
   402
        (
carlos@0
   403
          C_BankAccount_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   404
          IsActive, Created, CreatedBy, Updated, UpdatedBy,
carlos@0
   405
          B_InTransit_Acct, B_Asset_Acct, B_Expense_Acct, B_InterestRev_Acct,
carlos@0
   406
          B_InterestExp_Acct, B_UnIdentified_Acct, B_UnAllocatedCash_Acct, B_PaymentSelect_Acct,
carlos@0
   407
          B_SettlementGain_Acct, B_SettlementLoss_Acct, B_RevaluationGain_Acct, B_RevaluationLoss_Acct
carlos@0
   408
        )
carlos@0
   409
      SELECT x.C_BankAccount_ID, Cur_Acct.C_AcctSchema_ID, x.AD_Client_ID, x.AD_Org_ID,
carlos@0
   410
        'Y', now(), 0, now(),
carlos@0
   411
        0, Cur_Acct.B_InTransit_Acct, Cur_Acct.B_Asset_Acct, Cur_Acct.B_Expense_Acct,
carlos@0
   412
        Cur_Acct.B_InterestRev_Acct, Cur_Acct.B_InterestExp_Acct, Cur_Acct.B_UnIdentified_Acct, Cur_Acct.B_UnAllocatedCash_Acct,
carlos@0
   413
        Cur_Acct.B_PaymentSelect_Acct, Cur_Acct.B_SettlementGain_Acct, Cur_Acct.B_SettlementLoss_Acct, Cur_Acct.B_RevaluationGain_Acct,
carlos@0
   414
        Cur_Acct.B_RevaluationLoss_Acct
carlos@0
   415
      FROM C_BankAccount x
carlos@0
   416
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   417
        AND NOT EXISTS
carlos@0
   418
        (SELECT *
carlos@0
   419
        FROM C_BankAccount_Acct a
carlos@0
   420
        WHERE a.C_BankAccount_ID=x.C_BankAccount_ID
carlos@0
   421
          AND a.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   422
        )
carlos@0
   423
        ;
carlos@0
   424
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   425
      v_Created:=v_rowcount;
carlos@0
   426
      DBMS_OUTPUT.PUT_LINE('Bank Account = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   427
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   428
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   429
      -- Withholding
carlos@0
   430
      UPDATE C_Withholding_Acct
carlos@0
   431
        SET Withholding_Acct=Cur_Acct.Withholding_Acct,
antonio@735
   432
        Updated=now(),
carlos@0
   433
        UpdatedBy=0
carlos@0
   434
      WHERE C_Withholding_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   435
        AND EXISTS
carlos@0
   436
        (SELECT *
carlos@0
   437
        FROM C_Withholding_Acct x
carlos@0
   438
        WHERE x.C_Withholding_ID=C_Withholding_Acct.C_Withholding_ID
carlos@0
   439
        )
carlos@0
   440
        ;
carlos@0
   441
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   442
      v_Updated:=v_rowcount;
carlos@0
   443
      -- Insert new
carlos@0
   444
      INSERT
carlos@0
   445
      INTO C_Withholding_Acct
carlos@0
   446
        (
carlos@0
   447
          C_Withholding_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   448
          IsActive, Created, CreatedBy, Updated,
carlos@0
   449
          UpdatedBy, Withholding_Acct
carlos@0
   450
        )
carlos@0
   451
      SELECT x.C_Withholding_ID, Cur_Acct.C_AcctSchema_ID, x.AD_Client_ID, x.AD_Org_ID,
carlos@0
   452
        'Y', now(), 0, now(),
carlos@0
   453
        0, Cur_Acct.Withholding_Acct
carlos@0
   454
      FROM C_Withholding x
carlos@0
   455
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   456
        AND NOT EXISTS
carlos@0
   457
        (SELECT *
carlos@0
   458
        FROM C_Withholding_Acct a
carlos@0
   459
        WHERE a.C_Withholding_ID=x.C_Withholding_ID
carlos@0
   460
          AND a.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   461
        )
carlos@0
   462
        ;
carlos@0
   463
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   464
      v_Created:=v_rowcount;
carlos@0
   465
      DBMS_OUTPUT.PUT_LINE('Withholding = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   466
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   467
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   468
      -- Charge
carlos@0
   469
      UPDATE C_Charge_Acct
carlos@0
   470
        SET Ch_Expense_Acct=Cur_Acct.Ch_Expense_Acct,
carlos@0
   471
        Ch_Revenue_Acct=Cur_Acct.Ch_Revenue_Acct,
antonio@735
   472
        Updated=now(),
carlos@0
   473
        UpdatedBy=0
carlos@0
   474
      WHERE C_Charge_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   475
        AND EXISTS
carlos@0
   476
        (SELECT * FROM C_Charge_Acct x WHERE x.C_Charge_ID=C_Charge_Acct.C_Charge_ID)
carlos@0
   477
        ;
carlos@0
   478
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   479
      v_Updated:=v_rowcount;
carlos@0
   480
      -- Insert new
carlos@0
   481
      INSERT
carlos@0
   482
      INTO C_Charge_Acct
carlos@0
   483
        (
carlos@0
   484
          C_Charge_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   485
          IsActive, Created, CreatedBy, Updated,
carlos@0
   486
          UpdatedBy, Ch_Expense_Acct, Ch_Revenue_Acct
carlos@0
   487
        )
carlos@0
   488
      SELECT x.C_Charge_ID,
carlos@0
   489
        Cur_Acct.C_AcctSchema_ID, x.AD_Client_ID, x.AD_Org_ID, 'Y',
carlos@0
   490
        now(), 0, now(), 0,
carlos@0
   491
        Cur_Acct.Ch_Expense_Acct, Cur_Acct.Ch_Revenue_Acct
carlos@0
   492
      FROM C_Charge x
carlos@0
   493
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   494
        AND NOT EXISTS
carlos@0
   495
        (SELECT *
carlos@0
   496
        FROM C_Charge_Acct a
carlos@0
   497
        WHERE a.C_Charge_ID=x.C_Charge_ID
carlos@0
   498
          AND a.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   499
        )
carlos@0
   500
        ;
carlos@0
   501
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   502
      v_Created:=v_rowcount;
carlos@0
   503
      DBMS_OUTPUT.PUT_LINE('Charge = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   504
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   505
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   506
      -- Cashbook
carlos@0
   507
      UPDATE C_Cashbook_Acct
carlos@0
   508
        SET CB_Asset_Acct=Cur_Acct.CB_Asset_Acct,
carlos@0
   509
        CB_Differences_Acct=Cur_Acct.CB_Differences_Acct,
carlos@0
   510
        CB_CashTransfer_Acct=Cur_Acct.CB_CashTransfer_Acct,
carlos@0
   511
        CB_Expense_Acct=Cur_Acct.CB_Expense_Acct,
carlos@0
   512
        CB_Receipt_Acct=Cur_Acct.CB_Receipt_Acct,
antonio@735
   513
        Updated=now(),
carlos@0
   514
        UpdatedBy=0
carlos@0
   515
      WHERE C_Cashbook_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   516
        AND EXISTS
carlos@0
   517
        (SELECT *
carlos@0
   518
        FROM C_Cashbook_Acct x
carlos@0
   519
        WHERE x.C_Cashbook_ID=C_Cashbook_Acct.C_Cashbook_ID
carlos@0
   520
        )
carlos@0
   521
        ;
carlos@0
   522
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   523
      v_Updated:=v_rowcount;
carlos@0
   524
      -- Insert new
carlos@0
   525
      INSERT
carlos@0
   526
      INTO C_Cashbook_Acct
carlos@0
   527
        (
carlos@0
   528
          C_Cashbook_ID, C_AcctSchema_ID, AD_Client_ID, AD_Org_ID,
carlos@0
   529
          IsActive, Created, CreatedBy, Updated,
carlos@0
   530
          UpdatedBy, CB_Asset_Acct, CB_Differences_Acct, CB_CashTransfer_Acct,
carlos@0
   531
          CB_Expense_Acct, CB_Receipt_Acct
carlos@0
   532
        )
carlos@0
   533
      SELECT x.C_Cashbook_ID,
carlos@0
   534
        Cur_Acct.C_AcctSchema_ID, x.AD_Client_ID, x.AD_Org_ID, 'Y',
carlos@0
   535
        now(), 0, now(), 0,
carlos@0
   536
        Cur_Acct.CB_Asset_Acct, Cur_Acct.CB_Differences_Acct, Cur_Acct.CB_CashTransfer_Acct, Cur_Acct.CB_Expense_Acct,
carlos@0
   537
        Cur_Acct.CB_Receipt_Acct
carlos@0
   538
      FROM C_Cashbook x
carlos@0
   539
      WHERE AD_Client_ID=Cur_Acct.AD_Client_ID
carlos@0
   540
        AND NOT EXISTS
carlos@0
   541
        (SELECT *
carlos@0
   542
        FROM C_Cashbook_Acct a
carlos@0
   543
        WHERE a.C_Cashbook_ID=x.C_Cashbook_ID
carlos@0
   544
          AND a.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
   545
        )
carlos@0
   546
        ;
carlos@0
   547
      v_rowcount:=SQL%ROWCOUNT;
carlos@0
   548
      v_Created:=v_rowcount;
carlos@0
   549
      DBMS_OUTPUT.PUT_LINE('Cashbook = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   550
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   551
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   552
    END LOOP;
carlos@0
   553
    v_Message:='@Created@=' || v_Created_Total || ', @Updated@=' || v_Updated_Total;
gorkaion@239
   554
    --<<FINISH_PROCESS>>
carlos@0
   555
    --  Update AD_PInstance
carlos@0
   556
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
   557
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 1, v_Message) ;
carlos@0
   558
    RETURN;
carlos@0
   559
  END; --BODY
carlos@0
   560
EXCEPTION
carlos@0
   561
WHEN OTHERS THEN
carlos@0
   562
  v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
   563
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
   564
  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
   565
  RETURN;
antonio@735
   566
END C_ACCTSCHEMA_DEFAULT_COPY
gorkaion@239
   567
]]></body>
adrian@94
   568
    </function>
adrian@94
   569
  </database>