Files
Antifraude.Net/Antifraude.Net/GestionPersonalWeb/Components/Pages/InfoNominas.razor
2026-06-08 12:58:06 +02:00

435 lines
19 KiB
Plaintext

@page "/InfoNominas"
@using System.Net.Http.Headers
@using System.Linq.Expressions
@using Layout
@using Microsoft.AspNetCore.WebUtilities
@using Newtonsoft.Json
@using System.Text
@using GestionPersonalWeb.Components
@using Serialize.Linq.Serializers
@using GestionPersonalWeb.Models
@using BlazorBootstrap
@using bdAntifraude.db
@using System.Globalization
@using Microsoft.JSInterop
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
@using GestionPersonalWeb.Components.Pages.ComponentesInfoNomina
@inject IJSRuntime JSRuntime
@rendermode InteractiveServer
@layout MainLayout
@inject IHttpClientFactory HttpClientFactory
@inject IHttpContextAccessor HttpContextAccessor
@inject UserState UserState
@inject NavigationManager Navigation
@inject ProtectedSessionStorage ProtectedSessionStore
<Toasts class="p-3 font-weight-bold" Style="color:white;" AutoHide="true" Delay="4000" Messages="messages" Placement="ToastsPlacement.BottomCenter" />
<div class="pagina">
<div class="Cabecera">
@* <h6><small><i class="fas fa-briefcase"></i><b>Puestos de Trabajo (<a href="@HashRed()" id="lblNombre"> @lblNombre</a> )</b></small></h6> *@
</div>
<EditForm FormName="FormNomina" EditContext="@editContext" OnValidSubmit="guardarFormulario" OnInvalidSubmit="@MostrarErrores" class="formDtosAdmin">
<DataAnnotationsValidator />
<div class="botonera col-12" style="display:flex; gap:5px">
<Button Class="btnOAAFAzul" @onclick="volver"><Icon CustomIconName="fas fa-long-arrow-alt-left"></Icon> </Button>
<Button Class="btnOAAFAzul" Type="ButtonType.Submit"> <Icon CustomIconName="fas fa-save"></Icon> </Button>
<Button Class="btnOAAFAzul" hidden=@ocultarBtnBrr> <Icon CustomIconName="fas fa-trash"></Icon> </Button>
</div>
<Tabs Style="padding-top:50px; width:100%;" EnableFadeEffect="true">
<Tab Title="@descNom" Active="true">
<Content>
<div class="camposficha row">
<div class="col-6 mb-2 formatoCampos">
<label class="tituloLbl">Descripción:</label>
<InputText @bind-Value="Nomina.DESCRIPCION" class="inputForm"></InputText>
</div>
<div class="col-1 mb-2 formatoCampos">
<label class="tituloLbl">Año:</label>
<InputNumber @bind-Value="Nomina.AÑO" class="inputForm"></InputNumber>
</div>
<div class="col-1 mb-2 formatoCampos">
<label class="tituloLbl">Mes:</label>
<InputNumber @bind-Value="Nomina.MES" class="inputForm"></InputNumber>
</div>
<div class="col-4 mb-2 formatoCampos">
<label class="tituloLbl">Año:</label>
<InputSelect @bind-Value="Nomina!.IDTIPO" class="inputForm">
<option value="0">-- Seleccione un tipo -- </option>
@if (listadoTipo.Count > 0)
{
@foreach (var tip in listadoTipo)
{
<option value="@tip.IDENUMERACION">@tip.DESCRIPCION</option>
}
}
</InputSelect>
</div>
<div class="col-3 mb-2 formatoCampos">
<label class="tituloLbl">Fecha Inicio:</label>
<InputDate @bind-Value="Nomina.FECHAINICIO" class="inputForm"></InputDate>
</div>
<div class="col-3 mb-2 formatoCampos">
<label class="tituloLbl">Fecha Fin:</label>
<InputDate @bind-Value="Nomina.FECHAFIN" class="inputForm"></InputDate>
</div>
<div class="col-3 mb-2 formatoCampos">
<label class="tituloLbl">Fecha Inicio Liquidación Dieta:</label>
<InputDate @bind-Value="Nomina.FECHAFINLIQUIDACIONDIETA" class="inputForm"></InputDate>
</div>
<div class="col-3 mb-2 formatoCampos">
<label class="tituloLbl">Fecha Fin Liquidación Dieta:</label>
<InputDate @bind-Value="Nomina.FECHAFINLIQUIDACIONDIETA" class="inputForm"></InputDate>
</div>
<div class="col-6 mb-2 formatoCampos">
<label class="tituloLbl">Situación:</label>
<InputSelect @bind-Value="Nomina!.IDSITUACIONNOMINA" class="inputForm">
<option value="0">-- Seleccione una situación -- </option>
@if (listadoSituacion.Count > 0)
{
@foreach (var tip in listadoSituacion)
{
<option value="@tip.IDENUMERACION">@tip.DESCRIPCION</option>
}
}
</InputSelect>
</div>
<div class="col-6 mb-2" style="display:flex; gap:30px; align-items:end">
<div style="display:flex;gap:5px;align-items:center;">
<p style="margin-bottom:0">Paga Extra: </p>
<InputCheckbox @bind-Value="Nomina.PAGAEXTRA"></InputCheckbox>
</div>
<div style="display:flex;gap:5px;align-items:center;">
<p style="margin-bottom:0">General Recibo Nómina: </p>
<InputCheckbox @bind-Value="Nomina.GENERANOMINILLA"></InputCheckbox>
</div>
<div style="display:flex;gap:5px;align-items:center;">
<p style="margin-bottom:0">Visible Intranet: </p>
<InputCheckbox @bind-Value="Nomina.VISIBLEINTRANET"></InputCheckbox>
</div>
</div>
</div>
</Content>
</Tab>
</Tabs>
<Tabs @ref=tabsDtsNom style="margin-top:25px" OnShown="@(args => OnTabShownAsync(args))">
<Tab Title="Nóminas" Name="tabNominas">
<Content>
<NominasPers Nomina="Nomina"></NominasPers>
</Content>
</Tab>
<Tab Title="Incidencias" Name="tabIncidencias">
<Content>
<NominasIncidencias Nomina="Nomina"></NominasIncidencias>
</Content>
</Tab>
<Tab Title="Otras Retribuciones" Name="tabRetri">
<Content>
<NominasOtrasRet Nomina="Nomina"></NominasOtrasRet>
</Content>
</Tab>
<Tab Title="Enférmedades" Name="tabEnfermedades">
<Content>
<NominasEnfermedades Nomina="Nomina"></NominasEnfermedades>
</Content>
</Tab>
</Tabs>
</EditForm>
@if (!string.IsNullOrEmpty(idNom))
{
@* <Tabs Style="padding-top:50px; width:100%;" EnableFadeEffect="true">
<Tab Title="Descripción RPT" Active="true">
<Content>
<div style="display:block;gap:10px; margin-bottom:20px;" class="mt-4">
<Button class="btnOAAFAzul"> Nuevo puesto </Button>
<Grid TItem="bdAntifraude.db.PUESTOS"
Class="table tablaRegPers"
Data="Nomina"
AllowFiltering="false"
PageSize="10"
AllowPaging="true"
AllowSorting="true"
EmptyText="No se han encontrado datos"
Height="100"
PageSizeSelectorVisible="false"
PageSizeSelectorItems="@(new int[] { 5,10,20,50 })"
Responsive="true"
PaginationItemsTextFormat="{0} - {1} de {2} elementos">
<GridColumns> *@
@* <GridColumn TItem="bdAntifraude.db.PUESTOS" HeaderText="Código" Class="col-1" PropertyName="CODIGO" SortKeySelector="item => item.CODIGO">
@context.CODIGO
</GridColumn>
<GridColumn TItem="bdAntifraude.db.PUESTOS" HeaderText="Estado" Class="col-1" PropertyName="ESTADO" SortKeySelector="item => item.ESTADO">
@context.ESTADO
</GridColumn>
<GridColumn TItem="bdAntifraude.db.PUESTOS" HeaderText="Dotación" PropertyName="IDDOTACIONNavigation">
@context.IDDOTACIONNavigation?.DESCRIPCION
</GridColumn>
<GridColumn TItem="bdAntifraude.db.PUESTOS" HeaderText="Persona" PropertyName="IDPERSONALNavigation">
@context.IDPERSONALNavigation?.NOMBRE @context.IDPERSONALNavigation?.APELLIDOS
</GridColumn>
<GridColumn TItem="bdAntifraude.db.PUESTOS" HeaderText="Ocupación" PropertyName="IDOCUPACIONNavigation">
@context.IDOCUPACIONNavigation?.DESCRIPCION
</GridColumn>
<GridColumn TItem="bdAntifraude.db.PUESTOS" HeaderText="Titular" PropertyName="TITULARNavigation">
@context.TITULARNavigation?.NOMBRE @context.TITULARNavigation?.APELLIDOS
</GridColumn>
<GridColumn TItem="bdAntifraude.db.PUESTOS" HeaderText="Adscripción al servicio" PropertyName="IDRPTNavigation?.IDSITUACIONNavigation">
@context.IDSERVICIOADSCRITONavigation?.DESCRIPCION
</GridColumn>
<GridColumn TItem="bdAntifraude.db.PUESTOS" Class="col-1" HeaderText="">
<span @onclick="@(() => abrirPopupPuestos(@context))" style="cursor: pointer;">
<Icon CustomIconName="fas fa-edit"></Icon>
</span>
<span @onclick="@(() => abrirPopupConfirmacion(@context))" style="cursor: pointer;">
<Icon CustomIconName="fas fa-trash"></Icon>
</span>
</GridColumn> *@
@* </GridColumns> *@
@* </Grid> *@
@*
</div>
</Content> *@
@* </Tab>
</Tabs> *@
}
</div>
@code {
/// ATRIBUTOS
[Parameter]
public string? cl { get; set; } = "";
[Parameter]
public string? np { get; set; } = "";
public bool ocultarBtnBrr { get; set; }
private bool desactivarPlaza { get; set; }
public string idNom { get; set; } = "";
private Tabs tabsDtsNom { get; set; } = new Tabs();
List<ToastMessage> messages = new List<ToastMessage>();
private NOMINAS Nomina { get; set; } = new NOMINAS();
private List<ENUMERACIONES> listadoTipo = new List<ENUMERACIONES>();
private List<ENUMERACIONES> listadoSituacion = new List<ENUMERACIONES>();
private string tituloPopup = "";
private Modal popupNewPuesto = default!;
private Modal popupConfirmacion = default!;
public bool borrarPuesto { get; set; }
private EditContext? editContext;
private string descNom { get; set; }
private HttpClient client { get; set; } = new HttpClient();
private ExpressionSerializer? serializer { get; set; }
private async Task CargarCliente()
{
var token = UserState.Token;
client = HttpClientFactory.CreateClient();
client.BaseAddress = new Uri(Utilidades.urlSwagger());
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
serializer = new ExpressionSerializer(new Serialize.Linq.Serializers.JsonSerializer());
}
private async Task OnTabShownAsync(TabsEventArgs args)
{
var panelActivo = args.ActiveTabName;
await ProtectedSessionStore.SetAsync("ultiTabNom", panelActivo);
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var nombreTabsActivo = await ProtectedSessionStore.GetAsync<string>("ultiTabNom");
if (nombreTabsActivo.Value != null && tabsDtsNom != null)
{
await tabsDtsNom.ShowTabByNameAsync(nombreTabsActivo.Value);
}
}
}
protected override async Task OnInitializedAsync()
{
try
{
await CargarCliente();
editContext = new EditContext(Nomina);
messageStore = new ValidationMessageStore(editContext);
var uri = Navigation.ToAbsoluteUri(Navigation.Uri);
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("cl", out var clValue))
{
cl = clValue;
}
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("np", out var clValueNp))
{
np = clValueNp;
// idRPT = tsUtilidades.crypt.FEncS(np, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/-*", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/-*", -875421649);
}
idNom = tsUtilidades.crypt.FEncS(cl, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/-*", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/-*", -875421649);
cliente = Utilidades.ObtenerCliente(UserState.Token, HttpClientFactory);
if (string.IsNullOrEmpty(idNom))
{
ocultarBtnBrr = true;
descNom = "NUEVA NOMINA";
}
else
{
ocultarBtnBrr = false;
desactivarPlaza = true;
var response = await client.GetAsync("/api/NOMINAS/" + idNom.ToString());
var ResponseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
Nomina = JsonConvert.DeserializeObject<NOMINAS>(ResponseContent) ?? new NOMINAS();
}
else
{
Nomina = new NOMINAS();
}
descNom = Nomina.DESCRIPCION;
// lblNombre = Model?.IDRPTNavigation?.DESCRIPCION ?? "";
await obtListadoSituacion();
await obtListadoTipo();
var culture = new CultureInfo("es-ES");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
linkVolver = "/Nominas";
}
catch (Exception e)
{
Console.WriteLine($"Error al obtener los datos: {e.Message}");
}
}
private string HashRed(string id)
{
string link = "/InfoNominas?cl=" + tsUtilidades.crypt.FEncS(
id,
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/-*",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:/-*",
875421649);
return link;
}
protected void volver() { Navigation.NavigateTo(linkVolver, forceLoad: true); }
// LISTADOS PARA COMBOBOX
private void MostrarErrores()
{
// messageStore?.Clear();
// foreach (var field in new[] { nameof(Model.GRUPO1), nameof(Model.PLAZAS) })
// {
// ValidarYActualizar(new ChangeEventArgs { Value = typeof(DesgloseRPTVM).GetProperty(field)?.GetValue(Model) }, field);
// }
}
private async Task guardarFormulario()
{
// try
// {
// ValidarTodo();
// if (!editContext!.GetValidationMessages().Any())
// {
// await guardarRPTForm();
// messages.Add(new ToastMessage
// {
// Type = ToastType.Primary,
// Message = $"Guardado correctamente.",
// });
// }
// else
// {
// messages.Add(new ToastMessage
// {
// Type = ToastType.Warning,
// Message = $"Debe rellenar los campos obligatorios.",
// });
// }
// }
// catch (Exception)
// {
// messages.Add(new ToastMessage
// {
// Type = ToastType.Danger,
// Message = $"Error al guardar.",
// });
// }
}
private async Task obtListadoTipo()
{
try
{
Expression<Func<ENUMERACIONES, bool>> filtro = x => x.IDGRUPOENUMERACIONNavigation!.GRUPO! == "TIPONOM";
List<ENUMERACIONES> enumsEncontrado = await Utilidades.ObtenerObjeto<List<ENUMERACIONES>>(cliente, "/api/ENUMERACIONES/filtrar", filtro);
listadoTipo = enumsEncontrado;
}
catch (Exception e)
{
Console.WriteLine($"Error al obtener los datos: {e.Message}");
}
}
private async Task obtListadoSituacion(){
try
{
Expression<Func<ENUMERACIONES, bool>> filtro = x => x.IDGRUPOENUMERACIONNavigation!.GRUPO! == "SITNOM";
List<ENUMERACIONES> enumsEncontrado = await Utilidades.ObtenerObjeto<List<ENUMERACIONES>>(cliente, "/api/ENUMERACIONES/filtrar", filtro);
listadoSituacion = enumsEncontrado;
}
catch (Exception e)
{
Console.WriteLine($"Error al obtener los datos: {e.Message}");
}
}
private bool showDropdown { get; set; }
private bool showDropdowntit { get; set; }
private string filterText { get; set; } = "";
private string filterTextTit { get; set; } = "";
private string linkVolver { get; set; } = "";
//LIST GRID PUESTOS
private NOMINAS Nominas { get; set; }
private HttpClient cliente = new HttpClient();
private ValidationMessageStore? messageStore;
}