*= require bootstrap/dist/css/bootstrap
*= require rails_bootstrap_forms
*/
+
+
\ No newline at end of file
@enfant = Enfant.new
@enfant.compte = Compte.find(params[:compte_id])
@classrooms = @enfant.compte.structure.classrooms
+ @prestation_types = @enfant.compte.structure.organisation.prestation_types
+ date_rentrée = Vacance.find_by(nom: "Rentrée").début
+ date_grandes_vacances = Vacance.find_by(nom: "Vacances d'été").début
+
+ 2.times { @enfant.reservations.build(début: date_rentrée, fin: date_grandes_vacances) }
end
# GET /enfants/1/edit
def edit
@classrooms = @enfant.compte.structure.classrooms
+ @prestation_types = @enfant.compte.structure.organisation.prestation_types
+ 1.times { @enfant.reservations.build(début: Date.today) }
end
# POST /enfants
# Never trust parameters from the scary internet, only allow the white list through.
def enfant_params
- params.require(:enfant).permit(:compte_id, :classroom_id, :nom, :prénom, :date_naissance, :menuSP, :menuALL)
+ params.require(:enfant).permit(:compte_id, :classroom_id, :nom, :prénom, :date_naissance, :menuSP, :menuALL,
+ reservations_attributes: [:id, :enfant_id, :prestation_type_id, :début, :fin,
+ :lundi, :mardi, :mercredi, :jeudi, :vendredi, :matin, :midi, :soir, :_destroy])
end
end
belongs_to :compte
belongs_to :classroom
- has_many :prestations
has_many :reservations
has_many :absences
+ has_many :prestations
+
+ 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
def nom_et_prénom
"#{self.nom} #{self.prénom}"
accepts_nested_attributes_for :structures, reject_if: proc { |attributes| attributes[:nom].blank? }, allow_destroy: true
has_many :users
- has_many :prestation_types
+ has_many :prestation_types, inverse_of: :organisation
has_many :tarif_types
has_many :tarifs, through: :tarif_types
has_many :comptes, through: :structures
class Reservation < ApplicationRecord
- belongs_to :enfant
+ belongs_to :enfant, dependent: :destroy
belongs_to :prestation_type
scope :actives, ->{ where(active: true) }
class Vacance < ApplicationRecord
+
+ default_scope { order(:début) }
+
end
</div>
<div class="actions">
- <%= form.submit "Enregistrer", class: "btn btn-success" %>
+ <%= form.submit "Enregistrer" %>
</div>
<% end %>
-<h1>Editing Compte</h1>
+<h1>Editer Compte</h1>
<%= render 'form', compte: @compte %>
-<%= link_to 'Show', @compte %> |
-<%= link_to 'Back', comptes_path %>
+<%= link_to 'Voir', @compte %> |
+<%= link_to 'Retour', comptes_path %>
<th>Ville</th>
<th>Num allocataire</th>
<th>Mémo</th>
- <th colspan="3"></th>
+ <th colspan="2"></th>
</tr>
</thead>
<% @comptes.each do |compte| %>
<tr>
<td><%= compte.structure.nom %></td>
- <td><%= compte.nom %></td>
+ <td><%= link_to compte.nom, compte %></td>
<td><%= compte.civilité %></td>
<td><%= compte.adresse1 %></td>
<td><%= compte.adresse2 %></td>
<td><%= compte.ville %></td>
<td><%= compte.num_allocataire %></td>
<td><%= compte.mémo %></td>
- <td><%= link_to 'Show', compte %></td>
<td><%= link_to 'Edit', edit_compte_path(compte) %></td>
<td><%= link_to 'Destroy', compte, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<br>
-<%= link_to 'New Compte', new_compte_path %>
+<%= link_to 'Ajouter un Compte', new_compte_path %>
-<h1>New Compte</h1>
+<h1>Nouveau Compte</h1>
<%= render 'form', compte: @compte %>
-<%= link_to 'Back', comptes_path %>
+<%= link_to 'Retour', comptes_path %>
</p>
<%= link_to 'Editer', edit_compte_path(@compte) %>
</div>
+
<div class="col">
<p>
<h3>Contacts</h3>
<% @compte.enfants.each do |enfant| %>
<tr>
<td><%= enfant.nom %></td>
- <td><%= enfant.prénom %></td>
+ <td><%= link_to enfant.prénom, enfant %></td>
<td><%= enfant.date_naissance %></td>
<td><%= enfant.classroom.nom %></td>
<td><%= enfant.menuSP %></td>
</div>
<% end %>
- Compte: <br />
- <%= enfant.compte.nom %>
- <br /><br />
-
<%= form.hidden_field :compte_id %>
- <%= form.select :classroom_id, options_from_collection_for_select(@classrooms, 'id', 'nom'), { label: "Classe:", wrapper: { class: 'has-warning', data: { foo: 'bar' } } }, { class: "selectpicker" } %>
- <%= form.text_field :nom %>
- <%= form.text_field :prénom %>
- <%= form.date_select :date_naissance %>
+
+ <p>
+ Compte
+ <h3><%= enfant.compte.civilité %> <%= enfant.compte.nom %></h3>
+ </p>
+
+ <div class="row">
+ <div class="col"><%= form.select :classroom_id, options_from_collection_for_select(@classrooms, 'id', 'nom'), { label: "Classe" }, { class: "selectpicker" } %></div>
+ <div class="col"><%= form.text_field :nom %></div>
+ <div class="col"><%= form.text_field :prénom %></div>
+ <div class="col"><%= form.date_field :date_naissance %></div>
+ </div>
+
<%= form.check_box :menuSP, label: "Menu 'Sans porc' ?", custom: :switch %>
<%= form.check_box :menuALL, label: "Menu 'Allergie' ?", custom: :switch %>
<br />
+ <h3><i class="fas fa-calendar-alt"></i> Réservations</h3>
+
+ <%= form.fields_for :reservations, layout: :horizontal do |reservation_form| %>
+ <div class="row">
+ <div class="col"><%= reservation_form.select :prestation_type_id, options_from_collection_for_select(@prestation_types, 'id', 'nom'), { label: "Type" }, { class: "selectpicker" } %></div>
+ <div class="col"><%= reservation_form.date_field :début %></div>
+ <div class="col"><%= reservation_form.date_field :fin %></div>
+ </div>
+ <div class="row">
+ <div class="col"><%= reservation_form.number_field :lundi, step: :any, label_col: "col-sm-3", control_col: "col-sm-6" %></div>
+ <div class="col"><%= reservation_form.number_field :mardi, step: :any, label_col: "col-sm-3", control_col: "col-sm-6" %></div>
+ <div class="col"><%= reservation_form.number_field :mercredi, step: :any, label_col: "col-sm-4", control_col: "col-sm-6" %></div>
+ <div class="col"><%= reservation_form.number_field :jeudi, step: :any, label_col: "col-sm-4", control_col: "col-sm-6" %></div>
+ <div class="col"><%= reservation_form.number_field :vendredi, step: :any, label_col: "col-sm-4", control_col: "col-sm-6" %></div>
+ </div>
+ <div class="row">
+ <div class="col-sm-1"><%= reservation_form.check_box :matin, custom: :switch %></div>
+ <div class="col-sm-1"><%= reservation_form.check_box :midi, custom: :switch %></div>
+ <div class="col"><%= reservation_form.check_box :soir, custom: :switch %></div>
+ <% unless reservation_form.object.new_record? %>
+ <div class="col"></div>
+ <div class="col-sm-2"><%= reservation_form.check_box :active, custom: :switch %></div>
+ <div class="col-sm-2"><%= reservation_form.check_box :_destroy, label: "Supprimer?" %></div>
+ <% end %>
+ </div>
+ <hr />
+ <% end %>
+
<div class="actions">
- <%= form.submit "Enregistrer", class: "btn btn-success" %>
+ <%= form.submit "Enregistrer" %>
</div>
<% end %>
<%= render 'form', enfant: @enfant %>
-<%= link_to 'Show', @enfant %> |
-<%= link_to 'Back', enfants_path %>
+<%= link_to 'Voir', @enfant %> |
+<%= link_to 'Retour', enfants_path %>
<th>Date naissance</th>
<th>Menu SP?</th>
<th>Menu ALLERGIE?</th>
- <th colspan="3"></th>
+ <th colspan="2"></th>
</tr>
</thead>
<td><%= enfant.compte.nom %></td>
<td><%= enfant.classroom.nom %></td>
<td><%= enfant.nom %></td>
- <td><%= enfant.prénom %></td>
+ <td><%= link_to enfant.prénom, enfant %></td>
<td><%= enfant.date_naissance %></td>
<td><%= enfant.menuSP %></td>
<td><%= enfant.menuALL %></td>
- <td><%= link_to 'Show', enfant %></td>
<td><%= link_to 'Edit', edit_enfant_path(enfant) %></td>
<td><%= link_to 'Destroy', enfant, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
-<h1>New Enfant</h1>
+<h1>Ajouter Enfant</h1>
+<br />
<%= render 'form', enfant: @enfant %>
-
-<%= link_to 'Back', enfants_path %>
<p>
<h2>
- <%= @enfant.nom %>
<%= @enfant.prénom %>
+ <%= @enfant.nom %>
</h2>
</p>
<p>
<strong>Compte:</strong>
- <%= @enfant.compte.nom %>
+ <%= link_to @enfant.compte.nom, @enfant.compte %>
</p>
<p>
<%= @enfant.menuALL %>
</p>
-<%= link_to 'Editer', edit_enfant_path(@enfant) %>
-
-<br /><br />
+<br />
<p>
<h3><i class="fas fa-calendar-alt"></i> Réservations</h3>
</tr>
<% end %>
</table>
- <%= link_to "+ Ajouter une réservation", new_reservation_path(enfant_id: @enfant), class: "btn btn-outline-primary btn-sm" %>
+ <%= link_to 'Editer', edit_enfant_path(@enfant) %>
</p>
+<br />
<p>
<h3><i class="fas fa-calendar-times"></i> Absences</h3>
<%= link_to "+ Ajouter une absence", new_absence_path(enfant_id: @enfant), class: "btn btn-outline-primary btn-sm" %>
</p>
+<br />
-<h3><i class="fas fa-utensils"></i> Prestations</h3>
-<table class="table table-striped">
- <% @enfant.prestations.each do |prestation| %>
- <tr>
- <td><%= prestation.date %></td>
- <td><%= prestation.prestation_type.nom %>
- <td><%= prestation.qté %></td>
- </tr>
- <% end %>
-</table>
-
+<p>
+ <h3><i class="fas fa-utensils"></i> Prestations</h3>
+ <table class="table table-striped">
+ <% @enfant.prestations.each do |prestation| %>
+ <tr>
+ <td><%= prestation.date %></td>
+ <td><%= prestation.prestation_type.nom %>
+ <td><%= prestation.qté %></td>
+ </tr>
+ <% end %>
+ </table>
+</p>