public void ProcessRequest(HttpContext context)
        {
            if (context.Request.QueryString["mid"] != null)
            {
                FinanceManagerDataContext db = new FinanceManagerDataContext();
                Member _member = null ; //= db.Members.First<Member>(m => m.MemberId == Convert.ToInt32(context.Request.QueryString["mid"]));
                try
                {
                     _member = db.Members.First<Member>(m => m.MemberId == Convert.ToInt32(context.Request.QueryString["mid"]));

                    context.Response.ContentType = "image/jpeg";
                    context.Response.BinaryWrite(_member.MemberPhoto.ToArray());

                }
                catch (Exception)
                {
                    if (_member != null)
                    {
                         if (_member.MemberPhoto == null)
                    {
                        context.Response.WriteFile("~/images/NoImage.png");
                        context.Response.ContentType = "image/png";
                    }
                    }

                }
            }
        }
        protected void InsertButton_Click(object sender, EventArgs e)
        {
            using (FinanceManagerDataContext db = new FinanceManagerDataContext())
            {
                //set current receipt number
                Parameter prm = db.Parameters.FirstOrDefault();

                //increase receipt number by one
                prm.ReceiptNumber++;
                Contribution _contribution = new Contribution()
                {
                    InvestmentId = Convert.ToInt32(Request.QueryString["InvId"]),
                    ContributionAmount = Convert.ToDecimal(ContributionAmountTextBox.Text.Trim()),
                    ContributionAmountInWords = Utils.ConvertMoneyToText(ContributionAmountTextBox.Text.Trim()),
                    ContributionBy = ContributionByTextBox.Text,
                    Description = "SUSU Contribution",
                    ReceiptNumber = prm.ReceiptNumber.Value.ToString().PadLeft(6, '0'),
                    RecievedBy = Session["CurrentUser_session"].ToString(),
                    PaymentMethodId = PaymentMethodWebUserControl1.PaymentTypeID,
                    ChequeNumber = PaymentMethodWebUserControl1.ChequeNumber,
                     CreatedDate = DateWebUserControl1.DtSelectedDate
                };

                db.Contributions.InsertOnSubmit(_contribution);
                db.SubmitChanges();

                //audit
                Utils.logAction("Insert", _contribution);

                Response.Redirect("SUSUContributionReceipt_Group.aspx?cid=" + _contribution.ContributionId.ToString() + "&gid=" + _contribution.Investment.GroupId);
            }
        }
        protected void InsertButton_Click(object sender, EventArgs e)
        {
            //fixed deposit doesnt allow part withdrawal. The whole amount should be withdrawn
            using (FinanceManagerDataContext db = new FinanceManagerDataContext())
            {
                MemberWithdrawal _memberWithdrawal = new MemberWithdrawal()
                {
                    CreatedBy = HttpContext.Current.User.Identity.Name,
                    DateCreated = DateTime.Now,
                    IsDeleted = false,
                    WithdrawalIssuedByUserName = User.Identity.Name,
                    InvestmentID = Convert.ToInt32(Request.QueryString["invId"]),
                    Narration = "Fixed Deposit withdrawal"
                    ,
                    WithdrawalAmount = Convert.ToDecimal(WithdrawalAmountTextBox.Text),
                    WithdrawnBy = WithdrawalAmountTextBox.Text
                };

                db.MemberWithdrawals.InsertOnSubmit(_memberWithdrawal);
                db.SubmitChanges();

                //audit
                Utils.logAction("Insert", _memberWithdrawal);

                Response.Redirect("FixedDepositInvestmentStatement.aspx?invId=" + Request.QueryString["invId"] + "&gid=" + Request.QueryString["gid"]);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            using (FinanceManagerDataContext db = new FinanceManagerDataContext())
            {
                CompanyProfile cProfile = db.CompanyProfiles.FirstOrDefault();
                context.Response.ContentType = "image/" + cProfile.LogoFileExt.Remove(0,1);
                context.Response.BinaryWrite(cProfile.CompanyLogo.ToArray());

            }
        }
 public void ProcessRequest(HttpContext context)
 {
     if (context.Request.QueryString["mid"] != null)
     {
         FinanceManagerDataContext db = new FinanceManagerDataContext();
         Member _member = db.Members.First<Member>(m => m.MemberId == Convert.ToInt32(context.Request.QueryString["mid"]));
         context.Response.ContentType = "image/jpeg";
         context.Response.BinaryWrite(_member.MemberPhoto.ToArray());
     }
 }
        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 =
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Utils.IsAuthorized("Guarantors", "Create");
                using (FinanceManagerDataContext db = new FinanceManagerDataContext())
                {
                    CurrentGuarantorber = new Guarantor()
                    {
                        GuarantorFirstName = MemberFirstNameTextBox.Text,
                        GuarantorLastName = MemberLastNameTextBox.Text,
                        Address = MemberResidentialTextBox.Text,
                        BusinessAddress = MemberBusinessLocationTextBox.Text,
                        CreatedBy = HttpContext.Current.User.Identity.Name,
                       // DOB = MemberDOBNameTextBox.Text,
                        Telephone = MemberTelTextBox.Text,
                        IdentityNumber = MemberIDNumberTextBox.Text,
                        IdentityTypeID = Convert.ToInt32(DropDownList1.SelectedValue)
                    };

                    CurrentGuarantorber.GuarantorPhoto = FileUpload1.FileBytes;
            //DateWebUserControl1.DtSelectedDate;
                    CurrentGuarantorber.DOB = DateWebUserControl1.DtSelectedDate;// Convert.ToDateTime(MemberDOBNameTextBox.Text);
                    CurrentGuarantorber.Fax = MemberFaxTextBox0.Text;
                    CurrentGuarantorber.IdentityNumber = MemberIDNumberTextBox.Text;
                    CurrentGuarantorber.Mobile = MemberMobileTextBox.Text;
                    CurrentGuarantorber.ResidentialAddress = MemberResidentialTextBox.Text;
                    CurrentGuarantorber.Telephone = MemberTelTextBox.Text;
                    CurrentGuarantorber.IdentityTypeID = Convert.ToInt32(DropDownList1.SelectedValue);
                    // CurrentGuarantorber.ContactPerson = MemberContactPersonTextBox.Text;

                    db.Guarantors.InsertOnSubmit(CurrentGuarantorber);
                    db.SubmitChanges();

                    txtResult.Text = CurrentGuarantorber.GuarantorId.ToString();

                    string url = "";
                    if (Request.QueryString["lid"] != null)
                    {
                        url = "&lid=" + Request.QueryString["lid"];
                    }
                    Response.Redirect(Request.QueryString["redirectUrl"] + "&mid=" + Request.QueryString["mid"] + url + "&gtId=" + CurrentGuarantorber.GuarantorId);
                    //ClientScript.RegisterStartupScript(typeof(Page), "SymbolError","GetRowValue(" + CurrentGuarantorber.GuarantorId + ");", true);
                }
            //}

            //}
            //if (Request.QueryString["RedirectUrl"] == null)
            //{
            //    Response.Redirect("Members.aspx");
            //}
            //else
            //{
            //    Response.Redirect(Request.QueryString["RedirectUrl"]+"?mid=" + CurrentMember.MemberId);
            //}
        }
        protected void InsertButton_Click(object sender, EventArgs e)
        {
            //if (DropDownList1.SelectedIndex == 1 && chequeNumberTextBox.Text.Trim().Length == 0)
            //{
            //    lblChequeError.Visible = true;
            //    return;
            //}
            //else
            //{
            //    lblChequeError.Visible = false;
            //}

            using (FinanceManagerDataContext db = new FinanceManagerDataContext())
            {
                //set current receipt number
                Parameter prm = db.Parameters.FirstOrDefault();

                //increase receipt number by one
                prm.ReceiptNumber++;
                Contribution _contribution = new Contribution()
                {
                    InvestmentId = Convert.ToInt32(Request.QueryString["InvId"]),
                    ContributionAmount = Convert.ToDecimal(ContributionAmountTextBox.Text.Trim()),
                    ContributionAmountInWords = Utils.ConvertMoneyToText(ContributionAmountTextBox.Text.Trim()),
                    ContributionBy = ContributionByTextBox.Text,
                    Description = "Investment deposit",
                    ReceiptNumber = prm.ReceiptNumber.Value.ToString().PadLeft(6, '0'),
                    RecievedBy = Session["CurrentUser_session"].ToString(), IsDeleted = false,
                    CreatedDate = DateWebUserControl1.DtSelectedDate,
                    CreatedBy = HttpContext.Current.User.Identity.Name,
                   PaymentMethodId = PaymentMethodWebUserControl1.PaymentTypeID,
                   ChequeNumber = PaymentMethodWebUserControl1.ChequeNumber
                };

                //if (DropDownList1.SelectedIndex == 0)
                //{
                //    _contribution.ChequeNumber = chequeNumberTextBox.Text;
                //}

                db.Contributions.InsertOnSubmit(_contribution);
                db.SubmitChanges();

                //audit
                Utils.logAction("Insert", _contribution);

                Response.Redirect("ContributionReceipt_Group.aspx?cid=" + _contribution.ContributionId.ToString() + "&gid=" + _contribution.Investment.GroupId);
            }
        }
        protected void InsertButton_Click(object sender, EventArgs e)
        {
            Utils.IsAuthorized("Deposit", "Create");

            using (FinanceManagerDataContext db = new FinanceManagerDataContext())
            {
                //set current receipt number
                Parameter prm = db.Parameters.FirstOrDefault();

                //increase receipt number by one
                prm.ReceiptNumber++;
                Contribution _contribution = new Contribution()
                {
                    InvestmentId = Convert.ToInt32(Request.QueryString["InvId"]),
                    ContributionAmount = Convert.ToDecimal(ContributionAmountTextBox.Text.Trim()),
                    ContributionAmountInWords = Utils.ConvertMoneyToText(ContributionAmountTextBox.Text.Trim()),
                    ContributionBy = ContributionByTextBox.Text,
                    Description = "Investment deposit",
                    ReceiptNumber = prm.ReceiptNumber.Value.ToString().PadLeft(6, '0'),
                    RecievedBy = Session["CurrentUser_session"].ToString(),
                    PaymentMethodId = PaymentMethodWebUserControl1.PaymentTypeID,
                    ChequeNumber = PaymentMethodWebUserControl1.ChequeNumber,
                    CreatedDate = DateWebUserControl1.DtSelectedDate,
                    IsDeleted = false,
                    MobileBankerID = Utils.GetMobileBanker(Convert.ToInt32( Request.QueryString["mid"])),
                    CreatedBy = HttpContext.Current.User.Identity.Name
                };

                db.Contributions.InsertOnSubmit(_contribution);
                db.SubmitChanges();

                //audit
                Utils.logAction("Insert", _contribution);

                Response.Redirect("ContributionReceipt.aspx?cid=" + _contribution.ContributionId.ToString() + "&mid=" + _contribution.Investment.MemberID);
            }
        }
