Refactored ordering part two. Integrated stock order.

This commit is contained in:
benni 2011-06-19 19:56:04 +02:00
parent eb4705857b
commit 38b5dcba1f
17 changed files with 177 additions and 374 deletions

View file

@ -1,25 +0,0 @@
<script>
//<![CDATA[
$(function() {
<% for row in data_to_js(@ordering_data) %>
addData(<%= row.join(", ") %>);
<% end %>
setGroupBalance(<%= @ordering_data[:available_funds] %>);
// localization
setDecimalSeparator(",");
// configuration
setToleranceBehaviour(<%= Foodsoft.config[:tolerance_is_costly] %>);
// initialize javascript
updateBalance();
// show article info on row hover
<%#*$$('tbody tr').observer('hover', function() {%>
<%#*});%>
});
//]]>
</script>

View file

@ -1,23 +0,0 @@
#order-footer
#info-box
#total-sum
%table
%tr
%td Gesamtbetrag:
%td.currency
%span#total_price= total
%tr
%td Verfügbares Guthaben:
%td.currency= number_to_currency(@ordering_data[:available_funds])
%tr
%td Neuer Kontostand:
%td.currency
%strong
%span#new_balance= @ordergroup.account_balance - total
#order-button
= submit_tag( "Bestellung speichern", :id => 'submit_button' )
oder #{link_to "abbrechen", :controller => 'ordering'}
%input#total_balance{:name => "total_balance", :type => "hidden", :value => @ordergroup.account_balance - total}/
%input{:name => "version", :type => "hidden", :value => @version}/

View file

