2014-06-11 09:42:07 +02:00
|
|
|
|
- new_articles = (@order.supplier.articles.undeleted rescue @order.articles)
|
2014-01-01 23:45:57 +01:00
|
|
|
|
- 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
|
|
|
|
|
|
|
|
|
|
function update_delta(input) {
|
|
|
|
|
var units = $(input).val();
|
|
|
|
|
var expected = $(input).data('units-expected');
|
2014-01-13 11:37:18 +01:00
|
|
|
|
var delta = Math.round((units-expected)*100)/100.0;
|
2013-11-25 13:48:54 +01:00
|
|
|
|
var html;
|
|
|
|
|
|
|
|
|
|
if (units.replace(/\s/g,"")=="") {
|
|
|
|
|
// no value
|
|
|
|
|
html = '';
|
|
|
|
|
} else if (isNaN(units)) {
|
|
|
|
|
html = '<i class="icon-remove" style="color: red"></i>';
|
2014-01-13 11:37:18 +01:00
|
|
|
|
} else if (delta == 0) {
|
2013-11-25 13:48:54 +01:00
|
|
|
|
// equal value
|
|
|
|
|
html = '<i class="icon-ok" style="color: green"></i>';
|
2014-01-09 12:17:25 +01:00
|
|
|
|
} else {
|
2014-01-13 11:37:18 +01:00
|
|
|
|
if (delta < 0) {
|
|
|
|
|
html = '<span style="color: red">- '+(-delta)+'</span>';
|
2014-01-09 12:17:25 +01:00
|
|
|
|
} else /*if (units> expected)*/ {
|
2014-01-13 11:37:18 +01:00
|
|
|
|
html = '<span style="color: green">+ '+(delta)+'</span>';
|
|
|
|
|
}
|
|
|
|
|
// show package icon only if the receive field has one
|
|
|
|
|
if ($(input).hasClass('package')) {
|
|
|
|
|
html += '#{j pkg_helper_icon}';
|
2014-01-09 12:17:25 +01:00
|
|
|
|
}
|
2013-11-25 13:48:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(input).closest('tr').find('.units_delta').html(html);
|
2014-08-29 12:23:23 +02:00
|
|
|
|
|
|
|
|
|
// un-dim row when received is nonzero
|
|
|
|
|
$(input).closest('tr').toggleClass('unavailable', expected == 0 && html=='');
|
2013-11-25 13:48:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-08 19:28:39 +01:00
|
|
|
|
$(document).on('change keyup', 'input[data-units-expected]', function() {
|
2013-11-25 13:48:54 +01:00
|
|
|
|
update_delta(this);
|
|
|
|
|
});
|
|
|
|
|
|
2014-01-25 15:19:50 +01:00
|
|
|
|
$(document).on('touchclick', '#order_articles .unlocker', unlock_receive_input_field);
|
2014-01-09 10:13:57 +01:00
|
|
|
|
|
2021-02-08 01:07:59 +01:00
|
|
|
|
$(document).on('click', '#set_all_to_zero', function() {
|
|
|
|
|
$('tbody input').each(function(i, input) {
|
|
|
|
|
$(input).val(0);
|
|
|
|
|
update_delta(input);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
|
2013-11-25 13:48:54 +01:00
|
|
|
|
$(function() {
|
|
|
|
|
$('input[data-units-expected]').each(function() {
|
|
|
|
|
update_delta(this);
|
|
|
|
|
});
|
2016-08-12 15:54:28 +02:00
|
|
|
|
|
2014-01-01 23:45:57 +01:00
|
|
|
|
init_add_article('#add_article');
|
2013-11-26 13:31:07 +01:00
|
|
|
|
});
|
2016-08-12 15:54:28 +02:00
|
|
|
|
|
2014-01-01 23:45:57 +01:00
|
|
|
|
function init_add_article(sel) {
|
|
|
|
|
$(sel).removeAttr('disabled').select2({
|
2014-01-06 23:48:39 +01:00
|
|
|
|
placeholder: '#{j t('orders.receive.add_article')}',
|
2014-01-01 23:45:57 +01:00
|
|
|
|
formatNoMatches: function(term) { return '#{j t('.no_articles_available')}';}
|
|
|
|
|
// TODO implement adding a new article, like in deliveries
|
|
|
|
|
}).on('change', function(e) {
|
2016-08-12 15:54:28 +02:00
|
|
|
|
var $input = $(e.target);
|
|
|
|
|
var selectedArticleId = $input.val();
|
|
|
|
|
if(!selectedArticleId) {
|
2014-01-01 23:45:57 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: '#{order_order_articles_path(@order)}',
|
|
|
|
|
type: 'post',
|
2016-08-12 15:54:28 +02:00
|
|
|
|
data: JSON.stringify({order_article: {article_id: selectedArticleId}}),
|
2014-01-01 23:45:57 +01:00
|
|
|
|
contentType: 'application/json; charset=UTF-8'
|
|
|
|
|
});
|
2016-08-12 15:54:28 +02:00
|
|
|
|
|
|
|
|
|
$input.val('').trigger('change');
|
|
|
|
|
});
|
|
|
|
|
$(sel).val('').trigger('change');
|
2014-01-01 23:45:57 +01:00
|
|
|
|
}
|
2016-08-12 15:54:28 +02:00
|
|
|
|
|
2014-01-03 10:33:09 +01:00
|
|
|
|
function unlock_receive_input_field() {
|
2014-01-03 22:26:20 +01:00
|
|
|
|
$('.units_received', $(this).closest('tr')).prop('disabled', false).focus();
|
2014-01-09 13:01:10 +01:00
|
|
|
|
$(this).closest('.input-prepend').prop('title', I18n.t('orders.edit_amount.field_unlocked_title'));
|
2014-01-03 22:26:20 +01:00
|
|
|
|
$(this).replaceWith('<i class="icon icon-warning-sign add-on"></i>');
|
2014-01-03 10:33:09 +01:00
|
|
|
|
}
|
2013-11-26 13:31:07 +01:00
|
|
|
|
|
2014-01-06 23:48:39 +01:00
|
|
|
|
%table#order_articles.ordered-articles.table.table-striped.stupidtable{style: 'margin-bottom: 0'}
|
2013-11-25 13:48:54 +01:00
|
|
|
|
%thead
|
|
|
|
|
%tr
|
2013-12-18 21:06:05 +01:00
|
|
|
|
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true
|
2014-08-18 10:56:03 +02:00
|
|
|
|
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :name
|
2015-04-21 22:37:37 +02:00
|
|
|
|
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :unit
|
2014-01-02 22:30:04 +01:00
|
|
|
|
%th= heading_helper Article, :price
|
2014-01-08 00:06:25 +01:00
|
|
|
|
%th= heading_helper OrderArticle, :quantity, short: true
|
2014-01-08 12:52:29 +01:00
|
|
|
|
%th= heading_helper OrderArticle, :units_to_order, short: true
|
2013-12-18 21:53:31 +01:00
|
|
|
|
-#%th Invoice # TODO implement invoice screen
|
2014-01-08 00:06:25 +01:00
|
|
|
|
%th= heading_helper OrderArticle, :units_received, short: true
|
2013-11-25 13:48:54 +01:00
|
|
|
|
%th
|
2013-12-30 14:34:26 +01:00
|
|
|
|
%th= t 'ui.actions'
|
2014-01-09 14:47:05 +01:00
|
|
|
|
%tbody#result_table
|
|
|
|
|
- @order_articles.each do |order_article|
|
|
|
|
|
= render :partial => 'edit_amount', :locals => {:order_article => order_article}
|
2013-12-31 13:46:25 +01:00
|
|
|
|
%tfoot
|
|
|
|
|
%tr
|
2021-02-08 01:07:59 +01:00
|
|
|
|
%th{colspan: 6}
|
2014-01-01 23:45:57 +01:00
|
|
|
|
%select#add_article{:style => 'width: 500px;'}
|
|
|
|
|
- new_article_data.each do |option|
|
|
|
|
|
%option{id: "add_article_#{option[:id]}", value: option[:id]}= option[:text]
|
2021-02-08 01:07:59 +01:00
|
|
|
|
%th{colspan: 4}
|
|
|
|
|
%button.btn#set_all_to_zero{type: :button}
|
|
|
|
|
= t '.set_all_to_zero'
|