.qi_header
  .right
    #state=render :partial => "admin/m_odr_primes/state"
  %h1
    Primes
    %span
      Détail de la prime 
      ="##{@m_odr_prime.id}"
      


.qi_row
  .qi_pannel.qi_plain.padding
  
    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}
    
    %hr
  
  
    #head=render :partial => "admin/m_odr_primes/head"

    %h3
      Roulage


    %table.table
      %tr
        %th
          Date roulage
        %th Roulage
        %th Nbr primes
        %th Nbr primes utilisées
        %th Nbr primes restantes
        %th
      %tr
        %td
          =l @m_odr_prime.m_odr_file_roulage.date
        %td
          =@m_odr_prime.m_odr_file_roulage.m_event.title if @m_odr_prime.m_odr_file_roulage.m_event

        -m_odr_file = @m_odr_prime.m_odr_file_roulage.m_odr_file
        
        
        
   
        
        %td
          =m_odr_file.new_nbr_primes
        %td
          =m_odr_file.new_nbr_primes_useds
        %td
          =m_odr_file.new_nbr_primes_not_useds
        
        %td
          = link_to i(:pencil), edit_admin_m_odr_file_path(m_odr_file), :remote => false

    %h3
      Achats concernés


    %table.table
      %tr
        %th Date achat
        %th Nbr pneus
        %th Montant remboursé
        %th

      -@m_odr_prime.m_odr_prime_files.each do |m_odr_prime_file|
        %tr
          %td
            =l m_odr_prime_file.m_odr_file.buy_at if m_odr_prime_file.m_odr_file.buy_at

          %td
            =m_odr_prime_file.nbr_pneus

          %td
            =number_to_currency m_odr_prime_file.amount

          %td
            = link_to i(:pencil), edit_admin_m_odr_file_path(m_odr_prime_file.m_odr_file), :remote => false
    
    -if @m_odr_prime.state == "Erreur sur virement" and @m_odr_prime.m_odr_virements.where(:refused => false).count == 0
      =link_to "Générer le virement", generate_virement_admin_m_odr_prime_path(@m_odr_prime), :class => "btn btn-primary"

    -if @m_odr_prime.state == "A traiter" or @m_odr_prime.state == "Validé" or @m_odr_prime.state == "En attente de roulage" and @m_odr_prime.m_odr_virements.where(:refused => false).count == 0
      
      -if @m_odr_prime.m_odr_file_roulage.date? and @m_odr_prime.m_odr_file_roulage.date <= Date.today
        =link_to "Générer le virement", generate_virement_admin_m_odr_prime_path(@m_odr_prime), :class => "btn btn-primary"
      -else
        
        -if @m_odr_prime.state == "En attente de roulage"
          %span.btn.btn-default
            Vous pourrez générer le virement une fois la date de roulage passée.
        -else
          =link_to 'Valider et passer au statut "en attente de roulage"', attente_roulage_admin_m_odr_prime_path(@m_odr_prime), :class => "btn btn-primary"
    %hr
    Virements
    
    
    -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_virements = @m_odr_prime.m_odr_virements.page(page).per(per_page)
    
    =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @m_odr_virements}
    
    
    %hr
    Historique des mails envoyés
    
    -params[:search][:per_page] = params[:search][:per_page] || 50
    -per_page = params[:search][:per_page]
    -page = (params[:page] and params[:page] != "") ? params[:page] : 1 
    -@mail_hists = @m_odr_prime.mail_hists
    -@mail_hists = sort_by_sorting(@mail_hists, "created_at DESC")
    -@mail_hists = @mail_hists.page(page).per(per_page)
    
    =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @mail_hists}
    
    
    