Пример #10
0
    public static SearchResultComplexType SearchMember(string searchStrin)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            List<Member> members = (from m in db.Members
                                    where m.AccountNumber.ToLower() == searchStrin.ToLower() ||
                                    m.MemberFirstName.ToLower().Contains(searchStrin) || m.MemberLastName.ToLower().Contains(searchStrin)
                                    select m).ToList<Member>();

            List<vwGroup> groups = (from m in db.vwGroups
                                    where m.GroupName.ToLower() == searchStrin.ToLower() ||
                                    m.Description.ToLower().Contains(searchStrin)
                                    select m).ToList<vwGroup>();

            SearchResultComplexType _mySearchResultComplexType = new SearchResultComplexType() { GroupsFound = groups, MembersFound = members, NumberOFGroupsFound = groups.Count, NumberOfMembers = members.Count };
            return _mySearchResultComplexType;
        }
    }
Пример #11
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;
                    }
                }
            }
        }
    }
Пример #12
0
    public static void MarkMaturedInvestmentsAsSo()
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            foreach (Investment invItem in db.Investments)
            {
                try
                {
                    if (invItem.MaturityDate.Value.Date >= DateTime.Today.Date)
                    {
                        invItem.IsMatured = true;
                    }
                }
                catch (Exception)
                {

                }
            }
            db.SubmitChanges();
        }
    }
