Example #1
0
 /// <summary>
 /// Removes a Credit Line from the list of Credit Lines
 /// in this Financial Institution
 /// </summary>
 /// <param name="creditLine">Credit Line to be removed</param>
 public virtual void RemoveCreditLine(CreditLine creditLine)
 {
     CreditLines.Remove (creditLine);
 }
Example #2
0
 ///// <summary>
 ///// Adds a new client to the list of Clients
 ///// in this Financial Institution
 ///// </summary>
 ///// <param name="client">Client to be added</param>
 //public virtual void AddClient(Client client)
 //{
 //    client.FinancialInstitution = this;
 //    Clients.Add(client);
 //}
 ///// <summary>
 ///// Removes a Client from the list of Clients
 ///// in this Financial Institution
 ///// </summary>
 ///// <param name="client">Client to be removed</param>
 //public virtual void RemoveClient(Client client)
 //{
 //    Clients.Remove(client);
 //}
 /// <summary>
 /// Adds a new Credit Line to the list of Credit Lines
 /// in this Financial Institution
 /// </summary>
 /// <param name="creditLine">Credit Line to be added</param>
 public virtual void AddCreditLine(CreditLine creditLine)
 {
     creditLine.FinancialInstitution = this;
     CreditLines.Add (creditLine);
 }
