@factures = @factures.joins(:compte).where(comptes: { structure_id: params[:structure_id] })
end
- unless params[:date].blank?
- @factures = @factures.where("DATE(date) = ?", params[:date])
+ unless params[:structure_id].blank?
+ @factures = @factures.joins(:compte).where(comptes: { structure_id: params[:structure_id] })
+ end
+
+ unless params[:date_début].blank? || params[:date_fin].blank?
+ @factures = @factures.where("DATE(date) BETWEEN ? AND ?", params[:date_début], params[:date_fin])
end
unless params[:search].blank?
authorize Paiement
@paiements = current_user.organisation.paiements
- params[:date] ||= Date.today
+ @structures = current_user.organisation.structures
- unless params[:date].blank?
- @paiements = @paiements.where("DATE(date) = ?", params[:date])
+ unless params[:structure_id].blank?
+ @paiements = @paiements.joins(:compte).where(comptes: { structure_id: params[:structure_id] })
end
+ unless params[:date_début].blank? || params[:date_fin].blank?
+ @paiements = @paiements.where("DATE(date) BETWEEN ? AND ?", params[:date_début], params[:date_fin])
+ end
+
unless params[:nom].blank?
@paiements = @paiements.joins(:compte).where("UPPER(comptes.nom) like ?", "%#{params[:nom].upcase}%")
end
@paiements = @paiements.paginate(page: params[:page])
+
+ respond_to do |format|
+ format.html
+ format.xls do
+ book = Paiement.to_xls(@paiements)
+ file_contents = StringIO.new
+ book.write file_contents # => Now file_contents contains the rendered file output
+ filename = "Paiements.xls"
+ send_data file_contents.string.force_encoding('binary'), filename: filename
+ end
+ end
end
# GET /paiements/1
params[:date] ||= Date.today
unless params[:structure_id].blank?
- @prestations = @prestations.joins(enfant: [:prestation]).where(prestations: { structure_id: params[:structure_id] })
+ @prestations = @prestations.joins(enfant: [:compte]).where(comptes: { structure_id: params[:structure_id] })
@classrooms = @classrooms.where(structure_id: params[:structure_id])
end
# et quelques données de base pour aider la prise en main
organisation.structures.first.classrooms.create(nom: 'UNE CLASSE')
- organisation.structures.first.comptes.create(nom: 'TEST')
+ organisation.structures.first.comptes.create(nom: 'FAMILLE TEST')
organisation.facture_chronos.create(index: 1)
organisation.tarif_types.create(nom: 'Général')
organisation.prestation_types.create(nom: 'Repas')
# on se connecte avec l'utilisateur créé
sign_in @user
- format.html { redirect_to root_url, notice: 'Bienvenue ! Nous avons créé quelques exemples pour aider votre prise en main' }
+ format.html { redirect_to root_url, notice: 'Bienvenue ! Nous avons créé quelques exemples de données pour aider dans la prise en main du logiciel :)' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
def user_params
params.require(:user).permit(:email, :admin, :organisation_id, :password, :password_confirmation)
end
-
-
end
\ No newline at end of file
%w{AXA BNP_Paribas Banque_Populaire CIC Caisse_d'épargne Crédit_Agricole Crédit_Mutuel LA_BANQUE_POSTALE Société_Générale Autre}
end
+ def self.xls_headers
+ %w{ID Date Réf Compte Mode Banque Chèque_N° Montant Date_de_remise Mémo}
+ end
+
+ def self.to_xls(paiements)
+ require 'spreadsheet'
+
+ Spreadsheet.client_encoding = 'UTF-8'
+
+ book = Spreadsheet::Workbook.new
+ sheet = book.create_worksheet name: 'Paiements'
+ bold = Spreadsheet::Format.new :weight => :bold, :size => 10
+
+ sheet.row(0).concat Paiement.xls_headers
+ sheet.row(0).default_format = bold
+
+ index = 1
+ paiements.each do |p|
+ fields_to_export = [
+ p.id,
+ p.date,
+ p.réf,
+ p.compte.nom,
+ p.mode,
+ p.banque,
+ p.chèque_num,
+ p.montant,
+ p.date_remise,
+ p.mémo,
+ p.created_at,
+ p.updated_at
+ ]
+ sheet.row(index).replace fields_to_export
+ index += 1
+ end
+
+ return book
+
+ end
+
end
user.admin?
end
+ def to_xls?
+ user.admin?
+ end
+
end
<tr>
+ <td><%= absence.enfant.compte.structure.nom %></td>
<td><%= absence.enfant.nom_et_prénom %></td>
<td><%= absence.enfant.classroom.nom %></td>
<td><%= l absence.début %></td>
<table class="table table-striped table-hover">
<thead>
<tr>
+ <th>Structure</th>
<th>Enfant</th>
<th>Classe</th>
<th>Début</th>
</tr>
</thead><%= will_paginate @absences, renderer: WillPaginate::ActionView::BootstrapLinkRenderer %>
-
<tbody>
<%= render @absences %>
</tbody>
<tr>
+ <td><%= facture.compte.structure.nom %></td>
<td><%= link_to facture.réf, facture %></td>
<td><%= l facture.date.to_date %></td>
<td><%= facture.compte.nom %></td>
<%= bootstrap_form_tag url: factures_path, method: :get do |f| %>
<div class="row">
<div class="col-sm-3"><%= f.select :structure_id, options_from_collection_for_select(@structures, 'id', 'nom', params[:structure_id]), { include_blank: true, label: "Structure" }, { class: "selectpicker", onchange: "this.form.submit()" } %></div>
- <div class="col-sm-2"><%= f.date_field :date, value: params[:date], onchange: "this.form.submit()" %></div>
+ <div class="col-sm-2"><%= f.date_field :date_début, value: params[:date_début], onchange: "this.form.submit()" %></div>
+ <div class="col-sm-2"><%= f.date_field :date_fin, value: params[:date_fin], onchange: "this.form.submit()" %></div>
<div class="col"><%= f.text_field :search, value: params[:search], label:"Nom du compte/Référence facture", onchange: "this.form.submit()" %></div>
</div>
<% end %>
<table class="table table-striped table-hover">
<thead>
<tr>
+ <th>Structure</th>
<th>Réf</th>
<th>Date</th>
<th>Compte</th>
<br>
<% if policy(Facture).to_xls? %>
- <%= link_to "Export XLS", url_for(params.permit(:structure_id, :date, :search).merge(format: :xls)) %>
+ <%= link_to "Export XLS", url_for(params.permit(:structure_id, :date_début, :date_fin, :search).merge(format: :xls)) %>
<% end %>
\ No newline at end of file
<tr>
+ <td><%= paiement.compte.structure.nom %></td>
<td><%= l paiement.date.to_date %></td>
<td><%= link_to paiement.compte.nom, paiement.compte, class: "text-primary" %></td>
<td><%= paiement.réf %></td>
<td><%= paiement.banque %></td>
<td><%= paiement.chèque_num %></td>
<td class="text-right"><%= number_to_currency(paiement.montant, unit: '€', precision: 2, format: "%n %u") %></td>
- <td><%= paiement.date_remise %></td>
+ <td><%= l paiement.try(:date_remise) %></td>
<td><%= paiement.mémo %></td>
<td>
<% if policy(paiement).edit? %>
<%= bootstrap_form_tag url: paiements_path, method: :get do |f| %>
<div class="row">
- <div class="col-sm-2"><%= f.date_field :date, value: params[:date], onchange: "this.form.submit()" %></div>
+ <div class="col-sm-3"><%= f.select :structure_id, options_from_collection_for_select(@structures, 'id', 'nom', params[:structure_id]), { include_blank: true, label: "Structure" }, { class: "selectpicker", onchange: "this.form.submit()" } %></div>
+ <div class="col-sm-2"><%= f.date_field :date_début, value: params[:date_début], onchange: "this.form.submit()" %></div>
+ <div class="col-sm-2"><%= f.date_field :date_fin, value: params[:date_fin], onchange: "this.form.submit()" %></div>
<div class="col"><%= f.text_field :nom, value: params[:nom], onchange: "this.form.submit()" %></div>
</div>
<% end %>
<table class="table table-striped table-hover">
<thead>
<tr>
+ <th>Structure</th>
<th>Date</th>
<th>Compte</th>
<th>Réf</th>
<%= will_paginate @paiements, renderer: WillPaginate::ActionView::BootstrapLinkRenderer %>
<br>
+
+<% if policy(Paiement).to_xls? %>
+ <%= link_to "Export XLS", url_for(params.permit(:structure_id, :date_début, :date_fin, :search).merge(format: :xls)) %>
+<% end %>
\ No newline at end of file
<tr>
+ <td><%= prestation.enfant.compte.structure.nom %></td>
<td><%= l prestation.date %></td>
<td><%= prestation.prestation_type.nom %></td>
<td><%= link_to prestation.enfant.nom, prestation.enfant.compte, class: "text-primary" %></td>
<table class="table table-striped table-hover">
<thead>
<tr>
+ <th>Structure</th>
<th>Date</th>
<th>Type</th>
<th>Nom</th>
--- /dev/null
+class ChangePaiementDateRemiseToDate < ActiveRecord::Migration[5.2]
+ def change
+ change_column :paiements, :date_remise, "date USING date_remise::date"
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_09_23_141337) do
+ActiveRecord::Schema.define(version: 2019_09_24_124545) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
t.string "banque"
t.string "chèque_num"
t.decimal "montant", precision: 5, scale: 2, default: "0.0", null: false
- t.string "date_remise"
+ t.date "date_remise"
t.string "mémo"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false