Пример #13
0
 public static string RepaymentFreqName(int freqID)
 {
     using (FinanceManagerDataContext db = new FinanceManagerDataContext())
     {
         return db.RepaymentFrequencies.FirstOrDefault(r => r.RepaymentFrequencyId == freqID).Description;
     }
 }
Пример #14
0
 public static string IdentityType(object idType)
 {
     try
     {
         using (FinanceManagerDataContext db = new FinanceManagerDataContext())
         {
             return db.IdentificationTypes.FirstOrDefault(r => r.IdentificationTypeId == Convert.ToInt32(idType)).Description;
         }
     }
     catch (Exception)
     {
         return String.Empty;
     }
 }
Пример #15
0
    public static void logAction(string Action, object objInQuestion)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            try
            {
                AuditTrail _newAudit = new AuditTrail()
                   {
                       Action = Action,
                       AffectedTable = (objInQuestion.GetType()).Name,
                       CreatedBy = HttpContext.Current.User.Identity.Name,
                       CreatedDate = DateTime.Now,
                       ActionDescription = getPropertiesOfObject(objInQuestion),
                       AuditTrailId = Guid.NewGuid()
                   };
                db.AuditTrails.InsertOnSubmit(_newAudit);
                db.SubmitChanges();
            }
            catch (Exception)
            {

            }
        }
    }
Пример #16
0
 //get members that are a month old from a given date having a given account Type
 public static List<Member> GetMembersAMonthOld(int accountTypeID, DateTime date)
 {
     List<Member> members = new List<Member>();
     using (FinanceManagerDataContext db = new FinanceManagerDataContext())
     {
         return db.Members.Where(a => a.AccountTypeID == accountTypeID && (date - a.CreatedDate.Value.AddMonths(1)).Days >= 30).ToList();
     }
 }
