params[:date] ||= Date.today
- @absences = current_user.organisation.absences
- @structures = current_user.organisation.structures
- @classrooms = current_user.organisation.classrooms
+ organisation = current_user.organisation
+ @absences = organisation.absences
+ @structures = organisation.structures
+ @classrooms = organisation.classrooms
unless params[:structure_id].blank?
@absences = @absences.joins(enfant: [:compte]).where(comptes: { structure_id: params[:structure_id] })
class FacturesController < ApplicationController
before_action :set_facture, only: [:show, :edit, :update, :destroy]
+ helper_method :sort_column, :sort_direction
# GET /factures
# GET /factures.json
def index
authorize Facture
- @factures = current_user.organisation.factures
- @structures = current_user.organisation.structures
+ organisation = current_user.organisation
+ @factures = organisation.factures
+ @structures = organisation.structures
unless params[:structure_id].blank?
@factures = @factures.joins(:compte).where(comptes: { structure_id: params[:structure_id] })
end
unless params[:search].blank?
- @factures = @factures.joins(:compte).where("UPPER(comptes.nom) like ? OR factures.réf like ?", "%#{params[:search].upcase}%", "%#{params[:search].upcase}%")
+ @factures = @factures.joins(:compte).where("comptes.nom ILIKE ? OR factures.réf ILIKE ?", "%#{params[:search].upcase}%", "%#{params[:search].upcase}%")
end
+ # Appliquer le tri
+ @factures = @factures.reorder(Arel.sql("#{sort_column} #{sort_direction}"))
+
@factures = @factures.paginate(page: params[:page])
respond_to do |format|
params.require(:facture).permit(:compte_id, :réf, :date, :échéance, :envoyée_le, :montant, :vérifiée, :mémo,
facture_lignes_attributes: [:id, :facture_id, :prestation_type_id, :intitulé, :qté, :prix, :total ,:_destroy])
end
+
+ def sortable_columns
+ %w{factures.réf factures.date comptes.nom factures.envoyée_le factures.montant factures.vérifiée factures.mémo}
+ end
+
+ def sort_column
+ sortable_columns.include?(params[:column]) ? params[:column] : 'factures.id'
+ end
+
+ def sort_direction
+ %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
+ end
+
end
class PrestationsController < ApplicationController
before_action :set_prestation, only: [:show, :edit, :update, :destroy]
-
+ helper_method :sort_column, :sort_direction
def index
authorize Prestation
- @structures = current_user.organisation.structures
- @classrooms = current_user.organisation.classrooms
- @prestation_types = current_user.organisation.prestation_types
- @prestations = current_user.organisation.prestations
-
params[:date] ||= Date.today
+ organisation = current_user.organisation
+ @structures = organisation.structures
+ @classrooms = organisation.classrooms
+ @prestation_types = organisation.prestation_types
+ @prestations = organisation.prestations
+
unless params[:structure_id].blank?
@prestations = @prestations.joins(enfant: [:compte]).where(comptes: { structure_id: params[:structure_id] })
@classrooms = @classrooms.where(structure_id: params[:structure_id])
end
unless params[:nom].blank?
- @prestations = @prestations.joins(:enfant).where("UPPER(enfants.nom) like ?", "%#{params[:nom].upcase}%")
+ @prestations = @prestations.joins(:enfant).where("enfants.nom ILIKE ? OR enfants.prénom ILIKE ?", "%#{params[:nom]}%", "%#{params[:nom]}%")
end
+ # Appliquer le tri
+ @prestations = @prestations.joins(:enfant => :classroom)
+ .joins(:prestation_type)
+ .reorder(Arel.sql("#{sort_column} #{sort_direction}"))
+
@prestations = @prestations.paginate(page: params[:page])
end
authorize Prestation
end
- # GET /prestations/1/edit
- def edit
- authorize Prestation
- end
-
- # POST /prestations
- # POST /prestations.json
- def create
- authorize Prestation
- end
-
- # PATCH/PUT /prestations/1
- # PATCH/PUT /prestations/1.json
- def update
- authorize Prestation
-
- respond_to do |format|
- if @prestation.update(prestation_params)
- format.html { redirect_to @prestation, notice: 'Prestation modifié.e avec succès.' }
- format.json { render :show, status: :ok, location: @prestation }
- else
- format.html { render :edit }
- format.json { render json: @prestation.errors, status: :unprocessable_entity }
- end
+ # GET /prestations/1/edit
+ def edit
+ authorize Prestation
+ end
+
+ # POST /prestations
+ # POST /prestations.json
+ def create
+ authorize Prestation
+ end
+
+ # PATCH/PUT /prestations/1
+ # PATCH/PUT /prestations/1.json
+ def update
+ authorize Prestation
+
+ respond_to do |format|
+ if @prestation.update(prestation_params)
+ format.html { redirect_to @prestation, notice: 'Prestation modifié.e avec succès.' }
+ format.json { render :show, status: :ok, location: @prestation }
+ else
+ format.html { render :edit }
+ format.json { render json: @prestation.errors, status: :unprocessable_entity }
end
end
-
- # DELETE /prestations/1
- # DELETE /prestations/1.json
- def destroy
- authorize Prestation
-
- @prestation.destroy
- respond_to do |format|
- format.html { redirect_to prestations_url, notice: 'Prestation supprimé.e avec succès.' }
- format.json { head :no_content }
- end
+ end
+
+ # DELETE /prestations/1
+ # DELETE /prestations/1.json
+ def destroy
+ authorize Prestation
+
+ @prestation.destroy
+ respond_to do |format|
+ format.html { redirect_to prestations_url, notice: 'Prestation supprimé.e avec succès.' }
+ format.json { head :no_content }
end
-
- private
+ end
+
+ private
# Use callbacks to share common setup or constraints between actions.
def set_prestation
@prestation = Prestation.find(params[:id])
params.require(:prestation).permit(:qté)
end
-
+ def sortable_columns
+ %w{prestations.date prestation_types.nom enfants.nom enfants.prénom classrooms.nom prestations.qté}
+ end
+
+ def sort_column
+ sortable_columns.include?(params[:column]) ? params[:column] : 'prestations.id'
+ end
+
+ def sort_direction
+ %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
+ end
end
self.per_page = 10
- default_scope { order(Arel.sql('nom')) }
+ default_scope { order(Arel.sql('comptes.nom')) }
def self.xls_headers
%w{structure nom_compte civilité adresse1 adresse2 cp ville num_allocataire mémo_compte
accepts_nested_attributes_for :reservations, reject_if: proc { |attributes| attributes[:prestation_type_id].blank? or attributes[:début].blank? or attributes[:fin].blank?}, allow_destroy: true
- default_scope { order(Arel.sql('nom, prénom')) }
+ default_scope { order(Arel.sql('enfants.nom, enfants.prénom')) }
self.per_page = 10
self.per_page = 10
- default_scope { order("réf DESC") }
+ default_scope { order(Arel.sql("factures.réf DESC")) }
before_destroy :maj_prestations
class Organisation < ApplicationRecord
-
audited
has_one_attached :logo
has_many :tarifs, through: :tarif_types
validates :nom, :email, presence: true
-
end
validates :nom, presence: true
validates_uniqueness_of :nom, scope: [:organisation_id]
- default_scope { order(:nom) }
+ default_scope { order(Arel.sql('structures.nom')) }
def nom_avec_organisation
self.organisation.nom + "/" + self.nom
class Vacance < ApplicationRecord
audited
- default_scope { order(Arel.sql('début')) }
+ default_scope { order(Arel.sql('vacances.début')) }
end
<thead>
<tr>
<th>Structure</th>
- <th>Réf</th>
- <th>Date</th>
- <th>Compte</th>
- <th>Envoyée le</th>
- <th>Montant</th>
- <th>Vérifiée</th>
- <th>Mémo</th>
+ <th><%= sort_link 'factures.réf', 'Réf' %></th>
+ <th><%= sort_link 'factures.date', 'Date' %></th>
+ <th><%= sort_link 'comptes.nom', 'Compte' %></th>
+ <th><%= sort_link 'factures.envoyée_le', 'Envoyée le' %></th>
+ <th><%= sort_link 'factures.montant', 'Montant' %></th>
+ <th><%= sort_link 'factures.vérifiée', 'Vérifiée?' %></th>
+ <th><%= sort_link 'factures.mémo', 'Mémo' %></th>
<th colspan="2"></th>
</tr>
</thead>
<thead>
<tr>
<th>Structure</th>
- <th>Date</th>
- <th>Type</th>
- <th>Nom</th>
- <th>Prénom</th>
- <th>Classe</th>
- <th>Qté</th>
+ <th><%= sort_link 'prestations.date', 'Date' %></th>
+ <th><%= sort_link 'prestation_types.nom', 'Type' %></th>
+ <th><%= sort_link 'enfants.nom', 'Nom' %></th>
+ <th><%= sort_link 'enfants.prénom', 'Prénom' %></th>
+ <th><%= sort_link 'classrooms.nom', 'Classe' %></th>
+ <th><%= sort_link 'prestations.qté', 'Qté' %></th>
<th colspan=2></th>
</tr>
</thead>