Skip to content

Commit

Permalink
Afficher l'état de la payment_request dans la page de détail de l'élè…
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicolas1 and pskl authored Oct 25, 2024
1 parent b747ede commit 8e30143
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
30 changes: 5 additions & 25 deletions app/facades/classes_facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def nb_pfmps(class_id, state)
end

def nb_payment_requests(class_id, states)
count = 0
states.each do |state|
count += payments_requests_by_classe_and_state.dig(class_id, state.to_s) || 0
end
count
ASP::PaymentRequest.latest_per_pfmp
.joins(pfmp: { schooling: :classe })
.where(classes: { id: class_id })
.in_state(states)
.count
end

private
Expand All @@ -57,10 +57,6 @@ def pfmps_by_classe_and_state
@pfmps_by_classe_and_state ||= group_pfmps_by_classe_and_state
end

def payments_requests_by_classe_and_state
@payments_requests_by_classe_and_state ||= group_payments_requests_by_classe_and_state
end

def group_pfmps_by_classe_and_state
counts = {}

Expand All @@ -76,20 +72,4 @@ def group_pfmps_by_classe_and_state

counts
end

def group_payments_requests_by_classe_and_state
counts = {}

ASP::PaymentRequest.joins(:schooling)
.joins("LEFT JOIN asp_payment_request_transitions ON asp_payment_request_transitions.asp_payment_request_id = asp_payment_requests.id AND asp_payment_request_transitions.most_recent = true") # rubocop:disable Layout/LineLength
.where(schoolings: { classe_id: @classes.pluck(:id) })
.group("schoolings.classe_id", "COALESCE(asp_payment_request_transitions.to_state, 'pending')")
.count
.each do |(class_id, state), count|
counts[class_id] ||= {}
counts[class_id][state.presence || "pending"] = count
end

counts
end
end
8 changes: 4 additions & 4 deletions app/views/classes/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
= pfmps_status_count_badge :completed, @classes_facade.nb_pfmps(classe.id, :completed)
= pfmps_status_count_badge :validated, @classes_facade.nb_pfmps(classe.id, :validated)
%td
= payment_requests_status_count_badge :pending, @classes_facade.nb_payment_requests(classe.id, %i[pending ready])
= payment_requests_status_count_badge :sent, @classes_facade.nb_payment_requests(classe.id, %i[sent integrated])
= payment_requests_status_count_badge :incomplete, @classes_facade.nb_payment_requests(classe.id, %i[incomplete rejected unpaid])
= payment_requests_status_count_badge :paid, @classes_facade.nb_payment_requests(classe.id, %i[paid])
= payment_requests_status_count_badge :pending, @classes_facade.nb_payment_requests(classe, %i[pending ready])
= payment_requests_status_count_badge :sent, @classes_facade.nb_payment_requests(classe, %i[sent integrated])
= payment_requests_status_count_badge :incomplete, @classes_facade.nb_payment_requests(classe, %i[incomplete rejected unpaid])
= payment_requests_status_count_badge :paid, @classes_facade.nb_payment_requests(classe, %i[paid])
4 changes: 4 additions & 0 deletions app/views/pfmps/_pfmp_student_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
%caption Liste des PFMPs de l'élève
%thead
%th{scope: "col"} PFMP
%th{scope: "col"} Paiements
%th{scope: "col"} Nombre de jours
%th{scope: "col"} Montant
%tbody
- pfmps.each do |pfmp|
%tr
%td= link_to_if(classe.establishment.eql?(current_establishment), pfmp.listing_to_s.html_safe, school_year_class_schooling_pfmp_path(classe.school_year, classe, schooling, pfmp), title: "Voir la PFMP #{pfmp.full_dates}")
%td
-if pfmp.latest_payment_request.present?
= pfmp.latest_payment_request.status_badge
%td= pfmp.day_count
%td
%strong= number_to_currency(pfmp.amount)
Expand Down
12 changes: 12 additions & 0 deletions features/paiements.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,15 @@ Fonctionnalité: Gestion des paiements
Quand je consulte la dernière PFMP
Alors je peux voir une demande de paiement "échoué" de 90 euros
Et je peux changer le nombre de jours de la PFMP à 8

Scénario: Seule la dernière demande de paiement d'une PFMP est affichée
Sachant que la dernière PFMP de "Marie Curie" en classe de "A1" a une requête de paiement rejetée
Et que je consulte la liste des classes
Alors la page contient "Bloquées"
Quand je consulte le profil de "Marie Curie" dans la classe de "A1"
Quand je consulte la dernière PFMP
Et que je coche la case de responsable légal
Et que je clique sur "Relancer une demande de paiement"
Lorsque je consulte la liste des classes
Alors la page contient "En attente"
Et la page ne contient pas "Bloquées"

0 comments on commit 8e30143

Please sign in to comment.