Skip to content

Commit

Permalink
fix all insieme wagon specs
Browse files Browse the repository at this point in the history
  • Loading branch information
njaeggi committed Jun 28, 2024
1 parent 57947f8 commit acc56b6
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 105 deletions.
8 changes: 4 additions & 4 deletions app/domain/fp2015/course_reporting/aggregation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def total(course_records)
end

def select_clause
columns = ['event_course_records.year',
'event_course_records.kursart',
'event_course_records.inputkriterien',
'event_course_records.event_id']
columns = ['MIN(event_course_records.year) AS year',
'MIN(event_course_records.kursart) AS kursart',
'MIN(event_course_records.inputkriterien) AS inputkriterien',
'MIN(event_course_records.event_id) AS event_id']
columns.concat(sql_summed_attrs)
columns << sql_sum_unterkunft
columns.join(', ')
Expand Down
11 changes: 6 additions & 5 deletions app/domain/fp2020/course_reporting/aggregation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def build_totals(hash)
end

def records_for(attr, value)
records.select { |record| record.send(attr) == value }
Event::Course.first.fachkonzept
records.select { |record| record.event.send(attr) == value }
end

def find_record(fachkonzept, kursart)
Expand Down Expand Up @@ -137,10 +138,10 @@ def total(course_records)
end

def select_clause
columns = ['event_course_records.year',
'event_course_records.kursart',
'events.fachkonzept',
'event_course_records.event_id']
columns = ['MIN(event_course_records.year) AS year',
'MIN(event_course_records.kursart) AS kursart',
'MIN(event_course_records.inputkriterien) AS inputkriterien',
'MIN(event_course_records.event_id) AS event_id']
columns.concat(sql_summed_attrs)
columns << sql_sum_unterkunft
columns.join(', ')
Expand Down
4 changes: 2 additions & 2 deletions app/domain/fp2020/course_reporting/client_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def group_canton_participants

def group_canton_participants_relation # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
columns = [
'`groups`.id AS group_id',
'MAX(groups.id) AS group_id',
'events.leistungskategorie AS event_leistungskategorie'
]

Expand Down Expand Up @@ -104,7 +104,7 @@ def group_canton_participants_relation # rubocop:disable Metrics/MethodLength,Me
CASE events.leistungskategorie
WHEN 'tp' THEN 0
ELSE
CASE events.type
CASE MAX(events.type)
WHEN 'Event::AggregateCourse' THEN
SUM(COALESCE(event_course_records.tage_weitere, 0))
ELSE
Expand Down
8 changes: 4 additions & 4 deletions app/domain/fp2020/time_record/lufeb_pro_verein.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def time_records # rubocop:disable Metrics/MethodLength
.group(:group_id)
.select([
'group_id',
'SUM(total_lufeb_general) AS `general`',
'SUM(total_lufeb_specific) AS `specific`',
'SUM(total_lufeb_promoting) AS `promoting`',
'SUM(lufeb_grundlagen) AS `lufeb_grundlagen`',
'SUM(total_lufeb_general) AS general',
'SUM(total_lufeb_specific) AS specific',
'SUM(total_lufeb_promoting) AS promoting',
'SUM(lufeb_grundlagen) AS lufeb_grundlagen',
'SUM(kurse_grundlagen) AS kurse_grundlagen'
].join(', '))
.all
Expand Down
10 changes: 5 additions & 5 deletions app/domain/fp2022/course_reporting/aggregation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def build_totals(hash)
end

def records_for(attr, value)
records.select { |record| record.send(attr) == value }
records.select { |record| record.event.send(attr) == value }
end

def find_record(fachkonzept, kursart)
Expand Down Expand Up @@ -137,10 +137,10 @@ def total(course_records)
end

def select_clause
columns = ['event_course_records.year',
'event_course_records.kursart',
'events.fachkonzept',
'event_course_records.event_id']
columns = ['MIN(event_course_records.year) AS year',
'MIN(event_course_records.kursart) AS kursart',
'MIN(event_course_records.inputkriterien) AS inputkriterien',
'MIN(event_course_records.event_id) AS event_id']
columns.concat(sql_summed_attrs)
columns << sql_sum_unterkunft
columns.join(', ')
Expand Down
4 changes: 2 additions & 2 deletions app/domain/fp2022/course_reporting/client_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def group_canton_participants

def group_canton_participants_relation # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
columns = [
'`groups`.id AS group_id',
'MAX(groups.id) AS group_id',
'events.leistungskategorie AS event_leistungskategorie'
]

