database/model/functions/C_PERIODCONTROL_PROCESS.xml
author Gorka Ion Damián <gorkaion.damian@openbravo.com>
Fri, 14 Dec 2007 16:21:33 +0000
changeset 239 a30acae847e1
parent 170 4b5493776a7f
child 735 daced7e311c9
permissions -rw-r--r--
Added CDATA to views, functions and triggers.
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION C_PERIODCONTROL_PROCESS">
adrian@94
     3
    <function name="C_PERIODCONTROL_PROCESS" type="NULL">
adrian@94
     4
      <parameter name="p_PInstance_ID" type="NUMERIC" mode="in"/>
gorkaion@239
     5
      <body><![CDATA[/*************************************************************************
carlos@0
     6
  * The contents of this file are subject to the Compiere License
carlos@0
     7
  * Version 2.5.0 ("License"); You may not use this file except in
carlos@0
     8
  * compliance with the License. You may obtain a copy of the License at
carlos@0
     9
  * http://www.compiere.org/license.html
carlos@0
    10
  * Software distributed under the License is distributed on an
carlos@0
    11
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
carlos@0
    12
  * implied. See the License for the specific language governing rights
carlos@0
    13
  * and limitations under the License.
gorkaion@239
    14
  * The Original Code is  Compiere  ERP &  Business Solution
carlos@0
    15
  * The Initial Developer of the Original Code is Jorg Janke  and ComPiere,
carlos@0
    16
  Inc.
carlos@0
    17
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
carlos@0
    18
  * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
carlos@0
    19
  * All Rights Reserved.
carlos@0
    20
  * Contributor(s): Openbravo SL
carlos@0
    21
  * Contributions are Copyright (C) 1999-2005 Openbravo, S.L
carlos@0
    22
  *************************************************************************
carlos@0
    23
  * $Id: C_PeriodControl_Process.sql,v 1.2 2002/05/22 02:48:28 jjanke Exp $
carlos@0
    24
  ***
carlos@0
    25
  * Title: Opens/Close Period Control
carlos@0
    26
  * Description:
carlos@0
    27
  ************************************************************************/
carlos@0
    28
  -- Logistice
carlos@0
    29
  v_ResultStr VARCHAR2(2000):='';
carlos@0
    30
  v_Message VARCHAR2(2000):='';
carlos@0
    31
  v_Record_ID NUMBER;
carlos@0
    32
  -- Parameter
carlos@0
    33
  TYPE RECORD IS REF CURSOR;
carlos@0
    34
    Cur_Parameter RECORD;
carlos@0
    35
    -- Variables
carlos@0
    36
    v_PeriodAction C_PeriodControl.PeriodAction%TYPE;
carlos@0
    37
  BEGIN
carlos@0
    38
    --  Update AD_PInstance
carlos@0
    39
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
carlos@0
    40
    v_ResultStr:='PInstanceNotFound';
carlos@0
    41
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    42
  BEGIN --BODY
carlos@0
    43
    -- Get Parameters
carlos@0
    44
    v_ResultStr:='ReadingParameters';
carlos@0
    45
    FOR Cur_Parameter IN
carlos@0
    46
      (SELECT i.Record_ID,
carlos@0
    47
        p.ParameterName,
carlos@0
    48
        p.P_String,
carlos@0
    49
        p.P_Number,
carlos@0
    50
        p.P_Date
carlos@0
    51
      FROM AD_PInstance i
carlos@0
    52
      LEFT JOIN AD_PInstance_Para p
carlos@0
    53
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    54
      WHERE i.AD_PInstance_ID=p_PInstance_ID
carlos@0
    55
      ORDER BY p.SeqNo
carlos@0
    56
      )
carlos@0
    57
    LOOP
carlos@0
    58
      v_Record_ID:=Cur_Parameter.Record_ID;
carlos@0
    59
    END LOOP; -- Get Parameter
carlos@0
    60
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
carlos@0
    61
    v_ResultStr:='ReadingAction';
carlos@0
    62
    SELECT PeriodAction
carlos@0
    63
    INTO v_PeriodAction
carlos@0
    64
    FROM C_PeriodControl
carlos@0
    65
    WHERE C_PeriodControl_ID=v_Record_ID  FOR UPDATE OF PeriodStatus;
carlos@0
    66
    v_ResultStr:='UpdatingStatus';
carlos@0
    67
    -- Action: Open if not permanently closed
carlos@0
    68
    IF(v_PeriodAction='O') THEN
carlos@0
    69
      UPDATE C_PeriodControl
carlos@0
    70
        SET PeriodStatus='O',
carlos@0
    71
        PeriodAction='N'
carlos@0
    72
      WHERE C_PeriodControl_ID=v_Record_ID
gorkaion@239
    73
        AND PeriodStatus<>'P';
carlos@0
    74
      -- Action: Close if not permanently closed
carlos@0
    75
    ELSIF(v_PeriodAction='C') THEN
carlos@0
    76
      UPDATE C_PeriodControl
carlos@0
    77
        SET PeriodStatus='C',
carlos@0
    78
        PeriodAction='N'
carlos@0
    79
      WHERE C_PeriodControl_ID=v_Record_ID
gorkaion@239
    80
        AND PeriodStatus<>'P';
carlos@0
    81
      -- Action: Permanently Close
carlos@0
    82
    ELSIF(v_PeriodAction='P') THEN
carlos@0
    83
      UPDATE C_PeriodControl
carlos@0
    84
        SET PeriodStatus='P',
carlos@0
    85
        PeriodAction='N'
carlos@0
    86
      WHERE C_PeriodControl_ID=v_Record_ID;
carlos@0
    87
    END IF;
gorkaion@239
    88
    --<<FINISH_PROCESS>>
carlos@0
    89
    --  Update AD_PInstance
carlos@0
    90
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
    91
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 1, v_Message) ;
carlos@0
    92
    RETURN;
carlos@0
    93
  END; --BODY
carlos@0
    94
EXCEPTION
carlos@0
    95
WHEN OTHERS THEN
carlos@0
    96
  v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
    97
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
    98
  ROLLBACK;
carlos@0
    99
  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
   100
  RETURN;
adrian@94
   101
END C_PeriodControl_Process
adrian@170
   102
gorkaion@239
   103
gorkaion@239
   104
]]></body>
adrian@94
   105
    </function>
adrian@94
   106
  </database>