adding p_article stock out method

This commit is contained in:
Philippe 2021-11-17 19:52:30 +01:00
parent 6208ea74d5
commit 127f14f479
17 changed files with 266 additions and 198 deletions

View File

@ -214,7 +214,7 @@ class Admin::BuyListsController < ApplicationController
def reject
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.state = "refusée"
@p_customer_sheet.state = "Refusée"
@p_customer_sheet.save
@p_customer_sheet.archive_now if !@p_customer_sheet.archived

View File

@ -258,7 +258,7 @@ class Admin::PCustomerSheetsController < ApplicationController
def reject
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.state = "refusée"
@p_customer_sheet.state = "Refusée"
@p_customer_sheet.save
@p_customer_sheet.archive_now if !@p_customer_sheet.archived
@ -363,6 +363,5 @@ class Admin::PCustomerSheetsController < ApplicationController
}
end
end
end

View File

@ -551,28 +551,24 @@ class Admin::PriceDocumentsController < ApplicationController
if @p_customer_sheet
price_document = @p_customer_sheet.price_documents.new(:price_document_type => PriceDocumentType.find_by_label("Bon de livraison"), :bon_de_commande_id => @past_price_document.id, :date => Date.today)
price_document.p_customer = @past_price_document.p_customer
price_document.reliquat = true if @p_customer_sheet and @p_customer_sheet.price_documents.where(:cc_label => "Bon de livraison", :cancelled => false).count > 0
price_document.price_line_block = @past_price_document.price_line_block.dup
price_document.tva_type = @past_price_document.tva_type
price_document.price_line_block.ac_bon_de_commande_id = nil
price_document.price_line_block.ac_bon_de_livraison_id = nil
price_document.price_line_block.ac_facture_id = nil
price_document.price_line_block.ac_block_type = nil
price_document.price_line_block.ac_reliquat = nil
price_document.price_line_block.bk_tot_fdp_ht = price_document.price_line_block.cc_tot_fdp_ht
@past_price_document.price_line_block.price_lines.each do |pl|
new_pl = pl.dup
new_pl.price_line_ref_id = pl.id
new_pl.ac_block_type = nil
new_pl.p_articles = pl.p_articles
new_pl.save
if price_document.reliquat
bls = @p_customer_sheet.price_documents.where(:cc_label => "Bon de livraison", :cancelled => false)
@ -583,11 +579,11 @@ class Admin::PriceDocumentsController < ApplicationController
end
price_document.price_line_block.price_lines << new_pl
end
if price_document.save
price_document.reset_for_update
price_document.archive_now
@p_customer_sheet.state = "en livraison"
@p_customer_sheet.state = "Livraison"
@p_customer_sheet.save
redirect_to admin_p_customer_sheet_path(price_document.ref_element)
@ -821,14 +817,4 @@ class Admin::PriceDocumentsController < ApplicationController
end
def update_pcustomersheet_statut
@price_document = PriceDocument.find(params[:id])
state = params[:state]
@price_document.ref_element.state = state
if @price_document.ref_element.save
redirect_to [:admin, @price_document]
end
end
end

View File

@ -83,6 +83,8 @@ module TranslationHelper
r = '<span class="badge badge-success" style="background:rgb(42,171,43);">'+value+'</span>'
elsif value == "Payé"
r = '<span class="badge badge-success" style="background:rgb(110,45,116);">'+value+'</span>'
elsif value == "Refusée"
r = '<span class="badge badge-success" style="background:rgb(110,45,116);">'+value+'</span>'
end
return raw(r)

View File

@ -51,6 +51,9 @@
before_validation do
puts "SELF QTEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
puts self.qte
puts "SELF QTEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
if self.qte >= 0
self.qte_used = self.line_stock_usages.sum(:qte)
self.qte_available = self.qte - self.qte_used

View File

@ -244,12 +244,12 @@ class PCustomer < ApplicationRecord
end
def nbr_orders
self.p_customer_sheets.where(:state => "facturée")
self.p_customer_sheets.where(:state => "Payée")
end
def nbr_orders_refusees
self.p_customer_sheets.where(:state => "refusée")
self.p_customer_sheets.where(:state => "Refusée")
end

View File

