コード例 #1
0
        }       //	setDateAcct

        /// <summary>
        /// Set Period
        /// </summary>
        /// <param name="C_Period_ID">period</param>
        public new void SetC_Period_ID(int C_Period_ID)
        {
            base.SetC_Period_ID(C_Period_ID);
            if (C_Period_ID == 0)
            {
                return;
            }
            DateTime?dateAcct = GetDateAcct();
            //
            MPeriod period = GetPeriod();

            if (period != null && period.IsStandardPeriod())
            {
                if (!period.IsInPeriod(dateAcct))
                {
                    base.SetDateAcct(period.GetEndDate());
                }
            }
        }       //	setC_Period_ID
コード例 #2
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
コード例 #3
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
コード例 #4
0
        /// <summary>
        /// Find standard Period of DateAcct based on Client Calendar
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="C_Calendar_ID">calendar</param>
        /// <param name="DateAcct">DateAcct date</param>
        /// <returns> active Period or null</returns>
        /// <date>07-March-2011</date>
        /// <writer>raghu</writer>
        public static MPeriod GetOfCalendar(Ctx ctx, int C_Calendar_ID, DateTime?DateAcct)
        {
            if (DateAcct == null)
            {
                _log.Warning("No DateAcct");
                return(null);
            }
            if (C_Calendar_ID == 0)
            {
                _log.Warning("No Calendar");
                return(null);
            }
            //	Search in Cache first
            IEnumerator <MPeriod> it = cache.Values.GetEnumerator();

            while (it.MoveNext())
            {
                MPeriod period = it.Current;
                if (period.GetC_Calendar_ID() == C_Calendar_ID &&
                    period.IsStandardPeriod() &&
                    period.IsInPeriod(DateAcct))
                {
                    return(period);
                }
            }

            //	Get it from DB
            MPeriod retValue = null;
            // mohit 28-9-2015
            //String sql = "SELECT * FROM C_Period "
            //    + "WHERE C_Year_ID IN "
            //    + "(SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID=" + C_Calendar_ID + ")"
            //    + " AND '" + TimeUtil.GetDay(DateAcct) + "' BETWEEN TRUNC(StartDate,'DD') AND TRUNC(EndDate,'DD')"
            //    + " AND IsActive='Y' AND PeriodType='S'";
            String sql = "SELECT * FROM C_Period "
                         + "WHERE C_Year_ID IN "
                         + "(SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID=" + C_Calendar_ID + ")"
                         + " AND " + GlobalVariable.TO_DATE(DateAcct, true) + " BETWEEN TRUNC(StartDate,'DD') AND TRUNC(EndDate,'DD')"
                         + " AND IsActive='Y' AND PeriodType='S'";
            IDataReader idr = null;

            try
            {
                idr = DB.ExecuteReader(sql, null);
                DataTable dt = new DataTable();
                dt.Load(idr);
                idr.Close();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    MPeriod period = new MPeriod(ctx, dt.Rows[i], null);
                    int     key    = Util.GetValueOfInt(period.GetC_Period_ID());

                    cache[key] = period;

                    if (period.IsStandardPeriod())
                    {
                        retValue = period;
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, "DateAcct=" + DateAcct, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
            }
            if (retValue == null)
            {
                _log.Warning("No Standard Period for " + DateAcct
                             + " (C_Calendar_ID=" + C_Calendar_ID + ")");
            }
            return(retValue);
        }
コード例 #5
0
        /// <summary>
        /// Find standard Period of DateAcct based on Organization Calendar
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="dateAcct">date</param>
        /// <param name="AD_Org_ID">organization</param>
        /// <returns>active Period or null</returns>
        public static MPeriod Get(Ctx ctx, DateTime?dateAcct, int AD_Org_ID)
        {
            if (dateAcct == null)
            {
                return(null);
            }
            //	Search in Cache first
            //IEnumerator<MPeriod> it = cache.Values.GetEnumerator();
            //it.Reset();
            //while (it.MoveNext())
            //{
            //    MPeriod period = it.Current;
            //    if (period.GetAD_Client_ID() == ctx.GetAD_Client_ID() && period.IsStandardPeriod() && period.IsInPeriod((DateTime?)dateAcct))
            //        return period;
            //}

            // Get Calender ID
            StringBuilder qry          = new StringBuilder("");
            int           Calender_ID  = 0;
            int           AD_Client_ID = ctx.GetAD_Client_ID();

            if (AD_Org_ID > 0)
            {
                MOrgInfo orgInfo = MOrgInfo.Get(ctx, AD_Org_ID, null);
                if (orgInfo.Get_ColumnIndex("C_Calendar_ID") >= 0)
                {
                    Calender_ID = orgInfo.GetC_Calendar_ID();
                }
            }

            if (Calender_ID == 0)
            {
                qry.Append("SELECT C_Calendar_ID FROM AD_ClientInfo WHERE  IsActive = 'Y' AND AD_Client_ID=" + AD_Client_ID);
                Calender_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry.ToString()));
            }

            if (Calender_ID == 0)
            {
                return(null);
            }

            //	Get it from DB
            MPeriod retValue = null;
            String  sql      = "SELECT * "
                               + "FROM C_Period "
                               + "WHERE C_Year_ID IN "
                               + "(SELECT C_Year_ID FROM C_Year WHERE IsActive = 'Y' AND C_Calendar_ID= @calendarID)"
                               + " AND @dateAcc BETWEEN TRUNC(StartDate,'DD') AND TRUNC(EndDate,'DD')"
                               + " AND IsActive='Y' AND PeriodType='S'";

            try
            {
                //DateTime? dt = ((DateTime?)dateAcct).Date;
                DateTime?dt = ((DateTime?)dateAcct).Value.Date;

                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@calendarID", Calender_ID);
                param[1] = new SqlParameter("@dateAcc", TimeUtil.GetDay((DateTime?)dateAcct));

                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, null);
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        MPeriod period = new MPeriod(ctx, dr, null);
                        int     key    = period.GetC_Period_ID();
                        //cache.Add(key, period);
                        if (period.IsStandardPeriod())
                        {
                            retValue = period;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, "dateAcct=" + dateAcct, e);
            }
            if (retValue == null)
            {
                _log.Warning("No Standard Period for " + dateAcct + " (AD_Client_ID=" + AD_Client_ID + ")");
            }
            return(retValue);
        }
