using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.CustomerAssets.Contracts; using Centron.BusinessLogic.Sales.Receipts.Internal; using Centron.Data.Entities.Sales.CustomerAssets.Contracts; using Centron.Data.Entities.Sales.Receipts.Articles; using Centron.Tests.EndToEnd.Infrastructure; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.ContractSpecialPrices { public class ContractSpecialPricesTests : EndToEndTest { public ContractSpecialPricesTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } private const int ArticleI3D = 4352; private const int ContractI3D = 30; private const decimal DefaultSellPrice = 200; private const decimal DefaultRecommendedSellPrice = 300; private const decimal DefaultPurchasePrice = 100; private const decimal DefaultListPrice = 300; private const decimal ChangeValue = 50; // 50 €, or 50 % surcharge, depending on the ReceiptItemPriceBL.ContractSpecialPriceChangeKind of the contract-special-price public override void Execute() { var priceKindInputs = new[] { ReceiptItemPriceBL.ContractSpecialPriceKind.FixedPrice, ReceiptItemPriceBL.ContractSpecialPriceKind.ChangePurchasePrice, ReceiptItemPriceBL.ContractSpecialPriceKind.ChangeRecommendedSellPrice, ReceiptItemPriceBL.ContractSpecialPriceKind.ChangeSellPrice, ReceiptItemPriceBL.ContractSpecialPriceKind.ChangeListPrice }; var changeKindInputs = new[] { ReceiptItemPriceBL.ContractSpecialPriceChangeKind.Fixed, ReceiptItemPriceBL.ContractSpecialPriceChangeKind.Percentage }; this.ExecuteMatrix(priceKindInputs, changeKindInputs, (priceKind, changeKind) => { this.PrepareDatabase(priceKind, changeKind); this.CalculateArticlePrice($"PriceKind_{priceKind}_ChangeKind_{changeKind}"); }); } private void CalculateArticlePrice(string name) { var fakeArticle = new SearchedArticle { I3D = ArticleI3D, IsExternalArticle = false, SellPrice1 = DefaultSellPrice, SellPrice2 = DefaultSellPrice, SellPrice3 = DefaultSellPrice, SellPrice4 = DefaultSellPrice, RecommendedSellPrice = DefaultRecommendedSellPrice, ListPrice = DefaultListPrice, PurchasePrice = DefaultPurchasePrice }; using var session = new BLSession(); var (basePrice, discount) = session.GetBL().GetBasePrice(DefaultPurchasePrice, fakeArticle, null, ContractI3D); this.Verifier.Verify(name, new { BasePrice = basePrice, Discount = discount }); } private void PrepareDatabase(ReceiptItemPriceBL.ContractSpecialPriceKind priceKind, ReceiptItemPriceBL.ContractSpecialPriceChangeKind changeKind) { this.Sql("DELETE FROM dbo.KundenSonderpreise"); this.Sql("DELETE FROM dbo.VertragBepreisungArtikel"); this.Sql("DELETE FROM dbo.VertragBepreisungWaren"); var priceKindI3D = this.Sql($"SELECT TOP 1 I3D FROM dbo.VertragBepreisungArt WHERE ItemIndex = {(int)priceKind}"); var changeKindI3D = this.Sql($"SELECT TOP 1 I3D FROM dbo.VertragBepreisungWeise WHERE ItemIndex = {(int)changeKind}"); using var session = new BLSession(); session.GetBL().SaveContractPricingArticle(new ContractPricingArticle { ContractI3D = ContractI3D, ArticleI3D = ArticleI3D, ChangeType = priceKindI3D, ChangingWay = changeKindI3D, ChangeValue = ChangeValue, State = 1, }); } } }