private void RolloverOpportunities(IUser user)
        {
            // Get Current Date
            DateTime today = DateTime.Now.Date;

            // Get Fiscal Year Settings
            int      period              = Platform.GetQAndFPeriod();
            DateTime firstDayofPeriod    = (DateTime)Platform.FirstDayofPeriod(DateTime.Now);
            DateTime beginPreviousPeriod = (DateTime)Platform.FirstDayofPeriod(today.AddMonths(-1 * period)).Value.Date;
            DateTime endPreviousPeriod   = Date.EndOfDay((DateTime)Platform.LastDayofPeriod(beginPreviousPeriod));

            using (var session = new SessionScopeWrapper(true))
            {
                Phase = String.Format(Resources.Job_OpportunityRollover_Phase_ProcessingOpportunities, user.UserInfo.NameLF);
                // Get the Opportunities that need to be rolled over from the previous period
                IList <IOpportunity> opportunities = session.QueryOver <IOpportunity>()
                                                     .Where(x => x.AccountManager == user && x.Status == "Open" && x.AddToForecast == true && x.EstimatedClose >= beginPreviousPeriod && x.EstimatedClose <= endPreviousPeriod)
                                                     .List <IOpportunity>();
                foreach (IOpportunity opportunity in opportunities)
                {
                    opportunity.EstimatedClose = firstDayofPeriod;
                    opportunity.Save();
                }
            }
        }
        protected override void OnExecute()
        {
            if (String.IsNullOrEmpty(BulletinName))
            {
                throw new InvalidOperationException(Resources.Job_BulletinName_NotSpecified);
            }

            using (var session = new SessionScopeWrapper())
            {
                IBulletin bulletin = session.QueryOver <IBulletin>()
                                     .Where(x => x.BulletinName == BulletinName)
                                     .SingleOrDefault <IBulletin>();

                if (bulletin == null)
                {
                    throw new InvalidOperationException(Resources.Job_BulletinName_NotFound);
                }

                switch (bulletin.BulletinName)
                {
                case "Weekly Forecast Summary":
                    WeeklyForecastSummary(bulletin);
                    break;
                }
            }
        }
        protected override void OnExecute()
        {
            Phase = Resources.Job_Phase_Detail_Initializing;

            // Set progress bar to 0
            Progress = 0;
            int count = 0;

            // Retrieve all Users in the Role defined for Quota & Forecast Users
            using (var session = new SessionScopeWrapper(true))
            {
                Phase = Resources.Job_OpportunityRollover_Phase_Retrieving_Users;
                IRole role = session.QueryOver <IRole>()
                             .Where(x => x.RoleName == Resources.Job_OpportunityRollover_RoleName)
                             .SingleOrDefault <IRole>();

                foreach (IUserRole userRole in role.Users)
                {
                    RolloverOpportunities(userRole.User);
                    GenerateForecast(userRole.User);
                    Progress = (100M * ++count / role.Users.Count);
                    if (Interrupted)
                    {
                        return;
                    }
                }
            }
            Progress    = 100;
            Phase       = Resources.Job_Phase_Detail_Completed;
            PhaseDetail = String.Format(Resources.Job_OpportunityRollover_Results, count);
        }
Example #4
0
        protected override void OnExecute()
        {
            Progress = 0;
            using (var session = new SessionScopeWrapper())
            {
                Phase = "Gathering up Items to deliver";
                IList <IDeliveryItem> deliveryItems = session.QueryOver <IDeliveryItem>()
                                                      .Where(di => di.Status == DeliveryItemStatuses.ToBeProcessed)
                                                      .List <IDeliveryItem>();

                if (deliveryItems != null)
                {
                    decimal counter = 0;
                    Phase = "Delivering Items";
                    foreach (IDeliveryItem di in deliveryItems)
                    {
                        ProcessDeliveryItem(di);
                        Progress = 100M * ++counter / deliveryItems.Count;
                        if (Interrupted)
                        {
                            return;
                        }
                    }
                }
            }
            Progress = 100;
            Phase    = Resources.Job_Phase_Detail_Completed;
        }
    private IPickListView GetPickListView()
    {
        IPickListView plv = BindingSource.Current as IPickListView;

        using (ISession session = new SessionScopeWrapper(true))
        {
            return(session.QueryOver <IPickListView>()
                   .Where(x => x.Id == plv.Id)
                   .SingleOrDefault());
        }
    }
