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