public ActionResult GetNewBill(Guid memberId, Guid medallionId) { var today = DateTime.Now; var member = memberService.Get(memberId); var medallion = medallionService.Get(medallionId); //initial Object to view to New Bill BillMedallionViewModel medalBill = new BillMedallionViewModel(); medalBill.Bill = new Bill(); medalBill.Medallion = new Medallion(); medalBill.Bill.TotalPaid = 0; medalBill.Bill.MedallionId = medallion.Id; //set value for Member medalBill.Member = new Member() { Id = member.Id, AccountNumber = member.AccountNumber, Name = member.Name }; //set value for Medallion medalBill.Medallion = new Medallion() { Id = medallion.Id, MedallionNumber = medallion.MedallionNumber }; //get all loan of a member and medallion specificate var loanlist = loanService.GetLoanListByMemberAndMedallion(memberId, medallionId); var insuranceDeposit = insuranceDepositService.GetByMedallionAndMemberId(memberId, medallionId); var ccsys = ccsystemAirtimeService.GetByMedallionAndMemberId(memberId, medallionId); var accReceivable = accountReceivableService.GetByMedallionAndMemberId(memberId, medallionId); var saveDeposit = savingDepositService.GetByMedallionAndMemberId(memberId, medallionId); //get all balance of loans medalBill.Bill.Balance = (insuranceDeposit != null ? insuranceDeposit.CurrentBalance : 0) + (ccsys != null ? ccsys.Airtime : 0) + (accReceivable != null ? accReceivable.CurrentBalance : 0); decimal calculateMonthlypay = 0; //get balance from loan if (loanlist != null && loanlist.Count > 0) { foreach (Loan l in loanlist) { medalBill.Bill.Balance += l.CurrentBalance; calculateMonthlypay += l.CalculatedMonthlyPayment; } } //pull data of loans to pay medalBill.Bill.AccountReceivableAmount = accReceivable != null ? accReceivable.MonthlyPayment : 0; medalBill.Bill.AssociationDueAmount = 0; medalBill.Bill.Loan = calculateMonthlypay; medalBill.Bill.CCSystemAirtimeAmount = ccsys != null ? ccsys.Airtime : 0; medalBill.Bill.InsuranceDepositAmount = insuranceDeposit != null ? insuranceDeposit.WeeklyPayment * 4 : 0; //generate receiptNumber string recieptNumber = String.Format("{0:yyhhmmss}", DateTime.Now); medalBill.Bill.RecieptNumber = int.Parse(recieptNumber); //get all bill what are paid var Listbill = billService.GetBillByMemberAndMedallionId(memberId, medallionId); // order by NextPayment to get last bill Listbill = Listbill.OrderBy(c => c.NextPayment).ToList(); //First time to payment if (Listbill != null && Listbill.Count == 0) { if (medallion != null) { medalBill.Bill.StartDate = medallion.BillingStartDate; var nextPayment = today.AddMonths(1); if (nextPayment > medallion.BillingEndDate) { nextPayment = medallion.BillingEndDate; medalBill.Bill.EndDate = nextPayment; medalBill.Bill.NextPayment = nextPayment; } else { medalBill.Bill.EndDate = nextPayment; medalBill.Bill.NextPayment = nextPayment.AddDays(1); } medalBill.Bill.MemberId = memberId; } } //second Bill else { //get last bill from listbill var bill = Listbill.FirstOrDefault(); if (bill != null) { medalBill.Bill.StartDate = bill.NextPayment; var nextPayment = bill.NextPayment.AddMonths(1); //check if (nextPayment > medallion.BillingEndDate) { medalBill.Bill.EndDate = medallion.BillingEndDate; medalBill.Bill.NextPayment = medallion.BillingEndDate; } else { medalBill.Bill.EndDate = nextPayment; medalBill.Bill.NextPayment = nextPayment.AddMonths(1); } medalBill.Bill.MemberId = memberId; } } //calculate late fee var companySetting = companyService.Get().FirstOrDefault(); if (companySetting != null) { int allowLateDate = companySetting.DefaultLateBreak > 0 ? (int)companySetting.DefaultLateBreak : 0; var totalDateLate = today.Subtract(medalBill.Bill.EndDate).Days; if (totalDateLate > allowLateDate) { medalBill.Bill.StatysPastDue = "Past Due"; //calculate late fee decimal feeLateOneDay = (companySetting.DefaultLateCharge / 7); decimal totalFeeLate = Math.Round(feeLateOneDay * totalDateLate, 2, MidpointRounding.AwayFromZero); medalBill.Bill.LateFees = totalFeeLate; } else if (totalDateLate < allowLateDate && totalDateLate > 1) { medalBill.Bill.StatysPastDue = "Due"; } else { medalBill.Bill.StatysPastDue = "Current"; } } return Json(medalBill, JsonRequestBehavior.AllowGet); }
/// <summary> /// get Bill to edit /// </summary> /// <param name="billId"></param> /// <returns></returns> public ActionResult GetEditBill(Guid billId) { //get bill by Id Bill bill = billService.Get(billId); if (bill == null) return Json(bill, JsonRequestBehavior.AllowGet); var memberId = bill.MemberId; var medallionId = bill.MedallionId; //get member and medallion var member = memberService.Get(memberId); var medallion = medallionService.Get(medallionId); BillMedallionViewModel medalBill = new BillMedallionViewModel(); medalBill.Bill = bill; medalBill.Medallion = new Medallion(); medalBill.Bill.TotalPaid = 0; medalBill.Bill.MedallionId = medallion.Id; medalBill.Member = new Member() { Id = member.Id, AccountNumber = member.AccountNumber, Name = member.Name }; medalBill.Medallion = new Medallion() { Id = medallion.Id, MedallionNumber = medallion.MedallionNumber }; return Json(medalBill, JsonRequestBehavior.AllowGet); }