polish_invoicer 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3f7e001192f272c399b89003c67319860952016
4
- data.tar.gz: 81fbc5378c8c2d768116b0ad2f0c7286330e1ea1
3
+ metadata.gz: 644beb638eed958e59e1975f1c05c01c925622f5
4
+ data.tar.gz: b8b85f18b71cce1b17f039af4d03df5eb28f4c4e
5
5
  SHA512:
6
- metadata.gz: d3445e63f58a3fa8a665fb7eef10a846a046f1e4d13d66aab1591aa3426b20d7cb2a0bac769e9ed28b1e3c243bc67c38cfd66aee7261876d9d2ae1a425f338e4
7
- data.tar.gz: 477e55cf5e6a946ab513a4a7ffa5f1f82ae99e0d1de72bee6e99211d4ec7c40ca68af436ff3bc2d0395eebde24f536815d26544af8cfda8bcb141fe8d8212139
6
+ metadata.gz: 392e24d56f6e06c8c584da31b42292a653db624f59796ea809cdb17f62f534179b296fab8b2ccba018841f7f5de89e01ab0ebcfd1f69c7e43f85ebbd3ca935eb
7
+ data.tar.gz: b046255d9abd0474c8a4289ae96fbe36f7643965216dfe46ac8905f390cda8c45e121b912da87abc24ce2ba2140e7a188cf455da1f45dc85db5c0afc109ebeb3
data/README.md CHANGED
@@ -91,10 +91,12 @@ invoice.save_to_pdf('/path/to/invoice.pdf')
91
91
  # wartość domyślna: false
92
92
  :payment_type, # rodzaj płatności (string)
93
93
  # wartość domyślna: 'Przelew'
94
- :foreign_buyer, # nabywcą jest firma spoza Polski
95
- # wartość domyślna: false (boolean)
96
- :reverse_charge # faktura z odwrotnym obciążeniem VAT
97
- # wartość domyślna: false (boolean)
94
+ :foreign_buyer, # nabywcą jest firma spoza Polski (boolean)
95
+ # wartość domyślna: false
96
+ :reverse_charge # faktura z odwrotnym obciążeniem VAT (boolean)
97
+ # wartość domyślna: false
98
+ :currency # waluta rozliczeniowa (string)
99
+ # wartość domyślna: PLN
98
100
 
99
101
  ### Parametry dodatkowe
100
102
 
data/doc/invoice.rb CHANGED
@@ -19,7 +19,8 @@ invoice = PolishInvoicer::Invoice.new(
19
19
  # proforma: true,
20
20
  # paid: false,
21
21
  foreign_buyer: true,
22
- reverse_charge: true
22
+ reverse_charge: true,
23
+ currency: 'USD'
23
24
  )
24
25
  invoice.save_to_html('/tmp/invoice.html')
25
26
  invoice.save_to_pdf('/tmp/invoice.pdf')
@@ -22,7 +22,8 @@ module PolishInvoicer
22
22
  :proforma, # znacznik faktury pro-forma, domyślnie: false (boolean)
23
23
  :no_vat_reason, # podstawa prawna zwolnienia z VAT (string)
24
24
  :foreign_buyer, # nabywcą jest firma spoza Polski, domyślnie: false (boolean)
25
- :reverse_charge # faktura z odwrotnym obciążeniem VAT
25
+ :reverse_charge, # faktura z odwrotnym obciążeniem VAT
26
+ :currency # waluta rozliczeniowa, domyślnie: PLN (string)
26
27
  ].freeze
27
28
 
28
29
  attr_accessor(*AVAILABLE_PARAMS)
@@ -88,6 +89,7 @@ module PolishInvoicer
88
89
  @proforma = false
89
90
  @foreign_buyer = false
90
91
  @reverse_charge = false
92
+ @currency = 'PLN'
91
93
  @recipient = []
92
94
  end
93
95
 
@@ -18,6 +18,7 @@ module PolishInvoicer
18
18
  check_vat
19
19
  check_proforma
20
20
  check_create_and_payment_date
21
+ check_currency
21
22
  @errors.empty?
22
23
  end
23
24
 
