snappler_contable_multicurrency 2.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.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +398 -0
  4. data/Rakefile +39 -0
  5. data/app/helpers/snappler_contable_helper.rb +42 -0
  6. data/app/models/ledger_account.rb +217 -0
  7. data/app/models/ledger_account_activo.rb +8 -0
  8. data/app/models/ledger_account_pasivo.rb +6 -0
  9. data/app/models/ledger_account_patrimonio_neto.rb +6 -0
  10. data/app/models/ledger_account_relation.rb +8 -0
  11. data/app/models/ledger_account_resultado_negativo.rb +6 -0
  12. data/app/models/ledger_account_resultado_positivo.rb +6 -0
  13. data/app/models/ledger_currency.rb +5 -0
  14. data/app/models/ledger_entry.rb +7 -0
  15. data/app/models/ledger_move.rb +76 -0
  16. data/lib/generators/snappler_contable/initializer_generator.rb +11 -0
  17. data/lib/generators/snappler_contable/migrate_generator.rb +25 -0
  18. data/lib/generators/snappler_contable/new_currency_generator.rb +23 -0
  19. data/lib/generators/snappler_contable/templates/snappler_contable_add_currencies.rb +20 -0
  20. data/lib/generators/snappler_contable/templates/snappler_contable_app_ledger_accounts.rb +48 -0
  21. data/lib/generators/snappler_contable/templates/snappler_contable_migrate.rb +68 -0
  22. data/lib/generators/snappler_contable/templates/snappler_contable_new_currency.rb +14 -0
  23. data/lib/snappler_contable/ext/string.rb +5 -0
  24. data/lib/snappler_contable/railtie.rb +4 -0
  25. data/lib/snappler_contable/snappler_contable.rb +154 -0
  26. data/lib/snappler_contable/version.rb +3 -0
  27. data/lib/snappler_contable_multicurrency.rb +14 -0
  28. data/lib/tasks/snappler_contable_tasks.rake +4 -0
  29. data/spec/internal/config/database_example.yml +8 -0
  30. data/spec/internal/config/initializers/snappler_contable.rb +8 -0
  31. data/spec/internal/config/routes.rb +3 -0
  32. data/spec/internal/db/schema.rb +64 -0
  33. data/spec/internal/public/favicon.ico +0 -0
  34. data/spec/models/ledger_account_spec.rb +308 -0
  35. data/spec/spec_helper.rb +75 -0
  36. metadata +84 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1e2fbc479081a3898df533c376dc2d605b867b7
