public static List<Referencias> ObtenerReferencias(int idCuenta)
         {
             DetalleCuenta Detcuenta = new DetalleCuenta();
             Detcuenta = dal.ObtenerDetalleCuenta(idCuenta);

             List<Referencias> Ref = new List<Referencias>();

             Referencias referencia = new Referencias();

             referencia.Referencia = Detcuenta.Referencia1;
             referencia.LadaRef = Detcuenta.LadaRef1;
             referencia.TeleRef = Detcuenta.TeleRef1;
             referencia.Parentesco = Detcuenta.parantesco1;
             

             Ref.Add(referencia);

             referencia = new Referencias();

             referencia.Referencia = Detcuenta.Referencia2;
             referencia.LadaRef = Detcuenta.LadaRef2;
             referencia.TeleRef = Detcuenta.TeleRef2;
             referencia.Parentesco = Detcuenta.parantesco2;

             Ref.Add(referencia);

             return Ref;

         }
        public static double ObtenerCat(int idcuenta)
        {
            double CAT= 0.00;
            double TIR = 0.00;
            
            double guess = 0.01;
            DetalleCuenta cuenta = new DetalleCuenta();
            List<DataResultCredito.Usp_ObtenerTablaAmortizacion> recibos = new List<DataResultCredito.Usp_ObtenerTablaAmortizacion>();
            cuenta = Gestiones.DetalleCuentaBll.ObtenerDetalleCuenta(idcuenta);
            recibos = Creditos.TBRecibosBll.ObtenerTBRecibos(idcuenta);
            int totalPagos=0;
           switch(cuenta.frecuencia)
           {
               case "M":
                   
                       totalPagos = 12;
                       break;
                   
               case "Q":
                   
                       totalPagos = 24;
                       break;
               default:

                       totalPagos = 12;
                       break;
                  
                   
           }

            
            decimal Capital = cuenta.Capital;
            
            decimal Ergoacion = cuenta.Erogacion;
            decimal valorinicial = -1 * Capital;
            int RecibosTotales = cuenta.Rectot;
            double[] valores = new double[RecibosTotales+1];
            for (int i = 0; i <= RecibosTotales; i++)
            {
                if (i > 0)
                {
                    valorinicial = recibos[i-1].Capital + recibos[i-1].Interes;
                    valores[i] = Convert.ToDouble(valorinicial);
                }
                else
                {
                    valores[i] = Convert.ToDouble(valorinicial);
                }
                            

            }
            TIR = Financial.IRR(ref valores, guess);
            CAT = Math.Round((Math.Pow(1 + TIR, totalPagos) - 1) * 100, 2);
            return CAT;
        }
 public static DetalleCuenta ObtenerDetalleCuenta(int idCuenta)
 {
     DetalleCuenta detalle = new DetalleCuenta();
     
     return dal.ObtenerDetalleCuenta(idCuenta);
 }
        public DetalleCuenta ObtenerDetalleCuenta(int idCuenta)
        {

            DetalleCuenta resultado = new DetalleCuenta();
            try
			{
				//Obtener DbCommand para ejcutar el Store Procedure
                using (DbCommand com = db.GetStoredProcCommand("Gestiones.Sel_DetalleCuenta"))
				{
					//Parametros
                   
                    db.AddInParameter(com, "@IdCuenta", DbType.Int32, idCuenta);
				
					//Ejecucion de la Consulta
					using (IDataReader reader = db.ExecuteReader(com))
					{
						if (reader != null)
						{
                          
							//Le    ctura de los datos del ResultSet
                            while (reader.Read())
                            {
                                if (!reader.IsDBNull(0)) resultado.Idcuenta = Convert.ToDecimal(reader[0]);
                                if (!reader.IsDBNull(1)) resultado.Cliente = reader[1].ToString();
                                if (!reader.IsDBNull(2)) resultado.Direccion = reader[2].ToString();
                                if (!reader.IsDBNull(3)) resultado.Colonia = reader[3].ToString();
                                if (!reader.IsDBNull(4)) resultado.Ciudad = reader[4].ToString();
                                if (!reader.IsDBNull(5)) resultado.Estado = reader[5].ToString();
                                if (!reader.IsDBNull(6)) resultado.Rfc = reader[6].ToString();
                                if (!reader.IsDBNull(7)) resultado.Telefono = reader[7].ToString();
                                if (!reader.IsDBNull(8)) resultado.Celular = reader[8].ToString();
                                if (!reader.IsDBNull(9)) resultado.Referencia1 = reader[9].ToString();
                                if (!reader.IsDBNull(10)) resultado.LadaRef1 = reader[10].ToString();
                                if (!reader.IsDBNull(11)) resultado.TeleRef1 = reader[11].ToString();
                                if (!reader.IsDBNull(12)) resultado.Referencia2 = reader[12].ToString();
                                if (!reader.IsDBNull(13)) resultado.LadaRef2 = reader[13].ToString();
                                if (!reader.IsDBNull(14)) resultado.TeleRef2 = reader[14].ToString();
                                if (!reader.IsDBNull(15)) resultado.FchCredito = Convert.ToDateTime(reader[15]);
                                if (!reader.IsDBNull(16)) resultado.Producto = reader[16].ToString();
                                if (!reader.IsDBNull(17)) resultado.Erogacion = Convert.ToDecimal(reader[17]);
                                if (!reader.IsDBNull(18)) resultado.Capital = Convert.ToDecimal(reader[18]);
                                if (!reader.IsDBNull(19)) resultado.SdoVencido = Convert.ToInt32(reader[19]);
                                if (!reader.IsDBNull(20)) resultado.SdoVigente = Convert.ToInt32(reader[20]);
                                if (!reader.IsDBNull(21)) resultado.Diasinac = Convert.ToInt32(reader[21]);
                                if (!reader.IsDBNull(22)) resultado.Diasven = Convert.ToInt32(reader[22]);
                                if (!reader.IsDBNull(23)) resultado.Saldocredi = Convert.ToInt32(reader[23]);
                                if (!reader.IsDBNull(24)) resultado.Sigpag = reader[24].ToString();
                                if (!reader.IsDBNull(25)) resultado.Recexi = Convert.ToInt32(reader[25]);
                                if (!reader.IsDBNull(26)) resultado.Recven = Convert.ToInt32(reader[26]);
                                if (!reader.IsDBNull(27)) resultado.Recsal = Convert.ToInt32(reader[27]);
                                if (!reader.IsDBNull(28)) resultado.Rectot = Convert.ToInt32(reader[28]);
                                if (!reader.IsDBNull(29)) resultado.IdSolicitud = Convert.ToDecimal(reader[29]);
                                if (!reader.IsDBNull(30)) resultado.parantesco1 = reader[30].ToString();
                                if (!reader.IsDBNull(31)) resultado.parantesco2 = reader[31].ToString();
                                if (!reader.IsDBNull(32)) resultado.ReferenciaB = Convert.ToInt32(reader[32]);
                                if (!reader.IsDBNull(33)) resultado.frecuencia = reader[33].ToString();
                                if (!reader.IsDBNull(34)) resultado.BalanceTotal = Convert.ToInt32(reader[34]);
                                if (!reader.IsDBNull(35)) resultado.Banco = reader[35].ToString();
                                if (!reader.IsDBNull(36)) resultado.Clabe = reader[36].ToString();
                                if (!reader.IsDBNull(37)) resultado.EstatusBanco = reader[37].ToString();
                                if (!reader.IsDBNull(38)) resultado.FlagMoraInicioMes = reader[38].ToString();
                                if (!reader.IsDBNull(39)) resultado.FlagMoraActual = reader[39].ToString();
                                if (!reader.IsDBNull(40)) resultado.GestorAsigando = reader[40].ToString();
                                if (!reader.IsDBNull(41)) resultado.FechaUltimoPago = reader[41].ToString();

                                
		
                            }
                        }
                        reader.Close();
						reader.Dispose();
					}

					//Cierre de la conexion y liberacion de memoria
					com.Dispose();
				}
			}
			catch (Exception ex)
			{
				throw ex;
			}
			return resultado;

        }