Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void FindPurchasersListItemModelTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            int itemCount = RandomInt(5, 15);
            var testOrder = GetTestPurchaseOrderHeader(testCompany, testUser, itemCount);
            var brandCat  = ProductService.FindBrandCategoryModel(testOrder.BrandCategoryId.Value, testCompany, false);

            string errorMsg   = "";
            var    purchasers = PurchasingService.FindOrderPurchasers(testOrder,
                                                                      testCompany,
                                                                      testOrder.OrderNumber.Value,
                                                                      ref errorMsg);
            int expected = 1,
                actual   = purchasers.Count();

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

            // No add some more users to the same user group as the purchaser
            var testPurchaser1 = GetTestUser();

            MembershipManagementService.AddUserToGroup(brandCat.CategoryName + " Purchasing", testPurchaser1);

            var testPurchaser2 = GetTestUser();

            MembershipManagementService.AddUserToGroup(brandCat.CategoryName + " Purchasing", testPurchaser2);

            purchasers = PurchasingService.FindOrderPurchasers(testOrder,
                                                               testCompany,
                                                               testOrder.OrderNumber.Value,
                                                               ref errorMsg);
            expected = 3;
            actual   = purchasers.Count();
            Assert.IsTrue(actual == expected, $"Error: {actual} Purchaser(s) were found when {expected} were expected");
        }
Exemplo n.º 3
0
        public void FindOrderPurchasersTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            // Create a purchase
            var poh           = GetTestPurchaseOrderHeader(testCompany, testUser, 10);
            var brandCategory = ProductService.FindBrandCategoryModel(poh.BrandCategoryId.Value, testCompany, false);

            string userGroup = brandCategory.CategoryName + " purchasing";

            MembershipManagementService.AddUserToGroup(userGroup, testUser);

            // Get the users
            string errorMsg = "";
            var    users    = PurchasingService.FindOrderPurchasers(poh,
                                                                    testCompany,
                                                                    poh.OrderNumber.Value,
                                                                    ref errorMsg);

            Assert.IsTrue(users != null, errorMsg);
            int expected = 1,
                actual   = users.Count();

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

            // Add some more users
            var testUser2 = GetTestUser();

            MembershipManagementService.AddUserToGroup(userGroup, testUser2);
            var testUser3 = GetTestUser();

            MembershipManagementService.AddUserToGroup(userGroup, testUser3);

            users = PurchasingService.FindOrderPurchasers(poh,
                                                          testCompany,
                                                          poh.OrderNumber.Value,
                                                          ref errorMsg);
            Assert.IsTrue(users != null, errorMsg);
            expected = 3;
            actual   = users.Count();
            Assert.IsTrue(actual >= expected, $"Error: {actual} user(s) were returned when {expected} were expected");

            // Now remove one and try again
            MembershipManagementService.DeleteUser(testUser2);

            users = PurchasingService.FindOrderPurchasers(poh,
                                                          testCompany,
                                                          poh.OrderNumber.Value,
                                                          ref errorMsg);
            Assert.IsTrue(users != null, errorMsg);
            expected = 2;
            actual   = users.Count();
            Assert.IsTrue(actual >= expected, $"Error: {actual} user(s) were returned when {expected} were expected");

            // Now delete another and try again
            MembershipManagementService.DeleteUser(testUser3);

            users = PurchasingService.FindOrderPurchasers(poh,
                                                          testCompany,
                                                          poh.OrderNumber.Value,
                                                          ref errorMsg);
            Assert.IsTrue(users != null, errorMsg);
            expected = 1;
            actual   = users.Count();
            Assert.IsTrue(actual >= expected, $"Error: {actual} user(s) were returned when {expected} were expected");
        }
        void processFiles(FileTransferConfigurationModel config)
        {
            WriteTaskLog("Processing received files");

            foreach (var fileName in Directory.GetFiles(config.TargetFolder.TrimEnd('\\')))
            {
                bool   bError   = false;
                string errorMsg = "";

                // Open the file to get the purchase order number from the first data line
                CSVFileService.CSVReader reader = new CSVFileService.CSVReader();

                reader.OpenFile(fileName, true);
                Dictionary <string, string> firstLine = reader.ReadLine();
                reader.Close();

                int poNumber = -1;
                if (Int32.TryParse(firstLine["PO_NUMBER"], out poNumber))
                {
                    // Now we know what the PO Number is, attach the file to the purchase
                    // order notes/attachments so that it can be referenced in emails
                    CompanyModel company = new CompanyModel {
                        Id = config.CompanyId
                    };
                    var poh = PurchasingService.FindPurchaseOrderHeaderByPONumberModel(poNumber, company);
                    if (poh != null)
                    {
                        var note = new NoteModel();
                        bError = createNoteWithAttachment(poh, company, fileName, ref note, ref errorMsg);
                        if (!bError)
                        {
                            // A purchase order records who the 'sales person' was - actually the 'purchasor'.
                            // We need to email every user in the same team as the sales person to notify them
                            // of the slip file being received.

                            // To do this, we need to find what user groups the sales person is in and specifically
                            // look for one which has the name of the brand category of the order in it.
                            // We then email all users in that group. This ensures that when an order is received,
                            // the sales person's collegues are informed so that we don't create a situation where
                            // only one person knows about an order.

                            var userList = PurchasingService.FindOrderPurchasers(poh,
                                                                                 company,
                                                                                 poNumber,
                                                                                 ref errorMsg);
                            if (userList != null)
                            {
                                // Send emails to all the users in the list
                                var error = sendUnpackSlipMessage(poh, company, note, poNumber, userList);
                                if (error.IsError)
                                {
                                    errorMsg = error.Message;
                                    bError   = true;
                                }
                            }
                            else
                            {
                                bError = true;
                            }
                        }
                    }
                    else
                    {
                        errorMsg = $"Error: Failed to find the PurchaseOrderHeaderRecord corresponding to Order Number {poNumber} !";
                        bError   = true;
                    }
                }
                else
                {
                    errorMsg = $"Error: Failed to read PO_NUMBER column from '{fileName}' !";
                    bError   = true;
                }

                if (bError)
                {
                    // Failed to process the file so move it to the error folder
                    // Move the file to an error location.
                    // It may not exist if note/attachment creation has already moved it.
                    // It can be moved back in for later re-processing.
                    WriteTaskLog(errorMsg, LogSeverity.Severe);

                    string moveTarget = fileName.FolderName() + "\\Errors";
                    FileManagerService.FileManagerService.DeleteFile(moveTarget + "\\" + fileName.FileName());
                    var error = FileManagerService.FileManagerService.MoveFile(fileName, moveTarget, false);
                    if (error.IsError)
                    {
                        WriteTaskLog(error.Message, LogSeverity.Severe);
                    }
                }
            }
        }