private
def user_not_authorized
- flash[:alert] = "You are not authorized to perform this action."
+ flash[:alert] = "Vous n'êtes pas autorisé.e à effectuer cette action."
redirect_to(request.referrer || root_path)
end
end
# GET /factures/new
def new
+ authorize Facture
+
@facture = Facture.new
end
# GET /factures/1/edit
def edit
- @prestation_types = current_user.organisation.prestation_types
+ authorize Facture
+ @prestation_types = current_user.organisation.prestation_types
1.times { @facture.facture_lignes.build }
end
# POST /factures
# POST /factures.json
def create
+ authorize Facture
+
@facture = Facture.new(facture_params)
respond_to do |format|
# PATCH/PUT /factures/1
# PATCH/PUT /factures/1.json
def update
+ authorize Facture
+
respond_to do |format|
if @facture.update(facture_params)
format.html { redirect_to @facture, notice: 'Facture modifiée avec succès.' }
# DELETE /factures/1.json
def destroy
authorize Facture
-
- # marquer les prestations liées à cette facture comme non facturées
- @facture.prestations.update(facture_id: nil)
@facture.destroy
respond_to do |format|
default_scope { order("réf DESC") }
+ before_destroy :maj_prestations
+
def self.fabrique_une_référence_facture(index)
"#{Date.today.month}-#{Date.today.year}/#{index}"
end
end
+private
+ def maj_prestations
+ # libérer les prestations liées à la facture qui va être détruite (= prestations non facturées)
+ self.prestations.update(facture_id: nil)
+ end
+
end
scope.all
end
end
+
+ def show?
+ user.admin?
+ end
+
+ def edit?
+ user.admin?
+ end
+
+ def to_xls?
+ user.admin?
+ end
+
end
</table>
</p>
-<%= link_to new_enfant_path(compte_id: @compte), class: "btn text-primary" do %>
- <i class="fas fa-plus-circle"></i> Ajouter un enfant
+ <% if policy(Enfant).new? %>
+ <%= link_to new_enfant_path(compte_id: @compte), class: "btn text-primary" do %>
+ <i class="fas fa-plus-circle"></i> Ajouter un enfant
+ <% end %>
<% end %>
<br>
-<%= link_to "Export XLS", url_for(params.permit(:structure_id, :date, :search).merge(format: :xls)) %>
+<% if policy(Facture).to_xls? %>
+ <%= link_to "Export XLS", url_for(params.permit(:structure_id, :date, :search).merge(format: :xls)) %>
+<% end %>
\ No newline at end of file
<% end %>
<% end %>
|
-<%= link_to edit_facture_path(@facture), class: "btn text-primary" do %>
+<%= link_to edit_facture_path(@facture), class: "btn text-primary" do %>
<i class="far fa-edit"></i> Editer
<% end %>
|