Пример #17
0
    /// <summary>
    /// Creates a member account and automatically creates an investment for the member and returns the member id
    /// </summary>
    /// <param name="group"></param>
    /// <param name="enumIvestmentType"></param>
    /// <returns></returns>
    //public static int createAccountForGroup(LoanGroup group, EnumInvestmentTypes enumIvestmentType, bool AutoGenerateAccountNumber)
    //{
    //    using (FinanceManagerDataContext db = new FinanceManagerDataContext())
    //    {
    //        group.Investments.Add(new Investment() { InvestmentTypeId = (int)enumIvestmentType, IsActive = true, CreatedDate = DateTime.Now });
    //        db.LoanGroups.InsertOnSubmit(group);
    //        db.SubmitChanges();
    //        if (AutoGenerateAccountNumber)
    //        {
    //            group.AccountNumber = Utils.GenerateAccountNumber(group.GroupId);
    //            db.SubmitChanges();
    //        }
    //    }
    //    return group.GroupId;
    //}
    /// <summary>
    /// Creates a member account and automatically creates an investment for the member and returns the member id
    /// </summary>
    /// <param name="group"></param>
    /// <param name="enumIvestmentType"></param>
    /// <returns></returns>
    public static int createAccountForGroup(LoanGroup group, AccountType  accountType, bool AutoGenerateAccountNumber)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            group.Investments.Add(new Investment() { InvestmentTypeId = accountType.DefaultInvestmentTypeID,
                IsActive = true, CreatedDate = DateTime.Now, IsDeleted = false , AccountTypeId = accountType.AccountTypeId});
            group.CreatedDate = DateTime.Now;
            db.LoanGroups.InsertOnSubmit(group);
            db.SubmitChanges();

            if (AutoGenerateAccountNumber)
            {
                group.AccountNumber = Utils.GenerateAccountNumber(group.AccountTypeId.Value, group.BranchID.Value);
                db.SubmitChanges();
            }
        }
        return group.GroupId;
    }
Пример #18
0
    /// <summary>
    /// Creates a member account and automatically creates an investment for the member and returns the member id
    /// </summary>
    /// <param name="member"></param>
    /// <param name="enumIvestmentType"></param>
    /// <returns></returns>
    public static int createAccount(Member member, EnumInvestmentTypes enumIvestmentType, bool AutoGenerateAccountNumber)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            member.Investments.Add(new Investment() { InvestmentTypeId = (int)enumIvestmentType, IsActive = true, CreatedDate = DateTime.Now, CreatedBy = HttpContext.Current.User.Identity.Name, InvestmentAmount = 0 });
            member.CreatedDate = DateTime.Now;
            db.Members.InsertOnSubmit(member);
            db.SubmitChanges();

            if (AutoGenerateAccountNumber)
            {
                member.AccountNumber = Utils.GenerateAccountNumber(member.MemberId);
                db.SubmitChanges();
            }
        }
        return member.MemberId;
    }
Пример #19
0
    public static void CalculateDefaultersInterest()
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            TimeSpan tspan;
            CompanyProfile cProfile = db.CompanyProfiles.FirstOrDefault();
            //try
            //{
            //    tspan = DateTime.Today.Date - cProfile.EndOfDayLastRunDate.Value.Date;

            //    if (tspan.Days > 0)
            //    {
            //        for (int i = 1; i <= tspan.Days; i++)
            //        {
            //calculate loan penalty for each loan
            calculatePenaltyForEachLoan(db, cProfile);
            //        }
            //    }
            //}
            //catch (Exception)
            //{
            //    //caculate penalty for each Loan
            //    calculatePenaltyForEachLoan(db, cProfile, null);
            //}

            //update last run date
            cProfile.EndOfDayLastRunDate = DateTime.Now;
            db.SubmitChanges();
        }
    }
 void DeleteMemberFromGroupInDatabase(int memberID, int mobileBankerID)
 {
     System.Threading.Tasks.Task.Factory.StartNew(() =>
     {
         using (FinanceManagerDataContext db = new FinanceManagerDataContext())
         {
             MobileBankerCustomer _customer = db.MobileBankerCustomers.FirstOrDefault(m => m.MemberId == memberID && m.MobileBankerID == mobileBankerID);
             db.MobileBankerCustomers.DeleteOnSubmit(_customer);
             db.SubmitChanges();
         }
     });
 }