@ -48,7 +48,7 @@ class PCustomerSheet < ApplicationRecord
# STATES = ["brouillon", "offre", "commande", "livrée","facturée", "annulée", "refusée"]
# STATES = ["AV BPA", "PAS BPA","BPA", "Traitée"]
STATES = ["Brouillon", "Validée", "Préparation", "Livraison", "Réceptionné", "Payé"]
STATES = ["Brouillon", "Validée", "Préparation", "Livraison", "Réceptionné", "Payé", "Refusée"]
def personalised_archive
self.price_line_block.archive_now
@ -268,77 +268,32 @@ 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)
price_document.p_customer = self.p_customer
price_document.price_line_block = self.price_line_block.dup
price_document.tva_type = TvaType.first #le type de TVA est correctement enregistrée dans le fonction generate_f pour les factures
price_document.price_line_block.ac_block_type = nil
if !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
price_document_standard_tva = self.price_documents.new(:price_document_type => PriceDocumentType.find_by_label(label), :date => Date.today, :tva_type_id => 1)
price_document_standard_tva.p_customer = self.p_customer
price_document_standard_tva.price_line_block = self.price_line_block.dup
price_document_standard_tva.price_line_block.ac_block_type = nil
self.price_line_block.price_lines.each do |pl|
if !pl.p_articles.where(tva_type_id: 1).empty?
new_pl = pl.dup
new_pl.ac_block_type = nil
pl.p_articles.where(tva_type_id: 1).each do |p_article|
new_pl.p_articles << PArticle.first
end
new_pl.save
price_document_standard_tva.price_line_block.price_lines << new_pl
end
end
if price_document_standard_tva.save
price_document_standard_tva.archive_now
self.state = state
self.save
end
self.price_line_block.price_lines.each do |pl|
new_pl = pl.dup
new_pl.ac_block_type = nil
pl.p_articles.each { |p_article| new_pl.p_articles << p_article }
price_document.price_line_block.price_lines << new_pl
end
if !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
price_document_sur_marge_tva = self.price_documents.new(:price_document_type => PriceDocumentType.find_by_label(label), :date => Date.today, :tva_type_id => 2)
price_document_sur_marge_tva.p_customer = self.p_customer
price_document_sur_marge_tva.price_line_block = self.price_line_block.dup
price_document_sur_marge_tva.price_line_block.ac_block_type = nil
self.price_line_block.price_lines.each do |pl|
if !pl.p_articles.where(tva_type_id: 2).empty?
new_pl = pl.dup
new_pl.ac_block_type = nil
pl.p_articles.where(tva_type_id: 2).each { |p_article| new_pl.p_articles << p_article }
price_document_sur_marge_tva.price_line_block.price_lines << new_pl
end
end
if price_document_sur_marge_tva.save
price_document_sur_marge_tva.archive_now
self.state = state
self.save
end
if price_document.save
price_document.archive_now
puts 'STATEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE'
puts state
puts 'STATEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE'
self.state = state
self.save
else
puts "ERRORSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
puts price_document.errors.full_messages
puts "ERRORSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
end
# price_document = self.price_documents.new(:price_document_type => PriceDocumentType.find_by_label(label), :date => Date.today)
# price_document.p_customer = self.p_customer
# price_document.price_line_block = self.price_line_block.dup
# price_document.price_line_block.ac_block_type = nil
# self.price_line_block.price_lines.each do |pl|
# new_pl = pl.dup
# new_pl.ac_block_type = nil
# pl.p_articles.each { |p_article| new_pl.p_articles << p_article }
# price_document.price_line_block.price_lines << new_pl
# end
# if price_document.save
# price_document.archive_now
# self.state = state
# self.save
# end
end
def generate_d
@ -368,8 +323,58 @@ class PCustomerSheet < ApplicationRecord
end
def generate_f()
#generate_doc("Facture", "Payé") On n'appelle plus la fonction generate doc car on veut générer 1 facture par type de TVA présent dans la commande
generate_doc("Facture", "Payé")
self.archive_now if !self.archived
self.block_price if !self.price_blocked
if !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
price_document_standard_tva = self.price_documents.new(:price_document_type => PriceDocumentType.find_by_label("Facture"), :date => Date.today, :tva_type_id => 1)
price_document_standard_tva.p_customer = self.p_customer
price_document_standard_tva.price_line_block = self.price_line_block.dup
price_document_standard_tva.price_line_block.ac_block_type = nil
self.price_line_block.price_lines.each do |pl|
if !pl.p_articles.where(tva_type_id: 1).empty?
new_pl = pl.dup
new_pl.ac_block_type = nil
pl.p_articles.where(tva_type_id: 1).each do |p_article|
new_pl.p_articles << pl.p_articles
end
new_pl.save
price_document_standard_tva.price_line_block.price_lines << new_pl
end
end
if price_document_standard_tva.save
price_document_standard_tva.archive_now
self.state = "Payé"
self.save
end
end
if !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
price_document_sur_marge_tva = self.price_documents.new(:price_document_type => PriceDocumentType.find_by_label("Facture"), :date => Date.today, :tva_type_id => 2)
price_document_sur_marge_tva.p_customer = self.p_customer
price_document_sur_marge_tva.price_line_block = self.price_line_block.dup
price_document_sur_marge_tva.price_line_block.ac_block_type = nil
self.price_line_block.price_lines.each do |pl|
if !pl.p_articles.where(tva_type_id: 2).empty?
new_pl = pl.dup
new_pl.ac_block_type = nil
pl.p_articles.where(tva_type_id: 2).each { |p_article| new_pl.p_articles << p_article }
price_document_sur_marge_tva.price_line_block.price_lines << new_pl
end
end
if price_document_sur_marge_tva.save
price_document_sur_marge_tva.archive_now
self.state = "Payé"
self.save
end
end
end

