public async Task <ActionResult> NuevaBaseEjercicioGastos() { IRepositoryWrapper _repo = new RepositoryWrapper(); var model = new NuevaBaseEjercicioModel(); model.SelectedEmpresaMes = ""; DateTime _fecha = _unitOfWork.getDateTimeFromServer(); int _versionID = FTPresupuestoProvider.getVersionPresupuestoIdByTipo(enumTipoDePresupuesto.GASTOS); VersionPresupuesto _version = _unitOfWork.GetRepositoryInstance <VersionPresupuesto>().GetFirstOrDefault(_versionID); if (_version == null) { _version = new VersionPresupuesto(); _version.Consecutivo = 1; _version.Ejercicio = _fecha.Year; _version.TipoPresupuesto = (int)enumTipoDePresupuesto.GASTOS; _version.UsuarioCreacion = User.Identity.Name; _version.FechaCreacion = _fecha; } model.Ejercicio = _version.Ejercicio; model.Consecutivo = _version.Consecutivo; model.VersionId = _version.VersionPresupuestoId; model.Observaciones = _version.Observaciones; int anioActual = _fecha.Year; int mesActual = _fecha.Month; int tp = Convert.ToInt32(enumTipoDePresupuesto.GASTOS); int maxConsecutivo = 0; using (FTPresupuestoEntities _db = new FTPresupuestoEntities()) { maxConsecutivo = _db.VersionPresupuesto .Where(v => v.TipoPresupuesto == tp && v.Ejercicio == model.Ejercicio) .Select(v => v.Consecutivo) .DefaultIfEmpty(0) .Max(); } model.Consecutivo = maxConsecutivo + 1; ViewData["Empresas"] = FTPresupuestoProvider.GetAllEmpresasWithTODAS(); var listaEmpresasMeses = await _repo.Gastos.getEmpresasMesesAsync(); ViewData["EmpresasMeses"] = listaEmpresasMeses .OrderBy(x => x.Clave_Empresa).ThenByDescending(x => x.Ejercicio).ThenByDescending(x => x.Mes) .ToList(); return(View(model)); }
public JsonResult GenerarNuevaBaseEjercicioGastos(NuevaBaseEjercicioModel model) { IRepositoryWrapper _repo = new RepositoryWrapper(); if (ModelState.IsValid) { try { string[] selectedItems = CheckBoxListExtension.GetSelectedValues <string>("chkEmpresasMesesList"); int versionActualID = FTPresupuestoProvider.getVersionPresupuestoIdByTipo(enumTipoDePresupuesto.GASTOS); int versionPptoID = model.VersionId; // SE VALIDA QUE NO SE HAYA EJECUTADO DOS VECES EL MISMO PROCESO if (versionPptoID > 0) { if (versionActualID != versionPptoID) { return(Json("Proceso Duplicado")); } } var resultaTotal = _repo.Gastos.ActualizarBase(model, selectedItems, User.Identity.Name); if (!resultaTotal.Item1) { throw new Exception(string.Join(Environment.NewLine, resultaTotal.Item2)); } //// SE CREA LA TABLA TEMPORAL Y SE ACUMULAN //var resultaCrear = _repo.Gastos.ValidaExistenciaTmpResultadoGastos(); //if (!resultaCrear.Item1) //{ // throw new Exception(string.Join(Environment.NewLine, resultaCrear.Item2)); //} //string idTemporal = Guid.NewGuid().ToString(); //foreach (string selected in selectedItems) //{ // short pEjercicio = 0; // short.TryParse(selected.Substring(0, 4), out pEjercicio); // short pMes = 0; // short.TryParse(selected.Substring(4, 2), out pMes); // short pEmpresa = 0; // short.TryParse(selected.Substring(6, 2), out pEmpresa); // var resultaTmp = _repo.Gastos // .AgregarEnTmpResultadoGastos((short)model.Ejercicio, pEjercicio, pEmpresa, pMes, idTemporal); // if (!resultaTmp.Item1) // { // throw new Exception(string.Join(Environment.NewLine, resultaTmp.Item2)); // } //} //// SE CREA NUEVA VERSION DE PRESUPUESTO //if (model.VersionId == 0) //{ // VersionPresupuesto versionPpto = new VersionPresupuesto // { // Consecutivo = model.Consecutivo, // Ejercicio = model.Ejercicio, // FechaCreacion = _unitOfWork.getDateOnlyFromServer(), // Observaciones = model.Observaciones, // TipoPresupuesto = (int)enumTipoDePresupuesto.GASTOS, // UsuarioCreacion = User.Identity.Name, // EstaCerrado = false // }; // var result = await _repo.VersionesPresupuesto.CreateAsync(versionPpto); // if (!result.Item1) // { // throw new Exception(string.Join(Environment.NewLine, result.Item2)); // } // versionPptoID = versionPpto.VersionPresupuestoId; //} //// PROCESO PARA COPIAR VERSION DE PRESUPUESTO A NUEVA VERSION //var resultNuevaVersion = _repo.Gastos // .GenerarVersion(model.VersionId, true, model.Observaciones, model.Ejercicio, model.Consecutivo, User.Identity.Name); //if (!resultNuevaVersion.Item1) //{ // throw new Exception(string.Join(Environment.NewLine, resultNuevaVersion.Item2)); //} //int versionProcesarID = FTPresupuestoProvider.getVersionPresupuestoIdByTipo(enumTipoDePresupuesto.GASTOS); //var resultActualiza = _repo.Gastos.ActualizarBase(model.EmpresaId, model.Ejercicio, versionProcesarID, idTemporal); //if (!resultActualiza.Item1) //{ // throw new Exception(string.Join(Environment.NewLine, resultActualiza.Item2)); //} ////using (FTPresupuestoEntities _db = new FTPresupuestoEntities()) ////{ //// // CONFIGURAMOS PARA QUE EL TIEMMPO DE RESPUESTA SEA INDEFINIDO //// _db.Database.CommandTimeout = 0; //// // VALIDAMOS LA VERSION DE PRESUPUESTO A PROCESAR, DEBE SER LA ULTIMA //// // SE EJECUTA LA CARGA DE PRESUPUESTO BASE //// _db.ActualizarBase_Ppto_Gastos(model.EmpresaId, model.Ejercicio, versionProcesarID, idTemporal); ////} return(Json($"El Proceso finalizo de manera correcta a las {DateTime.Now.ToLongTimeString()} el {DateTime.Now.ToShortDateString()}")); } catch (Exception ex) { string errorMensaje = ex.Message; Exception _ex = ex.InnerException; while (_ex != null) { errorMensaje = _ex.Message; _ex = _ex.InnerException; } return(Json(errorMensaje)); //Json(ex.InnerException.Message); } } return(Json("La Informacion esta Incompleta para procesar el nuevo ejercicio")); }
public async Task <Tuple <bool, string[]> > ActualizarBaseAsync(NuevaBaseEjercicioModel model, string[] selectedItems, string userName) { bool todoCorrecto = false; List <string> errores = new List <string>(); try { //var userName = System.Web.HttpContext.Current.User.Identity.Name; FTPresupuestoEntities _contextDB = _dbContextCreator() as FTPresupuestoEntities; _contextDB.Database.CommandTimeout = 0; //_contextDB.Database.BeginTransaction(); // SE CREA LA TABLA TEMPORAL Y SE ACUMULAN var resultaCrear = await ValidaExistenciaTemporalAsync(); if (!resultaCrear.Item1) { throw new Exception(string.Join(Environment.NewLine, resultaCrear.Item2)); } string idTemporal = Guid.NewGuid().ToString(); foreach (string selected in selectedItems) { short pEjercicio = 0; short.TryParse(selected.Substring(0, 4), out pEjercicio); short pMes = 0; short.TryParse(selected.Substring(4, 2), out pMes); short pEmpresa = 0; short.TryParse(selected.Substring(6, 2), out pEmpresa); var resultaTmp = AgregarEnTemporal((short)model.Ejercicio, pEjercicio, pEmpresa, pMes, idTemporal); if (!resultaTmp.Item1) { throw new Exception(string.Join(Environment.NewLine, resultaTmp.Item2)); } } // SE CREA NUEVA VERSION DE PRESUPUESTO int versionPptoID = model.VersionId; if (model.VersionId == 0) { VersionPresupuesto versionPpto = new VersionPresupuesto { Consecutivo = model.Consecutivo, Ejercicio = model.Ejercicio, FechaCreacion = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day), Observaciones = model.Observaciones, TipoPresupuesto = (int)enumTipoDePresupuesto.SEMILLAS, UsuarioCreacion = userName, EstaCerrado = false }; IVersionPresupuestoRepository verPptpRepo = new VersionPresupuestoRepository(_dbContextCreator); var result = verPptpRepo.Create(versionPpto); if (!result.Item1) { throw new Exception(string.Join(Environment.NewLine, result.Item2)); } versionPptoID = versionPpto.VersionPresupuestoId; } // PROCESO PARA COPIAR VERSION DE PRESUPUESTO A NUEVA VERSION _contextDB.GenVersion_Ppto_Semillas(model.VersionId, true, model.Observaciones, userName, model.Ejercicio, model.Consecutivo); //var resultNuevaVersion = GenerarVersion(model.VersionId, true, model.Observaciones, model.Ejercicio, model.Consecutivo, userName); //if (!resultNuevaVersion.Item1) //{ // throw new Exception(string.Join(Environment.NewLine, resultNuevaVersion.Item2)); //} int versionProcesarID = FTPresupuestoProvider.getVersionPresupuestoIdByTipo(enumTipoDePresupuesto.SEMILLAS); _contextDB.ActualizarBase_Ppto_Semillas(0, model.EmpresaId, model.Ejercicio, versionProcesarID, idTemporal); todoCorrecto = true; } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { errores.Add(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:" , eve.Entry.Entity.GetType().Name, eve.Entry.State)); foreach (var ve in eve.ValidationErrors) { errores.Add(string.Format("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"" , ve.PropertyName, eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName), ve.ErrorMessage)); } } } catch (Exception ex) { errores.Add(ex.Message); Exception _ex = ex.InnerException; while (_ex != null) { errores.Add(_ex.Message); _ex = _ex.InnerException; } } return(Tuple.Create(todoCorrecto, errores.ToArray())); }
public async Task <JsonResult> GenerarNuevaBaseEjercicioSemillas(NuevaBaseEjercicioModel model) { IRepositoryWrapper _repo = new RepositoryWrapper(); if (ModelState.IsValid) { try { string[] selectedItems = CheckBoxListExtension.GetSelectedValues <string>("chkEmpresasMesesList"); int versionActualID = FTPresupuestoProvider.getVersionPresupuestoIdByTipo(enumTipoDePresupuesto.SEMILLAS); int versionPptoID = model.VersionId; // SE VALIDA QUE NO SE HAYA EJECUTADO DOS VECES EL MISMO PROCESO if (versionPptoID > 0) { if (versionActualID != versionPptoID) { return(Json("Proceso Duplicado")); } } var resultaTotal = await _repo.Semillas.ActualizarBaseAsync(model, selectedItems, User.Identity.Name); if (!resultaTotal.Item1) { throw new Exception(string.Join(Environment.NewLine, resultaTotal.Item2)); } //// SE CREA NUEVA VERSION DE PRESUPUESTO //if (model.VersionId == 0) //{ // VersionPresupuesto versionPpto = new VersionPresupuesto // { // Consecutivo = model.Consecutivo, // Ejercicio = model.Ejercicio, // FechaCreacion = _unitOfWork.getDateOnlyFromServer(), // Observaciones = model.Observaciones, // TipoPresupuesto = (int)enumTipoDePresupuesto.SEMILLAS, // UsuarioCreacion = User.Identity.Name, // EstaCerrado = false // }; // var result = await _repo.VersionesPresupuesto.CreateAsync(versionPpto); // if (!result.Item1) // { // throw new Exception(string.Join(Environment.NewLine, result.Item2)); // } // versionPptoID = versionPpto.VersionPresupuestoId; //} //// PROCESO PARA COPIAR VERSION DE PRESUPUESTO A NUEVA VERSION //var resultNuevaVersion = _repo.Semillas // .GenerarVersion(model.VersionId, true, model.Observaciones, model.Ejercicio, model.Consecutivo, User.Identity.Name); //if (!resultNuevaVersion.Item1) //{ // throw new Exception(string.Join(Environment.NewLine, resultNuevaVersion.Item2)); //} //// SE INICIALIZA LA CONEXION Y CONTEXTO DE BASE DE DATOS //using (FTPresupuestoEntities _db = new FTPresupuestoEntities()) //{ // // CONFIGURAMOS PARA QUE EL TIEMMPO DE RESPUESTA SEA INDEFINIDO // _db.Database.CommandTimeout = 0; // // VALIDAMOS LA VERSION DE PRESUPUESTO A PROCESAR, DEBE SER LA ULTIMA // int versionProcesarID = FTPresupuestoProvider.getVersionPresupuestoIdByTipo(enumTipoDePresupuesto.SEMILLAS); // // SE EJECUTA LA CARGA DE PRESUPUESTO BASE // _db.ActualizarBase_Ppto_Semillas(0, model.EmpresaId, model.Ejercicio, versionProcesarID, ""); //} return(Json($"El Proceso finalizo de manera correcta a las {DateTime.Now.ToLongTimeString()} el {DateTime.Now.ToShortDateString()}")); } catch (Exception ex) { string errorMensaje = ex.Message; Exception _ex = ex.InnerException; while (_ex != null) { errorMensaje = _ex.Message; _ex = _ex.InnerException; } return(Json(errorMensaje)); //Json(ex.InnerException.Message); } } return(Json("La Informacion esta Incompleta para procesar el nuevo ejercicio")); }