invoice 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -41,20 +41,22 @@ Only supports one page invoice.
41
41
 
42
42
  ## Usage
43
43
 
44
- Example script:
44
+ Example script(available in bin/generate_example.rb):
45
45
 
46
46
  ```ruby
47
- #!/usr/bin/env ruby
48
47
  #encoding:utf-8
49
48
  require 'invoice'
50
49
  require 'amount_inflector'
51
50
 
52
- SETTINGS= {
51
+ SETTINGS =
52
+ {
53
53
  company_info: {
54
54
  title: 'KROKODIL ITS d.o.o. društvo s ograničenom odgovornošću - za usluge',
55
55
  address: 'HRVOJA TURUDIĆA 55, HR-10000 Zagreb, HRVATSKA',
56
56
  numbers: 'MB 2511611, OIB 511111112312',
57
- phone: 'M: +385 94 111 7072'
57
+ phone: 'M: +385 94 111 7072',
58
+ account_number: 'HR3324640081405230496',
59
+ swift: 'RZBHHR2X'
58
60
  },
59
61
  customers:
60
62
  {
@@ -65,21 +67,22 @@ SETTINGS= {
65
67
  numbers: 'OIB 412121'
66
68
  },
67
69
  dinkovac: {
68
- name: 'Dinkovaca d.o.o.',
69
- address_street: 'Cvijete Zuzorić 137',
70
- address_city: '10000 ZAGREB',
71
- numbers: 'OIB 430101111212'
70
+ name: 'Dinkovaca Inc.',
71
+ address_street: 'Potomac 137',
72
+ address_city: '10000 Ney York',
73
+ numbers: '430101111212',
74
+ location: 'USA' #triggers "no-vat template" (also 'CA')
72
75
  }
73
76
  },
74
77
  tax: '25%',
75
78
  signature_line_1: 'Direktor "KROKODIL ITS" d.o.o.',
76
79
  signature_line_2: 'Krešimir Bojčić',
77
80
  number_to_words_translation: NumberToKune,
78
- footer: "©#{DateTime.now.year} Krokodil ITS d.o.o"
81
+ footer: "Društvo je upisano u registar Trgovačkog suda u Zagrebu pod brojem 080708370\nTemeljni kapital društva iznosi 20.000,00 kn i uplaćen je u cjelosti\nČlan Uprave Krešimir Bojčić zastupa društvo pojedinačno i samostalno"
79
82
  }
80
83
 
81
84
  INVOICE = {
82
- no: '116/2012',
85
+ no: '116/2012/KB',
83
86
  place_and_date: 'Zagreb, 25.11.2012.godine',
84
87
  reference_number: "16-2012",
85
88
  customer: 'dinkovac',
@@ -90,9 +93,16 @@ INVOICE = {
90
93
  ]
91
94
  }
92
95
 
93
- CroatianPDFInvoice.generate(SETTINGS, INVOICE, '~/Desktop')
96
+ PDFInvoice.generate(SETTINGS, INVOICE, '~/Desktop')
97
+ puts "Succefully generated on Desktop"
94
98
  ```
95
99
 
100
+ ##History
101
+ 1.0.3
102
+ Added support for no-vat invoices (for location 'USA' and 'CA')
103
+ Tweaked look and feel
104
+ New legal text needed since July 1, 2013
105
+
96
106
 
97
107
  ## Contributing
98
108
 
@@ -1,5 +1,5 @@
1
1
  #encoding:utf-8
2
- require './lib/invoice/croatian_pdf_invoice'
2
+ require '../lib/invoice/pdf_invoice'
3
3
  require 'amount_inflector'
4
4
 
5
5
  SETTINGS =
@@ -8,7 +8,9 @@ SETTINGS =
8
8
  title: 'KROKODIL ITS d.o.o. društvo s ograničenom odgovornošću - za usluge',
9
9
  address: 'HRVOJA TURUDIĆA 55, HR-10000 Zagreb, HRVATSKA',
10
10
  numbers: 'MB 2511611, OIB 511111112312',
11
- phone: 'M: +385 94 111 7072'
11
+ phone: 'M: +385 94 111 7072',
12
+ account_number: 'HR3324640081405230496',
13
+ swift: 'RZBHHR2X'
12
14
  },