4
+ data.tar.gz: 433542dbeff287ff71ebabbb9f3afaf52236ca97
5
+ SHA512:
6
+ metadata.gz: 7992a3fda9c994ea273f2633974723cbd2002e268b82ec4752825d50d6464a410c28cc0055a8433105fad687f201d3f582e04e3bfc5755bd0c1ca896eda096e8
7
+ data.tar.gz: 8ecfc911339bad0ae748e8cbc6956fbc798af6af9c94036141e911d50365aff67e46133f37ec01808550af11d3c63209fae623ac4b9736ffbe601e7847f1405b
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,398 @@
1
+ # SnapplerContable
2
+
3
+ Esta gema agrega a una aplicacion la capacidad de manejar cuentas contables con el modelo teorico economico.
4
+
5
+ ## Instalacion
6
+
7
+ Agregar esta linea al Gemfile
8
+ ```ruby
9
+ gem "snappler_contable_multicurrency"
10
+ ```
11
+ Ejecutar
12
+ ```bash
13
+ $ bundle install
14
+ ```
15
+ Después de instalar se deben correr estos comandos
16
+ ```bash
17
+ $ rails g snappler_contable:initializer
18
+ ```
19
+ Esto va a crear el achivo:
20
+ ```bash
21
+ # Configuracion de constantes para el sistema.
22
+ config/initializers/snappler_contable.rb
23
+ ```
24
+ ```bash
25
+ $ rails g snappler_contable:migrate
26
+ ```
27
+
28
+ Esto va a crear las migraciones:
29
+ ```bash
30
+ #Crea la estructura y crea cuentas base 'activo', 'pasivo', 'patrimonio_neto', 'resultado_positivo', 'resultado_negativo'
31
+ aaaammdd_snappler_contable_migrate.rb
32
+
33
+ #Agrega columnas para USD, EUR y BRL
34
+ aaaammdd_snappler_contable_add_currencies.rb
35
+
36
+ #Carga cuentas DUMMY (Esta se puede borrar si no hace falta)
37
+ aaaammdd_snappler_contable_app_ledger_accounts.rb
38
+ ```
39
+ ```bash
40
+ $ rake db:migrate
41
+ ```
42
+
43
+ Y listo
44
+
45
+ ### Extra
46
+ ```bash
47
+ $ rails g snappler_contable:new_currency
48
+ ```
49
+
50
+ Esto crea una migracion simulando una nueva moneda, ejemplo el YEN
51
+ ```bash
52
+ #Crea la columna en 'ledger_accounts' y agrega la entidad a 'ledger_currencies'
53
+ aaaammdd_snappler_contable_new_currency.rb
54
+ ```
55
+
56
+ ---
57
+
58
+
59
+ ## Problemas en Rails
60
+
61
+ ### Migrations
62
+ #### Versión de ActiveRecord
63
+ Si muestra un **error** como este al migrar:
64
+ ```
65
+ Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release
66
+ ```
67
+ Se debe agregar la versión de Rails en la definición de la superclase en las migraciones:
68
+
69
+ ```ruby
70
+ # /db/migrate/aaaammdd_snappler_contable_migrate
71
+
72
+ class SnapplerContableMigrate <ActiveRecord::Migration
73
+ ...
74
+ ```
75
+ Agregar:
76
+ ```ruby
77
+ # /db/migrate/aaaammdd_snappler_contable_migrate
78
+
79
+ class SnapplerContableMigrate <ActiveRecord::Migration[5.1] #o lo que corresponda
80
+ ...
81
+ ```
82
+ #### Error crando cuentas base (activo, pasivo...)
83
+ Rails agregó un control
84
+ ---```bash
85
+ $ rails g snappler_contable:initializer
86
+ ```
87
+ Esto va a crear el achivo:
88
+ ```bash
89
+ # Configuracion de constantes para el sistema.
90
+ config/initializers/snappler_contable.rb
91
+ ```
92
+ ```bash
93
+ $ rails g snappler_contable:migrate
94
+ ```
95
+
96
+ Esto va a crear las migraciones:
97
+ ```bash
98
+ #Crea la estructura y crea cuentas base 'activo', 'pasivo', 'patrimonio_neto', 'resultado_positivo', 'resultado_negativo'
99
+ aaaammdd_snappler_contable_migrate.rb
100
+
101
+ #Agrega columnas para USD, EUR y BRL
102
+ aaaammdd_snappler_contable_add_currencies.rb
103
+
104
+ #Carga cuentas DUMMY (Esta se puede borrar si no hace falta)
105
+ aaaammdd_snappler_contable_app_ledger_accounts.rb
106
+ ```
107
+ ```bash
108
+ $ rake db:migrate
109
+ ```
110
+
111
+ Y listo
112
+
113
+ ### Extra
114
+ ```bash
115
+ $ rails g snappler_contable:new_currency
116
+ ```
117
+
118
+ Esto crea una migracion simulando una nueva moneda, ejemplo el YEN
119
+ ```bash
120
+ #Crea la columna en 'ledger_accounts' y agrega la entidad a 'ledger_currencies'
121
+ aaaammdd_snappler_contable_new_currency.rb
122
+ ```
123
+
124
+ ---
125
+
126
+
127
+ ## Problemas en Rails
128
+
129
+ ### Migrations
130
+ #### Versión de ActiveRecord
131
+ Si muestra un **error** como este al migrar:
132
+ ```
133
+ Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release
134
+ ```
135
+ Se debe agregar la versión de Rails en la definición de la superclase en las migraciones:
136
+
137
+ ```ruby
138
+ # /db/migrate/aaaammdd_snappler_contable_migrate
139
+
140
+ class SnapplerContableMigrate <ActiveRecord::Migration
141
+ ...
142
+ ```
143
+ Agregar:
144
+ ```ruby
145
+ # /db/migrate/aaaammdd_snappler_contable_migrate
146
+
147
+ class SnapplerContableMigrate <ActiveRecord::Migration[5.1] #o lo que corresponda
148
+ ...
149
+ ```
150
+ #### Error crando cuentas base (activo, pasivo...)
151
+ Rails agregó un control
152
+ ---```bash
153
+ $ rails g snappler_contable:initializer
154
+ ```
155
+ Esto va a crear el achivo:
156
+ ```bash
157
+ # Configuracion de constantes para el sistema.
158
+ config/initializers/snappler_contable.rb
159
+ ```
160
+ ```bash
161
+ $ rails g snappler_contable:migrate
162
+ ```
163
+
164
+ Esto va a crear las migraciones:
165
+ ```bash
166
+ #Crea la estructura y crea cuentas base 'activo', 'pasivo', 'patrimonio_neto', 'resultado_positivo', 'resultado_negativo'
167
+ aaaammdd_snappler_contable_migrate.rb
168
+
169
+ #Agrega columnas para USD, EUR y BRL
170
+ aaaammdd_snappler_contable_add_currencies.rb
171
+
172
+ #Carga cuentas DUMMY (Esta se puede borrar si no hace falta)
173
+ aaaammdd_snappler_contable_app_ledger_accounts.rb
174
+ ```
175
+ ```bash
176
+ $ rake db:migrate
177
+ ```
178
+
179
+ Y listo
180
+
181
+ ### Extra
182
+ ```bash
183
+ $ rails g snappler_contable:new_currency
184
+ ```
185
+
186
+ Esto crea una migracion simulando una nueva moneda, ejemplo el YEN
187
+ ```bash
188
+ #Crea la columna en 'ledger_accounts' y agrega la entidad a 'ledger_currencies'
189
+ aaaammdd_snappler_contable_new_currency.rb
190
+ ```
191
+ ---
192
+
193
+ ## Uso
194
+
195
+ ### Traer cuentas
196
+ ```ruby
197
+ xxxx = LedgerAccount.get('Nombre de cuenta')
198
+ ```
199
+ #### Ejemplo:
200
+ ```ruby
201
+ activo = LedgerAccount.get('activo')
202
+ pasivo = LedgerAccount.get('pasivo')
203
+ patrimonio_neto = LedgerAccount.get('patrimonio_neto')
204
+ resultado_positivo = LedgerAccount.get('resultado_positivo')
205
+ resultado_negativo = LedgerAccount.get('resultado_negativo') (*)
206
+ ```
207
+ ```ruby
208
+ (*) LedgerAccount.get('resultado_negativo') == LedgerAccount.get('Resultado Negativo')
209
+ ```
210
+ Es similar, ya que el parametro se trata poniendo en minuscula y cambiando los " " por "_"
211
+
212
+
213
+ ### Agregar cuentas hijas
214
+
215
+ Agregar cuentas hija
216
+ ```ruby
217
+ #Cuenta padre
218
+ xxxx = LedgerAccount.get('XXXX')
219
+
220
+ #Agrego YYYY como hija de XXXX
221
+ xxxx.add_child("YYYY", "yyyy")
222
+ ```
223
+
224
+ #### Ejemplo:
225
+ ```ruby
226
+ activo = LedgerAccount.get('activo')
227
+ disponibilidades = activo.add_child("Disponibilidades", "disponibilidades")
228
+ caja = disponibilidades.add_child("Caja", "caja")
229
+ banco = disponibilidades.add_child("Banco", "banco")
230
+ ```
231
+
232
+ dejando una estructura asi:
233
+ ```
234
+ 1 activo
235
+ 1.1 disponibilidades
236
+ 1.1.1 caja
237
+ 1.1.2 banco
238
+ ```
239
+
240
+
241
+
242
+ Agregar cuentas hija con objeto relacionado
243
+ ```ruby
244
+ #Cuenta padre
245
+ xxxx = LedgerAccount.get('XXXX')
246
+
247
+ #En este caso lo relaciono ademas con un objeto
248
+ xxxx.add_child("ZZZZ", "zzzz", objeto_owner)
249
+ ```
250
+
251
+ #### Ejemplo:
252
+ ```ruby
253
+ banco = LedgerAccount.get('banco')
254
+
255
+ banco_1 = Bank.find(1)
256
+ banco_acc_1 = banco.add_child(banco_1.name, "banco", banco_1)
257
+
258
+ banco_2 = Bank.find(2)
259
+ banco_acc_2 = banco.add_child(banco_2.name, "banco", banco_2)
260
+ ```
261
+ dejando una estructura asi:
262
+ ```
263
+ 1 activo
264
+ 1.1 disponibilidades
265
+ 1.1.1 caja
266
+ 1.1.2 banco
267
+ 1.1.2.1 banco_1
268
+ 1.1.2.2 banco_2
269
+ ```
270
+
271
+ ### Generar Operaciones
272
+ ```ruby
273
+ entryX = SnapplerContable.op(array_debe(*), array_haber(*), hash(**))
274
+ ```
275
+ ```
276
+ (*) La estructura del array_debe o array_haber, es la misma, es un array de hashes, cada hash tiene la sig estructura:
277
+ ```
278
+ ```ruby
279
+ {
280
+ account: cuenta_x, # (LedgerAccount)
281
+ value: XXX.XX, # (puede tener hasta 2 decimales)
282
+ ledger_currency: 'XXX', #Opc* (Permite código ['ARS', 'USD', etc], o id [1,2,3], o entidad(LedgerCurrency), (Si no especifico la moneda, usa por defecto la configurada en el sistema)
283
+ represent_value: XXX.XX, # (puede tener hasta 2 decimales)
284
+ represent_ledger_currency: 'XXX', #Opc* (Permite código ['ARS', 'USD', etc], o id [1,2,3], o entidad(LedgerCurrency), (Si no especifico la moneda, usa por defecto la configurada en el sistema)
285
+ currency_change: XXX.XX, # (puede tener hasta 2 decimales)
286
+ }
287
+ ```
288
+ ```
289
+ (**) El hash es opcional y su estructura es:
290
+ ```
291
+ ```ruby
292
+ {
293
+ code_name: '', #Opc* (Código que se le asigna a la entry, sirve para filtrar entries por nombre)
294
+ owner: '' #Opc* (Indica el objeto que genera la Entry)
295
+ datetime: DateTime #Opc* (Por defecto si no se manda toma DateTime.now)
296
+ }
297
+ ```
298
+ #### Ejemplo:
299
+
300
+ ##### Movimiento Comun
301
+ ```ruby
302
+ #Incremento de deuda de cliente_1 por $10
303
+
304
+ entry1 = SnapplerContable.op([{account: cliente_1, value: 100}],
305
+ [{account: ventas, value: 100}])
306
+ ```
307
+
308
+ ##### Movimiento en otra divisa
309
+ ```ruby
310
+ #Incremento de deuda de cliente_1 por u$s100
311
+
312
+ entry2 = SnapplerContable.op([{account: cliente_1, value: 100, ledger_currency: 'USD'}],
313
+ [{account: ventas, value: 100, ledger_currency: 'USD'}])
314
+ ```
315
+
316
+
317
+ ##### Movimiento con variacion de divisas 1
318
+ ```ruby
319
+ #Decremento de deuda de cliente_1 por u$s10
320
+ #(El cliente en realidad paga $152, que es lo que queda en la caja, pero el valor representa un pago por u$s10 a una cotizacion de 15.2)
321
+
322
+ entry3 = SnapplerContable.op([{account: caja, value: 152, ledger_currency: 'ARS'}],
323
+ [{account: cliente_1, value: 152, ledger_currency: 'ARS', represent_value: 10, represent_ledger_currency: 'USD', currency_change: 15.2}])
324
+ ```
325
+ ##### Movimiento con variacion de divisas 2
326
+ ```ruby
327
+ #cambio de divisa sobre caja
328
+
329
+ entry4 = SnapplerContable.op([{account: caja, value: 1520, ledger_currency: 'ARS'}],
330
+ [{account: caja, value: 1520, ledger_currency: 'ARS', represent_value: 100, represent_ledger_currency: 'USD', currency_change: 15.2}])
331
+ ```
332
+ ### Consultas de saldo a una cuenta
333
+ ```ruby
334
+ #Cuenta a consultar
335
+ xxxx = LedgerAccount.get('XXXX')
336
+
337
+ #Balance de la cuenta xxxx en la moneda YYY
338
+ xxxx.balance_YYY(hash(*))
339
+
340
+ #Balance de la cuenta xxxx en todas las monedas
341
+ xxxx.balance(hash(*))
342
+ ```
343
+ ```
344
+ (*) El hash es opcional y su estructura es:
345
+ ```
346
+ ```ruby
347
+ {
348
+ from: '', #Opc* (Fecha desde)
349
+ to: DateTime #Opc* (Fecha hasta)
350
+ }
351
+ ```
352
+ #### Ejemplo:
353
+
354
+ ```ruby
355
+ cliente_1 = LedgerAccount.get('cliente_1')
356
+
357
+ #----------------------------- Consulta de saldo en $ al momento
358
+ cliente_1.balance_ars
359
+
360
+ #----------------------------- Consulta de saldo en u$s al momento
361
+ cliente_1.balance_usd
362
+
363
+ #----------------------------- Consulta de saldo en $ a partir del 20/10/2017
364
+ cliente_1.balance_ars({from: '20/10/2017'})
365
+
366
+ #----------------------------- Consulta de saldo en u$s hasta el 20/10/2017
367
+ cliente_1.balance_usd({to: '20/10/2017'})
368
+
369
+ #----------------------------- Consulta de saldo en u$s a partir del 20/10/2017 hasta el 22/10/2017
370
+ cliente_1.balance_usd({from: '20/10/2017', to: '22/10/2017'})
371
+
372
+ #----------------------------- Consulta de saldo en todas las monedas
373
+ cliente_1.balance
374
+
375
+ #----------------------------- Consulta de saldo en todas las monedas a partir del 20/10/2017 hasta el 22/10/2017
376
+ cliente_1.balance({from: '20/10/2017', to: '22/10/2017'})
377
+ ```
378
+ ### Helper que imprime el arbol de cuentas
379
+ ```ruby
380
+ <%= print_accounts_tree %>
381
+ ```
382
+ ## RubyGems
383
+
384
+ Esta gema está publicada en RubyGems:
385
+
386
+ * https://rubygems.org/gems/snappler_contable_multicurrency
387
+
388
+ **user:** juan.labattaglia@snappler.com
389
+
390
+ ### Actualizacion
391
+
392
+ Una vez que hay una nueva versión, modificar `lib/snappler_contable/version.rb`
393
+
394
+ Luego ejecutar:
395
+ ```bash
396
+ gem build snappler_contable_multicurrency.gemspec
397
+ gem push snappler_contable_multicurrency-[VERSION].gem
398
+ ```
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+
16
+ RDoc::Task.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'SnapplerContable'
19
+ rdoc.options << '--line-numbers'
20
+ rdoc.rdoc_files.include('README.rdoc')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rake/testtask'
30
+
31
+ Rake::TestTask.new(:test) do |t|
32
+ t.libs << 'lib'
33
+ t.libs << 'test'
34
+ t.pattern = 'test/**/*_test.rb'
35
+ #t.verbose = false
36
+ end
37
+
38
+
39
+ task :default => :test