Sha256: f74ccf4136df8994b83e903f492a03596d89d4cee3fe026ac9ca24d2d5737eda

Contents?: true

Size: 869 Bytes

Versions: 2

Compression:

Stored size: 869 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/letters"

module Renalware
  module Letters
    class Batch < ApplicationRecord
      include Accountable
      attr_accessor(
        :url,
        :enclosures_present,
        :state_eq,
        :author_id_eq,
        :created_by_id_eq,
        :letterhead_id_eq,
        :page_count_in_array,
        :s
      )

      enum status: { queued: 0, processing: 10, awaiting_printing: 15, failure: 20, success: 30 }
      has_many(
        :items,
        dependent: :restrict_with_exception,
        class_name: "Renalware::Letters::BatchItem"
      )
      has_many(
        :letters,
        through: :items,
        class_name: "Renalware::Letters::Letter"
      )

      def percent_complete
        ((items.where(status: :compiled).count.to_f / batch_items_count) * 100).ceil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
renalware-core-2.0.111 app/models/renalware/letters/batch.rb
renalware-core-2.0.110 app/models/renalware/letters/batch.rb