src-db/database/model/functions/C_PERIODCONTROL_PROCESS.xml
author Cristian Berner <cristian.berner@openbravo.com>
Mon, 31 Aug 2020 12:03:00 +0200
changeset 37516 743260848809
parent 20060 031fcdb0d02e
permissions -rw-r--r--
Fixes ISSUE-44863: Remove never thrown ServletException in OBScheduler methods

OBScheduler has been modified previously when quartz has been updated,
but reschedule and unschedule method declarations have not been updated.
ServletException is not thrown anymore in those methods, so it has been
removed from there.

Catch blocks that were catching this non-thrown exception have also been
removed in CallAcctServer and UnscheduleProcess classes.
<?xml version="1.0"?>
  <database name="FUNCTION C_PERIODCONTROL_PROCESS">
    <function name="C_PERIODCONTROL_PROCESS" type="NULL">
      <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
        <default/>
      </parameter>
      <body><![CDATA[/*************************************************************************
  * The contents of this file are subject to the Compiere Public
  * License 1.1 ("License"); You may not use this file except in
  * compliance with the License. You may obtain a copy of the License in
  * the legal folder of your Openbravo installation.
  * 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 SLU
  * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.U.
  *
  * Specifically, this derivative work is based upon the following Compiere
  * file and version.
  *************************************************************************
  * $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 VARCHAR2(32);
  v_Period_ID VARCHAR2(32);
  -- 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, c_period_id
    INTO v_PeriodAction, v_Period_ID
    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',
        openclose='C'
      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',
        openclose='O'
      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',
        openclose='O'
      WHERE C_PeriodControl_ID=v_Record_ID;
    END IF;

    UPDATE C_Period
      SET openclose= (SELECT CASE
            WHEN (max(pc.periodstatus) = min(pc.periodstatus) AND min(pc.periodstatus) = 'O') THEN 'C'
            ELSE 'O'
            END
         FROM c_periodcontrol pc
         WHERE pc.c_period_id = v_Period_ID)
      WHERE c_period_id=v_Period_ID;
    --<<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>