}       //	reverseCorrectIt

        /// <summary>
        /// Reverse Correction.As if nothing happened - same date
        /// </summary>
        /// <param name="GL_JournalBatch_ID">batch</param>
        /// <returns>reversed journal or null</returns>
        public MJournal ReverseCorrectIt(int GL_JournalBatch_ID)
        {
            log.Info(ToString());
            //	Journal
            MJournal reverse = new MJournal(this);

            reverse.SetGL_JournalBatch_ID(GL_JournalBatch_ID);
            reverse.SetDateDoc(GetDateDoc());
            reverse.SetC_Period_ID(GetC_Period_ID());
            reverse.SetDateAcct(GetDateAcct());
            //	Reverse indicator
            String description = reverse.GetDescription();

            if (description == null)
            {
                description = "** " + GetDocumentNo() + " **";
            }
            else
            {
                description += " ** " + GetDocumentNo() + " **";
            }
            reverse.SetDescription(description);
            if (!reverse.Save())
            {
                return(null);
            }

            //	Lines
            reverse.CopyLinesFrom(this, null, 'C');
            //
            SetProcessed(true);
            SetDocAction(DOCACTION_None);
            return(reverse);
        }       //	reverseCorrectionIt
        }       //	setClientOrg

        /// <summary>
        /// Get Journal Lines
        /// </summary>
        /// <param name="requery">requery</param>
        /// <returns> Array of lines</returns>
        public MJournal[] GetJournals(Boolean requery)
        {
            List <MJournal> list = new List <MJournal>();
            String          sql  = "SELECT * FROM GL_Journal WHERE GL_JournalBatch_ID=@param ORDER BY DocumentNo";
            IDataReader     idr  = null;

            SqlParameter[] param = new SqlParameter[1];
            try
            {
                //pstmt = DataBase.prepareStatement(sql, get_TrxName());
                //pstmt.setInt(1, getGL_JournalBatch_ID());
                param[0] = new SqlParameter("@param", GetGL_JournalBatch_ID());
                idr      = DataBase.DB.ExecuteReader(sql, param, Get_TrxName());
                while (idr.Read())
                {
                    list.Add(new MJournal(GetCtx(), idr, Get_TrxName()));
                }
                idr.Close();
            }
            catch (Exception ex)
            {
                log.Log(Level.SEVERE, sql, ex);
            }
            //
            MJournal[] retValue = new MJournal[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }       //	getJournals
        //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
        }       //	reverseAccrualIt

        /// <summary>
        ///	Reverse Accrual.	Flip Dr/Cr - Use Today's date
        /// </summary>
        /// <param name="GL_JournalBatch_ID">reversal batch</param>
        /// <returns> journal or null </returns>
        public MJournal ReverseAccrualIt(int GL_JournalBatch_ID)
        {
            log.Info(ToString());
            //	Journal
            MJournal reverse = new MJournal(this);

            reverse.SetGL_JournalBatch_ID(GL_JournalBatch_ID);
            reverse.SetDateDoc(DateTime.Now);
            reverse.Set_ValueNoCheck("C_Period_ID", null);              //	reset
            reverse.SetDateAcct(reverse.GetDateDoc());
            //	Reverse indicator
            String description = reverse.GetDescription();

            if (description == null)
            {
                description = "** " + GetDocumentNo() + " **";
            }
            else
            {
                description += " ** " + GetDocumentNo() + " **";
            }
            reverse.SetDescription(description);
            if (!reverse.Save())
            {
                return(null);
            }

            //	Lines
            reverse.CopyLinesFrom(this, reverse.GetDateAcct(), 'R');
            //
            SetProcessed(true);
            SetDocAction(DOCACTION_None);
            return(reverse);
        }       //	reverseAccrualIt
