Skip to content

Instantly share code, notes, and snippets.

@chrishutchinson
Created November 23, 2017 17:52
Show Gist options
  • Save chrishutchinson/71d8abd7aeeb2bbaa957754e5d3fdcf5 to your computer and use it in GitHub Desktop.
Save chrishutchinson/71d8abd7aeeb2bbaa957754e5d3fdcf5 to your computer and use it in GitHub Desktop.
// Polymer template code
<p>Your closest income band is {{results.income}}. Figures for a {{sheetLabel}}.</p>
<div class="row">
<div class="col">
<div class="label">Income change next year (2018/19)</div>
<div class="big income">{{results.change_2018}}</div>
</div>
</div>
<div class="row borderTop">
<div class="col">
<div class="label">Current net income (2017/18)</div>
<div class="big mid">{{results.total_income_2017}}</div>
<div class="label gill">after a {{results.tax_nic_bill_2017}} tax deduction</div>
</div>
<div class="col">
<div class="label">Net year's net income (2018/19)</div>
<div class="big mid">{{results.total_income_2018}}</div>
<div class="label gill">after a {{results.tax_nic_bill_2018}} tax deduction</div>
</div>
</div>
<div class="row borderBottom">
<div class="col">
<div class="label">Current child benefit (2017/18)</div>
<div class="big mid">{{results.child_benefit_2017}}</div>
</div>
<div class="col">
<div class="label">Next year's child benefit (2018/19)</div>
<div class="big mid">{{results.child_benefit_2018}}</div>
</div>
</div>
// Polymer JavaScript code
const rawIncomeBracketData = {
change_2018: 283,
change_2019: 0,
child_benefit_2017: 0,
child_benefit_2018: 0,
child_benefit_2019: 0,
income: 120000,
student_loan_repayment_2017: 9200,
student_loan_repayment_2018: 9150,
student_loan_repayment_2019: 9150,
tax_nic_bill_2017: 46620,
tax_nic_bill_2018: 46387,
tax_nic_bill_2019: 46387,
total_income_2017: 64180,
total_income_2018: 64463,
total_income_2019: 64463,
universal_credit_2017: 0,
universal_credit_2018: 0,
universal_credit_2019: 0
};
this.results = Object.keys(rawIncomeBracketData)
.reduce((acc, key) => {
const value = rawIncomeBracketData[key];
let prefix = '';
switch(key) {
case 'change_2018':
prefix = value < 0 ? '-' : '+';
break;
}
return Object.assign(acc, {
[key]: `${prefix}£${Math.abs(value).toLocaleString()}`
});
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment