polish_invoicer 0.0.20 → 0.0.25

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
- SHA1:
3
- metadata.gz: 644beb638eed958e59e1975f1c05c01c925622f5
4
- data.tar.gz: b8b85f18b71cce1b17f039af4d03df5eb28f4c4e
2
+ SHA256:
3
+ metadata.gz: e50ba77f3a3539b5a75c12e3213dd8e0f56bc7788c7ab74d43ec661ef8e12d94
4
+ data.tar.gz: 9193da0b3dd714fa51ac52e06a2b87191a493f7539132b41115ce89c86851632
5
5
  SHA512:
6
- metadata.gz: 392e24d56f6e06c8c584da31b42292a653db624f59796ea809cdb17f62f534179b296fab8b2ccba018841f7f5de89e01ab0ebcfd1f69c7e43f85ebbd3ca935eb
7
- data.tar.gz: b046255d9abd0474c8a4289ae96fbe36f7643965216dfe46ac8905f390cda8c45e121b912da87abc24ce2ba2140e7a188cf455da1f45dc85db5c0afc109ebeb3
6
+ metadata.gz: f0839922dbbab96b6e580f5c63ca86d4b2789c6b3f771d0195c5251cb48e9c6ef3b23fccd22ebfe3fb8f603ba007836d073f71a33f876af85a77f4e7e5a7d38d
7
+ data.tar.gz: 3f608c82265282b14e5c1af278e3b38fefb9830005ea0bf3c9517c552dc5a76e5c10052f684f056a180db45f7d5599a2bc4b12d25ef4901c2ab3858f73272ef5
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.10
4
- - 2.3.7
5
- - 2.4.4
6
- - 2.5.1
3
+ - 2.5.8
4
+ - 2.6.6
5
+ - 2.7.2
data/README.md CHANGED
@@ -97,6 +97,8 @@ invoice.save_to_pdf('/path/to/invoice.pdf')
97
97
  # wartość domyślna: false
98
98
  :currency # waluta rozliczeniowa (string)
99
99
  # wartość domyślna: PLN
100
+ :exchange_rate # kurs waluty rozliczeniowej (float)
101
+ # wartość domyślna: 1.0000
100
102
 
101
103
  ### Parametry dodatkowe
102
104
 
@@ -106,6 +108,7 @@ invoice.save_to_pdf('/path/to/invoice.pdf')
106
108
  :pkwiu, # numer PKWiU (string)
107
109
  :no_vat_reason, # podstawa prawna zwolnienia z VAT (string)
108
110
  :footer, # treść umieszczana w stopce faktury (string)
111
+ :price_paid, # kwota częściowego opłacenia faktury w złotych (float)
109
112
 
110
113
  ### Parametry systemowe
111
114
 
@@ -20,7 +20,9 @@ invoice = PolishInvoicer::Invoice.new(
20
20
  # paid: false,
21
21
  foreign_buyer: true,
22
22
  reverse_charge: true,
23
- currency: 'USD'
23
+ currency: 'EUR',
24
+ exchange_rate: 3.5432,
25
+ comments: 'To jest komentarz w ważnej sprawie do dokumentu'
24
26
  )
25
27
  invoice.save_to_html('/tmp/invoice.html')
26
28
  invoice.save_to_pdf('/tmp/invoice.pdf')
@@ -11,6 +11,7 @@ module PolishInvoicer
11
11
  :recipient, # odbiorca faktury (tablica stringów)
12
12
  :item_name, # nazwa usługi (string)
13
13
  :price, # cena w złotych (float)
14
+ :price_paid, # kwota częściowego opłacenia faktury w złotych
14
15
  :gross_price, # znacznik rodzaju ceny (netto/brutto), domyślnie: true (boolean)
15
16
  :vat, # stawka vat, domyślnie: 23 (integer)
16
17
  :pkwiu, # numer PKWiU (string)
@@ -23,7 +24,8 @@ module PolishInvoicer
23
24
  :no_vat_reason, # podstawa prawna zwolnienia z VAT (string)
24
25
  :foreign_buyer, # nabywcą jest firma spoza Polski, domyślnie: false (boolean)
25
26
  :reverse_charge, # faktura z odwrotnym obciążeniem VAT
