2013-12-21 17:33:06 +01:00
|
|
|
|
- new_articles = (@order.supplier.articles rescue @order.articles)
|
|
|
|
|
- new_article_data = articles_for_select2(new_articles, @order_articles.map(&:article_id)) {|a| "#{a.name} (#{a.unit_quantity}⨯#{a.unit})" }
|
2013-11-25 13:48:54 +01:00
|
|
|
|
- content_for :javascript do
|
|
|
|
|
:javascript
|
|
|
|
|
|
2013-12-18 17:34:45 +01:00
|
|
|
|
var new_article_data = #{new_article_data.to_json};
|
2013-11-26 13:31:07 +01:00
|
|
|
|
|
2013-11-25 13:48:54 +01:00
|
|
|
|
function update_delta(input) {
|
|
|
|
|
var units = $(input).val();
|
|
|
|
|
var expected = $(input).data('units-expected');
|
|
|
|
|
var html;
|
|
|
|
|
|
|
|
|
|
if (units.replace(/\s/g,"")=="") {
|
|
|
|
|
// no value
|
|
|
|
|
html = '';
|
|
|
|
|
} else if (isNaN(units)) {
|
|
|
|
|
html = '<i class="icon-remove" style="color: red"></i>';
|
|
|
|
|
} else if (units == expected) {
|
|
|
|
|
// equal value
|
|
|
|
|
html = '<i class="icon-ok" style="color: green"></i>';
|
|
|
|
|
} else if (units < expected) {
|
|
|
|
|
html = '<span style="color: red">- '+(expected-units)+'</span>';
|
|
|
|
|
} else /*if (units> expected)*/ {
|
|
|
|
|
html = '<span style="color: green">+ '+(units-expected)+'</span>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(input).closest('tr').find('.units_delta').html(html);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).on('change', 'input[data-units-expected]', function() {
|
|
|
|
|
update_delta(this);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
|
$('input[data-units-expected]').each(function() {
|
|
|
|
|
update_delta(this);
|
|
|
|
|
});
|
|
|
|
|
|
2013-11-26 13:31:07 +01:00
|
|
|
|
init_add_article('#add_article');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function init_add_article(sel) {
|
|
|
|
|
$(sel).removeAttr('disabled').select2({
|
2013-12-18 21:06:05 +01:00
|
|
|
|
placeholder: '#{t 'orders.add_article.title'}',
|
2013-11-26 13:31:07 +01:00
|
|
|
|
data: new_article_data,
|
2013-11-25 13:48:54 +01:00
|
|
|
|
// TODO implement adding a new article, like in deliveries
|
|
|
|
|
}).on('change', function(e) {
|
|
|
|
|
var selectedArticle = $(e.currentTarget).select2('data');
|
|
|
|
|
if(!selectedArticle) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
2013-12-18 21:06:05 +01:00
|
|
|
|
url: '#{add_article_order_path(@order)}',
|
2013-11-25 13:48:54 +01:00
|
|
|
|
type: 'get',
|
|
|
|
|
data: {article_id: selectedArticle.id},
|
|
|
|
|
contentType: 'application/json; charset=UTF-8'
|
|
|
|
|
});
|
2013-11-26 13:31:07 +01:00
|
|
|
|
// clear selection
|
2013-11-25 13:48:54 +01:00
|
|
|
|
$('#add_article').select2('data', null);
|
2013-11-26 13:31:07 +01:00
|
|
|
|
// remove newly added item from list of items
|
|
|
|
|
new_article_data = $.grep(new_article_data, function(el, i) {
|
|
|
|
|
return el.id != selectedArticle.id;
|
|
|
|
|
});
|
|
|
|
|
init_add_article(sel)
|
2013-11-25 13:48:54 +01:00
|
|
|
|
return true;
|
|
|
|
|
});
|
2013-11-26 13:31:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 13:48:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%table.ordered-articles.table.table-striped.stupidtable
|
|
|
|
|
%thead
|
|
|
|
|
%tr
|
2013-12-18 21:06:05 +01:00
|
|
|
|
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true
|
|
|
|
|
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :name
|
2013-11-25 13:48:54 +01:00
|
|
|
|
%th= heading_helper GroupOrderArticle, :units
|
|
|
|
|
%th Members
|
|
|
|
|
%th Ordered
|
2013-12-18 21:53:31 +01:00
|
|
|
|
-#%th Invoice # TODO implement invoice screen
|
2013-11-25 13:48:54 +01:00
|
|
|
|
%th Received
|
|
|
|
|
%th
|
|
|
|
|
%tbody#result_table
|
|
|
|
|
- @order_articles.each do |order_article|
|
2013-12-18 21:06:05 +01:00
|
|
|
|
= render :partial => 'edit_amount', :locals => {:order_article => order_article}
|
2013-11-25 13:48:54 +01:00
|
|
|
|
%tfoot
|
|
|
|
|
%tr
|
|
|
|
|
%th{:colspan => 8}
|
|
|
|
|
%input#add_article{:style => 'width: 500px;'}
|
|
|
|
|
|