invoicer 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/invoicer.gemspec +15 -0
- data/lib/invoicer.rb +122 -0
- metadata +56 -0
data/invoicer.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "invoicer"
|
3
|
+
s.version = "0.1"
|
4
|
+
s.date = "2010-01-21"
|
5
|
+
s.summary = "generate PDF invoices"
|
6
|
+
s.email = "harry@vangberg.name"
|
7
|
+
s.homepage = "http://github.com/ichverstehe/invoicer"
|
8
|
+
s.description = "generate PDF invoices"
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.authors = ["Harry Vangberg"]
|
11
|
+
s.files = [
|
12
|
+
"invoicer.gemspec",
|
13
|
+
"lib/invoicer.rb"
|
14
|
+
]
|
15
|
+
end
|
data/lib/invoicer.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'prawn'
|
2
|
+
require 'prawn/layout'
|
3
|
+
|
4
|
+
class Invoicer < Prawn::Document
|
5
|
+
attr_accessor :entries, :company, :customer, :notes, :foot
|
6
|
+
|
7
|
+
def initialize(options={})
|
8
|
+
# Array of hashes:
|
9
|
+
# @entries << {:description => '', :rate => 0, :number => 0}
|
10
|
+
@entries = options.delete(:entries) || []
|
11
|
+
@company = options.delete(:company)
|
12
|
+
@customer = options.delete(:customer)
|
13
|
+
@notes = options.delete(:notes)
|
14
|
+
@foot = options.delete(:footer)
|
15
|
+
@number = options.delete(:number)
|
16
|
+
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def draw_invoice
|
21
|
+
draw_header
|
22
|
+
draw_addresses
|
23
|
+
draw_entries
|
24
|
+
draw_vat_and_total
|
25
|
+
draw_notes
|
26
|
+
draw_foot
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def draw_header
|
31
|
+
text @company[:name], :size => 30
|
32
|
+
|
33
|
+
bounding_box margin_box.top_left, :width => margin_box.width do
|
34
|
+
text Time.now.strftime("%d. %B %Y"), :align => :right
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def draw_addresses
|
39
|
+
bounding_box [0, margin_box.top - 50] do
|
40
|
+
draw_customer
|
41
|
+
draw_company
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def draw_customer
|
46
|
+
bounding_box [0, bounds.top], :width => (margin_box.width / 2) do
|
47
|
+
text "KUNDE", :style => :bold
|
48
|
+
text @customer[:name]
|
49
|
+
text @customer[:address]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def draw_company
|
54
|
+
bounding_box([(margin_box.width / 2), bounds.top],
|
55
|
+
:width => (margin_box.width / 2)) do
|
56
|
+
text "FAKTURA ##{@number}", :style => :bold, :align => :right
|
57
|
+
text @company[:name], :align => :right
|
58
|
+
text @company[:address], :align => :right
|
59
|
+
text @company[:misc], :align => :right
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def draw_entries
|
64
|
+
move_down 20
|
65
|
+
table(
|
66
|
+
entries_for_table,
|
67
|
+
:border_style => :underline_header,
|
68
|
+
:headers => ['Beskrivelse', 'Antal', 'Pris', ''],
|
69
|
+
:align_headers => { 0 => :left, 1 => :center, 2 => :center },
|
70
|
+
:row_colors => ['ffffff', 'eeeeee'],
|
71
|
+
:align => {0 => :left, 1 => :center, 2 => :center, 3 => :right},
|
72
|
+
:width => margin_box.width
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def draw_vat_and_total
|
77
|
+
move_down 20
|
78
|
+
table [
|
79
|
+
['I alt', "kr. #{f entries_total}"],
|
80
|
+
['Moms', "kr. #{f vat}"],
|
81
|
+
['I alt at betale', "kr. #{f total}"]
|
82
|
+
],
|
83
|
+
:border_width => 0,
|
84
|
+
:align => { 0 => :left, 1 => :right },
|
85
|
+
:vertical_padding => 1,
|
86
|
+
:width => margin_box.width
|
87
|
+
end
|
88
|
+
|
89
|
+
def draw_notes
|
90
|
+
move_down 30
|
91
|
+
text @notes
|
92
|
+
end
|
93
|
+
|
94
|
+
def draw_foot
|
95
|
+
bounding_box [0, margin_box.bottom + 20], :width => margin_box.width do
|
96
|
+
text @foot, :align => :center
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def entries_for_table
|
101
|
+
@entries.map do |entry|
|
102
|
+
total = entry[:rate] * entry[:number] / 100.0
|
103
|
+
[entry[:description], entry[:number], "kr. #{f entry[:rate] / 100.0}", "kr. #{f total}"]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def entries_total
|
108
|
+
@entries.inject(0) {|a,e| a + e[:rate] * e[:number]} / 100.0
|
109
|
+
end
|
110
|
+
|
111
|
+
def f(n)
|
112
|
+
("%.2f" % n).sub ".", ","
|
113
|
+
end
|
114
|
+
|
115
|
+
def vat
|
116
|
+
entries_total * 0.25
|
117
|
+
end
|
118
|
+
|
119
|
+
def total
|
120
|
+
entries_total * 1.25
|
121
|
+
end
|
122
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: invoicer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harry Vangberg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-21 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: generate PDF invoices
|
17
|
+
email: harry@vangberg.name
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- invoicer.gemspec
|
26
|
+
- lib/invoicer.rb
|
27
|
+
has_rdoc: false
|
28
|
+
homepage: http://github.com/ichverstehe/invoicer
|
29
|
+
licenses: []
|
30
|
+
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.3.5
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: generate PDF invoices
|
55
|
+
test_files: []
|
56
|
+
|