diff --git a/app/controllers/server/universities_controller.rb b/app/controllers/server/universities_controller.rb index 5dd42f655ab2851bc0271d2645a5cd4359ceb324..dd43e821ac5100a5926c4d48dba949fee9a7b2e4 100644 --- a/app/controllers/server/universities_controller.rb +++ b/app/controllers/server/universities_controller.rb @@ -2,6 +2,7 @@ class Server::UniversitiesController < Server::ApplicationController load_and_authorize_resource def index + @universities = @universities.ordered breadcrumb end @@ -58,6 +59,6 @@ class Server::UniversitiesController < Server::ApplicationController end def university_params - params.require(:university).permit(:name, :address, :zipcode, :city, :country, :private, :identifier, :logo, :logo_delete, :sms_sender_name) + params.require(:university).permit(:name, :address, :zipcode, :city, :country, :private, :identifier, :logo, :logo_delete, :sms_sender_name, :invoice_date, :invoice_amount) end end diff --git a/app/models/university.rb b/app/models/university.rb index ee253140ad440344540c748a57f844bb2b1fed6f..7e65310db3239a3b41c53aa39e27fc16439b2a1e 100644 --- a/app/models/university.rb +++ b/app/models/university.rb @@ -7,6 +7,9 @@ # city :string # country :string # identifier :string +# invoice_amount :string +# invoice_date :date +# invoice_date_yday :integer # mail_from_address :string # mail_from_name :string # name :string @@ -21,6 +24,7 @@ class University < ApplicationRecord include WithCommunication include WithEducation include WithIdentifier + include WithInvoice include WithResearch include WithUsers diff --git a/app/models/university/with_invoice.rb b/app/models/university/with_invoice.rb new file mode 100644 index 0000000000000000000000000000000000000000..7c9c43ecbecc5264f5558485e2e78ebd05f7225f --- /dev/null +++ b/app/models/university/with_invoice.rb @@ -0,0 +1,32 @@ +module University::WithInvoice + extend ActiveSupport::Concern + + included do + + before_save :denormalize_invoice_date + + scope :invoiced, -> { where.not(invoice_amount: nil) } + + def invoice_proximity + if next_invoice_in_days < 30 + 'danger' + elsif next_invoice_in_days < 60 + 'warning' + end + end + + private + + def denormalize_invoice_date + self.invoice_date_yday = self.invoice_date.nil? ? nil : self.invoice_date.yday + end + + def next_invoice_in_days + return 999999 if invoice_date_yday.nil? + # ignores bisextil year but... who cares? + today = Time.now.yday + today < invoice_date_yday ? invoice_date_yday - today : invoice_date_yday + 365 - today + end + + end +end diff --git a/app/views/server/universities/_form.html.erb b/app/views/server/universities/_form.html.erb index 7b868882daade69dd4fb7bdcc5fc6a5788fa4401..f24ed12e03132d332dd2a62e435d93637a446412 100644 --- a/app/views/server/universities/_form.html.erb +++ b/app/views/server/universities/_form.html.erb @@ -26,6 +26,15 @@ direct_upload: true %> </div> </div> + <h3 class="mt-5">Invoice informations</h3> + <div class="row"> + <div class="col-md-4"> + <%= f.input :invoice_date %> + </div> + <div class="col-md-4"> + <%= f.input :invoice_amount %> + </div> + </div> <% content_for :action_bar_right do %> <%= submit f %> <% end %> diff --git a/app/views/server/universities/index.html.erb b/app/views/server/universities/index.html.erb index 75b999cfd6fa726bcdaac2ce53ce56a4245c2c33..0c266778609d1ea9eaf1c654fe23ec78afee0e52 100644 --- a/app/views/server/universities/index.html.erb +++ b/app/views/server/universities/index.html.erb @@ -6,6 +6,8 @@ <th><%= University.human_attribute_name('name') %></th> <th><%= University.human_attribute_name('url') %></th> <th><%= University.human_attribute_name('public_or_private') %></th> + <th><%= University.human_attribute_name('invoice_date') %></th> + <th><%= University.human_attribute_name('invoice_amount') %></th> <th></th> </tr> </thead> @@ -15,6 +17,13 @@ <td><%= link_to university, [:server, university] %></td> <td><%= link_to university.url, university.url, target: :_blank %></td> <td><%= university.private ? University.human_attribute_name('private') : University.human_attribute_name('public') %></td> + <% if university.invoice_amount.blank? %> + <td></td> + <td></td> + <% else %> + <td class="<%= university.invoice_proximity.blank? ? '' : "table-#{university.invoice_proximity}" %>"><%= l university.invoice_date, format: "%d %B" unless university.invoice_amount.blank? %></td> + <td class="<%= university.invoice_proximity.blank? ? '' : "table-#{university.invoice_proximity}" %>"><%= university.invoice_amount %></td> + <% end %> <td class="text-end"> <div class="btn-group" role="group"> <%= link_to t('edit'), diff --git a/app/views/server/universities/show.html.erb b/app/views/server/universities/show.html.erb index 1d9729c719a69e8c268e6dfb2c65b7cda0f69cf8..169a94c32b22bbfcb27a4b84aef7415816e5cabc 100644 --- a/app/views/server/universities/show.html.erb +++ b/app/views/server/universities/show.html.erb @@ -17,6 +17,16 @@ <td class="text-end"><%= @university.public_send variable %></td> </tr> <% end %> + <% unless @university.invoice_amount.blank? %> + <tr class="<%= @university.invoice_proximity.blank? ? '' : "table-#{@university.invoice_proximity}" %>"> + <td><%= t('activerecord.attributes.university.invoice_date') %></td> + <td class="text-end"><%= l @university.invoice_date, format: "%d %B" %></td> + </tr> + <tr class="<%= @university.invoice_proximity.blank? ? '' : "table-#{@university.invoice_proximity}" %>"> + <td><%= t('activerecord.attributes.university.invoice_amount') %></td> + <td class="text-end"><%= @university.invoice_amount %>€</td> + </tr> + <% end %> </table> </div> </div> diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml index a61d7c28445f599bd055c48ecb1e19b8865633ef..904b123daaab19ac61a0d5ecca7af14096fe6783 100644 --- a/config/locales/university/en.yml +++ b/config/locales/university/en.yml @@ -6,6 +6,8 @@ en: city: City country: Country identifier: Identifier + invoice_amount: Invoice amount + invoice_date: Invoice date logo: Logo name: Name private: Private diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml index 35473c389505724f1cd0feef41b05438961c5ac3..d9642ab439dde585c11edce432983fb514e567ac 100644 --- a/config/locales/university/fr.yml +++ b/config/locales/university/fr.yml @@ -6,6 +6,8 @@ fr: city: Ville country: Pays identifier: Identifiant + invoice_amount: Montant de facturation + invoice_date: Date de facturation logo: Logo name: Nom private: Etablissement privé diff --git a/db/migrate/20220224144107_add_invoice_elements_to_university.rb b/db/migrate/20220224144107_add_invoice_elements_to_university.rb new file mode 100644 index 0000000000000000000000000000000000000000..7ad199533d6176c11ec5fb330fbc164fcf45c111 --- /dev/null +++ b/db/migrate/20220224144107_add_invoice_elements_to_university.rb @@ -0,0 +1,7 @@ +class AddInvoiceElementsToUniversity < ActiveRecord::Migration[6.1] + def change + add_column :universities, :invoice_date, :date + add_column :universities, :invoice_date_yday, :integer + add_column :universities, :invoice_amount, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 544615fe4ec72e96e8ac2abc5d35ce44f6277ad3..51b023ae3fb403a78aa62d9b93b681df8f841f8e 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: 2022_02_24_140838) do +ActiveRecord::Schema.define(version: 2022_02_24_144107) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -558,6 +558,9 @@ ActiveRecord::Schema.define(version: 2022_02_24_140838) do t.string "mail_from_name" t.string "mail_from_address" t.string "sms_sender_name" + t.date "invoice_date" + t.integer "invoice_date_yday" + t.string "invoice_amount" end create_table "university_people", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| diff --git a/test/fixtures/universities.yml b/test/fixtures/universities.yml index 34655ffa67d9a34e443bc257df8af07ac9443ed9..0ce6f928742f8a5b7dd79ffe5a22572c0390e63d 100644 --- a/test/fixtures/universities.yml +++ b/test/fixtures/universities.yml @@ -7,6 +7,9 @@ # city :string # country :string # identifier :string +# invoice_amount :string +# invoice_date :date +# invoice_date_yday :integer # mail_from_address :string # mail_from_name :string # name :string