View File

@ -32,7 +32,7 @@ class PProduct < ApplicationRecord
belongs_to :p_product_cat
belongs_to :s_brand
validates :s_brand, :presence => true
validates :name, :presence => true, exclusion: { in: ["--> Selectioner un produit <--"], message: "Selectioner un produit avant de valider" }
validates :code, :presence => true, :uniqueness => true, exclusion: { in: ["--> Indiquer un code produit <--"], message: "Indiquer un code produit avant de valider" }

View File

@ -26,7 +26,7 @@ class PriceDocument < ApplicationRecord
#PURCHASES = ["Demande prix", "Réponse fournisseur", "Commande achat", "Facture achat", "Consultation fournisseur"]
PURCHASES = ["Facture achat", "Bon de réception achat"]
SALES = ["Devis", "Avoir", "Facture", "Bon de livraison", "Bon de commande"]
SALES = ["Facture", "Bon de livraison", "Bon de commande"]
# AVANCEMENT = ["0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"]
AVANCEMENT = ["0%", "25%", "50%", "75%", "100"]
@ -266,6 +266,7 @@ class PriceDocument < ApplicationRecord
:id => {:name => "ID", :reorder => false},
:actions => {:name => "Actions", :reorder => false},
:label => {:name => "Type", :reorder => false},
:p_customer_code => {:name => "Code client", :reorder => false},
#:avancement => {:name => "Avancement (%)", :reorder => true},
#:list_designaton => {:name => "Designation liste", :reorder => true},
@ -279,7 +280,6 @@ class PriceDocument < ApplicationRecord
:public_fournisseur_name => {:name => "Nom fournisseur saisi", :reorder => false},
:p_fournisseur => {:name => "Fournisseur", :reorder => false},
:com_counter => {:name => "N° Offre", :reorder => false},
:label => {:name => "Type", :reorder => false},
:stock_ok => {:name => "Stock mis à jour ?", :reorder => true},
#:tva_type_name => {:name => "Type de TVA", :reorder => true},
#:package_number => {:name => "Nombre de colis", :reorder => true},
@ -777,8 +777,9 @@ class PriceDocument < ApplicationRecord
end
def stock_generable
return self.price_line_block.price_lines.joins(:p_articles).count < self.price_line_block.price_lines.sum(:qte) ? false : true
return self.price_line_block.price_lines.joins(:p_articles).count == self.price_line_block.price_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

View File

