106 lines
4.4 KiB
C#
106 lines
4.4 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using TIAM.Core.Enums;
|
|
using TIAM.Database.DataLayers.Admins;
|
|
using TIAM.Entities.Products;
|
|
using TIAM.Entities.Transfers;
|
|
|
|
namespace TIAM.Services.Server
|
|
{
|
|
public class TransferBackendService(IConfiguration configuration, AdminDal adminDal)
|
|
{
|
|
//private readonly IConfiguration _configuration = configuration;
|
|
|
|
public double GetTransferPrice(Guid productId, Guid fromTransferDestinationId, Guid toTranferDestinationId, in byte seatNumber)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public double GetTransferPrice(Guid productId, TransferDestination fromTransferDestination, TransferDestination toTransferDestination, in byte seatNumber)
|
|
{
|
|
var product = adminDal.GetProductById(productId);
|
|
|
|
if (product == null) return -1;
|
|
|
|
return GetTransferPrice(product, fromTransferDestination, toTransferDestination, in seatNumber);
|
|
}
|
|
|
|
public double GetTransferPrice(Product product, TransferDestination fromTransferDestination, TransferDestination toTransferDestination, in byte seatNumber)
|
|
{
|
|
//ha from vagy to null, akkor a product price-t kellene kivenni (és majd vizsgálni, hogy buda vagy pest)
|
|
var baseDestination = product.Profile.AddressId == fromTransferDestination.AddressId ? toTransferDestination : fromTransferDestination;
|
|
|
|
var transferDestinationToProduct = adminDal.GetTransferDestinationToProduct(product.Id, baseDestination.Id);
|
|
|
|
var tranferDestinationPrice = transferDestinationToProduct ?? baseDestination as ITransfeDestinationPrices;
|
|
|
|
//product commission-t nem kellene hozzáadni, mivel a transferDestination árából lejön a transferdestination commission-je (ha van gondolom)
|
|
|
|
var price = GetSeatNumberPrice(in tranferDestinationPrice, seatNumber) + tranferDestinationPrice.ProductCommis + GetExtraPrice(in fromTransferDestination);
|
|
|
|
//TODO: ExtraPrice - J. seatnum percent price, FirstName, LastName, CascadeDelete
|
|
return price;
|
|
}
|
|
|
|
public double GetExtraPrice(in TransferDestination fromTransferDestination)
|
|
{
|
|
return fromTransferDestination.ExtraPrice > 0 ? fromTransferDestination.ExtraPrice : 0;
|
|
}
|
|
|
|
public double GetSeatNumberPrice(in ITransfeDestinationPrices transferDestinationPrices, in byte seatNumber)
|
|
=> GetSeatNumberPrice(transferDestinationPrices.Price, transferDestinationPrices.Price2, transferDestinationPrices.Price3, seatNumber);
|
|
|
|
public double GetSeatNumberPrice(double price, in double? price2, in double? price3, in byte seatNumber)
|
|
{
|
|
return seatNumber switch
|
|
{
|
|
>= (byte)SeatNumberPriceType.Price3SeatNum => price3 ?? price //TODO: price * seatnum percent - J.
|
|
,
|
|
>= (byte)SeatNumberPriceType.Price2SeatNum => price2 ?? price //TODO: price * seatnum percent - J.
|
|
,
|
|
_ => price
|
|
};
|
|
}
|
|
|
|
public double GetCommission(Guid productId, double price, TransferDestination to)
|
|
{
|
|
//check if Destination has a custom commissionRate by productId
|
|
double commissionRate = 0;
|
|
double commission = 0;
|
|
var transferDestinationToProduct = adminDal.GetTransferDestinationToProduct(productId, to.Id);
|
|
if (transferDestinationToProduct != null)
|
|
{
|
|
commissionRate = transferDestinationToProduct.ProductCommis;
|
|
}
|
|
else
|
|
{
|
|
if (to.ProductCommis > 0)
|
|
{
|
|
commissionRate = to.ProductCommis;
|
|
}
|
|
|
|
else
|
|
{
|
|
var product = adminDal.GetProductById(productId);
|
|
if (product != null)
|
|
{
|
|
if(product.ServiceProvider != null)
|
|
{
|
|
commissionRate = product.ServiceProvider.CommissionPercent;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
commission = GetCommission(price, commissionRate);
|
|
return commission;
|
|
}
|
|
|
|
public double GetCommission(double price, double commissionrate)
|
|
{
|
|
return price * commissionrate / 100;
|
|
}
|
|
|
|
}
|
|
}
|