/// <summary> /// Create new child earnings /// </summary> /// <param name="familyMemberId">Family member identifier</param> public void CreateNew(int familyMemberId) { var childEarings = new ChildEarnings { FamilyMemberID = familyMemberId }; Repository.Insert(childEarings); }
/// <summary> /// Add child earnings /// </summary> /// <param name="childEarnings">Child earnings</param> public void Add(ChildEarnings childEarnings) { Repository.Insert(childEarnings); }
/// <summary> /// Update child earnings /// </summary> /// <param name="childEarnings">Child earnings</param> public void Update(ChildEarnings childEarnings) { Repository.Update(childEarnings); }
/// <summary> /// Gets the financial overview of a child. /// </summary> /// <param name="weekDay">The weekday name</param> /// <param name="familyMemberId">The family member identifier.</param> public ChildFinancialOverview GetChildFinancialOverview(DayOfWeek weekDay, int?familyMemberId = null) { //Change TimeZone var dtTodayUtc = DateTime.UtcNow; var pendingPayDayApprovalAmount = decimal.Zero; var timeZoneCST = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); var utcOffset = new DateTimeOffset(dtTodayUtc, TimeSpan.Zero); var memberId = familyMemberId ?? _currentUserService.MemberID; var nextPayDayOld = DateTime.UtcNow.Date; bool pendingChoreStatus = false; var familyMember = Repository.Table <FamilyMember>().SingleOrDefault(p => p.UserID.Equals(_currentUserService.MemberID) && !p.IsDeleted); var ChildMember = Repository.Table <FamilyMember>().SingleOrDefault(p => p.Id.Equals(memberId) && !p.IsDeleted); // Get day of next payday to get completed chore values var nextPayDate = DateTime.UtcNow.GetNextPayDay().ToPayDayTime().Date; var startDate = DateTime.UtcNow.GetLastPayDay().Date; //Date to check amount DateTime cstTimeZoneTime = utcOffset.ToOffset(timeZoneCST.GetUtcOffset(utcOffset)).DateTime; //var payDayTime = Extension.GetPaydayTime(); if (weekDay == DayOfWeek.Friday)// Get last payday if today is friday { nextPayDate = startDate; } // Computes the amount to be paid on next pay day var chkStartDate = cstTimeZoneTime.getStartDate(); var nextPayDateCheck = cstTimeZoneTime.getEndDate(); var Previousthirtyday = Convert.ToDateTime(nextPayDateCheck).AddDays(-30); var completedChores = Repository.Table <Chore>().Where(p => p.FamilyMemberID == memberId && p.CompletedOn >= chkStartDate && p.CompletedOn < nextPayDateCheck && p.IsCompleted == true && p.ChoreStatus == ChoreStatus.Completed && !p.BankTransactionID.HasValue && !p.IsDeleted && !p.FamilyMember.IsDeleted).ToList().Select(p => p.Value); var nextPayAmount = decimal.Zero; if (completedChores.Any()) { nextPayAmount = completedChores.Sum(); } // Gets the allocation settings of current child var allocationSettings = Repository.Table <AllocationSettings>().SingleOrDefault(p => p.FamilyMemberID.Equals(memberId)); // Get expected earnings var nextPayDistribution = new ChildEarnings(); if (allocationSettings != null) { nextPayDistribution.Save = (nextPayAmount * (allocationSettings.Save / 100)); nextPayDistribution.Share = (nextPayAmount * (allocationSettings.Share / 100)); nextPayDistribution.Spend = (nextPayAmount * (allocationSettings.Spend / 100)); } // Gets child earnings var earnings = Repository.Table <ChildEarnings>().SingleOrDefault(p => p.FamilyMemberID.Equals(memberId)); var familyID = Repository.Table <User>().Where(m => m.Id == memberId).FirstOrDefault().FamilyID; var AdminFamilyMemberID = Repository.Table <User>().Where(m => m.FamilyID == familyID && m.Email != null).FirstOrDefault().Id; var IsSmsActive = Repository.Table <SMSApproval>().Where(M => M.FamilyMemberID == AdminFamilyMemberID && M.ApprovalType == ApprovalType.ChorePayment).OrderByDescending(p => p.Id).FirstOrDefault(); if (IsSmsActive != null && IsSmsActive.IsActive) //New logic has been added after 25 May { pendingPayDayApprovalAmount = GetPendingAmount(memberId, utcOffset); } if (pendingPayDayApprovalAmount > 0) { pendingChoreStatus = true; } //Get Child Latest corepro details var chkTXNDate = nextPayDateCheck.AddDays(-7); //New logic has been added after 25 May var transactionDetails = Repository.Table <BankTransaction>().Where(p => p.FamilyMemberID == AdminFamilyMemberID && p.CreatedOn >= chkTXNDate && p.PaymentType == PaymentType.Chore).OrderByDescending(p => p.Id).FirstOrDefault(); bool childPendingStatus = false; if (IsSmsActive != null) { if (transactionDetails != null) { childPendingStatus = transactionDetails.TransactionStatus == TransactionStatus.Completed ? false : true; } else { if (IsSmsActive.IsActive && pendingPayDayApprovalAmount > 0) { childPendingStatus = true; } } } //Approve Disapprove amount adjustment var ChildDisaprovedandPendingAmt = CalculateChildChoreStatusAmountDB(memberId); if (ChildDisaprovedandPendingAmt < 0) //New logic has been added after 25 May { nextPayAmount = nextPayAmount - ChildDisaprovedandPendingAmt; } int timeToday = utcOffset.ToOffset(timeZoneCST.GetUtcOffset(utcOffset)).TimeOfDay.Hours; if ((utcOffset.ToOffset(timeZoneCST.GetUtcOffset(utcOffset)).DayOfWeek == DayOfWeek.Thursday && timeToday >= 10) || (DateTime.UtcNow.DayOfWeek == DayOfWeek.Friday)) { // Get added day of next payday nextPayDayOld = DateTime.UtcNow.GetNextPayDay(DayOfWeek.Friday, 7).Date; // Get added day of next payday for friday } else { //Get day of next payday nextPayDayOld = DateTime.UtcNow.GetNextPayDay(DayOfWeek.Friday).Date; } DateTime dt = new DateTime(); dt = Convert.ToDateTime(nextPayDayOld); int PayDaydate = dt.Day; string PayDaydateSuffix = (PayDaydate % 10 == 1 && PayDaydate != 11) ? "st" : (PayDaydate % 10 == 2 && PayDaydate != 12) ? "nd" : (PayDaydate % 10 == 3 && PayDaydate != 13) ? "rd" : "th"; string PayDayMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dt.Month); var nextPayDay = PayDayMonth + " " + PayDaydate + "" + PayDaydateSuffix; // Prepare child financial overview var childFinancialOverview = new ChildFinancialOverview { NextPayDate = nextPayDay, NextPayAmount = nextPayAmount, AllocationSettings = allocationSettings != null ? allocationSettings : new AllocationSettings(), Earnings = earnings != null ? earnings : new ChildEarnings(), NextPayDistribution = nextPayDistribution, pendingChoreStatus = pendingChoreStatus, childChoreStatus = childPendingStatus }; return(childFinancialOverview); }