Exemplo n.º 1
0
        public void FindPurchaseOrderTotalTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            var poh   = GetTestPurchaseOrderHeader(testCompany, testUser, 1);
            var model = PurchasingService.FindPurchaseOrderDetailListModel(poh);

            var     pod        = model.Items.First();
            decimal totalValue = pod.OrderQty.Value * pod.UnitPriceExTax.Value;

            for (int i = 0; i < 16; i++)
            {
                pod          = model.Items.First();
                pod.Id       = 0;
                pod.OrderQty = RandomInt();
                totalValue  += pod.OrderQty.Value * pod.UnitPriceExTax.Value;

                var error = PurchasingService.InsertOrUpdatePurchaseOrderDetail(pod, testUser, "");
                Assert.IsTrue(!error.IsError, error.Message);
            }

            var result = PurchasingService.FindPurchaseOrderTotal(poh);

            Assert.IsTrue(result == totalValue, $"Error: {result} was returned when {totalValue} was expected");
        }
        public void LockPurchaseOrderDetailTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            // Create a record
            var poh = GetTestPurchaseOrderHeader(testCompany, testUser, 1);

            // Get the first detail record
            var detailList = PurchasingService.FindPurchaseOrderDetailListModel(poh);
            var detail     = detailList.Items.First();

            // Get the current Lock
            string lockGuid = PurchasingService.LockPurchaseOrderDetail(detail);

            Assert.IsTrue(!string.IsNullOrEmpty(lockGuid), "Error: Lock record was not found");

            // Simulate another user updating the record
            var otherUser = GetTestUser();
            var error     = PurchasingService.InsertOrUpdatePurchaseOrderDetail(detail, otherUser, lockGuid);

            Assert.IsTrue(!error.IsError, error.Message);

            // Now get the first user to update the record
            error = PurchasingService.InsertOrUpdatePurchaseOrderDetail(detail, testUser, lockGuid);
            Assert.IsTrue(error.IsError, "Error: The lock should have caused an error as it has changed");

            // Try to update with the new lock
            lockGuid = PurchasingService.LockPurchaseOrderDetail(detail);
            error    = PurchasingService.InsertOrUpdatePurchaseOrderDetail(detail, testUser, lockGuid);
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");
        }
Exemplo n.º 3
0
        public void FindSplitPurchaseDetailsListModelTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            int itemCount   = 6;
            var testOrder   = GetTestPurchaseOrderHeader(testCompany, testUser, itemCount);
            var testDetails = PurchasingService.FindPurchaseOrderDetailListModel(testOrder)
                              .Items
                              .OrderBy(td => td.Id)
                              .ToList();

            var splitModel = PurchasingService.FindSplitPurchaseDetailsListModel(testCompany, testOrder.Id, 0, 1, 1000)
                             .Items
                             .OrderBy(sd => sd.PurchaseOrderDetailId)
                             .ToList();
            int expected = itemCount,
                actual   = splitModel.Count();

            Assert.IsTrue(actual == expected, $"Error: {actual} items were returned when {expected} were expected");

            // Check that all the items match
            for (int i = 0; i < itemCount; i++)
            {
                expected = testDetails[i].Id;
                actual   = splitModel[i].PurchaseOrderDetailId;
                Assert.IsTrue(actual == expected, $"Error: Object Id {actual} was found when Id {expected} was expected");

                expected = testDetails[i].OrderQty.Value;
                actual   = splitModel[i].OrigOrderQty;
                Assert.IsTrue(actual == expected, $"Error: Order Qty {actual} was found when {expected} was expected");
            }
        }
        public void FindPurchaseOrderDetailListModelTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            var poh = GetTestPurchaseOrderHeader(testCompany, testUser, 1);

            var model  = PurchasingService.FindPurchaseOrderDetailListModel(poh);
            var dbData = db.FindPurchaseOrderDetails(testCompany.Id, poh.Id);

            int expected = dbData.Count(),
                actual   = model.Items.Count();

            Assert.IsTrue(actual == expected, $"Error: {actual} items were found when {expected} were expected");

            // Check that all the items match
            foreach (var item in model.Items)
            {
                var dbItem = dbData.Where(m => m.Id == item.Id).FirstOrDefault();
                Assert.IsTrue(dbItem != null, "Error: Model item not found in db item list");
                var temp = PurchasingService.MapToModel(dbItem);
                AreEqual(item, temp);
            }

            // Add another item a make sure it is found
            var newItem = createPurchaseOrderDetail(model);
            var error   = PurchasingService.InsertOrUpdatePurchaseOrderDetail(newItem, testUser, "");

            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");

            model = PurchasingService.FindPurchaseOrderDetailListModel(poh);
            var testItem = model.Items.Where(i => i.Id == newItem.Id).FirstOrDefault();

            Assert.IsTrue(testItem != null, "Error: A NULL value was returned when a non-NULL value was expected");

            // Delete it and make sure it disappears
            // Detail items are removed from the temp table, not main table, hence there is
            // no service API to delete them from main
            db.DeletePurchaseOrderDetail(newItem.Id);

            model    = PurchasingService.FindPurchaseOrderDetailListModel(poh);
            testItem = model.Items.Where(i => i.Id == newItem.Id).FirstOrDefault();
            Assert.IsTrue(testItem == null, "Error: A non-NULL value was returned when a NULL value was expected");
        }
        public void FindPurchaseOrderDetailModelTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            var poh = GetTestPurchaseOrderHeader(testCompany, testUser, 10);

            var podList = PurchasingService.FindPurchaseOrderDetailListModel(poh);

            Assert.IsTrue(podList != null, "Error: NULL was returned when an object was expected");

            var pod = PurchasingService.FindPurchaseOrderDetailModel(podList.Items[0].Id);

            Assert.IsTrue(podList != null, "Error: NULL was returned when an object was expected");

            // Now delete it and check it has gone
            PurchasingService.DeletePurchaseOrderDetail(pod);

            pod = PurchasingService.FindPurchaseOrderDetailModel(podList.Items[0].Id);
            Assert.IsTrue(pod == null, "Error: An object was returned when NULL was expected");
        }
