Some layout and model changes

This commit is contained in:
2024-08-01 15:45:09 +02:00
parent f510d4ed09
commit 69bca2d99e
6 changed files with 40 additions and 57 deletions

View File

@@ -2,21 +2,31 @@ 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
# NOTE: Multiple status if paing before brinting?
enum status: {
open: 0,
printing: 1,
ready_for_pickup: 2,
paid: 3,
cancelled: 4
canceled: 4
}
# BUG: shows the hole day of the utc timezone
scope :today, -> { where('DATE(created_at) = ?', Time.now.utc.to_date) }
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]) }
def self.current_jobs
today.order(created_at: :desc, status: :asc)
# today.order(created_at: :desc, status: :asc)
# 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