First part of stock-integratino. Orders with supplier_id == 0 become stockorders.

This commit is contained in:
Benjamin Meichsner 2009-02-05 16:40:02 +01:00
parent 251ced4fa1
commit 1912a3fd80
30 changed files with 112 additions and 95 deletions

View file

@ -53,9 +53,7 @@ class OrdersController < ApplicationController
# Page to create a new order.
def new
@supplier = Supplier.find(params[:supplier_id])
@order = @supplier.orders.build :ends => 4.days.from_now
@template_orders = @supplier.orders.finished :order => 'starts DESC', :limit => 5
@order = Order.new :ends => 4.days.from_now, :supplier_id => params[:supplier_id]
end
# Save a new order.
@ -104,13 +102,13 @@ class OrdersController < ApplicationController
# Renders the groups-orderd PDF.
def groupsPdf
@order = Order.find(params[:id])
prawnto :filename => "#{Date.today}_#{@order.supplier.name}_GruppenSortierung.pdf"
prawnto :filename => "#{Date.today}_#{@order.name}_GruppenSortierung.pdf"
end
# Renders the articles-orderd PDF.
def articlesPdf
@order = Order.find(params[:id])
prawnto :filename => "#{Date.today}_#{@order.supplier.name}_ArtikelSortierung.pdf",
prawnto :filename => "#{Date.today}_#{@order.name}_ArtikelSortierung.pdf",
:prawn => { :left_margin => 48,
:right_margin => 48,
:top_margin => 48,
@ -120,7 +118,7 @@ class OrdersController < ApplicationController
# Renders the fax PDF.
def faxPdf
@order = Order.find(params[:id])
prawnto :filename => "#{Date.today}_#{@order.supplier.name}_FAX.pdf"
prawnto :filename => "#{Date.today}_#{@order.name}_FAX.pdf"
end
# Renders the fax-text-file
@ -147,13 +145,13 @@ class OrdersController < ApplicationController
end
send_data text,
:type => 'text/plain; charset=utf-8; header=present',
:disposition => "attachment; filename=#{order.supplier.name}"
:disposition => "attachment; filename=#{order.name}"
end
# Renders the matrix PDF.
def matrixPdf
@order = Order.find(params[:id])
prawnto :filename => "#{Date.today}_#{@order.supplier.name}_Matrix.pdf"
prawnto :filename => "#{Date.today}_#{@order.name}_Matrix.pdf"
end
# adds a Comment to the Order

View file

@ -32,6 +32,7 @@ class Article < ActiveRecord::Base
belongs_to :supplier
belongs_to :article_category
has_many :article_prices, :order => "created_at"
has_many :stock_changes
named_scope :in_stock, :conditions => "quantity > 0", :order => 'suppliers.name', :include => :supplier
named_scope :available, :conditions => {:availability => true}
@ -172,8 +173,9 @@ class Article < ActiveRecord::Base
end
end
def update_quantity(amount)
update_attribute :quantity, quantity + amount
# Update the quantity of items in stock
def update_quantity!
update_attribute :quantity, stock_changes.collect(&:quantity).sum
end
protected

View file

@ -26,8 +26,8 @@ class GroupOrder < ActiveRecord::Base
validates_numericality_of :price
validates_uniqueness_of :ordergroup_id, :scope => :order_id # order groups can only order once per order
named_scope :open, lambda { {:conditions => ["order_id IN (?)", Order.open.collect{|o| o.id}]} }
named_scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished.collect{|o| o.id}]} }
named_scope :open, lambda { {:conditions => ["order_id IN (?)", Order.open.collect(&:id)]} }
named_scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished.collect(&:id)]} }
# Updates the "price" attribute.
# This will be the maximum value of an order

View file

@ -154,8 +154,8 @@ class GroupOrderArticle < ActiveRecord::Base
memoize :calculate_result
# Returns order result,
# either calcualted on the fly or fetched from quantity_/tolerance_result
# After an order is finished, there is only the result
# either calcualted on the fly or fetched from result attribute
# Result is set when finishing the order.
def result(type = :total)
self[:result] || calculate_result[type]
end

View file

