viehlieb
fb8ccfea4a
mv lib to app/lib due to upgrade removing concerns from autoload path resolve zeitwerk issues make foodsoft run for dev on rails 7 and ruby 2.7 fix mail file permission bug fix database_config fix articles controller test ActiveModell::Error bump Gemfile.lock
30 lines
1.4 KiB
Ruby
30 lines
1.4 KiB
Ruby
class OrderTxt
|
|
def initialize(order, _options = {})
|
|
@order = order
|
|
end
|
|
|
|
# Renders the fax-text-file
|
|
# e.g. for easier use with online-fax-software, which don't accept pdf-files
|
|
def to_txt
|
|
supplier = @order.supplier
|
|
contact = FoodsoftConfig[:contact].symbolize_keys
|
|
text = I18n.t('orders.fax.heading', :name => FoodsoftConfig[:name])
|
|
text += "\n#{Supplier.human_attribute_name(:customer_number)}: #{supplier.customer_number}" unless supplier.customer_number.blank?
|
|
text += "\n" + I18n.t('orders.fax.delivery_day')
|
|
text += "\n\n#{supplier.name}\n#{supplier.address}\n#{Supplier.human_attribute_name(:fax)}: #{supplier.fax}\n\n"
|
|
text += "****** " + I18n.t('orders.fax.to_address') + "\n\n"
|
|
text += "#{FoodsoftConfig[:name]}\n#{contact[:street]}\n#{contact[:zip_code]} #{contact[:city]}\n\n"
|
|
text += "****** " + I18n.t('orders.fax.articles') + "\n\n"
|
|
text += format("%8s %8s %s\n", I18n.t('orders.fax.number'), I18n.t('orders.fax.amount'), I18n.t('orders.fax.name'))
|
|
# now display all ordered articles
|
|
@order.order_articles.ordered.includes([:article, :article_price]).each do |oa|
|
|
text += format("%8s %8d %s\n", oa.article.order_number, oa.units_to_order.to_i, oa.article.name)
|
|
end
|
|
text
|
|
end
|
|
|
|
# Helper method to test pdf via rails console: OrderTxt.new(order).save_tmp
|
|
def save_tmp
|
|
File.write("#{Rails.root}/tmp/#{self.class.to_s.underscore}.txt", to_csv.force_encoding("UTF-8"))
|
|
end
|
|
end
|