Error sendUnpackSlipMessage(PurchaseOrderHeaderModel poh,
                                    CompanyModel company,           // Company of the file transfer
                                    NoteModel note,
                                    int poNumber,
                                    List <UserModel> userList)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.AddProperty("PURCHASEORDERNO", poNumber);
            dict.AddProperty("COMPANYNAME", company.FriendlyName);

            UserModel purchaser = MembershipManagementService.FindUserModel(poh.SalespersonId.Value);

            dict.AddProperty("PURCHASER", (purchaser == null ? "" : (purchaser.FirstName + " " + purchaser.LastName).Trim()));

            dict.AddProperty("SUPPLIER", poh.SupplierName);

            var attachment = NoteService.FindNoteAttachmentsModel(note, MediaSize.Medium, 0, 0).FirstOrDefault();

            string url = "";

            if (attachment != null)
            {
                url = MediaService.GetMediaFileName(attachment.Media, true);
            }
            dict.AddProperty("URL", url);

            return(SendMessage(company,
                               user,
                               MessageTemplateType.UnpackSlipNotification,
                               TaskType.Default,
                               userList,
                               dict));
        }
示例#2
0
        public List <UserModel> FindOrderPurchasers(PurchaseOrderHeaderModel poh,
                                                    CompanyModel company,
                                                    decimal poNumber,
                                                    ref string errorMsg)
        {
            // Given a PurchaseOrderHeader model, finds the sales person (purchaser)
            // for the order and returns a list of all the users in the same user
            // group as the sales person, including the sales person.
            List <UserModel> users = null;

            UserModel salesPerson = null;

            if (poh.SalespersonId != null)
            {
                salesPerson = MembershipManagementService.FindUserModel(poh.SalespersonId.Value);
            }
            if (salesPerson != null)
            {
                // Found the sales person
                BrandCategoryModel brandCat = null;
                if (poh.BrandCategoryId != null)
                {
                    brandCat = ProductService.FindBrandCategoryModel(poh.BrandCategoryId.Value, company, false);
                }
                if (brandCat != null)
                {
                    string groupName = brandCat.CategoryName.ToLower() + " purchasing";
                    var    userGroup = MembershipManagementService.FindGroupsForUser(salesPerson)
                                       .Where(ug => ug.GroupName.ToLower().Contains(groupName))
                                       .FirstOrDefault();
                    if (userGroup != null)
                    {
                        // Found the group, so get all the users in the group, including the sales person
                        users = MembershipManagementService.FindUsersInGroup(userGroup);
                        if (users.Count() == 0)
                        {
                            errorMsg = $"Error: Active Directory User Group '{groupName}' has no members!";
                            users    = null;;
                        }
                    }
                    else
                    {
                        errorMsg = $"Error: Failed to find Active Directory Group '{groupName}' !";
                    }
                }
                else
                {
                    errorMsg = $"Error: Failed to find a Brand Catgeory for Purchase Order Number {poNumber} !";
                }
            }
            else
            {
                errorMsg = $"Error: Failed to find a Sales Person for Purchase Order Number {poNumber} !";
            }

            return(users);
        }
示例#3
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);
        }
        public void DeleteUserTest()
        {
            var testUser = GetTestUser();

            var dbUser = db.FindUser(testUser.Id);

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

            var checkUser = MembershipManagementService.FindUserModel(dbUser.Id);

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

            var dbUserModel = MembershipManagementService.MapToModel(dbUser);

            AreEqual(checkUser, dbUserModel);

            MembershipManagementService.DeleteUser(dbUser.Id);
            checkUser = MembershipManagementService.FindUserModel(dbUser.Id);
            Assert.IsTrue(checkUser == null, "Error: A non-NULL value was returned when a NULL value was expected (user not deleted)");
        }