Пример #21
0
    public static void GenerateContributionSchedule(int months, RepaymentFrequency repaymentFrequency, Investment currentLoan)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {

            decimal repaymentIntervals = (decimal)(currentLoan.MaturityDate.Value.Date - currentLoan.InvestmentCalculationStartDate.Value).Days / (repaymentFrequency.ConversionUnit.Value * (decimal)months);
            DateTime tempScheduleDate = currentLoan.InvestmentCalculationStartDate.Value;
            DateTime tempDate = currentLoan.InvestmentCalculationStartDate.Value;
            CompanyProfile cProfile = db.CompanyProfiles.FirstOrDefault();
            decimal balance = 0;
            for (decimal i = 0; i < Math.Round((currentLoan.MaturityDate.Value - currentLoan.InvestmentCalculationStartDate.Value).Days / repaymentIntervals, MidpointRounding.AwayFromZero); i++)
            {
                tempScheduleDate = tempDate = tempDate.AddDays((int)repaymentIntervals);
                if (tempScheduleDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    tempScheduleDate = tempScheduleDate.AddDays(1);
                }
                else if (tempScheduleDate.DayOfWeek == DayOfWeek.Saturday)
                {
                    tempScheduleDate = tempScheduleDate.AddDays(2);
                }

                //decimal totalAmountContributed = db.Contributions.Where<Contribution>(cont => cont.InvestmentId == currentLoan.InvestmentID).Sum<Contribution>(c => c.ContributionAmount).Value;

                //update balance
                balance += currentLoan.ContributionFreqAmount.Value;

                var _contributionSchedule = new ContributionSchedule()
                {
                    IsContributionMade = false,
                    ExpectedContributionAmount = currentLoan.ContributionFreqAmount,
                    InvestmentId = currentLoan.InvestmentID,
                    ContributionDate = tempScheduleDate,
                    Balance = balance
                };

                db.SubmitChanges();
                db.ContributionSchedules.InsertOnSubmit(_contributionSchedule);

                //audit
                Utils.logAction("Insert", _contributionSchedule);
            }

            //DateTime.Now.Month

        }
    }
Пример #22
0
    public static string GenerateAccountNumber(int AccountTypeId, int branchId)
    {
        Branch _branch;
        AccountType _accType;
        StringBuilder strbuilder;
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            _branch = db.Branches.FirstOrDefault(b => b.BranchID == branchId);
            _accType = db.AccountTypes.FirstOrDefault(b => b.AccountTypeId == AccountTypeId);

            strbuilder = new StringBuilder();
            strbuilder.Append(DateTime.Now.Year);
            strbuilder.Append(DateTime.Now.Month);
            strbuilder.Append(DateTime.Now.Day);
            strbuilder.Append(_branch.BranchCode);
            strbuilder.Append(_accType.AccountTypeId);

            if (_accType.LastMemberID.HasValue == false)
            {
                _accType.LastMemberID = 1;
            }
            else
            {
                _accType.LastMemberID = _accType.LastMemberID + 1;
            }
            strbuilder.Append((_accType.LastMemberID).ToString().PadLeft(5, '0'));
            db.SubmitChanges();

        }

        return strbuilder.ToString();
    }
Пример #23
0
    static void calculatePenaltyForEachLoan(FinanceManagerDataContext dataContext, CompanyProfile cProfile)
    {
        //set grace period to zero if null
        if (cProfile.GracePeriodDays == null)
            cProfile.GracePeriodDays = 0;

        //select loans that have not been paid up and thier expected repayment dates are due. Given a grace period

        DateTime TodayPlusGracePeriod = DateTime.Today.Date.AddDays(cProfile.GracePeriodDays.Value);

        foreach (Loan Loanitem in dataContext.Loans.Where(l => l.IsPaidup.Value == false && TodayPlusGracePeriod >= l.ExpectedRepaymentEndDate.Value.Date)) //iterate through unpaid loans
        {

            LoanPenalty _loanPenalty = null;
            //get most recent penalty for current loan (Last penalty calculates)
            try
            {
                _loanPenalty = dataContext.LoanPenalties.Where<LoanPenalty>(l => l.LoanID == Loanitem.LoanID).OrderBy(lp => lp.CreatedDate).LastOrDefault();
            }
            catch (Exception)
            {

            }

            //get the frequency of calculation of penalty eg. every 30days
            int? _PenaltyCalculationFrequencyDays = cProfile.PenaltyCalculationFrequencyDays.Value;
            if (_PenaltyCalculationFrequencyDays == null)
                _PenaltyCalculationFrequencyDays = 0;

            if (_loanPenalty != null)
            {
                int numberOfTimesToRunPenalty = (DateTime.Today.Date - _loanPenalty.CreatedDate.Value.Date).Days / _PenaltyCalculationFrequencyDays.Value;
                if (numberOfTimesToRunPenalty > 0)
                    for (int i = 0; i < numberOfTimesToRunPenalty; i++)
                    {
                        decimal totalPenalty2;
                        try
                        {
                            totalPenalty2 = Loanitem.LoanPenalties.Sum(p => p.PenaltyAmount).Value;
                        }
                        catch (Exception)
                        {
                            totalPenalty2 = 0;
                        }

                        decimal balance2 = Loanitem.Amount.Value + totalPenalty2 - Loanitem.Repayments.Sum(r => r.RepaymentAmount).Value;
                        decimal penaltyInsterst2 = (cProfile.DefaultersInteresty.Value / 100) * balance2;

                        LoanPenalty _newLoanPenalty = new LoanPenalty();
                        _newLoanPenalty.CreatedDate = DateTime.Now;
                        _newLoanPenalty.LoanID = Loanitem.LoanID;
                        _newLoanPenalty.PenaltyAmount = penaltyInsterst2;
                        _newLoanPenalty.IsReleived = false;
                        _newLoanPenalty.PenaltyRate = cProfile.DefaultersInteresty.Value;
                        dataContext.LoanPenalties.InsertOnSubmit(_newLoanPenalty);

                        //audit
                        Utils.logAction("Insert", _newLoanPenalty);
                    }
            }
            else
            {
                //get the number of days between the lastRundate and today.
                int numberOfTimesToRunPenalty = (DateTime.Today.Date - cProfile.EndOfDayLastRunDate.Value).Days / _PenaltyCalculationFrequencyDays.Value;
                if (numberOfTimesToRunPenalty > 0)
                    for (int i = 0; i < numberOfTimesToRunPenalty; i++)
                    {
                        decimal totalPenalty2 = 0;

                        decimal balance2 = Loanitem.Amount.Value + totalPenalty2 - Loanitem.Repayments.Sum(r => r.RepaymentAmount).Value;
                        decimal penaltyInsterst2 = (cProfile.DefaultersInteresty.Value / 100) * balance2;

                        LoanPenalty _newLoanPenalty = new LoanPenalty();
                        _newLoanPenalty.CreatedDate = DateTime.Now;
                        _newLoanPenalty.LoanID = Loanitem.LoanID;
                        _newLoanPenalty.PenaltyAmount = penaltyInsterst2;
                        _newLoanPenalty.IsReleived = false;
                        _newLoanPenalty.PenaltyRate = cProfile.DefaultersInteresty.Value;
                        dataContext.LoanPenalties.InsertOnSubmit(_newLoanPenalty);

                        try
                        {
                            //test if this bit of the code works
                            totalPenalty2 = Loanitem.LoanPenalties.Sum(p => p.PenaltyAmount).Value;
                        }
                        catch (Exception)
                        {
                            totalPenalty2 = 0;
                        }
                        //audit
                        Utils.logAction("Insert", _newLoanPenalty);
                    }
            }
        }
    }
