.qi_header
  .right= link_to 'Ajouter un paiement', new_admin_p_payment_path(), :class => "btn btn-primary", :remote => true
  %h1
    Paiements
    %span
      Liste des paiements


.qi_row
  .qi_pannel.qi_plain.padding
    
    -if false
      %table.table
        -PPayment.where("theo_date is not null").order(:p_payment_type_id).each do |pp|
          -if pp.theo_date != pp.paid_at
            -pp.past_theo_date = pp.theo_date
            -pp.past_paid_at = pp.paid_at
          
            -pp.received_at = pp.paid_at
            -pp.paid_at = pp.theo_date
          
            -pp.save
    -if false
      =PPayment.where(:p_payment_type_id => 4).count
      =PPayment.where(:p_payment_type_id => 4).update_all(:p_payment_type_id => 41, :past_diff => true)
      
    
    =form_tag "", :method => "get",  :onsubmit => "" do
      :scss
        .search_table{
          td{
            vertical-align:top;
          }
        }
      %table.search_table
        %tr
          %td.search_label
            Type de paiement :
          %td
            -params[:p_payment_type_ids] = params[:p_payment_type_ids] || []
        
            %div{:style => "height:150px;overflow:auto;"}
              -PPaymentType.order("name").all.each do |pdt|
              
                %div
              
                  = check_box_tag "p_payment_type_ids[]", pdt.id, (true if params[:p_payment_type_ids].include?(pdt.id.to_s)), {:id => "p_payment_type_ids_#{pdt.id}"}
                  = label_tag "p_payment_type_ids_"+pdt.id.to_s, pdt.name
          
            
            =#select_tag :p_payment_type_id, options_from_collection_for_select(PPaymentType.order("name").all, "id", "name", params[:p_payment_type_id]), :include_blank => true
          
          
          
          %td.search_label
            Remise ?
          %td=select_tag :remise, options_for_select([["Non","0"], ["Oui","1"]], params[:remise]), :include_blank => true
          
          %td.search_label
            Affecté ?
          %td=select_tag :affected, options_for_select([["Non","0"], ["Oui","1"]], params[:affected]), :include_blank => true
          
         
          
          -if false
            %td=text_field_tag :name, params[:name],:class => "form-control", :placeholder => "Nom"
            %td=text_field_tag :city, params[:city],:class => "form-control", :placeholder => "Ville"
          
            %td=text_field_tag :tel, params[:tel],:class => "form-control", :placeholder => "Tel"
            %td=text_field_tag :document_number, params[:document_number],:class => "form-control", :placeholder => "N° document"
          
          
          
          
          
      =#text_field_tag :search, params[:search],:class => "form-control", :placeholder => "Rechercher"
      %table
        %tr
          %td.search_label
            Montant : 
          %td.search_op
            de
          %td.search_number_input
            =number_field_tag :amount_min, params[:amount_min],:class => "form-control", :placeholder => "Min", :step => 0.01
          %td.search_op
            à
          %td.search_number_input
            =number_field_tag :amount_max, params[:amount_max],:class => "form-control", :placeholder => "Max", :step => 0.01
          %td.search_op
          
          %td.search_label
            Date de paiement :
          %td.search_number_input
            .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)
    
          %td.search_op
            au
          %td.search_number_input
            .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)
         
            
          
      :scss
        .search_label{
          
          text-align:right;
          padding-right:5px;
        }
        .search_op{
          width:25px;
          text-align:center;
          color:rgba(0,0,0,0.5);
        }
        
        
        
            
            
            
        
      =submit_tag "Recherche", :class => "btn btn-default", :style => "margin-bottom: 10px;"
      ="-"
      =select_tag :per_page, options_for_select([50,100,200,500], params[:per_page])
      résultats par page
    %p
      ="#{@p_payments.total_count} résultat(s) -"
      =number_to_currency  @all_p_payments.sum(:amount)
    =form_tag new_f_admin_p_remises_path do
      %table.table
        %tr
          
          %th
          %th
          %th Type de paiement
          %th Date de paiement
          %th Date de réception du paiement
  
          %th Client
          %th Montant
          %th Montant à affecter
          %th
          %th
          %th
  
      
        %tbody#p_payments_rows
          =render @p_payments
      -if params[:p_payment_type_ids].size > 0
        =submit_tag "Créer une remise"
        
    
    .qi_pagination
      = paginate @p_payments
  
    