.qi_header
  .right
    -if false
      = link_to ic(:minus)+' Sortie de stock', new_admin_stock_movement_path(:movement_type => "deb"), :class => "btn btn-primary bgbd-documents", :remote => true
      = link_to ic(:plus)+' Entrée de stock', new_admin_stock_movement_path(:movement_type => "cred"), :class => "btn btn-primary bgbd-documents", :remote => true

  %h1
    Mouvements de stocks



.qi_search_row
  =form_tag "", :method => "get",  :onsubmit => "" do
    %table.qi_search_row_top
      %tr
        %td
          Début
        %td
          .input-group
            =text_field_tag :start, params[:start],:class => "form-control datepicker", :placeholder => "Début"
            %span.input-group-addon.btn{:onclick => "$(this).prev('input').val('');"}
              =ic(:times)

          %br
          -if @start and @stop

            =link_to "< Mois précédent",request.query_parameters.merge({start: ((@start - 1.month).beginning_of_month.strftime('%d/%m/%Y')), stop: ((@stop - 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-default"


        %td
          Fin
        %td
          .input-group
            =text_field_tag :stop, params[:stop],:class => "form-control datepicker", :placeholder => "Fin"
            %span.input-group-addon.btn{:onclick => "$(this).prev('input').val('');"}
              =ic(:times)
          %br
          -if @start and @stop
            =link_to "Mois suivant >",request.query_parameters.merge({start: ((@start + 1.month).beginning_of_month.strftime('%d/%m/%Y')), stop: ((@stop + 1.month).end_of_month.strftime('%d/%m/%Y'))}), :class => "btn btn-default"


        %td
          Produit :
        %td

          %input.form-control{:name => "p_product_ref", :class => "p_product_ref_autocomplete_input", :type => "text", :value => params[:p_product_ref]}


          = hidden_field_tag "p_product_ref_id".to_sym, params[:p_product_ref_id], :class => "p_product_ref_id"

          :javascript
            qi_autocomplete('p_product_ref');


    =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @line_stocks}

-if @p_product_ref


  .qi_kpi
    %h3
      =@p_product_ref.name



    .kpi{:style => "background:#4098df;"}
      .number
        =@line_stocks.sum(:qte_available)

      .label


      .desc
        unités en stock

    .kpi{:style => "background:#4098df;"}
      .number
        = @line_stocks.sum(:cc_qte_kg_available).to_i
        Kg

      .label


      .desc
        en stock

    .kpi{:style => "background:#4098df;"}
      .number
        =number_to_currency @line_stocks.sum(:price_ht)

      .label


      .desc
        de valorisation de stock





    .kpi{:style => "background:#f6c143;"}
      .number
        =@line_stocks.sum(:qte_used)

      .label


      .desc
        unités sorties



    .kpi{:style => "background:#f6c143;"}
      .number
        = @line_stocks.sum(:cc_qte_kg_used).to_i
        Kg

      .label


      .desc
        sortis

    .kpi{:style => "background:#f6c143;"}
      .number
        =number_to_currency @line_stocks.sum(:cc_price_ht_used)

      .label


      .desc
        sortis





.clear

=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @line_stocks}



