using System.Collections.Generic; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.BusinessLogic.WebServices.Warehousing; using Centron.Data.WebServices.Sales.Receipts.CreditVouchers; using Centron.Interfaces; using Centron.Interfaces.Administration.Environment; using Centron.Interfaces.BL; using Centron.Interfaces.Sales.Receipts.InsertReceipts; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.EntitiesWrongPlace.Sales.Receipts.DataAndResults; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket139258; public class Ticket139258Tests : EndToEndTest { public Ticket139258Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { this.Verifier.Settings.IgnoreColumn("Datum"); } public const int ArticleI3D = 17; public const int BarcodeI3D = 84; public const int InvoiceI3D = 43; public override void Execute() { // In this ticket the problem was the following: // 1. create invoice with some barcode (we already have a test-invoice in the database) // 2. create credit-voucher from that invoice (barcode is open again) // 3. close the barcode manually in the UI // 4. create a new version of the credit-voucher from 2. // => Barcode is open again // // This is incorrect, the barcode should stay closed this.PrepareDatabase(); this.VerifyBarcode("1_Original"); var creditVoucher = this.ForwardInvoiceToCreditVoucher(InvoiceI3D); this.VerifyBarcode("2_AfterCreditVoucher"); this.BookOutBarcodeManually(BarcodeI3D, ArticleI3D); this.VerifyBarcode("3_AfterManualClose"); this.CreateNewVersionOfCreditVoucherAndSave(creditVoucher); this.VerifyBarcode("4_AfterNewVersionOfCreditVoucher"); } private void PrepareDatabase() { this.Sql("ALTER TABLE GutKopf DROP COLUMN LcmStatus"); this.Sql($"UPDATE dbo.RechKopf SET ZahlKondID = 5, Bar = 0 WHERE I3D = {InvoiceI3D}"); } private void VerifyBarcode(string name) { this.Verifier.VerifyTable($"{name}_Barcode", "dbo.Barcode", $"I3D = {BarcodeI3D}"); this.Verifier.VerifyTable($"{name}_BarcodeHistory", "dbo.BarcodeHistory", $"BarcodeI3D = {BarcodeI3D}"); this.Verifier.VerifyTable($"{name}_SeriennummerToPosition", "dbo.SeriennummerToPosition", $"SNI3D = {BarcodeI3D}"); } private ReceiptCreditVoucherDTO ForwardInvoiceToCreditVoucher(int invoiceI3D) { var creditVoucher = (ReceiptCreditVoucherDTO)this.WithSession(s => s.GetBL().ForwardReceipt( CentronObjectKindNumeric.CreditVoucherClass, this.GetLoggedInUser().User, new ForwardReceiptData { CreateReceiptData = new CreateReceiptData { IgnoreCallbacks = true, }, CreateReceiptItemsFromExistingItemsData = new List { new() { IgnoreCallbacks = true, }, }, IgnoreCallbacks = true }, new List { new ReceiptToForward { ReceiptKind = CentronObjectKindNumeric.InvoiceClass, ReceiptI3D = invoiceI3D, } }, null, InsertReceiptTakeoverOptions.Reference, true, false)).ThrowIfError().Receipt; return this.SaveCreditVoucher(creditVoucher); } private void BookOutBarcodeManually(int barcodeI3D, int articleI3D) { this.WithSession(s => s.GetBL().CheckOutSerialNumbers( new List { barcodeI3D }, "Some reason", adjustStockInventory: true, this.GetLoggedInUser().User, returnWithAdditionalInformations: false, articleI3D)).ThrowIfError(); } private ReceiptCreditVoucherDTO CreateNewVersionOfCreditVoucherAndSave(ReceiptCreditVoucherDTO creditVoucher) { var newVersion = (ReceiptCreditVoucherDTO)this.WithSession(s => s.GetBL().CreateNewVersion( creditVoucher.ReceiptKind, creditVoucher.I3D, version: null, newContactPersonI3D: null, this.GetLoggedInUser().User, new CreateNewVersionData { IgnoreCallbacks = true })).ThrowIfError().Receipt; return this.SaveCreditVoucher(newVersion); } private ReceiptCreditVoucherDTO SaveCreditVoucher(ReceiptCreditVoucherDTO creditVoucher) { var savedCreditVoucher = (ReceiptCreditVoucherDTO)this.WithSession(s => s.GetBL().SaveReceipt( creditVoucher, this.GetLoggedInUser().User, new SaveReceiptData { IgnoreCallbacks = true, }, autoLockIfNewReceipt: false, CreatedThroughApplication.WebServices, receiptTemplateFolderI3D: null)).ThrowIfError().Receipt; return savedCreditVoucher; } }