Class: ORIS::Operation
- Inherits:
-
Object
- Object
- ORIS::Operation
- Defined in:
- lib/oris/operation.rb
Instance Attribute Summary collapse
-
#acc_credit ⇒ Object
Credit (-) account number.
-
#acc_debit ⇒ Object
Debit (+) account number.
-
#amount ⇒ Object
Amount and currency of the document.
-
#currency ⇒ Object
Amount and currency of the document.
-
#date ⇒ Object
Date of the document.
-
#description ⇒ Object
Short description.
-
#name_credit ⇒ Object
Name of the credit account.
-
#name_debit ⇒ Object
Name of the debit account.
-
#number ⇒ Object
Document number.
-
#project ⇒ Object
Project used.
-
#quantity ⇒ Object
Quantity in base units.
-
#quantity_normal ⇒ Object
Normal quantity – quantity in most small unit.
-
#related_to ⇒ Object
Number of the document, this document is related to.
-
#sysdate ⇒ Object
User who performed this operation and operation’s date.
-
#type ⇒ Object
Amount and currency of the document.
-
#unit ⇒ Object
Unit quantity.
-
#user ⇒ Object
User who performed this operation and operation’s date.
Class Method Summary collapse
-
.to_csv(opts) ⇒ Object
Convert to CSV.
Instance Method Summary collapse
- #calc_amount ⇒ Object
-
#errors ⇒ Object
Errors.
-
#initialize(opts = {}) ⇒ Operation
constructor
A new instance of Operation.
-
#to_a ⇒ Object
Operation representation as an arrya (row).
- #valid? ⇒ Boolean
-
#validate ⇒ Object
Validate this operation.
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_credit ⇒ Object
Credit (-) account number.
22 23 24 |
# File 'lib/oris/operation.rb', line 22 def acc_credit @acc_credit end |
#acc_debit ⇒ Object
Debit (+) account number.
18 19 20 |
# File 'lib/oris/operation.rb', line 18 def acc_debit @acc_debit end |
#amount ⇒ Object
Amount and currency of the document.
27 28 29 |
# File 'lib/oris/operation.rb', line 27 def amount @amount end |
#currency ⇒ Object
Amount and currency of the document.
27 28 29 |
# File 'lib/oris/operation.rb', line 27 def currency @currency end |
#date ⇒ Object
Date of the document
15 16 17 |
# File 'lib/oris/operation.rb', line 15 def date @date end |
#description ⇒ Object
Short description
13 14 15 |
# File 'lib/oris/operation.rb', line 13 def description @description end |
#name_credit ⇒ Object
Name of the credit account.
24 25 26 |
# File 'lib/oris/operation.rb', line 24 def name_credit @name_credit end |
#name_debit ⇒ Object
Name of the debit account.
20 21 22 |
# File 'lib/oris/operation.rb', line 20 def name_debit @name_debit end |
#number ⇒ Object
Document number
9 10 11 |
# File 'lib/oris/operation.rb', line 9 def number @number end |
#project ⇒ Object
Project used.
36 37 38 |
# File 'lib/oris/operation.rb', line 36 def project @project end |
#quantity ⇒ Object
Quantity in base units.
29 30 31 |
# File 'lib/oris/operation.rb', line 29 def quantity @quantity end |
#quantity_normal ⇒ Object
Normal quantity – quantity in most small unit.
31 32 33 |
# File 'lib/oris/operation.rb', line 31 def quantity_normal @quantity_normal end |
#related_to ⇒ Object
Number of the document, this document is related to
11 12 13 |
# File 'lib/oris/operation.rb', line 11 def @related_to end |
#sysdate ⇒ Object
User who performed this operation and operation’s date.
38 39 40 |
# File 'lib/oris/operation.rb', line 38 def sysdate @sysdate end |
#type ⇒ Object
Amount and currency of the document.
27 28 29 |
# File 'lib/oris/operation.rb', line 27 def type @type end |
#unit ⇒ Object
Unit quantity.
33 34 35 |
# File 'lib/oris/operation.rb', line 33 def unit @unit end |
#user ⇒ Object
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_amount ⇒ Object
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 |
#errors ⇒ Object
Errors.
41 42 43 |
# File 'lib/oris/operation.rb', line 41 def errors @errors end |
#to_a ⇒ Object
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., '0', '1', '3', '', '0', '', ''] end |
#valid? ⇒ Boolean
52 53 54 |
# File 'lib/oris/operation.rb', line 52 def valid? self.errors.nil? or self.errors.size == 0 end |
#validate ⇒ Object
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 |