private string GetAddress(LetterFieldsDto fields, string countryInSettings, string cszTemplate)
        {
            var addressLine = new StringBuilder();

            addressLine.Append($"{fields.Label}\n");
            if (!string.IsNullOrEmpty(fields.CompanyName))
            {
                addressLine.Append($"{fields.CompanyName}\n");
            }
            addressLine.Append($"{fields.Address}\n");
            if (!string.IsNullOrEmpty(fields.Address2))
            {
                addressLine.Append($"{fields.Address2}\n");
            }

            addressLine.Append(GetCSZByTemplate(cszTemplate, fields.City, fields.State, fields.Zip));



            if (string.IsNullOrEmpty(countryInSettings) || !string.Equals(fields.Country, countryInSettings, StringComparison.InvariantCultureIgnoreCase))
            {
                addressLine.Append($"\n{fields.Country}\n");
            }
            return(addressLine.ToString());
        }
Ejemplo n.º 2
0
        public byte[] PdfPreview(PdfSettingDto setting, bool isBase64Encode = true, string currency = "$")
        {
            setting.Date = DateTime.Now;
            var             trans     = _transactionService.GetAnyPayment();
            LetterFieldsDto fields    = _letterService.GetLetterFields((int)trans.TransactionId, currency: currency);
            var             addresses = _addressService.GetAddressesByFamilyId(trans.FamilyId);

            MapAddressesForPdfSetting(setting, addresses.FirstOrDefault());

            //check if we have alresdy pdf template
            if ((string.IsNullOrEmpty(setting.Template) || string.IsNullOrEmpty(setting.SignatureImage)) && setting.PDFSettingID != null)
            {
                var templ = _letterService.GetPdfSetting((int)setting.PDFSettingID);
                if (string.IsNullOrEmpty(setting.Template))
                {
                    setting.Template = templ.Template;
                }
                if (string.IsNullOrEmpty(setting.SignatureImage))
                {
                    setting.SignatureImage = templ.SignatureImage;
                }
            }
            //PdfSettingDto setting = PreparePdfSetting(letter, department, addresses, transaction);
            var country  = _settingsProvider.GetSetting(Settings.DefaultCountry).Value;
            var response = _pdfTemplate.GetPdfPreview(setting, country, fields);

            if (isBase64Encode)
            {
                return(EncodeBase64(response));
            }
            return(response);
        }
Ejemplo n.º 3
0
 private void ParseXMLFields(ref LetterFieldsDto fields)
 {
     if (!string.IsNullOrEmpty(fields.Subcategory))
     {
         fields.Subcategory = SplitDetails(_xmlService.GetSubcategory(fields.Subcategory));
     }
     if (!string.IsNullOrEmpty(fields.Category))
     {
         fields.Category = SplitDetails(_xmlService.GetCategory(fields.Category));
     }
     if (!string.IsNullOrEmpty(fields.Subclass))
     {
         fields.Subclass = SplitDetails(_xmlService.GetSubclass(fields.Subclass));
     }
     if (!string.IsNullOrEmpty(fields.Class))
     {
         fields.Class = SplitDetails(_xmlService.GetClass(fields.Class));
     }
 }
