rework group order edit form

* make switch order a menu list
* table more slim
* alert when balance negative instead of making everything red
* search to the right
This commit is contained in:
Philipp Rothmann 2023-02-21 15:08:32 +01:00
parent fec94f9683
commit 657b3e63bc
7 changed files with 159 additions and 157 deletions

View file

@ -179,17 +179,13 @@ function updateBalance() {
var balance = groupBalance - total; var balance = groupBalance - total;
$('#new_balance').html(I18n.l("currency", balance)); $('#new_balance').html(I18n.l("currency", balance));
$('#total_balance').val(I18n.l("currency", balance)); $('#total_balance').val(I18n.l("currency", balance));
// determine bgcolor and submit button state according to balance
var bgcolor = '';
if (balance < minimumBalance) { if (balance < minimumBalance) {
bgcolor = '#FF0000';
$('#submit_button').attr('disabled', 'disabled') $('#submit_button').attr('disabled', 'disabled')
$('#balance-alert').css('display', 'block')
} else { } else {
$('#submit_button').removeAttr('disabled') $('#submit_button').removeAttr('disabled')
} $('#balance-alert').css('display', 'none')
// update bgcolor
for (i in itemTotal) {
$('#td_price_' + i).css('background-color', bgcolor);
} }
} }

View file

@ -11,170 +11,126 @@
var listjsResetPlugin = ['reset', {highlightClass: 'btn-primary'}]; var listjsResetPlugin = ['reset', {highlightClass: 'btn-primary'}];
var listjsDelayPlugin = ['delay', {delayedSearchTime: 500}]; var listjsDelayPlugin = ['delay', {delayedSearchTime: 500}];
new List(document.body, { new List(document.body, {
valueNames: ['name'], valueNames: ['name'],
engine: 'unlist', engine: 'unlist',
plugins: [listjsResetPlugin, listjsDelayPlugin], plugins: [listjsResetPlugin, listjsDelayPlugin],
// make large pages work too (as we don't have paging - articles may disappear!) // make large pages work too (as we don't have paging - articles may disappear!)
page: 10000, page: 10000,
indexAsync: true indexAsync: true
}); });
}); });
- title t('.title'), false - title t('.title'), false
.alert.alert-error#balance-alert{style: ('display:none')}
=t 'group_orders.errors.balance_alert'
.row-fluid .row-fluid
.well.span9
%h2= @order.name
%a(href='#tab1' data-toggle="collapse")
Show Details
#tab1.collapse
%dl.dl-horizontal
- unless @order.note.blank?
%dt= heading_helper Order, :note
%dd= @order.note
%dt= heading_helper Order, :created_by
%dd= show_user_link(@order.created_by)
%dt= heading_helper Order, :ends
%dd= format_time(@order.ends)
%dt= heading_helper Order, :pickup
%dd= format_date(@order.pickup)
- unless @order.stockit? or @order.supplier.min_order_quantity.blank?
%dt= heading_helper Supplier, :min_order_quantity, short: true
%dd= @order.supplier.min_order_quantity
%dt= t '.sum_amount'
%dd= number_to_currency @order.sum
- unless @group_order.new_record?
%dt= heading_helper GroupOrder, :updated_by
%dd
= show_user(@group_order.updated_by)
(#{format_time(@group_order.updated_on)})
%dt= heading_helper Ordergroup, :account_balance
%dd= number_to_currency(@ordering_data[:account_balance])
- unless FoodsoftConfig[:charge_members_manually]
%dt= heading_helper Ordergroup, :available_funds
%dd= number_to_currency(@ordering_data[:available_funds])
.well.span3 .well.span3
= render 'switch_order', current_order: @order = render 'switch_order', current_order: @order
.row-fluid .well.span8
.well.span12 %h2= @order.name
%a(href='#tab1' data-toggle="collapse")
=t '.details'
#tab1.collapse
= render 'order_details'
.form-search.pull-right .form-search.pull-right
.input-append .input-append
= text_field_tag :article, params[:article], placeholder: t('.search_article'), class: 'search-query delayed-search resettable' = text_field_tag :article, params[:article], placeholder: t('.search_article'), class: 'search-query delayed-search resettable'
%button.add-on.btn.reset-search{:type => :button, :title => t('.reset_article_search')} %button.add-on.btn.reset-search{:type => :button, :title => t('.reset_article_search')}
%i.icon.icon-remove %i.icon.icon-remove
= form_for @group_order do |f|
= f.hidden_field :lock_version
= form_for @group_order do |f| = f.hidden_field :order_id
= f.hidden_field :lock_version = f.hidden_field :updated_by_user_id
= f.hidden_field :order_id = f.hidden_field :ordergroup_id
= f.hidden_field :updated_by_user_id %table.table
= f.hidden_field :ordergroup_id %thead
%table.table %tr
%thead %th= heading_helper Article, :name
%tr
%th= heading_helper Article, :name
- if @order.stockit?
%th{style: 'width:120px'}= heading_helper StockArticle, :supplier
%th{style: "width:13px;"}
%th{style: "width:4.5em;"}= t '.price'
%th{style: "width:4.5em;"}= heading_helper Article, :unit
- unless @order.stockit?
%th{style: "width:70px;"}= heading_helper OrderArticle, :missing_units, short: true
%th#col_required= heading_helper GroupOrderArticle, :quantity
%th#col_tolerance= heading_helper GroupOrderArticle, :tolerance
- else
%th(style="width:20px")= heading_helper StockArticle, :available
%th#col_required= heading_helper GroupOrderArticle, :quantity
%th{style: "width:15px;"}= heading_helper GroupOrderArticle, :total_price
%tbody.list
- @order.articles_grouped_by_category.each do |category, order_articles|
%tr.list-heading.article-category
%td
= category
%i.icon-tag
%td{colspan: "9"}
- order_articles.each do |order_article|
%tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article #{get_missing_units_css_class(@ordering_data[:order_articles][order_article.id][:missing_units])}", valign: "top", tabindex: "0"}
%td.name= order_article.article.name
- if @order.stockit? - if @order.stockit?
%td= truncate order_article.article.supplier.name, length: 15 %th{style: 'width:120px'}= heading_helper StockArticle, :supplier
%td= h order_article.article.origin %th{style: "width:13px;"}
%td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price]) %th{style: "width:4.5em;"}= t '.price'
%td= order_article.article.unit %th{style: "width:4.5em;"}= heading_helper Article, :unit
%td - unless @order.stockit?
- if @order.stockit? %th{style: "width:70px;"}= heading_helper OrderArticle, :missing_units, short: true
= @ordering_data[:order_articles][order_article.id][:quantity_available] %th#col_required= heading_helper GroupOrderArticle, :quantity
- else %th#col_tolerance= heading_helper GroupOrderArticle, :tolerance
%span{id: "missing_units_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:missing_units] - else
%th(style="width:20px")= heading_helper StockArticle, :available
%th#col_required= heading_helper GroupOrderArticle, :quantity
%th{style: "width:15px;"}= heading_helper GroupOrderArticle, :total_price
%tbody.list
- @order.articles_grouped_by_category.each do | category, order_articles|
%tr.list-heading.article-category
%td
= category
%i.icon-tag
%td{colspan: "9"}
- order_articles.each do |order_article|
%tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article #{get_missing_units_css_class(@ordering_data[:order_articles][order_article.id][:missing_units])}", valign: "top", tabindex: "0"}
%td.name= order_article.article.name
- if @order.stockit?
%td= truncate order_article.article.supplier.name, length: 15
%td= h order_article.article.origin
%td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price])
%td= order_article.article.unit
%td
- 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 %td.quantity
%input{id: "q_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][quantity]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:quantity], 'data-min' => (@ordering_data[:order_articles][order_article.id][:quantity] if @order.boxfill?), 'data-max' => (@ordering_data[:order_articles][order_article.id][:quantity]+@ordering_data[:order_articles][order_article.id][:missing_units] if @order.boxfill?)}/ %input{id: "q_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][quantity]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:quantity], 'data-min' => (@ordering_data[:order_articles][order_article.id][:quantity] if @order.boxfill?), 'data-max' => (@ordering_data[:order_articles][order_article.id][:quantity]+@ordering_data[:order_articles][order_article.id][:missing_units] if @order.boxfill?)}/
%span.used{id: "q_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_quantity] %span.used{id: "q_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_quantity]
+ +
%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] %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]
.btn-group .btn-group
%a.btn.btn-ordering{'data-decrease_quantity' => order_article.id} %a.btn.btn-ordering{'data-decrease_quantity' => order_article.id}
%i.icon-minus %i.icon-minus
%a.btn.btn-ordering{'data-increase_quantity' => order_article.id} %a.btn.btn-ordering{'data-increase_quantity' => order_article.id}
%i.icon-plus %i.icon-plus
%td.tolerance{style: ('display:none' if @order.stockit?)} %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]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:tolerance], 'data-min' => (@ordering_data[:order_articles][order_article.id][:tolerance] if @order.boxfill?)}/ %input{id: "t_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][tolerance]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:tolerance], 'data-min' => (@ordering_data[:order_articles][order_article.id][:tolerance] if @order.boxfill?)}/
- if (@ordering_data[:order_articles][order_article.id][:unit] > 1) - 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.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] %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]
.btn-group .btn-group
%a.btn.btn-ordering{'data-decrease_tolerance' => order_article.id} %a.btn.btn-ordering{'data-decrease_tolerance' => order_article.id}
%i.icon-minus %i.icon-minus
%a.btn.btn-ordering{'data-increase_tolerance' => order_article.id} %a.btn.btn-ordering{'data-increase_tolerance' => order_article.id}
%i.icon-plus %i.icon-plus
%td{id: "td_price_#{order_article.id}", style: "text-align:right; padding-right:10px; width:4em"} %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(@ordering_data[:order_articles][order_article.id][:total_price]) %span{id: "price_#{order_article.id}_display"}= number_to_currency(@ordering_data[:order_articles][order_article.id][:total_price])
.article-info .article-info
.article-name= order_article.article.name .article-name= order_article.article.name
.pull-right .pull-right
= t('.units_full') + ':' = t('.units_full') + ':'
%span{id: "units_#{order_article.id}"}= order_article.units_to_order %span{id: "units_#{order_article.id}"}= order_article.units_to_order
%br/ %br/
= t('.units_total') + ':' = t('.units_total') + ':'
%span{id: "q_total_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:quantity] + @ordering_data[:order_articles][order_article.id][:others_quantity] %span{id: "q_total_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:quantity] + @ordering_data[:order_articles][order_article.id][:others_quantity]
%br/ %br/
= t('.total_tolerance') + ':' = t('.total_tolerance') + ':'
%span{id: "t_total_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] + @ordering_data[:order_articles][order_article.id][:others_tolerance] %span{id: "t_total_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] + @ordering_data[:order_articles][order_article.id][:others_tolerance]
%br/ %br/
.pull-left .pull-left
#{heading_helper Article, :manufacturer}: #{order_article.article.manufacturer} #{heading_helper Article, :manufacturer}: #{order_article.article.manufacturer}
%br/ %br/
#{heading_helper Article, :units}: #{@order.stockit? ? order_article.article.quantity_available : @ordering_data[:order_articles][order_article.id][:unit]} * #{h order_article.article.unit} #{heading_helper Article, :units}: #{@order.stockit? ? order_article.article.quantity_available : @ordering_data[:order_articles][order_article.id][:unit]} * #{h order_article.article.unit}
%br/ %br/
#{heading_helper Article, :note}: #{order_article.article.note} #{heading_helper Article, :note}: #{order_article.article.note}
%br/ %br/
#order-footer #order-footer
#info-box #info-box
#total-sum #total-sum
%table = render 'total_sum'
%tr #order-button
%td= t('.total_sum_amount') + ':' = submit_tag( t('.action_save'), id: 'submit_button', class: 'btn btn-primary' )
%td.currency #{link_to t('ui.or_cancel'), group_orders_path}
%span#total_price= number_to_currency(@group_order.price) %input#total_balance{name: "total_balance", type: "hidden", value: @ordergroup.account_balance - @group_order.price}/
%tr %input{name: "version", type: "hidden", value: @version}/
- if FoodsoftConfig[:charge_members_manually]
- old_balance = @ordering_data[:account_balance]
%td= heading_helper(Ordergroup, :account_balance) + ':'
%td.currency= number_to_currency(@ordering_data[:account_balance])
- else
- old_balance = @ordering_data[:available_funds]
%td= heading_helper(Ordergroup, :available_funds) + ':'
%td.currency= number_to_currency(@ordering_data[:available_funds])
%tr
%td= t('.new_funds') + ':'
%td.currency
%strong
%span#new_balance= number_to_currency(old_balance - @group_order.price)
#order-button
= submit_tag( t('.action_save'), id: 'submit_button', class: 'btn btn-primary' )
#{link_to t('ui.or_cancel'), group_orders_path}
%input#total_balance{name: "total_balance", type: "hidden", value: @ordergroup.account_balance - @group_order.price}/
%input{name: "version", type: "hidden", value: @version}/

View file

@ -0,0 +1,28 @@
%a(href='#tab1' data-toggle="collapse")
=t '.details'
#tab1.collapse
%dl.dl-horizontal
- unless @order.note.blank?
%dt= heading_helper Order, :note
%dd= @order.note
%dt= heading_helper Order, :created_by
%dd= show_user_link(@order.created_by)
%dt= heading_helper Order, :ends
%dd= format_time(@order.ends)
%dt= heading_helper Order, :pickup
%dd= format_date(@order.pickup)
- unless @order.stockit? or @order.supplier.min_order_quantity.blank?
%dt= heading_helper Supplier, :min_order_quantity, short: true
%dd= @order.supplier.min_order_quantity
%dt= t 'group_orders.form.sum_amount'
%dd= number_to_currency @order.sum
- unless @group_order.new_record?
%dt= heading_helper GroupOrder, :updated_by
%dd
= show_user(@group_order.updated_by)
(#{format_time(@group_order.updated_on)})
%dt= heading_helper Ordergroup, :account_balance
%dd= number_to_currency(@ordering_data[:account_balance])
- unless FoodsoftConfig[:charge_members_manually]
%dt= heading_helper Ordergroup, :available_funds
%dd= number_to_currency(@ordering_data[:available_funds])

View file

@ -0,0 +1,19 @@
%table
%tr
%td= t('group_orders.form.total_sum_amount') + ':'
%td.currency
%span#total_price= number_to_currency(@group_order.price)
%tr
- if FoodsoftConfig[:charge_members_manually]
- old_balance = @ordering_data[:account_balance]
%td= heading_helper(Ordergroup, :account_balance) + ':'
%td.currency= number_to_currency(@ordering_data[:account_balance])
- else
- old_balance = @ordering_data[:available_funds]
%td= heading_helper(Ordergroup, :available_funds) + ':'
%td.currency= number_to_currency(@ordering_data[:available_funds])
%tr
%td= t('group_orders.form.new_funds') + ':'
%td.currency
%strong
%span#new_balance= number_to_currency(old_balance - @group_order.price)

View file

@ -1045,6 +1045,7 @@ de:
error_stale: In der Zwischenzeit hat jemand anderes auch bestellt, daher konnte die Bestellung nicht aktualisiert werden. error_stale: In der Zwischenzeit hat jemand anderes auch bestellt, daher konnte die Bestellung nicht aktualisiert werden.
notice: Die Bestellung wurde gespeichert. notice: Die Bestellung wurde gespeichert.
errors: errors:
balance_alert: Kontostand im Minus
closed: Diese Bestellung ist bereits abgeschlossen. closed: Diese Bestellung ist bereits abgeschlossen.
no_member: Du bist kein Mitglieder einer Bestellgruppe. no_member: Du bist kein Mitglieder einer Bestellgruppe.
notfound: Fehlerhafte URL, das ist nicht Deine Bestellung. notfound: Fehlerhafte URL, das ist nicht Deine Bestellung.

View file

@ -1047,6 +1047,7 @@ en:
error_stale: Someone else has ordered in the meantime, couldn't update the order. error_stale: Someone else has ordered in the meantime, couldn't update the order.
notice: The order was saved. notice: The order was saved.
errors: errors:
balance_alert: Negative account balance
closed: This order is already closed. closed: This order is already closed.
no_member: You are not a member of an ordergroup. no_member: You are not a member of an ordergroup.
notfound: Incorrect URL, this is not your order. notfound: Incorrect URL, this is not your order.

View file

@ -1017,6 +1017,7 @@ nl:
error_stale: In de tussentijd heeft iemand anders ook bestelt, daarom kon de bestelling niet bijgewerkt worden. error_stale: In de tussentijd heeft iemand anders ook bestelt, daarom kon de bestelling niet bijgewerkt worden.
notice: Bestelling opgeslagen. notice: Bestelling opgeslagen.
errors: errors:
balance_alert: Accountsaldo in het rood
closed: Deze bestelling is al gesloten. closed: Deze bestelling is al gesloten.
no_member: Je bent geen lid van dit huishouden. no_member: Je bent geen lid van dit huishouden.
notfound: Foute URL, dit is niet jouw bestelling. notfound: Foute URL, dit is niet jouw bestelling.