@@ -40,6 +41,7 @@ module PolishInvoicer
40
41
  def check_not_nil
41
42
  @errors[:gross_price] = 'Konieczne jest ustawienie znacznika rodzaju ceny (netto/brutto)' if @invoice.gross_price.nil?
42
43
  @errors[:paid] = 'Konieczne jest ustawienie znacznika opłacenia faktury' if @invoice.paid.nil?
44
+ @errors[:currency] = 'Konieczne jest ustawienie waluty rozliczeniowej' if @invoice.currency.nil?
43
45
  end
44
46
 
45
47
  def check_arrays
@@ -102,6 +104,12 @@ module PolishInvoicer
102
104
  @errors[:payment_date] = 'Termin płatności nie może być wcześniejszy niż data wystawienia'
103
105
  end
104
106
 
107
+ def check_currency
108
+ return if @errors[:currency]
109
+ return if %w[PLN EUR USD GBP].include?(@invoice.currency)
110
+ @errors[:currency] = 'Nieznana waluta'
111
+ end
112
+
105
113
  def blank?(value)
106
114
  value.to_s.strip == ''
107
115
  end
@@ -1,35 +1,27 @@
1
1
  module PolishInvoicer
2
2
  class Vat
3
3
  def self.rates
4
- [23, 8, 5, 0, -1] # -1 oznacza zwolniony z VAT
4
+ (0..27)
5
5
  end
6
6
 
7
7
  def self.valid?(rate)
8
+ return true if zw?(rate)
8
9
  rates.include?(rate)
9
10
  end
10
11
 
11
12
  # Czy stawka VAT to "zwolniony"?
12
13
  def self.zw?(rate)
13
- rate == -1
14
+ rate == -1 # -1 oznacza zwolniony z VAT
14
15
  end
15
16
 
16
17
  def self.to_s(rate)
17
- hash.invert[rate]
18
+ return 'zw.' if zw?(rate)
19
+ "#{rate}%"
18
20
  end
19
21
 
20
22
  # Potrzebne do obliczeń netto/vat/brutto
21
23
  def self.to_i(rate)
22
- rate != -1 ? rate : 0
23
- end
24
-
25
- def self.hash
26
- h = {}
27
- rates.each do |r|
28
- name = "#{r}%"
29
- name = 'zw.' if r == -1
30
- h[name] = r
31
- end
32
- h
24
+ zw?(rate) ? 0 : rate
33
25
  end
34
26
  end
35
27
  end
@@ -1,3 +1,3 @@
1
1
  module PolishInvoicer
2
- VERSION = '0.0.19'.freeze
2
+ VERSION = '0.0.20'.freeze
3
3
  end
data/test/invoice_test.rb CHANGED
@@ -26,26 +26,41 @@ module PolishInvoicer
26
26
  end
27
27
 
28
28
  def test_net_value
29
- i = Invoice.new(price: 123.45, gross_price: false, vat: 23)
29
+ i = Invoice.new(price: 123.45, gross_price: false)
30
+ i.vat = 23
30
31
  assert_in_delta 123.45, i.net_value, 0.01
32
+
31
33
  i.gross_price = true
34
+ i.vat = 23
32
35
  assert_in_delta 100.37, i.net_value, 0.01
36
+ i.vat = 5.5
37
+ assert_in_delta 117.01, i.net_value, 0.01
33
38
  i.vat = 0
34
39
  assert_in_delta 123.45, i.net_value, 0.01
35
40
  i.vat = -1
36
41
  assert_in_delta 123.45, i.net_value, 0.01
42
+
37
43
  i.gross_price = false
38
44
  i.vat = 0
39
45
  assert_in_delta 123.45, i.net_value, 0.01
40
46
  i.vat = -1
41
47
  assert_in_delta 123.45, i.net_value, 0.01
48
+ i.vat = 5.5
49
+ assert_in_delta 123.45, i.net_value, 0.01
42
50
  end
43
51
 
44
52
  def test_vat_value
45
- i = Invoice.new(price: 123.45, gross_price: false, vat: 23)
53
+ i = Invoice.new(price: 123.45, gross_price: false)
54
+ i.vat = 23
46
55
  assert_in_delta 28.39, i.vat_value, 0.01
