Skip to content
Snippets Groups Projects
Commit 6a6cf894 authored by pabois's avatar pabois
Browse files

close #198

parent c751152c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......
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
......@@ -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 %>
......
......@@ -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'),
......
......@@ -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>
......
......@@ -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
......
......@@ -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é
......
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
......@@ -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|
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment