# Enfant => classroom nom_enfant prénom date_naissance menuSP menuALL tarif_type badge
enfant = compte
.enfants
- .where('UPPER(nom) = ? AND UPPER(prénom) = ?', row[headers.index 'nom_enfant'].strip.upcase, row[headers.index 'prénom'].strip.upcase)
+ .where('UPPER(nom) = ?', row[headers.index 'nom_enfant'].strip.upcase)
+ .where('UPPER(prénom) = ?', row[headers.index 'prénom'].strip.upcase)
.first_or_initialize do |e|
e.nom = row[headers.index 'nom_enfant']
e.prénom = row[headers.index 'prénom']
classe.nom = row[headers.index 'classe']
end
e.date_naissance = row[headers.index 'date_naissance']
- e.menuSP = row[headers.index 'menuSP']
- e.menuALL = row[headers.index 'menuALL']
+ e.menuSP = (row[headers.index 'menuSP'].strip.upcase == 'OUI')
+ e.menuALL = (row[headers.index 'menuALL'].strip.upcase == 'OUI')
e.tarif_type = organisation.tarif_types.find_by(nom: row[headers.index 'tarif_type'])
e.badge = row[headers.index 'badge']
end
@messages << " || ERREURS: " + enfant.errors.messages.map{|m| "#{m.first} => #{m.last}"}.join(',')
end
+ # Réservations
+ # prestation_type début fin lundi mardi mercredi jeudi vendredi matin midi soir active hors_période_scolaire
+ reservation = enfant
+ .reservations
+ .where(prestation_type: PrestationType.find_by(nom: row[headers.index 'prestation_type']))
+ .where(début: row[headers.index 'début'])
+ .where(fin: row[headers.index 'fin'])
+ .first_or_initialize do |r|
+ r.prestation_type = PrestationType.find_by(nom: row[headers.index 'prestation_type'])
+ r.début = row[headers.index 'début']
+ r.fin = row[headers.index 'fin']
+ r.lundi = row[headers.index 'lundi']
+ r.mardi = row[headers.index 'mardi']
+ r.mercredi = row[headers.index 'mercredi']
+ r.jeudi = row[headers.index 'jeudi']
+ r.vendredi = row[headers.index 'vendredi']
+ r.matin = (row[headers.index 'matin'].strip.upcase == 'OUI')
+ r.midi = (row[headers.index 'midi'].strip.upcase == 'OUI')
+ r.soir = (row[headers.index 'soir'].strip.upcase == 'OUI')
+ r.active = (row[headers.index 'active'].strip.upcase == 'OUI')
+ r.hors_période_scolaire = (row[headers.index 'hors_période_scolaire'].strip.upcase == 'OUI')
+ end
+
+ if reservation.valid?
+ @messages << "RESERVATION #{reservation.new_record? ? 'NOUVEAU' : 'MAJ'} => id:#{reservation.id} changements:#{reservation.changes}"
+ reservation.save if params[:enregistrer] == '1'
+ else
+ @messages << " || ERREURS: " + reservation.errors.messages.map{|m| "#{m.first} => #{m.last}"}.join(',')
+ end
+
enfant.valid? ? @importes += 1 : @errors += 1
puts @messages
end
end
end
+
+ def exemple_fichier_import_xls
+ send_file ("public/openCantine5-Exemple_de_fichier_import.xls")
+ end
end
has_many :contacts, inverse_of: :compte, dependent: :delete_all
accepts_nested_attributes_for :contacts, reject_if: proc { |attributes| attributes[:nom].blank? }, allow_destroy: true
- has_many :enfants
+ has_many :enfants, dependent: :delete_all
has_many :classrooms
has_many :prestations, through: :enfants
has_many :factures
default_scope { order(:nom) }
def self.xls_headers
- %w{structure nom_compte civilité adresse1 adresse2 cp ville num_allocataire mémo nom_enfant prénom classe date_naissance menuSP menuALL tarif_type badge}
+ %w{structure nom_compte civilité adresse1 adresse2 cp ville num_allocataire mémo
+ nom_enfant prénom classe date_naissance menuSP menuALL tarif_type badge
+ prestation_type début fin lundi mardi mercredi jeudi vendredi matin midi soir active hors_période_scolaire}
end
end
audited
- belongs_to :compte, :counter_cache => true
+ belongs_to :compte, counter_cache: true
belongs_to :classroom
belongs_to :tarif_type
class Reservation < ApplicationRecord
audited
- belongs_to :enfant, dependent: :destroy
+ belongs_to :enfant
belongs_to :prestation_type
- scope :actives, ->{ where(active: true) }
+ scope :actives, ->{ where(active: true) }
self.per_page = 10
<div class="pb-2 mt-4 mb-2 border-bottom">
- <h1><i class="fas fa-file-import"></i> Importer Comptes et Enfants</h1>
+ <h1><i class="fas fa-file-import"></i> Importer données XLS</h1>
</div>
<p>
- <h4>Pour importer les données, votre fichier doit être au format Excel 97-2003 (.xls)<br /> et contenir les colonnes suivantes :</h4>
- <%= Compte.xls_headers.join(', ') %>
+ <p>
+ <h4>Pour importer les données, votre fichier doit être au format Excel 97-2003 (.xls)<br /> et contenir les colonnes suivantes :</h4>
+ <%= Compte.xls_headers.join(', ') %>
+ </p>
+
+ <p>
+ Exemple de fichier : <%= link_to "Fichier.xls", admin_exemple_fichier_import_xls_url %>
+ </p>
+
+ <p>
+ <i>
+ Ne permet que d'importer des données nouvelles.
+ Pour mettre à jour des données existantes, supprimer l'enregistrement pour qu'il soit recréer avec les nouvelles données.
+ </i>
+ </p>
</p>
-<br />
<%= bootstrap_form_with(url: "import_do", method: :post, local: true) do |form| %>
</div>
<br />
- <%= form.submit "Lancer", class: "btn btn-success" %>
+ <%= form.submit "Importer", class: "btn btn-success" %>
<% end %>
+
+<script type="text/javascript">
+ // Workaround for displaying selected file
+ $("input[type=file]").change(function () {
+ var fieldVal = $(this).val();
+
+ // Change the node's value by removing the fake path (Chrome)
+ fieldVal = fieldVal.replace("C:\\fakepath\\", "");
+
+ if (fieldVal != undefined || fieldVal != "") {
+ $(this).next(".custom-file-label").attr('data-content', fieldVal);
+ $(this).next(".custom-file-label").text(fieldVal);
+ }
+ });
+</script>
-<%= @messages %>
\ No newline at end of file
+<div class="pb-2 mt-4 mb-2 border-bottom">
+ <h1><i class="fas fa-file-import"></i> Importer données XLS</h1>
+</div>
+
+<pre>
+ <% @messages.each do |msg| %>
+ <p><%= msg %></p>
+ <% end %>
+</pre>
\ No newline at end of file
<li class="list-group-item">
<h5>
- <i class="fas fa-file-import"></i>
- <%= link_to admin_import_path, class: "text-dark" do %>Importer<% end %>
+ <i class="fas fa-search"></i>
+ <%= link_to admin_audit_path, class: "text-dark" do %>Audit des modifications<% end %>
</h5>
</li>
<li class="list-group-item">
<h5>
- <i class="fas fa-search"></i>
- <%= link_to admin_audit_path, class: "text-dark" do %>Audit des modifications<% end %>
+ <i class="fas fa-file-import"></i>
+ <%= link_to admin_import_path, class: "text-dark" do %>Importer<% end %>
</h5>
</li>
get 'admin/tarifs'
get 'admin/audit'
get 'admin/import'
+ get 'admin/exemple_fichier_import_xls'
post 'admin/ajout_prestations_do'
post 'admin/ajout_factures_do'