Пример #24
0
 public static int? GetMobileBanker(int memberId)
 {
     try
     {
         using (FinanceManagerDataContext db = new FinanceManagerDataContext())
         {
             return db.MobileBankerCustomers.FirstOrDefault(m => m.MemberId == memberId).MobileBanker.MobileBankerid;
         }
     }
     catch (Exception)
     {
         return null;
     }
 }
Пример #25
0
    public static void GenerateRepaymentSchedule(int months, RepaymentFrequency repaymentFrequency, Loan currentLoan)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            List<string> repaymentDays = new List<string>();
            DateTime tempDatertime = DateTime.Today;
            DateTime tempResultantDate = DateTime.Today;
            bool isSunday = false;
            CompanyProfile cProfile = db.CompanyProfiles.FirstOrDefault();
            for (int i = 0; i < months; i++)
            {
                for (int j = 0; j < repaymentFrequency.NumberOfDays; j++)
                {
                    if (tempDatertime.AddDays(1).DayOfWeek == DayOfWeek.Saturday)
                    {
                        if (cProfile.ExcludeSaturdayFromCalculations.Value)
                        {
                            tempResultantDate = tempDatertime.AddDays(3);
                            // tempDatertime = tempDatertime.AddDays(1);
                            //tempResultantDate.AddDays(3);
                            // isSunday = false;
                        }
                    }
                    else if (tempDatertime.AddDays(1).DayOfWeek == DayOfWeek.Sunday)
                    {
                        if (cProfile.ExcludeSundaysFromCalculations.Value)
                        {
                            tempResultantDate = tempDatertime.AddDays(2); //if day lands on sunday, move day to monday

                            // tempResultantDate.AddDays(2);
                            //  isSunday = true;
                        }
                    }
                    else
                    {
                        tempResultantDate = tempDatertime.AddDays(1);
                    }
                    tempDatertime = tempDatertime.AddDays(1);

                    //if (isSunday)
                    //{
                    //    tempDatertime = tempDatertime.AddDays(-1); //come back to sunday
                    //}
                    //else {
                    //    tempDatertime = tempDatertime.AddDays(-2); //come back to sutarday
                    //}

                }
                var _repaymentSchedule = new RepaymentSchedule() { LoanId = currentLoan.LoanID, ExpectedRepaymentAmount = currentLoan.RepaymentFreqAmount, RepaymentDate = tempResultantDate };
                db.RepaymentSchedules.InsertOnSubmit(_repaymentSchedule);

                //audit
                Utils.logAction("Insert", _repaymentSchedule);
                db.SubmitChanges();
            }

        }
    }
