%tr#price_document_row{:id => price_document.id}
  -tr = {}

  -tr[:p_payment_type] = capture do
    %td= price_document.price_line_block.p_payment_type.name if  price_document.price_line_block and price_document.price_line_block.p_payment_type 
    
  -tr[:p_customer_code] = capture do
    %td
      = price_document.p_customer.code if price_document.p_customer
  
  -tr[:p_commercial] = capture do
    %td
      = price_document.p_customer.p_commercial.long_name if price_document.p_customer and price_document.p_customer.p_commercial
  -tr[:p_customer] = capture do
    %td
      = price_document.p_customer.show_name if price_document.p_customer
    
  -tr[:p_fournisseur] = capture do
    %td
      = price_document.p_fournisseur.name if price_document.p_fournisseur  
  
  -tr[:com_counter] = capture do
    %td
      =link_to price_document.ref_element.com_counter, [:admin, price_document.ref_element] if price_document.ref_element and price_document.ref_element_type == "PCustomerSheet"
  -tr[:label] = capture do
    %td
      =price_document.label
  -tr[:d_number] = capture do
    %td
      =price_document.d_number
      
  
  -tr[:cc_cost_ht] = capture do
    %td
      =number_to_currency price_document.cost_ht if current_admin.has_permission?("show-costs")
    
  -tr[:cc_marge_ht] = capture do
    %td
      =number_to_currency price_document.marge_ht if current_admin.has_permission?("show-costs")
      
  
  
  -tr[:cc_to_paid_ttc] = capture do
    %td
      -if price_document.label == "Facture"
        =number_to_currency price_document.cc_to_paid_ttc
  
  -tr[:reste_to_affect] = capture do
    %td
      -if price_document.label == "Avoir"
        =number_to_currency price_document.cc_to_paid_ttc
   
      
      
      
  -tr[:stock_ok] = capture do
    %td
      -if !price_document.imported
        -if price_document.block_type == "Facture d'achat"
          -if price_document.stock_ok
            Oui
          -else
            =link_to "Générer les stocks", generate_stocks_admin_price_document_path(price_document), :class => "btn btn-primary" 
          
        -elsif price_document.price_document_type_id == 4 or price_document.price_document_type_id == 5
        
    
          -if !price_document.cost_ok
            =link_to "Mettre à jour les stocks, calculer la marge", update_stocks_admin_price_document_path(price_document), :class => "btn btn-primary"
          -else
            Oui
          
  
  -tr[:date] = capture do
    %td
      =l price_document.date, :format => :date
  -tr[:tot_amount_ht] = capture do
    %td.numeraire=number_to_currency price_document.tot_amount_ht, :unit => price_document.devise_symbol
  -tr[:tot_amount_tva] = capture do
    %td.numeraire=number_to_currency price_document.tot_amount_tva, :unit => price_document.devise_symbol
  -tr[:tot_amount_ttc] = capture do
    %td.numeraire=number_to_currency price_document.tot_amount_ttc, :unit => price_document.devise_symbol
  -tr[:solded] = capture do
    %td
      ="oui" if price_document.solded if price_document.price_document_type and price_document.price_document_type.accounting
  -tr[:to_paid_ttc] = capture do
    %td
      =number_to_currency price_document.to_paid_ttc, :unit => price_document.devise_symbol if price_document.price_document_type and price_document.price_document_type.accounting
  
  
  -tr[:actions] = capture do
    %td.actions
      -if !price_document.imported
        -if current_admin.has_permission?("payments")
          -if !price_document.d_number?
            = link_to i(:"trash-o"), [:admin, price_document], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true
            = link_to i(:pencil), edit_admin_price_document_path(price_document)
        
          -if price_document.label != "Facture"
        
        
            -if price_document.label == "Bon de commande" and @p_customer_sheet and @p_customer_sheet.price_documents.where(:cc_label => "Bon de livraison", :cancelled => false).count == 0
        
              = link_to i(:pencil), edit_admin_price_document_path(:id => price_document.id, :public_edit => true)
              =#link_to "Générer le bon de livraison",  bl_admin_price_document_path(price_document), :class => "btn btn-primary btn-ap-add"
          
            -elsif price_document.label == "Avoir"
            
              = link_to "Lettrage", edit_lettrage_admin_price_document_path(:id => price_document.id)
        
              = link_to i(:pencil), edit_admin_price_document_path(:id => price_document.id, :public_edit => true)
              =#link_to "Générer le bon de livraison",  bl_admin_price_document_path(price_document), :class => "btn btn-primary btn-ap-add"
           
          
          
    
          -if price_document.label == "Facture" 
            =link_to "Créer un avoir", create_avoir_admin_price_document_path(price_document)
      
          -if price_document.label == "Bon de livraison" and @p_customer_sheet
          
            -if @p_customer_sheet.price_documents.where(:cc_label => "Facture", :bon_de_livraison_id => price_document.id).count == 0
              -if price_document.cancelled
                %span.red
                  Document annulé
              -else
                =link_to "Annuler",  cancel_now_admin_price_document_path(price_document), :class => "btn btn-danger", :data => {:confirm => "Voulez-vous vraiment annuler ce BL (impossible de revenir en arrière)"}
                = link_to i(:pencil), edit_admin_price_document_path(:id => price_document.id, :public_edit => true)
                =link_to "Générer la facture",  bill_admin_price_document_path(price_document), :class => "btn btn-primary btn-ap-add", :onclick => "$(this).replaceWith('Sauvegarde en cours...');"
        
          =# link_to i(:eye), admin_price_document_path(price_document), :remote => true
      
      
        = link_to i(:eye), admin_price_document_path(price_document.id), :remote => false
        -if PriceLineBlock::PURCHASE_BLOCKS.include?(price_document.block_type)
          =# link_to i(:eye), admin_price_document_path(price_document.id), :remote => false
        
          -if !price_document.stock_ok
            = link_to i(:pencil), edit_admin_price_document_path(:id => price_document.id, :public_edit => true)
          
        -else
          = link_to i(:download), print_admin_price_document_path(price_document.token), :remote => false, :target => "_blank"
      
        = diag do
          = link_to i(:pencil), edit_admin_price_document_path(price_document)
          = link_to i(:eye), admin_price_document_path(price_document.id), :remote => false, :target => "_blank"
        

  =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => price_document}
  