src-db/database/model/functions/C_PERIODCONTROL_PROCESS.xml
author Antonio Moreno <antonio.moreno@openbravo.com>
Wed, 23 Apr 2008 17:34:12 +0000
changeset 756 ae11e4610537
parent 735 database/model/functions/C_PERIODCONTROL_PROCESS.xml@daced7e311c9
child 771 f0f606b4acf4
permissions -rw-r--r--
Moved database folder to src-db folder
<?xml version="1.0"?>
  <database name="FUNCTION C_PERIODCONTROL_PROCESS">
    <function name="C_PERIODCONTROL_PROCESS" type="NULL">
      <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
        <default/>
      </parameter>
      <body><![CDATA[/*************************************************************************
  * The contents of this file are subject to the Compiere License
  * Version 2.5.0 ("License"); You may not use this file except in
  * compliance with the License. You may obtain a copy of the License at
  * http://www.compiere.org/license.html
  * Software distributed under the License is distributed on an
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  * implied. See the License for the specific language governing rights
  * and limitations under the License.
  * The Original Code is  Compiere  ERP &  Business Solution
  * The Initial Developer of the Original Code is Jorg Janke  and ComPiere,
  Inc.
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
  * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
  * All Rights Reserved.
  * Contributor(s): Openbravo SL
  * Contributions are Copyright (C) 1999-2005 Openbravo, S.L
  *************************************************************************
  * $Id: C_PeriodControl_Process.sql,v 1.2 2002/05/22 02:48:28 jjanke Exp $
  ***
  * Title: Opens/Close Period Control
  * Description:
  ************************************************************************/
  -- Logistice
  v_ResultStr VARCHAR2(2000):='';
  v_Message VARCHAR2(2000):='';
  v_Record_ID NUMBER;
  -- Parameter
  TYPE RECORD IS REF CURSOR;
    Cur_Parameter RECORD;
    -- Variables
    v_PeriodAction C_PeriodControl.PeriodAction%TYPE;
  BEGIN
    --  Update AD_PInstance
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    v_ResultStr:='PInstanceNotFound';
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
  BEGIN --BODY
    -- Get Parameters
    v_ResultStr:='ReadingParameters';
    FOR Cur_Parameter IN
      (SELECT i.Record_ID,
        p.ParameterName,
        p.P_String,
        p.P_Number,
        p.P_Date
      FROM AD_PInstance i
      LEFT JOIN AD_PInstance_Para p
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
      WHERE i.AD_PInstance_ID=p_PInstance_ID
      ORDER BY p.SeqNo
      )
    LOOP
      v_Record_ID:=Cur_Parameter.Record_ID;
    END LOOP; -- Get Parameter
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
    v_ResultStr:='ReadingAction';
    SELECT PeriodAction
    INTO v_PeriodAction
    FROM C_PeriodControl
    WHERE C_PeriodControl_ID=v_Record_ID  FOR UPDATE OF PeriodStatus;
    v_ResultStr:='UpdatingStatus';
    -- Action: Open if not permanently closed
    IF(v_PeriodAction='O') THEN
      UPDATE C_PeriodControl
        SET PeriodStatus='O',
        PeriodAction='N'
      WHERE C_PeriodControl_ID=v_Record_ID
        AND PeriodStatus<>'P';
      -- Action: Close if not permanently closed
    ELSIF(v_PeriodAction='C') THEN
      UPDATE C_PeriodControl
        SET PeriodStatus='C',
        PeriodAction='N'
      WHERE C_PeriodControl_ID=v_Record_ID
        AND PeriodStatus<>'P';
      -- Action: Permanently Close
    ELSIF(v_PeriodAction='P') THEN
      UPDATE C_PeriodControl
        SET PeriodStatus='P',
        PeriodAction='N'
      WHERE C_PeriodControl_ID=v_Record_ID;
    END IF;
    --<<FINISH_PROCESS>>
    --  Update AD_PInstance
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 1, v_Message) ;
    RETURN;
  END; --BODY
EXCEPTION
WHEN OTHERS THEN
  v_ResultStr:= '@ERROR=' || SQLERRM;
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
  ROLLBACK;
  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
  RETURN;
END C_PERIODCONTROL_PROCESS
]]></body>
    </function>
  </database>