src-db/database/model/functions/M_CREATE_RESERVE_FROM_SOL.xml
author Gorka Ion Damián <gorkaion.damian@openbravo.com>
Thu, 25 Oct 2012 17:20:43 +0200
changeset 18663 157c92ecd0e2
parent 18652 649b5e295f8c
child 18721 852757ccfb86
permissions -rw-r--r--
[Reservations]Fix pg consistency issues.
gorkaion@18644
     1
<?xml version="1.0"?>
gorkaion@18644
     2
  <database name="FUNCTION M_CREATE_RESERVE_FROM_SOL">
gorkaion@18652
     3
    <function name="M_CREATE_RESERVE_FROM_SOL" type="NULL">
gorkaion@18644
     4
      <parameter name="p_orderline_id" type="VARCHAR" mode="in">
gorkaion@18644
     5
        <default/>
gorkaion@18644
     6
      </parameter>
gorkaion@18644
     7
      <parameter name="p_process_reserve" type="CHAR" mode="in">
gorkaion@18644
     8
        <default/>
gorkaion@18644
     9
      </parameter>
gorkaion@18650
    10
      <parameter name="p_user_id" type="VARCHAR" mode="in">
gorkaion@18650
    11
        <default/>
gorkaion@18650
    12
      </parameter>
gorkaion@18652
    13
      <parameter name="p_reservation_id" type="VARCHAR" mode="out">
gorkaion@18652
    14
        <default/>
gorkaion@18652
    15
      </parameter>
gorkaion@18644
    16
      <body><![CDATA[/*************************************************************************
gorkaion@18644
    17
* The contents of this file are subject to the Openbravo  Public  License
gorkaion@18644
    18
* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
gorkaion@18644
    19
* Version 1.1  with a permitted attribution clause; you may not  use this
gorkaion@18644
    20
* file except in compliance with the License. You  may  obtain  a copy of
gorkaion@18644
    21
* the License at http://www.openbravo.com/legal/license.html
gorkaion@18644
    22
* Software distributed under the License  is  distributed  on  an "AS IS"
gorkaion@18644
    23
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
gorkaion@18644
    24
* License for the specific  language  governing  rights  and  limitations
gorkaion@18644
    25
* under the License.
gorkaion@18644
    26
* The Original Code is Openbravo ERP.
gorkaion@18644
    27
* The Initial Developer of the Original Code is Openbravo SLU
gorkaion@18644
    28
* All portions are Copyright (C) 2012 Openbravo SLU
gorkaion@18644
    29
* All Rights Reserved.
gorkaion@18644
    30
* Contributor(s):  ______________________________________.
gorkaion@18644
    31
************************************************************************/
gorkaion@18644
    32
/*************
gorkaion@18652
    33
* Procedure to create reservations for the given Sales Order Line.
gorkaion@18644
    34
**************/
gorkaion@18650
    35
  v_product_id        VARCHAR2(32);
gorkaion@18650
    36
  v_uom_id            VARCHAR2(32);
gorkaion@18650
    37
  v_client_id         VARCHAR2(32);
gorkaion@18650
    38
  v_org_id            VARCHAR2(32);
gorkaion@18650
    39
  v_qtyordered        NUMBER;
gorkaion@18650
    40
  v_qtydelivered      NUMBER;
gorkaion@18650
    41
  v_issotrx           CHAR(1);
gorkaion@18650
    42
  v_reservation_id    VARCHAR2(32) := get_uuid();
gorkaion@18644
    43
BEGIN
gorkaion@18650
    44
  SELECT ol.m_product_id, ol.c_uom_id, ol.qtyordered, ol.qtydelivered, o.issotrx,
gorkaion@18650
    45
         ol.ad_client_id, ol.ad_org_id
gorkaion@18650
    46
    INTO v_product_id, v_uom_id, v_qtyordered, v_qtydelivered, v_issotrx,
gorkaion@18650
    47
         v_client_id, v_org_id
gorkaion@18650
    48
  FROM c_orderline ol JOIN c_order o ON ol.c_order_id = o.c_order_id
gorkaion@18650
    49
  WHERE ol.c_orderline_id = p_orderline_id;
gorkaion@18644
    50
gorkaion@18650
    51
  IF (v_issotrx = 'N') THEN
gorkaion@18650
    52
    RAISE_APPLICATION_ERROR(-20000,'@cannotReservePurchaseOrder@');
gorkaion@18650
    53
  END IF;
gorkaion@18650
    54
  IF (v_qtyordered < 0) THEN
gorkaion@18650
    55
    RAISE_APPLICATION_ERROR(-20000,'@cannotReservePurchaseOrder@');
gorkaion@18650
    56
  END IF;
gorkaion@18650
    57
  IF (v_qtyordered - v_qtydelivered <= 0) THEN
gorkaion@18650
    58
    RAISE_APPLICATION_ERROR(-20000,'@cannotReserveDeliveredSalesOrderLine@');
gorkaion@18650
    59
  END IF;
gorkaion@18644
    60
gorkaion@18650
    61
  INSERT INTO m_reservation(
gorkaion@18650
    62
    m_reservation_id, ad_client_id, ad_org_id, isactive,
gorkaion@18650
    63
    created, createdby, updated, updatedby,
gorkaion@18650
    64
    c_orderline_id,
gorkaion@18652
    65
    m_product_id, c_uom_id, quantity, reservedqty, releasedqty,
gorkaion@18650
    66
    res_status, res_process
gorkaion@18650
    67
  ) VALUES (
gorkaion@18650
    68
    v_reservation_id, v_client_id, v_org_id, 'Y',
gorkaion@18650
    69
    now(), p_user_id, now(), p_user_id,
gorkaion@18650
    70
    p_orderline_id,
gorkaion@18652
    71
    v_product_id, v_uom_id, v_qtyordered, 0, v_qtydelivered,
gorkaion@18650
    72
    'DR', 'CO'
gorkaion@18650
    73
  );
gorkaion@18644
    74
gorkaion@18650
    75
  IF (p_process_reserve = 'Y') THEN
gorkaion@18650
    76
    M_RESERVATION_POST(null, v_reservation_id, 'PR', p_user_id);
gorkaion@18650
    77
  END IF;
gorkaion@18644
    78
gorkaion@18652
    79
  p_reservation_id := v_reservation_id;
gorkaion@18652
    80
RETURN;
gorkaion@18663
    81
END M_CREATE_RESERVE_FROM_SOL
gorkaion@18663
    82
]]></body>
gorkaion@18644
    83
    </function>
gorkaion@18644
    84
  </database>