@solde = @total_paiements - @total_factures
end
+ def balance
+ @compte = Compte.friendly.find(params[:compte_id])
+ @releve = []
+ @solde = 0.00
+ @debit = 0.00
+ @credit = 0.00
+
+ @compte.factures.each do |f|
+ @releve << { id: f.id, date: f.date.to_date, type: "Facture", ref: f.réf, mnt: f.montant, solde: 0 }
+ end
+
+ @compte.paiements.each do |p|
+ @releve << { id: p.id, date: p.date.to_date, type: "Paiement", ref: p.réf, mnt: p.montant, solde: 0 }
+ end
+
+ @releve = @releve.sort_by { |r| r[:date] }
+
+ @releve.each do |r|
+ mnt = r[:mnt]
+ if r[:type] == "Facture"
+ @debit += mnt
+ @solde -= mnt
+ else
+ @credit += mnt
+ @solde += mnt
+ end
+ r[:solde] = @solde
+ end
+ end
+
# GET /comptes/new
def new
authorize Compte
--- /dev/null
+<div class="pb-2 mt-4 mb-2 border-bottom">
+ <h1><i class="fas fa-balance-scale"></i> Balance</h1>
+</div>
+
+<p>
+ <h3>Compte: <%= @compte.nom %></h3>
+ Solde à ce jour : <%= number_to_currency(@solde, unit:'€') %>
+</p>
+
+<table class="table table-hover table-striped">
+ <thead>
+ <th>Date</th>
+ <th>Type</th>
+ <th class="text-right">Référence</th>
+ <th class="text-right">Débit</th>
+ <th class="text-right">Crédit</th>
+ <th class="text-right">Solde</th>
+ </thead>
+
+ <tbody>
+ <% @releve.each do |r| %>
+ <tr>
+ <td><%= l r[:date] %></td>
+ <td><%= r[:type] %></td>
+ <% if r[:type] == "Facture" %>
+ <td class="text-right"><%= link_to r[:ref], facture_path(r[:id], format: :pdf) %></td>
+ <td class="text-right"><%= number_to_currency(r[:mnt], unit:'€') %></td>
+ <td />
+ <% else %>
+ <td class="text-right"><%= r[:ref] %></td>
+ <td />
+ <td class="text-right"><%= number_to_currency(r[:mnt], unit:'€') %></td>
+ <% end %>
+ <td class="text-right"><%= number_to_currency(r[:solde], unit:'€') %></td>
+ </tr>
+ <% end %>
+ </tbody>
+
+ <tfoot>
+ <tr>
+ <th><%= l Date.today %></th>
+ <th>SOLDE</th>
+ <th />
+ <th class="text-right"><%= number_to_currency(@debit, unit:'€') %></th>
+ <th class="text-right"><%= number_to_currency(@credit, unit:'€') %></th>
+ <th class="text-right"><%= number_to_currency(@solde, unit:'€') %></th>
+ </tr>
+ </tfoot>
+
+</table>
Rails.application.routes.draw do
- resources :paiements
- get 'admin/index'
- get 'admin/ajout_prestations'
- get 'admin/ajout_factures'
- 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'
- post 'admin/import_do'
-
devise_for :users, controllers: {registrations: 'registrations'}
resources :users_admin, controller: 'users'
+ resources :comptes do
+ get :balance
+ end
+
resources :factures
resources :prestations
resources :tarifs
resources :tarif_types
resources :prestation_types
resources :enfants
- resources :comptes
resources :structures
resources :organisations
+ resources :paiements
+
+ namespace :admin do
+ get :index
+ get :ajout_prestations
+ get :ajout_factures
+ get :tarifs
+ get :audit
+ get :import
+ get :exemple_fichier_import_xls
+
+ post :ajout_prestations_do
+ post :ajout_factures_do
+ post :import_do
+ end
root 'comptes#index'