This commit is contained in:
Nicolas Bally 2020-07-23 12:41:50 +02:00
parent f4ccdc82dc
commit 71350f9b8c
5 changed files with 124 additions and 181 deletions

View File

@ -23,7 +23,7 @@ class Admin::PStatsController < ApplicationController
@start = Date.parse(params[:start]).beginning_of_day
else
@start = Date.today.beginning_of_month
@start = Date.parse("2000-01-01")
end
params[:start]= @start.strftime('%d/%m/%Y')

View File

@ -8,24 +8,57 @@ class MOdrPrime < ApplicationRecord
include ActionView::Helpers::TranslationHelper
include ActionView::Helpers::UrlHelper
has_many :m_odr_prime_files #, :dependent => :destroy
has_many :m_odr_files, :through => :m_odr_prime_files
has_many :m_odr_places, :through => :m_odr_files
has_many :m_odr_file_products, :through => :m_odr_files
has_many :m_odr_products, :through => :m_odr_file_products
has_many :mail_hists
has_many :m_odr_virements
acts_as_sorting :fields => {
:id => {:name => "Id", :reorder => true},
:p_customer => {:name => "Client", :reorder => true, :sort_name => "p_customers.cc_show_name"},
#:p_customer => {:name => "Client", :reorder => true, :sort_name => "p_customers.cc_show_name"},
:p_customer_created_at => {:name => "Inscription", :reorder => true, :sort_name => "p_customers.created_at"},
:particular_name => {:name => "Nom", :reorder => true, :sort_name => "particulars.name"},
:particular_firstname => {:name => "Prénom", :reorder => true, :sort_name => "particulars.firstname"},
:amount => {:name => "Montant", :as => :currency},
:created_at => {:name => "Date"},
:pneu_gamme => {:name => "Gamme"},
#:pneu_tailles => {:name => "Tailles"},
:m_odr_place_name => {:name => "Nom"},
:m_odr_place_cp=> {:name => "CP"},
:m_odr_place_city => {:name => "Nom"},
:organisateur_name => {:name => "Organisateur"},
:date_roulage => {:name => "Date de roulage", :reorder => true, :sort_name => "m_odr_file_roulages.date"},
:state => {:name => "Statut", :reorder => true},
:amount => {:name => "Montant"},
:actions => {:name => "Actions", :reorder => true},
}
before_validation do

View File

@ -1,9 +1,18 @@
%tr#m_odr_prime_row{:id => m_odr_prime.id}
-tr = {}
-tr[:p_customer] = capture do
-tr[:particular_name] = capture do
%td
=link_to m_odr_prime.p_customer.show_name, [:admin, m_odr_prime.p_customer] if m_odr_prime.p_customer
=link_to m_odr_prime.particular.name, [:admin, m_odr_prime.p_customer] if m_odr_prime.particular
-tr[:particular_firstname] = capture do
%td
=link_to m_odr_prime.particular.firstname, [:admin, m_odr_prime.p_customer] if m_odr_prime.particular
-tr[:p_customer_created_at] = capture do
%td
=l m_odr_prime.p_customer.created_at if m_odr_prime.p_customer
-tr[:state] = capture do
%td
@ -14,6 +23,31 @@
=l m_odr_prime.m_odr_file_roulage.date if m_odr_prime.m_odr_file_roulage
-tr[:pneu_gamme] = capture do
%td
=m_odr_prime.m_odr_products.uniq.map{ |u| (u.name)}.join(" | ")
-tr[:m_odr_place_name] = capture do
%td
=m_odr_prime.m_odr_places.uniq.map{ |u| u.name}.join(" | ")
-tr[:m_odr_place_cp] = capture do
%td
=m_odr_prime.m_odr_places.uniq.map{ |u| u.cp}.join(" | ")
-tr[:m_odr_place_city] = capture do
%td
=m_odr_prime.m_odr_places.uniq.map{ |u| u.city}.join(" | ")
-tr[:organisateur_name] = capture do
%td
=m_odr_prime.m_odr_file_roulage.m_event.organisateur.name if m_odr_prime.m_odr_file_roulage and m_odr_prime.m_odr_file_roulage.m_event and m_odr_prime.m_odr_file_roulage.m_event.organisateur
-tr[:actions] = capture do

View File

