Skip to content

Commit 488b17a

Browse files
svenweyKagemaru
authored andcommitted
calculate figures (budget, witschaftlichkeit, Verrechneter Stundensatz) about order for all times dwspite only for selected period
1 parent 72808bc commit 488b17a

File tree

6 files changed

+59
-24
lines changed

6 files changed

+59
-24
lines changed

app/assets/stylesheets/_orders.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ h1.top {
5757
.cockpit-header {
5858
@include clearfix;
5959
margin: 0 auto;
60+
}
6061

61-
.filter-elements {
62-
margin-bottom: 20px;
63-
}
62+
.filter-elements {
63+
margin-top: 30px;
64+
margin-bottom: 10px;
6465
}
6566

6667
.cockpit-header-item {

app/domain/order/cockpit.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ def budget_open
2626

2727
# Ist-R[currency] / Ist-V[h]
2828
def billed_rate
29-
billable_hours.positive? ? billed_amount / billable_hours : nil
29+
billable_hours.positive? ? billed_amount / overall_billable_hours : nil
3030
end
3131

3232
# Ist-R[h] / Ist[h] x 100
3333
def cost_effectiveness_current
34-
result = (order.invoices.where.not(status: 'cancelled').sum(:total_hours).to_f / total_hours) * 100.0
34+
result = (order.invoices.where.not(status: 'cancelled').sum(:total_hours).to_f / overall_total_hours) * 100.0
3535
result.finite? ? result.round : EM_DASH
3636
end
3737

3838
# (Ist[h]-Ist-NV[h]) / Ist[h] x 100
3939
def cost_effectiveness_forecast
40-
result = (1 - (not_billable_hours / total_hours)) * 100.0
40+
result = (1 - (overall_not_billable_hours / overall_total_hours)) * 100.0
4141
result.finite? ? result.round : EM_DASH
4242
end
4343

@@ -59,6 +59,18 @@ def total_hours
5959
total.cells[:supplied_services].hours.to_f
6060
end
6161

62+
def overall_not_billable_hours
63+
total.order_info[:overall_not_billable_hours].to_f
64+
end
65+
66+
def overall_billable_hours
67+
overall_total_hours - overall_not_billable_hours
68+
end
69+
70+
def overall_total_hours
71+
total.order_info[:overall_supplied_services_hours].to_f
72+
end
73+
6274
def build_rows(period)
6375
if sub_levels?
6476
rows = accounting_posts.collect { |p| AccountingPostRow.new(p, period) }

app/domain/order/cockpit/accounting_post_row.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
class Order
99
class Cockpit
1010
class AccountingPostRow < Row
11-
attr_reader :cells, :accounting_post
11+
attr_reader :cells, :accounting_post, :row_info
1212

1313
def initialize(accounting_post, period, label = nil)
1414
super(label || accounting_post.to_s)
1515
@period = period
1616
@accounting_post = accounting_post
1717
@cells = build_cells
18+
@row_info = build_info
1819
end
1920

2021
def portfolio
@@ -31,14 +32,22 @@ def billable_hours
3132
accounting_post_hours[true] || 0
3233
end
3334

34-
def overall_billable_hours
35-
overall_acoounting_post_hours[true] || 0
35+
def to_end_billable_hours
36+
custom_acoounting_post_hours(Period.new(nil, @period.end_date))[true] || 0
3637
end
3738

3839
def not_billable_hours
3940
accounting_post_hours[false] || 0
4041
end
4142

43+
def overall_supplied_services_hours
44+
custom_acoounting_post_hours(Period.new(nil, nil)).values.sum
45+
end
46+
47+
def overall_not_billable_hours
48+
custom_acoounting_post_hours(Period.new(nil, nil))[false] || 0
49+
end
50+
4251
def shortnames
4352
accounting_post.work_item.path_shortnames
4453
end
@@ -78,7 +87,7 @@ def build_not_billable_cell
7887
end
7988

8089
def build_open_budget_cell
81-
hours = (accounting_post.offered_hours || 0) - overall_billable_hours
90+
hours = (accounting_post.offered_hours || 0) - to_end_billable_hours
8291
build_cell_with_amount(hours)
8392
end
8493

@@ -95,11 +104,15 @@ def calculate_amount(hours)
95104
end
96105

97106
def accounting_post_hours
98-
@hours ||= accounting_post.worktimes.in_period(@period).group(:billable).sum(:hours)
107+
@hours = accounting_post.worktimes.in_period(@period).group(:billable).sum(:hours)
108+
end
109+
110+
def custom_acoounting_post_hours(period)
111+
@overall_hours = accounting_post.worktimes.in_period(period).group(:billable).sum(:hours)
99112
end
100113

101-
def overall_acoounting_post_hours
102-
@overall_hours ||= accounting_post.worktimes.in_period(Period.new(nil, @period.end_date)).group(:billable).sum(:hours)
114+
def build_info
115+
{ overall_not_billable_hours:, overall_supplied_services_hours: }
103116
end
104117
end
105118
end

app/domain/order/cockpit/total_row.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
class Order
99
class Cockpit
1010
class TotalRow < Row
11+
attr_reader :order_info
12+
1113
def initialize(rows)
1214
super('Total')
1315
@cells = build_total_cells(rows)
16+
@order_info = build_order_info(rows)
1417
end
1518

1619
private
@@ -27,6 +30,14 @@ def build_total_cells(rows)
2730
hash
2831
end
2932

33+
# collect the row_info hash of every row and sum the individual values up (per key)
34+
def build_order_info(rows)
35+
row_infos = rows.collect(&:row_info)
36+
row_infos.each_with_object(Hash.new(0)) do |row, acc|
37+
row.each { |key, value| acc[key] += value }
38+
end
39+
end
40+
3041
def sum_non_nil_values(cells, key, field, converter)
3142
values = cells.collect { |c| c[key].send(field) }
3243
return if values.all?(&:nil?)

app/views/accounting_posts/_cockpit_header.html.haml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
-# or later. See the COPYING file at the top-level directory or at
44
-# https://github.com/puzzle/puzzletime.
55
6-
.filter-elements
7-
= form_tag(nil, method: :get, id: 'cockpit_filter_form', class: 'form-inline', role: 'filter') do
8-
= direct_filter_date(:start_date, 'Von', @period.start_date)
9-
= direct_filter_date(:end_date, 'Bis', @period.end_date)
10-
= direct_filter_select(:period_shortcut, nil, predefined_past_period_options, prompt: 'benutzerdefiniert')
116
127
.cockpit-header-item
138
Budget
9+
%br
10+
( Gesamte Vertragslaufzeit )
1411
.data-item{title: "Ist-R[#{currency}]"}
1512
%span.figure-label verrechnet
1613
%span.figure
@@ -26,9 +23,7 @@
2623
.cockpit-header-item
2724
Wirtschaftlichkeit
2825
%br
29-
(
30-
= @period
31-
)
26+
( Gesamte Vertragslaufzeit )
3227
- if @cockpit.cost_effectiveness_current
3328
.data-item{title: 'Ist-R[h] / Ist[h] x 100'}
3429
%span.figure-label Aktuell
@@ -46,9 +41,7 @@
4641
.cockpit-header-item{title: "Ist-R[#{currency}] / Ist-V[h]"}
4742
Verrechneter Stundenansatz
4843
%br
49-
(
50-
= @period
51-
)
44+
( Gesamte Vertragslaufzeit )
5245
.data-item
5346
%span.figure
5447
= f(@cockpit.billed_rate)

app/views/accounting_posts/index.html.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
.cockpit-header
1313
= render 'cockpit_header'
1414

15+
.filter-elements
16+
= form_tag(nil, method: :get, id: 'cockpit_filter_form', class: 'form-inline', role: 'filter') do
17+
= direct_filter_date(:start_date, 'Von', @period.start_date)
18+
= direct_filter_date(:end_date, 'Bis', @period.end_date)
19+
= direct_filter_select(:period_shortcut, nil, predefined_past_period_options, prompt: 'benutzerdefiniert')
1520
.unindented
1621
.cockpit-table
1722
= render 'cockpit_table'

0 commit comments

Comments
 (0)