productid added to transferdestination

This commit is contained in:
Adam 2024-09-01 09:24:54 +02:00
parent 7a88cdd21f
commit f28cd5aaba
7 changed files with 407 additions and 12 deletions

View File

@ -71,7 +71,7 @@
</div>
<div>
<h6 class="mb-0"> <a href="/user/transfers/@ProductId">All transfers</a> </h6>
<h6 class="mb-0"> <a href="/hotel/transfers/@ProductId">All transfers</a> </h6>
</div>
</div>
</div>

View File

@ -8,6 +8,7 @@
@using TIAM.Resources
@using TIAM.Services
@using TIAMSharedUI.Pages.Components.EditComponents
@using TIAMSharedUI.Shared
@using TIAMSharedUI.Shared.Components.BaseComponents
@using TIAMWebApp.Shared.Application.Interfaces
@using AyCode.Services.Loggers
@ -17,6 +18,7 @@
@using TIAMWebApp.Shared.Application.Utility
@using TIAMSharedUI.Pages.User.SysAdmins
@using TIAMSharedUI.Pages.Components
@layout AdminLayout
@inherits BasePageComponent
@inject HttpClient Http
@inject NavigationManager navManager

View File

@ -0,0 +1,393 @@
@page "/hotel/transfers/{HotelId:guid}"
@using BlazorAnimation
@using TIAM.Core.Consts
@using TIAM.Core.Enums
@using TIAM.Entities.Emails
@using TIAM.Entities.Transfers
@using TIAM.Resources
@using TIAM.Services
@using TIAMSharedUI.Pages.Components
@using TIAMSharedUI.Pages.User.SysAdmins
@using TIAMSharedUI.Shared
@using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
@using TIAMWebApp.Shared.Application.Models.PageModels
@using TIAMWebApp.Shared.Application.Utility
@using TIAMWebApp.Shared.Application.Services
@using TIAMSharedUI.Shared.Components.Grids
@using AyCode.Core.Enums
@using AyCode.Core.Extensions
@using AyCode.Core.Consts
@using AyCode.Core
@using AyCode.Core.Helpers
@using DevExpress.Data.Filtering
@using TIAM.Entities.Emails
@using TIAMSharedUI.Shared.Components.BaseComponents
@inherits UserBasePageComponent
@layout AdminLayout
@inject IWizardProcessor wizardProcessor
@inject ITransferDataService transferDataService
@inject AdminSignalRClient AdminSignalRClient;
<PageTitle>Transfers</PageTitle>
<div class="text-center m-5">
<h1>Transfer management</h1>
<h2 style="font-size:small">Manage transfers here!</h2>
</div>
<DxPopup CssClass="popup-demo-events"
@bind-Visible="@_popupVisible"
ShowFooter="true"
CloseOnEscape="true"
CloseOnOutsideClick="false"
ShowCloseButton="false"
HeaderText="MessageBox"
Closing="EulaPopupClosing"
Closed="EulaPopupClosed">
<BodyContentTemplate>
<InputWizard Data=@_messageWizardModel
OnSubmit="SubmitForm"
IgnoreReflection=@IgnoreList
TitleResourceString="NewMessage"
SubtitleResourceString="NewMessageSubtitle"
SubmitButtonText="@_localizer.GetString("ButtonSend")"></InputWizard>
</BodyContentTemplate>
<FooterContentTemplate Context="Context">
<div class="popup-demo-events-footer">
<!--DxCheckBox CssClass="popup-demo-events-checkbox" @bind-Checked="@EulaAccepted">I accept the terms of the EULA</!--DxCheckBox-->
<!--DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Primary" Text="OK" Click="Context.CloseCallback" /-->
<DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Secondary" Text="Cancel" Click="CancelCreateClick" />
</div>
</FooterContentTemplate>
</DxPopup>
<div class="container-fluid">
<div class="row">
<div class=" col-12">
<div class="card">
<DxTabs>
<DxTabPage Text="DataGrid">
<div class="d-flex flex-column mb-4 pb-2">
<div class="align-self-end pl-2 pb-2">
<DxButton Text="Column Chooser"
RenderStyle="ButtonRenderStyle.Secondary"
IconCssClass="btn-column-chooser"
Click="ColumnChooserButton_Click" />
</div>
<TransferGrid @ref="_gridTransfer"
Logger="_logger"
SignalRClient="AdminSignalRClient"
ContextIds="@(HotelId.IsNullOrEmpty() ? null : [HotelId])"
GetAllMessageTag="@SignalRTags.GetTransfersByOrderingProductId"
CustomizeElement="Grid_CustomizeElement"
CustomizeEditModel="Grid_CustomizeEditModel"
EditMode="GridEditMode.EditRow"
ColumnResizeMode="GridColumnResizeMode.NextColumn"
PageSize="13"
ShowFilterRow="true">
<Columns>
<DxGridCommandColumn NewButtonVisible="false" DeleteButtonVisible="AcDomain.IsDeveloperVersion" Width="80" MinWidth="80" FixedPosition="GridColumnFixedPosition.Left" />
<DxGridDataColumn FieldName="Id" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
<DxGridDataColumn FieldName="OrderId" Caption="Order" SortIndex="1" SortOrder="GridColumnSortOrder.Descending" Width="70">
<CellDisplayTemplate>
@{
var idKeyField = ((Transfer)context.DataItem).Id.ToString("N");
var editUri = $"hotel/mytransfers/{idKeyField}";
<NavLink href="@editUri">
<text>@context.Value</text>
</NavLink>
}
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName="FromAddress" />
<DxGridDataColumn FieldName="ToAddress" />
<DxGridDataColumn FieldName="Appointment" DisplayFormat="g" Width="125" />
<DxGridDataColumn FieldName="PassengerCount" Caption="Passengers" Width="90" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="LuggageCount" Caption="Luggages" Width="80" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="FlightNumber" Caption="FlightNum" Width="95" TextAlignment="GridTextAlignment.Center" CaptionAlignment="GridTextAlignment.Center" />
<DxGridDataColumn FieldName="FullName" />
<DxGridDataColumn FieldName="ContactPhone" Width="120" />
<DxGridDataColumn FieldName="ContactEmail" Width="120" />
<DxGridDataColumn FieldName="TransferStatusType" Caption="Status" SortIndex="0" Width="120" SortOrder="GridColumnSortOrder.Ascending" SortMode="GridColumnSortMode.Value" />
<DxGridDataColumn FieldName="Comment" Caption="Comment" />
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="125" Visible="false" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
</Columns>
</TransferGrid>
</div>
</DxTabPage>
</DxTabs>
</div>
</div>
<div class=" col-12 col-xl-6">
</div>
</div>
</div>
@code {
[Parameter]
public Guid HotelId { get; set; }
private LoggerClient<ManageTransfers> _logger;
private bool _popupVisible;
private TransferGrid _gridTransfer;
private DxTagBox<TransferStatusModel, TransferStatusModel> _filterTag;
public List<string> IgnoreList =
[
"ReceiverEmailAddress",
"ReceiverFullName",
"ReceiverId",
"SenderEmailAddress",
"SenderFullName",
"SenderId",
"ContextId",
"ContextType"
];
private static List<TransferStatusModel> _selectedCategories = TransferStatusModel.AllStatuses.Values.Where(x => x.StatusValue != TransferStatusType.Finished && x.StatusValue != TransferStatusType.UserCanceled && x.StatusValue != TransferStatusType.AdminDenied).ToList();
private MessageWizardModel _messageWizardModel = new();
public List<AppointmentModel> AppointmentModels { get; set; } = null!;
DateTime StartDate { get; set; } = DateTime.Today;
DxSchedulerDataStorage _dataStorage = new();
void SendMail(Transfer item)
{
_logger.Info($"Preparing mail to {item.ContactEmail}, {item.Id}");
_messageWizardModel.Subject = $"[#{item.OrderId}] New message regarding your transfer";
_messageWizardModel.ReceiverId = item.UserId;
_messageWizardModel.ContextId = item.Id;
_messageWizardModel.ContextType = MessageContextType.Transfer;
_messageWizardModel.SenderId = TiamConstClient.SysAccounts["SystemEmailSender"];
_messageWizardModel.SenderEmailAddress = TiamConstClient.SystemEmailAddress;
_messageWizardModel.ReceiverEmailAddress = item.ContactEmail;
_messageWizardModel.ReceiverFullName = item.FullName;
_popupVisible = true;
}
void CancelCreateClick()
{
_popupVisible = false;
}
void EulaPopupClosed()
{
//cancel clicked
}
void EulaPopupClosing(PopupClosingEventArgs args)
{
//myModel = new TransferWizardModel();
_messageWizardModel = new MessageWizardModel();
}
//-----------------------------------------------------------------------------------
public async Task SubmitForm(object result)
{
var messageModel = (result as MessageWizardModel)!;
_logger.Info(messageModel.Content);
var email = await wizardProcessor.ProcessWizardAsync<MessageWizardModel>(result.GetType(), messageModel);
_logger.Info($"Submitted nested form: {result.GetType().FullName}");
CancelCreateClick();
}
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
{
try
{
if (e.ElementType == GridElementType.HeaderCell)
{
e.Style = "background-color: rgba(0, 0, 0, 0.08)";
e.CssClass = "header-bold";
}
if (e.ElementType != GridElementType.DataRow) return;
var transferStatus = e.Grid?.GetRowValue(e.VisibleIndex, "TransferStatusType");
if (transferStatus == null) return;
var transferStatusByte = (byte)transferStatus;
switch (transferStatusByte)
{
case 5:
e.CssClass = "bg-important";
break;
case > 5 and < 35:
e.CssClass = "bg-attention";
break;
case 35:
e.CssClass = "bg-finished";
break;
case > 35:
e.CssClass = "bg-cancel";
break;
}
}
catch (Exception ex)
{
_logger.Error($"Grid_CustomizeElement; {ex.Message}", ex);
}
}
void Grid_CustomizeEditModel(GridCustomizeEditModelEventArgs e)
{
if (!e.IsNew) return;
var transferEditModel = (Transfer)e.EditModel; //TODO not valid cast
transferEditModel.Id = Guid.NewGuid();
transferEditModel.ToAddress = "Where to?";
transferEditModel.FromAddress = "From where?";
transferEditModel.Appointment = DateTime.UtcNow.AddDays(3);
transferEditModel.PassengerCount = 1;
transferEditModel.FirstName = "John";
transferEditModel.LastName = "Doe";
transferEditModel.ContactPhone = "+00000000000";
transferEditModel.ContactEmail = "your@email.address";
}
private static string GetFilterText(ICollection<TransferStatusType> selectedTransferStatuses)
=> selectedTransferStatuses.Count == 0 ? string.Empty : CriteriaOperator.FromLambda<Transfer>(t => selectedTransferStatuses.Contains(t.TransferStatusType)).ToString();
void TagBox_ValuesChanged(IEnumerable<TransferStatusModel> newSelectedCategories)
{
var filterText = string.Empty;
InOperator? filterCriteria = null;
_selectedCategories = newSelectedCategories.ToList();
if (_selectedCategories.Count > 0)
{
filterCriteria = new InOperator("TransferStatusType", _selectedCategories.Select(c => c.StatusValue));
filterText = GetFilterText(_selectedCategories.Select(x => (TransferStatusType)x.StatusValue).ToList());
}
_gridTransfer.SetFieldFilterCriteria("TransferStatusType", filterCriteria);
}
private void DataSourceChanged(IList<Transfer> transfers)
{
_logger.Info("DataSourceChanged called");
InitializeAppointments(transfers);
if (_selectedCategories.Count > 0)
TagBox_ValuesChanged(_selectedCategories);
// if(!SelectedCategories.Any())
// SelectedCategories = [Statuses.FirstOrDefault(x => x.StatusValue == (byte)TransferStatusType.Finished)!];
// var filterTransferStatusType = Statuses.FirstOrDefault(x => x.StatusValue == (byte)TransferStatusType.Finished)!;
// if (SelectedCategories.All(x => x.StatusValue != filterTransferStatusType.StatusValue))
// SelectedCategories.Add(filterTransferStatusType);
}
private void DataSourceItemChanging(GridDataItemChangingEventArgs<Transfer> args)
{
_logger.Info("DataSourceItemChanging called");
}
private void DataSourceItemChanged(GridDataItemChangedEventArgs<Transfer> args)
{
_logger.Info("DataSourceItemChanged called");
AppointmentModels.UpdateCollection(CreateAppointmentModel(args.DataItem), args.TrackingState == TrackingState.Remove);
}
private void DataItemSaving(GridEditModelSavingEventArgs e)
{
_logger.Info("DataItemSaving called");
}
private void DataItemDeleting(GridDataItemDeletingEventArgs e)
{
_logger.Info($"DataItemDeleting OnItemDeleting");
}
protected override Task OnInitializedAsync()
{
_logger = new LoggerClient<ManageTransfers>(_logWriters.ToArray());
return base.OnInitializedAsync();
}
private void InitializeAppointments(ICollection<Transfer> transferDataList)
{
_logger.Info("InitializeAppointments called");
AppointmentModels = new List<AppointmentModel>(transferDataList.Count);
foreach (var transfer in transferDataList)
{
// var bnm = DataStorage.CreateAppointmentItem();
// bnm.Start = transfer.Appointment;
// bnm.Description = $"{transfer.FullName}, {transfer.ToAddress}";
// bnm.Location = transfer.FromAddress;
// bnm.Subject = "Simple transfer";
AppointmentModels.Add(CreateAppointmentModel(transfer));
}
_dataStorage = new DxSchedulerDataStorage
{
AppointmentMappings = new DxSchedulerAppointmentMappings()
{
Type = "AppointmentType",
Start = "StartDate",
End = "EndDate",
Subject = "Caption",
AllDay = "AllDay",
Location = "Location",
Description = "Description",
LabelId = "Label",
StatusId = "Status",
RecurrenceInfo = "Recurrence"
},
AppointmentsSource = AppointmentModels
};
}
public AppointmentModel CreateAppointmentModel(Transfer transfer)
{
return new AppointmentModel { Id = transfer.Id, StartDate = transfer.Appointment, EndDate = transfer.Appointment.AddMinutes(30), Description = $"{transfer.FullName}, {transfer.ToAddress}", Location = transfer.FromAddress, Caption = "Simple transfer" };
}
void ColumnChooserButton_Click()
{
_gridTransfer.ShowColumnChooser();
}
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
//_gridTransfer.ExpandDetailRow(0);
}
}
}