@ -28,21 +28,44 @@ class Order < ActiveRecord::Base
belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id"
# Validations
validates_presence_of :supplier_id, :starts
validate_on_create :starts_before_ends, :include_articles
validates_presence_of :starts
validate :starts_before_ends, :include_articles
# Callbacks
after_update :update_price_of_group_orders
# Finders
named_scope :open, :conditions => { :state => 'open' },
:order => 'ends DESC'
named_scope :finished, :conditions => "state = 'finished' OR state = 'closed'",
:order => 'ends DESC'
named_scope :finished_not_closed, :conditions => { :state => 'finished' },
:order => 'ends DESC'
named_scope :closed, :conditions => { :state => 'closed' },
:order => 'ends DESC'
named_scope :open, :conditions => {:state => 'open'}, :order => 'ends DESC'
named_scope :finished, :conditions => "state = 'finished' OR state = 'closed'", :order => 'ends DESC'
named_scope :finished_not_closed, :conditions => {:state => 'finished'}, :order => 'ends DESC'
named_scope :closed, :conditions => {:state => 'closed'}, :order => 'ends DESC'
named_scope :stockit, :conditions => {:supplier_id => 0}, :order => 'ends DESC'
def stockit?
supplier_id == 0
end
def name
stockit? ? "Lager" : supplier.name
end
def articles_for_ordering
if stockit?
Article.in_stock.all(:include => :article_category,
:order => 'article_categories.name, articles.name').group_by { |a| a.article_category.name }
else
supplier.articles.available.all.group_by { |a| a.article_category.name }
end
end
# Fetch last orders from same supplier, to generate an article selection proposal
def templates
if stockit?
Order.stockit :limit => 5
else
supplier.orders.finished :limit => 5
end
end
# Create or destroy OrderArticle associations on create/update
def article_ids=(ids)
@ -163,7 +186,7 @@ class Order < ActiveRecord::Base
# Sets order.status to 'close' and updates all Ordergroup.account_balances
def close!(user)
raise "Bestellung wurde schon abgerechnet" if closed?
transaction_note = "Bestellung: #{supplier.name}, bis #{ends.strftime('%d.%m.%Y')}"
transaction_note = "Bestellung: #{name}, bis #{ends.strftime('%d.%m.%Y')}"
gos = group_orders.all(:include => :ordergroup) # Fetch group_orders
gos.each { |group_order| group_order.update_price! } # Update prices of group_orders

View file

@ -20,15 +20,11 @@ class StockChange < ActiveRecord::Base
validates_numericality_of :quantity
after_save :update_article_quantity
after_destroy :remove_added_quantity
after_destroy :update_article_quantity
protected
def update_article_quantity
article.update_quantity(quantity)
end
def remove_added_quantity
article.update_quantity(quantity * -1)
article.update_quantity!
end
end

View file

@ -41,11 +41,6 @@ class Supplier < ActiveRecord::Base
# for the sharedLists-App
belongs_to :shared_supplier
# Returns all articles for this supplier that are available, grouped by article category and ordered by name.
def get_articles_for_ordering
articles.available.all.group_by { |a| a.article_category.name }
end
# sync all articles with the external database
# returns an array with articles(and prices), which should be updated (to use in a form)
# also returns an array with outlisted_articles, which should be deleted

View file

@ -1,4 +1,4 @@
%b=h order.supplier.name
%b=h order.name
%br/
= "von #{format_date(order.starts)} bis #{format_date(order.ends)}"
%p

View file

@ -55,7 +55,7 @@
%tbody
- @orders.each do |order|
%tr{:class => cycle("even","odd", :name => "order")}
%td= order.supplier.name
%td= order.name
%td= format_date(order.ends)
%td{:class => "currency"}= number_to_currency(order.sum(:fc))
%td= link_to "abrechnen", :action => "new", :id => order

View file

@ -18,7 +18,7 @@
%tbody
- @orders.each do |order|
%tr{:class => cycle("even","odd", :name => "order")}
%td= link_to truncate(order.supplier.name), :action => "new", :id => order
%td= link_to truncate(order.name), :action => "new", :id => order
%td=h format_time(order.ends) unless order.ends.nil?
%td= order.closed? ? "abgerechnet (#{number_to_currency order.profit})" : "beendet"
%td= order.updated_by.nil? ? '??' : order.updated_by.nick

View file

@ -1,4 +1,4 @@
- title "#{@order.supplier.name} abrechnen"
- title "#{@order.name} abrechnen"
- if @order.closed?
%p

View file

@ -24,6 +24,7 @@
Artikelverwaltung
%ul
%li= link_to "Artikel aktualisieren", suppliers_path
%li= link_to "Lagerverwaltung", :controller => 'stockit'
%li= link_to "Lieferanten verwalten", suppliers_path
// Finance

View file

