Introduced group_order_article.result to save the result for each group/article.
This commit is contained in:
parent
6fd5d825f9
commit
251ced4fa1
27 changed files with 106 additions and 137 deletions
|
@ -111,10 +111,10 @@ class Finance::BalancingController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_group_order_article
|
def new_group_order_article
|
||||||
group_order_article = OrderArticle.find(params[:id]).group_order_articles.build
|
goa = OrderArticle.find(params[:id]).group_order_articles.build
|
||||||
render :update do |page|
|
render :update do |page|
|
||||||
page["edit_box"].replace_html :partial => "new_group_order_article",
|
page["edit_box"].replace_html :partial => "new_group_order_article",
|
||||||
:locals => {:group_order_article => group_order_article}
|
:locals => {:group_order_article => goa}
|
||||||
page["edit_box"].show
|
page["edit_box"].show
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -185,7 +185,6 @@ class Finance::BalancingController < ApplicationController
|
||||||
page["edit_box"].hide
|
page["edit_box"].hide
|
||||||
page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles',
|
page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles',
|
||||||
:locals => {:order_article => goa.order_article}
|
:locals => {:order_article => goa.order_article}
|
||||||
page["group_order_article_#{goa.id}"].visual_effect :highlight, :duration => 2
|
|
||||||
page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order}
|
page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order}
|
||||||
page["order_profit"].visual_effect :highlight, :duration => 2
|
page["order_profit"].visual_effect :highlight, :duration => 2
|
||||||
end
|
end
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Finance::TransactionsController < ApplicationController
|
||||||
amount = params[:financial_transaction][:amount]
|
amount = params[:financial_transaction][:amount]
|
||||||
note = params[:financial_transaction][:note]
|
note = params[:financial_transaction][:note]
|
||||||
begin
|
begin
|
||||||
@group.addFinancialTransaction(amount, note, @current_user)
|
@group.add_financial_transaction(amount, note, @current_user)
|
||||||
flash[:notice] = 'Transaktion erfolgreich angelegt.'
|
flash[:notice] = 'Transaktion erfolgreich angelegt.'
|
||||||
redirect_to :action => 'index'
|
redirect_to :action => 'index'
|
||||||
rescue => e
|
rescue => e
|
||||||
|
@ -90,7 +90,7 @@ class Finance::TransactionsController < ApplicationController
|
||||||
params[:financial_transactions].each do |trans|
|
params[:financial_transactions].each do |trans|
|
||||||
# ignore empty amount fields ...
|
# ignore empty amount fields ...
|
||||||
unless trans[:amount].blank?
|
unless trans[:amount].blank?
|
||||||
Ordergroup.find(trans[:ordergroup_id]).addFinancialTransaction trans[:amount], note, @current_user
|
Ordergroup.find(trans[:ordergroup_id]).add_financial_transaction trans[:amount], note, @current_user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
flash[:notice] = 'Saved all transactions successfully'
|
flash[:notice] = 'Saved all transactions successfully'
|
||||||
|
|
|
@ -16,18 +16,19 @@ class OrderingController < ApplicationController
|
||||||
@open_orders = Order.open
|
@open_orders = Order.open
|
||||||
@other_orders = @open_orders.reject{|order| order == @order}
|
@other_orders = @open_orders.reject{|order| order == @order}
|
||||||
# Load order article data...
|
# Load order article data...
|
||||||
@articles_by_category = @order.get_articles
|
@articles_grouped_by_category = @order.articles_grouped_by_category
|
||||||
# save results of earlier orders in array
|
# save results of earlier orders in array
|
||||||
ordered_articles = Array.new
|
ordered_articles = Array.new
|
||||||
@group_order = @order.group_orders.find(:first, :conditions => "ordergroup_id = #{@ordergroup.id}", :include => :group_order_articles)
|
@group_order = @order.group_orders.find(:first,
|
||||||
|
:conditions => "ordergroup_id = #{@ordergroup.id}", :include => :group_order_articles)
|
||||||
|
|
||||||
if @group_order
|
if @group_order
|
||||||
# Group has already ordered, so get the results...
|
# Group has already ordered, so get the results...
|
||||||
for article in @group_order.group_order_articles
|
for goa in @group_order.group_order_articles
|
||||||
result = article.result
|
ordered_articles[goa.order_article_id] = {:quantity => goa.quantity,
|
||||||
ordered_articles[article.order_article_id] = {'quantity' => article.quantity,
|
:tolerance => goa.tolerance,
|
||||||
'tolerance' => article.tolerance,
|
:quantity_result => goa.result(:quantity),
|
||||||
'quantity_result' => result[:quantity],
|
:tolerance_result => goa.result(:tolerance)}
|
||||||
'tolerance_result' => result[:tolerance]}
|
|
||||||
end
|
end
|
||||||
@version = @group_order.lock_version
|
@version = @group_order.lock_version
|
||||||
@availableFunds = @ordergroup.get_available_funds(@group_order)
|
@availableFunds = @ordergroup.get_available_funds(@group_order)
|
||||||
|
@ -41,19 +42,19 @@ class OrderingController < ApplicationController
|
||||||
@others_quantity = Array.new; @quantity = Array.new; @quantity_result = Array.new; @used_quantity = Array.new; @unused_quantity = Array.new
|
@others_quantity = Array.new; @quantity = Array.new; @quantity_result = Array.new; @used_quantity = Array.new; @unused_quantity = Array.new
|
||||||
@others_tolerance = Array.new; @tolerance = Array.new; @tolerance_result = Array.new; @used_tolerance = Array.new; @unused_tolerance = Array.new
|
@others_tolerance = Array.new; @tolerance = Array.new; @tolerance_result = Array.new; @used_tolerance = Array.new; @unused_tolerance = Array.new
|
||||||
i = 0;
|
i = 0;
|
||||||
@articles_by_category.each do |category_name, order_articles|
|
@articles_grouped_by_category.each do |category_name, order_articles|
|
||||||
for order_article in order_articles
|
for order_article in order_articles
|
||||||
# price/unit size
|
# price/unit size
|
||||||
@price[i] = order_article.article.fc_price
|
@price[i] = order_article.article.fc_price
|
||||||
@unit[i] = order_article.article.unit_quantity
|
@unit[i] = order_article.article.unit_quantity
|
||||||
# quantity
|
# quantity
|
||||||
@quantity[i] = (ordered_articles[order_article.id] ? ordered_articles[order_article.id]['quantity'] : 0)
|
@quantity[i] = (ordered_articles[order_article.id] ? ordered_articles[order_article.id][:quantity] : 0)
|
||||||
@others_quantity[i] = order_article.quantity - @quantity[i]
|
@others_quantity[i] = order_article.quantity - @quantity[i]
|
||||||
@used_quantity[i] = (ordered_articles[order_article.id] ? ordered_articles[order_article.id]['quantity_result'] : 0)
|
@used_quantity[i] = (ordered_articles[order_article.id] ? ordered_articles[order_article.id][:quantity_result] : 0)
|
||||||
# tolerance
|
# tolerance
|
||||||
@tolerance[i] = (ordered_articles[order_article.id] ? ordered_articles[order_article.id]['tolerance'] : 0)
|
@tolerance[i] = (ordered_articles[order_article.id] ? ordered_articles[order_article.id][:tolerance] : 0)
|
||||||
@others_tolerance[i] = order_article.tolerance - @tolerance[i]
|
@others_tolerance[i] = order_article.tolerance - @tolerance[i]
|
||||||
@used_tolerance[i] = (ordered_articles[order_article.id] ? ordered_articles[order_article.id]['tolerance_result'] : 0)
|
@used_tolerance[i] = (ordered_articles[order_article.id] ? ordered_articles[order_article.id][:tolerance_result] : 0)
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -90,8 +91,8 @@ class OrderingController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get ordered quantities and update group_order_articles/_quantities...
|
# Get ordered quantities and update group_order_articles/_quantities...
|
||||||
quantities = ordered.fetch(order_article.id.to_s, {'quantity' => 0, 'tolerance' => 0})
|
quantities = ordered.fetch(order_article.id.to_s, {:quantity => 0, :tolerance => 0})
|
||||||
group_order_article.update_quantities(quantities['quantity'].to_i, quantities['tolerance'].to_i)
|
group_order_article.update_quantities(quantities[:quantity].to_i, quantities[:tolerance].to_i)
|
||||||
|
|
||||||
# Also update results for the order_article
|
# Also update results for the order_article
|
||||||
order_article.update_results!
|
order_article.update_results!
|
||||||
|
|
|
@ -55,7 +55,7 @@ class OrdersController < ApplicationController
|
||||||
def new
|
def new
|
||||||
@supplier = Supplier.find(params[:supplier_id])
|
@supplier = Supplier.find(params[:supplier_id])
|
||||||
@order = @supplier.orders.build :ends => 4.days.from_now
|
@order = @supplier.orders.build :ends => 4.days.from_now
|
||||||
@template_orders = @supplier.orders.finished :order => 'starts DESC', :include => "order_article_results"
|
@template_orders = @supplier.orders.finished :order => 'starts DESC', :limit => 5
|
||||||
end
|
end
|
||||||
|
|
||||||
# Save a new order.
|
# Save a new order.
|
||||||
|
|
|
@ -34,6 +34,7 @@ class Article < ActiveRecord::Base
|
||||||
has_many :article_prices, :order => "created_at"
|
has_many :article_prices, :order => "created_at"
|
||||||
|
|
||||||
named_scope :in_stock, :conditions => "quantity > 0", :order => 'suppliers.name', :include => :supplier
|
named_scope :in_stock, :conditions => "quantity > 0", :order => 'suppliers.name', :include => :supplier
|
||||||
|
named_scope :available, :conditions => {:availability => true}
|
||||||
|
|
||||||
# Validations
|
# Validations
|
||||||
validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category_id
|
validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category_id
|
||||||
|
@ -171,24 +172,6 @@ class Article < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns Articles in a nested Array, grouped by category and ordered by article name.
|
|
||||||
# The array has the following form:
|
|
||||||
# e.g: [["drugs",[teethpaste, toiletpaper]], ["fruits" => [apple, banana, lemon]]]
|
|
||||||
# TODO: force article to belong to a category and remove this complicated implementation!
|
|
||||||
def self.group_by_category(articles)
|
|
||||||
articles_by_category = {}
|
|
||||||
ArticleCategory.find(:all).each do |category|
|
|
||||||
articles_by_category.merge!(category.name.to_s => articles.select {|article| article.article_category and article.article_category.id == category.id })
|
|
||||||
end
|
|
||||||
# add articles without a category
|
|
||||||
articles_by_category.merge!( "--" => articles.select {|article| article.article_category == nil})
|
|
||||||
# return "clean" hash, sorted by category.name
|
|
||||||
return articles_by_category.reject {|category, array| array.empty?}.sort
|
|
||||||
|
|
||||||
# it could be so easy ... but that doesn't work for empty category-ids...
|
|
||||||
# articles.group_by {|a| a.article_category}.sort {|a, b| a[0].name <=> b[0].name}
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_quantity(amount)
|
def update_quantity(amount)
|
||||||
update_attribute :quantity, quantity + amount
|
update_attribute :quantity, quantity + amount
|
||||||
end
|
end
|
||||||
|
@ -203,7 +186,7 @@ class Article < ActiveRecord::Base
|
||||||
# Create an ArticlePrice, when the price-attr are changed.
|
# Create an ArticlePrice, when the price-attr are changed.
|
||||||
def update_price_history
|
def update_price_history
|
||||||
if price_changed?
|
if price_changed?
|
||||||
article_prices.create(
|
article_prices.build(
|
||||||
:price => price,
|
:price => price,
|
||||||
:tax => tax,
|
:tax => tax,
|
||||||
:deposit => deposit,
|
:deposit => deposit,
|
||||||
|
|
|
@ -30,7 +30,7 @@ class GroupOrderArticle < ActiveRecord::Base
|
||||||
|
|
||||||
attr_accessor :ordergroup_id # To create an new GroupOrder if neccessary
|
attr_accessor :ordergroup_id # To create an new GroupOrder if neccessary
|
||||||
|
|
||||||
named_scope :ordered, :conditions => 'quantity_result > 0 OR tolerance_result > 0'
|
named_scope :ordered, :conditions => 'result > 0'
|
||||||
|
|
||||||
# Updates the quantity/tolerance for this GroupOrderArticle by updating both GroupOrderArticle properties
|
# Updates the quantity/tolerance for this GroupOrderArticle by updating both GroupOrderArticle properties
|
||||||
# and the associated GroupOrderArticleQuantities chronologically.
|
# and the associated GroupOrderArticleQuantities chronologically.
|
||||||
|
@ -155,18 +155,14 @@ class GroupOrderArticle < ActiveRecord::Base
|
||||||
|
|
||||||
# Returns order result,
|
# Returns order result,
|
||||||
# either calcualted on the fly or fetched from quantity_/tolerance_result
|
# either calcualted on the fly or fetched from quantity_/tolerance_result
|
||||||
def result
|
# After an order is finished, there is only the result
|
||||||
if quantity_result.nil?
|
def result(type = :total)
|
||||||
calculate_result
|
self[:result] || calculate_result[type]
|
||||||
else
|
|
||||||
{:quantity => quantity_result, :tolerance => tolerance_result, :total => quantity_result + tolerance_result}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is used when finishing the order.
|
# This is used during order.finish!.
|
||||||
def save_results!
|
def save_results!
|
||||||
self.quantity_result = calculate_result[:quantity]
|
self.update_attribute(:result, calculate_result[:total])
|
||||||
self.tolerance_result = calculate_result[:tolerance]
|
|
||||||
save!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,12 +76,18 @@ class Order < ActiveRecord::Base
|
||||||
# Returns OrderArticles in a nested Array, grouped by category and ordered by article name.
|
# Returns OrderArticles in a nested Array, grouped by category and ordered by article name.
|
||||||
# The array has the following form:
|
# The array has the following form:
|
||||||
# e.g: [["drugs",[teethpaste, toiletpaper]], ["fruits" => [apple, banana, lemon]]]
|
# e.g: [["drugs",[teethpaste, toiletpaper]], ["fruits" => [apple, banana, lemon]]]
|
||||||
def get_articles
|
def articles_grouped_by_category
|
||||||
order_articles.all(:include => [:article, :article_price], :order => 'articles.name').group_by { |a|
|
order_articles.all(:include => [:article, :article_price], :order => 'articles.name').group_by { |a|
|
||||||
a.article.article_category.name
|
a.article.article_category.name
|
||||||
}.sort { |a, b| a[0] <=> b[0] }
|
}.sort { |a, b| a[0] <=> b[0] }
|
||||||
end
|
end
|
||||||
memoize :get_articles
|
memoize :articles_grouped_by_category
|
||||||
|
|
||||||
|
def articles_sort_by_category
|
||||||
|
order_articles.all(:include => [:article], :order => 'articles.name').sort do |a,b|
|
||||||
|
a.article.article_category.name <=> b.article.article_category.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the defecit/benefit for the foodcoop
|
# Returns the defecit/benefit for the foodcoop
|
||||||
# Requires a valid invoice, belonging to this order
|
# Requires a valid invoice, belonging to this order
|
||||||
|
@ -117,9 +123,9 @@ class Order < ActiveRecord::Base
|
||||||
for goa in go.group_order_articles
|
for goa in go.group_order_articles
|
||||||
case type
|
case type
|
||||||
when :groups
|
when :groups
|
||||||
total += goa.quantity * goa.order_article.price.fc_price
|
total += goa.result * goa.order_article.price.fc_price
|
||||||
when :groups_without_markup
|
when :groups_without_markup
|
||||||
total += goa.quantity * goa.order_article.price.gross_price
|
total += goa.result * goa.order_article.price.gross_price
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -165,7 +171,7 @@ class Order < ActiveRecord::Base
|
||||||
transaction do # Start updating account balances
|
transaction do # Start updating account balances
|
||||||
for group_order in gos
|
for group_order in gos
|
||||||
price = group_order.price * -1 # decrease! account balance
|
price = group_order.price * -1 # decrease! account balance
|
||||||
group_order.ordergroup.addFinancialTransaction(price, transaction_note, user)
|
group_order.ordergroup.add_financial_transaction(price, transaction_note, user)
|
||||||
end
|
end
|
||||||
self.update_attributes! :state => 'closed', :updated_by => user
|
self.update_attributes! :state => 'closed', :updated_by => user
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,11 +43,12 @@ class OrderArticle < ActiveRecord::Base
|
||||||
# Count quantities of belonging group_orders.
|
# Count quantities of belonging group_orders.
|
||||||
# In balancing this can differ from ordered (by supplier) quantity for this article.
|
# In balancing this can differ from ordered (by supplier) quantity for this article.
|
||||||
def group_orders_sum
|
def group_orders_sum
|
||||||
quantity = group_order_articles.collect(&:quantity).sum
|
quantity = group_order_articles.collect(&:result).sum
|
||||||
{:quantity => quantity, :price => quantity * price.fc_price}
|
{:quantity => quantity, :price => quantity * price.fc_price}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update quantity/tolerance/units_to_order from group_order_articles
|
# Update quantity/tolerance/units_to_order from group_order_articles
|
||||||
|
# This is only used in opened orders.
|
||||||
def update_results!
|
def update_results!
|
||||||
quantity = group_order_articles.collect(&:quantity).sum
|
quantity = group_order_articles.collect(&:quantity).sum
|
||||||
tolerance = group_order_articles.collect(&:tolerance).sum
|
tolerance = group_order_articles.collect(&:tolerance).sum
|
||||||
|
@ -80,6 +81,10 @@ class OrderArticle < ActiveRecord::Base
|
||||||
units += ((remainder > 0) && (remainder + tolerance >= unit_size) ? 1 : 0)
|
units += ((remainder > 0) && (remainder + tolerance >= unit_size) ? 1 : 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ordered_quantities_equal_to_group_orders?
|
||||||
|
(units_to_order * price.unit_quantity) == group_orders_sum[:quantity]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def article_and_price_exist
|
def article_and_price_exist
|
||||||
|
|
|
@ -65,50 +65,22 @@ class Ordergroup < Group
|
||||||
|
|
||||||
# Creates a new FinancialTransaction for this Ordergroup and updates the account_balance accordingly.
|
# Creates a new FinancialTransaction for this Ordergroup and updates the account_balance accordingly.
|
||||||
# Throws an exception if it fails.
|
# Throws an exception if it fails.
|
||||||
def addFinancialTransaction(amount, note, user)
|
def add_financial_transaction(amount, note, user)
|
||||||
transaction do
|
transaction do
|
||||||
trans = FinancialTransaction.new(:ordergroup => self, :amount => amount, :note => note, :user => user)
|
trans = FinancialTransaction.new(:ordergroup => self, :amount => amount, :note => note, :user => user)
|
||||||
trans.save!
|
trans.save!
|
||||||
self.account_balance += trans.amount
|
self.account_balance += trans.amount
|
||||||
self.account_updated = trans.created_on
|
self.account_updated = trans.created_on
|
||||||
save!
|
save!
|
||||||
notifyNegativeBalance(trans)
|
notify_negative_balance(trans)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns all GroupOrders by this group that are currently running.
|
|
||||||
def findCurrent
|
|
||||||
group_orders.find(:all, :conditions => ["orders.finished = ? AND orders.starts < ? AND (orders.ends IS NULL OR orders.ends > ?)", false, Time.now, Time.now], :include => :order)
|
|
||||||
end
|
|
||||||
|
|
||||||
#find expired (lapsed) but not manually finished orders
|
|
||||||
def findExpiredOrders
|
|
||||||
group_orders.find(:all, :conditions => ["orders.ends < ?", Time.now], :include => :order, :order => 'orders.ends DESC')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns all GroupOrderResults by this group that are finished but not booked yet.
|
|
||||||
def findFinishedNotBooked
|
|
||||||
GroupOrderResult.find(:all,
|
|
||||||
:conditions => ["group_order_results.group_name = ? AND group_order_results.order_id = orders.id AND orders.finished = ? AND orders.booked = ? ", self.name, true, false],
|
|
||||||
:include => :order,
|
|
||||||
:order => 'orders.ends DESC')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns all GroupOrderResults for booked orders
|
|
||||||
def findBookedOrders(limit = false, offset = 0)
|
|
||||||
GroupOrderResult.find(:all,
|
|
||||||
:conditions => ["group_order_results.group_name = ? AND group_order_results.order_id = orders.id AND orders.finished = ? AND orders.booked = ? ", self.name, true, true],
|
|
||||||
:include => :order,
|
|
||||||
:order => "orders.ends DESC",
|
|
||||||
:limit => limit,
|
|
||||||
:offset => offset)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# If this order group's account balance is made negative by the given/last transaction,
|
# If this order group's account balance is made negative by the given/last transaction,
|
||||||
# a message is sent to all users who have enabled notification.
|
# a message is sent to all users who have enabled notification.
|
||||||
def notifyNegativeBalance(transaction)
|
def notify_negative_balance(transaction)
|
||||||
# Notify only when order group had a positive balance before the last transaction:
|
# Notify only when order group had a positive balance before the last transaction:
|
||||||
if (transaction.amount < 0 && self.account_balance < 0 && self.account_balance - transaction.amount >= 0)
|
if (transaction.amount < 0 && self.account_balance < 0 && self.account_balance - transaction.amount >= 0)
|
||||||
users = self.users.reject { |u| u.settings["notify.negativeBalance"] != '1' }
|
users = self.users.reject { |u| u.settings["notify.negativeBalance"] != '1' }
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
class Supplier < ActiveRecord::Base
|
class Supplier < ActiveRecord::Base
|
||||||
acts_as_paranoid # Avoid deleting the supplier for consistency of order-results
|
acts_as_paranoid # Avoid deleting the supplier for consistency of order-results
|
||||||
|
|
||||||
has_many :articles, :dependent => :destroy
|
has_many :articles, :dependent => :destroy,
|
||||||
|
:include => [:article_category], :order => 'article_categories.name, articles.name'
|
||||||
has_many :orders
|
has_many :orders
|
||||||
has_many :deliveries
|
has_many :deliveries
|
||||||
has_many :invoices
|
has_many :invoices
|
||||||
|
@ -40,10 +41,9 @@ class Supplier < ActiveRecord::Base
|
||||||
# for the sharedLists-App
|
# for the sharedLists-App
|
||||||
belongs_to :shared_supplier
|
belongs_to :shared_supplier
|
||||||
|
|
||||||
# Returns all articles for this supplier that are available and have a valid price, grouped by article category and ordered by name.
|
# Returns all articles for this supplier that are available, grouped by article category and ordered by name.
|
||||||
def getArticlesAvailableForOrdering
|
def get_articles_for_ordering
|
||||||
articles = Article.find(:all, :conditions => ['supplier_id = ? AND availability = ?', self.id, true], :order => 'article_categories.name, articles.name', :include => :article_category)
|
articles.available.all.group_by { |a| a.article_category.name }
|
||||||
articles.select {|article| article.fc_price}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# sync all articles with the external database
|
# sync all articles with the external database
|
||||||
|
@ -52,7 +52,7 @@ class Supplier < ActiveRecord::Base
|
||||||
def sync_all
|
def sync_all
|
||||||
updated_articles = Array.new
|
updated_articles = Array.new
|
||||||
outlisted_articles = Array.new
|
outlisted_articles = Array.new
|
||||||
for article in articles.find(:all, :order => "article_categories.name", :include => :article_category)
|
for article in articles
|
||||||
# try to find the associated shared_article
|
# try to find the associated shared_article
|
||||||
shared_article = article.shared_article
|
shared_article = article.shared_article
|
||||||
if shared_article
|
if shared_article
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
(Einheit:
|
(Einheit:
|
||||||
= group_order_article.order_article.article.unit
|
= group_order_article.order_article.article.unit
|
||||||
)
|
)
|
||||||
= form.text_field :quantity, :size => "6"
|
= form.text_field :result, :size => "6"
|
||||||
= submit_tag "Speichern"
|
= submit_tag "Speichern"
|
||||||
|
|
|
|
||||||
= link_to_function 'Abbrechen', "Element.hide('edit_box')"
|
= link_to_function 'Abbrechen', "Element.hide('edit_box')"
|
|
@ -16,5 +16,5 @@
|
||||||
%th Pfand
|
%th Pfand
|
||||||
%th{:colspan => "2"}
|
%th{:colspan => "2"}
|
||||||
%tbody#result_table
|
%tbody#result_table
|
||||||
- for order_article in @order.order_articles.all(:include => [:article, :article_price])
|
- for order_article in @order.order_articles.ordered.all(:include => [:article, :article_price])
|
||||||
= render :partial => "order_article_result", :locals => {:order_article => order_article}
|
= render :partial => "order_article_result", :locals => {:order_article => order_article}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
%td{:style=>"width:50%"}
|
%td{:style=>"width:50%"}
|
||||||
= group_order_article.group_order.ordergroup.name
|
= group_order_article.group_order.ordergroup.name
|
||||||
%td{:id => "group_order_article_#{group_order_article.id}_quantity"}
|
%td{:id => "group_order_article_#{group_order_article.id}_quantity"}
|
||||||
= group_order_article.quantity
|
= group_order_article.result
|
||||||
%td.currency
|
%td.currency
|
||||||
= number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.quantity, :unit => "")
|
= number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.quantity, :unit => "")
|
||||||
%td.actions{:style=>"width:1em"}
|
%td.actions{:style=>"width:1em"}
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
= form.select :ordergroup_id, Ordergroup.all(:order => "name").collect{ |og| [og.name, og.id] }
|
= form.select :ordergroup_id, Ordergroup.all(:order => "name").collect{ |og| [og.name, og.id] }
|
||||||
%p
|
%p
|
||||||
Menge:
|
Menge:
|
||||||
= form.text_field "quantity", :size => 5
|
= form.text_field :result, :size => 5
|
||||||
= form.hidden_field "order_article_id"
|
= form.hidden_field :order_article_id
|
||||||
%p
|
%p
|
||||||
= submit_tag "Speichern"
|
= submit_tag "Speichern"
|
||||||
|
|
|
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
"Element.toggle('group_order_articles_#{order_article.id}'); |
|
"Element.toggle('group_order_articles_#{order_article.id}'); |
|
||||||
Element.toggleClassName(this.up('td'), 'open')" |
|
Element.toggleClassName(this.up('td'), 'open')" |
|
||||||
%td= order_article.article.order_number
|
%td= order_article.article.order_number
|
||||||
%td= order_article.units_to_order
|
%td
|
||||||
|
= order_article.units_to_order
|
||||||
|
- unless order_article.ordered_quantities_equal_to_group_orders?
|
||||||
|
%span{:style => "color:red;font-weight: bold"} !
|
||||||
%td= order_article.price.unit_quantity.to_s + ' * ' + order_article.article.unit.to_s
|
%td= order_article.price.unit_quantity.to_s + ' * ' + order_article.article.unit.to_s
|
||||||
%td= number_to_currency(order_article.price.price, :unit => "")
|
%td= number_to_currency(order_article.price.price, :unit => "")
|
||||||
%td= number_to_currency(order_article.price.fc_price, :unit => "")
|
%td= number_to_currency(order_article.price.fc_price, :unit => "")
|
||||||
|
|
|
@ -62,11 +62,11 @@
|
||||||
%th
|
%th
|
||||||
%abbr{:title => "Menge + Toleranz"} Bestellt
|
%abbr{:title => "Menge + Toleranz"} Bestellt
|
||||||
%th
|
%th
|
||||||
%abbr{:title => "Unter Berücksichtigung der anderen Gruppen"} Zugeteilt
|
%abbr{:title => "Unter Berücksichtigung der anderen Gruppen"} Bekommen
|
||||||
%th Gesamtpreis
|
%th Gesamtpreis
|
||||||
%tbody
|
%tbody
|
||||||
- total = 0 #set counter for order-sum
|
- total = 0 #set counter for order-sum
|
||||||
- for category_name, order_articles in @order.get_articles
|
- for category_name, order_articles in @order.articles_grouped_by_category
|
||||||
%tr{:style => "background-color:#EFEFEF"}
|
%tr{:style => "background-color:#EFEFEF"}
|
||||||
%td{:style => "text-align:left;"}=h category_name
|
%td{:style => "text-align:left;"}=h category_name
|
||||||
%td{:colspan => "9"}
|
%td{:colspan => "9"}
|
||||||
|
@ -76,8 +76,11 @@
|
||||||
- if goa
|
- if goa
|
||||||
- quantity = goa.quantity
|
- quantity = goa.quantity
|
||||||
- tolerance = goa.tolerance
|
- tolerance = goa.tolerance
|
||||||
- result = goa.result[:total]
|
- result = goa.result
|
||||||
|
- if @order.open?
|
||||||
- sub_total = oa.price.fc_price * (quantity + tolerance)
|
- sub_total = oa.price.fc_price * (quantity + tolerance)
|
||||||
|
- else
|
||||||
|
- sub_total = oa.price.fc_price * result
|
||||||
- else
|
- else
|
||||||
- quantity, tolerance, result, sub_total = 0, 0, 0, 0
|
- quantity, tolerance, result, sub_total = 0, 0, 0, 0
|
||||||
- total += sub_total
|
- total += sub_total
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
<%-
|
<%-
|
||||||
total = 0
|
total = 0
|
||||||
i = 0
|
i = 0
|
||||||
@articles_by_category.each do |category, order_articles|
|
@articles_grouped_by_category.each do |category, order_articles|
|
||||||
-%>
|
-%>
|
||||||
<tr style="background-color:#EFEFEF">
|
<tr style="background-color:#EFEFEF">
|
||||||
<td style="text-align:left"><b><%=h category %></b></td>
|
<td style="text-align:left"><b><%=h category %></b></td>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
%th Bestellte Einheiten
|
%th Bestellte Einheiten
|
||||||
%th Volle Gebinde
|
%th Volle Gebinde
|
||||||
- total_net, total_gross, counter = 0, 0, 0
|
- total_net, total_gross, counter = 0, 0, 0
|
||||||
- order.get_articles.each do |category_name, order_articles|
|
- order.articles_grouped_by_category.each do |category_name, order_articles|
|
||||||
%tr{:style => "background-color:#EFEFEF"}
|
%tr{:style => "background-color:#EFEFEF"}
|
||||||
%td{:style => "text-align:left; color: grey;"}=h category_name
|
%td{:style => "text-align:left; color: grey;"}=h category_name
|
||||||
%td{:colspan => "9"}
|
%td{:colspan => "9"}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
%option{:value => "-1", :selected => "selected"}=_ "Choose an order..."
|
%option{:value => "-1", :selected => "selected"}=_ "Choose an order..."
|
||||||
- i = -1
|
- i = -1
|
||||||
- for order in @template_orders
|
- for order in @template_orders
|
||||||
%option{:value => (i += 1)}=h order.supplier.name
|
%option{:value => (i += 1)}= "#{h(order.supplier.name)} bis #{order.ends.strftime('%d. %b')}"
|
||||||
%table.list
|
%table.list
|
||||||
%tr
|
%tr
|
||||||
%th= check_box_tag 'checkall', "1", false, { :onclick => "checkUncheckAll(this)" }
|
%th= check_box_tag 'checkall', "1", false, { :onclick => "checkUncheckAll(this)" }
|
||||||
|
@ -41,11 +41,11 @@
|
||||||
%th=_ "Manufacturer"
|
%th=_ "Manufacturer"
|
||||||
%th=_ "Unit quantity"
|
%th=_ "Unit quantity"
|
||||||
%th=_ "Price"
|
%th=_ "Price"
|
||||||
- for category, articles in Article.group_by_category(@order.supplier.getArticlesAvailableForOrdering)
|
- for category_name, articles in @order.supplier.get_articles_for_ordering
|
||||||
%tr{:style => "background-color:#EFEFEF"}
|
%tr{:style => "background-color:#EFEFEF"}
|
||||||
%td
|
%td
|
||||||
%td{:colspan => "6", :style => "text-align:left"}
|
%td{:colspan => "6", :style => "text-align:left"}
|
||||||
%b=h category
|
%b=h category_name
|
||||||
- for article in articles
|
- for article in articles
|
||||||
/ check if the article is selected
|
/ check if the article is selected
|
||||||
- included = @order.order_articles.detect { |order_article| order_article.article_id == article.id }
|
- included = @order.order_articles.detect { |order_article| order_article.article_id == article.id }
|
||||||
|
|
|
@ -2,17 +2,19 @@
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
// Preset selected order articles per template order:
|
// Preset selected order articles per template order:
|
||||||
var template = new Array();
|
var template = new Array();
|
||||||
|
<% current_article_ids = @order.supplier.articles.available.map(&:id) -%>
|
||||||
<% i = -1; for order in @template_orders -%>
|
<% i = -1; for order in @template_orders -%>
|
||||||
template[<%= i += 1 %>] = new Array(<%= @order.supplier.getArticlesAvailableForOrdering.collect{|a| !order.order_article_results.detect{|t| t.name == a.name }.nil?}.join(', ') %>);
|
template[<%= i += 1 %>] = new Array(<%= current_article_ids.collect { |id| order.article_ids.include?(id) }.join(', ') %>);
|
||||||
<% end -%>
|
<% end -%>
|
||||||
// Call with index into template-array to select order articles from template.
|
// Call with index into template-array to select order articles from template.
|
||||||
function useTemplate(id) {
|
function useTemplate(id) {
|
||||||
if (id >= 0 && id < template.length) {
|
if (id >= 0 && id < template.length) {
|
||||||
<% i = -1; for article in @order.supplier.getArticlesAvailableForOrdering -%>
|
<% i = -1; for article_id in current_article_ids -%>
|
||||||
var status = template[id][<%= i += 1 %>]
|
var status = template[id][<%= i += 1 %>]
|
||||||
$('checkbox_<%= article.id %>').checked = status;
|
$('checkbox_<%= article_id %>').checked = status;
|
||||||
highlightRow('<%= article.id %>',status);
|
highlightRow('<%= article_id %>',status);
|
||||||
<% end -%>}
|
<% end -%>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//]]>
|
//]]>
|
||||||
</script>
|
</script>
|
|
@ -20,8 +20,8 @@ for order_article in @order.order_articles.ordered
|
||||||
data = []
|
data = []
|
||||||
for goa in order_article.group_order_articles
|
for goa in order_article.group_order_articles
|
||||||
data << [goa.group_order.ordergroup.name,
|
data << [goa.group_order.ordergroup.name,
|
||||||
goa.quantity,
|
goa.result,
|
||||||
number_with_precision(order_article.price.fc_price * goa.quantity)]
|
number_with_precision(order_article.price.fc_price * goa.result)]
|
||||||
end
|
end
|
||||||
|
|
||||||
pdf.table data,
|
pdf.table data,
|
||||||
|
|
|
@ -24,11 +24,10 @@ for group_order in @order.group_orders
|
||||||
data = []
|
data = []
|
||||||
group_order.group_order_articles.ordered.each do |goa|
|
group_order.group_order_articles.ordered.each do |goa|
|
||||||
price = goa.order_article.price.fc_price
|
price = goa.order_article.price.fc_price
|
||||||
quantity = goa.quantity
|
sub_total = price * goa.result
|
||||||
sub_total = price * quantity
|
|
||||||
total += sub_total
|
total += sub_total
|
||||||
data << [goa.order_article.article.name,
|
data << [goa.order_article.article.name,
|
||||||
quantity, number_with_precision(price),
|
goa.result, number_with_precision(price),
|
||||||
goa.order_article.price.unit_quantity,
|
goa.order_article.price.unit_quantity,
|
||||||
goa.order_article.article.unit,
|
goa.order_article.article.unit,
|
||||||
number_with_precision(sub_total)]
|
number_with_precision(sub_total)]
|
||||||
|
|
|
@ -59,7 +59,7 @@ while (page_number * max_order_articles_per_page < total_num_order_articles) do
|
||||||
for order_article in current_order_articles
|
for order_article in current_order_articles
|
||||||
# get the Ordergroup result for this order_article
|
# get the Ordergroup result for this order_article
|
||||||
goa = order_article.group_order_articles.first :conditions => { :group_order_id => group_order.id }
|
goa = order_article.group_order_articles.first :conditions => { :group_order_id => group_order.id }
|
||||||
group_result << ((goa.nil? || goa == 0) ? "" : goa.quantity.to_i)
|
group_result << ((goa.nil? || goa == 0) ? "" : goa.result.to_i)
|
||||||
end
|
end
|
||||||
groups_data << group_result
|
groups_data << group_result
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
%th{:colspan => '3'} Legende
|
%th{:colspan => '3'} Legende
|
||||||
%tr
|
%tr
|
||||||
%th{:style => 'width:70%'} Bestellgruppe
|
%th{:style => 'width:70%'} Bestellgruppe
|
||||||
%th Bestellt
|
%th Bestellt (Menge + Toleranz)
|
||||||
%th Bekommen
|
%th Bekommen
|
||||||
%th Gesamtpreis
|
%th Gesamtpreis
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@
|
||||||
- for goa in order_article.group_order_articles
|
- for goa in order_article.group_order_articles
|
||||||
%tr{:class => cycle('even', 'odd', :name => 'groups')}
|
%tr{:class => cycle('even', 'odd', :name => 'groups')}
|
||||||
%td{:style => "width:70%"}=h goa.group_order.ordergroup.name
|
%td{:style => "width:70%"}=h goa.group_order.ordergroup.name
|
||||||
%td= "#{goa.quantity} (#{goa.tolerance})"
|
%td= "#{goa.quantity} + #{goa.tolerance}"
|
||||||
%td
|
%td
|
||||||
%b= "#{goa.quantity_result} + #{goa.tolerance_result}"
|
%b= goa.result
|
||||||
%td= number_to_currency(order_article.price.fc_price * goa.quantity)
|
%td= number_to_currency(order_article.price.fc_price * goa.result)
|
||||||
- reset_cycle('groups')
|
- reset_cycle('groups')
|
|
@ -3,7 +3,7 @@
|
||||||
%tr
|
%tr
|
||||||
%th{:style => "width:40%"} Name
|
%th{:style => "width:40%"} Name
|
||||||
%th
|
%th
|
||||||
%acronym{:title => "zugeteilte Einheiten (davon aus Toleranzmenge)"} Menge
|
%acronym{:title => "zugeteilte Einheiten"} Menge
|
||||||
%th
|
%th
|
||||||
%acronym{:title => "Preis incl. MwSt, Pfand und Foodcoop-Aufschlag"} FC-Preis
|
%acronym{:title => "Preis incl. MwSt, Pfand und Foodcoop-Aufschlag"} FC-Preis
|
||||||
%th
|
%th
|
||||||
|
@ -20,11 +20,11 @@
|
||||||
- total = 0
|
- total = 0
|
||||||
- for goa in group_order.group_order_articles.ordered.all(:include => :order_article)
|
- for goa in group_order.group_order_articles.ordered.all(:include => :order_article)
|
||||||
- fc_price = goa.order_article.price.fc_price
|
- fc_price = goa.order_article.price.fc_price
|
||||||
- subTotal = fc_price * goa.quantity
|
- subTotal = fc_price * goa.result
|
||||||
- total += subTotal
|
- total += subTotal
|
||||||
%tr{:class => cycle('even', 'odd', :name => 'articles')}
|
%tr{:class => cycle('even', 'odd', :name => 'articles')}
|
||||||
%td{:style => "width:40%"}=h goa.order_article.article.name
|
%td{:style => "width:40%"}=h goa.order_article.article.name
|
||||||
%td= "#{goa.result[:quantity]} (#{goa.result[:tolerance]})"
|
%td= goa.result
|
||||||
%td= number_to_currency(fc_price)
|
%td= number_to_currency(fc_price)
|
||||||
%td= goa.order_article.price.unit_quantity
|
%td= goa.order_article.price.unit_quantity
|
||||||
%td= goa.order_article.article.unit
|
%td= goa.order_article.article.unit
|
||||||
|
|
|
@ -79,9 +79,8 @@ class RefactorOrderLogic < ActiveRecord::Migration
|
||||||
# change_column :group_orders, :updated_by_user_id, :integer, :default => nil, :null => true
|
# change_column :group_orders, :updated_by_user_id, :integer, :default => nil, :null => true
|
||||||
|
|
||||||
# == GroupOrderArticle
|
# == GroupOrderArticle
|
||||||
# The order result in ordergroup is now saved!
|
# The total order result in ordergroup is now saved!
|
||||||
add_column :group_order_articles, :quantity_result, :integer, :default => nil
|
add_column :group_order_articles, :result, :integer, :default => nil
|
||||||
add_column :group_order_articles, :tolerance_result, :integer, :default => nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.down
|
def self.down
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20090119155930) do
|
ActiveRecord::Schema.define(:version => 20090120184410) do
|
||||||
|
|
||||||
create_table "article_categories", :force => true do |t|
|
create_table "article_categories", :force => true do |t|
|
||||||
t.string "name", :default => "", :null => false
|
t.string "name", :default => "", :null => false
|
||||||
|
@ -97,6 +97,7 @@ ActiveRecord::Schema.define(:version => 20090119155930) do
|
||||||
t.integer "quantity", :default => 0, :null => false
|
t.integer "quantity", :default => 0, :null => false
|
||||||
t.integer "tolerance", :default => 0, :null => false
|
t.integer "tolerance", :default => 0, :null => false
|
||||||
t.datetime "updated_on", :null => false
|
t.datetime "updated_on", :null => false
|
||||||
|
t.integer "result"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "group_order_articles", ["group_order_id", "order_article_id"], :name => "goa_index", :unique => true
|
add_index "group_order_articles", ["group_order_id", "order_article_id"], :name => "goa_index", :unique => true
|
||||||
|
|
Loading…
Reference in a new issue