Skip to content

Commit

Permalink
ActivityParticipation, add sidebar counting on membership index
Browse files Browse the repository at this point in the history
Also improve trial_only? perf with counter cache.
  • Loading branch information
thibaudgg committed Sep 10, 2024
1 parent 9926ca5 commit 8ebd65b
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 93 deletions.
2 changes: 1 addition & 1 deletion app/admin/activity_participation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
side_panel t(".total") do
all = collection.unscope(:includes).offset(nil).limit(nil)
div class: "flex justify-between" do
span activities_human_name + ":"
span activities_human_name
span all.sum(:participants_count), class: "font-bold"
end
end
Expand Down
117 changes: 63 additions & 54 deletions app/admin/membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,57 @@
actions
end

sidebar :activity_participations, only: :index, if: -> {
Current.org.feature?("activity") && %w[
activity_participations_accepted_eq
activity_participations_accepted_gt
activity_participations_accepted_lt
activity_participations_demanded_eq
activity_participations_demanded_gt
activity_participations_demanded_lt
activity_participations_missing_eq
activity_participations_missing_gt
activity_participations_missing_lt
].any? { |a| params.dig(:q, a).present? }
} do
side_panel activities_human_name do
all = collection.offset(nil).limit(nil).to_a
%w[ accepted demanded missing ].each do |state|
div class: "flex justify-between" do
span t("states.activity_participation.#{state}").capitalize
span all.sum(&"activity_participations_#{state}".to_sym), class: "font-bold"
end
end
end
end

sidebar :basket_price_extra_title, only: :index, if: -> { Current.org.feature?("basket_price_extra") && params.dig(:q, :during_year).present? } do
side_panel Current.org.basket_price_extra_title, action: handbook_icon_link("basket_price_extra") do
coll =
collection
.unscope(:includes, :joins, :order)
.offset(nil).limit(nil)
.joins(:member)
.merge(Member.no_salary_basket)
baskets = Basket.billable.where(membership: coll)
if coll.where("basket_price_extra < 0").any?
div class: "flex justify-end" do
sum = baskets.where("price_extra > 0").sum("quantity * price_extra")
span cur(sum)
end
div class: "flex justify-end" do
sum = baskets.where("price_extra < 0").sum("quantity * price_extra")
span cur(sum)
end
end
div class: "flex justify-between" do
sum = baskets.sum("quantity * price_extra")
span t("active_admin.shared.sidebar_section.amount")
span cur(sum), class: "font-bold"
end
end
end

sidebar :renewal, only: :index do
side_panel t(".renewal"), action: handbook_icon_link("membership_renewal") do
renewal = MembershipsRenewal.new
Expand All @@ -103,43 +154,28 @@
else
ul do
li do
openable_count = renewal.openable.count
t(".openable_renewals",
count: openable_count,
count_link: link_to(
openable_count,
collection_path(scope: :all, q: { renewal_state_eq: :renewal_pending, during_year: Current.org.current_fiscal_year.year }))
).html_safe
link_to(
t(".openable_renewals_html", count: renewal.openable.count),
collection_path(scope: :all, q: { renewal_state_eq: :renewal_pending, during_year: Current.org.current_fiscal_year.year }))
end
if MailTemplate.active_template(:membership_renewal)
li do
renewal_opened_count = renewal.opened.count
t(".opened_renewals",
count: renewal_opened_count,
count_link: link_to(
renewal_opened_count,
collection_path(scope: :all, q: { renewal_state_eq: :renewal_opened, during_year: Current.org.current_fiscal_year.year }))
).html_safe
link_to(
t(".opened_renewals_html", count: renewal.opened.count),
collection_path(scope: :all, q: { renewal_state_eq: :renewal_opened, during_year: Current.org.current_fiscal_year.year }))
end
end
li do
renewed_count = renewal.renewed.count
t(".renewed_renewals",
count: renewed_count,
count_link: link_to(
renewed_count,
collection_path(scope: :all, q: { renewal_state_eq: :renewed, during_year: Current.org.current_fiscal_year.year }))
).html_safe
link_to(
t(".renewed_renewals_html", count: renewal.renewed.count),
collection_path(scope: :all, q: { renewal_state_eq: :renewed, during_year: Current.org.current_fiscal_year.year }))
end
li do
end_of_year = Current.org.current_fiscal_year.end_of_year
renewal_canceled_count = Membership.where(renew: false).where(ended_on: end_of_year).count
t(".canceled_renewals",
count: renewal_canceled_count,
count_link: link_to(
renewal_canceled_count,
collection_path(scope: :all, q: { renewal_state_eq: :renewal_canceled, during_year: Current.org.current_fiscal_year.year, ended_on_gteq: end_of_year, ended_on_lteq: end_of_year }))
).html_safe
link_to(
t(".canceled_renewals_html", count: renewal_canceled_count),
collection_path(scope: :all, q: { renewal_state_eq: :renewal_canceled, during_year: Current.org.current_fiscal_year.year, ended_on_gteq: end_of_year, ended_on_lteq: end_of_year }))
end
end
renewable_count = renewal.renewable.count
Expand Down Expand Up @@ -182,33 +218,6 @@
end
end

