src-db/database/model/functions/M_INOUT_POST.xml
changeset 21195 26448a5e9156
parent 20976 3f5e8c7117d6
child 21201 e81e664209d1
--- a/src-db/database/model/functions/M_INOUT_POST.xml	Wed Sep 25 19:55:16 2013 +0200
+++ b/src-db/database/model/functions/M_INOUT_POST.xml	Wed Sep 25 23:37:41 2013 +0200
@@ -47,6 +47,7 @@
   v_Message VARCHAR2(2000):='';
   v_Message_aux VARCHAR2(2000):='';
   v_Record_ID VARCHAR2(32);
+  v_DocStatus VARCHAR2(60);
   v_User VARCHAR2(32);
   v_PUser VARCHAR2(32);
   v_is_included NUMBER:=0;
@@ -590,12 +591,25 @@
               -- stocked product
               IF(Cur_InOutLine.M_Product_ID IS NOT NULL AND v_IsStocked=1) THEN
                 -- Update OrderLine (if C-, Qty is negative)
-                UPDATE C_ORDERLINE
-                  SET QtyReserved=QtyReserved - v_QtyPO - v_QtySO,
-                  QtyDelivered=QtyDelivered + v_QtySO,
-                  Updated=now(),
-                  UpdatedBy=v_User
-                WHERE C_OrderLine_ID=Cur_InOutLine.C_OrderLine_ID;
+                SELECT DOCSTATUS into v_DocStatus
+                FROM C_ORDER
+                WHERE C_ORDER_ID = (SELECT C_ORDER_ID
+                                    FROM C_ORDERLINE 
+                                    WHERE C_ORDERLINE_ID=Cur_InOutLine.C_OrderLine_ID);
+                IF (v_DocStatus = 'DR') THEN
+                  UPDATE C_ORDERLINE
+                    SET QtyDelivered=QtyDelivered + v_QtySO,
+                    Updated=now(),
+                    UpdatedBy=v_User
+                  WHERE C_OrderLine_ID=Cur_InOutLine.C_OrderLine_ID;
+                ELSE 
+                  UPDATE C_ORDERLINE
+                    SET QtyReserved=QtyReserved - v_QtyPO - v_QtySO,
+                    QtyDelivered=QtyDelivered + v_QtySO,
+                    Updated=now(),
+                    UpdatedBy=v_User
+                   WHERE C_OrderLine_ID=Cur_InOutLine.C_OrderLine_ID;
+                END IF;
                 -- Products not stocked
               ELSE
                 -- Update OrderLine (if C-, Qty is negative)