diff --git a/HerramientaCASA/Components/Pages/ConfiguracionPages/Enumeraciones.razor b/HerramientaCASA/Components/Pages/ConfiguracionPages/Enumeraciones.razor index 1855c61..6fe8531 100644 --- a/HerramientaCASA/Components/Pages/ConfiguracionPages/Enumeraciones.razor +++ b/HerramientaCASA/Components/Pages/ConfiguracionPages/Enumeraciones.razor @@ -38,14 +38,20 @@ - +
- + + +
+ +
+
+
diff --git a/HerramientaCASA/Components/Pages/ConfiguracionPages/EnumeracionesTabs/FasesURBANConf.razor b/HerramientaCASA/Components/Pages/ConfiguracionPages/EnumeracionesTabs/FasesURBANConf.razor new file mode 100644 index 0000000..9856d1b --- /dev/null +++ b/HerramientaCASA/Components/Pages/ConfiguracionPages/EnumeracionesTabs/FasesURBANConf.razor @@ -0,0 +1,425 @@ +@inject NavigationManager Navigation +@layout ConfiguracionLayout +@using BlazorBootstrap +@using System.Globalization +@using bdHerramientaCACOA.db + + + + + +
+ ¿Estás seguro que desea eliminarlo? +
+
+ + + + +
+ + + + + +
+
+ + +
+
@GetExternalValidationMessage(nameof(descripcionItem))
+
+ +
+
+ + + +
+
@GetExternalValidationMessage(nameof(valorNumericoItem))
+ +
+ + + +
+
@GetExternalValidationMessage(nameof(plazosItem))
+
+ +
+
+ + + +
+
+ + +
+ + + + +
+
+ + + +
+ +
+

