=semantic_form_for [:admin, @p_payment], :remote => true do |f|
  -@p_customer = @p_payment.p_customer if  @p_payment.p_customer
  .content
    =f.inputs do
    
    
      =hidden_field_tag :last_p_customer_id, @p_payment.p_customer_id
      .qi_autocomplete
        %label Client :
        %input.qi_autocomplete_input.form-control{:type => "text"}
        
        .qi_list
        
      = f.hidden_field :p_customer_id, :id => "p_customer_id"
      
      :coffeescript
        $(document).on "click", ".autocomplete_line", ->
          
          id = $(this).data('value')
          
          $(this).closest(".qi_autocomplete").next("input").val(id)
          
          $(this).closest(".qi_list").hide()
          $(this).closest(".qi_autocomplete").find(".qi_autocomplete_input").val("")
       
          
          change_address = false
          
          if (parseInt($("#last_p_customer_id").val()) != parseInt(id))
            change_address = true
          
          
          $.ajax
            url:"/admin/p_customers/"+id+"/autocomplete_apercu.js", 
            type : "GET",
            data : {search : $(this).val(),  change_address : change_address, payment: "true"}
          
          $("#last_p_customer_id").val(id)
          
          return false
          
        $(".qi_autocomplete_input").keyup ->
          input = $(this)
          $.ajax
            url:"/admin/p_customers/autocomplete.js", 
            type : "GET",
            data : {search : $(this).val()}
              
        
        
      
      :scss
        .qi_autocomplete{
          position:relative;
          
          .qi_autocomplete_input{
            width:100%;
            box-sizing:border-box;
            
            
          }
          
          .qi_list{
            position:absolute;
            left:1px;
            right:1px;
            background:rgba(255,255,255,0.9);
            box-shadow:0 0 5px rgba(0,0,0,0.3);
            
            a{
              display:block;
              padding:5px 7px;
              box-sizing:border-box;
              border-bottom:1px solid rgba(0,0,0,0.2);
              
              &:hover{
                text-decoration:none;
              }
            }
          }
        }
      
      .p_customer_sheet_customer
    
    
        -if @p_payment.p_customer and @p_payment.p_customer.particular
          =render :partial => "admin/p_customers/apercu", :locals => {:particular => @p_payment.p_customer.particular}
    
    
    
      
      %br
    
      = f.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"}
      
      = f.input :paid, :label => "Encaissé ?" 
      = f.input :paid_at, :label => "Date de paiement :" 
      .not_comptant{:style => ("display:none" if ![4,7,9].include?(@p_payment.p_payment_type_id))}
        = f.input :theo_date, :label => "Date de paiement théorique :" 
      = f.input :amount, :label => "Montant :" 
      = f.input :number, :label => "Numéro / référence :" 
      
      
      %hr
      
      .p_payment_documents_form
        =f.semantic_fields_for :p_payment_documents do |form|
          =render :partial => "admin/p_payment_documents/form", :locals => {:form => form}
    
      %p= link_to_add_fields "Ajouter une ligne", f, :p_payment_documents
    
    
      
    :coffeescript
      not_comptant_ids = [4,7,9]
      
      $('#payment_type_id_select').change ->
        val = $(this).val()
        if $.inArray(parseInt(val), not_comptant_ids) isnt -1
          $(".not_comptant").show()
        else
          $(".not_comptant").hide()
        
        


      
  .actions=f.submit "sauvegarder", :class => "btn btn-primary"
  