polish_invoicer 0.0.23 → 0.0.24

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: 9f720394b35d68552ab3e36b2db34f213024797d
4
- data.tar.gz: 70e8b6d45d50b0f255d665d9ccea85d5d5dd354f
2
+ SHA256:
3
+ metadata.gz: 83d6168d0e9d3dee433a2d9a0e7b6444120ea67834543ea6faf56ba4bf97d573
4
+ data.tar.gz: 12ce7534dd021a52e3b78efd9cb07e2f8872fd2b97c731c672785e68560b03fb
5
5
  SHA512:
6
- metadata.gz: 9a898a23b93bdc22b4b8acde9d1acc24447551dabef29b8bcaf5fedebeef68ba188f1ec51e1f5bccdb3fb072d218234e1bdbd6c7318871d338876d1917e2e130
7
- data.tar.gz: 78870d3a6072be8f966b57f752c8b360aca9bbdedc7bfe3e8056e2eb6de9235e08c5387b527a54f99640c485dd58931263d5d39d945b87ba79502d2deec72673
6
+ metadata.gz: 78c45cea18508cdabaef2d83a67b622135b1270b251f7ae9fa291ef31818ba0368784a28a1800ceaa811b6fdb470993dbf0815e41e443050a65146ffb7e5b6fb
7
+ data.tar.gz: 2ea922f4e34e5b20a27204ef7ca3a189a211cf1d8cb31da26c74310a6d8a468214ebf5902f0b5020783832397b4885c90ff181252440bbe39ee78b8289dced83
@@ -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
@@ -87,6 +87,8 @@ invoice.save_to_pdf('/path/to/invoice.pdf')
87
87
  # wartość domyślna: 23
88
88
  :paid, # znacznik opłacenia usługi (boolean)
89
89
  # wartość domyślna: true, czyli opłacona
90
+ :price_paid, # kwota częściowego opłacenia faktury w złotych (float)
91
+ # wartość domyślna: 0.0
90
92
  :proforma, # znacznik faktury pro-forma (boolean)
91
93
  # wartość domyślna: false
92
94
  :payment_type, # rodzaj płatności (string)
@@ -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, domyślnie: 0.0 (float)
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)
@@ -84,6 +85,18 @@ module PolishInvoicer
84
85
  (vat_value * exchange_rate)
85
86
  end
86
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
94
+ end
95
+
96
+ def to_pay_value
97
+ paid ? 0 : (total_to_pay_value - price_paid)
98
+ end
99
+
87
100
  private
88
101
 
89
102
  def set_defaults
@@ -91,6 +104,7 @@ module PolishInvoicer
91
104
  @vat = 23
92
105
  @payment_type = 'Przelew'
93
106
  @paid = true
107
+ @price_paid = 0.0
94
108
  @proforma = false
95
109
  @foreign_buyer = false
96
110
  @reverse_charge = false
@@ -45,7 +45,7 @@ module PolishInvoicer
45
45
  end
46
46
 
47
47
  def format_prices
48
- %w[net_value vat_value gross_value exchanged_tax].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
@@ -82,6 +83,16 @@ module PolishInvoicer
82
83
  end
83
84
  end
84
85
 
86
+ def check_price_paid
87
+ return if @invoice.price.nil?
88
+ if @invoice.price_paid.is_a?(Numeric)
89
+ @errors[:price_paid] = 'Kwota zapłacona musi być liczbą dodatnią' unless @invoice.price_paid >= 0
90
+ @errors[:price_paid] = 'Kwota zapłacona musi być mniejsza lub równa cenie' unless @invoice.price_paid <= @invoice.price
91
+ else
92
+ @errors[:price_paid] = 'Kwota zapłacona musi być liczbą'
93
+ end
94
+ end
95
+
85
96
  def check_vat
86
97
  if Vat.valid?(@invoice.vat)
87
98
  if Vat.zw?(@invoice.vat) && blank?(@invoice.no_vat_reason)
@@ -1,3 +1,3 @@
1
1
  module PolishInvoicer
2
- VERSION = '0.0.23'.freeze
2
+ VERSION = '0.0.24'.freeze
3
3
  end
