Пример #1
0
        public ActionResult Edit(int id)
        {
            // Called when a user clicks to edit a sale
            var model = new EditSalesOrderHeaderTempViewModel();

            var sale = SalesService.FindSalesOrderHeaderModel(id, CurrentCompany, true);

            // Copy the order into temp tables for editing
            model.SaleTemp = SalesService.CopySaleToTemp(CurrentCompany, sale, CurrentUser, false);
            prepareEditModel(model, model.SaleTemp.Id);

            // If any of the items on the order are partially or fully completed, then we
            // disable ading and editing of items.
            // The ids of SalesOrderLineStatus' are the same as the enums.
            var items = SalesService.FindSalesOrderDetailTempsListModel(CurrentCompany.Id, model.SaleTemp.Id, 0);

            foreach (var item in items.Items)
            {
                if (item.LineStatusId == (int)SalesOrderLineStatus.SentForPicking ||
                    item.LineStatusId == (int)SalesOrderLineStatus.Complete)
                {
                    model.PartiallyComplete = true;
                    break;
                }
            }

            model.LGS  = SalesService.LockSalesOrderHeader(sale);
            model.LGST = SalesService.LockSalesOrderHeaderTemp(model.SaleTemp);

            return(View("Edit", model));
        }
Пример #2
0
        public void DeleteSalesOrderDetailTempTest()
        {
            // Get a test user
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);
            var testSale     = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 1);

            var sohtModel = SalesService.CopySaleToTemp(testCompany, testSale, testUser, false);
            var model     = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, sohtModel.Id, 0, 1, PageSize, "");

            // Create a record
            var newItem = createSalesOrderDetailTemp(sohtModel, testCompany, testCustomer, testUser, model.Items[0].ProductId.Value);

            var error = SalesService.InsertOrUpdateSalesOrderDetailTemp(newItem, testUser, "");

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

            // Check that it was written
            var result = db.FindSalesOrderDetailTemp(newItem.Id);
            var test   = SalesService.MapToModel(result);

            AreEqual(model, test);

            // Now delete it
            SalesService.DeleteSalesOrderDetailTemp(newItem.Id);

            // And check that is was deleted
            result = db.FindSalesOrderDetailTemp(newItem.Id);
            Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed");
        }
Пример #3
0
        public void LockSalesOrderDetailTempTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);

            // Create a record
            var temp1 = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 1);
            var soht  = SalesService.CopySaleToTemp(testCompany, temp1, testUser, false);
            var sodtl = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, soht.Id, 0);
            var model = sodtl.Items.First();

            // Get the current Lock
            string lockGuid = SalesService.LockSalesOrderDetailTemp(model);

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

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

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

            // Now get the first user to update the record
            error = SalesService.InsertOrUpdateSalesOrderDetailTemp(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 = SalesService.LockSalesOrderDetailTemp(model);
            error    = SalesService.InsertOrUpdateSalesOrderDetailTemp(model, testUser, lockGuid);
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");
        }
Пример #4
0
        public ActionResult Add()
        {
            // Called when the user clicks 'Create' to create a new sale
            var editModel = new EditSalesOrderHeaderTempViewModel();

            var sale = SalesService.FindSalesOrderHeaderModel(0, CurrentCompany, true);

            sale.OrderDate       = DateTimeOffset.Now;
            sale.SalespersonId   = CurrentUser.Id;
            sale.BrandCategoryId = CurrentUser.DefaultBrandCategoryId;
            var freightCarrier = LookupService.FindFreightCarriersListItemModel(CurrentCompany)
                                 .Where(fc => fc.Text.ToLower() == "unspecified")
                                 .FirstOrDefault();

            if (freightCarrier != null)
            {
                sale.FreightCarrierId = Convert.ToInt32(freightCarrier.Id);
            }
            sale.ShipCountryId = CurrentCompany.DefaultCountryID;
            sale.NextActionId  = LookupService.FindSaleNextActionId(SaleNextAction.None);

            // Copy the order into temp tables for editing
            editModel.SaleTemp = SalesService.CopySaleToTemp(CurrentCompany, sale, CurrentUser, false);

            return(EditDetails(editModel.SaleTemp.Id));
        }
