Class: JournalEntryItem

Inherits:
Ekylibre::Record::Base show all
Defined in:
app/models/journal_entry_item.rb

Overview

What are the differents columns:

* (credit|debit|balance) are in currency of the journal
* real_(credit|debit|balance) are in currency of the financial year
* absolute_(credit|debit|balance) are in currency of the company
* cumulated_absolute_(credit|debit) are in currency of the company too

Instance Method Summary collapse

Methods inherited from Ekylibre::Record::Base

#already_updated?, attr_readonly_with_conditions, #check_if_destroyable?, #check_if_updateable?, columns_definition, complex_scopes, customizable?, #customizable?, #customized?, #destroyable?, #editable?, has_picture, #human_attribute_name, human_attribute_name_with_id, nomenclature_reflections, #old_record, #others, refers_to, scope_with_registration, simple_scopes, #updateable?

Instance Method Details

#balanced_entryObject

this method:allows to fix a display color if the entry containing the entry_item is balanced or not.


286
287
288
# File 'app/models/journal_entry_item.rb', line 286

def balanced_entry
  (entry.balanced? ? 'balanced' : 'unbalanced')
end

#balanced_letter?Boolean

Check if the current letter is balanced with all entry items with the same letter

Returns:

  • (Boolean)

255
256
257
258
# File 'app/models/journal_entry_item.rb', line 255

def balanced_letter?
  return true if letter.blank?
  .balanced_letter?(letter)
end

#clear_bank_statement_reconciliationObject


185
186
187
188
# File 'app/models/journal_entry_item.rb', line 185

def clear_bank_statement_reconciliation
  return unless bank_statement && bank_statement_letter
  bank_statement.items.where(letter: bank_statement_letter).update_all(letter: nil)
end

#cumulated_absolute_balanceObject

Returns the balance as cumulated_absolute_debit - cumulated_absolute_credit


241
242
243
# File 'app/models/journal_entry_item.rb', line 241

def cumulated_absolute_balance
  (self.cumulated_absolute_debit - self.cumulated_absolute_credit)
end

#followingsObject

Returns following items


231
232
233
234
235
236
237
238
# File 'app/models/journal_entry_item.rb', line 231

def followings
  return self.class.none unless 
  if new_record?
    .journal_entry_items.where('printed_on > ?', printed_on)
  else
    .journal_entry_items.where('(printed_on = ? AND id > ?) OR printed_on > ?', printed_on, id, printed_on)
  end
end

#journal_nameObject

This method returns the name of journal which the entries are saved.


277
278
279
280
281
282
283
# File 'app/models/journal_entry_item.rb', line 277

def journal_name
  if entry
    return entry.journal.name
  else
    :none.tl
  end
end

#modeObject

this method allows to fix a display color if the entry_item is in draft mode.


261
262
263
264
265
# File 'app/models/journal_entry_item.rb', line 261

def mode
  mode = ''
  mode += 'warning' if draft?
  mode
end

#next(balance) ⇒ Object

this method creates a next entry_item with an initialized value matching to the previous entry.


291
292
293
294
295
296
297
298
299
# File 'app/models/journal_entry_item.rb', line 291

def next(balance)
  entry_item = JournalEntryItem.new
  if balance > 0
    entry_item.real_credit = balance.abs
  elsif balance < 0
    entry_item.real_debit = balance.abs
  end
  entry_item
end

#previousObject

Returns the previous item


221
222
223
224
225
226
227
228
# File 'app/models/journal_entry_item.rb', line 221

def previous
  return nil unless 
  if new_record?
    .journal_entry_items.order(printed_on: :desc, id: :desc).where('printed_on <= ?', printed_on).limit(1).first
  else
    .journal_entry_items.order(printed_on: :desc, id: :desc).where('(printed_on = ? AND id < ?) OR printed_on < ?', printed_on, id, printed_on).limit(1).first
  end
end

#resourceObject


268
269
270
271
272
273
274
# File 'app/models/journal_entry_item.rb', line 268

def resource
  if entry
    return entry.resource_type
  else
    :none.tl
  end
end

#state_labelObject

Prints human name of current state


195
196
197
# File 'app/models/journal_entry_item.rb', line 195

def state_label
  JournalEntry.tc("states.#{state}")
end

#uncumulateObject

Cancel old values if specific columns have been updated


206
207
208
209
210
211
212
213
# File 'app/models/journal_entry_item.rb', line 206

def uncumulate
  old = old_record
  if absolute_debit != old.absolute_debit || absolute_credit != old.absolute_credit || printed_on != old.printed_on
    # self.cumulated_absolute_debit  -= old.absolute_debit
    # self.cumulated_absolute_credit -= old.absolute_credit
    old.followings.update_all("cumulated_absolute_debit = cumulated_absolute_debit - #{old.absolute_debit}, cumulated_absolute_credit = cumulated_absolute_credit - #{old.absolute_debit}")
  end
end

#unmarkObject

Unmark all the journal entry items with the same mark in the same account


216
217
218
# File 'app/models/journal_entry_item.rb', line 216

def unmark
  .unmark(letter) unless letter.blank?
end

#update_entryObject

Updates the amounts to the debit and the credit for the matching entry.


201
202
203
# File 'app/models/journal_entry_item.rb', line 201

def update_entry
  entry.refresh
end