Add tax_references, its controller and some basic pages for viewing ref data about taxes.

This commit is contained in:
2020-09-10 12:36:43 +01:00
parent 49d17e5850
commit 83ba256f9d
15 changed files with 142 additions and 4 deletions
@@ -0,0 +1,3 @@
// Place all the styles related to the TaxReferences controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
@@ -0,0 +1,10 @@
class TaxReferencesController < ApplicationController
def index
@tax_references = TaxReference.all
end
def show
@tax_references = TaxReference.all
@tax_reference = TaxReference.find_by(year: params[:year])
end
end
+2
View File
@@ -0,0 +1,2 @@
module TaxReferencesHelper
end
+17
View File
@@ -0,0 +1,17 @@
class TaxReference < ApplicationRecord
validates :year, uniqueness: true
MAX_MONTHLY_HOURS = 172
def worker_contribution(number_of_hours)
return self.hourly_wage * number_of_hours * self.worker_percentage / 100
end
def employer_contribution(number_of_hours)
return self.hourly_wage * number_of_hours * self.employer_percentage / 100
end
def total_contribution(number_of_hours)
return self.employer_contribution(number_of_hours) +
self.worker_contribution(number_of_hours)
end
end
+3 -3
View File
@@ -7,11 +7,11 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
<li class="nav-item">
<%= link_to(t('Home'), root_path, class: 'nav-link') %>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
<%= link_to(t('Tax References Tables'), tax_references_path, class: 'nav-link') %>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@@ -0,0 +1,13 @@
<ul class="nav nav-tabs" role="tablist">
<% tax_references.each do |tax_ref| %>
<li class="nav-item">
<% item_class = 'nav-link' %>
<% if not @tax_reference.nil? and tax_ref.year == @tax_reference.year %>
<% item_class.concat(' active') %>
<% end %>
<%= link_to tax_ref.year, {controller: 'tax_references', action: :show, year: tax_ref.year},
class: item_class %>
</li>
<% end %>
</ul>
+1
View File
@@ -0,0 +1 @@
<%= render 'top_list', tax_references: @tax_references %>
+28
View File
@@ -0,0 +1,28 @@
<%= render 'top_list', tax_references: @tax_references %>
<p><%= @tax_reference.year %></p>
<p><%= @tax_reference.hourly_wage %></p>
<p><%= number_to_percentage(@tax_reference.worker_percentage, precision: 2) %></p>
<p><%= number_to_percentage(@tax_reference.employer_percentage, precision: 2) %></p>
<table>
<thead>
<tr>
<th><%= t('Number of Hours') %></th>
<th><%= t('Employer (extra)') %></th>
<th><%= t('Worker (discount)') %></th>
<th><%= t('Total contribution') %></th>
</tr>
</thead>
<tbody>
<% hourly_contribution = @tax_reference.hourly_wage / 100 %>
<% (@tax_reference.min_monthly_hours..TaxReference::MAX_MONTHLY_HOURS).each do |n_hours| %>
<tr>
<td><%= n_hours %></td>
<td><%= number_to_currency(@tax_reference.employer_contribution(n_hours), locale: :pt) %></td>
<td><%= number_to_currency(@tax_reference.worker_contribution(n_hours), locale: :pt) %></td>
<td><%= number_to_currency(@tax_reference.total_contribution(n_hours), locale: :pt) %></td>
</tr>
<% end %>
</tbody>
</table>