コード例 #1
0
        protected override bool BeforeSave(bool newRecord)
        {
            MJournalLine obj = new MJournalLine(GetCtx(), GetGL_JournalLine_ID(), Get_Trx());

            // In Case of reversal, bypass this condition
            if (!(obj.Get_ColumnIndex("ReversalDoc_ID") > 0 && obj.GetReversalDoc_ID() > 0))
            {
                string val = "";
                if (obj.GetAmtSourceDr() > 0)
                {
                    val = " AmtSourceDr ";
                }
                else
                {
                    val = " AmtSourceCr ";
                }

                string  sql   = "SELECT SUM(amount) FROM Gl_Linedimension WHERE GL_JournalLine_ID=" + Get_Value("GL_JournalLine_ID") + " AND Gl_Linedimension_ID NOT IN( " + GetGL_LineDimension_ID() + ")";
                Decimal count = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, Get_Trx()));
                count += GetAmount();

                sql = "SELECT " + val + " FROM GL_JournalLine WHERE GL_JournalLine_ID=" + Get_Value("GL_JournalLine_ID");
                Decimal amtcount = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, Get_Trx()));

                if (count > amtcount)
                {
                    log.SaveWarning("AmoutCheck", "");
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        protected override bool BeforeSave(bool newRecord)
        {
            MJournalLine obj = new MJournalLine(GetCtx(), GetGL_JournalLine_ID(), Get_Trx());
            string       val = "";

            if (obj.GetAmtSourceDr() > 0)
            {
                val = " AmtSourceDr ";
            }
            else
            {
                val = " AmtSourceCr ";
            }

            string sql   = "SELECT SUM(amount) FROM Gl_Linedimension WHERE GL_JournalLine_ID=" + Get_Value("GL_JournalLine_ID") + " AND Gl_Linedimension_ID NOT IN( " + GetGL_LineDimension_ID() + ")";
            int    count = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx()));

            count += GetAmount();

            string sqlQry   = "SELECT " + val + " FROM GL_JournalLine WHERE GL_JournalLine_ID=" + Get_Value("GL_JournalLine_ID");
            int    amtcount = Util.GetValueOfInt(DB.ExecuteScalar(sqlQry, null, Get_Trx()));

            if (count > amtcount)
            {
                log.SaveWarning("AmoutCheck", "");
                return(false);
            }

            return(true);
        }
コード例 #3
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
コード例 #4
0
        }   //	updateJournalTotal

        /// <summary>
        /// This functionis used to create Line Dimension Line
        /// </summary>
        /// <param name="fromJournal">object of old GL Journal Line from where we need to pick lines</param>
        /// <param name="newlineID">GL Journal Line ID - new record agsint which we copy lines</param>
        /// <param name="typeCR">Optional Parameter - When 'C' - its means Reverse record - amount to be negate in this case</param>
        /// <returns>count of line - which is created</returns>
        public int CopyLinesFrom(MJournalLine fromJournal, int newlineID, char typeCR = 'X')
        {
            if (IsProcessed() || fromJournal == null)
            {
                return(0);
            }
            int count     = 0;
            int lineCount = 0;

            MLineDimension[] fromLines = fromJournal.GetLines(false);
            for (int i = 0; i < fromLines.Length; i++)
            {
                MLineDimension toLine = new MLineDimension(GetCtx(), 0, fromJournal.Get_TrxName());
                PO.CopyValues(fromLines[i], toLine, GetAD_Client_ID(), GetAD_Org_ID());

                toLine.SetC_BPartner_ID(fromLines[i].GetC_BPartner_ID());
                toLine.SetC_Campaign_ID(fromLines[i].GetC_Campaign_ID());
                toLine.SetC_ElementValue_ID(fromLines[i].GetC_ElementValue_ID());
                toLine.SetC_Element_ID(fromLines[i].GetC_Element_ID());
                toLine.SetC_Location_ID(fromLines[i].GetC_Location_ID());
                toLine.SetC_Project_ID(fromLines[i].GetC_Project_ID());
                toLine.SetC_SalesRegion_ID(fromLines[i].GetC_SalesRegion_ID());
                toLine.SetM_Product_ID(fromLines[i].GetM_Product_ID());
                toLine.SetOrg_ID(fromLines[i].GetOrg_ID());
                toLine.SetSeqNo(fromLines[i].GetSeqNo());
                toLine.SetLineType(fromLines[i].GetLineType());
                toLine.SetGL_JournalLine_ID(newlineID);

                if (typeCR == 'C')
                {
                    toLine.SetAmount(Decimal.Negate(fromLines[i].GetAmount()));
                }
                else
                {
                    toLine.SetAmount(fromLines[i].GetAmount());
                }
                toLine.SetLine(fromLines[i].GetLine());

                if (toLine.Save(fromJournal.Get_TrxName()))
                {
                    count++;
                }
            }
            if (fromLines.Length != count)
            {
                log.Log(Level.SEVERE, "Line difference - LinesDimensionl=" + fromLines.Length + " <> Saved=" + count);
            }
            return(lineCount);
        }
コード例 #5
0
        }       //	setRate

        /// <summary>
        /// Get Journal Lines
        /// </summary>
        /// <param name="requery">requery</param>
        /// <returns>Array of lines</returns>
        public MJournalLine[] GetLines(Boolean requery)
        {
            //ArrayList<MJournalLine> list = new ArrayList<MJournalLine>();
            List <MJournalLine> list = new List <MJournalLine>();
            String sql = "SELECT * FROM GL_JournalLine WHERE GL_Journal_ID=@Param1 ORDER BY Line";

            //PreparedStatement pstmt = null;
            SqlParameter[] Param = new SqlParameter[1];
            IDataReader    idr   = null;
            DataTable      dt    = null;

            try
            {
                //pstmt = DataBase.prepareStatement(sql, get_TrxName());
                //pstmt.setInt(1, getGL_Journal_ID());
                Param[0] = new SqlParameter("@Param1", GetGL_Journal_ID());

                idr = DataBase.DB.ExecuteReader(sql, Param, Get_TrxName());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                //while (rs.next())
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MJournalLine(GetCtx(), dr, Get_TrxName()));
                }
                dt = null;
            }
            catch (Exception ex)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                if (dt != null)
                {
                    dt = null;
                }
                log.Log(Level.SEVERE, "getLines", ex);
            }
            //
            MJournalLine[] retValue = new MJournalLine[list.Count];
            //list.toArray(retValue);
            retValue = list.ToArray();
            return(retValue);
        }       //	getLines
コード例 #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);
        }
コード例 #7
0
        }       //	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());

            //	Get Period
            MPeriod period = MPeriod.Get(GetCtx(), GetDateAcct());

            if (period == null)
            {
                log.Warning("No Period for " + GetDateAcct());
                m_processMsg = "@PeriodNotFound@";
                return(DocActionVariables.STATUS_INVALID);
            }
            //	Standard Period
            if (period.GetC_Period_ID() != GetC_Period_ID() &&
                period.IsStandardPeriod())
            {
                m_processMsg = "@PeriodNotValid@";
                return(DocActionVariables.STATUS_INVALID);
            }
            Boolean open = period.IsOpen(dt.GetDocBaseType());

            if (!open)
            {
                log.Warning(period.GetName()
                            + ": Not open for " + dt.GetDocBaseType() + " (" + GetDateAcct() + ")");
                m_processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Lines
            MJournalLine[] lines = GetLines(true);
            if (lines.Length == 0)
            {
                m_processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }

            //Manish 18/7/2016 .. Because if line dimention (Amount) column sum is not equals to debit or credit value complete process will not done.
            int     journalDRAndCR = 0;
            string  getlinevalues  = "SELECT NVL(ElementType,null) AS ElementType,AmtSourceDr,AmtAcctCr,AmtSourceCr,GL_JournalLine_ID FROM GL_JournalLine where GL_Journal_ID=" + Get_Value("GL_Journal_ID");
            DataSet dts            = DB.ExecuteDataset(getlinevalues, null, null);

            if (dts != null && dts.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
                {
                    journalDRAndCR = 0;

                    if (dts.Tables[0].Rows[i]["ElementType"].ToString() == "")
                    {
                        continue;
                    }

                    if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]) > 0)
                    {
                        journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceDr"]);
                    }
                    else
                    {
                        if (Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]) > 0)
                        {
                            journalDRAndCR = Convert.ToInt32(dts.Tables[0].Rows[i]["AmtSourceCr"]);
                        }
                    }

                    string getlineval = "SELECT SUM(amount) FROM gl_linedimension where GL_JournalLine_ID=" + Convert.ToInt32(dts.Tables[0].Rows[i]["GL_JournalLine_ID"]);
                    int    count      = Util.GetValueOfInt(DB.ExecuteScalar(getlineval));

                    if (journalDRAndCR != count)
                    {
                        m_processMsg = "@AmountNotMatch@";
                        return(DocActionVariables.STATUS_INVALID);
                    }
                }
            }



            //	Add up Amounts
            Decimal AmtSourceDr = Env.ZERO;
            Decimal AmtSourceCr = Env.ZERO;

            for (int i = 0; i < lines.Length; i++)
            {
                MJournalLine line = lines[i];
                if (!IsActive())
                {
                    continue;
                }
                //
                if (line.IsDocControlled())
                {
                    m_processMsg = "@DocControlledError@ - @Line@=" + line.GetLine()
                                   + " - " + line.GetAccountElementValue();
                    return(DocActionVariables.STATUS_INVALID);
                }
                //
                AmtSourceDr = Decimal.Add(AmtSourceDr, line.GetAmtAcctDr());
                AmtSourceCr = Decimal.Add(AmtSourceCr, line.GetAmtAcctCr());
            }
            SetTotalDr(AmtSourceDr);
            SetTotalCr(AmtSourceCr);

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

            //	Unbalanced Jornal & Not Suspense
            if (AmtSourceDr.CompareTo(AmtSourceCr) != 0)
            {
                MAcctSchemaGL gl = MAcctSchemaGL.Get(GetCtx(), GetC_AcctSchema_ID());
                if (gl == null || !gl.IsUseSuspenseBalancing())
                {
                    m_processMsg = "@UnbalancedJornal@";
                    return(DocActionVariables.STATUS_INVALID);
                }
            }

            if (!DOCACTION_Complete.Equals(GetDocAction()))
            {
                SetDocAction(DOCACTION_Complete);
            }
            m_justPrepared = true;
            return(DocActionVariables.STATUS_INPROGRESS);
        }       //	prepareIt
