From 9b86a9a3146df88fc1163b98073bcd231bac7c97 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Mon, 9 Nov 2020 15:38:09 +0100 Subject: [PATCH] =?UTF-8?q?mise=20=C3=A0=20jour=20process=20clients=20+=20?= =?UTF-8?q?facture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/price_documents_controller.rb | 2 +- app/models/p_customer.rb | 23 +++++------ app/models/p_customer_sheet.rb | 13 ++++++ app/models/particular.rb | 4 +- app/views/admin/p_customers/_form.html.haml | 40 ++++++++++--------- app/views/admin/p_customers/show.html.haml | 16 ++++---- app/views/admin/price_lines/_form.html.haml | 1 - ...109142527_add_code_index_to_p_customers.rb | 5 +++ db/schema.rb | 3 +- 9 files changed, 63 insertions(+), 44 deletions(-) create mode 100644 db/migrate/20201109142527_add_code_index_to_p_customers.rb diff --git a/app/controllers/admin/price_documents_controller.rb b/app/controllers/admin/price_documents_controller.rb index f7cfa33..e3ae476 100644 --- a/app/controllers/admin/price_documents_controller.rb +++ b/app/controllers/admin/price_documents_controller.rb @@ -225,7 +225,7 @@ class Admin::PriceDocumentsController < ApplicationController end - redirect_to admin_price_documents_path("price_document_type_ids[]" => @price_document.price_document_type_id) + redirect_back(fallback_location: admin_price_documents_path) end diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index b83e098..9b08106 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -31,7 +31,7 @@ class PCustomer < ApplicationRecord has_many :p_documents - validates :code, :presence => true, :uniqueness => true + #validates :code, :presence => true, :uniqueness => true has_many :p_compta_elements @@ -101,18 +101,7 @@ class PCustomer < ApplicationRecord before_validation do - if !self.code? - if self.particulars[0] - cars = self.particulars[0].organisation - cars += self.particulars[0].name - cars += self.particulars[0].firstname - - cars = cars.to_slug.gsub(/\W/,'').upcase - cars = cars[0..2] - cars += - self.code = self.particulars[0].cp+cars - end - end + generate_mlm_token @@ -296,6 +285,14 @@ class PCustomer < ApplicationRecord self.save end + + + if !self.code? + last = PCustomer.order("code_index DESC").first + self.code_index = last.code_index + 1 + self.code = "CLT"+('%05d' % self.code_index) + self.save + end end diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb index a37fbcc..d864656 100644 --- a/app/models/p_customer_sheet.rb +++ b/app/models/p_customer_sheet.rb @@ -20,6 +20,19 @@ class PCustomerSheet < ApplicationRecord has_many :price_documents, :as => :ref_element + acts_as_sorting :fields => { + + :p_commercial => {:name => "Commercial", :reorder => false}, + :created_at => {:name => "Date", :reorder => true, :sort_name => "p_customer_sheets.created_at"}, + :admin_id => {:name => "Déposée par", :reorder => true}, + :demande_type => {:name => "Type de demande", :reorder => true}, + :p_customer => {:name => "Client", :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}, + :actions => {:name => "Actions", :reorder => false}, + } + QI_DYNAMICS = %w(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 ) diff --git a/app/models/particular.rb b/app/models/particular.rb index f072e1a..e276136 100644 --- a/app/models/particular.rb +++ b/app/models/particular.rb @@ -11,9 +11,9 @@ class Particular < ApplicationRecord #validates :name, :presence => true, :if => :force_validation #validates :firstname, :presence => true, :if => :force_validation validates :email, :presence => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :if => :force_email_validation - validates :address_2, :presence => true, :if => :force_validation + #validates :address_2, :presence => true, :if => :force_validation validates :cp, :presence => true, :if => :force_validation - validates :city, :presence => true, :if => :force_validation + #validates :city, :presence => true, :if => :force_validation validates :country, :presence => true, :if => :force_validation #validates :tel, :presence => true, :if => :force_validation #validates :organisation, :presence => true, :if => :force_validation diff --git a/app/views/admin/p_customers/_form.html.haml b/app/views/admin/p_customers/_form.html.haml index fa6350b..467a3b0 100755 --- a/app/views/admin/p_customers/_form.html.haml +++ b/app/views/admin/p_customers/_form.html.haml @@ -43,11 +43,6 @@ -if @p_customer.id or (@p_customer.code? and @p_customer.errors[:code]) = form.input :code, :label => "Code client :" - = form.input :siret, :label => "Siret :" - = form.input :ape, :label => "Ape :" - = form.input :tva_intra, :label => "TVA intra. :" - = form.input :website, :label => "Site Web :" - .qi_row @@ -77,21 +72,30 @@ .qi_row .qi_pannel.qi_plain.padding - %h4 Paiements - .row.qi_cancel_margins - .col-sm-4 - = form.input :comptant, :label => "Paiement comptant nécessaire ?" + = form.input :siret, :label => "Siret :" + = form.input :ape, :label => "Ape :" + = form.input :tva_intra, :label => "TVA intra. :" + = form.input :website, :label => "Site Web :" - -if false - = form.input :acompte, :label => "Acompte nécessaire ?" - = form.input :acompte_percent, :label => "Pourcentage d'acompte :" - .col-sm-4 - = form.input :payment_delais, :label => "Délais jour de paiement :" - - = form.input :payment_fin_de_mois, :label => "Fin de mois ?" + .qi_row + .qi_pannel.qi_plain.padding - .col-sm-4 - = form.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"} + -if true + %h4 Paiements + .row.qi_cancel_margins + .col-sm-4 + = form.input :comptant, :label => "Paiement comptant nécessaire ?" + + -if false + = form.input :acompte, :label => "Acompte nécessaire ?" + = form.input :acompte_percent, :label => "Pourcentage d'acompte :" + .col-sm-4 + = form.input :payment_delais, :label => "Délais jour de paiement :" + + = form.input :payment_fin_de_mois, :label => "Fin de mois ?" + + .col-sm-4 + = form.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"} diff --git a/app/views/admin/p_customers/show.html.haml b/app/views/admin/p_customers/show.html.haml index 1347685..47fc09a 100644 --- a/app/views/admin/p_customers/show.html.haml +++ b/app/views/admin/p_customers/show.html.haml @@ -62,9 +62,9 @@ .qi_row#tabs .qi_pannel %ul.nav.nav-tabs - -params[:tab] = params[:tab] || "projets" + -params[:tab] = params[:tab] || "offres" - %li{:class => ("active" if params[:tab] == "projets")}=link_to "Projets", "?tab=projets#tabs" + %li{:class => ("active" if params[:tab] == "offres")}=link_to "Offres", "?tab=offres#tabs" -if false %li{:class => ("active" if params[:tab] == "etat")}=link_to "Etat de compte", "?tab=etat#tabs" @@ -74,13 +74,13 @@ %li{:class => ("active" if params[:tab] == "payments")}=link_to "Paiements", "?tab=payments#tabs" .qi_tab_content - -if params[:tab] == "projets" + -if params[:tab] == "offres" #offres .qi_tab_header .right{:style => "text-align:right;"} -if @p_customer.enabled - =#link_to ic(:plus)+" Demande de commande", new_admin_s_project_path(:p_customer_id => @p_customer.id), :class => "btn btn-primary btn-ap-add" + =link_to ic(:plus)+" Nouvelle offre", new_admin_p_customer_sheet_path(:p_customer_id => @p_customer.id), :class => "btn btn-primary btn-ap-add" @@ -91,11 +91,11 @@ -params[:search][:per_page] = params[:search][:per_page] || 50 -per_page = params[:search][:per_page] -page = (params[:page] and params[:page] != "") ? params[:page] : 1 - -@s_projects =@p_customer.s_projects - -@s_projects = sort_by_sorting(@s_projects, "created_at DESC") - -@s_projects = @s_projects.page(page).per(per_page) + -@p_customer_sheets =@p_customer.p_customer_sheets + -@p_customer_sheets = sort_by_sorting(@p_customer_sheets, "created_at DESC") + -@p_customer_sheets = @p_customer_sheets.page(page).per(per_page) - =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @s_projects} + =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_customer_sheets} diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index 9809025..e3d8997 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -63,7 +63,6 @@ p_customer_id: $(".p_customer_id").val() }, success: function (data) { - alert(data.p_product_cat_id); 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_p_product_cat_id").val(data.p_product_cat_id); diff --git a/db/migrate/20201109142527_add_code_index_to_p_customers.rb b/db/migrate/20201109142527_add_code_index_to_p_customers.rb new file mode 100644 index 0000000..986046a --- /dev/null +++ b/db/migrate/20201109142527_add_code_index_to_p_customers.rb @@ -0,0 +1,5 @@ +class AddCodeIndexToPCustomers < ActiveRecord::Migration[6.0] + def change + add_column :p_customers, :code_index, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 8d94aa3..9abc397 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: 2020_05_25_113631) do +ActiveRecord::Schema.define(version: 2020_11_09_142527) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -978,6 +978,7 @@ ActiveRecord::Schema.define(version: 2020_05_25_113631) do t.string "nav_vat_bus_posting_group" t.string "nav_primary_contact_no" t.datetime "nav_last_date_modified" + t.integer "code_index" t.index ["market_discount_id"], name: "index_p_customers_on_market_discount_id" t.index ["p_customer_cat_id"], name: "index_p_customers_on_p_customer_cat_id" t.index ["particular_id"], name: "index_p_customers_on_particular_id"