예제 #1
0
        public async Task <IActionResult> GetCashReceiptLookups([FromBody] GetCashReceiptLookupsRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await repository.AuthenticateUserToken(req.CurrentUser.UserId, req.CurrentUser.UserToken);

            if (user == null)
            {
                return(NotFound());
            }

            GetCashReceiptLookupsResponse resp = new GetCashReceiptLookupsResponse();


            var vendors = await repository.GetAllManufacturers();

            foreach (Manufacturer m in vendors)
            {
                resp.Vendors.Add(new VendorModel
                {
                    VendorId   = m.ManufacturerId,
                    VendorName = m.ManufacturerName
                });
            }
            resp.LogoData = user.ReferencingCompany.Logo;

            return(Ok(resp));
        }
예제 #2
0
        public async Task <IActionResult> GetDriverLookups([FromBody] GetDriverLookupsRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            GetDriverLookupsResponse resp = new GetDriverLookupsResponse();

            PortalUser user = await repository.AuthenticateUserToken(req.CurrentUser.UserId, req.CurrentUser.UserToken);

            if (user == null)
            {
                return(NotFound());
            }

            resp.GenderTypes = await repository.GetAllGenderTypes();

            resp.PhoneNumberTypes = await repository.GetAllPhoneNumberTypes();

            resp.StateProvinces = await repository.GetAllStateProvinces();

            resp.InsuranceProviders = await repository.GetAllInsuranceProviders();

            resp.MedicalProviders = await repository.GetAllMedicalProviders();

            resp.EthnicityTypes = await repository.GetAllEthnicityTypes();

            resp.LogoData = user.ReferencingCompany.Logo;

            return(Ok(resp));
        }
예제 #3
0
        public async Task <IActionResult> GetPeriodLookups([FromBody] GetPeriodLookupsRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await repository.AuthenticateUserToken(req.CurrentUser.UserId, req.CurrentUser.UserToken);

            if (user == null)
            {
                return(NotFound());
            }

            GetPeriodLookupsResponse resp = new GetPeriodLookupsResponse();

            resp.FrequencyTypes = await repository.GetAllFrequencyTypes();

            return(Ok(resp));
        }
