Add CustomerForm
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 12m18s
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 12m18s
This commit is contained in:
parent
f1cfad2c11
commit
0f4176a5b2
@ -9,34 +9,19 @@ namespace Domain.Entities
|
|||||||
public class ECustomerAddress
|
public class ECustomerAddress
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public int CustomersId { get; set; }
|
public int CustomersId { get; set; }
|
||||||
|
|
||||||
public string? BusinessName { get; set; }
|
public string? BusinessName { get; set; }
|
||||||
|
|
||||||
public string? Streetaddress1 { get; set; }
|
public string? Streetaddress1 { get; set; }
|
||||||
|
|
||||||
public string? Streetaddress2 { get; set; }
|
public string? Streetaddress2 { get; set; }
|
||||||
|
|
||||||
public string? City { get; set; }
|
public string? City { get; set; }
|
||||||
|
|
||||||
public string? Stateprovince { get; set; }
|
public string? Stateprovince { get; set; }
|
||||||
|
|
||||||
public string? Postalcode { get; set; }
|
public string? Postalcode { get; set; }
|
||||||
|
|
||||||
public string? Country { get; set; }
|
public string? Country { get; set; }
|
||||||
|
|
||||||
public decimal? Latitude { get; set; }
|
public decimal? Latitude { get; set; }
|
||||||
|
|
||||||
public decimal? Longitude { get; set; }
|
public decimal? Longitude { get; set; }
|
||||||
|
|
||||||
public string? Phonenumber { get; set; }
|
public string? Phonenumber { get; set; }
|
||||||
|
|
||||||
public string? Email { get; set; }
|
public string? Email { get; set; }
|
||||||
|
|
||||||
public string? Notes { get; set; }
|
public string? Notes { get; set; }
|
||||||
|
|
||||||
//public virtual ECustomer? Customers { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,9 +19,5 @@ namespace Domain.Entities
|
|||||||
public DateOnly? IssueDate { get; set; }
|
public DateOnly? IssueDate { get; set; }
|
||||||
|
|
||||||
public DateOnly? ExpiryDate { get; set; }
|
public DateOnly? ExpiryDate { get; set; }
|
||||||
|
|
||||||
//public virtual ECustomer Customers { get; set; } = null!;
|
|
||||||
|
|
||||||
public virtual EDocumentType Documenttypes { get; set; } = null!;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,5 @@
|
|||||||
public string Name { get; set; } = null!;
|
public string Name { get; set; } = null!;
|
||||||
|
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
|
|
||||||
//public virtual ICollection<ECustomerDocument> PhSCustomerDocuments { get; set; } = new List<ECustomerDocument>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
105
phronCare.UIBlazor/Pages/Sales/CustomerForm.razor
Normal file
105
phronCare.UIBlazor/Pages/Sales/CustomerForm.razor
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
@page "/sales/customerform"
|
||||||
|
@page "/sales/customerform/{CustomerId:int}"
|
||||||
|
|
||||||
|
@inject HttpClient _httpClient
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
@inject IToastService toastService
|
||||||
|
@inject AuthenticationStateProvider authenticationStateProvider
|
||||||
|
|
||||||
|
<EditForm Model="@customer" OnValidSubmit="@HandleValidSubmit">
|
||||||
|
<DataAnnotationsValidator />
|
||||||
|
<ValidationSummary />
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="Name">Razón Social:</label>
|
||||||
|
<InputText id="Name" @bind-Value="customer.Name" class="form-control" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="AccountTypeId">Tipo de Cuenta:</label>
|
||||||
|
<InputSelect id="AccountTypeId" @bind-Value="customer.AccounttypesId" class="form-control">
|
||||||
|
@foreach (var type in accountTypes)
|
||||||
|
{
|
||||||
|
<option value="@type.Id">@type.Name</option>
|
||||||
|
}
|
||||||
|
</InputSelect>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Acá van documentos y direcciones (lo agregamos más adelante) -->
|
||||||
|
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col">
|
||||||
|
<button type="submit" class="btn btn-primary">Guardar</button>
|
||||||
|
<button type="button" class="btn btn-secondary" @onclick="Cancel">Volver</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</EditForm>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public int? CustomerId { get; set; }
|
||||||
|
|
||||||
|
private ECustomer customer { get; set; } = new();
|
||||||
|
private List<EAccountType> accountTypes = new();
|
||||||
|
|
||||||
|
private string returnUrl = "/sales/customers";
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
// await LoadAccountTypes();
|
||||||
|
|
||||||
|
// if (CustomerId.HasValue)
|
||||||
|
// {
|
||||||
|
// // Cargar datos del cliente existente desde la API
|
||||||
|
// customer = await _httpClient.GetFromJsonAsync<ECustomer>($"/api/Customer/GetById/{CustomerId.Value}") ?? new();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadAccountTypes()
|
||||||
|
{
|
||||||
|
var result = await _httpClient.GetFromJsonAsync<List<EAccountType>>("/api/AccountType/GetAll");
|
||||||
|
accountTypes = result ?? new();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleValidSubmit()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponseMessage response;
|
||||||
|
|
||||||
|
if (CustomerId.HasValue)
|
||||||
|
{
|
||||||
|
response = await _httpClient.PutAsJsonAsync("/api/Customer/Update", customer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response = await _httpClient.PostAsJsonAsync("/api/Customer/Create", customer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
toastService.ShowSuccess("Cliente guardado exitosamente");
|
||||||
|
Navigation.NavigateTo(returnUrl);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var error = await response.Content.ReadAsStringAsync();
|
||||||
|
toastService.ShowError($"Error: {error}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
toastService.ShowError($"Error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Cancel()
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo(returnUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,8 +13,6 @@
|
|||||||
<h3 class="card-title">Listado de clientes</h3> @* wtf? *@
|
<h3 class="card-title">Listado de clientes</h3> @* wtf? *@
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@* <h3 class="text-xl font-bold mb-4">Buscar Clientes</h3>*@
|
|
||||||
|
|
||||||
<div class="mb-4 space-y-2">
|
<div class="mb-4 space-y-2">
|
||||||
<input @bind="SearchParams.Name" placeholder="Nombre" class="border rounded p-1 w-full" />
|
<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.Email" placeholder="Email" class="border rounded p-1 w-full" />
|
||||||
@ -25,14 +23,14 @@
|
|||||||
@if (TablaClientes != null && TablaClientes.Any())
|
@if (TablaClientes != null && TablaClientes.Any())
|
||||||
{
|
{
|
||||||
<PhTable Columns="TableColumns"
|
<PhTable Columns="TableColumns"
|
||||||
Data="TablaClientes"
|
Data="TablaClientes"
|
||||||
SelectionField="Id"
|
SelectionField="Id"
|
||||||
RowsPerPage=SearchParams.PageSize
|
RowsPerPage=SearchParams.PageSize
|
||||||
RenderButtons="true" Buttons="botones"
|
RenderButtons="true" Buttons="botones"
|
||||||
ShowPageButtons="false"
|
ShowPageButtons="false"
|
||||||
ShowQuickSearch="false"
|
ShowQuickSearch="false"
|
||||||
RenderSelect="false"
|
RenderSelect="false"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="mt-4 flex justify-between items-center">
|
<div class="mt-4 flex justify-between items-center">
|
||||||
<button class="btn btn-secondary" @onclick="AnteriorPagina" disabled="@(!PuedeRetroceder)">Anterior</button>
|
<button class="btn btn-secondary" @onclick="AnteriorPagina" disabled="@(!PuedeRetroceder)">Anterior</button>
|
||||||
@ -76,27 +74,30 @@
|
|||||||
private async Task CargarClientes()
|
private async Task CargarClientes()
|
||||||
{
|
{
|
||||||
PagedResult = await CustomerService.SearchCustomersAsync(SearchParams);
|
PagedResult = await CustomerService.SearchCustomersAsync(SearchParams);
|
||||||
|
if (PagedResult?.Items is not null)
|
||||||
TablaClientes = PagedResult.Items.Select(c =>
|
|
||||||
{
|
{
|
||||||
var addr = c.PhSCustomerAddresses.FirstOrDefault();
|
TablaClientes = PagedResult.Items.Select(c =>
|
||||||
var doc = c.PhSCustomerDocuments.FirstOrDefault();
|
{
|
||||||
|
var addr = c.PhSCustomerAddresses.FirstOrDefault();
|
||||||
|
var doc = c.PhSCustomerDocuments.FirstOrDefault();
|
||||||
|
|
||||||
return new Dictionary<string, object>
|
return new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "Id", c.Id },
|
{ "Id", c.Id },
|
||||||
{ "Nombre", c.Name ?? string.Empty },
|
{ "Nombre", c.Name ?? string.Empty },
|
||||||
{ "Activo", c.Active ? "Sí" : "No" },
|
{ "Activo", c.Active ? "Sí" : "No" },
|
||||||
{ "Crédito", c.HasCreditAccount ? "Sí" : "No" },
|
{ "Crédito", c.HasCreditAccount ? "Sí" : "No" },
|
||||||
{ "Límite", c.CreditLimit },
|
{ "Límite", c.CreditLimit },
|
||||||
{ "Email", addr?.Email ?? "" },
|
{ "Email", addr?.Email ?? string.Empty },
|
||||||
{ "Teléfono", addr?.Phonenumber ?? "" },
|
{ "Teléfono", addr?.Phonenumber ?? string.Empty },
|
||||||
{ "Dirección", $"{addr?.Streetaddress1} {addr?.Streetaddress2}, {addr?.City}, {addr?.Postalcode}, {addr?.Country}" },
|
{ "Dirección", addr is not null
|
||||||
{ "Documento", $"{doc?.Documenttypes} | {doc?.DocumentNumber}" }
|
? $"{addr.Streetaddress1}, {addr.City}, {addr.Postalcode}"
|
||||||
};
|
: string.Empty },
|
||||||
}).ToList();
|
{ "Documento", doc?.DocumentNumber ?? string.Empty }
|
||||||
|
};
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SiguientePagina() => await CambiarPagina(1);
|
private async Task SiguientePagina() => await CambiarPagina(1);
|
||||||
private async Task AnteriorPagina() => await CambiarPagina(-1);
|
private async Task AnteriorPagina() => await CambiarPagina(-1);
|
||||||
private async Task CambiarPagina(int delta)
|
private async Task CambiarPagina(int delta)
|
||||||
@ -121,7 +122,7 @@
|
|||||||
}
|
}
|
||||||
List<PhTable.ButtonOptions> botones = new List<PhTable.ButtonOptions>
|
List<PhTable.ButtonOptions> botones = new List<PhTable.ButtonOptions>
|
||||||
{
|
{
|
||||||
new PhTable.ButtonOptions{ Caption="Editar", ElementClass="btn btn-primary btn-circle btn-sm"}
|
new PhTable.ButtonOptions{ Caption="Editar", ElementClass="btn btn-primary btn-sm"}
|
||||||
};
|
};
|
||||||
private int TotalPaginas => PagedResult is null ? 1 :
|
private int TotalPaginas => PagedResult is null ? 1 :
|
||||||
(int)Math.Ceiling((double)(PagedResult.TotalItems) / SearchParams.PageSize);
|
(int)Math.Ceiling((double)(PagedResult.TotalItems) / SearchParams.PageSize);
|
||||||
|
|||||||
6
phronCare.UIBlazor/Services/Sales/CustomerService.cs
Normal file
6
phronCare.UIBlazor/Services/Sales/CustomerService.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace phronCare.UIBlazor.Services.Sales
|
||||||
|
{
|
||||||
|
public class CustomerService
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -67,7 +67,7 @@
|
|||||||
{
|
{
|
||||||
<ul class="nav-flex-column">
|
<ul class="nav-flex-column">
|
||||||
<div class="nav-item px-1">
|
<div class="nav-item px-1">
|
||||||
<NavLink class="nav-link">
|
<NavLink class="nav-link" href="sales/customerform/">
|
||||||
<li aria-hidden="true"></li> Nuevo
|
<li aria-hidden="true"></li> Nuevo
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user