src-db/database/model/functions/M_RESERVATION_POST.xml
author Gorka Ion Damián <gorkaion.damian@openbravo.com>
Mon, 22 Oct 2012 18:36:20 +0200
changeset 18652 649b5e295f8c
parent 18649 0cd06065418f
child 18663 157c92ecd0e2
permissions -rw-r--r--
[Reservations]Implementation of procedures and several fixes.
Procedures to manage reservations have been implemented:
- M_Reservation_Consumption
- M_Reserve_Stock_Manual
- M_Reserva_Stock_Auto
- ...
Trigger to keep updated quantities on reservation header added.
Several bug fixes and other minor enhancements.
gorkaion@18649
     1
<?xml version="1.0"?>
gorkaion@18649
     2
  <database name="FUNCTION M_RESERVATION_POST">
gorkaion@18649
     3
    <function name="M_RESERVATION_POST" type="NULL">
gorkaion@18649
     4
      <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
gorkaion@18649
     5
        <default/>
gorkaion@18649
     6
      </parameter>
gorkaion@18649
     7
      <parameter name="p_reservation_id" type="VARCHAR" mode="in">
gorkaion@18649
     8
        <default/>
gorkaion@18649
     9
      </parameter>
gorkaion@18649
    10
      <parameter name="p_resaction" type="VARCHAR" mode="in">
gorkaion@18649
    11
        <default/>
gorkaion@18649
    12
      </parameter>
gorkaion@18649
    13
      <parameter name="p_user_id" type="VARCHAR" mode="in">
gorkaion@18649
    14
        <default/>
gorkaion@18649
    15
      </parameter>
