protected override string DoIt() { try { sql.Clear(); sql.Append("SELECT * FROM M_InOut WHERE IsActive = 'Y' AND DocStatus IN ('DR') "); if (C_DocType_ID > 0) { sql.Append(" AND C_DocType_ID = " + C_DocType_ID); } sql.Append(" ORDER BY movementdate"); dsInOut = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); #region complete Order Record if (windowName == "OR") { sql.Clear(); sql.Append("SELECT * FROM C_Order WHERE IsActive = 'Y' AND DocStatus IN ('DR') "); if (C_DocType_ID > 0) { sql.Append(" AND C_DocType_ID = " + C_DocType_ID); } sql.Append(" ORDER BY dateacct"); dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); dataRow = dsRecord.Tables[0].Select("DocStatus = 'DR' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { MOrder order = null; for (int i = 0; i < dataRow.Length; i++) { try { order = new MOrder(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Order_ID"]), Get_Trx()); order.CompleteIt(); if (order.GetDocAction() == "CL") { order.SetDocStatus("CO"); order.SetDocAction("CL"); if (!order.Save(Get_Trx())) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + order.GetC_Order_ID() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { _log.Info("Order not completed for this Record ID = " + order.GetC_Order_ID()); } } catch { } } } } #endregion #region complete Invoice Record if (windowName == "IN") { sql.Clear(); sql.Append("SELECT * FROM C_Invoice WHERE IsActive = 'Y' AND DocStatus IN ('DR') "); if (C_DocType_ID > 0) { sql.Append(" AND C_DocType_ID = " + C_DocType_ID); } sql.Append(" ORDER BY dateacct"); dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); dataRow = dsRecord.Tables[0].Select("DocStatus = 'DR' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { MInvoice invoice = null; for (int i = 0; i < dataRow.Length; i++) { try { invoice = new MInvoice(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Invoice_ID"]), Get_Trx()); invoice.CompleteIt(); if (invoice.GetDocAction() == "CL") { invoice.SetDocStatus("CO"); invoice.SetDocAction("CL"); if (!invoice.Save(Get_Trx())) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Invoice Record ID = " + invoice.GetC_Invoice_ID() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { _log.Info("Invoice not completed for this Record ID = " + invoice.GetC_Invoice_ID()); } } catch { } } } } #endregion #region complete material receipt if (windowName == "MR") { dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'N' AND IsReturnTrx = 'N' AND DocStatus = 'DR' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { for (int i = 0; i < dataRow.Length; i++) { try { inout = new MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx()); inout.CompleteIt(); if (inout.GetDocAction() == "CL") { inout.SetDocStatus("CO"); inout.SetDocAction("CL"); if (!inout.Save(Get_Trx())) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetM_InOut_ID() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { _log.Info("Material Receipt not completed for this Record ID = " + inout.GetM_InOut_ID()); } } catch { } } } } #endregion #region complete Movement Record if (windowName == "IM") { sql.Clear(); sql.Append("SELECT * FROM M_Movement WHERE IsActive = 'Y' AND DocStatus IN ('DR') "); if (C_DocType_ID > 0) { sql.Append(" AND C_DocType_ID = " + C_DocType_ID); } sql.Append(" ORDER BY movementdate"); dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); dataRow = dsRecord.Tables[0].Select("DocStatus = 'DR' ", "movementdate"); if (dataRow != null && dataRow.Length > 0) { MMovement movement = null; for (int i = 0; i < dataRow.Length; i++) { try { movement = new MMovement(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_Movement_ID"]), Get_Trx()); movement.CompleteIt(); if (movement.GetDocAction() == "CL") { movement.SetDocStatus("CO"); movement.SetDocAction("CL"); if (!movement.Save(Get_Trx())) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Invoice Record ID = " + movement.GetM_Movement_ID() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { _log.Info("Movement not completed for this Record ID = " + movement.GetM_Movement_ID()); } } catch { } } } } #endregion #region complete shipment if (windowName == "SH") { dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'Y' AND IsReturnTrx = 'N' AND DocStatus = 'DR' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { for (int i = 0; i < dataRow.Length; i++) { try { inout = new MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx()); inout.CompleteIt(); if (inout.GetDocAction() == "CL") { inout.SetDocStatus("CO"); inout.SetDocAction("CL"); if (!inout.Save(Get_Trx())) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetM_InOut_ID() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { _log.Info("Shipment not completed for this Record ID = " + inout.GetM_InOut_ID()); } } catch { } } } } #endregion #region complete Customer Return if (windowName == "CR") { dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'Y' AND IsReturnTrx = 'Y' AND DocStatus = 'DR' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { for (int i = 0; i < dataRow.Length; i++) { try { inout = new MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx()); inout.CompleteIt(); if (inout.GetDocAction() == "CL") { inout.SetDocStatus("CO"); inout.SetDocAction("CL"); if (!inout.Save(Get_Trx())) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetM_InOut_ID() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { _log.Info("Customer return not completed for this Record ID = " + inout.GetM_InOut_ID()); } } catch { } } } } #endregion #region complete Return to Vendor if (windowName == "VR") { dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'N' AND IsReturnTrx = 'Y' AND DocStatus = 'DR' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { for (int i = 0; i < dataRow.Length; i++) { try { inout = new MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx()); inout.CompleteIt(); if (inout.GetDocAction() == "CL") { inout.SetDocStatus("CO"); inout.SetDocAction("CL"); if (!inout.Save(Get_Trx())) { Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetM_InOut_ID() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { _log.Info("Return to Vendor not completed for this Record ID = " + inout.GetM_InOut_ID()); } } catch { } } } } #endregion } catch (Exception ex) { _log.Info("Error Occured during completion of record by using ImportedDataCompletion Process - " + ex.ToString()); return(Msg.GetMsg(GetCtx(), "NotCompleted")); } return(Msg.GetMsg(GetCtx(), "SucessfullyCompleted")); }
} // createRequisition /// <summary> /// Create Inventory Movements /// </summary> private void CreateMovements() { int noMoves = 0; String info = ""; // MClient client = null; MMovement move = null; int M_Warehouse_ID = 0; int M_WarehouseSource_ID = 0; MWarehouse whSource = null; MWarehouse whTarget = null; string param = ""; if (_M_WareSource != null) { param = _M_WareSource; } else { param = "M_WarehouseSource_ID IS NOT NULL"; } X_T_Replenish[] replenishs = GetReplenish(param);; for (int i = 0; i < replenishs.Length; i++) { X_T_Replenish replenish = replenishs[i]; if (whSource == null || whSource.GetM_WarehouseSource_ID() != replenish.GetM_WarehouseSource_ID()) { whSource = MWarehouse.Get(GetCtx(), replenish.GetM_WarehouseSource_ID()); } if (whTarget == null || whTarget.GetM_Warehouse_ID() != replenish.GetM_Warehouse_ID()) { whTarget = MWarehouse.Get(GetCtx(), replenish.GetM_Warehouse_ID()); } if (client == null || client.GetAD_Client_ID() != whSource.GetAD_Client_ID()) { client = MClient.Get(GetCtx(), whSource.GetAD_Client_ID()); } // if (move == null || M_WarehouseSource_ID != replenish.GetM_WarehouseSource_ID() || M_Warehouse_ID != replenish.GetM_Warehouse_ID()) { M_WarehouseSource_ID = replenish.GetM_WarehouseSource_ID(); M_Warehouse_ID = replenish.GetM_Warehouse_ID(); move = new MMovement(GetCtx(), 0, Get_TrxName()); move.SetC_DocType_ID(_C_DocType_ID); move.SetDescription(Msg.GetMsg(GetCtx(), "Replenishment") + ": " + whSource.GetName() + "->" + whTarget.GetName()); // Set Org move.SetAD_Org_ID(whSource.GetAD_Org_ID()); if (!move.Save()) { return; } log.Fine(move.ToString()); noMoves++; info += " - " + move.GetDocumentNo(); } MProduct product = MProduct.Get(GetCtx(), replenish.GetM_Product_ID()); // To int M_LocatorTo_ID = GetLocator_ID(product, whTarget); // From: Look-up Storage MProductCategory pc = MProductCategory.Get(GetCtx(), product.GetM_Product_Category_ID()); String MMPolicy = pc.GetMMPolicy(); if (MMPolicy == null || MMPolicy.Length == 0) { MMPolicy = client.GetMMPolicy(); } // MStorage[] storages = MStorage.GetWarehouse(GetCtx(), whSource.GetM_Warehouse_ID(), replenish.GetM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.Equals(MMPolicy), Get_TrxName()); if (storages == null || storages.Length == 0) { AddLog("No Inventory in " + whSource.GetName() + " for " + product.GetName()); continue; } // Decimal target = replenish.GetQtyToOrder(); for (int j = 0; j < storages.Length; j++) { MStorage storage = storages[j]; //if (storage.GetQtyOnHand().signum() <= 0) if (Env.Signum(storage.GetQtyOnHand()) <= 0) { continue; } Decimal moveQty = target; if (storage.GetQtyOnHand().CompareTo(moveQty) < 0) { moveQty = storage.GetQtyOnHand(); } // MMovementLine line = new MMovementLine(move); line.SetM_Product_ID(replenish.GetM_Product_ID()); line.SetMovementQty(moveQty); if (replenish.GetQtyToOrder().CompareTo(moveQty) != 0) { line.SetDescription("Total: " + replenish.GetQtyToOrder()); } line.SetM_Locator_ID(storage.GetM_Locator_ID()); // from line.SetM_AttributeSetInstance_ID(storage.GetM_AttributeSetInstance_ID()); line.SetM_LocatorTo_ID(M_LocatorTo_ID); // to line.SetM_AttributeSetInstanceTo_ID(storage.GetM_AttributeSetInstance_ID()); line.Save(); // //target = target.subtract(moveQty); target = Decimal.Subtract(target, moveQty); //if (target.signum() == 0) if (Env.Signum(target) == 0) { break; } } if (Env.Signum(target) != 0) { AddLog("Insufficient Inventory in " + whSource.GetName() + " for " + product.GetName() + " Qty=" + target); } } if (replenishs.Length == 0) { _info = "No Source Warehouse"; log.Warning(_info); } else { _info = "#" + noMoves + info; log.Info(_info); } } // createRequisition
/// <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); }
/// <summary> /// Move stock to location /// </summary> /// <param name="target">storage</param> /// <returns>no of movements</returns> private int Move(MStorage target) { log.Info(target.ToString()); Decimal qty = Decimal.Negate(target.GetQtyOnHand());//.negate(); // Create Movement MMovement mh = new MMovement(GetCtx(), 0, Get_Trx()); mh.SetC_DocType_ID(_C_DocType_ID); mh.SetDescription(GetName()); if (!mh.Save()) { return(0); } int lines = 0; MStorage[] sources = GetSources(target.GetM_Product_ID(), target.GetM_Locator_ID()); for (int i = 0; i < sources.Length; i++) { MStorage source = sources[i]; // Movement Line MMovementLine ml = new MMovementLine(mh); ml.SetM_Product_ID(target.GetM_Product_ID()); ml.SetM_LocatorTo_ID(target.GetM_Locator_ID()); ml.SetM_AttributeSetInstanceTo_ID(target.GetM_AttributeSetInstance_ID()); // From ml.SetM_Locator_ID(source.GetM_Locator_ID()); ml.SetM_AttributeSetInstance_ID(source.GetM_AttributeSetInstance_ID()); Decimal qtyMove = qty; if (qtyMove.CompareTo(source.GetQtyOnHand()) > 0) { qtyMove = source.GetQtyOnHand(); } ml.SetMovementQty(qtyMove); // lines++; ml.SetLine(lines * 10); if (!ml.Save()) { return(0); } qty = Decimal.Subtract(qty, qtyMove); if (Env.Signum(qty) <= 0) { break; } } // for all movements // Process //mh.ProcessIt(MMovement.ACTION_Complete); mh.ProcessIt(DocActionVariables.ACTION_COMPLETE); mh.Save(); AddLog(0, null, new Decimal(lines), "@M_Movement_ID@ " + mh.GetDocumentNo() + " (" + MRefList.Get(GetCtx(), MMovement.DOCSTATUS_AD_Reference_ID, mh.GetDocStatus(), Get_Trx()) + ")"); EliminateReservation(target); return(lines); }