This commit is contained in:
Nicolas Bally 2020-03-19 23:10:02 +01:00
parent 0b9daf14b2
commit 1b60863a55
9 changed files with 132 additions and 124 deletions

View File

@ -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 >= ?", @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("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 != "" if params[:search][:state].to_s != ""
@p_customer_sheets = @p_customer_sheets.where(:state => params[:search][:state]) @p_customer_sheets = @p_customer_sheets.where(:state => params[:search][:state])

View File

@ -30,11 +30,10 @@ class Admin::PCustomersController < ApplicationController
def index def index
@p_customers = PCustomer.order("created_at DESC").all @p_customers = PCustomer.order("created_at DESC").all
@fav_p_customers = PCustomer.where(:fav => true).order(:name).all if params[:search][:name].to_s != ""
@p_customers = @p_customers.for_search(params[:search][:name])
if params[:search].to_s != ""
@p_customers = @p_customers.for_search(params[:search])
end end
per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 50 per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 50

View File

@ -31,6 +31,25 @@ class PCustomer < ActiveRecord::Base
has_many :mail_histories 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 attr_accessor :valid_public, :generate_mdp, :valid_siren
before_validation do before_validation do
self.generate_token if !self.token? and self.email? self.generate_token if !self.token? and self.email?

View File

@ -2,7 +2,7 @@
class PCustomerSheet < ActiveRecord::Base 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 => { acts_as_sorting :fields => {
:id => {:name => "ID", :reorder => true}, :id => {:name => "ID", :reorder => true},
@ -34,6 +34,9 @@ class PCustomerSheet < ActiveRecord::Base
end end
def ca_p_sheet_line_count
self.p_sheet_lines.count
end
has_many :p_documents, :as => :element has_many :p_documents, :as => :element

View File

@ -1,45 +1,44 @@
-totals = PSheetLine.totals(p_customer_sheet.p_sheet_lines) -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#p_customer_sheet{:id => p_customer_sheet.id} -tr = {}
-tr = {}
-tr[:id] = capture do -tr[:id] = capture do
%td="##{p_customer_sheet.id}" %td="##{p_customer_sheet.id}"
-tr[:created_at] = capture do -tr[:created_at] = capture do
%td=l p_customer_sheet.created_at, :format => :date %td=l p_customer_sheet.created_at, :format => :date
-tr[:customer_validation_at] = capture do -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 %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[:state] = capture do -tr[:p_customer] = capture do
%td %td= p_customer_sheet.p_customer.show_name if p_customer_sheet.p_customer
=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
=render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_customer_sheet} -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}

View File

@ -1,43 +1,47 @@
%tr#p_customer{:id => p_customer.id, :class => ("table-warning" if !p_customer.account_validated)} %tr#p_customer{:id => p_customer.id, :class => ("table-warning" if !p_customer.account_validated)}
%td= p_customer.email -tr = {}
%td= p_customer.code
%td= p_customer.show_name
%td= p_customer.particular.cp if p_customer.particular -tr[:particular_cp] = capture do
%td= p_customer.particular.city if p_customer.particular %td= p_customer.particular.cp 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
-p_customer.particulars.each do |p| -tr[:particular_city] = capture do
-p_contacts = p_contacts + p.p_contacts %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
-tr[:actions] = capture do
%td.actions %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(:"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(:pencil), edit_admin_p_customer_path(p_customer), :remote => true
= link_to i(:eye), admin_p_customer_path(p_customer) = link_to i(:eye), admin_p_customer_path(p_customer)
=render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => p_customer}

View File

@ -5,59 +5,27 @@
%span %span
Clients 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_search_row
.qi_pannel.qi_plain.padding =form_tag "", :method => "get", :onsubmit => "" do
-params[:search] =params[:search] || {}
=form_tag "", :method => "get", :onsubmit => "" do
%table
=text_field_tag :search, params[:search],:class => "form-control", :placeholder => "Rechercher"
=submit_tag "Recherche", :class => "btn btn-default", :style => "margin-bottom: 10px;"
%table.table
%tr %tr
%th Email %td Nom :
%th Code %td=text_field_tag "search[name]", params[:search][:name],:class => "form-control"
%th Nom
%th CP
%th Ville
%th Encours =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @p_customers}
%th Nbr emails
%th
=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

View File

@ -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

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "admin_admin_roles", force: :cascade do |t|
t.integer "admin_id", limit: 4 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 "cc_total_ttc", precision: 14, scale: 2
t.decimal "ac_total_ttc", precision: 14, scale: 2 t.decimal "ac_total_ttc", precision: 14, scale: 2
t.boolean "archived", default: false t.boolean "archived", default: false
t.integer "cc_p_sheet_line_count", limit: 4
t.integer "ac_p_sheet_line_count", limit: 4
end end
add_index "p_customer_sheets", ["p_payment_type_id"], name: "index_p_customer_sheets_on_p_payment_type_id", using: :btree add_index "p_customer_sheets", ["p_payment_type_id"], name: "index_p_customer_sheets_on_p_payment_type_id", using: :btree