@ -123,10 +123,65 @@ class PriceLineBlock < ApplicationRecord
def update_stocks_for(p_product_ref, qte, pl)
puts "TEST"
puts "Référence : #{p_product_ref.id} #{p_product_ref.p_product.name}"
if qte.to_f != 0.0
decr_line_stock = LineStock.create(:date => self.price_lineable.date,
if !pl.p_articles.empty?
pl.p_articles.each do |p_article|
decr_line_stock = LineStock.new(:date => self.price_lineable.date,
:p_product_ref => p_product_ref,
:qte => -1,
:description => "Attribution à la ligne d'une facture",
:price_ht => 0.0,
:price_line => pl,
:price_line_block => self,
:stockable => self.price_lineable)
price = 0.0
line_stock_usages = []
#qte_to_affect = qte
lsu_p_art = LineStockUsage.where(p_article_id: p_article.id)
# ls = LineStock.joins(:p_articles).joins(:line_stock_usages).where("p_articles.id = ?", p_article.id).where.not("line_stock_usages.p_article").order(:date).last
# ls = LineStock.joins(:p_articles).joins(:line_stock_usages).where("p_articles.id = ?", 69).where.not("line_stock_usages.p_article_id = ?", 69).order(:date).last
# used_line_stock_p_article = line_stocks_p_article.joins(:line_stock_usages).where("line_stock_usages.p_article_id = ?", p_article.id).order(date: :desc).last
# line_stocks_p_article = LineStock.joins(:p_articles).where("p_articles.id = ?", p_article.id)
line_stocks_p_article = p_article.line_stocks.where("qte_available > ?", 0) #LineStock.joins(:p_articles).where("p_articles.id = ?", p_article.id)
ls = nil
line_stocks_p_article.each do |p_article_line_stock|
if p_article_line_stock.line_stock_usages.where(p_article_id: p_article).empty?
ls = p_article_line_stock
end
end
#ls = LineStock.joins(:p_articles).where("p_articles.id = ?", p_article.id).joins(:line_stock_usages)
#ls.qte_available = ls.qte_available - 1
#qte_to_affect = qte_to_affect - qte_here
lsu = LineStockUsage.create(:qte => 1, :line_stock => ls, :dest_line_stock_id => decr_line_stock.id, p_article_id: p_article.id)
#line_stock_usages << lsu
price += lsu.price_ht
ls.save
decr_line_stock.price_ht = price * -1
decr_line_stock.save
ls_p_art = LineStockPArticle.new(
p_article: p_article,
line_stock: decr_line_stock
)
ls_p_art.save
end
else
#===================================================================================================================
puts "TEST"
puts "Référence : #{p_product_ref.id} #{p_product_ref.p_product.name}"
if qte.to_f != 0.0
decr_line_stock = LineStock.create(:date => self.price_lineable.date,
:p_product_ref => p_product_ref,
:qte => qte*-1,
:description => "Attribution à la ligne d'une facture",
@ -134,33 +189,37 @@ class PriceLineBlock < ApplicationRecord
:price_line => pl,
:price_line_block => self,
:stockable => self.price_lineable)
price = 0.0
line_stock_usages = []
qte_to_affect = qte
LineStock.where(:p_product_ref_id => p_product_ref.id).where("date <= ?", self.price_lineable.date).where("qte_available > 0.0").each do |ls|
if qte_to_affect <= ls.qte_available
qte_here = qte_to_affect
else
qte_here = ls.qte_available
price = 0.0
line_stock_usages = []
qte_to_affect = qte
#LineStock.where(:p_product_ref_id => p_product_ref.id).where("date <= ?", self.price_lineable.date).where("qte_available > 0.0").each do |ls|
LineStock.where(:p_product_ref_id => p_product_ref.id).where("date <= ?", self.price_lineable.date).where("qte_available > 0.0").each do |ls|
if qte_to_affect <= ls.qte_available
qte_here = qte_to_affect
else
qte_here = ls.qte_available
end
qte_to_affect = qte_to_affect - qte_here
lsu = LineStockUsage.create(:qte => qte_here, :line_stock => ls, :dest_line_stock_id => decr_line_stock.id)
line_stock_usages << lsu
price += lsu.price_ht
ls.save
break if qte_to_affect == 0.0
#price_u_ht
end
qte_to_affect = qte_to_affect - qte_here
lsu = LineStockUsage.create(:qte => qte_here, :line_stock => ls, :dest_line_stock_id => decr_line_stock.id)
line_stock_usages << lsu
price += lsu.price_ht
ls.save
break if qte_to_affect == 0.0
#price_u_ht
decr_line_stock.p_articles = pl.p_articles
decr_line_stock.price_ht = price * -1
decr_line_stock.save
end
decr_line_stock.p_articles = pl.p_articles
decr_line_stock.price_ht = price * -1
decr_line_stock.save
#===================================================================================================================
end
end
def update_stocks
@ -203,6 +262,8 @@ class PriceLineBlock < ApplicationRecord
ls.p_articles = pl.p_articles
ls.save
end
pl.p_articles.joins(:p_grade).where(p_grades: {grade: "RMA"}).each do |p_article|
decr_line_stock = LineStock.new(
:date => self.price_lineable.date,
@ -216,6 +277,11 @@ class PriceLineBlock < ApplicationRecord
decr_line_stock.p_articles << p_article
decr_line_stock.save
end
end

View File

@ -1,8 +1,8 @@
.qi_header
.right
=raw @p_customer_sheet.state_html
=#raw @p_customer_sheet.state_html
=state_helper(@p_customer_sheet.price_line_block.state)
=#debug @p_customer_sheet.archive_now
@ -27,62 +27,60 @@
-price_line_block = @p_customer_sheet.price_line_block
%h3
Contenu de la demande de commande :
=render price_line_block
%hr
-if @p_customer_sheet.demande_type?
%p
Demande lors de la saisie :
%strong=@p_customer_sheet.demande_type
.right{:style => "text-align:right;"}
-if current_admin.has_permission?("gestion-des-commandes")
-if @p_customer_sheet.state == "Brouillon"
%p
-if @p_customer_sheet.price_blocked
=link_to ic(:unlock)+" Débloquer les prix", block_price_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-default"
-else
=link_to ic(:lock)+" Bloquer les prix", block_price_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-default"
-if @p_customer_sheet.state == "Brouillon" or @p_customer_sheet.state == "offre"# or @p_customer_sheet.state == "Validée"
-if @p_customer_sheet.state == "Brouillon"
%p=link_to "Générer le devis", generate_d_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
%p=#link_to "Générer la facture proforma", generate_fp_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
%p=link_to "Générer le bon de commande", generate_bc_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-success btn-ap-add disabled" if !@p_customer_sheet.stock_generable
%p=link_to "Générer le bon de commande", generate_bc_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-success btn-ap-add" if @p_customer_sheet.stock_generable
-@bon_de_commande = @p_customer_sheet.price_documents.where(:cc_label => "Bon de commande client").first
%p=link_to "Marquer l'offre comme refusée", reject_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn", style: "background:rgb(110,45,116); color: white;"
%p=link_to "Générer le bon de commande et marquer la commande comme Validée", generate_bc_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-success btn-ap-add disabled" if !@p_customer_sheet.stock_generable
%p=link_to "Générer le bon de commande et marquer la commande comme Validée", generate_bc_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-success btn-ap-add" if @p_customer_sheet.stock_generable
%p=link_to "Marquer l'offre comme refusée", reject_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary btn-ap-error "
-if( @p_customer_sheet.state == "Validée" or (@p_customer_sheet.state == "en livraison" and @p_customer_sheet.price_documents.where(:cc_label => "Bon de livraison", :cancelled => false).count == 0)) and @bon_de_commande
-if price_line_block.nbr_ship
- if @bon_de_commande
-# %p=link_to "Générer le devis", generate_d_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
%p=link_to "Passer la commande en Préparation", admin_p_customer_sheet_path(:id => @p_customer_sheet.id, :p_customer_sheet => {:state => "Préparation"}), :method => :put, :class => "btn", style: "background:rgb(233,122,28); color: white" if !@bon_de_commande.stock_ok and @bon_de_commande.stock_generable
%p=link_to "Générer le bon de livraison et marquer la commande comme Livraison", bl_admin_price_document_path(@bon_de_commande), :class => "btn btn-primary btn-ap-add"
%p=link_to "Passer la commande en Livraison", admin_p_customer_sheet_path(:id => @p_customer_sheet.id, :p_customer_sheet => {:state => "Livraison"}), :method => :put, :class => "btn", style: "background:rgb(66,122,255); color: white" if !@bon_de_commande.stock_ok and @bon_de_commande.stock_generable
%p=link_to "Générer la facture", generate_f_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
%p=link_to "Mettre à jour les stocks, calculer la marge", update_stocks_admin_price_document_path(@bon_de_commande), :class => "btn btn-primary" if !@bon_de_commande.stock_ok and @bon_de_commande.stock_generable
-if false
-if @p_customer_sheet.demande_type?
%p
Demande lors de la saisie :
%strong=@p_customer_sheet.demande_type
.right{:style => "text-align:right;"}
-if current_admin.has_permission?("gestion-des-commandes")
-if @p_customer_sheet.state == "Brouillon"
%p
-if @bon_de_commande.label == "Bon de commande" and @p_customer_sheet and @p_customer_sheet.price_documents.where(:cc_label => "Bon de livraison", :cancelled => false).count == 0
= link_to ic(:pencil)+" Modifier le bon de commande", edit_admin_price_document_path(:id => @bon_de_commande.id, :public_edit => true), :class => "btn btn-default"
=link_to "Générer le bon de livraison", bl_admin_price_document_path(@bon_de_commande), :class => "btn btn-primary btn-ap-add"
-if @p_customer_sheet.price_blocked
=link_to ic(:unlock)+" Débloquer les prix", block_price_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-default"
-else
=link_to ic(:lock)+" Bloquer les prix", block_price_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-default"
-if @p_customer_sheet.state == "Brouillon" or @p_customer_sheet.state == "offre"# or @p_customer_sheet.state == "Validée"
-if @p_customer_sheet.state == "Brouillon"
%p=link_to "Générer le devis", generate_d_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
%p=#link_to "Générer la facture proforma", generate_fp_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
%p=link_to "Générer le bon de commande", generate_bc_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-success btn-ap-add disabled" if !@p_customer_sheet.stock_generable
%p=link_to "Générer le bon de commande", generate_bc_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-success btn-ap-add" if @p_customer_sheet.stock_generable
%p=link_to "Marquer l'offre comme refusée", reject_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary btn-ap-error "
-if( @p_customer_sheet.state == "Validée" or (@p_customer_sheet.state == "en livraison" and @p_customer_sheet.price_documents.where(:cc_label => "Bon de livraison", :cancelled => false).count == 0)) and @bon_de_commande
-if price_line_block.nbr_ship
%p
-if @bon_de_commande.label == "Bon de commande" and @p_customer_sheet and @p_customer_sheet.price_documents.where(:cc_label => "Bon de livraison", :cancelled => false).count == 0
= link_to ic(:pencil)+" Modifier le bon de commande", edit_admin_price_document_path(:id => @bon_de_commande.id, :public_edit => true), :class => "btn btn-default"
=link_to "Générer le bon de livraison", bl_admin_price_document_path(@bon_de_commande), :class => "btn btn-primary btn-ap-add"
-else
%p=link_to "Indiquer le nombre de colis à livrer", edit_ship_admin_price_document_path(@bon_de_commande), :class => "btn btn-default"
-elsif @bon_de_commande
-if (@bon_de_commande.price_line_block.price_lines.sum(:qte) > PriceLine.where(:price_line_block_id => PriceLineBlock.where(:price_lineable_type => "PriceDocument", :price_lineable_id => @p_customer_sheet.price_documents.where(:cancelled => false, :cc_label => "Bon de livraison").ids)).sum(:qte))
=link_to "Générer un bon de livraison pour le reliquat", bl_admin_price_document_path(@bon_de_commande), :class => "btn btn-primary btn-ap-add"
-else
%p=link_to "Indiquer le nombre de colis à livrer", edit_ship_admin_price_document_path(@bon_de_commande), :class => "btn btn-default"
-elsif @bon_de_commande
-if (@bon_de_commande.price_line_block.price_lines.sum(:qte) > PriceLine.where(:price_line_block_id => PriceLineBlock.where(:price_lineable_type => "PriceDocument", :price_lineable_id => @p_customer_sheet.price_documents.where(:cancelled => false, :cc_label => "Bon de livraison").ids)).sum(:qte))
=link_to "Générer un bon de livraison pour le reliquat", bl_admin_price_document_path(@bon_de_commande), :class => "btn btn-primary btn-ap-add"
.clear
@ -91,10 +89,10 @@
-params[:search][:per_page] = params[:search][:per_page] || 50
-per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@price_documents = @p_customer_sheet.price_documents.order("date DESC, created_at DESC")
-@price_documents = @p_customer_sheet.price_documents.order("date ASC, created_at ASC")
-if params[:price_document_ids]
-@price_documents = @price_documents.where(:id => params[:price_document_ids])
-@price_documents = sort_by_sorting(@price_documents, "created_at DESC")
-@price_documents = sort_by_sorting(@price_documents, "created_at ASC")
-@price_documents = @price_documents.page(page).per(per_page)
- if @price_documents.exists?

View File

@ -1,5 +1,11 @@
=semantic_form_for [:admin, @p_product], :remote => false do |f|
%div.error.has-error
-f.object.errors.keys.each do |key|
%p=key.to_s
%p=f.object.errors[key.to_sym][0]
.qi_row
.qi_pannel.qi_plain.padding
=f.inputs do
@ -17,7 +23,7 @@
#with_serial
= f.input :with_serial_number, :label => "Avec n° de série ?"
.col-sm-2
=f.input :s_brand_id, :label => "Marque :", :collection => SBrand.all, :as => :select, :include_blank => true
=f.input :s_brand_id, :label => "Marque :", :collection => SBrand.all, required: true, :as => :select, :include_blank => true
=# f.input :stocked, :label => "Suivi de stock ?"
.col-sm-2
=#f.input :sorecop_cat, label: "Catgorie Sorecop :", :collection => SorecopCat.all, :as => :select, :include_blank => true

View File

@ -13,7 +13,8 @@
= link_to i(:download), print_admin_price_document_path(@price_document.token), :remote => false, :target => "_blank" if !PriceLineBlock::PURCHASE_BLOCKS.include?(@price_document.block_type)
=breadcrumb second_title: @price_document.label, second_link: admin_price_documents_path(:price_document_type_id => @price_document.price_document_type_id), record: @price_document.d_number
=breadcrumb first_title: "Commandes", second_title: @price_document.label, second_link: admin_price_documents_path(:price_document_type_id => @price_document.price_document_type_id), record: @price_document.d_number
.qi_row
@ -251,20 +252,16 @@
=link_to "Générer un bon de réception", bon_de_reception_admin_price_document_path(@price_document), :class => "btn btn-primary disabled" if !@price_document.stock_ok and !@price_document.stock_generable
-elsif @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5
%p
Coût :
=number_to_currency @price_document.cost_ht
%p
Marge :
=number_to_currency @price_document.marge_ht
-# %p
-# Coût :
-# =number_to_currency @price_document.cost_ht
-# %p
-# Marge :
-# =number_to_currency @price_document.marge_ht
-if !@price_document.cost_ok
=link_to "Mettre à jour les stocks, calculer la marge", update_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok and @price_document.stock_generable
=link_to "Mettre à jour les stocks, calculer la marge", update_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary disabled" if !@price_document.stock_ok and !@price_document.stock_generable
-elsif @price_document.price_document_type_id == 12
%p=link_to "Mettre à jour les stocks, calculer la marge", update_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok and @price_document.stock_generable
%p=link_to "Passer la commande client au statut Préparation", update_pcustomersheet_statut_admin_price_document_path(@price_document, state: "Préparation"), :class => "btn btn-primary" if !@price_document.stock_ok and @price_document.stock_generable
%p=link_to "Passer la commande client au statut Livraison", update_pcustomersheet_statut_admin_price_document_path(@price_document, state: "Livraison"), :class => "btn btn-primary" if !@price_document.stock_ok and @price_document.stock_generable
=link_to "Mettre à jour les stocks", generate_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok and @price_document.stock_generable
=link_to "Mettre à jour les stocks", generate_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary disabled" if !@price_document.stock_ok and !@price_document.stock_generable
-if @price_document.d_number
-if @price_document.cc_label == "Commande achat"

View File

@ -62,7 +62,7 @@
%table.table
%thead
%tr
%th IDddd
%th ID
%th Référence
%th Désignation
%th Qté

View File

@ -672,7 +672,6 @@ Rails.application.routes.draw do
get :buy_order_create
get :bon_de_reception
get :facture_achat
get :update_pcustomersheet_statut
end
collection do

View File

@ -0,0 +1,5 @@
class AddPArticleToLineStockUsage < ActiveRecord::Migration[6.0]
def change
add_column :line_stock_usages, :p_article_id, :integer
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_11_16_144749) do
ActiveRecord::Schema.define(version: 2021_11_17_161758) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -568,6 +568,7 @@ ActiveRecord::Schema.define(version: 2021_11_16_144749) do
t.integer "dest_line_stock_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "p_article_id"
t.index ["line_stock_id"], name: "index_line_stock_usages_on_line_stock_id"
end