@@ -133,5 +133,62 @@ 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 100, Invoice.new(price: 123, paid: false, price_paid: 100).paid_value
146
+ assert_equal 100, Invoice.new(price: 123, gross_price: false, paid: false, price_paid: 100).paid_value
147
+ assert_equal 100, Invoice.new(price: 123, reverse_charge: true, paid: false, price_paid: 100).paid_value
148
+ end
149
+
150
+ def test_to_pay_value
151
+ assert_equal 0, Invoice.new(price: 123).to_pay_value
152
+ assert_equal 0, Invoice.new(price: 123, price_paid: 100).to_pay_value
153
+ assert_equal 23, Invoice.new(price: 123, paid: false, price_paid: 100).to_pay_value
154
+ assert_equal 23, Invoice.new(price: 100, gross_price: false, paid: false, price_paid: 100).to_pay_value
155
+ assert_equal 50, Invoice.new(price: 123, reverse_charge: true, paid: false, price_paid: 50).to_pay_value
156
+ end
157
+
158
+ def test_gross_and_net_price
159
+ gross_invoice = Invoice.new(price: 123, price_paid: 60, paid: false)
160
+ assert_equal 100, gross_invoice.net_value
161
+ assert_equal 23, gross_invoice.vat_value
162
+ assert_equal 123, gross_invoice.gross_value
163
+ assert_equal 123, gross_invoice.total_to_pay_value
164
+ assert_equal 60, gross_invoice.paid_value
165
+ assert_equal 63, gross_invoice.to_pay_value
166
+
167
+ net_invoice = Invoice.new(price: 100, price_paid: 60, paid: false, gross_price: false)
168
+ assert_equal 100, net_invoice.net_value
169
+ assert_equal 23, net_invoice.vat_value
170
+ assert_equal 123, net_invoice.gross_value
171
+ assert_equal 123, net_invoice.total_to_pay_value
172
+ assert_equal 60, net_invoice.paid_value
173
+ assert_equal 63, net_invoice.to_pay_value
174
+ end
175
+
176
+ def test_reverse_charge
177
+ gross_invoice = Invoice.new(price: 123, price_paid: 60, paid: false, reverse_charge: true)
178
+ assert_equal 100, gross_invoice.net_value
179
+ assert_equal 23, gross_invoice.vat_value
180
+ assert_equal 123, gross_invoice.gross_value
181
+ assert_equal 100, gross_invoice.total_to_pay_value
182
+ assert_equal 60, gross_invoice.paid_value
183
+ assert_equal 40, gross_invoice.to_pay_value
184
+
185
+ net_invoice = Invoice.new(price: 100, price_paid: 60, paid: false, gross_price: false, reverse_charge: true)
186
+ assert_equal 100, net_invoice.net_value
187
+ assert_equal 23, net_invoice.vat_value
188
+ assert_equal 123, net_invoice.gross_value
189
+ assert_equal 100, net_invoice.total_to_pay_value
190
+ assert_equal 60, net_invoice.paid_value
191
+ assert_equal 40, net_invoice.to_pay_value
192
+ end
136
193
  end
137
194
  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_error(: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')
@@ -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,19 @@ 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}"
175
167
  - if currency != 'PLN'
176
168
  .row
177
169
  .col-xs-6
@@ -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
 
@@ -108,17 +108,11 @@ html
108
108
  br
109
109
  | Podatek w PLN:
110
110
  .col-xs-3
111
- b = "#{gross_value} #{currency}"
111
+ b = "#{total_to_pay_value} #{currency}"
112
112
  br
113
- - if paid
114
- = "#{gross_value} #{currency}"
115
- - else
116
- = "0,00 #{currency}"
113
+ = "#{paid_value} #{currency}"
117
114
  br
118
- - if paid
119
- = "0,00 #{currency}"
120
- - else
121
- = "#{gross_value} #{currency}"
115
+ = "#{to_pay_value} #{currency}"
122
116
  - if currency != 'PLN'
123
117
  br
124
118
  = exchange_rate
@@ -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.23
4
+ version: 0.0.24
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-09-24 00:00:00.000000000 Z
11
+ date: 2020-10-28 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.0.8
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: