Example #1
0
        public void LockPurchaseOrderHeaderTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            // Create a record
            var model = GetTestPurchaseOrderHeader(testCompany, testUser, 10);

            // Get the current Lock
            string lockGuid = PurchasingService.LockPurchaseOrderHeader(model);

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

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

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

            // Now get the first user to update the record
            error = PurchasingService.InsertOrUpdatePurchaseOrderHeader(model, 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.LockPurchaseOrderHeader(model);
            error    = PurchasingService.InsertOrUpdatePurchaseOrderHeader(model, testUser, lockGuid);
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");
        }
        PurchaseOrderSplitViewModel createModel(int id, bool bLock = false)
        {
            var model = new PurchaseOrderSplitViewModel();

            PrepareViewModel(model, EvolutionResources.bnrSplitPurchase, id);
            model.ParentId = id;

            model.OrderDetails.PurchaseOrderHeaderId = id;
            var poh = PurchasingService.FindPurchaseOrderHeaderModel(id, CurrentCompany);

            if (poh != null)
            {
                model.OrderDetails.SupplierName = poh.SupplierName;
                model.OrderDetails.OrderNumber  = poh.OrderNumber.Value;
                if (poh.RequiredDate != null)
                {
                    model.OrderDetails.AdvertisedETA = poh.RequiredDate.Value.ToString(model.DisplayDateFormat);
                }

                if (bLock)
                {
                    model.LGS = PurchasingService.LockPurchaseOrderHeader(poh);
                }
            }

            model.OrderDetails.NewOrderAdvertisedETA = DateTimeOffset.Now;
            model.LocationList      = LookupService.FindLocationListItemModel(CurrentCompany, true);
            model.PurchaseOrderList = PurchasingService.FindPurchaseOrderHeadersString(CurrentCompany, true);

            return(model);
        }
        public ActionResult Edit(int id)
        {
            // Called when a user clicks to edit an order
            var model = new EditPurchaseOrderHeaderTempViewModel();

            var purchase = PurchasingService.FindPurchaseOrderHeaderModel(id, CurrentCompany, true);

            // Copy the order into temp tables for editing
            model.PurchaseTemp = PurchasingService.CopyPurchaseOrderToTemp(CurrentCompany, purchase, CurrentUser);
            prepareEditModel(model, model.PurchaseTemp.Id);

            model.LGS  = PurchasingService.LockPurchaseOrderHeader(purchase);
            model.LGST = PurchasingService.LockPurchaseOrderHeaderTemp(model.PurchaseTemp);

            return(View("Edit", model));
        }
        public void CheckCompanyForPassedUnpackDatesTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser);

            EMailService.EMailService service = new EMailService.EMailService(db);
            service.EmptyEMailQueue();

            var task = new NotificationTask(db);

            // Check email queue - should be 0 added
            var expected = 0;

            task.CheckCompanyForPassedUnpackDates(testCompany);
            var actual = service.GetQueueCount();

            Assert.IsTrue(actual == expected, $"Error: Email Count returned {actual} when {expected} was expected");

            // Call email queue = 0 = actual
            // Create POs with Data > now
            var poStatuses = Enum.GetValues(typeof(PurchaseOrderStatus));
            var names      = Enum.GetNames(typeof(PurchaseOrderStatus));

            foreach (var value in Enum.GetValues(typeof(PurchaseOrderStatus)))
            {
                var po = GetTestPurchaseOrderHeader(testCompany, testUser);
                po.RealisticRequiredDate = DateTime.Now.AddDays((int)value);
                po.POStatus = (int)value;
                PurchasingService.InsertOrUpdatePurchaseOrderHeader(po, testUser, PurchasingService.LockPurchaseOrderHeader(po));
            }
            task.CheckCompanyForPassedUnpackDates(testCompany);
            actual = service.GetQueueCount();
            Assert.IsTrue(actual == expected, $"Error: Email Count returned {actual} when {expected} was expected");

            // Create POs with Data < now
            foreach (var value in Enum.GetValues(typeof(PurchaseOrderStatus)))
            {
                var po = GetTestPurchaseOrderHeader(testCompany, testUser);
                po.RealisticRequiredDate = DateTime.Now.AddDays((int)value - 100);
                po.POStatus = (int)value;
                PurchasingService.InsertOrUpdatePurchaseOrderHeader(po, testUser, PurchasingService.LockPurchaseOrderHeader(po));
            }
            expected = 9;
            task.CheckCompanyForPassedUnpackDates(testCompany);
            actual = service.GetQueueCount();
            Assert.IsTrue(actual == expected, $"Error: Email Count returned {actual} when {expected} was expected");
        }
        public ActionResult EditDetails(int id)
        {
            // Called when a user is on one of the order screens and clicks the order details option
            var model = new EditPurchaseOrderHeaderTempViewModel();

            // Use the data in the temp tables
            var purchaseTemp = PurchasingService.FindPurchaseOrderHeaderTempModel(id, CurrentCompany, true);

            purchaseTemp.UserId = CurrentUser.Id;

            model.PurchaseTemp = purchaseTemp;
            prepareEditModel(model, id);

            var purchase = PurchasingService.FindPurchaseOrderHeaderModel(purchaseTemp.OriginalRowId, CurrentCompany, true);

            model.LGS  = PurchasingService.LockPurchaseOrderHeader(purchase);
            model.LGST = PurchasingService.LockPurchaseOrderHeaderTemp(model.PurchaseTemp);

            return(View("Edit", model));
        }
