public IQueryable <AgencyReportingHcRow> GetAgencyReportingData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions)
        {
            db.CommandTimeout = 600;
            var q = db.Over105HcHours(this.SelectedRegionId,
                                      this.SelectedAgencyGroupId,
                                      this.SelectedYear,
                                      this.sSearch,
                                      this.iDisplayLength == int.MaxValue ? int.MaxValue : this.iDisplayLength + 1,
                                      this.iDisplayStart,
                                      permissions.User.Id).Select(g => new AgencyReportingHcRow
            {
                AgencyGroupId   = g.AgencyGroupId,
                AgencyGroupName = g.AgencyGroupName,
                Year            = g.Year,
                Month           = g.Month,
                ClientId        = g.ClientId,
                ReportedHours   = g.ReportedHours,
                GovHours        = g.GovHours,
                TotalHours      = g.TotalHours,
                RegionId        = g.RegionId,
                ReportedDate    = g.ReportDate,
                Week            = g.Week
            }).Where(f => f.TotalHours > 105).OrderBy(f => f.ReportedDate).ToList();

            return(q.AsQueryable());
        }
Esempio n. 2
0
        public static IQueryable <ServiceConstraint> GetServiceTypeConstraints(ccEntities db, int appId)
        {
            var q = from item in
                    (from app in db.Apps
                     where app.Id == appId
                     from service in app.Services
                     select new
            {
                FundId = app.FundId,
                ServiceTypeId = service.TypeId
            })
                    group item by item into itemsGroup
                    select itemsGroup.Key;

            var qq = from s in q
                     join c in db.ServiceConstraints.Where(f => f.FundId == null) on s.ServiceTypeId equals c.ServiceTypeId into cg
                     from c in cg.DefaultIfEmpty()
                     join fc in db.ServiceConstraints on new { ServiceTypeId = (int?)s.ServiceTypeId, FundId = (int?)s.FundId }
            equals new { ServiceTypeId = fc.ServiceTypeId, FundId = fc.FundId } into fcg
            from fc in fcg.DefaultIfEmpty()
            where fc != null || c != null
            select fc ?? c;

            return(qq);
        }
