addin good select2 instead of autocomplete. adding bon de commande client to p custommer sheet

This commit is contained in:
Philippe 2021-11-08 18:43:44 +01:00
parent 877824fba4
commit e2ed7e5f22
15 changed files with 87 additions and 90 deletions

View File

@ -54,9 +54,9 @@ group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
# # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
# gem 'spring'
# gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
@ -118,3 +118,5 @@ gem 'axlsx_rails'
gem 'mimemagic', "0.3.10"
gem "roo"
gem "select2-rails"

View File

@ -301,6 +301,7 @@ GEM
activemodel (>= 5)
elasticsearch (>= 6)
hashie
select2-rails (4.0.13)
selenium-webdriver (3.142.3)
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
@ -308,10 +309,6 @@ GEM
sixarm_ruby_unaccent (1.2.0)
sort_alphabetical (1.1.0)
unicode_utils (>= 1.2.2)
spring (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
@ -406,9 +403,8 @@ DEPENDENCIES
roo
sass-rails (~> 5)
searchkick
select2-rails
selenium-webdriver
spring
spring-watcher-listen (~> 2.0.0)
sprockets
tiny_tds (= 1.3.0)
truncate_html

View File

@ -15,7 +15,7 @@
#= require vendor/jquery.fileupload
#= require vendor/jquery.fileupload-ui
#= require vendor/jquery.fileupload-process
#= require vendor/select2.min
#= require select2
#= require vendor/accounting
#= require vendor/jquery.mask
#= require vendor/datatables.min

View File

@ -1,3 +1,6 @@
/*
*= require select2
*/
// Variables
@import "1-variables/app";

View File

@ -98,7 +98,7 @@ class Admin::PriceDocumentsController < ApplicationController
if true
@price_documents = @price_documents.where(:price_document_type_id => params[:price_document_type_ids]) if params[:price_document_type_ids].size > 0
@price_documents = @price_documents.where(:price_document_type_id => params[:price_document_type_ids]).order(:id) if params[:price_document_type_ids].size > 0
if current_admin.p_commercial
@ -234,7 +234,6 @@ class Admin::PriceDocumentsController < ApplicationController
redirect_to admin_p_fournisseurs_path(:create_document => "Commande achat" )
else
@price_document = PriceDocument.new(:p_customer_id => params[:p_customer_id], :p_fournisseur_id => params[:p_fournisseur_id])
@price_document.price_document_type = PriceDocumentType.where(:label => params[:document_type]).first
@price_document.price_line_block = PriceLineBlock.new(:p_customer_id => params[:p_customer_id], :p_fournisseur_id => params[:p_fournisseur_id])
@ -332,7 +331,7 @@ class Admin::PriceDocumentsController < ApplicationController
if @price_document.save
#if @price_document.cc_label == "Demande prix"
if @price_document.cc_label == "Facture achat"
render action: :show
redirect_to admin_price_document_path(@price_document)
else
redirect_to admin_price_documents_path(:price_document_type_id => @price_document.price_document_type_id)
end

View File

@ -268,9 +268,11 @@ class PCustomerSheet < ApplicationRecord
self.archive_now if !self.archived
self.block_price if !self.price_blocked
price_document = self.price_documents.new(:price_document_type => PriceDocumentType.find_by_label(label), :date => Date.today)
#raise
price_document.p_customer = self.p_customer
price_document.price_line_block = self.price_line_block.dup
price_document.tva_type = self.price_line_block.price_document.tva_type
price_document.price_line_block.ac_block_type = nil
@ -278,7 +280,7 @@ class PCustomerSheet < ApplicationRecord
new_pl = pl.dup
new_pl.ac_block_type = nil
price_document.price_line_block.price_lines << new_pl
end
end
if price_document.save
@ -306,7 +308,7 @@ class PCustomerSheet < ApplicationRecord
def generate_bc
generate_doc("Bon de commande", "commande")
generate_doc("Bon de commande client", "commande")
end

View File

@ -29,6 +29,8 @@ class PriceLineBlock < ApplicationRecord
belongs_to :p_fournisseur
accepts_nested_attributes_for :p_fournisseur
belongs_to :price_document
def to_no_archive
if self.imported
@ -827,10 +829,6 @@ class PriceLineBlock < ApplicationRecord
AVOIR_TO_RESET = %w(weight_tot tot_lines_ht tot_lines_tva tot_lines_ttc tot_fdp_ht tot_fdp_tva tot_fdp_ttc tot_discount_ht tot_discount_tva tot_discount_ttc tot_amount_af_discount_ht tot_amount_af_discount_tva tot_amount_af_discount_ttc gen_discount_percent tot_gen_discount_ht tot_gen_discount_tva tot_gen_discount_ttc tot_amount_ht tot_amount_tva tot_amount_ttc nbr_ship)
end

View File

@ -11,8 +11,6 @@
-if params[:price_document_type_id]
=breadcrumb second_title: PriceDocumentType.find(params[:price_document_type_id]).label
.qi_search_row
=form_tag "", :method => "get", :onsubmit => "" do
@ -137,7 +135,7 @@
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @price_documents}
-if true #if params[:price_document_type_id].to_i != 0
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => params[:price_document_type_id].to_s}
= render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => params[:price_document_type_id].to_s}
:scss

