lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Example of using the current PDF generation approach


From: Vadim Zeitlin
Subject: [lmi] Example of using the current PDF generation approach
Date: Sat, 22 Jul 2017 23:37:05 +0200

 Hello,

 Sorry for yet another delay, I still haven't managed to make the code
using the external templates approach to work, so for now I'd like to at
least show to you how does the current code work, so that you could ask any
questions you might have about it while I continue working on the
alternative version.

 So here is a simple but representative example: consider the "Column
Headings and Key Terms Used in This Illustration" page. Here is the
(condensed for clarity, all ellipses are actually present in the real code)
code generating it currently:

---------------------------------- >8 --------------------------------------
class columns_headings_page : public numbered_page
{
  public:
    void render
        (Ledger const& ledger
        ,pdf_writer_wx& writer
        ,wxDC& dc
        ,html_interpolator const& interpolate_html
        ) override
    {
        numbered_page::render(ledger, writer, dc, interpolate_html);

        text page_html = tag::p[attr::align("center")]
            (text::from("Column Headings and Key Terms Used in This 
Illustration")
            );

        auto const add_term_paragraph = [=]
            (std::string const& term
            ,std::string const& definition
            ) -> text
            {
                return tag::p
                    (tag::b
                        (interpolate_html(term)
                        )
                    )
                    (interpolate_html(definition)
                    )
                    ;
            };

        text terms_html;
        terms_html += add_term_paragraph
            ("{{AvName}} Value:"
            ,R"(
The accumulation at interest of the net premiums paid,
{{^SinglePremium}}
less any withdrawals,
{{/SinglePremium}}
less any monthly charges deducted.
)"
            );

        terms_html += add_term_paragraph
            ("{{CsvName}} Value:"
            ,R"(
{{AvName}} Value less policy debt.
{{#Has1035ExchCharge}}
{{CashSurrValueFootnote}}
{{/Has1035ExchCharge}}
)"
            );

        if(!interpolate_html.test_variable("IsInforce"))
            {
            terms_html += add_term_paragraph
                ("Current Illustrated Crediting Rate:"
                ,"{{CreditingRateFootnote}}"
                );
            }

        ... some not interesting paragraphs snipped ...

            if(!interpolate_html.test_variable("GroupExperienceRating"))
                {
                terms_html += add_term_paragraph
                    ("Death Benefit Option 2:"
                    ,"..."
                    );

                if(interpolate_html.test_variable("Has1035ExchCharge"))
                    {
                    terms_html += add_term_paragraph
                        ("Exchange Charge:"
                        ,"{{ExchangeChargeFootnote1}}"
                        );
                    }
                }
                else
                {
                terms_html += add_term_paragraph
                    ("Experience Rating Risk Charge:"
                    ,"..."
                    );
                }

        ... more not very interesting paragraphs snipped ...

        if(  interpolate_html.test_variable("ModifiedSinglePremium")
          || interpolate_html.test_variable("ModifiedSinglePremium0")
          )
            {
            terms_html += add_term_paragraph
                ("Modified Single Premium:"
                ,"..."
                );
            }

        ... and more ...

        if(interpolate_html.test_variable("SinglePremium"))
            {
            if(  interpolate_html.test_variable("ModifiedSinglePremium")
              || interpolate_html.test_variable("ModifiedSinglePremium0")
              )
                {
                terms_html += add_term_paragraph
                    ("Single Premium:"
                    ,"..."
                    );
                }

            terms_html += add_term_paragraph
                ("Ultimate Illustrated Crediting Rate:"
                ,"{{UltCreditingRateFootnote}}"
                );
            }

        page_html += tag::font[attr::size("-1")](terms_html);

        writer.output_html
            (writer.get_horz_margin()
            ,writer.get_vert_margin()
            ,writer.get_page_width()
            ,page_html
            );
    }
};
---------------------------------- >8 --------------------------------------

 This generates almost exactly the same page as the current XSL-based code.

 I also hope that the code is sufficiently clear. Of course, it uses plenty
of things not defined in it, like "html::tag" namespace helpers (there is a
"using namespace html" directive in scope here) and "html_interpolator"
class (which is 99%-based on the old ledger_xml_io.cpp code, except that it
now expands {{Variables}} in the text passed to it instead of stashing the
values of all these variables in an XML file from which they're later
retrieved by XSLT). But, again, hopefully it's straightforward enough to be
understandable.

 I'll end this email here to not mix everything together and will second
another email with the discussion of the (not implemented yet) approach
based on external templates soon. Please let me know if you have any
questions about this approach or would like me to provide more details
about anything in this thread.

 Thanks,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]