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