-ok = ok || false



%table.table.sheet_line{:style => "width:100%;"}
  %tr
    =#%th{:style => "width:30px;"}
    %th 
      Etat
    %th
      Description
    %th
      Qte
    %th
      Prix U.
    %th 
      Prix Tot.
    %th
      Prix TTC
      
      
  -sheet_lines.each do |sheet_line|
    -ok = sheet_line.shiped ? true : false
    %tr
      %td
        
        - if sheet_line.shiped
          Livréé
        - elsif sheet_line.cancel
          %span{:style => "color:red;"} Annulée
        -elsif sheet_line.lock
          En cours de livraison
        -elsif sheet_line.p_product.p_product_cat_id != 6 or sheet_line.externe and @p_customer_sheet
          En cours de livraison
          %br
          
          =link_to "Indiquer comme livré", set_sheet_line_ship_admin_p_customer_sheet_path(@p_customer_sheet, :p_sheet_line_ids => [sheet_line.id]), :remote => true
            
        -elsif sheet_line.p_product.p_product_cat_id == 6 and !sheet_line.externe and @p_customer_sheet and (@p_customer_sheet.state == "commande" or @p_customer_sheet.state == "livraison-en-cours")
          =link_to "Ajouter à une livraison en cours", urg_ship_admin_p_customer_sheet_path(@p_customer_sheet, :p_sheet_line_id => sheet_line.id) #, :target => "_blank"
          %br
          =link_to ic(:remove)+" Annuler cette ligne (ne pas livrer)", cancel_admin_p_sheet_line_path(sheet_line), :data => {:confirm => "Attention : cette ligne ne pourra plus être mise en livraison."}, :style => "color:red;"
      %td
        =sheet_line.p_product.name 
        =#debug sheet_line.p_payments
        =#sheet_line.ref
        -if sheet_line.shiped
          -if sheet_line.decr
            Stocks décrémentés
          -else
            =link_to "Décrémenter les stocks", decrement_admin_p_sheet_line_path(sheet_line), :data => {:confirm => "Attention : les stocks seront définitivement décrémenté, à ne faire que dans le cas d'un remboursement où la marchandise a été rachetée."}
        
        -if sheet_line.stock_done
          &nbsp;&nbsp;
          =link_to "Voir les marges", "#", :onclick => "$(this).next('.marges').toggle();return false;"
          
          
        
          %table.table.marges{:style => "display:none;"}
            -sheet_line.p_sheet_line_stocks.each do |p_sheet_line_stock|
              %tr
                
                %td
                  =p_sheet_line_stock.p_brut_product.name
                %td
                  =p_sheet_line_stock.qte_ok
                %td
                  =number_to_currency p_sheet_line_stock.price_ok, :precision => 5
                %td
                  =number_to_currency p_sheet_line_stock.price_tot_ok
            %tr
              %td{:colspan => 3}
                Total cout
              %td  
                =number_to_currency sheet_line.total_cost_ok
          
            %tr
              %td{:colspan => 3}
                Total marge
              %td  
                =number_to_currency sheet_line.marge_ok
            %tr
              %td{:colspan => 3}
                Cout u
              %td  
                =number_to_currency sheet_line.cost_u_ok, :precision => 5
          
            %tr
              %td{:colspan => 3}
                Marge u
              %td  
                =number_to_currency sheet_line.marge_u_ok, :precision => 5
      
        
      -if ok
        %td
          =sheet_line.ok_qte
        %td
          =number_to_currency sheet_line.ok_price, :precision => 5 if sheet_line.ok_price
        
        %td
          =number_to_currency sheet_line.ok_price_tot if sheet_line.ok_price_tot
        
        %td
          =number_to_currency sheet_line.ok_price_tot_ttc if sheet_line.ok_price_tot_ttc
      -else
        %td
          =sheet_line.qte
          
        %td
          =number_to_currency sheet_line.price, :precision => 5 if sheet_line.price
        
        %td
          =number_to_currency sheet_line.price_tot if sheet_line.price_tot
        
        %td
          =number_to_currency sheet_line.price_tot_ttc if sheet_line.price_tot_ttc
        
  
  -totals =  PSheetLine.totals(sheet_lines)
  %tr
    %td{:style => "text-align:right;padding-right:10px;", :colspan =>5}
      %strong Total HT
    %td
      -if ok
        =number_to_currency totals[:ok_total]
      -else
        =number_to_currency totals[:total]
  %tr
    %td{:style => "text-align:right;padding-right:10px;", :colspan =>5}
      %strong Total TTC
    %td
      -if ok
        =number_to_currency totals[:ok_total_ttc]
      -else
        =number_to_currency totals[:total_ttc]

:scss
  .marges{
    td{
      vertical-align:top;
    }
  }