diff --git a/app/controllers/operator/jobs_controller.rb b/app/controllers/operator/jobs_controller.rb index c9380bd..e8022fb 100644 --- a/app/controllers/operator/jobs_controller.rb +++ b/app/controllers/operator/jobs_controller.rb @@ -6,6 +6,9 @@ class Operator::JobsController < ApplicationController @openjobs = Job.open.order(:created_at) @printingjobs = Job.printing.order(:status_changed_at) @pickupjobs = Job.pickup.order(:status_changed_at) + @paidjobs = Job.paid.status_changed_today.order(:status_changed_at) + @canceledjobs = Job.canceled.status_changed_today.order(:status_changed_at) + @paidcanceledjobs = Job.paidcanceled.status_changed_today.order(:status_changed_at) end diff --git a/app/models/job.rb b/app/models/job.rb index 67d369b..112b482 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -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 diff --git a/app/views/jobs/index.html.erb b/app/views/jobs/index.html.erb index 6b5de58..56972f7 100644 --- a/app/views/jobs/index.html.erb +++ b/app/views/jobs/index.html.erb @@ -6,9 +6,9 @@

Aktuelle Plottaufträge <%= Date.today.strftime("%d.%m.%Y") %>

<%= link_to "Plottauftrag aufgeben", new_job_path, class: "px-3 py-2 bg-hsrm-red drop-shadow-lg transition-colors hover:bg-hsrm-red-light text-white block font-medium" %> -
+
- + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b0d41d8..efdcbbb 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -30,14 +30,8 @@ + diff --git a/app/views/operator/jobs/index.html.erb b/app/views/operator/jobs/index.html.erb index a53db75..84addb4 100644 --- a/app/views/operator/jobs/index.html.erb +++ b/app/views/operator/jobs/index.html.erb @@ -1,57 +1,73 @@ <%= turbo_stream_from 'operator_jobs' %> <% content_for :title, "Current Print Jobs" %> +
+ <%= link_to "#openjobs-h" do %> +
+

+ Open + <%= @openjobs.count %> +

+
+ <% end %> + <%= link_to "#printingjobs-h" do %> +
+

+ Printing + <%= @printingjobs.count %> +

+
+ <% end %> + <%= link_to "#pickupjobs-h" do %> +
+

+ Pickup + <%= @pickupjobs.count %> +

+
+ <% end %> + <%= link_to "#paidcanceledjobs-h" do %> +
+

+ Paid + <%= @paidjobs.count %> +

+
+ <% end %> + <%= link_to "#paidcanceledjobs-h" do %> +
+

+ Canceled + <%= @canceledjobs.count %> +

+
+ <% end %> +

- abholbereite Plottaufträge + Printing

