allow to edit GroupOrderArticle result from orders screen
Conflicts: app/assets/javascripts/application.js
This commit is contained in:
parent
f9d2c20aaa
commit
60826ceedc
34 changed files with 393 additions and 220 deletions
|
|
@ -4,38 +4,31 @@
|
|||
%tr
|
||||
%td
|
||||
%td{:style => "width:8em"}= Ordergroup.model_name.human
|
||||
%td= t('.units')
|
||||
-#%td.center= t('.units')
|
||||
%td.center
|
||||
%acronym{:title => t('shared.articles.received_desc')}= t 'shared.articles.received'
|
||||
%td= t('.total')
|
||||
%td{:colspan => "3",:style => "width:14em"}
|
||||
= link_to t('.add_group'), new_finance_group_order_article_path(order_article_id: order_article.id),
|
||||
= link_to t('.add_group'), new_group_order_article_path(order_article_id: order_article.id),
|
||||
remote: true, class: 'btn btn-mini'
|
||||
%tbody
|
||||
- totals = {result: 0}
|
||||
- for group_order_article in order_article.group_order_articles.select { |goa| goa.result > 0 }
|
||||
%tr[group_order_article]
|
||||
%td
|
||||
%td{:style=>"width:50%"}
|
||||
= group_order_article.group_order.ordergroup.name
|
||||
%td{:id => "group_order_article_#{group_order_article.id}_quantity", :style => "white-space:nowrap"}
|
||||
= group_order_article.result
|
||||
= link_to "+", update_result_finance_group_order_article_path(group_order_article, modifier: '+'),
|
||||
method: :put, remote: true, class: 'btn btn-mini'
|
||||
= link_to "-", update_result_finance_group_order_article_path(group_order_article, modifier: '-'),
|
||||
method: :put, remote: true, class: 'btn btn-mini'
|
||||
%td.numeric
|
||||
= number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.result)
|
||||
%td.center= group_order_article_edit_result(group_order_article)
|
||||
%td.numeric= number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.result)
|
||||
%td.actions{:style=>"width:1em"}
|
||||
= link_to t('ui.edit'), edit_finance_group_order_article_path(group_order_article), remote: true,
|
||||
class: 'btn btn-mini'
|
||||
%td.actions{:style=>"width:1em"}
|
||||
= link_to t('ui.delete'), finance_group_order_article_path(group_order_article), method: :delete,
|
||||
= link_to t('ui.delete'), group_order_article_path(group_order_article), method: :delete,
|
||||
remote: true, class: 'btn btn-mini btn-danger'
|
||||
%td
|
||||
- totals[:result] += group_order_article.result
|
||||
%tfoot
|
||||
%tr
|
||||
%td
|
||||
%td{:style => "width:8em"}= t('.total_fc')
|
||||
%td{:id => "group_orders_sum_quantity_#{order_article.id}"}
|
||||
= order_article.group_orders_sum[:quantity]
|
||||
%td.numeric{:id => "group_orders_sum_price_#{order_article.id}"}
|
||||
= number_to_currency(order_article.group_orders_sum[:price])
|
||||
%td.center= totals[:result]
|
||||
%td.numeric= number_to_currency(order_article.group_orders_sum[:price])
|
||||
%td{:colspan => "3"}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
$(function() {
|
||||
// Subscribe to database changes.
|
||||
// See publish/subscribe design pattern in /doc.
|
||||
$(document).on('OrderArticle#update', function(e) {
|
||||
$(document).on('OrderArticle#update GroupOrderArticle#create GroupOrderArticle#update', function(e) {
|
||||
$.ajax({
|
||||
url: '#{new_on_order_article_update_finance_order_path(@order)}',
|
||||
type: 'get',
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
});
|
||||
});
|
||||
});
|
||||
= render 'shared/articles_by/common', order: @order
|
||||
|
||||
- title t('.title', name: @order.name)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
$('#modalContainer').html('#{j(render("form"))}');
|
||||
$('#modalContainer').modal();
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
$('#modalContainer').html('#{j(render("form"))}');
|
||||
$('#modalContainer').modal();
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
$('#modalContainer').modal('hide');
|
||||
$('#order_article_#{@order_article.id}').html('#{j(render('finance/balancing/order_article', order_article: @order_article))}');
|
||||
$('#group_order_articles_#{@order_article.id}').html('#{j(render('finance/balancing/group_order_articles', order_article: @order_article))}');
|
||||
$('#summaryChangedWarning').show();
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
= simple_form_for [:finance, @group_order_article], remote: true do |form|
|
||||
= simple_form_for @group_order_article, remote: true do |form|
|
||||
= form.hidden_field :order_article_id
|
||||
.modal-header
|
||||
= link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'}
|
||||
%h3= t('.amount_change_for', article: @order_article.article.name)
|
||||
.modal-body
|
||||
= form.input :ordergroup_id, as: :select, collection: Ordergroup.all.map { |g| [g.name, g.id] }
|
||||
= form.input :result, hint: I18n.t('finance.group_order_articles.form.result_hint', unit: @order_article.article.unit) # Why do we need the full prefix?
|
||||
= form.input :result, hint: I18n.t('group_order_articles.form.result_hint', unit: @order_article.article.unit) # Why do we need the full prefix?
|
||||
.modal-footer
|
||||
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
||||
= form.submit t('ui.save'), class: 'btn btn-primary'
|
||||
10
app/views/group_order_articles/create.js.erb
Normal file
10
app/views/group_order_articles/create.js.erb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
$('#modalContainer').modal('hide');
|
||||
|
||||
// trigger hooks for views
|
||||
$(document).trigger({
|
||||
type: 'GroupOrderArticle#create',
|
||||
order_article_id: <%= @group_order_article.order_article_id %>,
|
||||
group_order_id: <%= @group_order_article.group_order_id %>,
|
||||
group_order_article_id: <%= @group_order_article.id %>,
|
||||
group_order_article_price: <%= @group_order_article.total_price %>
|
||||
});
|
||||
2
app/views/group_order_articles/new.js.erb
Normal file
2
app/views/group_order_articles/new.js.erb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$('#modalContainer').html('<%= j render("form") %>');
|
||||
$('#modalContainer').modal();
|
||||
8
app/views/group_order_articles/update.js.erb
Normal file
8
app/views/group_order_articles/update.js.erb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// and trigger hooks for views including this
|
||||
$(document).trigger({
|
||||
type: 'GroupOrderArticle#update',
|
||||
order_article_id: <%= @group_order_article.order_article_id %>,
|
||||
group_order_id: <%= @group_order_article.group_order_id %>,
|
||||
group_order_article_id: <%= @group_order_article.id %>,
|
||||
group_order_article_price: <%= @group_order_article.total_price %>
|
||||
});
|
||||
|
|
@ -98,3 +98,5 @@
|
|||
$(function() {
|
||||
activate_search('#{j @view}', '#{j t(".search_placeholder.#{@view}")}');
|
||||
});
|
||||
|
||||
= render 'shared/articles_by/common', order: @order
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
%table.table.table-hover.list
|
||||
%thead.list-heading
|
||||
%tr
|
||||
%th{:style => 'width:70%'}= t '.ordergroup'
|
||||
%th
|
||||
%acronym{:title => t('shared.articles.ordered_desc')}= t 'shared.articles.ordered'
|
||||
%th
|
||||
%acronym{:title => t('shared.articles.received_desc')}= t 'shared.articles.received'
|
||||
%th= t '.price'
|
||||
|
||||
- for order_article in order.order_articles.ordered.all(:include => [:article, :article_price])
|
||||
%tbody
|
||||
%tr
|
||||
%th.name{:colspan => "4"}
|
||||
= order_article.article.name
|
||||
= "(#{order_article.article.unit} | #{order_article.price.unit_quantity} | #{number_to_currency(order_article.price.gross_price)})"
|
||||
- for goa in order_article.group_order_articles.ordered
|
||||
%tr{:class => [cycle('even', 'odd', :name => 'groups'), if goa.result == 0 then 'unavailable' end]}
|
||||
%td{:style => "width:70%"}=h goa.group_order.ordergroup.name
|
||||
%td= "#{goa.quantity} + #{goa.tolerance}"
|
||||
%td
|
||||
%b= goa.result
|
||||
%td= number_to_currency(order_article.price.fc_price * goa.result)
|
||||
%tr
|
||||
%td(colspan="4" )
|
||||
- reset_cycle('groups')
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
%table.table.table-hover.list
|
||||
%thead.list-heading
|
||||
%tr
|
||||
%th{:style => "width:40%"}= heading_helper Article, :name
|
||||
%th= heading_helper Article, :unit
|
||||
%th.center
|
||||
%acronym{:title => t('shared.articles.ordered_desc')}= t 'shared.articles.ordered'
|
||||
%th.center{colspan: 2}
|
||||
%acronym{:title => t('shared.articles.received_desc')}= t 'shared.articles.received'
|
||||
%th{colspan: 2}= heading_helper Article, :fc_price, short: true
|
||||
%th= t '.price'
|
||||
%th= #heading_helper Article, :unit_quantity, short: true
|
||||
|
||||
- for group_order in order.group_orders.ordered
|
||||
%tbody
|
||||
%tr.list-heading
|
||||
%th{:colspan => "9"}
|
||||
%h4.name= group_order.ordergroup.name
|
||||
- total = 0
|
||||
- for goa in group_order.group_order_articles.ordered.all(:include => :order_article)
|
||||
- fc_price = goa.order_article.price.fc_price
|
||||
- subTotal = fc_price * goa.result
|
||||
- total += subTotal
|
||||
%tr{:class => [cycle('even', 'odd', :name => 'articles'), if goa.result == 0 then 'unavailable' end]}
|
||||
%td.name{:style => "width:40%"}=h goa.order_article.article.name
|
||||
%td= goa.order_article.article.unit
|
||||
%td.center= "#{goa.quantity} + #{goa.tolerance}"
|
||||
%td.center
|
||||
%b= goa.result
|
||||
%td.symbol ×
|
||||
%td= number_to_currency(fc_price)
|
||||
%td.symbol =
|
||||
%td= number_to_currency(subTotal)
|
||||
%td= pkg_helper goa.order_article.price
|
||||
%tr{:class => cycle('even', 'odd', :name => 'articles')}
|
||||
%th{:colspan => "7"}= t '.price_sum'
|
||||
%th= number_to_currency(total)
|
||||
%th
|
||||
%tr
|
||||
%th(colspan="9")
|
||||
- reset_cycle("articles")
|
||||
11
app/views/shared/articles_by/_article_single.html.haml
Normal file
11
app/views/shared/articles_by/_article_single.html.haml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
%tbody{id: "oa_#{order_article.id}"}
|
||||
- if not defined?(heading) or heading
|
||||
%tr.list-heading
|
||||
%th.name{:colspan => "4"}>
|
||||
= order_article.article.name + ' '
|
||||
= "(#{order_article.article.unit}, #{number_to_currency order_article.price.fc_price}"
|
||||
- pkg_info = pkg_helper(order_article.price)
|
||||
= ", #{pkg_info}".html_safe unless pkg_info.blank?
|
||||
)
|
||||
- for goa in order_article.group_order_articles.ordered
|
||||
= render 'shared/articles_by/article_single_goa', goa: goa, edit: (edit rescue nil)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%tr{class: if goa.result == 0 then 'unavailable' end, id: "goa_#{goa.id}"}
|
||||
%td{:style => "width:70%"}= goa.group_order.ordergroup.name
|
||||
%td.center= "#{goa.quantity} + #{goa.tolerance}"
|
||||
%td.center.input-delta= (edit or true rescue true) ? group_order_article_edit_result(goa) : goa.result
|
||||
%td.price{data: {value: goa.total_price}}= number_to_currency(goa.total_price)
|
||||
14
app/views/shared/articles_by/_articles.html.haml
Normal file
14
app/views/shared/articles_by/_articles.html.haml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
%table.table.table-hover.list#articles_by_articles
|
||||
%thead.list-heading
|
||||
%tr
|
||||
%th{:style => 'width:70%'}= Ordergroup.model_name.human
|
||||
%th.center
|
||||
%acronym{:title => t('shared.articles.ordered_desc')}= t 'shared.articles.ordered'
|
||||
%th.center
|
||||
%acronym{:title => t('shared.articles.received_desc')}= t 'shared.articles.received'
|
||||
%th= t 'shared.articles_by.price'
|
||||
|
||||
- for order_article in order.order_articles.ordered.all(:include => [:article, :article_price])
|
||||
= render 'shared/articles_by/article_single', order_article: order_article, edit: (edit rescue nil)
|
||||
%tr
|
||||
%td{colspan: 4}
|
||||
30
app/views/shared/articles_by/_common.html.haml
Normal file
30
app/views/shared/articles_by/_common.html.haml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
-# common javascript for updating articles_by views
|
||||
-# include this in all pages that use articles_by views (directly or via ajax)
|
||||
= content_for :javascript do
|
||||
:javascript
|
||||
$(document).on('GroupOrderArticle#update', function(e) {
|
||||
|
||||
var el_goa = $('#goa_'+e.group_order_article_id);
|
||||
|
||||
// update total price of group_order_article
|
||||
// show localised value, store raw number in data attribute
|
||||
var el_price = $('.price', el_goa);
|
||||
var old_price = el_price.data('value');
|
||||
if (el_price.length) {
|
||||
el_price.text(I18n.l('currency', e.group_order_article_price));
|
||||
el_price.data('value', e.group_order_article_price);
|
||||
}
|
||||
|
||||
// group_order_article is greyed when result==0
|
||||
el_goa.toggleClass('unavailable', $('input#r_'+e.group_order_article_id, el_goa).val()==0);
|
||||
|
||||
// update total price of group_order, order_article and/or ordergroup, when present
|
||||
var el_sum = $('#group_order_'+e.group_order_id+', #single_ordergroup_total, #single_order_article_total');
|
||||
var el_price_sum = $('.price_sum', el_sum);
|
||||
if (el_price_sum.length) {
|
||||
var old_price_sum = el_price_sum.data('value');
|
||||
var new_price_sum = old_price_sum - old_price + e.group_order_article_price;
|
||||
el_price_sum.text(I18n.l('currency', new_price_sum));
|
||||
el_price_sum.data('value', new_price_sum);
|
||||
}
|
||||
});
|
||||
15
app/views/shared/articles_by/_group_single.html.haml
Normal file
15
app/views/shared/articles_by/_group_single.html.haml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
%tbody{id: "group_order_#{group_order.id}"}
|
||||
- if not defined?(heading) or heading
|
||||
%tr.list-heading
|
||||
%th{colspan: 9}
|
||||
%h4.name= group_order.ordergroup.name
|
||||
- total = 0
|
||||
- for goa in group_order.group_order_articles.ordered.all(:include => :order_article)
|
||||
- total += goa.total_price
|
||||
= render 'shared/articles_by/group_single_goa', goa: goa, edit: (edit rescue nil)
|
||||
%tr{class: cycle('even', 'odd', :name => 'articles')}
|
||||
%th{colspan: 7}= t 'shared.articles_by.price_sum'
|
||||
%th.price_sum{colspan: 2, data: {value: total}}= number_to_currency(total)
|
||||
%tr
|
||||
%th{colspan: 9}
|
||||
- reset_cycle("articles")
|
||||
11
app/views/shared/articles_by/_group_single_goa.html.haml
Normal file
11
app/views/shared/articles_by/_group_single_goa.html.haml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
%tr{class: [cycle('even', 'odd', :name => 'articles'), if goa.result == 0 then 'unavailable' end], id: "goa_#{goa.id}"}
|
||||
%td.name= goa.order_article.article.name
|
||||
%td= goa.order_article.article.unit
|
||||
%td.center= "#{goa.quantity} + #{goa.tolerance}"
|
||||
%td.center.input-delta= (edit or true rescue true) ? group_order_article_edit_result(goa) : goa.result
|
||||
%td.symbol ×
|
||||
%td= number_to_currency(goa.order_article.price.fc_price)
|
||||
%td.symbol =
|
||||
%td.price{data: {value: goa.total_price}}= number_to_currency(goa.total_price)
|
||||
%td= pkg_helper goa.order_article.price
|
||||
|
||||
17
app/views/shared/articles_by/_groups.html.haml
Normal file
17
app/views/shared/articles_by/_groups.html.haml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
%table.table.table-hover.list#articles_by_groups
|
||||
%thead.list-heading
|
||||
%tr
|
||||
%th{:style => "width:40%"}= heading_helper Article, :name
|
||||
%th= heading_helper Article, :unit
|
||||
%th.center
|
||||
%acronym{:title => t('shared.articles.ordered_desc')}= t 'shared.articles.ordered'
|
||||
%th.center
|
||||
%acronym{:title => t('shared.articles.received_desc')}= t 'shared.articles.received'
|
||||
%th.symbol
|
||||
%th= heading_helper Article, :fc_price, short: true
|
||||
%th.symbol
|
||||
%th= t 'shared.articles_by.price'
|
||||
%th= #heading_helper Article, :unit_quantity, short: true
|
||||
|
||||
- for group_order in order.group_orders.ordered
|
||||
= render 'shared/articles_by/group_single', group_order: group_order, edit: (edit rescue nil)
|
||||
Loading…
Add table
Add a link
Reference in a new issue