foodsoft/app/documents/order_fax.rb

107 lines
3.5 KiB
Ruby
Raw Normal View History

class OrderFax < OrderPdf
2016-06-04 21:58:37 +02:00
BATCH_SIZE = 250
def filename
I18n.t('documents.order_fax.filename', name: order.name, date: order.ends.to_date) + '.pdf'
end
def title
false
end
def body
contact = FoodsoftConfig[:contact].symbolize_keys
# From paragraph
bounding_box [margin_box.right - 200, margin_box.top], width: 200 do
2014-03-19 14:01:51 +01:00
text FoodsoftConfig[:name], size: fontsize(9), align: :right
move_down 5
2014-03-19 14:01:51 +01:00
text contact[:street], size: fontsize(9), align: :right
move_down 5
2014-03-19 14:01:51 +01:00
text "#{contact[:zip_code]} #{contact[:city]}", size: fontsize(9), align: :right
2013-01-30 19:46:18 +01:00
move_down 5
if order.supplier.try(:customer_number).present?
text "#{Supplier.human_attribute_name :customer_number}: #{order.supplier[:customer_number]}",
size: fontsize(9), align: :right
move_down 5
end
if contact[:phone].present?
2014-03-19 14:01:51 +01:00
text "#{Supplier.human_attribute_name :phone}: #{contact[:phone]}", size: fontsize(9), align: :right
move_down 5
end
if contact[:email].present?
text "#{Supplier.human_attribute_name :email}: #{contact[:email]}", size: fontsize(9),
align: :right
end
end
# Recipient
bounding_box [margin_box.left, margin_box.top - 60], width: 200 do
2016-06-04 21:58:37 +02:00
text order.name
move_down 5
2016-06-04 21:58:37 +02:00
text order.supplier.try(:address).to_s
if order.supplier.try(:fax).present?
move_down 5
2016-06-04 21:58:37 +02:00
text "#{Supplier.human_attribute_name :fax}: #{order.supplier[:fax]}"
end
end
2013-01-30 19:46:18 +01:00
move_down 5
2013-04-04 02:04:31 +02:00
text Date.today.strftime(I18n.t('date.formats.default')), align: :right
move_down 10
text "#{Delivery.human_attribute_name :date}:"
move_down 10
if order.supplier.try(:contact_person).present?
2016-06-04 21:58:37 +02:00
text "#{Supplier.human_attribute_name :contact_person}: #{order.supplier[:contact_person]}"
move_down 10
end
# Articles
total = 0
2013-04-04 02:04:31 +02:00
data = [I18n.t('documents.order_fax.rows')]
2016-06-04 21:58:37 +02:00
each_order_article do |oa|
subtotal = oa.units_to_order * oa.price.unit_quantity * oa.price.price
total += subtotal
2016-06-04 21:58:37 +02:00
data << [oa.article.order_number,
oa.units_to_order,
oa.article.name,
oa.price.unit_quantity,
oa.article.unit,
number_to_currency(oa.price.price),
number_to_currency(subtotal)]
end
data << [I18n.t('documents.order_fax.total'), nil, nil, nil, nil, nil, number_to_currency(total)]
table data, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table|
table.header = true
table.cells.border_width = 1
table.cells.border_color = '666666'
table.row(0).border_bottom_width = 2
table.columns(1).align = :right
table.columns(3..6).align = :right
table.row(data.length - 1).columns(0..5).borders = %i[top bottom]
table.row(data.length - 1).columns(0).borders = %i[top bottom left]
table.row(data.length - 1).border_top_width = 2
end
# font_size: fontsize(8),
# vertical_padding: 3,
# border_style: :grid,
# headers: ["BestellNr.", "Menge","Name", "Gebinde", "Einheit","Preis/Einheit"],
# align: {0 => :left}
end
2016-06-04 21:58:37 +02:00
private
def order_articles
order.order_articles.ordered
.joins(:article)
.order('articles.order_number').order('articles.name')
.preload(:article, :article_price)
2016-06-04 21:58:37 +02:00
end
def each_order_article(&block)
order_articles.find_each_with_order(batch_size: BATCH_SIZE, &block)
2016-06-04 21:58:37 +02:00
end
2013-01-30 19:46:18 +01:00
end