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
mikel@13319
     1
<?xml version="1.0"?>
mikel@13319
     2
  <database name="FUNCTION MA_PC_CASE_CREATE">
mikel@13319
     3
    <function name="MA_PC_CASE_CREATE" type="NULL">
mikel@13319
     4
      <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
mikel@13319
     5
        <default/>
mikel@13319
     6
      </parameter>
mikel@13319
     7
      <body><![CDATA[/*************************************************************************
mikel@13319
     8
* The contents of this file are subject to the Openbravo  Public  License
mikel@13319
     9
* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
mikel@13319
    10
* Version 1.1  with a permitted attribution clause; you may not  use this
mikel@13319
    11
* file except in compliance with the License. You  may  obtain  a copy of
mikel@13319
    12
* the License at http://www.openbravo.com/legal/license.html
mikel@13319
    13
* Software distributed under the License  is  distributed  on  an "AS IS"
mikel@13319
    14
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
mikel@13319
    15
* License for the specific  language  governing  rights  and  limitations
mikel@13319
    16
* under the License.
mikel@13319
    17
* The Original Code is Openbravo ERP.
mikel@13319
    18
* The Initial Developer of the Original Code is Openbravo SLU
mikel@13320
    19
* All portions are Copyright (C) 2001-2011 Openbravo SLU
mikel@13319
    20
* All Rights Reserved.
mikel@13319
    21
* Contributor(s):  ______________________________________.
mikel@13319
    22
************************************************************************/
mikel@13319
    23
  --  Logistice
mikel@13319
    24
  v_ResultStr VARCHAR2(2000):='';
mikel@13319
    25
  v_Message VARCHAR2(2000):='';
mikel@13319
    26
  --  Parameter
mikel@13319
    27
  v_NextNo VARCHAR2(32);
mikel@13319
    28
  TYPE RECORD IS REF CURSOR;
mikel@13319
    29
    Cur_Parameter RECORD;
mikel@13319
    30
    --
mikel@13319
    31
    p_Record_ID VARCHAR2(32):=NULL;
mikel@13319
    32
    --  Tests to include
mikel@13319
    33
    Cur_PC_Test RECORD;
mikel@13319
    34
    --
mikel@13319
    35
    v_StartDate DATE;
mikel@13319
    36
    v_Periodic_Control_ID VARCHAR2(32);
mikel@13319
    37
    v_User_ID VARCHAR2(32);
mikel@13319
    38
    v_Client_ID VARCHAR2(32);
mikel@13319
    39
    v_Org_ID VARCHAR2(32);
mikel@13319
    40
    v_Result NUMBER:=1;
mikel@13319
    41
  BEGIN
mikel@13319
    42
    --  Process Parameters
mikel@13319
    43
    IF(p_PInstance_ID IS NOT NULL) THEN
mikel@13319
    44
      --  Update AD_PInstance
mikel@13319
    45
      DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
mikel@13319
    46
      v_ResultStr:='PInstanceNotFound';
mikel@13319
    47
      AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
mikel@13319
    48
      --  Get Parameters
mikel@13319
    49
      v_ResultStr:='ReadingParameters';
mikel@13319
    50
      FOR Cur_Parameter IN
mikel@13319
    51
        (SELECT i.Record_ID,
mikel@13319
    52
          i.AD_User_ID,
mikel@13319
    53
          i.AD_Org_ID,
mikel@13319
    54
          i.AD_Client_ID,
mikel@13319
    55
          p.ParameterName,
mikel@13319
    56
          p.P_String,
mikel@13319
    57
          p.P_Number,
mikel@13319
    58
          p.P_Date
mikel@13319
    59
        FROM AD_PInstance i
mikel@13319
    60
        LEFT JOIN AD_PInstance_Para p
mikel@13319
    61
          ON i.AD_PInstance_ID=p.AD_PInstance_ID
mikel@13319
    62
        WHERE i.AD_PInstance_ID=p_PInstance_ID
mikel@13319
    63
        ORDER BY p.SeqNo
mikel@13319
    64
        )
mikel@13319
    65
      LOOP
mikel@13319
    66
        p_Record_ID:=Cur_Parameter.Record_ID;
mikel@13319
    67
        v_User_ID:=Cur_Parameter.AD_User_ID;
mikel@13319
    68
        v_Client_ID:=Cur_Parameter.AD_Client_ID;
mikel@13319
    69
        v_Org_ID:=Cur_Parameter.AD_Org_ID;
mikel@13319
    70
      END LOOP; --  Get Parameter
mikel@13319
    71
    ELSE
mikel@13319
    72
      DBMS_OUTPUT.PUT_LINE('--<<MA_WorkRequirement_Close>>') ;
mikel@13319
    73
    END IF;
mikel@13319
    74
  BEGIN --BODY
mikel@13319
    75
    v_ResultStr:='Read Periodic control and date';
mikel@13319
    76
    SELECT MA_PERIODIC_CONTROL_ID,
mikel@13319
    77
      STARTDATE
mikel@13319
    78
    INTO v_Periodic_Control_ID,
mikel@13319
    79
      v_StartDate
mikel@13319
    80
    FROM MA_PC_CASE
mikel@13319
    81
    WHERE MA_PC_Case_ID=p_Record_ID;
mikel@13319
    82
    FOR Cur_PC_Test IN
mikel@13319
    83
      (SELECT MA_PC_Test_ID,
mikel@13319
    84
        days
mikel@13319
    85
      FROM MA_PC_Test
mikel@13319
    86
      WHERE MA_Periodic_Control_ID=v_Periodic_Control_ID
mikel@13319
    87
      )
mikel@13319
    88
    LOOP
mikel@13319
    89
      AD_Sequence_Next('MA_PC_Value', v_Org_ID, v_NextNo);
mikel@13319
    90
      INSERT
mikel@13319
    91
      INTO MA_PC_Value
mikel@13319
    92
        (
mikel@13319
    93
          MA_Pc_Value_ID, AD_Client_ID, AD_Org_ID, Isactive,
mikel@13319
    94
          Created, Createdby, Updated, Updatedby,
mikel@13319
    95
          MA_Pc_Case_ID, MA_Pc_Test_ID, Datadate)
mikel@13319
    96
        VALUES
mikel@13319
    97
        (
mikel@13319
    98
          v_NextNo, v_Client_ID, v_Org_ID, 'Y',
mikel@13319
    99
          now(), v_User_ID, now(), v_User_ID,
mikel@13319
   100
          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
mikel@13319
   101
          )
mikel@13319
   102
        )
mikel@13319
   103
        ;
mikel@13319
   104
    END LOOP;
mikel@13319
   105
    UPDATE MA_PC_Case  SET launched='Y'  WHERE MA_PC_Case_ID=p_Record_ID;
mikel@13319
   106
    --<<FINISH_PROCESS>>
mikel@13319
   107
    --v_Message := v_Message || '@Created@: ' || v_NoRecords;
mikel@13319
   108
    IF(p_PInstance_ID IS NOT NULL) THEN
mikel@13319
   109
      --  Update AD_PInstance
mikel@13319
   110
      DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
mikel@13319
   111
      AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 1, v_Message) ;
mikel@13319
   112
    ELSE
mikel@13319
   113
      DBMS_OUTPUT.PUT_LINE('--<<MA_WorkRequirement_Process finished>> ' || v_Message) ;
mikel@13319
   114
    END IF;
mikel@13319
   115
    RETURN;
mikel@13319
   116
  END; --BODY
mikel@13319
   117
EXCEPTION
mikel@13319
   118
WHEN OTHERS THEN
mikel@13319
   119
  v_ResultStr:= '@ERROR=' || SQLERRM;
mikel@13319
   120
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
mikel@13319
   121
  IF(p_PInstance_ID IS NOT NULL) THEN
mikel@13319
   122
    ROLLBACK;
mikel@13319
   123
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
mikel@13319
   124
  END IF;
mikel@13319
   125
  --p_Invoice_ID := 0;        --  Error Indicator
mikel@13319
   126
  RETURN;
mikel@13319
   127
END MA_PC_CASE_CREATE
mikel@13319
   128
]]></body>
mikel@13319
   129
    </function>
mikel@13319
   130
  </database>