26
- :currency # waluta rozliczeniowa, domyślnie: PLN (string)
27
+ :currency, # waluta rozliczeniowa, domyślnie: PLN (string)
28
+ :exchange_rate # kurs waluty rozliczeniowej, domyślnie: 1.0000 (float)
27
29
  ].freeze
28
30
 
29
31
  attr_accessor(*AVAILABLE_PARAMS)
@@ -79,6 +81,22 @@ module PolishInvoicer
79
81
  Presenter.new(self).data
80
82
  end
81
83
 
84
+ def exchanged_tax
85
+ (vat_value * exchange_rate)
86
+ end
87
+
88
+ def total_to_pay_value
89
+ reverse_charge ? net_value : gross_value
90
+ end
91
+
92
+ def paid_value
93
+ paid ? total_to_pay_value : price_paid.to_f
94
+ end
95
+
96
+ def to_pay_value
97
+ paid ? 0 : (total_to_pay_value - price_paid.to_f)
98
+ end
99
+
82
100
  private
83
101
 
84
102
  def set_defaults
@@ -90,6 +108,7 @@ module PolishInvoicer
90
108
  @foreign_buyer = false
91
109
  @reverse_charge = false
92
110
  @currency = 'PLN'
111
+ @exchange_rate = 1.0000
93
112
  @recipient = []
94
113
  end
95
114
 
@@ -31,7 +31,7 @@ module PolishInvoicer
31
31
  end
32
32
 
33
33
  def copy_additional_params
34
- %w[net_value vat_value gross_value].each do |field|
34
+ %w[net_value vat_value gross_value exchanged_tax].each do |field|
35
35
  @out[field.to_sym] = @invoice.send(field)
36
36
  end
37
37
  end
@@ -45,7 +45,7 @@ module PolishInvoicer
45
45
  end
46
46
 
47
47
  def format_prices
48
- %w[net_value vat_value gross_value].each do |field|
48
+ %w[net_value vat_value gross_value exchanged_tax total_to_pay_value paid_value to_pay_value].each do |field|
49
49
  v = @invoice.send(field)
50
50
  next unless v
51
51
  @out[field.to_sym] = sprintf('%02.2f', v).tr('.', ',')
@@ -15,6 +15,7 @@ module PolishInvoicer
15
15
  check_arrays
16
16
  check_booleans
17
17
  check_price
18
+ check_price_paid
18
19
  check_vat
19
20
  check_proforma
20
21
  check_create_and_payment_date
@@ -42,6 +43,7 @@ module PolishInvoicer
42
43
  @errors[:gross_price] = 'Konieczne jest ustawienie znacznika rodzaju ceny (netto/brutto)' if @invoice.gross_price.nil?
43
44
  @errors[:paid] = 'Konieczne jest ustawienie znacznika opłacenia faktury' if @invoice.paid.nil?
44
45
  @errors[:currency] = 'Konieczne jest ustawienie waluty rozliczeniowej' if @invoice.currency.nil?
46
+ @errors[:exchange_rate] = 'Konieczne jest podanie kursu waluty rozliczeniowej' if @invoice.exchange_rate.nil?
45
47
  end
46
48
 
47
49
  def check_arrays
@@ -81,6 +83,18 @@ module PolishInvoicer
81
83
  end
82
84
  end
83
85
 
86
+ def check_price_paid
87
+ return if @invoice.price_paid.nil?
88
+ return if @invoice.price.nil?
89
+
90
+ if @invoice.price_paid.is_a?(Numeric)
91
+ @errors[:price_paid] = 'Kwota zapłacona musi być liczbą dodatnią' unless @invoice.price_paid >= 0
92
+ @errors[:price_paid] = 'Kwota zapłacona musi być mniejsza lub równa cenie' unless @invoice.price_paid <= @invoice.price
93
+ else
94
+ @errors[:price_paid] = 'Kwota zapłacona musi być liczbą'
95
+ end
96
+ end
97
+
84
98
  def check_vat
85
99
  if Vat.valid?(@invoice.vat)
86
100
  if Vat.zw?(@invoice.vat) && blank?(@invoice.no_vat_reason)
@@ -1,3 +1,3 @@
1
1
  module PolishInvoicer
