lucadeal 0.2.13 → 0.2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/luca_deal/contract.rb +1 -0
- data/lib/luca_deal/customer.rb +1 -0
- data/lib/luca_deal/invoice.rb +23 -11
- data/lib/luca_deal/product.rb +25 -17
- data/lib/luca_deal/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1b2a723a3fc191616f5a602a58428797afe69b19f9ee7e8d78d7dd187ae9b73
|
4
|
+
data.tar.gz: b45c547d86312b94b702c68b94999be576c4f14fb55258b7961aa218ff4f74ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9daff536435c5bcbcc9f6694b4068df22f108d667283eb48754fdda02121f3724312ca0257d7029ec09f27034112af72123e734b2262c6f91c3b93f56a099b4e
|
7
|
+
data.tar.gz: bdd40230688a1080fee49472adc22e8a98e53988aa2822688efc9e8537a0095de7919ec6c2c4a810da8f82e315fa714b2507d1e417dc07140fa0f1f897a31b0e
|
data/README.md
CHANGED
@@ -75,6 +75,8 @@ Fields for subscription customers are as bellows:
|
|
75
75
|
| terms | | | | |
|
76
76
|
| | billing_cycle | optional | | If 'monthly', invoices are generated on each month. |
|
77
77
|
| | category | optional | | Default: 'subscription' |
|
78
|
+
| products | | | | Array of products. |
|
79
|
+
| | id | | | reference for Product |
|
78
80
|
| items | | | | Array of items. |
|
79
81
|
| | name | | x | Item name. |
|
80
82
|
| | price | | x | Item price. |
|
@@ -115,6 +117,7 @@ Invoice is basically auto generated from Customer and Contract objects.
|
|
115
117
|
| | price | Item price. |
|
116
118
|
| | qty | quantity. Default: 1. |
|
117
119
|
| | type | |
|
120
|
+
| | product_id | refrence for Product |
|
118
121
|
| subtotal | | Array of subtotal by tax category. |
|
119
122
|
| | items | amount of items |
|
120
123
|
| | tax | amount of tax |
|
data/lib/luca_deal/contract.rb
CHANGED
data/lib/luca_deal/customer.rb
CHANGED
data/lib/luca_deal/invoice.rb
CHANGED
@@ -12,6 +12,7 @@ require 'luca_record'
|
|
12
12
|
module LucaDeal
|
13
13
|
class Invoice < LucaRecord::Base
|
14
14
|
@dirname = 'invoices'
|
15
|
+
@required = ['issue_date', 'customer', 'items', 'subtotal']
|
15
16
|
|
16
17
|
def initialize(date = nil)
|
17
18
|
@date = issue_date(date)
|
@@ -113,16 +114,12 @@ module LucaDeal
|
|
113
114
|
invoice['due_date'] = due_date(@date)
|
114
115
|
invoice['issue_date'] = @date
|
115
116
|
invoice['sales_fee'] = contract.dig('sales_fee')
|
116
|
-
invoice['items'] = contract
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
h['qty'] = item.dig('qty') || 1
|
123
|
-
h['type'] = item.dig('type') if item.dig('type')
|
124
|
-
end
|
125
|
-
end.compact
|
117
|
+
invoice['items'] = get_products(contract['products'])
|
118
|
+
.concat(contract['items']&.map { |i| i['qty'] ||= 1; i } || [])
|
119
|
+
.compact
|
120
|
+
invoice['items'].reject! do |item|
|
121
|
+
item.dig('type') == 'initial' && subsequent_month?(contract.dig('terms', 'effective'))
|
122
|
+
end
|
126
123
|
invoice['subtotal'] = subtotal(invoice['items'])
|
127
124
|
.map { |k, v| v.tap { |dat| dat['rate'] = k } }
|
128
125
|
gen_invoice!(invoice)
|
@@ -153,6 +150,20 @@ module LucaDeal
|
|
153
150
|
end
|
154
151
|
end
|
155
152
|
|
153
|
+
def get_products(products)
|
154
|
+
return [] if products.nil?
|
155
|
+
|
156
|
+
[].tap do |res|
|
157
|
+
products.each do |product|
|
158
|
+
LucaDeal::Product.find(product['id'])['items'].each do |item|
|
159
|
+
item['product_id'] = product['id']
|
160
|
+
item['qty'] ||= 1
|
161
|
+
res << item
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
156
167
|
def gen_invoice!(invoice)
|
157
168
|
id = invoice.dig('contract_id')
|
158
169
|
self.class.create_record!(invoice, @date, Array(id))
|
@@ -190,8 +201,9 @@ module LucaDeal
|
|
190
201
|
{}.tap do |subtotal|
|
191
202
|
items.each do |i|
|
192
203
|
rate = i.dig('tax') || 'default'
|
204
|
+
qty = i['qty'] || 1
|
193
205
|
subtotal[rate] = { 'items' => 0, 'tax' => 0 } if subtotal.dig(rate).nil?
|
194
|
-
subtotal[rate]['items'] +=
|
206
|
+
subtotal[rate]['items'] += qty * i['price']
|
195
207
|
end
|
196
208
|
subtotal.each do |rate, amount|
|
197
209
|
amount['tax'] = (amount['items'] * load_tax_rate(rate)).to_i
|
data/lib/luca_deal/product.rb
CHANGED
@@ -10,32 +10,40 @@ require 'luca_record'
|
|
10
10
|
module LucaDeal
|
11
11
|
class Product < LucaRecord::Base
|
12
12
|
@dirname = 'products'
|
13
|
+
@required = ['items']
|
13
14
|
|
14
15
|
def list_name
|
15
16
|
list = self.class.all.map { |dat| parse_current(dat) }
|
16
17
|
YAML.dump(list).tap { |l| puts l }
|
17
18
|
end
|
18
19
|
|
20
|
+
# Save data with hash in Product format. Simple format is also available as bellows:
|
21
|
+
# {
|
22
|
+
# name: 'item_name(required)', price: 'item_price', qty: 'item_qty',
|
23
|
+
# initial: { name: 'item_name', price: 'item_price', qty: 'item_qty' }
|
24
|
+
# }
|
19
25
|
def self.create(obj)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
if obj[:name].nil?
|
27
|
+
h = obj
|
28
|
+
else
|
29
|
+
items = [{
|
30
|
+
'name' => obj[:name],
|
31
|
+
'price' => obj[:price] || 0,
|
32
|
+
'qty' => obj[:qty] || 1
|
33
|
+
}]
|
34
|
+
if obj[:initial]
|
35
|
+
items << {
|
36
|
+
'name' => obj.dig(:initial, :name),
|
37
|
+
'price' => obj.dig(:initial, :price) || 0,
|
38
|
+
'qty' => obj.dig(:initial, :qty) || 1,
|
39
|
+
'type' => 'initial'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
h = {
|
43
|
+
'name' => obj[:name],
|
44
|
+
'items' => items
|
33
45
|
}
|
34
46
|
end
|
35
|
-
h = {
|
36
|
-
'name' => obj[:name],
|
37
|
-
'items' => items
|
38
|
-
}
|
39
47
|
super(h)
|
40
48
|
end
|
41
49
|
end
|
data/lib/luca_deal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucadeal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chuma Takahiro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lucarecord
|