[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>
+
+</p>
+<table width="100%" cellspacing="0" cellpadding="0" valign="top">
+ <tr>
+ <td width="60%">
+ Prepared for:<br>
+ Group Name:
{{CorpNameAbbrev50}}<br>
+ {{#Composite}}
+ Composite Illustration
+ {{/Composite}}
+ {{^Composite}}
+ Insured:
{{Insured1Abbrev50}}
+ {{/Composite}}
+ <br>
+ Age: {{Age}}<br>
+ Product: {{PolicyForm}} {{PolicyMktgName}}<br>
+ {{#ModifiedSinglePremium}}
+ Modified Single Premium Adjustable Life Insurance Policy
+ {{/ModifiedSinglePremium}}
+ {{^ModifiedSinglePremium}}
+ {{PolicyLegalName}}
+ {{/ModifiedSinglePremium}}
+ <br>
+
+ {{^IsInforce}}
+ {{^SinglePremium}}
+ Initial Premium:
+ {{/SinglePremium}}
+ {{#SinglePremium}}
+ Single Premium:
+ {{/SinglePremium}}
+ ${{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>
- [lmi-commits] [lmi] master 08559c3 121/156: Factor out base_suffix() and ir_suffix() functions, (continued)
- [lmi-commits] [lmi] master 08559c3 121/156: Factor out base_suffix() and ir_suffix() functions, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 36c84ce 123/156: Add another individual private placement illustration page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 0ecc8ec 036/156: Add support for partials to our ad hoc Mustache parser, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 6f09722 107/156: Add missing words to the narrative summary continuation page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 6510601 150/156: Rename a mute variable to avoid gcc -Wshadow warning, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 048ae05 093/156: Start NASD PDF illustration class implementation, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 5ea5c86 101/156: Simplify and correct current PDF DC font handling, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master ec490eb 153/156: Revise and extend some comments in PDF generation code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 38cab5e 096/156: Make footer template depend on illustration kind, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master d1204c2 111/156: Factor out common parts of render_or_measure_fixed_page_part(), Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master e388f6e 037/156: Add beginning of numeric summary page using an external template,
Greg Chicares <=
- [lmi-commits] [lmi] master 531699b 115/156: Factor out common page_with_basic_tabular_report class, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master a85943b 124/156: Add the rest of individual private placement illustration pages, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master f0b9cea 113/156: Add "Assumption Detail" page to NASD illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 031070b 132/156: Implement supplemental report page for the regular illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 9fe1d07 125/156: Implement page-specific footer for "Tabular Details" pages, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 4f3a02e 078/156: Add company logo to the cover page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 2d93248 118/156: Add the rest of group private placement illustration pages, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 1272ce2 127/156: Don't include "Assumptions" page in composite NASD illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master e00ab7d 080/156: Hide "attained age" column for composite illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 29e63d6 117/156: Add basic illustration page of group placement illustration, Greg Chicares, 2018/01/30