Example #6
0
        protected override void OnExecute()
        {
            IList <INotificationEvent> notificationEvents = null;

            // Get the list of Notification Events to process
            using (var session = new SessionScopeWrapper())
            {
                notificationEvents = session.QueryOver <INotificationEvent>()
                                     .Where(x => x.NextTimeToCheck <= DateTime.Now && x.Enabled == true)
                                     .List <INotificationEvent>();
            }

            if (notificationEvents != null)
            {
                foreach (INotificationEvent ne in notificationEvents)
                {
                    string   query   = ParseQueryForLiterals(ne);
                    DateTime now     = DateTime.UtcNow;
                    bool     bResult = false;

                    // Execute the query
                    using (var session = new SessionScopeWrapper())
                    {
                        Type entityType = typeof(Sage.SalesLogix.Entities.Account).Assembly.GetType(String.Format("Sage.SalesLogix.Entities.{0}", ne.EntityName));

                        IList <dynamic> payload = session.CreateQuery(query).List <dynamic>();

                        if (payload.Count > 0)
                        {
                            if (ne.Digest == true)
                            {
                                bResult = ProcessDigestEvent(ne, payload);
                            }
                            else
                            {
                                bResult = ProcessSingleEvent(ne, payload);
                            }
                        }
                        else
                        {
                            // Noting to process, but move the next time to check anyway.
                            bResult = true;
                        }
                    }
                    if (bResult)
                    {
                        // Update Notification Event
                        ne.LastChecked     = now;
                        ne.NextTimeToCheck = GetNextTimeToCheck(ne, now);
                        ne.Save();
                    }
                }
            }
        }
        private void WeeklyForecastSummary(IBulletin bulletin)
        {
            DateTime        today = DateTime.UtcNow;
            ForecastSummary fs    = new ForecastSummary();

            Progress = 0;
            decimal counter = 0;

            using (var session = new SessionScopeWrapper())
            {
                IList <IForecast> forecasts = session.QueryOver <IForecast>()
                                              .Where(x => today >= x.BeginDate && today <= x.EndDate && x.Active == true)
                                              .List <IForecast>();

                foreach (IForecast f in forecasts)
                {
                    ForecastInfo fi = new ForecastInfo();
                    fi.ForecastName = f.Description;
                    fi.AssignedTo   = f.AssignedTo.UserInfo.NameLF;
                    fi.Amount       = Convert.ToDecimal(f.Amount);
                    fi.Pipeline     = (decimal)f.PeriodPipelineAmt("Avg");
                    fi.ClosedWon    = (decimal)f.PeriodClosedWonAmt();
                    fi.Quota        = GetQuotaAmtforUser(f.AssignedTo, today);

                    fs.forecasts.Add(fi);
                    Progress = (100M * ++counter / forecasts.Count) / 2;
                }
            }

            counter = 0;
            if (fs.forecasts.Count > 0)
            {
                string msgBody = BuildMessageBody(fs);
                string subject = "Weekly Forecast Summary";

                IDeliveryItem di = Sage.Platform.EntityFactory.Create <IDeliveryItem>();
                di.Body           = msgBody;
                di.Subject        = subject;
                di.DeliverySystem = bulletin.DeliverySystem;
                di.Status         = "To Be Processed";

                foreach (IBulletinSubscriber subscriber in bulletin.Subscribers)
                {
                    IDeliveryItemTarget target = EntityFactory.Create <IDeliveryItemTarget>();
                    target.DeliveryItem = di;
                    target.Address      = subscriber.Subscriber.UserInfo.Email;
                    target.Type         = "TO";
                    di.DeliveryItemTargets.Add(target);
                    di.Save();
                    Progress = 50M + (50M * ++counter / bulletin.Subscribers.Count);
                }
            }
        }
    private IList <IPickListItemView> GetItems(IPickListView pickList)
    {
        using (ISession session = new SessionScopeWrapper(true))
        {
            if (string.IsNullOrEmpty(_sortExpression))
            {
                _sortExpression = "OrderSeq";
            }

            var query = session.QueryOver <IPickListItemView>()
                        .Where(x => x.UserId == "ADMIN" && x.PickListId == (string)pickList.Id);
            query.UnderlyingCriteria.AddOrder(new Order(_sortExpression, _sortDirection));
            return(query.List());
        }
    }
 private IList <IPickListItemView> GetItems(IPickListView pickList)
 {
     using (ISession session = new SessionScopeWrapper(true))
     {
         if (string.IsNullOrEmpty(_sortExpression))
         {
             _sortExpression = "OrderSeq";
         }
         var query = session.QueryOver <IPickListItemView>()
                     .Where(x => x.UserId == "ADMIN" && x.PickListId == (string)pickList.Id);
         if (!cboViewedLanguage.SelectedValue.Equals(AllItems))
         {
             query.WhereRestrictionOn(x => x.LanguageCode).IsInsensitiveLike(cboViewedLanguage.Text);
         }
         query.UnderlyingCriteria.AddOrder(new Order(_sortExpression, _sortDirection));
         return(query.List());
     }
 }
        private decimal GetQuotaAmtforUser(IUser user, DateTime today)
        {
            decimal amount = 0;

            if (user != null)
            {
                using (var session = new SessionScopeWrapper())
                {
                    IList <IQuota> quotas = session.QueryOver <IQuota>()
                                            .Where(x => today >= x.BeginDate && today <= x.EndDate && x.IsActive == true && x.AssignedTo == user)
                                            .List <IQuota>();

                    foreach (IQuota q in quotas)
                    {
                        amount += (decimal)q.Amount;
                    }
                }
            }

            return(amount);
        }
        protected override void OnExecute()
        {
            Phase = Resources.Job_Phase_Detail_Initializing;

            // Set progress bar to 0
            Progress = 0;
            decimal count = 0;

            // Get Current Date
            DateTime today = DateTime.Now.Date;

            // Retrieve all Forecasts for the current period
            // Cycle through them and create a snaphsot for each one.
            using (var session = new SessionScopeWrapper(true))
            {
                Phase = Resources.Job_SnapshotForecasts_Phase_Retrieving;
                IList <IForecast> forecasts = session.QueryOver <IForecast>()
                                              .Where(x => today >= x.BeginDate && today <= x.EndDate && x.Active == true)
                                              .List <IForecast>();

                // Cycle through each forecast and create a snapshot
                Phase = Resources.Job_SnapshotForecasts_Phase_TakingSnapshots;
                foreach (IForecast forecast in forecasts)
                {
                    forecast.TakeSnapshot();
                    Progress = (100M * ++count / forecasts.Count);
                    if (Interrupted)
                    {
                        return;
                    }
                }
                Phase = Resources.Job_Phase_Detail_Finalizing;
            }

            // Set progress bar to 100 (finished)
            Progress    = 100;
            Phase       = Resources.Job_Phase_Detail_Completed;
            PhaseDetail = String.Format(Resources.Job_SnapshotForecasts_Results, count);
        }
    private IPickListView GetPickListView()
    {
        var nextId = NextPickListId.Value;

        NextPickListId.Value = null;
        if (!string.IsNullOrWhiteSpace(nextId))
        {
            BindingSource.Current = EntityFactory.GetById <IPickListView>(nextId);
            ViewState["RunFormOnLoadLoadGrid"] = true;
        }
        var plv = BindingSource.Current as IPickListView;

        if (plv != null)
        {
            using (ISession session = new SessionScopeWrapper(true))
            {
                return(session.QueryOver <IPickListView>()
                       .Where(x => x.Id == plv.Id)
                       .SingleOrDefault());
            }
        }
        return(null);
    }
    private void ExportPickListData(IList<string> selections, string format)
    {
        if (selections == null)
        {
            using (ISession session = new SessionScopeWrapper())
            {
                selections = session.QueryOver<PickList>()
                    .Where(x => x.PickListId == "PICKLISTLIST")
                    .OrderBy(x => x.Text).Asc
                    .Select(x => x.ItemId)
                    .Cacheable()
                    .List<string>();
            }
        }

        DataTable dt = new DataTable("PickLists");
        DataColumn dc = dt.Columns.Add();
        dc.ColumnName = "PickListName";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "Text";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "Code";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "Order";
        dc.DataType = typeof(int);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "IsDefault";
        dc.DataType = typeof(bool);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "PickListId";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        dc = dt.Columns.Add();
        dc.ColumnName = "ItemId";
        dc.DataType = typeof(string);
        dc.AllowDBNull = true;

        IDictionary<string, Layout> layout = new Dictionary<string, Layout>();

        Layout item = new Layout();
        item = new Layout();
        item.ColumnName = "PickListName";
        item.ColumnCaption = "PickListName";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "Text";
        item.ColumnCaption = "Text";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "Code";
        item.ColumnCaption = "Code";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "Order";
        item.ColumnCaption = "Order";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "IsDefault";
        item.ColumnCaption = "IsDefault";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "PickListId";
        item.ColumnCaption = "PickListId";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        item = new Layout();
        item.ColumnName = "ItemId";
        item.ColumnCaption = "ItemId";
        item.Visible = true;
        item.FormatType = string.Empty;
        item.FormatString = string.Empty;
        item.Width = 64;
        layout.Add(item.ColumnName, item);

        foreach (string pickListId in selections)
        {
            PickList pl = PickList.GetPickListById(pickListId);
            if (pl != null)
            {
                PickList defaultItem = PickList.GetDefaultItem(pickListId);
                IList<PickList> Items = PickList.GetPickListItems(pickListId, false);
                if ((items != null) || (Items.Count > 0))
                {
                    foreach (PickList pitem in Items)
                    {
                        DataRow row = dt.NewRow();
                        row["PickListId"] = pickListId;
                        row["ItemId"] = pitem.ItemId;
                        row["PickListName"] = pl.Text;
                        row["Text"] = pitem.Text;
                        row["Code"] = pitem.Shorttext;
                        row["Order"] = pitem.Id;
                        if ((defaultItem != null) && (defaultItem.ItemId == pitem.ItemId))
                        {
                            row["IsDefault"] = true;
                        }
                        else
                        {
                            row["IsDefault"] = false;
                        }
                        dt.Rows.Add(row);
                    }
                }
                else
                {
                    DataRow row = dt.NewRow();
                    row["PickListId"] = pickListId;
                    row["ItemId"] = "NOITEMS";
                    row["PickListName"] = pl.Text;
                    row["Text"] = "";
                    row["Code"] = "";
                    row["Order"] = -1;
                    row["IsDefault"] = false;
                    dt.Rows.Add(row);
                }
            }
        }

        switch (format)
        {
            case "csv":
                ToCSV(dt, layout);
                break;
            case "tab":
                ToTab(dt, layout);
                break;
        }
    }
 private IPickListView GetPickListView()
 {
     IPickListView plv = BindingSource.Current as IPickListView;
     using (ISession session = new SessionScopeWrapper(true))
     {
         return session.QueryOver<IPickListView>()
             .Where(x => x.Id == plv.Id)
             .SingleOrDefault();
     }
 }
    private IList<IPickListItemView> GetItems(IPickListView pickList)
    {
        using (ISession session = new SessionScopeWrapper(true))
        {
            if (string.IsNullOrEmpty(_sortExpression))
            {
                _sortExpression = "OrderSeq";
            }

            var query = session.QueryOver<IPickListItemView>()
                .Where(x => x.UserId == "ADMIN" && x.PickListId == (string) pickList.Id);
            query.UnderlyingCriteria.AddOrder(new Order(_sortExpression, _sortDirection));
            return query.List();
        }
    }