/** * Before Delete * @return true if it can be deleted */ protected override bool BeforeDelete() { // Check Storage if (IsStocked() || PRODUCTTYPE_Item.Equals(GetProductType())) { MStorage[] storages = MStorage.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName()); Decimal OnHand = Env.ZERO; Decimal Ordered = Env.ZERO; Decimal Reserved = Env.ZERO; for (int i = 0; i < storages.Length; i++) { OnHand = Decimal.Add(OnHand, (storages[i].GetQtyOnHand())); Ordered = Decimal.Add(OnHand, (storages[i].GetQtyOrdered())); Reserved = Decimal.Add(OnHand, (storages[i].GetQtyReserved())); } String errMsg = ""; if (Env.Signum(OnHand) != 0) { errMsg = "@QtyOnHand@ = " + OnHand; } if (Env.Signum(Ordered) != 0) { errMsg += " - @QtyOrdered@ = " + Ordered; } if (Env.Signum(Reserved) != 0) { errMsg += " - @QtyReserved@" + Reserved; } if (errMsg.Length > 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), errMsg)); return(false); } } // delete costing MProductCosting[] costings = MProductCosting.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName()); for (int i = 0; i < costings.Length; i++) { costings[i].Delete(true, Get_TrxName()); } string sql = "DELETE FROM M_Cost WHERE M_Product_ID = " + Get_ID(); int no = DB.ExecuteQuery(sql, null, Get_TrxName()); if (no < 0) { return(false); } return(Delete_Accounting("M_Product_Acct")); }
/* Product is Item * @return true if item */ public bool IsItem() { return(PRODUCTTYPE_Item.Equals(GetProductType())); }
/** * Before Save * @param newRecord new * @return true */ protected override bool BeforeSave(bool newRecord) { // Check Storage if (!newRecord && // ((Is_ValueChanged("IsActive") && !IsActive()) || // now not active (Is_ValueChanged("IsStocked") && !IsStocked()) || // now not stocked (Is_ValueChanged("ProductType") && // from Item PRODUCTTYPE_Item.Equals(Get_ValueOld("ProductType"))))) { MStorage[] storages = MStorage.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName()); Decimal OnHand = Env.ZERO; Decimal Ordered = Env.ZERO; Decimal Reserved = Env.ZERO; for (int i = 0; i < storages.Length; i++) { OnHand = Decimal.Add(OnHand, (storages[i].GetQtyOnHand())); Ordered = Decimal.Add(OnHand, (storages[i].GetQtyOrdered())); Reserved = Decimal.Add(OnHand, (storages[i].GetQtyReserved())); } String errMsg = ""; if (Env.Signum(OnHand) != 0) { errMsg = "@QtyOnHand@ = " + OnHand; } if (Env.Signum(Ordered) != 0) { errMsg += " - @QtyOrdered@ = " + Ordered; } if (Env.Signum(Reserved) != 0) { errMsg += " - @QtyReserved@" + Reserved; } if (errMsg.Length > 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), errMsg)); return(false); } } // storage // Reset Stocked if not Item if (IsStocked() && !PRODUCTTYPE_Item.Equals(GetProductType())) { SetIsStocked(false); } // UOM reset if (_precision != null && Is_ValueChanged("C_UOM_ID")) { _precision = null; } if (Util.GetValueOfInt(Env.GetCtx().GetContext("#AD_User_ID")) != 100) { if (Is_ValueChanged("C_UOM_ID") || Is_ValueChanged("M_AttributeSet_ID")) { string uqry = "SELECT SUM(cc) as count FROM (SELECT COUNT(*) AS cc FROM M_MovementLine WHERE M_Product_ID = " + GetM_Product_ID() + @" UNION SELECT COUNT(*) AS cc FROM M_InventoryLine WHERE M_Product_ID = " + GetM_Product_ID() + " UNION SELECT COUNT(*) AS cc FROM C_OrderLine WHERE M_Product_ID = " + GetM_Product_ID() + " UNION SELECT COUNT(*) AS cc FROM M_InOutLine WHERE M_Product_ID = " + GetM_Product_ID() + ")"; int no = Util.GetValueOfInt(DB.ExecuteScalar(uqry)); if (no == 0 || IsBOM()) { uqry = "SELECT count(*) FROM M_ProductionPlan WHERE M_Product_ID = " + GetM_Product_ID(); no = Util.GetValueOfInt(DB.ExecuteScalar(uqry)); } if (no > 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "Could not Save Record. Transactions available in System.")); return(false); } } } if (newRecord) { string sql = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual"; int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null)); if (manu_ID > 0) { _log.SaveError("UPC is Unique", ""); return(false); } } else { if (!String.IsNullOrEmpty(GetUPC()) && Util.GetValueOfString(Get_ValueOld("UPC")) != GetUPC()) { string sql = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual"; int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null)); //if (manu_ID != 0 && manu_ID != GetM_Product_ID()) if (manu_ID > 0) { _log.SaveError("UPC is Unique", ""); return(false); } } } return(true); }
/** * Before Save * @param newRecord new * @return true */ protected override bool BeforeSave(bool newRecord) { // Set Search Key from Serial No defined on Product Category. MProductCategory pc = new MProductCategory(GetCtx(), GetM_Product_Category_ID(), Get_TrxName()); if (newRecord && pc.Get_ColumnIndex("M_SerNoCtl_ID") >= 0 && pc.GetM_SerNoCtl_ID() > 0) { string name = ""; MSerNoCtl ctl = new MSerNoCtl(GetCtx(), pc.GetM_SerNoCtl_ID(), Get_TrxName()); // if Organization level check box is true on Serila No Control, then Get Current next from Serila No tab. if (ctl.Get_ColumnIndex("IsOrgLevelSequence") >= 0) { name = ctl.CreateDefiniteSerNo(this); } else { name = ctl.CreateSerNo(); } SetValue(name); } // Check Storage if (!newRecord && // ((Is_ValueChanged("IsActive") && !IsActive()) // now not active || (Is_ValueChanged("IsStocked") && !IsStocked()) // now not stocked || (Is_ValueChanged("ProductType") // from Item && PRODUCTTYPE_Item.Equals(Get_ValueOld("ProductType"))))) { MStorage[] storages = MStorage.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName()); Decimal OnHand = Env.ZERO; Decimal Ordered = Env.ZERO; Decimal Reserved = Env.ZERO; for (int i = 0; i < storages.Length; i++) { OnHand = Decimal.Add(OnHand, (storages[i].GetQtyOnHand())); Ordered = Decimal.Add(OnHand, (storages[i].GetQtyOrdered())); Reserved = Decimal.Add(OnHand, (storages[i].GetQtyReserved())); } String errMsg = ""; if (Env.Signum(OnHand) != 0) errMsg = "@QtyOnHand@ = " + OnHand; if (Env.Signum(Ordered) != 0) errMsg += " - @QtyOrdered@ = " + Ordered; if (Env.Signum(Reserved) != 0) errMsg += " - @QtyReserved@" + Reserved; if (errMsg.Length > 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), errMsg)); return false; } } // storage // Reset Stocked if not Item if (IsStocked() && !PRODUCTTYPE_Item.Equals(GetProductType())) SetIsStocked(false); // UOM reset if (_precision != null && Is_ValueChanged("C_UOM_ID")) _precision = null; if (Util.GetValueOfInt(Env.GetCtx().GetContext("#AD_User_ID")) != 100) { if (Is_ValueChanged("C_UOM_ID") || Is_ValueChanged("M_AttributeSet_ID")) { string uqry = "SELECT SUM(cc) as count FROM (SELECT COUNT(*) AS cc FROM M_MovementLine WHERE M_Product_ID = " + GetM_Product_ID() + @" UNION SELECT COUNT(*) AS cc FROM M_InventoryLine WHERE M_Product_ID = " + GetM_Product_ID() + " UNION SELECT COUNT(*) AS cc FROM C_OrderLine WHERE M_Product_ID = " + GetM_Product_ID() + " UNION SELECT COUNT(*) AS cc FROM M_InOutLine WHERE M_Product_ID = " + GetM_Product_ID() + ") t"; int no = Util.GetValueOfInt(DB.ExecuteScalar(uqry)); if (no == 0 || IsBOM()) { uqry = "SELECT count(*) FROM M_ProductionPlan WHERE M_Product_ID = " + GetM_Product_ID(); no = Util.GetValueOfInt(DB.ExecuteScalar(uqry)); } if (no > 0) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "Could not Save Record. Transactions available in System.")); return false; } } } if (newRecord) { //string sql = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual"; //int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null)); int manu_ID = UpcUniqueClientWise(GetAD_Client_ID(), GetUPC()); if (manu_ID > 0) { _log.SaveError("UPCUnique", ""); return false; } } else { if (!String.IsNullOrEmpty(GetUPC()) && Util.GetValueOfString(Get_ValueOld("UPC")) != GetUPC()) { //string sql = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual"; //int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null)); //if (manu_ID != 0 && manu_ID != GetM_Product_ID()) int manu_ID = UpcUniqueClientWise(GetAD_Client_ID(), GetUPC()); if (manu_ID > 0) { _log.SaveError("UPCUnique", ""); return false; } } } return true; }