einvoice 2.0.0.alpha2 → 2.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +1 -1
- data/.github/workflows/cron.yml +33 -0
- data/CHANGELOG.md +20 -0
- data/README.md +150 -84
- data/README.zh-TW.md +140 -81
- data/einvoice.gemspec +3 -2
- data/lib/einvoice/amego/payload.rb +4 -10
- data/lib/einvoice/amego/provider.rb +17 -12
- data/lib/einvoice/ecpay/client.rb +4 -3
- data/lib/einvoice/ecpay/payload.rb +9 -9
- data/lib/einvoice/ecpay/provider.rb +26 -17
- data/lib/einvoice/ezpay/payload.rb +3 -3
- data/lib/einvoice/ezpay/provider.rb +31 -13
- data/lib/einvoice/input.rb +66 -13
- data/lib/einvoice/mock_provider.rb +1 -1
- data/lib/einvoice/number.rb +40 -0
- data/lib/einvoice/tax_split.rb +27 -39
- data/lib/einvoice/tradevan/default_api/payload.rb +3 -3
- data/lib/einvoice/tradevan/default_api/provider.rb +11 -24
- data/lib/einvoice/types.rb +48 -6
- data/lib/einvoice/version.rb +1 -1
- metadata +4 -3
data/lib/einvoice/types.rb
CHANGED
|
@@ -29,11 +29,26 @@ module Einvoice
|
|
|
29
29
|
|
|
30
30
|
module_function
|
|
31
31
|
|
|
32
|
+
# The tax type of each item, in item order. An item without a tax_type
|
|
33
|
+
# has the invoice's. This is the only place that applies that rule.
|
|
34
|
+
def per_item(items, invoice_tax_type)
|
|
35
|
+
items.map { |item| item.tax_type || invoice_tax_type }
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
# The tax type of a whole invoice: the one its items share, else MIXED.
|
|
33
39
|
def of(items, invoice_tax_type)
|
|
34
|
-
kinds = items
|
|
40
|
+
kinds = per_item(items, invoice_tax_type).uniq
|
|
35
41
|
kinds.size > 1 ? MIXED : kinds.first || invoice_tax_type
|
|
36
42
|
end
|
|
43
|
+
|
|
44
|
+
# The items of an existing invoice, read back from a provider. An item that
|
|
45
|
+
# the provider sent without a tax type has the invoice's, unless the
|
|
46
|
+
# invoice is MIXED: then each item has to say its own.
|
|
47
|
+
def fill_items(items, invoice_tax_type)
|
|
48
|
+
return items if invoice_tax_type.nil? || invoice_tax_type == MIXED
|
|
49
|
+
|
|
50
|
+
items.map { |item| item.tax_type ? item : item.with(tax_type: invoice_tax_type) }
|
|
51
|
+
end
|
|
37
52
|
end
|
|
38
53
|
|
|
39
54
|
# Invoice category. Derived from whether the buyer has a 統一編號:
|
|
@@ -115,6 +130,12 @@ module Einvoice
|
|
|
115
130
|
# {Input} enforces it on the way in, and both the adapters and
|
|
116
131
|
# {MOF::DonationCodes} refer to it rather than restating the pattern.
|
|
117
132
|
#
|
|
133
|
+
# F0401 NPOBAN also takes the recipient's 統一編號 [mig 表 15-3]. A recipient
|
|
134
|
+
# is always a 受捐贈機關或團體 that has registered on the MOF platform
|
|
135
|
+
# (電子發票實施作業要點第 2 點), not any company. At the time of sale the
|
|
136
|
+
# buyer gives a 愛心碼 (第 22 點), so the core takes that form only. ECPay and
|
|
137
|
+
# ezPay take 3 to 7 digits only too.
|
|
138
|
+
#
|
|
118
139
|
# Assigned here rather than inside a +Data.define+ block, where a constant
|
|
119
140
|
# would land in +Einvoice+ instead of on this class — the block is evaluated
|
|
120
141
|
# with the enclosing lexical scope, so +Donation::CODE_FORMAT+ would not exist.
|
|
@@ -151,9 +172,19 @@ module Einvoice
|
|
|
151
172
|
super
|
|
152
173
|
end
|
|
153
174
|
|
|
175
|
+
# The tax type of each item, in item order. See TaxType.per_item.
|
|
176
|
+
def item_tax_types
|
|
177
|
+
TaxType.per_item(items, tax_type)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# The tax type of the whole invoice: the one its items share, else MIXED.
|
|
181
|
+
def resolved_tax_type
|
|
182
|
+
TaxType.of(items, tax_type)
|
|
183
|
+
end
|
|
184
|
+
|
|
154
185
|
# True when a line is zero rated, by its own tax type or the invoice's.
|
|
155
186
|
def zero_rated?
|
|
156
|
-
|
|
187
|
+
item_tax_types.include?(TaxType::ZERO_RATED)
|
|
157
188
|
end
|
|
158
189
|
|
|
159
190
|
# Explicit +category+, else derived from the buyer's 統一編號.
|
|
@@ -163,8 +194,8 @@ module Einvoice
|
|
|
163
194
|
|
|
164
195
|
# The tax of every line and the MIG totals, computed by the core. See
|
|
165
196
|
# {TaxBreakdown}.
|
|
166
|
-
def tax_breakdown
|
|
167
|
-
TaxSplit.breakdown(items,
|
|
197
|
+
def tax_breakdown
|
|
198
|
+
TaxSplit.breakdown(items, types: item_tax_types, tax_rate: tax_rate, price_mode: price_mode)
|
|
168
199
|
end
|
|
169
200
|
end
|
|
170
201
|
|
|
@@ -262,8 +293,19 @@ module Einvoice
|
|
|
262
293
|
super
|
|
263
294
|
end
|
|
264
295
|
|
|
265
|
-
|
|
266
|
-
|
|
296
|
+
# See IssueInvoiceInput#item_tax_types.
|
|
297
|
+
def item_tax_types
|
|
298
|
+
TaxType.per_item(items, tax_type)
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
# See IssueInvoiceInput#resolved_tax_type.
|
|
302
|
+
def resolved_tax_type
|
|
303
|
+
TaxType.of(items, tax_type)
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# See IssueInvoiceInput#tax_breakdown.
|
|
307
|
+
def tax_breakdown
|
|
308
|
+
TaxSplit.breakdown(items, types: item_tax_types, tax_rate: tax_rate, price_mode: price_mode)
|
|
267
309
|
end
|
|
268
310
|
end
|
|
269
311
|
|
data/lib/einvoice/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: einvoice
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.0.
|
|
4
|
+
version: 2.0.0.beta1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Yun
|
|
@@ -73,6 +73,7 @@ extra_rdoc_files: []
|
|
|
73
73
|
files:
|
|
74
74
|
- ".coderabbit.yaml"
|
|
75
75
|
- ".github/workflows/build.yml"
|
|
76
|
+
- ".github/workflows/cron.yml"
|
|
76
77
|
- ".gitignore"
|
|
77
78
|
- ".rspec"
|
|
78
79
|
- CHANGELOG.md
|
|
@@ -127,7 +128,7 @@ licenses:
|
|
|
127
128
|
- MIT
|
|
128
129
|
metadata:
|
|
129
130
|
source_code_uri: https://github.com/abookyun/einvoice
|
|
130
|
-
changelog_uri: https://github.com/abookyun/einvoice/blob/v2.0.0.
|
|
131
|
+
changelog_uri: https://github.com/abookyun/einvoice/blob/v2.0.0.beta1/CHANGELOG.md
|
|
131
132
|
bug_tracker_uri: https://github.com/abookyun/einvoice/issues
|
|
132
133
|
rubygems_mfa_required: 'true'
|
|
133
134
|
rdoc_options: []
|
|
@@ -137,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
137
138
|
requirements:
|
|
138
139
|
- - ">="
|
|
139
140
|
- !ruby/object:Gem::Version
|
|
140
|
-
version: '3.
|
|
141
|
+
version: '3.3'
|
|
141
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
requirements:
|
|
143
144
|
- - ">="
|