src-db/database/model/functions/M_INOUT_UPDATEQUANTITYES.xml
changeset 1605 8a0fe0193bef
parent 756 ae11e4610537
child 6701 690d2af86089
equal deleted inserted replaced
1604:a1c518e6ed93 1605:8a0fe0193bef
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     2   <database name="FUNCTION M_INOUT_UPDATEQUANTITYES">
     2   <database name="FUNCTION M_INOUT_UPDATEQUANTITYES">
     3     <function name="M_INOUT_UPDATEQUANTITYES" type="NULL">
     3     <function name="M_INOUT_UPDATEQUANTITYES" type="NULL">
     4       <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
     4       <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
     5         <default/>
     5         <default/>
     6       </parameter>
     6       </parameter>
     7       <body><![CDATA[/*************************************************************************
     7       <body><![CDATA[/*************************************************************************
     8 * The contents of this file are subject to the Openbravo  Public  License
     8 * The contents of this file are subject to the Openbravo  Public  License
     9 * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
     9 * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
    20 * All Rights Reserved.
    20 * All Rights Reserved.
    21 * Contributor(s):  ______________________________________.
    21 * Contributor(s):  ______________________________________.
    22 ************************************************************************/
    22 ************************************************************************/
    23   v_ResultStr VARCHAR2(2000):='';
    23   v_ResultStr VARCHAR2(2000):='';
    24   v_Message VARCHAR2(2000):='';
    24   v_Message VARCHAR2(2000):='';
    25   v_Record_ID NUMBER;
    25   v_Record_ID VARCHAR2(32);
    26   v_Result NUMBER:=0; -- failure
    26   v_Result NUMBER:=0; -- failure
    27   v_AD_User_ID NUMBER;
    27   v_AD_User_ID VARCHAR2(32);
    28   v_AD_Org_ID NUMBER;
    28   v_AD_Org_ID VARCHAR2(32);
    29   v_AD_Client_ID NUMBER;
    29   v_AD_Client_ID VARCHAR2(32);
    30   -- Parameter
    30   -- Parameter
    31   TYPE RECORD IS REF CURSOR;
    31   TYPE RECORD IS REF CURSOR;
    32     Cur_Parameter RECORD;
    32     Cur_Parameter RECORD;
    33     -- Parameter Variables
    33     -- Parameter Variables
    34     v_M_InOut_ID NUMBER;
    34     v_M_InOut_ID VARCHAR2(32);
    35     v_Total NUMBER;
    35     v_Total NUMBER;
    36     FINISH_PROCESS BOOLEAN:=false;
    36     FINISH_PROCESS BOOLEAN:=false;
    37   BEGIN
    37   BEGIN
    38     --  Update AD_PInstance
    38     --  Update AD_PInstance
    39     DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    39     DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    61       v_Record_ID:=Cur_Parameter.Record_ID;
    61       v_Record_ID:=Cur_Parameter.Record_ID;
    62       v_AD_User_ID:=Cur_Parameter.AD_User_ID;
    62       v_AD_User_ID:=Cur_Parameter.AD_User_ID;
    63       v_AD_Org_ID:=Cur_Parameter.AD_Org_ID;
    63       v_AD_Org_ID:=Cur_Parameter.AD_Org_ID;
    64       v_AD_Client_ID:=Cur_Parameter.AD_Client_ID;
    64       v_AD_Client_ID:=Cur_Parameter.AD_Client_ID;
    65       IF(Cur_Parameter.ParameterName='M_InOut_ID') THEN
    65       IF(Cur_Parameter.ParameterName='M_InOut_ID') THEN
    66         v_M_InOut_ID:=Cur_Parameter.P_Number;
    66         v_M_InOut_ID:=Cur_Parameter.P_String;
    67         DBMS_OUTPUT.PUT_LINE('  M_InOut_ID=' || v_M_InOut_ID) ;
    67         DBMS_OUTPUT.PUT_LINE('  M_InOut_ID=' || v_M_InOut_ID) ;
    68       ELSE
    68       ELSE
    69         DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ;
    69         DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ;
    70       END IF;
    70       END IF;
    71     END LOOP; -- Get Parameter
    71     END LOOP; -- Get Parameter
    75     INTO v_Total
    75     INTO v_Total
    76     FROM
    76     FROM
    77       (SELECT M_PRODUCT_ID,
    77       (SELECT M_PRODUCT_ID,
    78         C_UOM_ID,
    78         C_UOM_ID,
    79         ROUND(MOVEMENTQTY, 2),
    79         ROUND(MOVEMENTQTY, 2),
    80         COALESCE(M_PRODUCT_UOM_ID, 0) AS M_PRODUCT_UOM_ID,
    80         COALESCE(M_PRODUCT_UOM_ID, '0') AS M_PRODUCT_UOM_ID,
    81         COALESCE(QUANTITYORDER, 0) AS QUANTITYORDER,
    81         COALESCE(QUANTITYORDER, 0) AS QUANTITYORDER,
    82         COUNT(*)
    82         COUNT(*)
    83       FROM M_INOUTLINE
    83       FROM M_INOUTLINE
    84       WHERE M_INOUT_ID=v_M_InOut_ID
    84       WHERE M_INOUT_ID=v_M_InOut_ID
    85         AND ISACTIVE='Y'
    85         AND ISACTIVE='Y'
    86       GROUP BY M_PRODUCT_ID,
    86       GROUP BY M_PRODUCT_ID,
    87         C_UOM_ID,
    87         C_UOM_ID,
    88         MOVEMENTQTY,
    88         MOVEMENTQTY,
    89         COALESCE(M_PRODUCT_UOM_ID, 0),
    89         COALESCE(M_PRODUCT_UOM_ID, '0'),
    90         COALESCE(QUANTITYORDER, 0) MINUS
    90         COALESCE(QUANTITYORDER, 0) MINUS
    91       SELECT M_PRODUCT_ID,
    91       SELECT M_PRODUCT_ID,
    92         C_UOM_ID,
    92         C_UOM_ID,
    93         ROUND(MOVEMENTQTY, 2),
    93         ROUND(MOVEMENTQTY, 2),
    94         COALESCE(M_PRODUCT_UOM_ID, 0) AS M_PRODUCT_UOM_ID,
    94         COALESCE(M_PRODUCT_UOM_ID, '0') AS M_PRODUCT_UOM_ID,
    95         COALESCE(QUANTITYORDER, 0) AS QUANTITYORDER,
    95         COALESCE(QUANTITYORDER, 0) AS QUANTITYORDER,
    96         COUNT(*)
    96         COUNT(*)
    97       FROM M_INOUTLINE
    97       FROM M_INOUTLINE
    98       WHERE M_INOUT_ID=v_Record_ID
    98       WHERE M_INOUT_ID=v_Record_ID
    99         AND ISACTIVE='Y'
    99         AND ISACTIVE='Y'
   100       GROUP BY M_PRODUCT_ID,
   100       GROUP BY M_PRODUCT_ID,
   101         C_UOM_ID,
   101         C_UOM_ID,
   102         MOVEMENTQTY,
   102         MOVEMENTQTY,
   103         COALESCE(M_PRODUCT_UOM_ID, 0),
   103         COALESCE(M_PRODUCT_UOM_ID, '0'),
   104         COALESCE(QUANTITYORDER, 0)
   104         COALESCE(QUANTITYORDER, 0)
   105       )
   105       )
   106       A;
   106       A;
   107     IF(v_Total>0) THEN
   107     IF(v_Total>0) THEN
   108       v_Message:='LinesNotMatch';
   108       v_Message:='LinesNotMatch';
   119       BEGIN
   119       BEGIN
   120         FOR Cur_Lines IN
   120         FOR Cur_Lines IN
   121           (SELECT M_PRODUCT_ID,
   121           (SELECT M_PRODUCT_ID,
   122             C_UOM_ID,
   122             C_UOM_ID,
   123             ROUND(MOVEMENTQTY, 2) AS MOVEMENTQTY,
   123             ROUND(MOVEMENTQTY, 2) AS MOVEMENTQTY,
   124             COALESCE(M_PRODUCT_UOM_ID, 0) AS M_PRODUCT_UOM_ID,
   124             COALESCE(M_PRODUCT_UOM_ID, '0') AS M_PRODUCT_UOM_ID,
   125             COALESCE(QUANTITYORDER, 0) AS QUANTITYORDER,
   125             COALESCE(QUANTITYORDER, 0) AS QUANTITYORDER,
   126             M_ATTRIBUTESETINSTANCE_ID
   126             M_ATTRIBUTESETINSTANCE_ID
   127           FROM M_INOUTLINE
   127           FROM M_INOUTLINE
   128           WHERE M_INOUT_ID=v_M_InOut_ID
   128           WHERE M_INOUT_ID=v_M_InOut_ID
   129             AND ISACTIVE='Y'
   129             AND ISACTIVE='Y'
   134           v_StrSQL:=v_StrSQL || 'WHERE M_INOUT_ID = ' || v_Record_ID || ' ';
   134           v_StrSQL:=v_StrSQL || 'WHERE M_INOUT_ID = ' || v_Record_ID || ' ';
   135           v_StrSQL:=v_StrSQL || 'AND ISACTIVE = ''Y'' ';
   135           v_StrSQL:=v_StrSQL || 'AND ISACTIVE = ''Y'' ';
   136           v_StrSQL:=v_StrSQL || 'AND M_PRODUCT_ID = ' || Cur_Lines.M_PRODUCT_ID || ' ';
   136           v_StrSQL:=v_StrSQL || 'AND M_PRODUCT_ID = ' || Cur_Lines.M_PRODUCT_ID || ' ';
   137           v_StrSQL:=v_StrSQL || 'AND C_UOM_ID = ' || Cur_Lines.C_UOM_ID || ' ';
   137           v_StrSQL:=v_StrSQL || 'AND C_UOM_ID = ' || Cur_Lines.C_UOM_ID || ' ';
   138           v_StrSQL:=v_StrSQL || 'AND ROUND(MOVEMENTQTY, 2) = TO_NUMBER(''' || Cur_Lines.MOVEMENTQTY || ''') ';
   138           v_StrSQL:=v_StrSQL || 'AND ROUND(MOVEMENTQTY, 2) = TO_NUMBER(''' || Cur_Lines.MOVEMENTQTY || ''') ';
   139           v_StrSQL:=v_StrSQL || 'AND COALESCE(M_PRODUCT_UOM_ID, 0) = ' || Cur_Lines.M_PRODUCT_UOM_ID || ' ';
   139           v_StrSQL:=v_StrSQL || 'AND COALESCE(M_PRODUCT_UOM_ID, ''0'') = ' || Cur_Lines.M_PRODUCT_UOM_ID || ' ';
   140           v_StrSQL:=v_StrSQL || 'AND COALESCE(QUANTITYORDER, 0) = ' || Cur_Lines.QUANTITYORDER || ' ';
   140           v_StrSQL:=v_StrSQL || 'AND COALESCE(QUANTITYORDER, 0) = ' || Cur_Lines.QUANTITYORDER || ' ';
   141           IF v_Lines IS NOT NULL THEN
   141           IF v_Lines IS NOT NULL THEN
   142             v_StrSQL:=v_StrSQL || 'AND M_INOUTLINE_ID NOT IN (' || v_Lines || ') ';
   142             v_StrSQL:=v_StrSQL || 'AND M_INOUTLINE_ID NOT IN (' || v_Lines || ') ';
   143           END IF;
   143           END IF;
   144           EXECUTE IMMEDIATE v_StrSQL INTO v_Lines_Aux;
   144           EXECUTE IMMEDIATE v_StrSQL INTO v_Lines_Aux;