invoice 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'amount_inflector'
4
+ gem 'prawn'
5
+ gem 'barby'
6
+ # Specify your gem's dependencies in invoice.gemspec
7
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 drKreso
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,89 @@
1
+ # Invoice
2
+
3
+ Print out simple invoice tailored for Croatia. You can setup your company data along with your customers with some easy settings.
4
+
5
+ This is called to generate your invoice in .pdf
6
+ ```ruby
7
+ CroatianPDFInvoice.generate(SETTINGS, INVOICE, '~/Desktop')
8
+ ```
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'invoice'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install invoice
23
+
24
+ ## Limitations
25
+
26
+ Only supports one page invoice.
27
+
28
+ ## Usage
29
+
30
+ Example script:
31
+
32
+ ```ruby
33
+ #!/usr/bin/env ruby
34
+ #encoding:utf-8
35
+ require 'invoice'
36
+ require 'amount_inflector'
37
+
38
+ SETTINGS= {
39
+ company_info: {
40
+ title: 'KROKODIL ITS d.o.o. društvo s ograničenom odgovornošću - za usluge',
41
+ address: 'HRVOJA TURUDIĆA 55, HR-10000 Zagreb, HRVATSKA',
42
+ numbers: 'MB 2511611, OIB 511111112312',
43
+ phone: 'M: +385 94 111 7072'
44
+ },
45
+ customers:
46
+ {
47
+ why_the_lucky_stiff: {
48
+ name: 'WHY THE LUCKY STIFF d.o.o.',
49
+ address_street: 'I Gnjile 18',
50
+ address_city: '10000 ZAGREB',
51
+ numbers: 'OIB 412121'
52
+ },
53
+ dinkovac: {
54
+ name: 'Dinkovaca d.o.o.',
55
+ address_street: 'Cvijete Zuzorić 137',
56
+ address_city: '10000 ZAGREB',
57
+ numbers: 'OIB 430101111212'
58
+ }
59
+ },
60
+ tax: '25%',
61
+ signature_line_1: 'Direktor "KROKODIL ITS" d.o.o.',
62
+ signature_line_2: 'Krešimir Bojčić',
63
+ number_to_words_translation: NumberToKune,
64
+ footer: "©#{DateTime.now.year} Krokodil ITS d.o.o"
65
+ }
66
+
67
+ INVOICE = {
68
+ no: '116/2012',
69
+ place_and_date: 'Zagreb, 25.11.2012.godine',
70
+ reference_number: "16-2012",
71
+ customer: 'dinkovac',
72
+ bank_number: '2484008-1105211111',
73
+ items: [
74
+ { description: 'EM-12/2011 Izrada izvješća održavanja iz aplikacije MIJAU', amount: 5_432.22 },
75
+ { description: 'EM-012/2011 Održavanje aplikacije MIJAU ', amount: 100.00 }
76
+ ]
77
+ }
78
+
79
+ CroatianPDFInvoice.generate(SETTINGS, INVOICE, '~/Desktop')
80
+ ```
81
+
82
+
83
+ ## Contributing
84
+
85
+ 1. Fork it
86
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
87
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
88
+ 4. Push to the branch (`git push origin my-new-feature`)
89
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,54 @@
1
+ #encoding:utf-8
2
+ require './lib/invoice/croatian_pdf_invoice'
3
+ require 'amount_inflector'
4
+
5
+ SETTINGS =
6
+ {
7
+ company_info: {
8
+ title: 'KROKODIL ITS d.o.o. društvo s ograničenom odgovornošću - za usluge',
9
+ address: 'HRVOJA TURUDIĆA 55, HR-10000 Zagreb, HRVATSKA',
10
+ numbers: 'MB 2511611, OIB 511111112312',
11
+ phone: 'M: +385 94 111 7072'
12
+ },
13
+ customers:
14
+ {
15
+ why_the_lucky_stiff: {
16
+ name: 'WHY THE LUCKY STIFF d.o.o.',
17
+ address_street: 'I Gnjile 18',
18
+ address_city: '10000 ZAGREB',
19
+ numbers: 'OIB 412121'
20
+ },
21
+ dinkovac: {
22
+ name: 'Dinkovaca d.o.o.',
23
+ address_street: 'Cvijete Zuzorić 137',
24
+ address_city: '10000 ZAGREB',
25
+ numbers: 'OIB 430101111212'
26
+ }
27
+ },
28
+ tax: '25%',
29
+ signature_line_1: 'Direktor "KROKODIL ITS" d.o.o.',
30
+ signature_line_2: 'Krešimir Bojčić',
31
+ number_to_words_translation: NumberToKune,
32
+ footer: "©#{DateTime.now.year} Krokodil ITS d.o.o"
33
+
34
+ }
35
+
36
+ INVOICE = {
37
+ no: '116/2012',
38
+ place_and_date: 'Zagreb, 25.11.2012.godine',
39
+ reference_number: "16-2012",
40
+ customer: 'dinkovac',
41
+ bank_number: '2484008-1105211111',
42
+ items: [
43
+ { description: 'EM-12/2011 Izrada izvješća održavanja iz aplikacije MIJAU', amount: 5_432.22 },
44
+ { description: 'EM-012/2011 Održavanje aplikacije MIJAU ', amount: 100.00 }
45
+ ]
46
+ }
47
+
48
+ CroatianPDFInvoice.generate(SETTINGS, INVOICE, '~/Desktop')
49
+
50
+
51
+
52
+
53
+
54
+
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'invoice/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "invoice"
8
+ gem.version = Invoice::VERSION
9
+ gem.authors = ["drKreso"]
10
+ gem.email = ["kresimir.bojcic@gmail.com"]
11
+ gem.description = %q{Simple .pdf invoice generator for Croatia}
12
+ gem.summary = %q{Generate your invoices with less effort}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,3 @@
1
+ require "invoice/version"
2
+ require "invoice/croatian_pdf_invoice"
3
+
@@ -0,0 +1,171 @@
1
+ #encoding: utf-8
2
+ require 'prawn'
3
+ require 'barby'
4
+ require 'barby/outputter/prawn_outputter'
5
+ require 'barby/barcode/code_39'
6
+ require 'date'
7
+ require 'action_view'
8
+
9
+ class CroatianPDFInvoice < Prawn::Document
10
+ include ActionView::Helpers::NumberHelper
11
+ extend ActionView::Helpers::NumberHelper
12
+
13
+ def self.generate(settings, invoice, path)
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
16
+ end
17
+
18
+ end
19
+
20
+ def initialize(data, invoice)
21
+ @data = data
22
+ @invoice = invoice
23
+ super(:page_size => 'A4', :left_margin => 10, :right_margin => 10, :top_margin => 10)
24
+ generate
25
+ end
26
+
27
+ def generate
28
+ set_font_family
29
+ add_header
30
+ add_invoice_info
31
+ add_footer
32
+ end
33
+
34
+ def add_header
35
+ bounding_box [bounds.left, bounds.top], :width => bounds.width do
36
+ move_down 5
37
+ indent 15 do
38
+ text company_info[:title], :style => :bold, :size => 9
39
+ text company_info[:address], :size => 8
40
+ text company_info[:numbers], :size => 8
41
+ text company_info[:phone], :size => 8
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ def add_invoice_info
48
+ fill_color "f5f5f5"
49
+ fill_rectangle [0,660], 575, 60
50
+ fill_color "0000"
51
+ move_down 10
52
+ bounding_box([0,750], :width => 575, :height => 730) do
53
+ stroke_color '0000'
54
+ stroke_bounds
55
+ move_down 35
56
+ indent 0, 15 do
57
+ text "R-1", :size => 10, :style => :bold, :align => :right
58
+ end
59
+ bounding_box [15, bounds.top - 15], :width => 160, :height => 35 do
60
+ barcode = Barby::Code39.new(invoice_no)
61
+ barcode.annotate_pdf(self, :height => 35, :width => 150)
62
+ end
63
+ move_down 15
64
+ indent 15,15 do
65
+ text "#{@invoice[:place_and_date]}", :align => :right
66
+ move_up 13
67
+ text "Račun broj: #{invoice_no}", :style => :bold, :size => 15
68
+ move_down 25
69
+ text "Kupac:", :style => :bold
70
+ move_up 9
71
+ indent 150, 15 do
72
+ text customer[:name], :style => :bold
73
+ text customer[:address_street], :style => :bold
74
+ text customer[:address_city], :style => :bold
75
+ text customer[:numbers], :style => :bold
76
+ end
77
+ move_down 40
78
+ stroke_horizontal_rule
79
+ move_down 5
80
+ items.each_with_index do |item, index|
81
+ move_down 5
82
+ text "#{index + 1}. #{item[:description]}"
83
+ move_up 9
84
+ text "#{to_currency(item[:amount])}", :align => :right
85
+ end
86
+ move_down 5
87
+ stroke_horizontal_rule
88
+ move_down 5
89
+ text "UKUPNO", :style => :bold
90
+ move_up 9
91
+ ukupno = items.map { |item| item[:amount] }.reduce(:+)
92
+ tax_amount = ukupno * (BigDecimal.new(@data[:tax].gsub('%',''))/100.0).round(2)
93
+ total = (tax_amount + ukupno).round(2)
94
+ 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
99
+ move_down 15
100
+ stroke_horizontal_rule
101
+ move_down 5
102
+ text "Sveukupno za platiti:"
103
+ move_up 9
104
+ text "#{to_currency(total)}", :align => :right , :style => :bold
105
+ move_down 3
106
+ text "Slovima: #{NumberToKune.convert(total)}", :font_size => 7
107
+ move_down 5
108
+ stroke_horizontal_rule
109
+ move_down 25
110
+ text "Žiro-račun: #{@invoice[:bank_number]}"
111
+ move_down 4
112
+ text "Poziv na broj: #{@invoice[:reference_number]}"
113
+ 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
119
+
120
+ end
121
+ end
122
+ end
123
+
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
+ def items
132
+ @invoice[:items]
133
+ end
134
+
135
+ def customer
136
+ @data[:customers][@invoice[:customer].to_s.to_sym]
137
+ end
138
+
139
+ def company_info
140
+ @data[:company_info]
141
+ end
142
+
143
+ def footer
144
+ @data[:footer]
145
+ end
146
+
147
+ def invoice_no
148
+ @invoice[:no]
149
+ end
150
+
151
+ def set_font_family
152
+ self.font_size = 9
153
+ font_families.update("Verdana" => {
154
+ :normal => File.expand_path('../../../fonts/verdana.ttf', __FILE__),
155
+ :italic => File.expand_path('../../../fonts/verdanai.ttf', __FILE__),
156
+ :bold => File.expand_path('../../../fonts/verdanab.ttf', __FILE__),
157
+ :bold_italic => File.expand_path('../../../fonts/verdanaz.ttf', __FILE__),
158
+ })
159
+ font("Verdana")
160
+ end
161
+
162
+ def to_d
163
+ BigDecimal.new(self.to_s)
164
+ end
165
+
166
+ def to_currency(amount)
167
+ return '' if amount.nil?
168
+ "#{number_with_precision(amount, :precision => 2, :delimiter => '.', :separator => ',')} kn"
169
+ end
170
+
171
+ end
@@ -0,0 +1,3 @@
1
+ module Invoice
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: invoice
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - drKreso
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Simple .pdf invoice generator for Croatia
15
+ email:
16
+ - kresimir.bojcic@gmail.com
17
+ executables:
18
+ - generate.rb
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .DS_Store
23
+ - .gitignore
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/generate.rb
29
+ - fonts/.DS_Store
30
+ - fonts/verdana.ttf
31
+ - fonts/verdanab.ttf
32
+ - fonts/verdanai.ttf
33
+ - fonts/verdanaz.ttf
34
+ - invoice.gemspec
35
+ - lib/invoice.rb
36
+ - lib/invoice/croatian_pdf_invoice.rb
37
+ - lib/invoice/version.rb
38
+ homepage: ''
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Generate your invoices with less effort
62
+ test_files: []