sidebar :basket_price_extra_title, only: :index, if: -> { Current.org.feature?("basket_price_extra") && params.dig(:q, :during_year).present? } do
side_panel Current.org.basket_price_extra_title, action: handbook_icon_link("basket_price_extra") do
coll =
collection
.unscope(:includes, :joins, :order)
.offset(nil).limit(nil)
.joins(:member)
.merge(Member.no_salary_basket)
baskets = Basket.billable.where(membership: coll)
if coll.where("basket_price_extra < 0").any?
div class: "flex justify-end" do
sum = baskets.where("price_extra > 0").sum("quantity * price_extra")
span cur(sum)
end
div class: "flex justify-end" do
sum = baskets.where("price_extra < 0").sum("quantity * price_extra")
span cur(sum)
end
end
div class: "flex justify-between" do
sum = baskets.sum("quantity * price_extra")
span t("active_admin.shared.sidebar_section.amount")
span cur(sum), class: "font-bold"
end
end
end

collection_action :renew_all, method: :post do
authorize!(:renew_all, Membership)
MembershipsRenewal.new.renew_all!
Expand Down
3 changes: 2 additions & 1 deletion app/models/membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def trial?
end

def trial_only?
baskets_count == baskets.trial.count
baskets_count == trial_baskets_count
end

