-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathworktimes_csv.rb
46 lines (38 loc) · 1.44 KB
/
worktimes_csv.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
# Copyright (c) 2006-2024, Puzzle ITC GmbH. This file is part of
# PuzzleTime and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/puzzle/puzzletime.
module WorktimesCsv
extend ActiveSupport::Concern
include CsvExportable
private
def send_worktimes_csv(worktimes, filename)
csv_data = worktimes_csv(worktimes)
send_csv(csv_data, filename)
end
def worktimes_csv(worktimes)
CSV.generate do |csv|
csv << ['Datum', 'Stunden', 'Von Zeit', 'Bis Zeit', 'Stundenansatz CHF', 'Reporttyp',
'Verrechenbar', 'Member', 'Position', 'Ticket', 'Bemerkungen', 'Interne Bemerkungen']
worktimes.each do |time|
csv << [I18n.l(time.work_date),
time.hours,
(time.start_stop? ? I18n.l(time.from_start_time, format: :time) : ''),
(time.start_stop? && time.to_end_time? ? I18n.l(time.to_end_time, format: :time) : ''),
amount(time),
time.report_type,
time.billable,
time.employee.label,
time.account.label_verbose,
time.ticket,
time.description,
time.internal_description]
end
end
end
def amount(time)
return '-' unless time.respond_to?(:amount)
format('%<amount>0.02f', amount: time.amount)
end
end