.qi_header
  .right
    -if false # params[:price_document_type_id].to_s == "5"
      =link_to ic(:plus)+" Ajouter un avoir", new_admin_price_document_path, :class => "btn btn-primary bgbd-ventes"
    -elsif params[:price_document_type_id].to_i == 6
      = link_to 'Ajouter une facture achat', new_admin_price_document_path(:document_type => "Facture d'achat"), :class => "btn btn-primary bgbd-documents", :remote => false
    
    -elsif params[:price_document_type_id].to_i == 7
      = link_to 'Ajouter une commande achat', new_admin_price_document_path(:document_type => "Commande achat"), :class => "btn btn-primary bgbd-documents", :remote => false
      
    
    
    -else
      =link_to ic(:plus)+" Demande de commande", admin_p_customers_path(:offre => true), :class => "btn btn-primary bgbd-ventes"
  %h1
    Documents
    %span
      Liste
      

.qi_search_row
  =form_tag "", :method => "get",  :onsubmit => "" do
    
    -if @p_customer
      .customer_label
        =link_to @p_customer.show_name, [:admin,@p_customer ]
    -if false and @p_customer
      .customer_label
        =@p_customer.show_name
        =link_to ic(:times),"#", :onclick => "$(this).closest('.customer_label').next('input').val('');$(this).closest('.customer_label').remove();return false;"
    =hidden_field_tag :p_customer_id, params[:p_customer_id],:class => "form-control", :placeholder => "Client" if params[:p_customer_id]
    


    %table.qi_search_row_top
      %tr.form-inline
        %td
          Début
        %td.input-group
          =text_field_tag :start, params[:start],:class => "form-control datepicker", :placeholder => "Début"
          .input-group-append
            %span.input-group-text{:onclick => "$(this).prev('input').val('');"}
              =ic(:times)
        %td.pl-4
          Fin
        %td.input-group
          =text_field_tag :stop, params[:stop],:class => "form-control datepicker", :placeholder => "Fin"
          .input-group-append
            %span.input-group-text{:onclick => "$(this).prev('input').val('');"}
              =ic(:times)

      %tr.form-inline
        %td.right.ml-auto
          -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-tertiary"
        %td.mr-auto
          -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-tertiary"


        -params[:price_document_type_ids] = params[:price_document_type_ids] || []
      %tr.form-inline
        %td
          Type de document :
        %td

          -if [1,2,6,7].include?(params[:price_document_type_id].to_i)or (params[:price_document_type_ids] and (params[:price_document_type_ids].include?("6") or params[:price_document_type_ids].include?("7")))
            -PriceDocumentType.where(:label => PriceDocument::PURCHASES, :enabled => true).order("id DESC").each do |pdt|
              %p.d-inline-flex.ml-3
                = check_box_tag :"price_document_type_ids[]", pdt.id, (true if params[:price_document_type_ids].include?(pdt.id.to_s)), {:id => "price_document_type_ids_#{pdt.id}", class: "my-auto"}
                = label_tag "price_document_type_ids_"+pdt.id.to_s, pdt.label, class: "ml-3 my-auto"
          
          -else
            -PriceDocumentType.where(:label => PriceDocument::SALES, :enabled => true).order("id DESC").each do |pdt|
              %p.d-inline-flex
                = check_box_tag :"price_document_type_ids[]", pdt.id, (true if params[:price_document_type_ids].include?(pdt.id.to_s)), {:id => "price_document_type_ids_#{pdt.id}"}
                = label_tag "price_document_type_ids_"+pdt.id.to_s, pdt.label, class: "ml-3"
    %br
    %table
      %tr
        %td
          Montant TTC : 
        %td
          de
        %td
          =number_field_tag :amount_min, params[:amount_min],:class => "form-control", :placeholder => "min", :step => 0.01
        %td
          à
        %td
          =number_field_tag :amount_max, params[:amount_max],:class => "form-control", :placeholder => "max", :step => 0.01
          
        -if !current_admin.p_commercial and params[:price_document_type_id].to_i != 6
          %td
            Commercial :
            =select_tag "search[p_commercial_id]", options_for_select([["",""],["Aucun","null"]]+PCommercial.order(:name).all.map{|a| [a.member_label, a.id]}, params[:search][:p_commercial_id])
    
        -if [6].include?(params[:price_document_type_id].to_i)
          %td
            Type de paiement :
            =select_tag "search[p_payment_type_id]", options_for_select([["",""]]+PPaymentType.order(:name).all.map{|a| [a.name, a.id]}, params[:search][:p_payment_type_id])
        
        
          %td
            Soldé ?
            =select_tag "search[cc_solded]", options_for_select([[""], "Oui", "Non"], params[:search][:cc_solded])

          %td
            Importé ?
            =select_tag "search[imported]", options_for_select([[""], "Oui", "Non"], params[:search][:imported])
          
    %table
      %tr
        %td
          Numéro de document :
        %td
          =text_field_tag "search[d_number]", params[:search][:d_number],:class => "form-control"
          
        %td
          Echeance :
        %td
          Début
        %td
          .input-group
            =text_field_tag :start_cc_payment_end_at, params[:start_cc_payment_end_at],:class => "form-control datepicker", :placeholder => "Début"
            %span.input-group-addon.btn{:onclick => "$(this).prev('input').val('');"}
              =ic(:times)
     
        %td
          Fin
        %td
          .input-group
            =text_field_tag :stop_cc_payment_end_at, params[:stop_cc_payment_end_at],:class => "form-control datepicker", :placeholder => "Fin"
            %span.input-group-addon.btn{:onclick => "$(this).prev('input').val('');"}
              =ic(:times)
        
        %td
          Marge calculée ?
          =select_tag "search[cost_ok]", options_for_select([[""], "Oui", "Non"], params[:search][:cost_ok])
        
    
    =render :partial => "qi/qi_ordered_table_search_footer", :locals => {:collection_object => @price_documents}
    
-if true #if params[:price_document_type_id].to_i != 0
  =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => params[:price_document_type_id].to_s}


:scss
  .qi_search_row_top{
    td{
      vertical-align:top;
    }
    p{
      margin:0;
    }
  }
    

    
