send_file ("public/openCantine5-Exemple_de_fichier_import.xls")
end
+ def envoyer_factures
+ authorize (:admin)
+ end
+
+ def envoyer_factures_do
+ authorize (:admin)
+
+ organisation = current_user.organisation
+ factures = organisation.factures.non_envoyées
+
+ @stdout_stream = capture_stdout do
+ puts "Hello mailer"
+ factures.each do |f|
+ puts f.réf
+ end
+ end
+ end
+
private
def message_import_log(model)
if model.valid?
--- /dev/null
+class FactureMailer < ApplicationMailer
+ default from: "nepasrepondre@opencantine.net"
+
+ def facture_email
+ @compte = Compte.first
+ @email = @compte.contacts.first.email
+
+ mail(to: @email, subject: "Facture XXX")
+ end
+end
audited
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
validates_uniqueness_of :réf, scope: [:compte_id]
- self.per_page = 10
+ accepts_nested_attributes_for :facture_lignes, reject_if: proc { |attributes| attributes[:intitulé].blank? }, allow_destroy: true
default_scope { order(Arel.sql("factures.réf DESC")) }
+ scope :non_envoyées, -> { where(Arel.sql("factures.envoyée_le IS NULL")) }
before_destroy :maj_prestations
+ self.per_page = 10
+
def self.fabrique_une_référence_facture(index)
"#{Date.today.month}-#{Date.today.year}/#{index}"
end
user.admin?
end
+ def envoyer_factures?
+ user.admin?
+ end
+
+ def envoyer_factures_do?
+ envoyer_factures?
+ end
+
end
--- /dev/null
+<div class="pb-2 mt-4 mb-2 border-bottom">
+ <h1><i class="fas fa-calendar-day"></i> Envoyer les factures</h1>
+</div>
+
+<p>
+ <h4>Permet l'envoi par email des factures vérifiées</h4>
+ <small>L'adresse du destinataire est celle du premier contact du compte.</small>
+</p>
+<br />
+
+<%= bootstrap_form_with(url: "envoyer_factures_do", method: :post, local: true) do |form| %>
+ <%= form.check_box :envoyer, {custom: :switch, label: "Envoyer les emails ? (non: visualisation seulement, ne fait rien de définitif :)"} %>
+ <br /><br />
+ <%= form.submit "Lancer", class: "btn btn-success" %>
+<% end %>
+
+
--- /dev/null
+<div class="pb-2 mt-4 mb-2 border-bottom">
+ <h1><i class="fas fa-calendar-day"></i> Envoyer factures</h1>
+</div>
+
+<pre>
+ <%= simple_format(@stdout_stream) %>
+</pre>
\ No newline at end of file
</h5>
</li>
+ <li class="list-group-item"></li>
+
+ <li class="list-group-item">
+ <h5>
+ <i class="fas fa-paper-plane"></i>
+ <%= link_to admin_envoyer_factures_path, class: "text-dark" do %>Envoyer les factures<% end %>
+ </h5>
+ </li>
+
</ul>
</div>
--- /dev/null
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
+ </head>
+ <body>
+ <h1>Facture...</h1>
+ <p>
+
+ </p>
+ </body>
+</html>
\ No newline at end of file
get :audit
get :import
get :exemple_fichier_import_xls
+ get :envoyer_factures
post :ajout_prestations_do
post :ajout_factures_do
post :import_do
+ post :envoyer_factures_do
end
root 'comptes#index'