move receive screen to orders
This commit is contained in:
parent
94b4454a1b
commit
d299fa4870
10 changed files with 75 additions and 79 deletions
|
@ -1,56 +0,0 @@
|
||||||
class Finance::ReceiveController < Finance::BaseController
|
|
||||||
|
|
||||||
def edit
|
|
||||||
@order = Order.find(params[:id])
|
|
||||||
@order_articles = @order.order_articles.ordered.includes(:article)
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
# where to leave remainder during redistribution
|
|
||||||
rest_to = []
|
|
||||||
rest_to << :tolerance if params[:rest_to_tolerance]
|
|
||||||
rest_to << :stock if params[:rest_to_stock]
|
|
||||||
rest_to << nil
|
|
||||||
# count what happens to the articles
|
|
||||||
counts = [0] * (rest_to.length+2)
|
|
||||||
cunits = [0] * (rest_to.length+2)
|
|
||||||
OrderArticle.transaction do
|
|
||||||
params[:order_articles].each do |oa_id, oa_params|
|
|
||||||
unless oa_params.blank?
|
|
||||||
oa = OrderArticle.find(oa_id)
|
|
||||||
# update attributes; don't use update_attribute because it calls save
|
|
||||||
# which makes received_changed? not work anymore
|
|
||||||
oa.attributes = oa_params
|
|
||||||
counts[0] += 1 if oa.units_received_changed?
|
|
||||||
cunits[0] += oa.units_received * oa.article.unit_quantity
|
|
||||||
unless oa.units_received.blank?
|
|
||||||
oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to
|
|
||||||
oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 }
|
|
||||||
end
|
|
||||||
oa.save!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
#flash[:notice] = I18n.t('finance.receive.update.notice')
|
|
||||||
notice = "Order received:"
|
|
||||||
notice += " #{counts.shift} articles (#{cunits.shift} units) updated"
|
|
||||||
notice += ", #{counts.shift} (#{cunits.shift}) using tolerance" if params[:rest_to_tolerance]
|
|
||||||
notice += ", #{counts.shift} (#{cunits.shift}) go to stock if foodsoft would support that" if params[:rest_to_stock]
|
|
||||||
notice += ", #{counts.shift} (#{cunits.shift}) left over"
|
|
||||||
flash[:notice] = notice
|
|
||||||
redirect_to finance_order_index_path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# ajax add article
|
|
||||||
def add_article
|
|
||||||
@order = Order.find(params[:receive_id])
|
|
||||||
@order_article = @order.order_articles.where(:article_id => params[:article_id]).includes(:article).first
|
|
||||||
# we need to create the order article if it's not part of the current order
|
|
||||||
if @order_article.nil?
|
|
||||||
@order_article = @order.order_articles.build({order: @order, article_id: params[:article_id]})
|
|
||||||
@order_article.save!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -106,6 +106,27 @@ class OrdersController < ApplicationController
|
||||||
redirect_to orders_url, alert: I18n.t('errors.general_msg', :msg => error.message)
|
redirect_to orders_url, alert: I18n.t('errors.general_msg', :msg => error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ajax add article
|
||||||
|
def add_article
|
||||||
|
@order = Order.find(params[:id])
|
||||||
|
@order_article = @order.order_articles.where(:article_id => params[:article_id]).includes(:article).first
|
||||||
|
# we need to create the order article if it's not part of the current order
|
||||||
|
if @order_article.nil?
|
||||||
|
@order_article = @order.order_articles.build({order: @order, article_id: params[:article_id]})
|
||||||
|
@order_article.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def receive
|
||||||
|
@order = Order.find(params[:id])
|
||||||
|
unless request.post?
|
||||||
|
@order_articles = @order.order_articles.ordered.includes(:article)
|
||||||
|
else
|
||||||
|
flash[:notice] = "Order received: " + update_order_amounts
|
||||||
|
redirect_to @order
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Renders the fax-text-file
|
# Renders the fax-text-file
|
||||||
|
@ -132,4 +153,37 @@ class OrdersController < ApplicationController
|
||||||
end
|
end
|
||||||
text
|
text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_order_amounts
|
||||||
|
# where to leave remainder during redistribution
|
||||||
|
rest_to = []
|
||||||
|
rest_to << :tolerance if params[:rest_to_tolerance]
|
||||||
|
rest_to << :stock if params[:rest_to_stock]
|
||||||
|
rest_to << nil
|
||||||
|
# count what happens to the articles
|
||||||
|
counts = [0] * (rest_to.length+2)
|
||||||
|
cunits = [0] * (rest_to.length+2)
|
||||||
|
OrderArticle.transaction do
|
||||||
|
params[:order_articles].each do |oa_id, oa_params|
|
||||||
|
unless oa_params.blank?
|
||||||
|
oa = OrderArticle.find(oa_id)
|
||||||
|
# update attributes; don't use update_attribute because it calls save
|
||||||
|
# which makes received_changed? not work anymore
|
||||||
|
oa.attributes = oa_params
|
||||||
|
counts[0] += 1 if oa.units_received_changed?
|
||||||
|
cunits[0] += oa.units_received * oa.article.unit_quantity
|
||||||
|
unless oa.units_received.blank?
|
||||||
|
oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to
|
||||||
|
oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 }
|
||||||
|
end
|
||||||
|
oa.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
notice = " #{counts.shift} articles (#{cunits.shift} units) updated"
|
||||||
|
notice += ", #{counts.shift} (#{cunits.shift}) using tolerance" if params[:rest_to_tolerance]
|
||||||
|
notice += ", #{counts.shift} (#{cunits.shift}) go to stock if foodsoft would support that" if params[:rest_to_stock]
|
||||||
|
notice += ", #{counts.shift} (#{cunits.shift}) left over"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
function init_add_article(sel) {
|
function init_add_article(sel) {
|
||||||
$(sel).removeAttr('disabled').select2({
|
$(sel).removeAttr('disabled').select2({
|
||||||
placeholder: '#{t '.add_article'}',
|
placeholder: '#{t 'orders.add_article.title'}',
|
||||||
data: new_article_data,
|
data: new_article_data,
|
||||||
// TODO implement adding a new article, like in deliveries
|
// TODO implement adding a new article, like in deliveries
|
||||||
}).on('change', function(e) {
|
}).on('change', function(e) {
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '#{finance_receive_add_article_path(@order)}',
|
url: '#{add_article_order_path(@order)}',
|
||||||
type: 'get',
|
type: 'get',
|
||||||
data: {article_id: selectedArticle.id},
|
data: {article_id: selectedArticle.id},
|
||||||
contentType: 'application/json; charset=UTF-8'
|
contentType: 'application/json; charset=UTF-8'
|
||||||
|
@ -71,8 +71,8 @@
|
||||||
%table.ordered-articles.table.table-striped.stupidtable
|
%table.ordered-articles.table.table-striped.stupidtable
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
%th.sort{:data => {:sort => 'string'}}= t('.number')
|
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true
|
||||||
%th.sort{:data => {:sort => 'string'}}= t('.article')
|
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :name
|
||||||
%th= heading_helper GroupOrderArticle, :units
|
%th= heading_helper GroupOrderArticle, :units
|
||||||
%th Members
|
%th Members
|
||||||
%th Ordered
|
%th Ordered
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
%th
|
%th
|
||||||
%tbody#result_table
|
%tbody#result_table
|
||||||
- @order_articles.each do |order_article|
|
- @order_articles.each do |order_article|
|
||||||
= render :partial => 'edit_article', :locals => {:order_article => order_article}
|
= render :partial => 'edit_amount', :locals => {:order_article => order_article}
|
||||||
%tfoot
|
%tfoot
|
||||||
%tr
|
%tr
|
||||||
%th{:colspan => 8}
|
%th{:colspan => 8}
|
|
@ -54,7 +54,7 @@
|
||||||
%td= truncate(order.note)
|
%td= truncate(order.note)
|
||||||
%td
|
%td
|
||||||
-# TODO btn-success class only if not received before
|
-# TODO btn-success class only if not received before
|
||||||
= link_to t('.receive'), edit_finance_receive_path(order), class: 'btn btn-small btn-success'
|
= link_to t('.receive'), receive_order_path(order), class: 'btn btn-small btn-success'
|
||||||
|
|
||||||
%td
|
%td
|
||||||
= link_to t('ui.edit'), '#', class: 'btn btn-small disabled'
|
= link_to t('ui.edit'), '#', class: 'btn btn-small disabled'
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
- title "Receiving #{@order.name}"
|
- title "Receiving #{@order.name}"
|
||||||
|
|
||||||
= form_tag(finance_receive_path(@order), :method => :put) do
|
= form_tag(receive_order_path(@order)) do
|
||||||
%section#results
|
%section#results
|
||||||
= render 'edit_articles'
|
= render 'edit_amounts'
|
||||||
|
|
||||||
.form-actions
|
.form-actions
|
||||||
.pull-left
|
.pull-left
|
||||||
|
@ -18,6 +18,6 @@
|
||||||
|
|
||||||
.pull-right
|
.pull-right
|
||||||
= submit_tag t('.submit'), class: 'btn btn-primary'
|
= submit_tag t('.submit'), class: 'btn btn-primary'
|
||||||
= link_to t('ui.or_cancel'), finance_order_index_path
|
= link_to t('ui.or_cancel'), order_path(@order)
|
||||||
|
|
||||||
%p= link_to_top
|
%p= link_to_top
|
|
@ -31,6 +31,9 @@
|
||||||
= link_to t('ui.edit'), edit_order_path(@order), class: 'btn'
|
= link_to t('ui.edit'), edit_order_path(@order), class: 'btn'
|
||||||
= link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success',
|
= link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success',
|
||||||
confirm: t('.confirm_end', order: @order.name)
|
confirm: t('.confirm_end', order: @order.name)
|
||||||
|
- elsif not @order.closed?
|
||||||
|
-# TODO btn-success class only if not received before
|
||||||
|
= link_to t('orders.index.receive'), receive_order_path(@order), class: 'btn btn-success'
|
||||||
- unless @order.closed?
|
- unless @order.closed?
|
||||||
= link_to t('ui.delete'), @order, confirm: t('.confirm_delete'), method: :delete,
|
= link_to t('ui.delete'), @order, confirm: t('.confirm_delete'), method: :delete,
|
||||||
class: 'btn btn-danger'
|
class: 'btn btn-danger'
|
||||||
|
|
|
@ -541,7 +541,6 @@ en:
|
||||||
last_edited_by: Last edited by
|
last_edited_by: Last edited by
|
||||||
name: Supplier
|
name: Supplier
|
||||||
no_closed_orders: At the moment there are no closed orders.
|
no_closed_orders: At the moment there are no closed orders.
|
||||||
receive: receive
|
|
||||||
state: State
|
state: State
|
||||||
summary:
|
summary:
|
||||||
changed: Data was changed!
|
changed: Data was changed!
|
||||||
|
@ -625,15 +624,6 @@ en:
|
||||||
ordergroups:
|
ordergroups:
|
||||||
account_statement: Account statement
|
account_statement: Account statement
|
||||||
new_transaction: New transaction
|
new_transaction: New transaction
|
||||||
receive:
|
|
||||||
add_article:
|
|
||||||
notice: Article "%{name}" was added to the order.
|
|
||||||
edit:
|
|
||||||
submit: Receive order
|
|
||||||
edit_articles:
|
|
||||||
add_article: Add article
|
|
||||||
update:
|
|
||||||
notice: Updated received article amounts for order
|
|
||||||
update:
|
update:
|
||||||
notice: Invoice was updated
|
notice: Invoice was updated
|
||||||
foodcoop:
|
foodcoop:
|
||||||
|
@ -1093,6 +1083,9 @@ en:
|
||||||
error_single_group: ! '%{user} is already a member of another ordergroup'
|
error_single_group: ! '%{user} is already a member of another ordergroup'
|
||||||
invalid_balance: is not a valid number
|
invalid_balance: is not a valid number
|
||||||
orders:
|
orders:
|
||||||
|
add_article:
|
||||||
|
title: Add article
|
||||||
|
notice: Article "%{name}" was added to the order.
|
||||||
articles:
|
articles:
|
||||||
article_count: ! 'Ordered articles:'
|
article_count: ! 'Ordered articles:'
|
||||||
prices: Net/gross price
|
prices: Net/gross price
|
||||||
|
@ -1138,6 +1131,8 @@ en:
|
||||||
warning_ordered_stock: ! 'Warning: Articles marked red have already been ordered/purchased within this open stock order. If you uncheck them here, all existing orders/purchases of these articles will be deleted and it will not be accounted for them.'
|
warning_ordered_stock: ! 'Warning: Articles marked red have already been ordered/purchased within this open stock order. If you uncheck them here, all existing orders/purchases of these articles will be deleted and it will not be accounted for them.'
|
||||||
new:
|
new:
|
||||||
title: Create new order
|
title: Create new order
|
||||||
|
receive:
|
||||||
|
submit: Receive order
|
||||||
show:
|
show:
|
||||||
action_end: Close!
|
action_end: Close!
|
||||||
amounts: ! 'Net/gross sum:'
|
amounts: ! 'Net/gross sum:'
|
||||||
|
|
|
@ -38,6 +38,10 @@ Foodsoft::Application.routes.draw do
|
||||||
member do
|
member do
|
||||||
post :finish
|
post :finish
|
||||||
post :add_comment
|
post :add_comment
|
||||||
|
|
||||||
|
get :receive
|
||||||
|
post :receive
|
||||||
|
get :add_article
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -146,10 +150,6 @@ Foodsoft::Application.routes.draw do
|
||||||
resources :order_articles
|
resources :order_articles
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :receive do
|
|
||||||
get :add_article
|
|
||||||
end
|
|
||||||
|
|
||||||
resources :group_order_articles do
|
resources :group_order_articles do
|
||||||
member do
|
member do
|
||||||
put :update_result
|
put :update_result
|
||||||
|
|
Loading…
Reference in a new issue