Ejemplo n.º 1
0
        public Error SendMSQOverrideEMail(CompanyModel company,
                                          UserModel sender,
                                          UserModel recipient,
                                          SalesOrderHeaderModel model)
        {
            var error = new Error();

            // Send a message to the selected user, indicating that they have been
            // nominated as an approver of an MSQ override
            var message = new EMailMessage(sender, recipient, MessageTemplateType.MSQChangeNotification);

            message.AddProperty("ORDERNO", model.OrderNumber);
            message.AddProperty("SALESPERSON", sender.FullName);
            message.AddProperty("URL", GetConfigurationSetting("SiteHttp", "") + "/Sales/Sales/Edit?id=" + model.Id.ToString());

            EMailService.EMailService emailService = new Evolution.EMailService.EMailService(db, company);
            error = emailService.SendEMail(message);

            if (!error.IsError)
            {
                var NotificationService = GetTaskManagerService(company);

                error = NotificationService.SendTask(Enumerations.MessageTemplateType.MSQChangeNotification,
                                                     TaskType.MSQChangeNotification,
                                                     LookupService.FindLOVItemsModel(company, LOVName.BusinessUnit)
                                                     .Where(bu => bu.ItemText == "Sales")
                                                     .FirstOrDefault(),
                                                     recipient,
                                                     model.CustomerId,
                                                     message.Dict);
            }
            return(error);
        }
Ejemplo n.º 2
0
        public Error PrintSale(SalePrintOptionsViewModel model,
                               CompanyModel company, UserModel currentUser, string selectedIds)
        {
            // Prints the sale according to the user selections
            var error = new Error();

            var soh = FindSalesOrderHeaderModelFromTempId(model.SalesOrderHeaderTempId, company, false);

            if (soh != null)
            {
                var customer = CustomerService.FindCustomerModel(soh.CustomerId.Value, company, false);
                if (customer != null)
                {
                    // Check the recipients and new contacts
                    var recipients = new List <UserModel>();
                    var copies     = new List <UserModel>();
                    error = BuildRecipientLists(selectedIds.ToLower(),
                                                model.CustomerContact,
                                                company,
                                                customer,
                                                model.SaveAsContact,
                                                recipients,
                                                copies);
                    if (!error.IsError)
                    {
                        // Create the required document PDF
                        string outputFile = "";
                        string pdfFile    = MediaServices.GetMediaFolder(MediaFolder.Temp, soh.CompanyId) +
                                            "\\" + soh.OrderNumber + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
                        error = CreateSalesDocumentPdf(soh, model.TemplateId, pdfFile, model.ShowCancelledItems, ref outputFile);
                        if (!error.IsError)
                        {
                            string url = MediaServices.GetMediaFolder(MediaFolder.Temp, soh.CompanyId, -1, -1, true) + "/" + outputFile.FileName();

                            if (model.SaveInSaleNotesAttachments)
                            {
                                // Save it against sale notes/attachments
                                error = NoteService.AttachNoteToSalesOrder(soh,
                                                                           currentUser,
                                                                           (string.IsNullOrEmpty(model.Subject) ? "Sale Preview Document" : model.Subject),
                                                                           model.Message,
                                                                           outputFile.ToStringList(),
                                                                           FileCopyType.Copy);
                            }
                            if (!error.IsError)
                            {
                                if (model.SendAsEMail)
                                {
                                    // Send it as an email attachment
                                    Dictionary <string, string> dict = new Dictionary <string, string>();

                                    if (!error.IsError)
                                    {
                                        var message = new EMailMessage(currentUser, recipients, model.Subject, model.Message);
                                        message.AddCopies(copies);
                                        message.AddProperties(dict);
                                        message.AddAttachment(outputFile, FileCopyType.Copy);

                                        EMailService.EMailService emailService = new Evolution.EMailService.EMailService(db, company);
                                        error = emailService.SendEMail(message);
                                        if (!error.IsError)
                                        {
                                            error.SetInfo(EvolutionResources.infEMailSuccessfullySent);

                                            if (model.ViewCreatedDocument)
                                            {
                                                error.URL = url;
                                            }
                                        }
                                    }
                                }
                                else if (model.ViewCreatedDocument)
                                {
                                    error.URL = url;
                                }
                                else
                                {
                                    error.SetInfo(EvolutionResources.infDocumentSuccessfullyCreated);
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(outputFile))
                        {
                            MediaServices.AddFileToLog(outputFile, 30);
                        }
                    }
                }
                else
                {
                    error.SetRecordError("Customer", soh.CustomerId.Value);
                }
            }
            else
            {
                error.SetError(EvolutionResources.errFailedToFindSOGForSOHT, "", model.SalesOrderHeaderTempId.ToString());
            }
            model.SetError(error.Icon, error.Message, null, null, null, null, true);

            return(error);
        }