56
+ i.vat = 5.5
57
+ assert_in_delta 6.79, i.vat_value, 0.01
58
+
47
59
  i.gross_price = true
60
+ i.vat = 23
48
61
  assert_in_delta 23.08, i.vat_value, 0.01
62
+ i.vat = 5.5
63
+ assert_in_delta 6.44, i.vat_value, 0.01
49
64
  i.vat = 0
50
65
  assert_equal 0.00, i.vat_value
51
66
  i.vat = -1
@@ -53,15 +68,23 @@ module PolishInvoicer
53
68
  end
54
69
 
55
70
  def test_gross_value
56
- i = Invoice.new(price: 123.45, gross_price: false, vat: 23)
71
+ i = Invoice.new(price: 123.45, gross_price: false)
72
+ i.vat = 23
57
73
  assert_in_delta 151.84, i.gross_value, 0.01
74
+
58
75
  i.gross_price = true
76
+ i.vat = 23
77
+ assert_in_delta 123.45, i.gross_value, 0.01
78
+ i.vat = 5.5
59
79
  assert_in_delta 123.45, i.gross_value, 0.01
60
80
  i.vat = 0
61
81
  assert_in_delta 123.45, i.gross_value, 0.01
62
82
  i.vat = -1
63
83
  assert_in_delta 123.45, i.gross_value, 0.01
84
+
64
85
  i.gross_price = false
86
+ i.vat = 5.5
87
+ assert_in_delta 130.24, i.gross_value, 0.01
65
88
  i.vat = 0
66
89
  assert_in_delta 123.45, i.gross_value, 0.01
67
90
  i.vat = -1
@@ -142,6 +142,21 @@ module PolishInvoicer
142
142
  assert_nil v.errors[:payment_date]
143
143
  end
144
144
 
145
+ def test_currency
146
+ @invoice.currency = nil
147
+ v = Validator.new(@invoice)
148
+ v.valid?
149
+ assert v.errors[:currency]
150
+ @invoice.currency = 'XYZ'
151
+ v = Validator.new(@invoice)
152
+ v.valid?
153
+ assert v.errors[:currency]
154
+ @invoice.currency = 'EUR'
155
+ v = Validator.new(@invoice)
156
+ v.valid?
157
+ refute v.errors[:currency]
158
+ end
159
+
145
160
  private
146
161
 
147
162
  def check_error(field, value = nil)
data/test/vat_test.rb CHANGED
@@ -4,22 +4,35 @@ module PolishInvoicer
4
4
  class VatTest < Minitest::Test
5
5
  def test_valid
6
6
  assert Vat.valid?(23)
7
+ assert Vat.valid?(27)
8
+ assert Vat.valid?(2)
9
+ assert Vat.valid?(5.5)
10
+ assert Vat.valid?(4.8)
7
11
  assert Vat.valid?(0)
8
12
  assert Vat.valid?(-1)
9
- assert_equal false, Vat.valid?(123)
10
- assert_equal false, Vat.valid?(-10)
11
- assert_equal false, Vat.valid?('test')
13
+ refute Vat.valid?(123)
14
+ refute Vat.valid?(-10)
15
+ refute Vat.valid?('test')
16
+ refute Vat.valid?('2,1')
17
+ refute Vat.valid?('2.1')
12
18
  end
13
19
 
14
20
  def test_zw
15
21
  assert Vat.zw?(-1)
16
- assert_equal false, Vat.zw?(23)
22
+ refute Vat.zw?(23)
17
23
  end
18
24
 
19
25
  def test_to_s
20
26
  assert_equal '23%', Vat.to_s(23)
27
+ assert_equal '5.5%', Vat.to_s(5.5)
21
28
  assert_equal '0%', Vat.to_s(0)
22
29
  assert_equal 'zw.', Vat.to_s(-1)
23
30
  end
31
+
32
+ def test_to_i
33
+ assert_equal 0, Vat.to_i(-1)
34
+ assert_equal 5.5, Vat.to_i(5.5)
35
+ assert_equal 20, Vat.to_i(20)
36
+ end
24
37
  end
25
38
  end
