rubocop-autocorrect #202
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
module Expenses
|
module Expenses
|
||||||
@ -16,7 +18,7 @@ module Expenses
|
|||||||
private
|
private
|
||||||
|
|
||||||
def query
|
def query
|
||||||
<<~SQL
|
<<~SQL.squish
|
||||||
WITH guest_count AS (#{guest_count_per_status}),
|
WITH guest_count AS (#{guest_count_per_status}),
|
||||||
expense_summary AS (#{expense_summary})
|
expense_summary AS (#{expense_summary})
|
||||||
SELECT guest_count.confirmed as confirmed_guests,
|
SELECT guest_count.confirmed as confirmed_guests,
|
||||||
@ -28,7 +30,7 @@ module Expenses
|
|||||||
end
|
end
|
||||||
|
|
||||||
def expense_summary
|
def expense_summary
|
||||||
<<~SQL
|
<<~SQL.squish
|
||||||
SELECT coalesce(sum(amount) filter (where pricing_type = 'fixed'), 0) as fixed,
|
SELECT coalesce(sum(amount) filter (where pricing_type = 'fixed'), 0) as fixed,
|
||||||
coalesce(sum(amount) filter (where pricing_type = 'per_person'), 0) as variable
|
coalesce(sum(amount) filter (where pricing_type = 'per_person'), 0) as variable
|
||||||
FROM expenses
|
FROM expenses
|
||||||
@ -37,7 +39,7 @@ module Expenses
|
|||||||
end
|
end
|
||||||
|
|
||||||
def guest_count_per_status
|
def guest_count_per_status
|
||||||
<<~SQL
|
<<~SQL.squish
|
||||||
SELECT COALESCE(count(*) filter(where status = #{Guest.statuses['confirmed']}), 0) as confirmed,
|
SELECT COALESCE(count(*) filter(where status = #{Guest.statuses['confirmed']}), 0) as confirmed,
|
||||||
COALESCE(count(*) filter(where status IN (#{Guest.statuses.values_at('confirmed', 'invited', 'tentative').join(',')})), 0) as projected
|
COALESCE(count(*) filter(where status IN (#{Guest.statuses.values_at('confirmed', 'invited', 'tentative').join(',')})), 0) as projected
|
||||||
FROM guests
|
FROM guests
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
module Groups
|
module Groups
|
||||||
@ -9,13 +11,21 @@ module Groups
|
|||||||
:icon,
|
:icon,
|
||||||
:parent_id,
|
:parent_id,
|
||||||
:color,
|
:color,
|
||||||
|
*count_expressions
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def count_expressions
|
||||||
|
[
|
||||||
Arel.sql('count(*) filter (where status IS NOT NULL) as total'),
|
Arel.sql('count(*) filter (where status IS NOT NULL) as total'),
|
||||||
Arel.sql('count(*) filter (where status = 0) as considered'),
|
Arel.sql('count(*) filter (where status = 0) as considered'),
|
||||||
Arel.sql('count(*) filter (where status = 10) as invited'),
|
Arel.sql('count(*) filter (where status = 10) as invited'),
|
||||||
Arel.sql('count(*) filter (where status = 20) as confirmed'),
|
Arel.sql('count(*) filter (where status = 20) as confirmed'),
|
||||||
Arel.sql('count(*) filter (where status = 30) as declined'),
|
Arel.sql('count(*) filter (where status = 30) as declined'),
|
||||||
Arel.sql('count(*) filter (where status = 40) as tentative'),
|
Arel.sql('count(*) filter (where status = 40) as tentative')
|
||||||
)
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user