1306 lines
No EOL
66 KiB
C#
1306 lines
No EOL
66 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Data.Entity.Validation;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Xml;
|
|
using System.Web.Http;
|
|
using ULA.Davivienda.PrendarioModel.Prendario;
|
|
using ULA.Davivienda.PrestamoAutos.Commons;
|
|
using ULA.Davivienda.PrestamoAutos.Json;
|
|
using ULA.Davivienda.PrestamoAutos.WCFAttachmentService;
|
|
using ULA.Davivienda.PrestamoAutos.WCFDocumentos;
|
|
using Ultimus.Utilitarios;
|
|
using System.Configuration;
|
|
using System.Text;
|
|
using System.Web.UI.WebControls;
|
|
using ULA.Davivienda.PrestamoAutos.WCFServiciosCobisGenerales.Pasivas;
|
|
using System.Reflection;
|
|
|
|
namespace ULA.Davivienda.PrestamoAutos.ControllersWebApi
|
|
{
|
|
public class CreaOperacionAPIController : ApiController
|
|
{
|
|
Crypt crypt = new Crypt();
|
|
LogFile log = new LogFile();
|
|
|
|
#region ObtenerSucursalDesembolso
|
|
[HttpGet]
|
|
public List<JsonCatalogos> ObtenerSucursalDesembolso()
|
|
{
|
|
List<JsonCatalogos> ret = new List<JsonCatalogos>();
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
List<Sucursal> list = db.Sucursal.ToList();
|
|
foreach (var ele in list)
|
|
{
|
|
JsonCatalogos catalogo = new JsonCatalogos();
|
|
catalogo.codigo = Convert.ToString(ele.IdSucursal).Trim();
|
|
catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim();
|
|
ret.Add(catalogo);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
}
|
|
return ret;
|
|
}
|
|
#endregion
|
|
|
|
#region ObtenerTipoFormaDesembolso
|
|
[HttpGet]
|
|
public List<JsonCatalogos> ObtenerTipoFormaDesembolso(int IdMoneda)
|
|
{
|
|
List<JsonCatalogos> ret = new List<JsonCatalogos>();
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
List<TipoFormaDesembolso> list = db.TipoFormaDesembolso.Where(q => q.Estado == true && q.IdMoneda == IdMoneda).ToList();
|
|
foreach (var ele in list)
|
|
{
|
|
JsonCatalogos catalogo = new JsonCatalogos();
|
|
catalogo.codigo = Convert.ToString(ele.IdTipoFormaDesembolso).Trim();
|
|
catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim();
|
|
ret.Add(catalogo);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
}
|
|
return ret;
|
|
}
|
|
#endregion
|
|
|
|
#region ObtenerCuentaDesembolso
|
|
[HttpGet]
|
|
public List<JsonConsultarCuentas> ObtenerCuentaDesembolso(int IdAgenciaVehiculo, string IdTipoFormaDesembolso, int IdMoneda)
|
|
{
|
|
List<JsonConsultarCuentas> ret = new List<JsonConsultarCuentas>();
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
string TipoCuenta = string.Empty;
|
|
TipoFormaDesembolso tfd = db.TipoFormaDesembolso.Where(q => q.IdTipoFormaDesembolso == IdTipoFormaDesembolso).FirstOrDefault();
|
|
if (tfd != null)
|
|
{
|
|
List<CuentaAgencia> list = new List<CuentaAgencia>();
|
|
list = db.CuentaAgencia.Where(q => q.TipoCuenta == tfd.Tipo && q.IdMoneda == IdMoneda && q.Estado == true).ToList();
|
|
foreach (var ele in list)
|
|
{
|
|
JsonConsultarCuentas catalogo = new JsonConsultarCuentas();
|
|
catalogo.codigo = Convert.ToString(ele.IdCuentaAgencia).Trim();
|
|
catalogo.numcuenta = Convert.ToString(ele.NumCuenta).Trim();
|
|
catalogo.descripcion = Convert.ToString(ele.Descripcion).Trim();
|
|
ret.Add(catalogo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
}
|
|
return ret;
|
|
}
|
|
#endregion
|
|
|
|
#region ObtenerFormaDesembolso
|
|
[HttpGet]
|
|
public JsonFormaDesembolso ObtenerFormaDesembolso(int IdSolicitud, int? IdFormaDesembolso = null)
|
|
{
|
|
JsonFormaDesembolso ret = new JsonFormaDesembolso();
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
Solicitud sol = db.Solicitud.Where(q => q.IdSolicitud == IdSolicitud).FirstOrDefault();
|
|
if (sol != null)
|
|
{
|
|
Cotizacion cot = db.Cotizacion
|
|
.Include(q => q.SegurosCotizacion)
|
|
.Include("SegurosCotizacion.RubroSeguro")
|
|
.Where(q => q.IdCotizacion == sol.IdCotizacion).FirstOrDefault();
|
|
if (cot != null)
|
|
{
|
|
decimal MontoPrestamo = 0;
|
|
if (cot.MontoPrestamo != null)
|
|
MontoPrestamo = cot.MontoPrestamo.Value;
|
|
|
|
decimal MontoTraspaso = 0;
|
|
if (cot.MontoTraspaso != null)
|
|
MontoTraspaso = cot.MontoTraspaso.Value;
|
|
|
|
decimal MontoConstitucionPrenda = 0;
|
|
if (cot.MontoConstitucionPrenda != null)
|
|
MontoConstitucionPrenda = cot.MontoConstitucionPrenda.Value;
|
|
|
|
decimal MontoComision = 0;
|
|
if (cot.MontoComision != null)
|
|
MontoComision = cot.MontoComision.Value;
|
|
|
|
ret.IdAgenciaVehiculo = cot.IdAgenciaVehiculo;
|
|
ret.IdMoneda = cot.IdMoneda;
|
|
ret.MontoPrestamo = MontoPrestamo;
|
|
ret.MontoComision = MontoComision;
|
|
|
|
SegurosCotizacion SegVida = cot.SegurosCotizacion.Where(q => q.RubroSeguro.IdTipoRubroSeguro == (int)EnumTipoRubroSeguro.Vida).FirstOrDefault();
|
|
if (SegVida != null)
|
|
ret.SegVida = SegVida.Monto;
|
|
|
|
|
|
SegurosCotizacion SegAuto = cot.SegurosCotizacion.Where(q => q.RubroSeguro.IdTipoRubroSeguro == (int)EnumTipoRubroSeguro.Auto).FirstOrDefault();
|
|
if (SegAuto != null)
|
|
ret.SegAuto = SegAuto.Monto;
|
|
|
|
|
|
//switch (cot.IdTipoGracia)
|
|
//{
|
|
// case EnumGracia.EnSeguroAuto:
|
|
// case EnumGracia.EnInteresEnCapitalEnSeguroAuto:
|
|
// ret.SegAuto = 0;
|
|
// break;
|
|
//}
|
|
|
|
|
|
|
|
SegurosCotizacion SegDesempleo = cot.SegurosCotizacion.Where(q => q.RubroSeguro.IdTipoRubroSeguro == (int)EnumTipoRubroSeguro.Desempleo).FirstOrDefault();
|
|
if (SegDesempleo != null)
|
|
ret.SegDesempleo = SegDesempleo.Monto;
|
|
|
|
#region Inserta Forma de Desembolso Automática
|
|
// Steven Rojas Inserta Forma de Desembolso Automática
|
|
FormaDesembolso FormaDesembolsoAnterior = db.FormaDesembolso.Where(q => q.IdSolicitud == IdSolicitud && q.TipoRegistro == "A").FirstOrDefault();
|
|
if (ret.SegAuto != 0)
|
|
{
|
|
if (FormaDesembolsoAnterior != null)
|
|
{
|
|
EliminarFormaDesembolso(IdSolicitud, FormaDesembolsoAnterior.IdFormaDesembolso);
|
|
}
|
|
FormaDesembolso FormaDesembolsoAutomatica = new FormaDesembolso();
|
|
FormaDesembolsoAutomatica.IdSolicitud = IdSolicitud;
|
|
|
|
CuentaAgencia cuentaAgencia = db.CuentaAgencia.Where(q => q.IdMoneda == ret.IdMoneda && q.IdTipoFuncionalidadCuenta == (int)EnumFuncionalidadCuenta.CuentaPolizaVehiculo && q.Estado == true).FirstOrDefault();
|
|
TipoFormaDesembolso tipoFormaDesembolso = db.TipoFormaDesembolso.Where(q => q.IdMoneda == ret.IdMoneda && q.Tipo == cuentaAgencia.TipoCuenta && q.Estado == true).FirstOrDefault();
|
|
FormaDesembolsoAutomatica.FormaDesembolso1 = tipoFormaDesembolso.IdTipoFormaDesembolso;
|
|
FormaDesembolsoAutomatica.ValorInicial = ret.MontoPrestamo.ToString();
|
|
FormaDesembolsoAutomatica.IdSucursal = sol.IdSucursal;
|
|
FormaDesembolsoAutomatica.Comision = ret.MontoComision.ToString();
|
|
FormaDesembolsoAutomatica.Monto = ret.SegAuto;
|
|
FormaDesembolsoAutomatica.IdCuentaAgencia = cuentaAgencia.IdCuentaAgencia;
|
|
FormaDesembolsoAutomatica.SegDesempleo = ret.SegDesempleo.ToString();
|
|
FormaDesembolsoAutomatica.SegVida = ret.SegVida.ToString();
|
|
FormaDesembolsoAutomatica.TipoRegistro = "A";
|
|
|
|
JsonResponseBase retGuardar = GuardarFormaDesembolso(FormaDesembolsoAutomatica);
|
|
if (retGuardar.CodigoRespuesta != "EXITOSO")
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (FormaDesembolsoAnterior != null)
|
|
{
|
|
EliminarFormaDesembolso(IdSolicitud, FormaDesembolsoAnterior.IdFormaDesembolso);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
ret.FormaDesembolsoList = (from q in db.FormaDesembolso
|
|
where q.IdSolicitud == IdSolicitud
|
|
&& (IdFormaDesembolso == null || IdFormaDesembolso.Value == q.IdFormaDesembolso)
|
|
select new JsonFormaDesembolsoDetalle
|
|
{
|
|
Beneficiario = q.Beneficiario,
|
|
Comision = q.Comision,
|
|
DescCuenta = q.CuentaAgencia == null ? string.Empty : q.CuentaAgencia.NumCuenta,
|
|
DescSucursal = q.Sucursal == null ? string.Empty : q.Sucursal.Descripcion,
|
|
FormaDesembolso1 = q.FormaDesembolso1,
|
|
IdCuentaAgencia = q.IdCuentaAgencia,
|
|
IdFormaDesembolso = q.IdFormaDesembolso,
|
|
IdSolicitud = q.IdSolicitud,
|
|
IdSucursal = q.IdSucursal,
|
|
Monto = q.Monto,
|
|
SecCobis = q.SecCobis,
|
|
SegDesempleo = q.SegDesempleo,
|
|
SegVida = q.SegVida,
|
|
TipoRegistro = q.TipoRegistro,
|
|
ValorInicial = q.ValorInicial,
|
|
XmlCobis = q.XmlCobis
|
|
}).ToList();
|
|
|
|
//DataFaseII df2 = db.DataFaseII.Where(q => q.IdSolicitud == IdSolicitud).FirstOrDefault();
|
|
//if (df2 != null)
|
|
//{
|
|
// if (!string.IsNullOrEmpty(df2.NoOperacion) && df2.NoOperacion != "0")
|
|
// {
|
|
// if (df2.MontoDesembolso != null)
|
|
// ret.MontoDesembolso = df2.MontoDesembolso.Value;
|
|
// }
|
|
//}
|
|
|
|
if (ret.MontoDesembolso == 0)
|
|
{
|
|
decimal SumMontoSeguros = 0;
|
|
if (cot.SegurosCotizacion != null)
|
|
{
|
|
SumMontoSeguros = cot.SegurosCotizacion.Where(q => q.Monto != null && q.RubroSeguro.IdTipoRubroSeguro != (int)EnumTipoRubroSeguro.Auto).Sum(q => q.Monto.Value);
|
|
//switch (cot.IdTipoGracia)
|
|
//{
|
|
// case EnumGracia.EnSeguroAuto:
|
|
// case EnumGracia.EnInteresEnCapitalEnSeguroAuto:
|
|
// SumMontoSeguros = cot.SegurosCotizacion.Where(q => q.Monto != null && q.RubroSeguro.IdTipoRubroSeguro != (int)EnumTipoRubroSeguro.Auto).Sum(q => q.Monto.Value);
|
|
// break;
|
|
// default:
|
|
// SumMontoSeguros = cot.SegurosCotizacion.Where(q => q.Monto != null).Sum(q => q.Monto.Value);
|
|
// break;
|
|
//} //Steven Rojas
|
|
}
|
|
|
|
ret.MontoDesembolso = MontoPrestamo - (MontoTraspaso + MontoConstitucionPrenda + MontoComision + SumMontoSeguros);
|
|
}
|
|
|
|
List<FormaDesembolso> list = db.FormaDesembolso.Where(q => q.IdSolicitud == IdSolicitud && q.Monto != null).ToList();
|
|
if (list.Count() > 0)
|
|
ret.MontoLiquidato = list.Sum(q => q.Monto.Value);
|
|
|
|
ret.MontoPendiente = ret.MontoDesembolso - ret.MontoLiquidato;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
}
|
|
return ret;
|
|
}
|
|
#endregion
|
|
|
|
#region GuardarFormaDesembolso
|
|
[HttpPost]
|
|
public JsonResponseBase GuardarFormaDesembolso([FromBody] FormaDesembolso Model)
|
|
{
|
|
JsonResponseBase ret = new JsonResponseBase();
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
FormaDesembolso ele = db.FormaDesembolso.Where(q => q.IdSolicitud == Model.IdSolicitud && q.IdFormaDesembolso == Model.IdFormaDesembolso).FirstOrDefault();
|
|
if (ele == null)
|
|
{
|
|
int id = 1;
|
|
if (db.FormaDesembolso.Count() > 0)
|
|
id = db.FormaDesembolso.Max(q => q.IdFormaDesembolso) + 1;
|
|
Model.IdFormaDesembolso = id;
|
|
db.FormaDesembolso.Add(Model);
|
|
}
|
|
else
|
|
{
|
|
db.Entry(ele).State = EntityState.Detached;
|
|
db.FormaDesembolso.Attach(Model);
|
|
db.Entry(Model).State = System.Data.Entity.EntityState.Modified;
|
|
}
|
|
db.SaveChanges();
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
}
|
|
return ret;
|
|
}
|
|
#endregion
|
|
|
|
#region EliminarFormaDesembolso
|
|
[HttpGet]
|
|
public JsonResponseBase EliminarFormaDesembolso(int IdSolicitud, int IdFormaDesembolso)
|
|
{
|
|
JsonResponseBase ret = new JsonResponseBase();
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
FormaDesembolso ele = db.FormaDesembolso.Where(q => q.IdSolicitud == IdSolicitud && q.IdFormaDesembolso == IdFormaDesembolso).FirstOrDefault();
|
|
if (ele != null)
|
|
{
|
|
db.FormaDesembolso.Remove(ele);
|
|
db.SaveChanges();
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
}
|
|
return ret;
|
|
}
|
|
#endregion
|
|
|
|
#region getDataModel
|
|
[HttpGet]
|
|
public JsonCrearOperacion getDataModel(int NoSolicitud, string etapa)
|
|
{
|
|
JsonCrearOperacion respuesta = new JsonCrearOperacion();
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
|
|
respuesta.LineaCredito = ConfigurationManager.AppSettings["Cartera.LineaCredito"].ToString();
|
|
|
|
respuesta.Solicitud = (from s in db.Solicitud
|
|
.Include(e => e.Cotizacion)
|
|
.Include(e => e.Solicitante)
|
|
.Include(e => e.DataFaseII)
|
|
.Include(e => e.CuentasInternas)
|
|
.Include(e => e.PropositoCredito)
|
|
where s.IdSolicitud == NoSolicitud
|
|
select s).FirstOrDefault();
|
|
|
|
if (respuesta.Solicitud != null)
|
|
{
|
|
if (respuesta.Solicitud.IdPropositoCredito == null)
|
|
{
|
|
int nParamIdPropositoCredito = int.Parse(ConfigurationManager.AppSettings["Cartera.IdPropositoCredito"].ToString());
|
|
respuesta.Solicitud.PropositoCredito = db.PropositoCredito.Where(e => e.IdPropositoCredito == nParamIdPropositoCredito).FirstOrDefault();
|
|
|
|
if (respuesta.Solicitud.PropositoCredito != null)
|
|
respuesta.Solicitud.IdPropositoCredito = respuesta.Solicitud.PropositoCredito.IdPropositoCredito;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (respuesta.Solicitud.Cotizacion != null)
|
|
{
|
|
respuesta.Solicitud.Cotizacion.EjecutivoCotizacion = db.EjecutivoCotizacion.Where(x => x.IdCotizacion == respuesta.Solicitud.IdCotizacion).FirstOrDefault();
|
|
respuesta.Solicitud.Cotizacion.CondicionesTasaCotizacion = db.CondicionesTasaCotizacion.Where(x => x.IdCotizacion == respuesta.Solicitud.IdCotizacion).ToList();
|
|
respuesta.Solicitud.Cotizacion.AgenciaVehiculo = db.AgenciaVehiculo.Where(x => x.IdAgenciaVehiculo == respuesta.Solicitud.Cotizacion.IdAgenciaVehiculo).FirstOrDefault();
|
|
respuesta.Solicitud.Cotizacion.Moneda = db.Moneda.Where(x => x.IdMoneda == respuesta.Solicitud.Cotizacion.IdMoneda).FirstOrDefault();
|
|
respuesta.JsonProgramaCrediticio = ObtenerDetalleProgramaCrediticio(respuesta.Solicitud.Cotizacion.IdProgramaCrediticio, respuesta.Solicitud.Cotizacion.IdCampanna,
|
|
respuesta.Solicitud.Cotizacion.IdMoneda, respuesta.Solicitud.Cotizacion.IdTipoVehiculo,
|
|
respuesta.Solicitud.Cotizacion.IdAnnoVehiculo, respuesta.Solicitud.Cotizacion.EsColaborador);
|
|
|
|
|
|
string ConfiguracionTipoOperacionCredito = ConfigurationManager.AppSettings["Cartera.TipoOperacionCredito"].ToString();
|
|
string[] arrConfiguracionTipoOperacionCredito = ConfiguracionTipoOperacionCredito.Split(new char[] { '|' });
|
|
|
|
|
|
if (respuesta.Solicitud.Cotizacion.EsColaborador == true)
|
|
{
|
|
respuesta.TipoOperacion = arrConfiguracionTipoOperacionCredito[1];
|
|
}
|
|
else
|
|
{
|
|
respuesta.TipoOperacion = arrConfiguracionTipoOperacionCredito[0];
|
|
}
|
|
}
|
|
|
|
if (respuesta.Solicitud.DataFaseII.FirstOrDefault() != null)
|
|
{
|
|
foreach (var df in respuesta.Solicitud.DataFaseII)
|
|
{
|
|
df.TipoCuenta = db.TipoCuenta.Where(x => x.IdTipoCuenta == df.IdTipoCuenta).FirstOrDefault();
|
|
df.TipoEnvioCuenta = db.TipoEnvioCuenta.Where(x => x.IdTipoEnvioCuenta == df.IdTipoEnvioCuenta).FirstOrDefault();
|
|
df.FormaPago = db.FormaPago.Where(x => x.IdFormaPago == df.IdFormaPago).FirstOrDefault();
|
|
df.CuentasInternas = db.CuentasInternas.Where(x => x.IdCuenta == df.IdCuenta).FirstOrDefault();
|
|
}
|
|
}
|
|
|
|
if (respuesta.Solicitud.Solicitante.FirstOrDefault() != null)
|
|
{
|
|
foreach (var s in respuesta.Solicitud.Solicitante)
|
|
{
|
|
s.Cliente = db.Cliente.Where(x => x.IdCliente == s.IdCliente).FirstOrDefault();
|
|
s.Cliente.InformacionLaboralCliente = db.InformacionLaboralCliente.Where(x => x.IdCliente == s.IdCliente).ToList();
|
|
s.Cliente.TipoIdentificacion = db.TipoIdentificacion.Where(x => x.IdTipoIdentificacion == s.Cliente.IdTipoIdentificacion).FirstOrDefault();
|
|
s.Cliente.TelefonoCliente = db.TelefonoCliente.Where(x => x.IdCliente == s.IdCliente).ToList();
|
|
s.Cliente.EmailCliente = db.EmailCliente.Where(x => x.IdCliente == s.IdCliente).ToList();
|
|
s.Cliente.DireccionCliente = db.DireccionCliente.Where(x => x.IdCliente == s.IdCliente).ToList();
|
|
s.Cliente.CondicionVivienda = db.CondicionVivienda.Where(x => x.IdCondicionVivienda == s.Cliente.IdCondicionVivienda).FirstOrDefault();
|
|
}
|
|
}
|
|
|
|
if (respuesta.Solicitud != null)
|
|
respuesta.Solicitud.Sucursal = db.Sucursal.Where(x => x.IdSucursal == respuesta.Solicitud.IdSucursal).FirstOrDefault();
|
|
|
|
|
|
int IdEtapa = db.Etapas.Where(x => x.DescripcionEtapa.Trim() == etapa).FirstOrDefault().IdEtapa;
|
|
|
|
List<HistorialDecision> ListaHistorial = (from hd in db.HistorialDecision
|
|
.Include(x => x.Decision)
|
|
.Include(x => x.Motivo)
|
|
where hd.IdSolicitud == NoSolicitud && hd.IdEtapa == IdEtapa
|
|
select hd).ToList();
|
|
if (ListaHistorial.FirstOrDefault() != null)
|
|
{
|
|
int IdHistorial = ListaHistorial.Max(q => q.IdHistorialDecision);
|
|
|
|
respuesta.HistorialDecision = (from hd in ListaHistorial
|
|
where hd.IdHistorialDecision == IdHistorial
|
|
select hd).FirstOrDefault();
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Error al obtener la información de la operación.");
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
Exception ESC = ex.InnerException;
|
|
while (ESC != null)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ESC);
|
|
ESC = ESC.InnerException;
|
|
}
|
|
|
|
respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
respuesta.DescripcionRespuesta = "Error al obtener la información de la operación." + ex.Message;
|
|
|
|
}
|
|
return respuesta;
|
|
}
|
|
#endregion
|
|
|
|
#region ObtenerDetalleProgramaCrediticio
|
|
public List<JsonProgramaCrediticio> ObtenerDetalleProgramaCrediticio(int? id = null, int? id2 = null, int? id3 = null, int? id4 = null, int? id5 = null, bool? id6 = null, int? id7 = null)
|
|
{
|
|
List<JsonProgramaCrediticio> listaJsonProgramaCrediticio = null;
|
|
|
|
try
|
|
{
|
|
|
|
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
|
|
|
|
listaJsonProgramaCrediticio = (from pc in db.ProgramaCrediticioCondiciones
|
|
.Include(e => e.ProgramaCrediticio)
|
|
.Include(e => e.Campanna)
|
|
.Include(e => e.Moneda)
|
|
.Include(e => e.TipoVehiculo)
|
|
.Include(e => e.AnnoVehiculo)
|
|
.Include(e => e.ProgramaCrediticioCondicionesTasa)
|
|
.Where(pc => pc.IdProgramaCrediticio == id
|
|
&& pc.IdCampanna == id2
|
|
&& pc.IdMoneda == id3
|
|
&& pc.IdTipoVehiculo == id4
|
|
&& pc.IdAnnoVehiculo == id5
|
|
&& pc.EsColaborador == id6
|
|
&& pc.Estado == true)
|
|
//&& pc.PeriodoMesesCredito == id7)
|
|
select new JsonProgramaCrediticio
|
|
{
|
|
IdProgramaCrediticio = pc.IdProgramaCrediticio,
|
|
Descripcion = pc.ProgramaCrediticio.Descripcion,
|
|
|
|
Campanna = pc.Campanna,
|
|
IdCampanna = pc.Campanna.IdCampanna,
|
|
DescripcionCampanna = pc.Campanna.Descripcion,
|
|
|
|
Moneda = pc.Moneda,
|
|
IdMoneda = pc.Moneda.IdMoneda,
|
|
DescripcionMoneda = pc.Moneda.Descripcion,
|
|
|
|
TipoVehiculo = pc.TipoVehiculo,
|
|
IdTipoVehiculo = pc.TipoVehiculo.IdTipoVehiculo,
|
|
DescripcionTipoVehiculo = pc.TipoVehiculo.Descripcion,
|
|
|
|
AnnoVehiculo = pc.AnnoVehiculo,
|
|
IdAnnoVehiculo = pc.AnnoVehiculo.IdAnnoVehiculo,
|
|
DescripcionAnnoVehiculo = pc.AnnoVehiculo.Descripcion,
|
|
|
|
ProgramaCrediticioCondicionesTasa = pc.ProgramaCrediticioCondicionesTasa,
|
|
|
|
PorcComision = pc.PorcComision,
|
|
PorcPrimaMinima = pc.PorcPrimaMinima,
|
|
PorcIngresoMinReq = pc.PorcIngresoMinReq,
|
|
PeriodoMesesCredito = pc.PeriodoMesesCredito,
|
|
PeriodoMesesGracia = pc.PeriodoMesesGracia,
|
|
Estado = pc.Estado
|
|
}).ToList();
|
|
|
|
|
|
|
|
foreach (JsonProgramaCrediticio x in listaJsonProgramaCrediticio)
|
|
{
|
|
foreach (ProgramaCrediticioCondicionesTasa y in x.ProgramaCrediticioCondicionesTasa)
|
|
{
|
|
y.TipoTasa = db.TipoTasa.Where(e => e.IdTipoTasa == y.IdTipoTasa).FirstOrDefault();
|
|
y.TipoTasaReferencia = db.TipoTasaReferencia.Where(e => e.IdTipoTasaReferencia == y.IdTipoTasaReferencia).FirstOrDefault();
|
|
y.PeriodoReajuste = db.PeriodoReajuste.Where(e => e.IdPeriodoReajuste == y.IdPeriodoReajuste).FirstOrDefault();
|
|
}
|
|
|
|
|
|
x.ProgramaCrediticioCondicionesTasaAdapted = (from p in x.ProgramaCrediticioCondicionesTasa
|
|
where p.Estado == true
|
|
select new JsonProgramaCrediticioCondicionesTasa()
|
|
{
|
|
DescripcionTipoTasa = p.TipoTasa.Descripcion,
|
|
DescripcionTipoTasaReferencia = p.TipoTasaReferencia.Descripcion,
|
|
DescripcionPeriodoReajuste = p.PeriodoReajuste.Descripcion,
|
|
Estado = p.Estado,
|
|
IdPeriodoReajuste = p.IdPeriodoReajuste,
|
|
IdProgramaCrediticioCondiciones = p.IdProgramaCrediticioCondiciones,
|
|
IdProgramaCrediticioCondicionesTasa = p.IdProgramaCrediticioCondicionesTasa,
|
|
IdTipoTasa = p.IdTipoTasa,
|
|
IdTipoTasaReferencia = p.IdTipoTasaReferencia,
|
|
Periodo = p.Periodo,
|
|
PeriodoReajuste = p.PeriodoReajuste,
|
|
PlazoMeses = p.PlazoMeses,
|
|
ProgramaCrediticioCondiciones = p.ProgramaCrediticioCondiciones,
|
|
Spread = p.Spread,
|
|
TasaMinima = p.TasaMinima,
|
|
TasaReferencia = p.TasaReferencia,
|
|
TipoTasa = p.TipoTasa,
|
|
TipoTasaReferencia = p.TipoTasaReferencia,
|
|
TasaInteresFinal = (p.TasaReferencia + p.Spread)
|
|
|
|
}).ToList();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
}
|
|
|
|
return listaJsonProgramaCrediticio;
|
|
}
|
|
#endregion
|
|
|
|
#region GuardarDatos
|
|
[HttpPost]
|
|
public JsonResponseBase GuardarDatos([FromBody] DataFaseII Model)
|
|
{
|
|
bool IsNewDataFaseII = false;
|
|
JsonResponseBase respuesta = new JsonResponseBase();
|
|
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
|
|
try
|
|
{
|
|
Solicitud _modelSolicitud = db.Solicitud.Where(h => h.IdSolicitud == Model.IdSolicitud).FirstOrDefault();
|
|
_modelSolicitud.IdPropositoCredito = Model.Solicitud.IdPropositoCredito;
|
|
|
|
db.Entry(_modelSolicitud).State = EntityState.Detached;
|
|
db.Solicitud.Attach(_modelSolicitud);
|
|
db.Entry(_modelSolicitud).State = System.Data.Entity.EntityState.Modified;
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex2);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DataFaseII _modelDataFaseII = db.DataFaseII.Where(a => a.IdSolicitud == Model.IdSolicitud).FirstOrDefault();
|
|
|
|
//Si no existen registros
|
|
if (_modelDataFaseII == null)
|
|
{
|
|
_modelDataFaseII = new DataFaseII();
|
|
|
|
int IdDataFaseII = 1;
|
|
if (db.DataFaseII.Count() > 0)
|
|
IdDataFaseII = db.DataFaseII.Max(q => q.IdDataFaseII) + 1;
|
|
|
|
_modelDataFaseII.IdDataFaseII = IdDataFaseII;
|
|
IsNewDataFaseII = true;
|
|
|
|
}
|
|
|
|
_modelDataFaseII.IdSolicitud = Model.IdSolicitud;
|
|
_modelDataFaseII.TipoOperacion = Model.TipoOperacion;
|
|
_modelDataFaseII.NLinea = Model.NLinea;
|
|
_modelDataFaseII.ProgCrediticio = Model.ProgCrediticio;
|
|
_modelDataFaseII.Clasificacion = Model.Clasificacion;
|
|
_modelDataFaseII.NumeroGarantia = Model.NumeroGarantia;
|
|
_modelDataFaseII.ConsecutivoBien = Model.ConsecutivoBien;
|
|
_modelDataFaseII.PolizaAuto = Model.PolizaAuto;
|
|
_modelDataFaseII.CrearCuenta = Model.CrearCuenta;
|
|
_modelDataFaseII.IdTipoCuenta = Model.IdTipoCuenta;
|
|
_modelDataFaseII.IdTipoEnvioCuenta = string.IsNullOrWhiteSpace(Model.IdTipoEnvioCuenta) ? null : Model.IdTipoEnvioCuenta;
|
|
_modelDataFaseII.IdFormaPago = Model.IdFormaPago;
|
|
_modelDataFaseII.IdCuenta = Model.IdCuenta;
|
|
_modelDataFaseII.NoOperacion = Model.NoOperacion;
|
|
_modelDataFaseII.FechaInicio = Model.FechaInicio;
|
|
_modelDataFaseII.InstruccionesEspeciales = Model.InstruccionesEspeciales;
|
|
|
|
|
|
if (IsNewDataFaseII)
|
|
{
|
|
db.DataFaseII.Add(_modelDataFaseII);
|
|
}
|
|
else
|
|
{
|
|
db.Entry(_modelDataFaseII).State = EntityState.Detached;
|
|
db.DataFaseII.Attach(_modelDataFaseII);
|
|
db.Entry(_modelDataFaseII).State = System.Data.Entity.EntityState.Modified;
|
|
}
|
|
|
|
db.SaveChanges();
|
|
respuesta.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
}
|
|
catch (DbEntityValidationException ex)
|
|
{
|
|
var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
|
|
var fullErrorMessage = string.Join("; ", errorMessages);
|
|
var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
|
|
|
|
UltimusLogs.logger.Error(exceptionMessage);
|
|
|
|
respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
respuesta.DescripcionRespuesta = exceptionMessage;
|
|
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", exceptionMessage);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
Exception Exp = ex.InnerException;
|
|
while (Exp != null)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", Exp);
|
|
Exp = Exp.InnerException;
|
|
}
|
|
}
|
|
|
|
return respuesta;
|
|
}
|
|
#endregion
|
|
|
|
#region ObtenerSucursal
|
|
[HttpGet]
|
|
public ICollection<Sucursal> ObtenerSucursal()
|
|
{
|
|
ICollection<Sucursal> sucursal = null;
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
sucursal = db.Sucursal.Where(d => d.Estado == true).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
}
|
|
return sucursal;
|
|
}
|
|
#endregion
|
|
|
|
#region EnviarDocumentoPrenda
|
|
[HttpPost]
|
|
public JsonResponseBase EnviarDocumentoPrenda(JsonEnviarEmailRequest req)
|
|
{
|
|
JsonResponseBase ret = new JsonResponseBase();
|
|
List<string> emails = new List<string>();
|
|
try
|
|
{
|
|
|
|
|
|
if (req.IsEmailInputList)
|
|
emails.AddRange(req.EmailsInputList);
|
|
|
|
if (req.IsEmailAgenciaList)
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
Cotizacion cot = db.Cotizacion.Where(q => q.IdCotizacion == req.IdCotizacion).FirstOrDefault();
|
|
if (cot != null)
|
|
{
|
|
var emailsAgencia = db.CorreoAgencia
|
|
.Include(x => x.SubAgenciaVehiculo)
|
|
.Include(x => x.SubAgenciaVehiculo.AgenciaVehiculo)
|
|
.Where(p => p.IdSubAgenciaVehiculo == cot.IdSubAgenciaVehiculo
|
|
&& p.Estado == true)
|
|
//&& p.SubAgenciaVehiculo.Estado == true
|
|
//&& p.SubAgenciaVehiculo.AgenciaVehiculo.Estado == true)
|
|
.Select(p => p.Email).ToList();
|
|
|
|
if (emailsAgencia != null) { emails.AddRange(emailsAgencia); }
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (emails != null && emails.Count > 0)
|
|
{
|
|
DocumentosAPIController api = new DocumentosAPIController();
|
|
JsonDocumentoResponse res = api.ImprimirDocumentoPrendaDinamico(req.IdCotizacion, 0);
|
|
|
|
if (res.CodigoRespuesta == TipoCodigoRespuesta.EXITOSO.ToString())
|
|
{
|
|
string Subject = Convert.ToString(ConfigurationManager.AppSettings["NotificaciónDocumentoPrenda.Subject"]);
|
|
string Body = Convert.ToString(ConfigurationManager.AppSettings["NotificaciónDocumentoPrenda.Body"]);
|
|
bool IsBodyHtml = Convert.ToBoolean(ConfigurationManager.AppSettings["NotificaciónDocumentoPrenda.IsBodyHtml"]);
|
|
List<string> Attach = new List<string>() { res.path };
|
|
List<string> MailTo = new List<string>(emails);
|
|
EmailManager em = new EmailManager();
|
|
em.Send(Body, IsBodyHtml, Subject, Attach, MailTo);
|
|
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
ret.DescripcionRespuesta = "EXITOSO"; ;
|
|
}
|
|
else
|
|
{
|
|
ret.CodigoRespuesta = res.CodigoRespuesta;
|
|
ret.DescripcionRespuesta = res.DescripcionRespuesta;
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
Exception Exp = ex.InnerException;
|
|
while (Exp != null)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", Exp);
|
|
Exp = Exp.InnerException;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
#endregion
|
|
|
|
#region CrearCuenta
|
|
|
|
[HttpPost]
|
|
public JsonResponseBase CrearCuenta(JsonCrearCuenta datos)
|
|
{
|
|
JsonResponseBase ret = new JsonResponseBase();
|
|
Solicitud solicitud = null;
|
|
Cliente cliente = null;
|
|
DireccionCliente direccion = null;
|
|
EmailCliente email = null;
|
|
TelefonoCliente telefono = null;
|
|
InformacionIngresosCliente ingresos = null;
|
|
|
|
try
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 1");
|
|
|
|
PrendarioContext db = new PrendarioContext();
|
|
solicitud = db.Solicitud
|
|
.Include("Cotizacion")
|
|
.Include("Sucursal")
|
|
.FirstOrDefault(t => t.IdSolicitud == datos.IdSolicitud);
|
|
|
|
solicitud.AplicaIntegracionConCartera = solicitud.AplicaIntegracionConCartera.HasValue ? solicitud.AplicaIntegracionConCartera : false;
|
|
if (db.CuentasInternas.Count(t => t.IdSolicitud == datos.IdSolicitud) > 0 || !solicitud.AplicaIntegracionConCartera.Value)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
return ret;
|
|
}
|
|
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 2");
|
|
|
|
int idCliente = db.Solicitante.First(t => t.IdSolicitud == datos.IdSolicitud && t.EsPrincipal == true).IdCliente;
|
|
cliente = db.Cliente.FirstOrDefault(t => t.IdCliente == idCliente);
|
|
|
|
if (datos.envioEstadoCuenta == "DR")
|
|
direccion = db.DireccionCliente.FirstOrDefault(t => t.IdCliente == idCliente && t.IdTipoDireccion == "DM");
|
|
|
|
if (datos.envioEstadoCuenta == "DL")
|
|
direccion = db.DireccionCliente.FirstOrDefault(t => t.IdCliente == idCliente && t.IdTipoDireccion == "DC");
|
|
|
|
if (datos.envioEstadoCuenta == "ER")
|
|
email = db.EmailCliente.FirstOrDefault(t => t.IdCliente == idCliente && t.IdTipoEmail == 1);
|
|
|
|
if (datos.envioEstadoCuenta == "EL")
|
|
email = db.EmailCliente.FirstOrDefault(t => t.IdCliente == idCliente && t.IdTipoEmail == 2);
|
|
|
|
if (datos.envioEstadoCuenta == "FR")
|
|
telefono = db.TelefonoCliente.FirstOrDefault(t => t.IdCliente == idCliente && t.IdTipoTelefono == "DMF");
|
|
|
|
if (datos.envioEstadoCuenta == "FL")
|
|
telefono = db.TelefonoCliente.FirstOrDefault(t => t.IdCliente == idCliente && t.IdTipoTelefono == "DCF");
|
|
|
|
ingresos = db.InformacionIngresosCliente.FirstOrDefault(t => t.IdCliente == idCliente);
|
|
|
|
if (solicitud == null)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString();
|
|
ret.DescripcionRespuesta = "IdSolicitud no existe";
|
|
return ret;
|
|
}
|
|
|
|
if (cliente == null)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString();
|
|
ret.DescripcionRespuesta = "Cliente no existe";
|
|
return ret;
|
|
}
|
|
|
|
if (ingresos == null)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString();
|
|
ret.DescripcionRespuesta = "Informacion de ingresos no existe";
|
|
return ret;
|
|
}
|
|
|
|
if (solicitud.Cotizacion == null)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString();
|
|
ret.DescripcionRespuesta = "Cotizacion no existe";
|
|
return ret;
|
|
}
|
|
|
|
if (solicitud.Sucursal == null)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString();
|
|
ret.DescripcionRespuesta = "Sucursal no existe";
|
|
return ret;
|
|
}
|
|
|
|
if (direccion == null && email == null && telefono == null)
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString();
|
|
ret.DescripcionRespuesta = "La dirección seleccionada para el envío de estados de cuenta no se encuentra registrada";
|
|
return ret;
|
|
}
|
|
|
|
if ((direccion == null || direccion.Secuencial == null) && (email == null || email.Secuencial == null) && (telefono == null || telefono.Secuencial == null))
|
|
{
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString();
|
|
ret.DescripcionRespuesta = "El deudor no tiene secuencial para este tipo de envío de estados de cuenta";
|
|
return ret;
|
|
}
|
|
|
|
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 3");
|
|
|
|
|
|
//TipoProducto
|
|
string ConfiguracionTipoOperacionCredito = ConfigurationManager.AppSettings["Cartera.TipoOperacionCredito"].ToString();
|
|
string[] arrConfiguracionTipoOperacionCredito = ConfiguracionTipoOperacionCredito.Split(new char[] { '|' });
|
|
|
|
string TipoProducto = string.Empty;
|
|
if (solicitud.Cotizacion.EsColaborador == true)
|
|
{
|
|
TipoProducto = arrConfiguracionTipoOperacionCredito[1];
|
|
}
|
|
else
|
|
{
|
|
TipoProducto = arrConfiguracionTipoOperacionCredito[0];
|
|
}
|
|
|
|
|
|
|
|
|
|
CrearCuentaRequest req = new CrearCuentaRequest()
|
|
{
|
|
Incidente = solicitud.Incidente.ToString(),
|
|
NumeroOperacion = datos.noOperacion,
|
|
TipoCuentaNueva = datos.tipoCuenta,
|
|
|
|
IngresoNetoCol = ((ingresos.SalarioNetoCol == null ? 0 : ingresos.SalarioNetoCol) +
|
|
(ingresos.OtrosNetoCol == null ? 0 : ingresos.OtrosNetoCol) +
|
|
(ingresos.OffShoreNetoCol == null ? 0 : ingresos.OffShoreNetoCol) +
|
|
(ingresos.VariableNetoCol == null ? 0 : ingresos.VariableNetoCol)).ToString(),
|
|
|
|
IngresoNetoDol = ((ingresos.SalarioNetoDol == null ? 0 : ingresos.SalarioNetoDol) +
|
|
(ingresos.OtrosNetoDol == null ? 0 : ingresos.OtrosNetoDol) +
|
|
(ingresos.OffShoreNetoDol == null ? 0 : ingresos.OffShoreNetoDol) +
|
|
(ingresos.VariableNetoDol == null ? 0 : ingresos.VariableNetoDol)).ToString(),
|
|
|
|
IngresoBrutoCol = ((ingresos.SalarioBrutoCol == null ? 0 : ingresos.SalarioBrutoCol) +
|
|
(ingresos.VariableBrutoCol == null ? 0 : ingresos.VariableBrutoCol)).ToString(),
|
|
|
|
IngresoBrutoDol = ((ingresos.SalarioBrutoDol == null ? 0 : ingresos.SalarioBrutoDol) +
|
|
(ingresos.VariableBrutoDol == null ? 0 : ingresos.VariableBrutoDol)).ToString(),
|
|
|
|
|
|
CoEnvioEstadoCuenta = datos.envioEstadoCuenta.Substring(0, 1),
|
|
SecEnvioEstadoCuenta = datos.envioEstadoCuenta.Substring(0, 1) == "D" ? direccion.Secuencial.ToString() : (datos.envioEstadoCuenta.Substring(0, 1) == "E" ? email.Secuencial.ToString() : (datos.envioEstadoCuenta.Substring(0, 1) == "F" ? telefono.Secuencial.ToString() : "")),
|
|
CodigoOficina = solicitud.Sucursal.IdSucursal.ToString(),
|
|
Moneda = "20",
|
|
MontoApertura = solicitud.Cotizacion.MontoPrestamo.ToString(),
|
|
Ente = cliente.Ente,
|
|
TipoProducto = TipoProducto,
|
|
CodigoOficial = datos.usuario,
|
|
strUsername = datos.usuario,
|
|
strPassword = "",
|
|
strProceso = datos.proceso
|
|
};
|
|
|
|
try
|
|
{
|
|
string sb = "";
|
|
sb += "\n" + "CodigoOficial:" + req.CodigoOficial == null ? "null" : req.CodigoOficial.ToString();
|
|
sb += "\n" + "CodigoOficina:" + req.CodigoOficina == null ? "null" : req.CodigoOficina.ToString();
|
|
sb += "\n" + "CoEnvioEstadoCuenta:" + req.CoEnvioEstadoCuenta == null ? "null" : req.CoEnvioEstadoCuenta.ToString();
|
|
sb += "\n" + "Ente:" + req.Ente == null ? "null" : req.Ente.ToString();
|
|
sb += "\n" + "Incidente:" + req.Incidente == null ? "null" : req.Incidente.ToString();
|
|
sb += "\n" + "IngresoBrutoCol:" + req.IngresoBrutoCol == null ? "null" : req.IngresoBrutoCol.ToString();
|
|
sb += "\n" + "IngresoBrutoDol:" + req.IngresoBrutoDol == null ? "null" : req.IngresoBrutoDol.ToString();
|
|
sb += "\n" + "IngresoNetoCol:" + req.IngresoNetoCol == null ? "null" : req.IngresoNetoCol.ToString();
|
|
sb += "\n" + "IngresoNetoDol:" + req.IngresoNetoDol == null ? "null" : req.IngresoNetoDol.ToString();
|
|
sb += "\n" + "Moneda:" + req.Moneda == null ? "null" : req.Moneda.ToString();
|
|
sb += "\n" + "MontoApertura:" + req.MontoApertura == null ? "null" : req.MontoApertura.ToString();
|
|
sb += "\n" + "NumeroOperacion:" + req.NumeroOperacion == null ? "null" : req.NumeroOperacion.ToString();
|
|
sb += "\n" + "SecEnvioEstadoCuenta:" + req.SecEnvioEstadoCuenta == null ? "null" : req.SecEnvioEstadoCuenta.ToString();
|
|
sb += "\n" + "strPassword:" + req.strPassword == null ? "null" : req.strPassword.ToString();
|
|
sb += "\n" + "strProceso:" + req.strProceso == null ? "null" : req.strProceso.ToString();
|
|
sb += "\n" + "strUsername:" + req.strUsername == null ? "null" : req.strUsername.ToString();
|
|
sb += "\n" + "TipoCuentaNueva:" + req.TipoCuentaNueva == null ? "null" : req.TipoCuentaNueva.ToString();
|
|
sb += "\n" + "TipoProducto:" + req.TipoProducto == null ? "null" : req.TipoProducto.ToString();
|
|
|
|
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 4 =>" + sb);
|
|
|
|
}
|
|
catch (Exception ex3)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 4 =>" + "Estructura no capturada" + ex3.Message);
|
|
}
|
|
|
|
|
|
|
|
|
|
CrearCuentaResponse res = null;
|
|
using (PasivasClient wcf = new PasivasClient())
|
|
{
|
|
res = wcf.CrearCuenta(req);
|
|
}
|
|
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 5 =>" + res.ToString());
|
|
|
|
if (res.errCode != "00")
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", res.errMessage);
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString();
|
|
ret.DescripcionRespuesta = res.errMessage;
|
|
return ret;
|
|
}
|
|
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 6");
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
xmlDoc.LoadXml(res.resultado);
|
|
int IdCuenta = db.CuentasInternas.Select(t => t.IdCuenta).DefaultIfEmpty(0).Max() + 1;
|
|
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 7=>" + res.resultado);
|
|
|
|
foreach (XmlNode n in xmlDoc.SelectNodes("//Resultado/CuentaAhorros/CUENTA"))
|
|
{
|
|
db.CuentasInternas.Add(new CuentasInternas()
|
|
{
|
|
IdCuenta = IdCuenta++,
|
|
IdSolicitud = datos.IdSolicitud,
|
|
CuentaNueva = true,
|
|
IdTipoCuenta = null, //n.SelectSingleNode("TIPOCTANUEVA").InnerText
|
|
Ncuenta = n.SelectSingleNode("NUMCTA").InnerText,
|
|
IdMoneda = int.Parse(n.SelectSingleNode("MONEDACTA").InnerText)
|
|
});
|
|
}
|
|
db.SaveChanges();
|
|
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", "Flag 8");
|
|
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
return ret;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
ret.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
ret.DescripcionRespuesta = ex.ToString();
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Enviar
|
|
[HttpPost]
|
|
public JsonResponseBase Enviar([FromBody] JsonEnviarCreaOperacion _model)
|
|
{
|
|
JsonResponseBase respuesta = null;
|
|
GlobalAPIController global = null;
|
|
JsonCrearOperacionResponse respCreaOperacion = null;
|
|
JsonResponseBase respTasaEscalonada = null;
|
|
JsonResponseBase respCodeudor = null;
|
|
|
|
|
|
try
|
|
{
|
|
respuesta = new JsonResponseBase();
|
|
global = new GlobalAPIController();
|
|
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
|
|
//****************************************
|
|
//Si la decision es Ir a Firma Documentos
|
|
//****************************************
|
|
if (_model.IdDecision.Trim() == Convert.ToString((int)EnumDecision.IrAFirmaDocumentos))
|
|
{
|
|
|
|
Solicitud _modelSolicitud = (db.Solicitud.Where(e => e.IdSolicitud == _model.IdSolicitud)).FirstOrDefault();
|
|
_modelSolicitud.AplicaIntegracionConCartera = _modelSolicitud.AplicaIntegracionConCartera.HasValue ? _modelSolicitud.AplicaIntegracionConCartera : false;
|
|
|
|
if (_modelSolicitud.AplicaIntegracionConCartera.Value)
|
|
{
|
|
//**********************************************************************
|
|
//Invoca la creación de la operacion en Cartera
|
|
//**********************************************************************
|
|
respCreaOperacion = global.CrearOperacion(new JsonCrearOperacionRequest()
|
|
{
|
|
IdSolicitud = (int)_model.IdSolicitud,
|
|
ProcessName = _model.Process,
|
|
UserId = _model.UserId.Split(new char[] { '/' })[1]
|
|
});
|
|
|
|
|
|
if (respCreaOperacion.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString())
|
|
{
|
|
throw new Exception(respCreaOperacion.DescripcionRespuesta);
|
|
}
|
|
|
|
//**********************************************************************
|
|
//Invoca el registro de la tasa escalonada para la operacion en Cartera
|
|
//**********************************************************************
|
|
respTasaEscalonada = global.RegistrarTasascalonada(new JsonRegistrarTasaEscalonadaRequest()
|
|
{
|
|
FechaPrimerPago = respCreaOperacion.FechaPrimerPagoCapital,
|
|
NoOperacion = respCreaOperacion.NoOperacion,
|
|
IdSolicitud = (int)_model.IdSolicitud,
|
|
ProcessName = _model.Process,
|
|
UserId = _model.UserId.Split(new char[] { '/' })[1]
|
|
});
|
|
|
|
|
|
|
|
if (respTasaEscalonada.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString())
|
|
{
|
|
throw new Exception(respTasaEscalonada.DescripcionRespuesta);
|
|
}
|
|
|
|
|
|
//**********************************************************************
|
|
//Invoca el registro de la tasa escalonada para la operacion en Cartera
|
|
//**********************************************************************
|
|
respCodeudor = global.RegistrarCodeudor(new JsonRegistrarTasaEscalonadaRequest()
|
|
{
|
|
IdSolicitud = (int)_model.IdSolicitud,
|
|
ProcessName = _model.Process,
|
|
UserId = _model.UserId.Split(new char[] { '/' })[1]
|
|
});
|
|
|
|
|
|
if (respCodeudor.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString())
|
|
{
|
|
throw new Exception(respCodeudor.DescripcionRespuesta);
|
|
}
|
|
|
|
|
|
//**********************************************************************
|
|
//Realiza el envío de a prenda a los email de los abogados
|
|
//**********************************************************************
|
|
if (_model.DocumentoPrenda != null)
|
|
{
|
|
var respEmailDocPrenda = EnviarDocumentoPrenda(_model.DocumentoPrenda);
|
|
if (respEmailDocPrenda.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString())
|
|
{
|
|
throw new Exception(respEmailDocPrenda.DescripcionRespuesta);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
respuesta = global.Enviar(_model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
finally
|
|
{
|
|
//respuesta.Alertas = respCreaOperacion.Alertas;
|
|
}
|
|
return respuesta;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region ValidarCuadreFormasDesembolso
|
|
[HttpPost]
|
|
public JsonResponseBase ValidarCuadreFormasDesembolso([FromBody] FormaDesembolso _model)
|
|
{
|
|
JsonFormaDesembolso ret = new JsonFormaDesembolso();
|
|
JsonResponseBase resp = new JsonResponseBase();
|
|
Solicitud sol = null;
|
|
try
|
|
{
|
|
using (PrendarioContext db = new PrendarioContext())
|
|
{
|
|
sol = db.Solicitud.Where(q => q.IdSolicitud == _model.IdSolicitud).FirstOrDefault();
|
|
if (sol == null)
|
|
{
|
|
throw new Exception("No se pudo obtener la información de la solicitud");
|
|
}
|
|
|
|
Cotizacion cot = db.Cotizacion
|
|
.Include(q => q.SegurosCotizacion)
|
|
.Include("SegurosCotizacion.RubroSeguro")
|
|
.Where(q => q.IdCotizacion == sol.IdCotizacion).FirstOrDefault();
|
|
if (cot == null)
|
|
{
|
|
throw new Exception("No se pudo obtener la información de la cotizacion");
|
|
}
|
|
|
|
|
|
decimal MontoPrestamo = 0;
|
|
if (cot.MontoPrestamo != null)
|
|
MontoPrestamo = cot.MontoPrestamo.Value;
|
|
|
|
decimal MontoTraspaso = 0;
|
|
if (cot.MontoTraspaso != null)
|
|
MontoTraspaso = cot.MontoTraspaso.Value;
|
|
|
|
decimal MontoConstitucionPrenda = 0;
|
|
if (cot.MontoConstitucionPrenda != null)
|
|
MontoConstitucionPrenda = cot.MontoConstitucionPrenda.Value;
|
|
|
|
decimal MontoComision = 0;
|
|
if (cot.MontoComision != null)
|
|
MontoComision = cot.MontoComision.Value;
|
|
|
|
ret.IdAgenciaVehiculo = cot.IdAgenciaVehiculo;
|
|
ret.IdMoneda = cot.IdMoneda;
|
|
ret.MontoPrestamo = MontoPrestamo;
|
|
ret.MontoComision = MontoComision;
|
|
|
|
SegurosCotizacion SegVida = cot.SegurosCotizacion.Where(q => q.RubroSeguro.IdTipoRubroSeguro == (int)EnumTipoRubroSeguro.Vida).FirstOrDefault();
|
|
if (SegVida != null)
|
|
ret.SegVida = SegVida.Monto;
|
|
|
|
|
|
SegurosCotizacion SegAuto = cot.SegurosCotizacion.Where(q => q.RubroSeguro.IdTipoRubroSeguro == (int)EnumTipoRubroSeguro.Auto).FirstOrDefault();
|
|
if (SegAuto != null)
|
|
ret.SegAuto = SegAuto.Monto;
|
|
|
|
|
|
//switch (cot.IdTipoGracia)
|
|
//{
|
|
// case EnumGracia.EnSeguroAuto:
|
|
// case EnumGracia.EnInteresEnCapitalEnSeguroAuto:
|
|
// ret.SegAuto = 0;
|
|
// break;
|
|
//}
|
|
|
|
|
|
SegurosCotizacion SegDesempleo = cot.SegurosCotizacion.Where(q => q.RubroSeguro.IdTipoRubroSeguro == (int)EnumTipoRubroSeguro.Desempleo).FirstOrDefault();
|
|
if (SegDesempleo != null)
|
|
ret.SegDesempleo = SegDesempleo.Monto;
|
|
|
|
|
|
//DataFaseII df2 = db.DataFaseII.Where(q => q.IdSolicitud == _model.IdSolicitud).FirstOrDefault();
|
|
//if (df2 != null)
|
|
//{
|
|
// if (!string.IsNullOrEmpty(df2.NoOperacion) && df2.NoOperacion != "0")
|
|
// {
|
|
// if (df2.MontoDesembolso != null)
|
|
// ret.MontoDesembolso = df2.MontoDesembolso.Value;
|
|
// }
|
|
//}
|
|
|
|
|
|
if (ret.MontoDesembolso == 0)
|
|
{
|
|
decimal SumMontoSeguros = 0;
|
|
if (cot.SegurosCotizacion != null)
|
|
{
|
|
SumMontoSeguros = cot.SegurosCotizacion.Where(q => q.Monto != null && q.RubroSeguro.IdTipoRubroSeguro != (int)EnumTipoRubroSeguro.Auto).Sum(q => q.Monto.Value);
|
|
//switch (cot.IdTipoGracia)
|
|
//{
|
|
// case EnumGracia.EnSeguroAuto:
|
|
// case EnumGracia.EnInteresEnCapitalEnSeguroAuto:
|
|
|
|
// break;
|
|
// default:
|
|
// SumMontoSeguros = cot.SegurosCotizacion.Where(q => q.Monto != null).Sum(q => q.Monto.Value);
|
|
// break;
|
|
//} // Steven Rojas
|
|
}
|
|
|
|
ret.MontoDesembolso = MontoPrestamo - (MontoTraspaso + MontoConstitucionPrenda + MontoComision + SumMontoSeguros);
|
|
}
|
|
|
|
List<FormaDesembolso> list = db.FormaDesembolso.Where(q => q.IdSolicitud == _model.IdSolicitud && q.Monto != null).ToList();
|
|
if (list.Count() > 0)
|
|
ret.MontoLiquidato = list.Sum(q => q.Monto.Value);
|
|
|
|
ret.MontoPendiente = ret.MontoDesembolso - ret.MontoLiquidato;
|
|
|
|
}
|
|
|
|
if (ret.MontoPendiente == 0 || sol.AplicaIntegracionConCartera != true )
|
|
{
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
resp.DescripcionRespuesta = "EXITOSO";
|
|
}
|
|
else
|
|
{
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.ADVERTENCIA.ToString();
|
|
resp.DescripcionRespuesta = "Estimado usuario, el saldo registrado en las formas de desembolso no cuadra a cero.<br>Por favor verifique antes de completar la etapa.";
|
|
}
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.EscribirArchivo("ULA.Davivienda.PrestamoAutos", ex);
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
resp.DescripcionRespuesta = ex.ToString();
|
|
}
|
|
return resp;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
} |