Example #3
0
        /// <summary>
        /// Adds the loan requests to a credit line. It also takes care of updating
        /// the loan requests amounts as per the new addition.
        /// </summary>
        /// <param name="creditLineToUpdate">creditLineToUpdate</param>
        /// <param name="loanRequestIds">loanRequestIds</param>
        /// <exception cref="ZiblerBusinessComponentsException"/>
        public void AddLoanRequestsToCreditLine(CreditLine creditLineToUpdate,
            IList<int> loanRequestIds)
        {
            try
            {
                ILoanRequestDAO loanRequestDAO = _daoFactory.GetLoanRequestDAO ();

                //First we verify the status of the credit line. Only
                //active credit lines can be associated with LoanRequests
                if (creditLineToUpdate.CreditLineStatus == CreditLineStatus.Suspendida)
                {
                    throw new ZiblerBusinessComponentsException (
                        Resources.CreditLineOperationsMsgCreditLineMustBeActiveForAssociation);
                }
                else
                {
                    //Loop through the array of loan requests
                    foreach (int loanRequestId in loanRequestIds)
                    {
                        //Get the Loan Request from the database.
                        LoanRequest loanRequest = loanRequestDAO.FindById (loanRequestId);

                        //If we could not find the loan request then raise the exception
                        if (loanRequest == null)
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.CreditLineOperationsMsgLoanRequestNotFound);
                        }

                        /* If there is an associated credit line then throw an exception and
                        * cancel the operation. */
                        if (loanRequest.CreditLine != null)
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.CreditLineOperationsMsgLoanRequestAlreadyHasCreditLine);
                        }

                        //Now lets add the amounts from all the associated loans to this loanRequest
                        decimal totalLoans = 0.0m;

                        foreach (Loan loan in loanRequest.Loans)
                        {
                            totalLoans = totalLoans + loan.LoanedAmount;
                        }

                        //TODO: The following code is identical to the code contained in the
                        //		LoanRequestOperations function:
                        //			public void UpdateLoanRequestInformation(string financialInstitutionName,
                        //								LoanRequest loanRequest)
                        //

                        //TODO: DO I have to add every capital payment to the credit line?
                        //		For now I will only add the loaned amounts back to the credit line
                        //		when the Loan has been paid in full, not everytime I get a Payment.

                        /*
                        * The following rules are followed to determine how to calculate the amounts for the
                        * credit line.
                        *
                        * If the Loan Request status is any of the following:
                        *
                        * -Cancelada
                        * -Rechazada
                        * -Pagada
                        * -EnCaptura
                        *
                        * Then no update will be made to the balances in the Credit line. The update to the balance
                        * will be performed when the LoanRequest status is changed to any of these. So we can
                        * safely assume that if a loan request status is any of the above mention, it means that
                        * the balance to its credit line has been updated.
                        *
                        * if the loan Request status is any of the following:
                        *
                        * -Capturada
                        * -Expediente Integrado
                        * -Condicionada
                        *
                        * then the total amount in loans will be added to the AmountInRequestedLoans
                        * and substracted from the available amount.
                        *
                        * if the request status is any of the following:
                        *
                        * -Aprobada
                        * -Corriente
                        * -Vencida
                        * -ExtraJudicial
                        * -Judicial de Alto Riesgo
                        *
                        * then the total amount in loans will be added to the AmountInApprovedLoans
                        * and substracted from the available amount
                        *
                        * */

                        if (loanRequest.LoanRequestStatus == LoanRequestStatus.Capturada
                            || loanRequest.LoanRequestStatus == LoanRequestStatus.ExpedienteIntegrado
                            || loanRequest.LoanRequestStatus == LoanRequestStatus.Condicionada)
                        {
                            //If there is not enough money in the credit line to associate
                            //the loan request then we raise an exception indicating the problem.
                            if (creditLineToUpdate.AvailableAmount < totalLoans)
                            {
                                throw new ZiblerBusinessComponentsException (
                                    Resources.CreditLineOperationsMsgNotEnoughMoneyInCreditLine);
                            }
                            // If there is enough money in the credit line
                            else
                            {
                                //Add the totalLoans amount to the Amount In Authorized Loans
                                creditLineToUpdate.AmountInRequestedLoans = creditLineToUpdate.AmountInRequestedLoans +
                                                                            totalLoans;
                                creditLineToUpdate.AvailableAmount = creditLineToUpdate.AvailableAmount -
                                                                     totalLoans;

                                //Associate the Credit Line to the LoanRequest
                                loanRequest.CreditLine = creditLineToUpdate;
                            }
                        }
                        else if (loanRequest.LoanRequestStatus == LoanRequestStatus.Aprobada
                                 || loanRequest.LoanRequestStatus == LoanRequestStatus.Corriente
                                 || loanRequest.LoanRequestStatus == LoanRequestStatus.Vencida
                                 || loanRequest.LoanRequestStatus == LoanRequestStatus.ExtraJudicial
                                 || loanRequest.LoanRequestStatus ==
                                    LoanRequestStatus.JudicialAltoRiesgo)
                        {
                            //If there is not enough money in the credit line to associate
                            //the loan request then we rais an exception indicating the problem.
                            if (creditLineToUpdate.AvailableAmount < totalLoans)
                            {
                                throw new ZiblerBusinessComponentsException (
                                    Resources.CreditLineOperationsMsgNotEnoughMoneyInCreditLine);
                            }
                            // If there is enough money in the credit line
                            else
                            {
                                //Update the CreditLine amounts
                                //Add the totalLoans amount to the Amount In Authorized Loans
                                creditLineToUpdate.AmountInAuthorizedLoans = creditLineToUpdate.AmountInAuthorizedLoans +
                                                                             totalLoans;
                                creditLineToUpdate.AvailableAmount = creditLineToUpdate.AvailableAmount -
                                                                     totalLoans;

                                //Associate the Credit Line to the LoanRequest
                                loanRequest.CreditLine = creditLineToUpdate;
                            }
                        }
                        else if (loanRequest.LoanRequestStatus == LoanRequestStatus.EnCaptura
                                 || loanRequest.LoanRequestStatus == LoanRequestStatus.Cancelada
                                 || loanRequest.LoanRequestStatus == LoanRequestStatus.Rechazada
                                 || loanRequest.LoanRequestStatus == LoanRequestStatus.Pagada)
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.CreditLineOperationsMsgLoanRequestStatusInvalid);
                        }
                    }
                }
            }
            /* 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;
            }
        }
Example #4
0
        /// <summary>
        /// Update credit line in the system
        /// </summary>
        /// <param name="creditLineToUpdate">Credit line to update</param>
        /// <exception cref="ZiblerBusinessComponentsException"/>
        public void UpdateCreditLine(CreditLine creditLineToUpdate)
        {
            try
            {
                //I won't worry about recalculating anything regarding the amounts
                //of available cash, since it could be a hard task.
                //I will only verify the name is not repeated. It is up to them to be responsible
                //when changing data in a credit line.
                IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO ();
                ICreditLineDAO creditLineDAO = _daoFactory.GetCreditLineDAO ();

                string oldName = creditLineDAO.GetCreditLineName (creditLineToUpdate.Id);

                //Before we go into updating or not (based on the name) we verify the Default
                //status.

                bool oldDefaultOption = financialInstitutionDAO.DefaultCreditLineExists (
                    creditLineToUpdate.Id);
                bool otherDefaultOption = financialInstitutionDAO.DefaultCreditLineExists (
                    creditLineToUpdate.FinancialInstitution.Name);

                //If it was never a default parameter and now it is.
                if (!oldDefaultOption && creditLineToUpdate.IsDefault)
                {
                    if (otherDefaultOption)
                        throw new ZiblerBusinessComponentsException (
                            Resources.CreditLineOperationsMsgDefaultCreditLineExists);
                }
                //If it was the default parameter and now it is not.
                else if (oldDefaultOption && !creditLineToUpdate.IsDefault)
                {
                    if (!otherDefaultOption)
                        throw new ZiblerBusinessComponentsException (
                            Resources.CreditLineOperationsMsgAtLeastOneDefaultCreditLine);
                }
                //If it was never the default parameter and it is not now.
                else if (!oldDefaultOption && !creditLineToUpdate.IsDefault)
                {
                    if (!otherDefaultOption)
                        throw new ZiblerBusinessComponentsException (
                            Resources.CreditLineOperationsMsgAtLeastOneDefaultCreditLine);
                }

                //If they marked the credit line as default
                //we must verify it is not suspended.
                if (creditLineToUpdate.IsDefault)
                {
                    if (creditLineToUpdate.CreditLineStatus == CreditLineStatus.Suspendida)
                    {
                        throw new ZiblerBusinessComponentsException (
                            Resources.CreditLineOperationsMsgDefaultCreditLineCannotBeSuspended);
                    }
                }

                //If the names are the same then just update
                if (String.Compare (oldName, creditLineToUpdate.Name, true) == 0)
                    creditLineDAO.MakePersistent (creditLineToUpdate);
                else
                {
                    //Verify the name does not exist in the database yet.
                    if (financialInstitutionDAO.CreditLineExists (
                        creditLineToUpdate.FinancialInstitution.Name,
                        creditLineToUpdate.Name))
                    {
                        throw new ZiblerBusinessComponentsException (
                            Resources.CreditLineOperationsMsgCreditLineExists);
                    }
                    else
                        creditLineDAO.MakePersistent (creditLineToUpdate);
                }
            }
            /* 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;
            }
        }
Example #5
0
        /// <summary>
        /// Removes the loan requests from a credit line. It also takes care of updating
        /// the loan requests amounts as per the new addition.
        /// </summary>
        /// <param name="creditLineToUpdate">creditLineToUpdate</param>
        /// <param name="loanRequestIds">loanRequestIds</param>
        /// <exception cref="ZiblerBusinessComponentsException"/>
        public void RemoveLoanRequestsFromCreditLine(CreditLine creditLineToUpdate,
            IList<int> loanRequestIds)
        {
            try
            {
                ILoanRequestDAO loanRequestDAO = _daoFactory.GetLoanRequestDAO ();

                //Loop through the array of loan requests
                foreach (int loanRequestId in loanRequestIds)
                {
                    //Get the Loan Request from the database.
                    LoanRequest loanRequest = loanRequestDAO.FindById (loanRequestId);

                    //If we could not find the loan request then raise the exception
                    if (loanRequest == null)
                    {
                        throw new ZiblerBusinessComponentsException (
                            Resources.CreditLineOperationsMsgLoanRequestNotFound);
                    }

                    //Make sure it has a credit line associated to it.
                    if (loanRequest.CreditLine == null)
                    {
                        throw new ZiblerBusinessComponentsException (
                            Resources.CreditLineOperationsMsgLoanRequestDoesNotHaveCreditLine);
                    }
                    else
                    {
                        //TODO: I am not quite sure what this would cause in NHibernate.
                        //If it does, then verify is the same one
                        if (!creditLineToUpdate.Equals (loanRequest.CreditLine))
                            throw new ZiblerBusinessComponentsException (
                                Resources.CreditLineOperationsMsgLoanRequestDoesNotHaveCreditLine);
                    }

                    //Now lets add the amounts from all the associated loans to this loanRequest
                    decimal totalLoans = 0.0m;

                    foreach (Loan loan in loanRequest.Loans)
                    {
                        totalLoans = totalLoans + loan.LoanedAmount;
                    }

                    //TODO: DO I have to add every capital payment to the credit line?
                    //		For now I will only add the loaned amounts back to the credit line
                    //		when the Loan has been paid in full, not everytime I get a Payment.

                    /*
                    * The following rules are followed to determine how to calculate the amounts for the
                    * credit line.
                    *
                    * If the Loan Request status is any of the following:
                    *
                    * -Cancelada
                    * -Rechazada
                    * -Pagada
                    * -EnCaptura
                    *
                    * Then no update will be made to the balances in the Credit line. The update to the balance
                    * will be performed when the LoanRequest status is changed to any of these. So we can
                    * safely assume that if a loan request status is any of the above mention, it means that
                    * the balance to its credit line has been updated.
                    *
                    * if the loan Request status is any of the following:
                    *
                    * -Capturada
                    * -Expediente Integrado
                    * -Condicionada
                    *
                    * then the total amount in loans will be added to the AmountInRequestedLoans
                    * and substracted from the available amount.
                    *
                    * if the request status is any of the following:
                    *
                    * -Aprobada
                    * -Corriente
                    * -Vencida
                    * -ExtraJudicial
                    * -Judicial de Alto Riesgo
                    *
                    * then the total amount in loans will be added to the AmountInApprovedLoans
                    * and substracted from the available amount
                    *
                    * */

                    if (loanRequest.LoanRequestStatus == LoanRequestStatus.Capturada
                        || loanRequest.LoanRequestStatus == LoanRequestStatus.ExpedienteIntegrado
                        || loanRequest.LoanRequestStatus == LoanRequestStatus.Condicionada)
                    {
                        //Add the totalLoans amount to the Amount In Authorized Loans
                        creditLineToUpdate.AmountInRequestedLoans = creditLineToUpdate.AmountInRequestedLoans -
                                                                    totalLoans;
                        creditLineToUpdate.AvailableAmount = creditLineToUpdate.AvailableAmount +
                                                             totalLoans;

                        //Remove the Credit Line from the LoanRequest
                        loanRequest.CreditLine = null;
                    }
                    else if (loanRequest.LoanRequestStatus == LoanRequestStatus.Aprobada
                             || loanRequest.LoanRequestStatus == LoanRequestStatus.Corriente
                             || loanRequest.LoanRequestStatus == LoanRequestStatus.Vencida
                             || loanRequest.LoanRequestStatus == LoanRequestStatus.ExtraJudicial
                             ||
                             loanRequest.LoanRequestStatus == LoanRequestStatus.JudicialAltoRiesgo)
                    {
                        //Update the CreditLine amounts
                        //Add the totalLoans amount to the Amount In Authorized Loans
                        creditLineToUpdate.AmountInAuthorizedLoans = creditLineToUpdate.AmountInAuthorizedLoans -
                                                                     totalLoans;
                        creditLineToUpdate.AvailableAmount = creditLineToUpdate.AvailableAmount +
                                                             totalLoans;

                        //Remove the Credit Line from the LoanRequest
                        loanRequest.CreditLine = null;
                    }
                }
            }
            /* 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;
            }
        }
Example #6
0
        /// <summary>
        /// Creates a new Credit Line in the system
        /// </summary>
        /// <param name="financialInstitution">financialInstitution</param>
        /// <param name="username">User name</param>
        /// <param name="creditLine">Credit Line</param>
        public void CreateNewCreditLine(string financialInstitutionName,
            string username,
            CreditLine creditLine)
        {
            try
            {
                IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO ();

                //Verify the name does not exist in the database yet.
                if (financialInstitutionDAO.CreditLineExists (financialInstitutionName,
                                                              creditLine.Name))
                {
                    throw new ZiblerBusinessComponentsException (
                        Resources.CreditLineOperationsMsgCreditLineExists);
                }
                else
                {
                    bool defaultCreditLineExists = financialInstitutionDAO.DefaultCreditLineExists (
                        financialInstitutionName);

                    //See if the parameter was marked as default.
                    //if so, then we need to verify there is no other
                    //parameter marked as such.
                    if (creditLine.IsDefault)
                    {
                        if (defaultCreditLineExists)
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.CreditLineOperationsMsgDefaultCreditLineExists);
                        }
                        else if (creditLine.CreditLineStatus == CreditLineStatus.Suspendida)
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.CreditLineOperationsMsgDefaultCreditLineCannotBeSuspended);
                        }
                    }
                    else
                    {
                        //If this loan parameter is not marked by defualt,
                        //and there is no default parameter in the system,
                        //we raise an exception indicating that they should
                        //select one parameter by default.
                        if (defaultCreditLineExists == false)
                        {
                            throw new ZiblerBusinessComponentsException (
                                Resources.CreditLineOperationsMsgAtLeastOneDefaultCreditLine);
                        }
                    }

                    FinancialInstitution financialInstitution = financialInstitutionDAO.GetFinancialInstitutionByName (
                        financialInstitutionName);

                    /* If financial institution does not exist, raise an exception */
                    if (financialInstitution == null)
                    {
                        throw new ZiblerBusinessComponentsUnknownException ();
                    }
                    else
                    {
                        financialInstitution.AddCreditLine (creditLine);
                    }
                }
            }
            /* 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;
            }
        }