13
15
  customers:
14
16
  {
@@ -19,22 +21,22 @@ SETTINGS =
19
21
  numbers: 'OIB 412121'
20
22
  },
21
23
  dinkovac: {
22
- name: 'Dinkovaca d.o.o.',
23
- address_street: 'Cvijete Zuzorić 137',
24
- address_city: '10000 ZAGREB',
25
- numbers: 'OIB 430101111212'
24
+ name: 'Dinkovaca Inc.',
25
+ address_street: 'Potomac 137',
26
+ address_city: '10000 Ney York',
27
+ numbers: '430101111212',
28
+ location: 'USA' #triggers "no-vat template" (also 'CA')
26
29
  }
27
30
  },
28
31
  tax: '25%',
29
32
  signature_line_1: 'Direktor "KROKODIL ITS" d.o.o.',
30
33
  signature_line_2: 'Krešimir Bojčić',
31
34
  number_to_words_translation: NumberToKune,
32
- footer: "©#{DateTime.now.year} Krokodil ITS d.o.o"
33
-
35
+ footer: "Društvo je upisano u registar Trgovačkog suda u Zagrebu pod brojem 080708370\nTemeljni kapital društva iznosi 20.000,00 kn i uplaćen je u cjelosti\nČlan Uprave Krešimir Bojčić zastupa društvo pojedinačno i samostalno"
34
36
  }
35
37
 
36
38
  INVOICE = {
37
- no: '116/2012',
39
+ no: '116/2012/KB',
38
40
  place_and_date: 'Zagreb, 25.11.2012.godine',
39
41
  reference_number: "16-2012",
40
42
  customer: 'dinkovac',
@@ -45,7 +47,9 @@ INVOICE = {
45
47
  ]
46
48
  }
47
49
 
48
- CroatianPDFInvoice.generate(SETTINGS, INVOICE, '~/Desktop')
50
+ PDFInvoice.generate(SETTINGS, INVOICE, '~/Desktop')
51
+ puts "Succefully generated on Desktop"
52
+
49
53
 
50
54
 
51
55
 
@@ -1,3 +1,3 @@
1
1
  require "invoice/version"
2
- require "invoice/croatian_pdf_invoice"
2
+ require "invoice/pdf_invoice"
3
3
 
@@ -6,13 +6,13 @@ require 'barby/barcode/code_39'
6
6
  require 'date'
7
7
  require 'action_view'
8
8
 
9
- class CroatianPDFInvoice < Prawn::Document
9
+ class PDFInvoice < Prawn::Document
10
10
  include ActionView::Helpers::NumberHelper
11
11
  extend ActionView::Helpers::NumberHelper
12
12
 
13
13
  def self.generate(settings, invoice, path)
14
14
  File.open(File.expand_path(path) + "/rn_#{invoice[:no].gsub('/','_')}_#{invoice[:customer]}.pdf", 'w') do |file|
15
- file.write CroatianPDFInvoice.new(settings, invoice).render
15
+ file.write PDFInvoice.new(settings, invoice).render
16
16
  end
17
17
 
18
18
  end
@@ -28,7 +28,6 @@ class CroatianPDFInvoice < Prawn::Document
28
28
  set_font_family
29
29
  add_header
30
30
  add_invoice_info
31
- add_footer
32
31
  end
33
32
 
34
33
  def add_header
@@ -64,15 +63,23 @@ class CroatianPDFInvoice < Prawn::Document
64
63
  indent 15,15 do
65
64
  text "#{@invoice[:place_and_date]}", :align => :right
66
65
  move_up 13
67
- text "Račun broj: #{invoice_no}", :style => :bold, :size => 15
66
+ if export_no_vat?
67
+ text "Invoice no. (Račun broj): #{invoice_no}", :style => :bold, :size => 15
68
+ else
69
+ text "Račun broj: #{invoice_no}", :style => :bold, :size => 15
70
+ end
68
71
  move_down 25
69
- text "Kupac:", :style => :bold
72
+ if export_no_vat?
73
+ text "Issued To (Kupac):", :style => :bold
74
+ else
75
+ text "Kupac:", :style => :bold
76
+ end
70
77
  move_up 9