2
- VERSION = '0.0.20'.freeze
2
+ VERSION = '0.0.25'.freeze
3
3
  end
@@ -133,5 +133,64 @@ module PolishInvoicer
133
133
  assert_equal false, h[:gross_price] # params
134
134
  assert_equal '123,45', h[:net_value] # presenter
135
135
  end
136
+
137
+ def test_total_to_pay_value
138
+ assert_equal 123, Invoice.new(price: 123).paid_value
139
+ assert_equal 100, Invoice.new(price: 123, reverse_charge: true).paid_value
140
+ end
141
+
142
+ def test_paid_value
143
+ assert_equal 123, Invoice.new(price: 123).paid_value
144
+ assert_equal 123, Invoice.new(price: 123, price_paid: 100).paid_value
145
+ assert_equal 0, Invoice.new(price: 123, paid: false).paid_value
146
+ assert_equal 100, Invoice.new(price: 123, paid: false, price_paid: 100).paid_value
147
+ assert_equal 100, Invoice.new(price: 123, gross_price: false, paid: false, price_paid: 100).paid_value
148
+ assert_equal 100, Invoice.new(price: 123, reverse_charge: true, paid: false, price_paid: 100).paid_value
149
+ end
150
+
151
+ def test_to_pay_value
152
+ assert_equal 0, Invoice.new(price: 123).to_pay_value
153
+ assert_equal 0, Invoice.new(price: 123, price_paid: 100).to_pay_value
154
+ assert_equal 123, Invoice.new(price: 123, paid: false).to_pay_value
155
+ assert_equal 23, Invoice.new(price: 123, paid: false, price_paid: 100).to_pay_value
156
+ assert_equal 23, Invoice.new(price: 100, gross_price: false, paid: false, price_paid: 100).to_pay_value
157
+ assert_equal 50, Invoice.new(price: 123, reverse_charge: true, paid: false, price_paid: 50).to_pay_value
158
+ end
159
+
160
+ def test_gross_and_net_price
161
+ gross_invoice = Invoice.new(price: 123, price_paid: 60, paid: false)
162
+ assert_equal 100, gross_invoice.net_value
163
+ assert_equal 23, gross_invoice.vat_value
164
+ assert_equal 123, gross_invoice.gross_value
165
+ assert_equal 123, gross_invoice.total_to_pay_value
166
+ assert_equal 60, gross_invoice.paid_value
167
+ assert_equal 63, gross_invoice.to_pay_value
168
+
169
+ net_invoice = Invoice.new(price: 100, price_paid: 60, paid: false, gross_price: false)
170
+ assert_equal 100, net_invoice.net_value
171
+ assert_equal 23, net_invoice.vat_value
172
+ assert_equal 123, net_invoice.gross_value
173
+ assert_equal 123, net_invoice.total_to_pay_value
174
+ assert_equal 60, net_invoice.paid_value
175
+ assert_equal 63, net_invoice.to_pay_value
176
+ end
177
+
178
+ def test_reverse_charge
179
+ gross_invoice = Invoice.new(price: 123, price_paid: 60, paid: false, reverse_charge: true)
180
+ assert_equal 100, gross_invoice.net_value
181
+ assert_equal 23, gross_invoice.vat_value
182
+ assert_equal 123, gross_invoice.gross_value
183
+ assert_equal 100, gross_invoice.total_to_pay_value
184
+ assert_equal 60, gross_invoice.paid_value
185
+ assert_equal 40, gross_invoice.to_pay_value
186
+
187
+ net_invoice = Invoice.new(price: 100, price_paid: 60, paid: false, gross_price: false, reverse_charge: true)
188
+ assert_equal 100, net_invoice.net_value
189
+ assert_equal 23, net_invoice.vat_value
190
+ assert_equal 123, net_invoice.gross_value
191
+ assert_equal 100, net_invoice.total_to_pay_value
192
+ assert_equal 60, net_invoice.paid_value
193
+ assert_equal 40, net_invoice.to_pay_value
194
+ end
136
195
  end
137
196
  end
@@ -54,6 +54,16 @@ module PolishInvoicer
54
54
  check_ok(:price, 19.99)
55
55
  end
56
56
 
