Add PhTable in Customers
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m12s
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m12s
This commit is contained in:
parent
b60a8bdd0f
commit
a65581a034
@ -1,6 +1,112 @@
|
||||
@page "/customers"
|
||||
@using phronCare.UIBlazor.Services.Sales
|
||||
@using phronCare.UIBlazor.Data
|
||||
@using Domain.Entities
|
||||
@using Domain.Generics
|
||||
|
||||
@inject CustomerHttpService CustomerService
|
||||
|
||||
<h3 class="text-xl font-bold mb-4">Buscar Clientes</h3>
|
||||
|
||||
<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="bg-blue-500 text-white px-4 py-2 rounded" @onclick="BuscarClientes">Buscar</button>
|
||||
</div>
|
||||
|
||||
@if (TablaClientes != null && TablaClientes.Any())
|
||||
{
|
||||
<PhTable Columns="TableColumns"
|
||||
Data="TablaClientes"
|
||||
RowsPerPage="0"
|
||||
ShowQuickSearch="true"
|
||||
RenderSelect="false"
|
||||
RenderButtons="false" />
|
||||
|
||||
<div class="mt-4 flex justify-between items-center">
|
||||
<button class="bg-gray-300 px-4 py-2 rounded" @onclick="AnteriorPagina" disabled="@(!PuedeRetroceder)">Anterior</button>
|
||||
<span>Página @SearchParams.Page de @TotalPaginas</span>
|
||||
<button class="bg-gray-300 px-4 py-2 rounded" @onclick="SiguientePagina" disabled="@(!PuedeAvanzar)">Siguiente</button>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>No hay resultados.</p>
|
||||
}
|
||||
|
||||
@code {
|
||||
private CustomerSearchParams SearchParams = new();
|
||||
private PagedResult<ECustomer>? PagedResult;
|
||||
private List<Dictionary<string, object>> TablaClientes = new();
|
||||
private List<string> TableColumns = new()
|
||||
{
|
||||
"Id", "Nombre", "Razon Social", "Activo", "Código Externo", "Crédito", "Límite",
|
||||
"Email", "Teléfono", "Dirección", "Documento"
|
||||
};
|
||||
|
||||
private async Task BuscarClientes()
|
||||
{
|
||||
SearchParams.Page = 1;
|
||||
await CargarClientes();
|
||||
}
|
||||
|
||||
private async Task CargarClientes()
|
||||
{
|
||||
PagedResult = await CustomerService.SearchCustomersAsync(SearchParams);
|
||||
|
||||
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 },
|
||||
{ "Razon Social", c.BusinessName },
|
||||
{ "Activo", c.Active ? "Sí" : "No" },
|
||||
{ "Código Externo", c.ExternalCode },
|
||||
{ "Crédito", c.HasCreditAccount ? "Sí" : "No" },
|
||||
{ "Límite", c.CreditLimit },
|
||||
{ "Email", addr?.Email ?? "" },
|
||||
{ "Teléfono", addr?.Phonenumber ?? "" },
|
||||
{ "Dirección", $"{addr?.Streetaddress1} {addr?.Streetaddress2}, {addr?.City}, {addr?.Postalcode}, {addr?.Country}" },
|
||||
{ "Documento", $"{doc?.DocumentNumber} | {doc?.IssueDate?.ToString("yyyy-MM-dd")} - {doc?.ExpiryDate?.ToString("yyyy-MM-dd")}" }
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private async Task SiguientePagina()
|
||||
{
|
||||
if (PuedeAvanzar)
|
||||
{
|
||||
SearchParams.Page++;
|
||||
await CargarClientes();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AnteriorPagina()
|
||||
{
|
||||
if (PuedeRetroceder)
|
||||
{
|
||||
SearchParams.Page--;
|
||||
await CargarClientes();
|
||||
}
|
||||
}
|
||||
|
||||
private int TotalPaginas => PagedResult is null ? 1 :
|
||||
(int)Math.Ceiling((double)(PagedResult.TotalItems) / SearchParams.PageSize);
|
||||
|
||||
private bool PuedeAvanzar => PagedResult != null && SearchParams.Page < TotalPaginas;
|
||||
private bool PuedeRetroceder => PagedResult != null && SearchParams.Page > 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@* @page "/customers"
|
||||
@using phronCare.UIBlazor.Services.Sales
|
||||
@using phronCare.UIBlazor.Data
|
||||
@using Domain.Generics
|
||||
|
||||
@inject CustomerHttpService CustomerService
|
||||
@ -141,3 +247,4 @@ else
|
||||
private bool PuedeAvanzar => PagedResult != null && SearchParams.Page < TotalPaginas;
|
||||
private bool PuedeRetroceder => PagedResult != null && SearchParams.Page > 1;
|
||||
}
|
||||
*@
|
||||
@ -72,7 +72,7 @@
|
||||
</NavLink>
|
||||
</div>
|
||||
<div class="nav-item px-1">
|
||||
<NavLink class="nav-link">
|
||||
<NavLink class="nav-link" href="sales/customers/">
|
||||
<li aria-hidden="true"></li> Listado
|
||||
</NavLink>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user