-ok = ok || false


%table.table.sheet_line{:style => "width:100%;"}
  %tr
    =#%th{:style => "width:30px;"}

    %th
      Description
    %th{:style => "width:50px;"}
      Qte
    %th{:style => "width:100px;"}
      Prix U.
    %th{:style => "width:100px;"} 
      Prix Tot.
    %th{:style => "width:100px;"}
      Prix TTC
      
      
  -sheet_lines.each do |sheet_line|
    -ok = true if sheet_line.shiped or sheet_line.element_label == "Avoir"
    %tr.product_principal
      
      %td
        -if sheet_line.p_product
          =sheet_line.p_product.name 
        -elsif sheet_line.custom
          =sheet_line.custom_title
          
        
        
        
       
        
      -if ok
        %td
          -if sheet_line.p_document and sheet_line.p_document.label == "Avoir"
            =sheet_line.ok_qte*-1
          -else
            =sheet_line.ok_qte
        %td
          -if sheet_line.ok_price
            -if sheet_line.ok_price.round(2) == sheet_line.ok_price
              =number_to_currency sheet_line.ok_price, :precision => 2
            -else
              =number_to_currency sheet_line.ok_price, :precision => 5
        
        %td
          -if sheet_line.p_document and sheet_line.p_document.label == "Avoir"
            =number_to_currency (sheet_line.ok_price_tot*-1) if sheet_line.ok_price_tot
          -else
            =number_to_currency sheet_line.ok_price_tot if sheet_line.ok_price_tot
        
          
        
        %td
          -if sheet_line.p_document and sheet_line.p_document.label == "Avoir"
            =number_to_currency sheet_line.ok_price_tot_ttc*-1 if sheet_line.ok_price_tot_ttc
          -else
            =number_to_currency sheet_line.ok_price_tot_ttc if sheet_line.ok_price_tot_ttc
      -else
        %td
          =sheet_line.qte
          
        %td
          -if sheet_line.price
            -if sheet_line.price.round(2) == sheet_line.price
              =number_to_currency sheet_line.price, :precision => 2 
            -else
              =number_to_currency sheet_line.price, :precision => 5
        %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
      -if sheet_line.p_product and sheet_line.p_product.p_product_specs.count > 0
        %tr
          %td{:colspan => 3,  :style => "font-size:8pt;"}
            -sheet_line.p_product.p_product_specs.each do |p_product_spec|
              %p
                =p_product_spec.code
                =p_product_spec.description
          %td
          %td
  
  -totals =  PSheetLine.totals(sheet_lines)
  %tr
    %td{:style => "border:0;"}
    %td{:style => "text-align:right;padding-right:10px;", :colspan =>2}
      %strong Total HT
    %td
      -if ok
        -if @p_document and @p_document.label == "Avoir"
          =number_to_currency totals[:ok_total]*-1
        -else
          =number_to_currency totals[:ok_total]
      -else
        =number_to_currency totals[:total]
    %td
  
  %tr
    %td{:style => "border:0;"}
    %td{:style => "text-align:right;padding-right:10px;", :colspan =>2}
      %strong TVA (20%)
    %td
      -if ok
        -if @p_document and @p_document.label == "Avoir"
          =number_to_currency (totals[:ok_total_ttc] - totals[:ok_total])*-1
        -else
          =number_to_currency totals[:ok_total_ttc] - totals[:ok_total]
      -else
        =number_to_currency totals[:total_ttc] - totals[:total]
    %td
  
  %tr
    %td{:style => "border:0;"}
    %td{:style => "text-align:right;padding-right:10px;", :colspan =>2}
      %strong Total TTC
    %td
      -if ok
        -if @p_document and @p_document.label == "Avoir"
          =number_to_currency totals[:ok_total_ttc]*-1
        -else
          =number_to_currency totals[:ok_total_ttc]
      -else
        =number_to_currency totals[:total_ttc]
    %td

:scss
  .marges{
    td{
      vertical-align:top;
    }
  }
  .product_principal{
    td{border-bottom:0 !important;}
  }