private void detach_AppliedAccountFeatures(AppliedAccountFeature entity) { this.SendPropertyChanging(); entity.AppliedFeatureHistory = null; }
private void attach_AppliedAccountFeatures(AppliedAccountFeature entity) { this.SendPropertyChanging(); entity.AccountTypeFeature = this; }
partial void DeleteAppliedAccountFeature(AppliedAccountFeature instance);
partial void UpdateAppliedAccountFeature(AppliedAccountFeature instance);
partial void InsertAppliedAccountFeature(AppliedAccountFeature instance);
static void AppliedAccountTypeFeaturesEndOfDay() { List<FailMessages> failMessages = new List<FailMessages>(); using (FinanceManagerDataContext db = new FinanceManagerDataContext()) { //AccountType accType = db.AccountTypes.FirstOrDefault(a => a.AccountTypeId == Convert.ToInt32(DropDownList1.SelectedValue)); foreach (AccountType accType in db.AccountTypes) { foreach (AccountTypeFeature item in accType.AccountTypeFeatures) { AppliedFeatureHistory _appHistory = item.AppliedFeatureHistories.LastOrDefault(); if (_appHistory != null) { if (item.CalculationFrequencyID.Value == 1) //monthly { //AppliedFeatureHistory _appHistory = item.AppliedFeatureHistories.LastOrDefault(); if (_appHistory.AppliedDate.Value.AddMonths(1) < DateTime.Today) { failMessages.Add(new FailMessages() { Message = "Monthly feature was last applied on " + item.AppliedFeatureHistories.LastOrDefault().AppliedDate.Value + " which is less than a month. This feature was skipped." }); continue; } } else if (item.CalculationFrequencyID.Value == 2) //annually { if (_appHistory.AppliedDate.Value.AddYears(1) < DateTime.Today) { failMessages.Add(new FailMessages() { Message = "Annual feature was last applied on " + item.AppliedFeatureHistories.LastOrDefault().AppliedDate.Value + " which is less than a year. This feature was skipped." }); continue; } } else if (item.CalculationFrequencyID.Value == 3) //custom { if (_appHistory.AppliedDate.Value.AddDays(item.CustomCalculationFreqNumberOfDays.Value) < DateTime.Today) { failMessages.Add(new FailMessages() { Message = "Custom feature was last applied on " + item.AppliedFeatureHistories.LastOrDefault().AppliedDate.Value + " which is less than " + item.CustomCalculationFreqNumberOfDays.Value + " day(s). This feature was skipped." }); continue; } } } switch (item.CalculateOn) { case 1: foreach (Member member in accType.Members.Where(m => m.IsDeleted == false)) { int investmentTypeID = member.Investments.FirstOrDefault(i => i.InvestmentTypeId == db.AccountTypes.FirstOrDefault(a => a.AccountTypeId == member.AccountTypeID.Value).DefaultInvestmentTypeID.Value).InvestmentID; decimal valueToapply; decimal balance; balance = Utils.GetMemberBalance(member.MemberId, DateTime.Today.Date); if (item.IsPercentage.Value) { valueToapply = (item.ValueToApply.Value / 100) * balance; } else { valueToapply = item.ValueToApply.Value; } AppliedAccountFeature aFeature = new AppliedAccountFeature(); aFeature.AccountNumber = member.AccountNumber; aFeature.AccountTypeFeatureID = item.AccountFeatureID; aFeature.AppliedValue = item.IsDeduction.Value ? valueToapply * -1 : valueToapply; aFeature.CreatedBy = HttpContext.Current.User.Identity.Name; aFeature.CreatedDate = DateTime.Now; aFeature.InvestmentID = investmentTypeID; aFeature.Narration = "Account type feature manually applied."; db.AppliedAccountFeatures.InsertOnSubmit(aFeature); if (item.IsDeduction.Value) //insert into appliedCharges Table { AppliedInterest aInterest = new AppliedInterest(); aInterest.CreatedBy = HttpContext.Current.User.Identity.Name; aInterest.CreatedDate = DateTime.Now; aInterest.InterestAmount = valueToapply; aInterest.InvestmentID = aFeature.InvestmentID; aInterest.Rate = item.ValueToApply; db.AppliedInterests.InsertOnSubmit(aInterest); } else //insert into Applied interest table { AppliedDeduction aDeduction = new AppliedDeduction(); aDeduction.CreatedBy = HttpContext.Current.User.Identity.Name; aDeduction.CreatedDate = DateTime.Now; aDeduction.DeductionAmount = valueToapply; aDeduction.InvestmentID = aFeature.InvestmentID; aDeduction.Rate = item.ValueToApply; db.AppliedDeductions.InsertOnSubmit(aDeduction); } } AppliedFeatureHistory appliedFeatureHistory = new AppliedFeatureHistory(); appliedFeatureHistory.AccountTypeFeatureID = item.AccountFeatureID; appliedFeatureHistory.ActionInitiatedBy = "Manually run"; appliedFeatureHistory.AppliedBy = HttpContext.Current.User.Identity.Name; appliedFeatureHistory.AppliedDate = DateTime.Now; db.AppliedFeatureHistories.InsertOnSubmit(appliedFeatureHistory); db.SubmitChanges(); break; case 4: foreach (Member member in accType.Members.Where(m => m.IsDeleted == false)) { int investmentTypeID = member.Investments.FirstOrDefault(i => i.InvestmentTypeId == db.AccountTypes.FirstOrDefault(a => a.AccountTypeId == member.AccountTypeID.Value).DefaultInvestmentTypeID.Value).InvestmentID; decimal valueToapply; decimal totalWithdrawal; totalWithdrawal = Utils.GetMemberTotalWithdrawals(member.MemberId, DateTime.Today.Date); if (item.IsPercentage.Value) { valueToapply = (item.ValueToApply.Value / 100) * totalWithdrawal; } else { valueToapply = item.ValueToApply.Value; } AppliedAccountFeature aFeature = new AppliedAccountFeature(); aFeature.AccountNumber = member.AccountNumber; aFeature.AccountTypeFeatureID = item.AccountFeatureID; aFeature.AppliedValue = item.IsDeduction.Value ? valueToapply * -1 : valueToapply; aFeature.CreatedBy = HttpContext.Current.User.Identity.Name; aFeature.CreatedDate = DateTime.Now; aFeature.InvestmentID = investmentTypeID; aFeature.Narration = "Account type feature manually applied."; db.AppliedAccountFeatures.InsertOnSubmit(aFeature); if (item.IsDeduction.Value) //insert into appliedCharges Table { AppliedInterest aInterest = new AppliedInterest(); aInterest.CreatedBy = HttpContext.Current.User.Identity.Name; aInterest.CreatedDate = DateTime.Now; aInterest.InterestAmount = valueToapply; aInterest.InvestmentID = aFeature.InvestmentID; aInterest.Rate = item.ValueToApply; db.AppliedInterests.InsertOnSubmit(aInterest); } else //insert into Applied interest table { AppliedDeduction aDeduction = new AppliedDeduction(); aDeduction.CreatedBy = HttpContext.Current.User.Identity.Name; aDeduction.CreatedDate = DateTime.Now; aDeduction.DeductionAmount = valueToapply; aDeduction.InvestmentID = aFeature.InvestmentID; aDeduction.Rate = item.ValueToApply; db.AppliedDeductions.InsertOnSubmit(aDeduction); } } AppliedFeatureHistory appliedFeatureHistory1 = new AppliedFeatureHistory(); appliedFeatureHistory1.AccountTypeFeatureID = item.AccountFeatureID; appliedFeatureHistory1.ActionInitiatedBy = "Manually run"; appliedFeatureHistory1.AppliedBy = HttpContext.Current.User.Identity.Name; appliedFeatureHistory1.AppliedDate = DateTime.Now; db.AppliedFeatureHistories.InsertOnSubmit(appliedFeatureHistory1); db.SubmitChanges(); break; } } } } }