57
+ def test_price_paid_validation
58
+ @invoice.price = 200
59
+ check_ok(:price_paid)
60
+ check_error(:price_paid, 'test')
61
+ check_error(:price_paid, '100')
62
+ check_error(:price_paid, -10)
63
+ check_error(:price_paid, 300)
64
+ check_ok(:price_paid, 19.99)
65
+ end
66
+
57
67
  def test_gross_price_validation
58
68
  check_error(:gross_price)
59
69
  check_error(:gross_price, 'test')
@@ -157,6 +167,17 @@ module PolishInvoicer
157
167
  refute v.errors[:currency]
158
168
  end
159
169
 
170
+ def test_exchange_rate
171
+ @invoice.exchange_rate = nil
172
+ v = Validator.new(@invoice)
173
+ v.valid?
174
+ assert v.errors[:exchange_rate]
175
+ @invoice.exchange_rate = 4,1234
176
+ v = Validator.new(@invoice)
177
+ v.valid?
178
+ refute v.errors[:exchange_rate]
179
+ end
180
+
160
181
  private
161
182
 
162
183
  def check_error(field, value = nil)
@@ -127,7 +127,7 @@ html
127
127
  - unless reverse_charge
128
128
  td.text-center = vat
129
129
  td.text-center = vat_value
130
- td.text-center = gross_value
130
+ td.text-center = total_to_pay_value
131
131
  tr
132
132
  td colspan="#{pkwiu ? 3 : 2}"
133
133
  | &nbsp;
@@ -139,7 +139,7 @@ html
139
139
  - unless reverse_charge
140
140
  td.text-center = vat
141
141
  td.text-center = vat_value
142
- th.text-center = gross_value
142
+ th.text-center = total_to_pay_value
143
143
 
144
144
  br
145
145
 
@@ -151,27 +151,35 @@ html
151
151
  .small
152
152
  em Total to pay:
153
153
  .col-xs-6
154
- b = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
154
+ b = "#{total_to_pay_value} #{currency}"
155
155
  .row
156
156
  .col-xs-6
157
157
  | Zapłacono:
158
158
  .small
159
159
  em Amount paid:
160
- .col-xs-6
161
- - if paid
162
- = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
163
- - else
164
- = "0,00 #{currency}"
160
+ .col-xs-6 = "#{paid_value} #{currency}"
165
161
  .row
166
162
  .col-xs-6
167
163
  | Zostało do zapłaty:
168
164
  .small
169
165
  em Left to pay:
170
- .col-xs-6
171
- - if paid
172
- = "0,00 #{currency}"
173
- - else
174
- = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
166
+ .col-xs-6 = "#{to_pay_value} #{currency}"
167
+ - if currency != 'PLN'
168
+ .row
169
+ .col-xs-6
170
+ | Kurs waluty:
171
+ .small
172
+ em Exchange rate:
173
+ .col-xs-6
174
+ = exchange_rate
175
+ - unless reverse_charge
176
+ .row
177
+ .col-xs-6
178
+ | Podatek w PLN:
179
+ .small
180
+ em Exchanged tax amount:
181
+ .col-xs-6
182
+ = "#{exchanged_tax} PLN"
175
183
 
176
184
  .col-xs-6
177
185
  - if comments.any?
@@ -83,7 +83,7 @@ html
83
83
  td.text-center = net_value
84
84
  td.text-center = vat
85
85
  td.text-center = vat_value
86
- td.text-center = gross_value
86
+ td.text-center = total_to_pay_value
87
87
  tr
88
88
  td colspan="#{pkwiu ? 3 : 2}"
89
89
  | &nbsp;
@@ -91,7 +91,7 @@ html
91
91
  td.text-center = net_value
92
92
  td.text-center = vat
93
93
  td.text-center = vat_value
94
- th.text-center = gross_value
94
+ th.text-center = total_to_pay_value
95
95
 
96
96
  br
97
97
 
@@ -102,18 +102,22 @@ html
102
102
  | Zapłacono:
103
103
  br
104
104
  | Zostało do zapłaty:
105
+ - if currency != 'PLN'
106
+ br
107
+ | Kurs waluty:
108
+ br
109
+ | Podatek w PLN:
105
110
  .col-xs-3
106
- b = "#{gross_value} #{currency}"
111
+ b = "#{total_to_pay_value} #{currency}"
107
112
  br
