Add tax_references, its controller and some basic pages for viewing ref data about taxes.
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1,2 @@
|
||||
module TaxReferencesHelper
|
||||
end
|
||||
@@ -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
|
||||
@@ -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>
|
||||
@@ -0,0 +1 @@
|
||||
<%= render 'top_list', tax_references: @tax_references %>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,10 @@
|
||||
pt:
|
||||
hello: "Olá Mundo"
|
||||
number:
|
||||
currency:
|
||||
format:
|
||||
unit: '€'
|
||||
delimiter: ','
|
||||
separator: '.'
|
||||
precision: 2
|
||||
format: '%u%n'
|
||||
@@ -1,6 +1,8 @@
|
||||
Rails.application.routes.draw do
|
||||
devise_for :users
|
||||
get 'pages/home'
|
||||
get '/tax_references', to: 'tax_references#index'
|
||||
get '/tax_references/:year', to: 'tax_references#show'
|
||||
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
|
||||
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class CreateTaxReferences < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :tax_references do |t|
|
||||
t.integer :year
|
||||
t.float :hourly_wage
|
||||
t.integer :min_monthly_hours
|
||||
t.float :worker_percentage
|
||||
t.float :employer_percentage
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
+11
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_08_19_085432) do
|
||||
ActiveRecord::Schema.define(version: 2020_09_09_112404) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -41,6 +41,16 @@ ActiveRecord::Schema.define(version: 2020_08_19_085432) do
|
||||
t.index ["unlock_token"], name: "index_admins_on_unlock_token", unique: true
|
||||
end
|
||||
|
||||
create_table "tax_references", force: :cascade do |t|
|
||||
t.integer "year"
|
||||
t.float "hourly_wage"
|
||||
t.integer "min_monthly_hours"
|
||||
t.float "worker_percentage"
|
||||
t.float "employer_percentage"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TaxReferencesControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
year: 1
|
||||
hourly_wage: 1.5
|
||||
min_monthly_hours: 1
|
||||
worker_percentage: 1.5
|
||||
employer_percentage: 1.5
|
||||
|
||||
two:
|
||||
year: 1
|
||||
hourly_wage: 1.5
|
||||
min_monthly_hours: 1
|
||||
worker_percentage: 1.5
|
||||
employer_percentage: 1.5
|
||||
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TaxReferenceTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user