View File

@ -63,7 +63,7 @@
=f.semantic_fields_for :price_lines do |f|
=render :partial => "admin/price_lines/form_bon_de_reception_achat", :locals => {:form => f}
%p= link_to_add_fields "Ajouter une ligneeeeeee", f, :price_lines, {:class => "btn btn-primary add_lines"}
%p= link_to_add_fields "Ajouter une ligne", f, :price_lines, {:class => "btn btn-primary add_lines"}
-if current_admin.has_permission?("payments")
@ -106,7 +106,8 @@
:javascript
$('.add_lines').click(function() {
console.log('LENGTH ' + $('.p_product_ref_select').length)
$('.p_product_ref_select').last().select2();
$('.p_product_ref_select').last().removeClass('form-control');
$('.p_product_ref_select').last().select2({
//theme: "bootstrap"
});
//$('.p_product_ref_select').last().removeClass('form-control');
})

View File

@ -1,5 +1,7 @@
=form.input :p_article_id, as: :select, collection: PArticle.all.map{|p_article| [p_article.serialized_name, p_article.id]}, label: "Article(s) associé(s)", input_html: {class:"p_article_select"}
= form.input :p_article_id, as: :select, collection: PArticle.joins(:p_product_ref).where(p_product_ref: price_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"}
:javascript
$('.p_article_select').select2();
$('.p_article_select').removeClass('form-control');
$('.p_article_select').select2({
//theme: "bootstrap"
});
//$('.p_article_select').removeClass('form-control');

View File

@ -1,8 +1,8 @@
.mx-2.my-2
=semantic_form_for [:admin, @price_line], :remote => true do |f|
=f.inputs do
.price_line_p_articles_form
.price_line_p_articles_form.col-3
= f.semantic_fields_for :price_line_p_articles do |form|
=render :partial => "admin/price_line_p_articles/form", :locals => {:form => form}
=render :partial => "admin/price_line_p_articles/form", :locals => {:form => form, price_line: @price_line}
%p= link_to_add_fields "Ajouter un article", f, :price_line_p_articles, {:class => "btn btn-primary"} if @price_line.p_articles.count < @price_line.qte
=render :partial => "qi/actions", :locals => {:f => f}

View File

@ -4,8 +4,8 @@
.take.mr-1{:style => "padding-left:10px;", :class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )}
=ic :arrows
.col-3{:style => "white-space: nowrap;"}
=form.input :p_product_ref, as: :select, collection: PProductRef.all.map{ |p_product_ref| [p_product_ref.member_label, p_product_ref.id] }, label: "Référence", input_html: {class:"p_product_ref_select"}
.col-3
= form.input :p_product_ref, as: :select, collection: PProductRef.all.map{ |p_product_ref| [p_product_ref.member_label, p_product_ref.id] }, label: "Référence :", input_html: {class:"p_product_ref_select"}
.input-group
-# %label Référence
-# %input.p_product_ref_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.member_label}" if form.object.p_product_ref), :class => "p_product_ref_name"}
@ -32,7 +32,7 @@
-# = form.input :forced_price, :label => "Prix personnalisé ?", :as => :boolean, :input_html => {:class => "form-inline input_price_line_forced_price"}
-# .forced_price_wrapper.mx-2{:style => ("display:none;" if !form.object.forced_price)}= form.input :ct_u_price_ht, :label => false, :input_html => {:class => "input_price_line_ct_u_price_ht"}
.col-3
= form.input :qte, :label => "Quantité", :input_html => {:class => "input_price_line_qte form-control p_product_ref_qte", tabindex: 1}
= form.input :qte, :label => "Quantité :", :input_html => {:class => "input_price_line_qte form-control p_product_ref_qte", tabindex: 1}
.col-3
= form.input :ct_u_price_ht, :label => "Prix Unitaire HT :", :input_html => { class: "mx-2"}
@ -43,59 +43,50 @@
= qi_js_field(form, :price_line, :tva_account_value, :hidden => true)
= form.hidden_field :position, :class => "price_line_position_input"
:javascript
$('.p_product_ref_autocomplete_input').focus()
$( function() {
$('.p_product_ref_autocomplete_input').autocomplete({
source: function( request, response ) {
$.ajax( {
url: "/admin/p_product_refs/autocomplete.json",
dataType: "json",
data: {
search: request.term,
p_customer_id: $(".p_customer_id").val()
},
success: function(data){
arr = jQuery.map( data, function( item ) {
return {
label: item.member_label,
value: item.member_label,
id: item.id
}
});
response(arr)
}
});
},
minLength: 2,
select: function( event, ui ) {
$(this).next(".p_product_ref_id").val(ui.item.id)
form = $(this).closest(".price_line_form")
$.ajax( {
url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json",
dataType: "json",
data: {
type: "price",
qte: form.find(".input_price_line_qte").val(),
p_customer_id: $(".p_customer_id").val()
},
success: function (data) {
form.find(".input_price_line_price_u_ht").val(data.price);
form.find(".input_price_line_tva_account_id").val(data.tva_account_id);
form.find(".input_price_line_tva_account_value").val(data.tva_account_value);
form.find(".input_price_line_weight_u").val(data.weight);
}
});
//return false
}
});
});
:scss
.price_line_form{
.form-group{
margin-bottom:0;}
}
-# $('.p_product_ref_autocomplete_input').focus()
-# $( function() {
-# $('.p_product_ref_autocomplete_input').autocomplete({
-# source: function( request, response ) {
-# $.ajax( {
-# url: "/admin/p_product_refs/autocomplete.json",
-# dataType: "json",
-# data: {
-# search: request.term,
-# p_customer_id: $(".p_customer_id").val()
-# },
-# success: function(data){
-# arr = jQuery.map( data, function( item ) {
-# return {
-# label: item.member_label,
-# value: item.member_label,
-# id: item.id
-# }
-# });
-# response(arr)
-# }
-# });
-# },
-# minLength: 2,
-# select: function( event, ui ) {
-# $(this).next(".p_product_ref_id").val(ui.item.id)
-# form = $(this).closest(".price_line_form")
-# $.ajax( {
-# url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json",
-# dataType: "json",
-# data: {
-# type: "price",
-# qte: form.find(".input_price_line_qte").val(),
-# p_customer_id: $(".p_customer_id").val()
-# },
-# success: function (data) {
-# form.find(".input_price_line_price_u_ht").val(data.price);
-# form.find(".input_price_line_tva_account_id").val(data.tva_account_id);
-# form.find(".input_price_line_tva_account_value").val(data.tva_account_value);
-# form.find(".input_price_line_weight_u").val(data.weight);
-# }
-# });
-# //return false
-# }
-# });
-# });

View File

@ -6,5 +6,8 @@ class AddColumnsToPriceDocsAdnPriceLineBlocks < ActiveRecord::Migration[6.0]
add_column :price_documents, :supplier_document_date, :date
add_column :price_line_blocks, :stock_entrance_date, :date
add_column :price_line_blocks, :ct_tot_amount_ht, :decimal, :precision => 14, :scale => 2
change_table :price_line_blocks do |t|
t.belongs_to :price_document
end
end
end

View File

@ -2471,7 +2471,9 @@ ActiveRecord::Schema.define(version: 2021_11_03_085623) do
t.string "cc_state"
t.date "stock_entrance_date"
t.decimal "ct_tot_amount_ht", precision: 14, scale: 2
t.bigint "price_document_id"
t.index ["p_customer_id"], name: "index_price_line_blocks_on_p_customer_id"
t.index ["price_document_id"], name: "index_price_line_blocks_on_price_document_id"
end
create_table "price_line_p_articles", force: :cascade do |t|