108
- - if paid
109
- = "#{gross_value} #{currency}"
110
- - else
111
- = "0,00 #{currency}"
113
+ = "#{paid_value} #{currency}"
112
114
  br
113
- - if paid
114
- = "0,00 #{currency}"
115
- - else
116
- = "#{gross_value} #{currency}"
115
+ = "#{to_pay_value} #{currency}"
116
+ - if currency != 'PLN'
117
+ br
118
+ = exchange_rate
119
+ br
120
+ = "#{exchanged_tax} PLN"
117
121
  - if comments.any?
118
122
  .col-xs-6
119
123
  b Uwagi:
@@ -115,7 +115,7 @@ html
115
115
  em 1&nbsp;service
116
116
  td.text-center = net_value
117
117
  td.text-center = net_value
118
- td.text-center = (reverse_charge == true ? net_value : gross_value)
118
+ td.text-center = total_to_pay_value
119
119
  tr
120
120
  td colspan="#{pkwiu ? 3 : 2}"
121
121
  | &nbsp;
@@ -124,7 +124,7 @@ html
124
124
  .small
125
125
  em Total
126
126
  td.text-center = net_value
127
- th.text-center = (reverse_charge == true ? net_value : gross_value)
127
+ th.text-center = total_to_pay_value
128
128
 
129
129
  br
130
130
 
@@ -136,27 +136,19 @@ html
136
136
  .small
137
137
  em Total to pay:
138
138
  .col-xs-6
139
- b = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
139
+ b = "#{total_to_pay_value} #{currency}"
140
140
  .row
141
141
  .col-xs-6
142
142
  | Zapłacono:
143
143
  .small
144
144
  em Amount paid:
145
- .col-xs-6
146
- - if paid
147
- = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
148
- - else
149
- = "0,00 #{currency}"
145
+ .col-xs-6 = "#{paid_value} #{currency}"
150
146
  .row
151
147
  .col-xs-6
152
148
  | Zostało do zapłaty:
153
149
  .small
154
150
  em Left to pay:
155
- .col-xs-6
156
- - if paid
157
- = "0,00 #{currency}"
158
- - else
159
- = "#{reverse_charge == true ? net_value : gross_value} #{currency}"
151
+ .col-xs-6 = "#{to_pay_value} #{currency}"
160
152
 
161
153
  .col-xs-6
162
154
  - if comments.any?
@@ -77,13 +77,13 @@ html
77
77
  | 1&nbsp;usł.
78
78
  td.text-center = net_value
79
79
  td.text-center = net_value
80
- td.text-center = gross_value
80
+ td.text-center = total_to_pay_value
81
81
  tr
82
82
  td colspan="#{pkwiu ? 3 : 2}"
83
83
  | &nbsp;
84
84
  th.text-center Razem
85
85
  td.text-center = net_value
86
- th.text-center = gross_value
86
+ th.text-center = total_to_pay_value
87
87
 
88
88
  br
89
89
 
@@ -95,17 +95,11 @@ html
95
95
  br
96
96
  | Zostało do zapłaty:
97
97
  .col-xs-3
98
- b = "#{gross_value} #{currency}"
98
+ b = "#{total_to_pay_value} #{currency}"
99
99
  br
100
- - if paid
101
- = "#{gross_value} #{currency}"
102
- - else
103
- = "0,00 #{currency}"
100
+ = "#{paid_value} #{currency}"
104
101
  br
105
- - if paid
106
- = "0,00 #{currency}"
107
- - else
108
- = "#{gross_value} #{currency}"
102
+ = "#{to_pay_value} #{currency}"
109
103
  - if comments.any?
110
104
  .col-xs-6
111
105
  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.20
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Macuk
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-11 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,7 +137,7 @@ homepage: ''
137
137
  licenses:
138
138
  - MIT
139
139
  metadata: {}
140
- post_install_message:
140
+ post_install_message:
141
141
  rdoc_options: []
142
142
  require_paths:
143
143
  - lib
@@ -152,9 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 2.6.14.1
157
- signing_key:
155
+ rubygems_version: 3.1.4
156
+ signing_key:
158
157
  specification_version: 4
159
158
  summary: Creates polish invoices and proforms as HTML or PDF files
160
159
  test_files: