src-db/database/model/functions/MA_WORKEFFORT_VALIDATE.xml
changeset 14983 fcf3ccf492f3
parent 9072 79e55dfc8af0
child 15001 a7a8ccfb1923
--- a/src-db/database/model/functions/MA_WORKEFFORT_VALIDATE.xml	Mon Sep 19 19:12:18 2011 +0200
+++ b/src-db/database/model/functions/MA_WORKEFFORT_VALIDATE.xml	Thu Sep 22 18:28:46 2011 +0200
@@ -16,7 +16,7 @@
 * under the License.
 * The Original Code is Openbravo ERP.
 * The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2001-2010 Openbravo SLU
+* All portions are Copyright (C) 2001-2011 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -67,6 +67,7 @@
     v_AD_Org_ID VARCHAR2(32);
     v_prodline NUMBER;
     v_line NUMBER;
+    v_AD_Pinstance_ID VARCHAR2(32);
   BEGIN
     -- Process Parameters
     IF(p_PInstance_ID IS NOT NULL) THEN
@@ -328,15 +329,29 @@
         (SELECT *  FROM M_PRODUCTIONPLAN pp  WHERE pp.M_PRODUCTION_ID=v_Record_ID)
       LOOP
         UPDATE MA_WRPHASE
-          SET DONEQUANTITY=DONEQUANTITY + Cur_ProductionPlan.PRODUCTIONQTY
+          SET DONEQUANTITY=DONEQUANTITY + Cur_ProductionPlan.PRODUCTIONQTY, RUNTIME=Cur_ProductionPlan.RUNTIME
         WHERE MA_WRPhase_ID=Cur_ProductionPlan.MA_WRPHASE_ID;
+        -- Close Phase if its marked
+	IF (Cur_ProductionPlan.CLOSEPHASE='Y') THEN
+	  v_AD_Pinstance_ID := GET_UUID();
+	  INSERT INTO AD_PINSTANCE 
+	  (AD_PINSTANCE_ID, AD_PROCESS_ID, RECORD_ID, ISACTIVE, 
+	  AD_USER_ID, AD_CLIENT_ID, AD_ORG_ID, CREATED, CREATEDBY,
+	  UPDATED, UPDATEDBY)
+	  VALUES
+	  (v_AD_Pinstance_ID,'800118',Cur_ProductionPlan.MA_WRPHASE_ID,'Y',
+	  v_User_ID, v_Client_ID, v_Org_ID, now(), v_User_ID,
+	  now(), v_User_ID
+	  );
+	  MA_WRPHASE_CLOSE(v_AD_Pinstance_ID);
+	END IF;
       END LOOP;
       -- Indicate that we are done
       UPDATE M_PRODUCTION
         SET Processed='Y',
         updated=now(),
         updatedby=v_User_ID
-      WHERE M_Production_ID=v_Record_ID;
+      WHERE M_Production_ID=v_Record_ID;    
     END IF; --FINISH_PROCESS
     IF(NOT FINISH_PROCESS) THEN
       v_ResultStr:='Updating used toolsets';