-if true
  #p_sheet_line.product_stock_form.field.p_sheet_line_field{:id => form.object.id}
    %table{:style => "width:100%;"}
      %tr
        %td{:style => "width:70%;"}
          -if form.object.lock != true  
            =link_to_remove_fields ic(:"trash-o"), form

          %label Produit :
          %input.p_product_autocomplete_input.form-control{:type => "text", :value => ("#{form.object.p_product.code} #{form.object.p_product.name}" if form.object.p_product), :readonly => ("true" if form.object.id)}


          = form.hidden_field :p_product_id, :class => "p_product_id"

          :javascript
            $( function() {
      
                $('.p_product_autocomplete_input').autocomplete({
                   source: function( request, response ) {
                           $.ajax( {
                             url: "/admin/p_products/autocomplete.json",
                             dataType: "json",
                             data: {
                               search: request.term
                             },
                             success: function(data){
                   
                               arr = jQuery.map( data, function( item ) {
                                                   return {
                                                       label: item.code+" "+item.name,
                                                       value: item.code+" "+item.name,
                                                       id: item.id
                                                   }
                               });
                     
                               response(arr)
           
                             }
                   
                           } );
                         },
                   minLength: 2,
                   select: function( event, ui ) {
   
                     $(this).next(".p_product_id").val(ui.item.id)
           
                     //return false
                   }
                });
      
      
      
              } );
        %td{:style => "width:30%;"}
          =form.input :cust_ref, :label => "Référence client :"
                
  




    
    
    -p_product = form.object.p_product if form.object.p_product
    %table.table.order_table
      %tr
        %th
        
        
      
      
        -if form.object.p_product
          
          -p_product.p_sizes.order("p_sizes.position ASC, p_sizes.id ASC").all.each do |p_size|
            %th.size_th
              =p_size.name
          %th.price_td Qte
          %th.price_td PU
          %th.price_td
            Prix tot.
      -if form.object.p_product 
        -p_product.p_colors.all.each do |p_color|
          %tr.color_line
            %td=p_color.name
    
            -p_product.p_sizes.order("p_sizes.position ASC, p_sizes.id ASC").all.each do |p_size|
              %td
                -ps = p_product.p_product_stocks.where(:p_size_id => p_size.id, :p_color_id => p_color.id).first
        
                -if ps
                  -p_sheet_line_line = form.object.p_sheet_line_lines.where(:p_product_stock_id => ps.id).first
                  -if p_sheet_line_line
                    =form.fields_for(:p_sheet_line_lines, p_sheet_line_line) do |builder|
                      =builder.hidden_field :p_product_stock_id,:label => false, :as => :string
                      =builder.input :qte,:label => false, :as => :string, :input_html => {:class => "qte"}
        
            %td.qte_tot.price_td
            %td.price.price_td{:data => {:price => form.object.price}}
              =number_to_currency form.object.price
          
            %td.price_color_tot.price_td
    
    -if form.object.p_product 
      %table{:style => "width:100%"}

        
        
        %tr
        
          %td
            &nbsp
          %td
          %td.qte_tot.price_td{:style => "font-weight:bold;"}
            %strong=form.object.qte
        
          %td.price.price_td{:style => "font-weight:bold;", :data => {:price => form.object.price}}
            %strong=number_to_currency form.object.price
      
        
          %td.price_tot.price_td{:style => "font-weight:bold;"}
            =number_to_currency form.object.price_tot
    %br

