using Centron.BusinessLogic; using Centron.BusinessLogic.Administration.Settings; using Centron.BusinessLogic.EmployeeArea; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.Data.WebServices.Sales.Receipts.Invoices; using Centron.Interfaces; using Centron.Tests.EndToEnd.Infrastructure; using Centron.Tests.EndToEnd.Infrastructure.Verifier; using CentronSoftware.Centron.WebServices.Entities.Sales.CustomerAssets.TimerBilling; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket87016 { public class Ticket87016Test : EndToEndTest { public static readonly int HelpdeskI3D = 10461; public static readonly int HelpdeskTimerI3D = 10509; public static readonly int HelpdeskTimerArticleI3D = 94; public static readonly int SpecialArticleFirstI3D = 6228; public static readonly int SpecialArticleSecondI3D = 6229; public static readonly int GlobalDriveArticleFirstI3D = 1; public static readonly int GlobalDriveArticleSecondI3D = 7; public static readonly int ContractI3D = 28; public Ticket87016Test(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { this.PrepareDatabase(); // We will create many invoices here from the same single timer // But we will make some changes to the database between each run, to make sure everything works as expected // // So the current state in the database looks like this // // Ticket: // I3D 10461, Number 12475, AddressI3D 1 // Timer: // I3D 10509, ArticleI3D 94, Timer 407 Seconds, ContractI3D 28 // Special Articles: // I3D 6228, ArticleI3D 56, Type 0 (Fixed Price), Price 35 // I3D 6229, ArticleI3D 1184, Type 1 (Multiplicator), Multiplier 44 // Global Drive Articles: // I3D 1, AddressI3D 1, ArticleI3D 56, Type 0 (Fixed Price), Price 35 // I3D 7, AddressI3D 1, ArticleI3D 1184, Type 1(Multiplicator), Multiplier 44 // // There are NO special prices at the contract this.CreateOriginalInvoice(); this.CreateInvoiceWithSpecialArticlePriceZero(); this.CreateInvoiceWithCustomPrice(); this.CreateInvoiceWithContractPriceForTimer(); } private void PrepareDatabase() { this.Sql($"UPDATE dbo.Stammdat SET WertText = 'g' WHERE I3D = {(int)AppSettingsConst.HelpdeskTimerStartTimeFormat}"); this.Sql($"UPDATE dbo.Stammdat SET WertText = 'g' WHERE I3D = {(int)AppSettingsConst.HelpdeskTimerEndTimeFormat}"); } private void CreateOriginalInvoice() { // Original Invoice should have the following prices // Time: 30 €, Quantity 1 // SpecialArticle 56: 35 €, Quantity 1 // SpecialArticle 1184: 1 €, Quantity 44 this.CreateInvoice("Original"); } private void CreateInvoiceWithSpecialArticlePriceZero() { // Set SpecialArticle Price to 0, so the global drive article price should be used this.Sql($"UPDATE dbo.HelpdeskTimerSpecialArticles SET Price = 0 WHERE I3D = {SpecialArticleFirstI3D}"); this.Sql($"UPDATE dbo.AnschriftSonderartikel SET Preis = 20 WHERE I3D = {GlobalDriveArticleFirstI3D}"); // So now the prices should be // Time: 30 €, Quantity 1 // SpecialArticle 56: 20 €, Quantity 1 // SpecialArticle 1184: 1 €, Quantity 44 this.CreateInvoice("SpecialArticlePriceZero"); // Reset back to default values this.Sql($"UPDATE dbo.HelpdeskTimerSpecialArticles SET Price = 35 WHERE I3D = {SpecialArticleFirstI3D}"); this.Sql($"UPDATE dbo.AnschriftSonderartikel SET Preis = 35 WHERE I3D = {GlobalDriveArticleFirstI3D}"); } private void CreateInvoiceWithCustomPrice() { // Set SpecialArticle Price to 50, making sure the custom price is going to be used this.Sql($"UPDATE dbo.HelpdeskTimerSpecialArticles SET Price = 50 WHERE I3D = {SpecialArticleFirstI3D}"); // So now the prices should be // Time: 30 €, Quantity 1 // SpecialArticle 56: 50 €, Quantity 1 // SpecialArticle 1184: 1 €, Quantity 44 this.CreateInvoice("CustomSpecialPrice"); // Reset back to default values this.Sql($"UPDATE dbo.HelpdeskTimerSpecialArticles SET Price = 35 WHERE I3D = {SpecialArticleFirstI3D}"); } private void CreateInvoiceWithContractPriceForTimer() { // Add a contract price for this contract and the timer article this.Sql($"INSERT INTO dbo.VertragBepreisungArtikel (VertragI3D, ArtikelI3D, Aenderungsart, Aenderungsweise, Aenderungswert, Status)" + $"VALUES({ContractI3D}, {HelpdeskTimerArticleI3D}, 3, 1, 80, 1)"); // So now the prices should be // Time: 80 €, Quantity 1 // SpecialArticle 56: 35 €, Quantity 1 // SpecialArticle 1184: 1 €, Quantity 44 this.CreateInvoice("ContractPriceForTimer"); // Reset back to default values this.Sql($"DELETE FROM dbo.VertragBepreisungArtikel WHERE VertragI3D = {ContractI3D} AND ArtikelI3D = {HelpdeskTimerArticleI3D}"); } private void CreateInvoice(string name) { using (var session = new BLSession()) { var user = session.GetBL().GetAppUser(f => f.I3D == 11); var settings = new TimerBillingSettingsDTO { InsertHelpdeskDescription = true, InsertHelpdeskShortDescription = true, InsertTimerText = true, InsertTimerTime = true, InsertTheFollowingAreTimersFromHelpdeskText = true, Sorting = Interfaces.Sales.Receipts.TimerBilling.TimerSorting.ChronologicalUp, ReceiptKind = CentronObjectKindNumeric.InvoiceClass, }; var invoiceResult = session.GetBL().CreateNewReceiptForHelpdekTimers(new[] { HelpdeskTimerI3D }, settings, user); var verifierSettings = new CentronVerifierSettings(); verifierSettings.IgnoreProperty(f => f.BalanceID); this.Verifier.Verify(name, invoiceResult, verifierSettings); } } } }