diff --git a/phronCare.UIBlazor/Pages/Sales/Customers.razor b/phronCare.UIBlazor/Pages/Sales/Customers.razor index 7369d87..e5a1887 100644 --- a/phronCare.UIBlazor/Pages/Sales/Customers.razor +++ b/phronCare.UIBlazor/Pages/Sales/Customers.razor @@ -1,6 +1,112 @@ @page "/customers" @using phronCare.UIBlazor.Services.Sales @using phronCare.UIBlazor.Data +@using Domain.Entities +@using Domain.Generics + +@inject CustomerHttpService CustomerService + +

Buscar Clientes

+ +
+ + + + +
+ +@if (TablaClientes != null && TablaClientes.Any()) +{ + + +
+ + Página @SearchParams.Page de @TotalPaginas + +
+} +else +{ +

No hay resultados.

+} + +@code { + private CustomerSearchParams SearchParams = new(); + private PagedResult? PagedResult; + private List> TablaClientes = new(); + private List 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 + { + { "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; } + *@ \ No newline at end of file diff --git a/phronCare.UIBlazor/Shared/NavMenu.razor b/phronCare.UIBlazor/Shared/NavMenu.razor index b896984..0417354 100644 --- a/phronCare.UIBlazor/Shared/NavMenu.razor +++ b/phronCare.UIBlazor/Shared/NavMenu.razor @@ -72,7 +72,7 @@