Example #6
0
        public void FindUndeliveredPurchaseOrders2Test()
        {
            // Tests the TaskProcessor/emails
            // Get a test user and test company
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            // Get the current email queue count
            db.EmptyEMailQueue();
            int beforeCount = db.FindEMailQueues().Count();

            var task = new NotificationTask(db);

            task.StartTask();

            int afterCount = db.FindEMailQueues().Count();

            Assert.IsTrue(afterCount == beforeCount, $"Error: The EMail queue contains {afterCount} item(s) when {beforeCount} were expected (1)");

            // Create some orders
            var order1 = GetTestPurchaseOrderHeader(testCompany, testUser, 10);
            var order2 = GetTestPurchaseOrderHeader(testCompany, testUser, 10);

            task.CheckCompanyForPassedUnpackDates(testCompany);

            // The orders are not overdue, so we should not have added any messages to the email queue
            afterCount = db.FindEMailQueues().Count();
            Assert.IsTrue(afterCount == beforeCount, $"Error: The EMail queue contains {afterCount} item(s) when {beforeCount} were expected (2)");

            // Now move the RealisticRequiredDate back so that the orders are overdue
            order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1);

            string lockGuid = PurchasingService.LockPurchaseOrderHeader(order1);

            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid);

            beforeCount = db.FindEMailQueues().Count();

            var error = task.CheckCompanyForPassedUnpackDates(testCompany);

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

            // We should have added a message to the email queue
            afterCount = db.FindEMailQueues().Count();
            int expected = 1 + beforeCount;

            Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (3)");

            // Now move the other order back
            order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1);

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order2);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid);

            beforeCount = db.FindEMailQueues().Count() - beforeCount;

            task.CheckCompanyForPassedUnpackDates(testCompany);

            // We should have added two messages
            afterCount = db.FindEMailQueues().Count();
            expected   = 2 + beforeCount;
            Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (4)");

            // Now add another sales person to the user groups of the orders.
            // Note that each order could be a different brand category/group
            var testUser2     = GetTestUser();
            var brandCategory = ProductService.FindBrandCategoryModel(order1.BrandCategoryId.Value, testCompany, false);

            MembershipManagementService.AddUserToGroup(brandCategory.CategoryName + " Purchasing", testUser2);

            brandCategory = ProductService.FindBrandCategoryModel(order2.BrandCategoryId.Value, testCompany, false);
            MembershipManagementService.AddUserToGroup(brandCategory.CategoryName + " Purchasing", testUser2);

            beforeCount = db.FindEMailQueues().Count();

            task.CheckCompanyForPassedUnpackDates(testCompany);

            // We should have added another 4 messages
            afterCount = db.FindEMailQueues().Count();
            expected   = 2 + beforeCount;
            Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (5)");

            // Put the orders forward
            order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10));

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order1);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid);

            order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10));

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order2);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid);

            beforeCount = db.FindEMailQueues().Count();

            task.CheckCompanyForPassedUnpackDates(testCompany);

            // We should not have added any more messages
            afterCount = db.FindEMailQueues().Count();
            expected   = 0 + beforeCount;
            Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (6)");

            task.EndTask(0);
        }
Example #7
0
        public void FindUndeliveredPurchaseOrdersTest()
        {
            // Tests the service
            // Get a test user and test company
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            // Should be no orders to start with
            var undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            int expected          = 0,
                actual            = undeliveredOrders.Items.Count;

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


            // Create some orders
            var order1 = GetTestPurchaseOrderHeader(testCompany, testUser, 10);
            var order2 = GetTestPurchaseOrderHeader(testCompany, testUser, 10);

            undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            expected          = 0;
            actual            = undeliveredOrders.Items.Count;
            Assert.IsTrue(actual == expected, $"Error: {actual} orders were returned when {expected} were expected (2)");

            // Now move the RealisticRequiredDate back so that the orders are overdue
            order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1);

            string lockGuid = PurchasingService.LockPurchaseOrderHeader(order1);

            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid);

            undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            expected          = 1;
            actual            = undeliveredOrders.Items.Count;
            Assert.IsTrue(actual == expected, $"Error: {actual} orders were returned when {expected} were expected (3)");

            // Now move the other order back
            order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1);

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order2);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid);

            undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            expected          = 2;
            actual            = undeliveredOrders.Items.Count;
            Assert.IsTrue(actual == expected, $"Error: {actual} orders were returned when {expected} were expected (4)");

            // Put them forward
            order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10));

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order1);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid);

            order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10));

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order2);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid);

            undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            expected          = 0;
            actual            = undeliveredOrders.Items.Count;
            Assert.IsTrue(actual == expected, $"Error: {actual} orders were returned when {expected} were expected (5)");
        }
Example #8
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
        }