private MortgageCalculationModel CalculateMortgageModel(Mortgage m, Purchase p)
        {
            var model = new MortgageCalculationModel();
            var rate  = (double)m.InterestRate / 100 / 12;

            var principal = -FinancialFunctions.PPMT(rate, 1, m.LoanAmortizationTerm, p.LoanAmount, 0, 0);

            var interestPayment = -FinancialFunctions.IPMT(rate, 1, m.LoanAmortizationTerm, p.LoanAmount, 0, 0);


            model.Interest  = interestPayment;
            model.Principle = principal;
            if (p.DownPaymentPercentage < 20)
            {
                model.PMI = (p.LoanAmount * ((0.4) / 100)) / 12;

                return(model);
            }

            return(model);
        }
        public static AjaxCallExpensifyRecordResult ExpensifyRecordProceed(string masterGuid, string recordGuid,
                                                                           string amountString, string amountVatString, int budgetId, string description)
        {
            GetAuthenticationDataAndCulture();

            List <ExpensifyRecord> recordList = (List <ExpensifyRecord>)GuidCache.Get("ExpensifyData-" + masterGuid);
            int index = LocateRecordsetIndex(recordList, recordGuid);

            amountString    = amountString.Trim();
            amountVatString = amountVatString.Trim();

            if (amountString.Contains(" "))
            {
                amountString = FinancialFunctions.InterpretCurrency(amountString).DisplayAmount;
            }

            if (amountVatString.Contains(" "))
            {
                amountVatString = FinancialFunctions.InterpretCurrency(amountVatString).DisplayAmount;
            }

            recordList[index].AmountCents = Formatting.ParseDoubleStringAsCents(amountString);
            recordList[index].VatCents    = Formatting.ParseDoubleStringAsCents(amountVatString);
            recordList[index].BudgetId    = budgetId;
            recordList[index].Description = description;

            GuidCache.Set("ExpensifyData-" + masterGuid, recordList);

            index++;

            if (index >= recordList.Count)
            {
                // We processed the last record, so return a null record

                return(new AjaxCallExpensifyRecordResult
                {
                    Guid = "", // indicates null record
                    Success = true,
                    DataUpdate = FormatExpensifyOutputRecords(recordList),
                    FooterUpdate = FormatExpensifyFooter(recordList),
                    SubmitPrompt = FormatExpensifySubmitPrompt(recordList)
                });
            }

            // Display the record next in line

            return(new AjaxCallExpensifyRecordResult
            {
                Amount = (recordList[index].AmountCents / 100.0).ToString("N2"),
                AmountVat = (recordList[index].VatCents / 100.0).ToString("N2"),
                Description = recordList[index].Description,
                DocumentId = recordList[index].Documents.First().Identity,
                BudgetId = recordList[index].BudgetId,
                Guid = recordList[index].Guid,
                ExistNext = (index < recordList.Count - 1 ? true : false),
                Success = true,
                DataUpdate = FormatExpensifyOutputRecords(recordList),
                FooterUpdate = FormatExpensifyFooter(recordList),
                SubmitPrompt = FormatExpensifySubmitPrompt(recordList)
            });
        }