Esempio n. 3
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            using (var db = new ccEntities())
            {
                var client = (from c in db.Clients
                              where c.Id == this.ClientId
                              select new
                {
                    JoinDate = c.JoinDate,
                    LeaveDate = c.LeaveDate,
                    DeceasedDate = c.DeceasedDate,
                }).SingleOrDefault();


                //it should be included in mainreport's period in case exists for all report types
                if (this.SubReport != null & client != null)
                {
                    if (this.SubReport.MainReport.End < client.JoinDate)
                    {
                        yield return(new ValidationResult("Join Date must be before End of the report"));
                    }
                    if (this.SubReport.MainReport.Start > client.LeaveDate)
                    {
                        yield return(new ValidationResult("Leave Date must be after Start of the report"));
                    }
                }
            }
        }
        public static IEnumerable <BegExportModel> GetBegExportData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions, ClientsListDataTableModel param)
        {
            var filtered = GetClients(db, permissions, param);

            return(filtered.Select(c => new BegExportModel
            {
                Id = c.Id,
                AgencyId = c.AgencyId,
                AgencyName = c.Agency.Name,
                FundStatusName = c.FundStatus.Name,
                ApprovalStatusName = c.ApprovalStatus.Name,
                CompensationProgramName = c.CompensationProgramName,
                AddCompName = c.AddCompName,
                AddCompRegNum = c.AddCompId,
                LastName = c.LastName,
                FirstName = c.FirstName,
                PrevLastName = c.PrevLastName,
                PrevFirstName = c.PrevFirstName,
                OtherLastName = c.OtherLastName,
                PobCity = c.PobCity,
                BirthCountryName = c.BirthCountry.Name,
                BirthDate = c.BirthDate,
                OtherBirthDate = c.OtherDob,
                Address = c.Address,
                City = c.City,
                Zip = c.ZIP,
                StateCode = c.State.Code,
                CountryCode = c.Country.Code,
            }));
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            using (var db = new ccEntities())
            {
                //validate start!=end
                if (this.EndDate.HasValue && this.EndDate <= this.StartDate)
                {
                    yield return(new ValidationResult("The End Date must be greater than the Start date."));
                }

                //validate start <= today
                if (this.StartDate > DateTime.Now)
                {
                    yield return(new ValidationResult(string.Format("Start date must be less than or equal to {0}.", DateTime.Now.Date.ToShortDateString())));
                }

                //validate that there are no overlapped periods
                var overlaped = db.HomeCareEntitledPeriods
                                .Where(overlappCheckExpression(this.StartDate, this.EndDate))
                                .Where(c => c.ClientId == this.ClientId && c.Id != this.Id);
                if (overlaped.Count() > 0)
                {
                    yield return(new ValidationResult("There is a duplicate period."));
                }
            }
        }
        public static IEnumerable <Client> SampleCusomers(int count)
        {
            Random rnd = new Random();

            using (var db = new ccEntities())
            {
                var countries = db.Countries.ToList();
                var agencies  = db.Agencies.ToList();
                var users     = db.Users.ToList();
                return(Enumerable.Range(0, count).Select(c =>
                {
                    int i = rnd.Next(int.MaxValue);
                    return new Client()
                    {
                        FirstName = string.Format("fn{0}", i),
                        LastName = string.Format("ln{0}", i),
                        JoinDate = DateTime.Now,
                        CountryId = countries.Skip(i % countries.Count).FirstOrDefault().Id,
                        AgencyId = agencies.Skip(i % agencies.Count).FirstOrDefault().Id,
                        City = string.Format("fn{0}", i),
                        Address = string.Format("fn{0}", i),
                        UpdatedById = users.Skip(i % users.Count).FirstOrDefault().Id,
                        UpdatedAt = DateTime.Now
                    };
                }));
            }
        }
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (!this.Countries.Any())
     {
         yield return(new ValidationResult("Please select at least one Country"));
     }
     using (var db = new ccEntities())
     {
         var cfsCountryIds = this.Countries.Select(f => f.Id).ToArray();
         var q             = from ca in db.CfsAmounts
                             from country in ca.Countries
                             where ca.Id != this.Id
                             where cfsCountryIds.Contains(country.Id)
                             where ca.Year == this.Year && ca.CurrencyId == this.CurrencyId && ca.Level == this.Level
                             select new
         {
             CfsAmountId = ca.Id,
             CountryId   = country.Id,
             CountryCode = country.Code,
             Year        = ca.Year,
             CurrencyId  = ca.CurrencyId,
             Level       = ca.Level
         };
         foreach (var item in q)
         {
             yield return(new ValidationResult(string.Format("Conflict with Country {0}, Year {1}, Currency {2}, Level {3}", item.CountryCode, item.Year, item.CurrencyId, item.Level)));
         }
     }
 }
Esempio n. 8
0
 public IQueryable <UsersListRow> GetUsers(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions)
 {
     return(from ag in db.Users.Where(permissions.UsersFilter)
            select new UsersListRow
     {
         Id = ag.Id,
         RegionId = ag.Agency.AgencyGroup.Country.RegionId,
         CountryId = ag.Agency.AgencyGroup.CountryId,
         AgencyGroupId = ag.Agency.GroupId,
         AgencyId = ag.AgencyId,
         FirstName = ag.FirstName,
         LastName = ag.LastName,
         Username = ag.UserName,
         Email = ag.Email,
         UniqueId = ag.UniqueId,
         RoleId = ag.RoleId,
         Role = ag.Role.Name,
         Disabled = ag.Disabled,
         RoleEnd = ag.RoleId == (int)FixedRoles.RegionOfficer ? ag.Region.Name :
                   ag.RoleId == (int)FixedRoles.RegionAssistant ? ag.Region.Name :
                   (ag.RoleId == (int)FixedRoles.Ser || ag.RoleId == (int)FixedRoles.SerAndReviewer) ? ag.AgencyGroup.Name :
                   (ag.RoleId == (int)FixedRoles.AgencyUser ||
                    ag.RoleId == (int)FixedRoles.AgencyUserAndReviewer ||
                    ag.RoleId == (int)FixedRoles.DafEvaluator ||
                    ag.RoleId == (int)FixedRoles.DafReviewer) ? ag.Agency.Name : null
     });
 }
        public static IEnumerable <DataRowExportRow> HseapDetailedExportData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions, int id)
        {
            var data = HseapDetailedData(db, permissions, id);

            var result = data.Data.Select(f => new DataRowExportRow
            {
                sds = data.Start.ToMonthString(),
                eds = data.End.AddDays(-1).ToMonthString(),
                tn  = f.TypeName + (string.IsNullOrWhiteSpace(f.TypeDescription) ? string.Empty : string.Format("({0})", f.TypeDescription)),
                ccc = f.ReportSummary.ClientsCount,
                cgc = f.ReportSummary.GrantsCount,
                cta = f.ReportSummary.TotalAmount,
                acc = f.AppSummary.ClientsCount,
                agc = f.AppSummary.GrantsCount,
                ata = f.AppSummary.TotalAmount
            }).ToList();

            result.AddRange(new[] { data.TotalsRow }.Select(f => new DataRowExportRow
            {
                sds = data.Start.ToMonthString(),
                eds = data.End.AddDays(-1).ToMonthString(),
                tn  = "Total",
                ccc = f.ReportSummary == null ? 0 : f.ReportSummary.ClientsCount,
                cgc = f.ReportSummary == null ? 0 : f.ReportSummary.GrantsCount,
                cta = f.ReportSummary == null ? 0 : f.ReportSummary.TotalAmount,
                acc = f.AppSummary == null ? 0 : f.AppSummary.ClientsCount,
                agc = f.AppSummary == null ? 0 : f.AppSummary.GrantsCount,
                ata = f.AppSummary == null ? 0 : f.AppSummary.TotalAmount
            }));


            return(result);
        }
        public static IEnumerable <LeaveEntriesExportModel> LeaveEntriesExportData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions, ClientsListDataTableModel param)
        {
            var q = (from c in GetClients(db, permissions, param)
                     join h in db.Histories on c.Id equals h.ReferenceId
                     where h.TableName == "Clients" && h.FieldName == "LeaveDate"
                     join hl in db.Histories on c.Id equals hl.ReferenceId
                     where hl.TableName == "Clients" && hl.FieldName == "LeaveReasonId" && hl.UpdateDate == h.UpdateDate
                     where h.NewValue != null && hl.NewValue != null
                     select new LeaveEntriesExportModel
            {
                ClientId = c.Id,
                LeaveDate = h.NewValue,
                LeaveReason = hl.NewValue,
            }).OrderBy(f => f.ClientId).ToList();

            DateTime tempDate;
            int      templrid;

            return(from item in q
                   select new LeaveEntriesExportModel
            {
                ClientId = item.ClientId,
                LeaveDate = DateTime.TryParseExact(item.LeaveDate, "M/d/yyyy h:mm:ss tt", new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.None, out tempDate) ? tempDate.ToString("dd MMM yyyy") : "",
                LeaveReason = int.TryParse(item.LeaveReason, out templrid) && db.LeaveReasons.Any(f => f.Id == templrid) ? db.LeaveReasons.FirstOrDefault(f => f.Id == templrid).Name : ""
            });
        }
 //"1.4.15.3.3.        Join Date- Clients that joined the agency could not be reported for hours in months before the month of their join date.  "
 public bool ValidateJoinDate()
 {
     using (var db = new ccEntities())
     {
         return(true);
     }
 }
