src-db/database/model/functions/C_PERIODCONTROL_PROCESS.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Thu, 24 Apr 2008 19:34:53 +0000
changeset 771 f0f606b4acf4
parent 756 ae11e4610537
child 778 6150609a1a0a
permissions -rw-r--r--
Update database files with the correct license
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">
antonio@735
     4
      <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
gorkaion@239
     7
      <body><![CDATA[/*************************************************************************
juanpablo@771
     8
  * The contents of this file are subject to the Compiere Public
juanpablo@771
     9
  * License 1.1 ("License"); You may not use this file except in
juanpablo@771
    10
  * compliance with the License. You may obtain a copy of the License in
juanpablo@771
    11
  * the legal folder of your Openbravo installation.
juanpablo@771
    12
carlos@0
    13
  * Software distributed under the License is distributed on an
carlos@0
    14
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
carlos@0
    15
  * implied. See the License for the specific language governing rights
juanpablo@771
    16
carlos@0
    17
  * and limitations under the License.
juanpablo@771
    18
  * The Original Code is  Compiere  ERP \&  Business Solution
juanpablo@771
    19
  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
juanpablo@771
    20
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@771
    25
juanpablo@771
    26
  * Contributions are Copyright (C) 1999-2008 Openbravo, S.L
juanpablo@771
    27
  *
juanpablo@771
    28
  * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    29
  * file and version.
carlos@0
    30
  *************************************************************************
carlos@0
    31
  * $Id: C_PeriodControl_Process.sql,v 1.2 2002/05/22 02:48:28 jjanke Exp $
carlos@0
    32
  ***
carlos@0
    33
  * Title: Opens/Close Period Control
carlos@0
    34
  * Description:
carlos@0
    35
  ************************************************************************/
carlos@0
    36
  -- Logistice
carlos@0
    37
  v_ResultStr VARCHAR2(2000):='';
carlos@0
    38
  v_Message VARCHAR2(2000):='';
carlos@0
    39
  v_Record_ID NUMBER;
carlos@0
    40
  -- Parameter
carlos@0
    41
  TYPE RECORD IS REF CURSOR;
carlos@0
    42
    Cur_Parameter RECORD;
carlos@0
    43
    -- Variables
carlos@0
    44
    v_PeriodAction C_PeriodControl.PeriodAction%TYPE;
carlos@0
    45
  BEGIN
carlos@0
    46
    --  Update AD_PInstance
carlos@0
    47
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
carlos@0
    48
    v_ResultStr:='PInstanceNotFound';
carlos@0
    49
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    50
  BEGIN --BODY
carlos@0
    51
    -- Get Parameters
carlos@0
    52
    v_ResultStr:='ReadingParameters';
carlos@0
    53
    FOR Cur_Parameter IN
carlos@0
    54
      (SELECT i.Record_ID,
carlos@0
    55
        p.ParameterName,
carlos@0
    56
        p.P_String,
carlos@0
    57
        p.P_Number,
carlos@0
    58
        p.P_Date
carlos@0
    59
      FROM AD_PInstance i
carlos@0
    60
      LEFT JOIN AD_PInstance_Para p
carlos@0
    61
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    62
      WHERE i.AD_PInstance_ID=p_PInstance_ID
carlos@0
    63
      ORDER BY p.SeqNo
carlos@0
    64
      )
carlos@0
    65
    LOOP
carlos@0
    66
      v_Record_ID:=Cur_Parameter.Record_ID;
carlos@0
    67
    END LOOP; -- Get Parameter
carlos@0
    68
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
carlos@0
    69
    v_ResultStr:='ReadingAction';
carlos@0
    70
    SELECT PeriodAction
carlos@0
    71
    INTO v_PeriodAction
carlos@0
    72
    FROM C_PeriodControl
carlos@0
    73
    WHERE C_PeriodControl_ID=v_Record_ID  FOR UPDATE OF PeriodStatus;
carlos@0
    74
    v_ResultStr:='UpdatingStatus';
carlos@0
    75
    -- Action: Open if not permanently closed
carlos@0
    76
    IF(v_PeriodAction='O') THEN
carlos@0
    77
      UPDATE C_PeriodControl
carlos@0
    78
        SET PeriodStatus='O',
carlos@0
    79
        PeriodAction='N'
carlos@0
    80
      WHERE C_PeriodControl_ID=v_Record_ID
gorkaion@239
    81
        AND PeriodStatus<>'P';
carlos@0
    82
      -- Action: Close if not permanently closed
carlos@0
    83
    ELSIF(v_PeriodAction='C') THEN
carlos@0
    84
      UPDATE C_PeriodControl
carlos@0
    85
        SET PeriodStatus='C',
carlos@0
    86
        PeriodAction='N'
carlos@0
    87
      WHERE C_PeriodControl_ID=v_Record_ID
gorkaion@239
    88
        AND PeriodStatus<>'P';
carlos@0
    89
      -- Action: Permanently Close
carlos@0
    90
    ELSIF(v_PeriodAction='P') THEN
carlos@0
    91
      UPDATE C_PeriodControl
carlos@0
    92
        SET PeriodStatus='P',
carlos@0
    93
        PeriodAction='N'
carlos@0
    94
      WHERE C_PeriodControl_ID=v_Record_ID;
carlos@0
    95
    END IF;
gorkaion@239
    96
    --<<FINISH_PROCESS>>
carlos@0
    97
    --  Update AD_PInstance
carlos@0
    98
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
    99
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 1, v_Message) ;
carlos@0
   100
    RETURN;
carlos@0
   101
  END; --BODY
carlos@0
   102
EXCEPTION
carlos@0
   103
WHEN OTHERS THEN
carlos@0
   104
  v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
   105
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
   106
  ROLLBACK;
carlos@0
   107
  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
   108
  RETURN;
antonio@735
   109
END C_PERIODCONTROL_PROCESS
gorkaion@239
   110
]]></body>
adrian@94
   111
    </function>
adrian@94
   112
  </database>