Beispiel #1
0
        /// <summary>
        /// After Save
        /// </summary>
        /// <param name="newRecord">new Record</param>
        /// <param name="success">save success</param>
        /// <returns>success</returns>
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }
            if (newRecord)
            {
                //	Info
                info = new MOrgInfo(this);
                info.Save();
                //	Access
                MRoleOrgAccess.CreateForOrg(this);
                MRole.GetDefault(GetCtx(), true);       //	reload
            }
            //	Value/Name change
            if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name")))
            {
                MAccount.UpdateValueDescription(GetCtx(), "AD_Org_ID=" + GetAD_Org_ID(), Get_Trx());
                if ("Y".Equals(GetCtx().GetContext("$Element_OT")))
                {
                    MAccount.UpdateValueDescription(GetCtx(), "AD_OrgTrx_ID=" + GetAD_Org_ID(), Get_Trx());
                }
            }

            return(true);
        }
Beispiel #2
0
 /// <summary>
 /// Get Org Info
 /// </summary>
 /// <returns>Org Info</returns>
 public MOrgInfo GetInfo()
 {
     if (info == null)
     {
         info = MOrgInfo.Get(GetCtx(), GetAD_Org_ID(), Get_Trx());
     }
     return(info);
 }
Beispiel #3
0
        /// <summary>
        /// Find first Year 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 first Period</returns>
        public static MPeriod GetFirstInYear(Ctx ctx, DateTime?dateAcct, int AD_Org_ID)
        {
            MPeriod retValue = null;

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

            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         = "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);
            }

            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 @date BETWEEN StartDate AND EndDate)"
                         + " AND IsActive='Y' AND PeriodType='S' "
                         + "ORDER BY StartDate";

            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@calendarID", Calender_ID);
                param[1] = new SqlParameter("@date", dateAcct);

                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, null);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];  //	first only
                    retValue = new MPeriod(ctx, dr, null);
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            return(retValue);
        }
 /// <summary>
 /// Get Primary Accounting Schema
 /// </summary>
 /// <returns>Acct Schema or null</returns>
 internal MAcctSchema GetAcctSchema()
 {
     if (info == null)
     {
         info = MOrgInfo.Get(GetCtx(), GetAD_Client_ID(), Get_TrxName());
     }
     if (info != null)
     {
         int C_AcctSchema_ID = info.GetC_AcctSchema_ID();
         if (C_AcctSchema_ID != 0)
         {
             return(MAcctSchema.Get(GetCtx(), C_AcctSchema_ID));
         }
     }
     return(null);
 }
        /// <summary>
        /// After Save
        /// </summary>
        /// <param name="newRecord">new Record</param>
        /// <param name="success">save success</param>
        /// <returns>success</returns>
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }
            if (newRecord)
            {
                //	Info
                info = new MOrgInfo(this);
                info.Save();
                //	Access
                MRoleOrgAccess.CreateForOrg(this);
                MRole.GetDefault(GetCtx(), true);       //	reload
            }
            //	Value/Name change
            if (!newRecord && (Is_ValueChanged("Value") || Is_ValueChanged("Name")))
            {
                MAccount.UpdateValueDescription(GetCtx(), "AD_Org_ID=" + GetAD_Org_ID(), Get_Trx());
                if ("Y".Equals(GetCtx().GetContext("$Element_OT")))
                {
                    MAccount.UpdateValueDescription(GetCtx(), "AD_OrgTrx_ID=" + GetAD_Org_ID(), Get_Trx());
                }
            }

            if (!newRecord)
            {
                if (!IsSummary())
                {
                    int orgTableID = MTable.Get_Table_ID("AD_Org");

                    string sql = "SELECT AD_Tree_ID FROM AD_Tree "
                                 + "WHERE AD_Client_ID=" + GetCtx().GetAD_Client_ID() + " AND AD_Table_ID=" + orgTableID + " AND IsActive='Y' AND IsAllNodes='Y' "
                                 + "ORDER BY IsDefault DESC, AD_Tree_ID";

                    object AD_Tree_ID = DB.ExecuteScalar(sql, null, null);

                    DB.ExecuteQuery("Update AD_TreeNode Set Parent_ID = 0 where Parent_ID=" + GetAD_Org_ID() + " AND AD_Tree_ID=" + Util.GetValueOfInt(AD_Tree_ID));
                }
            }

            return(true);
        }