Esempio n. 12
0
        protected override IQueryable <CriEmergencyPreview> PreviewQuery(Guid id, CC.Data.ccEntities _db)
        {
            var      objectSet         = _db.CriBases.OfType <CC.Data.CriEmergency>();
            var      Clients           = this.GetClients(_db);
            var      SubReports        = this.GetSubReports(_db);
            DateTime JoinDateToCompare = new DateTime(2018, 1, 1);
            var      source            = (from item in objectSet
                                          where item.ImportId == id
                                          join t in _db.EmergencyReportTypes on item.TypeId equals t.Id into tGroup
                                          from t in tGroup.DefaultIfEmpty()
                                          join client in Clients on item.ClientId equals client.Id into clientsGroup
                                          from client in clientsGroup.DefaultIfEmpty()
                                          join subReport in SubReports on item.SubReportId equals subReport.Id into srg
                                          from subReport in srg.DefaultIfEmpty()
                                          let ldx = System.Data.Objects.EntityFunctions.AddDays(client.LeaveDate, client.DeceasedDate == null ? 0 : SubReport.EAPDeceasedDaysOverhead)
                                                    let start = item.Date ?? subReport.MainReport.Start
                                                                let mrStart = subReport.MainReport.Start
                                                                              let end = subReport.MainReport.End
                                                                                        select new CriEmergencyPreview
            {
                RowIndex = item.RowIndex,
                ClientId = item.ClientId,
                Amount = item.Amount,
                Discretionary = item.Discretionary,
                Date = item.Date,
                TypeName = t.Name,
                ClientName = client.AgencyId != subReport.AppBudgetService.AgencyId ? "" : client.FirstName + " " + client.LastName,
                Remarks = item.Remarks,
                UniqueCircumstances = item.UniqueCircumstances,

                Errors = (item.Errors ??
                          (
                              ((item.Amount == null) ? "Amount is required." : "") +
                              ((item.Discretionary == null) ? "Discretionary amount is required." : "") +
                              ((item.Date == null) ? "Date is required." : "") +
                              ((t == null) ? "Type is required." : "") +
                              ((item.Remarks == null || item.Remarks.Trim() == "")?  "Purpose of grant":"") +
                              ((client == null) ? "Invalid ClientId" : "") +
                              (client.JoinDate > end ? "Client has joined after report end date" : "") +
                              (client.DeceasedDate == null && client.LeaveDate < mrStart ? "Client has left before report start date" : "") +
                              ((item.Date < subReport.MainReport.Start || item.Date >= subReport.MainReport.End) ? "Invalid Report Date" : "") +
                              ((client.AgencyId != subReport.AppBudgetService.AgencyId) ? "Invalid Agency" : "") +
                              ((subReport.AppBudgetService.AppBudget.App.Fund.AustrianEligibleOnly && !client.AustrianEligible) ? "Client Not Austrian Eligible" : "") +
                              ((subReport.AppBudgetService.AppBudget.App.Fund.RomanianEligibleOnly && !client.RomanianEligible) ? "Client Not Romanian Eligible" : "") +
                              ((client.AustrianEligible && item.Date > client.LeaveDate && (item.UniqueCircumstances == null || item.UniqueCircumstances == "")) ? "Unique Circumstances must be filled" : "") +
                              ((client.RomanianEligible && item.Date > client.LeaveDate && (item.UniqueCircumstances == null || item.UniqueCircumstances == "")) ? "Unique Circumstances must be filled" : "") +

                              ((client.JoinDate > subReport.MainReport.End) ? "Client cant be reported because of Join Date" : "") +
                              (ldx < start && !client.AustrianEligible && !client.RomanianEligible ? "The Client has left the agency." : "") +
                              (
                                  (client.LeaveDate < start && ldx >= start && (item.Remarks == null || item.Remarks.Trim().Length == 0)) ?
                                  "Deceased Client needs to be specified with Unique Circumstances." : ""
                              )
                          ))
            });

            return(source);
        }
