--- /dev/null
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
--- /dev/null
+// Place all the styles related to the Paiements controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
--- /dev/null
+class PaiementsController < ApplicationController
+ before_action :set_paiement, only: [:show, :edit, :update, :destroy]
+
+ # GET /paiements
+ # GET /paiements.json
+ def index
+ authorize Paiement
+
+ @paiements = Paiement.all
+
+
+ @paiements = current_user.organisation.paiements
+
+ params[:date] ||= Date.today
+
+ unless params[:date].blank?
+ @paiements = @paiements.where("DATE(date) = ?", params[:date])
+ end
+
+ unless params[:nom].blank?
+ @paiements = @paiements.joins(:compte).where("UPPER(comptes.nom) like ?", "%#{params[:nom].upcase}%")
+ end
+
+ @paiements = @paiements.paginate(page: params[:page])
+
+ end
+
+ # GET /paiements/1
+ # GET /paiements/1.json
+ def show
+ authorize Paiement
+ end
+
+ # GET /paiements/new
+ def new
+ authorize Paiement
+
+ @paiement = Paiement.new
+ @paiement.compte_id = params[:compte_id]
+ @paiement.date = Date.today
+ end
+
+ # GET /paiements/1/edit
+ def edit
+ authorize Paiement
+ end
+
+ # POST /paiements
+ # POST /paiements.json
+ def create
+ authorize Paiement
+
+ @paiement = Paiement.new(paiement_params)
+
+ respond_to do |format|
+ if @paiement.save
+ format.html { redirect_to @paiement, notice: 'Paiement was successfully created.' }
+ format.json { render :show, status: :created, location: @paiement }
+ else
+ format.html { render :new }
+ format.json { render json: @paiement.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /paiements/1
+ # PATCH/PUT /paiements/1.json
+ def update
+ authorize Paiement
+
+ respond_to do |format|
+ if @paiement.update(paiement_params)
+ format.html { redirect_to @paiement, notice: 'Paiement was successfully updated.' }
+ format.json { render :show, status: :ok, location: @paiement }
+ else
+ format.html { render :edit }
+ format.json { render json: @paiement.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /paiements/1
+ # DELETE /paiements/1.json
+ def destroy
+ authorize Paiement
+
+ @paiement.destroy
+ respond_to do |format|
+ format.html { redirect_to paiements_url, notice: 'Paiement was successfully destroyed.' }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_paiement
+ @paiement = Paiement.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def paiement_params
+ params.require(:paiement).permit(:compte_id, :date, :réf, :mode, :banque, :chèque_num, :montant, :date_remise, :mémo)
+ end
+end
--- /dev/null
+module PaiementsHelper
+end
has_many :classrooms
has_many :prestations, through: :enfants
has_many :factures
+ has_many :paiements
validates :nom, presence: true
has_many :classrooms, through: :structures
has_many :enfants, through: :comptes
has_many :factures, through: :comptes
+ has_many :paiements, through: :comptes
has_many :prestations, through: :enfants
has_many :reservations, through: :enfants
has_many :absences, through: :enfants
--- /dev/null
+class Paiement < ApplicationRecord
+ belongs_to :compte
+
+ self.per_page = 10
+
+ def self.modes
+ %w{Chèque CB Espèces Autre}
+ end
+
+ def self.banques
+ %w{AXA BNP_Paribas Banque_Populaire CIC Caisse_d'épargne Crédit_Agricole Crédit_Mutuel LA_BANQUE_POSTALE Société_Générale Autre}
+ end
+
+end
--- /dev/null
+class PaiementPolicy < ApplicationPolicy
+ class Scope < Scope
+ def resolve
+ scope.all
+ end
+ end
+end
<%= number_to_currency(@compte.factures.sum(:montant), unit: '€', precision: 2, format: "%n %u") %>
</p>
+ <p>
+ <%= link_to 'Ajouter un Paiement', new_paiement_path(compte_id: @compte.id) %>
+ </p>
+
</div>
</div>
<br />
<!DOCTYPE html>
<html>
<head>
- <title>OpenCantine5</title>
+ <title>openCantine 5</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<li class="nav-item <%= (params[:controller]=='factures' ? 'active' : '') %>">
<%= link_to factures_url, class: "nav-link" do %><i class="fas fa-file-invoice"></i></span> Factures<% end %>
</li>
+ <li class="nav-item <%= (params[:controller]=='paiements' ? 'active' : '') %>">
+ <%= link_to paiements_url, class: "nav-link" do %><i class="far fa-money-bill-alt"></i></span> Paiements<% end %>
+ </li>
</ul>
<ul class="navbar-nav navbar-right">
<% if current_user %>
--- /dev/null
+<%= bootstrap_form_with(model: paiement, local: true) do |form| %>
+ <% if paiement.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(paiement.errors.count, "error") %> prohibited this paiement from being saved:</h2>
+
+ <ul>
+ <% paiement.errors.full_messages.each do |message| %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <%= form.hidden_field :compte_id %>
+ <%= form.date_field :date %>
+ <%= form.text_field :réf %>
+ <%= form.select :mode, Paiement.modes %>
+ <%= form.select :banque, Paiement.banques %>
+ <%= form.text_field :chèque_num, label: 'Chèque N°' %>
+ <%= form.text_field :montant %>
+ <%= form.date_field :date_remise %>
+ <%= form.text_area :mémo %>
+ <%= form.submit "Enregistrer", class: "btn btn-success" %>
+
+<% end %>
--- /dev/null
+json.extract! paiement, :id, :compte_id, :réf, :mode, :banque, :chèque_num, :montant, :date_remise, :mémo, :created_at, :updated_at
+json.url paiement_url(paiement, format: :json)
--- /dev/null
+<h1>Editer Paiement</h1>
+
+<%= render 'form', paiement: @paiement %>
+
+<%= link_to 'Voir', @paiement %> |
+<%= link_to 'Retour', paiements_path %>
--- /dev/null
+<div class="pb-2 mt-4 mb-2 border-bottom">
+ <h1><i class="far fa-money-bill-alt"></i> Paiements</h1>
+</div>
+
+<%= bootstrap_form_tag url: paiements_path, method: :get do |f| %>
+ <div class="row">
+ <div class="col-sm-2"><%= f.date_field :date, value: params[:date], onchange: "this.form.submit()" %></div>
+ <div class="col"><%= f.text_field :nom, value: params[:nom], onchange: "this.form.submit()" %></div>
+ </div>
+<% end %>
+
+<table class="table table-striped table-hover">
+ <thead>
+ <tr>
+ <th>Date</th>
+ <th>Compte</th>
+ <th>Réf</th>
+ <th>Mode</th>
+ <th>Banque</th>
+ <th>Chèque num</th>
+ <th>Montant</th>
+ <th>Date remise</th>
+ <th>Mémo</th>
+ <th colspan="3"></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @paiements.each do |paiement| %>
+ <tr>
+ <td><%= l paiement.date.to_date %></td>
+ <td><%= paiement.compte.nom %></td>
+ <td><%= paiement.réf %></td>
+ <td><%= paiement.mode %></td>
+ <td><%= paiement.banque %></td>
+ <td><%= paiement.chèque_num %></td>
+ <td><%= number_to_currency(paiement.montant, unit: '€', precision: 2, format: "%n %u") %></td>
+ <td><%= paiement.date_remise %></td>
+ <td><%= paiement.mémo %></td>
+ <td><%= link_to 'Show', paiement %></td>
+ <td><%= link_to 'Edit', edit_paiement_path(paiement) %></td>
+ <td><%= link_to 'Destroy', paiement, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<br>
--- /dev/null
+json.array! @paiements, partial: "paiements/paiement", as: :paiement
--- /dev/null
+<h1>Nouveau Paiement</h1>
+
+<%= render 'form', paiement: @paiement %>
+
+<%= link_to 'Retour', paiements_path %>
--- /dev/null
+<p>
+ <strong>Compte:</strong>
+ <%= @paiement.compte.nom %>
+</p>
+
+<p>
+ <strong>Date</strong>
+ <%= @paiement.date %>
+</p>
+
+<p>
+ <strong>Réf:</strong>
+ <%= @paiement.réf %>
+</p>
+
+<p>
+ <strong>Mode:</strong>
+ <%= @paiement.mode %>
+</p>
+
+<p>
+ <strong>Banque:</strong>
+ <%= @paiement.banque %>
+</p>
+
+<p>
+ <strong>Chèque num:</strong>
+ <%= @paiement.chèque_num %>
+</p>
+
+<p>
+ <strong>Montant:</strong>
+ <%= number_to_currency(@paiement.montant, unit: '€', precision: 2, format: "%n %u") %>
+</p>
+
+<p>
+ <strong>Date remise:</strong>
+ <%= @paiement.date_remise %>
+</p>
+
+<p>
+ <strong>Mémo:</strong>
+ <%= @paiement.mémo %>
+</p>
+
+<%= link_to 'Editer', edit_paiement_path(@paiement) %> |
+<%= link_to 'Retour', paiements_path %>
--- /dev/null
+json.partial! "paiements/paiement", paiement: @paiement
Rails.application.routes.draw do
+ resources :paiements
get 'admin/index'
get 'admin/ajout_prestations'
get 'admin/ajout_factures'
--- /dev/null
+class CreatePaiements < ActiveRecord::Migration[5.2]
+ def change
+ create_table :paiements do |t|
+ t.references :compte, foreign_key: true
+ t.datetime :date
+ t.string :réf
+ t.string :mode
+ t.string :banque
+ t.string :chèque_num
+ t.decimal :montant, :precision => 4, :scale => 2, null: false, default: 0
+ t.string :date_remise
+ t.string :mémo
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class ChangeMontantPaiementPrecision < ActiveRecord::Migration[5.2]
+ def change
+ change_column :paiements, :montant, :decimal, :precision => 5, :scale => 2, null: false, default: 0
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_09_17_163847) do
+ActiveRecord::Schema.define(version: 2019_09_23_141337) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
t.string "zone"
end
+ create_table "paiements", force: :cascade do |t|
+ t.bigint "compte_id"
+ t.datetime "date"
+ t.string "réf"
+ t.string "mode"
+ t.string "banque"
+ t.string "chèque_num"
+ t.decimal "montant", precision: 5, scale: 2, default: "0.0", null: false
+ t.string "date_remise"
+ t.string "mémo"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["compte_id"], name: "index_paiements_on_compte_id"
+ end
+
create_table "prestation_types", force: :cascade do |t|
t.bigint "organisation_id"
t.string "nom", default: "", null: false
add_foreign_key "facture_lignes", "factures"
add_foreign_key "facture_lignes", "prestation_types"
add_foreign_key "factures", "comptes"
+ add_foreign_key "paiements", "comptes"
add_foreign_key "prestation_types", "organisations"
add_foreign_key "prestations", "enfants"
add_foreign_key "prestations", "factures"