public bool crearCronogramaPagosB(PrestamosModel aprestamo) { int ID = optenerIdPrestamo(aprestamo); MontosCuota mtn = new MontosCuota(); Decimal tea_ = aprestamo.Porcentaje_interes; Decimal monto_ = aprestamo.Montoprestamo; int plazo_ = aprestamo.Plazomeses; Decimal interes_ = aprestamo.Interes_moratorio ?? 0; bool Final = false; mtn = calculaMontos(tea_, monto_, plazo_, interes_); List <CronogramaPagosModel> CronogramaPagosModellist = new List <CronogramaPagosModel>(); for (int i = 0; i < aprestamo.Plazomeses; i++) { CronogramaPagosModel cuota = new CronogramaPagosModel(); cuota.Monto = Convert.ToDecimal(mtn.total); cuota.Prestamo = ID; cuota.Interes = Convert.ToDecimal(mtn.InteresMensual); cuota.DiaPago = aprestamo.Fechaprestamo.AddMonths(i + 1); cuota.Saldo = Convert.ToDecimal(mtn.total); cuota.Seguro = Convert.ToDecimal(mtn.SeguroDesgravamen); cuota.FechaCancelado = null; cuota.Fecha_creacion = aprestamo.Fecha_creacion; cuota.Fecha_modificacion = null; cuota.Usuario_creador = aprestamo.Usuario_creador; cuota.Usuario_modificador = aprestamo.Usuario_modificador; CronogramaPagosModellist.Add(cuota); Final = cuotas.InsertCuotas(cuota); } return(Final); }
/// <summary> /// Selects the Single object of CronogramaPagosModel table. /// </summary> public CronogramaPagosModel GetCronogramaPagosModel(int aID) { CronogramaPagosModel CronogramaPagosModel = null; try { using (var connection = Util.ConnectionFactory.conexion()) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.Parameters.AddWithValue("@ID", aID); command.CommandType = CommandType.StoredProcedure; command.CommandText = "CronogramaPagosModelSelect"; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { int ID = (int)(reader["ID"]); int Prestamo = (int)(reader["Prestamo"]); DateTime FechaPago = (DateTime)(reader["FechaPago"]); decimal Monto = (decimal)(reader["Monto"]); DateTime DiaPago = (DateTime)(reader["DiaPago"]); DateTime FECHA_CREACION = (DateTime)(reader["FECHA_CREACION"]); DateTime?FECHA_MODIFICACION = reader["FECHA_MODIFICACION"] as DateTime?; string USUARIO_CREADOR = (string)(reader["USUARIO_CREADOR"]); string USUARIO_MODIFICADOR = (string)(reader["USUARIO_MODIFICADOR"]); CronogramaPagosModel = new CronogramaPagosModel { Id = ID, Prestamo = Prestamo, Fechapago = FechaPago, Monto = Monto, Diapago = DiaPago, Fecha_creacion = FECHA_CREACION, Fecha_modificacion = FECHA_MODIFICACION, Usuario_creador = USUARIO_CREADOR, Usuario_modificador = USUARIO_MODIFICADOR, }; } } } return(CronogramaPagosModel); } catch (Exception) { return(null); } }
public bool InsertCuotas(CronogramaPagosModel cuota) { try { using (var connection = Util.ConnectionFactory.conexion()) { connection.Open(); SqlTransaction sqlTran = connection.BeginTransaction(); SqlCommand command = connection.CreateCommand(); command.Transaction = sqlTran; command.Parameters.AddWithValue("@Prestamo", cuota.Prestamo); command.Parameters.AddWithValue("@FechaPago", cuota.DiaPago); command.Parameters.AddWithValue("@Monto", cuota.Monto); command.Parameters.AddWithValue("@Amortizacion", cuota.Amortizacion); command.Parameters.AddWithValue("@Interes", cuota.Interes); command.Parameters.AddWithValue("@Seguro", cuota.Seguro); command.Parameters.AddWithValue("@Saldo", cuota.Saldo); command.Parameters.AddWithValue("@FechaCancelado", cuota.FechaCancelado == null ? (object)DBNull.Value : cuota.FechaCancelado); command.Parameters.AddWithValue("@Estado", 1);//cuota.Estado ); command.Parameters.AddWithValue("@FECHA_CREACION", cuota.Fecha_creacion == null ? (object)DBNull.Value : cuota.Fecha_creacion); command.Parameters.AddWithValue("@FECHA_MODIFICACION", cuota.Fecha_modificacion == null ? (object)DBNull.Value : cuota.Fecha_modificacion); command.Parameters.AddWithValue("@USUARIO_CREADOR", cuota.Usuario_creador == null ? (object)DBNull.Value : cuota.Usuario_creador); command.Parameters.AddWithValue("@USUARIO_MODIFICADOR", cuota.Usuario_modificador == null ? (object)DBNull.Value : cuota.Usuario_modificador); command.CommandType = CommandType.StoredProcedure; command.CommandText = "CronogramaPagosInsert"; int afectados = command.ExecuteNonQuery(); // Commit the transaction. sqlTran.Commit(); connection.Close(); connection.Dispose(); if (afectados < 0) { return(true); } else { return(false); } } } catch (Exception) { //throw; return(false); } }
/// <summary> /// Updates a record to the CronogramaPagosModel table. /// returns True if value saved successfully else false /// Throw exception with message value EXISTS if the data is duplicate /// </summary> public bool Update(CronogramaPagosModel aCronogramaPagosModel) { try { using (var connection = Util.ConnectionFactory.conexion()) { connection.Open(); SqlTransaction sqlTran = connection.BeginTransaction(); SqlCommand command = connection.CreateCommand(); command.Transaction = sqlTran; command.Parameters.AddWithValue("@ID", aCronogramaPagosModel.Id); command.Parameters.AddWithValue("@Prestamo", aCronogramaPagosModel.Prestamo); command.Parameters.AddWithValue("@FechaPago", aCronogramaPagosModel.FechaCancelado); command.Parameters.AddWithValue("@Monto", aCronogramaPagosModel.Monto); command.Parameters.AddWithValue("@DiaPago", aCronogramaPagosModel.DiaPago); command.Parameters.AddWithValue("@FECHA_CREACION", aCronogramaPagosModel.Fecha_creacion); command.Parameters.AddWithValue("@FECHA_MODIFICACION", aCronogramaPagosModel.Fecha_modificacion == null ? (object)DBNull.Value : aCronogramaPagosModel.Fecha_modificacion); command.Parameters.AddWithValue("@USUARIO_CREADOR", aCronogramaPagosModel.Usuario_creador); command.Parameters.AddWithValue("@USUARIO_MODIFICADOR", aCronogramaPagosModel.Usuario_modificador == null ? (object)DBNull.Value : aCronogramaPagosModel.Usuario_modificador); command.CommandType = CommandType.StoredProcedure; command.CommandText = "CronogramaPagosModelUpdate"; int afectados = command.ExecuteNonQuery(); // Commit the transaction. sqlTran.Commit(); connection.Close(); connection.Dispose(); if (afectados > 0) { return(true); } else { return(false); } } } catch (Exception) { return(false); } }
/// <summary> /// Selects the Single object of CronogramaPagosModel table. /// </summary> public CronogramaPagosModel GetCronogramaPagosModel(int aID) { CronogramaPagosModel CronogramaPagosModel = null; try { using (var connection = Util.ConnectionFactory.conexion()) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.Parameters.AddWithValue("@ID", aID); command.CommandType = CommandType.StoredProcedure; command.CommandText = "CronogramaPagosModelSelect"; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { int ID = (int)(reader["ID"]); int Prestamo = (int)(reader["Prestamo"]); DateTime?DiaPago = (reader["DiaPago"]) as DateTime?; decimal Monto = (decimal)(reader["Monto"]); decimal Amortizacion = (decimal)(reader["Amortizacion"]); decimal Interes = (decimal)(reader["Interes"]); decimal Seguro = (decimal)(reader["Seguro"]); decimal Saldo = (decimal)(reader["Saldo"]); DateTime?FechaCancelado = (reader["FechaCancelado"]) as DateTime?; //int estado = (int)(reader["Estado"]); bool estado = (bool)(reader["Estado"]); DateTime FECHA_CREACION = (DateTime)(reader["FECHA_CREACION"]); DateTime?FECHA_MODIFICACION = reader["FECHA_MODIFICACION"] as DateTime?; string USUARIO_CREADOR = (string)(reader["USUARIO_CREADOR"]); string USUARIO_MODIFICADOR = reader["USUARIO_MODIFICADOR"] as string; /*string estado_s = "POR PAGAR"; * switch (estado) * { * case 0: * estado_s = "POR PAGAR"; * break; * case 1: * estado_s = "CANCELADO"; * break; * case 2: * estado_s = "ANULADO"; * break; * }*/ CronogramaPagosModel = new CronogramaPagosModel { Id = ID, Prestamo = Prestamo, DiaPago = DiaPago, Monto = Monto, Amortizacion = Amortizacion, Interes = Interes, Seguro = Seguro, Saldo = Saldo, FechaCancelado = FechaCancelado, Estado = estado, EstadoString = "",//estado_s, Fecha_creacion = FECHA_CREACION, Fecha_modificacion = FECHA_MODIFICACION, Usuario_creador = USUARIO_CREADOR, Usuario_modificador = USUARIO_MODIFICADOR, }; } } } return(CronogramaPagosModel); } catch (Exception) { return(null); } }