src-db/database/model/functions/A_ASSET_GROUP_ACCT_COPY.xml
author Antonio Moreno <antonio.moreno@openbravo.com>
Wed, 23 Apr 2008 17:34:12 +0000
changeset 756 ae11e4610537
parent 735 database/model/functions/A_ASSET_GROUP_ACCT_COPY.xml@daced7e311c9
child 1605 8a0fe0193bef
permissions -rw-r--r--
Moved database folder to src-db folder
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION A_ASSET_GROUP_ACCT_COPY">
adrian@94
     3
    <function name="A_ASSET_GROUP_ACCT_COPY" type="NULL">
antonio@735
     4
      <parameter name="pinstance_id" type="NUMERIC" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
gorkaion@239
     7
      <body><![CDATA[/*************************************************************************
carlos@0
     8
* The contents of this file are subject to the Openbravo  Public  License
carlos@0
     9
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
carlos@0
    10
* Version 1.1  with a permitted attribution clause; you may not  use this
carlos@0
    11
* file except in compliance with the License. You  may  obtain  a copy of
carlos@0
    12
* the License at http://www.openbravo.com/legal/license.html
carlos@0
    13
* Software distributed under the License  is  distributed  on  an "AS IS"
carlos@0
    14
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
carlos@0
    15
* License for the specific  language  governing  rights  and  limitations
carlos@0
    16
* under the License.
carlos@0
    17
* The Original Code is Openbravo ERP.
carlos@0
    18
* The Initial Developer of the Original Code is Openbravo SL
carlos@0
    19
* All portions are Copyright (C) 2001-2006 Openbravo SL
carlos@0
    20
* All Rights Reserved.
carlos@0
    21
* Contributor(s):  ______________________________________.
carlos@0
    22
************************************************************************/
carlos@0
    23
  -- Logistice
carlos@0
    24
  v_ResultStr VARCHAR2(2000):='';
carlos@0
    25
  v_Message VARCHAR2(2000):='';
carlos@0
    26
  v_Record_ID NUMBER;
carlos@0
    27
  -- Parameter
carlos@0
    28
  TYPE RECORD IS REF CURSOR;
carlos@0
    29
    Cur_Parameter RECORD;
carlos@0
    30
    --
carlos@0
    31
    v_A_Asset_Group_ID NUMBER;
carlos@0
    32
    Cur_Acct RECORD;
carlos@0
    33
    --
carlos@0
    34
    v_Updated NUMBER:=0;
carlos@0
    35
    v_Created NUMBER:=0;
carlos@0
    36
    v_Updated_Total NUMBER:=0;
carlos@0
    37
    v_Created_Total NUMBER:=0;
carlos@0
    38
    rowcount NUMBER;
carlos@0
    39
  BEGIN
carlos@0
    40
    --  Update AD_PInstance
carlos@0
    41
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || PInstance_ID) ;
carlos@0
    42
    v_ResultStr:='PInstanceNotFound';
carlos@0
    43
    AD_UPDATE_PINSTANCE(PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    44
  BEGIN --BODY
carlos@0
    45
    -- Get Parameters
carlos@0
    46
    v_ResultStr:='ReadingParameters';
carlos@0
    47
    FOR Cur_Parameter IN
carlos@0
    48
      (SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
carlos@0
    49
      FROM AD_PInstance i
carlos@0
    50
      LEFT JOIN AD_PInstance_Para p
carlos@0
    51
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    52
      WHERE i.AD_PInstance_ID=PInstance_ID
carlos@0
    53
      ORDER BY p.SeqNo
carlos@0
    54
      )
carlos@0
    55
    LOOP
carlos@0
    56
      v_Record_ID:=Cur_Parameter.Record_ID;
carlos@0
    57
      IF(Cur_Parameter.ParameterName='A_Asset_Group_ID') THEN
carlos@0
    58
        v_A_Asset_Group_ID:=Cur_Parameter.P_Number;
carlos@0
    59
        DBMS_OUTPUT.PUT_LINE('  A_Asset_Group_ID=' || v_A_Asset_Group_ID) ;
carlos@0
    60
      ELSE
carlos@0
    61
        DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ;
carlos@0
    62
      END IF;
carlos@0
    63
    END LOOP; -- Get Parameter
carlos@0
    64
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
carlos@0
    65
    /**
carlos@0
    66
    * For all Accounting Schema of the Category
carlos@0
    67
    */
carlos@0
    68
    FOR Cur_Acct IN
carlos@0
    69
      (SELECT *  FROM A_Asset_Group_Acct  WHERE A_Asset_Group_ID=v_A_Asset_Group_ID)
carlos@0
    70
    LOOP
carlos@0
    71
      -- Update existing Assets
carlos@0
    72
      UPDATE A_Asset_Acct
carlos@0
    73
        SET A_DEPRECIATION_ACCT=Cur_Acct.A_DEPRECIATION_ACCT, A_ACCUMDEPRECIATION_ACCT=Cur_Acct.A_ACCUMDEPRECIATION_ACCT, A_DISPOSAL_LOSS=Cur_Acct.A_DISPOSAL_LOSS, A_DISPOSAL_GAIN=Cur_Acct.A_DISPOSAL_GAIN, updated=now(), UpdatedBy=0
carlos@0
    74
      WHERE A_Asset_Acct.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID  AND exists
carlos@0
    75
        (SELECT 1
carlos@0
    76
        FROM A_Asset a
carlos@0
    77
        WHERE a.A_Asset_ID=A_Asset_Acct.A_Asset_ID  AND a.A_Asset_Group_ID=Cur_Acct.A_Asset_Group_ID
carlos@0
    78
        )
carlos@0
    79
        ;
carlos@0
    80
      rowcount:=SQL%ROWCOUNT;
carlos@0
    81
      v_Updated:=rowcount;
carlos@0
    82
      -- Insert new Assets
carlos@0
    83
      INSERT
carlos@0
    84
      INTO A_Asset_Acct
carlos@0
    85
        (
carlos@0
    86
          A_ASSET_ID, C_ACCTSCHEMA_ID, AD_CLIENT_ID, AD_ORG_ID,
carlos@0
    87
          ISACTIVE, CREATED, CREATEDBY, UPDATED,
carlos@0
    88
          UPDATEDBY, A_DEPRECIATION_ACCT, A_ACCUMDEPRECIATION_ACCT, A_DISPOSAL_LOSS,
carlos@0
    89
          A_DISPOSAL_GAIN
carlos@0
    90
        )
carlos@0
    91
      SELECT a.A_ASSET_ID, Cur_Acct.C_ACCTSCHEMA_ID, a.AD_CLIENT_ID, a.AD_ORG_ID, 'Y', now(), 0, now(), 0, Cur_Acct.A_DEPRECIATION_ACCT, Cur_Acct.A_ACCUMDEPRECIATION_ACCT, Cur_Acct.A_DISPOSAL_LOSS, Cur_Acct.A_DISPOSAL_GAIN
carlos@0
    92
      FROM A_Asset a
carlos@0
    93
      WHERE a.A_Asset_Group_ID=Cur_Acct.A_Asset_Group_ID  AND NOT EXISTS
carlos@0
    94
        (SELECT 1
carlos@0
    95
        FROM a_Asset_Acct aa
carlos@0
    96
        WHERE aa.A_Asset_ID=a.A_Asset_Id  AND aa.C_AcctSchema_ID=Cur_Acct.C_AcctSchema_ID
carlos@0
    97
        )
carlos@0
    98
        ;
carlos@0
    99
      rowcount:=SQL%ROWCOUNT;
carlos@0
   100
      v_Created:=rowcount;
carlos@0
   101
      DBMS_OUTPUT.PUT_LINE('Asset = ' || v_Updated || ' / ' || v_Created) ;
carlos@0
   102
      v_Updated_Total:=v_Updated_Total + v_Updated;
carlos@0
   103
      v_Created_Total:=v_Created_Total + v_Created;
carlos@0
   104
    END LOOP;
carlos@0
   105
    v_Message:='@Created@=' || v_Created_Total || ', @Updated@=' || v_Updated_Total;
gorkaion@239
   106
    --<<FINISH_PROCESS>>
carlos@0
   107
    --  Update AD_PInstance
carlos@0
   108
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
   109
    AD_UPDATE_PINSTANCE(PInstance_ID, NULL, 'N', 1, v_Message) ;
carlos@0
   110
    RETURN;
carlos@0
   111
  END; --BODY
carlos@0
   112
EXCEPTION
carlos@0
   113
WHEN OTHERS THEN
carlos@0
   114
  v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
   115
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
   116
  AD_UPDATE_PINSTANCE(PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
   117
  RETURN;
antonio@735
   118
END A_ASSET_GROUP_ACCT_COPY
gorkaion@239
   119
]]></body>
adrian@94
   120
    </function>
adrian@94
   121
  </database>