Esempio n. 13
0
        public void LoadData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions, User user)
        {
            var availableAgencyGroups = db.AgencyGroups.Where(permissions.AgencyGroupsFilter).Select(f => new { Id = f.Id, Name = f.DisplayName });

            Funds = new SelectList(db.Funds.Select(f => new { Id = f.Id, Name = f.Name }).OrderBy(f => f.Name), "Id", "Name", this.FundId);
            Apps  = new SelectList(db.Apps.Where(this.Permissions.AppsFilter)
                                   .Where(f => FundId == null || f.FundId == FundId)
                                   .Select(f => new { Id = f.Id, Name = f.Name })
                                   .OrderBy(f => f.Name), "Id", "Name", this.AppId);
        }
        public IEnumerable <OverViewDataRow> LinqData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions)
        {
            var source = this.Filter(db, permissions);

            var q = from a in source
                    group a by new
            {
                a.AppId,
                a.ServiceId,
            } into g
                select new
            {
                g.Key.AppId,
                g.Key.ServiceId,
                Quantity     = g.Sum(f => f.Quantity),
                Amount       = g.Sum(f => f.Amount),
                ClientsCount = g.Select(f => f.ClientId).Distinct().Count(),
                CcGrant      = g.Select(f => new
                {
                    f.AppId,
                    f.ServiceId,
                    f.CcGrant
                }).Distinct().Sum(f => f.CcGrant)
            };
            var r = from f in q
                    join b in db.viewAppExchangeRates on new { AppId = f.AppId, ToCur = this.CurId }
            equals new { AppId = b.AppId, ToCur = b.ToCur }
            join s in db.Services on f.ServiceId equals s.Id
            join a in db.Apps on f.AppId equals a.Id
                select new OverViewDataRow
            {
                ServiceTypeName      = s.ServiceType.Name,
                ServiceName          = s.Name,
                FundName             = a.Fund.Name,
                AppName              = a.Name,
                Quantity             = f.Quantity,
                Amount               = b.Value * f.Amount,
                ClientsCount         = f.ClientsCount,
                AverageCostPerClient = b.Value * f.Amount / (f.ClientsCount == 0 ? (int?)null : f.ClientsCount),
                AverageCostPerUnit   = b.Value * f.Amount / (f.Quantity == 0 ? (int?)null : f.Quantity),
                MasterFundName       = a.Fund.MasterFund.Name,
                CcGrant              = b.Value * f.CcGrant,
                Cur       = this.CurId,
                ServiceId = f.ServiceId,
                AppId     = f.AppId
            };

            if (this.iDisplayLength != int.MaxValue)
            {
                r = r
                    .OrderBy(f => f.AppId)
                    .Skip(this.iDisplayStart).Take(this.iDisplayLength + 1);
            }
            return(r.ToList());
        }
Esempio n. 15
0
 /// <summary>
 /// check db for duplicate
 /// </summary>
 /// <returns>true if duplicate exists</returns>
 public static bool CheckForDuplicate(Client client)
 {
     if (client == null)
     {
         return(false);
     }
     using (var db = new ccEntities())
     {
         return(db.Clients.Any(Client.IsDuplicate(client)));
     }
 }
        private IEnumerable <ValidationResult> ValidateEmergencyReport(ValidationContext context)
        {
            if (this.Amount == null)
            {
                yield return(new ValidationResult("Amount is a required field", new[] { "Amount" }));
            }

            using (var db = new ccEntities())
            {
            }
        }
 public static IEnumerable <GovHcHoursExportModel> GetGovHcHoursExportData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions, ClientsListDataTableModel param)
 {
     return((from c in GetClients(db, permissions, param)
             join gh in db.GovHcHours on c.Id equals gh.ClientId
             select new GovHcHoursExportModel
     {
         ClientId = c.Id,
         StartDate = gh.StartDate,
         Value = gh.Value
     }).OrderBy(f => f.ClientId));
 }
Esempio n. 18
0
 public static int GetWeekNumber(DateTime ReportDate, int WeekStartDay)
 {
     using (var db = new ccEntities())
     {
         var queryText = "SELECT ccModel.Store.GetWeekNumber(@ReportDate, @WeekStartDay) FROM {1}";
         var result    = db.CreateQuery <int>(queryText
                                              , new ObjectParameter("ReportDate", ReportDate)
                                              , new ObjectParameter("WeekStartDay", WeekStartDay));
         return(result.First());
     }
 }
        public Models.jQueryDataTableResult GetJqResult(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions)
        {
            var source = Data(db, permissions);

            return(new CC.Web.Models.jQueryDataTableResult
            {
                aaData = source.Take(this.iDisplayLength),
                iTotalDisplayRecords = source.Count() > this.iDisplayLength ? this.iDisplayStart + this.iDisplayLength + 1 : this.iDisplayStart + 1,
                sEcho = this.sEcho
            });
        }
