oris.ge 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -0
- data/Rakefile +1 -0
- data/lib/oris.rb +37 -0
- data/lib/oris/date.rb +11 -0
- data/lib/oris/operation.rb +98 -0
- data/lib/oris/version.rb +4 -0
- data/oris.gemspec +22 -0
- data/spec/oris/date_spec.rb +7 -0
- data/spec/oris/operation_spec.rb +61 -0
- data/spec/spec_helper.rb +8 -0
- metadata +94 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dimitri Kurashvili
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/oris.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'oris/version'
|
3
|
+
require 'oris/date'
|
4
|
+
require 'oris/operation'
|
5
|
+
|
6
|
+
module ORIS
|
7
|
+
|
8
|
+
## Operation types.
|
9
|
+
|
10
|
+
# Full price for operation type.
|
11
|
+
FULL_PRICE = 0
|
12
|
+
|
13
|
+
# VAT part of the price. Basically, `price*0.18`.
|
14
|
+
VAT_PRICE = 1
|
15
|
+
|
16
|
+
# Part of the price without VAT. Basically, `price - price*0.18`.
|
17
|
+
EXCLUDE_VAT_PRICE = 2
|
18
|
+
|
19
|
+
## Ledger codes
|
20
|
+
|
21
|
+
# Ledger code for VAT transaction (in-mode).
|
22
|
+
VAT_LEDGER_CODE_IN = '3340'
|
23
|
+
|
24
|
+
# Ledger code for VAT transaction (out-mode).
|
25
|
+
VAT_LEDGER_CODE_OUT = '3330'
|
26
|
+
|
27
|
+
# Format accounting code, according to ORIS conventions.
|
28
|
+
def self.oris_acc_code(text)
|
29
|
+
if text
|
30
|
+
stripped = text.scan(/\d+/).join
|
31
|
+
if (stripped.size > 4)
|
32
|
+
[ stripped[0], stripped[1], stripped[2..3], stripped[4..-1] ].join(' ')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/oris/date.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'c12-commons'
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
module ORIS
|
6
|
+
|
7
|
+
class Operation
|
8
|
+
# Document number
|
9
|
+
attr_accessor :number
|
10
|
+
# Number of the document, this document is related to
|
11
|
+
attr_accessor :related_to
|
12
|
+
# Short description
|
13
|
+
attr_accessor :description
|
14
|
+
# Date of the document
|
15
|
+
attr_accessor :date
|
16
|
+
|
17
|
+
# Debit (+) account number.
|
18
|
+
attr_accessor :acc_debit
|
19
|
+
# Name of the debit account.
|
20
|
+
attr_accessor :name_debit
|
21
|
+
# Credit (-) account number.
|
22
|
+
attr_accessor :acc_credit
|
23
|
+
# Name of the credit account.
|
24
|
+
attr_accessor :name_credit
|
25
|
+
|
26
|
+
# Amount and currency of the document.
|
27
|
+
attr_accessor :amount, :currency, :type
|
28
|
+
# Quantity in base units.
|
29
|
+
attr_accessor :quantity
|
30
|
+
# Normal quantity -- quantity in most small unit.
|
31
|
+
attr_accessor :quantity_normal
|
32
|
+
# Unit quantity.
|
33
|
+
attr_accessor :unit
|
34
|
+
|
35
|
+
# Project used.
|
36
|
+
attr_accessor :project
|
37
|
+
# User who performed this operation and operation's date.
|
38
|
+
attr_accessor :user, :sysdate
|
39
|
+
|
40
|
+
# Errors.
|
41
|
+
def errors
|
42
|
+
@errors
|
43
|
+
end
|
44
|
+
|
45
|
+
# Validate this operation.
|
46
|
+
def validate
|
47
|
+
@errors = []
|
48
|
+
@errors.push('დებიტორული ანგარიში არაა განსაზღვრული') if self.acc_debit.blank?
|
49
|
+
@errors.push('კრედიტორული ანგარიში არაა განსაზღვრული') if self.acc_credit.blank?
|
50
|
+
end
|
51
|
+
|
52
|
+
def valid?
|
53
|
+
self.errors.nil? or self.errors.size == 0
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize(opts = {})
|
57
|
+
opts.each do |k, v|
|
58
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def calc_amount
|
63
|
+
unless self.amount.nil?
|
64
|
+
case self.type
|
65
|
+
when VAT_PRICE then (self.amount - (self.amount/1.18).round(2)).round(2)
|
66
|
+
when EXCLUDE_VAT_PRICE then (self.amount/1.18).round(2)
|
67
|
+
else self.amount.round(2)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Operation representation as an arrya (row).
|
73
|
+
def to_a
|
74
|
+
docnumb = self.number
|
75
|
+
docdate = self.date ? self.date.oris_format : Date.today.oris_format
|
76
|
+
currency = self.currency ? self.currency : 'GEL'
|
77
|
+
project = self.project ? self.project.to_geo : ' მთ.წიგნი'.to_geo
|
78
|
+
sysdate = self.sysdate ? self.sysdate.oris_format : Date.today.oris_format
|
79
|
+
unit = self.unit ? self.unit.to_geo : 'ერთეული'.to_geo
|
80
|
+
quant = self.quantity || 0
|
81
|
+
quant2 = self.quantity_normal || quant
|
82
|
+
user = self.user ? self.user.to_geo : ''
|
83
|
+
['', '', '', docnumb, '0', docdate, ORIS.oris_acc_code(self.acc_debit), ORIS.oris_acc_code(self.acc_credit),
|
84
|
+
'0', self.calc_amount, currency, self.description, '0', '1', unit, quant, quant2, project, user,
|
85
|
+
'0', '9', '0', '', '0', sysdate, self.related_to, '0', '1', '3', '', '0', '', '']
|
86
|
+
end
|
87
|
+
|
88
|
+
# Convert to CSV.
|
89
|
+
def self.to_csv(opts)
|
90
|
+
CSV.generate(force_quotes: true) do |csv|
|
91
|
+
opts.each do |opt|
|
92
|
+
csv << opt.to_a
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/lib/oris/version.rb
ADDED
data/oris.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oris/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "oris.ge"
|
8
|
+
gem.version = ORIS::VERSION
|
9
|
+
gem.authors = ["Dimitri Kurashvili"]
|
10
|
+
gem.email = ["dimitri@c12.ge"]
|
11
|
+
gem.description = %q{Library for ORIS.GE accounting}
|
12
|
+
gem.summary = %q{Library for transfering data to and from ORIS.GE accounting software}
|
13
|
+
gem.homepage = "http://c12.ge"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec', '~> 2'
|
21
|
+
gem.add_development_dependency 'c12-commons', '~> 0.1.0'
|
22
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
describe 'operation to csv' do
|
4
|
+
before(:all) do
|
5
|
+
@operation = ORIS::Operation.new(number: '001', acc_debit: '7210-01', acc_credit: '1610-01', amount: 10, quantity: 100, user: 'დიმიტრი ყურაშვილი')
|
6
|
+
end
|
7
|
+
subject { @operation.to_a }
|
8
|
+
its(:size) { should == 33 }
|
9
|
+
specify { subject[0].should == '' }
|
10
|
+
specify { subject[1].should == '' }
|
11
|
+
specify { subject[2].should == '' }
|
12
|
+
specify { subject[3].should == '001' }
|
13
|
+
specify { subject[4].should == '0' }
|
14
|
+
specify { subject[5].should == Date.today.oris_format }
|
15
|
+
specify { subject[6].should == '7 2 10 01' }
|
16
|
+
specify { subject[7].should == '1 6 10 01' }
|
17
|
+
specify { subject[8].should == '0' }
|
18
|
+
specify { subject[9].should == 10 }
|
19
|
+
specify { subject[10].should == 'GEL' }
|
20
|
+
specify { subject[11].should be_nil }
|
21
|
+
specify { subject[12].should == '0' }
|
22
|
+
specify { subject[13].should == '1' }
|
23
|
+
specify { subject[14].should == 'ერთეული'.to_geo }
|
24
|
+
specify { subject[15].should == 100 }
|
25
|
+
specify { subject[16].should == 100 }
|
26
|
+
specify { subject[17].should == ' მთ.წიგნი'.to_geo }
|
27
|
+
specify { subject[18].should == 'დიმიტრი ყურაშვილი'.to_geo }
|
28
|
+
specify { subject[19].should == '0' }
|
29
|
+
specify { subject[20].should == '9' }
|
30
|
+
specify { subject[21].should == '0' }
|
31
|
+
specify { subject[22].should == '' }
|
32
|
+
specify { subject[23].should == '0' }
|
33
|
+
specify { subject[24].should == Date.today.oris_format }
|
34
|
+
specify { subject[25].should be_nil }
|
35
|
+
specify { subject[26].should == '0' }
|
36
|
+
specify { subject[27].should == '1' }
|
37
|
+
specify { subject[28].should == '3' }
|
38
|
+
specify { subject[29].should == '' }
|
39
|
+
specify { subject[30].should == '0' }
|
40
|
+
specify { subject[31].should == '' }
|
41
|
+
specify { subject[32].should == '' }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'VAT calculations' do
|
45
|
+
context do
|
46
|
+
subject { ORIS::Operation.new(amount: 10) }
|
47
|
+
its(:calc_amount) { should == 10 }
|
48
|
+
end
|
49
|
+
context do
|
50
|
+
subject { ORIS::Operation.new(amount: 10, type: ORIS::VAT_PRICE) }
|
51
|
+
its(:calc_amount) { should == 1.53 }
|
52
|
+
end
|
53
|
+
context do
|
54
|
+
subject { ORIS::Operation.new(amount: 10, type: ORIS::EXCLUDE_VAT_PRICE) }
|
55
|
+
its(:calc_amount) { should == 8.47 }
|
56
|
+
end
|
57
|
+
context do
|
58
|
+
subject { ORIS::Operation.new(amount: 10.34, type: ORIS::EXCLUDE_VAT_PRICE) }
|
59
|
+
its(:calc_amount) { should == 8.76 }
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oris.ge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dimitri Kurashvili
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: c12-commons
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.1.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.1.0
|
46
|
+
description: Library for ORIS.GE accounting
|
47
|
+
email:
|
48
|
+
- dimitri@c12.ge
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/oris.rb
|
60
|
+
- lib/oris/date.rb
|
61
|
+
- lib/oris/operation.rb
|
62
|
+
- lib/oris/version.rb
|
63
|
+
- oris.gemspec
|
64
|
+
- spec/oris/date_spec.rb
|
65
|
+
- spec/oris/operation_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
homepage: http://c12.ge
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.24
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Library for transfering data to and from ORIS.GE accounting software
|
91
|
+
test_files:
|
92
|
+
- spec/oris/date_spec.rb
|
93
|
+
- spec/oris/operation_spec.rb
|
94
|
+
- spec/spec_helper.rb
|