Пример #5
0
        public void PrintSaleTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompanyAU();

            // Find a random sales order header
            int range   = db.FindSalesOrderHeaders(testCompany.Id).Count();
            var sohList = db.FindSalesOrderHeaders(testCompany.Id)
                          .Skip(RandomInt(0, range - 1))
                          .Take(1)
                          .FirstOrDefault();
            // Uncomment the following line to get a document for a random SOH, possibly with no items
            //var soh = SalesService.MapToModel(sohList);
            // Uncomment the following line to get a document known to have a number of items
            var soh      = SalesService.FindSalesOrderHeaderModel(58, testCompany);
            var soht     = SalesService.CopySaleToTemp(testCompany, soh, testUser, false);
            var customer = CustomerService.FindCustomerModel(soht.CustomerId == null ? 0 : soht.CustomerId.Value, testCompany);

            SalePrintOptionsViewModel model = new SalePrintOptionsViewModel {
                SalesOrderHeaderTempId     = soht.Id,
                TemplateId                 = LookupService.FindDocumentTemplateModel(DocumentTemplateCategory.SalesOrders, DocumentTemplateType.OrderConfirmation).Id,
                ShowCancelledItems         = true,
                SaveInSaleNotesAttachments = true,
                ViewCreatedDocument        = false,
                SendAsEMail                = true,
                Subject       = "Test Subject",
                Message       = "Test Message",
                SaveAsContact = true
            };

            model.CustomerContact.CustomerId = customer.Id;

            // Get all the recipients
            List <ListItemModel> recipients = CustomerService.FindCustomerRecipients(soht, testCompany, testUser);

            bool   bAlt        = false;
            string selectedIds = "To:OTH";

            for (int i = 0; i < recipients.Count(); i++)
            {
                var user = recipients[i];
                selectedIds += "," + (bAlt ? "To:" : "CC:") + user.Id.ToString();
                bAlt         = !bAlt;
            }

            // 'Other user'
            model.CustomerContact.ContactFirstname = RandomString();
            model.CustomerContact.ContactSurname   = RandomString();
            model.CustomerContact.ContactEmail     = RandomEMail();

            // Print the sale
            var error = SalesService.PrintSale(model,
                                               testCompany, testUser, selectedIds);

            Assert.IsTrue(!error.IsError, error.Message);
        }
Пример #6
0
        public ActionResult CopyOrder(int id)
        {
            // Called to copy an order
            var model = new EditSalesOrderHeaderTempViewModel();

            var sale = SalesService.FindSalesOrderHeaderModel(id, CurrentCompany, true);

            // Copy the order into temp tables for editing
            model.SaleTemp = SalesService.CopySaleToTemp(CurrentCompany, sale, CurrentUser, true);
            prepareEditModel(model, model.SaleTemp.Id);

            model.LGS  = SalesService.LockSalesOrderHeader(sale);
            model.LGST = SalesService.LockSalesOrderHeaderTemp(model.SaleTemp);

            return(View("Edit", model));
        }
Пример #7
0
        public void CopyTempToSalesOrderHeaderTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);
            var testSale     = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 10);

            var sohtModel = SalesService.CopySaleToTemp(testCompany, testSale, testUser, false);

            var excludes = new List <string>();

            excludes.Add("Id");
            excludes.Add("OriginalRowIdId");
            excludes.Add("SalesOrderDetails");

            AreEqual(testSale, sohtModel, excludes);
        }
Пример #8
0
        public void FindSalesOrderDetailTempsListModelTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);
            var testSale     = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 10);

            var sohtModel = SalesService.CopySaleToTemp(testCompany, testSale, testUser, false);

            var model  = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, sohtModel.Id, 0, 1, PageSize, "");
            var dbData = db.FindSalesOrderDetailTemps(testCompany.Id, sohtModel.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 = SalesService.MapToModel(dbItem);
                AreEqual(item, temp);
            }

            // Add another item a make sure it is found
            var newItem = createSalesOrderDetailTemp(sohtModel, testCompany, testCustomer, testUser, model.Items[0].ProductId.Value);
            var error   = SalesService.InsertOrUpdateSalesOrderDetailTemp(newItem, testUser, "");

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

            model = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, sohtModel.Id, 0, 1, PageSize, "");
            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
            SalesService.DeleteSalesOrderDetailTemp(newItem.Id);

            model    = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, sohtModel.Id, 0, 1, PageSize, "");
            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");
        }
Пример #9
0
        public void FindSalesOrderDetailTempModelTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);
            var testSale     = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 1);

            var sohtModel = SalesService.CopySaleToTemp(testCompany, testSale, testUser, false);
            var model     = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, sohtModel.Id);

            var newItem = createSalesOrderDetailTemp(sohtModel, testCompany, testCustomer, testUser, model.Items[0].ProductId.Value);
            var error   = SalesService.InsertOrUpdateSalesOrderDetailTemp(newItem, testUser, "");

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

            var test = SalesService.FindSalesOrderDetailTempModel(newItem.Id, null, false);

            AreEqual(model, test);
        }
Пример #10
0
        public void CreateOrderSummaryTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);

            // Create a record
            var temp = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 10);
            var soht = SalesService.CopySaleToTemp(testCompany, temp, testUser, false);

            var summary = SalesService.CreateOrderSummary(soht);

            Assert.IsTrue(summary.SubTotal > 0, $"Error: SubTotal {summary.SubTotal} was returned when a value greater than 0 was expected");
            Assert.IsTrue(!string.IsNullOrEmpty(summary.TaxName), $"Error: TaxName {summary.TaxName} was returned when a no-empty string was expected");
            Assert.IsTrue(summary.TaxTotal > 0, $"Error: TaxTotal {summary.TaxTotal} was returned when a value greater than 0 was expected");
            Assert.IsTrue(summary.Total > 0, $"Error: Total {summary.Total} was returned when a value greater than 0 was expected");
            Assert.IsTrue(summary.TotalCbms > 0, $"Error: TotalCbms {summary.TotalCbms} was returned when a value greater than 0 was expected");
            Assert.IsTrue(!string.IsNullOrEmpty(summary.CurrencySymbol), $"Error: CurrencySymbol {summary.CurrencySymbol} was returned when a no-empty string was expected");
        }
Пример #11
0
        public void FindSalesOrderHeaderModelFromTempIdTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);

            var soh  = GetTestSalesOrderHeader(testCompany, testCustomer, testUser);
            var soht = SalesService.CopySaleToTemp(testCompany, soh, testUser, false);

            var checkSoh = SalesService.FindSalesOrderHeaderModelFromTempId(soht.Id, testCompany, false);

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

            var excludes = new List <string>();

            excludes.Add("SalesOrderDetails");
            excludes.Add("OrderNumberUrl");     // Because it isn't known at test prep

            AreEqual(soh, checkSoh, excludes);
        }
Пример #12
0
        public void FindCustomerTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);

            var soh  = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 1);
            var soht = SalesService.CopySaleToTemp(testCompany, soh, testUser, false);

            var check1 = SalesService.FindCustomer(soht, testCompany);

            AreEqual(check1, testCustomer);

            var sodt = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, soht.Id)
                       .Items
                       .FirstOrDefault();

            var check2 = SalesService.FindCustomer(sodt, testCompany);

            AreEqual(check2, testCustomer);
        }
Пример #13
0
        public void GetNextSalesOrderDetailLineNumberTempTest()
        {
            // Test that next line numbers are correctly incremented in steps of 1000
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser);
            var testCustomer = GetTestCustomer(testCompany, testUser);
            var testSale     = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 1);

            var soht     = SalesService.CopySaleToTemp(testCompany, testSale, testUser, false);
            var itemList = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, soht.Id, 0, 1, 9999, "");

            int expected = 1,
                actual   = itemList.Items.Count();

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

            // Test array
            int[] tests = { 0,      1000,
                            400,    1000,
                            700,    1000,
                            1000,   2000,
                            1100,   2000,
                            2200,   3000,
                            9900,  10000,
                            10100, 11000 };

            for (int i = 0; i < tests.Count(); i += 2)
            {
                itemList.Items[0].LineNumber = tests[i];

                var lgs   = SalesService.LockSalesOrderDetailTemp(itemList.Items[0]);
                var error = SalesService.InsertOrUpdateSalesOrderDetailTemp(itemList.Items[0], testUser, lgs);
                Assert.IsTrue(!error.IsError, error.Message);

                expected = tests[i + 1];
                actual   = db.GetNextSalesOrderDetailLineNumber(soht.Id, true);
                Assert.IsTrue(expected == actual, $"Error: Line number {actual} was returned when {expected} were expected");
            }
        }