Update CustomerForm Address List
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m0s
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m0s
This commit is contained in:
parent
c1bb17cb65
commit
ab622e72ff
@ -111,75 +111,113 @@
|
|||||||
</table>
|
</table>
|
||||||
}
|
}
|
||||||
|
|
||||||
<h5 class="mt-4 mb-2">Direcciones</h5>
|
<h4 class="mt-4">Direcciones</h4>
|
||||||
|
|
||||||
@foreach (var address in customer.PhSCustomerAddresses)
|
<div class="row mb-3">
|
||||||
{
|
<div class="col-md-6">
|
||||||
<div class="mb-4 border rounded-lg p-4 space-y-3 shadow-sm bg-light">
|
<input class="form-control" placeholder="Nombre de sucursal" @bind="editingAddress.BusinessName" />
|
||||||
<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>
|
||||||
|
<div class="col-md-6">
|
||||||
<div class="mt-3 text-end">
|
<input class="form-control" placeholder="Dirección línea 1" @bind="editingAddress.Streetaddress1" />
|
||||||
<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>
|
||||||
</div>
|
</div>
|
||||||
}
|
|
||||||
|
|
||||||
<button type="button" class="btn btn-outline-primary mt-2" @onclick="AddAddress">
|
<div class="row mb-3">
|
||||||
<i class="bi bi-plus-circle"></i> Agregar dirección
|
<div class="col-md-6">
|
||||||
</button>
|
<input class="form-control" placeholder="Dirección línea 2" @bind="editingAddress.Streetaddress2" />
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<input class="form-control" placeholder="Ciudad" @bind="editingAddress.City" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<select class="form-control" value="@editingAddress.Country" @onchange="OnCountryChanged">
|
||||||
|
<option value="">Seleccionar país</option>
|
||||||
|
@foreach (var country in countries)
|
||||||
|
{
|
||||||
|
<option value="@country">@country</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
@if (editingAddress.Country == "Argentina" && provincesByCountry.TryGetValue("Argentina", out var provincias))
|
||||||
|
{
|
||||||
|
<select class="form-control" @bind="editingAddress.Stateprovince">
|
||||||
|
<option value="">Seleccionar provincia</option>
|
||||||
|
@foreach (var provincia in provincias)
|
||||||
|
{
|
||||||
|
<option value="@provincia">@provincia</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<input class="form-control" placeholder="Estado/Provincia" @bind="editingAddress.Stateprovince" />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<input class="form-control" placeholder="Código Postal" @bind="editingAddress.Postalcode" />
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<input class="form-control" placeholder="Teléfono" @bind="editingAddress.Phonenumber" />
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<input class="form-control" placeholder="Email" @bind="editingAddress.Email" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<textarea class="form-control" placeholder="Notas" @bind="editingAddress.Notes"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<button class="btn btn-sm btn-success" @onclick="AddOrUpdateAddress">
|
||||||
|
@((editingIndex == -1) ? "Agregar dirección" : "Actualizar dirección")
|
||||||
|
</button>
|
||||||
|
@if (editingIndex != -1)
|
||||||
|
{
|
||||||
|
<button class="btn btn-sm btn-secondary ms-2" @onclick="CancelAddressEdit">Cancelar</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (customer.PhSCustomerAddresses.Any())
|
||||||
|
{
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Sucursal</th>
|
||||||
|
<th>Dirección</th>
|
||||||
|
<th>Ciudad</th>
|
||||||
|
<th>Provincia</th>
|
||||||
|
<th>País</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var address in customer.PhSCustomerAddresses.Select((value, index) => new { value, index }))
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>@address.value.BusinessName</td>
|
||||||
|
<td>@address.value.Streetaddress1</td>
|
||||||
|
<td>@address.value.City</td>
|
||||||
|
<td>@address.value.Stateprovince</td>
|
||||||
|
<td>@address.value.Country</td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-sm btn-primary me-1" @onclick="() => EditAddress(address.index)">Editar</button>
|
||||||
|
<button class="btn btn-sm btn-danger" @onclick="() => RemoveAddress(address.index)">Eliminar</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
</EditForm>
|
</EditForm>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@ -191,11 +229,110 @@
|
|||||||
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";
|
||||||
|
|
||||||
|
private List<string> countries = new() {
|
||||||
|
"Argentina", "Brasil", "Chile", "Uruguay", "Paraguay", "Estados Unidos", "Canadá",
|
||||||
|
"México", "Alemania", "Reino Unido", "Francia", "Italia", "España"
|
||||||
|
};
|
||||||
|
|
||||||
|
private Dictionary<string, List<string>> provincesByCountry = new()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
"Argentina", new List<string>
|
||||||
|
{
|
||||||
|
"Buenos Aires", "CABA", "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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private ECustomerAddress editingAddress = new();
|
||||||
|
private int editingIndex = -1;
|
||||||
|
|
||||||
|
private void OnCountryChanged(ChangeEventArgs e)
|
||||||
|
{
|
||||||
|
var selectedCountry = e.Value?.ToString();
|
||||||
|
editingAddress.Country = selectedCountry;
|
||||||
|
editingAddress.Stateprovince = string.Empty; // Resetear la provincia si cambia el país
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddOrUpdateAddress()
|
||||||
|
{
|
||||||
|
if (editingIndex == -1)
|
||||||
|
{
|
||||||
|
// Agregar nueva dirección
|
||||||
|
customer.PhSCustomerAddresses.Add(editingAddress);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Actualizar dirección existente
|
||||||
|
var existing = customer.PhSCustomerAddresses.ElementAt(editingIndex);
|
||||||
|
|
||||||
|
existing.BusinessName = editingAddress.BusinessName;
|
||||||
|
existing.Streetaddress1 = editingAddress.Streetaddress1;
|
||||||
|
existing.Streetaddress2 = editingAddress.Streetaddress2;
|
||||||
|
existing.City = editingAddress.City;
|
||||||
|
existing.Stateprovince = editingAddress.Stateprovince;
|
||||||
|
existing.Postalcode = editingAddress.Postalcode;
|
||||||
|
existing.Country = editingAddress.Country;
|
||||||
|
existing.Latitude = editingAddress.Latitude;
|
||||||
|
existing.Longitude = editingAddress.Longitude;
|
||||||
|
existing.Phonenumber = editingAddress.Phonenumber;
|
||||||
|
existing.Email = editingAddress.Email;
|
||||||
|
existing.Notes = editingAddress.Notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResetAddressForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EditAddress(int index)
|
||||||
|
{
|
||||||
|
var addr = customer.PhSCustomerAddresses.ElementAt(index);
|
||||||
|
|
||||||
|
editingAddress = new ECustomerAddress
|
||||||
|
{
|
||||||
|
Id = addr.Id, // Incluí el Id como mencionamos antes, para no perder referencia
|
||||||
|
BusinessName = addr.BusinessName,
|
||||||
|
Streetaddress1 = addr.Streetaddress1,
|
||||||
|
Streetaddress2 = addr.Streetaddress2,
|
||||||
|
City = addr.City,
|
||||||
|
Stateprovince = addr.Stateprovince,
|
||||||
|
Postalcode = addr.Postalcode,
|
||||||
|
Country = addr.Country,
|
||||||
|
Latitude = addr.Latitude,
|
||||||
|
Longitude = addr.Longitude,
|
||||||
|
Phonenumber = addr.Phonenumber,
|
||||||
|
Email = addr.Email,
|
||||||
|
Notes = addr.Notes
|
||||||
|
};
|
||||||
|
|
||||||
|
editingIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveAddress(int index)
|
||||||
|
{
|
||||||
|
var itemToRemove = customer.PhSCustomerAddresses.ElementAt(index);
|
||||||
|
customer.PhSCustomerAddresses.Remove(itemToRemove);
|
||||||
|
ResetAddressForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void CancelAddressEdit()
|
||||||
|
{
|
||||||
|
ResetAddressForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetAddressForm()
|
||||||
|
{
|
||||||
|
editingAddress = new();
|
||||||
|
editingIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
await LoadAccountTypes();
|
await LoadAccountTypes();
|
||||||
@ -236,56 +373,11 @@
|
|||||||
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)
|
private void RemoveCustomerAddress(ECustomerAddress address)
|
||||||
{
|
{
|
||||||
customer.PhSCustomerAddresses.Remove(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
|
||||||
|
|||||||
0
phronCare.UIBlazor/Pages/_Imports.razor
Normal file
0
phronCare.UIBlazor/Pages/_Imports.razor
Normal file
Loading…
x
Reference in New Issue
Block a user