-ok = ok || false


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

    %th
      Description
    %th
      
    %th
      
    %th
      Qte
    -if @p_document and @p_document.label != "Bon de livraison"
      %th
        Prix U.
      %th 
        Prix Tot.
      %th
        Prix TTC
      
      
  -sheet_lines.each do |sheet_line|
    -p_sheet_line_lines = sheet_line.p_sheet_line_lines.where("qte > 0")
    -nbr_lines = p_sheet_line_lines.count
    -ok = true if sheet_line.shiped
    
    
    
    %tr
      %td{:colspan => 3, :style => "text-align:right;"}
        %table.size_table
          %tr
            %th{:style => "text-align:left !important;"}
              =sheet_line.product_name
              
              
            -p_sheet_line_lines.group(:p_size_id).joins(:p_size).order("p_sizes.position ASC, p_sizes.id ASC").uniq.each do |psize|
              %th.p_size_td=psize.p_size.name
              
            
      %td{:colspan => 4}
    -p_sheet_line_lines.group(:p_color_id).uniq.each do |pc|
      -qte_tot = 0.0
      %tr
        %td{:colspan => 3, :style => "text-align:right;"}
          %table.size_table
          
            
            
        
            %tr
              %td
                =pc.p_color.name
            
              -p_sheet_line_lines.group(:p_size_id).joins(:p_size).order("p_sizes.position ASC, p_sizes.id ASC").uniq.each do |psize|
            
                %td.p_size_td
                  -psl = p_sheet_line_lines.where(:p_size_id => psize.p_size_id, :p_color_id => pc.p_color_id ).first
                  -if psl
                    =psl.qte
                    -qte_tot += psl.qte
                  
      
        %td{}
          =qte_tot.to_i
        -if @p_document and @p_document.label != "Bon de livraison"
          %td
            =number_to_currency sheet_line.price.to_f
          %td
            =number_to_currency sheet_line.price.to_f * qte_tot.to_i
        
          %td
            =number_to_currency sheet_line.price.to_f * (sheet_line.tva.to_f+1) * qte_tot.to_i
    
    %tr.tr_sheet_line_head
    
      %td
      
   
      %td
      %td
     
      
  
      %td
        =sheet_line.qte
      
      -if @p_document and @p_document.label != "Bon de livraison"
        %td
          =number_to_currency sheet_line.price 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
      
      
  -total_with_labels =  PSheetLine.total_with_labels(sheet_lines)
  
  -if @p_document and @p_document.label != "Bon de livraison"
    -total_with_labels.each do |index, total|


      %tr.sheet_line_head
        %td{:style => "border:0;", :colspan =>3}
        %td{:style => "text-align:right;padding-right:10px;", :colspan =>3}
          %strong
            =total[:label]
        %td
          =number_to_currency total[:value]
  
    -if @p_document and @p_document.label == "Facture Acompte"
      %tr
        %td{:style => "border:0;", :colspan =>3}
        %td{:style => "text-align:right;padding-right:10px;", :colspan =>3}
          Pourcentage d'acompte :
        %td
          =@p_document.acompte_percent.to_s+"%"
      %tr
        %td{:style => "border:0;", :colspan =>3}
        %td{:style => "text-align:right;padding-right:10px;", :colspan =>3}
          Acompte HT :
        %td
          =number_to_currency @p_document.total_with_labels_table[:total][:value] * (@p_document.acompte_percent.to_f/100)
    
      %tr.sheet_line_head
        %td{:style => "border:0;", :colspan =>3}
        %td{:style => "text-align:right;padding-right:10px;", :colspan =>3}
          %strong Acompte TTC :
        %td
          %strong=number_to_currency @p_document.total_with_labels_table[:total_ttc][:value] * (@p_document.acompte_percent.to_f/100)
       


:scss
  .sheet_line_head{
    td, th{
      border-color:rgba(0,0,0,0.5) !important;
    }
    
  }
  
  
  .tr_sheet_line_head{
    td, th{
      border:0;
      border-bottom: 1px solid rgba(0,0,0,0.5) !important;
    }
    
  }
  
  .marges{
    td{
      vertical-align:top;
    }
    
    
    
    
  }
  
  .size_table{
    width:97%;
   
    text-align:center;
    margin-right:3%;
    td,th{
      text-align:right;
      border:0;
      border-right:solid 1px rgba(0,0,0,0.1) !important;
      padding:0 3px;
    }
    .p_size_td{
      width:60px;
      text-align:center;
    }
    
  }