示例#5
0
        } //	MJournalLine

        /// <summary>
        /// Parent Constructor
        /// </summary>
        /// <param name="parent">journal</param>
        public MJournalLine(MJournal parent) : this(parent.GetCtx(), 0, parent.Get_TrxName())
        {
            //this (parent.getCtx(), 0, parent.get_TrxName());
            SetClientOrg(parent);
            SetGL_Journal_ID(parent.GetGL_Journal_ID());
            SetC_Currency_ID(parent.GetC_Currency_ID());
            SetC_ConversionType_ID(parent.GetC_ConversionType_ID());
            SetDateAcct(parent.GetDateAcct());
        } //	MJournalLine
        }       //	copyLinesFrom

        // Mainsh 18/7/2016...
        public int CopyLines(MJournal fromJournal, char typeCR)
        {
            DateTime?dateAcct = GetDateAcct();

            if (IsProcessed() || fromJournal == null)
            {
                return(0);
            }
            int count     = 0;
            int lineCount = 0;

            MJournalLine[] fromLines = fromJournal.GetLines(false);
            for (int i = 0; i < fromLines.Length; i++)
            {
                MJournalLine toLine = new MJournalLine(GetCtx(), 0, fromJournal.Get_TrxName());
                PO.CopyValues(fromLines[i], toLine, GetAD_Client_ID(), GetAD_Org_ID());
                toLine.SetGL_Journal_ID(GetGL_Journal_ID());
                //
                //if (dateAcct != null)
                //{
                //    toLine.SetDateAcct(dateAcct);
                //}
                //	Amounts
                //if (typeCR == 'C')			//	correct
                //{
                //    // toLine.SetAmtSourceDr(fromLines[i].GetAmtSourceDr().negate());
                //    toLine.SetAmtSourceDr(Decimal.Negate(fromLines[i].GetAmtSourceDr()));
                //    toLine.SetAmtSourceCr(Decimal.Negate(fromLines[i].GetAmtSourceCr()));//.negate());
                //}
                //else if (typeCR == 'R')		//	reverse
                //{
                toLine.SetAmtSourceDr(fromLines[i].GetAmtSourceDr());
                toLine.SetAmtSourceCr(fromLines[i].GetAmtSourceCr());
                // }

                toLine.SetDescription(fromLines[i].GetDescription());
                toLine.SetC_Currency_ID(fromLines[i].GetC_Currency_ID());
                toLine.SetIsGenerated(true);
                toLine.SetProcessed(false);
                toLine.SetQty(fromLines[i].GetQty());
                toLine.SetElementType(fromLines[i].GetElementType());


                if (toLine.Save(fromJournal.Get_TrxName()))
                {
                    count++;
                    lineCount += toLine.CopyLinesFrom(fromLines[i], toLine.GetGL_JournalLine_ID());
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - JournalLines=" + fromLines.Length + " <> Saved=" + count);
            }

            return(count);
        }       //	copyLinesFrom
        }       //	copyLinesFrom

        //end

        //added by To Create Journal Lines Arpit Rai 15th Dec,2016
        public int CopyJLines(MJournal fromJournal, DateTime?dateAcct)
        {
            if (IsProcessed() || fromJournal == null)
            {
                return(0);
            }
            int count     = 0;
            int lineCount = 0;

            MJournalLine[] fromLines = fromJournal.GetLines(false);
            for (int i = 0; i < fromLines.Length; i++)
            {
                MJournalLine toLine = new MJournalLine(GetCtx(), 0, fromJournal.Get_TrxName());
                PO.CopyValues(fromLines[i], toLine, GetAD_Client_ID(), GetAD_Org_ID());
                toLine.SetGL_Journal_ID(GetGL_Journal_ID());
                if (dateAcct != null)
                {
                    toLine.SetDateAcct(dateAcct);
                }
                else
                {
                    toLine.SetDateAcct(DateTime.Now);
                }
                toLine.SetAmtSourceDr(fromLines[i].GetAmtSourceDr());
                toLine.SetAmtSourceCr(fromLines[i].GetAmtSourceCr());
                toLine.SetDescription(fromLines[i].GetDescription());
                toLine.SetC_Currency_ID(fromLines[i].GetC_Currency_ID());
                toLine.SetIsGenerated(true);
                toLine.SetProcessed(false);
                toLine.SetQty(fromLines[i].GetQty());
                toLine.SetElementType(fromLines[i].GetElementType());
                if (toLine.Save(fromJournal.Get_TrxName()))
                {
                    count++;
                    lineCount += toLine.CopyLinesFrom(fromLines[i], toLine.GetGL_JournalLine_ID());
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - JournalLines=" + fromLines.Length + " <> Saved=" + count);
            }

            return(count);
        }
        }       //	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
        }       //	MJournal

        /// <summary>
        /// Copy Constructor.Dos not copy: Dates/Period
        /// </summary>
        /// <param name="original">original</param>
        public MJournal(MJournal original)
            : this(original.GetCtx(), 0, original.Get_TrxName())
        {
            //this (original.GetCtx(), 0, original.get_TrxName())
            SetClientOrg(original);
            SetGL_JournalBatch_ID(original.GetGL_JournalBatch_ID());
            //
            SetC_AcctSchema_ID(original.GetC_AcctSchema_ID());
            SetGL_Budget_ID(original.GetGL_Budget_ID());
            SetGL_Category_ID(original.GetGL_Category_ID());
            SetPostingType(original.GetPostingType());
            SetDescription(original.GetDescription());
            SetC_DocType_ID(original.GetC_DocType_ID());
            SetControlAmt(original.GetControlAmt());
            //
            SetC_Currency_ID(original.GetC_Currency_ID());
            SetC_ConversionType_ID(original.GetC_ConversionType_ID());
            SetCurrencyRate(original.GetCurrencyRate());

            //	setDateDoc(original.getDateDoc());
            //	setDateAcct(original.getDateAcct());
            //	setC_Period_ID(original.getC_Period_ID());
        }       //	MJournal
        }       //	afterDelete

        /** Update combination and optionally **/
        private bool GetOrCreateCombination(Boolean newRecord)
        {
            int Account_ID = 0, C_SubAcct_ID = 0, M_Product_ID = 0, C_BPartner_ID = 0, AD_Org_ID = 0, AD_OrgTrx_ID = 0,
                C_LocFrom_ID = 0, C_LocTo_ID = 0, C_SalesRegion_ID = 0, C_Project_ID = 0, C_Campaign_ID = 0,
                C_Activity_ID = 0, User1_ID = 0, User2_ID = 0;

            if (GetC_ValidCombination_ID() == 0 ||
                (!newRecord && (Is_ValueChanged("Account_ID") ||
                                Is_ValueChanged("M_Product_ID") ||
                                Is_ValueChanged("C_BPartner_ID") ||
                                Is_ValueChanged("AD_Org_ID") ||
                                Is_ValueChanged("C_Project_ID") ||
                                Is_ValueChanged("C_Campaign_ID") ||
                                Is_ValueChanged("C_Activity_ID"))))
            {
                MJournal gl = new MJournal(GetCtx(), GetGL_Journal_ID(), Get_TrxName());

                // Validate all mandatory combinations are set
                MAcctSchema          asc      = MAcctSchema.Get(GetCtx(), gl.GetC_AcctSchema_ID());
                MAcctSchemaElement[] elements = MAcctSchemaElement.GetAcctSchemaElements(asc);
                for (int i = 0; i < elements.Length; i++)
                {
                    MAcctSchemaElement elem = elements[i];
                    String             et   = elem.GetElementType();
                    if (MAcctSchemaElement.ELEMENTTYPE_Account.Equals(et) && Get_ColumnIndex("Account_ID") > 0)
                    {
                        Account_ID = Util.GetValueOfInt(Get_Value("Account_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Account.Equals(et) && Get_ColumnIndex("C_SubAcct_ID") > 0)
                    {
                        C_SubAcct_ID = Util.GetValueOfInt(Get_Value("C_SubAcct_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Activity.Equals(et) && Get_ColumnIndex("C_Activity_ID") > 0)
                    {
                        C_Activity_ID = Util.GetValueOfInt(Get_Value("C_Activity_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_BPartner.Equals(et) && Get_ColumnIndex("C_BPartner_ID") > 0)
                    {
                        C_BPartner_ID = Util.GetValueOfInt(Get_Value("C_BPartner_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Campaign.Equals(et) && Get_ColumnIndex("C_BPartner_ID") > 0)
                    {
                        C_BPartner_ID = Util.GetValueOfInt(Get_Value("C_BPartner_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Organization.Equals(et))
                    {
                        AD_Org_ID = GetAD_Org_ID();
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_OrgTrx.Equals(et) && Get_ColumnIndex("AD_OrgTrx_ID") > 0)
                    {
                        AD_OrgTrx_ID = Util.GetValueOfInt(Get_Value("AD_OrgTrx_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(et) && Get_ColumnIndex("C_LocFrom_ID") > 0)
                    {
                        C_LocFrom_ID = Util.GetValueOfInt(Get_Value("C_LocFrom_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(et) && Get_ColumnIndex("C_LocTo_ID") > 0)
                    {
                        C_LocTo_ID = Util.GetValueOfInt(Get_Value("C_LocTo_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(et) && Get_ColumnIndex("M_Product_ID") > 0)
                    {
                        M_Product_ID = Util.GetValueOfInt(Get_Value("M_Product_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Project.Equals(et) && Get_ColumnIndex("C_Project_ID") > 0)
                    {
                        C_Project_ID = Util.GetValueOfInt(Get_Value("C_Project_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_Project.Equals(et) && Get_ColumnIndex("C_Campaign_ID") > 0)
                    {
                        C_Campaign_ID = Util.GetValueOfInt(Get_Value("C_Campaign_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_SalesRegion.Equals(et) && Get_ColumnIndex("C_SalesRegion_ID") > 0)
                    {
                        C_SalesRegion_ID = Util.GetValueOfInt(Get_Value("C_SalesRegion_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_UserList1.Equals(et) && Get_ColumnIndex("User1_ID") > 0)
                    {
                        User1_ID = Util.GetValueOfInt(Get_Value("User1_ID"));
                    }
                    if (MAcctSchemaElement.ELEMENTTYPE_UserList2.Equals(et) && Get_ColumnIndex("User2_ID") > 0)
                    {
                        User2_ID = Util.GetValueOfInt(Get_Value("User2_ID"));
                    }
                }

                MAccount acct = MAccount.Get(GetCtx(), GetAD_Client_ID(), AD_Org_ID, gl.GetC_AcctSchema_ID(), Account_ID,
                                             C_SubAcct_ID, M_Product_ID, C_BPartner_ID, AD_OrgTrx_ID, C_LocFrom_ID, C_LocTo_ID, C_SalesRegion_ID,
                                             C_Project_ID, C_Campaign_ID, C_Activity_ID, User1_ID, User2_ID, 0, 0, 0, 0, 0, 0, 0, 0, 0);

                if (acct != null)
                {
                    acct.Save(Get_TrxName());   // get ID from transaction
                    SetC_ValidCombination_ID(acct.Get_ID());

                    //if (acct.GetAlias() != null && acct.GetAlias().length > 0)
                    //    setAlias_ValidCombination_ID(acct.get_ID());
                    //else
                    //    setAlias_ValidCombination_ID(0);
                }
            }
            else
            {
                fillDimensionsFromCombination();
            }
            return(true);
        }
        }       //	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
        }       //	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
        }       //	invalidateIt

        /// <summary>
        /// Prepare Document
        /// </summary>
        /// <returns>new status (In Progress or Invalid) </returns>
        public String PrepareIt()
        {
            log.Info(ToString());
            m_processMsg = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_BEFORE_PREPARE);
            if (m_processMsg != null)
            {
                return(DocActionVariables.STATUS_INVALID);
            }
            MDocType dt = MDocType.Get(GetCtx(), GetC_DocType_ID());

            //	Std Period open?
            if (!MPeriod.IsOpen(GetCtx(), GetDateAcct(), dt.GetDocBaseType()))
            {
                m_processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

            // is Non Business Day?
            // JID_1205: At the trx, need to check any non business day in that org. if not fund then check * org.
            if (MNonBusinessDay.IsNonBusinessDay(GetCtx(), GetDateAcct(), GetAD_Org_ID()))
            {
                m_processMsg = Common.Common.NONBUSINESSDAY;
                return(DocActionVariables.STATUS_INVALID);
            }

            // JID_0521 - Restrict if debit and credit amount is not equal.-Mohit-12-jun-2019.
            if (GetTotalCr() != GetTotalDr())
            {
                m_processMsg = Msg.GetMsg(GetCtx(), "DBAndCRAmtNotEqual");
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Add up Amounts & prepare them
            MJournal[] journals = GetJournals(false);
            if (journals.Length == 0)
            {
                m_processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }

            Decimal TotalDr = Env.ZERO;
            Decimal TotalCr = Env.ZERO;

            for (int i = 0; i < journals.Length; i++)
            {
                MJournal journal = journals[i];
                if (!journal.IsActive())
                {
                    continue;
                }
                //	Prepare 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.PrepareIt();
                    if (!DocActionVariables.STATUS_INPROGRESS.Equals(status))
                    {
                        journal.SetDocStatus(status);
                        journal.Save();
                        m_processMsg = journal.GetProcessMsg();
                        return(status);
                    }
                    journal.SetDocStatus(DOCSTATUS_InProgress);
                    journal.Save();
                }
                //
                //TotalDr = TotalDr.add(journal.getTotalDr());
                TotalDr = Decimal.Add(TotalDr, journal.GetTotalDr());
                TotalCr = Decimal.Add(TotalCr, journal.GetTotalCr());
            }
            SetTotalDr(TotalDr);
            SetTotalCr(TotalCr);

            //	Control Amount
            if (Env.ZERO.CompareTo(GetControlAmt()) != 0 &&
                GetControlAmt().CompareTo(GetTotalDr()) != 0)
            {
                m_processMsg = "@ControlAmtError@";
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Add up Amounts
            m_justPrepared = true;
            return(DocActionVariables.STATUS_INPROGRESS);
        }       //	prepareIt
示例#16
0
        }       //	toString

        /// <summary>
        /// Execute Run.
        /// </summary>
        /// <returns>clear text info</returns>
        public String ExecuteRun()
        {
            DateTime?dateDoc = GetDateNextRun();

            if (!CalculateRuns())
            {
                throw new Exception("No Runs Left");
            }
            //	log
            MRecurringRun run = new MRecurringRun(GetCtx(), this);
            String        msg = "@Created@ ";

            //Checked if the Next Date Run is less then the date pressent Arpit on 15th Dec,2016
            if (GetDateNextRun() == DateTime.Now.Date || GetDateNextRun() == null)
            {
                //	Copy
                if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Order))
                {
                    MOrder from  = new MOrder(GetCtx(), GetC_Order_ID(), Get_TrxName());
                    MOrder order = MOrder.CopyFrom(from, dateDoc,
                                                   from.GetC_DocType_ID(), false, false, Get_TrxName());
                    run.SetC_Order_ID(order.GetC_Order_ID());
                    msg += order.GetDocumentNo();
                }
                else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Invoice))
                {
                    MInvoice from    = new MInvoice(GetCtx(), GetC_Invoice_ID(), Get_TrxName());
                    MInvoice invoice = MInvoice.CopyFrom(from, dateDoc,
                                                         from.GetC_DocType_ID(), false, Get_TrxName(), false);
                    run.SetC_Invoice_ID(invoice.GetC_Invoice_ID());
                    //Set Invoice Refrence and Description from Orignal to Recurring
                    invoice.Set_Value("InvoiceReference", from.GetDocumentNo() + "_" + (GetRunsMax() - GetRunsRemaining() + 1));
                    invoice.AddDescription(Msg.GetMsg(from.GetCtx(), "RecurringDocument") + from.GetDocumentNo());
                    if (!invoice.Save(Get_TrxName()))
                    {
                        ValueNamePair pp = VLogger.RetrieveError();
                        if (pp != null)
                        {
                            from.SetProcessMsg(Msg.GetMsg(from.GetCtx(), "CouldNotCreateInvoice") + pp.GetName());
                        }
                        else
                        {
                            from.SetProcessMsg(Msg.GetMsg(from.GetCtx(), "CouldNotCreateInvoice"));
                        }
                        throw new Exception(Msg.GetMsg(from.GetCtx(), "CouldNotCreateInvoice") + (pp != null ? pp.GetName() : ""));
                    }
                    msg += invoice.GetDocumentNo();
                }
                else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Project))
                {
                    MProject project = MProject.CopyFrom(GetCtx(), GetC_Project_ID(), dateDoc, Get_TrxName());
                    run.SetC_Project_ID(project.GetC_Project_ID());
                    msg += project.GetValue();
                }
                else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_GLJournalBatch)) //Changes to GL Journal Batch by Arpit
                {
                    MJournalBatch journal = MJournalBatch.CopyFrom(GetCtx(), GetGL_JournalBatch_ID(), dateDoc, Get_TrxName());
                    run.SetGL_JournalBatch_ID(journal.GetGL_JournalBatch_ID());
                    msg += journal.GetDocumentNo();
                }
                //Added by Arpit on 14th, Dec,2016
                else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_GLJournal))
                {
                    MJournal Journal = MJournal.CopyFrom(GetCtx(), GetGL_Journal_ID(), dateDoc, Get_TrxName());
                    run.SetGL_Journal_ID(Journal.GetGL_Journal_ID());
                    msg += Journal.GetDocumentNo();
                }

                //End here
                else if (GetRecurringType().Equals(MRecurring.RECURRINGTYPE_Payment))
                {
                    MPayment from    = new MPayment(GetCtx(), GetC_Payment_ID(), Get_TrxName());
                    MPayment payment = MPayment.CopyFrom(from, dateDoc,
                                                         from.GetC_DocType_ID(), Get_TrxName());
                    run.SetC_Payment_ID(payment.GetC_Payment_ID());
                    msg += payment.GetDocumentNo();
                }
                else
                {
                    return("Invalid @RecurringType@ = " + GetRecurringType());
                }
                run.Save(Get_TrxName());

                //
                SetDateLastRun(run.GetUpdated());
                SetRunsRemaining(GetRunsRemaining() - 1);
                SetDateNextRun();
                Save(Get_TrxName());
                return(msg);
            }
            else
            {
                return(Msg.GetMsg(GetCtx(), "RecurringNotCompleted") + String.Format("{0:dd/M/yyyy}", Convert.ToDateTime(GetDateNextRun())));
            }
        }       //	execureRun