@ -45,184 +45,60 @@
-if @start and @stop
=link_to "Mois suivant >","?start=#{CGI.escape((@start + 1.month).beginning_of_month.strftime('%d/%m/%Y'))}&stop=#{CGI.escape((@stop + 1.month).end_of_month.strftime('%d/%m/%Y'))}", :class => "btn btn-default"
%p
-if @start and @stop
=link_to "< Année précédente","?start=#{CGI.escape((@start - 1.year).beginning_of_month.strftime('%d/%m/%Y'))}&stop=#{CGI.escape((@stop - 1.year).end_of_month.strftime('%d/%m/%Y'))}", :class => "btn btn-default"
-if @start and @stop
=link_to "Année suivante >","?start=#{CGI.escape((@start + 1.year).beginning_of_month.strftime('%d/%m/%Y'))}&stop=#{CGI.escape((@stop + 1.year).end_of_month.strftime('%d/%m/%Y'))}", :class => "btn btn-default"
%hr
-@m_odr_primes = MOdrPrime.where("created_at >= ? and created_at < ?",@start.beginning_of_year, @stop).where(:state => ["Virement envoyé"])
%h2
=#raw("#{l(@start_at, :format => '%B %Y')}")
%table.table
%table.table.table-stripped
%tr
%td{:style => "width:50%;"}
=l @start
%td{:style => "width:50%;"}
=l @stop
%p
Nombre de commandes finalisées :
=orders_ok = @finished.count
-if false
%table
%th
%th Nombre
%th Montant
%th Nbr pneus
%tr
%th Motards
%td
=PCustomer.where(:test_user => false, :enabled => true).where("created_at < ?", @stop).count
%td
%td
%tr
%th Organisateurs
%td
=Organisateur.where("created_at < ?", @stop).count
%td
%td
%tr
%th Circuits
%td
=Circuit.where("created_at < ?", @stop).count
%td
%td
%tr
%th Dates
%td
-r = 0
-MEvent.where("start_at >= ? and start_at < ? and created_at >= ? and created_at < ?",@start.beginning_of_year, @stop.end_of_year, @start.beginning_of_year, @stop).all.each do |m_event|
-r+=(m_event.end_at - m_event.start_at ).to_i / (24 * 60 * 60) +1
=r
%td
%td
%tr
%th
Primes
%td
=@m_odr_primes.count
%td
=number_to_currency @m_odr_primes.sum(:amount)
%td
= @m_odr_primes.sum(:nbr_pneus)
-@finished.each do |ps|
%tr
%td
=ps.a_ok_total
%td
=ps.a_total_cost_ok
%br
%strong=number_to_percentage ((@finished.count*100)/@p_customer_sheets.count), :precision => 2 if @p_customer_sheets.count > 0
%p
Nombre de commandes non finalisées :
=orders_not_ok = (@p_customer_sheets.count - @finished.count)
%p
CA HT :
%strong=number_to_currency @finished.sum(:a_ok_total)
-if @sans_marges.count > 0
%p{:style => "color:red;"}
Attention : le calcul des marges est faussé car certaines factures fournisseurs semblent ne pas être saisies, et donc certaines commandes n'ont pas pu être attribuées.
%p
Coût estimé HT :
-cout = @finished.sum(:a_total_cost_ok)
%strong=number_to_currency cout
%p
Marge estimée HT :
-marge = @finished.sum(:a_ok_total) - @finished.sum(:a_total_cost_ok)
%strong=number_to_currency(marge)
%br
%strong=number_to_percentage ((@finished.sum(:a_ok_total) - @finished.sum(:a_total_cost_ok))/@finished.sum(:a_ok_total)*100), :precision => 2 if @finished.sum(:a_ok_total) > 0.0
%div{:style => "width:350px;display:inline-block;"}
<canvas id="ordersChart" width="400" height="400"></canvas>
:javascript
var myPieChart = new Chart("ordersChart",{
type: 'pie',
data: {
labels: ["Finalisées", "Non finalisées"],
datasets: [{
label: '# of Votes',
data: [#{orders_ok},#{orders_not_ok}],
backgroundColor: [
'#4BC0C0',
'#FF6384',
],
borderColor: [
'white',
'white',
],
borderWidth: 2
}]
},
options: {
title: {
display: true,
text: 'Finalisation des commandes'
}
}
// options: options
});
%div{:style => "width:350px;display:inline-block;"}
<canvas id="margeChart" width="400" height="400"></canvas>
:javascript
var myPieChart = new Chart("margeChart",{
type: 'pie',
data: {
labels: ["Marge", "Cout"],
datasets: [{
label: '# of Votes',
data: [#{marge},#{cout}],
backgroundColor: [
'#4BC0C0',
'#FF6384',
],
borderColor: [
'white',
'white',
],
borderWidth: 2
}]
},
options: {
title: {
display: true,
text: 'Marges'
}
}
// options: options
});
-if false
<canvas id="myChart" width="400" height="200"></canvas>
:javascript
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 0
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});

View File

@ -86,7 +86,7 @@
Tunnels fichier sécurisés
-if false
-if current_admin.has_permission?("statistiques")
.element
=link_to admin_p_stats_path do
.cat#big_cat_statistiques