71
78
  indent 150, 15 do
72
79
  text customer[:name], :style => :bold
73
80
  text customer[:address_street], :style => :bold
74
81
  text customer[:address_city], :style => :bold
75
- text customer[:numbers], :style => :bold
82
+ text customer[:numbers], :style => :bold unless customer[:numbers].nil?
76
83
  end
77
84
  move_down 40
78
85
  stroke_horizontal_rule
@@ -86,48 +93,95 @@ class CroatianPDFInvoice < Prawn::Document
86
93
  move_down 5
87
94
  stroke_horizontal_rule
88
95
  move_down 5
89
- text "UKUPNO", :style => :bold
96
+ if export_no_vat?
97
+ text "TOTAL (UKUPNO)", :style => :bold
98
+ else
99
+ text "UKUPNO", :style => :bold
100
+ end
90
101
  move_up 9
91
102
  ukupno = items.map { |item| item[:amount] }.reduce(:+)
92
103
  tax_amount = ukupno * (BigDecimal.new(@data[:tax].gsub('%',''))/100.0).round(2)
104
+ tax_amount = 0 if export_no_vat?
93
105
  total = (tax_amount + ukupno).round(2)
94
106
  text "#{to_currency(ukupno)}", :align => :right
95
- move_down 10
96
- text "PDV #{@data[:tax]}", :style => :bold
97
- move_up 9
98
- text "#{to_currency(tax_amount)}", :align => :right
107
+ unless export_no_vat?
108
+ move_down 10
109
+ text "PDV #{@data[:tax]}", :style => :bold
110
+ move_up 9
111
+ text "#{to_currency(tax_amount)}", :align => :right
112
+ end
99
113
  move_down 15
100
114
  stroke_horizontal_rule
101
115
  move_down 5
102
- text "Sveukupno za platiti:"
116
+ if export_no_vat?
117
+ text "Total Amount (Sveukupno za platiti):"
118
+ else
119
+ text "Sveukupno za platiti:"
120
+ end
103
121
  move_up 9
104
122
  text "#{to_currency(total)}", :align => :right , :style => :bold
105
- move_down 3
106
- text "Slovima: #{NumberToKune.convert(total)}", :font_size => 7
123
+ unless export_no_vat?
124
+ move_down 3
125
+ text "Slovima: #{NumberToKune.convert(total)}", :size => 7
126
+ end
107
127
  move_down 5
108
128
  stroke_horizontal_rule
109
129
  move_down 25
110
- text "Žiro-račun: #{@invoice[:bank_number]}"
130
+ if export_no_vat?
131
+ text "IBAN: #{company_info[:account_number]}", :style => :bold
132
+ else
133
+ text "Žiro-račun: #{company_info[:account_number]}"
134
+ end
135
+ move_down 4
136
+ if export_no_vat?
137
+ text "SWIFT: #{company_info[:swift]}"
138
+ else
139
+ text "Poziv na broj: #{@invoice[:no].gsub('/','-').gsub('-KB','')}"
140
+ end
111
141
  move_down 4
112
- text "Poziv na broj: #{@invoice[:reference_number]}"
142
+ if export_no_vat?
143
+ text "Payement type: bank wire (Način plaćanja: uplatom na žiro-račun)"
144
+ else
145
+ text "Način plaćanja: uplatom na žiro-račun"
146
+ end
147
+ move_down 35
148
+ text "#{@data[:signature_line_1]}", :style => :italic, :align => :left
149
+ move_up 10
150
+ indent 445 do
151
+ text "#{@data[:signature_line_2]}", :style => :bold, :align => :left
152
+ end
153
+ stroke do
154
+ horizontal_line(430, 540, :at => y - 58)
155
+ end
113
156
  move_down 25
