public ActionResult SaveEditBill(Bill bill, Guid transactionId)
        {
            try
            {
                if (bill != null && transactionId != Guid.Empty)
                {
                    var memberId = bill.MemberId;
                    var medallionId = bill.MedallionId;
                    var medallion = medallionService.Get(medallionId);
                    //get old Bill and old Transaction to compare
                    var oldBill = billService.Get(bill.Id);
                    var oldTransaction = transactionHistoryService.Get(transactionId);
                    if (oldBill != null && oldTransaction != null)
                    {
                        //get current loan
                        var loan = loanService.GetLoanListByMemberAndMedallion(memberId, medallionId).FirstOrDefault();
                        var insuranceDeposit = insuranceDepositService.GetByMedallionAndMemberId(memberId, medallionId);
                        var ccsys = ccsystemAirtimeService.GetByMedallionAndMemberId(memberId, medallionId);
                        var accReceivable = accountReceivableService.GetByMedallionAndMemberId(memberId, medallionId);
                        var saveDeposit = savingDepositService.GetByMedallionAndMemberId(memberId, medallionId);
                        //decrease balance in medallionLoan
                        if (loan != null && bill.Loan > 0)
                        {
                            loan.TotalPaid += bill.Loan - oldBill.Loan;
                            loan.CurrentBalance -= bill.Loan - oldBill.Loan;
                            CalculateEditPaidLoan(loan, bill, oldBill);
                            loanService.Update(loan);
                        }

                        // balance in insurance deposit
                        if (insuranceDeposit != null && bill.InsuranceDepositAmount > 0)
                        {
                            insuranceDeposit.TotalPaid += bill.InsuranceDepositAmount - oldBill.InsuranceDepositAmount;
                            insuranceDeposit.CurrentBalance -= bill.InsuranceDepositAmount - oldBill.InsuranceDepositAmount;
                            insuranceDepositService.Update(insuranceDeposit);
                        }

                        //decrease balance in accReceivable
                        if (accReceivable != null && bill.AccountReceivableAmount > 0)
                        {
                            accReceivable.TotalPaid += bill.AccountReceivableAmount - oldBill.AccountReceivableAmount;
                            accReceivable.CurrentBalance -= bill.AccountReceivableAmount - oldBill.AccountReceivableAmount;
                            accountReceivableService.Update(accReceivable);
                        }

                        if (!bill.IsZeroOut)
                        {
                            //decrease balance in saveDeposit
                            if (saveDeposit != null && bill.SavingDepositAmount > 0)
                            {
                                saveDeposit.TotalPaid += bill.SavingDepositAmount - oldBill.SavingDepositAmount;
                                savingDepositService.Update(saveDeposit);
                            }
                        }
                        else
                        {
                            //decrease balance in saveDeposit
                            if (saveDeposit != null && bill.SavingDepositAmount > 0)
                            {
                                saveDeposit.TotalPaid += -bill.SavingDepositAmount - oldBill.SavingDepositAmount;
                                savingDepositService.Update(saveDeposit);
                            }
                        }
                        oldBill = null;

                        //update bill
                        var billUpdate = billService.Get(bill.Id);
                        billUpdate.AccountReceivableAmount = bill.AccountReceivableAmount;
                        billUpdate.AssociationDueAmount = bill.AssociationDueAmount;
                        billUpdate.Loan = bill.Loan;
                        billUpdate.Balance = bill.Balance;
                        billUpdate.Cash = bill.Cash;
                        billUpdate.CCSystemAirtimeAmount = bill.CCSystemAirtimeAmount;
                        billUpdate.Check = bill.Check;
                        billUpdate.CollsionInsuranceAmount = bill.CollsionInsuranceAmount;
                        billUpdate.Credit = billUpdate.Credit;
                        billUpdate.CreditCardAmount = bill.CreditCardAmount;
                        billUpdate.CreditCardFee = bill.CreditCardFee;
                        billUpdate.DateReceived = bill.DateReceived;
                        billUpdate.EndDate = billUpdate.EndDate;
                        billUpdate.InsuranceDepositAmount = bill.InsuranceDepositAmount;
                        billUpdate.InsuranceSticker = bill.InsuranceSticker;
                        billUpdate.InsuranceSurchargeAmount = bill.InsuranceSurchargeAmount;
                        billUpdate.Interval = bill.Interval;
                        billUpdate.IsAutoCashiering = bill.IsAutoCashiering;
                        billUpdate.IsZeroOut = bill.IsZeroOut;
                        billUpdate.MiscCharge = billUpdate.MiscCharge;
                        billUpdate.NextPayment = bill.NextPayment;
                        billUpdate.RecieptNumber = bill.RecieptNumber;
                        billUpdate.SavingDepositAmount = bill.SavingDepositAmount;
                        billUpdate.StartDate = bill.StartDate;
                        billUpdate.StatysPastDue = bill.StatysPastDue;
                        billUpdate.Subtotal = bill.Subtotal;
                        billUpdate.TotalDueAmount = bill.TotalDueAmount;
                        billUpdate.TotalPaid = bill.TotalPaid;
                        billUpdate.TotalPaidAmount = bill.TotalPaidAmount;
                        billUpdate.TransactionType = bill.TransactionType;
                        billUpdate.WerkReceivableAmount = bill.WerkReceivableAmount;
                        billUpdate.WorkerCompensationAmount = bill.WorkerCompensationAmount;

                        billService.Update(billUpdate);
                        //update transaction
                        oldTransaction.BillId = bill.Id;
                        oldTransaction.IsZeroOut = bill.IsZeroOut;
                        oldTransaction.DateReceived = bill.DateReceived;
                        oldTransaction.TransactionType = bill.TransactionType;
                        oldTransaction.AccountReceivableAmount = bill.AccountReceivableAmount;
                        oldTransaction.AssociationDueAmount = bill.AssociationDueAmount;
                        oldTransaction.Loan = bill.Loan;
                        oldTransaction.Balance = bill.Balance;
                        oldTransaction.Cash = bill.Cash;
                        oldTransaction.CCSystemAirtimeAmount = bill.CCSystemAirtimeAmount;
                        oldTransaction.Check = bill.Check;
                        oldTransaction.CollsionInsuranceAmount = bill.CollsionInsuranceAmount;
                        oldTransaction.Credit = bill.Credit;
                        oldTransaction.CreditCardAmount = bill.CreditCardAmount;
                        oldTransaction.CreditCardFee = bill.CreditCardFee;
                        oldTransaction.DueDate = bill.EndDate;

                        oldTransaction.InsuranceDepositAmount = bill.InsuranceDepositAmount;
                        oldTransaction.InsuranceSticker = bill.InsuranceSticker;
                        oldTransaction.InsuranceSurchargeAmount = bill.InsuranceSurchargeAmount;
                        oldTransaction.Interval = bill.Interval;
                        oldTransaction.IsAutoCashiering = bill.IsAutoCashiering;
                        oldTransaction.IsDeleted = false;
                        oldTransaction.LateFees = bill.LateFees;
                        oldTransaction.MedallionId = bill.MedallionId;

                        oldTransaction.MedallionNumber = medallion.MedallionNumber;
                        oldTransaction.MemberId = bill.MemberId;
                        oldTransaction.MiscCharge = bill.MiscCharge;
                        oldTransaction.NextPayment = bill.NextPayment;
                        oldTransaction.RecieptNumber = bill.RecieptNumber;
                        oldTransaction.SavingDepositAmount = bill.SavingDepositAmount;
                        oldTransaction.Subtotal = bill.Subtotal;
                        oldTransaction.TotalDueAmount = bill.TotalDueAmount;
                        oldTransaction.TotalPaidAmount = bill.TotalPaidAmount;

                        oldTransaction.UserName = bill.UserName;
                        oldTransaction.WerkReceivableAmount = bill.WerkReceivableAmount;
                        oldTransaction.WorkerCompensationAmount = bill.WorkerCompensationAmount;
                        oldTransaction.TransactionDate = bill.StartDate;
                        oldTransaction.TotalPaid = bill.TotalPaid;

                        //update transaction
                        transactionHistoryService.Update(oldTransaction);

                        return Json(true);
                    }
                }
            }
            catch
            { return Json(false); }
            return Json(false);
        }
        public ActionResult MakeCurrent(Bill bill)
        {
            if (bill != null)
            {
                DateTime nextToPay = bill.NextPayment;
                DateTime currentDate = DateTime.Now;
                int lateMonth = (int)Math.Round(currentDate.Subtract(nextToPay).TotalDays / 30);

                if (lateMonth > 0)
                {
                    var memberId = bill.MemberId;
                    var medallionId = bill.MedallionId;
                    var loan = loanService.GetLoanListByMemberAndMedallion(memberId, medallionId).FirstOrDefault();
                    var insuranceDeposit = insuranceDepositService.GetByMedallionAndMemberId(memberId, medallionId);
                    var ccsys = ccsystemAirtimeService.GetByMedallionAndMemberId(memberId, medallionId);
                    var accReceivable = accountReceivableService.GetByMedallionAndMemberId(memberId, medallionId);
                    var saveDeposit = savingDepositService.GetByMedallionAndMemberId(memberId, medallionId);
                    bill.StartDate = nextToPay;
                    bill.EndDate = nextToPay.AddMonths(lateMonth);
                    bill.NextPayment = bill.EndDate.AddDays(1);
                    bill.Loan = loan != null ? loan.CalculatedMonthlyPayment * lateMonth : 0;
                    bill.InsuranceDepositAmount = insuranceDeposit != null ? insuranceDeposit.WeeklyPayment * lateMonth : 0;
                    bill.CCSystemAirtimeAmount = ccsys != null ? ccsys.Airtime * lateMonth : 0;
                    bill.AccountReceivableAmount = accReceivable != null ? accReceivable.AccountReceivableAmount * lateMonth : 0;
                }
            }
            return Json(bill, JsonRequestBehavior.AllowGet);
        }
        public void CalculateEditPaidLoan(Loan loan, Bill newBill, Bill oldBill)
        {
            decimal loanamount = loan.LoanAmount;
            decimal totalamount = loanamount + (loan.InterestRate * loan.LoanTerm);
            decimal amountInterest = loanamount * (loan.InterestRate / 12 / 100);
            decimal amountmonthlypay = totalamount / loan.LoanTerm;

            loan.TotalPrincipalPaid += Math.Round((newBill.Loan - amountInterest) - (oldBill.Loan - amountInterest), 2);
        }
        public ActionResult ZeroOut(Bill bill)
        {
            if (bill != null)
            {
                var saveDeposit = savingDepositService.GetByMedallionAndMemberId(bill.MemberId, bill.MedallionId);
                if (saveDeposit != null)
                {
                    return Json(saveDeposit.TotalPaid, JsonRequestBehavior.AllowGet);
                }

            }
            return Json(0);
        }
        public ActionResult SaveNewBill(Bill bill, bool isZeroOut)
        {
            try
            {
                //save to bill
                if (bill != null)
                {
                    bill.DateReceived = DateTime.Now;
                    Guid memberId = bill.MemberId;
                    Guid medallionId = bill.MedallionId;

                    var medallion = medallionService.Get(bill.MedallionId);
                    if (bill.Id != null && bill.Id != Guid.Empty)
                    {

                        bill.UserName = User.Identity.Name;
                        billService.Update(bill);
                    }
                    else
                    {
                        bill.Id = Guid.NewGuid();
                        bill.IsZeroOut = isZeroOut;
                        bill.UserName = User.Identity.Name;
                        billService.Add(bill);
                    }
                    //we are suspecting  just have only one for each medallion
                    var loan = loanService.GetLoanListByMemberAndMedallion(memberId, medallionId).FirstOrDefault();
                    var insuranceDeposit = insuranceDepositService.GetByMedallionAndMemberId(memberId, medallionId);
                    var ccsys = ccsystemAirtimeService.GetByMedallionAndMemberId(memberId, medallionId);
                    var accReceivable = accountReceivableService.GetByMedallionAndMemberId(memberId, medallionId);
                    var saveDeposit = savingDepositService.GetByMedallionAndMemberId(memberId, medallionId);

                    //decrease balance in loan
                    if (loan != null && bill.Loan > 0)
                    {
                        loan.TotalPaid += bill.Loan;
                        loan.CurrentBalance -= bill.Loan;
                        //decrease for total paid interested &  principal paid
                        CalculatePaidLoan(loan, bill.Loan);

                        loanService.Update(loan);
                    }

                    //decrease balance in insurance deposit
                    if (insuranceDeposit != null && bill.InsuranceDepositAmount > 0)
                    {
                        insuranceDeposit.TotalPaid += bill.InsuranceDepositAmount;
                        insuranceDeposit.CurrentBalance -= bill.InsuranceDepositAmount;
                        insuranceDepositService.Update(insuranceDeposit);
                    }

                    //decrease balance in accReceivable
                    if (accReceivable != null && bill.AccountReceivableAmount > 0)
                    {
                        accReceivable.TotalPaid += bill.AccountReceivableAmount;
                        accReceivable.CurrentBalance -= bill.AccountReceivableAmount;
                        accountReceivableService.Update(accReceivable);
                    }

                    if (isZeroOut)
                    {
                        //decrease balance in saveDeposit
                        if (saveDeposit != null && bill.TotalPaid > 0)
                        {
                            saveDeposit.TotalPaid -= bill.TotalPaid;
                            savingDepositService.Update(saveDeposit);
                        }
                    }
                    else
                    {
                        //decrease balance in saveDeposit
                        if (saveDeposit != null && bill.SavingDepositAmount > 0)
                        {
                            saveDeposit.TotalPaid += bill.SavingDepositAmount;
                            savingDepositService.Update(saveDeposit);
                        }
                    }
                    //get balance
                    bill.Balance = loan.CurrentBalance
                         + insuranceDeposit.CurrentBalance
                         + ccsys.Airtime
                         + accReceivable.CurrentBalance;
                    billService.Update(bill);
                    //save to transactionhistory
                    TransactionHistory trans = new TransactionHistory()
                    {
                        Id = Guid.NewGuid(),
                        BillId = bill.Id,
                        IsZeroOut = bill.IsZeroOut,
                        DateReceived = bill.DateReceived,
                        TransactionType = bill.TransactionType,
                        AccountReceivableAmount = bill.AccountReceivableAmount,
                        AssociationDueAmount = bill.AssociationDueAmount,
                        Loan = bill.Loan,
                        Balance = bill.Balance,
                        Cash = bill.Cash,
                        CCSystemAirtimeAmount = bill.CCSystemAirtimeAmount,
                        Check = bill.Check,
                        CollsionInsuranceAmount = bill.CollsionInsuranceAmount,
                        Credit = bill.Credit,
                        CreditCardAmount = bill.CreditCardAmount,
                        CreditCardFee = bill.CreditCardFee,
                        DueDate = bill.EndDate,

                        InsuranceDepositAmount = bill.InsuranceDepositAmount,
                        InsuranceSticker = bill.InsuranceSticker,
                        InsuranceSurchargeAmount = bill.InsuranceSurchargeAmount,
                        Interval = bill.Interval,
                        IsAutoCashiering = bill.IsAutoCashiering,
                        IsDeleted = false,
                        LateFees = bill.LateFees,
                        MedallionId = bill.MedallionId,
                        MedallionNumber = medallion.MedallionNumber,
                        MemberId = bill.MemberId,
                        MiscCharge = bill.MiscCharge,
                        NextPayment = bill.NextPayment,
                        RecieptNumber = bill.RecieptNumber,
                        SavingDepositAmount = bill.SavingDepositAmount,
                        Subtotal = bill.Subtotal,
                        TotalDueAmount = bill.TotalDueAmount,
                        TotalPaidAmount = bill.TotalPaidAmount,

                        UserName = bill.UserName,
                        WerkReceivableAmount = bill.WerkReceivableAmount,
                        WorkerCompensationAmount = bill.WorkerCompensationAmount,
                        TransactionDate = bill.StartDate,
                        TotalPaid = bill.TotalPaid
                    };
                    //save to transaction history
                    transactionHistoryService.Add(trans);
                    return Json(true);
                }
            }
            catch
            {
                return Json(false);
            }
            return Json(false);
        }