Expand Down Expand Up @@ -104,7 +104,7 @@ def group_canton_participants_relation # rubocop:disable Metrics/MethodLength,Me
CASE events.leistungskategorie
WHEN 'tp' THEN 0
ELSE
CASE events.type
CASE MAX(events.type)
WHEN 'Event::AggregateCourse' THEN
SUM(COALESCE(event_course_records.tage_weitere, 0))
ELSE
Expand Down
8 changes: 4 additions & 4 deletions app/domain/fp2022/time_record/lufeb_pro_verein.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def time_records # rubocop:disable Metrics/MethodLength
.group(:group_id)
.select([
'group_id',
'SUM(total_lufeb_general) AS `general`',
'SUM(total_lufeb_specific) AS `specific`',
'SUM(total_lufeb_promoting) AS `promoting`',
'SUM(lufeb_grundlagen) AS `lufeb_grundlagen`',
'SUM(total_lufeb_general) AS general',
'SUM(total_lufeb_specific) AS specific',
'SUM(total_lufeb_promoting) AS promoting',
'SUM(lufeb_grundlagen) AS lufeb_grundlagen',
'SUM(kurse_grundlagen) AS kurse_grundlagen',
].join(', '))
.all
Expand Down
14 changes: 7 additions & 7 deletions app/domain/statistics/vereinsmitglieder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def type_counts
end

def type_counts_per_layer
result = Role.connection.execute(type_counts_per_layer_query)
result = Role.connection.execute(type_counts_per_layer_query).to_a
result.each_with_object({}) do |row, hash|
hash[row[0]] ||= Hash.new(0)
hash[row[0]][row[1]] = row[2]
hash[row["layer_group_id"]] ||= Hash.new(0)
hash[row["layer_group_id"]][row["type_index"]] = row["count"]
end
end

Expand All @@ -55,16 +55,16 @@ def type_counts_per_layer_query