Exemplo n.º 6
0
        public void SplitToExistingOrderTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            var sourceOrder      = GetTestPurchaseOrderHeader(testCompany, testUser, 4);
            var sourceOrderItems = PurchasingService.FindPurchaseOrderDetailListModel(sourceOrder);

            // Create a model to split an item off to a new order
            SplitPurchaseModel model = new SplitPurchaseModel {
                PurchaseOrderHeaderId = sourceOrder.Id,
                SupplierName          = "",
                OrderNumber           = 0,
                AdvertisedETA         = null,
                NewOrderAdvertisedETA = DateTimeOffset.Now.AddDays(20),
                LocationId            = 0
            };


            // Try to split off more items than the original order
            var existingOrder = GetTestPurchaseOrderHeader(testCompany, testUser, 0);
            var splitItem     = createSplitItemModel(sourceOrderItems.Items[0].Id, 0, 1500, existingOrder.Id, 1);

            model.SplitItems.Add(splitItem);

            int updatedPOId = 0,
                newPOId     = 0;
            var lgs         = PurchasingService.LockPurchaseOrderHeader(sourceOrder);
            var error       = PurchasingService.SplitOrder(testCompany, model, testUser, lgs, ref updatedPOId, ref newPOId);

            Assert.IsTrue(error.IsError, "$Error: An error was expected but none was returned");


            // Try to split off to an invalid 'existing' order
            splitItem = createSplitItemModel(sourceOrderItems.Items[0].Id, 0, 5, -1, 1);
            model.SplitItems.Clear();
            model.SplitItems.Add(splitItem);

            error = PurchasingService.SplitOrder(testCompany, model, testUser, lgs, ref updatedPOId, ref newPOId);
            Assert.IsTrue(error.IsError, "$Error: An error was expected but none was returned");


            // Now try to split a valid number of items off to an existing order
            int originalQty = sourceOrderItems.Items[0].OrderQty.Value,
                splitQty    = 10;

            splitItem = createSplitItemModel(sourceOrderItems.Items[0].Id, 0, splitQty, existingOrder.Id, 1);
            model.SplitItems.Clear();
            model.SplitItems.Add(splitItem);
            lgs   = PurchasingService.LockPurchaseOrderHeader(sourceOrder);
            error = PurchasingService.SplitOrder(testCompany, model, testUser, lgs, ref updatedPOId, ref newPOId);
            Assert.IsTrue(!error.IsError, error.Message);


            // Check the newly created copy of the original record we have split
            var updatedOrder = PurchasingService.FindPurchaseOrderHeaderModel(updatedPOId, testCompany, false);

            Assert.IsTrue(updatedOrder != null, "Error: A NULL value was returned when an object was expected");

            var updatedPohd = PurchasingService.FindPurchaseOrderDetailListModel(updatedOrder);
            int expected    = originalQty - splitQty,
                actual      = updatedPohd.Items[0].OrderQty.Value;

            Assert.IsTrue(actual == expected, $"Error: The order quantity is now {actual} when {expected} was expected");

            // .. and that the updated order has a note with PDF attachment
            var noteList = NoteService.FindNotesListModel(NoteType.Purchase, updatedPOId, 0, 1, 1000, "", MediaSize.Medium, 0, 0);

            expected = 1;
            actual   = noteList.Items.Count();
            Assert.IsTrue(actual == expected, $"Error: (1) Order was found to have {actual} notes when {expected} were expected");

            var noteAttachments = NoteService.FindNoteAttachmentsModel(noteList.Items[0], MediaSize.Medium, 0, 0);

            expected = 1;
            actual   = noteAttachments.Count();
            Assert.IsTrue(actual == expected, $"Error: (1) Order note was found to have {actual} attachment PDFs when {expected} were expected");


            // Look for the new record in the exiting order
            var newPohdList = db.FindPurchaseOrderDetails(testCompany.Id, existingOrder.Id)
                              .OrderByDescending(ni => ni.Id)
                              .ToList();

            Assert.IsTrue(newPohdList.Count() == 1, $"Error: {newPohdList.Count()} items were returned when 1 was expected");
            expected = splitQty;
            actual   = newPohdList[0].OrderQty.Value;
            Assert.IsTrue(actual == splitQty, $"Error: {actual} items were returned when {expected} was expected");

            // .. and that the existing order has a note with PDF attachment
            noteList = NoteService.FindNotesListModel(NoteType.Purchase, existingOrder.Id, 0, 1, 1000, "", MediaSize.Medium, 0, 0);
            expected = 1;
            actual   = noteList.Items.Count();
            Assert.IsTrue(actual == expected, $"Error: (2) Order was found to have {actual} notes when {expected} were expected");

            noteAttachments = NoteService.FindNoteAttachmentsModel(noteList.Items[0], MediaSize.Medium, 0, 0);
            expected        = 1;
            actual          = noteAttachments.Count();
            Assert.IsTrue(actual == expected, $"Error: (2) Order note was found to have {actual} attachment PDFs when {expected} were expected");

            // TBD: Check that the allocations have been modified
        }
