Exemple #1
0
        public FinancialAnalysis(LoanRequest loanRequest, VAT vat)
        {
            //The loan Request contains all the necessary data
            //to calculate a Financial Analysis.
            _loanRequest = loanRequest;
            _financeUtil = new ZiblerFinanceUtilities ();

            //Establish what loans are present
            foreach (Loan existingLoan in _loanRequest.Loans)
            {
                if (existingLoan.LoanType == LoanType.CapitalDeTrabajo)
                {
                    _wrkngCptlAmrtztn = CreateAmortizationTable (existingLoan, vat);
                    _wrkngCptlLoan = existingLoan;
                    _financeUtil.AddAmortizationPaymentDates (_wrkngCptlAmrtztn.AmortizationTable,
                                                              _wrkngCptlAmrtztn.StartDate,
                                                              _wrkngCptlAmrtztn.PaymentFrequency,
                                                              Country.Mexico);
                }
                if (existingLoan.LoanType == LoanType.Refaccionario)
                {
                    _fxdAsstAmrtztn = CreateAmortizationTable (existingLoan, vat);
                    _fxdAsstLoan = existingLoan;
                    _financeUtil.AddAmortizationPaymentDates (_fxdAsstAmrtztn.AmortizationTable,
                                                              _fxdAsstAmrtztn.StartDate,
                                                              _fxdAsstAmrtztn.PaymentFrequency,
                                                              Country.Mexico);
                }
            }
        }
 /// <summary>
 /// Removes a VAT from the list of VATs
 /// in this Financial Institution
 /// </summary>
 /// <param name="vat">VAT to be removed</param>
 public virtual void RemoveVAT(VAT vat)
 {
     VATs.Remove (vat);
 }
 /// <summary>
 /// Adds a new VAT to the list of VATs
 /// in this Financial Institution
 /// </summary>
 /// <param name="vat">VAT to be added</param>
 public virtual void AddVAT(VAT vat)
 {
     vat.FinancialInstitution = this;
     VATs.Add (vat);
 }
 /// <summary>
 /// Returns a FinancialAnalysis object for a given loan request
 /// </summary>
 /// <param name="loanRequest">loanRequest</param>
 /// <param name="applicableVAT">applicableVAT</param>
 /// <returns></returns>
 public FinancialAnalysis GetFinancialAnalysis(LoanRequest loanRequest, VAT applicableVAT)
 {
     FinancialAnalysis financialAnalysis = new FinancialAnalysis(loanRequest, applicableVAT);
     return financialAnalysis;
 }