-
+ <%# render partial: "job_card", collection: @printingjobs, as: :job %> +
ID Vorschau - <%= job.costumer_fullname %> - <% if job.pdf.attached? %> - <%= image_tag url_for(job.pdf.preview(resize_to_limit: [100, 100])) %> + <%= link_to_if job.printing?, image_tag(url_for(job.pdf.preview(resize_to_limit: [100, 100]))), job.pdf, download:true, class: "shadow-lg" %> + <% end %> + <%= job.costumer_fullname %> + <% if job.pdf.attached? %> <%#= link_to job.pdf.filename, rails_blob_path(job.pdf, disposition: "attachment") %> @@ -22,9 +23,19 @@ <% end %> - + <% if job.printing? %> + + <%= button_to icon("chevron-up", class: "size-5 inline", title: "erhöhen"), operator_job_path(job), method: :patch, form_class: "inline" %> + + <% end %> + <%= job.number_of_plans_a0 %> + <% if job.printing? %> + + <%= button_to icon("chevron-down", class: "size-5 inline", title: "verringern"), operator_job_path(job), method: :patch, form_class: "inline" %> + + <% end %> @@ -57,7 +68,27 @@ - <%= link_to icon("folder-arrow-down", class: "text-hsrm-gray size-8 inline", title: "Download"), job.pdf, download:true %> - <%= button_to icon("x-circle", class: "text-hsrm-red size-8 inline", title: "Abbrechen"), cancel_job_path(job), method: :patch, form: {data: {turbo_confirm: 'Den Plottauftrag wirklich abbrechen?'}}, form_class: "inline" %> + + <% if job.open? %> + <%= button_to icon("printer", class: "text-hsrm-gray size-6 inline drop-shadow hover:text-opacity-75", title: "Drucken"), printing_operator_job_path(job), method: :patch, form_class: "inline" %> + <% else %> + <%= icon("printer", class: "text-hsrm-gray text-opacity-25 size-6 inline drop-shadow", title: "") %> + <% end %> + <%= link_to_if job.printing?, icon("document-arrow-down", class: "text-hsrm-gray #{ unless job.printing?; 'text-opacity-25' else; 'hover:text-opacity-75'; end} size-6 inline", title: "Download"), job.pdf, download:true %> + <% if job.printing? %> + <%= button_to icon("check-circle", class: "text-green-700 size-6 inline drop-shadow hover:text-opacity-75", title: "Pläne sind fertig gedruckt"), pickup_operator_job_path(job), method: :patch, form: {data: {turbo_confirm: 'Sind die Pläne gedruckt und die Seitenanzahl und QM korrekt?'}}, form_class: "inline" %> + <% else %> + <%= icon("check-circle", class: "text-hsrm-gray text-opacity-25 size-6 inline drop-shadow", title: "Kann nicht mehr abgebrochen werden") %> + <% end %> + <% if job.pickup? %> + <%= button_to icon("banknotes", class: "text-status-paid size-6 inline drop-shadow hover:text-opacity-75", title: "Bezahlt"), paid_operator_job_path(job), method: :patch, form_class: "inline" %> + <% else %> + <%= icon("banknotes", class: "text-hsrm-gray text-opacity-25 size-6 inline drop-shadow ", title: "") %> + <% end %> + <% if job.open? || job.printing? || job.pickup? %> + <%= button_to icon("x-circle", class: "text-hsrm-red size-6 inline drop-shadow hover:text-opacity-75", title: "Abbrechen"), cancel_operator_job_path(job), method: :patch, form: {data: {turbo_confirm: 'Den Plottauftrag wirklich abbrechen?'}}, form_class: "inline" %> + <% else %> + <%= icon("x-circle", class: "text-hsrm-gray text-opacity-25 size-6 inline drop-shadow", title: "Kann nicht mehr abgebrochen werden") %> + <% end %>
- + + - - - - - - + + + + + + - - <%= render partial: "job_tr", collection: @pickupjobs, as: :job %> - <%#= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - -
ID ID Vorschau Auftraggeber PDF A0 A1 A2 A3 noDIN PDF A0 A1 A2 A3 no DIN Kosten Status
-
-
-

- aktuell druckende Plottaufträge -

-
-
- - - - - - - - - - - - - - - - - + <%= render partial: "job_tr", collection: @printingjobs, as: :job %> <%#= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> @@ -59,30 +75,89 @@

- offene Plottaufträge + Pickup

-
+
ID Auftraggeber PDF A0 A1 A2 A3 noDIN Kosten Status
- + + - + - + - + + <%= render partial: "job_tr", collection: @pickupjobs, as: :job %> + <%#= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + +
ID ID Vorschau Auftraggeber PDF PDF A0 A1 A2 A3 noDIN no DIN Kosten Status
+
+
+

+ open +

+
+
+ + + + + + + + + + + + + + + + + + <%= render partial: "job_tr", collection: @openjobs, as: :job %> <%#= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
ID Vorschau Auftraggeber PDF A0 A1 A2 A3 no DIN Kosten Status
+
+

+ Paid/Canceled +

+
+
+ + + + + + + + + + + + + + + + + + + <%= render partial: "job_tr", collection: @paidcanceledjobs, as: :job %> + <%#= link_to "Show this job", job, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + +
ID Vorschau Auftraggeber PDF A0 A1 A2 A3 no DIN Kosten Status
+
diff --git a/config/routes.rb b/config/routes.rb index 54956ab..6991fff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,14 @@ Rails.application.routes.draw do end end namespace :operator do - resources :jobs + resources :jobs do + member do + patch "cancel" + patch "pickup" + patch "printing" + patch "paid" + end + end end # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html