diff --git a/app/assets/stylesheets/tax_references.scss b/app/assets/stylesheets/tax_references.scss
new file mode 100644
index 0000000..7830c92
--- /dev/null
+++ b/app/assets/stylesheets/tax_references.scss
@@ -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/
diff --git a/app/controllers/tax_references_controller.rb b/app/controllers/tax_references_controller.rb
new file mode 100644
index 0000000..9b089f1
--- /dev/null
+++ b/app/controllers/tax_references_controller.rb
@@ -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
diff --git a/app/helpers/tax_references_helper.rb b/app/helpers/tax_references_helper.rb
new file mode 100644
index 0000000..49539e9
--- /dev/null
+++ b/app/helpers/tax_references_helper.rb
@@ -0,0 +1,2 @@
+module TaxReferencesHelper
+end
diff --git a/app/models/tax_reference.rb b/app/models/tax_reference.rb
new file mode 100644
index 0000000..984aeff
--- /dev/null
+++ b/app/models/tax_reference.rb
@@ -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
diff --git a/app/views/layouts/_top_navigation.html.erb b/app/views/layouts/_top_navigation.html.erb
index 466c4af..6b0ef44 100644
--- a/app/views/layouts/_top_navigation.html.erb
+++ b/app/views/layouts/_top_navigation.html.erb
@@ -7,11 +7,11 @@
- -
- Home (current)
+
-
+ <%= link_to(t('Home'), root_path, class: 'nav-link') %>
-
- Link
+ <%= link_to(t('Tax References Tables'), tax_references_path, class: 'nav-link') %>
-
diff --git a/app/views/tax_references/_top_list.html.erb b/app/views/tax_references/_top_list.html.erb
new file mode 100644
index 0000000..d04ddc7
--- /dev/null
+++ b/app/views/tax_references/_top_list.html.erb
@@ -0,0 +1,13 @@
+
+ <% tax_references.each do |tax_ref| %>
+ -
+ <% 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 %>
+
+ <% end %>
+
\ No newline at end of file
diff --git a/app/views/tax_references/index.html.erb b/app/views/tax_references/index.html.erb
new file mode 100644
index 0000000..50ffb9e
--- /dev/null
+++ b/app/views/tax_references/index.html.erb
@@ -0,0 +1 @@
+<%= render 'top_list', tax_references: @tax_references %>
diff --git a/app/views/tax_references/show.html.erb b/app/views/tax_references/show.html.erb
new file mode 100644
index 0000000..235b504
--- /dev/null
+++ b/app/views/tax_references/show.html.erb
@@ -0,0 +1,28 @@
+<%= render 'top_list', tax_references: @tax_references %>
+
+<%= @tax_reference.year %>
+<%= @tax_reference.hourly_wage %>
+<%= number_to_percentage(@tax_reference.worker_percentage, precision: 2) %>
+<%= number_to_percentage(@tax_reference.employer_percentage, precision: 2) %>
+
+
+
+
+ | <%= t('Number of Hours') %> |
+ <%= t('Employer (extra)') %> |
+ <%= t('Worker (discount)') %> |
+ <%= t('Total contribution') %> |
+
+
+
+ <% hourly_contribution = @tax_reference.hourly_wage / 100 %>
+ <% (@tax_reference.min_monthly_hours..TaxReference::MAX_MONTHLY_HOURS).each do |n_hours| %>
+
+ | <%= n_hours %> |
+ <%= number_to_currency(@tax_reference.employer_contribution(n_hours), locale: :pt) %> |
+ <%= number_to_currency(@tax_reference.worker_contribution(n_hours), locale: :pt) %> |
+ <%= number_to_currency(@tax_reference.total_contribution(n_hours), locale: :pt) %> |
+
+ <% end %>
+
+
\ No newline at end of file
diff --git a/config/locales/pt.yml b/config/locales/pt.yml
new file mode 100644
index 0000000..c7e7453
--- /dev/null
+++ b/config/locales/pt.yml
@@ -0,0 +1,10 @@
+pt:
+ hello: "Olá Mundo"
+ number:
+ currency:
+ format:
+ unit: '€'
+ delimiter: ','
+ separator: '.'
+ precision: 2
+ format: '%u%n'
diff --git a/config/routes.rb b/config/routes.rb
index 3e7ab1b..092c8ba 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/db/migrate/20200909112404_create_tax_references.rb b/db/migrate/20200909112404_create_tax_references.rb
new file mode 100644
index 0000000..e230e5e
--- /dev/null
+++ b/db/migrate/20200909112404_create_tax_references.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index 17d170c..13e5e7a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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
diff --git a/test/controllers/tax_references_controller_test.rb b/test/controllers/tax_references_controller_test.rb
new file mode 100644
index 0000000..f23e04d
--- /dev/null
+++ b/test/controllers/tax_references_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class TaxReferencesControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/fixtures/tax_references.yml b/test/fixtures/tax_references.yml
new file mode 100644
index 0000000..47714db
--- /dev/null
+++ b/test/fixtures/tax_references.yml
@@ -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
diff --git a/test/models/tax_reference_test.rb b/test/models/tax_reference_test.rb
new file mode 100644
index 0000000..54f3974
--- /dev/null
+++ b/test/models/tax_reference_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class TaxReferenceTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end