@ -1,9 +1,52 @@
- content_for :head do
= render 'data'
:javascript
$(function() {
#{data_to_js(@ordering_data)}
setGroupBalance(#{@ordering_data[:available_funds]});
setDecimalSeparator(",");
setToleranceBehaviour(#{Foodsoft.config[:tolerance_is_costly]});
setStockit(#{@order.stockit?});
});
= render :partial => 'order_head'
- title "Bestellen"
- form_for @group_order do |f|
.left_column{:style => "width:49em"}
.box_title
%h2=h @order.name
.column_content
%table
%tr{:valign => "top"}
%td{:width => "60%"}
%p
%b Lieferantin:
=h @order.name
%p
%b Ende:
=h format_time(@order.ends)
- if @group_order && @group_order.updated_by
%p
%b Zuletzt bestellt:
=h @group_order.updated_by.nick if @group_order.updated_by
= "(#{format_time(@group_order.updated_on)})"
%p
%b Verfügbares Guthaben:
= number_to_currency(@ordering_data[:available_funds])
%td
- unless @order.note.empty?
%p
%b Notiz:
= simple_format(@order.note)
- unless @order.stockit? || @order.supplier.min_order_quantity.blank?
%p
%b Mindestellmenge:
=h @order.supplier.min_order_quantity
%p
%b Gesamtbestellmenge bisher:
= number_to_currency @order.sum
= render :partial => 'switch_order', :locals => {:current_order => @order}
= form_for @group_order do |f|
= f.hidden_field :lock_version
= f.hidden_field :order_id
= f.hidden_field :updated_by_user_id
@ -19,36 +62,32 @@
%th{:style => "width:13px;"}
%th{:style => "width:4.5em;"} Preis
%th{:style => "width:4.5em;"} Einheit
%th{:style => "width:70px;"} Fehlende Einheiten
%th#col_required Menge
- if not @order.stockit?
- unless @order.stockit?
%th{:style => "width:70px;"} Fehlende Einheiten
%th#col_required Menge
%th#col_tolerance Toleranz
- else
%th(style="width:20px") Verfügbar
%th#col_required Menge
%th{:style => "width:15px;"} Summe
%tbody
- total = 0
- @order.articles_grouped_by_category.each do |category, order_articles|
%tr{:style => "background-color:#EFEFEF"}
%td{:style => "text-align:left"}
%b= h category
%td{:colspan => "9"}
- order_articles.each do |order_article|
- if Foodsoft.config[:tolerance_is_costly]
- article_total = @ordering_data[:order_articles][order_article.id][:price] * (@ordering_data[:order_articles][order_article.id][:tolerance] + @ordering_data[:order_articles][order_article.id][:quantity])
- else
- article_total = @ordering_data[:order_articles][order_article.id][:price] * @ordering_data[:order_articles][order_article.id][:quantity]
- total += article_total
%tr{:class => "#{cycle('even', 'odd', :name => 'articles')} order-article", :valign => "top"}
%td.name= order_article.article.name
%td= h order_article.article.origin
%td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price])
%td= order_article.article.unit
%td
%span{:id => "missing_units_#{order_article.id}"}
- if @order.stockit?
- order_article.article.quantity_available
- else
- missing_units = @ordering_data[:order_articles][order_article.id][:unit] - (((@ordering_data[:order_articles][order_article.id][:quantity] + @ordering_data[:order_articles][order_article.id][:others_quantity]) % @ordering_data[:order_articles][order_article.id][:unit]) + @ordering_data[:order_articles][order_article.id][:tolerance] + @ordering_data[:order_articles][order_article.id][:others_tolerance])
- missing_units < 0 ? 0 : missing_units
- if @order.stockit?
= @ordering_data[:order_articles][order_article.id][:quantity_available]
- else
%span{:id => "missing_units_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:missing_units]
%td.quantity
%input{:id => "q_#{order_article.id}", :name => "group_order[group_order_articles_attributes][#{order_article.id}][quantity]", :size => "2", :type => "hidden", :value => @ordering_data[:order_articles][order_article.id][:quantity]}/
%span.used{:id => "q_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_quantity]
@ -56,17 +95,18 @@
%span.unused{:id => "q_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:quantity] - @ordering_data[:order_articles][order_article.id][:used_quantity]
%input{:type => 'button', :value => '+', 'data-increase_quantity' => order_article.id}
%input{:type => 'button', :value => '-', 'data-decrease_quantity' => order_article.id}
- unless @order.stockit?
%td.tolerance
%input{:id => "t_#{order_article.id}", :name => "group_order[group_order_articles_attributes][#{order_article.id}][tolerance]", :size => "2", :type => "hidden", :value => @ordering_data[:order_articles][order_article.id][:tolerance]}/
- if (@ordering_data[:order_articles][order_article.id][:unit] > 1)
%span.used{:id => "t_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_tolerance]
+
%span.unused{:id => "t_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance]
%input{:type => 'button', :value => '+', 'data-increase_tolerance' => order_article.id}
%input{:type => 'button', :value => '-', 'data-decrease_tolerance' => order_article.id}
%td.tolerance{:style => ('display:none' if @order.stockit?)}
%input{:id => "t_#{order_article.id}", :name => "group_order[group_order_articles_attributes][#{order_article.id}][tolerance]", :size => "2", :type => "hidden", :value => @ordering_data[:order_articles][order_article.id][:tolerance]}/
- if (@ordering_data[:order_articles][order_article.id][:unit] > 1)
%span.used{:id => "t_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_tolerance]
+
%span.unused{:id => "t_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance]
%input{:type => 'button', :value => '+', 'data-increase_tolerance' => order_article.id}
%input{:type => 'button', :value => '-', 'data-decrease_tolerance' => order_article.id}
%td{:id => "td_price_#{order_article.id}", :style => "text-align:right; padding-right:10px; width:4em"}
%span{:id => "price_#{order_article.id}_display"}= number_to_currency(article_total, :unit => "")
%span{:id => "price_#{order_article.id}_display"}= number_to_currency(@ordering_data[:order_articles][order_article.id][:total_price], :unit => "")
.article-info
%h3= order_article.article.name
@ -87,4 +127,26 @@
%br/
Notiz: #{order_article.article.note}
%br/
= render "footer", :total => total
#order-footer
#info-box
#total-sum
%table
%tr
%td Gesamtbetrag:
%td.currency
%span#total_price= @group_order.price
%tr
%td Verfügbares Guthaben:
%td.currency= number_to_currency(@ordering_data[:available_funds])
%tr
%td Neuer Kontostand:
%td.currency
%strong
%span#new_balance= @ordergroup.account_balance - @group_order.price
#order-button
= submit_tag( "Bestellung speichern", :id => 'submit_button' )
oder #{link_to "abbrechen", :controller => 'ordering'}
%input#total_balance{:name => "total_balance", :type => "hidden", :value => @ordergroup.account_balance - @group_order.price}/
%input{:name => "version", :type => "hidden", :value => @version}/

View file

@ -1,25 +0,0 @@
<div id="order-footer">
<div id="info-box">
</div>
<div id="total-sum">
<table>
<tr>
<td>Gesamtbetrag:</td>
<td class="currency"><span id="total_price"><%= total %></span> €</td>
</tr>
<tr>
<td>Verfügbares Guthaben:</td>
<td class="currency"><%= number_to_currency(@availableFunds) %></td>
</tr>
<tr>
<td>Neuer Kontostand:</td>
<td class="currency"><strong><span id="new_balance"><%= @ordergroup.account_balance - total %></span> €</strong></td>
</tr>
</table>
<div id="order-button">
<%= submit_tag( "Bestellung speichern", :id => 'submit_button' ) %></span> oder <%= link_to "abbrechen", :controller => 'ordering' %>
</div>
</div>
</div>
<input type="hidden" id="total_balance" name="total_balance" value="<%= @ordergroup.account_balance - total %>"/>
<input type="hidden" name="version" value="<%= @version %>"/>

View file

@ -1,48 +0,0 @@
- title "Bestellen"
.left_column{:style => "width:49em"}
.box_title
%h2=h @order.name
.column_content
%table
%tr{:valign => "top"}
%td{:width => "60%"}
%p
%b Lieferantin:
=h @order.name
%p
%b Ende:
=h format_time(@order.ends)
- if @group_order && @group_order.updated_by
%p
%b Zuletzt bestellt:
=h @group_order.updated_by.nick if @group_order.updated_by
= "(#{format_time(@group_order.updated_on)})"
%p
%b Verfügbares Guthaben:
= number_to_currency(@ordering_data[:available_funds])
%td
- unless @order.note.empty?
%p
%b Notiz:
= simple_format(@order.note)
- unless @order.stockit? || @order.supplier.min_order_quantity.blank?
%p
%b Mindestellmenge:
=h @order.supplier.min_order_quantity
%p
%b Gesamtbestellmenge bisher:
= number_to_currency @order.sum
- orders = Order.open.reject{ |order| order == @order }
- unless orders.empty?
.right_column{:style => "width:22em"}
.box_title
%h2 Anderer Bestellungen
.column_content
%table
- for order in orders
%tr
%td
= link_to_function order.name, "if (confirmSwitchOrder()) (window.location = '#{ url_for(:action => 'order', :id => order) }' )"
%td= "noch #{time_ago_in_words(order.ends)}" if order.ends

View file

@ -0,0 +1,12 @@
- orders = Order.open.reject{ |order| order == current_order }
- unless orders.empty?
.right_column{:style => "width:22em"}
.box_title
%h2 Laufende Bestellungen
.column_content
%table
- for order in orders
%tr
%td
= link_to_ordering(order, 'data-confirm_switch_order' => true)
%td= "noch #{time_ago_in_words(order.ends)}" if order.ends

View file

@ -35,16 +35,7 @@
= "Abgerechnet von #{@order.updated_by.nick}"
= link_to "Kommentare lesen/schreiben", "#comments"
// directly switch to active orders
.right_column{:style => "width:23em;"}
.box_title
%h2 Laufende Bestellungen
.column_content
%table
- for order in Order.open
%tr
%td= link_to_ordering(order)
%td= "("+ time_ago_in_words(order.ends) + ")" if order.ends
= render :partial => "switch_order", :locals => {:current_order => @order}
// Article box
.single_column{:style => "clear:both; width:70em;"}

View file

@ -1,75 +0,0 @@
= render :partial => 'order_head'
.single_column{:style => 'clear:both;margin-bottom:7em;'}
- form_tag(:action => 'saveOrder', :id => @order) do
.box_title
%h2 Anderer Bestellungen
.column_content
%table#order.list
%thead
%tr
%th Name
%th
%th Lieferantin
%th{:style => "width:5em;"} Einheit
%th{:style => "width:4.5em;"} Preis
%th(style="width:20px") Verfügbar
%th#col_required(style="width:110px") Menge
%th Summe
%tbody
- total = 0
- i = 0
- for category_name, order_articles in @articles_grouped_by_category
%tr{:style => "background-color:#EFEFEF"}
%td{:style => "text-align:left"}
%b=h category_name
%td{:colspan => "9"}
- for order_article in order_articles
- article_total = @price[i] * @quantity[i]
- total += article_total
%tr{:class => cycle('even', 'odd', :name => 'articles')+' order-article', :valign => "top"}
%td.name= order_article.article.name
%td=h order_article.article.origin
%td=h truncate order_article.article.supplier.name, :length => 11
%td=h order_article.article.unit
%td= number_to_currency @price[i]
%td= @quantity_available[i]
%td{:style => "text-align:right;"}
= hidden_field_tag "ordered[#{order_article.id}][quantity]", @quantity[i], :id => "q_#{i}", :size => "2"
%span.used{:id => "q_used_#{i}"}= @used_quantity[i]
= button_to_function('+', "increaseStockQuantity(#{i})")
= button_to_function('-', "decreaseStockQuantity(#{i})")
%td{:id => "td_price_#{i}", :style => "text-align:right; padding-right:10px; width:4em"}
%span{:id => "price_#{i}_display"}= number_to_currency(article_total, :unit => "")
.article-info
%h3= order_article.article.name
.right
Gesamt-Einheiten:
%span{:id => "q_total_#{i}"}= @quantity[i] + @others_quantity[i]
%br/
.left
Hersteller:
= order_article.article.manufacturer
%br/
Gebinde:
= order_article.article.quantity_available
*
= order_article.article.unit
%br/
Notiz:
= order_article.article.note
%br/
- i = i + 1
= render "order_footer", :total => total
%script{:type => "text/" + "javascript"}
// preset data
- for i in 0...@price.size
= "addData(#{@price[i]}, 1, #{@price[i] * @quantity[i]}, #{@others_quantity[i]}, 0, #{@used_quantity[i]}, #{@quantity_available[i]});"
= "setGroupBalance(#{@availableFunds});"
// localization
setDecimalSeparator(",");
// initialize javascript
updateBalance();