.qi_header
  %h1
    Documents
    %span
      Détail document


.qi_row
  .qi_pannel.qi_plain.padding
  
    =debug @p_document.save
    =debug @p_document.totals
    
    =debug @p_document.paid_completed?
    
    -if false
      =PDocument.where("cache_to_paid >= -1.0 and cache_to_paid <= 1.0 and paid = 0").all.count
      -PDocument.where("cache_to_paid >= -1.0 and cache_to_paid <= 1.0 and paid = 0").all.each do |p_doc|
        =p_doc.id
        =p_doc.save
      
      
      =#debug @p_document.save
    
      =debug @p_document.total_paid.to_f == @p_document.totals[:ok_total_ttc].to_f
      =debug @p_document.total_paid.to_f
      =debug @p_document.totals[:ok_total_ttc].to_f
    
    %table.en-tete-table{:style => "width:auto;"}
      %tr
        %th Date
        %th N° Client
        %th Type
        %th Référence doc.
        -if @p_document.cust_ref?
          %th Réf. com. client
        %th Total payé
        %th Payée ?
        %th Date paiement
        %th Reste à payer
        
        
        
      %tr
      
    
        %td{:style => "width:140px"}
          =l @p_document.created_at, :format => :date #@p_document.created_at
      
        %td{:style => "width:70px"}
          =@p_document.p_customer.code
      
        %td{:style => "width:110px"}
          =@p_document.label

        %td{:style => "width:120px"}
          =link_to @p_document.d_number, admin_p_document_path(@p_document.token)
          
      
        -if @p_document.cust_ref?
          %td{:style => "width:90px"}
            =@p_document.cust_ref
            
        %td
          =number_to_currency @p_document.total_paid.to_f
          
        %td{:style => "width:90px;font-size:3em;"}
          =ic(:check) if @p_document.paid
        %td
          =l @p_document.paid_at, :format => :date if @p_document.paid_at
        %td
          =number_to_currency @p_document.cache_to_paid
          
        
          
    
    %br
    %br
    =#render @p_document.arrondi if @p_document.arrondi
    
    %table.table
      %tr
        -if params[:p_payment_type_id].to_s != ""
          %th
        %th
        %th Type de paiement
        %th Date de paiement
        %th Date théorique

        %th Client
        %th Montant
        %th Montant à affecter
        %th
        %th
        %th

    
      %tbody#p_payments_rows
        =render @p_document.p_payments
        
    %p Affectations :
    %table.table
      %thead
        %tr
          %th ID
          %th
            Date
          %th
            Montant paiement total
          
          %th
            Montant affecté à cette facture
          
          %th
          
      %tbody=render @p_document.p_payment_documents
      
      
      
      
      
      
      