/// <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)); }
protected override bool BeforeSave(bool newRecord) { // Movement Quantity can not be less than 0 when planned is greater than 0 if (GetPlannedQty() > 0 && GetMovementQty() < 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbelesszero")); return(false); } // Movement Quantity can not be greater than 0 when planned is less than 0 if (GetPlannedQty() < 0 && GetMovementQty() > 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbegrtzero")); return(false); } MProduct product = new MProduct(GetCtx(), GetM_Product_ID(), Get_TrxName()); if (newRecord && product != null) { if (Util.GetValueOfString(product.Get_Value("IsSlopeOil")) == "True" && GetMovementQty() < 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbelesszero")); return(false); } if (Util.GetValueOfString(product.Get_Value("IsSlopeOil")) == "False" && GetMovementQty() > 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbegrtzero")); return(false); } } X_M_ProductionPlan plan = new X_M_ProductionPlan(GetCtx(), GetM_ProductionPlan_ID(), Get_TrxName()); if (Util.GetValueOfDecimal(plan.Get_Value("GOM01_ComponentLimit")) > 0 && GetPlannedQty() < 0) { decimal ComputedQty = (GetPlannedQty() * Util.GetValueOfDecimal(plan.Get_Value("GOM01_ComponentLimit"))) / 100; ComputedQty = decimal.Negate(GetPlannedQty() + ComputedQty); if (decimal.Negate(GetMovementQty()) > ComputedQty) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "GOM01_QtyConsumption")); return(false); } } // when warehouse disallow negative inventory is false then on hand qty can't be in negative wh = MWarehouse.Get(GetCtx(), GetM_Warehouse_ID()); if (wh.IsDisallowNegativeInv() && GetM_Product_ID() > 0) { product = MProduct.Get(GetCtx(), GetM_Product_ID()); string qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); //if (GetM_AttributeSetInstance_ID() != 0) //{ qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID(); //} Decimal?OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); qry = @"SELECT NVL(SUM(MovementQty) , 0) FROM M_ProductionLine WHERE IsActive = 'Y' AND M_Locator_ID=" + GetM_Locator_ID() + @" AND m_product_id=" + GetM_Product_ID() + @" AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID() + @" AND M_Production_ID = " + GetM_Production_ID(); if (!newRecord) { qry += @" AND M_ProductionLine_ID <> " + GetM_ProductionLine_ID(); } Decimal?moveQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); if ((OnHandQty + GetMovementQty() + moveQty) < 0) { log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } } return(true); }