-@date = Date.parse("2019-10-01") .qi_header Sociétés détectées .qi_row .qi_pannel.qi_plain.padding %p Cartes restant à traiter : %strong =VContact.where(:enabled => true, :nbr_mvt => nil).count %h3 Stats générales .table-area %table.table.table-hover %tr %td Nombre de sociétés %td.numeraire %strong=Societe.count %tr %td Nombre de sociétés valides %td.numeraire %strong=Societe.where(:enabled => true).count %tr %td Nombre de cartes retrouvées %td.numeraire =VContact.where("codemanaginn LIKE 'CCV%'").count %tr %td Nombre de cartes appartenants à des sociétés valides %td.numeraire %strong=VContact.where("codemanaginn LIKE 'CCV%'").where(:enabled => true).count -echantillon1 = VContact.where(:enabled => true) -echantillon2 = VContact.where(:enabled => true).where("last_volume_at < ?", @date - 10.year) -echantillon3 = VContact.where(:enabled => true).where("last_volume_at < ?", @date - 5.year) -echantillon4 = VContact.where(:enabled => true).where("last_volume_at < ?", @date - 2.year) %h3 Chifres clés %table.table{:style => "width:auto;"} %tr %th %th années %th Nbr %th Primes %tr %th Sur toutes les cartes actives %td %td.numeraire= echantillon1.count %td.numeraire=number_to_currency echantillon1.sum(:prime) %tr %th Sur cartes n'ayant pas eu d'activité depuis %td.numeraire 2 ans %td.numeraire= echantillon4.count %td.numeraire=number_to_currency echantillon4.sum(:prime) %tr %th Sur cartes n'ayant pas eu d'activité depuis %td.numeraire 5 ans %td.numeraire= echantillon3.count %td.numeraire=number_to_currency echantillon3.sum(:prime) %tr %th Sur cartes n'ayant pas eu d'activité depuis %td.numeraire 10 ans %td.numeraire= echantillon2.count %td.numeraire=number_to_currency echantillon2.sum(:prime) %h3 Chifres interessants %table.table{:style => "width:auto;"} %tr %th Cartes n'ayant jamais eu de mouvement %td=VContact.where(:enabled => true, :nbr_mvt => 0).count %tr %th Cartes avec % de remise nul %td=VContact.where(:enabled => true,:ac_rate => 0.0).count %tr %th Société sans seuil de déclenchement %td=VContact.where(:enabled => true,:ac_rate => 0.0).group(:codeproprietaire).map {|a| a.codeproprietaire}.join(", ") %h3 Cartes ayant une prime négative : %table.table =render VContact.where(:enabled => true).where("prime < 0.0").order("codeproprietaire") -if false -@soc_ids = VContact.where("codemanaginn LIKE 'CCV%'").group(:codeproprietaire).map{|a| a.codeproprietaire} =@soc_ids = (@soc_ids-["", nil]) -@valid_soc_ids = Societe.where(:socmanaginn => @soc_ids).group(:socmanaginn).map{|a| a.socmanaginn} %p Date de référence : %strong =l @date %table.table %tr %td Nombre de sociétés valides %td=@valid_soc_ids.size %tr %td Nombre de sociétés invalides %td=@soc_ids.size - @valid_soc_ids.size %tr %td Nombre de cartes retrouvées %td =VContact.where("codemanaginn LIKE 'CCV%'").count %tr %td Nombre de cartes appartenants à des sociétés valides %td =VContact.where("codemanaginn LIKE 'CCV%'").where(:codeproprietaire => @valid_soc_ids).count %p Nombre de cartes non traitées : =VContact.where("codemanaginn LIKE 'CCV%' and prime is null").count %p Total des primes : -echantillon1 = VContact.where("codemanaginn LIKE 'CCV%'") -echantillon2 = VContact.where("codemanaginn LIKE 'CCV%'").where("last_volume_at < ?", @date - 10.year) -echantillon3 = VContact.where("codemanaginn LIKE 'CCV%'").where("last_volume_at < ?", @date - 5.year) -echantillon4 = VContact.where("codemanaginn LIKE 'CCV%'").where("last_volume_at < ?", @date - 2.year) %strong= VContact.where("codemanaginn LIKE 'CCV%' and prime < 0.0").sum("prime") %table.table =#render VContact.where("codemanaginn LIKE 'CCV%' and prime < 0.0") %table.table{:style => "width:auto;"} %tr %th %th années %th Nbr %th Primes %tr %th Total %td %td= echantillon1.count %td=number_to_currency echantillon1.sum(:prime) %tr %th Sur cartes n'ayant pas eu d'activité depuis %td 10 ans %td= echantillon2.count %td=number_to_currency echantillon2.sum(:prime) %tr %th Sur cartes n'ayant pas eu d'activité depuis %td 5 ans %td= echantillon3.count %td=number_to_currency echantillon3.sum(:prime) %tr %th Sur cartes n'ayant pas eu d'activité depuis %td 2 ans %td= echantillon4.count %td=number_to_currency echantillon4.sum(:prime) %table.table -VContact.where("codemanaginn LIKE 'CCV%' and prime is null").order("rand()").limit(1000000).each do |v_contact| -societe = Societe.where(:socmanaginn => v_contact.codeproprietaire).first -seuils = SeuilDeclencheur.where(:codedeclencheur => "MGD00000004", :socmanaginn => v_contact.codeproprietaire).where("datefin > ?", @date) -#seuil_vidanges = SeuilDeclencheur.where(:codedeclencheur => "MGD00000005", :socmanaginn => v_contact.codeproprietaire).where("datefin > ?", @date) -seuil = seuils.first -if seuil -rate = ((seuil.valba.to_f / seuil.valseuil.to_f) * 100.0).round(2) if seuil.valba? and seuil.valseuil.to_f > 0.0 -else -rate = 0.0 -cagnotte = VolumePeriodique.where(:codemanaginn => v_contact.codemanaginn, :codeindicateur => "MGI000000001").where("datereception <= ?", @date).sum(:valeur) -prime = (cagnotte * (rate/100)).round(2) -#vidanges = VolumePeriodique.where(:codemanaginn => v_contact.codemanaginn, :codeindicateur => "MGI000000003").where("datereception <= ?", @date).sum(:valeur) -#seuil_vidange = seuil_vidanges.first -last_date = nil -last = VolumePeriodique.where(:codemanaginn => v_contact.codemanaginn).order("datereception DESC").first -if last -last_date = last.datereception -v_contact.rate = rate -v_contact.cagnotte = cagnotte -v_contact.prime = prime -#v_contact.nbr_vidanges = vidanges -if false -if seuil_vidange -v_contact.vidanges_seuil = seuil_vidange.valseuil.to_i -v_contact.vidanges_offerte = seuil_vidange.valba - v_contact.last_volume_at = last_date -v_contact.save -if false and societe %tr %td- v_contact.codemanaginn %td =v_contact.prenom =v_contact.nom %td= v_contact.codeproprietaire %td =societe.nom if societe %td = seuils.count %td =rate ="%" %td =number_to_currency cagnotte %td =number_to_currency prime %td =vidanges %td =last_date