Class: Check

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/check.rb

Overview

== Schema Information

Table name: checks
Database name: primary

id :integer not null, primary key
address :text
amount :decimal(10, 2)
check_number :string(255)
date :date
last_printed_at :datetime
payee :string(255)
print_audit :jsonb
print_count :integer default(0)
uploads_count :integer
created_at :datetime
updated_at :datetime
bank_account_id :integer
creator_id :integer
last_printed_by_id :integer
outgoing_payment_id :integer
updater_id :integer

Indexes

idx_check_number_outgoing_payment_id (check_number,outgoing_payment_id)
index_checks_on_bank_account_id_and_check_number (bank_account_id,check_number) UNIQUE
index_checks_on_outgoing_payment_id (outgoing_payment_id)

Foreign Keys

checks_bank_account_id_fkey (bank_account_id => outgoing_payments.id)
checks_payment_id_fkey (outgoing_payment_id => outgoing_payments.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.number_as_sentence(amount) ⇒ String

Render amount in the long-form cheque text — "One hundred twenty-three 45/100". Always lower-cased then capitalised so
the output reads as a sentence.

Parameters:

  • amount (Numeric, String)

Returns:

  • (String)


91
92
93
94
95
96
97
98
# File 'app/models/check.rb', line 91

def self.number_as_sentence(amount)
  m = BigDecimal(amount.to_s)
  dollars = m.to_i
  cents = ((m - dollars)*100).to_i
  dollars_string = dollars.humanize
  cents_string = "#{cents.to_s.rjust(2,'0')}/100"
  "#{dollars_string} #{cents_string}".capitalize
end

.pdf_marginsHash{Symbol=>Integer}

PDF margins (in points) for cheque-stock printing — these
are dialled in for our cheque vendor's pre-printed paper.

Returns:

  • (Hash{Symbol=>Integer})


103
104
105
# File 'app/models/check.rb', line 103

def self.pdf_margins
  { :top => 7, :bottom => 5, :left => 6, :right => 5 }
end

Instance Method Details

#bank_accountBankAccount



41
# File 'app/models/check.rb', line 41

belongs_to :bank_account, optional: true

#file_nameString

Browser filename used when the PDF is downloaded —
"check_<NUMBER>.pdf".

Returns:

  • (String)


81
82
83
# File 'app/models/check.rb', line 81

def file_name
  "check_#{self.check_number}.pdf"
end

#last_printed_byParty

Returns:

See Also:



42
# File 'app/models/check.rb', line 42

belongs_to :last_printed_by, :class_name => "Party", optional: true

#outgoing_paymentOutgoingPayment



40
# File 'app/models/check.rb', line 40

belongs_to :outgoing_payment, optional: true

Record a print and return the first attached PDF Upload
(the printable artifact).

Parameters:

Returns:



73
74
75
76
# File 'app/models/check.rb', line 73

def print_check(current_user)
  self.record_print(current_user)
  return self.uploads.first
end

#record_print(current_user) ⇒ Boolean

Bump print_count, stamp the printer / time, and append an
audit entry. Called whenever the cheque PDF is generated.

Parameters:

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
# File 'app/models/check.rb', line 58

def record_print(current_user)
  print_time = Time.current
  self.print_count ||= 0
  self.print_count += 1
  self.last_printed_by = current_user
  self.last_printed_at = print_time
  self.print_audit ||= []
  self.print_audit << {:printed_by => current_user.full_name, :printed_on => print_time}
  self.save
end

#uploadsActiveRecord::Relation<Upload>

Returns:

  • (ActiveRecord::Relation<Upload>)

See Also:



44
# File 'app/models/check.rb', line 44

has_many :uploads, :as => :resource, :dependent => :destroy