module Support
  module Helpers
    module AccountingRun
      class << self
        def in_progress?
          # get the current period
          period = Support::Services::VectorApi.active_accounting_period
          # Check if the current period is proccessing
          puts "current period is #{period}"
          query = "SELECT status FROM period WHERE period_id=#{period}"
          Support::DbClient.query_art_relations(query).each do |row|
            status = row["status"]
            return true if status == "closed"
            if status == "open"
              fail(StandardError, "Active period cannot be open")
            end
          end
          false
        end
      end
    end
  end
end
