.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
    =link_to @p_customer_sheet.p_customer.show_name, admin_p_customer_path(@p_customer_sheet.p_customer)
    
    
    %table.table{:style => ""}
      %tr
        %td{:style => "border:0"}
          %h3 Adresse de facturation
      
          -if @p_customer_sheet.particular_bill
            %strong=@p_customer_sheet.particular_bill.organisation
            %br
            =@p_customer_sheet.particular_bill.firstname

            =@p_customer_sheet.particular_bill.name
            %br
            =@p_customer_sheet.particular_bill.address_2

            -if @p_customer_sheet.particular_bill.address_3?
              %br
              =@p_customer_sheet.particular_bill.address_3
            %br
            =@p_customer_sheet.particular_bill.cp

            =@p_customer_sheet.particular_bill.city
            %br
            =@p_customer_sheet.particular_bill.country
            %br
            %br
            =@p_customer_sheet.particular_bill.tel
      
      
        %td{:style => "border:0"}
          %h3 Adresse de livraison
      
          -if @p_customer_sheet.particular_bill
            %strong=@p_customer_sheet.particular_bill.organisation
            %br
            =@p_customer_sheet.particular_send.firstname

            =@p_customer_sheet.particular_send.name
            %br
            =@p_customer_sheet.particular_send.address_2

            -if @p_customer_sheet.particular_send.address_3?
              %br
              =@p_customer_sheet.particular_send.address_3
            %br
            =@p_customer_sheet.particular_send.cp

            =@p_customer_sheet.particular_send.city
            %br
            =@p_customer_sheet.particular_send.country
            %br
            %br
            =@p_customer_sheet.particular_bill.tel
    
    
    %h3 Résumé
    -if @p_customer_sheet.cust_ref?
      Référence client :
      %strong=@p_customer_sheet.cust_ref
    =render :partial => "admin/p_sheet_lines/p_sheet_lines", :locals => {:sheet_lines => @p_customer_sheet.p_sheet_lines, :ok => (@p_customer_sheet.state_ok?) }
    
    
    
    
    .right
      -if @p_customer_sheet.state == "brouillon"
        %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"  
      
      -elsif @p_customer_sheet.state == "offre" or @p_customer_sheet.state == "panier"
        %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.acompte_percent? 
          %p=link_to "Générer la facture d'acompte", generate_fa_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
      
      -elsif @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.acompte_percent? 
          %p=link_to "Générer la facture d'acompte", generate_fa_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
        
      -elsif @p_customer_sheet.state == "livraison"  or @p_customer_sheet.state == "remboursée"  
        %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"]
    
    
    
    
    %table.table
      %tr
        %th Date
        %th Type
        %th Numéro
        %th Total HT
        %th Total TTC
  

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