Initial commit

This commit is contained in:
Yaser
2026-08-13 19:50:53 +03:30
commit 38084458fe
879 changed files with 95198 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
# frozen_string_literal: true
# TODO: Add admin rubric for Account.
module Operations
class Account < ApplicationRecord
SCOPES = %w[member platform].freeze
MEMBER_TYPES = %w[liability].freeze
PLATFORM_TYPES = %w[asset expense revenue].freeze
TYPES = (MEMBER_TYPES + PLATFORM_TYPES).freeze
validates :code, presence: true, uniqueness: true
validates :type, presence: true, inclusion: { in: TYPES }
validates :kind, presence: true, uniqueness: { scope: %i[type currency_type] }
validates :currency_type, presence: true, inclusion: { in: Currency.types.map(&:to_s) }
validates :scope, presence: true, inclusion: { in: SCOPES }
def self.table_name_prefix
'operations_'
end
# Type column reserved for STI.
self.inheritance_column = nil
# Allows dynamically check scopes.
# scope.platform?
def scope
super&.inquiry
end
# Allows dynamically check kinds.
# kind.main?
def kind
super&.inquiry
end
end
end
# == Schema Information
# Schema version: 20190115165813
#
# Table name: operations_accounts
#
# id :integer not null, primary key
# code :integer not null
# type :string(10) not null
# kind :string(30) not null
# currency_type :string(10) not null
# description :string(100)
# scope :string(10) not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_operations_accounts_on_code (code) UNIQUE
# index_operations_accounts_on_currency_type (currency_type)
# index_operations_accounts_on_scope (scope)
# index_operations_accounts_on_type (type)
# index_operations_accounts_on_type_and_kind_and_currency_type (type,kind,currency_type) UNIQUE
#

View File

@@ -0,0 +1,29 @@
# frozen_string_literal: true
module Operations
# {Asset} is a balance sheet operation
class Asset < Operation
end
end
# == Schema Information
# Schema version: 20201125134745
#
# Table name: assets
#
# id :integer not null, primary key
# code :integer not null
# currency_id :string(255) not null
# reference_type :string(255)
# reference_id :integer
# debit :decimal(32, 16) default(0.0), not null
# credit :decimal(32, 16) default(0.0), not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_assets_on_currency_id (currency_id)
# index_assets_on_reference_type_and_reference_id (reference_type,reference_id)
#

View File

@@ -0,0 +1,29 @@
# frozen_string_literal: true
module Operations
# {Expense} is a income statement operation
class Expense < Operation
end
end
# == Schema Information
# Schema version: 20201125134745
#
# Table name: expenses
#
# id :integer not null, primary key
# code :integer not null
# currency_id :string(255) not null
# reference_type :string(255)
# reference_id :integer
# debit :decimal(32, 16) default(0.0), not null
# credit :decimal(32, 16) default(0.0), not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_expenses_on_currency_id (currency_id)
# index_expenses_on_reference_type_and_reference_id (reference_type,reference_id)
#

View File

@@ -0,0 +1,56 @@
# frozen_string_literal: true
module Operations
# {Liability} is a balance sheet operation
class Liability < Operation
belongs_to :member
validates :member_id, presence: {
if: ->(liability) { liability.account.scope == 'member' }
}
validates :member_id, absence: {
if: ->(liability) { liability.account.scope != 'member' }
}
# Notify third party trading engine about member balance update.
after_commit on: :create do
AMQP::Queue.enqueue(:events_processor,
subject: :operation,
payload: as_json_for_events_processor)
end
def as_json_for_events_processor
{ code: code,
currency: currency_id,
member_id: member_id,
reference_id: reference_id,
reference_type: reference_type&.downcase,
debit: debit,
credit: credit }
end
end
end
# == Schema Information
# Schema version: 20201125134745
#
# Table name: liabilities
#
# id :integer not null, primary key
# code :integer not null
# currency_id :string(255) not null
# member_id :integer
# reference_type :string(255)
# reference_id :integer
# debit :decimal(32, 16) default(0.0), not null
# credit :decimal(32, 16) default(0.0), not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_liabilities_on_currency_id (currency_id)
# index_liabilities_on_member_id (member_id)
# index_liabilities_on_reference_type_and_reference_id (reference_type,reference_id)
#

View File

@@ -0,0 +1,32 @@
# frozen_string_literal: true
module Operations
# {Revenue} is a income statement operation
class Revenue < Operation
belongs_to :member
scope :h24, -> { where('created_at > ?', 24.hours.ago) }
end
end
# == Schema Information
# Schema version: 20201125134745
#
# Table name: revenues
#
# id :integer not null, primary key
# code :integer not null
# currency_id :string(255) not null
# member_id :integer
# reference_type :string(255)
# reference_id :integer
# debit :decimal(32, 16) default(0.0), not null
# credit :decimal(32, 16) default(0.0), not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_revenues_on_currency_id (currency_id)
# index_revenues_on_reference_type_and_reference_id (reference_type,reference_id)
#