adding ajax for sotck_movement_p_articles, fixing select width in pane hover form for stock movement_p_article, fixinf id_color method
This commit is contained in:
parent
b32ddd37f5
commit
21aab01b3d
@ -8,10 +8,8 @@ class Admin::PriceDocumentsController < ApplicationController
|
||||
|
||||
def generate_stocks
|
||||
@price_document = PriceDocument.find(params[:id])
|
||||
|
||||
@price_document.price_line_block.generate_stock
|
||||
|
||||
|
||||
redirect_to [:admin, @price_document]
|
||||
end
|
||||
|
||||
|
@ -56,7 +56,7 @@ class Admin::StockMovementLinesController < ApplicationController
|
||||
|
||||
def update
|
||||
@stock_movement_line = StockMovementLine.find(params[:id])
|
||||
|
||||
@stock_movement = @stock_movement_line.stock_movement
|
||||
|
||||
if @stock_movement_line.update_attributes(params.require(:stock_movement_line).permit!)
|
||||
|
||||
|
@ -82,22 +82,11 @@ module ApplicationHelper
|
||||
|
||||
def id_color(price_line)
|
||||
if price_line.p_articles.count == 0
|
||||
return "background-color: red"
|
||||
return "red"
|
||||
elsif price_line.p_articles.count < price_line.qte
|
||||
return "background-color: orange"
|
||||
return "orange"
|
||||
else
|
||||
return "background-color: #70ff29"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def id_color_array(price_line)
|
||||
if price_line.p_articles.count == 0
|
||||
return "background-color", "red"
|
||||
elsif price_line.p_articles.count < price_line.qte
|
||||
return "background-color", "orange"
|
||||
else
|
||||
return "background-color", "#70ff29"
|
||||
return "#70ff29"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -152,4 +152,10 @@ class StockMovement < ApplicationRecord
|
||||
return to_r
|
||||
end
|
||||
|
||||
def stock_generable
|
||||
return self.stock_movement_lines.joins(:p_articles).count == self.stock_movement_lines.sum(:qte) ? true : false
|
||||
#exclure les produit non stockable et sans SN
|
||||
#return self.price_line_block.price_lines.joins(:p_product_ref).joins(:p_product).where("p_products.stockable = ?", true).where("p_products.with_serial_number = ?", true).joins(:p_articles).count < self.price_line_block.price_lines.joins(:p_product_ref).joins(:p_product).where("p_products.stockable = ?", true).where("p_products.with_serial_number = ?", true).sum(:qte) ? false : true
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -4,8 +4,8 @@ class StockMovementLine < ApplicationRecord
|
||||
|
||||
has_many :stock_movement_line_p_articles
|
||||
has_many :p_articles, through: :stock_movement_line_p_articles
|
||||
accepts_nested_attributes_for :stock_movement_line_p_articles
|
||||
accepts_nested_attributes_for :p_articles, allow_destroy: true
|
||||
accepts_nested_attributes_for :stock_movement_line_p_articles, allow_destroy: true
|
||||
accepts_nested_attributes_for :p_articles, allow_destroy: true, allow_destroy: true
|
||||
|
||||
acts_as_caching :fields => [:tot_amount_ht, :price_u_ht]
|
||||
|
||||
@ -19,4 +19,9 @@ class StockMovementLine < ApplicationRecord
|
||||
self.ct_tot_amount_ht
|
||||
end
|
||||
end
|
||||
|
||||
def affected_qty
|
||||
return self.p_articles.count
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -210,7 +210,7 @@
|
||||
-price_line_block.price_lines.each do |price_line|
|
||||
%tbody
|
||||
%tr{id: "price_line_row_#{price_line.id}"}
|
||||
%td{style: id_color(price_line), id: "price_line_#{price_line.id}_id", onclick: "$('.p_articles_#{price_line.id}').toggle('800','swing');"}
|
||||
%td{style: "background-color: #{id_color(price_line)}", id: "price_line_#{price_line.id}_id", onclick: "$('.p_articles_#{price_line.id}').toggle('800','swing');"}
|
||||
="##{price_line.id}"
|
||||
%td
|
||||
=price_line.ref
|
||||
@ -232,7 +232,8 @@
|
||||
= link_to i(:"trash-o"), admin_price_line_path(price_line), method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true
|
||||
= link_to i(:pencil), edit_admin_price_line_path(price_line), :remote => true
|
||||
= link_to i(:eye), admin_price_line_path(price_line), :remote => true
|
||||
= link_to i(:"mobile-alt"), add_p_article_admin_price_lines_path(p_product_ref_id: price_line.p_product_ref.id, price_line_id: price_line.id), :remote => true if @price_document.price_document_type_id != 6 and price_line.p_product_ref.p_product.stockable and price_line.p_product_ref.p_product.with_serial_number
|
||||
= link_to i(:"mobile-alt"), add_p_article_admin_price_lines_path(p_product_ref_id: price_line.p_product_ref.id, price_line_id: price_line.id), :remote => true if @price_document.price_document_type_id != 6 and price_line.p_product_ref.p_product.stockable and price_line.p_product_ref.p_product.with_serial_number and !price_line_block.stock_ok
|
||||
= i(:"mobile-alt", {style: "color: rgb(143 143 143 / 80%)"}) if price_line_block.stock_ok
|
||||
-price_line.p_articles.each do |p_article|
|
||||
%tr{class: "p_articles_lines p_articles_#{price_line.id}"}
|
||||
%td
|
||||
|
@ -78,7 +78,7 @@
|
||||
%tbody
|
||||
-price_line_block.price_lines.each do |price_line|
|
||||
%tr
|
||||
%td{style: id_color(price_line), id: "price_line_#{price_line.id}", onclick: "$('.p_articles_#{price_line.id}').toggle('800','swing');"}
|
||||
%td{style: "background-color: #{id_color(price_line)}", id: "price_line_#{price_line.id}", onclick: "$('.p_articles_#{price_line.id}').toggle('800','swing');"}
|
||||
="##{price_line.id}"
|
||||
%td
|
||||
=price_line.ref
|
||||
|
@ -1,6 +1,6 @@
|
||||
$('#price_line_<%= @price_line.id %>_qte').text(<%= @price_line.qte %>)
|
||||
$('#price_line_<%= @price_line.id %>_affected_qty').text(<%= @price_line.affected_qty %>)
|
||||
$('#price_line_<%= @price_line.id %>_id').css( "<%= id_color_array(@price_line)[0] %>", "<%= id_color_array(@price_line)[1] %>" )
|
||||
$('#price_line_<%= @price_line.id %>_id').css( "background-color", "<%= id_color(@price_line) %>" )
|
||||
|
||||
<% if !@price_document.stock_ok and @price_document.stock_generable %>
|
||||
$('#generate_stock_button_price_document_<%= @price_document.id %>').removeClass('disabled')
|
||||
|
@ -1,5 +1,7 @@
|
||||
= form.input :p_article_id,
|
||||
.field
|
||||
= form.input :p_article_id,
|
||||
as: :select,
|
||||
collection: PArticle.available_articles.joins(:p_product_ref).where(p_product_ref: @stock_movement_line.p_product_ref).map{|p_article| [p_article.serialized_name, p_article.id]},
|
||||
label: "Article(s) associé(s)",
|
||||
input_html: {class:"p_article_select w-100"}
|
||||
input_html: {class:"p_article_select w-100", style:"width: 70%;"}
|
||||
%p.destroy=link_to_remove_fields "Supprimer l'article", form, {:class => "btn btn-danger", js: "remove_disabledClass();"}
|
||||
|
@ -6,8 +6,8 @@
|
||||
= f.semantic_fields_for :p_articles do |form|
|
||||
=render :partial => "admin/p_articles/form", :locals => {:form => form, @stock_movement_line => f.object}
|
||||
|
||||
%p= link_to_add_fields "Ajouter un article", f, :p_articles, {:class => "btn btn-primary", data: {qty_to_reach: @stock_movement_line.qte, qty: f.object.p_articles.count, btn_id: "add_p_article_id" }, js: "add_disabledClass();"}# if f.object.p_articles.count < f.object.qte
|
||||
-# %p= link_to_add_fields "Ajouter un article", f, :p_articles, {:class => "btn btn-primary disabled"} if f.object.p_articles.count >= f.object.qte
|
||||
%p= link_to_add_fields "Ajouter un article", f, :p_articles, {:class => "btn btn-primary", data: {qty_to_reach: @stock_movement_line.qte, qty: f.object.p_articles.count, btn_id: "add_p_article_id" }, js: "add_disabledClass();"} if f.object.p_articles.count < f.object.qte
|
||||
%p= link_to_add_fields "Ajouter un article", f, :p_articles, {:class => "btn btn-primary disabled"} if f.object.p_articles.count >= f.object.qte
|
||||
|
||||
|
||||
=render :partial => "qi/actions", :locals => {:f => f}
|
||||
|
@ -8,10 +8,43 @@
|
||||
%p= link_to_add_fields "Ajouter un article", f, :stock_movement_line_p_articles, {:class => "btn btn-primary add_stock_movement_line_p_article"} if @stock_movement_line.p_articles.count < @stock_movement_line.qte
|
||||
=render :partial => "qi/actions", :locals => {:f => f}
|
||||
|
||||
|
||||
|
||||
:javascript
|
||||
$('.p_article_select').select2();
|
||||
$('.add_stock_movement_line_p_article').click(function() {
|
||||
$('.p_article_select').last().select2();
|
||||
});
|
||||
|
||||
|
||||
var qty = parseInt($('[data-btn-id="add_p_article_id"]').data("qty"))
|
||||
window.localStorage.setItem('qty', qty);
|
||||
var qtyToReach = parseInt($('[data-btn-id="add_p_article_id"]').data("qty-to-reach"))
|
||||
|
||||
function add_disabledClass() {
|
||||
|
||||
var qty = parseInt(window.localStorage.getItem('qty'))
|
||||
qty += 1
|
||||
window.localStorage.setItem('qty', qty);
|
||||
$('[data-btn-id="add_p_article_id"]').attr('data-qty', qty);
|
||||
|
||||
if (qty >= qtyToReach) {
|
||||
$('[data-btn-id="add_p_article_id"]').addClass('disabled')
|
||||
} else {
|
||||
$('[data-btn-id="add_p_article_id"]').removeClass('disabled')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function remove_disabledClass() {
|
||||
|
||||
var qty = parseInt(window.localStorage.getItem('qty'))
|
||||
qty -= 1
|
||||
window.localStorage.setItem('qty', qty);
|
||||
$('[data-btn-id="add_p_article_id"]').attr('data-qty', qty);
|
||||
|
||||
if (qty >= qtyToReach) {
|
||||
$('[data-btn-id="add_p_article_id"]').addClass('disabled')
|
||||
} else {
|
||||
$('[data-btn-id="add_p_article_id"]').removeClass('disabled')
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,2 +1,13 @@
|
||||
$('#stock_movement_line_row_<%= @stock_movement_line.id %>').replaceWith("<%= escape_javascript(render(@stock_movement_line))%>");
|
||||
$('#stock_movement_line_<%= @stock_movement_line.id %>_qte').text(<%= @stock_movement_line.qte %>)
|
||||
$('#stock_movement_line_<%= @stock_movement_line.id %>_affected_qty').text(<%= @stock_movement_line.affected_qty %>)
|
||||
$('#stock_movement_line_<%= @stock_movement_line.id %>_id').css( "background-color", "<%= id_color(@stock_movement_line) %>" )
|
||||
|
||||
<% if !@stock_movement.stock_done and @stock_movement.stock_generable %>
|
||||
$('#generate_stock_button_stock_movement_<%= @stock_movement.id %>').removeClass('disabled')
|
||||
<% else %>
|
||||
$('#generate_stock_button_stock_movement_<%= @stock_movement.id %>').addClass('disabled')
|
||||
<% end %>
|
||||
|
||||
|
||||
//$('#stock_movement_line_row_<%= @stock_movement_line.id %>').replaceWith("<%= escape_javascript(render(@stock_movement_line))%>");
|
||||
close_pane_hover();
|
@ -20,23 +20,26 @@
|
||||
%h3 Contenu
|
||||
%table.table.table-hover.table-stripped
|
||||
%tr
|
||||
%th ID
|
||||
%th{style: "width: 25px;"} ID
|
||||
%th Produit
|
||||
%th DLUO ??
|
||||
-# %th DLUO ??
|
||||
%th Qté
|
||||
%th Qté saisie
|
||||
%th Prix / conditionnement
|
||||
%th Valeur
|
||||
%th Actions
|
||||
-@stock_movement.stock_movement_lines.each do |stock_movement_line|
|
||||
%tr
|
||||
%td
|
||||
%td{style: "background-color: #{id_color(stock_movement_line)}", id: "stock_movement_line_#{stock_movement_line.id}_id", onclick: "$('.p_articles_#{stock_movement_line.id}').toggle('800','swing');"}
|
||||
=stock_movement_line.id
|
||||
%td
|
||||
=stock_movement_line.p_product_ref.name if stock_movement_line.p_product_ref
|
||||
%td
|
||||
=l stock_movement_line.dluo if stock_movement_line.dluo
|
||||
%td
|
||||
-# %td
|
||||
-# =l stock_movement_line.dluo if stock_movement_line.dluo
|
||||
%td{id: "stock_movement_line_#{stock_movement_line.id}_qte"}
|
||||
=stock_movement_line.qte
|
||||
%td{id: "stock_movement_line_#{stock_movement_line.id}_affected_qty"}
|
||||
=stock_movement_line.affected_qty
|
||||
%td
|
||||
=number_to_currency(stock_movement_line.tot_amount_ht / stock_movement_line.qte) if stock_movement_line.tot_amount_ht
|
||||
%td
|
||||
@ -46,14 +49,24 @@
|
||||
= link_to i(:pencil), edit_admin_stock_movement_line_path(stock_movement_line), :remote => true
|
||||
= link_to i(:eye), admin_stock_movement_line_path(stock_movement_line), :remote => true
|
||||
-if @stock_movement.movement_type == "cred"
|
||||
= link_to i(:"mobile-alt"), add_p_article_admin_stock_movement_lines_path(p_product_ref_id: stock_movement_line.p_product_ref.id, stock_movement_line_id: stock_movement_line.id), :remote => true
|
||||
= link_to i(:"mobile-alt"), add_p_article_admin_stock_movement_lines_path(p_product_ref_id: stock_movement_line.p_product_ref.id, stock_movement_line_id: stock_movement_line.id), :remote => true if !@stock_movement.stock_done
|
||||
= i(:"mobile-alt", {style: "color: rgb(143 143 143 / 80%)"}) if @stock_movement.stock_done
|
||||
-else
|
||||
= link_to i(:"mobile-alt"), add_stock_movement_line_p_article_admin_stock_movement_lines_path(p_product_ref_id: stock_movement_line.p_product_ref.id, stock_movement_line_id: stock_movement_line.id), :remote => true
|
||||
|
||||
= link_to i(:"mobile-alt"), add_stock_movement_line_p_article_admin_stock_movement_lines_path(p_product_ref_id: stock_movement_line.p_product_ref.id, stock_movement_line_id: stock_movement_line.id), :remote => true if !@stock_movement.stock_done
|
||||
= i(:"mobile-alt", {style: "color: rgb(143 143 143 / 80%)"})if @stock_movement.stock_done
|
||||
-stock_movement_line.p_articles.each do |p_article|
|
||||
%tr{class: "stock_movement_lines p_articles_#{stock_movement_line.id}"}
|
||||
%td
|
||||
%td="##{p_article.id}"
|
||||
%td=p_article.p_product_ref.name
|
||||
%td
|
||||
- p_article.p_article_serial_nums.each do |sn|
|
||||
="#{sn.p_serial_num_type.name} - #{sn.value} /"
|
||||
|
||||
|
||||
%p.mt-5
|
||||
=link_to "Générer les stocks", generate_stocks_admin_stock_movement_path(@stock_movement), :class => "btn btn-primary" if !@stock_movement.stock_done
|
||||
=link_to "Générer les stocks", generate_stocks_admin_stock_movement_path(@stock_movement), :class => "btn btn-primary", id: "generate_stock_button_stock_movement_#{@stock_movement.id}" if !@stock_movement.stock_done and @stock_movement.stock_generable
|
||||
=link_to "Générer les stocks", generate_stocks_admin_stock_movement_path(@stock_movement), :class => "btn btn-primary disabled", id: "generate_stock_button_stock_movement_#{@stock_movement.id}" if !@stock_movement.stock_done and !@stock_movement.stock_generable
|
||||
|
||||
-if @stock_movement.stock_done
|
||||
%h3 Stocks générés
|
||||
@ -72,3 +85,6 @@
|
||||
|
||||
.clear
|
||||
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @line_stocks}
|
||||
|
||||
:javascript
|
||||
$('.stock_movement_lines').hide();
|
Reference in New Issue
Block a user