View File

@ -141,10 +141,10 @@
var transfer2 = (Company)EditFormContext.EditModel;
}
<DxFormLayout CssClass="w-100">
<DxFormLayoutItem Caption=@_localizer.GetString(ResourceKeys.LastName) ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
<DxFormLayoutItem Caption="Company name" ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
@EditFormContext.GetEditor("Name")
</DxFormLayoutItem>
<DxFormLayoutItem Caption=@_localizer.GetString(ResourceKeys.LastName) ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
<DxFormLayoutItem Caption="Commission rate (%)" ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
@EditFormContext.GetEditor("CommissionPercent")
</DxFormLayoutItem>
</DxFormLayout>

View File

@ -147,10 +147,10 @@
private ProductDetailGrid _productGrid = null!;
private LoggerClient<ProductDetailGridComponent> _logger = null!;
private async Task CopyUrl(string url)
{
await JsRuntime.InvokeVoidAsync("copyToClipboard", url);
}
@ -189,6 +189,7 @@
{
TransferDestination transferDestination = new TransferDestination();
transferDestination.Id = Guid.NewGuid();
transferDestination.ProductId = product.Id;
transferDestination.Name = product.Name;
if (!string.IsNullOrEmpty(product.Profile.Description))
{

View File

@ -126,9 +126,9 @@
<DxFormLayoutItem Caption=@Localizer.GetString(ResourceKeys.ProductType) ColSpanMd="4">
@editFormContext.GetEditor("ProductType")
</DxFormLayoutItem>
<DxFormLayoutItem Caption=@Localizer.GetString(ResourceKeys.Price) ColSpanMd="4">
@* <DxFormLayoutItem Caption=@Localizer.GetString(ResourceKeys.Price) ColSpanMd="4">
@editFormContext.GetEditor("Price")
</DxFormLayoutItem>
</DxFormLayoutItem> *@
<DxFormLayoutItem Caption=@Localizer.GetString(ResourceKeys.ProductDescription) ColSpanMd="4">
@editFormContext.GetEditor("Description")
</DxFormLayoutItem>
@ -189,6 +189,7 @@
{
TransferDestination transferDestination = new TransferDestination();
transferDestination.Id = Guid.NewGuid();
transferDestination.ProductId = product.Id;
transferDestination.Name = product.Name;
if (!string.IsNullOrEmpty(product.Profile.Description))
{

View File

@ -668,8 +668,7 @@ namespace TIAMWebApp.Server.Controllers
//check if revenue should be calculated
if (transfer.ProductId.HasValue && transfer.Price > 0)
{
if (transfer.Revenue == 0)
{
//price seems to have changed, update commission
if (to == null)
{
@ -677,15 +676,14 @@ namespace TIAMWebApp.Server.Controllers
var product = await _adminDal.Context.Products.FirstOrDefaultAsync(x => x.Id == transfer.ProductId);
if(product != null)
{
transfer.Revenue = transfer.Price * product.ServiceProvider.CommissionPercent;
transfer.Revenue = transfer.Price * product.ServiceProvider.CommissionPercent/100;
}
}
else
{
transfer.Revenue = _transferBackendService.GetCommission((Guid)transfer.ProductId, (double)transfer.Price, to);
}
}
}
}
return await _adminDal.UpdateTransferAsync(transfer);
}