diff --git a/app/controllers/admin/p_stats_controller.rb b/app/controllers/admin/p_stats_controller.rb index 83d1edd..b93afbb 100644 --- a/app/controllers/admin/p_stats_controller.rb +++ b/app/controllers/admin/p_stats_controller.rb @@ -56,7 +56,8 @@ class Admin::PStatsController < ApplicationController @m_odr_primes = MOdrPrime.where("m_odr_primes.created_at >= ? and m_odr_primes.created_at < ?",@start.beginning_of_year, @stop).where(:state => ["Virement envoyé"]) @m_odr_primes = @m_odr_primes.joins(:p_customer) @m_odr_primes = @m_odr_primes.where("m_odr_primes.created_at >= ?", @start) - @m_odr_primes = sort_by_sorting(@m_odr_primes, "m_odr_primes.created_at DESC") + @m_odr_primes = sort_by_sorting(@m_odr_primes, "m_odr_primes.cc_virement_date DESC") + @all_m_odr_primes = @m_odr_primes @m_odr_primes = @m_odr_primes.page(page).per(per_page) diff --git a/app/models/m_odr_prime.rb b/app/models/m_odr_prime.rb index 5a191fb..11a3631 100644 --- a/app/models/m_odr_prime.rb +++ b/app/models/m_odr_prime.rb @@ -55,11 +55,22 @@ class MOdrPrime < ApplicationRecord :date_roulage => {:name => "Date de roulage", :reorder => true, :sort_name => "m_odr_file_roulages.date"}, :state => {:name => "Statut", :reorder => true}, - :date_virement => {:name => "Date de virement"}, + #:date_virement => {:name => "Date de virement"}, + :cc_virement_date => {:name => "Date de virement", :reorder => true}, :actions => {:name => "Actions", :reorder => true}, } + acts_as_caching :fields => [:virement_date] + + def ca_virement_date + virement = self.m_odr_virements.where(:refused => 0, :sended => 1).order('id DESC').first + if virement and virement.m_odr_remise + virement.m_odr_remise.created_at + else + nil + end + end diff --git a/app/views/admin/p_stats/index.html.haml b/app/views/admin/p_stats/index.html.haml index ccaa82b..e5eb936 100644 --- a/app/views/admin/p_stats/index.html.haml +++ b/app/views/admin/p_stats/index.html.haml @@ -93,19 +93,19 @@ %th Primes %td - =@m_odr_primes.count + =@all_m_odr_primes.count %td - =number_to_currency @m_odr_primes.sum(:amount) + =number_to_currency @all_m_odr_primes.sum(:amount) %td - = @m_odr_primes.sum(:nbr_pneus) + = @all_m_odr_primes.sum(:nbr_pneus) %br %br - =link_to "Export CSV", params.permit!.merge({:format => :csv}) + =link_to "Export Excel", params.permit!.merge({:format => :csv}) =#debug MailHist.qi_ordered_table_name =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @m_odr_primes} diff --git a/db/migrate/20210701095917_add_ccv_to_m_odr_primes.rb b/db/migrate/20210701095917_add_ccv_to_m_odr_primes.rb new file mode 100644 index 0000000..c975fc7 --- /dev/null +++ b/db/migrate/20210701095917_add_ccv_to_m_odr_primes.rb @@ -0,0 +1,10 @@ +class AddCcvToMOdrPrimes < ActiveRecord::Migration[6.0] + def change + add_column :m_odr_primes, :cc_virement_date, :date + add_column :m_odr_primes, :ac_virement_date, :date + + MOdrPrime.all.each do |mop| + mop.save + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e233e2d..6855ef4 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_02_09_153303) do +ActiveRecord::Schema.define(version: 2021_07_01_095917) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -834,6 +834,8 @@ ActiveRecord::Schema.define(version: 2021_02_09_153303) do t.decimal "amount", precision: 14, scale: 2 t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.date "cc_virement_date" + t.date "ac_virement_date" t.index ["m_odr_file_roulage_id"], name: "index_m_odr_primes_on_m_odr_file_roulage_id" t.index ["p_customer_id"], name: "index_m_odr_primes_on_p_customer_id" end @@ -1743,6 +1745,10 @@ ActiveRecord::Schema.define(version: 2021_02_09_153303) do t.string "ac_particular_name" t.string "cc_particular_firstname" t.string "ac_particular_firstname" + t.integer "link_token_count" + t.boolean "unlimited", default: false + t.string "import_name" + t.datetime "import_date" 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"