



%p
  %center
    -date = (Date.today - 2.year).beginning_of_month
  
    -while date < Date.today
      -Date.today.beginning_of_month
      -Date.today.end_of_month
    
      =link_to raw("#{l(date, :format => '%B')}&nbsp;#{date.year}"), admin_p_stats_path(:start => date, :stop => date.end_of_month)
      ="-"
    
      -date = date + 1.month
  

.qi_row
  .qi_pannel.qi_plain.padding
    =form_tag "", :method => "get", :remote => false, :onsubmit => "set_busy();" do
    
      .row.qi_cancel_margins
        .col-xs-4
          .input-group
            =text_field_tag :start, params[:start],:class => "form-control datepicker", :placeholder => "Début"
            %span.input-group-addon.btn{:onclick => "$(this).prev('input').val('');"}
              =ic(:times)
        
        .col-xs-4
          .input-group
            =text_field_tag :stop, params[:stop],:class => "form-control datepicker", :placeholder => "Fin"
            %span.input-group-addon.btn{:onclick => "$(this).prev('input').val('');"}
              =ic(:times)
    
      
        
        .col-xs-2
          
          =submit_tag "filtrer", :class => "btn btn-default", :style => "margin-bottom: 10px;"
      
      %p
        -if @start and @stop
          =link_to "< Mois précédent","?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"
        -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"
      
     
          
    %hr
  
    

    %table.table.table-stripped
      %tr
        %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)

  %br
  %br
  
  

  =link_to "Export CSV", 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}

  
        