def fiscal_year
Expand Down Expand Up @@ -482,6 +482,7 @@ def update_baskets_counts!
cols = { past_baskets_count: baskets.past.count }
if Current.org.trial_basket_count.positive?
cols[:remaning_trial_baskets_count] = baskets.coming.trial.count
cols[:trial_baskets_count] = baskets.trial.count
end
update_columns(cols)
end
Expand Down
72 changes: 36 additions & 36 deletions config/locales/active_admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1902,17 +1902,17 @@ _:
_en: Calendar
_fr: Calendrier
_it: Calendario
canceled_renewals:
canceled_renewals_html:
one:
_de: "%{count_link} Kündigung"
_en: "%{count_link} cancellation"
_fr: "%{count_link} résiliation"
_it: "%{count_link} résiliation"
_de: "<b>%{count}</b> Kündigung"
_en: "<b>%{count}</b> cancellation"
_fr: "<b>%{count}</b> résiliation"
_it: "<b>%{count}</b> résiliation"
other:
_de: "%{count_link} Kündigungen"
_en: "%{count_link} cancellations"
_fr: "%{count_link} résiliations"
_it: "%{count_link} risoluzione"
_de: "<b>%{count}</b> Kündigungen"
_en: "<b>%{count}</b> cancellations"
_fr: "<b>%{count}</b> résiliations"
_it: "<b>%{count}</b> risoluzione"
confirm:
_de: Sind Sie mehr als sicher?
_en: Are you absolutely sure?
Expand Down Expand Up @@ -2001,28 +2001,28 @@ _:
_en: Send requests (%{count})
_fr: Envoyer demandes (%{count})
_it: Inviare domande (%{count})
openable_renewals:
openable_renewals_html:
one:
_de: "%{count_link} Anfrage zu senden"
_en: "%{count_link} request to send"
_fr: "%{count_link} demande à envoyer"
_it: "%{count_link} domanda da inviare"
_de: "<b>%{count}</b> Anfrage zu senden"
_en: "<b>%{count}</b> request to send"
_fr: "<b>%{count}</b> demande à envoyer"
_it: "<b>%{count}</b> domanda da inviare"
other:
_de: "%{count_link} Anfragen zu senden"
_en: "%{count_link} requests to send"
_fr: "%{count_link} demandes à envoyer"
_it: "%{count_link} domande da inviare"
opened_renewals:
_de: "<b>%{count}</b> Anfragen zu senden"
_en: "<b>%{count}</b> requests to send"
_fr: "<b>%{count}</b> demandes à envoyer"
_it: "<b>%{count}</b> domande da inviare"
opened_renewals_html:
one:
_de: "%{count_link} offener Antrag"
_en: "%{count_link} open request"
_fr: "%{count_link} demande ouverte"
_it: "%{count_link} domanda aperta"
_de: "<b>%{count}</b> offener Antrag"
_en: "<b>%{count}</b> open request"
_fr: "<b>%{count}</b> demande ouverte"
_it: "<b>%{count}</b> domanda aperta"
other:
_de: "%{count_link} offene Anträge"
_en: "%{count_link} open requests"
_fr: "%{count_link} demandes ouvertes"
_it: "%{count_link} domande aperte"
_de: "<b>%{count}</b> offene Anträge"
_en: "<b>%{count}</b> open requests"
_fr: "<b>%{count}</b> demandes ouvertes"
_it: "<b>%{count}</b> domande aperte"
opening:
_de: Anfragen werden gesendet ...
_en: Requests being sent...
Expand Down Expand Up @@ -2064,17 +2064,17 @@ _:
_en: Renewals
_fr: Renouvellements
_it: Rinnovi
renewed_renewals:
renewed_renewals_html:
one:
_de: "%{count_link} Erneuerung"
_en: "%{count_link} renewal"
_fr: "%{count_link} renouvellement"
_it: "%{count_link} rinnovo"
_de: "<b>%{count}</b> Erneuerung"
_en: "<b>%{count}</b> renewal"
_fr: "<b>%{count}</b> renouvellement"
_it: "<b>%{count}</b> rinnovo"
other:
_de: "%{count_link} Erneuerungen"
_en: "%{count_link} renewals"
_fr: "%{count_link} renouvellements"
_it: "%{count_link} rinnovi"
_de: "<b>%{count}</b> Erneuerungen"
_en: "<b>%{count}</b> renewals"
_fr: "<b>%{count}</b> renouvellements"
_it: "<b>%{count}</b> rinnovi"
renewing:
_de: Erneuerungen am laufen...
_en: Renewing...
Expand Down
15 changes: 15 additions & 0 deletions config/locales/states.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
_:
states:
activity_participation:
accepted:
_de: akzeptiert
_en: Accepted
_fr: acceptées
_it: accettato
demanded:
_de: angefordert
_en: Requested
_fr: demandées
_it: richiesto
future:
_de: Kommend
_en: Upcoming
_fr: à venir
_it: venendo
missing:
_de: fehlende
_en: missing
_fr: manquantes
_it: mancante
pending:
_de: Zu bestätigen
_en: Pending
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class AddTrialBasketsCountToMemberships < ActiveRecord::Migration[7.2]
def change
add_column :memberships, :trial_baskets_count, :integer, default: 0

up_only do
Membership.find_each(&:update_baskets_counts!)
end
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_09_07_093843) do
ActiveRecord::Schema[7.2].define(version: 2024_09_10_092937) do
# These are extensions that must be enabled in order to support this database
enable_extension "hstore"
enable_extension "plpgsql"
Expand Down Expand Up @@ -511,6 +511,7 @@
t.integer "absences_included_annually", null: false
t.integer "absences_included", default: 0, null: false
t.integer "billing_year_division", default: 1, null: false
t.integer "trial_baskets_count", default: 0
t.index ["basket_size_id"], name: "index_memberships_on_basket_size_id"
t.index ["delivery_cycle_id"], name: "index_memberships_on_delivery_cycle_id"
t.index ["depot_id"], name: "index_memberships_on_depot_id"
Expand Down

0 comments on commit 8ebd65b

Please sign in to comment.