Пример #1
0
        public FileMetadata SendDefaultNoticeComm14Borrower(CollectionMailModel model)
        {
            var variables = new Dictionary <string, string> {
                { "CustomerName", model.CustomerName },
                { "CompanyName", model.CompanyName },
                { "GuarantorName", model.GuarantorName },
                { "Date", model.Date.ToLongDateWithDayOfWeek() },
                { "LoanRef", model.LoanRef },
                { "LoanDate", model.LoanDate.ToLongDate() },
                { "LoanAmount", model.LoanAmount.ToNumericNoDecimals() },
                { "SchedDate", model.MissedPayment.DateDue.ToLongDate() },
                { "AmountDue", model.MissedPayment.AmountDue.ToNumeric2Decimals() },
                { "AmountPaid", model.MissedPayment.RepaidAmount.ToNumeric2Decimals() },
                { "AmountTotal", (model.MissedPayment.AmountDue - model.MissedPayment.RepaidAmount).ToNumeric2Decimals() },
                { "OutstandingBalance", model.OutstandingBalance.ToNumeric2Decimals() },
            };

            SetAddress(model.CustomerAddress, ref variables);

            var templateModel = this.templates.FirstOrDefault(x => x.TemplateName == DefaultnoticeComm14BorrowerTemplateName && model.OriginId == x.OriginID && x.IsActive);

            if (templateModel == null)
            {
                Log.Warn("template " + DefaultnoticeComm14BorrowerTemplateName + " was not found for origin" + model.OriginId);
                return(null);
            }
            Stream template = PrepareMail.ByteArrayToStream(templateModel.Template);

            byte[] pdfData = PrepareMail.ReplaceParametersAndConvertToPdf(template, variables);
            return(SendMail(pdfData, model.CustomerId, DefaultnoticeComm14BorrowerTemplateName, templateModel.ID));
        }
Пример #2
0
        public FileMetadata SendAnual77ANotification(int customerID, SnailMailTemplate template, Address address, Dictionary <string, string> variables, TableModel schedule, string scheduleNode)
        {
            SetAddress(address, ref variables);
            Stream templateStream          = PrepareMail.ByteArrayToStream(template.Template);
            var    templateDoc             = PrepareMail.GetDocumentFromTemplate(templateStream);
            var    scheduleTableDoc        = PrepareMail.CreateTable(schedule);
            var    templateDocWithSchedule = PrepareMail.ReplaceNodeByAnotherDocument(templateDoc, scheduleNode, scheduleTableDoc);

            byte[] pdfData = PrepareMail.ReplaceParametersAndConvertToPdf(templateDocWithSchedule, variables);
            return(SendMail(pdfData, customerID, template.TemplateName, template.ID));
        }
