From 1b60863a55d275100ebac5ad3620d70111a0fdd1 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Thu, 19 Mar 2020 23:10:02 +0100 Subject: [PATCH] suite --- .../admin/p_customer_sheets_controller.rb | 3 + .../admin/p_customers_controller.rb | 7 +- app/models/p_customer.rb | 19 +++++ app/models/p_customer_sheet.rb | 5 +- .../_p_customer_sheet.html.haml | 79 +++++++++---------- .../admin/p_customers/_p_customer.html.haml | 66 ++++++++-------- app/views/admin/p_customers/index.html.haml | 62 ++++----------- ...19215725_add_cache_to_p_customer_sheets.rb | 11 +++ db/schema.rb | 4 +- 9 files changed, 132 insertions(+), 124 deletions(-) create mode 100644 db/migrate/20200319215725_add_cache_to_p_customer_sheets.rb diff --git a/app/controllers/admin/p_customer_sheets_controller.rb b/app/controllers/admin/p_customer_sheets_controller.rb index 77ce8fe..f206c55 100644 --- a/app/controllers/admin/p_customer_sheets_controller.rb +++ b/app/controllers/admin/p_customer_sheets_controller.rb @@ -53,6 +53,9 @@ class Admin::PCustomerSheetsController < ApplicationController @p_customer_sheets = @p_customer_sheets.where("p_customer_sheets.created_at >= ?", @start) if @start @p_customer_sheets = @p_customer_sheets.where("p_customer_sheets.created_at <= ?", @stop.end_of_day) if @stop + + @p_customer_sheets = @p_customer_sheets.where("state != 'panier' or cc_p_sheet_line_count > 0") + if params[:search][:state].to_s != "" @p_customer_sheets = @p_customer_sheets.where(:state => params[:search][:state]) diff --git a/app/controllers/admin/p_customers_controller.rb b/app/controllers/admin/p_customers_controller.rb index 5151ba5..911a134 100644 --- a/app/controllers/admin/p_customers_controller.rb +++ b/app/controllers/admin/p_customers_controller.rb @@ -30,11 +30,10 @@ class Admin::PCustomersController < ApplicationController def index @p_customers = PCustomer.order("created_at DESC").all + - @fav_p_customers = PCustomer.where(:fav => true).order(:name).all - - if params[:search].to_s != "" - @p_customers = @p_customers.for_search(params[:search]) + if params[:search][:name].to_s != "" + @p_customers = @p_customers.for_search(params[:search][:name]) end per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 50 diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index 5d2cd6f..8a6a5bf 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -31,6 +31,25 @@ class PCustomer < ActiveRecord::Base has_many :mail_histories + + #acts_as_caching :fields => [:total_ht, :total_tva, :total_ttc] + + + acts_as_sorting :fields => { + + #:code => {:name => "Code", :reorder => true}, + :show_name => {:name => "Nom", :reorder => false}, + :particular_cp => {:name => "CP", :reorder => false}, + :particular_city => {:name => "Ville", :reorder => true}, + :email => {:name => "Email", :reorder => true}, + :cache_encours => {:name => "Encours", :reorder => true}, + :emails => {:name => "Nbr emails", :reorder => true}, + :actions => {:name => "Actions", :reorder => false} + } + + + + attr_accessor :valid_public, :generate_mdp, :valid_siren before_validation do self.generate_token if !self.token? and self.email? diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb index 463dea7..a586139 100644 --- a/app/models/p_customer_sheet.rb +++ b/app/models/p_customer_sheet.rb @@ -2,7 +2,7 @@ class PCustomerSheet < ActiveRecord::Base - acts_as_caching :fields => [:total_ht, :total_tva, :total_ttc] + acts_as_caching :fields => [:total_ht, :total_tva, :total_ttc, :p_sheet_line_count] acts_as_sorting :fields => { :id => {:name => "ID", :reorder => true}, @@ -34,6 +34,9 @@ class PCustomerSheet < ActiveRecord::Base end + def ca_p_sheet_line_count + self.p_sheet_lines.count + end has_many :p_documents, :as => :element 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 ef33838..a2fea9f 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 @@ -1,45 +1,44 @@ -totals = PSheetLine.totals(p_customer_sheet.p_sheet_lines) --if (p_customer_sheet.state != "panier" or p_customer_sheet.p_sheet_lines.count > 0) - %tr#p_customer_sheet{:id => p_customer_sheet.id} - -tr = {} +%tr#p_customer_sheet{:id => p_customer_sheet.id} + -tr = {} - -tr[:id] = capture do - %td="##{p_customer_sheet.id}" - -tr[:created_at] = capture do - %td=l p_customer_sheet.created_at, :format => :date - -tr[:customer_validation_at] = capture do - %td=l p_customer_sheet.customer_validation_at, :format => "%d/%m/%Y %H:%M" if p_customer_sheet.customer_validation_at - - -tr[:p_customer] = capture do - %td= p_customer_sheet.p_customer.show_name if p_customer_sheet.p_customer - - -tr[:cc_total_ht] = capture do - %td.numeraire - =number_to_currency p_customer_sheet.cc_total_ht - -tr[:cc_total_tva] = capture do - %td.numeraire - =number_to_currency p_customer_sheet.cc_total_tva - - - -tr[:cc_total_ttc] = capture do - %td.numeraire - =number_to_currency p_customer_sheet.cc_total_ttc + -tr[:id] = capture do + %td="##{p_customer_sheet.id}" + -tr[:created_at] = capture do + %td=l p_customer_sheet.created_at, :format => :date + -tr[:customer_validation_at] = capture do + %td=l p_customer_sheet.customer_validation_at, :format => "%d/%m/%Y %H:%M" if p_customer_sheet.customer_validation_at - -tr[:state] = capture do - %td - =raw p_customer_sheet.state_html - - -tr[:actions] = capture do - %td.actions - - - =link_to i(:copy), dup_admin_p_customer_sheet_path(p_customer_sheet), :data => {:confirm => 'Voulez-vous vraiment dupliquer cette commande ?'} - - -if p_customer_sheet.state == "brouillon" - = link_to i(:"trash-o"), [:admin, p_customer_sheet], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet auteur ? ' } , :remote => true - = link_to i(:pencil), edit_admin_p_customer_sheet_path(p_customer_sheet), :remote => false - = link_to i(:eye), admin_p_customer_sheet_path(p_customer_sheet), :remote => false - + -tr[:p_customer] = capture do + %td= p_customer_sheet.p_customer.show_name if p_customer_sheet.p_customer - =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_customer_sheet} \ No newline at end of file + -tr[:cc_total_ht] = capture do + %td.numeraire + =number_to_currency p_customer_sheet.cc_total_ht + -tr[:cc_total_tva] = capture do + %td.numeraire + =number_to_currency p_customer_sheet.cc_total_tva + + + -tr[:cc_total_ttc] = capture do + %td.numeraire + =number_to_currency p_customer_sheet.cc_total_ttc + + -tr[:state] = capture do + %td + =raw p_customer_sheet.state_html + + -tr[:actions] = capture do + %td.actions + + + =link_to i(:copy), dup_admin_p_customer_sheet_path(p_customer_sheet), :data => {:confirm => 'Voulez-vous vraiment dupliquer cette commande ?'} + + -if p_customer_sheet.state == "brouillon" + = link_to i(:"trash-o"), [:admin, p_customer_sheet], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cette offre ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_customer_sheet_path(p_customer_sheet), :remote => false + = link_to i(:eye), admin_p_customer_sheet_path(p_customer_sheet), :remote => false + + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_customer_sheet} \ No newline at end of file diff --git a/app/views/admin/p_customers/_p_customer.html.haml b/app/views/admin/p_customers/_p_customer.html.haml index 93ee3ab..da78a88 100644 --- a/app/views/admin/p_customers/_p_customer.html.haml +++ b/app/views/admin/p_customers/_p_customer.html.haml @@ -1,43 +1,47 @@ %tr#p_customer{:id => p_customer.id, :class => ("table-warning" if !p_customer.account_validated)} - %td= p_customer.email - %td= p_customer.code - %td= p_customer.show_name + -tr = {} + - %td= p_customer.particular.cp if p_customer.particular - %td= p_customer.particular.city if p_customer.particular - %td - -if p_customer.cache_encours < 0 - %span{:style => "color:green"}=number_to_currency p_customer.cache_encours - -elsif p_customer.cache_encours > 0 - %span=number_to_currency p_customer.cache_encours - - - -if false - %td{:style => "text-align:right;"}=number_to_currency p_customer.p_customer_sheets.sum(:a_ok_total) - %td - -emails = [] - - - -p_contacts = p_customer.p_contacts + -tr[:particular_cp] = capture do + %td= p_customer.particular.cp if p_customer.particular - -p_customer.particulars.each do |p| - -p_contacts = p_contacts + p.p_contacts + -tr[:particular_city] = capture do + %td= p_customer.particular.city if p_customer.particular + + -tr[:cache_encours] = capture do + %td + -if p_customer.cache_encours < 0 + %span{:style => "color:green"}=number_to_currency p_customer.cache_encours + -elsif p_customer.cache_encours > 0 + %span=number_to_currency p_customer.cache_encours + + -tr[:emails] = capture do + %td + -emails = [] + + + -p_contacts = p_customer.p_contacts + + -p_customer.particulars.each do |p| + -p_contacts = p_contacts + p.p_contacts - -p_contacts.uniq.each do |p_c| + -p_contacts.uniq.each do |p_c| - -emails << p_c.email + -emails << p_c.email - -emails << p_customer.email + -emails << p_customer.email - -emails = emails.uniq + -emails = emails.uniq - =emails.size + =emails.size - - %td.actions - = link_to i(:"trash-o"), [:admin, p_customer], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet auteur ? ' } , :remote => true - = link_to i(:pencil), edit_admin_p_customer_path(p_customer), :remote => true - = link_to i(:eye), admin_p_customer_path(p_customer) + -tr[:actions] = capture do + %td.actions + = link_to i(:"trash-o"), [:admin, p_customer], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet auteur ? ' } , :remote => true + = link_to i(:pencil), edit_admin_p_customer_path(p_customer), :remote => true + = link_to i(:eye), admin_p_customer_path(p_customer) + + =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_customer} diff --git a/app/views/admin/p_customers/index.html.haml b/app/views/admin/p_customers/index.html.haml index c9d40b6..0fba1b7 100644 --- a/app/views/admin/p_customers/index.html.haml +++ b/app/views/admin/p_customers/index.html.haml @@ -5,59 +5,27 @@ %span Clients - --if false and params[:search].to_s == "" and ! params[:page] - .qi_row - .qi_pannel.qi_plain.padding - - - %table.table - %tr - %th Email - %th Code - %th Nom - %th CP - %th Ville - %th Encours - %th Nbr emails - %th - - %tbody#p_customers_rows - =render @fav_p_customers - -.qi_row - .qi_pannel.qi_plain.padding - - =form_tag "", :method => "get", :onsubmit => "" do +.qi_search_row + =form_tag "", :method => "get", :onsubmit => "" do + -params[:search] =params[:search] || {} + - - =text_field_tag :search, params[:search],:class => "form-control", :placeholder => "Rechercher" - - - =submit_tag "Recherche", :class => "btn btn-default", :style => "margin-bottom: 10px;" - - - - %table.table + %table %tr - %th Email - %th Code - %th Nom - %th CP - %th Ville - %th Encours - %th Nbr emails - %th + %td Nom : + %td=text_field_tag "search[name]", params[:search][:name],:class => "form-control" + + + + =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_customers} + + +=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @p_customers} - %tbody#p_customers_rows - =render @p_customers - - - #pagination - = paginate @p_customers #, :remote => true + \ No newline at end of file diff --git a/db/migrate/20200319215725_add_cache_to_p_customer_sheets.rb b/db/migrate/20200319215725_add_cache_to_p_customer_sheets.rb new file mode 100644 index 0000000..d9f3b76 --- /dev/null +++ b/db/migrate/20200319215725_add_cache_to_p_customer_sheets.rb @@ -0,0 +1,11 @@ +class AddCacheToPCustomerSheets < ActiveRecord::Migration + def change + add_column :p_customer_sheets, :cc_p_sheet_line_count, :integer + add_column :p_customer_sheets, :ac_p_sheet_line_count, :integer + + PCustomerSheet.all.each do |pcs| + pcs.save + end + + end +end diff --git a/db/schema.rb b/db/schema.rb index cffab7f..dbaa72d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20200318223627) do +ActiveRecord::Schema.define(version: 20200319215725) do create_table "admin_admin_roles", force: :cascade do |t| t.integer "admin_id", limit: 4 @@ -871,6 +871,8 @@ ActiveRecord::Schema.define(version: 20200318223627) do t.decimal "cc_total_ttc", precision: 14, scale: 2 t.decimal "ac_total_ttc", precision: 14, scale: 2 t.boolean "archived", default: false + t.integer "cc_p_sheet_line_count", limit: 4 + t.integer "ac_p_sheet_line_count", limit: 4 end add_index "p_customer_sheets", ["p_payment_type_id"], name: "index_p_customer_sheets_on_p_payment_type_id", using: :btree