%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_at => date, :end_at => date.end_of_month)
      ="-"
    
      -date = date + 1.month
  

.qi_row
  .qi_pannel.qi_plain.padding
    %h2
      =raw("#{l(@start_at, :format => '%B %Y')}")
    %table.table
      %tr
        %td{:style => "width:50%;"}
          =@start_at
        %td{:style => "width:50%;"}
          =@end_at

    
    %p
      Nombre de commandes finalisées :
  
      =@finished.count
  
      %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 :
      =@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 :
  
      %strong=number_to_currency @finished.sum(:a_total_cost_ok)

    %p
      Marge estimée HT :
  
      %strong=number_to_currency(@finished.sum(:a_ok_total) - @finished.sum(:a_total_cost_ok))
      %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 
  
  