//Added by Arpit on 15th Dec,2016
        public static MJournal CopyFrom(Ctx ctx, int GL_Journal_ID, DateTime?dateDoc, Trx trxName)
        {
            MJournal from = new MJournal(ctx, GL_Journal_ID, trxName);

            if (from.GetGL_Journal_ID() == 0)
            {
                throw new ArgumentException("From Journal Batch not found GL_JournalBatch_ID=" + GL_Journal_ID);
            }
            //
            MJournal to = new MJournal(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);
            from.GetType();
            //
            if (!to.Save())
            {
                throw new Exception("Could not create GL Journal ");
            }

            if (to.CopyJLines(from, dateDoc) == 0)
            {
                throw new Exception("Could not create GL Journal Details");
            }

            return(to);
        }       //	copyFrom
        }       //	getJournals

        /// <summary>
        /// Copy Journal/Lines from other Journal Batch
        /// </summary>
        /// <param name="jb">Journal Batch</param>
        /// <returns>number of journals + lines copied</returns>
        public int CopyDetailsFrom(MJournalBatch jb)
        {
            if (IsProcessed() || jb == null)
            {
                return(0);
            }
            int count     = 0;
            int lineCount = 0;

            MJournal[] fromJournals = jb.GetJournals(false);
            for (int i = 0; i < fromJournals.Length; i++)
            {
                MJournal toJournal = new MJournal(GetCtx(), 0, jb.Get_TrxName());
                PO.CopyValues(fromJournals[i], toJournal, GetAD_Client_ID(), GetAD_Org_ID());
                toJournal.SetGL_JournalBatch_ID(GetGL_JournalBatch_ID());
                toJournal.Set_ValueNoCheck("DocumentNo", null); //	create new

                //Manish 18/7/2016. C_Period_ID was Null.. But column is mandatory in database so value can't be null.
                toJournal.Set_ValueNoCheck("C_Period_ID", fromJournals[i].GetC_Period_ID());
                // end
                toJournal.SetDateDoc(GetDateDoc());             //	dates from this Batch
                toJournal.SetDateAcct(GetDateAcct());
                toJournal.SetDocStatus(MJournal.DOCSTATUS_Drafted);
                toJournal.SetDocAction(MJournal.DOCACTION_Complete);
                toJournal.SetTotalCr(Env.ZERO);
                toJournal.SetTotalDr(Env.ZERO);
                toJournal.SetIsApproved(false);
                toJournal.SetIsPrinted(false);
                toJournal.SetPosted(false);
                toJournal.SetProcessed(false);
                if (toJournal.Save())
                {
                    count++;
                    lineCount += toJournal.CopyLinesFrom(fromJournals[i], GetDateAcct(), 'x');
                }
            }
            if (fromJournals.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - Journals=" + fromJournals.Length + " <> Saved=" + count);
            }

            return(count + lineCount);
        }       //	copyLinesFrom
        }       //	voidIt

        /// <summary>
        /// Close Document.
        /// </summary>
        /// <returns> true if success </returns>
        public Boolean CloseIt()
        {
            log.Info("closeIt - " + ToString());
            MJournal[] journals = GetJournals(true);
            for (int i = 0; i < journals.Length; i++)
            {
                MJournal journal = journals[i];
                if (!journal.IsActive() && !journal.IsProcessed())
                {
                    journal.SetProcessed(true);
                    journal.SetDocStatus(DOCSTATUS_Voided);
                    journal.SetDocAction(DOCACTION_None);
                    journal.Save();
                    continue;
                }
                if (DOCSTATUS_Drafted.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_InProgress.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_Invalid.Equals(journal.GetDocStatus()))
                {
                    m_processMsg = "Journal not Completed: " + journal.GetSummary();
                    return(false);
                }

                //	Close if not closed
                if (DOCSTATUS_Closed.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_Voided.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_Reversed.Equals(journal.GetDocStatus()))
                {
                    ;
                }
                else
                {
                    if (!journal.CloseIt())
                    {
                        m_processMsg = "Cannot close: " + journal.GetSummary();
                        return(false);
                    }
                    journal.Save();
                }
            }
            return(true);
        }       //	closeIt
        }       //	rejectIt

        /// <summary>
        /// Complete Document
        /// </summary>
        /// <returns>new status (Complete, In Progress, Invalid, Waiting ..)</returns>
        public String CompleteIt()
        {
            log.Info("completeIt - " + ToString());
            //	Re-Check
            if (!m_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
            ApproveIt();

            //	Add up Amounts & complete them
            MJournal[] journals = GetJournals(true);
            Decimal?   TotalDr  = Env.ZERO;
            Decimal?   TotalCr  = Env.ZERO;

            for (int i = 0; i < journals.Length; i++)
            {
                MJournal journal = journals[i];
                if (!journal.IsActive())
                {
                    journal.SetProcessed(true);
                    journal.SetDocStatus(DOCSTATUS_Voided);
                    journal.SetDocAction(DOCACTION_None);
                    journal.Save();
                    continue;
                }
                //	Complete if not closed
                if (DOCSTATUS_Closed.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_Voided.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_Reversed.Equals(journal.GetDocStatus()) ||
                    DOCSTATUS_Completed.Equals(journal.GetDocStatus()))
                {
                    ;
                }
                else
                {
                    String status = journal.CompleteIt();
                    if (!DocActionVariables.STATUS_COMPLETED.Equals(status))
                    {
                        journal.SetDocStatus(status);
                        journal.Save();
                        m_processMsg = journal.GetProcessMsg();
                        return(status);
                    }
                    journal.SetDocStatus(DOCSTATUS_Completed);
                    journal.Save();
                }
                //
                //TotalDr = TotalDr.add(journal.getTotalDr());
                TotalDr = Decimal.Add(TotalDr.Value, journal.GetTotalDr());
                TotalCr = Decimal.Add(TotalCr.Value, journal.GetTotalCr());
            }
            SetTotalDr(TotalDr.Value);
            SetTotalCr(TotalCr.Value);
            //	User Validation
            String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE);

            if (valid != null)
            {
                m_processMsg = valid;
                return(DocActionVariables.STATUS_INVALID);
            }
            //
            SetProcessed(true);
            SetDocAction(DOCACTION_Close);
            return(DocActionVariables.STATUS_COMPLETED);
        }       //	completeIt