Compare commits
No commits in common. "0ae1d6551e071d7ee52c6109c0e385f7044e7a75" and "f9229034de1e6a06858f8555445d1066c5ad2966" have entirely different histories.
0ae1d6551e
...
f9229034de
14 changed files with 33 additions and 75 deletions
2
Gemfile
2
Gemfile
|
@ -23,7 +23,7 @@ gem 'bootsnap', require: false
|
|||
gem 'mysql2'
|
||||
gem 'prawn'
|
||||
gem 'prawn-table'
|
||||
gem 'haml', '~> 5.0'
|
||||
gem 'haml'
|
||||
gem 'haml-rails'
|
||||
gem 'kaminari'
|
||||
gem 'simple_form'
|
||||
|
|
|
@ -241,8 +241,9 @@ GEM
|
|||
rails (>= 4.0.0)
|
||||
globalid (1.0.0)
|
||||
activesupport (>= 5.0)
|
||||
haml (5.2.2)
|
||||
temple (>= 0.8.0)
|
||||
haml (6.1.1)
|
||||
temple (>= 0.8.2)
|
||||
thor
|
||||
tilt
|
||||
haml-rails (2.1.0)
|
||||
actionpack (>= 5.1)
|
||||
|
@ -632,7 +633,7 @@ DEPENDENCIES
|
|||
foodsoft_polls!
|
||||
foodsoft_wiki!
|
||||
gaffe
|
||||
haml (~> 5.0)
|
||||
haml
|
||||
haml-rails
|
||||
hashie (~> 3.4.6)
|
||||
i18n-js (~> 3.0.0.rc8)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
OrdersController.class_eval do
|
||||
class OrdersController < ApplicationController
|
||||
# Send a order to the supplier.
|
||||
def send_result_to_supplier
|
||||
order = Order.find(params[:id])
|
||||
options = { file_formats: params[:file_formats] }
|
||||
order.send_to_supplier!(@current_user, options)
|
||||
redirect_to order_path(order), notice: I18n.t('orders.send_to_supplier.notice')
|
||||
# rescue => error
|
||||
# redirect_to order, alert: I18n.t('errors.general_msg', :msg => error.message)
|
||||
redirect_to order, notice: I18n.t('orders.send_to_supplier.notice')
|
||||
rescue => error
|
||||
redirect_to order, alert: I18n.t('errors.general_msg', :msg => error.message)
|
||||
end
|
||||
|
||||
def send_result_to_supplier_modal
|
||||
@order = Order.find(params[:id])
|
||||
end
|
8
plugins/bnn_upload/app/mailers/mailer.rb
Normal file
8
plugins/bnn_upload/app/mailers/mailer.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class Mailer
|
||||
# attaches files to mail sent to supplier
|
||||
def add_order_result_attachments(order, options = {})
|
||||
attachments['order.pdf'] = OrderFax.new(order, options).to_pdf if options[:file_formats][:pdf].present?
|
||||
attachments['order.csv'] = OrderCsv.new(order, options).to_csv if options[:file_formats][:csv].present?
|
||||
attachments['order.bnn'] = OrderBnn.new(order, options).to_bnn if options[:file_formats][:bnn].present?
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
Order.class_eval do
|
||||
class Order
|
||||
def send_to_supplier!(user, options = {})
|
||||
Mailer.deliver_now_with_default_locale do
|
||||
Mailer.order_result_supplier(user, self, options)
|
|
@ -1,8 +0,0 @@
|
|||
Mailer.class_eval do
|
||||
require 'foodsoft_bnn_upload/order_bnn'
|
||||
def add_order_result_attachments(order, options = {})
|
||||
# attachments['order.pdf'] = ::OrderFax.new(order, options).to_pdf if options[:file_formats][:pdf].present?
|
||||
# attachments['order.csv'] = ::OrderCsv.new(order, options).to_csv if options[:file_formats][:csv].present?
|
||||
attachments['order.bnn'] = FoodsoftBnnUpload::OrderBnn.new(order, options).to_csv if options[:file_formats][:bnn].present?
|
||||
end
|
||||
end
|
|
@ -1,3 +1,6 @@
|
|||
/ replace 'erb:contains("send_to_supplier")'
|
||||
/ replace 'erb:contains("send_result_to_supplier")'
|
||||
- if FoodsoftBnnUpload.enabled?
|
||||
= link_to t('.send_to_supplier'), order_send_result_to_supplier_modal_path(@order), class: 'btn btn-primary', remote: true
|
||||
- raise
|
||||
= link_to t('.send_to_supplier'), send_result_to_supplier_modal_order_path(@order), remote: true,
|
||||
class: "btn#{' btn-primary' unless @order.last_sent_mail}",
|
||||
data: {confirm: @order.last_sent_mail && t('.confirm_send_to_supplier', when: format_time(@order.last_sent_mail)) }
|
|
@ -5,10 +5,8 @@
|
|||
.modal-body
|
||||
= f.check_box 'file_formats[pdf]'
|
||||
= f.label 'file_formats[pdf]', "PDF"
|
||||
= f.check_box 'file_formats[csv]'
|
||||
= f.label 'file_formats[csv]', "CSV"
|
||||
= f.check_box 'file_formats[bnn]'
|
||||
= f.label 'file_formats[bnn]', "BNN"
|
||||
.modal-footer
|
||||
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
||||
= f.submit class: 'btn btn-primary'
|
||||
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
$('#modalContainer').html('#{escape_javascript(render("send_result_to_supplier_modal"))}');
|
||||
$('#modalContainer').html('#{j(render("send_to_supplier_modal"))}');
|
||||
$('#modalContainer').modal();
|
||||
$('#modalContainer').submit(function() {$('#modalContainer').modal('hide');});
|
|
@ -1,6 +1,5 @@
|
|||
Rails.application.routes.draw do
|
||||
scope '/:foodcoop' do
|
||||
get '/order/:id/send_result_to_supplier_modal', controller: 'orders', action: :send_result_to_supplier_modal, as: :order_send_result_to_supplier_modal
|
||||
post '/order/:id/send_result_to_supplier', controller: 'orders', action: :send_result_to_supplier, as: :send_result_to_supplier
|
||||
get '/order/send_result_to_supplier_modal' => 'orders#send_result_to_supplier_modal'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require "deface"
|
||||
require 'foodsoft_bnn_upload/engine'
|
||||
|
||||
module FoodsoftBnnUpload
|
||||
def self.enabled?
|
||||
FoodsoftConfig[:use_bnn_upload]
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
module FoodsoftBnnUpload
|
||||
class Engine < ::Rails::Engine
|
||||
config.to_prepare do
|
||||
Dir.glob(Rails.root + "app/decorators/**/*_decorator*.rb").each do |c|
|
||||
require_dependency(c)
|
||||
end
|
||||
end
|
||||
def default_foodsoft_config(cfg)
|
||||
cfg[:use_bnn_upload] = true
|
||||
end
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
module FoodsoftBnnUpload
|
||||
class OrderBnn < RenderCsv
|
||||
def initialize(object, options = {})
|
||||
super
|
||||
@options[:col_sep] = ""
|
||||
@options[:row_sep] = "\n"
|
||||
@options[:encoding] = 'IBM850'
|
||||
end
|
||||
|
||||
def header
|
||||
customer_id = "000001"
|
||||
delivery_date = Time.zone.now.strftime("%y%m%d")
|
||||
pickup = " "
|
||||
|
||||
["D##{customer_id}#{delivery_date}#{pickup}#{@object.id}"]
|
||||
end
|
||||
|
||||
def data
|
||||
@object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa|
|
||||
yield [
|
||||
pad_to_length(oa.article.order_number, 13),
|
||||
"+",
|
||||
pad_float_values(oa.units_to_order),
|
||||
pad_to_length(oa.article.name, 30),
|
||||
pad_float_values(oa.article.unit_quantity),
|
||||
pad_to_length(oa.article.unit, 14),
|
||||
pad_to_length(oa.article.manufacturer, 3),
|
||||
pad_to_length("", 26)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def pad_float_values(number, digits_before=4, digits_after=3)
|
||||
format_string = "%0#{digits_before + digits_after}d"
|
||||
formatted_number = sprintf(format_string, (number * 10 ** digits_after).to_i)
|
||||
end
|
||||
|
||||
def pad_to_length(string, length)
|
||||
string.to_s.rjust(length, " ")[0, length]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
/ insert_after 'erb:contains("title t(\'.title\'")'
|
||||
- content_for :actionbar do
|
||||
- if FoodsoftMessages.enabled?
|
||||
= link_to_new_message message_params: {order_id: @order.id}
|
Loading…
Reference in a new issue