Update CustomerForm Address
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 4m49s

This commit is contained in:
Leandro Hernan Rojas 2025-04-11 09:17:32 -03:00
parent 39ae7f0412
commit c1bb17cb65

View File

@ -110,6 +110,76 @@
</tbody> </tbody>
</table> </table>
} }
<h5 class="mt-4 mb-2">Direcciones</h5>
@foreach (var address in customer.PhSCustomerAddresses)
{
<div class="mb-4 border rounded-lg p-4 space-y-3 shadow-sm bg-light">
<div class="row g-2">
<div class="col-md-6">
<InputText class="form-control" @bind-Value="address.BusinessName" placeholder="Nombre de la sucursal" />
</div>
<div class="col-md-6">
<InputText class="form-control" @bind-Value="address.Streetaddress1" placeholder="Calle y número" />
</div>
<div class="col-md-6">
<InputText class="form-control" @bind-Value="address.Streetaddress2" placeholder="Piso, departamento, etc." />
</div>
<div class="col-md-6">
<InputText class="form-control" @bind-Value="address.City" placeholder="Ciudad" />
</div>
<div class="col-md-6">
<select class="form-control" value="@address.Country" @onchange="e => OnCountryChanged(e, address)">
<option value="">Seleccionar país</option>
@foreach (var country in countries)
{
<option value="@country">@country</option>
}
</select>
</div>
<div class="col-md-6">
@if (address.Country == "Argentina")
{
<select class="form-control" @bind="address.Stateprovince">
<option value="">Seleccionar provincia</option>
@foreach (var province in argentinaProvinces)
{
<option value="@province">@province</option>
}
</select>
}
else
{
<InputText class="form-control" @bind-Value="address.Stateprovince" placeholder="Provincia / Estado" />
}
</div>
<div class="col-md-4">
<InputText class="form-control" @bind-Value="address.Postalcode" placeholder="Código Postal" />
</div>
<div class="col-md-4">
<InputText class="form-control" @bind-Value="address.Phonenumber" placeholder="Teléfono" />
</div>
<div class="col-md-4">
<InputText class="form-control" @bind-Value="address.Email" placeholder="Email" />
</div>
<div class="col-12">
<InputTextArea class="form-control" @bind-Value="address.Notes" placeholder="Notas" />
</div>
</div>
<div class="mt-3 text-end">
<button type="button" class="btn btn-sm btn-outline-danger" @onclick="() => RemoveAddress(address)">
<i class="bi bi-trash"></i> Eliminar dirección
</button>
</div>
</div>
}
<button type="button" class="btn btn-outline-primary mt-2" @onclick="AddAddress">
<i class="bi bi-plus-circle"></i> Agregar dirección
</button>
</EditForm> </EditForm>
@code { @code {
@ -121,6 +191,8 @@
private List<ETaxCondition> taxConditions = new(); private List<ETaxCondition> taxConditions = new();
private List<EDocumentType> documentTypes = new(); private List<EDocumentType> documentTypes = new();
private ECustomerDocument documentFormModel = new(); private ECustomerDocument documentFormModel = new();
private ECustomerAddress AddressForModel = new();
private List<ECustomerAddress> addresses => customer.PhSCustomerAddresses.ToList();
private string returnUrl = "/sales/customers"; private string returnUrl = "/sales/customers";
@ -164,6 +236,56 @@
customer.PhSCustomerDocuments.Remove(document); customer.PhSCustomerDocuments.Remove(document);
} }
private void AddCustomerAddress()
{
if (!string.IsNullOrWhiteSpace(AddressForModel.Streetaddress1))
{
customer.PhSCustomerAddresses.Add(AddressForModel);
AddressForModel = new(); // limpiar el formulario
}
}
private void RemoveCustomerAddress(ECustomerAddress address)
{
customer.PhSCustomerAddresses.Remove(address);
}
private List<string> countries = new()
{
"Argentina", "Brasil", "Chile", "Uruguay", "Paraguay", "Bolivia", "Perú", "Colombia", "Venezuela", "México",
"Estados Unidos", "Canadá", "España", "Reino Unido", "Alemania", "Francia", "Italia", "China", "India", "Japón"
};
private List<string> argentinaProvinces = new()
{
"Buenos Aires", "Catamarca", "Chaco", "Chubut", "Córdoba", "Corrientes", "Entre Ríos", "Formosa", "Jujuy",
"La Pampa", "La Rioja", "Mendoza", "Misiones", "Neuquén", "Río Negro", "Salta", "San Juan", "San Luis",
"Santa Cruz", "Santa Fe", "Santiago del Estero", "Tierra del Fuego", "Tucumán", "Ciudad Autónoma de Buenos Aires"
};
private void OnCountryChanged(ChangeEventArgs e, ECustomerAddress address)
{
address.Country = e.Value?.ToString();
if (address.Country != "Argentina")
{
address.Stateprovince = string.Empty;
}
}
private void AddAddress()
{
customer.PhSCustomerAddresses.Add(new());
}
private void RemoveAddress(ECustomerAddress address)
{
customer.PhSCustomerAddresses.Remove(address);
}
private void OnCountryChanged(ECustomerAddress address)
{
if (address.Country != "Argentina")
{
address.Stateprovince = string.Empty;
}
}
private async Task HandleValidSubmit() private async Task HandleValidSubmit()
{ {
try try
@ -178,7 +300,6 @@
{ {
response = await _httpClient.PostAsJsonAsync("/api/Customer/Create", customer); response = await _httpClient.PostAsJsonAsync("/api/Customer/Create", customer);
} }
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {
toastService.ShowSuccess("Cliente guardado exitosamente"); toastService.ShowSuccess("Cliente guardado exitosamente");