Ejemplo n.º 4
0
        public LetterFieldsDto GetLetterFields(int transactionId, int?[] subCategoryIds = null, bool includeSubCats = true, string currency = "$")
        {
            AppSettingRecord defClasses = _settingsProvider.GetSetting(Settings.DefaultClasses);

            var select = QueryProvider.CreateQuery <SelectFieldsForLetterStoredProcedure>(_schema);

            select.TransactionId  = transactionId;
            select.ClassesOn      = Convert.ToBoolean(defClasses.Value);
            select.SubCategoryIds = subCategoryIds;
            select.SubCatInclude  = includeSubCats;

            LetterFieldsDto fields = select.Execute().FirstRow <LetterFieldsDto>();

            ParseXMLFields(ref fields);

            MakeFieldsInRegionalStandarts(ref fields, currency);

            return(fields);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// CreatePdf
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public byte[] PdfDoc(BatchLetterDto dto, bool isBase64Encode = true, string currency = "$")
        {
            LetterDto     letter      = null;
            DepartmentDto department  = null;
            var           transaction = _transactionService.GetPaymentById(dto.TransactionId);

            if (dto.LetterId != null)
            {
                transaction.LetterId = (short)dto.LetterId;
            }
            if (transaction.LetterId != null)
            {
                letter = _letterService.GetLetterById(transaction.LetterId.Value);
            }
            if (letter == null)
            {
                throw new Exception("Transaction don't contain letter");
            }
            LetterFieldsDto fields = _letterService.GetLetterFields(dto.TransactionId, currency: currency);

            if (!string.IsNullOrEmpty(letter.PDFLetterText))
            {
                letter.PDFLetterText = _templatesProvider.ReplaceFieldsTemplate(letter.PDFLetterText, fields);
            }
            if (letter.PDFSettingID == null)
            {
                department = _departmentService.GetDepartment(transaction.DepartmentId);
            }

            var addresses = _addressService.GetAddressesByFamilyId(transaction.FamilyId);

            PdfSettingDto setting  = PreparePdfSetting(letter, department, addresses, transaction, fields);
            var           country  = _settingsProvider.GetSetting(Settings.DefaultCountry).Value;
            var           response = _pdfTemplate.GetPdfFromTamplate(setting, country, fields);

            if (isBase64Encode)
            {
                return(EncodeBase64(response));
            }
            return(response);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Replace {{field placeholders}} with smart template
        /// </summary>
        /// <param name="html">Template letter that need to be parsed</param>
        /// <param name="fields">Data that will be include into text</param>
        /// <returns>Sring for sending</returns>
        public string ReplaceFieldsTemplate(string html, LetterFieldsDto fields, string country = null)
        {
            string smartString = html.Replace("{{", "{").Replace("}}", "}");

            if (smartString.Contains("{TransactionList}"))
            {
                smartString = smartString.Replace("{TransactionList}", "<<TransactionList>>");
            }
            if (smartString.Contains("{TotalAmount}"))
            {
                smartString = smartString.Replace("{TotalAmount}", "<<TotalAmount>>");
            }
            if (smartString.Contains("{AddressBlock}"))
            {
                smartString = FillAddressBlock(smartString, fields, country);
            }

            string resultString = SmartFormat.Smart.Format(smartString, fields);

            return(resultString);
        }
Ejemplo n.º 7
0
        private string FillAddressBlock(string smartString, LetterFieldsDto fields, string country = null)
        {
            StringBuilder addrBlock = new StringBuilder();

            addrBlock.Append(fields.Label);
            if (!string.IsNullOrEmpty(fields.CompanyName))
            {
                addrBlock.Append($"\n{fields.CompanyName}");
            }
            addrBlock.Append($"\n{fields.Address}");
            if (!string.IsNullOrEmpty(fields.Address2))
            {
                addrBlock.Append($"\n{fields.Address2}");
            }
            if (!string.IsNullOrEmpty(fields.City) || !string.IsNullOrEmpty(fields.State) ||
                string.IsNullOrEmpty(fields.Zip))
            {
                addrBlock.Append("\n");
            }
            if (!string.IsNullOrEmpty(fields.City))
            {
                addrBlock.Append($"{fields.City}, ");
            }
            if (!string.IsNullOrEmpty(fields.State))
            {
                addrBlock.Append($"{fields.State} ");
            }
            if (!string.IsNullOrEmpty(fields.Zip))
            {
                addrBlock.Append($"{fields.Zip} ");
            }
            if (!string.IsNullOrEmpty(fields.Country) && !string.IsNullOrEmpty(country) &&
                string.Equals(fields.Country, country, StringComparison.CurrentCultureIgnoreCase))
            {
                addrBlock.Append($"\n{fields.Country} ");
            }
            return(smartString.Replace("{AddressBlock}", addrBlock.ToString()));
        }
Ejemplo n.º 8
0
        private void MakeFieldsInRegionalStandarts(ref LetterFieldsDto fields, string currency)
        {
            var         timeHelper = new TimeHelper(_schema);
            CultureInfo culture    = Thread.CurrentThread.CurrentUICulture;
            DateTime    orgDate;
            DateTime    todayOrgDate = timeHelper.TryConvertLocalTimeToOrgTime(out orgDate) ? orgDate.Date : DateTime.Today.Date;
            JewishDate  jevishDate   = _hebrewDateService.ConvertToHebrewDate(todayOrgDate.Day, todayOrgDate.Month, todayOrgDate.Year, false);

            fields.TodayHebrewDate = jevishDate.GetDate();

            fields.DonationDate = fields.DonationDateTime.ToString(culture.DateTimeFormat.ShortDatePattern);
            //  fields.DonationLongDate = fields.DonationDateTime.ToString(culture.DateTimeFormat.LongDatePattern);
            fields.DonationLongDate = string.Equals(culture.Name, "en-US", StringComparison.InvariantCultureIgnoreCase) ? fields.DonationDateTime.ToString("MMMM d, yyyy")
                : fields.DonationDateTime.ToString(culture.DateTimeFormat.LongDatePattern);

            fields.TodayDate = todayOrgDate.ToString(culture.DateTimeFormat.ShortDatePattern);
            // fields.TodayLongDate = todayOrgDate.ToString(culture.DateTimeFormat.LongDatePattern);
            fields.TodayLongDate = string.Equals(culture.Name, "en-US", StringComparison.InvariantCultureIgnoreCase) ? todayOrgDate.ToString("MMMM d, yyyy")
                : todayOrgDate.ToString(culture.DateTimeFormat.LongDatePattern);
            // fields.DonationShortDate = fields.DonationDateTime.ToString(culture.DateTimeFormat.ShortDatePattern);

            //current in cms we use only dollars so this currency hardcoded
            fields.Amount = $"{currency}{fields.AmountDec}";
        }
        void FillFields(PdfDocument document, LetterFieldsDto fields, PdfSettingDto settings, string countryInSettings, bool isEndYear = false)
        {
            PdfAcroForm form = document.AcroForm;

            if (form == null || fields == null)
            {
                return;
            }
            var acroFields = form.Fields;
            var names      = acroFields.DescendantNames;

            if (!names.Any())
            {
                names = acroFields.Names;
            }


            foreach (string name in names)
            {
                var t    = form.Fields[name];
                var text = GetValueByName(name, fields, settings, countryInSettings);

                t.Value = new PdfString(text);
                ((PdfTextField)t).BackColor = XColor.FromKnownColor(XKnownColor.White);
                t.ReadOnly = true;
            }
            //Ensure the new values are displayed
            if (document.AcroForm.Elements.ContainsKey("/NeedAppearances") == false)
            {
                document.AcroForm.Elements.Add("/NeedAppearances", new PdfBoolean(true));
            }
            else
            {
                document.AcroForm.Elements["/NeedAppearances"] = new PdfBoolean(true);
            }
        }
Ejemplo n.º 10
0
        public PdfSettingDto PreparePdfSetting(LetterDto letter, DepartmentDto department, List <FamilyAddressDto> addresses, PaymentDto transaction, LetterFieldsDto fields)
        {
            PdfSettingDto setting = letter?.PDFSettingID == null ? department.PdfSettings : letter.PdfSettings;

            if (string.IsNullOrEmpty(letter.PDFLetterText))
            {
                throw new Exception("Letter doesn't contain pdf text");
            }
            setting.BodyText = letter.PDFLetterText;


            setting.Date = DateTime.Now;
            MapAddressesForPdfSetting(setting, addresses.FirstOrDefault(r => r.AddressId == transaction.AddressId));
            setting.Label = fields.Label;
            return(setting);
        }
Ejemplo n.º 11
0
        string GetValueByName(string name, LetterFieldsDto fields, PdfSettingDto settings, string countryInSettings)
        {
            switch (name)
            {
            case "Name":
                return(fields.Name);

            case "CompanyName":
                return(fields.CompanyName);

            case "Address":
                return(fields.Address);

            case "Address2":
                return(fields.Address2);

            case "City":
                return(fields.City);

            case "State":
                return(fields.State);

            case "Zip":
                return(fields.Zip);

            case "Country":
                return(fields.Country);

            case "NameAddress":
                return(GetAddress(fields, countryInSettings, settings.CSZ));

            case "CityStateZip":
                return(GetCSZByTemplate(settings.CSZ, fields.City, fields.State, fields.Zip));

            case "Amount":
                return(fields.Amount);

            case "GoodsAmount":
                //todo implement
                return("");

            case "GoodsDescription":
                //todo implement
                return("");

            case "TaxDeductibleAmount":
                //todo implement
                return("");

            case "TextAmount":
                //todo implement
                return("");

            case "HonorMemory":
                return(fields.HonorMemory);

            case "DonationDate":
                return(fields.DonationDate);

            case "DonationLongDate":
                return(fields.DonationLongDate);

            case "Method":
                return(fields.PaymentMethod);

            case "CheckNumber":
                return(fields.CheckNo);

            case "ReceiptNumber":
                return(fields.ReceiptNo.ToString());

            case "Category":
                return(fields.Category);

            case "Subcategory":
                return(fields.Subcategory);

            case "Purpose":
                return(fields.Subcategory);

            case "Solicitor":
                return(fields.Solicitor);

            case "Organization":
                return(fields.Department);

            case "TransactionNote":
                //todo implement
                return("");

            case "HebrewDate":
                return(fields.TodayHebrewDate);

            case "TodayDate":
                return(fields.TodayDate);

            case "TodayLongDate":
                return(fields.TodayLongDate);
            }

            return("");
        }
Ejemplo n.º 12
0
        private PdfDocument PrepareDocumentForEndYearBatch(PdfDocument document, PdfSettingDto settings, string countryInSettings, LetterFieldsDto fields, decimal totalAmount, List <EndYearTransactions> transactionList)
        {
            Document doc = new Document();
            //  PdfPage page = document.Pages[0];

            Section sec = doc.AddSection();

            sec.PageSetup.LeftMargin   = Unit.FromInch(settings.LeftMargin);
            sec.PageSetup.RightMargin  = Unit.FromInch(settings.RightMargin);
            sec.PageSetup.TopMargin    = Unit.FromInch(settings.TopMargin);
            sec.PageSetup.BottomMargin = Unit.FromInch(settings.BottomMargin);

            //date
            if (settings.ShowDate)
            {
                AddDate(sec, settings);
            }

            //address
            if (settings.ShowAddress)
            {
                AddAddress(sec, settings, countryInSettings);
            }

            // body
            AddEndYearBody(sec, settings, transactionList, totalAmount);

            //signature
            //if (settings.ShowSingnature)
            //    AddSignature(sec, settings);

            //fields
            //if (settings.HasReceiptStub)
            //    FillFields(document, fields, settings, countryInSettings, true);
            ConvertMigraDocToPdfSharp(ref document, doc);
            return(document);
        }
Ejemplo n.º 13
0
        PdfDocument PrepareDocument(PdfDocument document, PdfSettingDto settings, string countryInSettings, LetterFieldsDto fields, int pageNum = 0, bool isBase64 = false)
        {
            PdfPage   page = document.Pages[pageNum];
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            // HACK²
            gfx.MUH = PdfFontEncoding.Unicode;
            Document         doc         = new Document();
            Section          sec         = doc.AddSection();
            DocumentRenderer docRenderer = new DocumentRenderer(doc);

            sec.PageSetup.LeftMargin   = Unit.FromInch(settings.LeftMargin);
            sec.PageSetup.RightMargin  = Unit.FromInch(settings.RightMargin);
            sec.PageSetup.TopMargin    = Unit.FromInch(settings.TopMargin);
            sec.PageSetup.BottomMargin = Unit.FromInch(settings.BottomMargin);

            //date
            if (settings.ShowDate)
            {
                AddDate(sec, settings);
            }

            //address
            if (settings.ShowAddress)
            {
                AddAddress(sec, settings, countryInSettings);
            }

            // body
            AddBody(sec, settings);

            //signature
            if (settings.ShowSingnature)
            {
                AddSignature(sec, settings, isBase64);
            }

            //fields
            if (settings.HasReceiptStub)
            {
                FillFields(document, fields, settings, countryInSettings);
            }
            docRenderer.PrepareDocument();
            int pageCount = docRenderer.FormattedDocument.PageCount;

            for (int idx = 0; idx < pageCount; idx++)
            {
                docRenderer.RenderPage(gfx, idx + 1, PageRenderOptions.All);
            }

            gfx.Dispose();
            return(document);
        }
Ejemplo n.º 14
0
        public byte[] GetPdfPreview(PdfSettingDto settings, string countryInSettings, LetterFieldsDto fields)
        {
            PdfDocument document = PrepareDocument(CreateDocumentForPreview(settings, PdfDocumentOpenMode.Modify), settings, countryInSettings, fields, isBase64: true);


            using (MemoryStream ms = new MemoryStream())
            {
                document.Save(ms, false);
                byte[] buffer = new byte[ms.Length];
                ms.Seek(0, SeekOrigin.Begin);
                ms.Flush();
                ms.Read(buffer, 0, (int)ms.Length);
                ms.Close();
                return(buffer);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Save File end return path(use for batch letter
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="countryInSettings"></param>
        /// <param name="fields"></param>
        /// <param name="path">path for saving</param>
        /// <returns></returns>
        public string GetBatchPdfFromTamplate(PdfSettingDto settings, string countryInSettings, LetterFieldsDto fields, string path)
        {
            PdfDocument document = PrepareDocument(ReadOrCreateDocument(settings, PdfDocumentOpenMode.Modify), settings, countryInSettings, fields);

            document.Save(path);
            document.Dispose();
            return(path);
        }