Simplify balancing view. Part 1 of ...

This commit is contained in:
benni 2012-06-21 17:19:00 +02:00
parent 218f40eb8d
commit 467874a8a5
22 changed files with 128 additions and 170 deletions

View file

@ -3,7 +3,7 @@ class Finance::BalancingController < ApplicationController
before_filter :authenticate_finance before_filter :authenticate_finance
def index def index
@financial_transactions = FinancialTransaction.find(:all, :order => "created_on DESC", :limit => 8) @financial_transactions = FinancialTransaction.order(:created_on.desc).limit(8)
@orders = Order.finished_not_closed @orders = Order.finished_not_closed
@unpaid_invoices = Invoice.unpaid @unpaid_invoices = Invoice.unpaid
end end
@ -48,117 +48,6 @@ class Finance::BalancingController < ApplicationController
end end
end end
def edit_note
@order = Order.find(params[:id])
render :layout => false
end
def update_note
@order = Order.find(params[:id])
if @order.update_attributes(params[:order])
render :layout => false
else
render :action => :edit_note, :layout => false
end
end
def new_order_article
@order = Order.find(params[:id])
render :update do |page|
page["edit_box"].replace_html :partial => "new_order_article"
page["edit_box"].show
end
end
def auto_complete_for_article_name
order = Order.find(params[:order_id])
find_params = {
:conditions => ["LOWER(articles.name) LIKE ?", "%#{params[:article][:name].downcase}%" ],
:order => 'articles.name ASC',
:limit => 8
}
@articles = if order.stockit?
StockArticle.all find_params
else
order.supplier.articles.all find_params
end
render :partial => 'shared/auto_complete_articles'
end
def create_order_article
@order = Order.find(params[:order_id])
article = Article.find(params[:order_article][:article_id])
order_article = @order.order_articles.find_by_article_id(article.id)
unless order_article
# Article wasn't already assigned with this order, lets create a new one
order_article = @order.order_articles.build(params[:order_article])
order_article.article_price = order_article.article.article_prices.first
end
# Set units to order to 1, so the article is visible on page
order_article.units_to_order = 1
render :update do |page|
if order_article.save
page["edit_box"].hide
page.insert_html :top, "result_table", :partial => "order_article_result", :locals => {:order_article => order_article}
page["order_article_#{order_article.id}"].visual_effect :highlight, :duration => 2
page["group_order_articles_#{order_article.id}"].show
else
page["edit_box"].replace_html :partial => "new_order_article"
end
end
rescue
render :update do |page|
page.replace_html "edit_box", :text => "<b>Keinen Artikel gefunden. Bitte erneut versuchen.</b>"
page.insert_html :bottom, "edit_box", :partial => "new_order_article"
end
end
def edit_order_article
@order_article = OrderArticle.find(params[:id])
render :update do |page|
page["edit_box"].replace_html :partial => 'edit_order_article'
page["edit_box"].show
end
end
# Update this article and creates a new articleprice if neccessary
def update_order_article
@order_article = OrderArticle.find(params[:id])
begin
@order_article.update_article_and_price!(params[:article], params[:price], params[:order_article])
render :update do |page|
page["edit_box"].hide
page["summary"].replace_html :partial => 'summary', :locals => {:order => @order_article.order}
page["summary"].visual_effect :highlight, :duration => 2
page["order_article_#{@order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => @order_article}
page["order_article_#{@order_article.id}"].visual_effect :highlight, :delay => 0.5, :duration => 2
page["group_order_articles_#{@order_article.id}"].replace_html :partial => "group_order_articles", :locals => {:order_article => @order_article}
end
rescue => @error
render :update do |page|
page['edit_box'].replace_html :partial => 'edit_order_article'
end
end
end
def destroy_order_article
order_article = OrderArticle.find(params[:id])
order_article.destroy
# Updates ordergroup values
order_article.group_order_articles.each { |goa| goa.group_order.update_price! }
render :update do |page|
page["order_article_#{order_article.id}"].remove
page["group_order_articles_#{order_article.id}"].remove
page["summary"].replace_html :partial => 'summary', :locals => {:order => order_article.order}
page["summary"].visual_effect :highlight, :duration => 2
end
end
def new_group_order_article def new_group_order_article
goa = 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|

View file

@ -0,0 +1,10 @@
class Finance::GroupOrderArticlesController < ApplicationController
before_filter :authenticate_finance
layout false # We only use this controller to server js snippets, no need for layout rendering
def new
@order_article = OrderArticle.find(params[:order_article_id])
end
end

View file

@ -0,0 +1,39 @@
class Finance::OrderArticlesController < ApplicationController
before_filter :authenticate_finance
layout false # We only use this controller to server js snippets, no need for layout rendering
def new
@order = Order.find(params[:order_id])
@order_article = @order.order_articles.build
end
def create
@order = Order.find(params[:order_id])
@order_article = @order.order_articles.build(params[:order_article])
unless @order_article.save
render action: :new
end
end
def edit
@order = Order.find(params[:order_id])
@order_article = OrderArticle.find(params[:id])
end
def update
@order = Order.find(params[:order_id])
@order_article = OrderArticle.find(params[:id])
begin
@order_article.update_article_and_price!(params[:article], params[:price], params[:order_article])
rescue
render action: :edit
end
end
def destroy
@order_article = OrderArticle.find(params[:id])
@order_article.destroy
end
end

View file

@ -0,0 +1,2 @@
module Finance::OrderArticlesHelper
end

View file

@ -8,9 +8,12 @@ class OrderArticle < ActiveRecord::Base
validates_presence_of :order_id, :article_id validates_presence_of :order_id, :article_id
validate :article_and_price_exist validate :article_and_price_exist
validates_uniqueness_of :article_id, scope: :order_id
scope :ordered, :conditions => "units_to_order >= 1" scope :ordered, :conditions => "units_to_order >= 1"
before_create :init_from_balancing
after_destroy :update_ordergroup_prices
# This method returns either the ArticlePrice or the Article # This method returns either the ArticlePrice or the Article
# The first will be set, when the the order is finished # The first will be set, when the the order is finished
@ -112,6 +115,19 @@ class OrderArticle < ActiveRecord::Base
errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.fc_price.nil? errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.fc_price.nil?
end end
# Associate with current article price if created in a finished order
def init_from_balancing
if order.present? and order.finished?
self.article_price = article.article_prices.first
self.units_to_order = 1
end
end
#TODO: Delayed job maybe??
def update_ordergroup_prices
group_order_articles.each { |goa| goa.group_order.update_price! }
end
end end
# == Schema Information # == Schema Information

View file

@ -1,7 +1,7 @@
%p{:style => "float:left"} %p{:style => "float:left"}
%b Lieferung bearbeiten %b Lieferung bearbeiten
%p{:style => "float:right"} %p{:style => "float:right"}
/= remote_link_to "Artikel hinzufügen", :url => {:action => "new_order_article", :id => @order} = link_to "Artikel hinzufügen", new_finance_order_order_article_path(@order), remote: true
%table{:class => "ordered_articles", :style => "clear:both"} %table{:class => "ordered_articles", :style => "clear:both"}
%thead %thead

View file

@ -7,8 +7,8 @@
%td Einheiten %td Einheiten
%td Gesamtpreis %td Gesamtpreis
%td{:colspan => "3",:style => "width:14em"} %td{:colspan => "3",:style => "width:14em"}
= link_to '[Gruppe hinzufügen]', '#' = link_to '[Gruppe hinzufügen]', new_finance_group_order_article_path(order_id: order_article.order_id),
/:url => {:action => "new_group_order_article", :id => order_article} remote: true
%tbody %tbody
- for group_order_article in order_article.group_order_articles.ordered.all(:include => [:group_order]) - for group_order_article in order_article.group_order_articles.ordered.all(:include => [:group_order])
%tr{:class => cycle('even', 'odd', :name => 'results')}[group_order_article] %tr{:class => cycle('even', 'odd', :name => 'results')}[group_order_article]

View file

@ -1,15 +0,0 @@
%h2
Neuer gelieferter Artikel die Bestellung
- remote_form_for :order_article, :url => {:action => 'create_order_article', :order_id => @order.id}, |
:before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| |
%p
Suche im Katalog
= text_field_with_auto_complete :article, :name, {}, |
{:url => {:action => 'auto_complete_for_article_name', :order_id => @order.id}, |
:after_update_element => 'setHiddenId'} |
%p
= form.hidden_field :article_id, :id => 'hidden_id'
= submit_tag "Neuen Artikel hinzufügen"
|
= link_to_function "Abbrechen", "Element.hide('edit_box')"

View file

@ -1,7 +1,5 @@
%td.closed %td.closed
= link_to order_article.article.name, '#' = link_to order_article.article.name, '#', 'data-toggle-this' => "#group_order_articles_#{order_article.id}"
/"Element.toggle('group_order_articles_#{order_article.id}'); |
/Element.toggleClassName(this.up('td'), 'open')" |
%td= order_article.article.order_number %td= order_article.article.order_number
%td %td
= order_article.units_to_order = order_article.units_to_order
@ -21,10 +19,7 @@
%td= order_article.price.tax %td= order_article.price.tax
%td= order_article.price.deposit %td= order_article.price.deposit
%td %td
= link_to icon(:edit), '#' = link_to icon(:edit), edit_finance_order_order_article_path(@order, order_article), remote: true
/:url => {:action => 'edit_order_article', :id => order_article} |
%td %td
= link_to icon(:delete), '#' = link_to icon(:delete), finance_order_order_article_path(@order, order_article), method: :delete,
/:confirm => 'Bist du sicher?' remote: true, confirm: 'Bist du sicher?'
/:url => {:action => 'destroy_order_article', :id => order_article},
/:method => :post

View file

@ -1,26 +0,0 @@
- if @error
%b= @error
%table
%tr
%th Name
%th Nr.
%th
%abbr{:title=>"Anzahl gelieferter Gebinde"} Menge
%th Einheit
%th GebGr
%th Netto
%th MwSt.
%th Pfand
%tr
%td= text_field_tag 'article[name]', @order_article.article.name, :size => 20
%td= text_field_tag 'article[order_number]', @order_article.article.order_number, :size => 3
%td= text_field_tag 'order_article[units_to_order]', @order_article.units_to_order, :size => 5
%td= text_field_tag 'article[unit]', @order_article.article.unit, :size => 5
%td= text_field_tag 'price[unit_quantity]', @order_article.price.unit_quantity, :size => 3
%td= text_field_tag 'price[price]', @order_article.price.price, :size => 3
%td= text_field_tag 'price[tax]', @order_article.price.tax, :size => 3
%td= text_field_tag 'price[deposit]', @order_article.price.deposit, :size => 3
%br/
= submit_tag "Speichern"
|
= link_to_function 'Abbrechen', "Element.hide('edit_box')"

View file

@ -1,5 +1,5 @@
%tr{:class => cycle('even', 'odd', :name => 'articles')}[order_article] %tr{:class => cycle('even', 'odd', :name => 'articles')}[order_article]
= render :partial => 'order_article', :locals => {:order_article => order_article} = render :partial => 'finance/balancing/order_article', :locals => {:order_article => order_article}
%tr{:id => "group_order_articles_#{order_article.id}", :class => "results", :style => "display:none"} %tr{:id => "group_order_articles_#{order_article.id}", :class => "results", :style => "display:none"}
= render :partial => 'group_order_articles', :locals => {:order_article => order_article} = render :partial => 'finance/balancing/group_order_articles', :locals => {:order_article => order_article}

View file

@ -43,7 +43,7 @@
.box_title .box_title
%h2 noch nicht abgerechnet %h2 noch nicht abgerechnet
.column_content .column_content
%p= link_to "Bestellungsübersicht", :controller => 'balancing', :action => 'list' %p= link_to "Bestellungsübersicht", finance_balancing_path
- unless @orders.empty? - unless @orders.empty?
%table.list %table.list
%thead %thead
@ -58,6 +58,6 @@
%td= order.name %td= order.name
%td= format_date(order.ends) %td= format_date(order.ends)
%td{:class => "currency"}= number_to_currency(order.sum(:fc)) %td{:class => "currency"}= number_to_currency(order.sum(:fc))
%td= link_to "abrechnen", :action => "new", :id => order %td= link_to "abrechnen", new_finance_order_path(id: order)
- else - else
Super, alles schon abgerechnet... Super, alles schon abgerechnet...

View file

@ -0,0 +1,26 @@
%h2 Artikel aktualisieren
= form_for [:finance, @order, @order_article], remote: true do |form|
= @order_article.errors.try(:full_messages)
%table
%tr
%th Name
%th Nr.
%th
%abbr{:title=>"Anzahl gelieferter Gebinde"} Menge
%th Einheit
%th GebGr
%th Netto
%th MwSt.
%th Pfand
%tr
%td= text_field_tag 'article[name]', @order_article.article.name, :size => 20
%td= text_field_tag 'article[order_number]', @order_article.article.order_number, :size => 3
%td= text_field_tag 'order_article[units_to_order]', @order_article.units_to_order, :size => 5
%td= text_field_tag 'article[unit]', @order_article.article.unit, :size => 5
%td= text_field_tag 'price[unit_quantity]', @order_article.price.unit_quantity, :size => 3
%td= text_field_tag 'price[price]', @order_article.price.price, :size => 3
%td= text_field_tag 'price[tax]', @order_article.price.tax, :size => 3
%td= text_field_tag 'price[deposit]', @order_article.price.deposit, :size => 3
%br/
= submit_tag "Speichern"

View file

@ -0,0 +1,6 @@
%h2
Neuer gelieferter Artikel die Bestellung
= simple_form_for [:finance, @order, @order_article], remote: true do |form|
= form.input :article_id, as: :select, collection: @order.supplier.articles.order(:name)
= form.submit

View file

@ -0,0 +1,3 @@
$.fancybox.close();
$('#result_table').
prepend('<%= escape_javascript(render(partial: 'finance/balancing/order_article_result', locals: {order_article: @order_article}))%>');

View file

@ -0,0 +1 @@
$('#order_article_<%= @order_article.id %>, #group_order_articles_<%= @order_article.id %>').hide();

View file

@ -0,0 +1 @@
$.fancybox('<%= escape_javascript(render("edit")) %>');

View file

@ -0,0 +1 @@
$.fancybox('<%= escape_javascript(render("new")) %>');

View file

@ -0,0 +1,3 @@
$.fancybox.close();
$('#order_article_<%= @order_article.id %>').
html('<%= escape_javascript(render(partial: 'finance/balancing/order_article', locals: {order_article: @order_article})) %>');

View file

@ -51,7 +51,7 @@ development: &defaults
# Access to sharedLists, the external article-database # Access to sharedLists, the external article-database
shared_lists: shared_lists:
adapter: mysql adapter: mysql2
host: localhost host: localhost
database: sharedlists_development database: sharedlists_development
username: root username: root

View file

@ -221,6 +221,7 @@ de:
financial_transaction: Kontotransaktion financial_transaction: Kontotransaktion
order: Bestellung order: Bestellung
order_comment: Kommentar order_comment: Kommentar
order_article: Bestell-Artikel
attributes: attributes:
article: article:
price: Nettopreis price: Nettopreis
@ -345,6 +346,8 @@ de:
order: order:
starts: "Läuft vom" starts: "Läuft vom"
ends: "Endet am" ends: "Endet am"
order_article:
article_id: Artikel aus dem Katalog wählen
invoice: invoice:
supplier: Lieferant supplier: Lieferant
number: Nummer number: Nummer

View file

@ -125,8 +125,12 @@ Foodsoft::Application.routes.draw do
get :edit_note get :edit_note
put :update_note put :update_note
end end
resources :order_articles
end end
resources :group_order_articles
match 'balancing/list' => 'balancing#list', :as => 'balancing' match 'balancing/list' => 'balancing#list', :as => 'balancing'
resources :invoices resources :invoices