114
- text "Račun je izrađen na računalu i pravovaljan je bez potpisa i žiga", :style => :bold
115
- move_up 9
116
- text "#{@data[:signature_line_1]}", :style => :bold, :align => :right
117
- move_down 10
118
- text "#{@data[:signature_line_2]}", :style => :bold, :align => :right
157
+ if export_no_vat?
158
+ text "This is computer generated INVOICE and requires no signature or stamp (Račun je izrađen na računalu i pravovaljan je bez potpisa i žiga)", :style => :italic, :size => 7
159
+ else
160
+ text "Račun je izrađen na računalu i pravovaljan je bez potpisa i žiga", :style => :italic, :size => 7
161
+ end
119
162
 
163
+ # footer
164
+ move_y = 25 + @data[:footer].split("\n").count * 9
165
+ page_count.times do |i|
166
+ go_to_page(i+1)
167
+ self.font_size = 7
168
+ bounding_box([bounds.left, bounds.bottom + move_y], :width => 550) do
169
+ if export_no_vat?
170
+ text "Usluga ne podliježe oporezivanju sukladno odredbi čl.5.st.6.t.2 Zakona o PDV-u.", :align => :left , :style => :italic
171
+ else
172
+ move_down 10
173
+ end
174
+ move_down 15
175
+ @data[:footer].each_line do |line|
176
+ text line, :style => :italic
177
+ end
178
+ end
179
+ self.font_size = 9
180
+ end
120
181
  end
121
182
  end
122
183
  end
123
184
 
124
- def add_footer
125
- bounding_box [bounds.left, bounds.bottom + 12], :width => bounds.width do
126
- move_down(5)
127
- text "#{footer}", :size => 7
128
- end
129
- end
130
-
131
185
  def items
132
186
  @invoice[:items]
133
187
  end
@@ -140,10 +194,6 @@ class CroatianPDFInvoice < Prawn::Document
140
194
  @data[:company_info]
141
195
  end
142
196
 
143
- def footer
144
- @data[:footer]
145
- end
146
-
147
197
  def invoice_no
148
198
  @invoice[:no]
149
199
  end
@@ -163,7 +213,18 @@ class CroatianPDFInvoice < Prawn::Document
163
213
  BigDecimal.new(self.to_s)
164
214
  end
165
215
 
216
+ def to_usd_currency(amount)
217
+ return '' if amount.nil?
218
+ "$#{number_with_precision(amount, :precision => 2, :delimiter => '.', :separator => ',')}"
219
+ end
220
+
221
+ def export_no_vat?
222
+ @data[:customers][@invoice[:customer].to_sym][:location] == 'USA' ||
223
+ @data[:customers][@invoice[:customer].to_sym][:location] == 'CA'
224
+ end
225
+
166
226
  def to_currency(amount)
227
+ return to_usd_currency(amount) if export_no_vat?
167
228
  return '' if amount.nil?
168
229
  "#{number_with_precision(amount, :precision => 2, :delimiter => '.', :separator => ',')} kn"
169
230
  end
@@ -1,3 +1,3 @@
1
1
  module Invoice
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoice
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,13 +9,13 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-10 00:00:00.000000000 Z
12
+ date: 2013-07-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Simple .pdf invoice generator for Croatia
15
15
  email:
16
16
  - kresimir.bojcic@gmail.com
17
17
  executables:
18
- - generate.rb
18
+ - generate_example.rb
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
@@ -25,7 +25,7 @@ files:
25
25
  - LICENSE.txt
26
26
  - README.md
27
27
  - Rakefile
28
- - bin/generate.rb
28
+ - bin/generate_example.rb
29
29
  - fonts/.DS_Store
30
30
  - fonts/verdana.ttf
31
31
  - fonts/verdanab.ttf
@@ -35,7 +35,7 @@ files:
35
35
  - images/example_invoice.png
36
36
  - invoice.gemspec
37
37
  - lib/invoice.rb
38
- - lib/invoice/croatian_pdf_invoice.rb
38
+ - lib/invoice/pdf_invoice.rb
39
39
  - lib/invoice/version.rb
40
40
  homepage: https://github.com/drKreso/invoice
41
41
  licenses: []
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  version: '0'
58
58
  requirements: []
59
59
  rubyforge_project:
60
- rubygems_version: 1.8.24
60
+ rubygems_version: 1.8.23
61
61
  signing_key:
62
62
  specification_version: 3
63
63
  summary: Generate your invoices with less effort