class Accounting::StudentMatrix < ApplicationRecord
  include Validatable

  belongs_to :student
  belongs_to :subcategory

  def self.build_all(student)
    student.school.accounting_subcategories.ordered.map do |subcategory|
      student.accounting_student_matrices.find_or_initialize_by(subcategory: subcategory)
    end
  end

  def process_matrix(transaction_total)
    amounts = {}
    amounts[:one] = primary * transaction_total.to_f / 100
    amounts[:two] = transaction_total.to_f - amounts[:one]
    amounts
  end
end