Esempio n. 20
0
        public void LoadRelatedData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions)
        {
            var validStatuses = AppBudget.ValidStatuses.Select(f => (int?     )f);

            this.MainReport.AppBudget = db.AppBudgets
                                        .Include(f => f.App.Fund)
                                        .Include(f => f.App.AgencyGroup)
                                        .Where(permissions.AppBudgetsFilter)
                                        .Where(f => validStatuses.Contains(f.StatusId))
                                        .Single(f => f.Id == this.MainReport.AppBudgetId);
            IsLoaded = true;
        }
Esempio n. 21
0
 public static decimal?GovHcCapLeaveDate(int clientId, DateTime?checkPeriodStart, DateTime?checkPeriodEnd)
 {
     using (var db = new ccEntities())
     {
         var queryText = "SELECT ccModel.Store.GovHcCapLeaveDate(@clientId, @checkPeriodStart, @checkPeriodEnd) FROM {1}";
         var result    = db.CreateQuery <decimal?>(queryText
                                                   , new ObjectParameter("clientId", clientId)
                                                   , new ObjectParameter("checkPeriodStart", checkPeriodStart)
                                                   , new ObjectParameter("checkPeriodEnd", checkPeriodEnd));
         return(result.First());
     }
 }
Esempio n. 22
0
        public static int CfsLevelForGivenDate(int clientId, DateTime?givenDate)
        {
            using (var db = new ccEntities())
            {
                var queryText = "SELECT ccModel.Store.CfsLevelForGivenDate(@clientId, @givenDate) FROM {1}";
                var result    = db.CreateQuery <int>(queryText
                                                     , new ObjectParameter("clientId", clientId)
                                                     , new ObjectParameter("givenDate", givenDate));

                return(result.First());
            }
        }
 public static IEnumerable <HASExportModel> HASExportData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions, ClientsListDataTableModel param)
 {
     return((from c in GetClients(db, permissions, param)
             join has in db.ClientHcStatuses on c.Id equals has.ClientId
             select new HASExportModel
     {
         ClientId = c.Id,
         StatusDate = has.StartDate,
         FundStatus = has.FundStatusId.HasValue != null ? has.FundStatus.Name : "N/A",
         ApprovalStatus = has.ApprovalStatusId.HasValue != null ? has.ApprovalStatus.Name : "N/A",
         HCStatus = has.HcStatusId
     }).OrderBy(f => f.ClientId));
 }
