Class: ORIS::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/oris/operation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Operation

Returns a new instance of Operation.



56
57
58
59
60
# File 'lib/oris/operation.rb', line 56

def initialize(opts = {})
  opts.each do |k, v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
end

Instance Attribute Details

#acc_creditObject

Credit (-) account number.



22
23
24
# File 'lib/oris/operation.rb', line 22

def acc_credit
  @acc_credit
end

#acc_debitObject

Debit (+) account number.



18
19
20
# File 'lib/oris/operation.rb', line 18

def acc_debit
  @acc_debit
end

#amountObject

Amount and currency of the document.



27
28
29
# File 'lib/oris/operation.rb', line 27

def amount
  @amount
end

#currencyObject

Amount and currency of the document.



27
28
29
# File 'lib/oris/operation.rb', line 27

def currency
  @currency
end

#dateObject

Date of the document



15
16
17
# File 'lib/oris/operation.rb', line 15

def date
  @date
end

#descriptionObject

Short description



13
14
15
# File 'lib/oris/operation.rb', line 13

def description
  @description
end

#name_creditObject

Name of the credit account.



24
25
26
# File 'lib/oris/operation.rb', line 24

def name_credit
  @name_credit
end

#name_debitObject

Name of the debit account.



20
21
22
# File 'lib/oris/operation.rb', line 20

def name_debit
  @name_debit
end

#numberObject

Document number



9
10
11
# File 'lib/oris/operation.rb', line 9

def number
  @number
end

#projectObject

Project used.



36
37
38
# File 'lib/oris/operation.rb', line 36

def project
  @project
end

#quantityObject

Quantity in base units.



29
30
31
# File 'lib/oris/operation.rb', line 29

def quantity
  @quantity
end

#quantity_normalObject

Normal quantity – quantity in most small unit.



31
32
33
# File 'lib/oris/operation.rb', line 31

def quantity_normal
  @quantity_normal
end

Number of the document, this document is related to



11
12
13
# File 'lib/oris/operation.rb', line 11

def related_to
  @related_to
end

#sysdateObject

User who performed this operation and operation’s date.



38
39
40
# File 'lib/oris/operation.rb', line 38

def sysdate
  @sysdate
end

#typeObject

Amount and currency of the document.



27
28
29
# File 'lib/oris/operation.rb', line 27

def type
  @type
end

#unitObject

Unit quantity.



33
34
35
# File 'lib/oris/operation.rb', line 33

def unit
  @unit
end

#userObject

User who performed this operation and operation’s date.



38
39
40
# File 'lib/oris/operation.rb', line 38

def user
  @user
end

Class Method Details

.to_csv(opts) ⇒ Object

Convert to CSV.



89
90
91
92
93
94
95
# File 'lib/oris/operation.rb', line 89

def self.to_csv(opts)
  CSV.generate(force_quotes: true) do |csv|
    opts.each do |opt|
      csv << opt.to_a
    end
  end
end

Instance Method Details

#calc_amountObject



62
63
64
65
66
67
68
69
70
# File 'lib/oris/operation.rb', line 62

def calc_amount
  unless self.amount.nil?
    case self.type
    when VAT_PRICE then (self.amount - (self.amount/1.18).round(2)).round(2)
    when EXCLUDE_VAT_PRICE then (self.amount/1.18).round(2)
    else self.amount.round(2)
    end
  end
end

#errorsObject

Errors.



41
42
43
# File 'lib/oris/operation.rb', line 41

def errors
  @errors
end

#to_aObject

Operation representation as an arrya (row).



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/oris/operation.rb', line 73

def to_a
  docnumb  = self.number
  docdate  = self.date ? self.date.oris_format : Date.today.oris_format
  currency = self.currency ? self.currency : 'GEL'
  project   = self.project ? self.project.to_geo : ' მთ.წიგნი'.to_geo
  sysdate  = self.sysdate ? self.sysdate.oris_format : Date.today.oris_format
  unit = self.unit ? self.unit.to_geo : 'ერთეული'.to_geo
  quant = self.quantity || 0
  quant2 = self.quantity_normal || quant
  user = self.user ? self.user.to_geo : ''
  ['', '', '', docnumb, '0', docdate, ORIS.oris_acc_code(self.acc_debit), ORIS.oris_acc_code(self.acc_credit),
    '0', self.calc_amount, currency, self.description, '0', '1', unit, quant, quant2, project, user,
    '0', '9', '0', '', '0', sysdate, self.related_to, '0', '1', '3', '', '0', '', '']
end

#valid?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/oris/operation.rb', line 52

def valid?
  self.errors.nil? or self.errors.size == 0
end

#validateObject

Validate this operation.



46
47
48
49
50
# File 'lib/oris/operation.rb', line 46

def validate
  @errors = []
  @errors.push('დებიტორული ანგარიში არაა განსაზღვრული') if self.acc_debit.blank?
  @errors.push('კრედიტორული ანგარიში არაა განსაზღვრული') if self.acc_credit.blank?
end