+ +
+ + + + + @context.ValorAlfabetico1 + + + + @context.ValorNumerico1 + + + + @context.ValorNumerico2 + + + @context.Orden + + +
+ + + + + + +
+
+
+
+
+ +@code { + + public List listadoFases { get; set; } = new List(); + + [SupplyParameterFromForm] + private enumeraciones itemSeleccionado { get; set; } = new enumeraciones(); + + private string tituloPopup = ""; + private Modal popupGestionDatos = default!; + private Modal popupConfirmarBorrado = default!; + + private double? valorNumericoOriginal; + + private bool nuevoElemento; + + private string descripcionItem = ""; + private int? ordenItem = 0; + private double? valorNumericoItem = 0; + private double? plazosItem = 0; + + List mensajes = new List(); + + private EditContext? editContext; + private ValidationMessageStore? messageStore; + public tsHerramientasCACOA bd; + private string codigoEnumeracion = "FASURB"; + + protected override async Task OnInitializedAsync() + { + bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false); + + editContext = new EditContext(itemSeleccionado); + messageStore = new ValidationMessageStore(editContext); + + listadoFases = UtilidadesCASA.devolverListadoOrdenadoEnumeracion(bd, codigoEnumeracion); + } + + + private async Task abrirPopupGestionDatos(enumeraciones objeto, bool esNuevo) + { + valorNumericoOriginal = objeto.ValorNumerico1; + itemSeleccionado = objeto; + + if (esNuevo) + { + nuevoElemento = true; + + + descripcionItem = ""; + ordenItem = 0; + valorNumericoItem = 0; + plazosItem = 0; + } + else + { + nuevoElemento = false; + + descripcionItem = objeto.ValorAlfabetico1; + ordenItem = objeto.Orden; + valorNumericoItem = objeto.ValorNumerico1; + plazosItem = objeto.ValorNumerico2; + } + + if (!nuevoElemento) + { + tituloPopup = "Modificar fase"; + } + else + { + tituloPopup = "Nueva fase"; + } + + await popupGestionDatos.ShowAsync(); + } + private async Task cerrarPopupGestionDatos() + { + await popupGestionDatos.HideAsync(); + } + + private void ValidarYActualizar(ChangeEventArgs e, string fieldName) + { + var value = e.Value?.ToString(); + var field = new FieldIdentifier(itemSeleccionado, fieldName); + + switch (fieldName) + { + case nameof(descripcionItem): + if (!string.IsNullOrEmpty(value)) + { + + descripcionItem = value; + } + else + { + descripcionItem = ""; + } + break; + + case nameof(valorNumericoItem): + + if (!string.IsNullOrEmpty(value)) + { + + string parseado = value.Replace(",", "."); + valorNumericoItem = double.Parse(parseado, CultureInfo.InvariantCulture); + } + + break; + case nameof(plazosItem): + + if (!string.IsNullOrEmpty(value)) + { + + string parseado = value.Replace(",", "."); + plazosItem = double.Parse(parseado, CultureInfo.InvariantCulture); + } + + break; + } + + messageStore?.Clear(field); + if (fieldName == nameof(descripcionItem) && descripcionItem == "") + { + messageStore?.Add(field, "La descripción no puede estar vacía."); + } + + if (fieldName == nameof(valorNumericoItem) && valorNumericoItem == null) + { + messageStore?.Add(field, "El valor numérico no puede estar vacío."); + } + + editContext?.NotifyValidationStateChanged(); + } + + + private void ValidarTodo() + { + ValidarYActualizar(new ChangeEventArgs { Value = descripcionItem }, nameof(descripcionItem)); + ValidarYActualizar(new ChangeEventArgs { Value = valorNumericoItem }, nameof(valorNumericoItem)); + ValidarYActualizar(new ChangeEventArgs { Value = plazosItem }, nameof(plazosItem)); + } + + private string GetExternalValidationMessage(string fieldName) + { + var field = new FieldIdentifier(itemSeleccionado, fieldName); + return messageStore?[field].FirstOrDefault() ?? string.Empty; + } + + private async Task GestionarDatos(string accion) + { + + var enumObtenido = bd.enumeraciones.Where(x => x.idEnumeracion == itemSeleccionado.idEnumeracion).FirstOrDefault(); + + itemSeleccionado.ValorAlfabetico1 = descripcionItem; + itemSeleccionado.Orden = ordenItem; + itemSeleccionado.ValorNumerico1 = valorNumericoItem; + itemSeleccionado.ValorNumerico2 = plazosItem; + + + switch (accion) + { + case "update": + UtilidadesCASA.guardarEnumeracion(bd, itemSeleccionado, codigoEnumeracion, nuevoElemento, enumObtenido); + + await cerrarPopupGestionDatos(); + + mensajes.Add(new ToastMessage + { + Type = ToastType.Primary, + Message = $"Actualizado correctamente.", + }); + + break; + + case "create": + UtilidadesCASA.guardarEnumeracion(bd, itemSeleccionado, codigoEnumeracion, nuevoElemento); + + await cerrarPopupGestionDatos(); + mensajes.Add(new ToastMessage + { + Type = ToastType.Primary, + Message = $"Guardado correctamente.", + }); + break; + + case "delete": + UtilidadesCASA.eliminarEnumeracion(bd, enumObtenido); + + await cerrarPopupConfirmarBorrado(); + mensajes.Add(new ToastMessage + { + Type = ToastType.Primary, + Message = $"Eliminado correctamente.", + }); + break; + } + bd.SaveChanges(); + listadoFases = UtilidadesCASA.devolverListadoOrdenadoEnumeracion(bd, codigoEnumeracion); + await InvokeAsync(StateHasChanged); + } + + + private async Task BorrarItem() + { + await GestionarDatos("delete"); + } + //////// PopUp eliminar registro + private async Task abrirPopupConfirmarBorrado(enumeraciones objeto) + { + itemSeleccionado = objeto; + await popupConfirmarBorrado.ShowAsync(); + } + private async Task cerrarPopupConfirmarBorrado() + { + await popupConfirmarBorrado.HideAsync(); + } + + // GUARDAR + private async Task guardarFormulario() + { + try + { + ValidarTodo(); + + if (!editContext!.GetValidationMessages().Any()) + { + string accion = nuevoElemento ? "create" : "update"; + bool porcentajeMenosCien = comprobarPorcentaje(); + + if (porcentajeMenosCien) + { + await GestionarDatos(accion); + } + else + { + await cerrarPopupGestionDatos(); + itemSeleccionado.ValorNumerico1 = valorNumericoOriginal; + await InvokeAsync(StateHasChanged); + mensajes.Add(new ToastMessage + { + Type = ToastType.Warning, + Message = $"El porcentaje total no puede ser mayor de 100.", + }); + + } + } + else + { + mensajes.Add(new ToastMessage + { + Type = ToastType.Warning, + Message = $"Debe rellenar los campos obligatorios.", + }); + } + + } + catch (Exception) + { + mensajes.Add(new ToastMessage + { + Type = ToastType.Danger, + Message = $"Error al guardar.", + }); + } + + } + + private void MostrarErrores() + { + messageStore?.Clear(); + foreach (var field in new[] { nameof(descripcionItem), nameof(valorNumericoItem) }) + { + ValidarYActualizar(new ChangeEventArgs { Value = typeof(enumeraciones).GetProperty(field)?.GetValue(itemSeleccionado) }, field); + } + } + + + private bool comprobarPorcentaje() + { + bool menorCien = false; + + var porcentajeTotal = listadoFases.Sum(x => x.ValorNumerico1); + + if (!nuevoElemento) + { + if (porcentajeTotal <= 100) + { + menorCien = true; + } + } + else + { + if (porcentajeTotal + valorNumericoItem <= 100) + { + menorCien = true; + } + } + + + return menorCien; + } + +} \ No newline at end of file diff --git a/HerramientaCASA/Components/Pages/HerramientaCASATabs/CostesProduccionComponents/HorasCostes.razor b/HerramientaCASA/Components/Pages/HerramientaCASATabs/CostesProduccionComponents/HorasCostes.razor index 021a194..60f3a96 100644 --- a/HerramientaCASA/Components/Pages/HerramientaCASATabs/CostesProduccionComponents/HorasCostes.razor +++ b/HerramientaCASA/Components/Pages/HerramientaCASATabs/CostesProduccionComponents/HorasCostes.razor @@ -83,7 +83,7 @@ - + @@ -95,12 +95,25 @@ - + - + diff --git a/bdHerramientaCACOA/LicitacionesURBAN.cs b/bdHerramientaCACOA/LicitacionesURBAN.cs index 4ba7087..24a9d55 100644 --- a/bdHerramientaCACOA/LicitacionesURBAN.cs +++ b/bdHerramientaCACOA/LicitacionesURBAN.cs @@ -145,17 +145,36 @@ namespace bdHerramientaCACOA var listaFases = bd.enumeraciones.Where(x => x.idGrupoEnumeracion == grupoFases.idGrupoEnumeracion).ToList(); foreach (enumeraciones enu in listaFases) { - FasesURBAN ft = new FasesURBAN(); - ft.idFase = enu.idEnumeracion; - ft.Codigo = enu.Codigo; - ft.Denominacion = enu.ValorAlfabetico1; - ft.Porcentaje = (double)enu.ValorNumerico1; + if (!TrabajoProfesional.FasesTrabajoProfesional.Any(x => x.idFase == enu.idEnumeracion)) + { + FasesURBAN ft = new FasesURBAN(); + ft.idFase = enu.idEnumeracion; + ft.Codigo = enu.Codigo; + ft.Denominacion = enu.ValorAlfabetico1; + ft.Porcentaje = (double)enu.ValorNumerico1; - TrabajoProfesional.FasesTrabajoProfesional.Add(ft); + TrabajoProfesional.FasesTrabajoProfesional.Add(ft); + } } + + checkListFasesURBAN(listaFases); + + Enumerados.FasesTrabajo = JsonSerializer.Deserialize>(JsonSerializer.Serialize(TrabajoProfesional.FasesTrabajoProfesional)); } + private void checkListFasesURBAN(List listaFases) + { + var itemsAEliminar = TrabajoProfesional.FasesTrabajoProfesional + .Where(item => !listaFases.Any(x => x.idEnumeracion == item.idFase)) + .ToList(); + + foreach (var item in itemsAEliminar) + { + TrabajoProfesional.FasesTrabajoProfesional.Remove(item); + } + } + public void CalcularLicitacion() { var horasAnualesDes = Math.Round(TrabajoProfesional.horasTrabProfesional * 12 / PlazoPresentacionDocumentos,2,MidpointRounding.AwayFromZero); var CD = ObtenerCDTabla(horasAnualesDes);
TrabajosTrabajos Horas
Horas de documentación en Despacho Profesional@objetoCASA.CostesProduccion.HorasProduccionDespachoElabDocumentacion.MilesYDecimales() h +
+ + @objetoCASA.CostesProduccion.HorasProduccionDespachoElabDocumentacion.MilesYDecimales() + + + h + +
+
Horas de documentación mediante externalización@objetoCASA.CostesProduccion.NumHorasMinimoExt.MilesYDecimales() h +
+ @objetoCASA.CostesProduccion.NumHorasMinimoExt.MilesYDecimales() h +
+