src-db/database/model/functions/MA_PC_CASE_CREATE.xml
author Mikel Irurita <mikel.irurita@openbravo.com>
Thu, 28 Jul 2011 12:36:33 +0200
changeset 13320 021aea273863
parent 13319 178a991820b0
child 29706 a8a6d8bd52e5
permissions -rw-r--r--
Related to issue 18065: update year in the license text
<?xml version="1.0"?>
  <database name="FUNCTION MA_PC_CASE_CREATE">
    <function name="MA_PC_CASE_CREATE" type="NULL">
      <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
        <default/>
      </parameter>
      <body><![CDATA[/*************************************************************************
* The contents of this file are subject to the Openbravo  Public  License
* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
* Version 1.1  with a permitted attribution clause; you may not  use this
* file except in compliance with the License. You  may  obtain  a copy of
* the License at http://www.openbravo.com/legal/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 Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
* All portions are Copyright (C) 2001-2011 Openbravo SLU
* All Rights Reserved.
* Contributor(s):  ______________________________________.
************************************************************************/
  --  Logistice
  v_ResultStr VARCHAR2(2000):='';
  v_Message VARCHAR2(2000):='';
  --  Parameter
  v_NextNo VARCHAR2(32);
  TYPE RECORD IS REF CURSOR;
    Cur_Parameter RECORD;
    --
    p_Record_ID VARCHAR2(32):=NULL;
    --  Tests to include
    Cur_PC_Test RECORD;
    --
    v_StartDate DATE;
    v_Periodic_Control_ID VARCHAR2(32);
    v_User_ID VARCHAR2(32);
    v_Client_ID VARCHAR2(32);
    v_Org_ID VARCHAR2(32);
    v_Result NUMBER:=1;
  BEGIN
    --  Process Parameters
    IF(p_PInstance_ID IS NOT NULL) THEN
      --  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) ;
      --  Get Parameters
      v_ResultStr:='ReadingParameters';
      FOR Cur_Parameter IN
        (SELECT i.Record_ID,
          i.AD_User_ID,
          i.AD_Org_ID,
          i.AD_Client_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
        p_Record_ID:=Cur_Parameter.Record_ID;
        v_User_ID:=Cur_Parameter.AD_User_ID;
        v_Client_ID:=Cur_Parameter.AD_Client_ID;
        v_Org_ID:=Cur_Parameter.AD_Org_ID;
      END LOOP; --  Get Parameter
    ELSE
      DBMS_OUTPUT.PUT_LINE('--<<MA_WorkRequirement_Close>>') ;
    END IF;
  BEGIN --BODY
    v_ResultStr:='Read Periodic control and date';
    SELECT MA_PERIODIC_CONTROL_ID,
      STARTDATE
    INTO v_Periodic_Control_ID,
      v_StartDate
    FROM MA_PC_CASE
    WHERE MA_PC_Case_ID=p_Record_ID;
    FOR Cur_PC_Test IN
      (SELECT MA_PC_Test_ID,
        days
      FROM MA_PC_Test
      WHERE MA_Periodic_Control_ID=v_Periodic_Control_ID
      )
    LOOP
      AD_Sequence_Next('MA_PC_Value', v_Org_ID, v_NextNo);
      INSERT
      INTO MA_PC_Value
        (
          MA_Pc_Value_ID, AD_Client_ID, AD_Org_ID, Isactive,
          Created, Createdby, Updated, Updatedby,
          MA_Pc_Case_ID, MA_Pc_Test_ID, Datadate)
        VALUES
        (
          v_NextNo, v_Client_ID, v_Org_ID, 'Y',
          now(), v_User_ID, now(), v_User_ID,
          p_Record_ID, Cur_PC_Test.MA_PC_Test_ID, ( CASE TO_CHAR(v_StartDate + Cur_PC_Test.days, 'd') WHEN '7' THEN v_StartDate + Cur_PC_Test.days+1 ELSE v_StartDate + Cur_PC_Test.days END
          )
        )
        ;
    END LOOP;
    UPDATE MA_PC_Case  SET launched='Y'  WHERE MA_PC_Case_ID=p_Record_ID;
    --<<FINISH_PROCESS>>
    --v_Message := v_Message || '@Created@: ' || v_NoRecords;
    IF(p_PInstance_ID IS NOT NULL) THEN
      --  Update AD_PInstance
      DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
      AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 1, v_Message) ;
    ELSE
      DBMS_OUTPUT.PUT_LINE('--<<MA_WorkRequirement_Process finished>> ' || v_Message) ;
    END IF;
    RETURN;
  END; --BODY
EXCEPTION
WHEN OTHERS THEN
  v_ResultStr:= '@ERROR=' || SQLERRM;
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
  IF(p_PInstance_ID IS NOT NULL) THEN
    ROLLBACK;
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
  END IF;
  --p_Invoice_ID := 0;        --  Error Indicator
  RETURN;
END MA_PC_CASE_CREATE
]]></body>
    </function>
  </database>