示例#5
0
        private Error BuildRecipientLists(string selectedIds,
                                          CustomerContactModel contact,
                                          CompanyModel company, CustomerModel customer,
                                          bool bSaveAsContact,
                                          List <UserModel> toUsers, List <UserModel> ccUsers)
        {
            // SelectedIds is supplied as a comma separated list:
            //  To:123,CC:-345,To:OTH
            // Where:
            //  A prefix of 'To' denotes a recipient
            //  A prefix of 'Cc' denotes a user to 'cc' to
            //  A positive number represents an id of a CustomerContact record
            //  A negative number represents the id of a User record (multiply it by -1 to get the positive value)
            //  OTH indicates that the details for 'Other User' should be retrieved from parameter: contact

            // The method returns two lists of UserModels, one for 'To' and one for 'cc' recipients.
            var error = new Error();

            var selected = selectedIds.ToLower().Split(',');

            foreach (var recipient in selected)
            {
                var pos = recipient.IndexOf(":");
                if (pos != -1)
                {
                    UserModel user    = null;
                    var       recType = recipient.Substring(0, pos).ToLower();
                    var       recId   = recipient.Substring(pos + 1).ToLower();

                    if (recId == "oth")
                    {
                        // New contact
                        if (bSaveAsContact)
                        {
                            contact.CompanyId = company.Id;
                            contact.Enabled   = true;
                            error             = CustomerService.InsertOrUpdateCustomerContact(contact, user, "");
                        }
                        else
                        {
                            error = CustomerService.ValidateContactModel(contact);
                        }
                        if (error.IsError)
                        {
                            break;
                        }
                        else
                        {
                            user = new UserModel {
                                FirstName = contact.ContactFirstname,
                                LastName  = contact.ContactSurname,
                                EMail     = contact.ContactEmail
                            };
                        }
                    }
                    else
                    {
                        var id = Convert.ToInt32(recId);
                        if (Convert.ToInt32(id) < 0)
                        {
                            // User
                            user = MembershipManagementService.FindUserModel(Math.Abs(id));
                        }
                        else
                        {
                            // Contact
                            var temp = CustomerService.FindCustomerContactModel(id, company, customer, false);
                            if (temp != null)
                            {
                                user = new UserModel {
                                    FirstName = temp.ContactFirstname,
                                    LastName  = temp.ContactSurname,
                                    EMail     = temp.ContactEmail
                                }
                            }
                            ;
                        }
                    }
                    if (user != null)
                    {
                        if (recType == "to")
                        {
                            toUsers.Add(user);
                        }
                        else
                        {
                            ccUsers.Add(user);
                        }
                    }
                }
            }
            return(error);
        }
    }
示例#6
0
        public ActionResult Save(EditSalesOrderHeaderTempViewModel model, string command)
        {
            switch (command.ToLower())
            {
            case "save":
                // Save the screen data back to the temp tables, then copy to live tables and exit
                if (ModelState.IsValid)
                {
                    adjustDates(model.SaleTemp, model.TZ);

                    var modelError = new Error();

                    var items = SalesService.FindSalesOrderDetailTempsListModel(CurrentCompany.Id, model.SaleTemp.Id, 0, 1, 9999, "");
                    if (items.Items.Count() == 0)
                    {
                        prepareEditModel(model, model.SaleTemp.Id);
                        model.SetErrorOnField(ErrorIcon.Error,
                                              EvolutionResources.errCantSaveSaleWithNoLines,
                                              "SaleTemp_EndUserName");
                        return(View("Edit", model));
                    }
                    else
                    {
                        modelError = SalesService.InsertOrUpdateSalesOrderHeaderTemp(model.SaleTemp, CurrentUser, model.LGST, false);
                        if (modelError.IsError)
                        {
                            prepareEditModel(model, model.SaleTemp.Id);
                            model.SetErrorOnField(ErrorIcon.Error,
                                                  modelError.Message,
                                                  "SaleTemp_" + modelError.FieldName);
                            return(View("Edit", model));
                        }
                        else
                        {
                            // Copy the temp tables back to the main tables
                            modelError = SalesService.CopyTempToSalesOrderHeader(model.SaleTemp.Id, CurrentUser, model.LGS);
                            if (modelError.IsError)
                            {
                                prepareEditModel(model, model.SaleTemp.Id);
                                model.SetErrorOnField(ErrorIcon.Error,
                                                      modelError.Message,
                                                      "SaleTemp_" + modelError.FieldName);
                            }
                            else
                            {
                                if (model.SaleTemp.OverrideApproverId != null)
                                {
                                    // Send override approbal notification
                                    var sohm = SalesService.FindSalesOrderHeaderModel(modelError.Id, CurrentCompany, false);

                                    SalesService.SendMSQOverrideEMail(CurrentCompany,
                                                                      CurrentUser,
                                                                      MembershipManagementService.FindUserModel(model.SaleTemp.OverrideApproverId.Value),
                                                                      sohm);

                                    // Update the temp record so that we don't send a second approval email
                                    model.SaleTemp.OverrideApproverId = null;
                                    SalesService.InsertOrUpdateSalesOrderHeaderTemp(model.SaleTemp, CurrentUser,
                                                                                    SalesService.LockSalesOrderHeaderTemp(model.SaleTemp),
                                                                                    false);
                                }

                                return(RedirectToAction("Sales"));
                            }
                        }
                    }
                }
                prepareEditModel(model, model.SaleTemp.Id);
                return(View("Edit", model));

            default:
                return(RedirectToAction("Sales"));
            }
        }
