Add transport costs to Order
This commit is contained in:
parent
8cb70d819e
commit
4c567fece1
16 changed files with 141 additions and 6 deletions
|
@ -60,6 +60,19 @@ class Finance::BalancingController < Finance::BaseController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit_transport
|
||||||
|
@order = Order.find(params[:id])
|
||||||
|
render :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_transport
|
||||||
|
@order = Order.find(params[:id])
|
||||||
|
@order.update_attributes! params[:order]
|
||||||
|
redirect_to new_finance_order_path(order_id: @order.id)
|
||||||
|
rescue => error
|
||||||
|
redirect_to new_finance_order_path(order_id: @order.id), alert: t('errors.general_msg', msg: error.message)
|
||||||
|
end
|
||||||
|
|
||||||
# before the order will booked, a view lists all Ordergroups and its order_prices
|
# before the order will booked, a view lists all Ordergroups and its order_prices
|
||||||
def confirm
|
def confirm
|
||||||
@order = Order.find(params[:id])
|
@order = Order.find(params[:id])
|
||||||
|
|
|
@ -94,4 +94,9 @@ class GroupOrder < ApplicationRecord
|
||||||
ordergroup ? ordergroup.name : I18n.t('model.group_order.stock_ordergroup_name', :user => updated_by.try(:name) || '?')
|
ordergroup ? ordergroup.name : I18n.t('model.group_order.stock_ordergroup_name', :user => updated_by.try(:name) || '?')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def total
|
||||||
|
return price + transport if transport
|
||||||
|
price
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
#
|
#
|
||||||
class Order < ApplicationRecord
|
class Order < ApplicationRecord
|
||||||
attr_accessor :ignore_warnings
|
attr_accessor :ignore_warnings, :transport_distribution
|
||||||
|
|
||||||
# Associations
|
# Associations
|
||||||
has_many :order_articles, :dependent => :destroy
|
has_many :order_articles, :dependent => :destroy
|
||||||
|
@ -17,6 +17,7 @@ class Order < ApplicationRecord
|
||||||
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
|
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
|
||||||
|
|
||||||
enum end_action: { no_end_action: 0, auto_close: 1, auto_close_and_send: 2, auto_close_and_send_min_quantity: 3 }
|
enum end_action: { no_end_action: 0, auto_close: 1, auto_close_and_send: 2, auto_close_and_send_min_quantity: 3 }
|
||||||
|
enum transport_distribution: [:skip, :ordergroup, :price, :articles]
|
||||||
|
|
||||||
# Validations
|
# Validations
|
||||||
validates_presence_of :starts
|
validates_presence_of :starts
|
||||||
|
@ -25,6 +26,7 @@ class Order < ApplicationRecord
|
||||||
|
|
||||||
# Callbacks
|
# Callbacks
|
||||||
after_save :save_order_articles, :update_price_of_group_orders
|
after_save :save_order_articles, :update_price_of_group_orders
|
||||||
|
before_validation :distribute_transport
|
||||||
|
|
||||||
# Finders
|
# Finders
|
||||||
scope :started, -> { where('starts <= ?', Time.now) }
|
scope :started, -> { where('starts <= ?', Time.now) }
|
||||||
|
@ -258,7 +260,7 @@ class Order < ApplicationRecord
|
||||||
transaction do # Start updating account balances
|
transaction do # Start updating account balances
|
||||||
for group_order in gos
|
for group_order in gos
|
||||||
if group_order.ordergroup
|
if group_order.ordergroup
|
||||||
price = group_order.price * -1 # decrease! account balance
|
price = group_order.total * -1 # decrease! account balance
|
||||||
group_order.ordergroup.add_financial_transaction!(price, transaction_note, user, transaction_type, nil, group_order)
|
group_order.ordergroup.add_financial_transaction!(price, transaction_note, user, transaction_type, nil, group_order)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -347,6 +349,27 @@ class Order < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def distribute_transport
|
||||||
|
return unless group_orders.any?
|
||||||
|
case transport_distribution.try(&:to_i)
|
||||||
|
when Order.transport_distributions[:ordergroup] then
|
||||||
|
amount = transport / group_orders.size
|
||||||
|
group_orders.each do |go|
|
||||||
|
go.transport = amount.ceil(2)
|
||||||
|
end
|
||||||
|
when Order.transport_distributions[:price] then
|
||||||
|
amount = transport / group_orders.sum(:price)
|
||||||
|
group_orders.each do |go|
|
||||||
|
go.transport = (amount * go.price).ceil(2)
|
||||||
|
end
|
||||||
|
when Order.transport_distributions[:articles] then
|
||||||
|
amount = transport / group_orders.includes(:group_order_articles).sum(:result)
|
||||||
|
group_orders.each do |go|
|
||||||
|
go.transport = (amount * go.group_order_articles.sum(:result)).ceil(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Updates the "price" attribute of GroupOrders or GroupOrderResults
|
# Updates the "price" attribute of GroupOrders or GroupOrderResults
|
||||||
# This will be either the maximum value of a current order or the actual order value of a finished order.
|
# This will be either the maximum value of a current order or the actual order value of a finished order.
|
||||||
def update_price_of_group_orders
|
def update_price_of_group_orders
|
||||||
|
|
|
@ -36,8 +36,15 @@
|
||||||
%th= heading_helper Article, :tax
|
%th= heading_helper Article, :tax
|
||||||
%th= heading_helper Article, :deposit
|
%th= heading_helper Article, :deposit
|
||||||
%th{:colspan => "2"}
|
%th{:colspan => "2"}
|
||||||
= link_to t('.add_article'), new_order_order_article_path(@order), remote: true,
|
- unless @order.closed?
|
||||||
class: 'btn btn-small' unless @order.closed?
|
.btn-group
|
||||||
|
= link_to t('.add_article'), new_order_order_article_path(@order), remote: true,
|
||||||
|
class: 'btn btn-small'
|
||||||
|
= link_to '#', data: {toggle: 'dropdown'}, class: 'btn btn-small dropdown-toggle' do
|
||||||
|
%span.caret
|
||||||
|
%ul.dropdown-menu
|
||||||
|
%li= link_to t('.add_article'), new_order_order_article_path(@order), remote: true
|
||||||
|
%li= link_to t('.edit_transport'), edit_transport_finance_order_path(@order), remote: true
|
||||||
%tbody.list#result_table
|
%tbody.list#result_table
|
||||||
- for order_article in @articles.select { |oa| oa.units > 0 }
|
- for order_article in @articles.select { |oa| oa.units > 0 }
|
||||||
= render :partial => "order_article_result", :locals => {:order_article => order_article}
|
= render :partial => "order_article_result", :locals => {:order_article => order_article}
|
||||||
|
@ -47,3 +54,10 @@
|
||||||
|
|
||||||
- for order_article in @articles.select { |oa| oa.units == 0 }
|
- for order_article in @articles.select { |oa| oa.units == 0 }
|
||||||
= render :partial => "order_article_result", :locals => {:order_article => order_article}
|
= render :partial => "order_article_result", :locals => {:order_article => order_article}
|
||||||
|
|
||||||
|
- if @order.transport
|
||||||
|
%tr
|
||||||
|
%td{ colspan: 5 }= heading_helper Order, :transport
|
||||||
|
%td{ colspan: 3, data: {value: @order.transport} }= number_to_currency(@order.transport)
|
||||||
|
%td= link_to t('ui.edit'), edit_transport_finance_order_path(@order), remote: true,
|
||||||
|
class: 'btn btn-mini' unless order_article.order.closed?
|
||||||
|
|
11
app/views/finance/balancing/_edit_transport.html.haml
Normal file
11
app/views/finance/balancing/_edit_transport.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
= simple_form_for @order, url: update_transport_finance_order_path(@order), method: :put do |f|
|
||||||
|
.modal-header
|
||||||
|
= close_button :modal
|
||||||
|
%h3= t('.title')
|
||||||
|
.modal-body
|
||||||
|
= f.input :transport
|
||||||
|
= f.input :transport_distribution, as: :radio_buttons, collection: Order.transport_distributions,
|
||||||
|
include_blank: false, label_method: ->(k){ t("activerecord.attributes.order.transport_distributions.#{k.first}") }
|
||||||
|
.modal-footer
|
||||||
|
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
||||||
|
= f.submit t('ui.save'), class: 'btn btn-primary'
|
|
@ -8,7 +8,7 @@
|
||||||
- for group_order in @order.group_orders
|
- for group_order in @order.group_orders
|
||||||
%tr{:class => cycle('even', 'odd')}
|
%tr{:class => cycle('even', 'odd')}
|
||||||
%td= group_order.ordergroup_name
|
%td= group_order.ordergroup_name
|
||||||
%td.numeric= number_to_currency(group_order.price)
|
%td.numeric= number_to_currency(group_order.total)
|
||||||
.form-actions
|
.form-actions
|
||||||
= submit_tag t('.clear'), class: 'btn btn-primary'
|
= submit_tag t('.clear'), class: 'btn btn-primary'
|
||||||
= link_to t('.or_cancel'), new_finance_order_path(order_id: @order.id)
|
= link_to t('.or_cancel'), new_finance_order_path(order_id: @order.id)
|
||||||
|
|
2
app/views/finance/balancing/edit_transport.js.haml
Normal file
2
app/views/finance/balancing/edit_transport.js.haml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
$('#modalContainer').html('#{j(render("edit_transport"))}');
|
||||||
|
$('#modalContainer').modal();
|
|
@ -24,6 +24,11 @@
|
||||||
= number_to_currency(@group_order.price)
|
= number_to_currency(@group_order.price)
|
||||||
- else
|
- else
|
||||||
= t '.not_ordered'
|
= t '.not_ordered'
|
||||||
|
- if @group_order && @group_order.transport
|
||||||
|
%dt= heading_helper GroupOrder, :transport
|
||||||
|
%dd= number_to_currency(@group_order.transport)
|
||||||
|
%dt= heading_helper GroupOrder, :total
|
||||||
|
%dd= number_to_currency(@group_order.total)
|
||||||
- if @order.closed?
|
- if @order.closed?
|
||||||
%dt= heading_helper Order, :closed_by
|
%dt= heading_helper Order, :closed_by
|
||||||
%dd= show_user_link @order.updated_by
|
%dd= show_user_link @order.updated_by
|
||||||
|
@ -83,6 +88,13 @@
|
||||||
%tr{class: cycle('even', 'odd', name: 'articles')}
|
%tr{class: cycle('even', 'odd', name: 'articles')}
|
||||||
%th{colspan: "5"}= heading_helper GroupOrder, :price
|
%th{colspan: "5"}= heading_helper GroupOrder, :price
|
||||||
%th= number_to_currency(@group_order.price)
|
%th= number_to_currency(@group_order.price)
|
||||||
|
- if @group_order.transport
|
||||||
|
%tr{class: cycle('even', 'odd', name: 'articles')}
|
||||||
|
%td{colspan: "5"}= heading_helper GroupOrder, :transport
|
||||||
|
%td= number_to_currency(@group_order.transport)
|
||||||
|
%tr{class: cycle('even', 'odd', name: 'articles')}
|
||||||
|
%th{colspan: "5"}= heading_helper GroupOrder, :total
|
||||||
|
%th= number_to_currency(@group_order.total)
|
||||||
%br/
|
%br/
|
||||||
= link_to_top
|
= link_to_top
|
||||||
- else
|
- else
|
||||||
|
|
|
@ -12,3 +12,13 @@
|
||||||
= render 'shared/articles_by/article_single', order_article: order_article
|
= render 'shared/articles_by/article_single', order_article: order_article
|
||||||
%tr
|
%tr
|
||||||
%td{colspan: 4}
|
%td{colspan: 4}
|
||||||
|
- if order.transport
|
||||||
|
%tbody
|
||||||
|
%tr.list-heading
|
||||||
|
%th{colspan: 4}>
|
||||||
|
%h4.name.pull-left= heading_helper GroupOrder, :transport
|
||||||
|
- for go in order.group_orders
|
||||||
|
- if go.transport
|
||||||
|
%tr
|
||||||
|
%td{colspan: 3, style: 'width:70%'}= go.ordergroup_name
|
||||||
|
%td= number_to_currency(go.transport)
|
||||||
|
|
|
@ -27,4 +27,11 @@
|
||||||
el_price_sum.text(I18n.l('currency', new_price_sum));
|
el_price_sum.text(I18n.l('currency', new_price_sum));
|
||||||
el_price_sum.data('value', new_price_sum);
|
el_price_sum.data('value', new_price_sum);
|
||||||
}
|
}
|
||||||
|
var el_total = $('.total', el_sum);
|
||||||
|
if (el_total.length) {
|
||||||
|
var old_total = el_total.data('value');
|
||||||
|
var new_total = old_total - old_price + e.group_order_article_price;
|
||||||
|
el_total.text(I18n.l('currency', new_total));
|
||||||
|
el_total.data('value', new_total);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,8 +8,16 @@
|
||||||
- total += goa.total_price
|
- total += goa.total_price
|
||||||
= render 'shared/articles_by/group_single_goa', goa: goa
|
= render 'shared/articles_by/group_single_goa', goa: goa
|
||||||
%tr{class: cycle('even', 'odd', :name => 'articles')}
|
%tr{class: cycle('even', 'odd', :name => 'articles')}
|
||||||
%th{colspan: 7}= t 'shared.articles_by.price_sum'
|
%th{colspan: 7}= heading_helper GroupOrder, :price
|
||||||
%th.price_sum{colspan: 2, data: {value: total}}= number_to_currency(total)
|
%th.price_sum{colspan: 2, data: {value: total}}= number_to_currency(total)
|
||||||
|
- if group_order.transport
|
||||||
|
- total += group_order.transport
|
||||||
|
%tr{class: cycle('even', 'odd', :name => 'articles')}
|
||||||
|
%td{colspan: 7}= heading_helper GroupOrder, :transport
|
||||||
|
%td{colspan: 2}= number_to_currency(group_order.transport)
|
||||||
|
%tr{class: cycle('even', 'odd', :name => 'articles')}
|
||||||
|
%th{colspan: 7}= heading_helper GroupOrder, :total
|
||||||
|
%th.total{colspan: 2, data: {value: total}}= number_to_currency(total)
|
||||||
%tr
|
%tr
|
||||||
%th{colspan: 9}
|
%th{colspan: 9}
|
||||||
- reset_cycle("articles")
|
- reset_cycle("articles")
|
||||||
|
|
|
@ -113,6 +113,13 @@ de:
|
||||||
pickup: Abholung
|
pickup: Abholung
|
||||||
starts: Läuft vom
|
starts: Läuft vom
|
||||||
supplier: Lieferant
|
supplier: Lieferant
|
||||||
|
transport: Transportkosten
|
||||||
|
transport_distribution: Transportkostenverteilung
|
||||||
|
transport_distributions:
|
||||||
|
articles: Kosten anhand der Anzahl an erhaltenen Artiklen verteilen
|
||||||
|
ordergroup: Jede Bestellgruppe zahlt gleich viel
|
||||||
|
price: Kosten anhand der Bestellsumme aufteilen
|
||||||
|
skip: Kosten nicht auf die Bestellgruppen aufteilen
|
||||||
updated_by: Zuletzt geändert von
|
updated_by: Zuletzt geändert von
|
||||||
order_article:
|
order_article:
|
||||||
article: Artikel
|
article: Artikel
|
||||||
|
@ -738,8 +745,11 @@ de:
|
||||||
edit_results_by_articles:
|
edit_results_by_articles:
|
||||||
add_article: Artikel hinzufügen
|
add_article: Artikel hinzufügen
|
||||||
amount: Menge
|
amount: Menge
|
||||||
|
edit_transport: Transportkosten bearbeiten
|
||||||
gross: Brutto
|
gross: Brutto
|
||||||
net: Netto
|
net: Netto
|
||||||
|
edit_transport:
|
||||||
|
title: Transportkosten verteilen
|
||||||
group_order_articles:
|
group_order_articles:
|
||||||
add_group: Gruppe hinzufügen
|
add_group: Gruppe hinzufügen
|
||||||
total: Gesamtpreis
|
total: Gesamtpreis
|
||||||
|
|
|
@ -121,6 +121,13 @@ en:
|
||||||
starts: Starts at
|
starts: Starts at
|
||||||
status: Status
|
status: Status
|
||||||
supplier: Supplier
|
supplier: Supplier
|
||||||
|
transport: Transport costs
|
||||||
|
transport_distribution: Transport costs distribution
|
||||||
|
transport_distributions:
|
||||||
|
articles: Distribute the costs among the number of received articles
|
||||||
|
ordergroup: Every ordergroup pays the same amount
|
||||||
|
price: Distribute the costs among the order sum
|
||||||
|
skip: Do not distribute the costs
|
||||||
updated_by: Last edited by
|
updated_by: Last edited by
|
||||||
order_article:
|
order_article:
|
||||||
article: Article
|
article: Article
|
||||||
|
@ -761,8 +768,11 @@ en:
|
||||||
edit_results_by_articles:
|
edit_results_by_articles:
|
||||||
add_article: Add article
|
add_article: Add article
|
||||||
amount: Amount
|
amount: Amount
|
||||||
|
edit_transport: Edit transport
|
||||||
gross: Gross
|
gross: Gross
|
||||||
net: Net
|
net: Net
|
||||||
|
edit_transport:
|
||||||
|
title: Distribute transport costs
|
||||||
group_order_articles:
|
group_order_articles:
|
||||||
add_group: Add group
|
add_group: Add group
|
||||||
total: Total costs
|
total: Total costs
|
||||||
|
|
|
@ -154,6 +154,8 @@ Foodsoft::Application.routes.draw do
|
||||||
get :update_summary
|
get :update_summary
|
||||||
get :edit_note
|
get :edit_note
|
||||||
put :update_note
|
put :update_note
|
||||||
|
get :edit_transport
|
||||||
|
put :update_transport
|
||||||
|
|
||||||
get :confirm
|
get :confirm
|
||||||
post :close
|
post :close
|
||||||
|
|
6
db/migrate/20181201000220_add_transport_to_order.rb
Normal file
6
db/migrate/20181201000220_add_transport_to_order.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class AddTransportToOrder < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :orders, :transport, :decimal, precision: 8, scale: 2
|
||||||
|
add_column :group_orders, :transport, :decimal, precision: 8, scale: 2
|
||||||
|
end
|
||||||
|
end
|
|
@ -174,6 +174,7 @@ ActiveRecord::Schema.define(version: 20181205010000) do
|
||||||
t.integer "lock_version", limit: 4, default: 0, null: false
|
t.integer "lock_version", limit: 4, default: 0, null: false
|
||||||
t.datetime "updated_on", null: false
|
t.datetime "updated_on", null: false
|
||||||
t.integer "updated_by_user_id", limit: 4
|
t.integer "updated_by_user_id", limit: 4
|
||||||
|
t.decimal "transport", precision: 8, scale: 2
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "group_orders", ["order_id"], name: "index_group_orders_on_order_id", using: :btree
|
add_index "group_orders", ["order_id"], name: "index_group_orders_on_order_id", using: :btree
|
||||||
|
@ -362,6 +363,7 @@ ActiveRecord::Schema.define(version: 20181205010000) do
|
||||||
t.date "pickup"
|
t.date "pickup"
|
||||||
t.datetime "last_sent_mail"
|
t.datetime "last_sent_mail"
|
||||||
t.integer "end_action", limit: 4, default: 0, null: false
|
t.integer "end_action", limit: 4, default: 0, null: false
|
||||||
|
t.decimal "transport", precision: 8, scale: 2
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "orders", ["state"], name: "index_orders_on_state", using: :btree
|
add_index "orders", ["state"], name: "index_orders_on_state", using: :btree
|
||||||
|
|
Loading…
Reference in a new issue