.qi_header
  
  %h1
    Ventes
    %span
      =link_to "Offres",admin_p_customer_sheets_path

.qi_row
  .qi_pannel.qi_plain.padding
    .right
      =raw @p_customer_sheet.state_html
      
      -if @p_customer_sheet.state != "livrée" and @p_customer_sheet.state != "facturée"
        = link_to i(:pencil), edit_admin_p_customer_sheet_path(@p_customer_sheet), :remote => false
    %h3 Client
    
    -if @p_customer_sheet.p_customer and @p_customer_sheet.p_customer.particular
      =render :partial => "admin/p_customers/apercu", :locals => {:particular => @p_customer_sheet.p_customer.particular}
    
    
    %table.table{:style => ""}
      %tr
        %td{:style => "border:0"}
          %h3 Adresse de facturation
      
          =render(:partial => "admin/particulars/particular_detail", :locals => {:particular => @p_customer_sheet.particular_bill}) if @p_customer_sheet.particular_bill
      
        %td{:style => "border:0"}
          %h3 Adresse de livraison
      
          =render(:partial => "admin/particulars/particular_detail", :locals => {:particular => @p_customer_sheet.particular_send}) if @p_customer_sheet.particular_send
    
    
    %h3 Résumé
    -if @p_customer_sheet.cust_ref?
      Référence client :
      %strong=@p_customer_sheet.cust_ref
      
    -if false
      %table

        %tr
          %td
            =number_to_currency @p_customer_sheet.a_ok_total
          %td
            =number_to_currency @p_customer_sheet.a_total_cost_ok

   
    =render :partial => "admin/p_sheet_lines/p_sheet_lines", :locals => {:sheet_lines => @p_customer_sheet.p_sheet_lines, :ok => (@p_customer_sheet.state_ok?) }
    
    
    
    %table.en-tete-table{:style => "width:auto;position:relative;top:-40px;"}
      %tr
        %th Conditions de réglement
       
    
      %tr
      
    
        %td{:style => "width:150px;"}
          -if @p_customer_sheet.p_payment_type
            =@p_customer_sheet.p_payment_type.name
            %br
        
          -if @p_customer_sheet.comptant
            Comptant
          -else
            =@p_customer_sheet.payment_delais.to_i
            j nets
      
       
          
    .right
      -if @p_customer_sheet.state == "brouillon" or @p_customer_sheet.state == "offre" or @p_customer_sheet.state == "commande"
        %p=link_to "Générer le devis", generate_d_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
        %p=link_to "Générer la facture proforma", generate_fp_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"  
        %p=link_to "Générer le bon de commande", generate_bc_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-success"
        %p=link_to "Marquer l'offre comme refusée", reject_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-danger"
      
      -if @p_customer_sheet.state == "commande" and @p_customer_sheet.p_sheet_lines.joins(:p_product).where("bl = 0 and (p_products.p_product_cat_id != 6 OR (p_products.p_product_cat_id = 6 and externe = 1))").count > 0
        %p=link_to "Générer le bon de livraison", generate_bl_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
      
      -if @p_customer_sheet.state == "livrée" or @p_customer_sheet.state == "remboursée"  
        -if @p_customer_sheet.state == "remboursée"  
          %p= link_to ic(:pencil)+" Modifier l'adresse, le client, ou le montant avant de re-facturer", edit_admin_p_customer_sheet_path(@p_customer_sheet), :remote => false, :class => "btn btn-warning"
        %p=link_to "Générer la facture", generate_f_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
        
    .clear
    
    
    %h3 Documents
    =#["brouillon", "offre", "commande", "livrée","facturée", "annulée", "refusée"]
    
    =#debug @p_customer_sheet.p_documents.first.save
    
    
    
    %table.table.table-hover.table-striped
      %tr
        %th Date
        %th Client
        %th Type
        %th Numéro
        %th Total HT
        %th Total TTC
        %th.actions

      %tbody#p_customer_sheets_rows
        =render @p_customer_sheet.p_documents.order("created_at DESC")
  
 