.qi_header
  .right{:style => "text-align:right;"}
    = link_to i(:pencil), edit_admin_p_customer_path(@p_customer), :remote => false
    
    
    
  %h1
    Clients
    %span
      Détail d'un client
    %span
      =link_to [:admin, @p_customer] do
        =@p_customer.code
        =@p_customer.show_name



.qi_row
  .qi_pannel.qi_plain.padding
    .right
      -if !@p_customer.enabled
        .badge.badge-danger
          =ic :lock
          Client bloqué :
          =@p_customer.disabled_raison
    
    
    
    =render :partial => "admin/p_customers/apercu.html.haml", :locals => {:particular => @p_customer.particular, :mask_fin => true}
   

#customer_adresses
  =render(:partial => "admin/particulars/customer_preview", :locals => {:p_customer => @p_customer})
  


=render :partial => "admin/p_customers/financier.html.haml", :locals => {:p_customer => @p_customer}
    

    
    
    



.qi_row#tabs
  .qi_pannel
    %ul.nav.nav-tabs
      -params[:tab] = params[:tab] || "offres"
      %li{:class => ("active" if params[:tab] == "offres")}=link_to "Demandes de commande", "?tab=offres#tabs"
      -if false
        %li{:class => ("active" if params[:tab] == "etat")}=link_to "Etat de compte", "?tab=etat#tabs"
      
      -if current_admin.has_permission?("bills")
        %li{:class => ("active" if params[:tab] == "bills")}=link_to "Factures", "?tab=bills#tabs"
      -if current_admin.has_permission?("payments")
        %li{:class => ("active" if params[:tab] == "payments")}=link_to "Paiements", "?tab=payments#tabs"
    
    .tab-content{:style => "min-height:1000px;margin-bottom:300px;"}
      -if params[:tab] == "offres"
        #offres
          .qi_row
            .qi_pannel.qi_plain.padding
              .right
                -if @p_customer.enabled
                  =link_to ic(:plus)+" Demande de commande", new_admin_p_customer_sheet_path(:p_customer_id => @p_customer.id), :class => "btn btn-primary btn-ap-add" 
                
              %h3 Demande de commande
              .clear
    
             
              %hr
    
              %table.table.table-hover.table-striped
                %tr
                  %th ID
                  %th N° BC
                  %th Commercial
                  %th=sort_link "created_at", "Date"
                  %th=sort_link "price_line_blocks.wish_date", "Date de livraison souhaitée"
                  %th Client
        
       
                  %th Total HT
                  %th Total TTC
                  %th Statut

                  %th
                
  

                %tbody#p_customer_sheets_rows
                  - @p_customer_sheets = @p_customer.p_customer_sheets.order("created_at DESC")
                  -per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 30
                  -page = (params[:page] and params[:page] != "") ? params[:page] : 1 
                  -@p_customer_sheets = @p_customer_sheets.page(page).per(per_page)
                
                  =render @p_customer_sheets
              
              .qi_pagination
                = paginate @p_customer_sheets
      
      -if params[:tab] == "etat"
        #etat
          .qi_row
            .qi_pannel.qi_plain.padding
              .right
                = link_to 'Ajouter un paiement', new_admin_p_payment_path(:p_customer_id => @p_customer.id), :class => "btn btn-primary bgbd-payments", :remote => true
    
              %h3 
                Etat de compte
              
            
              =render :partial => "search_etat_form"
            
        
              -if false
                -@p_customer.p_compta_elements.destroy_all
                -@p_customer.price_documents.each do |pd|
                  -pd.save
      
                -@p_customer.p_payments.each do |pd|
                  -pd.save
    
    
              =render :partial => "admin/p_customers/etat", :locals => {:p_customer => @p_customer}
        
      -if params[:tab] == "bills"
        #bills
          .qi_row
            .qi_pannel.qi_plain.padding

              %h3 
                Factures
              %p
                =#link_to "Documents du client", admin_p_customer_price_documents_path(@p_customer)
              .clear
    

              %hr
              -if params[:doc_label]
                %p
                  Factures
                  =params[:doc_label]
              %table.table.table-hover.table-striped
                %tr
                  %th Code client
                  %th Commercial
                  %th Client
                  %th Type
        
        
        
                  %th Numéro
                  %th Date
        
                  %th Montant HT
                  %th TVA
                  %th Montant TTC
                  %th Soldé ?
                  %th Restant dû
                  %th.actions

                %tbody#p_customer_sheets_rows
                  -@price_documents = @p_customer.price_documents.where(:price_document_type_id => 4).order("date DESC, created_at DESC")
                  -if params[:price_document_ids]
                    -@price_documents = @price_documents.where(:id => params[:price_document_ids])
                  =render @price_documents



        
      
      -if params[:tab] == "payments"
        #payments

   
          .qi_row
            .qi_pannel.qi_plain.padding
              .right
                = link_to 'Ajouter un paiement', new_admin_p_payment_path(:p_customer_id => @p_customer.id), :class => "btn btn-primary bgbd-payments", :remote => true
              %h3 
                Paiements
                ="(#{@p_customer.p_payments.count})"
              .clear
            
            
            
              %hr

              %p
                Paiements encaissés :
                =number_to_currency @p_customer.paiements_total
              %p
                Paiements théoriques :
                =number_to_currency @p_customer.th_paiements_total
    
              %p
                Paiements totaux :
                =number_to_currency @p_customer.th_r_paiements_total
      
              %hr
    
              %table.table.table-hover.table-striped
                %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_customer.p_payments.order("paid_at DESC")

   


 
  