Exemple #6
0
 public Bill Update(Bill bill)
 {
     billRepository.Update(bill);
     return bill;
 }
Exemple #7
0
 public Bill Add(Bill bill)
 {
     billRepository.Add(bill);
     return bill;
 }
Exemple #8
0
        public List<MedallionLoan> GetMedallionLoanByMemberId(Guid memberId)
        {
            DateTime today = DateTime.Now;

            var list = new List<MedallionLoan>();
            //get medallion
            var medallionlist = GetMemberMedallions(memberId);
            //get transaction
            var transactionhistory = transactionHistoryRepository.Get.Where(c => c.MemberId == memberId).ToList();
            //get list bill
            var listbill = billRepository.Get.Where(c => c.MemberId == memberId).OrderBy(c => c.NextPayment).ToList();
            //get company setting
            var companySetting = companyRepository.Get.FirstOrDefault();

            Bill bill = null;
            //initial bill with last bill
            if (listbill != null && listbill.Count > 0)
            {
                bill = listbill.First();
            }

            foreach (Medallion med in medallionlist)
            {
                DateTime billingStartDate = med.BillingStartDate;
                DateTime billingEndDate = med.BillingEndDate;

                if (bill == null)
                {
                    bill = new Bill();
                    bill.StartDate = billingStartDate;
                    bill.EndDate = billingStartDate.AddMonths(1);
                    bill.NextPayment = bill.EndDate.AddDays(1);
                }
                else
                {
                    bill.StartDate = bill.NextPayment;
                    bill.EndDate = bill.EndDate.AddMonths(1);
                    bill.NextPayment = bill.EndDate.AddDays(1);
                }
                MedallionLoan medloan = new MedallionLoan();
                medloan.MedallionId = med.Id;
                medloan.MedallionNumber = med.MedallionNumber;

                //get insurance deposit
                var insruance = insuranceDepositRepository.Get.Where(c => c.MedallionId == med.Id && c.MemberId == c.MemberId).FirstOrDefault();
                var ccsystem = ccsystemAirtimeRepository.Get.Where(c => c.MedallionId == med.Id && c.MemberId == c.MemberId).FirstOrDefault();
                //get loans by medallionId
                var loanlist = loanRepository.Get.Where(c => c.MemberId == memberId && c.MedallionId == med.Id && c.IsDeleted == false);

                var accountreceivabl = accountReceivableRepository.Get.Where(c => c.MedallionId == med.Id && c.MemberId == c.MemberId).FirstOrDefault();
                var savingdeposit = savingDepositRepository.Get.Where(c => c.MedallionId == med.Id && c.MemberId == c.MemberId).FirstOrDefault();

                //current balance
                medloan.CurrentBalance += insruance != null ? insruance.CurrentBalance : 0;
                medloan.CurrentBalance += ccsystem != null ? ccsystem.Airtime : 0;
                medloan.CurrentBalance += accountreceivabl != null ? accountreceivabl.CurrentBalance : 0;
                if (loanlist != null && loanlist.Count() > 0)
                {
                    foreach (Loan l in loanlist)
                    {
                        medloan.CurrentBalance += l.CurrentBalance;
                    }
                }
                //calculate late fee
                if (companySetting != null)
                {
                    int allowLateDate = companySetting.DefaultLateBreak > 0 ? (int)companySetting.DefaultLateBreak : 0;

                    var totalDateLate = today.Subtract(bill.EndDate).Days;
                    if (totalDateLate > allowLateDate)
                    {
                        //calculate late fee
                        decimal feeLateOneDay = (companySetting.DefaultLateCharge / 7);
                        decimal totalFeeLate = Math.Round(feeLateOneDay * totalDateLate, 2, MidpointRounding.AwayFromZero);
                        bill.LateFees = totalFeeLate;

                        medloan.DateLates = totalDateLate;
                        medloan.Status = "Past Due";
                    }
                    else if (totalDateLate < allowLateDate && totalDateLate > 1)
                    {
                        medloan.Status = "Due";
                    }
                    else
                    {
                        medloan.Status = "Current";
                    }
                }

                medloan.PayTillDate = bill.EndDate;
                medloan.PaymentDueDate = bill.StartDate;

                list.Add(medloan);
            }

            return list;
        }