lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master e388f6e 037/156: Add beginning of numeric sum


From: Greg Chicares
Subject: [lmi-commits] [lmi] master e388f6e 037/156: Add beginning of numeric summary page using an external template
Date: Tue, 30 Jan 2018 17:22:04 -0500 (EST)

branch: master
commit e388f6e52fa3df2a2e1d0fa83ca2346c4806ebf7
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>

    Add beginning of numeric summary page using an external template
    
    Switch to using external templates instead of generating page contents
    from C++ code.
    
    This requires defining some extra artificial variables, as external
    templates can't contain any logic, but significantly increases
    flexibility.
---
 header.mustache             | 105 ++++++++++++++++++++++++++++++++++++++++++++
 ledger_pdf_generator_wx.cpp |  62 +++++++++++++++++++++++++-
 numeric_summary.mustache    |   3 ++
 3 files changed, 168 insertions(+), 2 deletions(-)

diff --git a/header.mustache b/header.mustache
new file mode 100644
index 0000000..4ec8747
--- /dev/null
+++ b/header.mustache
@@ -0,0 +1,105 @@
+<font size=-1>
+<p align="center">
+    {{#IsInforce}}
+        LIFE INSURANCE IN FORCE BASIC ILLUSTRATION
+    {{/IsInforce}}
+    {{^IsInforce}}
+        LIFE INSURANCE BASIC ILLUSTRATION
+    {{/IsInforce}}
+
+    <br>{{InsCoName}}
+    <br>Presented by: {{ProducerName}}
+    <br>{{ProducerStreet}}
+    {{#HasProducerCity}}
+        <br>{{ProducerCity}}
+    {{/HasProducerCity}}
+</p>
+<p>
+    &nbsp;
+</p>
+<table width="100%" cellspacing="0" cellpadding="0" valign="top">
+    <tr>
+        <td width="60%">
+            Prepared for:<br>
+            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Group Name: 
{{CorpNameAbbrev50}}<br>
+            {{#Composite}}
+                Composite Illustration
+            {{/Composite}}
+            {{^Composite}}
+                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insured: 
{{Insured1Abbrev50}}
+            {{/Composite}}
+            <br>
+            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Age: {{Age}}<br>
+            Product: {{PolicyForm}}&nbsp;{{PolicyMktgName}}<br>
+            {{#ModifiedSinglePremium}}
+                Modified Single Premium Adjustable Life Insurance Policy
+            {{/ModifiedSinglePremium}}
+            {{^ModifiedSinglePremium}}
+                {{PolicyLegalName}}
+            {{/ModifiedSinglePremium}}
+            <br>
+
+            {{^IsInforce}}
+                {{^SinglePremium}}
+                    Initial Premium:
+                {{/SinglePremium}}
+                {{#SinglePremium}}
+                    Single Premium:
+                {{/SinglePremium}}
+                &nbsp;${{InitPrem}}
+            {{/IsInforce}}
+            <br>
+
+            {{^Composite}}
+                Initial Death Benefit Option: {{InitDBOpt}}
+            {{/Composite}}
+        </td>
+        <td width="40%">
+            Initial {{#HasTerm}}Total{{/HasTerm}}
+            Selected Face Amount: ${{InitTotalSA}}<br>
+
+            {{#HasTerm}}
+                Initial Base Face Amount: ${{InitBaseSpecAmt}}<br>
+                Initial Term Face Amount: ${{InitTermSpecAmt}}<br>
+            {{/HasTerm}}
+
+            Guaranteed Crediting Rate: {{InitAnnGenAcctInt_Guaranteed}}<br>
+
+            Current Illustrated Crediting Rate:
+            {{#InforceYear}}
+                {{UltimateInterestRate}}
+            {{/InforceYear}}
+            {{^InforceYear}}
+                {{InitAnnGenAcctInt_Current}}
+            {{/InforceYear}}
+            <br>
+
+            {{#SinglePremium}}
+                {{#InforceYearLE4}}
+                    Ultimate Illustrated Crediting Rate:
+                    {{#ModifiedSinglePremium0}}
+                        {{AnnGAIntRate_Current[11]}}
+                    {{/ModifiedSinglePremium0}}
+                    {{^ModifiedSinglePremium0}}
+                        {{AnnGAIntRate_Current[6]}}
+                    {{/ModifiedSinglePremium0}}
+                    <br>
+                {{/InforceYearLE4}}
+            {{/SinglePremium}}
+
+            {{^Composite}}
+                Underwriting Type:
+                {{#UWTypeIsMedical}}
+                    Fully underwritten
+                {{/UWTypeIsMedical}}
+                {{^UWTypeIsMedical}}
+                    {{UWType}}
+                {{/UWTypeIsMedical}}
+                <br>
+            {{/Composite}}
+
+            Rate Classification: {{UWClass}}, {{Smoker}}, {{Gender}}<br>
+        </td>
+    </tr>
+</table>
+</font>
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index d258771..bb4ce0d 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -29,6 +29,7 @@
 #include "force_linking.hpp"
 #include "html.hpp"
 #include "interpolate_string.hpp"
+#include "istream_to_string.hpp"
 #include "ledger.hpp"
 #include "ledger_evaluator.hpp"
 #include "ledger_invariant.hpp"
@@ -40,6 +41,7 @@
 #include <wx/pdfdc.h>
 
 #include <cstdint>                      // SIZE_MAX
+#include <fstream>
 #include <map>
 #include <memory>
 #include <sstream>
@@ -91,9 +93,22 @@ class html_interpolator
         return text::from_html
             (interpolate_string
                 (s
-                ,[this](std::string const& s, interpolate_lookup_kind)
+                ,[this]
+                    (std::string const& s
+                    ,interpolate_lookup_kind kind
+                    ) -> std::string
                     {
-                    return expand_html(s).as_html();
+                    switch(kind)
+                        {
+                        case interpolate_lookup_kind::variable:
+                        case interpolate_lookup_kind::section:
+                            return expand_html(s).as_html();
+
+                        case interpolate_lookup_kind::partial:
+                            return load_partial_from_file(s);
+                        }
+
+                    throw std::runtime_error("invalid lookup kind");
                     }
                 )
             );
@@ -198,6 +213,23 @@ class html_interpolator
         return text::from(evaluator_(s));
     }
 
+    std::string load_partial_from_file(std::string const& file) const
+    {
+        std::ifstream ifs(file + ".mustache");
+        if(!ifs)
+            {
+            alarum()
+                << "Template file \""
+                << file
+                << ".mustache\" not found."
+                << std::flush
+                ;
+            }
+        std::string partial;
+        istream_to_string(ifs, partial);
+        return partial;
+    }
+
     // Object used for variables expansion.
     ledger_evaluator const evaluator_;
 
@@ -1691,6 +1723,26 @@ from lapsing, or payment required to reinstate the 
policy.
     }
 };
 
+class numeric_summary_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);
+
+        writer.output_html
+            (writer.get_horz_margin()
+            ,writer.get_vert_margin()
+            ,writer.get_page_width()
+            ,interpolate_html("{{>numeric_summary}}")
+            );
+    }
+};
 
 // Regular illustration.
 class pdf_illustration_regular : public pdf_illustration
@@ -1750,6 +1802,11 @@ class pdf_illustration_regular : public pdf_illustration
             }
 
         add_variable
+            ("HasProducerCity"
+            ,invar.ProducerCity != "0"
+            );
+
+        add_variable
             ("HasGuarPrem"
             ,invar.GuarPrem != 0
             );
@@ -1789,6 +1846,7 @@ class pdf_illustration_regular : public pdf_illustration
         add<narrative_summary_page>();
         add<narrative_summary_cont_page>();
         add<columns_headings_page>();
+        add<numeric_summary_page>();
     }
 };
 
diff --git a/numeric_summary.mustache b/numeric_summary.mustache
new file mode 100644
index 0000000..275a3ea
--- /dev/null
+++ b/numeric_summary.mustache
@@ -0,0 +1,3 @@
+{{>header}}
+
+<p align="center">Numeric Summary</p>



reply via email to

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