From 6208ea74d5867f212781f8f6205f1a8b69326415 Mon Sep 17 00:00:00 2001
From: Philippe
Date: Tue, 16 Nov 2021 21:42:44 +0100
Subject: [PATCH] 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