コード例 #1
0
        protected void FormView2_ItemInserted1(object sender, FormViewInsertedEventArgs e)
        {
            FormView3.DataBind();

            using (FinanceManagerDataContext db = new FinanceManagerDataContext())
            {
                Member _member = db.Members.FirstOrDefault(m => m.MemberId == Convert.ToInt32(Request.QueryString["mid"]));
                //int investmentTypeID = ( db.Investments.FirstOrDefault(i => i.InvestmentID == Convert.ToInt32( Request.QueryString["InvId"])).InvestmentTypeId.Value);
                //AccountType accType = db.AccountTypes.FirstOrDefault(a => a.DefaultInvestmentTypeID == investmentTypeID);

                //withdrawal
                List<AccountTypeFeature> aFeatures = _member.AccountType.AccountTypeFeatures.Where(a => a.CalculateOn == 2).ToList();
                foreach (AccountTypeFeature item in aFeatures)
                {
                    decimal valueToApply = 0;
                    if (item.IsPercentage.Value)
                    {
                        valueToApply = item.ValueToApply.Value / 100 * Convert.ToDecimal(Session["WithdrawnAmount"]);
                    }
                    else
                    {
                        valueToApply = item.ValueToApply.Value;
                    }

                    if (item.IsDeduction.Value) //is deduction
                    {
                        AppliedDeduction aDeduction = new AppliedDeduction();
                        aDeduction.CreatedBy = User.Identity.Name;
                        aDeduction.CreatedDate = DateTime.Now;
                        aDeduction.DeductionAmount = valueToApply;
                        aDeduction.InvestmentID = Convert.ToInt32(Request.QueryString["InvId"]);
                        //aDeduction.IsDeleted = false;
                        aDeduction.Rate = item.ValueToApply;
                        db.AppliedDeductions.InsertOnSubmit(aDeduction);
                    }
                    else //is addition
                    {
                        AppliedInterest aInterest = new AppliedInterest();
                        aInterest.CreatedBy = User.Identity.Name;
                        aInterest.CreatedDate = DateTime.Now;
                        aInterest.InterestAmount = valueToApply;
                        aInterest.InvestmentID = Convert.ToInt32(Request.QueryString["InvId"]);
                        //aDeduction.IsDeleted = false;
                        aInterest.Rate = item.ValueToApply;
                        db.AppliedInterests.InsertOnSubmit(aInterest);
                    }

                    db.SubmitChanges();
                    ////AppliedAccountFeature aAccountFeature = new AppliedAccountFeature();
                    ////aAccountFeature.InvestmentID = Convert.ToInt32(Request.QueryString["InvId"]);
                    ////aAccountFeature.AccountNumber =
                }
            }
        }
コード例 #2
0
		private void detach_AppliedDeductions(AppliedDeduction entity)
		{
			this.SendPropertyChanging();
			entity.AppliedFeatureHistory = null;
		}
コード例 #3
0
		private void detach_AppliedDeductions(AppliedDeduction entity)
		{
			this.SendPropertyChanging();
			entity.Investment = null;
		}
コード例 #4
0
 partial void DeleteAppliedDeduction(AppliedDeduction instance);
コード例 #5
0
 partial void UpdateAppliedDeduction(AppliedDeduction instance);
コード例 #6
0
 partial void InsertAppliedDeduction(AppliedDeduction instance);
コード例 #7
0
    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;
                    }
                }
            }
        }
    }