/// <summary> /// Create new Journal Batch by copying /// </summary> /// <param name="ctx">context</param> /// <param name="GL_JournalBatch_ID">journal batch</param> /// <param name="dateDoc">date of the document date</param> /// <param name="trxName">transaction</param> /// <returns>Journal Batch</returns> public static MJournalBatch CopyFrom(Ctx ctx, int GL_JournalBatch_ID, DateTime?dateDoc, Trx trxName) { MJournalBatch from = new MJournalBatch(ctx, GL_JournalBatch_ID, trxName); if (from.GetGL_JournalBatch_ID() == 0) { throw new ArgumentException("From Journal Batch not found GL_JournalBatch_ID=" + GL_JournalBatch_ID); } // MJournalBatch to = new MJournalBatch(ctx, 0, trxName); PO.CopyValues(from, to, from.GetAD_Client_ID(), from.GetAD_Org_ID()); to.Set_ValueNoCheck("DocumentNo", null); to.Set_ValueNoCheck("C_Period_ID", null); to.SetDateAcct(dateDoc); to.SetDateDoc(dateDoc); to.SetDocStatus(DOCSTATUS_Drafted); to.SetDocAction(DOCACTION_Complete); to.SetIsApproved(false); to.SetProcessed(false); // if (!to.Save()) { throw new Exception("Could not create Journal Batch"); } if (to.CopyDetailsFrom(from) == 0) { throw new Exception("Could not create Journal Batch Details"); } return(to); } // copyFrom
} // reverseCorrectionIt /// <summary> /// Reverse Accrual. Flip Dr/Cr - Use Today's date /// </summary> /// <returns>true if success </returns> public Boolean ReverseAccrualIt() { log.Info("ReverseCorrectIt - " + ToString()); MJournal[] journals = GetJournals(true); // check prerequisites for (int i = 0; i < journals.Length; i++) { MJournal journal = journals[i]; if (!journal.IsActive()) { continue; } // All need to be closed/Completed if (DOCSTATUS_Completed.Equals(journal.GetDocStatus())) { ; } else { m_processMsg = "All Journals need to be Compleded: " + journal.GetSummary(); return(false); } } // Reverse it MJournalBatch reverse = new MJournalBatch(this); reverse.SetC_Period_ID(0); //reverse.SetDateDoc(new Timestamp(System.currentTimeMillis())); reverse.SetDateDoc(DateTime.Now); reverse.SetDateAcct(reverse.GetDateDoc()); // Reverse indicator String description = reverse.GetDescription(); if (description == null) { description = "** " + GetDocumentNo() + " **"; } else { description += " ** " + GetDocumentNo() + " **"; } reverse.SetDescription(description); reverse.Save(); // Reverse Journals for (int i = 0; i < journals.Length; i++) { MJournal journal = journals[i]; if (!journal.IsActive()) { continue; } if (journal.ReverseCorrectIt(reverse.GetGL_JournalBatch_ID()) == null) { m_processMsg = "Could not reverse " + journal; return(false); } journal.Save(); } return(true); } // ReverseCorrectIt
} // closeIt /// <summary> /// Reverse Correction.As if nothing happened - same date /// </summary> /// <returns>true if success </returns> public Boolean ReverseCorrectIt() { log.Info("reverseCorrectIt - " + ToString()); MJournal[] journals = GetJournals(true); // check prerequisites for (int i = 0; i < journals.Length; i++) { MJournal journal = journals[i]; if (!journal.IsActive()) { continue; } // All need to be closed/Completed if (DOCSTATUS_Completed.Equals(journal.GetDocStatus())) { ; } else { m_processMsg = "All Journals need to be Compleded: " + journal.GetSummary(); return(false); } } // Reverse it MJournalBatch reverse = new MJournalBatch(this); reverse.SetDateDoc(GetDateDoc()); reverse.SetC_Period_ID(GetC_Period_ID()); reverse.SetDateAcct(GetDateAcct()); reverse.SetC_Year_ID(GetC_Year_ID()); // Reverse indicator if (reverse.Get_ColumnIndex("ReversalDoc_ID") > 0 && reverse.Get_ColumnIndex("IsReversal") > 0) { // set Reversal property for identifying, record is reversal or not during saving or for other actions reverse.SetIsReversal(true); // Set Orignal Document Reference reverse.SetReversalDoc_ID(GetGL_JournalBatch_ID()); } // for reversal document set Temp Document No to empty if (reverse.Get_ColumnIndex("TempDocumentNo") > 0) { reverse.SetTempDocumentNo(""); } String description = reverse.GetDescription(); if (description == null) { description = "** " + GetDocumentNo() + " **"; } else { description += " ** " + GetDocumentNo() + " **"; reverse.SetDescription(description); } if (!reverse.Save()) { ValueNamePair pp = VLogger.RetrieveError(); if (pp != null && !String.IsNullOrEmpty(pp.GetName())) { m_processMsg = pp.GetName() + " - " + "Could not reverse " + this; } else { m_processMsg = "Could not reverse " + this; } return(false); } // // Reverse Journals for (int i = 0; i < journals.Length; i++) { MJournal journal = journals[i]; if (!journal.IsActive()) { continue; } if (journal.ReverseCorrectIt(reverse.GetGL_JournalBatch_ID()) == null) { m_processMsg = "Could not reverse " + journal; return(false); } journal.Save(); } return(true); } // reverseCorrectionIt