예제 #4
0
        public async Task <IActionResult> GetJournalLookups([FromBody] GetJournalLookupRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            GetJournalLookupResponse resp = new GetJournalLookupResponse();

            PortalUser user = await repository.AuthenticateUserToken(req.CurrentUser.UserId, req.CurrentUser.UserToken);

            if (user == null)
            {
                return(NotFound());
            }

            resp.JournalTypes = await repository.GetAllJournalTypes();

            resp.MaintenanceTypes = await repository.GetAllMaintenanceTypes();

            resp.FrequencyTypes = await repository.GetAllFrequencyTypes();

            resp.LogoData = user.ReferencingCompany.Logo;

            return(Ok(resp));
        }
        public async Task <IActionResult> GetLoanSchedule([FromBody] GetLoanScheduleRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await repository.AuthenticateUserToken(req.CurrentUser.UserId, req.CurrentUser.UserToken);

            if (user == null)
            {
                return(NotFound());
            }

            if (req.LoanAmount <= 0)
            {
                throw new ArgumentException("Loan Amount needs to be greater than $0.00.");
            }

            if (req.NumberOfPayments <= 0)
            {
                throw new ArgumentException("Number of Payments needs to be greater than 0.");
            }

            if (req.StartDate < new DateTime(2000, 1, 1))
            {
                throw new ArgumentException("Start Date needs to be greater than 1/1/2000.");
            }


            //*********************************************************************
            //TODO:MAKE THIS CALCULATION DATABASE DRIVEN SINCE NEEDED FOR REPORTING
            GetLoanScheduleResponse resp  = new GetLoanScheduleResponse();
            List <LoanScheduleItem> items = new List <LoanScheduleItem>();
            //LoanScheduleItem item;
            DateTime _startDate    = req.StartDate;
            Decimal  _principal    = req.LoanAmount;
            Decimal  _interestRate = req.InterestRate;
            int      _period       = req.NumberOfPayments;


            // Make sure we use types that hold decimal places
            //DateTime payDate = DateTime.ParseExact(_startDate.ToString(), "yyyyMMdd", null);
            DateTime payDate         = _startDate;
            double   interestRate    = 0;
            double   monthlyInterest = 0;
            double   loanAmount;
            short    amortizationTerm = 0;
            double   currentBalance;
            double   cummulativeInterest  = 0;
            double   monthlyPrincipal     = 0;
            double   cummulativePrincipal = 0;

            loanAmount       = double.Parse(_principal.ToString());
            currentBalance   = loanAmount;
            interestRate     = double.Parse(_interestRate.ToString()) * 0.01;
            amortizationTerm = short.Parse(_period.ToString());

            // Calculate the monthly payment and round it to 2 decimal places
            var monthlyPayment = ((interestRate / 12) / (1 - (Math.Pow((1 + (interestRate / 12)), -(amortizationTerm))))) * loanAmount;

            monthlyPayment = Math.Round(monthlyPayment, 2);

            // Storage List
            //List<AmortPayment> amortPaymentList = new List<AmortPayment>();

            // Loop for amortization term (number of monthly payments)
            for (int j = 0; j < amortizationTerm; j++)
            {
                // Calculate monthly cycle
                monthlyInterest  = currentBalance * interestRate / 12;
                monthlyPrincipal = monthlyPayment - monthlyInterest;
                currentBalance   = currentBalance - monthlyPrincipal;

                if (j == amortizationTerm - 1 && currentBalance != monthlyPayment)
                {
                    // Adjust the last payment to make sure the final balance is 0
                    monthlyPayment += currentBalance;
                    currentBalance  = 0;
                }

                // Reset Date
                payDate = payDate.AddMonths(1);
                // Add to cummulative totals
                cummulativeInterest  += monthlyInterest;
                cummulativePrincipal += monthlyPrincipal;

                items.Add(new LoanScheduleItem
                {
                    LoanScheduleItemID = j + 1,
                    PaymentNumber      = j + 1,
                    PaymentDate        = payDate,
                    PaymentAmount      = Math.Round(Decimal.Parse(monthlyPayment.ToString()) + Decimal.Parse(monthlyInterest.ToString()), 2),
                    AppliedToInterest  = Math.Round(Decimal.Parse(monthlyInterest.ToString()), 2),
                    AppliedToPrinciple = Math.Round(Decimal.Parse(monthlyPayment.ToString()), 2),
                    RemainingBalance   = Math.Round(Decimal.Parse(currentBalance.ToString()), 2)
                });
            }


            resp.LoanScheduleItems = items;



            ////GetLoanScheduleResponse resp = new GetLoanScheduleResponse();
            ////List<LoanScheduleItem> items = new List<LoanScheduleItem>();
            ////LoanScheduleItem item;
            ////decimal paymentAmount = 0m;
            ////decimal runningBalance = 0m;
            ////int recCount = 0;
            ////bool isLastPayment = false;

            //////BI-MONTHLY FREQUENCY TYPE
            ////paymentAmount = req.LoanAmount / req.NumberOfPayments / 2;

            ////runningBalance = req.LoanAmount;

            ////MaintenanceController mc = new MaintenanceController(this.repository,config);
            ////List<PeriodModel> paymentPeriods = mc.BuildPeriodList(req.FrequencyTypeID, req.StartDate, req.StartDate.AddMonths(req.NumberOfPayments));
            ////foreach(PeriodModel pm in paymentPeriods)
            ////{
            ////    recCount++;

            ////    if (paymentAmount > runningBalance)
            ////        paymentAmount = runningBalance;

            ////    runningBalance = runningBalance - paymentAmount;

            ////    item = new LoanScheduleItem();
            ////    item.AppliedToPrinciple = paymentAmount;
            ////    item.AppliedToInterest = 0;
            ////    item.LoanScheduleItemID = recCount;
            ////    item.PaymentAmount = paymentAmount;
            ////    item.PaymentDate = pm.EndDate;
            ////    item.PaymentNumber = recCount;
            ////    item.RemainingBalance = runningBalance;

            ////    if(runningBalance<=0)
            ////    {
            ////        item.RemainingBalance = 0m;
            ////        isLastPayment = true;
            ////    }

            ////    items.Add(item);

            ////    if (isLastPayment)
            ////        break;
            ////}


            ////resp.LoanScheduleItems =items;

            return(Ok(resp));
        }