Esempio n. 24
0
        public static IEnumerable <FundStatusReportDataRow> LoadData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions, CC.Data.User user, FundStatusReportFilter filter)
        {
            var dbData = from cr in db.ViewClientReports
                         join sra in db.viewSubreportAmounts on cr.SubReportId equals sra.id
                         join abs in db.AppBudgetServices.Where(f => !f.Agency.AgencyGroup.ExcludeFromReports) on sra.AppBudgetServiceId equals abs.Id
                         join mr in db.MainReports on sra.MainReportId equals mr.Id
                         join c in db.Clients on cr.ClientId equals c.Id
                         select new FundStatusReportDataRow
            {
                Active         = c.DeceasedDate == null && c.LeaveDate == null,
                AgencyName     = c.Agency.Name,
                AgencyId       = c.AgencyId,
                Amount         = cr.Amount ?? sra.EstAmountPerClient,
                AppId          = mr.AppBudget.AppId,
                AppName        = mr.AppBudget.App.Name,
                BirthDate      = c.BirthDate,
                ClientId       = c.Id,
                CurrencyId     = mr.AppBudget.App.CurrencyId,
                End            = mr.End,
                FirstName      = c.FirstName,
                FundId         = mr.AppBudget.App.FundId,
                FundName       = mr.AppBudget.App.Fund.Name,
                FundStatusId   = c.FundStatusId,
                FundStatusName = c.FundStatus.Name,
                LastName       = c.LastName,
                SerId          = c.Agency.GroupId,
                SerName        = c.Agency.AgencyGroup.Name,
                ServiceId      = abs.ServiceId,
                ServiceName    = abs.Service.Name,
                Start          = mr.Start,
                Year           = System.Data.Objects.SqlClient.SqlFunctions.DatePart("year", mr.Start),
            };

            if (filter.FundStatusesString.Any())
            {
                dbData = dbData.Where(f => filter.FundStatusesString.Contains(f.FundStatusId ?? 0));
            }
            if (filter.Funds.Any())
            {
                dbData = dbData.Where(f => filter.Funds.Contains(f.FundId ?? 0));
            }
            if (filter.Year.HasValue)
            {
                dbData = dbData.Where(f => f.Year == (int)filter.Year.Value);
            }

            var result = dbData.ToList();

            return(result);
        }
        public static int?ValidateInterlineTranfer(int id)
        {
            using (var db = new ccEntities())
            {
                var prev = from a in db.ApprovedAppBudgetServices
                           where a.AppBudgetId == id
                           join s in db.Services on a.ServiceId equals s.Id
                           group a by s.ServiceLevel into ag
                           select new
                {
                    ServiceLevel = ag.Key,
                    CcGrant      = ag.Sum(f => f.CcGrant)
                };
                var current = from a in db.AppBudgetServices
                              where a.AppBudgetId == id
                              join s in db.Services on a.ServiceId equals s.Id
                              group a by s.ServiceLevel into ag
                              select new
                {
                    ServiceLevel = ag.Key,
                    CcGrant      = ag.Sum(f => f.CcGrant)
                };
                var change = (from level in Enumerable.Range(1, 3)
                              join o in prev.ToList() on level equals o.ServiceLevel into og
                              from o in og.DefaultIfEmpty()
                              join n in current.ToList() on level equals n.ServiceLevel into ng
                              from n in ng.DefaultIfEmpty()
                              select new
                {
                    level = level,
                    o = o == null ? 0 : o.CcGrant,
                    n = n == null ? 0 : n.CcGrant
                }).Select(f => new { l = f.level, o = f.o, n = f.n, c = f.n - f.o });

                var shift = 0M;
                foreach (var item in change.OrderBy(f => f.l))
                {
                    if (item.c < 0)
                    {
                        shift -= item.c;
                    }
                    else if (item.c > 0 && item.c > shift)
                    {
                        return(item.l);
                    }
                }
            }
            return(null);
        }
Esempio n. 26
0
 /// <summary>
 /// Returns the first date of an approval status Approved or Research in progress with proof
 /// No Eligibility periods are allowed to be changed prior this date.
 /// </summary>
 /// <param name="clientId"></param>
 /// <returns></returns>
 public static DateTime?ClientFirstApprovedDate(int clientId)
 {
     using (var db = new ccEntities())
     {
         var result = (from h in db.Histories
                       where h.ReferenceId == clientId && h.TableName == "Clients" && h.FieldName == "ApprovalStatusId"
                       where h.NewValue == "2" || h.NewValue == "2048"
                       select h).OrderBy(f => f.UpdateDate);
         if (result.Any())
         {
             return(result.FirstOrDefault().UpdateDate);
         }
         return(null);
     }
 }
        public static IEnumerable <DuplicateExportModel> GetDuplicateExportData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions, ClientsListDataTableModel param)
        {
            var clients  = GetClients(db, permissions, param);
            var filtered = clients.Where(f => f.MasterId != null).Select(c => new { c.MasterId });
            var result   = (from c in clients
                            join f in filtered on(c.MasterIdClcd) equals f.MasterId
                            select new DuplicateExportModel
            {
                Id = c.Id,
                AgencyName = c.Agency.Name,
                MasterId = c.MasterId != null ? c.MasterId : c.Id
            }).Distinct();

            return(result);
        }
