Improve delivery workflow; introduce sortable tables; use js.erb for deliveries
This commit is contained in:
parent
49cfa9aded
commit
65f61e09d5
18 changed files with 357 additions and 105 deletions
|
@ -10,6 +10,34 @@
|
||||||
//= require_self
|
//= require_self
|
||||||
//= require ordering
|
//= require ordering
|
||||||
|
|
||||||
|
// function for sorting DOM elements
|
||||||
|
$.fn.sorter = (function(){
|
||||||
|
// Thanks to James Padolsey and Avi Deitcher
|
||||||
|
// http://james.padolsey.com/javascript/sorting-elements-with-jquery/#comment-29400
|
||||||
|
var sort = [].sort;
|
||||||
|
|
||||||
|
return function(comparator, getSortable) {
|
||||||
|
getSortable = getSortable || function(){return this;};
|
||||||
|
|
||||||
|
var sorted = sort.call(this, comparator); // sort all elements in memory
|
||||||
|
var prevElmt = null;
|
||||||
|
for(i=sorted.length-1; i>=0; --i) { // loop starting from last
|
||||||
|
var criterionElmt = sorted[i];
|
||||||
|
var curElmt = ( 'function' === typeof getSortable ) ? ( getSortable.call(criterionElmt) ) : ( criterionElmt );
|
||||||
|
var parent = curElmt.parentNode;
|
||||||
|
if (!prevElmt) {
|
||||||
|
parent.appendChild(curElmt); // place last element to the end
|
||||||
|
} else {
|
||||||
|
parent.insertBefore(curElmt, prevElmt); // move each element before the previous one
|
||||||
|
}
|
||||||
|
prevElmt = curElmt;
|
||||||
|
}
|
||||||
|
return sorted;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
// Load following statements, when DOM is ready
|
// Load following statements, when DOM is ready
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
|
@ -100,17 +128,74 @@ $(function() {
|
||||||
|
|
||||||
// Use bootstrap datepicker for dateinput
|
// Use bootstrap datepicker for dateinput
|
||||||
$('.datepicker').datepicker({format: 'yyyy-mm-dd', weekStart: 1, language: 'de'});
|
$('.datepicker').datepicker({format: 'yyyy-mm-dd', weekStart: 1, language: 'de'});
|
||||||
|
|
||||||
|
// Init table sorting
|
||||||
|
var myBars = $('span.sorter-bar');
|
||||||
|
myBars.html('<button type="button" class="sorter-button btn btn-mini"><i class="icon-chevron-up"></i></button><button type="button" class="sorter-button btn btn-mini"><i class="icon-chevron-down"></i></button>');
|
||||||
|
$('button:nth-child(1)', myBars).click(function(e) {sortTable(e, false);}).attr('title', 'Sortiere aufsteigend');
|
||||||
|
$('button:nth-child(2)', myBars).click(function(e) {sortTable(e, true);}).attr('title', 'Sortiere absteigend (umgekehrt)');
|
||||||
|
|
||||||
|
$('span.sorter-bar.default-sort-asc button:nth-child(1)').trigger('click');
|
||||||
|
$('span.sorter-bar.default-sort-desc button:nth-child(2)').trigger('click');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// parse a string to a float
|
||||||
|
function myFloatParse(input) {
|
||||||
|
var number = input.trim();
|
||||||
|
number = number.split(' ')[0];
|
||||||
|
number = number.replace(',', '.');
|
||||||
|
number = parseFloat(number, 10);
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compare two elements interpreted as text
|
||||||
|
function compareText(a, b) {
|
||||||
|
return $.trim(a.textContent).toLowerCase() < $.trim(b.textContent).toLowerCase() ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compare two elements interpreted as float
|
||||||
|
function compareFloat(a, b) {
|
||||||
|
a = myFloatParse( $(a).text() );
|
||||||
|
b = myFloatParse( $(b).text() );
|
||||||
|
return ( a<b ) ? ( -1 ) : ( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// wrapper for $.fn.sorter (see above) for sorting tables
|
||||||
|
function sortTable(e, inverted) {
|
||||||
|
var sign = ( inverted ) ? ( -1 ) : ( 1 );
|
||||||
|
|
||||||
|
var myBar = $(e.currentTarget).closest('.sorter-bar'); // bar containing the clicked up/down arrow
|
||||||
|
var sortCriterion = myBar.data('sortCriterion'); // class name of (usually td) elements which define the order
|
||||||
|
var compareFunction = myBar.data('compareFunction'); // function to compare two element contents for ordering
|
||||||
|
var sortElement = myBar.data('sortElement'); // name of function which returns the movable element (default: 'thisParent')
|
||||||
|
var myTable = myBar.closest('table'); // table to sort
|
||||||
|
|
||||||
|
sortElement = ( 'undefined' === typeof sortElement ) ? ( function() {return this.parentNode;} ) : ( window[sortElement] ); // is this dirty?
|
||||||
|
|
||||||
|
$('.' + sortCriterion, myTable).sorter(
|
||||||
|
function(a, b) {
|
||||||
|
return sign*window[compareFunction](a, b); // again dirty?
|
||||||
|
},
|
||||||
|
sortElement
|
||||||
|
);
|
||||||
|
|
||||||
|
$('.sorter-button', myTable).removeClass('btn-primary active');
|
||||||
|
$(e.currentTarget).addClass('btn-primary active');
|
||||||
|
}
|
||||||
|
|
||||||
|
// resort a certain table (e.g. after DOM update)
|
||||||
|
function updateSort(whichTable) {
|
||||||
|
$('.sorter-bar button.active.btn-primary', whichTable).trigger('click');
|
||||||
|
}
|
||||||
|
|
||||||
// gives the row an yellow background
|
// gives the row an yellow background
|
||||||
function highlightRow(checkbox) {
|
function highlightRow(checkbox) {
|
||||||
var row = checkbox.closest('tr');
|
var row = checkbox.closest('tr');
|
||||||
if (checkbox.is(':checked')) {
|
if (checkbox.is(':checked')) {
|
||||||
row.addClass('selected');
|
row.addClass('selected');
|
||||||
} else {
|
} else {
|
||||||
row.removeClass('selected');
|
row.removeClass('selected');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use with auto_complete to set a unique id,
|
// Use with auto_complete to set a unique id,
|
||||||
|
@ -118,4 +203,4 @@ function highlightRow(checkbox) {
|
||||||
// There must be a hidden field with the id 'hidden_field'
|
// There must be a hidden field with the id 'hidden_field'
|
||||||
function setHiddenId(text, li) {
|
function setHiddenId(text, li) {
|
||||||
$('hidden_id').value = li.id;
|
$('hidden_id').value = li.id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,43 +5,24 @@ class DeliveriesController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@deliveries = @supplier.deliveries.all :order => 'delivered_on DESC'
|
@deliveries = @supplier.deliveries.all :order => 'delivered_on DESC'
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html # index.html.erb
|
|
||||||
format.xml { render :xml => @deliveries }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@delivery = Delivery.find(params[:id])
|
@delivery = Delivery.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html # show.html.erb
|
|
||||||
format.xml { render :xml => @delivery }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@delivery = @supplier.deliveries.build
|
@delivery = @supplier.deliveries.build
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html # new.html.erb
|
|
||||||
format.xml { render :xml => @delivery }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@delivery = Delivery.new(params[:delivery])
|
@delivery = Delivery.new(params[:delivery])
|
||||||
|
|
||||||
respond_to do |format|
|
if @delivery.save
|
||||||
if @delivery.save
|
flash[:notice] = I18n.t('deliveries.create.notice')
|
||||||
flash[:notice] = I18n.t('deliveries.create.notice')
|
redirect_to [@supplier, @delivery]
|
||||||
format.html { redirect_to([@supplier,@delivery]) }
|
else
|
||||||
format.xml { render :xml => @delivery, :status => :created, :location => @delivery }
|
render :action => "new"
|
||||||
else
|
|
||||||
format.html { render :action => "new" }
|
|
||||||
format.xml { render :xml => @delivery.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -52,15 +33,11 @@ class DeliveriesController < ApplicationController
|
||||||
def update
|
def update
|
||||||
@delivery = Delivery.find(params[:id])
|
@delivery = Delivery.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
if @delivery.update_attributes(params[:delivery])
|
||||||
if @delivery.update_attributes(params[:delivery])
|
flash[:notice] = I18n.t('deliveries.update.notice')
|
||||||
flash[:notice] = I18n.t('deliveries.update.notice')
|
redirect_to [@supplier,@delivery]
|
||||||
format.html { redirect_to([@supplier,@delivery]) }
|
else
|
||||||
format.xml { head :ok }
|
render :action => "edit"
|
||||||
else
|
|
||||||
format.html { render :action => "edit" }
|
|
||||||
format.xml { render :xml => @delivery.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,19 +46,23 @@ class DeliveriesController < ApplicationController
|
||||||
@delivery.destroy
|
@delivery.destroy
|
||||||
|
|
||||||
flash[:notice] = I18n.t('deliveries.destroy.notice')
|
flash[:notice] = I18n.t('deliveries.destroy.notice')
|
||||||
respond_to do |format|
|
redirect_to supplier_deliveries_url(@supplier)
|
||||||
format.html { redirect_to(supplier_deliveries_url(@supplier)) }
|
|
||||||
format.xml { head :ok }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_stock_article
|
def new_stock_article
|
||||||
@stock_article = @supplier.stock_articles.build
|
@old_stock_article = StockArticle.find_by_id(params[:old_stock_article_id])
|
||||||
|
|
||||||
|
unless @old_stock_article.nil?
|
||||||
|
@stock_article = @old_stock_article.dup
|
||||||
|
else
|
||||||
|
@stock_article = @supplier.stock_articles.build
|
||||||
|
end
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_stock_article
|
def add_stock_article
|
||||||
@stock_article = StockArticle.new(params[:stock_article])
|
@stock_article = StockArticle.new(params[:stock_article])
|
||||||
|
|
||||||
if @stock_article.valid? and @stock_article.save
|
if @stock_article.valid? and @stock_article.save
|
||||||
render :layout => false
|
render :layout => false
|
||||||
else
|
else
|
||||||
|
@ -89,17 +70,25 @@ class DeliveriesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_stock_change
|
def edit_stock_article
|
||||||
|
@stock_article = StockArticle.find(params[:stock_article_id])
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def fill_new_stock_article_form
|
def update_stock_article
|
||||||
article = Article.find(params[:article_id])
|
@stock_article = StockArticle.find(params[:stock_article][:id])
|
||||||
@supplier = article.supplier
|
|
||||||
stock_article = @supplier.stock_articles.build(
|
if @stock_article.update_attributes(params[:stock_article])
|
||||||
article.attributes.reject { |attr| attr == ('id' || 'type')}
|
render :layout => false
|
||||||
)
|
else
|
||||||
|
render :action => 'edit_stock_article', :layout => false
|
||||||
render :partial => 'stock_article_form', :locals => {:stock_article => stock_article}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_stock_change
|
||||||
|
@stock_change = StockChange.new
|
||||||
|
@stock_change.stock_article = StockArticle.find(params[:stock_article_id])
|
||||||
|
render :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,4 +14,8 @@ module DeliveriesHelper
|
||||||
supplier.stock_articles.undeleted.reorder('articles.name ASC').map {|a| ["#{a.name} (#{number_to_currency a.price}/#{a.unit})", a.id] }
|
supplier.stock_articles.undeleted.reorder('articles.name ASC').map {|a| ["#{a.name} (#{number_to_currency a.price}/#{a.unit})", a.id] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stock_articles_for_table(supplier)
|
||||||
|
supplier.stock_articles.undeleted.reorder('articles.name COLLATE NOCASE ASC')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,10 @@ class Delivery < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :supplier
|
belongs_to :supplier
|
||||||
has_one :invoice
|
has_one :invoice
|
||||||
has_many :stock_changes, :dependent => :destroy
|
has_many :stock_changes,
|
||||||
|
:dependent => :destroy,
|
||||||
|
:include => 'stock_article',
|
||||||
|
:order => 'articles.name COLLATE NOCASE ASC'
|
||||||
|
|
||||||
scope :recent, :order => 'created_at DESC', :limit => 10
|
scope :recent, :order => 'created_at DESC', :limit => 10
|
||||||
|
|
||||||
|
@ -15,6 +18,10 @@ class Delivery < ActiveRecord::Base
|
||||||
stock_changes.build(attributes) unless attributes[:quantity].to_i == 0
|
stock_changes.build(attributes) unless attributes[:quantity].to_i == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def includes_article?(article)
|
||||||
|
self.stock_changes.map{|stock_change| stock_change.stock_article.id}.include? article.id
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,42 +2,94 @@
|
||||||
:javascript
|
:javascript
|
||||||
$(function() {
|
$(function() {
|
||||||
$('.destroy_stock_change').live('click', function() {
|
$('.destroy_stock_change').live('click', function() {
|
||||||
$(this).prev('input').val('1').parent().hide();
|
$(this).prev('input').val('1'); // check for destruction
|
||||||
|
|
||||||
|
var stock_change = $(this).closest('tr');
|
||||||
|
stock_change.hide(); // do not remove (to ensure destruction)
|
||||||
|
unmark_article_unavailable_for_delivery( stock_change.data('id') );
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.remove_new_stock_change').live('click', function() {
|
$('.remove_new_stock_change').live('click', function() {
|
||||||
$(this).parent().remove();
|
var stock_change = $(this).closest('tr');
|
||||||
|
stock_change.remove();
|
||||||
|
unmark_article_unavailable_for_delivery( stock_change.data('id') );
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
function mark_article_unavailable_for_delivery(stock_article_id) {
|
||||||
|
var articleTr = $('#stock_article_' + stock_article_id);
|
||||||
|
articleTr.addClass('unavailable');
|
||||||
|
$('.button-add-stock-change', articleTr).attr('disabled', 'disabled');
|
||||||
|
}
|
||||||
|
function unmark_article_unavailable_for_delivery(stock_article_id) {
|
||||||
|
var articleTr = $('#stock_article_' + stock_article_id);
|
||||||
|
articleTr.removeClass('unavailable');
|
||||||
|
$('.button-add-stock-change', articleTr).removeAttr('disabled');
|
||||||
|
}
|
||||||
|
function is_article_unavailable_for_delivery(stock_article_id) {
|
||||||
|
var articleTr = $('#stock_article_' + stock_article_id);
|
||||||
|
return articleTr.hasClass('unavailable');
|
||||||
|
}
|
||||||
|
|
||||||
- content_for :javascript do
|
-# remove validate true for the form, because it disabled html5 validation
|
||||||
:javascript
|
-# is there anything broken with the simple_form validation? (bootstrap issue?)
|
||||||
$(function() {
|
= simple_form_for [@supplier, @delivery] do |f|
|
||||||
$('#add-stock-change').click();
|
|
||||||
});
|
|
||||||
|
|
||||||
.well.well-small
|
|
||||||
.btn-toolbar
|
|
||||||
.btn-group
|
|
||||||
= link_to t('.new_stock_article'), new_stock_article_supplier_deliveries_path(@supplier), remote: true, class: 'btn'
|
|
||||||
|
|
||||||
= simple_form_for [@supplier, @delivery], validate: true do |f|
|
|
||||||
= f.hidden_field :supplier_id
|
= f.hidden_field :supplier_id
|
||||||
#stock_changes
|
.row-fluid
|
||||||
= f.fields_for :stock_changes do |stock_change_form|
|
|
||||||
%p
|
.span6
|
||||||
= stock_change_form.select :stock_article_id, stock_articles_for_select(@supplier)
|
%h2 #{t '.title_select_stock_articles'}
|
||||||
Menge
|
.well.well-small
|
||||||
= stock_change_form.text_field :quantity, size: 5, autocomplete: 'off'
|
.btn-toolbar
|
||||||
= stock_change_form.hidden_field :_destroy
|
.btn-group
|
||||||
= link_to t('.remove_article'), "#", class: 'destroy_stock_change'
|
= link_to t('.new_stock_article'), new_stock_article_supplier_deliveries_path(@supplier), remote: true, class: 'btn'
|
||||||
%p
|
%table.table.table-condensed.table-hover#stock_articles_for_adding
|
||||||
= link_to t('.add_article'), {action: 'add_stock_change', supplier_id: @supplier.id}, :id => 'add-stock-change', remote: true, class: 'btn btn-small btn-primary'
|
%thead
|
||||||
%hr/
|
%tr
|
||||||
= f.input :delivered_on, as: :date_picker
|
%th
|
||||||
= f.input :note, input_html: {size: '35x4'}
|
= t '.article'
|
||||||
.form-actions
|
%span.sorter-bar.default-sort-asc{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-name'}}
|
||||||
= f.submit class: 'btn btn-primary'
|
%th= t '.unit'
|
||||||
= link_to t('ui.or_cancel'), supplier_deliveries_path(@supplier)
|
%th
|
||||||
|
= t '.price'
|
||||||
|
%span.sorter-bar{:data => {'compare-function' => 'compareFloat', 'sort-criterion' => 'sort-by-price'}}
|
||||||
|
%th= t '.vat'
|
||||||
|
%th
|
||||||
|
= t '.category'
|
||||||
|
%span.sorter-bar{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-category'}}
|
||||||
|
%th= t '.actions'
|
||||||
|
%tbody
|
||||||
|
- for article in stock_articles_for_table(@supplier)
|
||||||
|
= render :partial => 'stock_article_for_adding', :locals => {:article => article}
|
||||||
|
|
||||||
|
.span6
|
||||||
|
%h2 #{t '.title_fill_quantities'}
|
||||||
|
%table.table.table-condensed#stock_changes
|
||||||
|
%thead
|
||||||
|
%tr
|
||||||
|
%th
|
||||||
|
= t '.article'
|
||||||
|
%span.sorter-bar.default-sort-asc{:data => {'compare-function' => 'compareText', 'sort-criterion' => 'sort-by-name'}}
|
||||||
|
%th= t '.price_per_unit'
|
||||||
|
%th= t '.quantity'
|
||||||
|
%th= t '.actions'
|
||||||
|
%tbody
|
||||||
|
= f.fields_for :stock_changes do |stock_change_form|
|
||||||
|
- stock_change = stock_change_form.object
|
||||||
|
%tr{:id => "stock_change_stock_article_#{stock_change.stock_article.id}", :data => {:id => stock_change.stock_article.id}}
|
||||||
|
%td.sort-by-name
|
||||||
|
= stock_change_form.hidden_field :stock_article_id
|
||||||
|
%span.stock_article_name= stock_change.stock_article.name
|
||||||
|
%td.numeric.price-per-unit #{number_to_currency stock_change.stock_article.price}/#{stock_change.stock_article.unit}
|
||||||
|
%td= stock_change_form.text_field :quantity, :size => 5, :autocomplete => 'off'
|
||||||
|
%td
|
||||||
|
= stock_change_form.hidden_field :_destroy
|
||||||
|
= link_to t('.remove_article'), "#", :class => 'destroy_stock_change btn btn-small'
|
||||||
|
|
||||||
|
%h2 #{t '.title_finish_delivery'}
|
||||||
|
= f.input :delivered_on, as: :date_picker
|
||||||
|
= f.input :note, input_html: {size: '35x4'}
|
||||||
|
.form-actions
|
||||||
|
= f.submit class: 'btn btn-primary'
|
||||||
|
= link_to t('ui.or_cancel'), supplier_deliveries_path(@supplier)
|
||||||
|
|
16
app/views/deliveries/_stock_article_for_adding.html.haml
Normal file
16
app/views/deliveries/_stock_article_for_adding.html.haml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
- css_class = ( @delivery and @delivery.includes_article? article ) ? ( 'unavailable' ) : ( false )
|
||||||
|
%tr{:id => "stock_article_#{article.id}", :class => css_class}
|
||||||
|
%td.sort-by-name
|
||||||
|
= article.name
|
||||||
|
%td.numeric= article.unit
|
||||||
|
%td.numeric= number_to_currency article.price
|
||||||
|
%td.numeric= number_to_percentage article.tax
|
||||||
|
%td.sort-by-category= article.article_category.name
|
||||||
|
%td
|
||||||
|
.btn-group
|
||||||
|
= link_to t('.action_edit'), edit_stock_article_supplier_deliveries_path(@supplier, :stock_article_id => article.id), remote: true, class: 'btn btn-mini'
|
||||||
|
= link_to t('.action_other_price'), new_stock_article_supplier_deliveries_path(@supplier, :old_stock_article_id => article.id), remote: true, class: 'btn btn-mini'
|
||||||
|
- if @delivery and @delivery.includes_article? article
|
||||||
|
= link_to t('.action_add_to_delivery'), add_stock_change_supplier_deliveries_path(@supplier, :stock_article_id => article.id), :method => :post, remote: true, class: 'button-add-stock-change btn btn-mini', disabled: 'disabled'
|
||||||
|
- else
|
||||||
|
= link_to t('.action_add_to_delivery'), add_stock_change_supplier_deliveries_path(@supplier, :stock_article_id => article.id), :method => :post, remote: true, class: 'button-add-stock-change btn btn-mini'
|
|
@ -1,5 +1,8 @@
|
||||||
= simple_form_for stock_article, url: add_stock_article_supplier_deliveries_path(supplier), remote: true, validate: true do |f|
|
- url = ( stock_article.new_record? ) ? ( add_stock_article_supplier_deliveries_path(@supplier) ) : ( update_stock_article_supplier_deliveries_path(@supplier) )
|
||||||
|
= simple_form_for stock_article, url: url, remote: true, validate: true do |f|
|
||||||
= f.hidden_field :supplier_id
|
= f.hidden_field :supplier_id
|
||||||
|
- unless stock_article.new_record?
|
||||||
|
= f.hidden_field :id
|
||||||
.modal-header
|
.modal-header
|
||||||
= link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'}
|
= link_to t('ui.marks.close').html_safe, '#', class: 'close', data: {dismiss: 'modal'}
|
||||||
%h3= t 'activerecord.models.stock_article'
|
%h3= t 'activerecord.models.stock_article'
|
||||||
|
@ -12,7 +15,7 @@
|
||||||
= f.input :tax
|
= f.input :tax
|
||||||
= f.input :deposit
|
= f.input :deposit
|
||||||
- else
|
- else
|
||||||
= f.input :price, :input_html => {:disabled => 'disabled'}, :hint => t('.form.price_hint')
|
= f.input :price, :input_html => {:disabled => 'disabled'}, :hint => t('stockit.form.price_hint')
|
||||||
= f.association :article_category
|
= f.association :article_category
|
||||||
.modal-footer
|
.modal-footer
|
||||||
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
%p
|
= fields_for "delivery[new_stock_changes][]", stock_change, validate: true do |f|
|
||||||
= fields_for "delivery[new_stock_changes][]", stock_change do |form|
|
- f.object.quantity = '' if 0 == f.object.quantity
|
||||||
= form.select :stock_article_id, stock_articles_for_select(supplier)
|
%tr{:id => "stock_change_stock_article_#{stock_change.stock_article.id}", :data => {:id => stock_change.stock_article.id}}
|
||||||
Menge
|
%td.sort-by-name
|
||||||
= form.text_field :quantity, :size => 5, :autocomplete => 'off'
|
= f.hidden_field :stock_article_id
|
||||||
= link_to t('.remove_article'), "#", :class => 'remove_new_stock_change btn btn-small'
|
%span.stock_article_name= stock_change.stock_article.name
|
||||||
|
%td.numeric.price-per-unit #{number_to_currency stock_change.stock_article.price}/#{stock_change.stock_article.unit}
|
||||||
|
%td= f.text_field :quantity, :size => 4, :autocomplete => 'off', :required => true, :class => 'stock-change-quantity'
|
||||||
|
%td= link_to t('.remove_article'), "#", :class => 'remove_new_stock_change btn btn-small'
|
||||||
|
|
14
app/views/deliveries/add_stock_article.js.erb
Normal file
14
app/views/deliveries/add_stock_article.js.erb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
$('div.container-fluid').prepend(
|
||||||
|
'<%= j(render(:partial => 'shared/alert_success', :locals => {:alert_message => t('.notice', :name => @stock_article.name)})) %>'
|
||||||
|
);
|
||||||
|
|
||||||
|
$('#stock_articles_for_adding tr').removeClass('success');
|
||||||
|
|
||||||
|
$('#stock_articles_for_adding tbody').append(
|
||||||
|
$(
|
||||||
|
'<%= j(render(:partial => 'stock_article_for_adding', :locals => {:article => @stock_article})) %>'
|
||||||
|
).addClass('success')
|
||||||
|
);
|
||||||
|
updateSort('#stock_articles_for_adding');
|
||||||
|
|
||||||
|
$('#modalContainer').modal('hide');
|
|
@ -1,3 +0,0 @@
|
||||||
$('div.container-fluid').prepend('#{j(render(:partial => 'shared/alert_success', :locals => {:alert_message => t('.notice', :name => @stock_article.name)}))}');
|
|
||||||
|
|
||||||
$('#modalContainer').modal('hide');
|
|
20
app/views/deliveries/add_stock_change.js.erb
Normal file
20
app/views/deliveries/add_stock_change.js.erb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
if(!is_article_unavailable_for_delivery(<%= @stock_change.stock_article.id %>)) {
|
||||||
|
<%# would be easier to return in the opposite case, but how? %>
|
||||||
|
|
||||||
|
mark_article_unavailable_for_delivery(<%= @stock_change.stock_article.id %>);
|
||||||
|
|
||||||
|
(function(w) {
|
||||||
|
$('#stock_changes tr').removeClass('success');
|
||||||
|
|
||||||
|
var stock_change = $(
|
||||||
|
'<%= j(render(:partial => 'stock_change', :locals => {:stock_change => @stock_change})) %>'
|
||||||
|
).addClass('success');
|
||||||
|
|
||||||
|
$('#stock_changes').append(stock_change);
|
||||||
|
updateSort('#stock_changes');
|
||||||
|
|
||||||
|
var quantity = w.prompt('<%= j(t('.how_many_units', :unit => @stock_change.stock_article.unit, :name => @stock_change.stock_article.name)) %>'); <%# how to properly escape here? %>
|
||||||
|
$('input.stock-change-quantity', stock_change).val(quantity);
|
||||||
|
})(window);
|
||||||
|
|
||||||
|
}
|
|
@ -1 +0,0 @@
|
||||||
$('#stock_changes').append('#{escape_javascript(render(:partial => 'stock_change', :locals => {:stock_change => StockChange.new, :supplier => @supplier}))}');
|
|
5
app/views/deliveries/edit_stock_article.js.erb
Normal file
5
app/views/deliveries/edit_stock_article.js.erb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$('#modalContainer').html(
|
||||||
|
'<%= j(render(:partial => "stock_article_form", :locals => {:stock_article => @stock_article})) %>'
|
||||||
|
);
|
||||||
|
|
||||||
|
$('#modalContainer').modal();
|
5
app/views/deliveries/new_stock_article.js.erb
Normal file
5
app/views/deliveries/new_stock_article.js.erb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
$('#modalContainer').html(
|
||||||
|
'<%= j(render(:partial => "stock_article_form", :locals => {:stock_article => @stock_article})) %>'
|
||||||
|
);
|
||||||
|
|
||||||
|
$('#modalContainer').modal();
|
|
@ -1,2 +0,0 @@
|
||||||
$('#modalContainer').html('#{j(render(:partial => "stock_article_form", :locals => {:stock_article => @stock_article, :supplier => @supplier}))}');
|
|
||||||
$('#modalContainer').modal();
|
|
35
app/views/deliveries/update_stock_article.js.erb
Normal file
35
app/views/deliveries/update_stock_article.js.erb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
$('div.container-fluid').prepend(
|
||||||
|
'<%= j(render(:partial => 'shared/alert_success', :locals => {:alert_message => t('.notice', :name => @stock_article.name)})) %>'
|
||||||
|
);
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
$('#stock_articles_for_adding tr').removeClass('success');
|
||||||
|
|
||||||
|
var old_entry = $('#stock_article_<%= @stock_article.id %>');
|
||||||
|
var unavailable = old_entry.hasClass('unavailable');
|
||||||
|
var stock_article_for_adding = $(
|
||||||
|
'<%= j(render(:partial => 'stock_article_for_adding', :locals => {:article => @stock_article, :delivery => @delivery})) %>'
|
||||||
|
).addClass('success');
|
||||||
|
|
||||||
|
if(unavailable) {
|
||||||
|
stock_article_for_adding.addClass('unavailable');
|
||||||
|
$('.button-add-stock-change', stock_article_for_adding).attr('disabled', 'disabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
old_entry.replaceWith(stock_article_for_adding);
|
||||||
|
updateSort('#stock_articles_for_adding');
|
||||||
|
|
||||||
|
$('#stock_changes tr').removeClass('success');
|
||||||
|
|
||||||
|
var stock_change_entry = $('#stock_change_stock_article_<%= @stock_article.id %>');
|
||||||
|
$('.stock_article_name', stock_change_entry).text('<%= j(@stock_article.name) %>');
|
||||||
|
$('.price-per-unit', stock_change_entry).text(
|
||||||
|
'<%= "#{j(number_to_currency(@stock_article.price))}/#{j(number_to_currency(@stock_article.unit))}" %>'
|
||||||
|
);
|
||||||
|
|
||||||
|
stock_change_entry.addClass('success');
|
||||||
|
|
||||||
|
updateSort('#stock_changes');
|
||||||
|
})();
|
||||||
|
|
||||||
|
$('#modalContainer').modal('hide');
|
|
@ -416,8 +416,10 @@ de:
|
||||||
second: Sekunden
|
second: Sekunden
|
||||||
year: Jahr
|
year: Jahr
|
||||||
deliveries:
|
deliveries:
|
||||||
|
add_stock_change:
|
||||||
|
how_many_units: Wie viele Einheiten (%{unit}) des Artikels »%{name}« liefern?
|
||||||
add_stock_article:
|
add_stock_article:
|
||||||
notice: Neuer Lagerartikel »%{name}« gespeichert. Zum Auswählen bitte erneut einen Lagerartikel der Lieferung hinzufügen.
|
notice: Neuer Lagerartikel »%{name}« gespeichert.
|
||||||
create:
|
create:
|
||||||
notice: Lieferung wurde erstellt. Bitte nicht vergessen die Rechnung anzulegen!
|
notice: Lieferung wurde erstellt. Bitte nicht vergessen die Rechnung anzulegen!
|
||||||
destroy:
|
destroy:
|
||||||
|
@ -425,14 +427,22 @@ de:
|
||||||
edit:
|
edit:
|
||||||
title: Lieferung bearbeiten
|
title: Lieferung bearbeiten
|
||||||
form:
|
form:
|
||||||
|
actions: Optionen
|
||||||
add_article: Lagerartikel der Lieferung hinzufügen
|
add_article: Lagerartikel der Lieferung hinzufügen
|
||||||
|
article: Artikel
|
||||||
|
category: Kategorie
|
||||||
new_stock_article: Neuen Lagerartikel anlegen
|
new_stock_article: Neuen Lagerartikel anlegen
|
||||||
new_article:
|
|
||||||
search: Suche nach Artikeln aus dem <i>%{supplier}</i> Katalog
|
|
||||||
title: Neuen Lagerartikel anlegen
|
|
||||||
note_new_article: Ist ein Artikel noch nicht in der Lagerverwaltung, muss er erst %{new_link} werden.
|
note_new_article: Ist ein Artikel noch nicht in der Lagerverwaltung, muss er erst %{new_link} werden.
|
||||||
note_new_article_link: neu angelegt
|
note_new_article_link: neu angelegt
|
||||||
|
price: Preis (netto)
|
||||||
|
price_per_unit: Preis/Einheit
|
||||||
|
quantity: Menge
|
||||||
remove_article: Artikel aus Lieferung entfernen
|
remove_article: Artikel aus Lieferung entfernen
|
||||||
|
title_fill_quantities: 2. Liefermenge angeben
|
||||||
|
title_finish_delivery: 3. Lieferung abschließen
|
||||||
|
title_select_stock_articles: 1. Lagerartikel auswählen
|
||||||
|
unit: Einheit
|
||||||
|
vat: MwSt
|
||||||
index:
|
index:
|
||||||
confirm_delete: Bist Du sicher?
|
confirm_delete: Bist Du sicher?
|
||||||
new_delivery: Neue Lieferung für %{supplier} anlegen
|
new_delivery: Neue Lieferung für %{supplier} anlegen
|
||||||
|
@ -452,11 +462,17 @@ de:
|
||||||
title: Lieferung anzeigen
|
title: Lieferung anzeigen
|
||||||
title_articles: Artikel
|
title_articles: Artikel
|
||||||
unit: Einheit
|
unit: Einheit
|
||||||
|
stock_article_for_adding:
|
||||||
|
action_add_to_delivery: 'Liefern'
|
||||||
|
action_edit: 'Bearbeiten'
|
||||||
|
action_other_price: 'Anderer Preis'
|
||||||
stock_change:
|
stock_change:
|
||||||
remove_article: Artikel aus Lieferung entfernen
|
remove_article: Artikel aus Lieferung entfernen
|
||||||
suppliers_overview: Lieferantenübersicht
|
suppliers_overview: Lieferantenübersicht
|
||||||
update:
|
update:
|
||||||
notice: Lieferung wurde aktualisiert.
|
notice: Lieferung wurde aktualisiert.
|
||||||
|
update_stock_article:
|
||||||
|
notice: Lagerartikel »%{name}« aktualisiert.
|
||||||
documents:
|
documents:
|
||||||
order_by_articles:
|
order_by_articles:
|
||||||
filename: Bestellung %{name}-%{date} - Artikelsortierung
|
filename: Bestellung %{name}-%{date} - Artikelsortierung
|
||||||
|
|
|
@ -102,9 +102,13 @@ Foodsoft::Application.routes.draw do
|
||||||
get :shared_suppliers, :on => :collection
|
get :shared_suppliers, :on => :collection
|
||||||
|
|
||||||
resources :deliveries do
|
resources :deliveries do
|
||||||
post :drop_stock_change, :on => :member
|
post :add_stock_change, :on => :collection
|
||||||
|
|
||||||
get :new_stock_article, :on => :collection
|
get :new_stock_article, :on => :collection
|
||||||
post :add_stock_article, :on => :collection
|
post :add_stock_article, :on => :collection
|
||||||
|
|
||||||
|
get :edit_stock_article, :on => :collection
|
||||||
|
put :update_stock_article, :on => :collection
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :articles do
|
resources :articles do
|
||||||
|
|
Loading…
Reference in a new issue