コード例 #6
0
        /// <summary>
        /// Find standard Period of DateAcct based on Client Calendar
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="dateAcct">date</param>
        /// <returns>active Period or null</returns>
        public static MPeriod Get(Ctx ctx, DateTime?dateAcct)
        {
            if (dateAcct == null)
            {
                return(null);
            }
            //	Search in Cache first
            IEnumerator <MPeriod> it = cache.Values.GetEnumerator();

            it.Reset();
            while (it.MoveNext())
            {
                MPeriod period = it.Current;
                if (period.GetAD_Client_ID() == ctx.GetAD_Client_ID() && period.IsStandardPeriod() && period.IsInPeriod((DateTime?)dateAcct))
                {
                    return(period);
                }
            }

            //	Get it from DB
            MPeriod retValue     = null;
            int     AD_Client_ID = ctx.GetAD_Client_ID();
            String  sql          = "SELECT * "
                                   + "FROM C_Period "
                                   + "WHERE C_Year_ID IN "
                                   + "(SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID= "
                                   + "(SELECT C_Calendar_ID FROM AD_ClientInfo WHERE AD_Client_ID=@clientid))"
                                   + " AND @dateAcc BETWEEN TRUNC(StartDate,'DD') AND TRUNC(EndDate,'DD')"
                                   + " AND IsActive='Y' AND PeriodType='S'";

            try
            {
                //DateTime? dt = ((DateTime?)dateAcct).Date;
                DateTime?dt = ((DateTime?)dateAcct).Value.Date;

                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@clientid", AD_Client_ID);
                param[1] = new SqlParameter("@dateAcc", TimeUtil.GetDay((DateTime?)dateAcct));

                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, null);
                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        MPeriod period = new MPeriod(ctx, dr, null);
                        int     key    = period.GetC_Period_ID();
                        cache.Add(key, period);
                        if (period.IsStandardPeriod())
                        {
                            retValue = period;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, "dateAcct=" + dateAcct, e);
            }
            if (retValue == null)
            {
                _log.Warning("No Standard Period for " + dateAcct + " (AD_Client_ID=" + AD_Client_ID + ")");
            }
            return(retValue);
        }