src-db/database/model/functions/MA_WRPHASE_CLOSE.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 1273 3f48377a0023
child 6701 690d2af86089
permissions -rw-r--r--
Merge r2.5x intro trunk
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION MA_WRPHASE_CLOSE">
adrian@94
     3
    <function name="MA_WRPHASE_CLOSE" type="NULL">
juanpablo@1605
     4
      <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
gorkaion@239
     7
      <body><![CDATA[/*************************************************************************
carlos@0
     8
* The contents of this file are subject to the Openbravo  Public  License
carlos@0
     9
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
carlos@0
    10
* Version 1.1  with a permitted attribution clause; you may not  use this
carlos@0
    11
* file except in compliance with the License. You  may  obtain  a copy of
carlos@0
    12
* the License at http://www.openbravo.com/legal/license.html
carlos@0
    13
* Software distributed under the License  is  distributed  on  an "AS IS"
carlos@0
    14
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
carlos@0
    15
* License for the specific  language  governing  rights  and  limitations
carlos@0
    16
* under the License.
carlos@0
    17
* The Original Code is Openbravo ERP.
carlos@0
    18
* The Initial Developer of the Original Code is Openbravo SL
carlos@0
    19
* All portions are Copyright (C) 2001-2006 Openbravo SL
carlos@0
    20
* All Rights Reserved.
carlos@0
    21
* Contributor(s):  ______________________________________.
carlos@0
    22
************************************************************************/
carlos@0
    23
  --  Logistice
carlos@0
    24
  v_ResultStr VARCHAR2(2000):='';
carlos@0
    25
  v_Message VARCHAR2(2000):='';
carlos@0
    26
  --  Parameter
carlos@0
    27
  TYPE RECORD IS REF CURSOR;
carlos@0
    28
    Cur_Parameter RECORD;
carlos@0
    29
    --
juanpablo@1605
    30
    v_Record_ID VARCHAR2(32):=NULL;
juanpablo@1605
    31
    v_WorkRequirement_ID VARCHAR2(32);
carlos@0
    32
    v_Count NUMBER;
juanpablo@1605
    33
    v_Client_ID VARCHAR2(32);
carlos@0
    34
  BEGIN
carlos@0
    35
    --  Process Parameters
carlos@0
    36
    IF(p_PInstance_ID IS NOT NULL) THEN
carlos@0
    37
      --  Update AD_PInstance
carlos@0
    38
      DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
carlos@0
    39
      v_ResultStr:='PInstanceNotFound';
carlos@0
    40
      AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    41
      --  Get Parameters
carlos@0
    42
      v_ResultStr:='ReadingParameters';
carlos@0
    43
      FOR Cur_Parameter IN
carlos@0
    44
        (SELECT i.Record_ID,
carlos@0
    45
          i.AD_User_ID,
carlos@0
    46
          i.AD_Org_ID,
carlos@0
    47
          i.AD_Client_ID,
carlos@0
    48
          p.ParameterName,
carlos@0
    49
          p.P_String,
carlos@0
    50
          p.P_Number,
carlos@0
    51
          p.P_Date
carlos@0
    52
        FROM AD_PInstance i
carlos@0
    53
        LEFT JOIN AD_PInstance_Para p
carlos@0
    54
          ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    55
        WHERE i.AD_PInstance_ID=p_PInstance_ID
carlos@0
    56
        ORDER BY p.SeqNo
carlos@0
    57
        )
carlos@0
    58
      LOOP
carlos@0
    59
        v_Record_ID:=Cur_Parameter.Record_ID;
asier@799
    60
        v_Client_ID:=Cur_Parameter.AD_Client_ID;
carlos@0
    61
      END LOOP; --  Get Parameter
carlos@0
    62
    ELSE
gorkaion@239
    63
      DBMS_OUTPUT.PUT_LINE('--<<MA_WorkRequirement_Close>>') ;
carlos@0
    64
    END IF;
carlos@0
    65
  BEGIN --BODY
carlos@0
    66
    SELECT MA_WorkRequirement_ID
carlos@0
    67
    INTO v_WorkRequirement_ID
carlos@0
    68
    FROM MA_WRPhase
carlos@0
    69
    WHERE MA_WRPhase_ID=v_Record_ID;
carlos@0
    70
    v_ResultStr:='Closing phases';
carlos@0
    71
    UPDATE MA_WRPhase  SET closed='Y'  WHERE MA_WRPhase_ID=v_Record_ID;
carlos@0
    72
    SELECT count(*)
carlos@0
    73
    INTO v_Count
carlos@0
    74
    FROM MA_WRPhase
carlos@0
    75
    WHERE MA_WorkRequirement_ID=v_WorkRequirement_ID
carlos@0
    76
      AND closed='N';
carlos@0
    77
    IF v_Count=0 THEN
carlos@0
    78
      UPDATE MA_Workrequirement
carlos@0
    79
        SET closed='Y'
carlos@0
    80
      WHERE MA_WorkRequirement_ID=v_WorkRequirement_ID;
carlos@0
    81
    END IF;
gorkaion@239
    82
    --<<FINISH_PROCESS>>
carlos@0
    83
    --v_Message := v_Message || '@Created@: ' || v_NoRecords;
carlos@0
    84
    IF(p_PInstance_ID IS NOT NULL) THEN
carlos@0
    85
      --  Update AD_PInstance
carlos@0
    86
      DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
    87
      AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 1, v_Message) ;
carlos@0
    88
    ELSE
gorkaion@239
    89
      DBMS_OUTPUT.PUT_LINE('--<<MA_WorkRequirement_Process finished>> ' || v_Message) ;
carlos@0
    90
    END IF;
carlos@0
    91
    RETURN;
carlos@0
    92
  END; --BODY
carlos@0
    93
EXCEPTION
carlos@0
    94
WHEN OTHERS THEN
carlos@0
    95
  v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
    96
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
    97
  IF(p_PInstance_ID IS NOT NULL) THEN
carlos@0
    98
    ROLLBACK;
carlos@0
    99
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
   100
  END IF;
carlos@0
   101
  --p_Invoice_ID := 0;        --  Error Indicator
carlos@0
   102
  RETURN;
antonio@735
   103
END MA_WRPHASE_CLOSE
gorkaion@239
   104
]]></body>
carlos@0
   105
    </function>
adrian@94
   106
  </database>