Top Level Namespace
Defined Under Namespace
Modules: ContractLtd
Classes: Invoice
Instance Method Summary
collapse
Instance Method Details
#file_date(prefix, date, suffix) ⇒ Object
1
2
3
|
# File 'lib/contract_ltd/invoice.rb', line 1
def file_date(prefix, date, suffix)
"#{prefix}_#{date.to_s(:file_no_day)}.#{suffix}"
end
|
#invoice_filename(date) ⇒ Object
9
10
11
|
# File 'lib/contract_ltd/invoice.rb', line 9
def invoice_filename(date)
file_date("invoice", date, "pdf")
end
|
#timesheet_filename(date) ⇒ Object
5
6
7
|
# File 'lib/contract_ltd/invoice.rb', line 5
def timesheet_filename(date)
file_date("timesheet", date, "csv")
end
|
#working_days(date) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/contract_ltd/invoice.rb', line 91
def working_days(date)
if @days_are_included
@days[date.day] || ''
else
if date.saturday? || date.sunday?
''
else
1.0 - @days[date.day].to_f
end
end
end
|
#write_pdf(template) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/contract_ltd/base.rb', line 15
def write_pdf(template)
html = Slim::Template.new(template.name('slim')).render(template)
File.write(template.name('html'), html)
phantom = Shrimp::Phantom.new("file:///#{Dir.pwd}/#{template.name('html')}")
phantom.to_pdf(template.filename)
FileUtils.rm_f(template.name('html'))
end
|
#write_timesheet(date) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/contract_ltd/invoice.rb', line 13
def write_timesheet(date)
csv = "Timesheet for Ruby Web Development Services\n"
csv += "by Phil Thompson (Electric Visions Ltd)\n"
csv += "for #{date.to_s(:month_name_year)}\n\n"
csv += "Day,Hours\n"
total = 0
(date..date.end_of_month.to_date).each do |d|
day = working_days(d)
total += day if day.is_a?(Float)
csv += "#{d.day},#{day * 7.5}\n"
end
csv += "\n"
csv += "Total (hours),#{total * 7.5}\n"
csv += "Total (days),#{total}\n"
File.open(timesheet_filename(date), 'w') {|f| f.write csv }
total
end
|