All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m44s
208 lines
8.0 KiB
Plaintext
208 lines
8.0 KiB
Plaintext
@page "/sales/customers"
|
|
@using phronCare.UIBlazor.Services.Sales
|
|
@using Domain.Entities
|
|
@using Domain.Generics
|
|
@inject IToastService toastService
|
|
@inject NavigationManager Navigation
|
|
@inject CustomerService customerService
|
|
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-center align-items-center" style="zoom:80%;">
|
|
<h3 class="card-title m-0">Búsqueda de clientes</h3> @* wtf? *@
|
|
</div>
|
|
<div class="card-body" style="zoom:80%;">
|
|
<div class="mb-4 space-y-2" >
|
|
<input @bind="SearchParams.Name" placeholder="Nombre" class="border rounded p-1 w-full" />
|
|
<input @bind="SearchParams.Email" placeholder="Email" class="border rounded p-1 w-full" />
|
|
<input @bind="SearchParams.Document" placeholder="Documento" class="border rounded p-1 w-full" />
|
|
<button class="btn btn-primary rounded-pill" @onclick="BuscarClientes">
|
|
<i class="fas fa-binoculars me-1"></i> Buscar
|
|
</button>
|
|
<button class="btn btn-success rounded-pill" @onclick="NuevoCliente">
|
|
<i class="fas fa-plus me-1"></i> Nuevo
|
|
</button>
|
|
<button class="btn btn-success rounded-pill" @onclick="ExportarExcel">
|
|
<i class="fas fa-file-excel me-1"></i> Excel
|
|
</button>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="Cancel">
|
|
<i class="fas fa-arrow-left me-1"></i> Volver
|
|
</button>
|
|
</div>
|
|
<hr />
|
|
<div>
|
|
@if (TablaClientes != null && TablaClientes.Any())
|
|
{
|
|
<PhTable Columns="TableColumns"
|
|
Data="TablaClientes"
|
|
SelectionField="Id"
|
|
RowsPerPage=SearchParams.PageSize
|
|
RenderButtons="true" Buttons="botones"
|
|
ShowPageButtons="false"
|
|
ShowQuickSearch="false"
|
|
RenderSelect="false"
|
|
/>
|
|
|
|
}
|
|
else
|
|
{
|
|
<p>No hay resultados.</p>
|
|
}
|
|
|
|
</div>
|
|
</div>
|
|
<div class="card-footer d-flex justify-content-center align-items-center" style="zoom:80%;">
|
|
<div class="d-flex align-items-center gap-3">
|
|
<button class="btn btn-secondary rounded-pill" @onclick="PrimeraPagina" disabled="@(SearchParams.Page == 1)">
|
|
<i class="fas fa-angle-double-left me-1"></i> Primera
|
|
</button>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="AnteriorPagina" disabled="@(!PuedeRetroceder)">
|
|
<i class="fas fa-chevron-left me-1"></i> Anterior
|
|
</button>
|
|
<span class="mx-2">
|
|
Página <strong>@SearchParams.Page</strong> de <strong>@TotalPaginas</strong>
|
|
</span>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="SiguientePagina" disabled="@(!PuedeAvanzar)">
|
|
Siguiente <i class="fas fa-chevron-right ms-1"></i>
|
|
</button>
|
|
<button class="btn btn-secondary rounded-pill" @onclick="UltimaPagina" disabled="@(SearchParams.Page == TotalPaginas)">
|
|
Última <i class="fas fa-angle-double-right ms-1"></i>
|
|
</button>
|
|
<div class="d-flex align-items-center ms-3">
|
|
<input type="number" class="form-control form-control-sm rounded" style="width: 80px;" min="1" max="@TotalPaginas" @bind="PaginaDeseada" />
|
|
<button class="btn btn-outline-primary btn-sm ms-2 rounded-pill" @onclick="IrAPagina">
|
|
<i class="fas fa-arrow-right-to-bracket me-1"></i> Ir
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@code {
|
|
protected override void OnInitialized()
|
|
{
|
|
botones = new List<PhTable.ButtonOptions>
|
|
{
|
|
new PhTable.ButtonOptions
|
|
{
|
|
Caption = "Editar",
|
|
ElementClass = "btn btn-primary btn-sm",
|
|
UrlAction = "/sales/customers/edit/",
|
|
OnClickAction = async (id) =>
|
|
{
|
|
if (int.TryParse(id, out var customerId))
|
|
{
|
|
Navigation.NavigateTo($"/sales/customerform/{customerId}");
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
private CustomerSearchParams SearchParams = new();
|
|
private PagedResult<ECustomer>? PagedResult;
|
|
private List<Dictionary<string, object>> TablaClientes = new();
|
|
private List<string> TableColumns = new()
|
|
{
|
|
"Id", "Nombre", "Activo", "Crédito", "Límite",
|
|
"Email", "Teléfono", "Dirección", "Documento"
|
|
};
|
|
private int PaginaDeseada = 1;
|
|
|
|
private async Task PrimeraPagina()
|
|
{
|
|
SearchParams.Page = 1;
|
|
await BuscarClientes();
|
|
}
|
|
private async Task UltimaPagina()
|
|
{
|
|
SearchParams.Page = TotalPaginas;
|
|
await BuscarClientes();
|
|
}
|
|
private async Task IrAPagina()
|
|
{
|
|
if (PaginaDeseada >= 1 && PaginaDeseada <= TotalPaginas)
|
|
{
|
|
SearchParams.Page = PaginaDeseada;
|
|
await BuscarClientes();
|
|
}
|
|
else
|
|
{
|
|
toastService.ShowWarning("Número de página fuera de rango.");
|
|
}
|
|
}
|
|
private async Task BuscarClientes()
|
|
{
|
|
await CargarClientes();
|
|
}
|
|
private async Task CargarClientes()
|
|
{
|
|
PagedResult = await customerService.SearchCustomersAsync(SearchParams);
|
|
if (PagedResult?.Items is not null)
|
|
{
|
|
TablaClientes = PagedResult.Items.Select(c =>
|
|
{
|
|
var addr = c.PhSCustomerAddresses.FirstOrDefault();
|
|
var doc = c.PhSCustomerDocuments.FirstOrDefault();
|
|
|
|
return new Dictionary<string, object>
|
|
{
|
|
{ "Id", c.Id },
|
|
{ "Nombre", c.Name ?? string.Empty },
|
|
{ "Activo", c.Active ? "Sí" : "No" },
|
|
{ "Crédito", c.HasCreditAccount ? "Sí" : "No" },
|
|
{ "Límite", c.CreditLimit },
|
|
{ "Email", addr?.Email ?? string.Empty },
|
|
{ "Teléfono", addr?.Phonenumber ?? string.Empty },
|
|
{ "Dirección", addr is not null
|
|
? $"{addr.Streetaddress1}, {addr.City}, {addr.Postalcode}"
|
|
: string.Empty },
|
|
{ "Documento", doc?.DocumentNumber ?? string.Empty }
|
|
};
|
|
}).ToList();
|
|
}
|
|
}
|
|
private async Task SiguientePagina() => await CambiarPagina(1);
|
|
private async Task AnteriorPagina() => await CambiarPagina(-1);
|
|
private async Task CambiarPagina(int delta)
|
|
{
|
|
var nuevaPagina = SearchParams.Page + delta;
|
|
if (nuevaPagina >= 1 && nuevaPagina <= TotalPaginas)
|
|
{
|
|
SearchParams.Page = nuevaPagina;
|
|
await CargarClientes();
|
|
}
|
|
}
|
|
private async Task ExportarExcel()
|
|
{
|
|
// Crea el objeto de parámetros para la búsqueda
|
|
var searchParams = new CustomerSearchParams
|
|
{
|
|
Name = SearchParams.Name, // Aquí podés obtener los filtros de los campos en el formulario
|
|
Email = SearchParams.Email,
|
|
Document = SearchParams.Document,
|
|
Page = 1,
|
|
PageSize = int.MaxValue // Puedes ajustar el tamaño de la página para exportar todos los registros
|
|
};
|
|
try
|
|
{
|
|
await customerService.ExportFilteredAsync(searchParams);
|
|
toastService.ShowSuccess("Exportación completada exitosamente.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
toastService.ShowError($"{ex.Message}");
|
|
}
|
|
}
|
|
|
|
private bool PuedeRetroceder => PagedResult != null && SearchParams.Page > 1;
|
|
private bool PuedeAvanzar => PagedResult != null && SearchParams.Page < TotalPaginas;
|
|
private int TotalPaginas => PagedResult is null ? 1 :
|
|
(int)Math.Ceiling((double)(PagedResult.TotalItems) / SearchParams.PageSize);
|
|
private void NuevoCliente()
|
|
{
|
|
Navigation.NavigateTo("/sales/customerform/");
|
|
}
|
|
public void Cancel()
|
|
{
|
|
Navigation.NavigateTo("/DashboardPanel");
|
|
}
|
|
List<PhTable.ButtonOptions> botones = new();
|
|
} |