
.price_line_form.field
  .qi_row{:style => "padding:5px 20px"}
    .qi_pannel.qi_plain.padding{:style =>"border-left:4px solid gray;padding-left:5px;"}
      %table.form-table{:style => "width:100%;"}
        %tr
          %td{:style => "width:30px;"}
            .take 
              =ic :arrows
          
          %td
            = form.input :ct_title, :label => "Désignation personnalisée :"
            = form.input :ct_description, :label => "Description personnalisée :", :input_html => {:style => "height:70px;"}
            
          
          %td{:style => "width:300px"}
            %label Produit :
            %input.p_product_ref_autocomplete_input.form-control{:type => "text", :value => ("#{form.object.p_product_ref.ref} #{form.object.p_product_ref.cc_name}" if form.object.p_product_ref)}
       
      
            = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id"
        
        
            :javascript
              $( function() {
              
                  $('.p_product_ref_autocomplete_input').autocomplete({
                     source: function( request, response ) {
                             $.ajax( {
                               url: "/admin/p_product_refs/autocomplete.json",
                               dataType: "json",
                               data: {
                                 search: request.term,
                                 p_customer_id: $(".p_customer_id").val()
                               },
                               success: function(data){
                           
                                 arr = jQuery.map( data, function( item ) {
                                                     return {
                                                         label: item.member_label,
                                                         value: item.member_label,
                                                         id: item.id
                                                     }
                                 });
                             
                                 response(arr)
                   
                               }
                           
                             } );
                           },
                     minLength: 2,
                     select: function( event, ui ) {
           
                       $(this).next(".p_product_ref_id").val(ui.item.id)
                   
                       form = $(this).closest(".price_line_form")
                   
                   
                   
                       $.ajax( {
                         url: "/admin/p_product_refs/"+ui.item.id+"/get_infos.json",
                         dataType: "json",
                         data: {
                           type: "price",
                           qte: form.find(".input_price_line_qte").val(),
                           p_customer_id: $(".p_customer_id").val()
                         },
                         success: function (data) {
                           alert(data.p_product_cat_id);
                           form.find(".input_price_line_price_u_ht").val(data.price);
                           form.find(".input_price_line_tva_account_id").val(data.tva_account_id);
                           form.find(".input_price_line_p_product_cat_id").val(data.p_product_cat_id);
                           form.find(".input_price_line_tva_account_value").val(data.tva_account_value);
                           form.find(".input_price_line_weight_u").val(data.weight);
                       
                      
                       
                        }
                     
                     
                       } );
                   
                   
                   
                   
                       //return false
                     }
                  });
              
              
              
                } );
            
        
          
            
        
      %table.form-table{:style => "width:100%;margin-top:5px;"}
        %tr
          %td{:style => "width:30px"}
            %span.destroy=link_to_remove_fields ic(:"trash-o"), form
          %td
            -form.object.forced_price = true if form.object.ct_u_price_ht
        
            -if form.object.forced_price and form.object.p_product_ref
              =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :", :value => form.object.th_price_u_ht)
            -else
              =qi_js_field(form, :price_line, :price_u_ht, :label => "Prix U HT :")
        
            = form.input :forced_price, :label => "Prix personnalisé ?", :as => :boolean, :input_html => {:class => "input_price_line_forced_price"}
            .forced_price_wrapper{:style => ("display:none;" if !form.object.forced_price)}
            = form.input :ct_u_price_ht, :label => "Prix HT :" , :input_html => {:class => "input_price_line_ct_u_price_ht"}
      
          %td
            = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte"}
    
        
      
          %td
            =#qi_js_field(form, :price_line, :tva_account_id, :label => "Compte TVA :")
            %label Taux de TVA :
            %br
            =#select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id" #, :disabled => true
        
            = form.input :ct_tva_account_id, :collection => TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, :as => :select, :member_label => :name, :include_blank => false, :label => false, :input_html => {:class => "input_price_line_tva_account_id"}
        
        
            =qi_js_field(form, :price_line, :tva_account_value, :hidden => true)
      
          %td
            = form.input :ct_p_product_cat_id, :collection => PProductCat.order(:code).all, :as => :select, :member_label => :member_label, :include_blank => false, :label => "Catégorie vente", :input_html => {:class => "input_price_line_p_product_cat_id"}
      
      %table.form-table{:style => "width:100%;margin-top:5px;"}
        %tr
          %td{:style => "width:30px"}
          %td
            = form.input :start_at, :label => "Date de début de location :", :as => :date
          %td
            = form.input :end_at, :label => "Date de fin de location : ", :as => :date
            
          %td
            = form.input :ship_at, :label => "Date de livraison :", :as => :date
          %td
            = form.input :return_at, :label => "Date de récupération : ", :as => :date
          
          %td
            = form.input :ct_ship_price_ht, :label => "Prix livraison HT :"
            
      

      = form.hidden_field :position, :class => "price_line_position_input"
  

