Files
SomniaGuestLog/src/Somnia.GuestLog/Components/Forms/StayEntryForm.razor
T
Daniel-Garmig 7b86b2224f StayExportTracking - Edit StayEntry UploadStatus
- Page Details - Added UI to edit UploadStatus.
- Page List - Filter by UploadStatus.
2026-10-07 13:33:24 +02:00

282 lines
11 KiB
Plaintext

@using System.Diagnostics
@using FluentValidation;
@using Somnia.GuestLog.Models.DTOs;
@using Somnia.GuestLog.Services;
@using Somnia.GuestLog.Validators;
@inject IDataListService dataListService;
@inject IValidator<StayEntryDTO> stayValidator;
@inject IDialogService dialogService;
@inject IUserMessageService userMessage;
@inject ILocalizerService Localizer;
<MudForm @ref="@_form" Model="@Model" Validation="@((stayValidator as StayEntryDTOValidator)!.ValidateValue)"
ReadOnly="@ReadOnly">
<MudGrid>
<MudItem xs="12" sm="@stayDetailPanelSize">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<SectionTitle Title="@LanguageLocale.control_StayEntryForm_sectionDetails" />
<MudStack Row style="@FieldMarginY">
<MudDatePicker Date="Model.DateIn" For="@(() => Model.DateIn)"
DateChanged="@((newVal) => Model.DateIn = GetDateTimeFromDateAndTime(newVal, Model.DateIn?.TimeOfDay))"
Label="@LanguageLocale.dto_StayEntry_DateIn" Clearable OpenTo="OpenTo.Date" Editable
AutoClose="true" />
<MudTimePicker Time="Model.DateIn?.TimeOfDay" Label=" " Editable
TimeChanged="@((newVal) => Model.DateIn = GetDateTimeFromDateAndTime(Model.DateIn, newVal))" />
<MudDatePicker Date="Model.DateOut" For="@(() => Model.DateOut)"
DateChanged="@((newVal) => Model.DateOut = GetDateTimeFromDateAndTime(newVal, Model.DateOut?.TimeOfDay))"
Label="@LanguageLocale.dto_StayEntry_DateOut" Clearable OpenTo="OpenTo.Date" Editable
AutoClose="true" />
<MudTimePicker Time="Model.DateOut?.TimeOfDay" Label=" " Editable
TimeChanged="@((newVal) => Model.DateOut = GetDateTimeFromDateAndTime(Model.DateOut, newVal))" />
</MudStack>
<MudStack Row style="@FieldMarginY">
<MudTextField @bind-Value="Model.RoomCount" For="@(() => Model.RoomCount)"
Label="@LanguageLocale.dto_StayEntry_RoomCount" InputType="InputType.Number" FullWidth />
<MudTextField @bind-Value="Model.RoomNumber" For="@(() => Model.RoomNumber)"
Label="@LanguageLocale.dto_StayEntry_RoomNumber" FullWidth />
<MudSelect @bind-Value="Model.PaymentMethod" For="@(() => Model.PaymentMethod)"
Label="@LanguageLocale.dto_StayEntry_PaymentMethod" FullWidth>
@foreach (string payment in PaymentMethodSet)
{
<MudSelectItem Value="payment">
@dataListService.GetLocalizedValue(GuestConsts.DataList_PaymentMethods, payment)
</MudSelectItem>
}
</MudSelect>
</MudStack>
</MudPaper>
</MudItem>
@if (FormMode == FormMode.ReadOnly)
{
<MudItem xs="12" sm="3">
<MudPaper Class="pa-4" Elevation="3" Height="100%">
<SectionTitle Title="@LanguageLocale.control_StayEntryForm_sectionUploadStatus" />
<MudTextField Value="@Localizer.GetEnumValue(Model.StayUploadStatus)"
Label="@LanguageLocale.dto_StayEntry_StayUploadStatus" FullWidth ReadOnly />
@if (Model.StayUploadStatusTime != null)
{
<MudTextField @bind-Value="Model.StayUploadStatusTime" For="@(() => Model.StayUploadStatusTime)"
Label="@LanguageLocale.dto_StayEntry_StayUploadStatusTime" FullWidth ReadOnly />
}
</MudPaper>
</MudItem>
}
<MudItem xs="12" xl="12">
<MudPaper Class="pa-4" Elevation="3" Height="100%" Width="100%">
<SectionTitle Title="@LanguageLocale.control_StayEntryForm_sectionGuests" />
@if (!ReadOnly)
{
<MudStack Row style="@FieldMarginY">
<MudButton OnClick="BtnAddGuest" StartIcon="@Icons.Material.Filled.Add">
@LanguageLocale.control_StayEntryForm_btnAddGuest
</MudButton>
</MudStack>
}
<MudTable Items="@Model.GuestDocuments" Hover="true">
<HeaderContent>
<MudTh>@LanguageLocale.dto_GuestDocument_DocumentType</MudTh>
<MudTh>@LanguageLocale.dto_GuestDocument_DocumentNum</MudTh>
<MudTh>@LanguageLocale.dto_GuestDocument_Name</MudTh>
<MudTh>@LanguageLocale.dto_GuestDocument_Surname</MudTh>
<MudTh>@LanguageLocale.dto_GuestDocument_Surname2</MudTh>
<MudTh>@LanguageLocale.general_actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_DocumentType">
@context.DocumentType
</MudTd>
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_DocumentNum">
@context.DocumentNum
</MudTd>
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_Name">
@context.Name
</MudTd>
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_Surname" HideSmall="true">
@context.Surname
</MudTd>
<MudTd DataLabel="@LanguageLocale.dto_GuestDocument_Surname2" HideSmall="true">
@context.Surname2
</MudTd>
@if (!ReadOnly)
{
<MudTd DataLabel="@LanguageLocale.general_actions">
<MudIconButton Icon="@Icons.Material.Filled.Delete"
OnClick="@(() => BtnDeleteGuest(context.Id!.Value, context.Version!.Value))" />
</MudTd>
}
@if (ReadOnly)
{
<MudTd DataLabel="@LanguageLocale.general_actions">
<MudIconButton Icon="@Icons.Material.Filled.Info"
OnClick="@(() => BtnViewGuestDetails(context))" />
</MudTd>
}
</RowTemplate>
</MudTable>
</MudPaper>
</MudItem>
</MudGrid>
</MudForm>
@code {
[Parameter]
public StayEntryDTO Model { private get; set; } = new();
[Parameter, EditorRequired]
public FormMode FormMode { get; set; }
private bool ReadOnly => FormMode == FormMode.ReadOnly;
private int stayDetailPanelSize => FormMode == FormMode.ReadOnly ? 9 : 12;
private MudForm _form = null!;
private const string FieldMarginY = "margin-block: 0.5em";
private IEnumerable<string> PaymentMethodSet
{
get
{
if (field is null)
{
field = dataListService.GetDataListByName(GuestConsts.DataList_PaymentMethods);
}
return field;
}
}
protected override void OnInitialized()
{
//Initialize values when not ReadOnly.
if (FormMode == FormMode.Create)
{
Model.DateIn = DateTime.Now;
DateTime dateOut = DateTime.Today.AddDays(1);
Model.DateOut = new(
year: dateOut.Year, month: dateOut.Month, day: dateOut.Day,
hour: 12, minute: 0, second: 0
);
//Init Guest List
Model.GuestDocuments = [];
}
}
#region Public Methods
public async Task<bool> ValidateForm()
{
await _form.ValidateAsync();
if (Model.GuestDocuments is null || Model.GuestDocuments.Count == 0)
{
userMessage.ShowMessage("At least 1 guest is required!", MessageKind.Warning);
return false;
}
return _form.IsValid;
}
public StayEntryDTO GetModel()
{
return Model;
}
#endregion
private static DateTime? GetDateTimeFromDateAndTime(DateTime? date, TimeSpan? time)
{
DateOnly? dateOnly = date is not null ? DateOnly.FromDateTime(date.Value) : null;
TimeOnly? timeOnly = time is not null ? TimeOnly.FromTimeSpan(time.Value) : null;
if (dateOnly is not null && timeOnly is not null)
{
return new DateTime(dateOnly.Value, timeOnly.Value);
}
return null;
}
#region Event Handlers
private async Task BtnAddGuest()
{
Debug.Assert(Model.GuestDocuments != null);
DialogOptions dialogOptions = new()
{
MaxWidth = MaxWidth.Medium,
FullWidth = true,
BackdropClick = false,
CloseOnEscapeKey = true,
};
var dialog = await dialogService.ShowAsync<GuestDocumentSearchDialog>(title: "", options: dialogOptions);
DialogResult? result = await dialog.Result;
if (result is null || result.Canceled)
{
return;
}
GuestDocumentDTO? resultData = await dialog.GetReturnValueAsync<GuestDocumentDTO>();
if (resultData is null)
{
userMessage.ShowMessage("Error! No Guest Document selected!", MessageKind.Error);
return;
}
//Check if this guest is already added.
if (Model.GuestDocuments.Count > 0)
{
bool alreadyAdded = Model.GuestDocuments.Any(e => e.Id == resultData.Id);
if (alreadyAdded)
{
userMessage.ShowMessage("GuestDocument already added!", MessageKind.Warning);
return;
}
}
Model.GuestDocuments.Add(resultData);
}
private void BtnDeleteGuest(long guestDocId, int version)
{
Debug.Assert(Model.GuestDocuments is not null);
//Filter out given GuestDocument from model.
Model.GuestDocuments = Model.GuestDocuments
.Where(e => !(e.Id == guestDocId && e.Version == version))
.ToList();
}
private async Task BtnViewGuestDetails(GuestDocumentDTO item)
{
var parameters =
new DialogParameters<GuestDocDetailsDialog> { { x => x.DocumentDTO, item } };
var options = new DialogOptions()
{
FullScreen = true,
CloseButton = true,
CloseOnEscapeKey = true,
};
await dialogService.ShowAsync<GuestDocDetailsDialog>("GuestDoc Details", parameters, options);
}
#endregion
}