data/tpl/invoice-en.slim CHANGED
@@ -151,7 +151,7 @@ html
151
151
  .small
152
152
  em Total to pay:
153
153
  .col-xs-6
154
- b = "#{reverse_charge == true ? net_value : gross_value} PLN"
154
+ b = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
155
155
  .row
156
156
  .col-xs-6
157
157
  | Zapłacono:
@@ -159,9 +159,9 @@ html
159
159
  em Amount paid:
160
160
  .col-xs-6
161
161
  - if paid
162
- = "#{reverse_charge == true ? net_value : gross_value} PLN"
162
+ = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
163
163
  - else
164
- | 0,00 PLN
164
+ = "0,00 #{currency}"
165
165
  .row
166
166
  .col-xs-6
167
167
  | Zostało do zapłaty:
@@ -169,9 +169,9 @@ html
169
169
  em Left to pay:
170
170
  .col-xs-6
171
171
  - if paid
172
- | 0,00 PLN
172
+ = "0,00 #{currency}"
173
173
  - else
174
- = "#{reverse_charge == true ? net_value : gross_value} PLN"
174
+ = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
175
175
 
176
176
  .col-xs-6
177
177
  - if comments.any?
data/tpl/invoice.slim CHANGED
@@ -103,17 +103,17 @@ html
103
103
  br
104
104
  | Zostało do zapłaty:
105
105
  .col-xs-3
106
- b = "#{gross_value} PLN"
106
+ b = "#{gross_value} #{currency}"
107
107
  br
108
108
  - if paid
109
- = "#{gross_value} PLN"
109
+ = "#{gross_value} #{currency}"
110
110
  - else
111
- | 0,00 PLN
111
+ = "0,00 #{currency}"
112
112
  br
113
113
  - if paid
114
- | 0,00 PLN
114
+ = "0,00 #{currency}"
115
115
  - else
116
- = "#{gross_value} PLN"
116
+ = "#{gross_value} #{currency}"
117
117
  - if comments.any?
118
118
  .col-xs-6
119
119
  b Uwagi:
data/tpl/proforma-en.slim CHANGED
@@ -136,7 +136,7 @@ html
136
136
  .small
137
137
  em Total to pay:
138
138
  .col-xs-6
139
- b = "#{reverse_charge == true ? net_value : gross_value} PLN"
139
+ b = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
140
140
  .row
141
141
  .col-xs-6
142
142
  | Zapłacono:
@@ -144,9 +144,9 @@ html
144
144
  em Amount paid:
145
145
  .col-xs-6
146
146
  - if paid
147
- = "#{reverse_charge == true ? net_value : gross_value} PLN"
147
+ = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
148
148
  - else
149
- | 0,00 PLN
149
+ = "0,00 #{currency}"
150
150
  .row
151
151
  .col-xs-6
152
152
  | Zostało do zapłaty:
@@ -154,9 +154,9 @@ html
154
154
  em Left to pay:
155
155
  .col-xs-6
156
156
  - if paid
157
- | 0,00 PLN
157
+ = "0,00 #{currency}"
158
158
  - else
159
- = "#{reverse_charge == true ? net_value : gross_value} PLN"
159
+ = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
160
160
 
161
161
  .col-xs-6
162
162
  - if comments.any?
data/tpl/proforma.slim CHANGED
@@ -95,17 +95,17 @@ html
95
95
  br
96
96
  | Zostało do zapłaty:
97
97
  .col-xs-3
98
- b = "#{gross_value} PLN"
98
+ b = "#{gross_value} #{currency}"
99
99
  br
100
100
  - if paid
101
- = "#{gross_value} PLN"
101
+ = "#{gross_value} #{currency}"
102
102
  - else
103
- | 0,00 PLN
103
+ = "0,00 #{currency}"
104
104
  br
105
105
  - if paid
106
- | 0,00 PLN
106
+ = "0,00 #{currency}"
107
107
  - else
108
- = "#{gross_value} PLN"
108
+ = "#{gross_value} #{currency}"
109
109
  - if comments.any?
110
110
  .col-xs-6
111
111
  b Uwagi:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polish_invoicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Macuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-09 00:00:00.000000000 Z
11
+ date: 2018-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler