예제 #1
0
        public Error CheckCompanyForPassedUnpackDates(CompanyModel company)
        {
            var error = new Error();

            foreach (var undeliveredOrder in PurchasingService.FindUndeliveredPurchaseOrders(company).Items)
            {
                string errorMsg = "";
                var    users    = PurchasingService.FindOrderPurchasers(undeliveredOrder,
                                                                        company,
                                                                        undeliveredOrder.OrderNumber.Value,
                                                                        ref errorMsg);
                if (users == null)
                {
                    WriteTaskLog(errorMsg, LogSeverity.Severe);
                }
                else
                {
                    // Send an email
                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    dict.AddProperty("PURCHASEORDERNO", undeliveredOrder.OrderNumber.ToString());
                    dict.AddProperty("COMPANYNAME", company.FriendlyName);

                    var purchaser = MembershipManagementService.FindUserModel(undeliveredOrder.SalespersonId.Value);
                    dict.AddProperty("PURCHASER", (purchaser == null ? "" : purchaser.FullName));
                    dict.AddProperty("REALISTICETA", (undeliveredOrder.RealisticRequiredDate == null ?
                                                      "" :
                                                      undeliveredOrder.RealisticRequiredDate.Value.ToString(company.DateFormat)));

                    var supplier = SupplierService.FindSupplierModel(undeliveredOrder.SupplierId.Value);
                    dict.AddProperty("SUPPLIER", supplier.Name);

                    string url = GetConfigSetting("SiteHttp", "");
                    url += "/Purchasing/Purchasing/Edit?id=" + undeliveredOrder.Id.ToString();
                    dict.AddProperty("URL", url);

                    error = SendMessage(company,
                                        MembershipManagementService.FindNoReplyMailSenderUser(),
                                        MessageTemplateType.UndeliveredPurchaseNotification,
                                        TaskType.Default,
                                        users,
                                        dict);
                }
            }
            return(error);
        }
예제 #2
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)");
        }