suite
This commit is contained in:
parent
7a1ea4f4c1
commit
91722c7262
@ -11,7 +11,7 @@ class Admin::MOdrPrimesController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@m_odr_primes = MOdrPrime.all
|
||||
@m_odr_primes = MOdrPrime.joins(:p_customer).all
|
||||
|
||||
@m_odr_primes = sort_by_sorting(@m_odr_primes, "id DESC")
|
||||
respond_to do |format|
|
||||
|
@ -59,7 +59,7 @@ class Circuit < ApplicationRecord
|
||||
|
||||
|
||||
before_save do
|
||||
self.slug = "#{self.name} #{self.cp} #{self.city}".to_slug if !self.slug
|
||||
self.slug = "#{self.name} #{self.cp} #{self.city}".to_slug if !self.slug?
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -15,37 +15,41 @@ class MOdrFileRoulage < ApplicationRecord
|
||||
|
||||
def generate_prime
|
||||
prime_ids = []
|
||||
if nbr_primes_to_use = self.nbr_primes_not_useds and nbr_primes_to_use > 0
|
||||
|
||||
if self.m_odr_file.p_customer.m_odr_primes.where("created_at > ?", Date.today.beginning_of_year).count < 5
|
||||
|
||||
if nbr_primes_to_use = self.nbr_primes_not_useds and nbr_primes_to_use > 0
|
||||
|
||||
|
||||
if achats = MOdrFile.where(:admin_ok => true, :p_customer_id => self.m_odr_file.p_customer_id,:m_odr_file_type_id => 2).where("buy_at <= ? and nbr_pneus_not_useds > 0", self.date) and (achats.sum(:nbr_pneus_not_useds) > 0)
|
||||
if achats = MOdrFile.where(:admin_ok => true, :p_customer_id => self.m_odr_file.p_customer_id,:m_odr_file_type_id => 2).where("buy_at <= ? and nbr_pneus_not_useds > 0", self.date) and (achats.sum(:nbr_pneus_not_useds) > 0)
|
||||
|
||||
state = "A traiter"
|
||||
state = "A traiter"
|
||||
|
||||
prime = MOdrPrime.new(:state => state, :m_odr_file_roulage => self, :p_customer_id => self.m_odr_file.p_customer_id)
|
||||
n_tot = 0
|
||||
achats.each do |a|
|
||||
if n_tot < nbr_primes_to_use
|
||||
if (nbr_primes_to_use - n_tot) <= a.nbr_pneus_not_useds
|
||||
n = (nbr_primes_to_use - n_tot)
|
||||
prime = MOdrPrime.new(:state => state, :m_odr_file_roulage => self, :p_customer_id => self.m_odr_file.p_customer_id)
|
||||
n_tot = 0
|
||||
achats.each do |a|
|
||||
if n_tot < nbr_primes_to_use
|
||||
if (nbr_primes_to_use - n_tot) <= a.nbr_pneus_not_useds
|
||||
n = (nbr_primes_to_use - n_tot)
|
||||
|
||||
else
|
||||
n = a.nbr_pneus_not_useds
|
||||
else
|
||||
n = a.nbr_pneus_not_useds
|
||||
end
|
||||
|
||||
prime.m_odr_prime_files.build(:m_odr_file => a, :nbr_pneus => n, :amount => n*15.0)
|
||||
|
||||
a.nbr_pneus_useds = a.nbr_pneus_useds.to_i + n
|
||||
|
||||
prime.save
|
||||
a.save
|
||||
|
||||
prime_ids << prime.id
|
||||
|
||||
n_tot = n_tot + n
|
||||
|
||||
self.nbr_primes_useds = self.nbr_primes_useds.to_i + n
|
||||
self.save
|
||||
end
|
||||
|
||||
prime.m_odr_prime_files.build(:m_odr_file => a, :nbr_pneus => n, :amount => n*15.0)
|
||||
|
||||
a.nbr_pneus_useds = a.nbr_pneus_useds.to_i + n
|
||||
|
||||
prime.save
|
||||
a.save
|
||||
|
||||
prime_ids << prime.id
|
||||
|
||||
n_tot = n_tot + n
|
||||
|
||||
self.nbr_primes_useds = self.nbr_primes_useds.to_i + n
|
||||
self.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,12 +14,15 @@ class MOdrPrime < ApplicationRecord
|
||||
|
||||
acts_as_sorting :fields => {
|
||||
:id => {:name => "Id", :reorder => true},
|
||||
:p_customer => {:name => "Client"},
|
||||
:p_customer => {:name => "Client", :reorder => true, :sort_name => "p_customers.cc_show_name"},
|
||||
:state => {:name => "Statut", :reorder => true},
|
||||
:amount => {:name => "Montant"},
|
||||
:actions => {:name => "Actions", :reorder => true},
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
before_validation do
|
||||
|
||||
|
@ -43,7 +43,7 @@ class Organisateur < ApplicationRecord
|
||||
end
|
||||
|
||||
before_save do
|
||||
self.slug = "#{self.name} #{self.cp} #{self.city}".to_slug if !self.slug
|
||||
self.slug = "#{self.name} #{self.cp} #{self.city}".to_slug if !self.slug?
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -73,6 +73,9 @@ class PCustomer < ApplicationRecord
|
||||
|
||||
validates :past_id, :uniqueness => true, :if => :imported
|
||||
|
||||
acts_as_caching :fields => [:show_name]
|
||||
|
||||
|
||||
attr_accessor :refresh_import
|
||||
|
||||
def do_import
|
||||
@ -249,7 +252,7 @@ class PCustomer < ApplicationRecord
|
||||
def self.qi_table_order
|
||||
{
|
||||
:created_at => {:name => "Date de création", :reorder => true, :as => :date},
|
||||
:show_name => "Nom",
|
||||
:cc_show_name => {:name => "Nom", :reorder => true},
|
||||
:mlm_token => {:name => "Code ambassadeur", :reorder => true},
|
||||
:enabled => "Actif ?",
|
||||
:parent => "Ambassadeur",
|
||||
@ -262,7 +265,7 @@ class PCustomer < ApplicationRecord
|
||||
|
||||
def self.valid_sort
|
||||
|
||||
["code", "created_at", "cache_encours_th", "cache_encours", "cache_payments_th", "cache_payments", "cache_payments_tot", "cache_ca"]
|
||||
["code", "cc_show_name", "created_at", "cache_encours_th", "cache_encours", "cache_payments_th", "cache_payments", "cache_payments_tot", "cache_ca"]
|
||||
|
||||
end
|
||||
|
||||
@ -470,7 +473,7 @@ class PCustomer < ApplicationRecord
|
||||
end
|
||||
|
||||
|
||||
def show_name
|
||||
def ca_show_name
|
||||
if self.particular
|
||||
n = ""
|
||||
n += self.particular.organisation+" " if self.particular.organisation?
|
||||
|
@ -105,6 +105,19 @@
|
||||
-@mail_hists = @mail_hists.page(page).per(per_page)
|
||||
|
||||
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @mail_hists}
|
||||
|
||||
|
||||
%hr
|
||||
Dernières primes versées au client
|
||||
|
||||
-params[:search][:per_page] = params[:search][:per_page] || 50
|
||||
-per_page = params[:search][:per_page]
|
||||
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
|
||||
-@m_odr_primes = @m_odr_prime.p_customer.m_odr_primes.where("id != ? ", @m_odr_prime.id)
|
||||
-@m_odr_primes = sort_by_sorting(@m_odr_primes, "created_at DESC")
|
||||
-@m_odr_primes = @m_odr_primes.page(page).per(per_page)
|
||||
|
||||
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @m_odr_primes}
|
||||
|
||||
|
||||
|
||||
|
11
db/migrate/20200715113020_add_name_cache_to_p_customers.rb
Normal file
11
db/migrate/20200715113020_add_name_cache_to_p_customers.rb
Normal file
@ -0,0 +1,11 @@
|
||||
class AddNameCacheToPCustomers < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :p_customers, :cc_show_name, :string
|
||||
add_column :p_customers, :ac_show_name, :string
|
||||
|
||||
PCustomer.all.each do |pc|
|
||||
pc.save
|
||||
end
|
||||
|
||||
end
|
||||
end
|
348
db/schema.rb
348
db/schema.rb
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user