/// <summary> /// After Delete /// </summary> /// <param name="sucess">new</param> /// <returns>true if can be deleted</returns> /// SI_0682_1 Need to update the reserved qty on requisition line by internal use line save aslo and should work as work in inventory move. protected override bool AfterDelete(bool success) { if (Env.IsModuleInstalled("DTD001_") && IsInternalUse()) { if (GetM_RequisitionLine_ID() != 0) { MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx()); // Trx used to handle query stuck problem requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() - qtyReserved); if (!requisition.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); // Trx used to handle query stuck problem if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); // Trx used to handle query stuck problem } storage.SetQtyReserved(storage.GetQtyReserved() - qtyReserved); if (!storage.Save()) { return(false); } } } return(true); }
protected override bool AfterDelete(bool success) { Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { if (GetM_RequisitionLine_ID() != 0) { MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null); requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() - qtyReserved); if (!requisition.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), null); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null); } storage.SetQtyReserved(storage.GetQtyReserved() - qtyReserved); if (!storage.Save()) { return(false); } } } return(true); }
/// <summary> /// After Save /// </summary> /// <param name="newRecord">new</param> /// <param name="success">success</param> /// <returns>true</returns> protected override bool AfterSave(bool newRecord, bool success) { if (!success) { return(success); } // Create MA if (newRecord && success && _isManualEntry && GetM_AttributeSetInstance_ID() == 0) { CreateMA(true); } if (!IsInternalUse()) { MInventory inv = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx()); inv.SetIsAdjusted(false); if (!inv.Save()) { } } else // SI_0682_1 Need to update the reserved qty on requisition line by internal use line save aslo and should work as work in inventory move. { if (Env.IsModuleInstalled("DTD001_")) { if (!newRecord && GetM_RequisitionLine_ID() != 0) { MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx()); requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + (GetQtyInternalUse() - qtyReserved)); if (!requisition.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); } storage.SetQtyReserved(storage.GetQtyReserved() + (GetQtyInternalUse() - qtyReserved)); if (!storage.Save()) { return(false); } } if (newRecord && GetM_RequisitionLine_ID() != 0 && GetDescription() != "RC") { MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx()); requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + GetQtyInternalUse()); if (!requisition.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); } storage.SetQtyReserved(storage.GetQtyReserved() + GetQtyInternalUse()); if (!storage.Save()) { return(false); } } } } return(true); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true</returns> protected override Boolean BeforeSave(Boolean newRecord) { // Set Line No if (GetLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID(); int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetLine(ii); } // Check Locator For Header Warehouse MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName()); MLocator loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName()); Tuple <string, string, string> aInfo = null; if (Env.HasModulePrefix("DTD001_", out aInfo)) { if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID()) { } else { String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'"; int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetM_Locator_ID(ii); } } if (GetM_Locator_ID() == GetM_LocatorTo_ID()) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement return(false); } if (Env.Signum(GetMovementQty()) == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty")); return(false); } //Amit Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged")); return(false); } } if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0) { if (GetM_RequisitionLine_ID() > 0) { MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null); if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame")); return(false); } } } // IF Doc Status = InProgress then No record Save MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), null); if (newRecord && move.GetDocStatus() == "IP") { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate")); return(false); } // Qty Precision if (newRecord || Is_ValueChanged("QtyEntered")) { SetMovementQty(GetMovementQty()); } int M_Warehouse_ID = 0; MWarehouse wh = null; string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID(); M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry)); wh = MWarehouse.Get(GetCtx(), M_Warehouse_ID); 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 M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); if (wh.IsDisallowNegativeInv() == true) { if (GetDescription() != "RC") { if (GetMovementQty() < 0) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "Qty Available " + OnHandQty)); //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null); return(false); } else if ((OnHandQty - GetMovementQty()) < 0) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "Qty Available " + OnHandQty)); //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null); return(false); } } } if (Env.HasModulePrefix("DTD001_", out mInfo)) { qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry)); qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("MovementQty")); if (wh.IsDisallowNegativeInv() == true) { if ((qtyAvailable < (GetMovementQty() - qtyReserved))) { log.SaveError("Message", Msg.GetElement(GetCtx(), "DTD001_QtyNotAvailable")); return(false); } } } // Mandatory Instance if (GetM_AttributeSetInstanceTo_ID() == 0) { if (GetM_AttributeSetInstance_ID() != 0) // Set to from { SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID()); } else { if (Env.HasModulePrefix("DTD001_", out mInfo)) { MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); //if (mas.IsInstanceAttribute() // && (mas.IsMandatory() || mas.IsMandatoryAlways())) //{ // log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); // return false; //} if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } } else { if (product != null) { if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)) { return(true); } else { //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); //ShowMessage.Info("a", true, "Product is not of Attribute Type", null); log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } //Check No Of Attributes Are Equal To Quantity Or Less Than int Count = CountAttributes(GetDTD001_AttributeNumber()); if (Count != GetMovementQty()) { if (Count > GetMovementQty()) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater")); return(false); } else { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess")); return(false); } } } } } else { MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); if (mas.IsInstanceAttribute() && (mas.IsMandatory() || mas.IsMandatoryAlways())) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); return(false); } } } } } // ASI return(true); }
protected override bool AfterSave(bool newRecord, bool success) { Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { if (!newRecord && GetM_RequisitionLine_ID() != 0 && GetConfirmedQty() == 0) { MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null); requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + (GetMovementQty() - qtyReserved)); if (!requisition.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), null); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null); } storage.SetQtyReserved(storage.GetQtyReserved() + (GetMovementQty() - qtyReserved)); if (!storage.Save()) { return(false); } } //vikas 11/21/2014 _mvlNewAttId = GetM_AttributeSetInstance_ID(); if (_mvlOldAttId != _mvlNewAttId && !newRecord) { // Set QtyReserved On Storage Correspng to New attributesetinstc_id storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), null); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null); } storage.SetQtyReserved(storage.GetQtyReserved() + qtyReserved); if (!storage.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), _mvlOldAttId, null); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null); } storage.SetQtyReserved(storage.GetQtyReserved() - qtyReserved); if (!storage.Save()) { return(false); } }//vikas if (newRecord && GetM_RequisitionLine_ID() != 0 && GetDescription() != "RC") { MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null); requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + GetMovementQty()); if (!requisition.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), null); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null); } storage.SetQtyReserved(storage.GetQtyReserved() + GetMovementQty()); if (!storage.Save()) { return(false); } } } return(true); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true</returns> protected override Boolean BeforeSave(Boolean newRecord) { Decimal VA024_ProvisionPrice = 0; MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); // chck pallet Functionality applicable or not bool isContainrApplicable = MTransaction.ProductContainerApplicable(GetCtx()); // Get Old Value of AttributeSetInstance_ID _mvlOldAttId = Util.GetValueOfInt(Get_ValueOld("M_AttributeSetInstance_ID")); // Set Line No if (GetLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID(); int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetLine(ii); } // JID_0775: System is not checking on move line that the attribute set instance is mandatory. if (GetM_AttributeSetInstance_ID() == 0) { if (product != null && product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); if (mas.IsMandatory() || mas.IsMandatoryAlways()) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstance_ID")); return(false); } } } // Check Locator For Header Warehouse MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName()); MLocator loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName()); Tuple <string, string, string> aInfo = null; if (Env.HasModulePrefix("DTD001_", out aInfo)) { if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID()) { } else { String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'"; int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetM_Locator_ID(ii); } } // when we try to move product from container to container which are in same locator then no need to check this case if (GetM_Locator_ID() == GetM_LocatorTo_ID() && (Get_ColumnIndex("M_ProductContainer_ID") > 0 && Get_ColumnIndex("Ref_M_ProductContainerTo_ID") > 0 && !(GetM_ProductContainer_ID() > 0 || GetRef_M_ProductContainerTo_ID() > 0))) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement return(false); } if (Env.Signum(GetMovementQty()) == 0 && Util.GetValueOfInt(GetTargetQty()) == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty")); return(false); } Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged")); return(false); } } //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0) if (Env.IsModuleInstalled("VA203_")) { if (GetM_RequisitionLine_ID() > 0) { MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx()); // Trx used to handle query stuck problem if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame")); return(false); } } } // IF Doc Status = InProgress then No record Save MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx()); // Trx used to handle query stuck problem if (newRecord && move.GetDocStatus() == "IP") { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate")); return(false); } // Qty Precision if (newRecord || Is_ValueChanged("QtyEntered")) { SetQtyEntered(GetQtyEntered()); } // change to set Converted Quantity in Movement quantity if there is differnce in UOM of Base Product and UOM Selected on line if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID")) { Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered")); if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID"))) { SetMovementQty(MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered")))); } } // Qty Precision if (newRecord || Is_ValueChanged("QtyEntered")) { SetMovementQty(GetMovementQty()); } string qry; if (!mov.IsProcessing() || newRecord) { MWarehouse wh = null; MWarehouse whTo = null; wh = MWarehouse.Get(GetCtx(), mov.GetDTD001_MWarehouseSource_ID()); whTo = MWarehouse.Get(GetCtx(), MLocator.Get(GetCtx(), GetM_LocatorTo_ID()).GetM_Warehouse_ID()); 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 (GetDTD001_AttributeNumber() == null || GetM_AttributeSetInstance_ID() > 0) { qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID(); } OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_LocatorTo_ID() + " and m_product_id=" + GetM_Product_ID(); qry += " AND NVL(M_AttributeSetInstance_ID, 0) =" + GetM_AttributeSetInstance_ID(); OnHandQtyTo = Convert.ToDecimal(DB.ExecuteScalar(qry)); // SI_0635 : System is giving error of insufficient qty if disallow is true in TO warehouse and false in From warehouse // when record is in completed & closed stage - then no need to check qty availablity in warehouse if ((wh.IsDisallowNegativeInv() || whTo.IsDisallowNegativeInv()) && (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE" || move.GetDocStatus() == "VO"))) { // pick container current qty from transaction based on locator / product / ASI / Container / Movement Date if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0) { // qry = @"SELECT SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS CurrentQty FROM m_transaction t // INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + // " AND t.AD_Client_ID = " + GetAD_Client_ID() + // @" AND t.M_Locator_ID = " + (move.IsReversal() && GetMovementQty() < 0 ? GetM_LocatorTo_ID() : GetM_Locator_ID()) + // " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() + // " AND NVL(t.M_ProductContainer_ID, 0) = " + (move.IsReversal() && !IsMoveFullContainer() && GetMovementQty() < 0 ? GetRef_M_ProductContainerTo_ID() : GetM_ProductContainer_ID()); // containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null)); // dont use Transaction here - otherwise impact goes wrong on completion // qry = @"SELECT SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS CurrentQty FROM m_transaction t // INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + // " AND t.AD_Client_ID = " + GetAD_Client_ID() + // @" AND t.M_Locator_ID = " + (move.IsReversal() && GetMovementQty() < 0 ? GetM_Locator_ID() : GetM_LocatorTo_ID()) + // " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() + // " AND NVL(t.M_ProductContainer_ID, 0) = " + (move.IsReversal() && !IsMoveFullContainer() && GetMovementQty() < 0 ? GetM_ProductContainer_ID() : GetRef_M_ProductContainerTo_ID()); // containerQtyTo = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null)); // dont use Transaction here - otherwise impact goes wrong on completion qry = @"SELECT DISTINCT First_VALUE(t.ContainerCurrentQty) OVER (PARTITION BY t.M_Product_ID, t.M_AttributeSetInstance_ID ORDER BY t.MovementDate DESC, t.M_Transaction_ID DESC) AS CurrentQty FROM m_transaction t INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + " AND t.AD_Client_ID = " + GetAD_Client_ID() + @" AND t.M_Locator_ID = " + GetM_Locator_ID() + " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_ProductContainer_ID, 0) = " + GetM_ProductContainer_ID(); // In Case of Attribute Number do not check qty with attribute from storage if (GetDTD001_AttributeNumber() == null || GetM_AttributeSetInstance_ID() > 0) { qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID(); } containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null)); // dont use Transaction here - otherwise impact goes wrong on completion qry = @"SELECT DISTINCT First_VALUE(t.ContainerCurrentQty) OVER (PARTITION BY t.M_Product_ID, t.M_AttributeSetInstance_ID ORDER BY t.MovementDate DESC, t.M_Transaction_ID DESC) AS CurrentQty FROM m_transaction t INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + " AND t.AD_Client_ID = " + GetAD_Client_ID() + @" AND t.M_Locator_ID = " + GetM_LocatorTo_ID() + " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() + " AND NVL(t.M_ProductContainer_ID, 0) = " + GetRef_M_ProductContainerTo_ID(); containerQtyTo = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null)); // dont use Transaction here - otherwise impact goes wrong on completion } if (wh.IsDisallowNegativeInv() && (OnHandQty - GetMovementQty()) < 0) { // check for From Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } else if (isContainrApplicable && wh.IsDisallowNegativeInv() && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQty - GetMovementQty()) < 0) { // check container qty - for From Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainer") + containerQty); return(false); } else if (whTo.IsDisallowNegativeInv() && (OnHandQtyTo + GetMovementQty()) < 0) { // check for To Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQtyTo); return(false); } else if (isContainrApplicable && whTo.IsDisallowNegativeInv() && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQtyTo + GetMovementQty()) < 0) { // check for To Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainerTo") + containerQtyTo); return(false); } } } if (Env.IsModuleInstalled("DTD001_")) { // not used this variable, that why commented //qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable 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(); //} //qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry)); qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("MovementQty")); //if (wh.IsDisallowNegativeInv() == true) //{ // if ((qtyAvailable < (GetMovementQty() - qtyReserved))) // { // log.SaveError("Message", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "DTD001_QtyNotAvailable")); // return false; // } //} } //By Amit - 17-April-2017 if (Env.IsModuleInstalled("VA024_")) { // checking are we moving product from one warehouse to other warehouse if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT CASE WHEN ((SELECT CASE WHEN o.IsLegalEntity = 'Y' THEN w.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o.LegalEntityOrg ) END FROM m_warehouse w INNER JOIN ad_org o ON o.AD_Org_ID = w.AD_Org_ID WHERE w.m_warehouse_id = m.DTD001_MWarehouseSource_ID)) = (SELECT CASE WHEN o2.IsLegalEntity = 'Y' THEN w2.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o2.LegalEntityOrg) END FROM m_warehouse w2 INNER JOIN ad_org o2 ON o2.AD_Org_ID = w2.AD_Org_ID WHERE M_Warehouse_ID = m.M_Warehouse_ID ) THEN 0 ELSE (SELECT ad_org_id FROM m_warehouse WHERE M_Warehouse_ID = m.M_Warehouse_ID ) END AS result FROM m_movement m WHERE m_movement_id = " + GetM_Movement_ID(), null, Get_Trx())) > 0) { string qry1 = @"SELECT SUM(o.VA024_UnitPrice) FROM VA024_t_ObsoleteInventory o WHERE o.IsActive = 'Y' AND o.M_Product_ID = " + GetM_Product_ID() + @" and ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" + " AND o.AD_Org_ID = " + GetAD_Org_ID(); VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())); SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetMovementQty())); // is used to get cost of binded cost method / costing level of primary accounting schema Decimal cost = MCost.GetproductCosts(move.GetAD_Client_ID(), move.GetAD_Org_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx(), move.GetDTD001_MWarehouseSource_ID()); SetVA024_CostPrice((cost - VA024_ProvisionPrice) * GetMovementQty()); } } // Mandatory Instance if (GetM_AttributeSetInstanceTo_ID() == 0) { if (GetM_AttributeSetInstance_ID() != 0) // Set to from { SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID()); } else { if (Env.HasModulePrefix("DTD001_", out mInfo)) { //MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); //if (mas.IsInstanceAttribute() // && (mas.IsMandatory() || mas.IsMandatoryAlways())) //{ // log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); // return false; //} // Code Addeded by Bharat as Discussed with Mukesh Sir if (String.IsNullOrEmpty(GetDTD001_AttributeNumber())) { return(true); } else { if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } } //JID_1422: Check No Of Attributes Are Equal To Quantity Or Less Than int Count = CountAttributes(GetDTD001_AttributeNumber()); if (Count != GetQtyEntered()) { if (Count > GetQtyEntered()) { log.SaveError("DTD001_MovementAttrbtGreater", ""); return(false); } else { log.SaveError("DTD001_MovementAttrbtLess", ""); return(false); } } } else { if (product != null) { if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)) { return(true); } else { //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); //ShowMessage.Info("a", true, "Product is not of Attribute Type", null); log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } //Check No Of Attributes Are Equal To Quantity Or Less Than //int Count = CountAttributes(GetDTD001_AttributeNumber()); //if (Count != GetMovementQty()) //{ // if (Count > GetMovementQty()) // { // log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater")); // return false; // } // else // { // log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess")); // return false; // } //} } } } else { //MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); if (mas.IsInstanceAttribute() && (mas.IsMandatory() || mas.IsMandatoryAlways())) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); return(false); } } } } } // ASI return(true); }
protected override bool AfterSave(bool newRecord, bool success) { Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { // JID_0657: Requistion is without ASI but on move selected the ASI system is minus the Reserved qty from ASI field but not removing the reserved qty without ASI _mvlNewAttId = GetM_AttributeSetInstance_ID(); if (_mvlOldAttId != _mvlNewAttId && !newRecord && GetM_RequisitionLine_ID() != 0) { // Set QtyReserved On Storage Correspng to New attributesetinstc_id storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); // Trx used to handle query stuck problem if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); // Trx used to handle query stuck problem } storage.SetQtyReserved(storage.GetQtyReserved() + qtyReserved); if (!storage.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), _mvlOldAttId, Get_Trx()); // Trx used to handle query stuck problem if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), _mvlOldAttId, Get_Trx()); // Trx used to handle query stuck problem } storage.SetQtyReserved(storage.GetQtyReserved() - qtyReserved); if (!storage.Save()) { return(false); } }//vikas if (!newRecord && GetM_RequisitionLine_ID() != 0 && GetConfirmedQty() == 0 && String.IsNullOrEmpty(GetDescription())) { MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx()); // Trx used to handle query stuck problem requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + (GetMovementQty() - qtyReserved)); if (!requisition.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); // Trx used to handle query stuck problem if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); // Trx used to handle query stuck problem } storage.SetQtyReserved(storage.GetQtyReserved() + (GetMovementQty() - qtyReserved)); if (!storage.Save()) { return(false); } } if (newRecord && GetM_RequisitionLine_ID() != 0 && GetDescription() != "RC") { MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx()); // Trx used to handle query stuck problem requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + GetMovementQty()); if (!requisition.Save()) { return(false); } storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); // Trx used to handle query stuck problem if (storage == null) { storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx()); // Trx used to handle query stuck problem } storage.SetQtyReserved(storage.GetQtyReserved() + GetMovementQty()); if (!storage.Save()) { return(false); } } } // 17-April-2017 Amit // If Provision already occured against any product then need to give message to client that //Inventory Provision on the selected Product/s is/are done with the Specific Organization. if (Env.IsModuleInstalled("VA024_")) { // checking are we moving product from one warehouse to other warehouse if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT CASE WHEN ((SELECT CASE WHEN o.IsLegalEntity = 'Y' THEN w.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o.LegalEntityOrg ) END FROM m_warehouse w INNER JOIN ad_org o ON o.AD_Org_ID = w.AD_Org_ID WHERE w.m_warehouse_id = m.DTD001_MWarehouseSource_ID)) = (SELECT CASE WHEN o2.IsLegalEntity = 'Y' THEN w2.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o2.LegalEntityOrg) END FROM m_warehouse w2 INNER JOIN ad_org o2 ON o2.AD_Org_ID = w2.AD_Org_ID WHERE M_Warehouse_ID = m.M_Warehouse_ID ) THEN 0 ELSE (SELECT ad_org_id FROM m_warehouse WHERE M_Warehouse_ID = m.M_Warehouse_ID ) END AS result FROM m_movement m WHERE m_movement_id = " + GetM_Movement_ID(), null, Get_Trx())) > 0) { //checking product is provisioned or not if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(*) FROM va024_t_obsoleteinventory WHERE ISACTIVE = 'Y' AND AD_Org_ID = " + GetAD_Org_ID() + @" AND M_Product_ID = " + GetM_Product_ID() + " AND NVL(M_AttributeSetInstance_ID , 0) = " + Util.GetValueOfInt(GetM_AttributeSetInstance_ID()))) > 0) { log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "VA024_AlreadyProvisionConvey")); } } } return(true); }
/// <summary> /// Complete Document /// </summary> /// <returns>new status (Complete, In Progress, Invalid, Waiting ..)</returns> public String CompleteIt() { // Re-Check if (!_justPrepared) { String status = PrepareIt(); if (!DocActionVariables.STATUS_INPROGRESS.Equals(status)) { return(status); } } // Implicit Approval if (!IsApproved()) { ApproveIt(); } log.Info("CompleteIt - " + ToString()); // MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName()); MMovementLineConfirm[] lines = GetLines(false); for (int i = 0; i < lines.Length; i++) { MMovementLineConfirm confirm = lines[i]; confirm.Set_TrxName(Get_TrxName()); if (!confirm.ProcessLine()) { _processMsg = "ShipLine not saved - " + confirm; return(DocActionVariables.STATUS_INVALID); } if (confirm.IsFullyConfirmed()) { confirm.SetProcessed(true); confirm.Save(Get_TrxName()); } else { if (CreateDifferenceDoc(move, confirm)) { confirm.SetProcessed(true); confirm.Save(Get_TrxName()); } else { log.Log(Level.SEVERE, "completeIt - Scrapped=" + confirm.GetScrappedQty() + " - Difference=" + confirm.GetDifferenceQty()); _processMsg = "Differnce Doc not created"; return(DocActionVariables.STATUS_INVALID); } } } // for all lines if (_inventoryInfo != null) { _processMsg = " @M_Inventory_ID@: " + _inventoryInfo; AddDescription(Msg.Translate(GetCtx(), "M_Inventory_ID") + ": " + _inventoryInfo); } //Amit 21-nov-2014 (Reduce reserved quantity from requisition and warehouse distribution center) Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { MMovementLine movementLine = null; MRequisitionLine requisitionLine = null; MStorage storage = null; for (int i = 0; i < lines.Length; i++) { MMovementLineConfirm confirm = lines[i]; if (confirm.GetDifferenceQty() > 0) { movementLine = new MMovementLine(GetCtx(), confirm.GetM_MovementLine_ID(), Get_Trx()); if (movementLine.GetM_RequisitionLine_ID() > 0) { requisitionLine = new MRequisitionLine(GetCtx(), movementLine.GetM_RequisitionLine_ID(), Get_Trx()); requisitionLine.SetDTD001_ReservedQty(decimal.Subtract(requisitionLine.GetDTD001_ReservedQty(), confirm.GetDifferenceQty())); if (!requisitionLine.Save(Get_Trx())) { _processMsg = Msg.GetMsg(GetCtx(), "DTD001_ReqNotUpdate"); // _processMsg = "Requisitionline not updated"; return(DocActionVariables.STATUS_INVALID); } storage = MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), movementLine.GetM_AttributeSetInstance_ID(), Get_Trx()); if (storage == null) { storage = MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), 0, Get_Trx()); } storage.SetQtyReserved(decimal.Subtract(storage.GetQtyReserved(), confirm.GetDifferenceQty())); if (!storage.Save(Get_Trx())) { _processMsg = Msg.GetMsg(GetCtx(), "DTD001_StorageNotUpdate"); //_processMsg = "Storage From not updated (MA)"; return(DocActionVariables.STATUS_INVALID); } } } } } //Amit SetProcessed(true); SetDocAction(DOCACTION_Close); return(DocActionVariables.STATUS_COMPLETED); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true</returns> protected override Boolean BeforeSave(Boolean newRecord) { Decimal VA024_ProvisionPrice = 0; MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID()); // By vikas // Get Old Value of AttributeSetInstance_ID _mvlOldAttId = Util.GetValueOfInt(Get_ValueOld("M_AttributeSetInstance_ID")); // Set Line No if (GetLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID(); int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetLine(ii); } // Check Locator For Header Warehouse MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName()); MLocator loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName()); Tuple <string, string, string> aInfo = null; if (Env.HasModulePrefix("DTD001_", out aInfo)) { if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID()) { } else { String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'"; int ii = DataBase.DB.GetSQLValue(Get_TrxName(), sql); SetM_Locator_ID(ii); } } if (GetM_Locator_ID() == GetM_LocatorTo_ID()) { log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement return(false); } if (Env.Signum(GetMovementQty()) == 0 && Util.GetValueOfInt(GetTargetQty()) == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty")); return(false); } //Amit Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged")); return(false); } if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged")); return(false); } } //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0) if (Env.IsModuleInstalled("VA203_")) { if (GetM_RequisitionLine_ID() > 0) { MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx()); // Trx used to handle query stuck problem if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID()) { log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame")); return(false); } } } // IF Doc Status = InProgress then No record Save MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx()); // Trx used to handle query stuck problem if (newRecord && move.GetDocStatus() == "IP") { log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate")); return(false); } // change to set Converted Quantity in Movement quantity if there is differnce in UOM of Base Product and UOM Selected on line if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID")) { Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered")); if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID"))) { SetMovementQty(MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered")))); } } // Qty Precision if (newRecord || Is_ValueChanged("QtyEntered")) { SetMovementQty(GetMovementQty()); } MWarehouse wh = null; MWarehouse whTo = null; //string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID(); //M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry)); wh = MWarehouse.Get(GetCtx(), mov.GetDTD001_MWarehouseSource_ID()); whTo = MWarehouse.Get(GetCtx(), mov.GetM_Warehouse_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 M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry)); qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_LocatorTo_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } OnHandQtyTo = Convert.ToDecimal(DB.ExecuteScalar(qry)); // SI_0635 : System is giving error of insufficient qty if disallow is true in TO warehouse and false in From warehouse // when record is in completed & closed stage - then no need to check qty availablity in warehouse if ((wh.IsDisallowNegativeInv() || whTo.IsDisallowNegativeInv()) && (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE" || move.GetDocStatus() == "VO"))) { if (wh.IsDisallowNegativeInv() && (OnHandQty - GetMovementQty()) < 0) { // check for From Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty); return(false); } else if (whTo.IsDisallowNegativeInv() && (OnHandQtyTo + GetMovementQty()) < 0) { // check for To Locator log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQtyTo); return(false); } } if (Env.HasModulePrefix("DTD001_", out mInfo)) { qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID(); if (GetM_AttributeSetInstance_ID() != 0) { qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID(); } qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry)); qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("MovementQty")); //if (wh.IsDisallowNegativeInv() == true) //{ // if ((qtyAvailable < (GetMovementQty() - qtyReserved))) // { // log.SaveError("Message", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "DTD001_QtyNotAvailable")); // return false; // } //} } //By Amit - 17-April-2017 if (Env.IsModuleInstalled("VA024_")) { // checking are we moving product from one warehouse to other warehouse if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT CASE WHEN ((SELECT CASE WHEN o.IsLegalEntity = 'Y' THEN w.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o.LegalEntityOrg ) END FROM m_warehouse w INNER JOIN ad_org o ON o.AD_Org_ID = w.AD_Org_ID WHERE w.m_warehouse_id = m.DTD001_MWarehouseSource_ID)) = (SELECT CASE WHEN o2.IsLegalEntity = 'Y' THEN w2.AD_Org_ID ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o2.LegalEntityOrg) END FROM m_warehouse w2 INNER JOIN ad_org o2 ON o2.AD_Org_ID = w2.AD_Org_ID WHERE M_Warehouse_ID = m.M_Warehouse_ID ) THEN 0 ELSE (SELECT ad_org_id FROM m_warehouse WHERE M_Warehouse_ID = m.M_Warehouse_ID ) END AS result FROM m_movement m WHERE m_movement_id = " + GetM_Movement_ID(), null, Get_Trx())) > 0) { MMovement inventory = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx()); try { string qry1 = @"SELECT SUM(o.VA024_UnitPrice) FROM VA024_t_ObsoleteInventory o WHERE o.IsActive = 'Y' AND o.M_Product_ID = " + GetM_Product_ID() + @" and ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" + " AND o.AD_Org_ID = " + GetAD_Org_ID(); VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())); SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetMovementQty())); qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + GetMovementQty(); qry1 += @" FROM m_product p INNER JOIN va024_t_obsoleteinventory oi ON p.m_product_id = oi.M_product_ID INNER JOIN m_product_category pc ON pc.m_product_category_ID = p.m_product_category_ID INNER JOIN AD_client c ON c.AD_Client_ID = p.Ad_Client_ID INNER JOIN AD_ClientInfo ci ON c.AD_Client_ID = ci.Ad_Client_ID INNER JOIN m_cost ct ON ( p.M_Product_ID = ct.M_Product_ID AND ci.C_AcctSchema1_ID = ct.C_AcctSchema_ID ) INNER JOIN c_acctschema asch ON (asch.C_AcctSchema_ID = ci.C_AcctSchema1_ID) INNER JOIN va024_obsoleteinvline oil ON oil.va024_obsoleteinvline_ID = oi.va024_obsoleteinvline_ID "; qry1 += @" WHERE ct.AD_Org_ID = CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel = 'C' OR pc.costinglevel = 'B')) THEN 0 WHEN (pc.costinglevel IS NULL AND asch.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel = 'C' OR asch.costinglevel = 'B')) THEN 0 END AND ct.m_costelement_id = CASE WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod != 'C') THEN (SELECT MIN(m_costelement_id) FROM m_costelement WHERE m_costelement.costingmethod =pc.costingmethod AND m_costelement.Ad_Client_ID = oi.ad_client_id ) WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod = 'C' ) THEN pc.m_costelement_id WHEN ( pc.costingmethod IS NULL AND asch.costingmethod != 'C') THEN (SELECT MIN(m_costelement_id) FROM m_costelement WHERE m_costelement.costingmethod = asch.costingmethod AND m_costelement.Ad_Client_ID = oi.ad_client_id ) WHEN ( pc.costingmethod IS NULL AND asch.costingmethod = 'C') THEN asch.m_costelement_id END AND NVL(ct.M_Attributesetinstance_ID , 0) = CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel = 'C' OR pc.costinglevel = 'O')) THEN 0 WHEN ( pc.costinglevel IS NULL AND asch.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel = 'C' OR asch.costinglevel = 'O')) THEN 0 END AND p.M_Product_ID = " + GetM_Product_ID(); SetVA024_CostPrice(Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()))); } catch { } } } // Mandatory Instance if (GetM_AttributeSetInstanceTo_ID() == 0) { if (GetM_AttributeSetInstance_ID() != 0) // Set to from { SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID()); } else { if (Env.HasModulePrefix("DTD001_", out mInfo)) { //MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); //if (mas.IsInstanceAttribute() // && (mas.IsMandatory() || mas.IsMandatoryAlways())) //{ // log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); // return false; //} // Code Addeded by Bharat as Discussed with Mukesh Sir if (String.IsNullOrEmpty(GetDTD001_AttributeNumber())) { return(true); } else { if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } } } else { if (product != null) { if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)) { return(true); } else { //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); //ShowMessage.Info("a", true, "Product is not of Attribute Type", null); log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber")); return(false); } //Check No Of Attributes Are Equal To Quantity Or Less Than int Count = CountAttributes(GetDTD001_AttributeNumber()); if (Count != GetMovementQty()) { if (Count > GetMovementQty()) { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater")); return(false); } else { log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess")); return(false); } } } } } else { //MProduct product = GetProduct(); if (product != null && product.GetM_AttributeSet_ID() != 0) { MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID()); if (mas.IsInstanceAttribute() && (mas.IsMandatory() || mas.IsMandatoryAlways())) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID")); return(false); } } } } } // ASI return(true); }
/** * Close Document. * Cancel not delivered Qunatities * @return true if success */ public bool CloseIt() { try { log.Info("closeIt - " + ToString()); // Close Not delivered Qty MRequisitionLine[] lines = GetLines(); Decimal totalLines = Env.ZERO; for (int i = 0; i < lines.Length; i++) { MRequisitionLine line = lines[i]; Decimal finalQty = line.GetQty(); if (line.GetC_OrderLine_ID() == 0) { finalQty = Env.ZERO; } else { MOrderLine ol = new MOrderLine(GetCtx(), line.GetC_OrderLine_ID(), Get_TrxName()); finalQty = ol.GetQtyOrdered(); } Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { int quant = Util.GetValueOfInt(line.GetQty() - line.GetDTD001_DeliveredQty()); //Update storage requisition reserved qty if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0) { if (GetDocAction() != "VO" && GetDocStatus() != "DR") { if (quant > 0) { int loc_id = GetLocation(GetM_Warehouse_ID()); storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null); } storage.SetDTD001_QtyReserved((Decimal.Subtract(storage.GetDTD001_QtyReserved(), (Decimal)quant))); storage.Save(); } } } else if (GetDocAction() != "VO" && GetDocStatus() != "DR") { if (quant > 0) { int loc_id = GetLocation(GetM_Warehouse_ID()); storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), 0, null); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), 0, null); } storage.SetDTD001_QtyReserved((Decimal.Subtract(storage.GetDTD001_QtyReserved(), (Decimal)quant))); storage.Save(); } } } // final qty is not line qty if (finalQty.CompareTo(line.GetQty()) != 0) { String description = line.GetDescription(); if (description == null) { description = ""; } description += " [" + line.GetQty() + "]"; line.SetDescription(description); // Amit 9-feb-2015 // line.SetQty(finalQty); //Amit line.SetLineNetAmt(); line.Save(); } //get Grand Total or SubTotal totalLines = Decimal.Add(totalLines, line.GetLineNetAmt()); } if (totalLines.CompareTo(GetTotalLines()) != 0) { SetTotalLines(totalLines); Save(); } } catch (Exception ex) { // MessageBox.Show("MRequisition--CloseIt"); log.Severe(ex.ToString()); } return(true); }
/** * Complete Document * @return new status (Complete, In Progress, Invalid, Waiting ..) */ public String CompleteIt() { try { // Re-Check if (!_justPrepared) { String status = PrepareIt(); if (!DocActionVariables.STATUS_INPROGRESS.Equals(status)) { return(status); } } // Implicit Approval if (!IsApproved()) { ApproveIt(); } log.Info(ToString()); // User Validation String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE); if (valid != null) { _processMsg = valid; return(DocActionVariables.STATUS_INVALID); } // SetProcessed(true); SetDocAction(DocActionVariables.ACTION_CLOSE); /**************************************************************************************************************/ Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { MRequisitionLine[] lines = GetLines(); for (int i = 0; i < lines.Length; i++) { MRequisitionLine line = lines[i]; int loc_id = GetLocation(GetM_Warehouse_ID()); if (loc_id == 0) { //return Msg.GetMsg(GetCtx(),"MMPM_DefineLocator"); _processMsg = "Define Locator For That Warehouse"; return(DocActionVariables.STATUS_INVALID); } if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0) { storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null); } storage.SetDTD001_QtyReserved((Decimal.Add(storage.GetDTD001_QtyReserved(), (Decimal)line.GetQty()))); if (!storage.Save()) { log.Info("Requisition Reserverd Quantity not saved at storage at locator " + loc_id + " and product is " + line.GetM_Product_ID()); } } else { storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), 0, null); if (storage == null) { //MStorage.Add(GetCtx(), GetM_Warehouse_ID(), loc_id, line.GetM_Product_ID(), 0, 0, 0, 0, line.GetQty(), null); MStorage.Add(GetCtx(), GetM_Warehouse_ID(), loc_id, line.GetM_Product_ID(), 0, 0, (Decimal)0, (Decimal)0, (Decimal)0, line.GetQty(), null); } else { storage.SetDTD001_QtyReserved((Decimal.Add(storage.GetDTD001_QtyReserved(), (Decimal)line.GetQty()))); storage.Save(); } } } } } catch (Exception ex) { //MessageBox.Show("MRequisition--CompleteIt"); log.Severe(ex.ToString()); } return(DocActionVariables.STATUS_COMPLETED); }
/** * Prepare Document * @return new status (In Progress or Invalid) */ public String PrepareIt() { try { log.Info(ToString()); _processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE); if (_processMsg != null) { return(DocActionVariables.STATUS_INVALID); } MRequisitionLine[] lines = GetLines(); // Invalid if (GetAD_User_ID() == 0 || GetM_PriceList_ID() == 0 || GetM_Warehouse_ID() == 0 || lines.Length == 0) { return(DocActionVariables.STATUS_INVALID); } // Std Period open? if (!MPeriod.IsOpen(GetCtx(), GetDateDoc(), MDocBaseType.DOCBASETYPE_PURCHASEREQUISITION)) { _processMsg = "@PeriodClosed@"; return(DocActionVariables.STATUS_INVALID); } // is Non Business Day? if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateDoc())) { _processMsg = Common.Common.NONBUSINESSDAY; return(DocActionVariables.STATUS_INVALID); } // Add up Amounts int precision = MPriceList.GetStandardPrecision(GetCtx(), GetM_PriceList_ID()); Decimal totalLines = Env.ZERO; for (int i = 0; i < lines.Length; i++) { MRequisitionLine line = lines[i]; Decimal lineNet = Decimal.Multiply(line.GetQty(), line.GetPriceActual()); lineNet = Decimal.Round(lineNet, precision);//, MidpointRounding.AwayFromZero); if (lineNet.CompareTo(line.GetLineNetAmt()) != 0) { line.SetLineNetAmt(lineNet); line.Save(); } totalLines = Decimal.Add(totalLines, line.GetLineNetAmt()); } if (totalLines.CompareTo(GetTotalLines()) != 0) { SetTotalLines(totalLines); Save(); } _justPrepared = true; } catch (Exception ex) { // MessageBox.Show("MRequisition--PrepareIt"); log.Severe(ex.ToString()); } return(DocActionVariables.STATUS_INPROGRESS); }
/** * Complete Document * @return new status (Complete, In Progress, Invalid, Waiting ..) */ public String CompleteIt() { try { // Re-Check if (!_justPrepared) { String status = PrepareIt(); if (!DocActionVariables.STATUS_INPROGRESS.Equals(status)) { return(status); } } // JID_1290: Set the document number from completed document sequence after completed (if needed) SetCompletedDocumentNo(); // Implicit Approval if (!IsApproved()) { ApproveIt(); } log.Info(ToString()); // User Validation String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE); if (valid != null) { _processMsg = valid; return(DocActionVariables.STATUS_INVALID); } // SetProcessed(true); SetDocAction(DocActionVariables.ACTION_CLOSE); /**************************************************************************************************************/ // Check Column Name new 6jan 0 vikas int _count = Util.GetValueOfInt(DB.ExecuteScalar(" SELECT Count(*) FROM AD_Column WHERE columnname = 'DTD001_SourceReserve' ")); Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { MRequisitionLine[] lines = GetLines(); MProduct product = null; for (int i = 0; i < lines.Length; i++) { MRequisitionLine line = lines[i]; if (line.GetM_Product_ID() > 0) { product = MProduct.Get(GetCtx(), line.GetM_Product_ID()); } int loc_id = GetLocation(GetM_Warehouse_ID()); //new 6jan 1 int Sourcewhloc_id = GetSwhLocation(GetDTD001_MWarehouseSource_ID()); if (Sourcewhloc_id == 0) { // JID_1098: done by Bharat on 31 Jan 2019, need to correct these messages _processMsg = Msg.GetMsg(GetCtx(), "DTD001_DefineSrcLocator"); //"Define Locator For That SourceWarehouse"; return(DocActionVariables.STATUS_INVALID); } //End if (loc_id == 0) { //return Msg.GetMsg(GetCtx(),"MMPM_DefineLocator"); _processMsg = Msg.GetMsg(GetCtx(), "DTD001_DefineLocator"); //"Define Locator For That Warehouse"; return(DocActionVariables.STATUS_INVALID); } if (line.Get_ColumnIndex("OrderLocator_ID") > 0) { line.SetOrderLocator_ID(loc_id); line.SetReserveLocator_ID(Sourcewhloc_id); if (!line.Save()) { _processMsg = Msg.GetMsg(GetCtx(), "ReqLineNotSaved"); return(DocActionVariables.STATUS_INVALID); } } //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0) // SI_0686_2 : storage should not update in case of product is other than item type. if (Env.IsModuleInstalled("VA203_") && product != null && product.GetProductType() == X_M_Product.PRODUCTTYPE_Item) { storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx()); if (storage == null) { storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx()); } storage.SetDTD001_QtyReserved((Decimal.Add(storage.GetDTD001_QtyReserved(), (Decimal)line.GetQty()))); if (!storage.Save()) { log.Info("Requisition Reserverd Quantity not saved at storage at locator " + loc_id + " and product is " + line.GetM_Product_ID()); } ///new 6jan 2 if (_count > 0) { Swhstorage = MStorage.Get(GetCtx(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx()); if (Swhstorage == null) { Swhstorage = MStorage.GetCreate(GetCtx(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx()); } Swhstorage.SetDTD001_SourceReserve((Decimal.Add(Swhstorage.GetDTD001_SourceReserve(), (Decimal)line.GetQty()))); if (!Swhstorage.Save()) { log.Info("Requisition Reserverd Quantity not saved at storage at locator " + Sourcewhloc_id + " and product is " + line.GetM_Product_ID()); } } //End } else if (product != null && product.GetProductType() == X_M_Product.PRODUCTTYPE_Item) { // SI_0657: consider Attribute also storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx()); if (storage == null) { //MStorage.Add(GetCtx(), GetM_Warehouse_ID(), loc_id, line.GetM_Product_ID(), 0, 0, 0, 0, line.GetQty(), null); MStorage.Add(GetCtx(), GetM_Warehouse_ID(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.GetM_AttributeSetInstance_ID(), (Decimal)0, (Decimal)0, (Decimal)0, line.GetQty(), Get_Trx()); } else { storage.SetDTD001_QtyReserved((Decimal.Add(storage.GetDTD001_QtyReserved(), (Decimal)line.GetQty()))); storage.Save(); } //new 6jan 3 if (_count > 0) { Swhstorage = MStorage.Get(GetCtx(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx()); if (Swhstorage == null) { MStorage.Add(GetCtx(), GetDTD001_MWarehouseSource_ID(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.GetM_AttributeSetInstance_ID(), (Decimal)0, (Decimal)0, (Decimal)0, 0, Get_Trx()); MStorage StrgResrvQty = null; StrgResrvQty = MStorage.GetCreate(GetCtx(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx()); StrgResrvQty.SetDTD001_SourceReserve(Decimal.Add(StrgResrvQty.GetDTD001_SourceReserve(), line.GetQty())); StrgResrvQty.Save(); } else { Swhstorage.SetDTD001_SourceReserve((Decimal.Add(Swhstorage.GetDTD001_SourceReserve(), (Decimal)line.GetQty()))); Swhstorage.Save(); } } //End } } } } catch (Exception ex) { //MessageBox.Show("MRequisition--CompleteIt"); log.Severe(ex.ToString()); } return(DocActionVariables.STATUS_COMPLETED); }
/// <summary> /// Complete Document /// </summary> /// <returns>new status (Complete, In Progress, Invalid, Waiting ..)</returns> public String CompleteIt() { // Re-Check if (!_justPrepared) { String status = PrepareIt(); if (!DocActionVariables.STATUS_INPROGRESS.Equals(status)) { return(status); } } // Implicit Approval if (!IsApproved()) { ApproveIt(); } log.Info("CompleteIt - " + ToString()); // MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName()); MMovementLineConfirm[] lines = GetLines(false); #region [Change By Sukhwinder on 11th October,2017 To Check if VA Material Quality Control Module exists or not, and then check if actual value at Quality Control tab exists or not] if (Env.IsModuleInstalled("VA010_")) { try { StringBuilder sb = new StringBuilder(); for (int i = 0; i < lines.Length; i++) { sb.Append(lines[i].Get_ID() + ","); } string mMovementLinesConfirm = sb.ToString().Trim(','); if (!string.IsNullOrEmpty(mMovementLinesConfirm)) { string qry = DBFunctionCollection.MoveConfirmNoActualValue(mMovementLinesConfirm); string productsNoActualValue = Util.GetValueOfString(DB.ExecuteScalar(qry)); if (!string.IsNullOrEmpty(productsNoActualValue)) { //_processMsg = productsNoActualValue + " is/are not verified with all the Quality Parameters." + // " Please fill actual value for the missing Quality Parameters in Quality Control. "; _processMsg = productsNoActualValue + " " + Msg.GetMsg(GetCtx(), "VIS_NoActualValueInQC"); return(DocActionVariables.STATUS_INVALID); } } } catch (Exception ex) { log.Severe("Exception When Checking actual value at Quality Control Tab - " + ex.Message); } } #endregion for (int i = 0; i < lines.Length; i++) { MMovementLineConfirm confirm = lines[i]; confirm.Set_TrxName(Get_TrxName()); //Added By Arpit if (GetDescription() != null && GetDescription().Contains("{->")) { //if (!confirm.ProcessLineReverse()) //{ // _processMsg = "ShipLine not saved - " + confirm; // return DocActionVariables.STATUS_INVALID; //} } else if (!confirm.ProcessLine()) { _processMsg = "ShipLine not saved - " + confirm; return(DocActionVariables.STATUS_INVALID); } if (confirm.IsFullyConfirmed()) { confirm.SetProcessed(true); confirm.Save(Get_TrxName()); } else { if (CreateDifferenceDoc(move, confirm)) { confirm.SetProcessed(true); confirm.Save(Get_TrxName()); } else { log.Log(Level.SEVERE, "completeIt - Scrapped=" + confirm.GetScrappedQty() + " - Difference=" + confirm.GetDifferenceQty()); _processMsg = "Differnce Doc not created"; return(DocActionVariables.STATUS_INVALID); } } } // for all lines if (_inventoryInfo != null) { _processMsg = " @M_Inventory_ID@: " + _inventoryInfo; AddDescription(Msg.Translate(GetCtx(), "M_Inventory_ID") + ": " + _inventoryInfo); } //Amit 21-nov-2014 (Reduce reserved quantity from requisition and warehouse distribution center) Tuple <String, String, String> mInfo = null; if (Env.HasModulePrefix("DTD001_", out mInfo)) { MMovementLine movementLine = null; MRequisitionLine requisitionLine = null; MStorage storage = null; for (int i = 0; i < lines.Length; i++) { MMovementLineConfirm confirm = lines[i]; if (confirm.GetDifferenceQty() > 0) { movementLine = new MMovementLine(GetCtx(), confirm.GetM_MovementLine_ID(), Get_Trx()); if (movementLine.GetM_RequisitionLine_ID() > 0) { requisitionLine = new MRequisitionLine(GetCtx(), movementLine.GetM_RequisitionLine_ID(), Get_Trx()); requisitionLine.SetDTD001_ReservedQty(decimal.Subtract(requisitionLine.GetDTD001_ReservedQty(), confirm.GetDifferenceQty())); if (!requisitionLine.Save(Get_Trx())) { _processMsg = Msg.GetMsg(GetCtx(), "DTD001_ReqNotUpdate"); // _processMsg = "Requisitionline not updated"; return(DocActionVariables.STATUS_INVALID); } storage = MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), movementLine.GetM_AttributeSetInstance_ID(), Get_Trx()); if (storage == null) { storage = MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), 0, Get_Trx()); } storage.SetQtyReserved(decimal.Subtract(storage.GetQtyReserved(), confirm.GetDifferenceQty())); if (!storage.Save(Get_Trx())) { Get_Trx().Rollback(); _processMsg = Msg.GetMsg(GetCtx(), "DTD001_StorageNotUpdate"); //_processMsg = "Storage From not updated (MA)"; return(DocActionVariables.STATUS_INVALID); } } } } } //Amit SetProcessed(true); SetDocAction(DOCACTION_Close); Save(Get_Trx()); //Adde by Arpit To complete The Inventory Move if Move Confirmation is completed ,16th Dec,2016 MMovement Mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx()); if (move.GetDocStatus() != DOCSTATUS_Completed) { string Status = Mov.CompleteIt(); if (Status == "CO") { move.SetDocStatus(DOCSTATUS_Completed); move.SetDocAction("CL"); move.SetProcessed(true); move.Save(Get_Trx()); } else { Get_Trx().Rollback(); _processMsg = Mov.GetProcessMsg(); return(DocActionVariables.STATUS_INVALID); } } //End Here return(DocActionVariables.STATUS_COMPLETED); }