Add Fields in CustomerForm and new Services
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m41s

This commit is contained in:
Leandro Hernan Rojas 2025-04-11 00:25:27 -03:00
parent ee126d074c
commit 8271d399f4
8 changed files with 134 additions and 66 deletions

View File

@ -1,43 +1,74 @@
@page "/sales/customerform" @page "/sales/customerform"
@page "/sales/customerform/{CustomerId:int}" @page "/sales/customerform/{CustomerId:int}"
@using phronCare.UIBlazor.Services.Sales
@inject HttpClient _httpClient @inject HttpClient _httpClient
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject IToastService toastService @inject IToastService toastService
@inject AuthenticationStateProvider authenticationStateProvider @inject AuthenticationStateProvider authenticationStateProvider
@inject AccountTypeService accountTypeService
@inject TaxConditionService taxConditionService
<EditForm Model="@customer" OnValidSubmit="@HandleValidSubmit"> <EditForm Model="@customer" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator /> <DataAnnotationsValidator />
<ValidationSummary /> <ValidationSummary />
<div class="row">
<div class="col-md-6">
<label for="Name">Nombre / Razón Social:</label>
<InputText id="Name" @bind-Value="customer.Name" class="form-control" />
</div>
<div class="col-md-6">
<label for="BusinessName">Sucursal / Nombre Comercial:</label>
<InputText id="BusinessName" @bind-Value="customer.BusinessName" class="form-control" />
</div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-md-6">
<div class="form-group"> <label for="AccounttypesId">Tipo de Cuenta:</label>
<label for="Name">Razón Social:</label> <InputSelect id="AccounttypesId" @bind-Value="customer.AccounttypesId" class="form-control">
<InputText id="Name" @bind-Value="customer.Name" class="form-control" /> <option value="">-- Seleccionar --</option>
</div> @foreach (var type in accountTypes)
{
<option value="@type.Id">@type.Name</option>
}
</InputSelect>
</div> </div>
<div class="col-sm-6"> <div class="col-md-6">
<div class="form-group"> <label for="TaxConditionId">Condición Fiscal:</label>
<label for="AccountTypeId">Tipo de Cuenta:</label> <InputSelect id="TaxConditionId" @bind-Value="customer.TaxConditionId" class="form-control">
<InputSelect id="AccountTypeId" @bind-Value="customer.AccounttypesId" class="form-control"> <option value="">-- Seleccionar --</option>
@foreach (var type in accountTypes) @foreach (var tax in taxConditions)
{ {
<option value="@type.Id">@type.Name</option> <option value="@tax.Id">@tax.Description</option>
} }
</InputSelect> </InputSelect>
</div>
</div> </div>
</div> </div>
<!-- Acá van documentos y direcciones (lo agregamos más adelante) --> <div class="row">
<div class="col-md-4">
<div class="row mt-3"> <label for="HasCreditAccount">¿Cuenta Corriente?</label><br />
<div class="col"> <InputCheckbox id="HasCreditAccount" @bind-Value="customer.HasCreditAccount" />
<button type="submit" class="btn btn-primary">Guardar</button> </div>
<button type="button" class="btn btn-secondary" @onclick="Cancel">Volver</button> <div class="col-md-4">
<label for="CreditLimit">Límite de Crédito:</label>
<InputNumber id="CreditLimit" @bind-Value="customer.CreditLimit" class="form-control" />
</div>
<div class="col-md-4">
<label for="Active">Activo:</label><br />
<InputCheckbox id="Active" @bind-Value="customer.Active" />
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-6">
<label for="ExternalCode">Código Externo (opcional):</label>
<InputText id="ExternalCode" @bind-Value="customer.ExternalCode" class="form-control" />
</div>
</div>
</EditForm> </EditForm>
@code { @code {
@ -46,13 +77,14 @@
private ECustomer customer { get; set; } = new(); private ECustomer customer { get; set; } = new();
private List<EAccountType> accountTypes = new(); private List<EAccountType> accountTypes = new();
private List<ETaxCondition> taxConditions = new();
private string returnUrl = "/sales/customers"; private string returnUrl = "/sales/customers";
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await LoadAccountTypes(); await LoadAccountTypes();
await LoadTaxConditions();
if (CustomerId.HasValue) if (CustomerId.HasValue)
{ {
// Cargar datos del cliente existente desde la API // Cargar datos del cliente existente desde la API
@ -62,8 +94,12 @@
private async Task LoadAccountTypes() private async Task LoadAccountTypes()
{ {
var result = await _httpClient.GetFromJsonAsync<List<EAccountType>>("/api/AccountType/GetAll"); accountTypes = await accountTypeService.GetAllAsync();
accountTypes = result ?? new(); }
private async Task LoadTaxConditions()
{
taxConditions = await taxConditionService.GetAllAsync();
} }
private async Task HandleValidSubmit() private async Task HandleValidSubmit()

View File

@ -4,9 +4,7 @@
@using Domain.Entities @using Domain.Entities
@using Domain.Generics @using Domain.Generics
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject CustomerService customerService
@inject CustomerHttpService CustomerService
<div class="card " style="zoom:90%"> <div class="card " style="zoom:90%">
<div class="card-header"> <div class="card-header">
@ -73,7 +71,7 @@
private async Task CargarClientes() private async Task CargarClientes()
{ {
PagedResult = await CustomerService.SearchCustomersAsync(SearchParams); PagedResult = await customerService.SearchCustomersAsync(SearchParams);
if (PagedResult?.Items is not null) if (PagedResult?.Items is not null)
{ {
TablaClientes = PagedResult.Items.Select(c => TablaClientes = PagedResult.Items.Select(c =>

View File

@ -39,7 +39,9 @@ if (config != null)
#endregion #endregion
#region Injection Dependencis #region Injection Dependencis
builder.Services.AddScoped<TicketsService>(); builder.Services.AddScoped<TicketsService>();
builder.Services.AddScoped<CustomerHttpService>(); builder.Services.AddScoped<CustomerService>();
builder.Services.AddScoped<TaxConditionService>();
builder.Services.AddScoped<AccountTypeService>();
#endregion #endregion
#region UI #region UI
builder.Services.AddBlazoredModal(); builder.Services.AddBlazoredModal();

View File

@ -0,0 +1,21 @@
using Domain.Entities;
using System.Net.Http.Json;
namespace phronCare.UIBlazor.Services.Sales
{
public class AccountTypeService
{
private readonly HttpClient _httpClient;
public AccountTypeService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<List<EAccountType>> GetAllAsync()
{
var result = await _httpClient.GetFromJsonAsync<List<EAccountType>>("/api/AccountType/GetAll");
return result ?? new List<EAccountType>();
}
}
}

View File

@ -1,25 +0,0 @@
using Domain.Entities;
using Domain.Generics;
using System.Net.Http.Json;
namespace phronCare.UIBlazor.Services.Sales
{
public class CustomerHttpService
{
private readonly HttpClient _http;
public CustomerHttpService(HttpClient http)
{
_http = http;
}
public async Task<PagedResult<ECustomer>?> SearchCustomersAsync(CustomerSearchParams searchParams)
{
var url = $"api/Customer/search?" +
$"name={searchParams.Name}&" +
$"email={searchParams.Email}&" +
$"document={searchParams.Document}&" +
$"page={searchParams.Page}&" +
$"pageSize={searchParams.PageSize}";
return await _http.GetFromJsonAsync<PagedResult<ECustomer>>(url);
}
}
}

View File

@ -1,11 +0,0 @@
namespace phronCare.UIBlazor.Services.Sales
{
public class CustomerSearchParams
{
public string? Name { get; set; }
public string? Email { get; set; }
public string? Document { get; set; }
public int Page { get; set; } = 1;
public int PageSize { get; set; } = 10;
}
}

View File

@ -1,6 +1,32 @@
namespace phronCare.UIBlazor.Services.Sales using Domain.Entities;
using Domain.Generics;
using System.Net.Http.Json;
namespace phronCare.UIBlazor.Services.Sales
{ {
public class CustomerService public class CustomerService
{ {
private readonly HttpClient _http;
public CustomerService(HttpClient http)
{
_http = http;
}
public async Task<PagedResult<ECustomer>?> SearchCustomersAsync(CustomerSearchParams searchParams)
{
var url = $"api/Customer/search?" +
$"name={searchParams.Name}&" +
$"email={searchParams.Email}&" +
$"document={searchParams.Document}&" +
$"page={searchParams.Page}&" +
$"pageSize={searchParams.PageSize}";
return await _http.GetFromJsonAsync<PagedResult<ECustomer>>(url);
}
}
public class CustomerSearchParams
{
public string? Name { get; set; }
public string? Email { get; set; }
public string? Document { get; set; }
public int Page { get; set; } = 1;
public int PageSize { get; set; } = 10;
} }
} }

View File

@ -0,0 +1,21 @@
using Domain.Entities;
using System.Net.Http.Json;
namespace phronCare.UIBlazor.Services.Sales
{
public class TaxConditionService
{
private readonly HttpClient _httpClient;
public TaxConditionService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<List<ETaxCondition>> GetAllAsync()
{
var result = await _httpClient.GetFromJsonAsync<List<ETaxCondition>>("/api/TaxCondition/GetAll");
return result ?? new List<ETaxCondition>();
}
}
}