2019-02-02 12:40:57 +01:00
|
|
|
class PrinterJobsController < ApplicationController
|
|
|
|
include Concerns::SendOrderPdf
|
|
|
|
|
2019-10-28 21:11:35 +01:00
|
|
|
before_action -> { require_plugin_enabled FoodsoftPrinter }
|
2019-02-02 12:40:57 +01:00
|
|
|
|
|
|
|
def index
|
|
|
|
jobs = PrinterJob.includes(:printer_job_updates)
|
|
|
|
@pending_jobs = jobs.pending
|
|
|
|
@queued_jobs = jobs.queued
|
|
|
|
@finished_jobs = jobs.finished.order(finished_at: :desc).page(params[:page]).per(@per_page)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
order = Order.find(params[:order])
|
|
|
|
state = order.open? ? 'queued' : 'ready'
|
|
|
|
count = 0
|
|
|
|
PrinterJob.transaction do
|
2023-05-12 13:01:12 +02:00
|
|
|
%w[articles fax groups matrix].each do |document|
|
2019-02-02 12:40:57 +01:00
|
|
|
next unless FoodsoftConfig["printer_print_order_#{document}"]
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2019-02-02 12:40:57 +01:00
|
|
|
job = PrinterJob.create! order: order, document: document, created_by: current_user
|
|
|
|
job.add_update! state
|
|
|
|
count += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
redirect_to order, notice: t('.notice', count: count)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@job = PrinterJob.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2020-08-12 20:05:57 +02:00
|
|
|
def requeue
|
|
|
|
job = PrinterJob.find(params[:id])
|
|
|
|
job = PrinterJob.create! order: job.order, document: job.document, created_by: current_user
|
|
|
|
job.add_update! 'requeued'
|
|
|
|
PrinterChannel.broadcast_unfinished
|
|
|
|
redirect_to printer_jobs_path, notice: t('.notice')
|
|
|
|
end
|
|
|
|
|
2019-02-02 12:40:57 +01:00
|
|
|
def document
|
|
|
|
job = PrinterJob.find(params[:id])
|
|
|
|
send_order_pdf job.order, job.document
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
job = PrinterJob.find(params[:id])
|
|
|
|
job.finish! current_user
|
|
|
|
redirect_to printer_jobs_path, notice: t('.notice')
|
2023-05-12 13:01:12 +02:00
|
|
|
rescue StandardError => e
|
|
|
|
redirect_to printer_jobs_path, t('errors.general_msg', msg: e.message)
|
2019-02-02 12:40:57 +01:00
|
|
|
end
|
|
|
|
end
|