@absence.destroy
respond_to do |format|
- format.html { redirect_to absences_url, notice: 'Absence supprimé.e avec succès.' }
+ format.html { redirect_to absences_url, notice: 'Absence supprimée avec succès.' }
format.json { head :no_content }
end
end
# GET /factures/1/edit
def edit
+ @prestation_types = current_user.organisation.prestation_types
+
+ 1.times { @facture.facture_lignes.build }
end
# POST /factures
def update
respond_to do |format|
if @facture.update(facture_params)
- format.html { redirect_to @facture, notice: 'Facture was successfully updated.' }
+ format.html { redirect_to @facture, notice: 'Facture modifiée avec succès.' }
format.json { render :show, status: :ok, location: @facture }
else
format.html { render :edit }
@facture.destroy
respond_to do |format|
- format.html { redirect_to factures_url, notice: 'Facture was successfully destroyed.' }
+ format.html { redirect_to factures_url, notice: 'Facture supprimée avec succès.' }
format.json { head :no_content }
end
end
# Never trust parameters from the scary internet, only allow the white list through.
def facture_params
- params.require(:facture).permit(:compte_id, :réf, :date, :échéance, :envoyée_le, :montant, :vérifiée, :mémo)
+ 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
end
belongs_to :compte
has_many :facture_lignes, dependent: :destroy
+ accepts_nested_attributes_for :facture_lignes, reject_if: proc { |attributes| attributes[:intitulé].blank? }, allow_destroy: true
+
has_many :prestations
validates :réf, presence: true
<tr>
<td><%= facture.réf %></td>
- <td><%= l facture.date %></td>
+ <td><%= l facture.date.to_date %></td>
<td><%= facture.compte.nom %></td>
- <td><%= l facture.envoyée_le if facture.envoyée_le %></td>
+ <td><%= l facture.envoyée_le.to_date if facture.envoyée_le %></td>
<td><%= number_to_currency(facture.montant, unit: '€', precision: 2, format: '%n %u') %></td>
<td><%= facture.vérifiée %></td>
<td><%= facture.mémo %></td>
-<%= form_with(model: facture, local: true) do |form| %>
+<%= bootstrap_form_with(model: facture, local: true) do |form| %>
+
<% if facture.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(facture.errors.count, "error") %> prohibited this facture from being saved:</h2>
</div>
<% end %>
- <div class="field">
- <%= form.label :compte_id %>
- <%= form.text_field :compte_id %>
- </div>
-
- <div class="field">
- <%= form.label :réf %>
- <%= form.text_field :réf %>
- </div>
-
- <div class="field">
- <%= form.label :date %>
- <%= form.datetime_select :date %>
- </div>
-
- <div class="field">
- <%= form.label :échéance %>
- <%= form.datetime_select :échéance %>
- </div>
-
- <div class="field">
- <%= form.label :envoyée_le %>
- <%= form.datetime_select :envoyée_le %>
- </div>
-
- <div class="field">
- <%= form.label :montant %>
- <%= form.text_field :montant %>
- </div>
-
- <div class="field">
- <%= form.label :vérifiée %>
- <%= form.check_box :vérifiée %>
- </div>
-
- <div class="field">
- <%= form.label :mémo %>
- <%= form.text_field :mémo %>
+ <%= form.hidden_field :compte_id %>
+
+ <div class="row">
+ <div class="col">
+ <%= form.datetime_select :date %>
+ <%= form.datetime_select :échéance %>
+ <div class="row">
+ <div class="col">
+ <%= form.text_field :réf %>
+ </div>
+ <div class="col">
+ <%= form.number_field :montant, step: :any %>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <%= form.text_area :mémo %>
+ <%= form.datetime_select :envoyée_le %>
+ <%= form.check_box :vérifiée, custom: :switch %>
+ </div>
</div>
+ <hr />
+
+ <p>
+ <%= form.fields_for :facture_lignes, layout: :horizontal do |ligne_form| %>
+ <div class="row">
+ <div class="col"><%= ligne_form.text_field :intitulé, label: "Intitulé de la ligne" %></div>
+ </div>
+ <div class="row">
+ <div class="col"><%= ligne_form.select :prestation_type_id, options_from_collection_for_select(@prestation_types, 'id', 'nom'), { label: "Type" }, { class: "selectpicker" } %></div>
+ <div class="col"><%= ligne_form.number_field :qté, step: :any %></div>
+ <div class="col"><%= ligne_form.number_field :prix, step: :any %></div>
+ <div class="col"><%= ligne_form.number_field :total, step: :any %></div>
+ </div>
+ <div class="col"><%= ligne_form.check_box :_destroy, label: "Supprimer ?" %></div>
+ <hr />
+ <% end %>
+ </p>
+
+ <%= form.submit %>
- <div class="actions">
- <%= form.submit %>
- </div>
<% end %>
-<h1>Editing Facture</h1>
+<h1>Editer Facture</h1>
<%= render 'form', facture: @facture %>
-<%= link_to 'Show', @facture %> |
-<%= link_to 'Back', factures_path %>
+<%= link_to 'Voir', @facture %> |
+<%= link_to 'Retour', factures_path %>
-<p id="notice"><%= notice %></p>
-
<p>
<strong>Compte:</strong>
<%= @facture.compte.nom %>
<p>
<strong>Date:</strong>
- <%= @facture.date %>
+ <%= l @facture.date %>
</p>
<p>
<strong>échéance:</strong>
- <%= @facture.échéance %>
+ <%= l @facture.échéance.to_date %>
</p>
<p>
<strong>Envoyée le:</strong>
- <%= @facture.envoyée_le %>
+ <%= l @facture.envoyée_le %>
</p>
<p>
<%= wicked_pdf_javascript_include_tag "number_pages" %>
</head>
<body onload='number_pages'>
+
+ <!--
<div id="header">
<%= wicked_pdf_image_tag 'diner.png' %>
</div>
+ </!-->
+
<div id="content">
- openCantine
<%= yield %>
</div>
</body>