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