1350 lines
No EOL
66 KiB
C#
1350 lines
No EOL
66 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
using ULA.Cathay.Credito.Json;
|
|
using ULA.Cathay.Credito.WCFDocumentos;
|
|
using ULA.Cathay.CreditoModel.Credito;
|
|
using ULA.Cathay.CreditoModel.DAL.Credito;
|
|
using Ultimus.Interfaces;
|
|
using Ultimus.Utilitarios;
|
|
using System.Data.Entity;
|
|
using Ultimus.Interfaces.UltimusForm;
|
|
using Newtonsoft.Json;
|
|
using System.Web;
|
|
using System.Data.Entity.Validation;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using ULA.Cathay.CreditoModel.Entidades;
|
|
using ULA.Cathay.CreditoModel.DAL.ComponentManager;
|
|
|
|
namespace ULA.Cathay.Credito.ControllersWebApi
|
|
{
|
|
public sealed class ExtentedStringWriter : StringWriter
|
|
{
|
|
private readonly Encoding stringWriterEncoding;
|
|
public ExtentedStringWriter(StringBuilder builder, Encoding desiredEncoding)
|
|
: base(builder)
|
|
{
|
|
this.stringWriterEncoding = desiredEncoding;
|
|
}
|
|
|
|
public override Encoding Encoding
|
|
{
|
|
get
|
|
{
|
|
return this.stringWriterEncoding;
|
|
}
|
|
}
|
|
}
|
|
|
|
public partial class DocumentosAPIController : ApiController
|
|
{
|
|
private UltimusLogs logs = new UltimusLogs("DocumentosAPIController");
|
|
|
|
public DocumentosAPIController()
|
|
{
|
|
GlobalAPIController.SetRegionalConfig();
|
|
}
|
|
|
|
|
|
|
|
private string getRutaPlantillasDocumentos()
|
|
{
|
|
return new ObtieneParametros().GetValueKeyRegedit("RutaPlantillasDocumentosCATHAY", false);
|
|
}
|
|
string VALOR_PORDEFECTO_CAMPOS_VACIOS = "NO INDICADO";
|
|
|
|
/// <summary>
|
|
/// colocar solo documentos que se requieren adjuntar al ser solicitados
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public ResultadoGeneracion GenerarDocumento(JsonSolicitud model)
|
|
{
|
|
ResultadoGeneracion resultado = new ResultadoGeneracion();
|
|
|
|
if (model == null || model.Solicitud == null)
|
|
{
|
|
resultado.Error = "Se requiere el número de solicitud para generar el documento";
|
|
return resultado;
|
|
}
|
|
|
|
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
switch (model.DetalleDocumento.IdTipoDocumento)
|
|
{
|
|
case 37://codigo de documento oferta
|
|
resultado = ObtenerValorCriteriosSolicitud(new Oferta() { IdSolicitud = model.Solicitud.IdSolicitud });
|
|
break;
|
|
case 1://codigo de documento oferta
|
|
resultado = GenerarCaratulaCredito(model.Solicitud);
|
|
break;
|
|
case 82://codigo de Contrato de línea de crédito
|
|
resultado = GenerarContratoLineaCredito(model);
|
|
break;
|
|
case 83://codigo de documento Contrato de sobregiro
|
|
resultado = GenerarContratoSobregiro(model);
|
|
break;
|
|
case 84://codigo de documento Letra de cambio (Operaciones crediticias)
|
|
resultado = GenerarLetraCambioOperacionesCrediticias(model);
|
|
break;
|
|
case 85://codigo de documento Mandato
|
|
resultado = GenerarDocMandato(model);
|
|
break;
|
|
case 86://codigo de documento Pagaré
|
|
resultado = GenerarDocPagare(model);
|
|
break;
|
|
case 87://codigo de documento Carta de solicitud de desembolso
|
|
resultado = GenerarCartaSolicitudDesembolso(model);
|
|
|
|
break;
|
|
case 88://codigo de documento Carta misiva
|
|
resultado = GenerarCartaMisiva(model);
|
|
break;
|
|
case 89://codigo de documento Contrato cesión de derechos con responsabilidad
|
|
resultado = GenerarContratoCesionDerechoResponsabilidad(model);
|
|
break;
|
|
case 90://codigo de documento Contrato cesión de derechos sin responsabilidad
|
|
resultado = GenerarContratoCesionSinResponsabilidad(model);
|
|
break;
|
|
case 91://codigo de documento Letra de cambio (Descuento de facturas)
|
|
resultado = GenerarLetraCambioDescuentoFacturas(model);
|
|
break;
|
|
case 92://codigo de documento Misiva cesión total
|
|
resultado = GenerarMisivaCesionTotal(model);
|
|
break;
|
|
case 93://codigo de documento Carta de condiciones
|
|
resultado = GenerarCartaCondiciones(model);
|
|
break;
|
|
case 94://codigo de documento Carta de pignoración
|
|
resultado = GenerarCartaPignoracion(model);
|
|
break;
|
|
case 95://codigo de documento Contrato de crédito especifico
|
|
resultado = GenerarContratoCreditoEspecifico(model);
|
|
break;
|
|
case 96://codigo de documento Contrato cesión universal cuenta seca
|
|
resultado = GenerarContratoCesionUniversalCtaSeca(model);
|
|
break;
|
|
case 41://codigo de documento de Aceptación Empresarial
|
|
resultado = GenerarAceptacionEmpresarialExcel(model);
|
|
break;
|
|
default:
|
|
resultado.Error = "No se ha definido el documento que está solicitando";
|
|
break;
|
|
}
|
|
}
|
|
|
|
return resultado;
|
|
}
|
|
|
|
[HttpPost]
|
|
public ResultadoGeneracion ObtenerValorCriteriosSolicitud(Oferta modelo)
|
|
{
|
|
OfertaDAL Conn = new OfertaDAL();
|
|
ResultadoGeneracion respuesta = new ResultadoGeneracion();
|
|
Entrada obj = new Entrada();
|
|
DocumentoDB doc = new DocumentoDB();
|
|
Cliente Deudor = new Cliente();
|
|
ClienteDAL ConnCliente = new ClienteDAL();
|
|
|
|
|
|
try
|
|
{
|
|
modelo = Conn.ObtenerOfertaSolicitud(modelo);
|
|
if (modelo != null)
|
|
{
|
|
|
|
obj.TipoDb = TipoDB.SQLServer;
|
|
obj.Formato = FormatoSalida.pdf;
|
|
obj.ConnectionString = null;
|
|
doc.Ruta = string.Format("{0}\\{1}", getRutaPlantillasDocumentos(), "Propuestas.dotx");
|
|
doc.NumeroCopias = 1;
|
|
|
|
obj.NombreDocumentoGenerado = string.Format("{0}_{1}_{2}", "PropuestaSolicitud", modelo.IdSolicitud, DateTime.Now.ToString("dd.MM.yyyy_hh.mm.ss"));
|
|
|
|
doc.CamposAdicionales = new List<Campo>();
|
|
|
|
Deudor = ConnCliente.ObtenerPrincipal(modelo.IdSolicitud);
|
|
doc.CamposAdicionales.Add(new Campo() { Nombre = "NombreEmpresa", Valor = Deudor.IdTipoCliente == 2 ? Deudor.RazonSocial : string.Format("{0} {1} {2} {3}", Deudor.PrimerNombre, Deudor.SegundoNombre, Deudor.PrimerApellido, Deudor.SegundoApellido) });
|
|
|
|
|
|
doc.CamposAdicionales.Add(new Campo() { Nombre = "NombreEjecutivo", Valor = modelo.Ejecutivo != null ? modelo.Ejecutivo.Nombre : "" });
|
|
|
|
|
|
string DescripcionTipoPropuesta = string.Empty;
|
|
if (modelo.OfertaFacilidades != null)
|
|
{
|
|
DescripcionTipoPropuesta = modelo.OfertaFacilidades.Where(c => c.Eslinea == true && c.Secuencia != 0).Any() ? "una línea de crédito revolutiva" : string.Empty;
|
|
DescripcionTipoPropuesta += modelo.OfertaFacilidades.Where(c => c.Eslinea != true && c.Secuencia != 0).Any() ? (!string.IsNullOrEmpty(DescripcionTipoPropuesta) ? " y trámite específico" : "un trámite específico") : string.Empty;
|
|
}
|
|
|
|
doc.CamposAdicionales.Add(new Campo() { Nombre = "DescripcionTipoPropuesta", Valor = (string.IsNullOrEmpty(DescripcionTipoPropuesta) ? "una línea de crédito revolutiva" : DescripcionTipoPropuesta) });
|
|
doc.CamposAdicionales.Add(new Campo() { Nombre = "FechaDocumento", Valor = DateTime.Now.ToString("dddd dd") + " de " + DateTime.Now.ToString("MMMM") + " de " + DateTime.Now.ToString("yyyy") });
|
|
|
|
doc.TablasAdicionales = new List<Tabla>();
|
|
FilaResultado fr;
|
|
int FIla_titulo = 1;
|
|
|
|
for (int i = 0; i <= 1; i++)
|
|
{
|
|
int FIla = 1;
|
|
Tabla DetalleLinea = new Tabla();
|
|
DetalleLinea.FilasResultado = new List<FilaResultado>();
|
|
DetalleLinea.Puntero = i == 1 ? "DetalleEspecifico" : "DetalleLinea";
|
|
DetalleLinea.NombreEstiloPersonalizadoFilas = "Cathay_Valores_Linea";
|
|
|
|
var facilidades = modelo.OfertaFacilidades.Where(q => q.Eslinea == (i == 0 ? true : false) && q.Secuencia != 0).ToList();
|
|
|
|
if (facilidades != null && facilidades.Count > 0)
|
|
{
|
|
if (DetalleLinea.Puntero == "DetalleLinea")
|
|
{
|
|
DetalleLinea.FilasResultado.Add(
|
|
new FilaResultado
|
|
{
|
|
Columnas = new List<ColumnaResultado> {
|
|
new ColumnaResultado{
|
|
Valor=string.Format("{0}. Condiciones para Línea",FIla_titulo ),
|
|
NombreEstiloPersonalizado_Individual="Cathay_Titulo_Linea"
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
DetalleLinea.FilasResultado.Add(
|
|
new FilaResultado
|
|
{
|
|
Columnas = new List<ColumnaResultado> {
|
|
new ColumnaResultado{
|
|
Valor=string.Format("Monto línea global:"),
|
|
NombreEstiloPersonalizado_Individual="Cathay_Detalles_Linea"
|
|
}
|
|
,new ColumnaResultado{
|
|
Valor= string.Format("{1}{0:N}", (modelo.MontoPropuestoLinea.HasValue ? modelo.MontoPropuestoLinea : 0),(modelo.IdMonedaMontoPropuestoLinea==1?"$":"¢"))
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
DetalleLinea.FilasResultado.Add(
|
|
new FilaResultado
|
|
{
|
|
Columnas = new List<ColumnaResultado> {
|
|
new ColumnaResultado{
|
|
Valor=string.Format("Plazo de la línea:"),
|
|
NombreEstiloPersonalizado_Individual="Cathay_Detalles_Linea"
|
|
}
|
|
,new ColumnaResultado{
|
|
Valor= string.Format("{0} {1}", string.IsNullOrWhiteSpace(modelo.PlazoLinea) == false ? modelo.PlazoLinea : VALOR_PORDEFECTO_CAMPOS_VACIOS, "meses")
|
|
}
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
DetalleLinea.FilasResultado.Add(
|
|
new FilaResultado
|
|
{
|
|
Columnas = new List<ColumnaResultado> {
|
|
new ColumnaResultado{
|
|
Valor=string.Format("{0}. Condiciones para Específicos",FIla_titulo),
|
|
NombreEstiloPersonalizado_Individual="Cathay_Titulo_Linea"
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
foreach (OfertaFacilidades Facilidad in facilidades)
|
|
{
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " " });
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " " });
|
|
DetalleLinea.FilasResultado.Add(fr);
|
|
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = string.Format(" {0}.{1} Plan de Inversión{2}", FIla_titulo, FIla, (DetalleLinea.Puntero == "DetalleEspecifico" ? ":" : " de la línea de crédito:")) });
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = Facilidad.TipoFacilidad.Descripcion.Trim() });
|
|
DetalleLinea.FilasResultado.Add(fr);
|
|
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " " });
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " " });
|
|
DetalleLinea.FilasResultado.Add(fr);
|
|
|
|
#region MontoPropuesto
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " Monto:" });
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = string.Format("{1}{0:N}", (Facilidad.MontoPropuesto.HasValue ? Facilidad.MontoPropuesto.Value : 0), (Facilidad.IdMonedaMontoPropuesto == 1 ? "$" : "¢")) });
|
|
|
|
if (Facilidad.MontoPropuesto.HasValue)
|
|
DetalleLinea.FilasResultado.Add(fr);
|
|
#endregion
|
|
|
|
#region Plazo
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " Plazo:" });
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = !string.IsNullOrWhiteSpace(Facilidad.PlazoMaximoPropuesto) ? Facilidad.PlazoMaximoPropuesto : VALOR_PORDEFECTO_CAMPOS_VACIOS });
|
|
|
|
if (!string.IsNullOrWhiteSpace(Facilidad.PlazoMaximoPropuesto)) DetalleLinea.FilasResultado.Add(fr);
|
|
#endregion
|
|
|
|
#region Forma de Pago
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " Forma de pago:" });
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = Facilidad.FormasPagos != null ? Facilidad.FormasPagos.Descripcion : VALOR_PORDEFECTO_CAMPOS_VACIOS });
|
|
|
|
if (Facilidad.FormasPagos != null) DetalleLinea.FilasResultado.Add(fr);
|
|
#endregion
|
|
|
|
#region TasaPropuestaMonedaLocal
|
|
if (Facilidad.TasaPropuestaMonedaLocal.HasValue && Facilidad.TasaPropuestaMonedaLocal > 0)
|
|
{
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " Tasa (Colones):" });
|
|
|
|
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = (string.Format("{0} % anual", ((Facilidad.TasaPropuestaMonedaLocal.HasValue ? Facilidad.TasaPropuestaMonedaLocal.Value : 0) + (Facilidad.TBPPropuestaMonedaLocal.HasValue ? Facilidad.TBPPropuestaMonedaLocal.Value : 0)).ToString("n2"))) });
|
|
|
|
if (Facilidad.TasaPropuestaMonedaLocal.HasValue) DetalleLinea.FilasResultado.Add(fr);
|
|
}
|
|
#endregion
|
|
|
|
#region TasaPropuestaDolares
|
|
if (Facilidad.TasaPropuestaDolares.HasValue && Facilidad.TasaPropuestaDolares > 0)
|
|
{
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " Tasa (Dólares):" });
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = (string.Format("{0} % anual", ((Facilidad.TasaPropuestaDolares.HasValue ? Facilidad.TasaPropuestaDolares.Value : 0) + (Facilidad.TRPropuestaDolares.HasValue ? Facilidad.TRPropuestaDolares.Value : 0)).ToString("n2"))) });
|
|
|
|
if (Facilidad.TasaPropuestaDolares.HasValue) DetalleLinea.FilasResultado.Add(fr);
|
|
}
|
|
#endregion
|
|
|
|
StringBuilder Valor = new StringBuilder();
|
|
|
|
foreach (OfertaFacilidadesComisiones Comision in Facilidad.OfertaFacilidadesComisiones)
|
|
Valor.AppendFormat("{0}{1}", (string.IsNullOrEmpty(Comision.DetalleComision) ? "" : Comision.DetalleComision.Trim()), (string.IsNullOrEmpty(Comision.DetalleComision) ? "" : SaltoLinea));
|
|
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " Comisión:" });
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = Valor.Length == 0 ? VALOR_PORDEFECTO_CAMPOS_VACIOS : Valor.ToString() });
|
|
|
|
if (Valor.Length > 0) DetalleLinea.FilasResultado.Add(fr);
|
|
|
|
Valor.Clear();
|
|
foreach (OfertaFacilidadesGarantias garantia in Facilidad.OfertaFacilidadesGarantias)
|
|
Valor.AppendFormat("{0}{1}", (garantia.DetalleGarantia == null ? "" : garantia.DetalleGarantia.Trim()), (garantia.DetalleGarantia == null ? "" : SaltoLinea));
|
|
|
|
fr = new FilaResultado();
|
|
fr.Columnas = new List<ColumnaResultado>();
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = " Garantía:" });
|
|
fr.Columnas.Add(new ColumnaResultado() { Valor = Valor.Length == 0 ? VALOR_PORDEFECTO_CAMPOS_VACIOS : Valor.ToString() });
|
|
|
|
if (Valor.Length > 0) DetalleLinea.FilasResultado.Add(fr);
|
|
|
|
FIla++;
|
|
}
|
|
|
|
FIla_titulo++;
|
|
}
|
|
|
|
doc.TablasAdicionales.Add(DetalleLinea);
|
|
}
|
|
|
|
doc.Fuente = null;
|
|
doc.Filtro = null;
|
|
doc.Firmas = null;
|
|
doc.Imagenes = null;
|
|
doc.Tablas = null;
|
|
|
|
|
|
Tabla TablasDocumentos = new Tabla();
|
|
|
|
|
|
|
|
obj.Plantillas = new List<DocumentoDB>() { doc };
|
|
|
|
using (WCFDocumentosClient ws = new WCFDocumentosClient())
|
|
respuesta = ws.GenerarDocumento(obj);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
}
|
|
finally
|
|
{
|
|
Conn = null;
|
|
obj = null;
|
|
doc = null;
|
|
Deudor = null;
|
|
}
|
|
return respuesta;
|
|
}
|
|
|
|
#region ADJUNTOS
|
|
|
|
[HttpPost]
|
|
public DocumentosAdjuntosCategoriaJSON CargarDocumentosAdjuntos(JsonSolicitud model)
|
|
{
|
|
DocumentosAdjuntosCategoriaJSON resp = new DocumentosAdjuntosCategoriaJSON();
|
|
List<BitacoraDocumentosIngresoCliente> listadocumentosreferencia = new List<BitacoraDocumentosIngresoCliente>();
|
|
List<AdjuntoEmailSolicitud> AdjuntoEmailSolicitud = new List<AdjuntoEmailSolicitud>();
|
|
|
|
try
|
|
{
|
|
|
|
Ultimus.Interfaces.UltimusForm.DocumentosParametros parametros = new Ultimus.Interfaces.UltimusForm.DocumentosParametros();
|
|
|
|
if (model.DocumentosIngresoCliente != null)
|
|
{
|
|
listadocumentosreferencia = new BitacoraDocumentosIngresoClienteDAL().obtener(model.DocumentosIngresoCliente);
|
|
|
|
}
|
|
|
|
parametros.CodSolicitud = model.Solicitud.IdSolicitud;
|
|
parametros.NombreProceso = model.UltimusProcess;
|
|
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
ClasificacionDocumentosAdjuntos filtro = model.ClasicacionEspecificaDocumentos ?? new ClasificacionDocumentosAdjuntos();
|
|
|
|
if (model.IdEmailSolicitud != 0)
|
|
{
|
|
AdjuntoEmailSolicitud = new AdjuntoEmailSolicitudDAL().Obtener(model.IdEmailSolicitud);
|
|
resp.ListaDocumentos = new List<ClasificacionDocumentosAdjuntos>();
|
|
foreach (AdjuntoEmailSolicitud Adjunto in AdjuntoEmailSolicitud)
|
|
{
|
|
ClasificacionDocumentosAdjuntos Documento = new ClasificacionDocumentosAdjuntos();
|
|
Documento.CodDocumento = Adjunto.CodDocumento;
|
|
Documento.IdCategoria = Convert.ToInt32( Adjunto.IdCategoriaTipoDocumento);
|
|
Documento.CategoriaTipoDocumento = new CategoriaTipoDocumentoDAL().Obtener(Documento.IdCategoria);
|
|
Documento.Fecha = Convert.ToDateTime( Adjunto.Fecha);
|
|
Documento.RutaDescarga = Adjunto.RutaDescarga;
|
|
Documento.RutaFisica = Adjunto.RutaFisica;
|
|
Documento.IdEtapa = Convert.ToInt32( Adjunto.IdEtapa);
|
|
Documento.Etapas = new EtapasDAL().ObtenerEtapa(Documento.IdEtapa);
|
|
Documento.NombreDocumento = Adjunto.NombreDocumento;
|
|
|
|
resp.ListaDocumentos.Add(Documento);
|
|
}
|
|
|
|
}
|
|
else if (listadocumentosreferencia.Count > 0)
|
|
{
|
|
List<ClasificacionDocumentosAdjuntos> ListaDocumentos = (from doc in db.ClasificacionDocumentosAdjuntos.Include(c => c.CategoriaTipoDocumento).Include(c => c.Etapas)
|
|
join l in db.BitacoraDocumentosIngresoCliente on doc.CodDocumento equals l.CodDocumento
|
|
where model.DocumentosIngresoCliente.IdSolicitud == l.IdSolicitud
|
|
select doc)
|
|
.Include(c => c.CategoriaTipoDocumento)
|
|
.Include(c => c.Etapas)
|
|
.AsNoTracking()
|
|
.ToList();
|
|
|
|
resp.ListaDocumentos = (from doc in ListaDocumentos
|
|
join l in listadocumentosreferencia on doc.CodDocumento equals l.CodDocumento
|
|
select doc).ToList();
|
|
|
|
}
|
|
else if (EnumEtapas.FR_Ejecutar_Desembolso == model.UltimusStep ||EnumEtapas.FR_Notificar_Desembolso ==model.UltimusStep || EnumEtapas.DE_Ejecutar_Desembolso == model.UltimusStep)
|
|
{
|
|
resp.ListaDocumentos = (from doc in db.ClasificacionDocumentosAdjuntos.Include(c => c.CategoriaTipoDocumento).Include(c => c.Etapas)
|
|
join l in db.BitacoraDocumentosFormalizacion on doc.CodDocumento equals l.CodDocumentoAdjunto
|
|
where l.Incident == model.UltimusIncident
|
|
select doc)
|
|
.Include(c => c.CategoriaTipoDocumento)
|
|
.Include(c => c.Etapas)
|
|
.AsNoTracking()
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
resp.ListaDocumentos =
|
|
(from doc in db.ClasificacionDocumentosAdjuntos.Include(c => c.CategoriaTipoDocumento).Include(c => c.Etapas)
|
|
join sol in db.Solicitante on doc.IdCliente equals sol.IdCliente
|
|
where sol.IdSolicitud == model.Solicitud.IdSolicitud
|
|
&& ((filtro.CodDocumento == 0 && filtro.IdCategoria == 0)
|
|
|| ((filtro.CodDocumento > 0 || filtro.CodDocumento == -1) && filtro.CodDocumento == doc.CodDocumento)
|
|
|| (filtro.CodDocumento == 0 && filtro.IdCategoria > 0 && filtro.IdCategoria == doc.IdCategoria)
|
|
)
|
|
select doc)
|
|
.Include(c => c.CategoriaTipoDocumento)
|
|
.Include(c => c.Etapas)
|
|
.AsNoTracking()
|
|
.ToList();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
resp = JsonConvert.DeserializeObject<DocumentosAdjuntosCategoriaJSON>(JsonConvert.SerializeObject(resp));
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
|
|
return resp;
|
|
}
|
|
|
|
[HttpPost]
|
|
public BaseJson EliminarDocumentoAdjunto(ClasificacionDocumentosAdjuntos model)
|
|
{
|
|
BaseJson resp = new BaseJson();
|
|
|
|
try
|
|
{
|
|
HttpRequest Request = HttpContext.Current.Request;
|
|
|
|
string MetodoIdentificadorGuardado = Request.QueryString["MetodoIdentificadorGuardado"];
|
|
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
var doc = db.ClasificacionDocumentosAdjuntos.Where(c => c.CodDocumento == model.CodDocumento).FirstOrDefault();
|
|
|
|
if (doc != null)
|
|
db.ClasificacionDocumentosAdjuntos.Remove(doc);
|
|
|
|
new UltimusFormAPIController().EliminarDocumentoAdjunto((int)model.CodDocumento);
|
|
|
|
GuardadoRelacionAdjuntos(MetodoIdentificadorGuardado, doc, "delete");
|
|
|
|
db.SaveChanges();
|
|
}
|
|
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
|
|
resp.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
}
|
|
|
|
return resp;
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<CategoriaTipoDocumento> ObtenerClasificacionAdjuntos()
|
|
{
|
|
List<CategoriaTipoDocumento> resp = null;
|
|
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
resp = db.CategoriaTipoDocumento.ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
}
|
|
|
|
return resp;
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
[ActionName("GenerarMatriz2")]
|
|
public object GenerarMatrizCondicionada2(object BitacoraDocumentos)
|
|
{
|
|
HttpRequest Request = HttpContext.Current.Request;
|
|
HttpResponseMessage response = new HttpResponseMessage();
|
|
|
|
try
|
|
{
|
|
|
|
//Create the file in Web App Physical Folder
|
|
string fileName = Guid.NewGuid().ToString() + ".xls";
|
|
string directory = HttpContext.Current.Server.MapPath("~/FileDownload/");
|
|
|
|
if (!Directory.Exists(directory))
|
|
Directory.CreateDirectory(directory);
|
|
|
|
|
|
string filePath = String.Format("{0}{1}", directory, fileName);
|
|
|
|
//if (!File.Exists(filePath))
|
|
// File.Create(filePath);
|
|
|
|
string jsonGridStructure = JsonConvert.SerializeObject(BitacoraDocumentos);
|
|
|
|
// write the data into Excel file
|
|
StreamWriter sw = new StreamWriter(filePath, false);
|
|
sw.Write(jsonGridStructure);
|
|
sw.Flush();
|
|
sw.Close();
|
|
sw.Dispose();
|
|
|
|
|
|
////Get the File Stream
|
|
//FileStream fileStream = System.IO.File.Open(filePath, FileMode.Append);
|
|
|
|
////Set response
|
|
//response.Content = new StreamContent(fileStream);
|
|
//response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
|
|
//response.Content.Headers.ContentDisposition.FileName = FileName;
|
|
//response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/ms-excel");
|
|
//response.Content.Headers.ContentLength = fileStream.Length;
|
|
|
|
return response;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
[ActionName("GenerarMatriz")]
|
|
public object GenerarMatrizCondicionada()
|
|
{
|
|
|
|
string NombreCliente = string.Empty;
|
|
string FileName = string.Empty;
|
|
string Header = string.Empty;
|
|
|
|
HttpResponse Response = HttpContext.Current.Response;
|
|
HttpRequest Request = HttpContext.Current.Request;
|
|
|
|
Cliente ClientePrincipal = new Cliente();
|
|
List<BitacoraDocumentosCliente> BitacoraDocumentos = new List<BitacoraDocumentosCliente>();
|
|
List<Observacion> BitacoraObservacionesDocumentos = null;
|
|
var BitacoraDocumentosReporte = new object();
|
|
|
|
try
|
|
{
|
|
int IdSolicitud = int.Parse(Request.QueryString["IdSolicitud"]);
|
|
int IdTipoExpediente = int.Parse(Request.QueryString["IdTipoExpediente"]);
|
|
|
|
|
|
try
|
|
{
|
|
ClientePrincipal = new ClienteDAL().ObtenerPrincipal(IdSolicitud);
|
|
|
|
if (ClientePrincipal == null)
|
|
throw new Exception(string.Format("No se pudo obtener la información del Cliente para la Solicitud {0}", IdSolicitud));
|
|
|
|
switch (ClientePrincipal.IdTipoCliente)
|
|
{
|
|
case EnumTipoCliente.Fisico:
|
|
string PNombre = string.IsNullOrEmpty(ClientePrincipal.PrimerNombre) ? "" : ClientePrincipal.PrimerNombre.Trim() + " ";
|
|
string SNombre = string.IsNullOrEmpty(ClientePrincipal.SegundoNombre) ? "" : ClientePrincipal.SegundoNombre.Trim() + " ";
|
|
string PApellido = string.IsNullOrEmpty(ClientePrincipal.PrimerApellido) ? "" : ClientePrincipal.PrimerApellido.Trim() + " ";
|
|
string SApellido = string.IsNullOrEmpty(ClientePrincipal.SegundoApellido) ? "" : ClientePrincipal.SegundoApellido.Trim() + " ";
|
|
NombreCliente = String.Format("{0}{1}{2}{3}", PNombre, SNombre, PApellido, SApellido);
|
|
break;
|
|
case EnumTipoCliente.Juridico:
|
|
NombreCliente = string.IsNullOrEmpty(ClientePrincipal.RazonSocial) ? "" : ClientePrincipal.RazonSocial.Trim();
|
|
break;
|
|
}
|
|
|
|
|
|
BitacoraDocumentos = new BitacoraDocumentosClienteDAL().Obtener(IdSolicitud);
|
|
BitacoraObservacionesDocumentos = new ObservacionDAL().Obtener(null, null, ClientePrincipal.IdCliente, null, null);
|
|
|
|
if (BitacoraObservacionesDocumentos == null)
|
|
BitacoraObservacionesDocumentos = new List<Observacion>();
|
|
|
|
if (BitacoraObservacionesDocumentos.Count > 0)
|
|
BitacoraDocumentos.ForEach(x =>
|
|
{
|
|
x.Observacion = BitacoraObservacionesDocumentos.Where(y => y.IdTipoDocumento == x.IdTipoDocumento).ToList();
|
|
});
|
|
|
|
|
|
|
|
BitacoraDocumentosReporte = BitacoraDocumentos
|
|
.Where(x => x.TipoDocumento.TipoExpedienteDocumentos.Where(y => y.IdTipoExpediente == IdTipoExpediente).Any())
|
|
.Select(x => new
|
|
{
|
|
ID = x.IdTipoDocumento,
|
|
Periodo = x.Periodo.HasValue ? x.Periodo.Value.ToString("dd/MM/yyyy") : "",
|
|
//RequisitoBasico = x.RequisitoBasico == true ? "Si" : "No",
|
|
Documento = x.TipoDocumento.Descripcion,
|
|
//VerificacionNegocio = x.VerifNegocio == true ? "Si" : "No",
|
|
//ObservacionesNegocio = x.Observacion.Where(i => i.IdTipoObservacion == 1).Any() ? x.Observacion.Where(i => i.IdTipoObservacion == 1).Select(i => i.DescripcionObservacion).Aggregate((i, j) => i + "<br>" + j) : "",
|
|
//VBNegocio = x.VBNegocio == true ? "Si" : "No",
|
|
//VerificacionCumplimiento = x.VerifCumplimiento == true ? "Si" : "No",
|
|
//ObservacionesCumplimiento = x.Observacion.Where(i => i.IdTipoObservacion == 3).Any() ? x.Observacion.Where(i => i.IdTipoObservacion == 3).Select(i => i.DescripcionObservacion).Aggregate((i, j) => i + "<br>" + j) : "",
|
|
//VBCumplimiento = x.VBCumplimiento == true ? "Si" : "No",
|
|
//Disconforme = x.Disconforme == true ? "Si" : "No",
|
|
SatisfacePoliticaCumplimiento = x.SatisfacePoliticaCumplimiento == true ? "Sí" : "No",
|
|
ObservacionesSatisfacePoliticaCumplimiento = x.Observacion.Where(i => i.IdTipoObservacion == 3).Any() ? x.Observacion.Where(i => i.IdTipoObservacion == 3).Select(i => i.DescripcionObservacion).Aggregate((i, j) => i + "<br>" + j) : "",
|
|
})
|
|
.ToList();
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
logs.Error(ex2);
|
|
}
|
|
|
|
|
|
FileName = string.Format("Matriz de Cumplimiento_{0}.xls", DateTime.Now);
|
|
Encoding encoding = Encoding.UTF8;
|
|
Response.Clear();
|
|
Response.Buffer = true;
|
|
Response.ClearContent();
|
|
Response.ClearHeaders();
|
|
//Response.Charset = encoding.EncodingName;
|
|
//Response.ContentEncoding = Encoding.UTF8;
|
|
Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
|
|
|
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
|
|
Response.AddHeader("Content-Type", "application/Excel");
|
|
Response.ContentType = "application/vnd.ms-excel";
|
|
string charSet = Response.Charset;
|
|
if (String.IsNullOrEmpty(charSet))
|
|
encoding = Encoding.Default;
|
|
else
|
|
encoding = Encoding.GetEncoding(charSet);
|
|
|
|
encoding = Encoding.Default;
|
|
Response.ContentEncoding = encoding;
|
|
Response.Charset = encoding.EncodingName;
|
|
|
|
StringBuilder sbWritter = new StringBuilder();
|
|
StringWriter strwritter = new ExtentedStringWriter(sbWritter, encoding);
|
|
|
|
HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
|
|
|
|
|
|
|
|
|
|
//var ListaBitacoraDocumentos = ((Newtonsoft.Json.Linq.JArray)BitacoraDocumentos).Select(x => new
|
|
//{
|
|
// IdCliente = (int)x["IdCliente"],
|
|
// IdTipoDocumento = (int)x["IdTipoDocumento"]
|
|
//}).ToList();
|
|
|
|
|
|
|
|
DataGrid gvRegistrosCarga = new DataGrid();
|
|
gvRegistrosCarga.HeaderStyle.VerticalAlign = VerticalAlign.Middle;
|
|
gvRegistrosCarga.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
|
|
gvRegistrosCarga.HeaderStyle.BackColor = System.Drawing.Color.DarkRed;
|
|
gvRegistrosCarga.HeaderStyle.ForeColor = System.Drawing.Color.White;
|
|
|
|
gvRegistrosCarga.ItemStyle.VerticalAlign = VerticalAlign.Middle;
|
|
gvRegistrosCarga.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
|
|
|
|
|
|
gvRegistrosCarga.DataSource = BitacoraDocumentosReporte;
|
|
gvRegistrosCarga.DataBind();
|
|
gvRegistrosCarga.RenderControl(htmltextwrtter);
|
|
gvRegistrosCarga.Dispose();
|
|
|
|
|
|
Header += "<div>" + string.Format("Cliente: {0}", NombreCliente) + "</div>";
|
|
Header += "<div>" + string.Format("Solicitud: {0}", IdSolicitud) + "</div>";
|
|
Header += "<div>" + string.Format("Fecha: {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt")) + "</div>";
|
|
|
|
Response.Write(Header);
|
|
Response.Write(strwritter.ToString());
|
|
|
|
Response.End();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
[ActionName("AdjuntarDocumento")]
|
|
public object AdjuntarDocumentos()
|
|
{
|
|
DocumentosParametros Parametros = null;
|
|
HttpRequest Request = HttpContext.Current.Request;
|
|
DocumentoAdjuntoJSON respuesta = new DocumentoAdjuntoJSON();
|
|
System.Web.Http.Results.RedirectResult redirect = null;
|
|
int IEVersion = -1;
|
|
EtapasDAL EtapasDal = new EtapasDAL();
|
|
ClasificacionDocumentosAdjuntosDAL ClasificacionDocumentosAdjuntosDal = new ClasificacionDocumentosAdjuntosDAL();
|
|
ClienteDAL ClienteDal = new ClienteDAL();
|
|
string jsonParam = string.Empty;
|
|
try
|
|
{
|
|
|
|
|
|
|
|
Ultimus.Interfaces.UltimusFormAPIController FormInterface = new UltimusFormAPIController();
|
|
string MetodoIdentificadorGuardado = Request.QueryString["MetodoIdentificadorGuardado"];
|
|
string jsonParametroExtra = Request.Form["ParametroExtraAdjunto"] != null ? Request.Form["ParametroExtraAdjunto"] : Request.Form["ParametroExtraAdjuntoCorreo"];
|
|
|
|
int IdCliente = 0;
|
|
int.TryParse(Request.Form["IdCliente"], out IdCliente);
|
|
|
|
HttpFileCollection files = Request.Files.Count > 0 ? Request.Files : null;
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(Request.Form["AttacmentJSONParameters"]))
|
|
{
|
|
if (!string.IsNullOrEmpty(Request.Form["AttacmentJSONParametersCorreo"]))
|
|
jsonParam = Request.Form["AttacmentJSONParametersCorreo"];
|
|
else if (!string.IsNullOrEmpty(Request.Form["AttacmentJSONParametersAdjunto"]))
|
|
jsonParam = Request.Form["AttacmentJSONParametersAdjunto"];
|
|
}
|
|
else
|
|
{
|
|
jsonParam = Request.Form["AttacmentJSONParameters"];
|
|
}
|
|
|
|
|
|
Parametros = JsonConvert.DeserializeObject<DocumentosParametros>(jsonParam);
|
|
IEVersion = Parametros.IEVersion;
|
|
Parametros.IEVersion = -1;
|
|
List<FileJSON> Documentos = new List<FileJSON>();
|
|
|
|
foreach (string name in files)
|
|
{
|
|
HttpPostedFile item = files[name];
|
|
Documentos.Add(
|
|
new FileJSON()
|
|
{
|
|
FileName = item.FileName,
|
|
FileData = UltimusFormAPIController.ReadFullyBytes(item.InputStream),
|
|
ContentType = item.ContentType,
|
|
ContentLength = item.ContentLength
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
System.ServiceModel.WSHttpBinding Binding = new System.ServiceModel.WSHttpBinding();
|
|
Binding.Security.Mode = System.ServiceModel.SecurityMode.None;
|
|
Binding.MaxReceivedMessageSize = int.MaxValue;
|
|
Binding.MaxBufferPoolSize = int.MaxValue;
|
|
System.ServiceModel.HttpTransportSecurity security = new System.ServiceModel.HttpTransportSecurity();
|
|
security.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None;
|
|
Binding.Security.Transport = security;
|
|
|
|
Binding.CloseTimeout = new TimeSpan(0, 5, 0);
|
|
Binding.SendTimeout = Binding.CloseTimeout;
|
|
Binding.ReceiveTimeout = Binding.CloseTimeout;
|
|
Binding.OpenTimeout = Binding.CloseTimeout;
|
|
|
|
using (UltimusFormClient client = new UltimusFormClient(Binding, new System.ServiceModel.EndpointAddress(new ObtieneParametros().GetValueKeyRegedit("UltimusFormUrl", false) + "/soap")))
|
|
{
|
|
respuesta = client.AdjuntarDocumentos(new DocumentosAdjuntosJSON()
|
|
{
|
|
Files = Documentos,
|
|
Parametros = Parametros
|
|
});
|
|
|
|
if (respuesta.CodigoRespuesta == TipoCodigoRespuesta.ERROR.ToString())
|
|
{
|
|
logs.Error(respuesta.DescripcionRespuesta);
|
|
throw new Exception(respuesta.DescripcionRespuesta);
|
|
}
|
|
|
|
if (IdCliente == 0)
|
|
{
|
|
Cliente cliente = ClienteDal.ObtenerPrincipal(Parametros.CodSolicitud);
|
|
IdCliente = cliente.IdCliente;
|
|
}
|
|
|
|
Etapas etapa = EtapasDal.ObtenerEtapa(Parametros.Etapa, Parametros.NombreProceso);
|
|
|
|
ClasificacionDocumentosAdjuntos doc = new ClasificacionDocumentosAdjuntos();
|
|
|
|
//logs.Trace("respuesta : " + JsonConvert.SerializeObject(respuesta));
|
|
|
|
doc = doc.CopyValueProperties(respuesta);
|
|
doc.CodDocumento = respuesta.CodDocumento;
|
|
doc.NombreDocumento = respuesta.NombreDocumento + respuesta.TipoArchivo;
|
|
doc.IdCliente = IdCliente;
|
|
doc.IdEtapa = etapa.IdEtapa;
|
|
doc.IdCategoria = int.Parse(Request.QueryString["IdCategoria"]);
|
|
|
|
logs.Trace("DOC : " + JsonConvert.SerializeObject(doc));
|
|
|
|
doc = ClasificacionDocumentosAdjuntosDal.InsertarActualizar(doc);
|
|
|
|
GuardadoRelacionAdjuntos(MetodoIdentificadorGuardado, doc, "guardar", jsonParametroExtra, respuesta.CodSolicitud, respuesta.Incidente);
|
|
|
|
}
|
|
|
|
}
|
|
catch (DbEntityValidationException ex)
|
|
{
|
|
logs.Error(ex);
|
|
respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
respuesta.DescripcionRespuesta = ex.Message;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
respuesta.CodigoRespuesta = TipoCodigoRespuesta.ERROR.ToString();
|
|
respuesta.DescripcionRespuesta = ex.Message;
|
|
}
|
|
|
|
if (Parametros != null && IEVersion != -1 && IEVersion < 10)
|
|
{
|
|
var url = new Uri(HttpContext.Current.Request.UrlReferrer.ToString());
|
|
|
|
redirect = new System.Web.Http.Results.RedirectResult(url, new HttpRequestMessage());
|
|
return redirect;
|
|
}
|
|
else
|
|
return respuesta;
|
|
}
|
|
|
|
[HttpPost]
|
|
public ResultadoGeneracion ObtenerAdjunto(JsonSolicitud model)
|
|
{
|
|
ResultadoGeneracion resultado = new ResultadoGeneracion();
|
|
|
|
if (model == null || model.Solicitud == null)
|
|
{
|
|
resultado.Error = "Se requiere el número de solicitud para obtener el documento";
|
|
return resultado;
|
|
}
|
|
|
|
|
|
List<FormalizacionDocumentosLegales> DocLegales = new FormalizacionDocumentosLegalesDAL().ObtenerDocumentos(model.Solicitud.IdSolicitud, Convert.ToInt32(model.Solicitud.Incidente), model.DetalleDocumento.IdTipoDocumento);
|
|
|
|
if (DocLegales != null && DocLegales.Count > 0 && DocLegales.FirstOrDefault().CodDocumentoAdjunto != null)
|
|
{
|
|
DocumentosAdjuntosDAL documentosAdjuntos = new DocumentosAdjuntosDAL();
|
|
var listaDocumentos = documentosAdjuntos.Obtener(DocLegales.FirstOrDefault().CodDocumentoAdjunto);
|
|
|
|
if (listaDocumentos != null)
|
|
{
|
|
string rutaVirtual = string.Empty;
|
|
rutaVirtual = listaDocumentos.RutaDescarga;
|
|
|
|
if (rutaVirtual.Length > 0)
|
|
{
|
|
resultado.RutaVirtual = rutaVirtual;
|
|
resultado.Error = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return resultado;
|
|
}
|
|
|
|
[HttpPost]
|
|
public ResultadoGeneracion ObtenerAdjuntoFormalizacion(JsonSolicitud model)
|
|
{
|
|
ResultadoGeneracion resultado = new ResultadoGeneracion();
|
|
|
|
if (model == null || model.Solicitud == null)
|
|
{
|
|
resultado.Error = "Se requiere el número de solicitud para obtener el documento";
|
|
return resultado;
|
|
}
|
|
|
|
|
|
BitacoraDocumentosFormalizacion BitDocFormalizacion = new BitacoraDocumentosFormalizacionDAL().ObtenerDocumento(new BitacoraDocumentosFormalizacion()
|
|
{
|
|
IdTipoDocumento = model.DetalleDocumento.IdTipoDocumento,
|
|
IdCliente = model.Solicitante.IdCliente,
|
|
IdProceso = model.Solicitud.IdSolicitudProceso.Value,
|
|
Incident = model.Solicitud.Incidente.Value,
|
|
IdSolicitud = model.Solicitud.IdSolicitud
|
|
});
|
|
|
|
|
|
if (BitDocFormalizacion != null && BitDocFormalizacion.CodDocumentoAdjunto != null)
|
|
{
|
|
DocumentosAdjuntosDAL documentosAdjuntos = new DocumentosAdjuntosDAL();
|
|
var listaDocumentos = documentosAdjuntos.Obtener(BitDocFormalizacion.CodDocumentoAdjunto);
|
|
|
|
if (listaDocumentos != null)
|
|
{
|
|
string rutaVirtual = string.Empty;
|
|
rutaVirtual = listaDocumentos.RutaDescarga;
|
|
|
|
if (rutaVirtual.Length > 0)
|
|
{
|
|
resultado.RutaVirtual = rutaVirtual;
|
|
resultado.Error = TipoCodigoRespuesta.EXITOSO.ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return resultado;
|
|
}
|
|
|
|
public void GuardadoRelacionAdjuntos(string MetodoIdentificadorGuardado, ClasificacionDocumentosAdjuntos doc, string modo, string ParametroExtra = null, int? IdSolicitud = null, int? Incidente = null)
|
|
{
|
|
try
|
|
{
|
|
using (CreditoContex db = new CreditoContex())
|
|
{
|
|
Solicitante solicitante = db.Solicitante.Where(c => c.IdCliente == doc.IdCliente).FirstOrDefault();
|
|
|
|
switch (MetodoIdentificadorGuardado)
|
|
{
|
|
case "OfertaLeasing":
|
|
#region OfertaLeasing
|
|
|
|
var propuesta = db.DetalleRequisitos.Where(c => c.IdSolicitud == solicitante.IdSolicitud).FirstOrDefault();
|
|
|
|
if (modo == "guardar")
|
|
{
|
|
|
|
if (propuesta != null)
|
|
{
|
|
propuesta.IdDocumentoOfertaLeasing = doc.CodDocumento;
|
|
propuesta.RutaFisicaOfertaLeasing = doc.RutaFisica;
|
|
|
|
}
|
|
}
|
|
else if (modo == "delete")
|
|
{
|
|
|
|
if (propuesta != null)
|
|
{
|
|
propuesta.IdDocumentoOfertaLeasing = null;
|
|
propuesta.RutaFisicaOfertaLeasing = null;
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
break;
|
|
case "Requisitos":
|
|
#region Requisitos
|
|
BitacoraDocumentosCliente requisito = db.BitacoraDocumentosCliente.Where(c => c.IdCliente == solicitante.IdCliente).AsNoTracking().FirstOrDefault();
|
|
|
|
if (modo == "guardar")
|
|
{
|
|
requisito = JsonConvert.DeserializeObject<BitacoraDocumentosCliente>(ParametroExtra);
|
|
|
|
requisito.CodDocumentoAdjunto = doc.CodDocumento;
|
|
requisito.RutaFisicaAdjunto = doc.RutaFisica;
|
|
}
|
|
else if (modo == "delete")
|
|
{
|
|
if (requisito == null) return;
|
|
requisito.CodDocumentoAdjunto = null;
|
|
requisito.RutaFisicaAdjunto = null;
|
|
|
|
db.BitacoraDocumentosCliente.Attach(requisito);
|
|
}
|
|
|
|
foreach (var item in requisito.GetType().GetProperties())
|
|
{
|
|
if (item.GetGetMethod().IsVirtual)
|
|
item.SetValue(requisito, null, null);
|
|
}
|
|
|
|
db.Entry(requisito).State = System.Data.Entity.EntityState.Modified;
|
|
|
|
#endregion
|
|
break;
|
|
case "DocsAdicionales":
|
|
#region DocsAdicionales
|
|
|
|
if (modo == "guardar")
|
|
{
|
|
ClasificacionDocumentosAdjuntos bitacora = JsonConvert.DeserializeObject<ClasificacionDocumentosAdjuntos>(ParametroExtra);
|
|
doc.Comentarios = bitacora.Comentarios;
|
|
db.Entry(doc).State = EntityState.Modified;
|
|
}
|
|
|
|
#endregion
|
|
break;
|
|
case "DocsInformeAnalisis":
|
|
#region DocsInformeAnalisis
|
|
BitacoraDocumentosInformeAnalisis BitacoraInforme = new BitacoraDocumentosInformeAnalisis();
|
|
|
|
if (modo == "guardar")
|
|
{
|
|
BitacoraInforme = JsonConvert.DeserializeObject<BitacoraDocumentosInformeAnalisis>(ParametroExtra);
|
|
// db.BitacoraDocumentosInformeAnalisis.Attach(BitacoraInforme);
|
|
BitacoraInforme.CodDocumentoAdjunto = doc.CodDocumento;
|
|
BitacoraInforme.Fecha = DateTime.Now;
|
|
}
|
|
else if (modo == "delete")
|
|
{
|
|
BitacoraInforme = db.BitacoraDocumentosInformeAnalisis.Where(c => c.IdCliente == solicitante.IdCliente && c.CodDocumentoAdjunto == doc.CodDocumento).FirstOrDefault();
|
|
|
|
if (BitacoraInforme == null) return;
|
|
|
|
BitacoraInforme.CodDocumentoAdjunto = null;
|
|
BitacoraInforme.Fecha = null;
|
|
}
|
|
BitacoraInforme.ClearVirtualProperties();
|
|
db.Entry(BitacoraInforme).State = System.Data.Entity.EntityState.Modified;
|
|
|
|
#endregion
|
|
break;
|
|
case "PersoneriaJuridica":
|
|
#region PersoneriaJuridica
|
|
|
|
BitacoraDocumentosCliente BitDocCliente = JsonConvert.DeserializeObject<BitacoraDocumentosCliente>(ParametroExtra);
|
|
|
|
if (modo == "guardar")
|
|
{
|
|
if (BitDocCliente != null)
|
|
{
|
|
BitDocCliente.CodDocumentoAdjunto = doc.CodDocumento;
|
|
BitDocCliente.RutaFisicaAdjunto = doc.RutaFisica;
|
|
}
|
|
}
|
|
else if (modo == "delete")
|
|
{
|
|
if (BitDocCliente != null)
|
|
{
|
|
BitDocCliente.CodDocumentoAdjunto = null;
|
|
BitDocCliente.RutaFisicaAdjunto = null;
|
|
}
|
|
}
|
|
|
|
BitDocCliente.ClearVirtualProperties();
|
|
|
|
new BitacoraDocumentosClienteDAL().ActualizarDocumento(BitDocCliente);
|
|
|
|
|
|
#endregion
|
|
break;
|
|
case "DocLegalFormalizacion":
|
|
#region DocLegalFormalizacion
|
|
|
|
FormalizacionDocumentosLegalesDAL FormalizacionDocumentosLegalesDal = new FormalizacionDocumentosLegalesDAL();
|
|
|
|
if (modo == "guardar")
|
|
{
|
|
FormalizacionDocumentosLegales bitacora = JsonConvert.DeserializeObject<FormalizacionDocumentosLegales>(ParametroExtra);
|
|
bitacora.CodDocumentoAdjunto = doc.CodDocumento;
|
|
|
|
FormalizacionDocumentosLegalesDal.ActualizarDocumento(bitacora);
|
|
}
|
|
else if (modo == "delete")
|
|
{
|
|
FormalizacionDocumentosLegales bitacora = db.FormalizacionDocumentosLegales.Where(c => c.CodDocumentoAdjunto == doc.CodDocumento).FirstOrDefault();
|
|
bitacora.CodDocumentoAdjunto = null;
|
|
|
|
FormalizacionDocumentosLegalesDal.ActualizarDocumento(bitacora);
|
|
}
|
|
|
|
#endregion
|
|
break;
|
|
case "DocExpedienteFormalizacion":
|
|
#region DocExpedienteFormalizacion
|
|
|
|
BitacoraDocumentosFormalizacionDAL BitacoraDocumentosFormalizacionDal = new BitacoraDocumentosFormalizacionDAL();
|
|
BitacoraDocumentosFormalizacion BitacoraFormalizacion = new BitacoraDocumentosFormalizacion();
|
|
|
|
if (modo == "guardar")
|
|
{
|
|
BitacoraDocumentosFormalizacion bitacora = JsonConvert.DeserializeObject<BitacoraDocumentosFormalizacion>(ParametroExtra);
|
|
bitacora.CodDocumentoAdjunto = doc.CodDocumento;
|
|
|
|
BitacoraDocumentosFormalizacionDal.Actualizar(new List<BitacoraDocumentosFormalizacion>() { bitacora });
|
|
}
|
|
else if (modo == "delete")
|
|
{
|
|
BitacoraFormalizacion = db.BitacoraDocumentosFormalizacion.Where(c => c.CodDocumentoAdjunto == doc.CodDocumento).FirstOrDefault();
|
|
|
|
if (BitacoraFormalizacion == null) return;
|
|
|
|
BitacoraFormalizacion.CodDocumentoAdjunto = null;
|
|
BitacoraDocumentosFormalizacionDal.Actualizar(new List<BitacoraDocumentosFormalizacion>() { BitacoraFormalizacion });
|
|
}
|
|
|
|
#endregion
|
|
break;
|
|
case "FacturasDesembolso":
|
|
#region FacturasDesembolso
|
|
|
|
DesembolsoDatosGeneralesDAL DesembolsoDatosGeneralesDal = new DesembolsoDatosGeneralesDAL();
|
|
|
|
if (modo == "guardar")
|
|
{
|
|
|
|
DesembolsoDatosGenerales bitacora = DesembolsoDatosGeneralesDal.Obtener(solicitante.IdSolicitud);
|
|
bitacora.IdDocumentoFacturasAdjuntadas = doc.CodDocumento;
|
|
bitacora.RutaFisicaFacturasAdjuntadas = doc.RutaFisica;
|
|
|
|
DesembolsoDatosGeneralesDal.InsertarActualizar(bitacora);
|
|
}
|
|
else if (modo == "delete")
|
|
{
|
|
DesembolsoDatosGenerales bitacora = DesembolsoDatosGeneralesDal.Obtener(solicitante.IdSolicitud);
|
|
bitacora.IdDocumentoFacturasAdjuntadas = null;
|
|
bitacora.RutaFisicaFacturasAdjuntadas = null;
|
|
|
|
DesembolsoDatosGeneralesDal.InsertarActualizar(bitacora);
|
|
}
|
|
|
|
#endregion
|
|
break;
|
|
case "SolicitudDesembolso":
|
|
#region FacturasDesembolso
|
|
|
|
DesembolsoDatosGeneralesDAL DesembolsoDatosGeneralesDal_ = new DesembolsoDatosGeneralesDAL();
|
|
|
|
if (modo == "guardar")
|
|
{
|
|
|
|
DesembolsoDatosGenerales bitacora = DesembolsoDatosGeneralesDal_.Obtener(solicitante.IdSolicitud);
|
|
bitacora.IdDocumentoSolicitudDesembolsoAdjuntadas = doc.CodDocumento;
|
|
bitacora.RutaFisicaSolicitudDesembolsoAdjuntadas = doc.RutaFisica;
|
|
|
|
DesembolsoDatosGeneralesDal_.InsertarActualizar(bitacora);
|
|
}
|
|
else if (modo == "delete")
|
|
{
|
|
DesembolsoDatosGenerales bitacora = DesembolsoDatosGeneralesDal_.Obtener(solicitante.IdSolicitud);
|
|
bitacora.IdDocumentoSolicitudDesembolsoAdjuntadas = null;
|
|
bitacora.RutaFisicaSolicitudDesembolsoAdjuntadas = null;
|
|
|
|
DesembolsoDatosGeneralesDal_.InsertarActualizar(bitacora);
|
|
}
|
|
|
|
#endregion
|
|
break;
|
|
case "Referencias":
|
|
#region Referencias
|
|
BitacoraDocumentosIngresoClienteDAL BitacoraDocumentosIngresoClienteDAL = new BitacoraDocumentosIngresoClienteDAL();
|
|
BitacoraDocumentosIngresoCliente BitacoraDocumentosIngresoCliente = new BitacoraDocumentosIngresoCliente();
|
|
if (modo == "guardar")
|
|
{
|
|
BitacoraDocumentosIngresoCliente = JsonConvert.DeserializeObject<BitacoraDocumentosIngresoCliente>(ParametroExtra);
|
|
BitacoraDocumentosIngresoCliente.CodDocumento = doc.CodDocumento;
|
|
BitacoraDocumentosIngresoClienteDAL.InsertarActualizar(BitacoraDocumentosIngresoCliente);
|
|
}
|
|
if (modo == "delete")
|
|
{
|
|
BitacoraDocumentosIngresoCliente.IdSolicitud = solicitante.IdSolicitud;
|
|
BitacoraDocumentosIngresoCliente.CodDocumento = doc.CodDocumento;
|
|
BitacoraDocumentosIngresoClienteDAL.Eliminar(BitacoraDocumentosIngresoCliente);
|
|
}
|
|
break;
|
|
#endregion
|
|
case "ComprobanteDesembolso":
|
|
#region ComprobanteDesembolso
|
|
BitacoraDocumentosFormalizacion BitacoraDocumentos = new BitacoraDocumentosFormalizacion();
|
|
BitacoraDocumentosFormalizacion respuesta = new BitacoraDocumentosFormalizacion();
|
|
if (modo == "guardar")
|
|
{
|
|
|
|
Solicitud solicitud = new SolicitudDAL().Obtener(IdSolicitud.Value);
|
|
Etapas etapa = new EtapasDAL().ObtenerEtapa(doc.IdEtapa);
|
|
BitacoraDocumentos.IdTipoDocumento = EnumTipoDocumento.ComprobanteDesembolso;
|
|
BitacoraDocumentos.IdCliente = doc.IdCliente;
|
|
BitacoraDocumentos.IdProceso = etapa.DescripcionEtapa == EnumEtapas.FR_Notificar_Desembolso || etapa.DescripcionEtapa == EnumEtapas.FR_Ejecutar_Desembolso? EnumProcesos.Formalizacion : EnumProcesos.Desembolso;
|
|
BitacoraDocumentos.Incident = Incidente.Value;
|
|
BitacoraDocumentos.IdSolicitud = IdSolicitud.Value;
|
|
respuesta = new BitacoraDocumentosFormalizacionDAL().ObtenerDocumento(BitacoraDocumentos);
|
|
|
|
if (respuesta != null)
|
|
{
|
|
respuesta.RutaFisicaAdjunto = doc.RutaFisica;
|
|
respuesta.CodDocumentoAdjunto = doc.CodDocumento;
|
|
new BitacoraDocumentosFormalizacionDAL().ActualizarDocumento(respuesta);
|
|
}
|
|
}
|
|
if (modo == "delete")
|
|
{
|
|
respuesta = new BitacoraDocumentosFormalizacionDAL().ObtenerDocumento(doc.CodDocumento);
|
|
respuesta.RutaFisicaAdjunto = null;
|
|
respuesta.CodDocumentoAdjunto = null;
|
|
new BitacoraDocumentosFormalizacionDAL().ActualizarDocumento(respuesta);
|
|
}
|
|
|
|
break;
|
|
#endregion
|
|
case "AdjuntosCorreos":
|
|
if (modo == "guardar")
|
|
{
|
|
AdjuntoEmailSolicitud Adjunto = new AdjuntoEmailSolicitud();
|
|
Adjunto = JsonConvert.DeserializeObject<AdjuntoEmailSolicitud>(ParametroExtra);
|
|
Adjunto.CodDocumento = Convert.ToInt32(doc.CodDocumento);
|
|
Adjunto.IdEtapa = doc.IdEtapa;
|
|
Adjunto.IdCategoriaTipoDocumento = doc.IdCategoria;
|
|
Adjunto.RutaDescarga = doc.RutaDescarga;
|
|
Adjunto.RutaFisica = doc.RutaFisica;
|
|
Adjunto.NombreDocumento = doc.NombreDocumento;
|
|
Adjunto.Fecha = DateTime.Now;
|
|
|
|
new AdjuntoEmailSolicitudDAL().InsertarActualizar(Adjunto);
|
|
}
|
|
if (modo == "delete")
|
|
{
|
|
BaseJson respuestaEmail = new AdjuntoEmailSolicitudDAL().Eliminar( Convert.ToInt32(doc.CodDocumento));
|
|
}
|
|
break;
|
|
}
|
|
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
}
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
public string OntenerRutaDocumento(int? IdSolcitud, int IdTipoDocumento, int IdPeriodo)
|
|
{
|
|
string respuesta = string.Empty;
|
|
long? CodDocumentoAdjunto = 0;
|
|
List<BitacoraDocumentosCliente> Documentos = new List<BitacoraDocumentosCliente>();
|
|
ULA.Cathay.CreditoModel.ComponentManager.DocumentosAdjuntos Adjunto = new ULA.Cathay.CreditoModel.ComponentManager.DocumentosAdjuntos();
|
|
try
|
|
{
|
|
|
|
Documentos = new BitacoraDocumentosClienteDAL().Obtener(IdSolcitud);
|
|
CodDocumentoAdjunto = Documentos.Where(x => x.IdTipoDocumento == IdTipoDocumento && x.ConsecutivoPeriodo == IdPeriodo).FirstOrDefault().CodDocumentoAdjunto;
|
|
Adjunto = new DocumentosAdjuntosDAL().Obtener(CodDocumentoAdjunto);
|
|
respuesta = Adjunto.RutaDescarga;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logs.Error(ex);
|
|
|
|
}
|
|
return respuesta;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |