using System; using System.Collections.Generic; using System.Linq; using Centron.BusinessLogic.Sales.Receipts; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.Warehousing; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.BusinessLogic.WebServices.Warehousing; using Centron.Data.WebServices.Sales.Receipts.Orders; using Centron.Interfaces; using Centron.Interfaces.Administration.Environment; using Centron.Interfaces.BL; using Centron.Interfaces.Sales.Receipts; using Centron.Tests.EndToEnd.Infrastructure; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket136900; public class Ticket136900Tests : EndToEndTest { public Ticket136900Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { BarcodeBL.GetCurrentDateForSerialNumberGeneration = () => new DateTime(2023, 3, 14); } public const int ArticleI3D = 4363; public const int CustomerI3D = 10006; public override void Execute() { // In this ticket the problem was, that our barcode-logic couldn't deal with the fact // that a receipt might have more than 2000 barcodes var order = this.CreateOrder(); var savedOrder = this.SaveOrder(order); this.Verifier.Verify("SavedOrder", savedOrder); var newVersion = this.CreateNewVersion(savedOrder); var secondSavedOrder = this.SaveOrder(newVersion); this.Verifier.Verify("UpdatedOrder", secondSavedOrder); } private ReceiptOrderDTO CreateOrder() { // Create new barcodes const int barcodeCount = 2500; // 2000 is our own limit, 2100 the one from SQL-Server, so lets go above both of them var barcodes = this.WithSession(s => s.GetBL().CreateAutomaticNewSerialNumbers( amount: barcodeCount, ArticleI3D, warehouseI3D: -1, reason: "Test", adjustStockInventory: true, returnSerialNumbersWithAdditionalInformations: false, this.GetLoggedInUser().User).ThrowIfError()); // Create a order var order = (ReceiptOrderDTO)this.WithSession(s => s.GetBL().CreateNewReceipt( CentronObjectKindNumeric.OrderClass, this.GetLoggedInUser(), CustomerI3D, new CreateReceiptData { IgnoreCallbacks = true, }, addressI3D: null, contactPersonI3D: null, insertSalutationAndAgreement: false, ignoreDefaultContract: true, insertCustomerDiscount: false).ThrowIfError()).Receipt; // Insert article into order var receiptItem = (ReceiptOrderItemDTO)this.WithSession(s => s.GetBL().CreateArticleReceiptItems( order, isExternalArticle: false, ArticleI3D, externalArticleKind: null, externalArticleId: null, warehouseI3D: -1, this.GetLoggedInUser(), CreateArticleReceiptItemsConfig.None()).ThrowIfError()).ReceiptItems.Single(); order.Items = new List { receiptItem }; // Insert barcodes into order receiptItem.Barcodes = barcodes .Select(f => new ReceiptItemBarcode { BarcodeCaption = f.Serialnumber, IsActive = true, BarcodeI3D = f.I3D, }) .ToList(); receiptItem.QuantityComplete = barcodes.Count; return order; } private ReceiptOrderDTO SaveOrder(ReceiptOrderDTO order) { var savedOrder = (ReceiptOrderDTO)this.WithSession(s => s.GetBL().SaveReceipt( order, this.GetLoggedInUser().User, new SaveReceiptData { IgnoreCallbacks = true, }, autoLockIfNewReceipt: false, CreatedThroughApplication.WebServices, receiptTemplateFolderI3D: null).ThrowIfError()).Receipt; return savedOrder; } private ReceiptOrderDTO CreateNewVersion(ReceiptOrderDTO savedOrder) { var newVersion = (ReceiptOrderDTO)this.WithSession(s => s.GetBL().CreateNewVersion( CentronObjectKindNumeric.OrderClass, savedOrder.I3D, null, null, this.GetLoggedInUser().User, new CreateNewVersionData())).ThrowIfError().Receipt; return newVersion; } }