36 lines
1.3 KiB
Ruby
36 lines
1.3 KiB
Ruby
class Job < ApplicationRecord
|
|
belongs_to :operator, class_name: 'User', optional: true
|
|
belongs_to :costumer, class_name: 'User', optional: true
|
|
|
|
# NOTE: Multiple status if paing before brinting?
|
|
enum status: {
|
|
open: 0,
|
|
printing: 1,
|
|
ready_for_pickup: 2,
|
|
paid: 3,
|
|
canceled: 4
|
|
}
|
|
|
|
scope :of_the_day, ->(date) { where('created_at >= ? AND created_at <= ?', date.beginning_of_day, date.end_of_day) }
|
|
scope :of_today, -> { of_the_day(Time.now) }
|
|
# NOTE: only named status are returned because of WHERE/IN clause for the enum values
|
|
scope :in_status_order, -> { in_order_of(:status, %w[open printing ready_for_pickup paid canceled]) }
|
|
|
|
# TODO: add logic (all with status: open, printing, ready_for_pickup. with status paid and canceled only from today)
|
|
scope :done_on_day, ->(date) { where('created_at >= ? AND created_at <= ?', date.beginning_of_day, date.end_of_day) }
|
|
|
|
def self.current_jobs_of_today
|
|
# NOTE: use Time.now instead of Date.today to take the timezone into account
|
|
of_the_day(Time.now).in_status_order
|
|
end
|
|
|
|
def self.current_jobs_of_(date)
|
|
# NOTE: use Time.now instead of Date.today to take the timezone into account
|
|
of_the_day(date).in_status_order
|
|
end
|
|
|
|
def fullname
|
|
[costumer_firstname, ' ', costumer_lastname].join
|
|
end
|
|
end
|