Add view to sort orders by pickup day

This commit is contained in:
Patrick Gansterer 2017-11-06 18:07:36 +01:00
parent bd49a64cd7
commit 209ad615b4
7 changed files with 90 additions and 1 deletions

View file

@ -0,0 +1,26 @@
class PickupsController < ApplicationController
def index
@orders = Order.finished_not_closed.order('pickup DESC').group_by { |o| o.pickup }
end
def document
return redirect_to pickups_path, alert: t('.empty_selection') unless params[:orders]
order_ids = params[:orders].map(&:to_i)
if params[:articles_pdf]
klass = OrderByArticles
elsif params[:groups_pdf]
klass = OrderByGroups
elsif params[:matrix_pdf]
klass = OrderMatrix
end
return redirect_to pickups_path, alert: t('.invalid_document') unless klass
date = params[:date]
pdf = klass.new(order_ids, title: t('.title', date: date), show_supplier: true)
send_data pdf.to_pdf, filename: t('.filename', date: date) + '.pdf', type: 'application/pdf'
end
end

View file

@ -0,0 +1,34 @@
- title t('.title')
- @orders.each do |pickup, orders|
= form_tag document_pickups_path do
= hidden_field_tag 'date', l(pickup, format: :long)
%h2
- if pickup
= l pickup, format: :long
- else
= t '.without_pickup'
%span{style:'float:right'}
= submit_tag t('.article_pdf'), name: 'articles_pdf', class: 'btn'
= submit_tag t('.group_pdf'), name: 'groups_pdf', class: 'btn'
= submit_tag t('.matrix_pdf'), name: 'matrix_pdf', class: 'btn'
%table.table.table-striped
%thead
%tr
%th{style:'width:50%'}= heading_helper Order, :name
%th{style:'width:50%'}= heading_helper Order, :note
%th{style:'width:1px'}= t 'ui.actions'
%tbody
- for order in orders
%tr
%td
= check_box_tag "orders[]", order.id, true #, style: 'float:left'
- if current_user.role_orders?
= link_to order.name, order_path(order)
- else
= order.name
%td= truncate order.note
%td{style:'white-space:nowrap'}
= render 'shared/order_download_button', order: order, klass: 'btn-small'
= receive_button order, class: 'btn-small'

View file

@ -1451,6 +1451,7 @@ de:
archive: Meine Bestellungen archive: Meine Bestellungen
manage: Bestellverwaltung manage: Bestellverwaltung
ordering: Bestellen! ordering: Bestellen!
pickups: Abholtage
title: Bestellungen title: Bestellungen
tasks: Aufgaben tasks: Aufgaben
wiki: wiki:
@ -1672,6 +1673,17 @@ de:
title: "%{title} - Version %{version}" title: "%{title} - Version %{version}"
title_version: Version title_version: Version
view_current: Aktuelle Version sehen view_current: Aktuelle Version sehen
pickups:
document:
empty_selection: Es muss zumindest eine Bestellung ausgewählt sein.
filename: Abholungen für %{date}
invalid_document: Ungültiger Dokumententyp
title: Abholungen für %{date}
index:
article_pdf: Artikel PDF
group_pdf: Gruppen PDF
matrix_pdf: Matrix PDF
title: Abholtage
sessions: sessions:
logged_in: Angemeldet! logged_in: Angemeldet!
logged_out: Abgemeldet! logged_out: Abgemeldet!

View file

@ -1461,6 +1461,7 @@ en:
archive: My Orders archive: My Orders
manage: Manage orders manage: Manage orders
ordering: Place order! ordering: Place order!
pickups: Pickup days
title: Orders title: Orders
tasks: Tasks tasks: Tasks
wiki: wiki:
@ -1682,6 +1683,17 @@ en:
title: "%{title} - version %{version}" title: "%{title} - version %{version}"
title_version: Version title_version: Version
view_current: See current version view_current: See current version
pickups:
document:
empty_selection: At least one order must be selected.
filename: Pickup for %{date}
invalid_document: Invalid document type
title: Pickup for %{date}
index:
article_pdf: Article PDF
group_pdf: Group PDF
matrix_pdf: Matrix PDF
title: Pickup days
sessions: sessions:
logged_in: Logged in! logged_in: Logged in!
logged_out: Logged out! logged_out: Logged out!

View file

@ -24,6 +24,7 @@ SimpleNavigation::Configuration.run do |navigation|
subnav.item :ordering, I18n.t('navigation.orders.ordering'), group_orders_path subnav.item :ordering, I18n.t('navigation.orders.ordering'), group_orders_path
subnav.item :ordering_archive, I18n.t('navigation.orders.archive'), archive_group_orders_path subnav.item :ordering_archive, I18n.t('navigation.orders.archive'), archive_group_orders_path
subnav.item :orders, I18n.t('navigation.orders.manage'), orders_path, if: Proc.new { current_user.role_orders? } subnav.item :orders, I18n.t('navigation.orders.manage'), orders_path, if: Proc.new { current_user.role_orders? }
subnav.item :pickups, I18n.t('navigation.orders.pickups'), pickups_path, if: Proc.new { current_user.role_orders? }
end end
primary.item :articles, I18n.t('navigation.articles.title'), '#', primary.item :articles, I18n.t('navigation.articles.title'), '#',

View file

@ -51,6 +51,10 @@ Foodsoft::Application.routes.draw do
resources :order_articles resources :order_articles
end end
resources :pickups, only: [:index] do
post :document, on: :collection
end
resources :group_orders do resources :group_orders do
get :archive, on: :collection get :archive, on: :collection
end end

View file

@ -85,7 +85,7 @@ class RenderPDF < Prawn::Document
} }
) )
header = title header = options[:title] || title
footer = I18n.l(Time.now, format: :long) footer = I18n.l(Time.now, format: :long)
header_size = 0 header_size = 0