Class: Check
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Check
- 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
Belongs to collapse
Methods included from Models::Auditable
Has many collapse
Class Method Summary collapse
Instance Method Summary collapse
- #file_name ⇒ Object
- #print_check(current_user) ⇒ Object
-
#record_print(current_user) ⇒ Object
validates_uniqueness_of :check_number, :scope => :bank_account_id.
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 Models::EventPublishable
Class Method Details
.number_as_sentence(amount) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'app/models/check.rb', line 70 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_margins ⇒ Object
79 80 81 |
# File 'app/models/check.rb', line 79 def self.pdf_margins { :top => 7, :bottom => 5, :left => 6, :right => 5 } end |
Instance Method Details
#bank_account ⇒ BankAccount
40 |
# File 'app/models/check.rb', line 40 belongs_to :bank_account, optional: true |
#file_name ⇒ Object
66 67 68 |
# File 'app/models/check.rb', line 66 def file_name "check_#{self.check_number}.pdf" end |
#last_printed_by ⇒ Party
41 |
# File 'app/models/check.rb', line 41 belongs_to :last_printed_by, :class_name => "Party", optional: true |
#outgoing_payment ⇒ OutgoingPayment
39 |
# File 'app/models/check.rb', line 39 belongs_to :outgoing_payment, optional: true |
#print_check(current_user) ⇒ Object
61 62 63 64 |
# File 'app/models/check.rb', line 61 def print_check(current_user) self.record_print(current_user) return self.uploads.first end |
#record_print(current_user) ⇒ Object
validates_uniqueness_of :check_number, :scope => :bank_account_id
50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/check.rb', line 50 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 |
#uploads ⇒ ActiveRecord::Relation<Upload>
43 |
# File 'app/models/check.rb', line 43 has_many :uploads, :as => :resource, :dependent => :destroy |