/// <summary> /// Is used to do a reverse entry of "Production Record" into the system /// </summary> /// <returns>message successfuly created or not</returns> protected override string DoIt() { if (M_Production_ID > 0) { //Copy Production Header ViennaAdvantage.Model.X_M_Production production = new ViennaAdvantage.Model.X_M_Production(GetCtx(), M_Production_ID, Get_Trx()); string cnt = "Select count(*) from m_production pro where pro.movementdate >" + GlobalVariable.TO_DATE(production.GetMovementDate(), true) + " and pro.processed='Y' "; int trncnt = Util.GetValueOfInt(DB.ExecuteScalar(cnt)); if (trncnt > 0) { production.SetGOM01_IsRecordAvail(true); production.Save(Get_TrxName()); return(Msg.GetMsg(GetCtx(), "Please Check some transaction already availble in future")); } else { production.SetGOM01_IsRecordAvail(false); production.Save(Get_TrxName()); } //check production is Reversed or not, if Reversed then not to do anything if (production.IsReversed()) { return(Msg.GetMsg(GetCtx(), "AlreadyReversed")); } //Get data from Production Plan dsProductionPlan = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_LOCATOR_ID , M_PRODUCT_ID , M_PRODUCTIONPLAN_ID , M_PRODUCTION_ID , PROCESSED , PRODUCTIONQTY M_WAREHOUSE_ID FROM M_ProductionPlan WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx()); //get data from production Line dsProductionLine = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_ATTRIBUTESETINSTANCE_ID , M_LOCATOR_ID , M_PRODUCT_ID , M_PRODUCTIONLINE_ID, M_PRODUCTIONPLAN_ID , M_PRODUCTION_ID , PROCESSED , MOVEMENTQTY , C_UOM_ID , PLANNEDQTY , M_WAREHOUSE_ID FROM M_ProductionLine WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx()); // Create New record of Production Header with Reverse Entry X_M_Production productionTo = new X_M_Production(production.GetCtx(), 0, production.Get_Trx()); try { productionTo.Set_TrxName(production.Get_Trx()); PO.CopyValues(production, productionTo, production.GetAD_Client_ID(), production.GetAD_Org_ID()); productionTo.SetName("{->" + productionTo.GetName() + ")"); if (production.Get_ColumnIndex("DocumentNo") > 0) { productionTo.Set_Value("DocumentNo", ("{->" + productionTo.Get_Value("DocumentNo") + ")")); } productionTo.SetMovementDate(production.GetMovementDate()); //SI_0662 : not to create reverse record in current date, it should be created with the same date. productionTo.SetProcessed(false); if (!productionTo.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production reverse entry"); } else { #region create new record of Production Plan if (dsProductionPlan != null && dsProductionPlan.Tables.Count > 0 && dsProductionPlan.Tables[0].Rows.Count > 0) { for (int i = 0; i < dsProductionPlan.Tables[0].Rows.Count; i++) { //Original Line fromProdPlan = new X_M_ProductionPlan(GetCtx(), Util.GetValueOfInt(dsProductionPlan.Tables[0].Rows[i]["M_PRODUCTIONPLAN_ID"]), Get_Trx()); // Create New record of Production Plan with Reverse Entry toProdPlan = new X_M_ProductionPlan(production.GetCtx(), 0, production.Get_Trx()); try { toProdPlan.Set_TrxName(production.Get_Trx()); PO.CopyValues(fromProdPlan, toProdPlan, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID()); toProdPlan.SetProductionQty(Decimal.Negate(toProdPlan.GetProductionQty())); toProdPlan.SetM_Production_ID(productionTo.GetM_Production_ID()); toProdPlan.SetProcessed(false); if (!toProdPlan.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production Plan reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production Plan reverse entry"); } else { #region check record exist on production line if (dsProductionLine != null && dsProductionLine.Tables.Count > 0 && dsProductionLine.Tables[0].Rows.Count > 0) { //check record exist on production line against production plan drProductionLine = dsProductionLine.Tables[0].Select("M_ProductionPlan_ID = " + fromProdPlan.GetM_ProductionPlan_ID()); if (drProductionLine.Length > 0) { for (int j = 0; j < drProductionLine.Length; j++) { //Original Line fromProdline = new X_M_ProductionLine(GetCtx(), Util.GetValueOfInt(drProductionLine[j]["M_PRODUCTIONLINE_ID"]), Get_Trx()); // Create New record of Production line with Reverse Entry toProdline = new X_M_ProductionLine(production.GetCtx(), 0, production.Get_Trx()); try { toProdline.Set_TrxName(production.Get_Trx()); PO.CopyValues(fromProdline, toProdline, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID()); toProdline.SetMovementQty(Decimal.Negate(toProdline.GetMovementQty())); toProdline.SetPlannedQty(Decimal.Negate(toProdline.GetPlannedQty())); toProdline.SetM_Production_ID(productionTo.GetM_Production_ID()); toProdline.SetM_ProductionPlan_ID(toProdPlan.GetM_ProductionPlan_ID()); toProdline.SetReversalDoc_ID(fromProdline.GetM_ProductionLine_ID()); //maintain refernce of Orignal record on reversed record toProdline.SetProcessed(false); // if (!CheckQtyAvailablity(GetCtx(), toProdline.GetM_Warehouse_ID(), toProdline.GetM_Locator_ID(), toProdline.GetM_ProductContainer_ID(), toProdline.GetM_Product_ID(), toProdline.GetM_AttributeSetInstance_ID(), toProdline.GetMovementQty(), Get_Trx())) if (!CheckQtyAvailablity(GetCtx(), toProdline.GetM_Warehouse_ID(), toProdline.GetM_Locator_ID(), 0, toProdline.GetM_Product_ID(), toProdline.GetM_AttributeSetInstance_ID(), toProdline.GetMovementQty(), Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); if (!string.IsNullOrEmpty(pp.GetName())) { throw new Exception("Could not create Production line reverse entry, " + pp.GetName()); } else { throw new Exception("Could not create Production line reverse entry"); } } if (!toProdline.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production Line reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production line reverse entry"); } else { // Create New record of Production line Policy (Material Policy) with Reverse Entry sql.Clear(); sql.Append(@"INSERT INTO M_ProductionLineMA ( AD_CLIENT_ID, AD_ORG_ID , CREATED , CREATEDBY , ISACTIVE , UPDATED , UPDATEDBY , M_PRODUCTIONLINE_ID , M_ATTRIBUTESETINSTANCE_ID , MMPOLICYDATE , M_PRODUCTCONTAINER_ID, MOVEMENTQTY ) (SELECT AD_CLIENT_ID, AD_ORG_ID , sysdate , CREATEDBY , ISACTIVE , sysdate , UPDATEDBY , " + toProdline.GetM_ProductionLine_ID() + @" , M_ATTRIBUTESETINSTANCE_ID , MMPOLICYDATE , M_PRODUCTCONTAINER_ID, -1 * MOVEMENTQTY FROM M_ProductionLineMA WHERE M_ProductionLine_ID = " + fromProdline.GetM_ProductionLine_ID() + @" ) "); int no = DB.ExecuteQuery(sql.ToString(), null, Get_Trx()); _log.Info("No of records saved on Meterial Policy against Production line ID : " + toProdline.GetM_ProductionLine_ID() + " are : " + no); } } catch (Exception ex) { _log.Info("Error Occured during Production Reverse " + ex.ToString()); if (dsProductionLine != null) { dsProductionLine.Dispose(); } if (dsProductionPlan != null) { dsProductionPlan.Dispose(); } return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result)); } } } } #endregion } } catch (Exception ex) { _log.Info("Error Occured during Production Reverse " + ex.ToString()); if (dsProductionLine != null) { dsProductionLine.Dispose(); } if (dsProductionPlan != null) { dsProductionPlan.Dispose(); } return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result)); } } } #endregion result = productionTo.GetName(); } //set Reversed as True productionTo.SetIsReversed(true); if (!productionTo.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production reverse entry"); } //Set reversed as true, Reverse Refernce on Orignal Document production.SetIsReversed(true); production.SetM_Ref_Production(productionTo.GetM_Production_ID()); if (!production.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production reverse entry"); } } catch (Exception ex) { _log.Info("Error Occured during Production Reverse " + ex.ToString()); if (dsProductionLine != null) { dsProductionLine.Dispose(); } if (dsProductionPlan != null) { dsProductionPlan.Dispose(); } return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result)); } } return(Msg.GetMsg(GetCtx(), "DocumentReversedSuccessfully" + result)); }
/// <summary> /// Is used to do a reverse entry of "Production Record" into the system /// </summary> /// <returns>message successfuly created or not</returns> protected override string DoIt() { if (M_Production_ID > 0) { //Copy Production Header X_M_Production production = new X_M_Production(GetCtx(), M_Production_ID, Get_Trx()); //check production is Reversed or not, if Reversed then not to do anything if (production.IsReversed()) { return(Msg.GetMsg(GetCtx(), "AlreadyReversed")); } //Get data from Production Plan dsProductionPlan = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_LOCATOR_ID , M_PRODUCT_ID , M_PRODUCTIONPLAN_ID , M_PRODUCTION_ID , PROCESSED , PRODUCTIONQTY M_WAREHOUSE_ID FROM M_ProductionPlan WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx()); //get data from production Line dsProductionLine = DB.ExecuteDataset(@"SELECT AD_CLIENT_ID , AD_ORG_ID , DESCRIPTION , LINE , M_ATTRIBUTESETINSTANCE_ID , M_LOCATOR_ID , M_PRODUCT_ID , M_PRODUCTIONLINE_ID, M_PRODUCTIONPLAN_ID , M_PRODUCTION_ID , PROCESSED , MOVEMENTQTY , C_UOM_ID , PLANNEDQTY , M_WAREHOUSE_ID FROM M_ProductionLine WHERE IsActive = 'Y' AND M_PRODUCTION_ID = " + M_Production_ID, null, Get_Trx()); // Create New record of Production Header with Reverse Entry X_M_Production productionTo = new X_M_Production(production.GetCtx(), 0, production.Get_Trx()); try { productionTo.Set_TrxName(production.Get_Trx()); PO.CopyValues(production, productionTo, production.GetAD_Client_ID(), production.GetAD_Org_ID()); productionTo.SetName("{->" + productionTo.GetName() + ")"); if (production.Get_ColumnIndex("DocumentNo") > 0) { productionTo.Set_Value("DocumentNo", ("{->" + productionTo.Get_Value("DocumentNo") + ")")); } productionTo.SetMovementDate(production.GetMovementDate()); //SI_0662 : not to create reverse record in current date, it should be created with the same date. productionTo.SetProcessed(false); if (!productionTo.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production reverse entry"); } else { #region create new record of Production Plan if (dsProductionPlan != null && dsProductionPlan.Tables.Count > 0 && dsProductionPlan.Tables[0].Rows.Count > 0) { for (int i = 0; i < dsProductionPlan.Tables[0].Rows.Count; i++) { //Original Line fromProdPlan = new X_M_ProductionPlan(GetCtx(), Util.GetValueOfInt(dsProductionPlan.Tables[0].Rows[i]["M_PRODUCTIONPLAN_ID"]), Get_Trx()); // Create New record of Production Plan with Reverse Entry toProdPlan = new X_M_ProductionPlan(production.GetCtx(), 0, production.Get_Trx()); try { toProdPlan.Set_TrxName(production.Get_Trx()); PO.CopyValues(fromProdPlan, toProdPlan, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID()); toProdPlan.SetProductionQty(Decimal.Negate(toProdPlan.GetProductionQty())); toProdPlan.SetM_Production_ID(productionTo.GetM_Production_ID()); toProdPlan.SetProcessed(false); if (!toProdPlan.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production Plan reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production Plan reverse entry"); } else { #region check record exist on production line if (dsProductionLine != null && dsProductionLine.Tables.Count > 0 && dsProductionLine.Tables[0].Rows.Count > 0) { //check record exist on production line against production plan drProductionLine = dsProductionLine.Tables[0].Select("M_ProductionPlan_ID = " + fromProdPlan.GetM_ProductionPlan_ID()); if (drProductionLine.Length > 0) { for (int j = 0; j < drProductionLine.Length; j++) { //Original Line fromProdline = new X_M_ProductionLine(GetCtx(), Util.GetValueOfInt(drProductionLine[j]["M_PRODUCTIONLINE_ID"]), Get_Trx()); // Create New record of Production line with Reverse Entry toProdline = new X_M_ProductionLine(production.GetCtx(), 0, production.Get_Trx()); try { toProdline.Set_TrxName(production.Get_Trx()); PO.CopyValues(fromProdline, toProdline, fromProdPlan.GetAD_Client_ID(), fromProdPlan.GetAD_Org_ID()); toProdline.SetMovementQty(Decimal.Negate(toProdline.GetMovementQty())); toProdline.SetPlannedQty(Decimal.Negate(toProdline.GetPlannedQty())); toProdline.SetM_Production_ID(productionTo.GetM_Production_ID()); toProdline.SetM_ProductionPlan_ID(toProdPlan.GetM_ProductionPlan_ID()); toProdline.SetReversalDoc_ID(fromProdline.GetM_ProductionLine_ID()); //maintain refernce of Orignal record on reversed record toProdline.SetProcessed(false); if (!CheckQtyAvailablity(GetCtx(), toProdline.GetM_Warehouse_ID(), toProdline.GetM_Locator_ID(), toProdline.GetM_Product_ID(), toProdline.GetM_AttributeSetInstance_ID(), toProdline.GetMovementQty(), Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); if (!string.IsNullOrEmpty(pp.GetName())) { throw new Exception("Could not create Production line reverse entry, " + pp.GetName()); } else { throw new Exception("Could not create Production line reverse entry"); } } if (!toProdline.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production Line reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production line reverse entry"); } } catch (Exception ex) { _log.Info("Error Occured during Production Reverse " + ex.ToString()); if (dsProductionLine != null) { dsProductionLine.Dispose(); } if (dsProductionPlan != null) { dsProductionPlan.Dispose(); } return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result)); } } } } #endregion } } catch (Exception ex) { _log.Info("Error Occured during Production Reverse " + ex.ToString()); if (dsProductionLine != null) { dsProductionLine.Dispose(); } if (dsProductionPlan != null) { dsProductionPlan.Dispose(); } return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result)); } } } #endregion result = productionTo.GetName(); } //set Reversed as True productionTo.SetIsReversed(true); if (!productionTo.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production reverse entry"); } //Set reversed as true, Reverse Refernce on Orignal Document production.SetIsReversed(true); production.SetM_Ref_Production(productionTo.GetM_Production_ID()); if (!production.Save(production.Get_Trx())) { production.Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Log(Level.SEVERE, "Could Not create Production reverse entry. ERRor Value : " + pp.GetValue() + "ERROR NAME : " + pp.GetName()); throw new Exception("Could not create Production reverse entry"); } } catch (Exception ex) { _log.Info("Error Occured during Production Reverse " + ex.ToString()); if (dsProductionLine != null) { dsProductionLine.Dispose(); } if (dsProductionPlan != null) { dsProductionPlan.Dispose(); } return(Msg.GetMsg(GetCtx(), "DocumentNotReversed" + result)); } } return(Msg.GetMsg(GetCtx(), "DocumentReversedSuccessfully" + result)); }
/// <summary> /// Load Invoice Line /// </summary> /// <param name="prod">production</param> /// <returns> DoaLine Array</returns> private DocLine[] LoadLines(X_M_Production prod) { List <DocLine> list = new List <DocLine>(); // Production // -- ProductionPlan // -- -- ProductionLine - the real level String sqlPP = "SELECT * FROM M_ProductionPlan pp " + "WHERE pp.M_Production_ID=@param1 " + "ORDER BY pp.Line"; IDataReader idrPP = null; String sqlPL = "SELECT * FROM M_ProductionLine pl " + "WHERE pl.M_ProductionPlan_ID=@param2 " + "ORDER BY pl.Line"; IDataReader idrPL = null; try { SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@param1", Get_ID()); idrPP = DataBase.DB.ExecuteReader(sqlPP, param, GetTrx()); //idrPP.setInt(1, get_ID()); //ResultSet rsPP = idrPP.executeQuery(); while (idrPP.Read()) { int M_Product_ID = Utility.Util.GetValueOfInt(idrPP["M_Product_ID"]); int M_ProductionPlan_ID = Utility.Util.GetValueOfInt(idrPP["M_ProductionPlan_ID"]); // try { param = new SqlParameter[1]; param[0] = new SqlParameter("@param2", M_ProductionPlan_ID); idrPL = DataBase.DB.ExecuteReader(sqlPL, param, GetTrx()); //idrPL.setInt(1, M_ProductionPlan_ID); //ResultSet rsPL = idrPL.executeQuery(); while (idrPL.Read()) { X_M_ProductionLine line = new X_M_ProductionLine(GetCtx(), idrPL, GetTrx()); if (Env.Signum(line.GetMovementQty()) == 0) { log.Info("LineQty=0 - " + line); continue; } DocLine docLine = new DocLine(line, this); docLine.SetQty(line.GetMovementQty(), false); // Identify finished BOM Product docLine.SetProductionBOM(line.GetM_Product_ID() == M_Product_ID); // log.Fine(docLine.ToString()); list.Add(docLine); } idrPL.Close(); } catch (Exception ee) { if (idrPL != null) { idrPL.Close(); idrPL = null; } log.Log(Level.SEVERE, sqlPL, ee); } } idrPP.Close(); } catch (Exception e) { if (idrPP != null) { idrPP.Close(); idrPP = null; } log.Log(Level.SEVERE, sqlPP, e); } // Return Array DocLine[] dl = new DocLine[list.Count]; dl = list.ToArray(); return(dl); }