-start_date = Time.parse("2015/06/30")

%p=link_to raw("Modérer les annonces <span class='badge'>#{Annonce.not_moderated.where(:published => true).count}</span>"), admin_annonces_path, :class => "btn btn-lg btn-primary"

.row
  .col-md-4
    .panel.panel-default
      .panel-heading
        Chiffre d'affaire
      .panel-body
        %p
          -total_ht = Order.between(Time.now.beginning_of_day, Time.now.end_of_day).where("unpaid is null").where("payment_type_id = 2").where(:paid => true).sum(:price_ht)
          %strong{:style => "color:green"}
            =number_to_currency total_ht
            HT
          (
          =number_to_currency (total_ht*1.2)
          TTC
          )
          aujourd'hui
        %p
          -total_ht = Order.between(start_date, Time.now.end_of_day).where("unpaid is null").where("payment_type_id = 2", ((start_date).beginning_of_day)).where(:paid => true).sum(:price_ht)
          %strong{:style => "color:green"}
            =number_to_currency total_ht
            HT
          (
          =number_to_currency (total_ht*1.2)
          TTC
          )
        %p
          depuis le 
          =l start_date, :format => :date
  
    
  
  .col-md-4
    .panel.panel-default
      .panel-heading
        Stats depuis le
        =l start_date, :format => :date
      .panel-body
        %p
          =link_to admin_annonce_accounts_path do
            %strong=AnnonceAccount.count
            comptes
          dont :
        %p
          %strong=AnnonceAccount.where("binary_parent_id IS NOT NULL").count
          dans le binaire
        %p
          %strong=AnnonceAccount.where("binary_parent_id IS NULL").count
          gratuits
        %p
          =link_to "/search.html" do
            %strong=Annonce.valid_to_show.count
            annonces
        
  .col-md-4
    .panel.panel-default
      .panel-heading
        Commissions depuis le
        =l start_date, :format => :date
      .panel-body
      
        %p
          Commissions directes :
          -com_direct = Commission.where("created_at >= ?", ((start_date).beginning_of_day)).where(:commission_type_id => 1).sum(:amount)
          %strong=number_to_currency com_direct
        %p
          Commissions binaires :
          -com_binaire =  Commission.where("created_at >= ?", ((start_date).beginning_of_day)).where(:commission_type_id => 2).sum(:amount)
          %strong=number_to_currency com_binaire
        %p
          Commissions de participation :
          -com_part_1 =  Commission.where("created_at >= ?", ((start_date).beginning_of_day)).where(:commission_type_id => 3).sum(:amount)
          %strong=number_to_currency com_part_1
        
        %p
          Cumul des 3 commissions :
          -com_part_1 =  Commission.where("created_at >= ?", ((start_date).beginning_of_day)).where(:commission_type_id => 3).sum(:amount)
          %strong=number_to_currency com_binaire + com_direct + com_part_1
.row
  .col-md-4
    .panel.panel-default
      .panel-heading
        Commissions versées
        =l start_date, :format => :date
      .panel-body
        %p
          Demandes de virements :
          -com_virements =  Commission.where("created_at >= ?", ((start_date).beginning_of_day)).where(:commission_type_id => 4).sum(:amount)
          %strong=number_to_currency com_virements
        %p
          Utilisé pour acheté des crédits :
          -com_credits =  Commission.where("created_at >= ?", ((start_date).beginning_of_day)).where(:commission_type_id => 5).sum(:amount)
          %strong=number_to_currency com_credits
        
        %p
          Solde commissions à verser :
          %strong=number_to_currency Commission.where("created_at >= ?", ((start_date).beginning_of_day)).sum(:amount)


  .col-md-4
    .panel.panel-default
      .panel-heading
        Prochain versement de coms de participations
        
      .panel-body

        -last_cpc = CountPartCom.last_paid

        %p

          Date de début du calcul :
          %strong=start = CountPartCom.last_paid.last_day.tomorrow.beginning_of_day
        %p

          Date de fin du calcul :
          %strong=stop = CountPartCom.order("last_day DESC").first.last_day.end_of_day

        %p
          Montant :
          %strong=number_to_currency(next_part_com = Order.com_part_between(start, stop))
          
          
        .alert.alert-info
          %p
            Points binaires
            %strong= Order.points_binaires_between(start, stop)
          %p
            Points binaires MLM
            %strong= Order.points_binaires_mlm_between(start, stop)
          
          %p
            Points binaires hors MLM
            %strong= Order.points_binaires_direct_between(start, stop)
          
          
  .col-md-4
    .panel.panel-default
      .panel-heading
        Commissions reversées
        
      .panel-body
        %p
          Avant le prochain versement :
          %strong=number_to_currency com_binaire + com_direct + com_part_1
        %p 
          Avec le prochain : 
          %strong=number_to_currency com_binaire + com_direct + com_part_1 + next_part_com
          
        %p
          Soit 
          %strong=number_to_percentage ((com_binaire + com_direct + com_part_1 + next_part_com)*100)/total_ht, precision: 1
          du chiffre d'affaire total HT
          ="."
        
        %p
          Soit 
          %strong=number_to_percentage ((Commission.where("created_at >= ?", ((start_date).beginning_of_day)).where(:commission_type_id =>[1,2,3] ).sum(:amount) + next_part_com - Commission.where("created_at >= ?", ((start_date).beginning_of_day)).where(:commission_type_id =>[1,2,3] ).where(:annonce_account_id => [1,2,5]).sum(:amount))*100)/total_ht, precision: 1
          du chiffre d'affaire total HT
          en excluant les 3 premiers comptes
          
          
          
          
          



          

=link_to "Stats détaillés", stats_admin_auths_path, :class => "btn btn-lg btn-primary"