Beispiel #6
0
        /// <summary>
        /// Load Constructor
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="AD_Org_ID">id</param>
        /// <param name="trx">transaction</param>
        /// <returns>Org Info</returns>
        public static MOrgInfo Get(Ctx ctx, int AD_Org_ID, Trx trxName)
        {
            MOrgInfo retValue = null;
            String   sql      = "SELECT * FROM AD_OrgInfo WHERE AD_Org_ID=" + AD_Org_ID;

            try
            {
                DataSet ds = DataBase.DB.ExecuteDataset(sql, null, trxName);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    retValue = new MOrgInfo(ctx, dr, null);
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            return(retValue);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        /// <summary>
        /// Is standard Period Open for specified orgs for the client. For best
        /// performance, ensure that the list of orgs does not contain duplicates.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="AD_Client_ID"></param>
        /// <param name="orgs"></param>
        /// <param name="DateAcct">accounting date</param>
        /// <param name="DocBaseType">document base type</param>
        /// <returns>error message or null</returns>
        /// <date>07-March-2011</date>
        /// <writer>raghu</writer>
        public static String IsOpen(Ctx ctx, int AD_Client_ID, List <int> orgs, DateTime?DateAcct,
                                    String DocBaseType)
        {
            if (DateAcct == null)
            {
                return("@NotFound@ @DateAcct@");
            }
            if (DocBaseType == null)
            {
                return("@NotFound@ @DocBaseType@");
            }

            MAcctSchema as1 = MClient.Get(ctx, AD_Client_ID).GetAcctSchema();

            if (as1 == null)
            {
                return("@NotFound@ @C_AcctSchema_ID@ for AD_Client_ID=" + AD_Client_ID);
            }
            if (as1.IsAutoPeriodControl())
            {
                if (as1.IsAutoPeriodControlOpen(DateAcct))
                {
                    return(null);
                }
                else
                {
                    return("@PeriodClosed@ - @AutoPeriodControl@");
                }
            }

            //	Get all Calendars in line with Organizations
            MClientInfo clientInfo   = MClientInfo.Get(ctx, AD_Client_ID, null);
            List <int>  orgCalendars = new List <int>();
            List <int>  calendars    = new List <int>();

            foreach (int org in orgs)
            {
                MOrgInfo orgInfo = MOrgInfo.Get(ctx, org, null);

                int C_Calendar_ID = orgInfo.GetC_Calendar_ID();
                if (C_Calendar_ID == 0)
                {
                    C_Calendar_ID = clientInfo.GetC_Calendar_ID();
                }
                orgCalendars.Add(C_Calendar_ID);
                if (!calendars.Contains(C_Calendar_ID))
                {
                    calendars.Add(C_Calendar_ID);
                }
            }
            //	Should not happen
            if (calendars.Count == 0)
            {
                return("@NotFound@ @C_Calendar_ID@");
            }

            //	For all Calendars get Periods
            for (int i = 0; i < calendars.Count; i++)
            {
                int     C_Calendar_ID = calendars[i];
                MPeriod period        = MPeriod.GetOfCalendar(ctx, C_Calendar_ID, DateAcct);
                //	First Org for Calendar
                int AD_Org_ID = 0;
                for (int j = 0; j < orgCalendars.Count; j++)
                {
                    if (orgCalendars[j] == C_Calendar_ID)
                    {
                        AD_Org_ID = orgs[j];
                        break;
                    }
                }
                if (period == null)
                {
                    MCalendar cal  = MCalendar.Get(ctx, C_Calendar_ID);
                    String    date = DisplayType.GetDateFormat(DisplayType.Date).Format(DateAcct);
                    if (cal != null)
                    {
                        return("@NotFound@ @C_Period_ID@: " + date
                               + " - " + MOrg.Get(ctx, AD_Org_ID).GetName()
                               + " -> " + cal.GetName());
                    }
                    else
                    {
                        return("@NotFound@ @C_Period_ID@: " + date
                               + " - " + MOrg.Get(ctx, AD_Org_ID).GetName()
                               + " -> C_Calendar_ID=" + C_Calendar_ID);
                    }
                }
                String error = period.IsOpen(DocBaseType, DateAcct);
                if (error != null)
                {
                    return(error
                           + " - " + MOrg.Get(ctx, AD_Org_ID).GetName()
                           + " -> " + MCalendar.Get(ctx, C_Calendar_ID).GetName());
                }
            }
            return(null);        //	open
        }