gorkaion@18649
    16
      <body><![CDATA[/*************************************************************************
gorkaion@18649
    17
* The contents of this file are subject to the Openbravo  Public  License
gorkaion@18649
    18
* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
gorkaion@18649
    19
* Version 1.1  with a permitted attribution clause; you may not  use this
gorkaion@18649
    20
* file except in compliance with the License. You  may  obtain  a copy of
gorkaion@18649
    21
* the License at http://www.openbravo.com/legal/license.html
gorkaion@18649
    22
* Software distributed under the License  is  distributed  on  an "AS IS"
gorkaion@18649
    23
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
gorkaion@18649
    24
* License for the specific  language  governing  rights  and  limitations
gorkaion@18649
    25
* under the License.
gorkaion@18649
    26
* The Original Code is Openbravo ERP.
gorkaion@18649
    27
* The Initial Developer of the Original Code is Openbravo SLU
gorkaion@18649
    28
* All portions are Copyright (C) 2012 Openbravo SLU
gorkaion@18649
    29
* All Rights Reserved.
gorkaion@18649
    30
* Contributor(s):  ______________________________________.
gorkaion@18649
    31
************************************************************************/
gorkaion@18649
    32
  v_ResultStr       VARCHAR2(2000):='';
gorkaion@18649
    33
  v_Message         VARCHAR2(2000):='';
gorkaion@18649
    34
  v_reservation_id  VARCHAR2(32);
gorkaion@18649
    35
  v_user_id         VARCHAR2(32);
gorkaion@18649
    36
  v_Result          NUMBER:=1; --  Success
gorkaion@18649
    37
  v_resaction       VARCHAR2(60);
gorkaion@18649
    38
  v_resstatus       VARCHAR2(60);
gorkaion@18649
    39
  v_newstatus       VARCHAR2(60);
gorkaion@18649
    40
  v_newaction       VARCHAR2(60);
gorkaion@18649
    41
gorkaion@18649
    42
TYPE RECORD IS REF CURSOR;
gorkaion@18649
    43
  Cur_Parameter RECORD;
gorkaion@18649
    44
gorkaion@18649
    45
BEGIN
gorkaion@18649
    46
  IF (p_PInstance_ID IS NOT NULL) THEN
gorkaion@18649
    47
    --  Update AD_PInstance
gorkaion@18649
    48
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_pinstance_id) ;
gorkaion@18649
    49
    v_ResultStr:='PInstanceNotFound';
gorkaion@18649
    50
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
gorkaion@18649
    51
    --  Get Parameters
gorkaion@18649
    52
    v_ResultStr:='ReadingParameters';
gorkaion@18649
    53
    FOR Cur_Parameter IN (
gorkaion@18649
    54
        SELECT i.record_id, i.ad_user_id, p.parametername, p.p_string, p.p_number, p.p_date
gorkaion@18649
    55
        FROM ad_pinstance i
gorkaion@18649
    56
            LEFT JOIN ad_pinstance_para p ON i.ad_pinstance_id=p.ad_pinstance_id
gorkaion@18649
    57
        WHERE i.ad_pinstance_id=p_pinstance_id
gorkaion@18649
    58
        ORDER BY p.seqno
gorkaion@18649
    59
    ) LOOP
gorkaion@18649
    60
      IF (cur_parameter.parametername = 'RES_Action') THEN
gorkaion@18649
    61
        v_resaction := cur_parameter.p_string;
gorkaion@18649
    62
      END IF;
gorkaion@18649
    63
      v_reservation_id := cur_parameter.record_id;
gorkaion@18649
    64
      v_user_id := cur_parameter.ad_user_id;
gorkaion@18649
    65
    END LOOP; --  Get Parameter
gorkaion@18649
    66
    DBMS_OUTPUT.PUT_LINE('  v_Record_ID=' || v_reservation_id) ;
gorkaion@18649
    67
  ELSE
gorkaion@18649
    68
    v_reservation_id := p_reservation_id;
gorkaion@18649
    69
    v_resaction := p_resaction;
gorkaion@18649
    70
    v_user_id := p_user_id;
gorkaion@18649
    71
  END IF;
gorkaion@18649
    72
gorkaion@18649
    73
BEGIN
gorkaion@18649
    74
  SELECT res_status
gorkaion@18649
    75
    INTO v_resstatus
gorkaion@18649
    76
  FROM m_reservation
gorkaion@18649
    77
  WHERE m_reservation_id = v_reservation_id;
gorkaion@18649
    78
  
gorkaion@18649
    79
  IF (v_resaction = 'PR') THEN
gorkaion@18649
    80
  /*
gorkaion@18649
    81
    Reservation Complete Process
gorkaion@18649
    82
  */
gorkaion@18649
    83
    IF (v_resstatus != 'DR') THEN
gorkaion@18649
    84
      RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
gorkaion@18649
    85
    END IF;
gorkaion@18649
    86
    v_newstatus := 'CO';
gorkaion@18649
    87
    v_newaction := 'HO';
gorkaion@18649
    88
    
gorkaion@18649
    89
    -- ADD RESERVED STOCK
gorkaion@18652
    90
    M_RESERVE_STOCK_AUTO (v_reservation_id, v_user_id, v_message);
gorkaion@18649
    91
gorkaion@18649
    92
  ELSIF (v_resaction = 'HO') THEN
gorkaion@18649
    93
  /*
gorkaion@18649
    94
    Reservation Hold Process
gorkaion@18649
    95
  */
gorkaion@18649
    96
    IF (v_resstatus != 'CO') THEN
gorkaion@18649
    97
      RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
gorkaion@18649
    98
    END IF;
gorkaion@18649
    99
    v_newstatus := 'HO';
gorkaion@18649
   100
    v_newaction := 'UNHO';
gorkaion@18649
   101
  
gorkaion@18649
   102
  
gorkaion@18649
   103
  ELSIF (v_resaction = 'UNHO') THEN
gorkaion@18649
   104
  /*
gorkaion@18649
   105
    Reservation Un-Hold Process
gorkaion@18649
   106
  */
gorkaion@18649
   107
    IF (v_resstatus != 'HO') THEN
gorkaion@18649
   108
      RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
gorkaion@18649
   109
    END IF;
gorkaion@18649
   110
    v_newstatus := 'CO';
gorkaion@18649
   111
    v_newaction := 'HO';
gorkaion@18649
   112
gorkaion@18649
   113
  ELSIF (v_resaction = 'RE') THEN
gorkaion@18649
   114
  /*
gorkaion@18649
   115
    Reservation Reactivate Process
gorkaion@18649
   116
  */
gorkaion@18649
   117
    IF (v_resstatus != 'CO') THEN
gorkaion@18649
   118
      RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
gorkaion@18649
   119
    END IF;
gorkaion@18649
   120
    v_newstatus := 'DR';
gorkaion@18649
   121
    v_newaction := 'PR';
gorkaion@18649
   122
  
gorkaion@18649
   123
  ELSIF (v_resaction = 'CL') THEN
gorkaion@18649
   124
  /*
gorkaion@18649
   125
    Reservation Close Process
gorkaion@18649
   126
  */
gorkaion@18649
   127
    IF (v_resstatus != 'CO' AND v_resstatus != 'HO') THEN
gorkaion@18649
   128
      RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
gorkaion@18649
   129
    END IF;
gorkaion@18649
   130
    v_newstatus := 'CL';
gorkaion@18649
   131
    v_newaction := 'CL';
gorkaion@18649
   132
gorkaion@18649
   133
  ELSE
gorkaion@18649
   134
    RAISE_APPLICATION_ERROR(-20000, '@UnsupportedResAction@');
gorkaion@18649
   135
  END IF;
gorkaion@18649
   136
gorkaion@18649
   137
  UPDATE m_reservation
gorkaion@18649
   138
  SET res_status = v_newstatus,
gorkaion@18649
   139
      res_process = v_newaction,
gorkaion@18649
   140
      updated = now(),
gorkaion@18649
   141
      updatedby = v_user_id
gorkaion@18649
   142
  WHERE m_reservation_id = v_reservation_id;
gorkaion@18649
   143
gorkaion@18649
   144
  IF (p_pinstance_id IS NOT NULL) THEN
gorkaion@18649
   145
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
gorkaion@18649
   146
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', v_Result, v_Message) ;
gorkaion@18649
   147
    DBMS_OUTPUT.PUT_LINE('--<<M_Reservation_Post finished>> ' || v_Message) ;
gorkaion@18649
   148
  END IF;
gorkaion@18649
   149
  RETURN;
gorkaion@18649
   150
END; --BODY
gorkaion@18649
   151
EXCEPTION
gorkaion@18649
   152
WHEN OTHERS THEN
gorkaion@18649
   153
  v_ResultStr:= '@ERROR=' || SQLERRM;
gorkaion@18649
   154
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
gorkaion@18649
   155
  IF (p_pinstance_id IS NOT NULL) THEN
gorkaion@18649
   156
    ROLLBACK;
gorkaion@18649
   157
    AD_UPDATE_PINSTANCE(p_pinstance_id, NULL, 'N', 0, v_ResultStr) ;
gorkaion@18649
   158
  ELSE
gorkaion@18649
   159
    RAISE;
gorkaion@18649
   160
  END IF;
gorkaion@18649
   161
  RETURN;
gorkaion@18649
   162
END M_RESERVATION_POST
gorkaion@18649
   163
]]></body>
gorkaion@18649
   164
    </function>
gorkaion@18649
   165
  </database>