cashctrl 0.0.1 → 0.2.0
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/LICENSE.txt +21 -0
- data/README.md +831 -14
- data/cashctrl.gemspec +1 -1
- data/lib/cashctrl/client.rb +219 -0
- data/lib/cashctrl/collection.rb +78 -0
- data/lib/cashctrl/configuration.rb +30 -0
- data/lib/cashctrl/error.rb +29 -0
- data/lib/cashctrl/errors.rb +76 -0
- data/lib/cashctrl/localized_string.rb +115 -0
- data/lib/cashctrl/models/account.rb +39 -0
- data/lib/cashctrl/models/article.rb +48 -0
- data/lib/cashctrl/models/asset.rb +37 -0
- data/lib/cashctrl/models/attachment.rb +14 -0
- data/lib/cashctrl/models/bank.rb +18 -0
- data/lib/cashctrl/models/category.rb +13 -0
- data/lib/cashctrl/models/certificate_document.rb +14 -0
- data/lib/cashctrl/models/certificate_template.rb +13 -0
- data/lib/cashctrl/models/cost_center.rb +17 -0
- data/lib/cashctrl/models/currency.rb +18 -0
- data/lib/cashctrl/models/custom_field.rb +18 -0
- data/lib/cashctrl/models/custom_field_group.rb +12 -0
- data/lib/cashctrl/models/file.rb +20 -0
- data/lib/cashctrl/models/fiscal_period.rb +16 -0
- data/lib/cashctrl/models/fiscal_period_task.rb +14 -0
- data/lib/cashctrl/models/history.rb +19 -0
- data/lib/cashctrl/models/insurance_type.rb +13 -0
- data/lib/cashctrl/models/journal.rb +65 -0
- data/lib/cashctrl/models/journal_import.rb +18 -0
- data/lib/cashctrl/models/journal_import_entry.rb +20 -0
- data/lib/cashctrl/models/journal_item.rb +20 -0
- data/lib/cashctrl/models/loader.rb +55 -0
- data/lib/cashctrl/models/location.rb +22 -0
- data/lib/cashctrl/models/order.rb +53 -0
- data/lib/cashctrl/models/order_book_entry.rb +17 -0
- data/lib/cashctrl/models/order_document.rb +15 -0
- data/lib/cashctrl/models/order_item.rb +23 -0
- data/lib/cashctrl/models/order_layout.rb +18 -0
- data/lib/cashctrl/models/order_payment.rb +16 -0
- data/lib/cashctrl/models/person.rb +78 -0
- data/lib/cashctrl/models/report.rb +15 -0
- data/lib/cashctrl/models/report_collection.rb +13 -0
- data/lib/cashctrl/models/report_element.rb +16 -0
- data/lib/cashctrl/models/rounding.rb +16 -0
- data/lib/cashctrl/models/salary_book_entry.rb +16 -0
- data/lib/cashctrl/models/salary_certificate.rb +16 -0
- data/lib/cashctrl/models/salary_document.rb +15 -0
- data/lib/cashctrl/models/salary_field.rb +16 -0
- data/lib/cashctrl/models/salary_layout.rb +13 -0
- data/lib/cashctrl/models/salary_payment.rb +16 -0
- data/lib/cashctrl/models/salary_setting.rb +12 -0
- data/lib/cashctrl/models/salary_statement.rb +19 -0
- data/lib/cashctrl/models/salary_status.rb +12 -0
- data/lib/cashctrl/models/salary_sum.rb +14 -0
- data/lib/cashctrl/models/salary_template.rb +12 -0
- data/lib/cashctrl/models/salary_type.rb +14 -0
- data/lib/cashctrl/models/sequence_number.rb +13 -0
- data/lib/cashctrl/models/setting.rb +33 -0
- data/lib/cashctrl/models/tax.rb +18 -0
- data/lib/cashctrl/models/text.rb +13 -0
- data/lib/cashctrl/models/title.rb +13 -0
- data/lib/cashctrl/models/unit.rb +11 -0
- data/lib/cashctrl/relation.rb +271 -0
- data/lib/cashctrl/resource.rb +433 -0
- data/lib/cashctrl/resources/account/bank.rb +14 -0
- data/lib/cashctrl/resources/account/category.rb +16 -0
- data/lib/cashctrl/resources/account/cost_center/category.rb +18 -0
- data/lib/cashctrl/resources/account/cost_center.rb +26 -0
- data/lib/cashctrl/resources/account.rb +28 -0
- data/lib/cashctrl/resources/attachments.rb +32 -0
- data/lib/cashctrl/resources/base.rb +237 -0
- data/lib/cashctrl/resources/currency.rb +17 -0
- data/lib/cashctrl/resources/custom_field/group.rb +16 -0
- data/lib/cashctrl/resources/custom_field.rb +18 -0
- data/lib/cashctrl/resources/file/category.rb +16 -0
- data/lib/cashctrl/resources/file.rb +82 -0
- data/lib/cashctrl/resources/fiscal_period/task.rb +20 -0
- data/lib/cashctrl/resources/fiscal_period.rb +54 -0
- data/lib/cashctrl/resources/history.rb +26 -0
- data/lib/cashctrl/resources/import_session.rb +43 -0
- data/lib/cashctrl/resources/inventory/article/category.rb +18 -0
- data/lib/cashctrl/resources/inventory/article/import.rb +13 -0
- data/lib/cashctrl/resources/inventory/article.rb +19 -0
- data/lib/cashctrl/resources/inventory/asset/category.rb +18 -0
- data/lib/cashctrl/resources/inventory/asset.rb +19 -0
- data/lib/cashctrl/resources/inventory/unit.rb +12 -0
- data/lib/cashctrl/resources/journal/import/entry.rb +33 -0
- data/lib/cashctrl/resources/journal/import.rb +16 -0
- data/lib/cashctrl/resources/journal.rb +56 -0
- data/lib/cashctrl/resources/location.rb +10 -0
- data/lib/cashctrl/resources/order/book_entry.rb +12 -0
- data/lib/cashctrl/resources/order/category.rb +21 -0
- data/lib/cashctrl/resources/order/document.rb +30 -0
- data/lib/cashctrl/resources/order/layout.rb +12 -0
- data/lib/cashctrl/resources/order/payment.rb +36 -0
- data/lib/cashctrl/resources/order.rb +47 -0
- data/lib/cashctrl/resources/organization.rb +13 -0
- data/lib/cashctrl/resources/person/category.rb +16 -0
- data/lib/cashctrl/resources/person/import.rb +11 -0
- data/lib/cashctrl/resources/person/title.rb +12 -0
- data/lib/cashctrl/resources/person.rb +21 -0
- data/lib/cashctrl/resources/report/collection.rb +40 -0
- data/lib/cashctrl/resources/report/element.rb +48 -0
- data/lib/cashctrl/resources/report.rb +34 -0
- data/lib/cashctrl/resources/rounding.rb +10 -0
- data/lib/cashctrl/resources/salary/book_entry.rb +12 -0
- data/lib/cashctrl/resources/salary/category.rb +16 -0
- data/lib/cashctrl/resources/salary/certificate/document.rb +47 -0
- data/lib/cashctrl/resources/salary/certificate/template.rb +18 -0
- data/lib/cashctrl/resources/salary/certificate.rb +20 -0
- data/lib/cashctrl/resources/salary/document.rb +42 -0
- data/lib/cashctrl/resources/salary/field.rb +24 -0
- data/lib/cashctrl/resources/salary/insurance/type.rb +14 -0
- data/lib/cashctrl/resources/salary/layout.rb +12 -0
- data/lib/cashctrl/resources/salary/payment.rb +36 -0
- data/lib/cashctrl/resources/salary/setting.rb +12 -0
- data/lib/cashctrl/resources/salary/statement.rb +42 -0
- data/lib/cashctrl/resources/salary/status.rb +16 -0
- data/lib/cashctrl/resources/salary/sum.rb +12 -0
- data/lib/cashctrl/resources/salary/template.rb +16 -0
- data/lib/cashctrl/resources/salary/type.rb +17 -0
- data/lib/cashctrl/resources/sequence_number.rb +14 -0
- data/lib/cashctrl/resources/setting.rb +34 -0
- data/lib/cashctrl/resources/tax.rb +10 -0
- data/lib/cashctrl/resources/text.rb +10 -0
- data/lib/cashctrl/schema.yml +712 -0
- data/lib/cashctrl/version.rb +2 -2
- data/lib/cashctrl.rb +125 -3
- data/lib/generators/model_generator.rb +104 -0
- data/sig/cashctrl.rbs +1 -1
- metadata +126 -2
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class Base
|
|
6
|
+
PAGE_SIZE = 100
|
|
7
|
+
|
|
8
|
+
def self.api_path(path = nil)
|
|
9
|
+
if path
|
|
10
|
+
@api_path = path
|
|
11
|
+
else
|
|
12
|
+
@api_path
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.model_class(klass = nil)
|
|
17
|
+
if klass
|
|
18
|
+
@model_class = klass
|
|
19
|
+
else
|
|
20
|
+
@model_class || Resource
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.client
|
|
25
|
+
CashCtrl.client
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.list_params(*names)
|
|
29
|
+
@list_params = own_list_params + names.map { |name| camelize_key(name).to_sym } if names.any?
|
|
30
|
+
inherited = superclass.respond_to?(:list_params) ? superclass.list_params : []
|
|
31
|
+
inherited + own_list_params
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.own_list_params
|
|
35
|
+
@list_params || []
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.camelize_key(key)
|
|
39
|
+
key.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
list_params :query, :category_id, :fiscal_period_id, :only_active, :columns
|
|
43
|
+
|
|
44
|
+
def self.with_client(client)
|
|
45
|
+
resource = allocate
|
|
46
|
+
resource.send(:initialize, client)
|
|
47
|
+
resource
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.new(attributes = {}, **)
|
|
51
|
+
with_client(client).build(attributes, **)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.method_missing(name, ...)
|
|
55
|
+
return super unless public_method_defined?(name)
|
|
56
|
+
|
|
57
|
+
with_client(client).public_send(name, ...)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.respond_to_missing?(name, include_private = false)
|
|
61
|
+
public_method_defined?(name) || super
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
attr_reader :client
|
|
65
|
+
|
|
66
|
+
def initialize(client)
|
|
67
|
+
@client = client
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def api_path
|
|
71
|
+
self.class.api_path
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def model_class
|
|
75
|
+
self.class.model_class
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def build(attributes = {}, **kwargs)
|
|
79
|
+
model_class.new(camelize_keys(normalize_attributes(attributes.merge(kwargs))), resource: self)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def list(**params)
|
|
83
|
+
response = client.get("#{api_path}/list.json", api_params(**params))
|
|
84
|
+
Collection.from_response(response, resource_class: model_class, resource: self)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def all
|
|
88
|
+
Relation.new(self)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
[
|
|
92
|
+
:where, :order, :limit, :offset, :first, :last, :count, :exists?, :pluck,
|
|
93
|
+
:find_by, :find_by!, :find_each, :in_batches, :find_in_batches, :delete_all, :destroy_all, :includes
|
|
94
|
+
].each do |method_name|
|
|
95
|
+
define_method(method_name) do |*args, **kwargs, &block|
|
|
96
|
+
all.public_send(method_name, *args, **kwargs, &block)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def pageable?
|
|
101
|
+
method(:list).owner == Base
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def list_param?(key)
|
|
105
|
+
self.class.list_params.include?(self.class.camelize_key(key).to_sym)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def read(id:)
|
|
109
|
+
response = client.get("#{api_path}/read.json", id: id)
|
|
110
|
+
raise NotFoundError, "#{self.class.name} #{id} not found" unless response.is_a?(Hash) && response["data"]
|
|
111
|
+
|
|
112
|
+
model_class.from_response(response, resource: self)
|
|
113
|
+
rescue ValidationError => e
|
|
114
|
+
raise unless e.errors.empty?
|
|
115
|
+
|
|
116
|
+
raise NotFoundError.new(e.message, response: e.response)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def find(*ids)
|
|
120
|
+
many = ids.first.is_a?(Array) || ids.size > 1
|
|
121
|
+
ids = ids.flatten
|
|
122
|
+
raise ArgumentError, "find needs at least one id" if ids.empty?
|
|
123
|
+
|
|
124
|
+
many ? ids.map { |id| read(id: id) } : read(id: ids.first)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def create(...)
|
|
128
|
+
record = build(...)
|
|
129
|
+
record.save ? read_back(record) : record
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def create!(...)
|
|
133
|
+
record = build(...)
|
|
134
|
+
record.save!
|
|
135
|
+
read_back(record)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def update(id, **changes)
|
|
139
|
+
record = find(id)
|
|
140
|
+
record.reload if record.update(normalize_attributes(changes))
|
|
141
|
+
record
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def update!(id, **changes)
|
|
145
|
+
record = find(id)
|
|
146
|
+
record.update!(normalize_attributes(changes))
|
|
147
|
+
record.reload
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def replace(id, **attributes)
|
|
151
|
+
response = client.post("#{api_path}/update.json", camelize_keys({ id: id, **attributes }))
|
|
152
|
+
wrap_response(response)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def delete(*ids)
|
|
156
|
+
client.post("#{api_path}/delete.json", ids: csv(ids.flatten))
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def destroy(*ids)
|
|
160
|
+
records = find(*ids)
|
|
161
|
+
Array(records).each(&:destroy)
|
|
162
|
+
records
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def save_record(record)
|
|
166
|
+
if record.new_record?
|
|
167
|
+
client.post("#{api_path}/create.json", record_attributes(record))
|
|
168
|
+
else
|
|
169
|
+
client.post("#{api_path}/update.json", { "id" => record.id, **record_attributes(record) })
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def list_csv(**params)
|
|
174
|
+
client.get_raw("#{api_path}/list.csv", api_params(**params))
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def list_xlsx(**params)
|
|
178
|
+
client.get_raw("#{api_path}/list.xlsx", api_params(**params))
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def list_pdf(**params)
|
|
182
|
+
client.get_raw("#{api_path}/list.pdf", api_params(**params))
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
private
|
|
186
|
+
|
|
187
|
+
def normalize_attributes(attributes)
|
|
188
|
+
associations = model_class.associations
|
|
189
|
+
|
|
190
|
+
attributes.to_h do |key, value|
|
|
191
|
+
association = associations[key.to_sym]
|
|
192
|
+
next [key, value] unless association
|
|
193
|
+
|
|
194
|
+
[association[:foreign_key], value.is_a?(Resource) ? value.id : value]
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def record_attributes(record)
|
|
199
|
+
record.api_attributes
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def api_params(**params)
|
|
203
|
+
camelize_keys(params.compact)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def camelize_keys(params)
|
|
207
|
+
params.transform_keys { |key| self.class.camelize_key(key) }
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def csv(values)
|
|
211
|
+
Array(values).join(",")
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def tree_collection(response)
|
|
215
|
+
Collection.from_response(response, resource_class: model_class, resource: self)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def read_back(record)
|
|
219
|
+
return record if record.new_record?
|
|
220
|
+
|
|
221
|
+
record.reload
|
|
222
|
+
rescue NotImplementedError
|
|
223
|
+
record.response
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def wrap_response(response)
|
|
227
|
+
return response unless response.is_a?(Hash) && response["data"]
|
|
228
|
+
|
|
229
|
+
if response["data"].is_a?(Array)
|
|
230
|
+
Collection.from_response(response, resource_class: model_class, resource: self)
|
|
231
|
+
else
|
|
232
|
+
model_class.from_response(response["data"], resource: self)
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class Currency < Base
|
|
6
|
+
api_path "currency"
|
|
7
|
+
model_class Models::Currency
|
|
8
|
+
|
|
9
|
+
def exchange_rate(from:, to:, date: nil)
|
|
10
|
+
params = { from: from, to: to }
|
|
11
|
+
params[:date] = date if date
|
|
12
|
+
result = client.get_raw("#{api_path}/exchangerate", params)
|
|
13
|
+
BigDecimal(result.to_s)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class CustomField
|
|
6
|
+
class Group < Base
|
|
7
|
+
api_path "customfield/group"
|
|
8
|
+
model_class Models::CustomFieldGroup
|
|
9
|
+
|
|
10
|
+
def reorder(ids:, target:, before: nil)
|
|
11
|
+
client.post("#{api_path}/reorder.json", api_params(ids: csv(ids), target: target, before: before))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class CustomField < Base
|
|
6
|
+
api_path "customfield"
|
|
7
|
+
model_class Models::CustomField
|
|
8
|
+
|
|
9
|
+
def types
|
|
10
|
+
client.get("#{api_path}/types.json")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def reorder(ids:, target:, before: nil)
|
|
14
|
+
client.post("#{api_path}/reorder.json", api_params(ids: csv(ids), target: target, before: before))
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class File
|
|
6
|
+
class Category < Base
|
|
7
|
+
api_path "file/category"
|
|
8
|
+
model_class Models::Category
|
|
9
|
+
|
|
10
|
+
def tree(id = nil)
|
|
11
|
+
tree_collection(client.get("#{api_path}/tree.json", api_params(id: id)))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class File < Base
|
|
6
|
+
api_path "file"
|
|
7
|
+
model_class Models::File
|
|
8
|
+
|
|
9
|
+
MIME_TYPES = {
|
|
10
|
+
".csv" => "text/csv",
|
|
11
|
+
".gif" => "image/gif",
|
|
12
|
+
".heic" => "image/heic",
|
|
13
|
+
".jpeg" => "image/jpeg",
|
|
14
|
+
".jpg" => "image/jpeg",
|
|
15
|
+
".pdf" => "application/pdf",
|
|
16
|
+
".png" => "image/png",
|
|
17
|
+
".txt" => "text/plain",
|
|
18
|
+
".vcf" => "text/vcard",
|
|
19
|
+
".xls" => "application/vnd.ms-excel",
|
|
20
|
+
".xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
21
|
+
".xml" => "application/xml",
|
|
22
|
+
".zip" => "application/zip",
|
|
23
|
+
}.freeze
|
|
24
|
+
|
|
25
|
+
def self.mime_type_for(name)
|
|
26
|
+
MIME_TYPES.fetch(::File.extname(name.to_s).downcase, "application/octet-stream")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def get(id:)
|
|
30
|
+
client.get_raw("#{api_path}/get", id: id)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def prepare(files: nil, name: nil, mime_type: nil, category_id: nil, size: nil)
|
|
34
|
+
files ||= [{ name: name, mime_type: mime_type, category_id: category_id, size: size }]
|
|
35
|
+
|
|
36
|
+
payload = files.map do |file|
|
|
37
|
+
{
|
|
38
|
+
name: file[:name],
|
|
39
|
+
mimeType: file[:mime_type] || self.class.mime_type_for(file[:name]),
|
|
40
|
+
categoryId: file[:category_id],
|
|
41
|
+
size: file[:size],
|
|
42
|
+
}.compact
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
client.post("#{api_path}/prepare.json", files: payload)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def upload(file, name: nil, mime_type: nil, category_id: nil, persist: true)
|
|
49
|
+
content = file.respond_to?(:read) ? file.read : ::File.binread(file)
|
|
50
|
+
name ||= file.respond_to?(:path) ? ::File.basename(file.path) : ::File.basename(file.to_s)
|
|
51
|
+
mime_type ||= self.class.mime_type_for(name)
|
|
52
|
+
|
|
53
|
+
prepared = prepare(name: name, mime_type: mime_type, category_id: category_id, size: content.bytesize)
|
|
54
|
+
entry = Array(prepared["data"]).first || raise(Error, "CashCtrl did not return an upload URL")
|
|
55
|
+
|
|
56
|
+
client.put_raw(entry["writeUrl"], content, content_type: mime_type)
|
|
57
|
+
persist(ids: entry["fileId"]) if persist
|
|
58
|
+
|
|
59
|
+
entry["fileId"]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def persist(ids:)
|
|
63
|
+
ids_param = Array(ids).join(",")
|
|
64
|
+
client.post("#{api_path}/persist.json", ids: ids_param)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def categorize(ids:, target:)
|
|
68
|
+
ids_param = Array(ids).join(",")
|
|
69
|
+
client.post("#{api_path}/categorize.json", ids: ids_param, target: target)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def empty_archive
|
|
73
|
+
client.post("#{api_path}/empty_archive.json")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def restore(ids:)
|
|
77
|
+
ids_param = Array(ids).join(",")
|
|
78
|
+
client.post("#{api_path}/restore.json", ids: ids_param)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class FiscalPeriod
|
|
6
|
+
class Task < Base
|
|
7
|
+
api_path "fiscalperiod/task"
|
|
8
|
+
model_class Models::FiscalPeriodTask
|
|
9
|
+
|
|
10
|
+
def read(id:)
|
|
11
|
+
raise NotImplementedError, "FiscalPeriod::Task does not support read"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def update(*, **)
|
|
15
|
+
raise NotImplementedError, "FiscalPeriod::Task does not support update"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class FiscalPeriod < Base
|
|
6
|
+
api_path "fiscalperiod"
|
|
7
|
+
model_class Models::FiscalPeriod
|
|
8
|
+
|
|
9
|
+
def current
|
|
10
|
+
list.find(&:is_current)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def result(id:)
|
|
14
|
+
client.get("#{api_path}/result", id: id)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def depreciations(id:)
|
|
18
|
+
client.get("#{api_path}/depreciations.json", id: id)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def exchangediff(id: nil, date: nil)
|
|
22
|
+
client.get("#{api_path}/exchangediff.json", api_params(id: id, date: date))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def switch(id:)
|
|
26
|
+
client.post("#{api_path}/switch.json", id: id)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def book_depreciations(id:, depreciation:)
|
|
30
|
+
client.post("#{api_path}/bookdepreciations.json", id: id, depreciation: csv(depreciation))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def book_exchangediff(exchange_diff:, id: nil, date: nil)
|
|
34
|
+
client.post("#{api_path}/bookexchangediff.json", api_params(exchange_diff: exchange_diff, id: id, date: date))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def complete(id:, is_salary: nil)
|
|
38
|
+
client.post("#{api_path}/complete.json", api_params(id: id, is_salary: is_salary))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def reopen(id:, is_salary: nil)
|
|
42
|
+
client.post("#{api_path}/reopen.json", api_params(id: id, is_salary: is_salary))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def complete_months(id:, months: nil, is_salary: nil)
|
|
46
|
+
client.post("#{api_path}/complete_months.json", api_params(id: id, months: months, is_salary: is_salary))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def reopen_months(id:, months: nil, is_salary: nil)
|
|
50
|
+
client.get("#{api_path}/reopen_months.json", api_params(id: id, months: months, is_salary: is_salary))
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class History < Base
|
|
6
|
+
api_path "history"
|
|
7
|
+
model_class Models::History
|
|
8
|
+
|
|
9
|
+
def create(**params)
|
|
10
|
+
raise NotImplementedError, "History does not support create"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def update(*, **)
|
|
14
|
+
raise NotImplementedError, "History does not support update"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def delete(*)
|
|
18
|
+
raise NotImplementedError, "History does not support delete"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def read(id:)
|
|
22
|
+
raise NotImplementedError, "History does not support read"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class ImportSession < Base
|
|
6
|
+
def list
|
|
7
|
+
raise NotImplementedError, "#{self.class.name} does not support list"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def read(id:)
|
|
11
|
+
raise NotImplementedError, "#{self.class.name} does not support read"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def update(*, **)
|
|
15
|
+
raise NotImplementedError, "#{self.class.name} does not support update"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def delete(*)
|
|
19
|
+
raise NotImplementedError, "#{self.class.name} does not support delete"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create(file_id:, category_id: nil)
|
|
23
|
+
client.post("#{api_path}/create.json", api_params(file_id: file_id, category_id: category_id))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def mapping(id:, mapping:)
|
|
27
|
+
client.post("#{api_path}/mapping.json", id: id, mapping: mapping)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def mapping_combo
|
|
31
|
+
client.get("#{api_path}/mapping_combo.json")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def preview(id:)
|
|
35
|
+
client.get("#{api_path}/preview.json", id: id)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def execute(id:, indexes: nil)
|
|
39
|
+
client.post("#{api_path}/execute.json", api_params(id: id, indexes: indexes && csv(indexes)))
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
module Inventory
|
|
6
|
+
class Article
|
|
7
|
+
class Category < Base
|
|
8
|
+
api_path "inventory/article/category"
|
|
9
|
+
model_class Models::Category
|
|
10
|
+
|
|
11
|
+
def tree(id = nil)
|
|
12
|
+
tree_collection(client.get("#{api_path}/tree.json", api_params(id: id)))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
module Inventory
|
|
6
|
+
class Article < Base
|
|
7
|
+
include Attachments
|
|
8
|
+
|
|
9
|
+
api_path "inventory/article"
|
|
10
|
+
model_class Models::Article
|
|
11
|
+
|
|
12
|
+
def categorize(ids:, target:)
|
|
13
|
+
ids_param = Array(ids).join(",")
|
|
14
|
+
client.post("#{api_path}/categorize.json", ids: ids_param, target: target)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
module Inventory
|
|
6
|
+
class Asset
|
|
7
|
+
class Category < Base
|
|
8
|
+
api_path "inventory/asset/category"
|
|
9
|
+
model_class Models::Category
|
|
10
|
+
|
|
11
|
+
def tree(id = nil)
|
|
12
|
+
tree_collection(client.get("#{api_path}/tree.json", api_params(id: id)))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
module Inventory
|
|
6
|
+
class Asset < Base
|
|
7
|
+
include Attachments
|
|
8
|
+
|
|
9
|
+
api_path "inventory/asset"
|
|
10
|
+
model_class Models::Asset
|
|
11
|
+
|
|
12
|
+
def categorize(ids:, target:)
|
|
13
|
+
ids_param = Array(ids).join(",")
|
|
14
|
+
client.post("#{api_path}/categorize.json", ids: ids_param, target: target)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class Journal
|
|
6
|
+
class Import
|
|
7
|
+
class Entry < Base
|
|
8
|
+
api_path "journal/import/entry"
|
|
9
|
+
model_class Models::JournalImportEntry
|
|
10
|
+
|
|
11
|
+
def create(**params)
|
|
12
|
+
raise NotImplementedError, "Journal::Import::Entry does not support create"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def restore(ids:)
|
|
16
|
+
ids_param = Array(ids).join(",")
|
|
17
|
+
client.post("#{api_path}/restore.json", ids: ids_param)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def confirm(ids:)
|
|
21
|
+
ids_param = Array(ids).join(",")
|
|
22
|
+
client.post("#{api_path}/confirm.json", ids: ids_param)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def unconfirm(ids:)
|
|
26
|
+
ids_param = Array(ids).join(",")
|
|
27
|
+
client.post("#{api_path}/unconfirm.json", ids: ids_param)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CashCtrl
|
|
4
|
+
module Resources
|
|
5
|
+
class Journal
|
|
6
|
+
class Import < Base
|
|
7
|
+
api_path "journal/import"
|
|
8
|
+
model_class Models::JournalImport
|
|
9
|
+
|
|
10
|
+
def execute(id:)
|
|
11
|
+
client.post("#{api_path}/execute.json", id: id)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|