示例#7
0
        private Error processPurchaseOrder(PurchaseOrderHeader poh,
                                           FileTransferConfigurationModel template,
                                           FileRecipient fileRecipient)
        {
            var error = new Error();

            // Load the template configuration file
            string configFile = getTemplateFileName(template),
                   tempFile   = "",
                   zipFile    = "";

            XElement doc = XElement.Load(configFile);

            var file = doc.Element("File");

            error = createPurchaseOrderDataFile(poh, file, ref tempFile);
            if (!error.IsError)
            {
                // Check if the file is compressed individually and sent
                bool bCompress = file.Attribute("CompressFile").Value.ParseBool();
                if (bCompress)
                {
                    // File is to be compressed
                    zipFile = tempFile.ChangeExtension(".zip");

                    error = Zip.ZipFile(tempFile, zipFile);

                    if (error.IsError)
                    {
                        FileManagerService.FileManagerService.DeleteFile(zipFile);
                    }
                    else
                    {
                        tempFile = zipFile;
                    }
                }

                bool bDelTempFile = true;
                if (!error.IsError)
                {
                    if (file.Attribute("FTPFile").Value.ParseBool())
                    {
                        // Copy the file to the FTP pickup folder
                        error = moveFileToFTPFolder(tempFile, template.SourceFolder, poh.OrderNumber + (bCompress ? ".zip" : ".txt"));
                    }
                    if (!error.IsError && file.Attribute("EMailFile").Value.ParseBool())
                    {
                        // Queue the file to be sent as an email
                        var company = CompanyService.FindCompanyModel(poh.CompanyId);

                        var purchaser = MembershipManagementService.FindUserModel(poh.SalespersonId.Value);

                        string email = "";
                        if (fileRecipient == FileRecipient.FreightForwarder)
                        {
                            var fforwarder = LookupService.FindFreightForwarderModel(poh.FreightForwarderId.Value);
                            if (string.IsNullOrEmpty(fforwarder.Email))
                            {
                                error.SetError(EvolutionResources.errCantSendEMailToBlankFreightForwarderAddress);
                            }
                            else
                            {
                                email = fforwarder.Email;
                            }
                        }
                        else
                        {
                            error.SetError(EvolutionResources.errEMailingWarehouseNotSupported);
                        }

                        if (!error.IsError)
                        {
                            var recipient = new UserModel {
                                EMail = email
                            };
                            var message = new EMailMessage(purchaser, recipient, MessageTemplateType.PurchaseOrderNotificationFF);

                            EMailService(company).AddOrganisationDetails(message.Dict);
                            EMailService().AddUserDetails(purchaser, message.Dict);
                            message.AddProperty("PURCHASEORDERNO", poh.OrderNumber.Value);

                            message.AddAttachment(tempFile);

                            error = EMailService().SendEMail(message);
                            if (!error.IsError)
                            {
                                bDelTempFile = false;
                            }
                        }
                    }
                }
                if (bDelTempFile)
                {
                    FileManagerService.FileManagerService.DeleteFile(tempFile);
                }
            }

            return(error);
        }