Пример #26
0
    /// <summary>
    /// Creates a member account and automatically creates an investment for the member and returns the member id
    /// </summary>
    /// <param name="member"></param>
    /// <param name="enumIvestmentType"></param>
    /// <returns></returns>
    public static int createAccount(Member member, AccountType accountType, bool AutoGenerateAccountNumber)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            member.Investments.Add(new Investment()
            {
                IsDeleted = false,
                InvestmentTypeId = accountType.DefaultInvestmentTypeID,
                IsActive = true,
                CreatedDate = DateTime.Now,
                CreatedBy = HttpContext.Current.User.Identity.Name,
                InvestmentAmount = 0,
                AccountTypeId = accountType.AccountTypeId
            });
            member.CreatedDate = DateTime.Now;
            db.Members.InsertOnSubmit(member);
            db.SubmitChanges();

            if (AutoGenerateAccountNumber)
            {
                //member.AccountNumber = Utils.GenerateAccountNumber(member.MemberId);
                member.AccountNumber = Utils.GenerateAccountNumber(member.AccountTypeID.Value, member.BranchID.Value);
                db.SubmitChanges();
            }
        }
        return member.MemberId;
    }
Пример #27
0
    public static void GenerateRepaymentSchedule_new(int months, RepaymentFrequency repaymentFrequency, Loan currentLoan)
    {
        using (FinanceManagerDataContext db = new FinanceManagerDataContext())
        {
            decimal tempLoanAmount = currentLoan.Amount.Value;
            decimal repaymentIntervals = (decimal)(currentLoan.ExpectedRepaymentEndDate.Value.Date - currentLoan.LoanCalculationStartDate.Value).Days / (repaymentFrequency.ConversionUnit.Value * (decimal)months);
            DateTime tempScheduleDate = currentLoan.LoanCalculationStartDate.Value;
            DateTime tempDate = currentLoan.LoanCalculationStartDate.Value;
            CompanyProfile cProfile = db.CompanyProfiles.FirstOrDefault();

            decimal numberOfPayments = Math.Round((currentLoan.ExpectedRepaymentEndDate.Value - currentLoan.LoanCalculationStartDate.Value).Days / repaymentIntervals, MidpointRounding.AwayFromZero);

            for (decimal i = 0; i < numberOfPayments; i++)
            {
                tempScheduleDate = tempDate = tempDate.AddDays((int)repaymentIntervals);
                if (tempScheduleDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    tempScheduleDate = tempScheduleDate.AddDays(1);
                }
                else if (tempScheduleDate.DayOfWeek == DayOfWeek.Saturday)
                {
                    tempScheduleDate = tempScheduleDate.AddDays(2);
                }

                //get the loan amount
                tempLoanAmount -= currentLoan.RepaymentFreqAmount.Value;

                decimal _repaymentAmount = currentLoan.RepaymentFreqAmount.Value;
                // decimal _interestRepayment = (currentLoan.Interest.Value / 100) * _repaymentAmount;
                decimal _interestRepayment = (currentLoan.Amount.Value - currentLoan.Principal.Value) / numberOfPayments;

                //create new loan schedule
                var _repaymentSchedule = new RepaymentSchedule()
                {
                    Balance = tempLoanAmount,
                    IsPaymentMade = false,
                    ExpectedRepaymentAmount = currentLoan.RepaymentFreqAmount,
                    LoanId = currentLoan.LoanID,
                    RepaymentDate = tempScheduleDate,
                    InterestPayment = _interestRepayment,
                    PrincipalPayment = _repaymentAmount - _interestRepayment
                };
                db.RepaymentSchedules.InsertOnSubmit(_repaymentSchedule);
                db.SubmitChanges();

                //audit
                Utils.logAction("Insert", _repaymentSchedule);
            }

            //DateTime.Now.Month

        }
    }
Пример #28
0
 public static FinanceManagerDataContext GetDataContext()
 {
     context = new FinanceManagerDataContext();
     return context;
 }
