.qi_header
  %h1
    
    %span
      
-@m_odr_rep.save

.qi_row
  .qi_pannel.qi_plain.padding

      
    
    %table.table.table-striped.table-hover.table-bordered
      %tr
        %td{:style => "width:200px;"} Nom
        %td
          =@m_odr_rep.long_name
      
      %tr
        %td Adresse
        %td
          =@m_odr_rep.particular_address_2
          
          -if @m_odr_rep.particular_address_3.to_s != ""
            %br
            =@m_odr_rep.particular_address_3
      
      %tr
        %td Ville
        %td
          =@m_odr_rep.particular_cp
          =@m_odr_rep.particular_city
          ="-"
          =@m_odr_rep.particular_country
      
      %tr
        %td Tel
        %td
          =@m_odr_rep.particular_tel
      
      
      %tr
        %td Email
        %td
          =@m_odr_rep.particular_email
    
    
    %hr
    Achat
    .row
      .columns.span_4
        %table.table.table-striped.table-hover.table-bordered
          %tr
            %td{:style => "width:200px;"} Marque :
            %td
              =@m_odr_rep.product_brand
    
          %tr
            %td Produit
            %td
              =@m_odr_rep.product_name
          %tr
            %td Quantité
            %td
              =@m_odr_rep.qte
    
        %table.table.table-striped.table-hover.table-bordered
          %tr
            %td{:style => "width:200px;"} Remise :
            %td
              =number_to_currency @m_odr_rep.remise
        
        
        -@m_odr_rep.m_odr_files.order("id DESC").each do |file|
          %table.table.table-striped.table-hover.table-bordered
            %tr
              %td{:style => "width:200px;"} Fichier 
              %td
                =File.basename file.file.path
    
            %tr
              %td Lien
              %td
                =link_to "Télécharger", download_admin_m_odr_file_path(file, :disposition => "attachment")
                
                
            %tr
              %td Validation
              %td
                -if file.admin_ok == true
                  =state_helper "Validé"
                -elsif file.admin_ok == false
                  =state_helper "Refusé"
                  %br
                  =file.reject_reason
                  =simple_format file.reject_reason_description if file.reject_reason_description?
                  -[["achat-hors-delais", "Achat hors délais"],["facture-illisible", "Facture illisible"],["pneus-non-porteurs-de-l-offre", "Pneus invalides"]].each do |key|
                    %br
                    =link_to "Envoyer un mail de notification : #{key[1]}", send_mail_admin_m_odr_file_path(file, :slug => key[0]), :remote => false
                  %br
              
                =link_to "Modérer ce fichier", edit_admin_m_odr_file_path(file), :remote => true
              
      
        RIBs : 
        -@m_odr_rep.m_odr_rep_ribs.order("id DESC").each do |m_odr_rep_rib|
          %table.table.table-striped.table-hover.table-bordered
            %tr
              %td{:style => "width:200px;"} ID Rib
              %td
                =m_odr_rep_rib.id
      
            %tr
              %td IBAN
              %td
                =m_odr_rep_rib.iban
      
            %tr
              %td BIC
              %td
                =m_odr_rep_rib.bic
            
        
            %tr
              %td Validation
              %td
                -if m_odr_rep_rib.admin_ok == true
                  =state_helper "Validé"
                -elsif m_odr_rep_rib.admin_ok == false
                  =state_helper "Refusé"
                  %br
                  =m_odr_rep_rib.reject_reason
                  =simple_format m_odr_rep_rib.reject_reason_description if m_odr_rep_rib.reject_reason_description?
                  
                  -if m_odr_rep_rib.mail_hists.count == 0
                    =link_to "Envoyer un mail de notification", send_mail_admin_m_odr_rep_rib_path(m_odr_rep_rib), :remote => false
                    
          
                =link_to "Modérer ce RIB", edit_admin_m_odr_rep_rib_path(m_odr_rep_rib), :remote => true
            
        
        -if @m_odr_rep.state == "Refusée"
          .red Offre refusée :
          -[["achat-hors-delais", "Achat hors délais"],["facture-illisible", "Facture illisible"],["pneus-non-porteurs-de-l-offre", "Pneus invalides"]].each do |key|
            %br
            =link_to " Envoyer un mail de notification : #{key[1]}", send_mail_admin_m_odr_rep_path(@m_odr_rep, :slug => key[0]), :remote => false
        
        -else
          =link_to "Marquer cette offre comme refusée", refuse_admin_m_odr_rep_path(@m_odr_rep)
          
          
      .columns.span_8{:style => "padding-left:20px;"}
        -file = @m_odr_rep.m_odr_files.order("id DESC").first
        -if file
          =link_to "Télécharger", download_admin_m_odr_file_path(file, :disposition => "attachment")
          %iframe{:src => file.file.url, :style => "width:100%;height:800px;border:1px solid gray;"}
          
          
          
          
    .clear
    %hr
    Virements
    -if @m_odr_rep.admin_ok_to_send and @m_odr_rep.m_odr_virements.where(:refused => false).count == 0
      =link_to "Générer le virement", generate_virement_admin_m_odr_rep_path(@m_odr_rep)
    
    
    -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_rep.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_rep.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}
    
    