Example #1
0
        //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
Example #2
0
        }       //	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
Example #3
0
        }       //	getLines

        /// <summary>
        /// Copy Lines from other Journal
        /// </summary>
        /// <param name="fromJournal">Journal</param>
        /// <param name="dateAcct">date used - if null original</param>
        /// <param name="typeCR">type of copying (C)orrect=negate - (R)everse=flip dr/cr - otherwise just copy</param>
        /// <returns>number of lines copied</returns>
        public int CopyLinesFrom(MJournal fromJournal, DateTime?dateAcct, char typeCR)
        {
            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].GetAmtSourceCr());
                    toLine.SetAmtSourceCr(fromLines[i].GetAmtSourceDr());
                }
                toLine.SetIsGenerated(true);
                toLine.SetProcessed(false);

                // // Set Orignal Document Reference on Reversal Document
                if (Get_ColumnIndex("IsReversal") > 0 && IsReversal())
                {
                    if (toLine.Get_ColumnIndex("ReversalDoc_ID") > 0)
                    {
                        toLine.SetReversalDoc_ID(fromLines[i].GetGL_JournalLine_ID());
                    }
                }

                if (toLine.Save())
                {
                    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
Example #4
0
        }       //	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
Example #5
0
        }       //	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.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_Journal_ID());
            }

            // for reversal document set Temp Document No to empty
            if (reverse.Get_ColumnIndex("TempDocumentNo") > 0)
            {
                reverse.SetTempDocumentNo("");
            }

            if (!reverse.Save())
            {
                return(null);
            }

            //	Lines
            reverse.CopyLinesFrom(this, null, 'C');
            //
            SetProcessed(true);
            SetDocAction(DOCACTION_None);
            return(reverse);
        }       //	reverseCorrectionIt
Example #6
0
        }       //	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);
        }
Example #7
0
        }       //	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