Exemple #5
0
        /// <summary>
        /// Creates an amortization table using the given parameters
        /// </summary>
        /// <param name="loan">loan</param>
        /// <param name="vat">vat</param>
        /// <returns>Amortization Table</returns>
        private Amortization CreateAmortizationTable(Loan loan, VAT vat)
        {
            AmortizationFactory amrtztnFctry = new AmortizationFactory ();
            Amortization amortization;

            //Before we continue, we need to get the applicable interest Rate.
            //note that this is only for the Analysis, and because of this,
            //then we will take the most active interest rate, if the loan request
            //has not been approved, or the approved date.

            DateTime? loanStartDate;

            if (loan.StartDate == null)
                loanStartDate = DateTime.Today;
            else
                loanStartDate = loan.StartDate;

            DateTime? selectedDate = null;
            decimal selectedInterest = 0.0m;

            //TODO: Note that this code, will get all the values applicable to an interest rate.
            //		this may not be a big deal if they only register the value every month,
            //		but it may cause a problem after a couple years if the register the values
            //		every day.

            //Look for the interest RAte
            foreach (InterestRateValue value in loan.InterestRate.InterestRateValues)
            {
                DateTime? newDate = value.ValidFrom;

                bool newDateLessEqualLoanDate
                = !DateUtilities.IsFirstDateGreaterThanSecondDate (Convert.ToDateTime (newDate),
                                                                   Convert.ToDateTime (loanStartDate));

                if (newDateLessEqualLoanDate)
                {
                    if (selectedDate == null)
                    {
                        selectedDate = newDate;
                        selectedInterest = value.Value;
                    }
                    else
                    {
                        bool isNewDateGreaterSelected =
                        DateUtilities.IsFirstDateGreaterThanSecondDate (Convert.ToDateTime (newDate),
                                                                        Convert.ToDateTime (
                                                                            selectedDate));

                        if (isNewDateGreaterSelected)
                        {
                            selectedDate = newDate;
                            selectedInterest = value.Value;
                        }
                    }
                }
            }

            //Technically the selected date should never be null
            if (selectedDate == null)
                throw new ZiblerBusinessComponentsException (
                    Resources.LoanAnalysisMsgNoInterestRateAvailableCheckDates);

            //Add the Gross Earnings Margin (margen de intermediacion) to the
            //Interest Rate.
            decimal interestToUse = selectedInterest + loan.GrossEarningsMargin;

            amortization = amrtztnFctry.CreateAmortization (loan.AmortizationTableType,
                                                            loan.LoanedAmount,
                                                            loan.NumberOfAmortizations,
                                                            loan.PaymentFrequency,
                                                            interestToUse,
                                                            loan.GracePeriod,
                                                            Convert.ToDateTime (loanStartDate),
                                                            vat.Value);

            //Calculate the amortization.
            amortization.CalculateAmortizationTable ();

            return amortization;
        }
        /// <summary>
        /// Creates a new VAT and adds it to the system
        /// </summary>
        /// <param name="financialInstitutionName">Financial Institution name</param>
        /// <param name="userName">User name</param>
        /// <param name="interestRate">New vat</param>
        /// <exception cref="ZiblerBusinessComponentsException" />
        public void CreateNewVAT(string financialInstitutionName, string userName, VAT vat)
        {
            try
            {
                IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO ();

                //Verify the user does not exist in the system first.
                if (financialInstitutionDAO.VATExists (financialInstitutionName, vat.ValidFrom))
                {
                    throw new ZiblerBusinessComponentsException (
                        Resources.SystemParametersOperationMsgVATExists);
                }
                else
                {
                    //Get the financial institution, and add the new interest to it.
                    FinancialInstitution financialInstitution = financialInstitutionDAO.GetFinancialInstitutionByName (
                        financialInstitutionName);
                    financialInstitution.AddVAT (vat);
                }
            }
            /* If the exception was thrown here, just pass it up */
            catch (ZiblerBusinessComponentsException ex)
            {
                throw;
            }
            /* Catch any Data Layer or other exception and throw an unkown exception */
            catch (Exception ex)
            {
                ZiblerBusinessComponentsUnknownException exc
                = new ZiblerBusinessComponentsUnknownException (ex);

                /* Throw the new exception */
                throw exc;
            }
        }
        /// <summary>
        /// Update the VAT and save it to the system
        /// </summary>
        /// <param name="vatToUpdate">VAT to be updated</param>
        /// <exception cref="ZiblerBusinessComponentsException" />
        public void UpdateVAT(VAT vatToUpdate)
        {
            try
            {
                IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO ();
                IVatDAO vatDAO = _daoFactory.GetVatDAO ();

                DateTime? oldVATDate = vatDAO.GetVATDate (vatToUpdate.Id);

                if (oldVATDate == null)
                    throw new ZiblerBusinessComponentsException (Resources.RecordNotFound);
                else
                {
                    //If the dates are the same then just go ahead and update
                    if (DateTime.Compare (Convert.ToDateTime (oldVATDate),
                                          Convert.ToDateTime (vatToUpdate.ValidFrom)) == 0)
                        vatDAO.MakePersistent (vatToUpdate);
                    else
                    {
                        //If dates are different, then verify there is no other VAT registered on that date.
                        if (financialInstitutionDAO.VATExists (vatToUpdate.FinancialInstitution.Name,
                                                               vatToUpdate.ValidFrom))
                            throw new ZiblerBusinessComponentsException (
                                Resources.SystemParametersOperationMsgVATExists);
                        else
                            vatDAO.MakePersistent (vatToUpdate);
                    }
                }
            }
            /* If the exception was thrown here, just pass it up */
            catch (ZiblerBusinessComponentsException ex)
            {
                throw;
            }
            /* Catch any Data Layer or other exception and throw an unkown exception */
            catch (Exception ex)
            {
                ZiblerBusinessComponentsUnknownException exc
                = new ZiblerBusinessComponentsUnknownException (ex);

                /* Throw the new exception */
                throw exc;
            }
        }