Esempio n. 28
0
 /// <summary>
 /// returns last submitted hc report date end (+1month)
 /// No Eligibility periods or functionality scores are allowed to be changed prior this date.
 /// </summary>
 /// <param name="clientId"></param>
 /// <returns></returns>
 public static DateTime?LastSubmittedHcRepDate(int clientId)
 {
     using (var db = new ccEntities())
     {
         var result = (from cr in db.ClientReports
                       where cr.ClientId == clientId
                       join sr in db.SubReports on cr.SubReportId equals sr.Id
                       join mr in db.MainReports.Where(MainReport.Submitted) on sr.MainReportId equals mr.Id
                       where sr.AppBudgetService.Service.ReportingMethodId == (int)Service.ReportingMethods.Homecare ||
                       sr.AppBudgetService.Service.ReportingMethodId == (int)Service.ReportingMethods.HomecareWeekly
                       select mr).OrderByDescending(f => f.Start);
         if (result.Any())
         {
             return(result.FirstOrDefault().End);
         }
         return(null);
     }
 }
Esempio n. 29
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            using (var db = new ccEntities())
            {
                if (db.MembershipUsers.Any(f => f.LoweredUserName == this.UserName.ToLower() &&
                                           f.Id != this.Id))
                {
                    yield return(new ValidationResult("Duplicate username."));
                }
            }

            if (!Enum.IsDefined(typeof(FixedRoles), this.RoleId))
            {
                yield return(new ValidationResult("Invalid Role"));
            }
            else
            {
                switch ((FixedRoles)this.RoleId)
                {
                case FixedRoles.AgencyUser:
                case FixedRoles.AgencyUserAndReviewer:
                    if (this.AgencyId == null)
                    {
                        yield return(new ValidationResult("Agency is a required field."));
                    }
                    break;

                case FixedRoles.RegionOfficer:
                    if (!this.AgencyGroups.Any())
                    {
                        yield return(new ValidationResult("Region is a required field."));
                    }
                    break;

                case FixedRoles.Ser:
                case FixedRoles.SerAndReviewer:
                    if (this.AgencyGroupId == null)
                    {
                        yield return(new ValidationResult("Ser is a required field."));
                    }
                    break;
                }
            }
        }
        public IQueryable <AgencyReportingHomecareDetailsRow> GetAgencyReportingData(CC.Data.ccEntities db, CC.Data.Services.IPermissionsBase permissions)
        {
            db.CommandTimeout = 600;
            var source = db.spAgencyReportingHomecareDetails(this.CurId, this.StartDate, this.EndDate
                                                             , !this.IncludeNotSubmittedReports
                                                             , this.AgencyId
                                                             , this.RegionId
                                                             , this.CountryId
                                                             , this.StateId
                                                             , this.ServiceId
                                                             , this.MasterFundId
                                                             , this.FundId
                                                             , this.AppId
                                                             , this.ClientId
                                                             , this.sSearch
                                                             , this.sSortCol_0
                                                             , this.sSortDir_0 == "asc"
                                                             , this.iDisplayLength == int.MaxValue ? int.MaxValue : this.iDisplayLength + 1
                                                             , this.iDisplayStart
                                                             , permissions.User.Id).ToList();

            DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
            Calendar           cal = dfi.Calendar;

            var q = from item in source
                    select new AgencyReportingHomecareDetailsRow
            {
                AgencyId    = item.AgencyId,
                Cur         = this.CurId,
                ClientId    = item.ClientId,
                FundName    = item.FundName,
                AppName     = item.AppName,
                ServiceName = item.ServiceName,
                Quantity    = item.Quantity,
                Rate        = item.Rate,
                Amount      = item.Amount,
                Date        = item.ReportDate,
                IsWeekly    = item.IsWeekly.Value,
                WeekNumber  = "W" + (item.IsWeekly.Value ? (cal.GetWeekOfYear(item.ReportDate, dfi.CalendarWeekRule, item.SelectedDayOfWeek != null ? (DayOfWeek)item.SelectedDayOfWeek : item.MrStart.DayOfWeek)).ToString() : item.ReportDate.Month.ToString())
            };

            return(q.AsQueryable());
        }