Пример #3
0
        public FileMetadata SendDefaultTemplateConsumer31(CollectionMailModel model)
        {
            var variables = new Dictionary <string, string> {
                { "CustomerName", model.CustomerName },
                { "Date", model.Date.ToLongDateWithDayOfWeek() },
                { "LoanRef", model.LoanRef },
                { "LoanDate", model.LoanDate.ToLongDate() },
                { "TotalBalance", (model.MissedInterest + model.OutstandingPrincipal).ToNumeric2Decimals() },
                { "AmountDue1", (model.PreviousMissedPayment.AmountDue).ToNumeric2Decimals() },
                { "DateDue1", (model.PreviousMissedPayment.DateDue).ToLongDate() },
                { "PartialPaid1", (model.PreviousMissedPayment.RepaidAmount).ToNumeric2Decimals() },
                { "RepaidDate1", (model.PreviousMissedPayment.RepaidDate).ToLongDate() },
                { "Total1", (model.PreviousMissedPayment.AmountDue - model.PreviousMissedPayment.RepaidAmount).ToNumeric2Decimals() },
                { "AmountDue2", (model.MissedPayment.AmountDue).ToNumeric2Decimals() },
                { "DateDue2", (model.MissedPayment.DateDue).ToLongDate() },
                { "PartialPaid2", (model.MissedPayment.RepaidAmount).ToNumeric2Decimals() },
                { "RepaidDate2", (model.MissedPayment.RepaidDate).ToLongDate() },
                { "Total2", (model.MissedPayment.AmountDue - model.MissedPayment.RepaidAmount).ToNumeric2Decimals() },
                { "Total", (model.MissedPayment.AmountDue - model.MissedPayment.RepaidAmount + model.PreviousMissedPayment.AmountDue - model.PreviousMissedPayment.RepaidAmount).ToNumeric2Decimals() },
            };

            SetAddress(model.CustomerAddress, ref variables);

            var templateModel = this.templates.FirstOrDefault(x => x.TemplateName == DefaulttemplateConsumer31TemplateName && model.OriginId == x.OriginID && x.IsActive);

            if (templateModel == null)
            {
                Log.Warn("template " + DefaulttemplateConsumer31TemplateName + " was not found for origin" + model.OriginId);
                return(null);
            }

            Stream template = PrepareMail.ByteArrayToStream(templateModel.Template);

            byte[] pdfData          = PrepareMail.ReplaceParametersAndConvertToPdf(template, variables);
            byte[] concatinatedMail = pdfData;

            var attachmentTemplateModel = this.templates.FirstOrDefault(x => x.TemplateName == DefaulttemplateConsumer31Attachment && model.OriginId == x.OriginID && x.IsActive);

            if (attachmentTemplateModel != null)
            {
                concatinatedMail = PrepareMail.ConcatinatePdfFiles(new List <byte[]> {
                    pdfData,
                    attachmentTemplateModel.Template
                });
            }
            else
            {
                Log.Warn("template " + DefaulttemplateConsumer31Attachment + " was not found for origin" + model.OriginId);
            }

            return(SendMail(concatinatedMail, model.CustomerId, DefaulttemplateConsumer31TemplateName, templateModel.ID));
        }
Пример #4
0
        private FileMetadata SendDefaultTemplateComm7Personal(int customerID, Dictionary <string, string> variables, Address customerAddress, int originId)
        {
            SetAddress(customerAddress, ref variables);
            var templateModel = this.templates.FirstOrDefault(x => x.TemplateName == DefaulttemplateComm7PersonalTemplateName && originId == x.OriginID && x.IsActive);

            if (templateModel == null)
            {
                Log.Warn("template " + DefaulttemplateComm7PersonalTemplateName + " was not found for origin" + originId);
                return(null);
            }
            Stream template = PrepareMail.ByteArrayToStream(templateModel.Template);

            byte[] pdfData = PrepareMail.ReplaceParametersAndConvertToPdf(template, variables);
            return(SendMail(pdfData, customerID, DefaulttemplateComm7PersonalTemplateName, templateModel.ID));
        }
Пример #5
0
        private FileMetadata SendMail(byte[] pdfData, int customerID, string templateName, int templateID)
        {
            Log.InfoFormat("Sending mail to customer {0} template {1}", customerID, templateName);
            bool success = false;

            success = this.api.Authenticate(this.userName, this.password);
            if (!success)
            {
                Log.ErrorFormat("Imail authentication failed\n{0}", this.api.GetErrorMessage());
                return(null);
            }
            if (this.isDebugMode)
            {
                Log.InfoFormat("Sending mail to customer {0} template {1} in debug mode to email {2}", customerID, templateName, this.debugModeEmail);
                if (!string.IsNullOrEmpty(this.debugModeEmail))
                {
                    success = this.api.SetEmailPreview(this.debugModeEmail);
                    if (!success)
                    {
                        Log.ErrorFormat("Imail authentication failed\n{0}", this.api.GetErrorMessage());
                        return(null);
                    }
                }
                else
                {
                    Log.ErrorFormat("Imail Debug mode and email is not provided");
                    return(null);
                }
            }

            success = this.api.ProcessPrintReadyPDF(pdfData, null, false);
            if (!success)
            {
                Log.ErrorFormat("Imail ProcessPrintReadyPDF failed\n{0}", this.api.GetErrorMessage());
                return(null);
            }
            if (!string.IsNullOrEmpty(this.savePath))
            {
                try {
                    return(PrepareMail.SaveFile(pdfData, this.savePath, customerID, templateName, templateID));
                } catch (Exception ex) {
                    Log.WarnFormat("Failed to save mail copy for {0} for customer {1}\n{2}", templateName, customerID, ex);
                }
            }

            return(null);
        }