/** * Complete Document * @return new status (Complete, In Progress, Invalid, Waiting ..) */ 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(ToString()); // MInOut inout = new MInOut(GetCtx(), GetM_InOut_ID(), Get_TrxName()); MInOutLineConfirm[] lines = GetLines(false); /* created by sunil 19/9/2016*/ if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(*) FROM AD_ModuleInfo WHERE Prefix = 'DTD001_'")) > 0) { MPackage package = new MPackage(GetCtx(), inout.GetM_Package_ID(), Get_Trx()); if (inout.GetM_Package_ID() > 0 && !package.IsDTD001_IsPackgConfirm()) { _processMsg = Msg.GetMsg(GetCtx(), "PleaseConfirmPackage"); return(DocActionVariables.STATUS_INVALID); } } //End // Check if we need to split Shipment if (IsInDispute()) { MDocType dt = MDocType.Get(GetCtx(), inout.GetC_DocType_ID()); if (dt.IsSplitWhenDifference()) { if (dt.GetC_DocTypeDifference_ID() == 0) { _processMsg = "No Split Document Type defined for: " + dt.GetName(); return(DocActionVariables.STATUS_INVALID); } SplitInOut(inout, dt.GetC_DocTypeDifference_ID(), lines); _lines = null; } } // All lines for (int i = 0; i < lines.Length; i++) { MInOutLineConfirm confirmLine = lines[i]; confirmLine.Set_TrxName(Get_TrxName()); if (!confirmLine.ProcessLine(inout.IsSOTrx(), GetConfirmType())) { _processMsg = "ShipLine not saved - " + confirmLine; return(DocActionVariables.STATUS_INVALID); } if (confirmLine.IsFullyConfirmed()) { confirmLine.SetProcessed(true); confirmLine.Save(Get_TrxName()); } else { if (CreateDifferenceDoc(inout, confirmLine)) { confirmLine.SetProcessed(true); confirmLine.Save(Get_TrxName()); } else { log.Log(Level.SEVERE, "Scrapped=" + confirmLine.GetScrappedQty() + " - Difference=" + confirmLine.GetDifferenceQty()); return(DocActionVariables.STATUS_INVALID); } } } // for all lines if (_creditMemo != null) { _processMsg += " @C_Invoice_ID@=" + _creditMemo.GetDocumentNo(); } if (_inventory != null) { // _processMsg += " @M_Inventory_ID@=" + _inventory.GetDocumentNo(); //new 13 jan _processMsg += " Internal.Inventory= " + _inventory.GetDocumentNo(); } // User Validation String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE); if (valid != null) { _processMsg = valid; return(DocActionVariables.STATUS_INVALID); } SetProcessed(true); if (!Save(Get_Trx())) { Get_Trx().Rollback(); _processMsg = "Ship/Receipt Confirmation Not saved"; return(DocActionVariables.STATUS_INVALID); } // Created By Sunil 17/9/2016 // Complete Shipment MInOut io = new MInOut(GetCtx(), GetM_InOut_ID(), Get_TrxName()); var Status = io.CompleteIt(); if (Status == "CO") { io.SetProcessed(true); io.SetDocStatus(DocActionVariables.STATUS_COMPLETED); io.SetDocAction(DocActionVariables.ACTION_CLOSE); io.Save(); } else if (Status == "IN") { Get_Trx().Rollback(); _processMsg = "Shipment Not Completed"; return(DocActionVariables.STATUS_INVALID); } //end //SetProcessed(true); SetDocAction(DOCACTION_Close); return(DocActionVariables.STATUS_COMPLETED); }
protected override string DoIt() { try { _log.Info("Start Imported Data completion for GulfOil : " + System.DateTime.Now); #region complete Order Record sql.Clear(); sql.Append("SELECT * FROM C_Order WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL') ORDER BY dateacct"); dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); dataRow = dsRecord.Tables[0].Select("IsActive = 'Y' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { ViennaAdvantage.Model.MOrder order = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of C_Order "); for (int i = 0; i < dataRow.Length; i++) { try { order = new ViennaAdvantage.Model.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())) { notCompletedRecord.Append(order.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + order.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(order.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Order not completed for this Record ID = " + order.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete Invoice Record sql.Clear(); sql.Append("SELECT * FROM C_Invoice WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL') ORDER BY dateacct"); dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); dataRow = dsRecord.Tables[0].Select("IsActive = 'Y' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { ViennaAdvantage.Model.MInvoice invoice = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of C_Invoice "); for (int i = 0; i < dataRow.Length; i++) { try { invoice = new ViennaAdvantage.Model.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())) { notCompletedRecord.Append(invoice.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Invoice Record ID = " + invoice.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(invoice.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Invoice not completed for this Record ID = " + invoice.GetDocumentNo() + " Message- " + invoice.GetProcessMsg()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion sql.Clear(); sql.Append("SELECT * FROM M_InOut WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY movementdate"); dsInOut = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM M_Inventory WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY movementdate"); dsInventory = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM M_Movement WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY movementdate"); dsMovement = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM C_Payment WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY dateacct"); dsPayment = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM C_Cash WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY dateacct"); dsCashJournal = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM GL_Journal WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY dateacct"); dsGLJournal = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); // min date record from the transaction window minDateRecord = SerachMinDate(); int diff = (DateTime.Now - minDateRecord.Value).Days; for (int days = 0; days <= diff; days++) { if (days != 0) { minDateRecord = minDateRecord.Value.AddDays(1); } try { #region Physical Inventory dataRow = dsInventory.Tables[0].Select("isinternaluse = 'N' AND movementdate = '" + minDateRecord + "'", "M_Inventory_ID"); if (dataRow != null && dataRow.Length > 0) { MInventory inventory = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Physical Inventory "); for (int i = 0; i < dataRow.Length; i++) { try { inventory = new MInventory(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_Inventory_ID"]), Get_Trx()); inventory.CompleteIt(); if (inventory.GetDocAction() == "CL") { inventory.SetDocStatus("CO"); inventory.SetDocAction("CL"); if (!inventory.Save(Get_Trx())) { notCompletedRecord.Append(inventory.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving Physical Inventory Record ID = " + inventory.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inventory.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Physical Inventory not completed for this Record ID = " + inventory.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region Internal use inventory dataRow = dsInventory.Tables[0].Select("isinternaluse = 'Y' AND movementdate = '" + minDateRecord + "'", "M_Inventory_ID"); if (dataRow != null && dataRow.Length > 0) { MInventory inventory = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Internal use inventory "); for (int i = 0; i < dataRow.Length; i++) { try { inventory = new MInventory(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_Inventory_ID"]), Get_Trx()); inventory.CompleteIt(); if (inventory.GetDocAction() == "CL") { inventory.SetDocStatus("CO"); inventory.SetDocAction("CL"); if (!inventory.Save(Get_Trx())) { notCompletedRecord.Append(inventory.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving Physical Inventory Record ID = " + inventory.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inventory.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Physical Inventory not completed for this Record ID = " + inventory.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete material receipt dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'N' AND IsReturnTrx = 'N' AND DocStatus NOT IN ('CO' , 'CL') AND DateAcct = '" + minDateRecord + "'", "M_InOut_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of material receipt "); for (int i = 0; i < dataRow.Length; i++) { try { inout = new ViennaAdvantage.Model.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())) { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Material Receipt not completed for this Record ID = " + inout.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete Movement Record dataRow = dsMovement.Tables[0].Select("movementdate = '" + minDateRecord + "'", "M_Movement_ID"); if (dataRow != null && dataRow.Length > 0) { ViennaAdvantage.Model.MMovement movement = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of M_Movement "); for (int i = 0; i < dataRow.Length; i++) { try { movement = new ViennaAdvantage.Model.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())) { notCompletedRecord.Append(movement.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Invoice Record ID = " + movement.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(movement.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Movement not completed for this Record ID = " + movement.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete shipment dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'Y' AND IsReturnTrx = 'N' AND DateAcct = '" + minDateRecord + "'", "M_Inout_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of shipment "); for (int i = 0; i < dataRow.Length; i++) { try { inout = new ViennaAdvantage.Model.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())) { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Shipment not completed for this Record ID = " + inout.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete Customer Return dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'Y' AND IsReturnTrx = 'Y' AND DateAcct = '" + minDateRecord + "'", "M_Inout_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Customer Return "); for (int i = 0; i < dataRow.Length; i++) { try { inout = new ViennaAdvantage.Model.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())) { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Customer return not completed for this Record ID = " + inout.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete Return to Vendor dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'N' AND IsReturnTrx = 'Y' AND DateAcct = '" + minDateRecord + "'", "M_InOut_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Return to Vendor "); for (int i = 0; i < dataRow.Length; i++) { try { inout = new ViennaAdvantage.Model.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())) { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Return to Vendor not completed for this Record ID = " + inout.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region Complete Payment dataRow = dsPayment.Tables[0].Select("DateAcct = '" + minDateRecord + "'", "C_Payment_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Payment "); for (int i = 0; i < dataRow.Length; i++) { try { payment = new MPayment(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Payment_ID"]), Get_Trx()); payment.CompleteIt(); if (payment.GetDocAction() == "CL") { payment.SetDocStatus("CO"); payment.SetDocAction("CL"); if (!payment.Save(Get_Trx())) { notCompletedRecord.Append(payment.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Payment Record ID = " + payment.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(payment.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Payment not completed for this Record ID = " + payment.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region Complete Cash Journal dataRow = dsCashJournal.Tables[0].Select("DateAcct = '" + minDateRecord + "'", "C_Cash_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Cash Journal "); for (int i = 0; i < dataRow.Length; i++) { try { cash = new MCash(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Cash_ID"]), Get_Trx()); cash.CompleteIt(); if (cash.GetDocAction() == "CL") { cash.SetDocStatus("CO"); cash.SetDocAction("CL"); if (!cash.Save(Get_Trx())) { notCompletedRecord.Append(cash.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Cash Record ID = " + cash.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(cash.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Cash Journal not completed for this Record ID = " + cash.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region Complete GL Journal dataRow = dsGLJournal.Tables[0].Select("DateAcct = '" + minDateRecord + "'", "GL_Journal_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of GL Journal "); for (int i = 0; i < dataRow.Length; i++) { try { journal = new MJournal(GetCtx(), Util.GetValueOfInt(dataRow[i]["GL_Journal_ID"]), Get_Trx()); journal.CompleteIt(); if (journal.GetDocAction() == "CL") { journal.SetDocStatus("CO"); journal.SetDocAction("CL"); if (!journal.Save(Get_Trx())) { notCompletedRecord.Append(journal.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Cash Record ID = " + journal.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(journal.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Cash Journal not completed for this Record ID = " + journal.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion } catch { } } _log.Info(" End Imported Data completion for GulfOil : " + System.DateTime.Now); } catch (Exception ex) { _log.Info("Error Occured during completion of record by using ImportedDataCompletion Process - " + ex.ToString()); return(Msg.GetMsg(GetCtx(), "NotCompleted")); } if (!string.IsNullOrEmpty(errorMessage.ToString())) { return("Not Completed Record : " + errorMessage.ToString()); } else { return(Msg.GetMsg(GetCtx(), "SucessfullyCompleted")); } }
/// <summary> /// Create Difference Document. /// Creates one or two inventory lines /// </summary> /// <param name="move">movement</param> /// <param name="confirm">confirm line</param> /// <returns>true if created</returns> private Boolean CreateDifferenceDoc(MMovement move, MMovementLineConfirm confirm) { string query = ""; int result = 0; decimal currentQty = 0; MMovementLine mLine = confirm.GetLine(); // Difference - Create Inventory Difference for Source Location if (Env.ZERO.CompareTo(confirm.GetDifferenceQty()) != 0) { // Get Warehouse for Source MLocator loc = MLocator.Get(GetCtx(), mLine.GetM_Locator_ID()); if (_inventoryFrom != null && _inventoryFrom.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID()) { _inventoryFrom = null; } if (_inventoryFrom == null) { MWarehouse wh = MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID()); _inventoryFrom = new MInventory(wh); _inventoryFrom.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo()); if (!_inventoryFrom.Save(Get_TrxName())) { _processMsg += "Inventory not created"; return(false); } // First Inventory if (GetM_Inventory_ID() == 0) { SetM_Inventory_ID(_inventoryFrom.GetM_Inventory_ID()); _inventoryInfo = _inventoryFrom.GetDocumentNo(); } else { _inventoryInfo += "," + _inventoryFrom.GetDocumentNo(); } } log.Info("createDifferenceDoc - Difference=" + confirm.GetDifferenceQty()); MInventoryLine line = new MInventoryLine(_inventoryFrom, mLine.GetM_Locator_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(), confirm.GetDifferenceQty(), Env.ZERO); //Added By amit 11-jun-2015 //Opening Stock , Qunatity Book => CurrentQty From Transaction of MovementDate //As On Date Count = Opening Stock - Diff Qty //Qty Count = Qty Book - Diff Qty query = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate = " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); result = Util.GetValueOfInt(DB.ExecuteScalar(query)); if (result > 0) { query = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID = (SELECT MAX(M_Transaction_ID) FROM M_Transaction WHERE movementdate = (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query)); } else { query = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); result = Util.GetValueOfInt(DB.ExecuteScalar(query)); if (result > 0) { query = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID = (SELECT MAX(M_Transaction_ID) FROM M_Transaction WHERE movementdate = (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query)); } } //End line.SetAdjustmentType("D"); line.SetDifferenceQty(Util.GetValueOfDecimal(confirm.GetDifferenceQty())); line.SetQtyBook(currentQty); line.SetOpeningStock(currentQty); line.SetAsOnDateCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetOpeningStock()), Util.GetValueOfDecimal(confirm.GetDifferenceQty()))); line.SetQtyCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetQtyBook()), Util.GetValueOfDecimal(confirm.GetDifferenceQty()))); line.SetDescription(Msg.Translate(GetCtx(), "DifferenceQty")); if (!line.Save(Get_TrxName())) { _processMsg += "Inventory Line not created"; return(false); } confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID()); } // Difference // Scrapped - Create Inventory Difference for TarGet Location if (Env.ZERO.CompareTo(confirm.GetScrappedQty()) != 0) { // Get Warehouse for TarGet MLocator loc = MLocator.Get(GetCtx(), mLine.GetM_LocatorTo_ID()); if (_inventoryTo != null && _inventoryTo.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID()) { _inventoryTo = null; } if (_inventoryTo == null) { MWarehouse wh = MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID()); _inventoryTo = new MInventory(wh); _inventoryTo.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo()); if (!_inventoryTo.Save(Get_TrxName())) { _processMsg += "Inventory not created"; return(false); } // First Inventory if (GetM_Inventory_ID() == 0) { SetM_Inventory_ID(_inventoryTo.GetM_Inventory_ID()); _inventoryInfo = _inventoryTo.GetDocumentNo(); } else { _inventoryInfo += "," + _inventoryTo.GetDocumentNo(); } } log.Info("CreateDifferenceDoc - Scrapped=" + confirm.GetScrappedQty()); MInventoryLine line = new MInventoryLine(_inventoryTo, mLine.GetM_LocatorTo_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(), confirm.GetScrappedQty(), Env.ZERO); line.SetDescription(Msg.Translate(GetCtx(), "ScrappedQty")); if (!line.Save(Get_TrxName())) { _processMsg += "Inventory Line not created"; return(false); } confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID()); } // Scrapped return(true); }
/** * Complete Document * @return new status (Complete, In Progress, Invalid, Waiting ..) */ 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(ToString()); // MInOut inout = new MInOut(GetCtx(), GetM_InOut_ID(), Get_TrxName()); MInOutLineConfirm[] lines = GetLines(false); // Check if we need to split Shipment if (IsInDispute()) { MDocType dt = MDocType.Get(GetCtx(), inout.GetC_DocType_ID()); if (dt.IsSplitWhenDifference()) { if (dt.GetC_DocTypeDifference_ID() == 0) { _processMsg = "No Split Document Type defined for: " + dt.GetName(); return(DocActionVariables.STATUS_INVALID); } SplitInOut(inout, dt.GetC_DocTypeDifference_ID(), lines); _lines = null; } } // All lines for (int i = 0; i < lines.Length; i++) { MInOutLineConfirm confirmLine = lines[i]; confirmLine.Set_TrxName(Get_TrxName()); if (!confirmLine.ProcessLine(inout.IsSOTrx(), GetConfirmType())) { _processMsg = "ShipLine not saved - " + confirmLine; return(DocActionVariables.STATUS_INVALID); } if (confirmLine.IsFullyConfirmed()) { confirmLine.SetProcessed(true); confirmLine.Save(Get_TrxName()); } else { if (CreateDifferenceDoc(inout, confirmLine)) { confirmLine.SetProcessed(true); confirmLine.Save(Get_TrxName()); } else { log.Log(Level.SEVERE, "Scrapped=" + confirmLine.GetScrappedQty() + " - Difference=" + confirmLine.GetDifferenceQty()); return(DocActionVariables.STATUS_INVALID); } } } // for all lines if (_creditMemo != null) { _processMsg += " @C_Invoice_ID@=" + _creditMemo.GetDocumentNo(); } if (_inventory != null) { _processMsg += " @M_Inventory_ID@=" + _inventory.GetDocumentNo(); } // User Validation String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE); if (valid != null) { _processMsg = valid; return(DocActionVariables.STATUS_INVALID); } SetProcessed(true); SetDocAction(DOCACTION_Close); return(DocActionVariables.STATUS_COMPLETED); }