src-db/database/model/functions/M_CHECK_STOCK.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
<?xml version="1.0"?>
  <database name="FUNCTION M_CHECK_STOCK">
    <function name="M_CHECK_STOCK" type="NULL">
      <parameter name="p_m_product_id" type="VARCHAR" mode="in">
        <default/>
      </parameter>
      <parameter name="p_ad_client_id" type="VARCHAR" mode="in">
        <default/>
      </parameter>
      <parameter name="p_ad_org_id" type="VARCHAR" mode="in">
        <default/>
      </parameter>
      <parameter name="p_result" type="NUMERIC" mode="out">
        <default/>
      </parameter>
      <parameter name="p_message" type="VARCHAR" mode="out">
        <default/>
      </parameter>
      <body><![CDATA[/*************************************************************************
* The contents of this file are subject to the Openbravo  Public  License
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
* Version 1.1  with a permitted attribution clause; you may not  use this
* file except in compliance with the License. You  may  obtain  a copy of
* the License at http://www.openbravo.com/legal/license.html
* Software distributed under the License  is  distributed  on  an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific  language  governing  rights  and  limitations
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SL
* All portions are Copyright (C) 2001-2006 Openbravo SL
* All Rights Reserved.
* Contributor(s):  ______________________________________.
************************************************************************/
  v_ResultStr VARCHAR2(2000):='';
  v_ExistsNegativeStock NUMBER;
  v_Stock CHAR:='N';
  v_Name VARCHAR2(60) ;
  v_AD_Client_ID VARCHAR2(32);
BEGIN
  v_ResultStr:='Checking stock';
  p_Result:=1;
  SELECT ALLOWNEGATIVESTOCK
  INTO v_Stock
  FROM AD_CLIENTINFO
  WHERE AD_CLIENT_ID=p_AD_Client_ID;
  IF v_Stock='N' THEN
    SELECT COUNT(*)
    INTO v_ExistsNegativeStock
    FROM
      ( SELECT ROUND(COALESCE(QTYONHAND, 0), 2) AS QTY,
        ROUND(COALESCE(QTYORDERONHAND, 0), 2) AS QTYORDER
      FROM M_STORAGE_DETAIL
      WHERE M_PRODUCT_ID=p_M_Product_ID
        AND AD_CLIENT_ID=p_AD_Client_ID
        AND AD_ORG_ID=p_AD_Org_ID
      )
      A
    WHERE QTY<0
      OR QTYORDER<0;
    IF v_ExistsNegativeStock<>0 THEN
      p_Result:=0;
      p_Message:='@NotEnoughStocked@';
    END IF;
  END IF;
  RETURN;
EXCEPTION
WHEN OTHERS THEN
  v_ResultStr:= '@ERROR=' || SQLERRM;
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
  RAISE;
  RETURN;
END M_CHECK_STOCK
]]></body>
    </function>
  </database>