-params[:solde] = params[:solde] || "0"
-p_customer = @p_customer
-if p_customer
  
  
  -@price_documents = p_customer.price_documents



  -date_regex = /^(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/](19|20)\d\d$/i
  -if params[:start] and params[:start] =~ date_regex
    -@start = Date.parse(params[:start]).beginning_of_day 
    -params[:start]= @start.strftime('%d/%m/%Y')
  -else
    -@start = nil


  -if params[:stop].to_s != "" and params[:stop] =~ date_regex
    -@stop = Date.parse(params[:stop]).end_of_day 
    -params[:stop]= @stop.strftime('%d/%m/%Y')
 
  -else
    -@stop = nil

  -@price_documents = @price_documents.where("created_at >= ?", @start) if @start
  -@price_documents = @price_documents.where("created_at <= ?", @stop.end_of_day) if @stop

  -if params[:solde].to_s != ""
  
    -if params[:solde].to_s == "0"
      -@price_documents = @price_documents.where("cc_to_paid_ttc != 0.0")
    -else
      -@price_documents = @price_documents.where("cc_to_paid_ttc = 0")
  
  


  -@price_documents = @price_documents.order("created_at DESC")

  -per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 20
  -page = (params[:page] and params[:page] != "") ? params[:page] : 1 
  -@price_documents = @price_documents.page(page).per(per_page)






  #search_to_affect
    .header_table
      -if true
        #search_to_affect_form
          =form_tag search_to_affect_admin_price_documents_path(), :method => "get",  :onsubmit => "", :autocomplete => "off", :remote => true do
            =hidden_field_tag :p_customer_id, (@p_customer.id if @p_customer)


      
            %table.search_table
              %tr
                %td.search_label
                  Début
                %td
                  .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)
      
   
                  -if @start and @stop
        
                    =link_to "< Mois précédent",request.query_parameters.merge({start: ((@start - 1.month).beginning_of_month.strftime('%d/%m/%Y')), stop: ((@stop - 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-default"
        
                %td.search_op
          

                %td.search_label
                  Fin
                %td
                  .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)
       
                  -if @start and @stop
                    =link_to "Mois suivant >",request.query_parameters.merge({start: ((@start + 1.month).beginning_of_month.strftime('%d/%m/%Y')), stop: ((@stop + 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-default"
                %td.search_op
                %td.search_label
                  Soldé ?
                %td=select_tag :solde, options_for_select([["Non","0"], ["Oui","1"]], params[:solde]), :include_blank => true
                %td.search_op
                %td
        
                  =submit_tag "Rechercher", :class => "btn btn-primary"
      
      %table.table.table-stripped.table-hover
        %tr
          %th{:style => "width:30px"}
            
          %th{:style => "width:100px"} Date
          %th Numéro de doc.
          %th.numeraire{:style => "width:90px"} Montant TTC
          %th.numeraire{:style => "width:90px"} Solde TTC
          %th.numeraire{:style => "width:30px"}
          %th{:style => "width:10px"}
  

  
    .inner_panel
      
      %table.table.table-stripped.table-hover
      
        -@price_documents.where(:price_document_type_id => 4).each do |price_document|
          %tr.price_document_search#price_document_search{:data => {:id => price_document.id}}
            %td{:style => "width:30px;text-align:center;"}=ic :check if price_document.solded
            %td{:style => "width:100px"}=l price_document.date, :format => "%y/%m/%Y"
            
            %td
              =link_to price_document.d_number, admin_price_document_path(:id => price_document.id), :target => "_blank"
            %td.numeraire{:style => "width:90px"}=number_to_currency price_document.tot_amount_ttc
          
            %td.numeraire{:style => "width:90px"}
              =number_to_currency price_document.to_paid_ttc.to_f
            %td{:style => "width:30px;text-align:center;"}
            
              -@fields = nil
              -new_object = PPaymentDocument.new(:price_document_id => price_document.id)
              -semantic_form_for([:admin, PPayment.new]) do |form|
                -@fields = form.semantic_fields_for(:p_payment_documents, new_object, :child_index => "new_p_payment_documents") do |builder|
                  -render("admin/p_payment_documents/form", :form => builder)
              
  
              =link_to ic(:plus) ,"#", :onclick => "qi_add_fields(this, 'p_payment_documents', \"#{escape_javascript(@fields)}\");return false;", :class => "add_to_affects"
          
            
         
            %td{:style => "width:10px;text-align:center;"}
  
  
    .qi_pagination
      = paginate @price_documents, :remote => true
-else
  #search_to_affect

:scss
  
  #search_to_affect{
    
    width:600px;
    height:400px;
    margin:auto;
    overflow:hidden;
    position:relative;
    background:white;
    box-shadow:0 0 5px rgba(0,0,0,0.5);
    
    
    .add_to_affects{
      cursor:pointer;
      
      &:hover{
        color:white;
        background:#428bca;
        padding:1px 3px;
        margin:2px;
      }
    }
    
    .header_table{
      position:absolute;
      top:0px;
      height:50px;
      right:0;
      left:0;
      background:white;
      box-shadow:0 0 5px rgba(0,0,0,0.5);
      
    }
    
    .qi_pagination{
      box-shadow:0 0 5px rgba(0,0,0,0.5);
      margin:0;
      position:absolute;
      background:white;
      right:0;
      left:0;
      bottom:0px;
      height:30px;
      padding:2px;
      font-size:11px;
      .gap, .current, a{
        padding:4px 8px !important;
      }
    }
    
    
    
    .inner_panel{
      position:absolute;
      top:50px;
      right:0;
      left:0;
      bottom:30px;
      overflow:auto;
      
    }
    
    .table{
      font-size:11px;
      td,th{
        padding:2px 4px;
      }
    }
  }
  
  //dddd
  #search_to_affect_form{
    font-size:0.9em;
    width:600px;
    margin:auto;
    background:white;
    margin-bottom:4px;
    .btn{
      padding:3px 4px !important;
      font-size:0.9em !important;
      
  
    }
    .input-group{
      .form-control, .btn{
        padding:3px 4px !important;
        font-size:0.9em !important;
        height:20px !important;
        
      }
      
      .form-control{
        width:100px !important;
      }
      
    }
    
    .search_table{
      td{
        vertical-align:middle;
      }
    }  

    .search_label{
      text-align:right;
      padding-right:5px;
    
    }
    .search_op{
      width:25px;
      text-align:center;
      color:rgba(0,0,0,0.5);
    
    }
    
    
  
  }

  
  
  