Exemplo n.º 7
0
        public void CompleteOrderTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);
            var poh         = GetTestPurchaseOrderHeader(testCompany, testUser, 10);

            Assert.IsTrue(poh.POStatusValue != PurchaseOrderStatus.Closed, $"Error: Purchase order status {PurchaseOrderStatus.Closed} was found when any other value was expected");

            var podList = PurchasingService.FindPurchaseOrderDetailListModel(poh);

            var testProd1 = ProductService.FindProductModel(podList.Items[0].ProductId.Value, null, null, false);
            var testProd2 = ProductService.FindProductModel(podList.Items[1].ProductId.Value, null, null, false);


            // Clear the records for the first product
            db.DeleteAllocationsForProduct(testCompany.Id, testProd1.Id);

            testProd1.QuantityOnHand = 0;
            string lgs = ProductService.LockProduct(testProd1);

            ProductService.InsertOrUpdateProduct(testProd1, testUser, lgs);

            db.DeleteProductLocationsForProduct(testCompany.Id, testProd1.Id);


            // Copy the order to temp
            var poht = PurchasingService.CopyPurchaseOrderToTemp(testCompany, poh, testUser);

            // Complete the order
            var error = PurchasingService.CompleteOrder(testCompany, testUser, poht.Id);

            Assert.IsTrue(!error.IsError, error.Message);

            poht = PurchasingService.FindPurchaseOrderHeaderTempModel(poht.Id, testCompany, false);
            Assert.IsTrue(poht.POStatusValue == PurchaseOrderStatus.Closed, $"Error: Purchase order status {poht.POStatusValue} was returned when {PurchaseOrderStatus.Closed} was expected");

            // Now try to complete the order again
            error = PurchasingService.CompleteOrder(testCompany, testUser, poht.Id);
            Assert.IsTrue(error.IsError, "Error: No error was returned when one was expected - an order cannot be completed twice");

            poht = PurchasingService.FindPurchaseOrderHeaderTempModel(poht.Id, testCompany, false);
            Assert.IsTrue(poht.POStatusValue == PurchaseOrderStatus.Closed, $"Error: Purchase order status {poht.POStatusValue} was returned when {PurchaseOrderStatus.Closed} was expected");


            // Check the results of the completion
            // Force a reload of all objects
            //ReloadDbContext();

            // Check the Allocations table for the first product
            // The Allocations table records quantity reservations against order lines.
            var allocs1  = AllocationService.FindAllocationListModel(testCompany, testProd1);
            int expected = 0,       // Because it was deleted above
                actual   = allocs1.Items.Count();

            Assert.IsTrue(actual == expected, $"Error: {actual} records were returned when {expected} were expected");

            // Check the Allocations table for the second product
            var allocs2 = AllocationService.FindAllocationListModel(testCompany, testProd2);

            expected = 1;
            actual   = allocs2.Items.Count();
            Assert.IsTrue(actual >= expected, $"Error: {actual} records were returned when >={expected} were expected");

            expected = (int)podList.Items[1].OrderQty;
            actual   = (int)allocs2.Items[0].Quantity;
            Assert.IsTrue(actual >= expected, $"Error: Allocation quantity {actual} was returned when {expected} was expected");


            // Check that the product table has been updated
            // Product.QuantityOnHand is for all locations whereas Allocation and ProductLocation
            // are for individual locations so the quantity in Product will always be higher than
            // the latter two.
            testProd1 = ProductService.FindProductModel(podList.Items[0].ProductId.Value, null, null, false);
            expected  = (int)podList.Items[0].OrderQty;
            actual    = (int)testProd1.QuantityOnHand.Value;
            Assert.IsTrue(actual >= expected, $"Error: Product quantity {actual} was returned when {expected} was expected");

            testProd2 = ProductService.FindProductModel(podList.Items[1].ProductId.Value, null, null, false);
            expected  = (int)podList.Items[1].OrderQty;
            actual    = (int)testProd2.QuantityOnHand.Value;
            Assert.IsTrue(actual >= expected, $"Error: Product quantity {actual} was returned when {expected} was expected");


            // Check that the ProductLocation table has been updated
            var prodLoc = ProductService.FindProductLocationModel(testCompany, testProd1, poh.LocationId.Value);

            expected = (int)podList.Items[0].OrderQty;
            actual   = (int)prodLoc.QuantityOnHand;
            Assert.IsTrue(actual == expected, $"Error: ProductLocation quantity {actual} was returned when {expected} was expected");

            prodLoc  = ProductService.FindProductLocationModel(testCompany, testProd2, poh.LocationId.Value);
            expected = (int)podList.Items[1].OrderQty;
            actual   = (int)prodLoc.QuantityOnHand;
            Assert.IsTrue(actual == expected, $"Error: ProductLocation quantity {actual} was returned when {expected} was expected");
        }