.p_product_page
  .qi_header
    %h1
      =link_to ic(:user)+" Mon compte", public_my_account_path
      %span
        =link_to "Les produits Biocoton disponibles", public_p_products_path
      %span
        =@p_product.p_product_cat.name if @p_product.p_product_cat
        =@p_product.name


  .qi_row
    .qi_pannel.qi_plain.padding
      -if @p_product.image_file
        .image_col
          =image_tag @p_product.image_file.file.large.medium.url 
      .description{:style => ("margin-left:0;" if !@p_product.image_file)}
        =simple_format @p_product.description
      .clear
      %br
      
      
            
      
          
        
      -if @p_product.get_prices(current_p_customer).count > 0 and @p_product.get_prices(current_p_customer).first.price > 0.0
        .sub_header
          -if current_p_customer.account_validated
            .right
            
              -if @p_product.get_prices(current_p_customer).count > 1
                %p
                  Prix de
                  =number_to_currency @p_product.get_prices(current_p_customer).last.price
                  à 
                  = number_to_currency @p_product.get_prices(current_p_customer).first.price 
                %table.table.price_table
                  %tr
        
                    -@p_product.get_prices(current_p_customer).each do |price|
  
                      %td
                        A partir de 
                        =price.nbr.to_i
                        ex
                  %tr
        
                    -@p_product.get_prices(current_p_customer).each do |price|
  
                      %td
                        =number_to_currency price.price
      
              -elsif @p_product.get_prices(current_p_customer).count == 1
                %p
                  %strong Votre prix : 
                  =number_to_currency @p_product.get_prices(current_p_customer).last.price
          
          -if !current_p_customer.account_validated
            %p
              %strong Vous pourrez commander ce produit dès que votre compte sera validé
          -else
            %h2 Commander
      
        -if current_p_customer.account_validated
          .p_sheet_line_order
            -@p_sheet_line = PSheetLine.new(:p_product => @p_product)
            -#@p_sheet_line.generate_p_sheet_line_lines
            .p_sheet_lines_form
              =semantic_form_for [:public, @p_sheet_line], :remote => false, :html => {  :id => "cart_form"} do |form|
  
                #p_sheet_line.product_stock_form.field.p_sheet_line_field{:id => form.object.id}

                  = form.hidden_field :p_product_id, :class => "p_product_id"
        
                  -if form.object.p_product

                    -p_product = form.object.p_product
  
                
                    %table.table.order_table
                      %tr
                        %th
                  
                          =#form.input :cust_ref, :placeholder => "Votre référence", :label => false
                      
                        -p_product.p_sizes.order("position").all.each do |p_size|
                          %th.size_th
                            =p_size.name
                    
                        %th.price_td PU
                        %th.price_td
                          Prix tot.
                    
                      -p_product.p_colors.all.each do |p_color|
                        %tr.color_line
                          %td=p_color.name
                  
                          -p_product.p_sizes.order("position").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 = @p_sheet_line.p_sheet_line_lines.new(:p_product_stock_id => ps.id)
                                -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, :input_html => {:class => "qte"}
                                    .stock_line{:style => "text-align:left;font-size:0.8em;color:rgba(0,0,0,0.5)"}
                                    
                                      %span{:style => "font-size:0.75em;"}
                                        &nbsp;&nbsp;
                                        Stock :
                                      =ps.stock_th_ok
                      
                          %td.price.price_td{:data => {:price => form.object.price}}
                            =number_to_currency form.object.price
                        
                          %td.price_color_tot.price_td
                
                
                  %table{:style => "width:100%"}

                    
                    
                    %tr
                    
                      %td
                        &nbsp
                      %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
                  %br
                  .right=form.submit "Ajouter à ma commande", :class => "btn btn-primary"
                  .clear
                
:scss
  .size_th{
    width:80px;
    
  }


  
:scss
  .price_emp{
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857;
    color: #555555;
    height:34px;

  }

  .price_td{
    width:170px;
    text-align:right;

  }


:scss
  .product_stock_form{
  td{
    vertical-align:top;
  .form-control, .form-group{
  margin-bottom:0}
  }

  }
  
:scss
  .size_th{
    width:80px;
    
  }
  
:coffeescript
  
  
  udpate_sheet_lines()
  
  $("#cart_form").change ->
    udpate_sheet_lines()
    #$(this).submit()
  $("#cart_form").keyup ->
    udpate_sheet_lines()
    #$(this).submit()

