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