@ -1,6 +1,6 @@
Liebe <%= group.name %>,
die Bestellung für "<%= order.supplier.name %>" wurde am <%= order.ends.strftime('%d.%m.%Y um %H:%M') %> von <%= order.updated_by.nick %> beendet.
die Bestellung für "<%= order.name %>" wurde am <%= order.ends.strftime('%d.%m.%Y um %H:%M') %> von <%= order.updated_by.nick %> beendet.
Für Euch wurden die folgenden Artikel bestellt:
<% for group_order_article in group_order.group_order_articles.all(:include => :order_article)

View file

@ -11,7 +11,7 @@
- group_order = order.group_order(@ordergroup) # Get GroupOrder if possible
- order_class = group_order ? "" : "color:grey"
%tr{:class=> cycle('even', 'odd', :name => 'orders'), :style => order_class}
%td= link_to order.supplier.name, :action => 'my_order_result', :id => order
%td= link_to order.name, :action => 'my_order_result', :id => order
%td= format_time(order.ends)
%td{:class => "currency"}= group_order ? number_to_currency(group_order.price) : "--"

View file

@ -1,10 +1,10 @@
- title "Dein Bestellergebnis für #{@order.supplier.name}"
- title "Dein Bestellergebnis für #{@order.name}"
#element_navigation
= link_to_unless @order.previous == @order, "<< #{@order.previous.supplier.name}", :action => "my_order_result", :id => @order.previous
= link_to_unless @order.previous == @order, "<< #{@order.previous.name}", :action => "my_order_result", :id => @order.previous
|
= link_to _("Overview"), :controller => 'ordering'
|
= link_to_unless @order.next == @order, "#{@order.next.supplier.name} >>", :action => "my_order_result", :id => @order.next
= link_to_unless @order.next == @order, "#{@order.next.name} >>", :action => "my_order_result", :id => @order.next
// Order summary
.left_column{:style => "width:45em"}
@ -16,7 +16,7 @@
%td{:style => "width:50%"}
%p
Lieferant:
%b=h @order.supplier.name
%b=h @order.name
- unless @order.note.blank?
%p
Notiz:
@ -43,7 +43,7 @@
%table
- for order in Order.open
%tr
%td= link_to order.supplier.name, :action => 'order', :id => order
%td= link_to order.name, :action => 'order', :id => order
%td= "("+ time_ago_in_words(order.ends) + ")" if order.ends
// Article box

View file