def person_roles_per_layer_query
<<-SQL
SELECT `groups`.layer_group_id AS layer_group_id,
SELECT "groups".layer_group_id AS layer_group_id,
MIN(#{type_index_switch}) AS type_index,
roles.person_id AS person_id
FROM roles
INNER JOIN `groups` `groups` ON `groups`.id = roles.group_id
INNER JOIN `groups` layers ON layers.id = `groups`.layer_group_id
INNER JOIN "groups" "groups" ON "groups".id = roles.group_id
INNER JOIN "groups" layers ON layers.id = "groups".layer_group_id
WHERE layers.type = '#{Group::Regionalverein.sti_name}' AND
roles.deleted_at IS NULL AND
roles.type IN (#{role_types_param})
GROUP BY `groups`.layer_group_id,
GROUP BY "groups".layer_group_id,
roles.person_id
SQL
end
Expand Down
12 changes: 0 additions & 12 deletions app/indices/person_index.rb

This file was deleted.

5 changes: 4 additions & 1 deletion app/models/insieme/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module Insieme::Person

Person::PUBLIC_ATTRS << :number << :salutation << :correspondence_language

Person::SEARCHABLE_ATTRS << :number << :salutation << :canton
include PgSearchable

ADDRESS_TYPES.each do |prefix|
ADDRESS_FIELDS.each do |field|
Person::PUBLIC_ATTRS << :"#{prefix}_#{field}"
Expand Down Expand Up @@ -72,7 +75,7 @@ def grouped_active_membership_roles
if @grouped_active_membership_roles.nil?
active_memberships = roles.includes(:group)
.joins(:group)
.where(groups: { type: ::Group::Aktivmitglieder })
.where(groups: { type: ::Group::Aktivmitglieder.sti_name })
@grouped_active_membership_roles = Hash.new { |h, k| h[k] = [] }
active_memberships.each do |role|
@grouped_active_membership_roles[role.group] << role
Expand Down
34 changes: 18 additions & 16 deletions spec/domain/fp2015/export/tabular/statistics/group_figures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ def export(figures)
-200000.0, 0.0, 0.0, 0.0, 0.0]

expect(data.second).to eq [
'Biel-Seeland', 'Bern', nil, 3115,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0, 0, 0,
0, 0, 0, 0,
0,
0.0, 0.0, 0.0, 0.0, 0.0,
-200000.0, 0.0, 0.0, 0.0, 0.0]

expect(data.third).to eq [
'Freiburg', 'Freiburg', nil, 12607,
1, 0.0, 1545.0, 0.0, 0.0, 1545.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
Expand All @@ -200,7 +216,7 @@ def export(figures)
2.0, 1.6, (21.0/1900).round(5), (21.0/1900).round(5), (21.0/1900).round(5),
-185550.0, 0.0, 1100.0, 0.0, -1100.0]

expect(data.third).to eq [
expect(data.fourth).to eq [
'Kanton Bern', 'Bern', nil, 2024,
2, 1100.0, 1000.0, 1111.0, 0.0, 2111.0,
1, 800.0, 5400.0, 0.0, 0.0, 5400.0,
Expand All @@ -216,21 +232,7 @@ def export(figures)
0.25, 0.25, (50.0/1900).round(5), (50.0/1900).round(5), (20.0/1900).round(5),
10_074_000.0, 100.0, 2050.0, 20.0, -2000.0]

expect(data.fourth).to eq [
'Biel-Seeland', 'Bern', nil, 3115,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0.0, 0.0, 0.0, 0.0, 0.0,
0, 0, 0, 0,
0, 0, 0, 0,
0,
0.0, 0.0, 0.0, 0.0, 0.0,
-200000.0, 0.0, 0.0, 0.0, 0.0]

end

def create_course(year, group_key, leistungskategorie, kategorie, attrs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
context 'for employee time' do
it 'contains all data' do
data = export
expect(data[2]).to eq(['Kanton Bern',
expect(data[3]).to eq(['Kanton Bern',
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0,
200, nil, nil, 330, 530,
nil, nil, nil, nil, nil, 0,
Expand Down Expand Up @@ -153,7 +153,7 @@

it 'contains all data' do
data = export
expect(data[2]).to eq(['Kanton Bern',
expect(data[3]).to eq(['Kanton Bern',
300,
nil,
nil,
Expand Down
34 changes: 17 additions & 17 deletions spec/domain/fp2020/export/tabular/statistics/group_figures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,23 @@
}))
end

it 'for Freiburg' do
it 'for Biel-Seeland' do
expect(data.second).to include(empty_row.merge({
"Vollständiger Name" => "Biel-Seeland",
'Kanton' => 'Bern',
'BSV Nummer' => 3115,

"Geschlüsseltes Kapitalsubstrat nach Art. 74" => -200_000.0,
"Faktor Kapitalsubstrat" => 0.0,
"Totaler Aufwand gemäss FIBU" => 0.0,
"Vollkosten nach Umlagen Betrieb Art. 74" => 0.0,
"IV-Beitrag" => 0.0,
"Deckungsbeitrag 4" => 0.0,
}))
end

it 'for Freiburg' do
expect(data.third).to include(empty_row.merge({
"Vollständiger Name"=>"Freiburg",
"Kanton"=>"Freiburg",
"VID"=>nil,
Expand Down Expand Up @@ -438,7 +453,7 @@

it 'for Kanton Bern' do
# 30 Stunden für LUFEB / 1900 BSV-Stunden
expect(data.third).to include(empty_row.merge({
expect(data.fourth).to include(empty_row.merge({
"Vollständiger Name" => "Kanton Bern",
"Kanton" => "Bern",
"BSV Nummer" => 2024,
Expand Down Expand Up @@ -503,21 +518,6 @@
"Deckungsbeitrag 4" => -2000.0,
}))
end

it 'for Biel-Seeland' do
expect(data.fourth).to include(empty_row.merge({
"Vollständiger Name" => "Biel-Seeland",
'Kanton' => 'Bern',
'BSV Nummer' => 3115,

"Geschlüsseltes Kapitalsubstrat nach Art. 74" => -200_000.0,
"Faktor Kapitalsubstrat" => 0.0,
"Totaler Aufwand gemäss FIBU" => 0.0,
"Vollkosten nach Umlagen Betrieb Art. 74" => 0.0,
"IV-Beitrag" => 0.0,
"Deckungsbeitrag 4" => 0.0,
}))
end
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
context 'for employee time' do
it 'contains all data' do
data = export
expect(data[2]).to eq(["Kanton Bern",
expect(data[3]).to eq(["Kanton Bern",
nil, nil, nil, nil, 0,
nil, nil, nil, nil, 0,
nil, nil, nil, nil, 0, 0,
Expand Down Expand Up @@ -163,7 +163,7 @@

it 'contains all data' do
data = export
expect(labels.zip(data[2]).to_h).to eq empty_row.merge({
expect(labels.zip(data[3]).to_h).to eq empty_row.merge({
"Gruppe" => 'Kanton Bern',

"Allgemeine Medien- und Öffentlichkeitsarbeit" => 300,
Expand Down
Loading

0 comments on commit acc56b6

Please sign in to comment.