From 398cf587bed8b5b4e2a60f530b132bef3be18a12 Mon Sep 17 00:00:00 2001
From: Philippe
Date: Tue, 16 Nov 2021 18:03:15 +0100
Subject: [PATCH 1/4] Auto stash before checking out "HEAD"
---
.../admin/price_documents_controller.rb | 7 +-
app/controllers/application_controller.rb | 14 +--
app/helpers/translation_helper.rb | 60 +++++++-----
app/models/p_customer_sheet.rb | 81 +++++++++++-----
app/models/p_product_ref.rb | 4 +-
app/models/particular.rb | 19 ++++
app/models/price_document.rb | 12 +--
app/models/price_line_block.rb | 71 +++++++-------
.../admin/accounting_zones/_form.html.haml | 5 +-
.../admin/admin_permissions/_form.html.haml | 5 +-
app/views/admin/admin_roles/_form.html.haml | 4 +-
app/views/admin/import_csvs/_form.html.haml | 4 +-
.../admin/line_stock_usages/_form.html.haml | 4 +-
app/views/admin/line_stocks/_form.html.haml | 4 +-
app/views/admin/mail_hists/_form.html.haml | 6 +-
.../p_article_serial_nums/_form.html.haml | 5 +-
app/views/admin/p_articles/_form.html.haml | 3 +-
.../admin/p_commercial_cats/_form.html.haml | 4 +-
app/views/admin/p_commercials/_form.html.haml | 13 +--
.../admin/p_customer_cats/_form.html.haml | 9 +-
.../_p_customer_sheet.html.haml | 8 +-
.../admin/p_customer_sheets/index.html.haml | 9 +-
.../admin/p_customer_sheets/show.html.haml | 10 +-
app/views/admin/p_customers/show.html.haml | 24 ++++-
app/views/admin/p_devises/_form.html.haml | 5 +-
app/views/admin/p_documents/_form.html.haml | 4 +-
app/views/admin/p_grades/_form.html.haml | 9 +-
.../admin/p_product_cats/_form.html.haml | 4 +-
.../admin/p_product_zones/_form.html.haml | 4 +-
.../admin/p_serial_num_types/_form.html.haml | 4 +-
.../admin/particulars/_large_form.html.haml | 4 +-
app/views/admin/partitions/_form.html.haml | 11 +--
.../price_documents/_form_avoir.html.haml | 5 +-
.../price_documents/_price_document.html.haml | 2 +-
.../admin/price_documents/show.html.haml | 33 +++++--
.../admin/price_line_blocks/_form.html.haml | 2 +-
app/views/admin/price_lines/_form.html.haml | 96 ++++++++++++++-----
.../admin/price_lines/_form_old.html.haml | 1 -
.../_reponse_pane_hover_form.html.haml | 57 +----------
app/views/admin/price_lines/edit.js.erb | 2 +-
app/views/admin/s_brands/_form.html.haml | 8 +-
.../admin/stock_movements/_form.html.haml | 12 +--
app/views/admin/tva_rates/_form.html.haml | 5 +-
...115181445_add_br_ok_to_price_line_block.rb | 5 +
...d_particular_infos_to_p_custommer_sheet.rb | 6 ++
db/schema.rb | 5 +-
46 files changed, 378 insertions(+), 291 deletions(-)
create mode 100644 db/migrate/20211115181445_add_br_ok_to_price_line_block.rb
create mode 100644 db/migrate/20211116144749_add_particular_infos_to_p_custommer_sheet.rb
diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb
index 4e02801..3840432 100644
--- a/app/controllers/admin/price_documents_controller.rb
+++ b/app/controllers/admin/price_documents_controller.rb
@@ -701,7 +701,9 @@ class Admin::PriceDocumentsController < ApplicationController
@p_customer_sheet = @past_price_document.ref_element
if @p_customer_sheet
- price_document = @p_customer_sheet.price_documents.new(:price_document_type => PriceDocumentType.find_by_label("Bon de réception achat"), :demande_de_prix_id => @past_price_document.id, :date => Date.today)
+ price_document = @p_customer_sheet.price_documents.new(:price_document_type => PriceDocumentType.find_by_label("Bon de réception achat"),
+ :demande_de_prix_id => @past_price_document.id,
+ :date => Date.today)
else
price_document = PriceDocument.new(:price_document_type => PriceDocumentType.find_by_label("Bon de réception achat"), :date => Date.today)
end
@@ -743,7 +745,9 @@ class Admin::PriceDocumentsController < ApplicationController
new_pl.qte = new_pl.qte - qte_ok
end
+ new_pl.p_articles = pl.p_articles
price_document.price_line_block.price_lines << new_pl
+ price_document.price_line_block.br_ok = true
end
if price_document.save
@@ -770,6 +774,7 @@ class Admin::PriceDocumentsController < ApplicationController
@p_customer_sheet = @past_price_document.ref_element
if @p_customer_sheet
+
price_document = @p_customer_sheet.price_documents.new(:price_document_type => PriceDocumentType.find_by_label("Facture achat"), :demande_de_prix_id => @past_price_document.id, :date => Date.today)
else
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index dddda40..05e0c17 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -118,8 +118,8 @@ class ApplicationController < ActionController::Base
end
if current_admin.has_permission?("boutique")
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_colors, "Couleurs"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_article_serial_nums, "Numeros série"
+ # set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_colors, "Couleurs"
+ #set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_article_serial_nums, "Numeros série"
set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_serial_num_types, "Types de Numero série"
set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_ref_specs, "Specs"
set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_spec_types, "Types de specs"
@@ -128,9 +128,9 @@ class ApplicationController < ActionController::Base
set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_powers, "Types de chargeurs"
set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_zones, "Zones produits"
set_sub_sub_menu :stocks, :p_preferences_products_menu, :import_csvs, "Import Excel"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :import_csv_match_refs, "Rapprochement références", match_refs_admin_import_csvs_path
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_cats, "Catégories SORECOP"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_taxes, "taxe SORECOP"
+ # set_sub_sub_menu :stocks, :p_preferences_products_menu, :import_csv_match_refs, "Rapprochement références", match_refs_admin_import_csvs_path
+ # set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_cats, "Catégories SORECOP"
+ # set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_taxes, "taxe SORECOP"
end
@@ -143,7 +143,7 @@ class ApplicationController < ActionController::Base
set_sub_menu :ventes, :p_customer_sheets, "Demande de commande", admin_p_customer_sheets_path
- if false
+ #if false
PriceDocumentType.where(:label => PriceDocument::SALES).order("id DESC").all.each do |p_document_type|
set_sub_menu :ventes, :"p_document_type_#{p_document_type.label.to_s.to_slug}", p_document_type.label, admin_price_documents_path(:price_document_type_id => p_document_type.id)
@@ -151,7 +151,7 @@ class ApplicationController < ActionController::Base
end
set_sub_menu :ventes, :price_documents_all, "Tous documents", admin_price_documents_path
- end
+ #end
diff --git a/app/helpers/translation_helper.rb b/app/helpers/translation_helper.rb
index a608c96..068f0ab 100755
--- a/app/helpers/translation_helper.rb
+++ b/app/helpers/translation_helper.rb
@@ -46,31 +46,45 @@ module TranslationHelper
def state_helper(value)
value = value.to_s
- if ["brouillon","Reçue", "Panier web", "AV BPA"].include?(value)
- r = ''+value+''
- elsif ["Virement envoyé", "Validé"].include?(value)
- r = ''+value+''
- elsif value == "commande" or value == "Commande" or value == "Réglée" or value == "PAS BPA"
- r = ''+value+''
- elsif value == "En cours d'expédition" or value == "Expédiée" or value == "BPA"
- r = ''+value+''
- elsif ["Virement demandé"].include?(value)
- r = ''+value+''
- elsif value =="Livrée"
- r = ''+value+''
- elsif value == "annulée"
- r = ''+value+''
- elsif ["Erreur sur virement", "Refusé", "Refusée","refusée"].include?(value)
- r = ''+value+''
- elsif ["En cours de traitement"].include?(value)
- r = ''+value+''
+ # if ["Brouillon", "Validée", "Préparation", "Livraison", "Réceptionné", "Payé"].include?(value)
+ # r = ''+value+''
+ # elsif ["Virement envoyé", "Validé"].include?(value)
+ # r = ''+value+''
+ # elsif value == "commande" or value == "Commande" or value == "Réglée" or value == "PAS BPA"
+ # r = ''+value+''
+ # elsif value == "En cours d'expédition" or value == "Expédiée" or value == "BPA"
+ # r = ''+value+''
+ # elsif ["Virement demandé"].include?(value)
+ # r = ''+value+''
+ # elsif value =="Livrée"
+ # r = ''+value+''
+ # elsif value == "annulée"
+ # r = ''+value+''
+ # elsif ["Erreur sur virement", "Refusé", "Refusée","refusée"].include?(value)
+ # r = ''+value+''
+ # elsif ["En cours de traitement"].include?(value)
+ # r = ''+value+''
- elsif ["Disponible en boutique", "Disponible en point retrait"].include?(value)
- r = ''+value+''
- else
- r = ''+value+''
+ # elsif ["Disponible en boutique", "Disponible en point retrait"].include?(value)
+ # r = ''+value+''
+ # else
+ # r = ''+value+''
+ # end
+
+ if value == "Brouillon"
+ r = ''+value+''
+ elsif value == "Validée"
+ r = ''+value+''
+ elsif value == "Préparation"
+ r = ''+value+''
+ elsif value == "Livraison"
+ r = ''+value+''
+ elsif value == "Réceptionné"
+ r = ''+value+''
+ elsif value == "Payé"
+ r = ''+value+''
end
-
+
return raw(r)
end
diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb
index 19358f0..f3e4801 100644
--- a/app/models/p_customer_sheet.rb
+++ b/app/models/p_customer_sheet.rb
@@ -25,7 +25,7 @@ class PCustomerSheet < ApplicationRecord
has_many :price_documents, :as => :ref_element
- acts_as_caching :fields => %w(weight_tot com_counter accounting_zone_id accounting_zone_name tot_amount_ht tot_amount_ttc tot_amount_tva payment_days payment_delais payment_month_end payment_end_at )
+ acts_as_caching :fields => %w(weight_tot com_counter accounting_zone_id accounting_zone_name tot_amount_ht tot_amount_ttc tot_amount_tva payment_days payment_delais payment_month_end payment_end_at particular_infos)
acts_as_sorting :fields => {
@@ -35,9 +35,10 @@ class PCustomerSheet < ApplicationRecord
:d_number => {:name => "N° BC", :reorder => false},
:created_at => {:name => "Date", :reorder => true, :sort_name => "p_customer_sheets.created_at"},
:admin_id => {:name => "Déposée par", :reorder => true},
- :wish_date => {:name => "Semaine de livraison", :reorder => true, :sort_name => "price_line_blocks.wish_date"},
- :wish_date_2 => {:name => "Date de livraison souhaitée ", :reorder => true, :sort_name => "price_line_blocks.wish_date"},
+ #:wish_date => {:name => "Semaine de livraison", :reorder => true, :sort_name => "price_line_blocks.wish_date"},
+ #:wish_date_2 => {:name => "Date de livraison souhaitée ", :reorder => true, :sort_name => "price_line_blocks.wish_date"},
:p_customer => {:name => "Client", :reorder => false, :member_label => :show_name, :as => :ref_link},
+ :particular_infos => {:name => "Client final", :reorder => false},
:tot_amount_ht => {:name => "Total HT", :reorder => true, :sort_name => "cc_tot_amount_ht", :sort_name => "p_customer_sheets.cc_tot_amount_ht"},
:tot_amount_ttc => {:name => "Total TTC", :reorder => true, :sort_name => "cc_tot_amount_ttc", :sort_name => "p_customer_sheets.cc_tot_amount_ttc"},
:state => {:name => "Statut", :reorder => false, :as => :state},
@@ -46,8 +47,8 @@ class PCustomerSheet < ApplicationRecord
}
# STATES = ["brouillon", "offre", "commande", "livrée","facturée", "annulée", "refusée"]
- STATES = ["AV BPA", "PAS BPA","BPA", "Traitée"]
-
+ # STATES = ["AV BPA", "PAS BPA","BPA", "Traitée"]
+ STATES = ["Brouillon", "Validée", "Préparation", "Livraison", "Réceptionné", "Payé"]
def personalised_archive
self.price_line_block.archive_now
@@ -106,6 +107,9 @@ class PCustomerSheet < ApplicationRecord
end
+ def ca_particular_infos
+ self.price_line_block.particular_bill.organisation + self.price_line_block.particular_bill.firstname + self.price_line_block.particular_bill.name
+ end
def ca_com_counter
@@ -237,17 +241,17 @@ class PCustomerSheet < ApplicationRecord
def state_html
if self.state == "Panier web"
'Panier web'
- elsif self.state == "brouillon"
+ elsif self.state == "Brouillon"
''+self.demande_type.to_s+''
elsif self.state == "offre"
'Offre'
- elsif self.state == "commande"
+ elsif self.state == "Validée"
'Commande'
- elsif self.state == "en livraison"
+ elsif self.state == "Livraison"
'En livraison'
elsif self.state == "livrée"
'livrée'
- elsif self.state =="facturée"
+ elsif self.state =="Payée"
'Facturée'
elsif self.state == "annulée"
'Annulée'
@@ -260,7 +264,7 @@ class PCustomerSheet < ApplicationRecord
after_create do
- self.state = "brouillon" if self.state != "Panier web"
+ self.state = "Brouillon" if self.state != "Panier web"
self.save
end
@@ -268,29 +272,54 @@ class PCustomerSheet < ApplicationRecord
def generate_doc(label, state)
self.archive_now if !self.archived
self.block_price if !self.price_blocked
- self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1)
+
+ puts "TVA TYPE IDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
+ puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
+ puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
+ puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
+ puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
+ puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
+ puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
+ puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
+ puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
+ puts "TVA TYPE IDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
+
+
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
+ puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
+ puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
+ puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
+ puts pl.p_articles.where(tva_type_id: 1)
pl.p_articles.where(tva_type_id: 1).each { |p_article| new_pl.p_articles << p_article }
+ puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
+ puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
+ puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
+
+
+ raise
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
end
- if price_document_standard_tva.save
- price_document_standard_tva.archive_now
- self.state = state
- self.save
- 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)
@@ -306,13 +335,15 @@ class PCustomerSheet < ApplicationRecord
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
end
- if price_document_sur_marge_tva.save
- price_document_sur_marge_tva.archive_now
- self.state = state
- self.save
- 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
@@ -349,19 +380,19 @@ class PCustomerSheet < ApplicationRecord
def generate_bc
- generate_doc("Bon de commande client", "commande")
+ generate_doc("Bon de commande client", "Validée")
end
def generate_bl()
- generate_doc("Bon de livraison", "en livraison")
+ generate_doc("Bon de livraison", "Livraison")
end
def generate_f()
- generate_doc("Facture", "facturée")
+ generate_doc("Facture", "Payé")
end
diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb
index 6da7f5f..e79a790 100644
--- a/app/models/p_product_ref.rb
+++ b/app/models/p_product_ref.rb
@@ -51,8 +51,8 @@ class PProductRef < ApplicationRecord
:ct_price_ht => {:name => "Prix de vente", :as => :currency},
:ean => {:name => "EAN"},
:deee => {:name => "DEEE", :as => :currency},
- :sorecop => {:name => "Sorecop", :as => :currency},
- :sorecop_comment => {:name => "Commentaire Sorecop"},
+ # :sorecop => {:name => "Sorecop", :as => :currency},
+ # :sorecop_comment => {:name => "Commentaire Sorecop"},
:actions => {:name => "Actions", :reorder => false}
}
diff --git a/app/models/particular.rb b/app/models/particular.rb
index 9fbe2bd..ca23dfe 100644
--- a/app/models/particular.rb
+++ b/app/models/particular.rb
@@ -21,6 +21,25 @@ class Particular < ApplicationRecord
attr_accessor :validate_email, :skip_email
belongs_to :particular_ref, :class_name => "Particular"
+
+
+
+ def self.qi_table_order
+ {
+ :created_at => {:name => "Date de création", :reorder => true, :as => :date},
+ :organisation => {:name => "Raison sociale", :reorder => true},
+ :name => {:name => "Nom", :reorder => true},
+ :firstname => {:name => "Prénom", :reorder => true},
+ :address_1 => {:name => "Adresse", :reorder => true},
+ :address_2 => {:name => "Adresse", :reorder => true},
+ :city => {:name => "Ville", :reorder => true},
+ :country => {:name => "Pays", :reorder => true},
+ :actions => {:name => "Actions", :reorder => false}
+ }
+ #, :sort_name => "code"
+ end
+
+
def validate_pro
true if self.force_validation and self.pro
end
diff --git a/app/models/price_document.rb b/app/models/price_document.rb
index 4f47d8e..582ffb6 100644
--- a/app/models/price_document.rb
+++ b/app/models/price_document.rb
@@ -6,7 +6,7 @@ class PriceDocument < ApplicationRecord
belongs_to :p_devise
belongs_to :p_payment_type
belongs_to :tva_type
-
+ validates :tva_type, :presence => true
has_one :p_compta_element, :dependent => :destroy, :as => :element
@@ -21,13 +21,12 @@ class PriceDocument < ApplicationRecord
has_many :p_payments, :through => :p_payment_documents
has_many :line_stocks, :as => :stockable
-
has_many :avoir_p_payment_documents, :dependent => :destroy, :foreign_key => :avoir_id, :class_name => "PPaymentDocument"
accepts_nested_attributes_for :avoir_p_payment_documents, allow_destroy: true
#PURCHASES = ["Demande prix", "Réponse fournisseur", "Commande achat", "Facture achat", "Consultation fournisseur"]
- PURCHASES = ["Facture achat"]
- SALES = ["Bon de commande", "Devis", "Bon de livraison", "Facture", "Avoir"]
+ PURCHASES = ["Facture achat", "Bon de réception achat"]
+ SALES = ["Devis", "Avoir", "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"]
@@ -282,7 +281,7 @@ class PriceDocument < ApplicationRecord
:com_counter => {:name => "N° Offre", :reorder => false},
:label => {:name => "Type", :reorder => false},
:stock_ok => {:name => "Stock mis à jour ?", :reorder => true},
- :tva_type_name => {:name => "ID Type de TVA", :reorder => true},
+ #:tva_type_name => {:name => "Type de TVA", :reorder => true},
#:package_number => {:name => "Nombre de colis", :reorder => true},
:d_number => {:name => "Numéro", :reorder => true},
:date => {:name => "Date", :reorder => true},
@@ -444,9 +443,10 @@ class PriceDocument < ApplicationRecord
last_dt = PriceDocument.where("d_number is not null").where(:d_year => self.d_year,:price_document_type_id => self.price_document_type_id).order("d_index DESC").first
last_number = last_dt.d_index if last_dt
+ tva_prefix = self.tva_type.name == "Standard" ? "S" : "M"
self.d_index = last_number+1
- self.d_number = self.d_prefix+self.d_year.to_s+('%05d' % self.d_index)
+ self.d_number = self.d_prefix+tva_prefix+self.d_year.to_s+('%05d' % self.d_index)
self.save
diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb
index abee8ee..e63b0df 100644
--- a/app/models/price_line_block.rb
+++ b/app/models/price_line_block.rb
@@ -127,12 +127,18 @@ class PriceLineBlock < ApplicationRecord
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", :price_ht => 0.0, :price_line => pl, :price_line_block => self, :stockable => self.price_lineable)
+ 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",
+ :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
LineStock.where(:p_product_ref_id => p_product_ref.id).where("date <= ?", self.price_lineable.date).where("qte_available > 0.0").each do |ls|
@@ -140,22 +146,18 @@ class PriceLineBlock < ApplicationRecord
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
+ decr_line_stock.p_articles = pl.p_articles
decr_line_stock.price_ht = price * -1
decr_line_stock.save
end
@@ -163,47 +165,39 @@ class PriceLineBlock < ApplicationRecord
end
def update_stocks
- if self.block_type == "Facture" and !self.cost_ok
+ puts "UPDATE STOCKSSSSSSSSSSSSSSSSSSSSSSSSSSS"
+ puts self.block_type == "Facture"
+ puts self.block_type == "Bon de commande client"
+ puts self.block_type
+ puts self.block_type
+ puts self.block_type
+ puts self.block_type
+ puts self.block_type
+ puts !self.cost_ok
+ puts "UPDATE STOCKSSSSSSSSSSSSSSSSSSSSSSSSSSS"
+
+
+
+ if self.block_type == "Facture" or self.block_type == "Bon de commande client" or self.block_type == "Bon de réception achat" && !self.cost_ok
if self.test_if_stock_ok?
-
self.price_lines.each do |pl|
if pl.p_product_ref && pl.p_product_ref.stocked
if pl.p_product_ref.assembled
-
pl.p_product_ref.p_product_assembleds.all.each do |ppa|
-
-
self.update_stocks_for(ppa.p_product_ref, (pl.qte.to_f * ppa.qte.to_f), pl)
-
end
-
else
-
self.update_stocks_for(pl.p_product_ref, pl.qte, pl)
-
-
-
end
-
-
end
-
end
self.cost_ok = true
-
-
self.save
self.save # deuxième sauvegarde pour prendre en compte les couts de price_line
-
-
self.price_lineable.save if self.price_lineable
return true
-
end
-
-
-
end
end
@@ -223,7 +217,19 @@ 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,
+ :p_product_ref => pl.p_product_ref,
+ :qte => -1,
+ :description => "Sortie de stock automatique des RMA",
+ :price_ht => 0.0,
+ :price_line => pl,
+ :price_line_block => self,
+ :stockable => self.price_lineable)
+ decr_line_stock.p_articles << p_article
+ decr_line_stock.save
+ end
end
@@ -276,7 +282,7 @@ class PriceLineBlock < ApplicationRecord
def wish_date_needed?
if PriceLineBlock::PURCHASE_BLOCKS.include?(self.block_type)
false
- elsif self.block_type == "Devis"
+ elsif self.block_type == "Devis" or self.block_type == "Demande de commande"
false
else
true
@@ -453,9 +459,6 @@ class PriceLineBlock < ApplicationRecord
end
if self.particular_bill_needed? and (!self.p_customer or !self.particular_bill or !self.particular_bill.owner or self.particular_bill.owner != self.p_customer)
- puts "PARTICULEARRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
- puts self.particular_bill
- puts "PARTICULEARRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"
errors.add(:particular_bill_id, 'doit être une adresse du client')
end
diff --git a/app/views/admin/accounting_zones/_form.html.haml b/app/views/admin/accounting_zones/_form.html.haml
index 11f012e..ebeaf0f 100644
--- a/app/views/admin/accounting_zones/_form.html.haml
+++ b/app/views/admin/accounting_zones/_form.html.haml
@@ -4,11 +4,12 @@
=f.inputs do
= f.input :enabled, :label => "Actif ?"
= f.input :name, :label => "Nom de la zone :"
- =# f.input :description, :label => "description :"
+ =# f.input :description, :label => "description :"
+ =render :partial => "qi/actions", :locals => {:f => f}
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ -# .actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/admin_permissions/_form.html.haml b/app/views/admin/admin_permissions/_form.html.haml
index 687700c..2894429 100755
--- a/app/views/admin/admin_permissions/_form.html.haml
+++ b/app/views/admin/admin_permissions/_form.html.haml
@@ -11,9 +11,10 @@
= f.input :slug, :label => "Slug :"
- = f.input :position, :label => "Position :"
+ = f.input :position, :label => "Position :"
+ =render :partial => "qi/actions", :locals => {:f => f}
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/admin_roles/_form.html.haml b/app/views/admin/admin_roles/_form.html.haml
index f3b279a..60f1f68 100755
--- a/app/views/admin/admin_roles/_form.html.haml
+++ b/app/views/admin/admin_roles/_form.html.haml
@@ -6,6 +6,6 @@
= f.input :name, :label => "Nom :"
=f.input :admin_permissions, :label => "Permissions :", :collection => AdminPermission.all, :as => :check_boxes, :member_label => :member_label
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/import_csvs/_form.html.haml b/app/views/admin/import_csvs/_form.html.haml
index 71bbec7..a2d1d01 100644
--- a/app/views/admin/import_csvs/_form.html.haml
+++ b/app/views/admin/import_csvs/_form.html.haml
@@ -21,6 +21,6 @@
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
diff --git a/app/views/admin/line_stock_usages/_form.html.haml b/app/views/admin/line_stock_usages/_form.html.haml
index 40d9b10..e2eb6db 100644
--- a/app/views/admin/line_stock_usages/_form.html.haml
+++ b/app/views/admin/line_stock_usages/_form.html.haml
@@ -13,6 +13,6 @@
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/line_stocks/_form.html.haml b/app/views/admin/line_stocks/_form.html.haml
index 736979f..6fcd608 100644
--- a/app/views/admin/line_stocks/_form.html.haml
+++ b/app/views/admin/line_stocks/_form.html.haml
@@ -12,6 +12,6 @@
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/mail_hists/_form.html.haml b/app/views/admin/mail_hists/_form.html.haml
index 8253451..2f95060 100644
--- a/app/views/admin/mail_hists/_form.html.haml
+++ b/app/views/admin/mail_hists/_form.html.haml
@@ -17,8 +17,6 @@
= f.input :nbr_send, :label => "nbr_send :"
-
-
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/p_article_serial_nums/_form.html.haml b/app/views/admin/p_article_serial_nums/_form.html.haml
index 88de8b6..c1305c9 100644
--- a/app/views/admin/p_article_serial_nums/_form.html.haml
+++ b/app/views/admin/p_article_serial_nums/_form.html.haml
@@ -7,9 +7,10 @@
= f.input :p_serial_num_type_id, :label => "type", as: :select, collection: PSerialNumType.pluck(:name, :id)
= f.input :value
+
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
- else
.ml-5
diff --git a/app/views/admin/p_articles/_form.html.haml b/app/views/admin/p_articles/_form.html.haml
index 4ba3f64..6ed23d2 100644
--- a/app/views/admin/p_articles/_form.html.haml
+++ b/app/views/admin/p_articles/_form.html.haml
@@ -13,7 +13,8 @@
=render :partial => "admin/p_article_serial_nums/form", :locals => {:form => form}
%p= link_to_add_fields "Ajouter un numéro de série", f, :p_article_serial_nums, {:class => "btn btn-primary"}
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
- elsif params[:controller] == "admin/price_lines"
= form.inputs do
diff --git a/app/views/admin/p_commercial_cats/_form.html.haml b/app/views/admin/p_commercial_cats/_form.html.haml
index 03ed408..71993d8 100644
--- a/app/views/admin/p_commercial_cats/_form.html.haml
+++ b/app/views/admin/p_commercial_cats/_form.html.haml
@@ -9,6 +9,6 @@
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/p_commercials/_form.html.haml b/app/views/admin/p_commercials/_form.html.haml
index 3d27b29..dd892be 100755
--- a/app/views/admin/p_commercials/_form.html.haml
+++ b/app/views/admin/p_commercials/_form.html.haml
@@ -30,14 +30,7 @@
= f.input :birth, :label => "Date de naissance :", :as => :date
= f.input :objectif_ht, :label => "Objectif CA (HT)"
-
-
-
-
-
-
-
-
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/p_customer_cats/_form.html.haml b/app/views/admin/p_customer_cats/_form.html.haml
index 2c34830..960762b 100755
--- a/app/views/admin/p_customer_cats/_form.html.haml
+++ b/app/views/admin/p_customer_cats/_form.html.haml
@@ -7,11 +7,6 @@
=# f.input :payment_days, :label => "Délais de paiement par défaut :"
=# f.input :encourt_max, :label => "Encours max par défaut :"
-
-
-
-
-
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+
\ No newline at end of file
diff --git a/app/views/admin/p_customer_sheets/_p_customer_sheet.html.haml b/app/views/admin/p_customer_sheets/_p_customer_sheet.html.haml
index 7d589a3..992af6d 100644
--- a/app/views/admin/p_customer_sheets/_p_customer_sheet.html.haml
+++ b/app/views/admin/p_customer_sheets/_p_customer_sheet.html.haml
@@ -29,11 +29,11 @@
-tr[:created_at] = capture do
%td=l p_customer_sheet.created_at, :format => :date
- -tr[:wish_date] = capture do
- %td=l p_customer_sheet.price_line_block.wish_date, :format => "semaine %V (%Y)"
+ -# -tr[:wish_date] = capture do
+ -# %td=l p_customer_sheet.price_line_block.wish_date, :format => "semaine %V (%Y)"
- -tr[:wish_date_2] = capture do
- %td=l p_customer_sheet.price_line_block.wish_date, :format => :date
+ -# -tr[:wish_date_2] = capture do
+ -# %td=l p_customer_sheet.price_line_block.wish_date, :format => :date
-tr[:tot_amount_ht] = capture do
diff --git a/app/views/admin/p_customer_sheets/index.html.haml b/app/views/admin/p_customer_sheets/index.html.haml
index b8341f9..de3a613 100644
--- a/app/views/admin/p_customer_sheets/index.html.haml
+++ b/app/views/admin/p_customer_sheets/index.html.haml
@@ -63,19 +63,14 @@
%span.input-group-addon.btn{:onclick => "$(this).prev('input').val('');"}
=ic(:times)
-
-
-
-
-
-
=render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_customer_sheets}
+
.qi_kpi
-params[:active_kpi] = [] if params[:active_kpi].to_s == ""
- -[["brouillon", "Brouillon", "#ffc107"], ["commande", "Commande", "#fd7e14"], ["en livraison", "En livraison", "#28a745"], ["facturée", "Facturée", "#3B7DDD"]].each do |state| #,["refusée", "Refusée", "#dc3545"]
+ -[["Brouillon", "Brouillon", "#a3a3a3"], ["Validée", "Validée", "#fab92b"], ["Préparation", "Préparation", "#e97a1c"], ["Livraison", "Livraison", "#28a745"], ["Payée", "Payée", "#3B7DDD"]].each do |state| #,["refusée", "Refusée", "#dc3545"]
-p_customer_sheets = @p_customer_sheets.where(:state => state[0])
-if p_customer_sheets.count > 0
diff --git a/app/views/admin/p_customer_sheets/show.html.haml b/app/views/admin/p_customer_sheets/show.html.haml
index d664b6d..7315b0d 100644
--- a/app/views/admin/p_customer_sheets/show.html.haml
+++ b/app/views/admin/p_customer_sheets/show.html.haml
@@ -7,7 +7,7 @@
- -if !@p_customer_sheet.archived and (current_admin.has_permission?("gestion-des-commandes") or @p_customer_sheet.demande_type.to_s == "Brouillon" or @p_customer_sheet.state == "commande")
+ -if !@p_customer_sheet.archived and (current_admin.has_permission?("gestion-des-commandes") or @p_customer_sheet.demande_type.to_s == "Brouillon" or @p_customer_sheet.state == "Validée")
= link_to i(:pencil), edit_admin_p_customer_sheet_path(@p_customer_sheet), :remote => false
@@ -45,7 +45,7 @@
-if current_admin.has_permission?("gestion-des-commandes")
- -if @p_customer_sheet.state == "brouillon"
+ -if @p_customer_sheet.state == "Brouillon"
%p
-if @p_customer_sheet.price_blocked
@@ -55,14 +55,14 @@
- -if @p_customer_sheet.state == "brouillon" or @p_customer_sheet.state == "offre"# or @p_customer_sheet.state == "commande"
- -if @p_customer_sheet.state == "brouillon"
+ -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"
%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 == "commande" 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( @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
diff --git a/app/views/admin/p_customers/show.html.haml b/app/views/admin/p_customers/show.html.haml
index ea0dbf2..a877a99 100644
--- a/app/views/admin/p_customers/show.html.haml
+++ b/app/views/admin/p_customers/show.html.haml
@@ -160,9 +160,7 @@
#customer_adresses
- =render(:partial => "admin/particulars/customer_preview", :locals => {:p_customer => @p_customer})
-
-
+ =render(:partial => "admin/particulars/customer_preview", :locals => {:p_customer => @p_customer}) if !@p_customer.p_customer_cat.name == "Plateforme"
@@ -181,6 +179,8 @@
%li.nav-item=link_to "Factures & Avoirs", "?tab=bills#tabs", :class => "nav-link"+(" active" if params[:tab] == "bills").to_s
-if current_admin.has_permission?("payments")
%li.nav-item=link_to "Paiements", "?tab=payments#tabs", :class => "nav-link"+(" active" if params[:tab] == "payments").to_s
+ -if current_admin.has_permission?("payments") and @p_customer.p_customer_cat.name == "Plateforme"
+ %li.nav-item=link_to "Adresses", "?tab=adresses#tabs", :class => "nav-link"+(" active" if params[:tab] == "adresses").to_s
@@ -281,6 +281,24 @@
-@p_payments = @p_payments.page(page).per(per_page)
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_payments}
+
+
+ -if params[:tab] == "adresses" and @p_customer.p_customer_cat.name == "Plateforme"
+ #adresses
+ .qi_tab_header
+ .right{:style => "text-align:right;"}
+ /= link_to 'Ajouter une adresse', new_admin_p_payment_path(:p_customer_id => @p_customer.id), :class => "btn btn-primary bgbd-payments", :remote => true
+
+ .clear
+
+ -params[:search][:per_page] = params[:search][:per_page] || 50
+ -per_page = params[:search][:per_page]
+ -page = (params[:page] and params[:page] != "") ? params[:page] : 1
+ -@adresses =@p_customer.particulars
+ -@adresses = sort_by_sorting(@adresses, "created_at DESC")
+ -@adresses = @adresses.page(page).per(per_page)
+
+ =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @adresses}
diff --git a/app/views/admin/p_devises/_form.html.haml b/app/views/admin/p_devises/_form.html.haml
index c8d8d8c..a4c51c9 100644
--- a/app/views/admin/p_devises/_form.html.haml
+++ b/app/views/admin/p_devises/_form.html.haml
@@ -8,7 +8,6 @@
-
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/p_documents/_form.html.haml b/app/views/admin/p_documents/_form.html.haml
index 2d96aad..1dc4676 100755
--- a/app/views/admin/p_documents/_form.html.haml
+++ b/app/views/admin/p_documents/_form.html.haml
@@ -11,6 +11,6 @@
= f.input :i_archive, :label => "Indiquer le lettrage comme effectué ? (forcer, même si aucun paiements rattachés)"
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/p_grades/_form.html.haml b/app/views/admin/p_grades/_form.html.haml
index 00d2fa0..3da7ffa 100644
--- a/app/views/admin/p_grades/_form.html.haml
+++ b/app/views/admin/p_grades/_form.html.haml
@@ -3,10 +3,7 @@
.content
=f.inputs do
= f.input :grade, :label => f.object.label_for(:grade)
-
-
-
-
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/p_product_cats/_form.html.haml b/app/views/admin/p_product_cats/_form.html.haml
index fc64cdf..e2c34ee 100755
--- a/app/views/admin/p_product_cats/_form.html.haml
+++ b/app/views/admin/p_product_cats/_form.html.haml
@@ -13,5 +13,5 @@
=# f.input :purchase_account, :label => "Compte achat :"
=# f.input :sale_account, :label => "Compte vente :"
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
diff --git a/app/views/admin/p_product_zones/_form.html.haml b/app/views/admin/p_product_zones/_form.html.haml
index c0bea09..d95fde4 100644
--- a/app/views/admin/p_product_zones/_form.html.haml
+++ b/app/views/admin/p_product_zones/_form.html.haml
@@ -7,6 +7,6 @@
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/p_serial_num_types/_form.html.haml b/app/views/admin/p_serial_num_types/_form.html.haml
index 99f609b..30c0ec7 100644
--- a/app/views/admin/p_serial_num_types/_form.html.haml
+++ b/app/views/admin/p_serial_num_types/_form.html.haml
@@ -7,6 +7,6 @@
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
diff --git a/app/views/admin/particulars/_large_form.html.haml b/app/views/admin/particulars/_large_form.html.haml
index 955e106..8d3e124 100755
--- a/app/views/admin/particulars/_large_form.html.haml
+++ b/app/views/admin/particulars/_large_form.html.haml
@@ -6,6 +6,6 @@
=f.inputs do
= render :partial => "form", :locals => {:form => f}
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/partitions/_form.html.haml b/app/views/admin/partitions/_form.html.haml
index 7fc7ed9..00a6121 100644
--- a/app/views/admin/partitions/_form.html.haml
+++ b/app/views/admin/partitions/_form.html.haml
@@ -12,12 +12,7 @@
=render :partial => "admin/partition_lines/form", :locals => {:form => f}
%p= link_to_add_fields "Ajouter une ligne", f, :partition_lines, {:class => "btn btn-primary", :partial =>( "admin/partition_lines/form")}
-
-
-
-
-
-
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/price_documents/_form_avoir.html.haml b/app/views/admin/price_documents/_form_avoir.html.haml
index 38556a2..d07f214 100644
--- a/app/views/admin/price_documents/_form_avoir.html.haml
+++ b/app/views/admin/price_documents/_form_avoir.html.haml
@@ -15,9 +15,8 @@
-
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
diff --git a/app/views/admin/price_documents/_price_document.html.haml b/app/views/admin/price_documents/_price_document.html.haml
index a18ec45..3ebbc8b 100644
--- a/app/views/admin/price_documents/_price_document.html.haml
+++ b/app/views/admin/price_documents/_price_document.html.haml
@@ -202,7 +202,7 @@
-if price_document.cc_label == "Bon de réception achat"
%br
- =link_to "Générer la facture", facture_achat_admin_price_document_path(price_document)
+ =link_to "Générer la factureeee", facture_achat_admin_price_document_path(price_document)
=render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => price_document}
diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml
index 9b78bee..7631d82 100644
--- a/app/views/admin/price_documents/show.html.haml
+++ b/app/views/admin/price_documents/show.html.haml
@@ -246,8 +246,10 @@
-if current_admin.has_permission?("show-costs")
%p
-if @price_document.price_document_type_id == 6
- =link_to "Générer 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 "Générer 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
+ -# =link_to "Générer 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 "Générer 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
+ =link_to "Générer un bon de réception", bon_de_reception_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok and @price_document.stock_generable
+ =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 :
@@ -257,7 +259,11 @@
=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"
+ =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
+ =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
+
-if @price_document.d_number
-if @price_document.cc_label == "Commande achat"
%p=link_to "Générer un bon de réception", bon_de_reception_admin_price_document_path(@price_document), :class => "btn btn-primary"
@@ -334,20 +340,29 @@
-params[:search][:per_page] = params[:search][:per_page] || 5000
-per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
-
-@line_stocks = @price_document.line_stocks.order("date DESC, created_at DESC")
-if params[:price_document_ids]
-@line_stocks = @line_stocks.where(:id => params[:price_document_ids])
-
-
-@line_stocks = sort_by_sorting(@line_stocks, "created_at DESC")
-@line_stocks = @line_stocks.page(page).per(per_page)
%br
-
-
-
.clear
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @line_stocks}
+ -if @price_document.price_line_block.br_ok
+ %h3 Bons de reception générés
+ #bills
+ -params[:search][:per_page] = params[:search][:per_page] || 5000
+ -per_page = params[:search][:per_page]
+ -page = (params[:page] and params[:page] != "") ? params[:page] : 1
+
+ -@price_documents = PriceDocument.where(facture_achat_id: @price_document.id).order("date DESC, created_at DESC")
+ -# -if params[:price_document_ids]
+ -# -@line_stocks = @line_stocks.where(:id => params[:price_document_ids])
+ -@price_documents = sort_by_sorting(@price_documents, "created_at DESC")
+ -@price_documents = @price_documents.page(page).per(per_page)
+ %br
+ .clear
+ =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents}
-if @price_document.label == "Demande prix"
diff --git a/app/views/admin/price_line_blocks/_form.html.haml b/app/views/admin/price_line_blocks/_form.html.haml
index a600eef..08a6a60 100644
--- a/app/views/admin/price_line_blocks/_form.html.haml
+++ b/app/views/admin/price_line_blocks/_form.html.haml
@@ -9,7 +9,7 @@
.col-6
= f.input :customer_ref, :label => "Référence commande client :"
.col-6
- = f.input :wish_date, :label => "Date de livraison souhaitée :", :as => :date
+ /= f.input :wish_date, :label => "Date de livraison souhaitée :", :as => :date
= f.input :ct_creation_date, :label => "Date de commande (si différente de la date de création) :", :as => :date
= f.input :validation_date, :label => "Date de validation :", :as => :date
= f.hidden_field :p_customer_id, :class => "p_customer_id"
diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml
index e1c9540..0d0765a 100644
--- a/app/views/admin/price_lines/_form.html.haml
+++ b/app/views/admin/price_lines/_form.html.haml
@@ -1,33 +1,78 @@
.row.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"}
- .take.mr-1{:style => "padding-left:10px;", :class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )}
+ .take
=ic :arrows
- .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"}
- -# = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id"
+ .col-3
+ = form.input :ct_title, :label => "Designation personnalisée : " if @avoir
+ %div{:class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )}
+ %label Produit :
+
+ %input.p_product_ref_autocomplete_input.form-control{:type => "text", tabindex: 1, autofocus: true, :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)}
+ = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id"
+
+ :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 ) {
- -# .input-group-append
- -# =link_to "#", class: "btn btn-dark",:onclick => "key=genRanHex(12);select_product_from_manager(key);$(this).closest('tr').find('.p_product_ref_id').attr('id', 'p_product_ref_id_'+key);$(this).closest('tr').find('.p_product_ref_name').attr('id', 'p_product_ref_name_'+key);$(this).closest('tr').find('.p_product_ref_qte').attr('id', 'p_product_ref_qte_'+key);return false;" do
- -# =ic(:search)
+ $(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
+ }
+ });
+ } );
+
+
- -form.object.forced_price = true if form.object.ct_u_price_ht
- -# -if form.object.forced_price and form.object.p_product_ref
- -# .col-3
- -# .mx-2
- -# .form-inline
- -# =qi_js_field_price_line_form(form, :price_line, :price_u_ht, :label => false, label_class: "mr-1", :value => form.object.th_price_u_ht)
- -# -else
- -# .col-3
- -# .mx-2
- -# .form-inline
- -# =qi_js_field_price_line_form(form, :price_line, :price_u_ht, :label =>false, label_class: "mr-1")
- -# .col-3
- -# .form-inline.mr-2{:style => ("display:none;" if !current_admin or !current_admin.has_permission?("customer-sheets-personalised-price"))}
- -# = 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}
.col-3
@@ -39,3 +84,4 @@
%span.destroy{style: "font-size: 2rem;"}=link_to_remove_fields ic(:"trash-o"), form
= qi_js_field(form, :price_line, :tva_account_value, :hidden => true)
= form.hidden_field :position, :class => "price_line_position_input"
+
diff --git a/app/views/admin/price_lines/_form_old.html.haml b/app/views/admin/price_lines/_form_old.html.haml
index 60e70c1..2fab6d6 100644
--- a/app/views/admin/price_lines/_form_old.html.haml
+++ b/app/views/admin/price_lines/_form_old.html.haml
@@ -1,4 +1,3 @@
-
.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"}
%table{:style => "width:100%;"}
%tr
diff --git a/app/views/admin/price_lines/_reponse_pane_hover_form.html.haml b/app/views/admin/price_lines/_reponse_pane_hover_form.html.haml
index 7bf404a..22fce64 100644
--- a/app/views/admin/price_lines/_reponse_pane_hover_form.html.haml
+++ b/app/views/admin/price_lines/_reponse_pane_hover_form.html.haml
@@ -1,59 +1,10 @@
=semantic_form_for [:admin, @price_line], :remote => true do |form|
.content
- Produit :
- =form.object.p_product_ref.cc_name if form.object.p_product_ref
- %br
- Quantité à satisfaire :
- =form.object.qte
-
- %br
- %br
-
- %table.top_td{:style => "width:100%;"}
- %tr
-
- %td
- = form.input :p_product_power_id, :label => "Type de chargeur", :collection => PProductPower.all, :include_blank => false, :as => :select
-
- %td
- = form.input :qte_available, :label => "Qté disponible :", :input_html => {:class => "input_price_line_qte"}
-
-
- %td
- = form.input :ct_u_price_ht, :label => "Prix vente"
-
- %td
- = form.input :ready_stock, :label => "Ready stock", :as => :select
-
- %td
- = form.input :ram, :label => "Ram"
-
- %td
- = form.input :ram_unit, :label => "Ram unité"
-
-
- %td
- = form.input :eu, :label => "EU ?", :as => :select
-
-
- %td
- = form.input :p_product_zone_id, :label => "Zone", :collection => PProductZone.all, :include_blank => true, :as => :select
-
-
-
- %td
- = form.input :fullkit, :label => "Fullkit", :as => :select
-
- %td
- = form.input :lang_start, :label => "Démarage sur l'écran de langue (starting on screen language)", :as => :select
-
-
-
-
-
-
+ = form.input :p_product_ref, label: "Produit :" if form.object.p_product_ref
+ = form.input :qte, label: "Quantité à satisfaire :"
+ = form.input :ct_u_price_ht, :label => "Prix vente"
= form.input :comment, :label => "Commentaire", :input_html => {:style => "height:70px;"}
- .actions= form.submit "Sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => form}
diff --git a/app/views/admin/price_lines/edit.js.erb b/app/views/admin/price_lines/edit.js.erb
index 30200cb..78ab72e 100644
--- a/app/views/admin/price_lines/edit.js.erb
+++ b/app/views/admin/price_lines/edit.js.erb
@@ -1 +1 @@
-show_pane_hover("<%= escape_javascript(render(:partial => "reponse_pane_hover_form"))%>",1200,900);
\ No newline at end of file
+show_pane_hover("<%= escape_javascript(render(:partial => "reponse_pane_hover_form"))%>",700,900);
\ No newline at end of file
diff --git a/app/views/admin/s_brands/_form.html.haml b/app/views/admin/s_brands/_form.html.haml
index 515ea9b..cb67cf4 100644
--- a/app/views/admin/s_brands/_form.html.haml
+++ b/app/views/admin/s_brands/_form.html.haml
@@ -3,10 +3,12 @@
.content
=f.inputs do
= f.input :code, :label => "Code :"
- = f.input :name, :label => "Nom :"
+ = f.input :name, :label => "Nom :"
+
+ =render :partial => "qi/actions", :locals => {:f => f}
+
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/stock_movements/_form.html.haml b/app/views/admin/stock_movements/_form.html.haml
index 7aa0dd0..4ce17fa 100644
--- a/app/views/admin/stock_movements/_form.html.haml
+++ b/app/views/admin/stock_movements/_form.html.haml
@@ -2,7 +2,8 @@
.content
=f.inputs do
- = f.input :movement_type, :label => "movement_type :", :as => :hidden
+ -# = f.input :movement_type, :label => "movement_type :", :as => :hidden
+ = f.hidden_field :movement_type
= f.input :description, :label => "Description :", :as => :string
= f.input :date, :label => "Date :", :as => :date
@@ -14,12 +15,7 @@
=render :partial => "admin/stock_movement_lines/form", :locals => {:form => f}
%p= link_to_add_fields "Ajouter une ligne", f, :stock_movement_lines, {:class => "btn btn-primary", :partial =>(@stock_movement.movement_type == "cred" ? "admin/stock_movement_lines/form_cred" : "admin/stock_movement_lines/form")}
+
+ =render :partial => "qi/actions", :locals => {:f => f}
-
-
-
-
-
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/app/views/admin/tva_rates/_form.html.haml b/app/views/admin/tva_rates/_form.html.haml
index 912d303..8a054cc 100644
--- a/app/views/admin/tva_rates/_form.html.haml
+++ b/app/views/admin/tva_rates/_form.html.haml
@@ -13,7 +13,6 @@
-
-
- .actions=f.submit "sauvegarder", :class => "btn btn-primary"
+ =render :partial => "qi/actions", :locals => {:f => f}
+ /.actions=f.submit "sauvegarder", :class => "btn btn-primary"
\ No newline at end of file
diff --git a/db/migrate/20211115181445_add_br_ok_to_price_line_block.rb b/db/migrate/20211115181445_add_br_ok_to_price_line_block.rb
new file mode 100644
index 0000000..cd7ca46
--- /dev/null
+++ b/db/migrate/20211115181445_add_br_ok_to_price_line_block.rb
@@ -0,0 +1,5 @@
+class AddBrOkToPriceLineBlock < ActiveRecord::Migration[6.0]
+ def change
+ add_column :price_line_blocks, :br_ok, :boolean
+ end
+end
diff --git a/db/migrate/20211116144749_add_particular_infos_to_p_custommer_sheet.rb b/db/migrate/20211116144749_add_particular_infos_to_p_custommer_sheet.rb
new file mode 100644
index 0000000..5dbbef9
--- /dev/null
+++ b/db/migrate/20211116144749_add_particular_infos_to_p_custommer_sheet.rb
@@ -0,0 +1,6 @@
+class AddParticularInfosToPCustommerSheet < ActiveRecord::Migration[6.0]
+ def change
+ add_column :p_customer_sheets, :cc_particular_infos, :string
+ add_column :p_customer_sheets, :ac_particular_infos, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index bb52740..dd6f2ee 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2021_11_12_130721) do
+ActiveRecord::Schema.define(version: 2021_11_16_144749) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -1271,6 +1271,8 @@ ActiveRecord::Schema.define(version: 2021_11_12_130721) do
t.datetime "customer_validation_at"
t.boolean "web_order", default: false
t.string "past_id"
+ t.string "cc_particular_infos"
+ t.string "ac_particular_infos"
t.index ["p_customer_id"], name: "index_p_customer_sheets_on_p_customer_id"
end
@@ -2474,6 +2476,7 @@ ActiveRecord::Schema.define(version: 2021_11_12_130721) do
t.date "stock_entrance_date"
t.decimal "ct_tot_amount_ht", precision: 14, scale: 2
t.bigint "price_document_id"
+ t.boolean "br_ok"
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
From 6208ea74d5867f212781f8f6205f1a8b69326415 Mon Sep 17 00:00:00 2001
From: Philippe
Date: Tue, 16 Nov 2021 21:42:44 +0100
Subject: [PATCH 2/4] adding alexis feedbacks
---
.../admin/p_customer_sheets_controller.rb | 12 ++---
.../admin/price_documents_controller.rb | 29 +++++++-----
app/models/p_customer_sheet.rb | 38 ++++-----------
app/models/price_document.rb | 15 +-----
app/models/price_line_block.rb | 21 ++-------
.../admin/p_customer_sheets/_form.html.haml | 2 +-
.../admin/p_customer_sheets/show.html.haml | 4 +-
.../price_documents/_price_document.html.haml | 2 +-
.../admin/price_documents/show.html.haml | 6 ++-
.../admin/price_line_blocks/_form.html.haml | 46 +++++++++++++------
config/routes.rb | 2 +
11 files changed, 80 insertions(+), 97 deletions(-)
diff --git a/app/controllers/admin/p_customer_sheets_controller.rb b/app/controllers/admin/p_customer_sheets_controller.rb
index 74d7ee7..8cd2e5d 100644
--- a/app/controllers/admin/p_customer_sheets_controller.rb
+++ b/app/controllers/admin/p_customer_sheets_controller.rb
@@ -175,20 +175,14 @@ class Admin::PCustomerSheetsController < ApplicationController
def create
@p_customer_sheet = PCustomerSheet.new(params.require(:p_customer_sheet).permit!)
@p_customer_sheet.admin = current_admin
+ @p_customer_sheet.price_line_block.particular_send = @p_customer_sheet.price_line_block.particular_bill if params[:p_customer_sheet][:price_line_block_attributes][:same_adress] == "oui"
+
if @p_customer_sheet.save
-
redirect_to admin_p_customer_sheet_path(@p_customer_sheet)
else
- puts "ERRORSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
- puts params
- puts @p_customer_sheet.errors.messages
- puts "ERRORSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
@p_customer = @p_customer_sheet.price_line_block.p_customer
-
render action: "new"
-
end
-
end
@@ -233,7 +227,7 @@ class Admin::PCustomerSheetsController < ApplicationController
redirect_back(fallback_location: admin_p_customer_sheets_path)
end
-
+
def generate_bc
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer_sheet.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1)
diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb
index 3840432..ca35b64 100644
--- a/app/controllers/admin/price_documents_controller.rb
+++ b/app/controllers/admin/price_documents_controller.rb
@@ -711,6 +711,7 @@ class Admin::PriceDocumentsController < ApplicationController
price_document.doc_ref_id = @past_price_document.id
price_document.p_fournisseur = @past_price_document.p_fournisseur
price_document.price_line_block = @past_price_document.price_line_block.dup
+ price_document.tva_type = @past_price_document.tva_type
if @past_price_document.cc_label == "Commande achat"
price_document.bon_de_commande_achat_id = @past_price_document.id
@@ -747,9 +748,11 @@ class Admin::PriceDocumentsController < ApplicationController
end
new_pl.p_articles = pl.p_articles
price_document.price_line_block.price_lines << new_pl
- price_document.price_line_block.br_ok = true
- end
+ @past_price_document.price_line_block.br_ok = true
+ @past_price_document.save
+ end
+
if price_document.save
#price_document.reset_for_update
#price_document.archive_now
@@ -770,7 +773,6 @@ class Admin::PriceDocumentsController < ApplicationController
def facture_achat
@past_price_document = PriceDocument.find(params[:id])
-
@p_customer_sheet = @past_price_document.ref_element
if @p_customer_sheet
@@ -783,21 +785,19 @@ class Admin::PriceDocumentsController < ApplicationController
price_document.doc_ref_id = @past_price_document.id
price_document.p_fournisseur = @past_price_document.p_fournisseur
-
price_document.price_line_block = @past_price_document.price_line_block.dup
-
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.tva_type = @past_price_document.tva_type
@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
price_document.price_line_block.price_lines << new_pl
end
@@ -818,10 +818,17 @@ class Admin::PriceDocumentsController < ApplicationController
render :inline => price_document.errors.messages.to_s
end
-
-
-
-
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
diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb
index f3e4801..b64b760 100644
--- a/app/models/p_customer_sheet.rb
+++ b/app/models/p_customer_sheet.rb
@@ -59,11 +59,6 @@ class PCustomerSheet < ApplicationRecord
end
-
-
- #["created_at", "price_line_blocks.wish_date", "cc_tot_amount_ht","cc_tot_amount_ttc"]
-
-
before_validation do
@@ -273,18 +268,6 @@ class PCustomerSheet < ApplicationRecord
self.archive_now if !self.archived
self.block_price if !self.price_blocked
- puts "TVA TYPE IDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
- puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
- puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
- puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
- puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 1).empty?
- puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
- puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
- puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
- puts !self.price_line_block.price_lines.joins(:p_articles).where("p_articles.tva_type_id = ?", 2).empty?
- puts "TVA TYPE IDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
-
-
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)
@@ -297,17 +280,11 @@ class PCustomerSheet < ApplicationRecord
new_pl = pl.dup
new_pl.ac_block_type = nil
- puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
- puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
- puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
- puts pl.p_articles.where(tva_type_id: 1)
- pl.p_articles.where(tva_type_id: 1).each { |p_article| new_pl.p_articles << p_article }
- puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
- puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
- puts "PARTICLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
-
-
- raise
+ 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
@@ -454,5 +431,10 @@ class PCustomerSheet < 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
+ #exclure les produit non stockable et sans SN
+ end
+
end
diff --git a/app/models/price_document.rb b/app/models/price_document.rb
index 582ffb6..2505167 100644
--- a/app/models/price_document.rb
+++ b/app/models/price_document.rb
@@ -331,7 +331,6 @@ class PriceDocument < ApplicationRecord
end
-
def personalised_archive
self.price_line_block.archive_now
end
@@ -596,19 +595,7 @@ class PriceDocument < ApplicationRecord
url = (Rails.env.development? ? "http://localhost:3000" : "http://mdmb.basiclabs.fr").to_s+url
pdf = ("pdf2")
node_file = @temp_file
-
-
- puts "NODE IFLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
- puts url
- puts url
- puts url
- puts url
- puts url
- puts node_file
- puts "NODE IFLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
-
-
-
+
system("node #{pdf}.js #{Shellwords.escape(url)} #{Shellwords.escape(@temp_file)}")
require 'posix/spawn'
diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb
index e63b0df..6211ab7 100644
--- a/app/models/price_line_block.rb
+++ b/app/models/price_line_block.rb
@@ -1,6 +1,6 @@
class PriceLineBlock < ApplicationRecord
belongs_to :price_lineable, :polymorphic => true
- validates :wish_date, :presence => true, :if => :wish_date_needed?
+ #validates :wish_date, :presence => true, :if => :wish_date_needed?
has_many :price_lines
accepts_nested_attributes_for :price_lines, allow_destroy: true
belongs_to :p_devise
@@ -11,17 +11,16 @@ class PriceLineBlock < ApplicationRecord
#validates :particular_send_id, :presence => true, :if => :particular_send_needed?
belongs_to :particular_bill, :class_name => "Particular"#, :dependent => :destroy
-
accepts_nested_attributes_for :particular_bill
-
+
belongs_to :particular_send, :class_name => "Particular"#, :dependent => :destroy
-
accepts_nested_attributes_for :particular_send
has_many :line_blocks
belongs_to :p_customer
belongs_to :p_payment_type
+ attr_accessor :same_adress
PURCHASE_BLOCKS = ["Réponse fournisseur", "Consultation fournisseur", "Facture d'achat", "Commande achat", "Demande prix", "Bon de commande achat", "Bon de réception achat", "Facture achat", "Avoir achat", "Catalogue fournisseur"]
@@ -165,19 +164,6 @@ class PriceLineBlock < ApplicationRecord
end
def update_stocks
- puts "UPDATE STOCKSSSSSSSSSSSSSSSSSSSSSSSSSSS"
- puts self.block_type == "Facture"
- puts self.block_type == "Bon de commande client"
- puts self.block_type
- puts self.block_type
- puts self.block_type
- puts self.block_type
- puts self.block_type
- puts !self.cost_ok
- puts "UPDATE STOCKSSSSSSSSSSSSSSSSSSSSSSSSSSS"
-
-
-
if self.block_type == "Facture" or self.block_type == "Bon de commande client" or self.block_type == "Bon de réception achat" && !self.cost_ok
if self.test_if_stock_ok?
self.price_lines.each do |pl|
@@ -285,6 +271,7 @@ class PriceLineBlock < ApplicationRecord
elsif self.block_type == "Devis" or self.block_type == "Demande de commande"
false
else
+ raise
true
end
end
diff --git a/app/views/admin/p_customer_sheets/_form.html.haml b/app/views/admin/p_customer_sheets/_form.html.haml
index 5df9e97..b1382c6 100755
--- a/app/views/admin/p_customer_sheets/_form.html.haml
+++ b/app/views/admin/p_customer_sheets/_form.html.haml
@@ -2,7 +2,7 @@
=#debug form.object.errors.messages if current_admin.id == 1
=form.semantic_fields_for :price_line_block do |f|
=render :partial => "admin/price_line_blocks/form", :locals => {:f => f}
-
+
-# .content
-# .qi_row
-# .qi_pannel.qi_plain.padding.row
diff --git a/app/views/admin/p_customer_sheets/show.html.haml b/app/views/admin/p_customer_sheets/show.html.haml
index 7315b0d..544a72e 100644
--- a/app/views/admin/p_customer_sheets/show.html.haml
+++ b/app/views/admin/p_customer_sheets/show.html.haml
@@ -59,7 +59,9 @@
-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"
+ %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
diff --git a/app/views/admin/price_documents/_price_document.html.haml b/app/views/admin/price_documents/_price_document.html.haml
index 3ebbc8b..a18ec45 100644
--- a/app/views/admin/price_documents/_price_document.html.haml
+++ b/app/views/admin/price_documents/_price_document.html.haml
@@ -202,7 +202,7 @@
-if price_document.cc_label == "Bon de réception achat"
%br
- =link_to "Générer la factureeee", facture_achat_admin_price_document_path(price_document)
+ =link_to "Générer la facture", facture_achat_admin_price_document_path(price_document)
=render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => price_document}
diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml
index 7631d82..a078692 100644
--- a/app/views/admin/price_documents/show.html.haml
+++ b/app/views/admin/price_documents/show.html.haml
@@ -16,7 +16,6 @@
=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
-
.qi_row
=#debug @price_document.price_line_block.price_lines.count
%table.table.table-striped
@@ -250,6 +249,7 @@
-# =link_to "Générer 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
=link_to "Générer un bon de réception", bon_de_reception_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok and @price_document.stock_generable
=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 :
@@ -262,7 +262,9 @@
=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
- =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 "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
-if @price_document.d_number
-if @price_document.cc_label == "Commande achat"
diff --git a/app/views/admin/price_line_blocks/_form.html.haml b/app/views/admin/price_line_blocks/_form.html.haml
index 08a6a60..d4a8b66 100644
--- a/app/views/admin/price_line_blocks/_form.html.haml
+++ b/app/views/admin/price_line_blocks/_form.html.haml
@@ -20,18 +20,24 @@
-if f.object.p_customer and f.object.p_customer.particular
=render :partial => "admin/p_customers/apercu", :locals => {:particular => f.object.p_customer.particular}
.qi_pannel.qi_plain.padding.row
- .col-6
- Adresse de livraison :
- =f.semantic_fields_for :particular_send do |form_particular_send|
- =render :partial => "admin/particulars/form", :locals => {:form => form_particular_send}
- =form_particular_send.hidden_field :owner_id
- =form_particular_send.hidden_field :owner_type
- .col-6
- Adresse de facturation :
- =f.semantic_fields_for :particular_bill do |form_particular_bill|
- =render :partial => "admin/particulars/form", :locals => {:form => form_particular_bill}
- =form_particular_bill.hidden_field :owner_id
- =form_particular_bill.hidden_field :owner_type
+ .col-12
+ .row
+ .col-3
+ = f.input :same_adress, label: "Adresse de livraison identique ?", collection: [["oui", "oui"], ["non", "non"]], include_blank: false, as: :select
+ .row
+ .col-6
+ Adresse de facturation :
+ =f.semantic_fields_for :particular_bill do |form_particular_bill|
+ =render :partial => "admin/particulars/form", :locals => {:form => form_particular_bill}
+ =form_particular_bill.hidden_field :owner_id
+ =form_particular_bill.hidden_field :owner_type
+ .col-6#send_adress
+ Adresse de livraison :
+ =f.semantic_fields_for :particular_send do |form_particular_send|
+ =render :partial => "admin/particulars/form", :locals => {:form => form_particular_send}
+ =form_particular_send.hidden_field :owner_id
+ =form_particular_send.hidden_field :owner_type
+
-if current_admin.has_permission?("customer-sheets-bl")
=# f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"}
@@ -97,4 +103,18 @@
$('.p_product_ref_select').select2();
$('.add_lines').click(function() {
$('.p_product_ref_select').last().select2();
- });
\ No newline at end of file
+ });
+
+ $('#p_customer_sheet_price_line_block_attributes_same_adress_input').on('change', function(e) {
+ if ($('#p_customer_sheet_price_line_block_attributes_same_adress_input :selected').text() == "oui") {
+ $( "#send_adress" ).show().fadeOut( 500 );
+ } else {
+ $( "#send_adress" ).show().fadeIn( 500 );
+ }
+ });
+
+ if ($('#p_customer_sheet_price_line_block_attributes_same_adress_input :selected').text() == "oui") {
+ $( "#send_adress" ).hide();
+ } else {
+ $( "#send_adress" ).show();
+ }
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index e0a0032..11a9e6d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -672,6 +672,8 @@ Rails.application.routes.draw do
get :buy_order_create
get :bon_de_reception
get :facture_achat
+ get :update_pcustomersheet_statut
+
end
collection do
get :search_to_affect
From 581b20c92ca8742fa669feeee5defa067e1d70e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Barnab=C3=A9?=
Date: Wed, 17 Nov 2021 14:13:16 +0100
Subject: [PATCH 3/4] breadcrumb bugfix + reorder menus + adding commercials
---
.../admin/price_documents_controller.rb | 23 ++--
app/controllers/application_controller.rb | 118 +++++++++---------
app/models/price_document.rb | 2 +-
.../admin/price_documents/index.html.haml | 3 +
4 files changed, 74 insertions(+), 72 deletions(-)
diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb
index ca35b64..cef886c 100644
--- a/app/controllers/admin/price_documents_controller.rb
+++ b/app/controllers/admin/price_documents_controller.rb
@@ -44,21 +44,26 @@ class Admin::PriceDocumentsController < ApplicationController
def admin_space
- if (params[:document_type] and (params[:document_type] == "Facture d'achat" or params[:document_type] == "Commande achat")) or [6,7].include?(params[:price_document_type_id].to_i) or (params[:price_document_type_ids] and (params[:price_document_type_ids].include?("6") or params[:price_document_type_ids].include?("7"))) or (params[:id] and d = PriceDocument.where(:id => params[:id]).first and [6,7].include?(d.price_document_type_id))
- @admin_space = "documents"
-
- qi_menu(:documents)
-
- else
+ # if (params[:document_type] and (params[:document_type] == "Facture d'achat" or params[:document_type] == "Commande achat")) or [6,7].include?(params[:price_document_type_id].to_i) or (params[:price_document_type_ids] and (params[:price_document_type_ids].include?("6") or params[:price_document_type_ids].include?("7"))) or (params[:id] and d = PriceDocument.where(:id => params[:id]).first and [6,7].include?(d.price_document_type_id))
+ if PriceDocument::PURCHASES.include?(params[:document_type]) or (params[:price_document_type_id].present? and PriceDocument::PURCHASES.include?(PriceDocumentType.find(params[:price_document_type_id].to_i).label)) or (params[:id] and d = PriceDocument.where(:id => params[:id]).first and PriceDocument::PURCHASES.include?(d.price_document_type.label)) or (params[:price_document_type_ids].present? and params[:price_document_type_ids] == PriceDocumentType.where(label: PriceDocument::PURCHASES).ids.map{|id| id.to_s})
+
+ @admin_space = "achats"
+
+ qi_menu(:achats)
+
+ elsif PriceDocument::SALES.include?(params[:document_type]) or (params[:price_document_type_id].present? and PriceDocument::SALES.include?(PriceDocumentType.find(params[:price_document_type_id].to_i).label)) or (params[:id] and d = PriceDocument.where(:id => params[:id]).first and PriceDocument::SALES.include?(d.price_document_type.label)) or (params[:price_document_type_ids].present? and params[:price_document_type_ids] == PriceDocumentType.where(label: PriceDocument::SALES).ids.map{|id| id.to_s})
@admin_space = "ventes"
qi_menu(:ventes)
-
+ else
+ @admin_space = "documents"
+
+ qi_menu(:documents)
end
- @admin_space = "documents"
+ # @admin_space = "documents"
- qi_menu(:documents)
+ # qi_menu(:documents)
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 05e0c17..5ada2fe 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -66,68 +66,52 @@ class ApplicationController < ActionController::Base
def set_admin_menu
-
+ # CLient
set_big_menu :clients, "Clients", admin_p_customers_path, "address-book-o", "#016699"
set_sub_menu :clients, :p_customers, "Clients", admin_p_customers_path if current_admin.has_permission?("customers")
-
set_sub_menu :clients, :p_customer_cats, "Catégories clients", admin_p_customer_cats_path if current_admin.has_permission?("p_customer_cats")
-
-
+ set_sub_menu :clients, :p_commercials, "Commerciaux", admin_p_commercials_path if current_admin.has_permission?("commercials")
+ set_sub_menu :clients, :p_commercial_cats, "Catégories de commerciaux", admin_p_commercial_cats_path if current_admin.has_permission?("commercial-cats")
- set_big_menu :stocks, "Produits", admin_p_products_path, "cubes", "#718197"
+
+ # Produit
+ set_big_menu :products, "Produits", admin_p_products_path, "cubes", "#718197"
if current_admin.has_permission?("products")
- set_sub_menu :stocks, :p_products, "Produits", admin_p_products_path
-
- set_sub_menu :stocks, :p_product_refs, "Références", admin_p_product_refs_path
- set_sub_menu :stocks, :p_articles, "Articles", admin_p_articles_path
- # set_sub_menu :stocks, :promos_p_products, "Offres spots", promos_admin_p_products_path
-
- end
-
-
-
- if current_admin.has_permission?("product-cats")
- set_sub_menu :stocks, :p_product_cats, "Catégories produits", admin_p_product_cats_path
- # set_sub_menu :stocks, :p_product_sub_cats, "Sous catégories produits", admin_p_product_sub_cats_path
+ set_sub_menu :products, :p_products, "Produits", admin_p_products_path
+ set_sub_menu :products, :p_product_refs, "Références", admin_p_product_refs_path
+ set_sub_menu :products, :p_articles, "Articles", admin_p_articles_path
+ if current_admin.has_permission?("product-cats")
+ set_sub_menu :products, :p_product_cats, "Catégories produits", admin_p_product_cats_path
+ # set_sub_menu :products, :p_product_sub_cats, "Sous catégories produits", admin_p_product_sub_cats_path
+ end
+ set_sub_menu :products, :p_preferences_products_menu, "Préférences", admin_p_products_path
+ # set_sub_menu :products, :promos_p_products, "Offres spots", promos_admin_p_products_path
end
- set_sub_menu :stocks, :p_preferences_products_menu, "Préférences", admin_p_products_path
-
-
if current_admin.has_permission?("brands")
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :s_brands, "Marques", admin_s_brands_path
-
-
+ set_sub_sub_menu :products, :p_preferences_products_menu, :s_brands, "Marques", admin_s_brands_path
end
if current_admin.has_permission?("fournisseurs")
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_fournisseurs, "Fournisseurs", admin_p_fournisseurs_path
-
-
- end
-
- if current_admin.has_permission?("stocks")
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :stock_alias, "Stocks", admin_line_stocks_path
-
-
+ set_sub_sub_menu :products, :p_preferences_products_menu, :p_fournisseurs, "Fournisseurs", admin_p_fournisseurs_path
end
if current_admin.has_permission?("boutique")
# set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_colors, "Couleurs"
#set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_article_serial_nums, "Numeros série"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_serial_num_types, "Types de Numero série"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_ref_specs, "Specs"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_spec_types, "Types de specs"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_spec_values, "Valeurs de specs"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_grades, "Grades" if PGrade::ACTIVATED
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_powers, "Types de chargeurs"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :p_product_zones, "Zones produits"
- set_sub_sub_menu :stocks, :p_preferences_products_menu, :import_csvs, "Import Excel"
+ set_sub_sub_menu :products, :p_preferences_products_menu, :p_serial_num_types, "Types de Numero série"
+ set_sub_sub_menu :products, :p_preferences_products_menu, :p_product_ref_specs, "Specs"
+ set_sub_sub_menu :products, :p_preferences_products_menu, :p_spec_types, "Types de specs"
+ set_sub_sub_menu :products, :p_preferences_products_menu, :p_spec_values, "Valeurs de specs"
+ set_sub_sub_menu :products, :p_preferences_products_menu, :p_grades, "Grades" if PGrade::ACTIVATED
+ set_sub_sub_menu :products, :p_preferences_products_menu, :p_product_powers, "Types de chargeurs"
+ set_sub_sub_menu :products, :p_preferences_products_menu, :p_product_zones, "Zones produits"
+ set_sub_sub_menu :products, :p_preferences_products_menu, :import_csvs, "Import Excel"
# set_sub_sub_menu :stocks, :p_preferences_products_menu, :import_csv_match_refs, "Rapprochement références", match_refs_admin_import_csvs_path
# set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_cats, "Catégories SORECOP"
# set_sub_sub_menu :stocks, :p_preferences_products_menu, :sorecop_taxes, "taxe SORECOP"
@@ -135,46 +119,56 @@ class ApplicationController < ActionController::Base
end
-
-
-
-
+ # Vente
set_big_menu :ventes, "Commandes", admin_p_customer_sheets_path, "shopping-cart", "#518889"
-
set_sub_menu :ventes, :p_customer_sheets, "Demande de commande", admin_p_customer_sheets_path
- #if false
- PriceDocumentType.where(:label => PriceDocument::SALES).order("id DESC").all.each do |p_document_type|
+ PriceDocumentType.where(:label => PriceDocument::SALES).order("id DESC").all.each do |p_document_type|
+ set_sub_menu :ventes, :"p_document_type_#{p_document_type.label.to_s.to_slug}", p_document_type.label, admin_price_documents_path(:price_document_type_id => p_document_type.id)
+ end
+ set_sub_menu :ventes, :price_documents_all, "Tous documents", admin_price_documents_path(:price_document_type_ids => PriceDocumentType.where(:label => PriceDocument::SALES).ids)
- set_sub_menu :ventes, :"p_document_type_#{p_document_type.label.to_s.to_slug}", p_document_type.label, admin_price_documents_path(:price_document_type_id => p_document_type.id)
- end
+ # Achat
+ set_big_menu :achats, "Achats", admin_price_documents_path(:price_document_type_ids => PriceDocumentType.where(:label => PriceDocument::PURCHASES).ids), "file-text-o", "#d97941"
+ PriceDocumentType.where(:label => PriceDocument::PURCHASES).order("id DESC").all.each do |p_document_type|
+ set_sub_menu :achats, :"p_document_type_#{p_document_type.label.to_s.to_slug}", p_document_type.label, admin_price_documents_path(:price_document_type_id => p_document_type.id)
+ end
+ set_sub_menu :achats, :price_documents_all, "Tous documents", admin_price_documents_path(:price_document_type_ids => PriceDocumentType.where(:label => PriceDocument::PURCHASES).ids)
+
+ if current_admin.has_permission?("stocks")
+ set_sub_menu :achats, :line_stocks, "Lignes de stock", admin_line_stocks_path
+ set_sub_menu :achats, :stock_movements, "Mouvements de stock manuel", admin_stock_movements_path
+ end
+
+ # Stock
+ # set_big_menu :stocks, "Stocks", admin_line_stocks_path, "cubes", "#d97941"
+ # TODO Corriger le path
+
+
+ # set_sub_sub_menu :stocks, :p_preferences_products_menu, :stock_alias, "Stocks", admin_line_stocks_path
+
+
+
+ # Documents
+ # set_big_menu :documents, "Documents", admin_price_documents_path, "file-text-o", "#d97941"
+ # PriceDocumentType.all.order("id DESC").each do |p_document_type|
+ # set_sub_menu :documents, :"p_document_type_#{p_document_type.label.to_s.to_slug}", p_document_type.label, admin_price_documents_path(:price_document_type_id => p_document_type.id)
+ # end
- set_sub_menu :ventes, :price_documents_all, "Tous documents", admin_price_documents_path
- #end
if current_admin.has_permission?("bills")
- set_big_menu :documents, "Achats", admin_price_documents_path(:price_document_type_id =>6, :purchase => true), "file-text-o", "#d97941"
#set_sub_menu :documents, :buy_lists, "TdB achats"
- set_sub_menu :documents, :line_stocks, "Lignes de stock", admin_line_stocks_path
- set_sub_menu :documents, :stock_movements, "Mouvements de stock manuel", admin_stock_movements_path
- PriceDocumentType.where(:label => PriceDocument::PURCHASES).order("id DESC").all.each do |p_document_type|
- set_sub_menu :documents, :"p_document_type_#{p_document_type.label.to_s.to_slug}", p_document_type.label, admin_price_documents_path(:price_document_type_id => p_document_type.id)
- end
# set_sub_menu :documents, :"p_document_type_reponse_fournisseur", "Réponses fournisseurs", admin_price_documents_path(:price_document_type_id => PriceDocumentType.find_by(label: "Réponse fournisseur").id)
-
-
-
-
end
diff --git a/app/models/price_document.rb b/app/models/price_document.rb
index 2505167..3076daf 100644
--- a/app/models/price_document.rb
+++ b/app/models/price_document.rb
@@ -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 = ["Devis", "Avoir", "Facture", "Bon de livraison", "Bon de commande client"]
# AVANCEMENT = ["0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"]
AVANCEMENT = ["0%", "25%", "50%", "75%", "100"]
diff --git a/app/views/admin/price_documents/index.html.haml b/app/views/admin/price_documents/index.html.haml
index 6ad976f..65869ab 100644
--- a/app/views/admin/price_documents/index.html.haml
+++ b/app/views/admin/price_documents/index.html.haml
@@ -8,8 +8,11 @@
-else
=link_to ic(:plus)+" Demande de commande", admin_p_customers_path(:offre => true), :class => "btn btn-primary bgbd-ventes"
+
-if params[:price_document_type_id]
=breadcrumb second_title: PriceDocumentType.find(params[:price_document_type_id]).label
+ -else
+ =breadcrumb second_title: "Tous les documents"
.qi_search_row
=form_tag "", :method => "get", :onsubmit => "" do
From 127f14f479e2c4c124c568c54dc64711fdb64434 Mon Sep 17 00:00:00 2001
From: Philippe
Date: Wed, 17 Nov 2021 19:52:30 +0100
Subject: [PATCH 4/4] adding p_article stock out method
---
app/controllers/admin/buy_lists_controller.rb | 2 +-
.../admin/p_customer_sheets_controller.rb | 3 +-
.../admin/price_documents_controller.rb | 30 +---
app/helpers/translation_helper.rb | 2 +
app/models/line_stock.rb | 3 +
app/models/p_customer.rb | 4 +-
app/models/p_customer_sheet.rb | 141 +++++++++---------
app/models/p_product.rb | 2 +-
app/models/price_document.rb | 7 +-
app/models/price_line_block.rb | 122 +++++++++++----
.../admin/p_customer_sheets/show.html.haml | 106 +++++++------
app/views/admin/p_products/_form.html.haml | 8 +-
.../admin/price_documents/show.html.haml | 23 ++-
.../_price_line_block.html.haml | 2 +-
config/routes.rb | 1 -
...61758_add_p_article_to_line_stock_usage.rb | 5 +
db/schema.rb | 3 +-
17 files changed, 266 insertions(+), 198 deletions(-)
create mode 100644 db/migrate/20211117161758_add_p_article_to_line_stock_usage.rb
diff --git a/app/controllers/admin/buy_lists_controller.rb b/app/controllers/admin/buy_lists_controller.rb
index 51bd848..7e15188 100644
--- a/app/controllers/admin/buy_lists_controller.rb
+++ b/app/controllers/admin/buy_lists_controller.rb
@@ -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
diff --git a/app/controllers/admin/p_customer_sheets_controller.rb b/app/controllers/admin/p_customer_sheets_controller.rb
index 8cd2e5d..0d83a9a 100644
--- a/app/controllers/admin/p_customer_sheets_controller.rb
+++ b/app/controllers/admin/p_customer_sheets_controller.rb
@@ -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
diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb
index ca35b64..18956fb 100644
--- a/app/controllers/admin/price_documents_controller.rb
+++ b/app/controllers/admin/price_documents_controller.rb
@@ -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
diff --git a/app/helpers/translation_helper.rb b/app/helpers/translation_helper.rb
index 068f0ab..825930e 100755
--- a/app/helpers/translation_helper.rb
+++ b/app/helpers/translation_helper.rb
@@ -83,6 +83,8 @@ module TranslationHelper
r = ''+value+''
elsif value == "Payé"
r = ''+value+''
+ elsif value == "Refusée"
+ r = ''+value+''
end
return raw(r)
diff --git a/app/models/line_stock.rb b/app/models/line_stock.rb
index 21da23b..b06f8e0 100644
--- a/app/models/line_stock.rb
+++ b/app/models/line_stock.rb
@@ -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
diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb
index 0d11ced..d046876 100644
--- a/app/models/p_customer.rb
+++ b/app/models/p_customer.rb
@@ -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
diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb
index b64b760..974391f 100644
--- a/app/models/p_customer_sheet.rb
+++ b/app/models/p_customer_sheet.rb
@@ -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
diff --git a/app/models/p_product.rb b/app/models/p_product.rb
index 886c99f..7eaf7b8 100644
--- a/app/models/p_product.rb
+++ b/app/models/p_product.rb
@@ -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" }
diff --git a/app/models/price_document.rb b/app/models/price_document.rb
index 2505167..78145fa 100644
--- a/app/models/price_document.rb
+++ b/app/models/price_document.rb
@@ -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
diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb
index 6211ab7..03bab55 100644
--- a/app/models/price_line_block.rb
+++ b/app/models/price_line_block.rb
@@ -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
diff --git a/app/views/admin/p_customer_sheets/show.html.haml b/app/views/admin/p_customer_sheets/show.html.haml
index 544a72e..7276f32 100644
--- a/app/views/admin/p_customer_sheets/show.html.haml
+++ b/app/views/admin/p_customer_sheets/show.html.haml
@@ -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?
diff --git a/app/views/admin/p_products/_form.html.haml b/app/views/admin/p_products/_form.html.haml
index 6a02656..fb28bce 100755
--- a/app/views/admin/p_products/_form.html.haml
+++ b/app/views/admin/p_products/_form.html.haml
@@ -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
diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml
index a078692..7bd05c1 100644
--- a/app/views/admin/price_documents/show.html.haml
+++ b/app/views/admin/price_documents/show.html.haml
@@ -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"
diff --git a/app/views/admin/price_line_blocks/_price_line_block.html.haml b/app/views/admin/price_line_blocks/_price_line_block.html.haml
index 54da1fc..ac38232 100644
--- a/app/views/admin/price_line_blocks/_price_line_block.html.haml
+++ b/app/views/admin/price_line_blocks/_price_line_block.html.haml
@@ -62,7 +62,7 @@
%table.table
%thead
%tr
- %th IDddd
+ %th ID
%th Référence
%th Désignation
%th Qté
diff --git a/config/routes.rb b/config/routes.rb
index 11a9e6d..effb589 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/db/migrate/20211117161758_add_p_article_to_line_stock_usage.rb b/db/migrate/20211117161758_add_p_article_to_line_stock_usage.rb
new file mode 100644
index 0000000..6486543
--- /dev/null
+++ b/db/migrate/20211117161758_add_p_article_to_line_stock_usage.rb
@@ -0,0 +1,5 @@
+class AddPArticleToLineStockUsage < ActiveRecord::Migration[6.0]
+ def change
+ add_column :line_stock_usages, :p_article_id, :integer
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index dd6f2ee..29d819f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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