Worked on operator view

This commit is contained in:
2024-08-13 04:42:17 +02:00
parent b467f9c86d
commit ead82a9222
8 changed files with 195 additions and 68 deletions

View File

@@ -31,9 +31,13 @@ class Job < ApplicationRecord
scope :created_on_day, lambda { |date|
where("created_at >= ? AND created_at <= ?", date.beginning_of_day, date.end_of_day)
}
scope :upgraded_today, -> { upgraded_on_day(Time.now) }
scope :upgraded_on_day, lambda { |date|
where("upgraded_at >= ? AND upgraded_at <= ?", date.beginning_of_day, date.end_of_day)
scope :updated_today, -> { updated_on_day(Time.now) }
scope :updated_on_day, lambda { |date|
where("updated_at >= ? AND updated_at <= ?", date.beginning_of_day, date.end_of_day)
}
scope :status_changed_today, -> { status_changed_on_day(Time.now) }
scope :status_changed_on_day, lambda { |date|
where("status_changed_at >= ? AND status_changed_at <= ?", date.beginning_of_day, date.end_of_day)
}
# Returns all jobs with status: open print pickup and jobs from today with status: paid canceled
# paid: only updated_at today
@@ -45,11 +49,15 @@ class Job < ApplicationRecord
.where("status_changed_at >= ?", Time.now.beginning_of_day))
# .in_status_order
.order(created_at: :desc)
#.order(:costumer_firstname, :costumer_lastname)
# .order(:costumer_firstname, :costumer_lastname)
.with_attached_pdf # scope from activestorage for .includes(pdf_attachment: :blob)
# .references(:pdf_attachment, :blob) # creates big join table
end
def self.paidcanceled
Job.where(status: %i[paid canceled])
end
def costumer_fullname
[ costumer_firstname, " ", costumer_lastname ].join
end
@@ -65,12 +73,17 @@ class Job < ApplicationRecord
def able_to_cancel?
open?
# TODO: different check for operator and admin
end
# cancel job only if it is still open
def canceled!
self.status = :canceled if open?
save
if able_to_cancel?
self.status = :canceled
self.printed_at = nil
self.paid_at = nil
save
end
end
private