Пример #29
0
 protected void Page_Load(object sender, EventArgs e)
 {
     FinanceManagerDataContext db = new FinanceManagerDataContext();
     //db.CreateDatabase();
     Response.Redirect("~/admin/Default.aspx");
 }
        void CreateMember()
        {
            using (FinanceManagerDataContext db = new FinanceManagerDataContext())
            {
                if (Request.QueryString["mid"] != null) //editing
                {
                    Utils.IsAuthorized("Members", "Edit");

                    CurrentMember = db.Members.First<Member>(m => m.MemberId == Convert.ToInt32(Request.QueryString["mid"]));
                    CurrentMember.BranchID = Convert.ToInt32( cboBranches.SelectedValue);
                    CurrentMember.MemberFirstName = MemberFirstNameTextBox.Text;
                    CurrentMember.MemberLastName = MemberLastNameTextBox.Text;
                    //CurrentMember.MemberBranch = MemberBranchTextBox.Text;
                    //CurrentMember.Balance.Value.ToString() = BalanceTextBox.Text;
                    if (FileUpload1.HasFile)
                        CurrentMember.MemberPhoto = FileUpload1.FileBytes;
                    if (FileUpload2.HasFile)
                        CurrentMember.Signature = FileUpload2.FileBytes;
                    if (FileUpload3.HasFile)
                        CurrentMember.IDPhoto = FileUpload3.FileBytes;

                    CurrentMember.AccountNumber = AccountTextBox.Text;

                    CurrentMember.AccountNumber = AccountTextBox.Text;
                    CurrentMember.OtherName = MemberOtherNameTextBox.Text;
                    CurrentMember.DOB = Convert.ToDateTime(MemberDOBNameTextBox.Text);
                    CurrentMember.Fax = MemberFaxTextBox0.Text;
                    CurrentMember.IdentityNumber = MemberIDNumberTextBox.Text;
                    CurrentMember.Mobile = MemberMobileTextBox.Text;
                    CurrentMember.ResidentialAddress = MemberResidentialTextBox.Text;
                    CurrentMember.Telephone = MemberTelTextBox.Text;
                    CurrentMember.IdentityTypeID = Convert.ToInt32(DropDownList1.SelectedValue);
                    CurrentMember.ContactPerson = MemberContactPersonTextBox.Text;
                    CurrentMember.BusinessAddress = MemberBusinessLocationTextBox.Text;
                    CurrentMember.AccountTypeID = Convert.ToInt32(cboAccountType.SelectedValue);
                    CurrentMember.ContactPersonPhone = MemberContactNumberTextBox.Text;

                    CurrentMember.NextOfKin = txtNextOfKin.Text;
                    CurrentMember.NextOfKinTelephone = txtNextOfKinTelephone.Text;
                    CurrentMember.Gender = cboGender.SelectedValue;
                    //audit
                    Utils.logAction("Edit", CurrentMember);

                    //CurrentMember.AccountTypeId = Convert.ToInt32( cboAccountType.SelectedValue);
                    db.SubmitChanges();
                }
                else //inserting
                {
                    Utils.IsAuthorized("Members", "Create");
                    CurrentMember = new Member() { Balance = 0M };

                    CurrentMember.BranchID = Convert.ToInt32(cboBranches.SelectedValue);
                    CurrentMember.MemberFirstName = MemberFirstNameTextBox.Text;
                    CurrentMember.MemberLastName = MemberLastNameTextBox.Text;
                    //CurrentMember.MemberBranch = MemberBranchTextBox.Text;
                    if (FileUpload1.HasFile)
                        CurrentMember.MemberPhoto = FileUpload1.FileBytes;
                    if (FileUpload2.HasFile)
                        CurrentMember.Signature = FileUpload2.FileBytes;
                    if (FileUpload3.HasFile)
                        CurrentMember.IDPhoto = FileUpload3.FileBytes;
                    // BalanceTextBox.Text = "00.00";
                    CurrentMember.AccountNumber = AccountTextBox.Text;

                    CurrentMember.AccountNumber = AccountTextBox.Text;
                    CurrentMember.OtherName = MemberOtherNameTextBox.Text;
                    CurrentMember.DOB = Convert.ToDateTime(MemberDOBNameTextBox.Text);
                    CurrentMember.Fax = MemberFaxTextBox0.Text;
                    CurrentMember.IdentityNumber = MemberIDNumberTextBox.Text;
                    CurrentMember.Mobile = MemberMobileTextBox.Text;
                    CurrentMember.ResidentialAddress = MemberResidentialTextBox.Text;
                    CurrentMember.Telephone = MemberTelTextBox.Text;
                    CurrentMember.IdentityTypeID = Convert.ToInt32(DropDownList1.SelectedValue);
                    CurrentMember.ContactPerson = MemberContactPersonTextBox.Text;
                    CurrentMember.BusinessAddress = MemberBusinessLocationTextBox.Text;
                    //CurrentMember.AccountTypeId = Convert.ToInt32(cboAccountType.SelectedValue);
                    CurrentMember.ContactPersonPhone = MemberContactNumberTextBox.Text;
                    CurrentMember.AccountTypeID = Convert.ToInt32(cboAccountType.SelectedValue);
                    CurrentMember.Gender = cboGender.SelectedValue;

                    CurrentMember.NextOfKin = txtNextOfKin.Text;
                    CurrentMember.NextOfKinTelephone = txtNextOfKinTelephone.Text;
                    CurrentMember.IsDeleted = false;

                    //GET account type
                    AccountType accType = db.AccountTypes.FirstOrDefault(a => a.AccountTypeId == CurrentMember.AccountTypeID);

                    Utils.createAccount(CurrentMember, accType, CheckBox1.Checked);

                    //audit
                    Utils.logAction("Insert", CurrentMember);

                    //if (CheckBox1.Checked)
                    //{

                    //    CurrentMember.AccountNumber = Utils.GenerateAccountNumber(CurrentMember.MemberId);
                    //    db.SubmitChanges();
                    //}
                }
            }
        }