All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m41s
142 lines
4.6 KiB
Plaintext
142 lines
4.6 KiB
Plaintext
@page "/sales/customerform"
|
|
@page "/sales/customerform/{CustomerId:int}"
|
|
@using phronCare.UIBlazor.Services.Sales
|
|
|
|
@inject HttpClient _httpClient
|
|
@inject NavigationManager Navigation
|
|
@inject IToastService toastService
|
|
@inject AuthenticationStateProvider authenticationStateProvider
|
|
@inject AccountTypeService accountTypeService
|
|
@inject TaxConditionService taxConditionService
|
|
|
|
|
|
<EditForm Model="@customer" OnValidSubmit="@HandleValidSubmit">
|
|
<DataAnnotationsValidator />
|
|
<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="col-md-6">
|
|
<label for="AccounttypesId">Tipo de Cuenta:</label>
|
|
<InputSelect id="AccounttypesId" @bind-Value="customer.AccounttypesId" class="form-control">
|
|
<option value="">-- Seleccionar --</option>
|
|
@foreach (var type in accountTypes)
|
|
{
|
|
<option value="@type.Id">@type.Name</option>
|
|
}
|
|
</InputSelect>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label for="TaxConditionId">Condición Fiscal:</label>
|
|
<InputSelect id="TaxConditionId" @bind-Value="customer.TaxConditionId" class="form-control">
|
|
<option value="">-- Seleccionar --</option>
|
|
@foreach (var tax in taxConditions)
|
|
{
|
|
<option value="@tax.Id">@tax.Description</option>
|
|
}
|
|
</InputSelect>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<label for="HasCreditAccount">¿Cuenta Corriente?</label><br />
|
|
<InputCheckbox id="HasCreditAccount" @bind-Value="customer.HasCreditAccount" />
|
|
</div>
|
|
<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 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>
|
|
|
|
@code {
|
|
[Parameter]
|
|
public int? CustomerId { get; set; }
|
|
|
|
private ECustomer customer { get; set; } = new();
|
|
private List<EAccountType> accountTypes = new();
|
|
private List<ETaxCondition> taxConditions = new();
|
|
|
|
private string returnUrl = "/sales/customers";
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadAccountTypes();
|
|
await LoadTaxConditions();
|
|
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()
|
|
{
|
|
accountTypes = await accountTypeService.GetAllAsync();
|
|
}
|
|
|
|
private async Task LoadTaxConditions()
|
|
{
|
|
taxConditions = await taxConditionService.GetAllAsync();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|