@ -1,33 +1,33 @@
<h1>Bestellen</h1>
<div class="left_column" style="width:49em">
<div class="box_title"><h2><%=h @order.supplier.name %></h2></div>
<div class="box_title"><h2><%=h @order.name %></h2></div>
<div class="column_content">
<table>
<tr valign="top">
<td width="60%">
<p><b><%=_ "Supplier" %>:</b> <%=h @order.supplier.name %></p>
<p><b><%=_ "End" %>:</b> <%=h format_time(@order.ends) %></p>
<p><b>Lieferant:</b> <%=h @order.name %></p>
<p><b>Ende:</b> <%=h format_time(@order.ends) %></p>
<% if @group_order && @group_order.updated_by -%>
<p><b><%=_ "person ordered at last" %>:</b> <%=h @group_order.updated_by.nick if @group_order.updated_by %> (<%= format_time(@group_order.updated_on) %>)</p>
<p><b>Zuletzt bestellt:</b> <%=h @group_order.updated_by.nick if @group_order.updated_by %> (<%= format_time(@group_order.updated_on) %>)</p>
<% end -%>
<p><b><%=_ "Credit available"%>:</b> <%= number_to_currency(@availableFunds) %></p>
<p><b>Verfügbares Guthaben:</b> <%= number_to_currency(@availableFunds) %></p>
</td>
<td>
<% unless @order.note.empty? %>
<p>
<b><%=_ "Note" %>:</b>
<b>Notiz:</b>
</p>
<%= simple_format(@order.note) %>
<% end %>
<% unless @order.supplier.min_order_quantity.nil? || @order.supplier.min_order_quantity.empty? %>
<% unless @order.stockit? || @order.supplier.min_order_quantity.blank? -%>
<p>
<b><%=_ "Minimum order quantity" %>:</b>
<b>Mindestellmenge:</b>
<%=h @order.supplier.min_order_quantity %>
</p>
<% end %>
<% end -%>
<p>
<b><%=_ "Order quanitity so far" %>:</b>
<b>Gesamtbestellmenge bisher:</b>
<%= number_to_currency @order.sum %>
</p>
</td>
@ -39,14 +39,14 @@
<%- if !@other_orders.empty? -%>
<div class="right_column" style="width:22em">
<div class="box_title">
<h2><%=_ "Other orders" %></h2>
<h2>Andere Bestellungen</h2>
</div>
<div class="column_content">
<table>
<% for order in @other_orders -%>
<tr>
<td>
<%= link_to_function order.supplier.name, "if (confirmSwitchOrder()) (window.location = '#{ url_for(:action => 'order', :id => order) }' )" %>
<%= link_to_function order.name, "if (confirmSwitchOrder()) (window.location = '#{ url_for(:action => 'order', :id => order) }' )" %>
</td>
<td>noch <%= time_ago_in_words(order.ends) if order.ends -%></td>
</tr>
@ -61,21 +61,23 @@
<div class="single_column">
<% form_tag(:action => 'saveOrder', :id => @order) do %>
<div class="box_title">
<h2><%=_ "Articles" %></h2>
<h2>Artikel</h2>
</div>
<div class="column_content">
<table id="order" class="list">
<thead>
<tr>
<th><%=_ "Name" %></th>
<th>Name</th>
<th></th>
<th><%=_ "Manufacturer" %></th>
<th style="width:7em;"><%=_ "Package" %></th>
<th style="width:4.5em;"><%=_ "Price" %></th>
<th id="col_packages"><acronym title="<%=_ "totally ordered packages" %>"><%=_ "Ord."%></acronym></th>
<th id="col_required"><%=_ "Quantity" %></th>
<th id="col_tolerance"><%=_ "Tolerance" %></th>
<th><%=_ "Amount" %></th>
<th>Herstellerin</th>
<th style="width:7em;"><%= @order.stockit? ? "im Lager" : "Gebinde" -%></th>
<th style="width:4.5em;">Preis</th>
<th id="col_packages"><acronym title="insgesamt bestellte Gebinde">Best</acronym></th>
<th id="col_required">Menge</th>
<% unless @order.stockit? -%>
<th id="col_tolerance">Toleranz</th>
<% end -%>
<th>Summe</th>
</tr>
</thead>
<tbody>
@ -104,7 +106,7 @@
</td>
<td><%=h order_article.article.origin %></td>
<td><%=h truncate order_article.article.manufacturer, :length => 11 %></td>
<td><%= @unit[i] %> * <%=h order_article.article.unit %></td>
<td><%= @order.stockit? ? order_article.article.quantity_available : @unit[i] %> * <%=h order_article.article.unit %></td>
<td><%= number_to_currency(@price[i]) %></td>
<td id="units_<%= i %>"><%= order_article.units_to_order %></td>
<td style="text-align:right;">

View file

@ -7,7 +7,7 @@
= form.hidden_field :supplier_id
%p
Lieferant:
= @order.supplier.name
= @order.name
%p
Notiz
%br/
@ -31,7 +31,7 @@
%option{:value => "-1", :selected => "selected"}=_ "Choose an order..."
- i = -1
- for order in @template_orders
%option{:value => (i += 1)}= "#{h(order.supplier.name)} bis #{order.ends.strftime('%d. %b')}"
%option{:value => (i += 1)}= "#{h(order.name)} bis #{order.ends.strftime('%d. %b')}"
%table.list
%tr
%th= check_box_tag 'checkall', "1", false, { :onclick => "checkUncheckAll(this)" }
@ -41,7 +41,7 @@
%th=_ "Manufacturer"
%th=_ "Unit quantity"
%th=_ "Price"
- for category_name, articles in @order.supplier.get_articles_for_ordering
- for category_name, articles in @order.articles_for_ordering
%tr{:style => "background-color:#EFEFEF"}
%td
%td{:colspan => "6", :style => "text-align:left"}
@ -65,6 +65,3 @@
- if (@template_orders && !@template_orders.empty?)
= render :partial => 'template_orders_script'

View file

@ -12,7 +12,7 @@
%tbody
- @orders.each do |order|
%tr{:class => cycle('even', 'odd', :name => 'orders')}
%td=h order.supplier.name
%td=h order.name
%td=h format_time(order.starts)
%td=h format_time(order.ends)
%td= order.state

View file

@ -1,5 +1,5 @@
end_date = @order.ends.strftime('%d.%m.%Y')
title = "#{@order.supplier.name} | beendet am #{end_date}"
title = "#{@order.name} | beendet am #{end_date}"
# Define header and footer
pdf.header [pdf.margin_box.left,pdf.margin_box.top+30] do

View file

@ -25,7 +25,7 @@ end
# Recipient
pdf.bounding_box [pdf.margin_box.left,pdf.margin_box.top-60], :width => 200 do
pdf.text @order.supplier.name
pdf.text @order.name
pdf.move_down 5
pdf.text @order.supplier.address
pdf.move_down 5

View file

@ -1,5 +1,5 @@
end_date = @order.ends.strftime('%d.%m.%Y')
title = "Gruppensortierung für #{@order.supplier.name}, beendet am #{end_date}"
title = "Gruppensortierung für #{@order.name}, beendet am #{end_date}"
# Define header and footer
pdf.header [pdf.margin_box.left,pdf.margin_box.top+20] do

View file

@ -24,7 +24,7 @@
- for order in @open_orders
- active = (order.open? and order.ends < Time.now) ? " active" : ""
%tr{:class => cycle('even', 'odd', :name => 'open_orders') + active}
%td=h order.supplier.name
%td=h order.name
%td=h format_time(order.ends) unless order.ends.nil?
%td=h truncate(order.note)
%td= link_to "Beenden", finish_order_path(order), :confirm => _("Are you really sure to finish the order?"), :method => :post

View file

@ -1,4 +1,4 @@
title = "#{@order.supplier.name}, beendet am #{@order.ends.strftime('%d.%m.%Y')}"
title = "#{@order.name}, beendet am #{@order.ends.strftime('%d.%m.%Y')}"
# Define header and footer
pdf.header [pdf.margin_box.left,pdf.margin_box.top+20] do

View file

@ -1,7 +1,7 @@
- title _("New order")
- title "Neue Bestellung anlegen"
- form_for @order do |form|
= render :partial => 'form', :locals => { :form => form }
= submit_tag _("Put the order online")
= submit_tag "Bestellung online stellen"
|
= link_to "Abbrechen", orders_path

View file

@ -1,10 +1,10 @@
- title _("Show order")
- title "Bestellung: #{@order.name}"
#element_navigation
= link_to_unless @order.previous == @order, "<< #{@order.previous.supplier.name}", @order.previous
= link_to_unless @order.previous == @order, "<< #{@order.previous.name}", @order.previous
|
= link_to _("Overview"), orders_path
|
= link_to_unless @order.next == @order, "#{@order.next.supplier.name} >>", @order.next
= link_to_unless @order.next == @order, "#{@order.next.name} >>", @order.next
// Order summary
.left_column{:style => "width:65em"}
@ -16,7 +16,7 @@
%b{:style => "color:red"}=_ "Order isn't closed yet"
%p
Lieferant:
%b=h @order.supplier.name
%b=h @order.name
- unless @order.note.empty?
%p
Notiz:

View file

@ -13,7 +13,7 @@
- total = 0
- Order.open.each do |order|
%tr{:class => cycle('even', 'odd', :name => 'open_orders')}
%td= link_to h(order.supplier.name), :controller => 'ordering', :action => 'order', :id => order
%td= link_to h(order.name), :controller => 'ordering', :action => 'order', :id => order
%td=h format_time(order.ends) unless order.ends.nil?
- if group_order = order.group_order(@ordergroup)
- total += group_order.price

View file

@ -7,7 +7,8 @@
options_for_select([" -- Lieferantin wählen --", ""] + |
Supplier.find(:all).collect {|s| [ s.name, url_for(new_supplier_delivery_path(s))] }), |
:onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;" |
%p
= link_to "Lagerbestellung online stellen", new_order_path(:supplier_id => 0)
%p
%table.list
%thead

View file

@ -4,6 +4,8 @@ ActionController::Routing::Routes.draw do |map|
map.my_tasks '/home/tasks', :controller => 'tasks', :action => 'myTasks'
map.resources :orders, :member => { :finish => :post, :add_comment => :post }
map.resources :stock_orders, :member => { :finish => :post, :add_comment => :post },
:controller => 'orders'
map.resources :messages, :only => [:index, :show, :new, :create],
:member => { :reply => :get, :user => :get, :group => :get }

View file

@ -77,10 +77,10 @@ class RefactorOrderLogic < ActiveRecord::Migration
#
# # == GroupOrder
# change_column :group_orders, :updated_by_user_id, :integer, :default => nil, :null => true
# == GroupOrderArticle
# The total order result in ordergroup is now saved!
add_column :group_order_articles, :result, :integer, :default => nil
#
# # == GroupOrderArticle
# # The total order result in ordergroup is now saved!
# add_column :group_order_articles, :result, :integer, :default => nil
end
def self.down

View file

@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20090120184410) do
ActiveRecord::Schema.define(:version => 20090119155930) do
create_table "article_categories", :force => true do |t|
t.string "name", :default => "", :null => false