コード例 #8
0
        }       //	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());

            //	Get Period
            MPeriod period = MPeriod.Get(GetCtx(), GetDateAcct());

            if (period == null)
            {
                log.Warning("No Period for " + GetDateAcct());
                m_processMsg = "@PeriodNotFound@";
                return(DocActionVariables.STATUS_INVALID);
            }
            //	Standard Period
            if (period.GetC_Period_ID() != GetC_Period_ID() &&
                period.IsStandardPeriod())
            {
                m_processMsg = "@PeriodNotValid@";
                return(DocActionVariables.STATUS_INVALID);
            }
            Boolean open = period.IsOpen(dt.GetDocBaseType());

            if (!open)
            {
                log.Warning(period.GetName()
                            + ": Not open for " + dt.GetDocBaseType() + " (" + GetDateAcct() + ")");
                m_processMsg = "@PeriodClosed@";
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Lines
            MJournalLine[] lines = GetLines(true);
            if (lines.Length == 0)
            {
                m_processMsg = "@NoLines@";
                return(DocActionVariables.STATUS_INVALID);
            }

            //	Add up Amounts
            Decimal AmtSourceDr = Env.ZERO;
            Decimal AmtSourceCr = Env.ZERO;

            for (int i = 0; i < lines.Length; i++)
            {
                MJournalLine line = lines[i];
                if (!IsActive())
                {
                    continue;
                }
                //
                if (line.IsDocControlled())
                {
                    m_processMsg = "@DocControlledError@ - @Line@=" + line.GetLine()
                                   + " - " + line.GetAccountElementValue();
                    return(DocActionVariables.STATUS_INVALID);
                }
                //
                AmtSourceDr = Decimal.Add(AmtSourceDr, line.GetAmtSourceDr());
                AmtSourceCr = Decimal.Add(AmtSourceCr, line.GetAmtSourceCr());
            }
            SetTotalDr(AmtSourceDr);
            SetTotalCr(AmtSourceCr);

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

            //	Unbalanced Jornal & Not Suspense
            if (AmtSourceDr.CompareTo(AmtSourceCr) != 0)
            {
                MAcctSchemaGL gl = MAcctSchemaGL.Get(GetCtx(), GetC_AcctSchema_ID());
                if (gl == null || !gl.IsUseSuspenseBalancing())
                {
                    m_processMsg = "@UnbalancedJornal@";
                    return(DocActionVariables.STATUS_INVALID);
                }
            }

            if (!DOCACTION_Complete.Equals(GetDocAction()))
            {
                SetDocAction(DOCACTION_Complete);
            }
            m_justPrepared = true;
            return(DocActionVariables.STATUS_INPROGRESS);
        }       //	prepareIt