Skip to content

Commit d1b0bf9

Browse files
anna-devKagemaru
authored andcommitted
Add billing report csv export (64939)
1 parent 75fef9d commit d1b0bf9

File tree

7 files changed

+74
-3
lines changed

7 files changed

+74
-3
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Naming/MemoizedInstanceVariableName:
149149
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
150150
Naming/MethodParameterName:
151151
Exclude:
152+
- 'app/domain/billing/report/csv.rb'
152153
- 'app/domain/invoicing/small_invoice/invoice_sync.rb'
153154
- 'app/domain/invoice/report/csv.rb'
154155
- 'app/domain/order/controlling.rb'

app/controllers/billing_reports_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Copyright (c) 2006-2017, Puzzle ITC GmbH. This file is part of
3+
# Copyright (c) 2006-2025, Puzzle ITC GmbH. This file is part of
44
# PuzzleTime and licensed under the Affero General Public License version 3
55
# or later. See the COPYING file at the top-level directory or at
66
# https://github.com/puzzle/puzzletime.
@@ -32,6 +32,10 @@ def index
3232
format.js do
3333
set_filter_values
3434
end
35+
format.csv do
36+
send_data(Billing::Report::Csv.new(@report).generate,
37+
type: 'text/csv; charset=utf-8; header=present')
38+
end
3539
end
3640
end
3741

app/domain/billing/report/csv.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2006-2025, Puzzle ITC GmbH. This file is part of
4+
# PuzzleTime and licensed under the Affero General Public License version 3
5+
# or later. See the COPYING file at the top-level directory or at
6+
# https://github.com/puzzle/puzzletime.
7+
8+
module Billing
9+
class Report
10+
class Csv
11+
attr_reader :report
12+
13+
def initialize(report)
14+
@report = report
15+
end
16+
17+
def generate
18+
CSV.generate do |csv|
19+
csv << header
20+
21+
report.entries.each do |e|
22+
csv << row(e)
23+
end
24+
end
25+
end
26+
27+
private
28+
29+
def header
30+
['Kunde', 'Status', 'Geleistet', 'Verrechenbar', 'Verrechnet', 'Verrechnung offen']
31+
end
32+
33+
def row(e)
34+
[e.client, e.status.to_s, e.supplied_amount, e.billable_amount, e.billed_amount,
35+
e.not_billed_amount]
36+
end
37+
end
38+
end
39+
end

app/views/billing_addresses/_actions_index.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-# Copyright (c) 2006-2017, Puzzle ITC GmbH. This file is part of
1+
-# Copyright (c) 2006-2025, Puzzle ITC GmbH. This file is part of
22
-# PuzzleTime and licensed under the Affero General Public License version 3
33
-# or later. See the COPYING file at the top-level directory or at
44
-# https://github.com/puzzle/puzzletime.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-# Copyright (c) 2006-2025, Puzzle ITC GmbH. This file is part of
2+
-# PuzzleTime and licensed under the Affero General Public License version 3
3+
-# or later. See the COPYING file at the top-level directory or at
4+
-# https://github.com/puzzle/puzzletime.
5+
6+
7+
= action_link(action_icon('export', 'CSV Export'), params.to_unsafe_h.merge(format: :csv, only_path: true))

app/views/billing_reports/index.html.haml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-# Copyright (c) 2006-2017, Puzzle ITC GmbH. This file is part of
1+
-# Copyright (c) 2006-2025, Puzzle ITC GmbH. This file is part of
22
-# PuzzleTime and licensed under the Affero General Public License version 3
33
-# or later. See the COPYING file at the top-level directory or at
44
-# https://github.com/puzzle/puzzletime.
@@ -11,3 +11,5 @@
1111

1212
.list
1313
= render 'list'
14+
15+
= render 'actions'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2006-2017, Puzzle ITC GmbH. This file is part of
4+
# PuzzleTime and licensed under the Affero General Public License version 3
5+
# or later. See the COPYING file at the top-level directory or at
6+
# https://github.com/puzzle/puzzletime.
7+
8+
require 'test_helper'
9+
10+
class BillingReportsControllerTest < ActionController::TestCase
11+
setup :login
12+
13+
test 'GET index csv exports csv file' do
14+
get :index, format: :csv
15+
16+
assert_match(/Kunde,Status,Geleistet,Verrechenbar,Verrechnet,Verrechnung offen/, response.body)
17+
end
18+
end

0 commit comments

Comments
 (0)