diff --git a/app/admin/activity_participation.rb b/app/admin/activity_participation.rb index 5916da0b..33d8789e 100644 --- a/app/admin/activity_participation.rb +++ b/app/admin/activity_participation.rb @@ -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 diff --git a/app/admin/membership.rb b/app/admin/membership.rb index 428b3dcd..c989de4d 100644 --- a/app/admin/membership.rb +++ b/app/admin/membership.rb @@ -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 @@ -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 @@ -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! diff --git a/app/models/membership.rb b/app/models/membership.rb index ebb8d897..46cc9c6d 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -172,7 +172,7 @@ def trial? end def trial_only? - baskets_count == baskets.trial.count + baskets_count == trial_baskets_count end def fiscal_year @@ -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 diff --git a/config/locales/active_admin.yml b/config/locales/active_admin.yml index d2e2e585..eb54b9ba 100644 --- a/config/locales/active_admin.yml +++ b/config/locales/active_admin.yml @@ -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: "%{count} Kündigung" + _en: "%{count} cancellation" + _fr: "%{count} résiliation" + _it: "%{count} résiliation" other: - _de: "%{count_link} Kündigungen" - _en: "%{count_link} cancellations" - _fr: "%{count_link} résiliations" - _it: "%{count_link} risoluzione" + _de: "%{count} Kündigungen" + _en: "%{count} cancellations" + _fr: "%{count} résiliations" + _it: "%{count} risoluzione" confirm: _de: Sind Sie mehr als sicher? _en: Are you absolutely sure? @@ -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: "%{count} Anfrage zu senden" + _en: "%{count} request to send" + _fr: "%{count} demande à envoyer" + _it: "%{count} 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: "%{count} Anfragen zu senden" + _en: "%{count} requests to send" + _fr: "%{count} demandes à envoyer" + _it: "%{count} 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: "%{count} offener Antrag" + _en: "%{count} open request" + _fr: "%{count} demande ouverte" + _it: "%{count} 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: "%{count} offene Anträge" + _en: "%{count} open requests" + _fr: "%{count} demandes ouvertes" + _it: "%{count} domande aperte" opening: _de: Anfragen werden gesendet ... _en: Requests being sent... @@ -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: "%{count} Erneuerung" + _en: "%{count} renewal" + _fr: "%{count} renouvellement" + _it: "%{count} rinnovo" other: - _de: "%{count_link} Erneuerungen" - _en: "%{count_link} renewals" - _fr: "%{count_link} renouvellements" - _it: "%{count_link} rinnovi" + _de: "%{count} Erneuerungen" + _en: "%{count} renewals" + _fr: "%{count} renouvellements" + _it: "%{count} rinnovi" renewing: _de: Erneuerungen am laufen... _en: Renewing... diff --git a/config/locales/states.yml b/config/locales/states.yml index 8c719fbe..135edf91 100644 --- a/config/locales/states.yml +++ b/config/locales/states.yml @@ -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 diff --git a/db/migrate/20240910092937_add_trial_baskets_count_to_memberships.rb b/db/migrate/20240910092937_add_trial_baskets_count_to_memberships.rb new file mode 100644 index 00000000..cfdc3a16 --- /dev/null +++ b/db/migrate/20240910092937_add_trial_baskets_count_to_memberships.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 456dbf72..9cf89718 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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"